public FBAInvoiceInfo GetAllFBACustomerChargingReportFromDate(DateTime startDate, DateTime closeDate) { var info = new FBAInvoiceInfo { CustomerCode = "ALL FBA CUSTOMER", FromDate = startDate, ToDate = closeDate }; var invoiceReportList = new List <InvoiceReportDetail>(); closeDate = closeDate.AddDays(1); var invoiceDetails = _context.InvoiceDetails .Include(x => x.FBAMasterOrder.Customer) .Include(x => x.FBAMasterOrder.FBAOrderDetails) .Include(x => x.FBAMasterOrder.FBAPallets) .Include(x => x.FBAShipOrder.FBAPickDetails) .Where(x => x.FBAMasterOrder.Customer.DepartmentCode == "FBA" || x.FBAShipOrder.Id > 0) .Where(x => x.FBAShipOrder == null ? x.FBAMasterOrder.CloseDate < closeDate && x.FBAMasterOrder.CloseDate >= startDate : x.FBAShipOrder.CloseDate >= startDate && x.FBAShipOrder.CloseDate < closeDate) .ToList(); foreach (var i in invoiceDetails) { var newInvoiceDetail = new InvoiceReportDetail { Cost = i.Cost, InvoiceType = i.InvoiceType, Activity = i.Activity, ChargingType = i.ChargingType, Unit = i.Unit, Quantity = i.Quantity, Rate = i.Rate, Amount = i.Amount, DateOfCost = i.DateOfCost, Memo = i.Memo }; if (i.FBAMasterOrder == null) { newInvoiceDetail.CustomerCode = i.FBAShipOrder.CustomerCode; newInvoiceDetail.GrandNumber = "N/A"; newInvoiceDetail.Reference = i.FBAShipOrder.ShipOrderNumber; newInvoiceDetail.Destination = i.FBAShipOrder.Destination; newInvoiceDetail.ActualCtnsInThisOrder = i.FBAShipOrder.FBAPickDetails.Sum(x => x.ActualQuantity); newInvoiceDetail.ActualPltsInThisOrder = i.FBAShipOrder.FBAPickDetails.Sum(x => x.ActualPlts); newInvoiceDetail.DateOfClose = i.FBAShipOrder.CloseDate; } else if (i.FBAShipOrder == null) { newInvoiceDetail.CustomerCode = i.FBAMasterOrder.Customer.CustomerCode; newInvoiceDetail.GrandNumber = i.FBAMasterOrder.GrandNumber; newInvoiceDetail.Reference = i.FBAMasterOrder.Container; newInvoiceDetail.Destination = " "; newInvoiceDetail.ActualCtnsInThisOrder = i.FBAMasterOrder.FBAOrderDetails.Sum(x => x.ActualQuantity); newInvoiceDetail.ActualPltsInThisOrder = i.FBAMasterOrder.FBAPallets.Sum(x => x.ActualPallets); newInvoiceDetail.DateOfClose = i.FBAMasterOrder.CloseDate; } invoiceReportList.Add(newInvoiceDetail); } info.InvoiceReportDetails = invoiceReportList; return(info); }
public FBAInvoiceInfo GetChargingReportFormDateRangeAndCustomerId(int customerId, DateTime startDate, DateTime closeDate) { var customer = _context.UpperVendors.Find(customerId); var invoiceReportList = new List <InvoiceReportDetail>(); var info = new FBAInvoiceInfo { FromDate = startDate, ToDate = closeDate, CustomerCode = customer.CustomerCode }; closeDate = closeDate.AddDays(1); var invoiceDetails = _context.InvoiceDetails .Include(x => x.FBAMasterOrder.Customer) .Include(x => x.FBAMasterOrder.FBAOrderDetails) .Include(x => x.FBAMasterOrder.FBAPallets) .Include(x => x.FBAShipOrder.FBAPickDetails) .Where(x => x.FBAMasterOrder.Customer.Id == customerId || x.FBAShipOrder.CustomerCode == customer.CustomerCode) .Where(x => x.FBAShipOrder == null ? x.FBAMasterOrder.CloseDate < closeDate && x.FBAMasterOrder.CloseDate >= startDate : x.FBAShipOrder.CloseDate >= startDate && x.FBAShipOrder.CloseDate < closeDate) //.Where(x => x.DateOfCost >= startDate && x.DateOfCost <= closeDate) .ToList(); foreach (var i in invoiceDetails) { var newInvoiceDetail = new InvoiceReportDetail { Cost = i.Cost, InvoiceType = i.InvoiceType, Activity = i.Activity, ChargingType = i.ChargingType, Unit = i.Unit, Quantity = i.Quantity, Rate = i.Rate, Amount = i.Amount, DateOfCost = i.DateOfCost, Memo = i.Memo }; if (i.FBAMasterOrder == null) { newInvoiceDetail.GrandNumber = "N/A"; newInvoiceDetail.Reference = i.FBAShipOrder.ShipOrderNumber; newInvoiceDetail.Destination = i.FBAShipOrder.Destination; newInvoiceDetail.ActualCtnsInThisOrder = i.FBAShipOrder.FBAPickDetails.Sum(x => x.ActualQuantity); newInvoiceDetail.ActualPltsInThisOrder = i.FBAShipOrder.FBAPickDetails.Sum(x => x.ActualPlts); newInvoiceDetail.DateOfClose = i.FBAShipOrder.CloseDate; } else if (i.FBAShipOrder == null) { newInvoiceDetail.GrandNumber = i.FBAMasterOrder.GrandNumber; newInvoiceDetail.Reference = i.FBAMasterOrder.Container; newInvoiceDetail.Destination = " "; newInvoiceDetail.ActualCtnsInThisOrder = i.FBAMasterOrder.FBAOrderDetails.Sum(x => x.ActualQuantity); newInvoiceDetail.ActualPltsInThisOrder = i.FBAMasterOrder.FBAPallets.Sum(x => x.ActualPallets); newInvoiceDetail.DateOfClose = i.FBAMasterOrder.CloseDate; } invoiceReportList.Add(newInvoiceDetail); } info.InvoiceReportDetails = invoiceReportList; return(info); }