コード例 #1
0
        public async Task AddAsync(RecInvoiceAddModel model)
        {
            // var items = (await _itemRepository.GetAsync(model.Items)).ToList();

            //model.TotalAmount = items.Sum(x => x.Rate);

            //model.Tax = items.Where(x => x.IsTaxable).Sum(x => x.Rate * x.SalesTax.TaxPercentage / 100);

            //var customer = await _customerRepository.GetAsync(model.CustomerId);

            //if (customer.Discount != null)
            //{
            //    model.Discount = model.TotalAmount * customer.Discount / 100;
            //    model.TotalAmount = model.TotalAmount - (model.Discount ?? 0);
            //}

            //if (model.Tax != null)
            //{
            //    model.TotalAmount = model.TotalAmount + (model.Tax ?? 0);
            //}
            model.LineAmountSubTotal = model.Items.Sum(x => x.LineAmount);
            var count = await _recInvoiceRepository.getCount();

            //await _invoiceRepository.AddAsync(InvoiceFactory.Create(model, _userId, items));
            await _recInvoiceRepository.AddAsync(RecurringInvoiceFactory.Create(model, _userId, count));

            await _unitOfWork.SaveChangesAsync();
        }
コード例 #2
0
        public static RecurringInvoice Create(RecInvoiceAddModel model, string userId, int count)
        {
            var recInvoice = new RecurringInvoice
            {
                CustomerId       = model.CustomerId,
                RecInvoiceNumber = "REC-INV" + "-" + model.RecInvoiceDate.ToString("yy") + "-" + (count + 1).ToString("000"),
                Tax                = model.Tax,
                Discount           = model.Discount,
                TotalAmount        = model.TotalAmount,
                Remark             = model.Remark,
                Status             = Constants.InvoiceStatus.Pending,
                CreatedBy          = userId ?? "0",
                CreatedOn          = Utility.GetDateTime(),
                RecInvoiceDate     = model.RecInvoiceDate,
                StrRecInvoiceDate  = model.RecInvoiceDate.ToString("yyyy-MM-dd"),
                RecDueDate         = model.RecDueDate,
                StrRecDueDate      = model.RecDueDate.ToString("yyyy-MM-dd"),
                PoSoNumber         = model.PoSoNumber,
                SubTotal           = model.SubTotal,
                LineAmountSubTotal = model.LineAmountSubTotal,
                Services           = model.Items.Select(x => new RecurringInvoiceService
                {
                    Id            = Guid.NewGuid(),
                    ServiceId     = x.ServiceId,
                    Rate          = x.Rate,
                    Quantity      = x.Quantity,
                    Price         = x.Price,
                    TaxId         = x.TaxId,
                    TaxPercentage = x.TaxPercentage,
                    LineAmount    = x.LineAmount,
                    TaxPrice      = x.TaxPrice
                }).ToList()
            };


            if (model.Attachments == null || !model.Attachments.Any())
            {
                return(recInvoice);
            }

            foreach (var attachment in model.Attachments)
            {
                recInvoice.Attachments = new List <RecurringInvoiceAttachment>
                {
                    new RecurringInvoiceAttachment
                    {
                        Title            = attachment.Title,
                        FileName         = attachment.FileName,
                        OriginalFileName = attachment.OriginalFileName,
                        CreatedBy        = userId ?? "0",
                        CreatedOn        = Utility.GetDateTime()
                    }
                };
            }

            return(recInvoice);
        }
コード例 #3
0
        public async Task <IActionResult> Add([FromBody] RecInvoiceAddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorList()));
            }

            if (!EnumerableExtensions.Any(model.Items))
            {
                return(BadRequest("Please select items/services to continue"));
            }

            try
            {
                await _recInvoiceManager.AddAsync(model);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            return(Ok());
        }