public ActionResult Customer(int id = 0) { var model = new Models.ViewModels.Sales.CustomerViewModel(); if (id == 0) { model.Id = id; } else { var customer = _salesService.GetCustomerById(id); var allocations = _salesService.GetCustomerReceiptsForAllocation(id); model.Id = customer.Id; model.Name = customer.Name; model.Balance = customer.Balance; foreach (var receipt in allocations) { model.CustomerAllocations.Add(new Models.ViewModels.Sales.CustomerAllocation() { Id = receipt.Id, AmountAllocated = receipt.SalesReceiptLines.Sum(a => a.AmountPaid), AvailableAmountToAllocate = receipt.AvailableAmountToAllocate }); } foreach (var invoice in customer.SalesInvoices) { model.CustomerInvoices.Add(new Models.ViewModels.Sales.CustomerSalesInvoice() { Id = invoice.Id, InvoiceNo = invoice.No, Date = invoice.Date, Amount = invoice.SalesInvoiceLines.Sum(a => a.Amount), Status = invoice.IsFullPaid() ? "Paid" : "Open" }); } } return(View(model)); }
public ActionResult Customer(int id = 0) { var model = new Models.ViewModels.Sales.CustomerViewModel(); if (id == 0) { model.Id = id; } else { var customer = _salesService.GetCustomerById(id); var allocations = _salesService.GetCustomerReceiptsForAllocation(id); model.Id = customer.Id; model.Name = customer.Name; model.Balance = customer.Balance; foreach (var receipt in allocations) { model.CustomerAllocations.Add(new Models.ViewModels.Sales.CustomerAllocation() { Id = receipt.Id, AmountAllocated = receipt.SalesReceiptLines.Sum(a => a.AmountPaid), AvailableAmountToAllocate = receipt.AvailableAmountToAllocate }); } foreach (var invoice in customer.SalesInvoices) { model.CustomerInvoices.Add(new Models.ViewModels.Sales.CustomerSalesInvoice() { Id = invoice.Id, InvoiceNo = invoice.No, Date = invoice.Date, Amount = invoice.SalesInvoiceLines.Sum(a => a.Amount), Status = invoice.IsFullPaid() ? "Paid" : "Open" }); } } return View(model); }