public async Task EditAsync(QuotationEditModel 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);
            //}

            var invoice = await _quotationRepository.GetAsync(model.Id);

            //InvoiceFactory.Create(model, invoice, _userId, items);
            QuotationFactory.EditInvoice(model, invoice, _userId);

            _quotationRepository.Edit(invoice);

            await _unitOfWork.SaveChangesAsync();
        }
Exemple #2
0
        public async Task <IActionResult> Edit([FromBody] QuotationEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorList()));
            }

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

            try
            {
                await _quotationManager.EditAsync(model);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            return(Ok());
        }
Exemple #3
0
        public static void EditInvoice(QuotationEditModel model, Quotation entity, string userId)
        {
            entity.CustomerId         = model.CustomerId;
            entity.Tax                = model.Tax;
            entity.Discount           = model.Discount;
            entity.TotalAmount        = model.TotalAmount;
            entity.Remark             = model.Remark;
            entity.UpdatedBy          = userId ?? "0";
            entity.UpdatedOn          = Utility.GetDateTime();
            entity.QuotationDate      = model.QuotationDate;
            entity.StrQuotationDate   = model.QuotationDate.ToString("yyyy-MM-dd");
            entity.ExpireDate         = model.ExpiryDate;
            entity.StrExpireDate      = model.ExpiryDate.ToString("yyyy-MM-dd");
            entity.PoSoNumber         = model.PoSoNumber;
            entity.Memo               = model.Memo;
            entity.SubTotal           = model.SubTotal;
            entity.LineAmountSubTotal = model.LineAmountSubTotal;

            //int[] arr = new int[100];
            ArrayList tempArr = new ArrayList();

            //for (int i=0;i<model.Items.Count; i++)
            //{
            //    arr[i] = model.Items[i].ServiceId;
            //}

            foreach (var item in model.Items)
            {
                tempArr.Add(item.ServiceId);
                var alreadyExistServices = entity.Services.Where(x => item.ServiceId == x.ServiceId).FirstOrDefault();
                //entity.Services.Where(x => item.ServiceId == x.ServiceId).Select(c => { c.CreditLimit = 1000; return c; });
                if (alreadyExistServices != null)
                {
                    alreadyExistServices.Price         = item.Price;
                    alreadyExistServices.TaxId         = item.TaxId;
                    alreadyExistServices.TaxPercentage = item.TaxPercentage;
                    alreadyExistServices.Rate          = item.Rate;
                    alreadyExistServices.Quantity      = item.Quantity;
                    alreadyExistServices.TaxPrice      = item.TaxPrice;
                    alreadyExistServices.LineAmount    = item.LineAmount;
                    entity.Services.Add(alreadyExistServices);
                }
            }

            var deletedServices = entity.Services.Where(x => !tempArr.Contains(x.ServiceId)).ToList();

            //var resultAll = items.Where(i => filter.All(x => i.Features.Any(f => x == f.Id)));

            foreach (var deletedService in deletedServices)
            {
                entity.Services.Remove(deletedService);
            }

            var addedServices = model.Items
                                .Where(x => !entity.Services.Select(y => y.ServiceId).Contains(x.ServiceId))
                                .ToList();

            foreach (var service in addedServices)
            {
                entity.Services.Add(new QuotationService
                {
                    Id            = Guid.NewGuid(),
                    ServiceId     = service.ServiceId,
                    Rate          = service.Rate,
                    TaxId         = service.TaxId,
                    Price         = service.Price,
                    TaxPrice      = service.TaxPrice,
                    Quantity      = service.Quantity,
                    TaxPercentage = service.TaxPercentage,
                    LineAmount    = service.LineAmount
                });
            }

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

            var deletedAttachemntFiles = entity.Attachments.Select(x => x.FileName)
                                         .Except(model.Attachments.Select(y => y.FileName)).ToList();

            foreach (var deletedAttachemntFile in deletedAttachemntFiles)
            {
                var attachemnt = entity.Attachments.Single(x => x.FileName.Equals(deletedAttachemntFile));
                entity.Attachments.Remove(attachemnt);
            }

            foreach (var attachment in model.Attachments)
            {
                var invoiceAttachment = entity.Attachments.SingleOrDefault(x => x.FileName.Equals(attachment.FileName));

                if (invoiceAttachment == null)
                {
                    invoiceAttachment = new QuotationAttachment
                    {
                        Title            = attachment.Title,
                        FileName         = attachment.FileName,
                        OriginalFileName = attachment.OriginalFileName,
                        CreatedBy        = userId ?? "0",
                        CreatedOn        = Utility.GetDateTime()
                    };
                }
                else
                {
                    invoiceAttachment.Title            = attachment.Title;
                    invoiceAttachment.FileName         = attachment.FileName;
                    invoiceAttachment.OriginalFileName = attachment.OriginalFileName;
                }

                entity.Attachments.Add(invoiceAttachment);
            }
        }