public InvoiceInfotViewModel GetLimitStartAndEndInvoiceD(string invoiceMainC, string invoiceSubC, int invoiceMonth, int invoiceYear) { DateTime?startDate = null; DateTime?endDate = null; var settlement = new CustomerSettlement_M(); var result = new InvoiceInfotViewModel(); var customerSettlement = _customerSettlementRepository.Query(cus => cus.CustomerMainC == invoiceMainC && cus.CustomerSubC == invoiceSubC && cus.ApplyD.Year <= invoiceYear) .OrderBy("ApplyD desc"); if (customerSettlement.Any()) { var customerSettlementList = customerSettlement.ToList(); if (customerSettlementList[0].ApplyD.Year < invoiceYear) { settlement = customerSettlementList[0]; } else { for (var iloop = 0; iloop < customerSettlementList.Count; iloop++) { if (customerSettlementList[iloop].ApplyD.Month <= invoiceMonth) { settlement = customerSettlementList[iloop]; break; } settlement = null; } } // check settlement if (settlement != null) { // set start date if (settlement.ApplyD.Month == invoiceMonth && settlement.ApplyD.Year == invoiceYear) { startDate = settlement.ApplyD; } else { if (settlement.SettlementD == 31) { startDate = new DateTime(invoiceYear, invoiceMonth, 1); } else { startDate = new DateTime(invoiceYear, invoiceMonth, 1); //startDate = new DateTime(invoiceYear, invoiceMonth, settlement.SettlementD + 1); } } // set end date if (settlement.SettlementD == 31) { endDate = new DateTime(invoiceYear, invoiceMonth, DateTime.DaysInMonth(invoiceYear, invoiceMonth)); } else { if (invoiceMonth == 12) { endDate = new DateTime(invoiceYear + 1, 1, settlement.SettlementD); } else { endDate = new DateTime(invoiceYear, invoiceMonth, DateTime.DaysInMonth(invoiceYear, invoiceMonth)); //endDate = new DateTime(invoiceYear, invoiceMonth + 1, settlement.SettlementD); } } } } if (startDate == null) { startDate = new DateTime(invoiceYear, invoiceMonth, 1); endDate = new DateTime(invoiceYear, invoiceMonth, DateTime.DaysInMonth(invoiceYear, invoiceMonth)); } result.CustomerMainC = invoiceMainC; result.CustomerSubC = invoiceSubC; result.StartDate = (DateTime)startDate; result.EndDate = (DateTime)endDate; result.SettlementD = 31; result.TaxMethodI = "0"; result.TaxRate = 0; result.TaxRoundingI = "0"; result.RevenueRoundingI = "0"; if (settlement != null) { result.ApplyD = settlement.ApplyD; result.SettlementD = settlement.SettlementD; result.TaxMethodI = settlement.TaxMethodI; result.TaxRate = (settlement.TaxRate != null ? (decimal)settlement.TaxRate : 0); result.TaxRoundingI = settlement.TaxRoundingI; result.RevenueRoundingI = settlement.RevenueRoundingI; } return(result); }
public InvoiceInfotViewModel GetLimitStartAndEndInvoiceDSelf(int invoiceMonth, int invoiceYear) { DateTime?startDate = null; DateTime?endDate = null; var result = new InvoiceInfotViewModel(); var basic = _basicRepository.GetAllQueryable().FirstOrDefault(); if (basic != null) { // set startDate if (basic.SettlementDay == 31) { startDate = new DateTime(invoiceYear, invoiceMonth, 1); } else { startDate = new DateTime(invoiceYear, invoiceMonth, basic.SettlementDay + 1); } // set end date if (basic.SettlementDay == 31) { endDate = new DateTime(invoiceYear, invoiceMonth, DateTime.DaysInMonth(invoiceYear, invoiceMonth)); } else { if (invoiceMonth == 12) { endDate = new DateTime(invoiceYear + 1, 1, basic.SettlementDay); } else { endDate = new DateTime(invoiceYear, invoiceMonth + 1, basic.SettlementDay); } } } if (startDate == null) { startDate = new DateTime(invoiceYear, invoiceMonth, 1); endDate = new DateTime(invoiceYear, invoiceMonth, DateTime.DaysInMonth(invoiceYear, invoiceMonth)); } result.StartDate = (DateTime)startDate; result.EndDate = (DateTime)endDate; result.SettlementD = 31; result.TaxMethodI = "0"; result.TaxRate = 0; result.TaxRoundingI = "0"; result.RevenueRoundingI = "0"; if (basic != null) { result.SettlementD = basic.SettlementDay; result.TaxMethodI = basic.TaxMethodI; result.TaxRate = (decimal)basic.TaxRate; result.TaxRoundingI = basic.TaxRoundingI; } return(result); }