Beispiel #1
0
        public ActionResult Allocate(int id)
        {
            var receipt     = _salesService.GetSalesReceiptById(id);
            var customer    = _salesService.GetCustomerById(receipt.CustomerId);
            var allocations = _salesService.GetCustomerReceiptsForAllocation(customer.Id);
            var model       = new Models.ViewModels.Sales.Allocate();

            model.ReceiptId = id;
            model.TotalAmountAvailableToAllocate = allocations.Sum(a => a.AvailableAmountToAllocate);
            model.LeftToAllocateFromReceipt      = receipt.AvailableAmountToAllocate;
            var openInvoices = _salesService.GetSalesInvoices().Where(inv => inv.IsFullPaid() == false);

            foreach (var invoice in openInvoices)
            {
                model.OpenInvoices.Add(new SelectListItem()
                {
                    Value = invoice.Id.ToString(),
                    Text  = invoice.No + " - " + (invoice.ComputeTotalAmount() - invoice.SalesInvoiceLines.Sum(a => a.GetAmountPaid()))
                });
            }
            return(PartialView(model));
        }
Beispiel #2
0
        public ActionResult SaveAllocation(Models.ViewModels.Sales.Allocate model)
        {
            var receipt     = _salesService.GetSalesReceiptById(model.ReceiptId);
            var customer    = _salesService.GetCustomerById(receipt.CustomerId);
            var invoice     = _salesService.GetSalesInvoiceById(model.InvoiceId);
            var allocations = _salesService.GetCustomerReceiptsForAllocation(customer.Id);

            model.InvoiceId = model.InvoiceId;
            model.TotalAmountAvailableToAllocate = allocations.Sum(a => a.AvailableAmountToAllocate);
            model.LeftToAllocateFromReceipt      = receipt.AvailableAmountToAllocate;
            if (invoice == null)
            {
                return(View(model));
            }
            else
            {
                var invoiceTotalAmount = invoice.ComputeTotalAmount();
                if (model.AmountToAllocate > invoiceTotalAmount ||
                    model.AmountToAllocate > receipt.AvailableAmountToAllocate ||
                    invoice.Status == Core.Domain.SalesInvoiceStatus.Closed)
                {
                    return(View(model));
                }

                var allocation = new CustomerAllocation()
                {
                    CustomerId           = customer.Id,
                    SalesReceiptHeaderId = receipt.Id,
                    SalesInvoiceHeaderId = invoice.Id,
                    Amount = model.AmountToAllocate,
                    Date   = DateTime.Now
                };
                _salesService.SaveCustomerAllocation(allocation);
            }
            return(RedirectToAction("CustomerDetail", new { id = customer.Id }));
        }
 public ActionResult Allocate(int id)
 {
     var receipt = _salesService.GetSalesReceiptById(id);
     var customer = _salesService.GetCustomerById(receipt.CustomerId);
     var allocations = _salesService.GetCustomerReceiptsForAllocation(customer.Id);
     var model = new Models.ViewModels.Sales.Allocate();
     model.ReceiptId = id;
     model.TotalAmountAvailableToAllocate = allocations.Sum(a => a.AvailableAmountToAllocate);
     model.LeftToAllocateFromReceipt = receipt.AvailableAmountToAllocate;
     var openInvoices = _salesService.GetSalesInvoices().Where(inv => inv.IsFullPaid() == false);
     foreach(var invoice in openInvoices)
     {
         model.OpenInvoices.Add(new SelectListItem()
         {
             Value = invoice.Id.ToString(),
             Text = invoice.No + " - " + (invoice.ComputeTotalAmount() - invoice.SalesInvoiceLines.Sum(a => a.GetAmountPaid()))
         });
     }
     return PartialView(model);
 }