Beispiel #1
0
        private decimal CalculateTotalFromPremiumSummaryRow(IPremiumSummaryTableRow row)
        {
            var anyFailed = false;

            //cleanup
            row.BasePremium = row.BasePremium.Replace("\r\a", string.Empty);
            row.BasePremium = row.BasePremium.Replace("$", string.Empty);

            row.BrokerFeePerPolicyClass = row.BrokerFeePerPolicyClass.Replace("\r\a", string.Empty);
            row.BrokerFeePerPolicyClass = row.BrokerFeePerPolicyClass.Replace("$", string.Empty);

            row.FireServicesLevies = row.FireServicesLevies.Replace("\r\a", string.Empty);
            row.FireServicesLevies = row.FireServicesLevies.Replace("$", string.Empty);

            row.OtherTaxesCharges = row.OtherTaxesCharges.Replace("\r\a", string.Empty);
            row.OtherTaxesCharges = row.OtherTaxesCharges.Replace("$", string.Empty);

            row.OtherTaxesCharges = row.OtherTaxesCharges.Replace("\r\a", string.Empty);
            row.OtherTaxesCharges = row.OtherTaxesCharges.Replace("$", string.Empty);

            row.PolicyUnderwriterGst = row.PolicyUnderwriterGst.Replace("\r\a", string.Empty);
            row.PolicyUnderwriterGst = row.PolicyUnderwriterGst.Replace("$", string.Empty);

            row.StampDuty = row.StampDuty.Replace("\r\a", string.Empty);
            row.StampDuty = row.StampDuty.Replace("$", string.Empty);

            row.TotalGst = row.TotalGst.Replace("\r\a", string.Empty);
            row.TotalGst = row.TotalGst.Replace("$", string.Empty);

            //convert to double
            decimal dBasePrem;

            if (!decimal.TryParse(row.BasePremium, out dBasePrem))
            {
                anyFailed = true;
            }
            decimal dbrokerPolicyFee;

            if (!decimal.TryParse(row.BrokerFeePerPolicyClass, out dbrokerPolicyFee))
            {
                anyFailed = true;
            }
            decimal dFireServices;

            if (!decimal.TryParse(row.FireServicesLevies, out dFireServices))
            {
                anyFailed = true;
            }
            decimal dOtherTaxes;

            if (!decimal.TryParse(row.OtherTaxesCharges, out dOtherTaxes))
            {
                anyFailed = true;
            }
            decimal dPolicyUnderwriterGst;

            if (!decimal.TryParse(row.PolicyUnderwriterGst, out dPolicyUnderwriterGst))
            {
                anyFailed = true;
            }
            decimal dStampDuty;

            if (!decimal.TryParse(row.StampDuty, out dStampDuty))
            {
                anyFailed = true;
            }
            decimal dTotalGst;

            if (!decimal.TryParse(row.TotalGst, out dTotalGst))
            {
                anyFailed = true;
            }

            if (anyFailed)
            {
                return(0);
            }

            return(dBasePrem + dbrokerPolicyFee + dFireServices + dOtherTaxes + dPolicyUnderwriterGst + dStampDuty +
                   dTotalGst);
        }
Beispiel #2
0
        private void SyncPremiumSummaryTable()
        {
            var allRows = new List <IPremiumSummaryTableRow>();

            //store cell indexs
            int classOfInsuranceCIndex        = -1;
            int recommendedInsurerCIndex      = -1;
            int basePremiumCIndex             = -1;
            int policyUnderwriterGstIndex     = -1;
            int fireServicesLeviesCIndex      = -1;
            int totalGstCIndex                = -1;
            int stampDutyCIndex               = -1;
            int otherTaxesChargesCIndex       = -1;
            int brokerFeePerPolicyClassCIndex = -1;


            //      int headerRowIndex = -1;

            //first build table object
            foreach (WordOM.Table premiumSummary in Globals.ThisAddIn.Application.ActiveDocument.Tables)
            {
                if (premiumSummary.Title != null && String.Equals(Constants.WordTables.RenewalReportPremiumSummary, premiumSummary.Title, StringComparison.OrdinalIgnoreCase))
                {
                    foreach (WordOM.Cell headerCell in premiumSummary.Range.Cells)
                    {
                        switch (headerCell.Range.Text.Replace("\r\a", string.Empty))
                        {
                        case "Class of insurance":
                            classOfInsuranceCIndex = headerCell.ColumnIndex;
                            break;

                        case "Recommended insurer":
                            recommendedInsurerCIndex = headerCell.ColumnIndex;
                            break;

                        case "Base premium":
                            basePremiumCIndex = headerCell.ColumnIndex;
                            break;

                        case "Policy (Underwriter) GST":
                            policyUnderwriterGstIndex = headerCell.ColumnIndex;
                            break;

                        case "Fire services levies":
                            fireServicesLeviesCIndex = headerCell.ColumnIndex;
                            break;

                        case "Broker fee GST":
                            totalGstCIndex = headerCell.ColumnIndex;
                            break;

                        case "Stamp duties":
                            stampDutyCIndex = headerCell.ColumnIndex;
                            break;

                        case "Other taxes/ charges":
                            otherTaxesChargesCIndex = headerCell.ColumnIndex;
                            break;

                        case "Broker fee per policy class":
                            brokerFeePerPolicyClassCIndex = headerCell.ColumnIndex;
                            break;
                        }
                    }


                    int previous = -1;
                    PremiumSummaryTableRow pr = null;

                    foreach (WordOM.Cell cc in premiumSummary.Range.Cells)
                    {
                        if (cc.RowIndex == previous)
                        {
                            if (pr == null)
                            {
                                continue;
                            }

                            if (cc.ColumnIndex == classOfInsuranceCIndex)
                            {
                                pr.ClassOfInsurance = cc.Range.Text;
                            }

                            else if (cc.ColumnIndex == recommendedInsurerCIndex)
                            {
                                pr.RecommendedInsurer = cc.Range.Text;
                            }

                            else if (cc.ColumnIndex == basePremiumCIndex)
                            {
                                pr.BasePremium = cc.Range.Text;
                            }

                            else if (cc.ColumnIndex == fireServicesLeviesCIndex)
                            {
                                pr.FireServicesLevies = cc.Range.Text;
                            }

                            else if (cc.ColumnIndex == totalGstCIndex)
                            {
                                pr.TotalGst = cc.Range.Text;
                            }

                            else if (cc.ColumnIndex == policyUnderwriterGstIndex)
                            {
                                pr.PolicyUnderwriterGst = cc.Range.Text;
                            }

                            else if (cc.ColumnIndex == stampDutyCIndex)
                            {
                                pr.StampDuty = cc.Range.Text;
                            }

                            else if (cc.ColumnIndex == otherTaxesChargesCIndex)
                            {
                                pr.OtherTaxesCharges = cc.Range.Text;
                            }

                            else if (cc.ColumnIndex == brokerFeePerPolicyClassCIndex)
                            {
                                pr.BrokerFeePerPolicyClass = cc.Range.Text;
                            }
                        }
                        else
                        {
                            if (pr != null)
                            {
                                allRows.Add(pr);
                            }

                            pr = new PremiumSummaryTableRow();
                        }
                        previous = cc.RowIndex;
                    }
                }
            }

            foreach (WordOM.Table premiumCosts in Globals.ThisAddIn.Application.ActiveDocument.Tables)
            {
                if (premiumCosts.Title != null && premiumCosts.Title.Contains(Constants.WordTables.RenewalReportPremiumCosts + "_"))
                {
                    string[] classOfInsurance = premiumCosts.Title.Split('_');
                    if (classOfInsurance.Length == 2)
                    {
                        IPremiumSummaryTableRow premRow = allRows.FirstOrDefault(i => i.ClassOfInsurance != null && String.Equals(i.ClassOfInsurance.Replace("\r\a", string.Empty), classOfInsurance[1], StringComparison.OrdinalIgnoreCase));
                        if (premRow != null)
                        {
                            premiumCosts.Rows[basePremiumCIndex - 3].Cells[3].Range.Text        = premRow.BasePremium.Replace("\r\a", string.Empty);
                            premiumCosts.Rows[fireServicesLeviesCIndex - 3].Cells[3].Range.Text = premRow.FireServicesLevies.Replace("\r\a", string.Empty);
                            premiumCosts.Rows[totalGstCIndex - 3].Cells[3].Range.Text           = premRow.TotalGst.Replace("\r\a", string.Empty);

                            premiumCosts.Rows[policyUnderwriterGstIndex - 3].Cells[3].Range.Text     = premRow.PolicyUnderwriterGst.Replace("\r\a", string.Empty);
                            premiumCosts.Rows[stampDutyCIndex - 3].Cells[3].Range.Text               = premRow.StampDuty.Replace("\r\a", string.Empty);
                            premiumCosts.Rows[otherTaxesChargesCIndex - 3].Cells[3].Range.Text       = premRow.OtherTaxesCharges.Replace("\r\a", string.Empty);
                            premiumCosts.Rows[brokerFeePerPolicyClassCIndex - 3].Cells[3].Range.Text = premRow.BrokerFeePerPolicyClass.Replace("\r\a", string.Empty);

                            //now do the total row
                            var c = CalculateTotalFromPremiumSummaryRow(premRow);
                            premiumCosts.Rows[8].Cells[3].Range.Text = String.Format("{0:C}", c);
                        }
                    }
                }
            }
        }