Ejemplo n.º 1
0
        public async Task AddAsync(QuotationAddModel 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 _quotationRepository.getCount();

            //await _invoiceRepository.AddAsync(InvoiceFactory.Create(model, _userId, items));
            await _quotationRepository.AddAsync(QuotationFactory.Create(model, _userId, count));

            await _unitOfWork.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public static Quotation Create(QuotationAddModel model, string userId, int count)
        {
            var quotation = new Quotation
            {
                CustomerId         = model.CustomerId,
                QuotationNumber    = "QUO" + "-" + model.QuotationDate.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(),
                QuotationDate      = model.QuotationDate,
                StrQuotationDate   = model.QuotationDate.ToString("yyyy-MM-dd"),
                ExpireDate         = model.ExpiryDate,
                StrExpireDate      = model.ExpiryDate.ToString("yyyy-MM-dd"),
                PoSoNumber         = model.PoSoNumber,
                Memo               = model.Memo,
                SubTotal           = model.SubTotal,
                LineAmountSubTotal = model.LineAmountSubTotal,
                Services           = model.Items.Select(x => new QuotationService
                {
                    Id            = Guid.NewGuid(),
                    ServiceId     = x.ServiceId,
                    Rate          = x.Rate,
                    Quantity      = x.Quantity,
                    Price         = x.Price,
                    TaxId         = x.TaxId,
                    TaxPrice      = x.TaxPrice,
                    TaxPercentage = x.TaxPercentage,
                    LineAmount    = x.LineAmount
                }).ToList()
            };


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

            quotation.Attachments = model.Attachments.Select(x => new QuotationAttachment
            {
                Title            = x.Title,
                FileName         = x.FileName,
                OriginalFileName = x.OriginalFileName,
                CreatedBy        = userId ?? "0",
                CreatedOn        = Utility.GetDateTime()
            }).ToList();

            return(quotation);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Add([FromBody] QuotationAddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorList()));
            }

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

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