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); } }
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); }
public static string DeletePolicy(int piID) { DataClassesDataContext dc = new DataClassesDataContext(); string retString = "Полисата е избришана."; PolicyItem pi = PolicyItem.Get(piID); Distribution d = Distribution.GetByNumberAndSubTypeAndCompany(pi.InsuranceSubTypeID, pi.PolicyNumber, pi.Policy.InsuranceCompanyID); Policy p = Policy.Get(pi.PolicyID); List <RollBackDistributionItem> listRDI = RollBackDistributionItem.Table.Where(c => c.PolicyItemID == pi.ID).ToList(); if (listRDI.Count > 0) { retString = "Полисата е раздолжена и не може да се брише!"; return(retString); } List <Rate> lstRates = Rate.GetByPolicyItemID(pi.ID); if (lstRates.Count > 0) { List <Payment> lstPayments = Payment.GetByRateID(lstRates[0].ID); if (lstPayments.Count > 0) { if (lstPayments[0].IsFactured) { retString = "Полисата е фактурирана за брокеража и не може да се брише!"; return(retString); } } foreach (Rate r in lstRates) { List <Payment> lstP = Payment.GetByRateID(r.ID); foreach (Payment pay in lstP) { List <PaymentsPerInsSubType> lstPPIST = PaymentsPerInsSubType.GetByPayment(pay.ID); foreach (PaymentsPerInsSubType ppist in lstPPIST) { string queryppist = @"DELETE FROM PaymentsPerInsSubTypes WHERE ID = " + ppist.ID; dc.ExecuteCommand(queryppist); //ppist.Delete(); } string queryppay = @"DELETE FROM Payments WHERE ID = " + pay.ID; dc.ExecuteCommand(queryppay); //pay.Delete(); } string queryr = @"DELETE FROM Rates WHERE ID = " + r.ID; dc.ExecuteCommand(queryr); //r.Delete(); } string querypei = @"DELETE FROM PolicyExtendInformations WHERE PolicyItemID = " + pi.ID; dc.ExecuteCommand(querypei); Broker.DataAccess.Facture facture = PolicyItemFactureItem.GetByPolicyItemID(pi.ID); if (facture != null) { List <Broker.DataAccess.FactureItem> listFI = FactureItem.GetByFacture(facture.ID); foreach (FactureItem fi in listFI) { string querypifi = @"DELETE FROM PolicyItemFactureItems WHERE FactureItemID = " + fi.ID; dc.ExecuteCommand(querypifi); string queryfi = @"DELETE FROM FactureItems WHERE ID = " + fi.ID; dc.ExecuteCommand(queryfi); } string queryf = @"DELETE FROM Factures WHERE ID = " + facture.ID; dc.ExecuteCommand(queryf); } string querypi = @"DELETE FROM PolicyItems WHERE ID = " + pi.ID; dc.ExecuteCommand(querypi); //pi.Delete(); string queryp = @"DELETE FROM Policies WHERE ID = " + p.ID; dc.ExecuteCommand(queryp); //p.Delete(); string queryd = @"UPDATE Distributions SET IsUsed = 0 WHERE ID = " + d.ID; dc.ExecuteCommand(queryd); //d.IsUsed = false; //Distribution.Table.Context.SubmitChanges(); } return(retString); }