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> GetCalculationProductListWithChargeGroupSettings(int CalculationID, int DocumentTypeId, int SiteId, int DivisionId, int?ChargeGroupPersonId, int?ChargeGroupProductId) { var ChargeGroupSettings = from C in db.ChargeGroupSettings where C.ChargeGroupPersonId == ChargeGroupPersonId && C.ChargeGroupProductId == ChargeGroupProductId select C; int ChargeLedgerAccountId = new LedgerAccountService(_unitOfWork).Find(LedgerAccountConstants.Charge).LedgerAccountId; 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 table1 join Cgs in ChargeGroupSettings on p.ChargeTypeId equals Cgs.ChargeTypeId into ChargeGroupSettingsTable from ChargeGroupSettingsTab in ChargeGroupSettingsTable.DefaultIfEmpty() from tab1 in table1.DefaultIfEmpty() where p.CalculationId == CalculationID orderby p.Sr select new CalculationProductViewModel { AddDeduct = p.AddDeduct, AffectCost = p.AffectCost, CalculateOnId = p.CalculateOnId, CalculateOnName = p.CalculateOn.ChargeName, CalculateOnCode = p.CalculateOn.ChargeCode, CalculationId = p.CalculationId, CalculationName = p.Calculation.CalculationName, ChargeId = p.ChargeId, ChargeName = p.Charge.ChargeName, ChargeCode = p.Charge.ChargeCode, ChargeTypeId = p.ChargeTypeId, ChargeTypeName = p.ChargeType.ChargeTypeName, CostCenterId = p.CostCenterId, CostCenterName = p.CostCenter.CostCenterName, IncludedInBase = p.IncludedInBase, LedgerAccountCrId = (tab1.LedgerAccountCrId == ChargeLedgerAccountId ? ChargeGroupSettingsTab.ChargeLedgerAccountId : tab1.LedgerAccountCrId), LedgerAccountCrName = tab1.LedgerAccountCr.LedgerAccountName, LedgerAccountDrId = (tab1.LedgerAccountDrId == ChargeLedgerAccountId ? ChargeGroupSettingsTab.ChargeLedgerAccountId : tab1.LedgerAccountDrId), LedgerAccountDrName = tab1.LedgerAccountDr.LedgerAccountName, ContraLedgerAccountId = tab1.ContraLedgerAccountId, ContraLedgerAccountName = tab1.ContraLedgerAccount.LedgerAccountName, Rate = ChargeGroupSettingsTab.ChargePer, Sr = p.Sr, RateType = p.RateType, IsVisible = p.IsVisible, Amount = p.Amount, ParentChargeId = p.ParentChargeId, ElementId = "CALL_" + p.Charge.ChargeCode, IncludedCharges = p.IncludedCharges, IncludedChargesCalculation = p.IncludedChargesCalculation, }); }
public IEnumerable <ChargeRateSettings> GetChargeRateSettingForValidation(int CalculationId, int DocTypeId, int SiteId, int DivisionId, int ProcessId, int ChargeGroupPersonId, int ChargeGroupProductId) { IEnumerable <ChargeRateSettings> ChargeRateSettingsList = (from p in db.CalculationProduct join t in db.CalculationLineLedgerAccount.Where(m => m.DocTypeId == DocTypeId && m.SiteId == SiteId && m.DivisionId == DivisionId) on p.CalculationProductId equals t.CalculationProductId into table1 from tab1 in table1.DefaultIfEmpty() join Cgs in db.ChargeGroupSettings.Where(m => m.ChargeGroupPersonId == ChargeGroupPersonId && m.ChargeGroupProductId == ChargeGroupProductId && m.ProcessId == ProcessId) on p.ChargeTypeId equals Cgs.ChargeTypeId into ChargeGroupSettingsTable from ChargeGroupSettingsTab in ChargeGroupSettingsTable.DefaultIfEmpty() where p.CalculationId == CalculationId && p.ChargeType.Category == ChargeTypeCategoryConstants.SalesTax select new ChargeRateSettings { ChargeId = p.ChargeId, ChargeName = p.Charge.ChargeName, LedgerAccountCrName = p.LedgerAccountCr.LedgerAccountName, LedgerAccountDrName = p.LedgerAccountDr.LedgerAccountName, ChargeGroupSettingId = ChargeGroupSettingsTab.ChargeGroupSettingsId, ChargePer = ChargeGroupSettingsTab.ChargePer, ChargeLedgerAccountId = ChargeGroupSettingsTab.ChargeLedgerAccountId, }).ToList(); return(ChargeRateSettingsList); }