/// <summary> /// Ledger Posting edit function /// </summary> /// <param name="decpdcMasterId"></param> public void LedgerPostingEdit(decimal decpdcMasterId) { PDCRecivebleBll BllPdcRecieveble = new PDCRecivebleBll(); List<DataTable> listObjLedgerPostingId = new List<DataTable>(); LedgerPostingBll BllLedgerPosting = new LedgerPostingBll(); LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo(); ExchangeRateBll BllExchangeRate = new ExchangeRateBll(); decimal decOldExchange = 0; decimal decNewExchangeRate = 0; decimal decNewExchangeRateId = 0; decimal decSelectedCurrencyRate = 0; decimal decAmount = 0; decimal decConvertRate = 0; string strReferenceType = string.Empty; decimal decOldExchangeId = 0; try { listObjLedgerPostingId = BllPdcRecieveble.LedgerPostingIdByPDCReceivableId(decpdcMasterId); decimal decledgerpostingId1 = Convert.ToDecimal(listObjLedgerPostingId[0].Rows[0]["ledgerPostingId"].ToString()); decimal decLedgerPostingId2 = Convert.ToDecimal(listObjLedgerPostingId[0].Rows[1]["ledgerPostingId"].ToString()); if (!btnAgainRef.Enabled) { infoLedgerPosting.LedgerPostingId = decledgerpostingId1; infoLedgerPosting.VoucherTypeId = decPDCReceivableVoucherTypeId; infoLedgerPosting.VoucherNo = strVoucherNo; infoLedgerPosting.InvoiceNo = txtVoucherNo.Text.Trim(); infoLedgerPosting.Date = PublicVariables._dtCurrentDate; infoLedgerPosting.LedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString()); infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId; infoLedgerPosting.Debit = 0; infoLedgerPosting.Credit = Convert.ToDecimal(txtAmount.Text); infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtCheckDate.Text); infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim(); infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate; infoLedgerPosting.Extra1 = string.Empty; infoLedgerPosting.Extra2 = string.Empty; BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting); } else { infoLedgerPosting.LedgerPostingId = decledgerpostingId1; infoLedgerPosting.VoucherTypeId = decPDCReceivableVoucherTypeId; infoLedgerPosting.VoucherNo = strVoucherNo; infoLedgerPosting.InvoiceNo = txtVoucherNo.Text.Trim(); infoLedgerPosting.Date = PublicVariables._dtCurrentDate; infoLedgerPosting.LedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString()); infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId; infoLedgerPosting.Debit = 0; foreach (DataRow dr in dtblPartyBalance.Rows) { if (infoLedgerPosting.LedgerId == Convert.ToDecimal(dr["LedgerId"].ToString())) { decOldExchange = Convert.ToDecimal(dr["OldExchangeRate"].ToString()); decNewExchangeRateId = Convert.ToDecimal(dr["CurrencyId"].ToString()); decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(decOldExchange); decAmount = Convert.ToDecimal(dr["Amount"].ToString()); decConvertRate = decConvertRate + (decAmount * decSelectedCurrencyRate); } } infoLedgerPosting.Credit = decConvertRate; infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtCheckDate.Text); infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim(); infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate; infoLedgerPosting.Extra1 = string.Empty; infoLedgerPosting.Extra2 = string.Empty; BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting); infoLedgerPosting.LedgerId = 12; foreach (DataRow dr in dtblPartyBalance.Rows) { if (Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString()) == Convert.ToDecimal(dr["LedgerId"].ToString())) { if (dr["ReferenceType"].ToString() == "Against") { decNewExchangeRateId = Convert.ToDecimal(dr["CurrencyId"].ToString()); decNewExchangeRate = BllExchangeRate.GetExchangeRateByExchangeRateId(decNewExchangeRateId); decOldExchangeId = Convert.ToDecimal(dr["OldExchangeRate"].ToString()); decOldExchange = BllExchangeRate.GetExchangeRateByExchangeRateId(decOldExchangeId); decAmount = Convert.ToDecimal(dr["Amount"].ToString()); decimal decForexAmount = (decAmount * decNewExchangeRate) - (decAmount * decOldExchange); if (decForexAmount >= 0) { infoLedgerPosting.Credit = decForexAmount; infoLedgerPosting.Debit = 0; } else { infoLedgerPosting.Debit = -1 * decForexAmount; infoLedgerPosting.Credit = 0; } BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting); } } } } infoLedgerPosting.LedgerPostingId = decLedgerPostingId2; infoLedgerPosting.VoucherNo = strVoucherNo; infoLedgerPosting.InvoiceNo = txtVoucherNo.Text.Trim(); infoLedgerPosting.Date = PublicVariables._dtCurrentDate; infoLedgerPosting.LedgerId = 7; infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId; infoLedgerPosting.Debit = Convert.ToDecimal(txtAmount.Text); infoLedgerPosting.Credit = 0; infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate; infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtCheckDate.Text); infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim(); infoLedgerPosting.Extra1 = string.Empty; infoLedgerPosting.Extra2 = string.Empty; BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting); } catch (Exception ex) { MessageBox.Show("PR10:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
// Function to edit LedgerPosting table /// <summary> /// Function to edit the ledger posting /// </summary> /// <param name="decLedgerPostingId"></param> /// <param name="decLedgerId"></param> /// <param name="decCredit"></param> /// <param name="decDebit"></param> public void LedgerPostingEdit(decimal decLedgerPostingId, decimal decLedgerId, decimal decCredit, decimal decDebit) { try { LedgerPostingBll BllLedgerPosting = new LedgerPostingBll(); LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo(); infoLedgerPosting.LedgerPostingId = decLedgerPostingId; infoLedgerPosting.Date = PublicVariables._dtCurrentDate; infoLedgerPosting.VoucherTypeId = DecServicetVoucherTypeId; infoLedgerPosting.VoucherNo = strVoucherNo; infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId; if (isAutomatic) // Checking voucher number generation is automatic or not { infoLedgerPosting.InvoiceNo = strInvoiceNo; } else { infoLedgerPosting.InvoiceNo = txtInvoiceNumber.Text; //For Manual mode } infoLedgerPosting.ChequeNo = string.Empty; infoLedgerPosting.ChequeDate = DateTime.Now; infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate; infoLedgerPosting.Extra1 = string.Empty; infoLedgerPosting.Extra2 = string.Empty; infoLedgerPosting.LedgerId = decLedgerId; infoLedgerPosting.Credit = decCredit; infoLedgerPosting.Debit = decDebit; BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting); } catch (Exception ex) { MessageBox.Show("SV 03: " + ex.Message, "Open Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// LedgerPosting Update Function /// </summary> /// <param name="decLedgerPostingId"></param> /// <param name="decLedgerId"></param> /// <param name="decCredit"></param> /// <param name="decDebit"></param> /// <param name="decDetailsId"></param> /// <param name="inI"></param> public void LedgerPostingEdit(decimal decLedgerPostingId, decimal decLedgerId, decimal decCredit, decimal decDebit, decimal decDetailsId, int inI) { try { LedgerPostingBll BllLedgerPosting = new LedgerPostingBll(); LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo(); infoLedgerPosting.LedgerPostingId = decLedgerPostingId; infoLedgerPosting.Date = PublicVariables._dtCurrentDate; infoLedgerPosting.VoucherTypeId = DecContraVoucherTypeId; infoLedgerPosting.VoucherNo = strVoucherNo; infoLedgerPosting.DetailsId = decDetailsId; infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId; infoLedgerPosting.InvoiceNo = txtVoucherNo.Text; infoLedgerPosting.Extra1 = string.Empty; infoLedgerPosting.Extra2 = string.Empty; infoLedgerPosting.LedgerId = decLedgerId; infoLedgerPosting.Credit = decCredit; infoLedgerPosting.Debit = decDebit; if (inI > -1) { if (dgvContraVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvContraVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty) { infoLedgerPosting.ChequeNo = dgvContraVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString(); } else { infoLedgerPosting.ChequeNo = string.Empty; } if (dgvContraVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvContraVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty) { infoLedgerPosting.ChequeDate = Convert.ToDateTime(dgvContraVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value); } else { infoLedgerPosting.ChequeDate = DateTime.Now; } } else { infoLedgerPosting.ChequeNo = string.Empty; infoLedgerPosting.ChequeDate = DateTime.Now; } BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting); } catch (Exception ex) { MessageBox.Show("CV:20" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to update ledger posting table /// </summary> public void LedgerUpdate() { try { decimal decLedgerPostingId = 0; LedgerPostingBll BllLedgerPosting = new LedgerPostingBll(); LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo(); List<DataTable> listObj = new List<DataTable>(); listObj = BllLedgerPosting.GetLedgerPostingIds(strVoucherNo, decMonthlyVoucherTypeId); int ini = 0; foreach (DataRow dr in listObj[0].Rows) { ini++; if (ini == 2) { decLedgerPostingId = Convert.ToDecimal(dr.ItemArray[0].ToString()); infoLedgerPosting.LedgerPostingId = decLedgerPostingId; infoLedgerPosting.Date = Convert.ToDateTime(dtpVoucherDate.Value.ToString()); if (isAutomatic) { infoLedgerPosting.VoucherNo = strVoucherNo; } else { infoLedgerPosting.VoucherNo = txtVoucherNo.Text; } infoLedgerPosting.Debit = Convert.ToDecimal(lblTotalAmount.Text.ToString()); infoLedgerPosting.Credit = 0; infoLedgerPosting.VoucherTypeId = decMonthlyVoucherTypeId; infoLedgerPosting.LedgerId = 4; infoLedgerPosting.DetailsId = 0; if (isAutomatic) { infoLedgerPosting.InvoiceNo = strInvoiceNo; } else { infoLedgerPosting.InvoiceNo = txtVoucherNo.Text; } infoLedgerPosting.ChequeNo = string.Empty; infoLedgerPosting.ChequeDate = DateTime.Now; infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId; infoLedgerPosting.Extra1 = string.Empty; infoLedgerPosting.Extra2 = string.Empty; BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting); } if (ini == 1) { decLedgerPostingId = Convert.ToDecimal(dr.ItemArray[0].ToString()); infoLedgerPosting.LedgerPostingId = decLedgerPostingId; infoLedgerPosting.Date = PublicVariables._dtCurrentDate; if (isAutomatic) { infoLedgerPosting.VoucherNo = strVoucherNo; } else { infoLedgerPosting.VoucherNo = txtVoucherNo.Text; } infoLedgerPosting.Debit = 0; infoLedgerPosting.Credit = Convert.ToDecimal(lblTotalAmount.Text.ToString()); infoLedgerPosting.VoucherTypeId = decMonthlyVoucherTypeId; infoLedgerPosting.LedgerId = Convert.ToDecimal(cmbCashOrBankAcc.SelectedValue.ToString()); infoLedgerPosting.DetailsId = 0; if (isAutomatic) { infoLedgerPosting.InvoiceNo = strInvoiceNo; } else { infoLedgerPosting.InvoiceNo = txtVoucherNo.Text; } infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId; infoLedgerPosting.Extra1 = string.Empty; infoLedgerPosting.Extra2 = string.Empty; infoLedgerPosting.ChequeNo = string.Empty; infoLedgerPosting.ChequeDate = DateTime.Now; BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting); } } } catch (Exception ex) { MessageBox.Show("MSV5:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Details ledger posting edit /// </summary> /// <param name="inA"></param> /// <param name="decLedgerPostingId"></param> /// <param name="decPaymentDetailsId"></param> public void DetailsLedgerPostingEdit(int inA, decimal decLedgerPostingId, decimal decPaymentDetailsId) { LedgerPostingInfo InfoLedgerPosting = new LedgerPostingInfo(); LedgerPostingBll BllLedgerPosting = new LedgerPostingBll(); ExchangeRateBll BllExchangeRate = new ExchangeRateBll(); decimal decOldExchange = 0; decimal decNewExchangeRate = 0; decimal decNewExchangeRateId = 0; decimal decOldExchangeId = 0; try { if (!dgvPaymentVoucher.Rows[inA].Cells["dgvtxtAmount"].ReadOnly) { decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dgvPaymentVoucher.Rows[inA].Cells["dgvcmbCurrency"].Value.ToString())); decAmount = Convert.ToDecimal(dgvPaymentVoucher.Rows[inA].Cells["dgvtxtAmount"].Value.ToString()); decConvertRate = decAmount * decSelectedCurrencyRate; InfoLedgerPosting.Credit = 0; InfoLedgerPosting.Date = dtpDate.Value; InfoLedgerPosting.Debit = decConvertRate; InfoLedgerPosting.DetailsId = decPaymentDetailsId; InfoLedgerPosting.Extra1 = string.Empty; InfoLedgerPosting.Extra2 = string.Empty; InfoLedgerPosting.InvoiceNo = strInvoiceNo; InfoLedgerPosting.LedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inA].Cells["dgvcmbAccountLedger"].Value.ToString()); if (!isAutomatic) { InfoLedgerPosting.VoucherNo = txtVoucherNo.Text.Trim(); } else { InfoLedgerPosting.VoucherNo = strVoucherNo; } if (dgvPaymentVoucher.Rows[inA].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inA].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty) { InfoLedgerPosting.ChequeNo = dgvPaymentVoucher.Rows[inA].Cells["dgvtxtChequeNo"].Value.ToString(); if (dgvPaymentVoucher.Rows[inA].Cells["dgvtxtChequeDate"].Value != null && dgvPaymentVoucher.Rows[inA].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty) { InfoLedgerPosting.ChequeDate = Convert.ToDateTime(dgvPaymentVoucher.Rows[inA].Cells["dgvtxtChequeDate"].Value.ToString()); } else InfoLedgerPosting.ChequeDate = DateTime.Now; } else { InfoLedgerPosting.ChequeNo = string.Empty; InfoLedgerPosting.ChequeDate = DateTime.Now; } InfoLedgerPosting.VoucherTypeId = decPaymentVoucherTypeId; InfoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId; InfoLedgerPosting.LedgerPostingId = decLedgerPostingId; BllLedgerPosting.LedgerPostingEdit(InfoLedgerPosting); } else { InfoLedgerPosting.Date = dtpDate.Value; InfoLedgerPosting.Extra1 = string.Empty; InfoLedgerPosting.Extra2 = string.Empty; InfoLedgerPosting.InvoiceNo = strInvoiceNo; InfoLedgerPosting.VoucherTypeId = decPaymentVoucherTypeId; InfoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId; InfoLedgerPosting.Credit = 0; InfoLedgerPosting.LedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inA].Cells["dgvcmbAccountLedger"].Value.ToString()); InfoLedgerPosting.VoucherNo = strVoucherNo; InfoLedgerPosting.DetailsId = decPaymentDetailsId; InfoLedgerPosting.InvoiceNo = txtVoucherNo.Text.Trim(); if (dgvPaymentVoucher.Rows[inA].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inA].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty) { InfoLedgerPosting.ChequeNo = dgvPaymentVoucher.Rows[inA].Cells["dgvtxtChequeNo"].Value.ToString(); if (dgvPaymentVoucher.Rows[inA].Cells["dgvtxtChequeDate"].Value != null && dgvPaymentVoucher.Rows[inA].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty) { InfoLedgerPosting.ChequeDate = Convert.ToDateTime(dgvPaymentVoucher.Rows[inA].Cells["dgvtxtChequeDate"].Value.ToString()); } else InfoLedgerPosting.ChequeDate = DateTime.Now; } else { InfoLedgerPosting.ChequeNo = string.Empty; InfoLedgerPosting.ChequeDate = DateTime.Now; } foreach (DataRow dr in dtblPartyBalance.Rows) { if (InfoLedgerPosting.LedgerId == Convert.ToDecimal(dr["LedgerId"].ToString())) { decOldExchange = Convert.ToDecimal(dr["OldExchangeRate"].ToString()); decNewExchangeRateId = Convert.ToDecimal(dr["CurrencyId"].ToString()); decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(decOldExchange); decAmount = Convert.ToDecimal(dr["Amount"].ToString()); decConvertRate = decConvertRate + (decAmount * decSelectedCurrencyRate); } } InfoLedgerPosting.Debit = decConvertRate; InfoLedgerPosting.LedgerPostingId = decLedgerPostingId; BllLedgerPosting.LedgerPostingEdit(InfoLedgerPosting); InfoLedgerPosting.LedgerId = 12; foreach (DataRow dr in dtblPartyBalance.Rows) { if (Convert.ToDecimal(dgvPaymentVoucher.Rows[inA].Cells["dgvcmbAccountLedger"].Value.ToString()) == Convert.ToDecimal(dr["LedgerId"].ToString())) { if (dr["ReferenceType"].ToString() == "Against") { decNewExchangeRateId = Convert.ToDecimal(dr["CurrencyId"].ToString()); decNewExchangeRate = BllExchangeRate.GetExchangeRateByExchangeRateId(decNewExchangeRateId); decOldExchangeId = Convert.ToDecimal(dr["OldExchangeRate"].ToString()); decOldExchange = BllExchangeRate.GetExchangeRateByExchangeRateId(decOldExchangeId); decAmount = Convert.ToDecimal(dr["Amount"].ToString()); decimal decForexAmount = (decAmount * decNewExchangeRate) - (decAmount * decOldExchange); if (decForexAmount >= 0) { InfoLedgerPosting.Debit = decForexAmount; InfoLedgerPosting.Credit = 0; } else { InfoLedgerPosting.Credit = -1 * decForexAmount; InfoLedgerPosting.Debit = 0; } BllLedgerPosting.LedgerPostingAdd(InfoLedgerPosting); } } } } } catch (Exception ex) { MessageBox.Show("PV24:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to update values in ledgerposting table /// </summary> public void ledgerUpdate() { try { string strfinancialId; FinancialYearBll BllFinancialYear = new FinancialYearBll(); FinancialYearInfo infoFinancialYear = new FinancialYearInfo(); infoFinancialYear = BllFinancialYear.FinancialYearViewForAccountLedger(1); strfinancialId = infoFinancialYear.FromDate.ToString("dd-MMM-yyyy"); decimal decLedgerPostingId = 0; if (txtOpeningBalance.Text.Trim() != string.Empty) { decOpeningBlnc = Convert.ToDecimal(txtOpeningBalance.Text.Trim()); } else { decOpeningBlnc = 0; } LedgerPostingBll BllLedgerPosting = new LedgerPostingBll(); LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo(); List<DataTable> dtbl = BllLedgerPosting.GetLedgerPostingIds(decLedgerIdForEdit.ToString(), 1); foreach (DataRow dr in dtbl[0].Rows) { decLedgerPostingId = Convert.ToDecimal(dr.ItemArray[0].ToString()); } if (cmbDrorCr.Text == "Dr") { infoLedgerPosting.Debit = decOpeningBlnc; } else { infoLedgerPosting.Credit = decOpeningBlnc; } infoLedgerPosting.LedgerPostingId = decLedgerPostingId; infoLedgerPosting.VoucherTypeId = 1; infoLedgerPosting.VoucherNo = decLedgerIdForEdit.ToString(); infoLedgerPosting.Date = Convert.ToDateTime(strfinancialId.ToString()); infoLedgerPosting.LedgerId = decLedgerIdForEdit; infoLedgerPosting.DetailsId = 0; infoLedgerPosting.InvoiceNo = decLedgerIdForEdit.ToString(); infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId; infoLedgerPosting.ChequeDate = DateTime.Now; infoLedgerPosting.ChequeNo = string.Empty; infoLedgerPosting.Extra1 = string.Empty; infoLedgerPosting.Extra2 = string.Empty; if (dtbl[0].Rows.Count > 0) { if (decOpeningBlnc > 0) { BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting); } else { AccountLedgerBll bllAccountLedger = new AccountLedgerBll(); bllAccountLedger.LedgerPostingDeleteByVoucherTypeAndVoucherNo(decLedgerIdForEdit.ToString(), 1); } } else { BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting); } } catch (Exception ex) { MessageBox.Show("Cus16:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> ///Function to edit ledgerposting incase of opening balance /// </summary> public void LedgerPostingEdit() { try { string strfinancialId; decOpeningBalance = Convert.ToDecimal(((txtOpeningBalance.Text == "") ? "0" : txtOpeningBalance.Text.Trim())); LedgerPostingBll BllLedgerPosting = new LedgerPostingBll(); LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo(); AccountLedgerBll bllAccountLedger = new AccountLedgerBll(); FinancialYearBll BllFinancialYear = new FinancialYearBll(); FinancialYearInfo infoFinancialYear = new FinancialYearInfo(); infoFinancialYear = BllFinancialYear.FinancialYearViewForAccountLedger(1); strfinancialId = infoFinancialYear.FromDate.ToString("dd-MMM-yyyy"); infoLedgerPosting.VoucherTypeId = 1; infoLedgerPosting.Date = Convert.ToDateTime(strfinancialId.ToString()); if (cmbOpeningBalanceCrOrDr.Text == "Dr") { infoLedgerPosting.Debit = decOpeningBalance; } else { infoLedgerPosting.Credit = decOpeningBalance; } infoLedgerPosting.DetailsId = 0; infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId; infoLedgerPosting.InvoiceNo = decAccountLedgerId.ToString(); infoLedgerPosting.Extra1 = string.Empty; infoLedgerPosting.Extra2 = string.Empty; infoLedgerPosting.LedgerId = decAccountLedgerId; infoLedgerPosting.VoucherNo = decAccountLedgerId.ToString(); infoLedgerPosting.ChequeNo = string.Empty; infoLedgerPosting.ChequeDate = DateTime.Now; List<DataTable> dtbl = BllLedgerPosting.GetLedgerPostingIds(decAccountLedgerId.ToString(), 1); if (dtbl[0].Rows.Count > 0) { if (decOpeningBalance > 0) { //Edit infoLedgerPosting.LedgerPostingId = Convert.ToDecimal(dtbl[0].Rows[0][0].ToString()); BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting); } else { //Delete bllAccountLedger.LedgerPostingDeleteByVoucherTypeAndVoucherNo(decAccountLedgerId.ToString(), 1); } } else { //Add new row BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting); } } catch (Exception ex) { MessageBox.Show("AL5:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }