public ApiResponse Update(InvoiceSetup invoiceSetup)
        {
            var validationError = ValidateUpdate(invoiceSetup);

            if (validationError.Count() == 0)
            {
                _faciTechDbContext.SaveChanges();
                return(new ApiResponse(new { Id = invoiceSetup.Id }));
            }
            return(new ApiResponse(validationError));
        }
        private List <ErrorInfo> ValidateCreate(InvoiceSetup invoiceSetup)
        {
            List <ErrorInfo> errorInfos = new List <ErrorInfo>();

            /*
             * errorInfos.Add(new ErrorInfo()
             * {
             *    Key = "Name", Code = "UNIQUE_VIOLATION_ERROR", Description = "Name has to be unique"
             * });
             */
            return(errorInfos);
        }
Ejemplo n.º 3
0
        public InvoiceSetup Map(InvoiceSetupApiModel invoiceSetupApiModel, InvoiceSetup invoiceSetup = null)
        {
            if (invoiceSetup == null)
            {
                invoiceSetup = new InvoiceSetup();
            }

            invoiceSetup.InvoiceDate = invoiceSetupApiModel.InvoiceDate.ToDateTime().Value;
            invoiceSetup.PayByDate   = invoiceSetupApiModel.PayByDate.ToDateTime().Value;
            invoiceSetup.SectionId   = invoiceSetupApiModel.SectionId;
            invoiceSetup.Description = invoiceSetupApiModel.Description;
            return(invoiceSetup);
        }
        public ApiResponse Add(Guid communityId, InvoiceSetup invoiceSetup)
        {
            var validationError = ValidateCreate(invoiceSetup);

            if (validationError.Count() == 0)
            {
                invoiceSetup.Id          = Guid.NewGuid();
                invoiceSetup.CommunityId = communityId;
                _faciTechDbContext.InvoiceSetup.Add(invoiceSetup);
                _faciTechDbContext.SaveChanges();
                return(new ApiResponse(new { Id = invoiceSetup.Id }));
            }
            return(new ApiResponse(validationError));
        }
 public ActionResult GetSingle(Guid id)
 {
     try
     {
         ApiResponse  apiResponse          = this._invoiceSetupService.GetSingle(id);
         InvoiceSetup invoiceSetup         = apiResponse.GetData <InvoiceSetup>();
         var          invoiceSetupApiModel = _invoiceSetupMapper.Map(invoiceSetup);
         return(Ok(invoiceSetupApiModel));
     }
     catch (Exception ex)
     {
         return(new UnknownErrorResult(ex, base._errorEnabled));
     }
 }
Ejemplo n.º 6
0
        public InvoiceSetupApiModel Map(InvoiceSetup invoiceSetup, InvoiceSetupApiModel invoiceSetupApiModel = null)
        {
            if (invoiceSetupApiModel == null)
            {
                invoiceSetupApiModel = new InvoiceSetupApiModel();
            }

            invoiceSetupApiModel.Id          = invoiceSetup.Id.ToString();
            invoiceSetupApiModel.InvoiceDate = invoiceSetup.InvoiceDate.ToDateString();
            invoiceSetupApiModel.PayByDate   = invoiceSetup.PayByDate.ToDateString();
            invoiceSetupApiModel.SectionId   = invoiceSetup.SectionId;
            invoiceSetupApiModel.SectionName = invoiceSetup.SectionId != null ? invoiceSetup.Section.FullName : "All";
            invoiceSetupApiModel.Description = invoiceSetup.Description;
            invoiceSetupApiModel.ParentId    = invoiceSetup.ParentInvoiceSetupId.HasValue ? invoiceSetup.ParentInvoiceSetupId.ToString() : "";
            return(invoiceSetupApiModel);
        }
Ejemplo n.º 7
0
        public async Task CreateInvoiceSetup(string companyId, InvoiceSetup invoiceSetup)
        {
            var queryParameters = new DynamicParameters();

            queryParameters.Add("@VATActive", invoiceSetup.VatActive);
            queryParameters.Add("@VATLabel", invoiceSetup.VatLabel);
            queryParameters.Add("@DefaultVATCode", invoiceSetup.DefaultVATCode);
            queryParameters.Add("@TolerancePercentage", invoiceSetup.TolerancePercentage);
            queryParameters.Add("@AuthorizedForPosting", invoiceSetup.AuthorizedForPosting);
            queryParameters.Add("@CompanyId", companyId);
            queryParameters.Add("@PaymentTermId", invoiceSetup.PaymentTermId);
            queryParameters.Add("@ThresholdCostAmount", invoiceSetup.ThresholdCostAmount);
            queryParameters.Add("@DefaultCostVATCode", invoiceSetup.DefaultCostVATCode);
            queryParameters.Add("@TaxTypeId", invoiceSetup.TaxTypeId);

            await ExecuteNonQueryAsync(StoredProcedureNames.CreateInvoiceSetup, queryParameters, true);
        }
Ejemplo n.º 8
0
        private void GenerateUnitInvoice(InvoiceSetup invoiceSetup, Unit unit)
        {
            List <InvoiceItem> invoiceItemList = new List <InvoiceItem>();

            foreach (var invoiceSetupItem in invoiceSetup.InvoiceSetupItems)
            {
                InvoiceItem invoiceItem = GetInvoiceItem(invoiceSetupItem, unit);
                if (invoiceItem != null)
                {
                    invoiceItemList.Add(invoiceItem);
                }
            }
            if (invoiceItemList.Count() > 0)
            {
                CreateInvoice(invoiceSetup, invoiceItemList, unit);
            }
            else
            {
            }
        }
        public ActionResult Update(Guid id, InvoiceSetupApiModel invoiceSetupApiModel)
        {
            try
            {
                ApiResponse serviceResponse = this._invoiceSetupService.GetSingle(id);
                if (serviceResponse.IsSuccess() == false)
                {
                    return(new ObjectNotFoundResult(serviceResponse));
                }

                InvoiceSetup invoiceSetup = serviceResponse.GetData <InvoiceSetup>();
                _invoiceSetupMapper.Map(invoiceSetupApiModel, invoiceSetup);
                serviceResponse = this._invoiceSetupService.Update(invoiceSetup);
                return(SendResponse(serviceResponse));
            }
            catch (Exception ex)
            {
                return(new UnknownErrorResult(ex, base._errorEnabled));
            }
        }
Ejemplo n.º 10
0
        private List <Unit> GetTargetUnits(InvoiceSetup invoiceSetup)
        {
            IQueryable <Unit> unitQuery = null;

            if (invoiceSetup.SectionId.HasValue)
            {
                unitQuery = _faciTechDbContext.Unit.Where(e => e.SectionId == invoiceSetup.SectionId.Value);
            }
            else
            {
                unitQuery = _faciTechDbContext.Unit.Where(e => e.CommunityId == invoiceSetup.CommunityId);
            }

            var units = unitQuery.Select(e => new Unit()
            {
                Id = e.Id, Area = e.Area, CommunityId = e.CommunityId
            })
                        .ToList();

            return(units);
        }
        private List <InvoiceSetup> PrepareChildInvoiceSetup(InvoiceSetupScheduleDto invoiceSetupScheduleDto, InvoiceSetup parentInvoiceSetup)
        {
            List <InvoiceSetup> childInvoiceSetupList = new List <InvoiceSetup>();
            DateTime            scheduleDate          = invoiceSetupScheduleDto.StartDate;

            while (scheduleDate <= invoiceSetupScheduleDto.EndDate)
            {
                InvoiceSetup childInvoiceSetup = new InvoiceSetup();
                childInvoiceSetup.Id                   = Guid.NewGuid();
                childInvoiceSetup.InvoiceDate          = scheduleDate;
                childInvoiceSetup.ParentInvoiceSetupId = parentInvoiceSetup.Id;
                childInvoiceSetup.PayByDate            = scheduleDate.AddDays(invoiceSetupScheduleDto.PaymentDays);
                childInvoiceSetup.CommunityId          = parentInvoiceSetup.CommunityId;

                childInvoiceSetupList.Add(childInvoiceSetup);

                var computeFunction = frequencyRepository.Get(invoiceSetupScheduleDto.Frequency).Item3;
                scheduleDate = computeFunction(scheduleDate);
            }
            return(childInvoiceSetupList);
        }
Ejemplo n.º 12
0
        private void CreateInvoice(InvoiceSetup invoiceSetup, List <InvoiceItem> invoiceItemList, Unit unit)
        {
            if (invoiceItemList == null || invoiceItemList.Sum(e => e.TotalAmount) <= 0)
            {
                return;
            }

            decimal amount    = 0;
            decimal taxAmount = 0;
            Guid    invoiceId = Guid.NewGuid();

            foreach (var invoiceItem in invoiceItemList)
            {
                amount               += invoiceItem.Amount;
                taxAmount            += invoiceItem.TaxAmount.HasValue ? invoiceItem.TaxAmount.Value : 0;
                invoiceItem.InvoiceId = invoiceId;
                invoiceItem.Id        = Guid.NewGuid();
            }
            var     invoiceNumber = _faciTechDbContext.GenerateSequence("invoice_number");
            Invoice invoice       = new Invoice()
            {
                Id          = invoiceId,
                Number      = invoiceNumber,
                InvoiceDate = invoiceSetup.InvoiceDate,
                PayByDate   = invoiceSetup.PayByDate,
                CommunityId = invoiceSetup.CommunityId,
                UnitId      = unit.Id,
                Amount      = amount,
                TaxAmount   = taxAmount,
                TotalAmount = amount + taxAmount
            };

            _faciTechDbContext.Invoice.Add(invoice);
            _faciTechDbContext.InvoiceItem.AddRange(invoiceItemList);
            _faciTechDbContext.SaveChanges();
        }
        private List <ErrorInfo> ValidateUpdate(InvoiceSetup invoiceSetup)
        {
            List <ErrorInfo> errorInfos = new List <ErrorInfo>();

            return(errorInfos);
        }