public IEnumerable <CalculationProductViewModel> GetChargeRates(int CalculationID, int DocumentTypeId, int SiteId, int DivisionId, int ProcessId, int?ChargeGroupPersonId, int?ChargeGroupProductId, int?ProductId = null) { var ChargeGroupSettings = from C in db.ChargeGroupSettings where C.ChargeGroupPersonId == ChargeGroupPersonId && C.ChargeGroupProductId == ChargeGroupProductId && C.ProcessId == ProcessId select C; var PurchaseProcess = new ProcessService(_unitOfWork).Find(ProcessConstants.Purchase); if (ChargeGroupSettings.ToList().Count() == 0 && PurchaseProcess != null) { ChargeGroupSettings = from C in db.ChargeGroupSettings where C.ChargeGroupPersonId == ChargeGroupPersonId && C.ChargeGroupProductId == ChargeGroupProductId && C.ProcessId == PurchaseProcess.ProcessId select C; } int ChargeLedgerAccountId = new LedgerAccountService(_unitOfWork).Find(LedgerAccountConstants.Charge).LedgerAccountId; int?ProductLedgerAccountId = null; int?ChargeTypeId_SalesTaxTaxableAmount = null; if (ProductId != null) { var ProductLedgerAccount = (from L in db.LedgerAccount where L.ProductId == ProductId select L).FirstOrDefault(); if (ProductLedgerAccount != null) { ProductLedgerAccountId = ProductLedgerAccount.LedgerAccountId; } var ChargeType_SalesTaxTaxableAmount = (from Ct in db.ChargeType where Ct.ChargeTypeName == ChargeTypeConstants.SalesTaxableAmount select Ct).FirstOrDefault(); if (ChargeType_SalesTaxTaxableAmount != null) { ChargeTypeId_SalesTaxTaxableAmount = ChargeType_SalesTaxTaxableAmount.ChargeTypeId; } } return(from p in db.CalculationProduct join t in db.CalculationLineLedgerAccount.Where(m => m.DocTypeId == DocumentTypeId && m.SiteId == SiteId && m.DivisionId == DivisionId) on p.CalculationProductId equals t.CalculationProductId into CalculationLineLedgerAccountTable from CalculationLineLedgerAccountTab in CalculationLineLedgerAccountTable.DefaultIfEmpty() join Cgs in ChargeGroupSettings on p.ChargeTypeId equals Cgs.ChargeTypeId into ChargeGroupSettingsTable from ChargeGroupSettingsTab in ChargeGroupSettingsTable.DefaultIfEmpty() where p.CalculationId == CalculationID orderby p.Sr select new CalculationProductViewModel { ChargeId = p.ChargeId, LedgerAccountCrId = (CalculationLineLedgerAccountTab.LedgerAccountCrId == ChargeLedgerAccountId ? (p.ChargeTypeId == ChargeTypeId_SalesTaxTaxableAmount ? (ProductLedgerAccountId ?? ChargeGroupSettingsTab.ChargeLedgerAccountId) : ChargeGroupSettingsTab.ChargeLedgerAccountId) : CalculationLineLedgerAccountTab.LedgerAccountCrId), LedgerAccountDrId = (CalculationLineLedgerAccountTab.LedgerAccountDrId == ChargeLedgerAccountId ? (p.ChargeTypeId == ChargeTypeId_SalesTaxTaxableAmount ? (ProductLedgerAccountId ?? ChargeGroupSettingsTab.ChargeLedgerAccountId) : ChargeGroupSettingsTab.ChargeLedgerAccountId) : CalculationLineLedgerAccountTab.LedgerAccountDrId), Rate = (Decimal?)ChargeGroupSettingsTab.ChargePer ?? 0, ChargeTypeId = ChargeGroupSettingsTab.ChargeTypeId }); }
public IEnumerable <CalculationProductViewModel> GetCalculationProductList(int CalculationID, int DocumentTypeId, int SiteId, int DivisionId) { return(from Cp in db.CalculationProduct join Clla in db.CalculationLineLedgerAccount.Where(m => m.DocTypeId == DocumentTypeId && m.SiteId == SiteId && m.DivisionId == DivisionId) on Cp.CalculationProductId equals Clla.CalculationProductId into CalculationLineLedgerAccountTable from CalculationLineLedgerAccountTab in CalculationLineLedgerAccountTable.DefaultIfEmpty() where Cp.CalculationId == CalculationID orderby Cp.Sr select new CalculationProductViewModel { AddDeduct = Cp.AddDeduct, AffectCost = Cp.AffectCost, CalculateOnId = Cp.CalculateOnId, CalculateOnName = Cp.CalculateOn.ChargeName, CalculateOnCode = Cp.CalculateOn.ChargeCode, CalculationId = Cp.CalculationId, CalculationName = Cp.Calculation.CalculationName, ChargeId = Cp.ChargeId, ChargeName = Cp.Charge.ChargeName, ChargeCode = Cp.Charge.ChargeCode, ChargeTypeId = Cp.ChargeTypeId, ChargeTypeName = Cp.ChargeType.ChargeTypeName, CostCenterId = Cp.CostCenterId, CostCenterName = Cp.CostCenter.CostCenterName, IncludedInBase = Cp.IncludedInBase, LedgerAccountCrId = CalculationLineLedgerAccountTab.LedgerAccountCrId, LedgerAccountCrName = CalculationLineLedgerAccountTab.LedgerAccountCr.LedgerAccountName, LedgerAccountDrId = CalculationLineLedgerAccountTab.LedgerAccountDrId, LedgerAccountDrName = CalculationLineLedgerAccountTab.LedgerAccountDr.LedgerAccountName, ContraLedgerAccountId = CalculationLineLedgerAccountTab.ContraLedgerAccountId, ContraLedgerAccountName = CalculationLineLedgerAccountTab.ContraLedgerAccount.LedgerAccountName, Rate = Cp.Rate, Sr = Cp.Sr, RateType = Cp.RateType, IsVisible = Cp.IsVisible, Amount = Cp.Amount, ParentChargeId = Cp.ParentChargeId, ElementId = "CALL_" + Cp.Charge.ChargeCode, IncludedCharges = Cp.IncludedCharges, IncludedChargesCalculation = Cp.IncludedChargesCalculation, IsVisibleLedgerAccountCr = CalculationLineLedgerAccountTab.IsVisibleLedgerAccountCr, IsVisibleLedgerAccountDr = CalculationLineLedgerAccountTab.IsVisibleLedgerAccountDr, filterLedgerAccountGroupsCrId = CalculationLineLedgerAccountTab.filterLedgerAccountGroupsCrId, filterLedgerAccountGroupsDrId = CalculationLineLedgerAccountTab.filterLedgerAccountGroupsDrId }); }