/// <summary> /// Save Function /// </summary> public void Save() { try { int inGridRowCount = dgvPaymentVoucher.RowCount; int inTableRowCount = dtblPartyBalance.Rows.Count; int inB = 0; PaymentMasterInfo InfoPaymentMaster = new PaymentMasterInfo(); PaymentMasterSP SpPaymentMaster = new PaymentMasterSP(); PaymentDetailsInfo InfoPaymentDetails = new PaymentDetailsInfo(); PaymentDetailsSP SpPaymentDetails = new PaymentDetailsSP(); PartyBalanceSP SpPartyBalance = new PartyBalanceSP(); PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo(); DateValidation objVal = new DateValidation(); TextBox txtDate1 = new TextBox(); InfoPaymentMaster.Date = dtpDate.Value; InfoPaymentMaster.Extra1 = string.Empty; InfoPaymentMaster.Extra2 = string.Empty; InfoPaymentMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId; InfoPaymentMaster.InvoiceNo = txtVoucherNo.Text.Trim(); ; InfoPaymentMaster.LedgerId = Convert.ToDecimal(cmbBankorCash.SelectedValue.ToString()); InfoPaymentMaster.Narration = txtNarration.Text.Trim(); InfoPaymentMaster.SuffixPrefixId = decDailySuffixPrefixId; decimal decTotalAmount = TotalAmountCalculation(); InfoPaymentMaster.TotalAmount = decTotalAmount; InfoPaymentMaster.UserId = PublicVariables._decCurrentUserId; InfoPaymentMaster.VoucherNo = strVoucherNo; InfoPaymentMaster.VoucherTypeId = decPaymentVoucherTypeId; decimal decPaymentMasterId = SpPaymentMaster.PaymentMasterAdd(InfoPaymentMaster); if (decPaymentMasterId != 0) { MasterLedgerPosting(); } for (int inI = 0; inI < inGridRowCount - 1; inI++) { if (dgvPaymentVoucher.Rows[inI].HeaderCell.Value.ToString() != "X") { InfoPaymentDetails.Amount = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString()); InfoPaymentDetails.ExchangeRateId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString()); InfoPaymentDetails.Extra1 = string.Empty; InfoPaymentDetails.Extra2 = string.Empty; InfoPaymentDetails.LedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString()); InfoPaymentDetails.PaymentMasterId = decPaymentMasterId; if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty) { InfoPaymentDetails.LedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString()); } if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty) { InfoPaymentDetails.ChequeNo = dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString(); if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty) { InfoPaymentDetails.ChequeDate = Convert.ToDateTime(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value); } else { InfoPaymentDetails.ChequeDate = DateTime.Now; } } else { InfoPaymentDetails.ChequeNo = string.Empty; InfoPaymentDetails.ChequeDate = DateTime.Now; } decimal decPaymentDetailsId = SpPaymentDetails.PaymentDetailsAdd(InfoPaymentDetails); if (decPaymentDetailsId != 0) { for (int inJ = 0; inJ < inTableRowCount; inJ++) { if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString()) { PartyBalanceAddOrEdit(inJ); } } inB++; DetailsLedgerPosting(inI, decPaymentDetailsId); } } } Messages.SavedMessage(); if (cbxPrintafterSave.Checked) { if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix") { PrintForDotMatrix(decPaymentmasterId); } else { Print(decPaymentMasterId); } } Clear(); } catch (Exception ex) { MessageBox.Show("PV17:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Edit Function /// </summary> /// <param name="decMasterId"></param> public void Edit(decimal decMasterId) { try { int inRowCount = dgvPaymentVoucher.RowCount; int inTableRowCount = dtblPartyBalance.Rows.Count; int inB = 0; PaymentMasterInfo InfoPaymentMaster = new PaymentMasterInfo(); PaymentMasterSP SpPaymentMaster = new PaymentMasterSP(); PaymentDetailsInfo InfoPaymentDetails = new PaymentDetailsInfo(); PaymentDetailsSP SpPaymentDetails = new PaymentDetailsSP(); LedgerPostingSP SpLedgerPosting = new LedgerPostingSP(); LedgerPostingInfo InfoLegerPosting = new LedgerPostingInfo(); PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo(); PartyBalanceSP SpPartyBalance = new PartyBalanceSP(); BankReconciliationSP SpBankReconcilation = new BankReconciliationSP(); InfoPaymentMaster.Date = dtpDate.Value; InfoPaymentMaster.PaymentMasterId = decMasterId; InfoPaymentMaster.Extra1 = string.Empty; InfoPaymentMaster.Extra2 = string.Empty; InfoPaymentMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId; InfoPaymentMaster.InvoiceNo = txtVoucherNo.Text.Trim(); InfoPaymentMaster.LedgerId = Convert.ToDecimal(cmbBankorCash.SelectedValue.ToString()); InfoPaymentMaster.Narration = txtNarration.Text.Trim(); InfoPaymentMaster.SuffixPrefixId = decDailySuffixPrefixId; decimal decTotalAmount = TotalAmountCalculation(); InfoPaymentMaster.TotalAmount = decTotalAmount; InfoPaymentMaster.UserId = PublicVariables._decCurrentUserId; InfoPaymentMaster.VoucherNo = strVoucherNo; InfoPaymentMaster.VoucherTypeId = decPaymentVoucherTypeId; decimal decPaymentMasterId = SpPaymentMaster.PaymentMasterEdit(InfoPaymentMaster); if (decPaymentmasterId != 0) { MasterLedgerPostingEdit(); } foreach (object obj in arrlstOfRemove) { string str = Convert.ToString(obj); SpPaymentDetails.PaymentDetailsDelete(Convert.ToDecimal(str)); SpLedgerPosting.LedgerPostDeleteByDetailsId(Convert.ToDecimal(str), strVoucherNo, decPaymentVoucherTypeId); } SpLedgerPosting.LedgerPostingDeleteByVoucherNoVoucherTypeIdAndLedgerId(strVoucherNo, decPaymentVoucherTypeId, 12); decimal decPaymentDetailsId1 = 0; for (int inI = 0; inI < inRowCount - 1; inI++) { InfoPaymentDetails.Amount = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString()); InfoPaymentDetails.ExchangeRateId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString()); InfoPaymentDetails.Extra1 = string.Empty; InfoPaymentDetails.Extra2 = string.Empty; if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty) { InfoPaymentDetails.LedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString()); } if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty) { InfoPaymentDetails.ChequeNo = dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString(); if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty) { InfoPaymentDetails.ChequeDate = Convert.ToDateTime(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value); } else { InfoPaymentDetails.ChequeDate = DateTime.Now; } } else { InfoPaymentDetails.ChequeNo = string.Empty; InfoPaymentDetails.ChequeDate = DateTime.Now; } InfoPaymentDetails.PaymentMasterId = decPaymentMasterId; if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].FormattedValue.ToString() == "0")//if new rows are added { if (dgvPaymentVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")//add new rows added which are completed { decimal decPaymentDetailsId = SpPaymentDetails.PaymentDetailsAdd(InfoPaymentDetails);//to add new rows in payment details if (decPaymentDetailsId != 0) { for (int inJ = 0; inJ < inTableRowCount; inJ++) { if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString()) { PartyBalanceAddOrEdit(inJ); } } inB++; DetailsLedgerPosting(inI, decPaymentDetailsId);//to add new ledger posting } } } else { if (dgvPaymentVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")//add new rows updated which are completed { InfoPaymentDetails.PaymentDetailsId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].Value.ToString()); decimal decPaymentDetailsId = SpPaymentDetails.PaymentDetailsEdit(InfoPaymentDetails);//to edit rows if (decPaymentDetailsId != 0) { for (int inJ = 0; inJ < inTableRowCount; inJ++) { if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString()) { PartyBalanceAddOrEdit(inJ); } } inB++; decPaymentDetailsId1 = InfoPaymentDetails.PaymentDetailsId; decimal decLedgerPostId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value.ToString()); DetailsLedgerPostingEdit(inI, decLedgerPostId, decPaymentDetailsId1); } } else { decimal decDetailsId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].Value.ToString()); SpPaymentDetails.PaymentDetailsDelete(decDetailsId); SpLedgerPosting.LedgerPostDeleteByDetailsId(decDetailsId, strVoucherNo, decPaymentVoucherTypeId); for (int inJ = 0; inJ < dtblPartyBalance.Rows.Count; inJ++) { if (dtblPartyBalance.Rows.Count == inJ) { break; } if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty) { if (dtblPartyBalance.Rows[inJ]["LedgerId"].ToString() == dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString()) { if (dtblPartyBalance.Rows[inJ]["PartyBalanceId"].ToString() != "0") { arrlstOfDeletedPartyBalanceRow.Add(dtblPartyBalance.Rows[inJ]["PartyBalanceId"]); } } } } } } } DeletePartyBalanceOfRemovedRow(); isUpdated = true; Messages.UpdatedMessage(); if (cbxPrintafterSave.Checked) { if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix") { PrintForDotMatrix(decPaymentmasterId); } else { Print(decPaymentMasterId); } } if (frmPaymentRegisterObj != null) { this.Close(); frmPaymentRegisterObj.CallFromPaymentVoucher(this); } if (frmPaymentReportObj != null) { this.Close(); frmPaymentReportObj.CallFromPaymentVoucher(this); } if (frmDayBookObj != null) { this.Close(); } if (frmBillallocationObj != null) { this.Close(); } this.Close(); } catch (Exception ex) { MessageBox.Show("PV18:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Grid Fill function while coming from other form to update or delete /// </summary> public void FillFunction() { try { PaymentMasterSP SpPaymentMaster = new PaymentMasterSP(); PaymentMasterInfo InfoPaymentMaster = new PaymentMasterInfo(); PaymentDetailsSP SpPaymentDetails = new PaymentDetailsSP(); PartyBalanceSP SpPartyBalance = new PartyBalanceSP(); LedgerPostingSP SpLedgerPosting = new LedgerPostingSP(); VoucherTypeSP SpVoucherType = new VoucherTypeSP(); AccountGroupSP spAccountGroup = new AccountGroupSP(); AccountLedgerSP SpAccountLedger = new AccountLedgerSP(); InfoPaymentMaster = SpPaymentMaster.PaymentMasterViewByMasterId(decPaymentmasterId);//view master details isAutomatic = SpVoucherType.CheckMethodOfVoucherNumbering(InfoPaymentMaster.VoucherTypeId); if (isAutomatic) { txtVoucherNo.ReadOnly = true; txtVoucherNo.Text = InfoPaymentMaster.InvoiceNo; txtDate.Focus(); } else { txtVoucherNo.ReadOnly = false; txtVoucherNo.Text = InfoPaymentMaster.InvoiceNo; txtVoucherNo.Focus(); } dtpDate.Text = InfoPaymentMaster.Date.ToString(); cmbBankorCash.SelectedValue = InfoPaymentMaster.LedgerId; txtNarration.Text = InfoPaymentMaster.Narration; txtTotal.Text = InfoPaymentMaster.TotalAmount.ToString(); decDailySuffixPrefixId = InfoPaymentMaster.SuffixPrefixId; decPaymentVoucherTypeId = InfoPaymentMaster.VoucherTypeId; strVoucherNo = InfoPaymentMaster.VoucherNo; strInvoiceNo = InfoPaymentMaster.InvoiceNo; DataTable dtbl = new DataTable(); dtbl = SpPaymentDetails.PaymentDetailsViewByMasterId(decPaymentmasterId);//view details details for (int inI = 0; inI < dtbl.Rows.Count; inI++) { dgvPaymentVoucher.Rows.Add(); dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value = Convert.ToDecimal(dtbl.Rows[inI]["ledgerId"].ToString()); dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentMasterId"].Value = dtbl.Rows[inI]["paymentMasterId"].ToString(); dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].Value = dtbl.Rows[inI]["paymentDetailsId"].ToString(); dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].Value = dtbl.Rows[inI]["amount"].ToString(); dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(dtbl.Rows[inI]["exchangeRateId"].ToString()); decimal decDetailsId1 = Convert.ToDecimal(dtbl.Rows[inI]["paymentDetailsId"].ToString()); decimal decLedgerPostingId = SpLedgerPosting.LedgerPostingIdFromDetailsId(decDetailsId1, strVoucherNo, decPaymentVoucherTypeId); dgvPaymentVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value = decLedgerPostingId.ToString(); decimal decLedgerId = Convert.ToDecimal(dtbl.Rows[inI]["ledgerId"].ToString()); bool IsBankAccount = spAccountGroup.AccountGroupwithLedgerId(decLedgerId); decimal decI = Convert.ToDecimal(SpAccountLedger.AccountGroupIdCheck(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].FormattedValue.ToString())); if (decI > 0)//to make amount and currency read only when party is choosen as ledger { dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].ReadOnly = true; dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].ReadOnly = true; } else { dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].ReadOnly = false; dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].ReadOnly = false; } dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value = dtbl.Rows[inI]["ChequeNo"].ToString(); if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty) { dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value = Convert.ToDateTime(dtbl.Rows[inI]["ChequeDate"].ToString()).ToString("dd-MMM-yyyy"); } } DataTable dtbl1 = new DataTable(); dtbl1 = SpPartyBalance.PartyBalanceViewByVoucherNoAndVoucherType(decPaymentVoucherTypeId, strVoucherNo, InfoPaymentMaster.Date); dtblPartyBalance = dtbl1; } catch (Exception ex) { MessageBox.Show("PV36:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }