Ejemplo n.º 1
0
        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
            });
        }
Ejemplo n.º 2
0
        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 string ValidateCostCenter(int DocTypeId, int HeaderId, int JobWorkerId, string CostCenterName)
        {
            int SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
            int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];

            var Settings        = new SaleQuotationSettingsService(_unitOfWork).GetSaleQuotationSettingsForDocument(DocTypeId, DivisionId, SiteId);
            var LedgerAccountId = new LedgerAccountService(_unitOfWork).GetLedgerAccountByPersondId(JobWorkerId).LedgerAccountId;

            string ValidationMsg = "";

            if (Settings.IsPersonWiseCostCenter == true)
            {
                var CostCenter = (db.CostCenter.AsNoTracking().Where(m => m.CostCenterName == CostCenterName &&
                                                                     m.ReferenceDocTypeId == DocTypeId && m.SiteId == SiteId && m.DivisionId == DivisionId).FirstOrDefault());
                if (CostCenter != null)
                {
                    if (CostCenter.LedgerAccountId != LedgerAccountId)
                    {
                        ValidationMsg += "CostCenter belongs to a different person. ";
                    }
                }
            }

            if (Settings.isUniqueCostCenter == true)
            {
                var CostCenter = db.CostCenter.AsNoTracking().Where(m => m.CostCenterName == CostCenterName &&
                                                                    m.ReferenceDocTypeId == DocTypeId && m.SiteId == SiteId && m.DivisionId == DivisionId).FirstOrDefault();
                if (CostCenter != null)
                {
                    var UniqueCostCenter = (from p in db.SaleQuotationHeader
                                            where p.CostCenterId == CostCenter.CostCenterId && p.SaleQuotationHeaderId != HeaderId && p.DocTypeId == DocTypeId &&
                                            p.SiteId == SiteId && p.DivisionId == DivisionId
                                            select p
                                            ).FirstOrDefault();
                    if (UniqueCostCenter != null)
                    {
                        ValidationMsg += "CostCenter Already exists";
                    }
                }
            }

            return(ValidationMsg);
        }