public InvoiceReportViewModel GetInvoice(Guid exitId) { Exit exit = UnitOfWork.ExitRepository.GetById(exitId); if (exit != null) { string paymentAmount = "0"; if (exit.PaymentAmount != null) { paymentAmount = exit.PaymentAmount.Value.ToString("N0"); } string remainAmount = "0"; if (exit.RemainAmount != null) { remainAmount = exit.RemainAmount.Value.ToString("N0"); } InvoiceReportViewModel invoice = new InvoiceReportViewModel() { Date = DateTime.Now.ToShortDateString(), SellerName = "انبار داریوش", SellerEcoNumber = "", SellerNationamNumber = "1189084910", SellerAddress = "تهران، ابتدای جاده قدیم قم، بعد از سه راهی ترانسفو", SellerPhone = "02155208921-6", CustomerName = exit.Customer.FullName, CustomerCarNumber = exit.CarNumber, Products = GetProductList(exit), SubTotal = exit.SubTotalAmount.Value.ToString("N0"), Total = exit.TotalAmount.Value.ToString("N0"), Vat = exit.Vat.Value.ToString("N0"), PaymentAmount = paymentAmount, RemainAmount = remainAmount, }; return(invoice); } return(new InvoiceReportViewModel()); }
//GET: Shipments/GenerateInvoiceRecord public ActionResult GenerateInvoiceRecord(int?CurrentShippingAccountId, DateTime?StartShippedDate, DateTime?EndShippedDate, string sortOrder) { // Instantiate an instance of the ShipmentsReportViewModel and the ShipmentsSearchViewModel. var InvoiceSearch = new InvoiceReportViewModel(); InvoiceSearch.Invoice = new InvoiceSearchViewModel(); ViewBag.CurrentSort = sortOrder; int?shippingAccountId; if (User.IsInRole("Customer")) { /* * if (ShippingAccountId == null) * { * ShippingAccountId = CurrentShippingAccountId; * } * else * { * page = 1; * } */ shippingAccountId = GetUserId(); ViewBag.CurrentShippingAccountId = shippingAccountId; InvoiceSearch.Invoice.ShippingAccountId = shippingAccountId.GetValueOrDefault(); InvoiceSearch.Invoice.AccountType = db.ShippingAccounts.Find(shippingAccountId).AccountType; ViewBag.DisplayedShippingAccountId = ShowShippingAccountId(shippingAccountId.GetValueOrDefault()); } else { InvoiceSearch.Invoice.AccountType = "Employee"; shippingAccountId = null; } if (StartShippedDate == null && EndShippedDate == null) { StartShippedDate = DateTime.MinValue; EndShippedDate = DateTime.MaxValue; } ViewBag.CurrentStartShippedDate = StartShippedDate; ViewBag.CurrentEndShippedDate = EndShippedDate; // Initialize the query to retrieve shipments using the ShipmentsListViewModel. var InvoiceQuery = from s in db.Shipments select new InvoiceListViewModel { WaybillId = s.WaybillId, ServiceType = s.ServiceType, ShippedDate = s.ShippedDate, RecipientName = s.RecipientName, NumberOfInvoice = s.ShipmentCost + s.DutiesCost + s.TaxesCost, Origin = s.Origin, Destination = s.Destination, ShippingAccountId = s.ShippingAccountId, Status = s.Status }; ViewBag.ServiceTypeSortParm = sortOrder == "ServiceType" ? "ServiceType_desc" : "ServiceType"; ViewBag.ShippedDateSortParm = sortOrder == "ShippedDate" ? "ShippedDate_desc" : "ShippedDate"; ViewBag.NumberOfInvoiceSortParm = sortOrder == "NumberOfInvoice" ? "NumberOfInvoice_desc" : "NumberOfInvoiceDate"; ViewBag.RecipientNameSortParm = sortOrder == "RecipientName" ? "RecipientName_desc" : "RecipientName"; ViewBag.OriginSortParm = sortOrder == "Origin" ? "Origin_desc" : "Origin"; ViewBag.DestinationSortParm = sortOrder == "Destination" ? "Destination_desc" : "Destination"; switch (sortOrder) { case "ServiceType": InvoiceQuery = InvoiceQuery.OrderBy(s => s.ServiceType); break; case "ServiceType_desc": InvoiceQuery = InvoiceQuery.OrderByDescending(s => s.ServiceType); break; case "ShippedDate": InvoiceQuery = InvoiceQuery.OrderBy(s => s.ShippedDate); break; case "ShippedDate_desc": InvoiceQuery = InvoiceQuery.OrderByDescending(s => s.ShippedDate); break; case "NumberOfInoviceDate": InvoiceQuery = InvoiceQuery.OrderBy(s => s.NumberOfInvoice); break; case "NumberOfInvoice_desc": InvoiceQuery = InvoiceQuery.OrderByDescending(s => s.NumberOfInvoice); break; case "RecipientName": InvoiceQuery = InvoiceQuery.OrderBy(s => s.RecipientName); break; case "RecipientName_desc": InvoiceQuery = InvoiceQuery.OrderByDescending(s => s.RecipientName); break; case "Origin": InvoiceQuery = InvoiceQuery.OrderBy(s => s.Origin); break; case "Origin_desc": InvoiceQuery = InvoiceQuery.OrderByDescending(s => s.Origin); break; case "Destination": InvoiceQuery = InvoiceQuery.OrderBy(s => s.Destination); break; case "Destination_desc": InvoiceQuery = InvoiceQuery.OrderByDescending(s => s.Destination); break; default: InvoiceQuery = InvoiceQuery.OrderBy(s => s.WaybillId); break; } // Add the condition to select a spefic shipping account if shipping account id is not null. if (shippingAccountId != null) { // TODO: Construct the LINQ query to retrive only the shipments for the specified shipping account id. InvoiceQuery = InvoiceQuery.Where(s => s.ShippingAccountId == shippingAccountId); InvoiceQuery = InvoiceQuery.Where(s => (s.ShippedDate >= StartShippedDate && s.ShippedDate <= EndShippedDate)); } /* else * { * // Return an empty result if no shipping account id has been selected. * shipmentSearch.Shipments = new ShipmentsListViewModel[0]; * } */ InvoiceSearch.Invoices = InvoiceQuery.ToList(); return(View(InvoiceSearch)); }