Example #1
0
 public static void ValidateUpdateCode(int codeID, string code)
 {
     Broker.DataAccess.PaymentType paymentType = new Broker.DataAccess.PaymentType();
     paymentType.Code = code;
     paymentType.ID   = codeID;
     paymentType.TestBeforeUpdate();
 }
Example #2
0
 protected void ddlPaymentTypes_SelectedIndexChanged(object sender, EventArgs e)
 {
     Broker.DataAccess.PaymentType pt = Broker.DataAccess.PaymentType.Get(Convert.ToInt32(ddlPaymentTypes.SelectedValue));
     if (pt.Code == Broker.DataAccess.PaymentType.CREDITCARD)
     {
         ddlBank.Enabled      = true;
         ddlCardTypes.Enabled = true;
     }
     else
     {
         ddlBank.Enabled      = false;
         ddlCardTypes.Enabled = false;
     }
 }
Example #3
0
 public static void ValidateInsertCode(string code)
 {
     Broker.DataAccess.PaymentType paymentType = new Broker.DataAccess.PaymentType();
     paymentType.Code = code;
     paymentType.TestBeforeInsert();
 }
Example #4
0
    protected void btnGenerate_Click(object sender, EventArgs e)
    {
        DateTime       inputDate = Convert.ToDateTime(tbDateOfPayment.Text);
        PolicyItem     pi;
        List <Payment> newPayments = new List <Payment>();

        if (ddlInsuranceSubTypes.Items.Count > 0)
        {
            pi = PolicyItem.GetByNumberAndInsuranceSubType(tbPolicyNumber.Text, Convert.ToInt32(ddlInsuranceSubTypes.SelectedValue), int.Parse(ddlInsuranceCompany.SelectedValue));
        }
        else
        {
            pi = PolicyItem.GetByNumber(tbPolicyNumber.Text, int.Parse(ddlInsuranceCompany.SelectedValue));
        }
        if (inputDate.Date > DateTime.Today)
        {
            lblFeedback.Text = "Не е можно внесување на датуми поголеми од денешниот";
        }
        else
        {
            lblFeedback.Text = string.Empty;
            List <Payment> listPayments = Payment.GetByPolicyItemID(pi.ID);
            newPayments.AddRange(listPayments);
            decimal paymentTotalValue = 0;
            foreach (Payment payment in listPayments)
            {
                paymentTotalValue += payment.Value;
            }
            if (Convert.ToDecimal(tbValueOfPayment.Text) > (pi.PremiumValue - paymentTotalValue))
            {
                lblFeedback.Text = "Поголем износ од преостанатиот износ за плаќање";
            }
            else
            {
                lblFeedback.Text = string.Empty;
                decimal valueFromClient          = Convert.ToDecimal(tbValueOfPayment.Text);
                Broker.DataAccess.PaymentType pt = Broker.DataAccess.PaymentType.Get(Convert.ToInt32(ddlPaymentTypes.SelectedValue));
                Rate currentRate = Rate.GetCurrentRateForPayment(pi.ID);
                while (valueFromClient > 0)
                {
                    Payment newPayment = new Payment();
                    newPayment.Date           = Convert.ToDateTime(tbDateOfPayment.Text);
                    newPayment.RateID         = currentRate.ID;
                    newPayment.Rate           = currentRate;
                    newPayment.IsCashReported = false;
                    newPayment.PaymentTypeID  = pt.ID;
                    if (pt.Code == Broker.DataAccess.PaymentType.CREDITCARD)
                    {
                        newPayment.BankCreditCardID = BankCreditCard.GetByBankAndCard(Convert.ToInt32(ddlBank.SelectedValue), Convert.ToInt32(ddlCardTypes.SelectedValue)).ID;
                    }
                    newPayment.UserID   = this.PageUser.ID;
                    newPayment.BranchID = this.PageUser.BranchID;
                    if (tbBankslipNumber.Text.Trim() != string.Empty)
                    {
                        newPayment.BankslipNumber = tbBankslipNumber.Text;
                        newPayment.BankslipBankID = Convert.ToInt32(ddlBankslipBanks.SelectedValue);
                    }
                    if (valueFromClient >= currentRate.Value)
                    {
                        newPayment.Value       = currentRate.Value - Payment.GetPaidValueForRate(currentRate.ID);
                        valueFromClient       -= newPayment.Value;
                        currentRate.PaidValue += newPayment.Value;
                        newPayments.Add(newPayment);
                        int currentRateNumber = currentRate.Number;
                        int nextNumber;
                        int maxNumber = Rate.Table.Where(r => r.PolicyItemID == pi.ID).OrderBy(r => r.Number).Select(r => r.Number).ToList().Last();
                        if (currentRateNumber < maxNumber)
                        {
                            nextNumber = ++currentRateNumber;
                        }
                        else
                        {
                            nextNumber = currentRateNumber;
                        }
                        currentRate = Rate.Table.Where(r => r.PolicyItemID == pi.ID && r.Number == nextNumber).SingleOrDefault();
                    }
                    else
                    {
                        if (valueFromClient <= (currentRate.Value - currentRate.PaidValue))
                        {
                            newPayment.Value      = valueFromClient;
                            currentRate.PaidValue = valueFromClient;
                            newPayments.Add(newPayment);
                            break;
                        }
                        else
                        {
                            newPayment.Value      = (currentRate.Value - currentRate.PaidValue);
                            currentRate.PaidValue = currentRate.PaidValue;
                            newPayments.Add(newPayment);
                            valueFromClient -= newPayment.Value;
                            int currentRateNumber = currentRate.Number;
                            int nextNumber;
                            int maxNumber = Rate.Table.Where(r => r.PolicyItemID == pi.ID).OrderBy(r => r.Number).Select(r => r.Number).ToList().Last();
                            if (currentRateNumber < maxNumber)
                            {
                                nextNumber = ++currentRateNumber;
                            }
                            else
                            {
                                nextNumber = currentRateNumber;
                            }
                            currentRate = Rate.Table.Where(r => r.PolicyItemID == pi.ID && r.Number == nextNumber).SingleOrDefault();
                        }
                    }
                }
                btnInsert.Enabled = true;
            }
        }
        odsPaidPayments.SelectParameters.Clear();
        GridViewPayments.DataSourceID = null;
        GridViewPayments.DataSource   = newPayments;
        GridViewPayments.DataBind();
    }
Example #5
0
        public static decimal GetCountByPaymentTypeAndInsuranceCompanyInPeriod(DateTime fromDate, DateTime toDate, int insuranceCompanyID, PaymentType pt)
        {
            int count             = 0;
            List <PolicyItem> lst = Table.Where(c => c.Date.Date >= fromDate.Date && c.Date.Date <= toDate.Date && c.Rate.PolicyItem.Policy.Discard == false &&
                                                c.Rate.PolicyItem.Policy.InsuranceCompanyID == insuranceCompanyID && c.PaymentTypeID == pt.ID).Select(c => c.Rate.PolicyItem).Distinct().ToList();

            return(lst.Count);
        }
Example #6
0
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        DateTime   inputDate          = Convert.ToDateTime(tbDateOfPayment.Text);
        int        insuranceCompanyID = int.Parse(ddlInsuranceCompany.SelectedValue);
        PolicyItem pi;

        if (ddlInsuranceSubTypes.Items.Count > 0)
        {
            pi = PolicyItem.GetByNumberAndInsuranceSubType(tbPolicyNumber.Text, Convert.ToInt32(ddlInsuranceSubTypes.SelectedValue), insuranceCompanyID);
        }
        else
        {
            pi = PolicyItem.GetByNumber(tbPolicyNumber.Text, insuranceCompanyID);
        }
        if (inputDate.Date > DateTime.Today)
        {
            lblFeedback.Text = "Не е можно внесување на датуми поголеми од денешниот";
        }
        else
        {
            List <Payment> listPayments      = Payment.GetByPolicyItemID(pi.ID);
            decimal        paymentTotalValue = 0;
            foreach (Payment payment in listPayments)
            {
                paymentTotalValue += payment.Value;
            }
            if (Convert.ToDecimal(tbValueOfPayment.Text) > (pi.PremiumValue - paymentTotalValue))
            {
                lblFeedback.Text = "Поголем износ од преостанатиот износ за плаќање";
            }
            else
            {
                decimal valueFromClient = Convert.ToDecimal(tbValueOfPayment.Text);
                while (valueFromClient > 0)
                {
                    Rate    currentRate = Rate.GetCurrentRateForPayment(pi.ID);
                    Payment newPayment  = new Payment();
                    newPayment.Date           = Convert.ToDateTime(tbDateOfPayment.Text);
                    newPayment.RateID         = currentRate.ID;
                    newPayment.IsCashReported = false;
                    Broker.DataAccess.PaymentType pt = Broker.DataAccess.PaymentType.Get(Convert.ToInt32(ddlPaymentTypes.SelectedValue));
                    newPayment.PaymentTypeID = pt.ID;
                    if (pt.Code == Broker.DataAccess.PaymentType.CREDITCARD)
                    {
                        newPayment.BankCreditCardID = BankCreditCard.GetByBankAndCard(Convert.ToInt32(ddlBank.SelectedValue), Convert.ToInt32(ddlCardTypes.SelectedValue)).ID;
                    }
                    newPayment.UserID   = this.PageUser.ID;
                    newPayment.BranchID = this.PageUser.BranchID;
                    if (tbBankslipNumber.Text.Trim() != string.Empty)
                    {
                        newPayment.BankslipNumber = tbBankslipNumber.Text;
                        newPayment.BankslipBankID = Convert.ToInt32(ddlBankslipBanks.SelectedValue);
                    }
                    if (valueFromClient >= currentRate.Value)
                    {
                        newPayment.Value = currentRate.Value - Payment.GetPaidValueForRate(currentRate.ID);
                        newPayment.Insert();
                        decimal basicValue = newPayment.Value;
                        decimal k          = basicValue / newPayment.Rate.PolicyItem.PremiumValue;
                        List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList();
                        foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST)
                        {
                            PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID);
                            if (pei != null)
                            {
                                decimal peiValue = 0;
                                decimal.TryParse(pei.Value, out peiValue);
                                basicValue -= k * peiValue;
                                if (peiValue > 0)
                                {
                                    PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                    ppist.PaymentID          = newPayment.ID;
                                    ppist.InsuranceSubTypeID = c.InsuranceSubTypeID;
                                    ppist.PaidValue          = k * peiValue;
                                    ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                    ppist.Insert();
                                }
                            }
                        }
                        if (basicValue > 0)
                        {
                            PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                            ppist.PaymentID          = newPayment.ID;
                            ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID;
                            ppist.PaidValue          = basicValue;
                            ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                            ppist.Insert();
                        }
                        valueFromClient       -= newPayment.Value;
                        currentRate.PaidValue += newPayment.Value;
                        Rate.Table.Context.SubmitChanges();
                    }
                    else
                    {
                        if (valueFromClient <= (currentRate.Value - currentRate.PaidValue))
                        {
                            newPayment.Value = valueFromClient;
                            newPayment.Insert();
                            decimal basicValue = newPayment.Value;
                            decimal k          = basicValue / newPayment.Rate.PolicyItem.PremiumValue;
                            List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList();
                            foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST)
                            {
                                PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID);
                                if (pei != null)
                                {
                                    decimal peiValue = 0;
                                    decimal.TryParse(pei.Value, out peiValue);
                                    basicValue -= k * peiValue;
                                    if (peiValue > 0)
                                    {
                                        PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                        ppist.PaymentID          = newPayment.ID;
                                        ppist.InsuranceSubTypeID = c.InsuranceSubTypeID;
                                        ppist.PaidValue          = k * peiValue;
                                        ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                        ppist.Insert();
                                    }
                                }
                            }
                            if (basicValue > 0)
                            {
                                PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                ppist.PaymentID          = newPayment.ID;
                                ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID;
                                ppist.PaidValue          = basicValue;
                                ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                ppist.Insert();
                            }
                            currentRate.PaidValue += valueFromClient;
                            Rate.Table.Context.SubmitChanges();
                            break;
                        }
                        else
                        {
                            newPayment.Value = (currentRate.Value - currentRate.PaidValue);
                            newPayment.Insert();
                            decimal basicValue = newPayment.Value;
                            decimal k          = basicValue / newPayment.Rate.PolicyItem.PremiumValue;
                            List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList();
                            foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST)
                            {
                                PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID);
                                if (pei != null)
                                {
                                    decimal peiValue = 0;
                                    decimal.TryParse(pei.Value, out peiValue);
                                    basicValue -= k * peiValue;
                                    if (peiValue > 0)
                                    {
                                        PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                        ppist.PaymentID          = newPayment.ID;
                                        ppist.InsuranceSubTypeID = c.InsuranceSubTypeID;
                                        ppist.PaidValue          = k * peiValue;
                                        ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                        ppist.Insert();
                                    }
                                }
                            }

                            if (basicValue > 0)
                            {
                                PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                ppist.PaymentID          = newPayment.ID;
                                ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID;
                                ppist.PaidValue          = basicValue;
                                ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                ppist.Insert();
                            }
                            //currentRate.PaidValue += valueFromClient;
                            //Rate.Table.Context.SubmitChanges();
                            currentRate.PaidValue += newPayment.Value;
                            Rate.Table.Context.SubmitChanges();
                            valueFromClient -= newPayment.Value;
                        }
                    }
                }
                Broker.DataAccess.Facture.UpdatePaidStatusForFacture(pi.ID);
            }
        }
        GridViewPayments.DataSource   = null;
        GridViewPayments.DataSourceID = odsPaidPayments.ID;
        odsPaidPayments.SelectParameters.Clear();
        odsPaidPayments.SelectParameters.Add("policyItemID", pi.ID.ToString());
        GridViewPayments.DataBind();

        GridViewRates.DataSource   = null;
        GridViewRates.DataSourceID = odsRates.ID;

        odsRates.SelectParameters.Clear();
        odsRates.TypeName           = "Broker.DataAccess.Rate";
        odsRates.DataObjectTypeName = "Broker.DataAccess.Rate";
        odsRates.SelectMethod       = "GetByPolicyNumberAndInsuranceSubTypeIDAndInsuranceCompanyID";
        odsRates.SelectParameters.Add("policyNumber", tbPolicyNumber.Text);
        odsRates.SelectParameters.Add("insuranceSubTypeID", pi.InsuranceSubType.ID.ToString());
        odsRates.SelectParameters.Add("insuranceCompanyID", ddlInsuranceCompany.SelectedValue);
        //odsRates.SelectMethod = "Broker.DataAccess.PolicyItem.GetByNumberAndInsuranceSubType";
        GridViewRates.DataBind();
        UpdateTextBoxes(pi);
    }
Example #7
0
        public static void PrintCashReport(CashReport cr)
        {
            PDFCreators creator = new PDFCreators(true, 15, 15, 15, 15);

            creator.OpenPDF();
            creator.GetContentByte();
            creator.AddJDBLogoForFactures(10, 775);
            creator.SetTitleLeft10(" ");
            creator.SetTitleLeft10(" ");
            creator.SetTitleLeft10(" ");
            if (cr.Discard)
            {
                creator.SetTitleCenterForFactureNumber("СТОРНИРАН КАСОВ ИЗВЕШТАЈ бр. " + cr.Number);
            }
            else
            {
                creator.SetTitleCenterForFactureNumber("КАСОВ ИЗВЕШТАЈ бр. " + cr.Number);
            }
            creator.SetTitleLeft10("Статус: " + cr.CashReportStatuse.Name);
            creator.SetTitleLeft10("Датум: " + cr.CashReportDate.ToShortDateString());
            creator.SetTitleLeft10("Филијала: " + cr.Branch.Code + " " + cr.Branch.Name);
            List <CashReportItem> lstCRI = CashReportItem.GetByCashReport(cr.ID);

            creator.SetTitleLeft10(" ");
            creator.SetTitleLeft10("Кеш уплата");
            Broker.DataAccess.PaymentType ptCash   = Broker.DataAccess.PaymentType.GetByCode(Broker.DataAccess.PaymentType.CASH);
            List <CashReportItem>         cashList = lstCRI.Where(c => c.Payment.PaymentTypeID == ptCash.ID).ToList();

            string[]   headers          = { "Ред. бр.", "Број на полиса", "Компанија", "Подкласа", "Договорувач", "Уплата" };
            float[]    widthPercentages = { 8, 10, 17, 18, 32, 15 };
            TypeCode[] typeCodes        = { TypeCode.Int32, TypeCode.String, TypeCode.String, TypeCode.String, TypeCode.String, TypeCode.Decimal };
            creator.CreateTable_Facture(headers.Length, headers, widthPercentages);
            object[] values;
            int      ordinalNumber = 1;
            decimal  totCash       = 0;

            foreach (CashReportItem cri in cashList)
            {
                values    = new object[headers.Length];
                values[0] = ordinalNumber.ToString();
                values[1] = cri.Payment.Rate.PolicyItem.PolicyNumber;
                values[2] = cri.Payment.Rate.PolicyItem.Policy.InsuranceCompany.ShortName;
                values[3] = cri.Payment.Rate.PolicyItem.InsuranceSubType.ShortDescription;
                values[4] = cri.Payment.Rate.PolicyItem.Policy.Client.Name;
                values[5] = String.Format("{0:#,0.00}", cri.Payment.Value);
                creator.AddDataRowForFactures(values, headers.Length, typeCodes);
                ordinalNumber++;
                totCash += cri.Payment.Value;
            }
            values    = new object[headers.Length];
            values[0] = "";
            values[1] = "";
            values[2] = "";
            values[3] = "";
            values[4] = "Вкупно";
            values[5] = String.Format("{0:#,0.00}", totCash);
            creator.AddDataRowForFactures(values, headers.Length, typeCodes);
            creator.AddTable();

            creator.SetTitleLeft10(" ");
            creator.SetTitleLeft10("Кредитни картички");
            Broker.DataAccess.PaymentType ptCreditCard   = Broker.DataAccess.PaymentType.GetByCode(Broker.DataAccess.PaymentType.CREDITCARD);
            List <CashReportItem>         creditCardList = lstCRI.Where(c => c.Payment.PaymentTypeID == ptCreditCard.ID).ToList();

            string[]   headersCC          = { "Ред. бр.", "Број на полиса", "Компанија", "Подкласа", "Договорувач", "Банка", "Уплата" };
            float[]    widthPercentagesCC = { 7, 9, 16, 17, 27, 10, 14 };
            TypeCode[] typeCodesCC        = { TypeCode.Int32, TypeCode.String, TypeCode.String, TypeCode.String, TypeCode.String, TypeCode.String, TypeCode.Decimal };
            creator.CreateTable_Facture(headersCC.Length, headersCC, widthPercentagesCC);
            object[] valuesCC;
            int      ordinalNumberCC = 1;
            decimal  totCreditCard   = 0;

            foreach (CashReportItem cri in creditCardList)
            {
                valuesCC    = new object[headersCC.Length];
                valuesCC[0] = ordinalNumberCC.ToString();
                valuesCC[1] = cri.Payment.Rate.PolicyItem.PolicyNumber;
                valuesCC[2] = cri.Payment.Rate.PolicyItem.Policy.InsuranceCompany.ShortName;
                valuesCC[3] = cri.Payment.Rate.PolicyItem.InsuranceSubType.ShortDescription;
                valuesCC[4] = cri.Payment.Rate.PolicyItem.Policy.Client.Name;
                if (cri.Payment.BankCreditCardID != null)
                {
                    valuesCC[5] = cri.Payment.BankCreditCard.Bank.Name;
                }
                else
                {
                    valuesCC[5] = "";
                }
                valuesCC[6] = String.Format("{0:#,0.00}", cri.Payment.Value);
                creator.AddDataRowForFactures(valuesCC, headersCC.Length, typeCodesCC);
                ordinalNumberCC++;
                totCreditCard += cri.Payment.Value;
            }
            valuesCC    = new object[headersCC.Length];
            valuesCC[0] = "";
            valuesCC[1] = "";
            valuesCC[2] = "";
            valuesCC[3] = "";
            valuesCC[4] = "";
            valuesCC[5] = "Вкупно";
            valuesCC[6] = String.Format("{0:#,0.00}", totCreditCard);
            creator.AddDataRowForFactures(valuesCC, headersCC.Length, typeCodesCC);
            creator.AddTable();
            creator.SetTitleLeft10(" ");
            creator.SetTitleRightBold14("Вкупно: " + String.Format("{0:#,0.00}", (totCreditCard + totCash)));
            creator.FinishPDF_FileName("KasovIzvestaj" + cr.ID);
        }
Example #8
0
        public static decimal GetSumByPaymentTypeAndInsuranceCompanyInPeriod(DateTime fromDate, DateTime toDate, int insuranceCompanyID, PaymentType pt, out int count)
        {
            decimal sum = 0;

            count = 0;
            HashSet <int>  hs  = new HashSet <int>();
            List <Payment> lst = Table.Where(c => c.Date.Date >= fromDate.Date && c.Date.Date <= toDate.Date && c.Rate.PolicyItem.Policy.Discard == false &&
                                             c.Rate.PolicyItem.Policy.InsuranceCompanyID == insuranceCompanyID && c.PaymentTypeID == pt.ID).ToList();

            foreach (Payment p in lst)
            {
                if (!hs.Contains(p.Rate.PolicyItemID))
                {
                    hs.Add(p.Rate.PolicyItemID);
                }
                sum += p.Value;
            }
            count = hs.Count;
            return(sum);
        }
Example #9
0
 protected void dvDataSource_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
 {
     Broker.DataAccess.PaymentType pt = e.InputParameters["entityToInsert"] as Broker.DataAccess.PaymentType;
     PaymentTypeController.ValidateInsertCode(pt.Code);
 }
Example #10
0
 protected void dvDataSource_Updating(object sender, ObjectDataSourceMethodEventArgs e)
 {
     Broker.DataAccess.PaymentType pt = e.InputParameters["newEntity"] as Broker.DataAccess.PaymentType;
     PaymentTypeController.ValidateUpdateCode(pt.ID, pt.Code);
 }
Example #11
0
        public static decimal GetPremiumValueForExistingRollBack(int rollBackID, bool isPaidInBrokerHouse, PaymentType pt, out int count)
        {
            decimal sum = 0;

            count = 0;
            List <RollBackDistributionItem> rbdiList = RollBackDistributionItem.GetByRollBackDistibution(rollBackID);

            if (isPaidInBrokerHouse)
            {
                foreach (RollBackDistributionItem rbdi in rbdiList)
                {
                    if (rbdi.PolicyItem.IsPaidInBrokerHouse && !rbdi.PolicyItem.Policy.Discard)
                    {
                        count++;
                        sum += rbdi.PolicyItem.PremiumValue;
                    }
                }
                //} else {
                //    foreach (RollBackDistributionItem rbdi in rbdiList) {
                //        if (!rbdi.PolicyItem.IsPaidInBrokerHouse && !rbdi.PolicyItem.Policy.Discard) {
                //            List<Rate> ratesList = Rate.GetByPolicyItemID(rbdi.PolicyItemID);
                //            int paymentTypeID = pt.ID;
                //            if (ratesList[0].PaymentTypeID == paymentTypeID) {
                //                count++;
                //                sum += rbdi.PolicyItem.PremiumValue;
                //            }
                //        }
                //    }
            }
            return(sum);
        }
Example #12
0
        public static decimal GetPremiumValueForSummury(DateTime fromDate, DateTime toDate, bool isPaidInBrokerHouse, int insuranceCompanyID, PaymentType pt, out int count)
        {
            decimal sum = 0;

            count = 0;
            List <PolicyItem> listPolicyItems = Table.Where(p => p.Policy.Discard == false && p.Policy.ApplicationDate.Date >= fromDate && p.Policy.ApplicationDate.Date <= toDate && p.Policy.InsuranceCompanyID == insuranceCompanyID).ToList();

            if (isPaidInBrokerHouse)
            {
                foreach (PolicyItem pi in listPolicyItems)
                {
                    if (pi.IsPaidInBrokerHouse)
                    {
                        count++;
                        sum += pi.PremiumValue;
                    }
                }
                //} else {
                //    foreach (PolicyItem pi in listPolicyItems) {
                //        if (!pi.IsPaidInBrokerHouse) {
                //            List<Rate> ratesList = Rate.GetByPolicyItemID(pi.ID);
                //            int paymentTypeID = pt.ID;
                //            if (ratesList[0].PaymentTypeID == paymentTypeID) {
                //                count++;
                //                sum += pi.PremiumValue;
                //            }
                //        }
                //    }
            }
            return(sum);
        }
Example #13
0
    void InsertPaymentsForPolicy(PolicyItem pi, decimal newPaidValue, DateTime dateOfNewPaid, string bankslipNumber, int bankslipBankID)
    {
        List <Payment> listPayments      = Payment.GetByPolicyItemID(pi.ID);
        decimal        paymentTotalValue = 0;

        foreach (Payment payment in listPayments)
        {
            paymentTotalValue += payment.Value;
        }
        if (newPaidValue > (pi.PremiumValue - paymentTotalValue))
        {
            RegisterStartupScript("myAlert", "<script>alert('Поголем износ од преостанатиот износ за плаќање!')</script>");
        }
        else
        {
            decimal valueFromClient = newPaidValue;
            while (valueFromClient > 0)
            {
                Rate    currentRate = Rate.GetCurrentRateForPayment(pi.ID);
                Payment newPayment  = new Payment();
                newPayment.Date           = dateOfNewPaid;
                newPayment.RateID         = currentRate.ID;
                newPayment.IsCashReported = false;
                Broker.DataAccess.PaymentType pt = Broker.DataAccess.PaymentType.GetByCode(Broker.DataAccess.PaymentType.VIRMAN);
                newPayment.PaymentTypeID  = pt.ID;
                newPayment.UserID         = this.PageUser.ID;
                newPayment.BranchID       = this.PageUser.BranchID;
                newPayment.BankslipNumber = bankslipNumber;
                newPayment.BankslipBankID = bankslipBankID;
                if (valueFromClient >= currentRate.Value)
                {
                    newPayment.Value = currentRate.Value - Payment.GetPaidValueForRate(currentRate.ID);
                    newPayment.Insert();
                    decimal basicValue = newPayment.Value;
                    decimal k          = basicValue / newPayment.Rate.PolicyItem.PremiumValue;
                    List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList();
                    foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST)
                    {
                        PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID);
                        if (pei != null)
                        {
                            decimal peiValue = 0;
                            decimal.TryParse(pei.Value, out peiValue);
                            basicValue -= k * peiValue;
                            if (peiValue > 0)
                            {
                                PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                ppist.PaymentID          = newPayment.ID;
                                ppist.InsuranceSubTypeID = c.InsuranceSubTypeID;
                                ppist.PaidValue          = k * peiValue;
                                ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                ppist.Insert();
                            }
                        }
                    }
                    if (basicValue > 0)
                    {
                        PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                        ppist.PaymentID          = newPayment.ID;
                        ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID;
                        ppist.PaidValue          = basicValue;
                        ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                        ppist.Insert();
                    }
                    valueFromClient       -= newPayment.Value;
                    currentRate.PaidValue += newPayment.Value;
                    Rate.Table.Context.SubmitChanges();
                }
                else
                {
                    if (valueFromClient <= (currentRate.Value - currentRate.PaidValue))
                    {
                        newPayment.Value = valueFromClient;
                        newPayment.Insert();
                        decimal basicValue = newPayment.Value;
                        decimal k          = basicValue / newPayment.Rate.PolicyItem.PremiumValue;
                        List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList();
                        foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST)
                        {
                            PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID);
                            if (pei != null)
                            {
                                decimal peiValue = 0;
                                decimal.TryParse(pei.Value, out peiValue);
                                basicValue -= k * peiValue;
                                if (peiValue > 0)
                                {
                                    PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                    ppist.PaymentID          = newPayment.ID;
                                    ppist.InsuranceSubTypeID = c.InsuranceSubTypeID;
                                    ppist.PaidValue          = k * peiValue;
                                    ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                    ppist.Insert();
                                }
                            }
                        }
                        if (basicValue > 0)
                        {
                            PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                            ppist.PaymentID          = newPayment.ID;
                            ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID;
                            ppist.PaidValue          = basicValue;
                            ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                            ppist.Insert();
                        }
                        currentRate.PaidValue += valueFromClient;
                        Rate.Table.Context.SubmitChanges();
                        break;
                    }
                    else
                    {
                        newPayment.Value = (currentRate.Value - currentRate.PaidValue);
                        newPayment.Insert();
                        decimal basicValue = newPayment.Value;
                        decimal k          = basicValue / newPayment.Rate.PolicyItem.PremiumValue;
                        List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList();
                        foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST)
                        {
                            PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID);
                            if (pei != null)
                            {
                                decimal peiValue = 0;
                                decimal.TryParse(pei.Value, out peiValue);
                                basicValue -= k * peiValue;
                                if (peiValue > 0)
                                {
                                    PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                    ppist.PaymentID          = newPayment.ID;
                                    ppist.InsuranceSubTypeID = c.InsuranceSubTypeID;
                                    ppist.PaidValue          = k * peiValue;
                                    ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                    ppist.Insert();
                                }
                            }
                        }

                        if (basicValue > 0)
                        {
                            PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                            ppist.PaymentID          = newPayment.ID;
                            ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID;
                            ppist.PaidValue          = basicValue;
                            ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                            ppist.Insert();
                        }
                        //currentRate.PaidValue += valueFromClient;
                        //Rate.Table.Context.SubmitChanges();
                        currentRate.PaidValue += newPayment.Value;
                        Rate.Table.Context.SubmitChanges();
                        valueFromClient -= newPayment.Value;
                    }
                }
            }
            Broker.DataAccess.Facture.UpdatePaidStatusForFacture(pi.ID);
        }
    }