Beispiel #1
0
        public double CalculateBuildingPermit(lead lead)
        {
            double buildingPermitCost = 0.00;

            if (lead.in_city && lead.delivery_status.delivery_status_name.Equals(Constants.deliver_Status_Installed))
            {
                if (lead.installations != null)
                {
                    foreach (var item in lead.installations)
                    {
                        if (item.installation_labor_only_cost != null)
                        {
                            buildingPermitCost += (double)item.installation_labor_only_cost;
                        }

                        if (item.total_construction_materials_cost != null)
                        {
                            buildingPermitCost += (double)item.total_construction_materials_cost;
                        }
                    }
                }

                buildingPermitCost += new TotalCostHelper().CalculateProductCost(lead);
                return(Math.Round(helper.GetBuildingPermitAmount(buildingPermitCost), 2));
            }

            return(buildingPermitCost);
        }
Beispiel #2
0
        public void SaveProjectTotal(int leadNbr)
        {
            var lead = db.leads.Where(l => l.lead_number == leadNbr).First();

            if ((lead.products != null && lead.products.Count != 0) || (lead.installations != null && lead.installations.Count != 0))
            {
                // set calculated installation data
                lead = this.SetAllInstallationCosts(lead);

                //set totalcost data
                TotalCostHelper cHelper = new TotalCostHelper();
                InstallationCalculationHelper installHelper = new InstallationCalculationHelper();
                double buildingPermit   = 0;
                double installationCost = 0;
                double materialCost     = 0;
                foreach (var item in lead.installations)
                {
                    buildingPermit   = (double)item.building_permit_cost;
                    installationCost = (double)item.total_installation_labor_cost;
                    materialCost     = (double)item.total_construction_materials_cost;
                }

                if (lead.total_cost.Count == 0)
                {
                    total_cost total = new total_cost
                    {
                        lead_number          = (int)lead.lead_number,
                        product_cost         = cHelper.CalculateProductCost(lead),
                        building_permit_cost = buildingPermit,
                        tax_cost             = cHelper.CalculateApplicableTax(lead)
                    };

                    // this is when there is no installation data
                    if (installationCost == 0)
                    {
                        buildingPermit   = installHelper.CalculateBuildingPermit(lead);
                        installationCost = cHelper.CalculateInstallationCost(lead);
                    }

                    total.total_cost1 = total.product_cost + materialCost + total.installation_cost + total.tax_cost;
                    List <total_cost> costList = new List <total_cost>
                    {
                        total
                    };

                    lead.total_cost = costList;
                }
                else
                {
                    foreach (var item2 in lead.total_cost)
                    {
                        item2.product_cost         = cHelper.CalculateProductCost(lead);
                        item2.installation_cost    = cHelper.CalculateInstallationCost(lead);
                        item2.building_permit_cost = installHelper.CalculateBuildingPermit(lead);
                        item2.tax_cost             = cHelper.CalculateApplicableTax(lead);
                        item2.total_cost1          = item2.product_cost + materialCost + item2.installation_cost + item2.tax_cost;
                    }
                }

                db.SaveChanges();
            }
        }