/// <summary>
 /// Function to edit the service voucher
 /// </summary>
 /// <param name="decServiceMasterId"></param>
 public void EditFunction(decimal decServiceMasterId)
 {
     try
     {
         ServiceMasterInfo infoServiceMaster = new ServiceMasterInfo();
         ServiceDetailsInfo infoServiceDetails = new ServiceDetailsInfo();
         ServicesBll BllService = new ServicesBll();
         LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
         LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
         ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
         int inRowCount = dgvServiceVoucher.RowCount;
         int inValue = 0;
         decimal decLedgerPostingId1 = 0;
         decimal decLedgerPostingId2 = 0;
         List<DataTable> listObjLedgerPostingId = new List<DataTable>();
         listObjLedgerPostingId = BllService.LedgerPostingIdByServiceMaasterId(decServiceMasterId);
         decLedgerPostingId1 = Convert.ToDecimal(listObjLedgerPostingId[0].Rows[0]["ledgerPostingId"].ToString());
         decLedgerPostingId2 = Convert.ToDecimal(listObjLedgerPostingId[0].Rows[1]["ledgerPostingId"].ToString());
         for (int ini = 0; ini < inRowCount - 1; ini++)
         {
             if (dgvServiceVoucher.Rows[ini].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[ini].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
             {
                 inValue++;
             }
         }
         if (inValue > 0)
         {
             infoServiceMaster.ServiceMasterId = decServiceMasterId;
             infoServiceMaster.SuffixPrefixId = decServiceSuffixPrefixId;
             infoServiceMaster.Date = Convert.ToDateTime(txtVoucherDate.Text);
             infoServiceMaster.LedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
             infoServiceMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
             infoServiceMaster.Narration = txtNarration.Text.Trim();
             infoServiceMaster.UserId = PublicVariables._decCurrentUserId;
             infoServiceMaster.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
             infoServiceMaster.ServiceAccount = Convert.ToDecimal(cmbServiceAC.SelectedValue.ToString());
             decimal decExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());//spExchangeRate.GetExchangeRateByCurrencyId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
             infoServiceMaster.ExchangeRateId = decExchangeRateId;
             infoServiceMaster.EmployeeId = Convert.ToDecimal(cmbSalesman.SelectedValue.ToString());
             infoServiceMaster.Customer = txtCustomer.Text.Trim();
             infoServiceMaster.Discount = Convert.ToDecimal(txtDiscount.Text);
             infoServiceMaster.GrandTotal = Convert.ToDecimal(txtGrandTotal.Text);
             infoServiceMaster.VoucherTypeId = DecServicetVoucherTypeId;
             infoServiceMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
             infoServiceMaster.ExtraDate = PublicVariables._dtCurrentDate;
             infoServiceMaster.Extra1 = string.Empty;
             infoServiceMaster.Extra2 = string.Empty;
             //------------------deleting removed rows----------------------------------------//
             BankReconciliationBll BllBankReconciliation = new BankReconciliationBll();
             foreach (object obj in strArrOfRemove)
             {
                 string str = Convert.ToString(obj);
                 BllService.ServiceDetailsDelete(Convert.ToDecimal(str));
             }
             BllService.ServiceMasterEdit(infoServiceMaster);
             infoServiceDetails.ServiceMasterId = decServiceMasterId;
             infoServiceDetails.Extra1 = string.Empty;
             infoServiceDetails.Extra2 = string.Empty;
             infoServiceDetails.ExtraDate = PublicVariables._dtCurrentDate;
             for (int i = 0; i < inRowCount - 1; i++)
             {
                 if (dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.ServiceId = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value.ToString());
                 }
                 if (dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.Measure = dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value.ToString();
                 }
                 if (dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.Amount = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                     if (dgvServiceVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value.ToString() != string.Empty)
                     {
                         infoServiceDetails.ServiceDetailsId = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value.ToString());
                         infoServiceDetails.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                         BllService.ServiceDetailsEdit(infoServiceDetails);
                     }
                     else
                     {
                         infoServiceDetails.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                         decServiceDetailsId = BllService.ServiceDetailsAddReturnWithIdentity(infoServiceDetails);
                     }
                     decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                     decAmount = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value);
                     decConvertRate += decAmount * decSelectedCurrencyRate;
                 }
             }
             decCredit = 0;
             decDebit = decConvertRate;
             decLedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
             LedgerPostingEdit(decLedgerPostingId1, decLedgerId, decCredit, decDebit);
             decCredit = decConvertRate;
             decDebit = 0;
             decLedgerId = Convert.ToDecimal(cmbServiceAC.SelectedValue.ToString());
             LedgerPostingEdit(decLedgerPostingId2, decLedgerId, decCredit, decDebit);
             AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
             decimal decI = Convert.ToDecimal(bllAccountLedger.AccountGroupIdCheck(cmbCashParty.Text));
             if (decI > 0)
             {
                 PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
                 PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                 infoPartyBalance.PartyBalanceId = decPartyBalanceId;
                 infoPartyBalance.Date = Convert.ToDateTime(txtVoucherDate.Text);
                 infoPartyBalance.LedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
                 infoPartyBalance.VoucherTypeId = DecServicetVoucherTypeId;
                 infoPartyBalance.VoucherNo = strVoucherNo;
                 infoPartyBalance.AgainstVoucherTypeId = 0;
                 infoPartyBalance.AgainstVoucherNo = "0";
                 infoPartyBalance.InvoiceNo = strInvoiceNo;
                 infoPartyBalance.AgainstInvoiceNo = "0";
                 infoPartyBalance.ReferenceType = "New";
                 infoPartyBalance.Debit = decAmount;
                 infoPartyBalance.Credit = 0;
                 infoPartyBalance.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
                 infoPartyBalance.ExchangeRateId = decExchangeRateId;
                 infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoPartyBalance.Extra1 = string.Empty;
                 infoPartyBalance.Extra2 = string.Empty;
                 BllPartyBalance.PartyBalanceEdit(infoPartyBalance);
             }
             Messages.UpdatedMessage();
             if (cbxPrintAfterSave.Checked)
             {
                 if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                 {
                     PrintForDotMatrix(decServiceMasterId);
                 }
                 else
                 {
                     Print(decServiceMasterId, infoServiceMaster.ExchangeRateId);
                 }
             }
             this.Close();
             if (frmServiceVoucherRegisterObj != null)
             {
                 frmServiceVoucherRegisterObj.Show();
                 frmServiceVoucherRegisterObj.GridFill();
             }
             else if (frmServiceReportObj != null)
             {
                 frmServiceReportObj.Show();
                 frmServiceReportObj.GridFill();
             }
         }
         else
         {
             Messages.InformationMessage("Can't save Service Voucher without atleast one ledger with complete details");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 24 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <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);
            }
        }
 /// <summary>
 /// Function to save the service voucher
 /// </summary>
 public void SaveFunction()
 {
     try
     {
         ServiceMasterInfo infoServiceMaster = new ServiceMasterInfo();
         ServiceDetailsInfo infoServiceDetails = new ServiceDetailsInfo();
         ServicesBll BllService = new ServicesBll();
         LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
         LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
         ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
         int inRowCount = dgvServiceVoucher.RowCount;
         int inValue = 0;
         for (int ini = 0; ini < inRowCount - 1; ini++)
         {
             if (dgvServiceVoucher.Rows[ini].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[ini].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
             {
                 inValue++;
             }
         }
         if (inValue > 0)
         {
             txtDiscount.Enabled = true;
             infoServiceMaster.InvoiceNo = txtInvoiceNumber.Text;
             if (isAutomatic)
             {
                 infoServiceMaster.VoucherNo = strVoucherNo;
             }
             else
             {
                 infoServiceMaster.VoucherNo = Convert.ToString(BllService.ServiceMasterGetMax(DecServicetVoucherTypeId) + 1);
             }
             infoServiceMaster.SuffixPrefixId = decServiceSuffixPrefixId;
             infoServiceMaster.Date = Convert.ToDateTime(txtVoucherDate.Text);
             infoServiceMaster.LedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
             infoServiceMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
             infoServiceMaster.Narration = txtNarration.Text.Trim();
             infoServiceMaster.UserId = PublicVariables._decCurrentUserId;
             infoServiceMaster.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
             infoServiceMaster.ServiceAccount = Convert.ToDecimal(cmbServiceAC.SelectedValue.ToString());
             decimal decExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());//spExchangeRate.GetExchangeRateByCurrencyId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
             infoServiceMaster.ExchangeRateId = decExchangeRateId;
             infoServiceMaster.EmployeeId = Convert.ToDecimal(cmbSalesman.SelectedValue.ToString());
             infoServiceMaster.Customer = txtCustomer.Text.Trim();
             infoServiceMaster.Discount = Convert.ToDecimal(txtDiscount.Text.Trim());
             infoServiceMaster.GrandTotal = Convert.ToDecimal(txtGrandTotal.Text);
             infoServiceMaster.VoucherTypeId = DecServicetVoucherTypeId;
             infoServiceMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
             infoServiceMaster.ExtraDate = PublicVariables._dtCurrentDate;
             infoServiceMaster.Extra1 = string.Empty;
             infoServiceMaster.Extra2 = string.Empty;
             decServiceMasterId = BllService.ServiceMasterAddReturnWithIdentity(infoServiceMaster);
             infoServiceDetails.ServiceMasterId = decServiceMasterId;
             infoServiceDetails.Extra1 = string.Empty;
             infoServiceDetails.Extra2 = string.Empty;
             infoServiceDetails.ExtraDate = PublicVariables._dtCurrentDate;
             for (int i = 0; i < inRowCount - 1; i++)
             {
                 if (dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.ServiceId = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value.ToString());
                 }
                 if (dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.Measure = dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value.ToString();
                 }
                 if (dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.Amount = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                     decAmount += Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value);
                 }
                 decServiceDetailsId = BllService.ServiceDetailsAddReturnWithIdentity(infoServiceDetails);
             }
             decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(infoServiceMaster.ExchangeRateId);
             decConvertRate = decAmount * decSelectedCurrencyRate;
             decCredit = 0;
             decDebit = decConvertRate;
             decLedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
             LedgerPosting(decLedgerId, decCredit, decDebit, decServiceDetailsId, infoServiceMaster.VoucherNo);
             AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
             decimal decI = Convert.ToDecimal(bllAccountLedger.AccountGroupIdCheck(cmbCashParty.Text));
             if (decI > 0)
             {
                 PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
                 PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                 infoPartyBalance.Date = Convert.ToDateTime(txtVoucherDate.Text);
                 infoPartyBalance.LedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
                 infoPartyBalance.VoucherTypeId = DecServicetVoucherTypeId;
                 infoPartyBalance.VoucherNo = strVoucherNo;
                 infoPartyBalance.AgainstVoucherTypeId = 0;
                 infoPartyBalance.AgainstVoucherNo = "0";
                 infoPartyBalance.InvoiceNo = strInvoiceNo;
                 infoPartyBalance.AgainstInvoiceNo = "0";
                 infoPartyBalance.ReferenceType = "New";
                 infoPartyBalance.Debit = decAmount;
                 infoPartyBalance.Credit = 0;
                 infoPartyBalance.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
                 infoPartyBalance.ExchangeRateId = decExchangeRateId;
                 infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoPartyBalance.Extra1 = string.Empty;
                 infoPartyBalance.Extra2 = string.Empty;
                 BllPartyBalance.PartyBalanceAdd(infoPartyBalance);
             }
             Messages.SavedMessage();
             if (cbxPrintAfterSave.Checked)
             {
                 if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                 {
                     PrintForDotMatrix(decServiceMasterId);
                 }
                 else
                 {
                     Print(decServiceMasterId, infoServiceMaster.ExchangeRateId);
                 }
             }
             Clear();
         }
         else
         {
             Messages.InformationMessage("Can't save Service Voucher without atleast one ledger with complete details");
             dgvServiceVoucher.ClearSelection();
             dgvServiceVoucher.CurrentCell = dgvServiceVoucher.Rows[0].Cells["dgvcmbParticulars"];
             dgvServiceVoucher.Rows[0].Cells["dgvcmbParticulars"].Selected = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 19 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Total amount calculation of Grid rows and the calculate the exchange rate if the currency conversion is available
 /// </summary>
 public void TotalAmount()
 {
     try
     {
         decimal decTotalAmount = 0;
         decimal decSelectedCurrencyRate = 0;
         ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
         foreach (DataGridViewRow dr in dgvContraVoucher.Rows)
         {
             if (dr.Cells["dgvtxtAmount"].Value != null && dr.Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
             {
                 if (dr.Cells["dgvcmbCurrency"].Value != null)
                 {
                     decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dr.Cells["dgvcmbCurrency"].Value.ToString()));//Exchange rate of grid's row
                     decTotalAmount = decTotalAmount + (Convert.ToDecimal(dr.Cells["dgvtxtAmount"].Value.ToString()) * decSelectedCurrencyRate);
                 }
                 else
                 {
                     decTotalAmount = decTotalAmount + Convert.ToDecimal(dr.Cells["dgvtxtAmount"].Value.ToString());
                 }
             }
         }
         txtTotal.Text = Math.Round(decTotalAmount, PublicVariables._inNoOfDecimalPlaces).ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show("CV:05" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Edit function Call the ledger posting Edit function also
        /// </summary>
        /// <param name="decMasterId"></param>
        public void EditFunction(decimal decMasterId)
        {
            try
            {
                //ContraMasterSP spContraMaster = new ContraMasterSP();
                ContraMasterInfo infoContraMaster = new ContraMasterInfo();
                //ContraDetailsSP spContraDetails = new ContraDetailsSP();
                ContraVoucherDetailsBll bllContraVoucherDetails = new ContraVoucherDetailsBll();
                ContraDetailsInfo infoCOntraDetails = new ContraDetailsInfo();
                ExchangeRateBll BllExchangeRate = new ExchangeRateBll();

                LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                decimal decContraDetailsId = 0;
                decimal decLedgerPostId = 0;
                infoContraMaster.ContraMasterId = decMasterId;
                infoContraMaster.LedgerId = Convert.ToDecimal(cmbBankAccount.SelectedValue.ToString());
                if (isAutomatic)
                {
                    infoContraMaster.VoucherNo = strVoucherNo;
                }

                if (isAutomatic)
                {
                    infoContraMaster.InvoiceNo = strInvoiceNo;
                }
                else
                {
                    infoContraMaster.InvoiceNo = txtVoucherNo.Text;
                }
                infoContraMaster.Date = Convert.ToDateTime(dtpContraVoucherDate.Text.ToString());

                infoContraMaster.Narration = txtNarration.Text.Trim();
                infoContraMaster.TotalAmount = Convert.ToDecimal(txtTotal.Text);
                if (rbtnDeposit.Checked)
                    infoContraMaster.Type = "Deposit";
                else
                    infoContraMaster.Type = "Withdraw";
                infoContraMaster.SuffixPrefixId = decContraSuffixPrefixId;
                infoContraMaster.VoucherTypeId = DecContraVoucherTypeId;
                infoContraMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                infoContraMaster.UserId = PublicVariables._decCurrentUserId;
                infoContraMaster.Extra1 = string.Empty;
                infoContraMaster.Extra2 = string.Empty;
                infoContraMaster.Date = Convert.ToDateTime(txtContraVoucherDate.Text);

                int inCount = dgvContraVoucher.RowCount;
                int inValue = 0;
                for (int i = 0; i < inCount - 1; i++)
                {

                    if (dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value != null &&
                        dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString() != null)
                    {
                        inValue++;
                    }
                }
                if (inValue > 0)
                {

                    if (Convert.ToDecimal(txtTotal.Text) != 0)
                    {
                        infoCOntraDetails.ContraMasterId = decMasterId;
                        infoCOntraDetails.Extra1 = string.Empty;
                        infoCOntraDetails.Extra2 = string.Empty;
                        //------------------deleting removed rows----------------------------------------//

                        foreach (var item in arrlstOfRemove)
                        {
                            decimal decId = Convert.ToDecimal(item);
                            bllContraVoucherDetails.ContraDetailsDelete(Convert.ToDecimal(decId));
                            BllLedgerPosting.LedgerPostDeleteByDetailsId(Convert.ToDecimal(decId), strVoucherNo, DecContraVoucherTypeId);
                        }
                        //--------------------------End---------------------------------------------------//
                        int inRowCount = dgvContraVoucher.RowCount;

                        decimal decLedgerId = 0;
                        decimal decLedger1Id = 0;
                        decimal decDebit = 0;
                        decimal decCredit = 0;

                        decLedger1Id = Convert.ToDecimal(cmbBankAccount.SelectedValue.ToString());

                        for (int i = 0; i < inRowCount; i++)
                        {
                            if (dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString() != "")
                            {
                                decLedgerId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString());
                                infoCOntraDetails.LedgerId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString());
                            }
                            if (dgvContraVoucher.Rows[i].Cells["dgvtxtChequeNo"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvtxtChequeNo"].Value.ToString() != "")
                            {
                                infoCOntraDetails.ChequeNo = dgvContraVoucher.Rows[i].Cells["dgvtxtChequeNo"].Value.ToString();
                            }
                            else
                            {
                                infoCOntraDetails.ChequeNo = string.Empty;
                            }
                            if (dgvContraVoucher.Rows[i].Cells["dgvtxtChequeDate"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvtxtChequeDate"].Value.ToString() != "")
                            {
                                infoCOntraDetails.ChequeDate = Convert.ToDateTime(dgvContraVoucher.Rows[i].Cells["dgvtxtChequeDate"].Value.ToString());
                            }
                            else
                            {
                                infoCOntraDetails.ChequeDate = Convert.ToDateTime("1/1/1753");
                            }
                            if (dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString() != "")
                            {
                                infoCOntraDetails.Amount = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                                if (dgvContraVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value.ToString() != "")
                                {
                                    infoCOntraDetails.ContraDetailsId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value.ToString());
                                    decContraDetailsId = infoCOntraDetails.ContraDetailsId;
                                    decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbCurrency"].Value.ToString()));
                                    decAmount = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                                    decConvertRate = decAmount * decSelectedCurrencyRate;
                                    if (rbtnDeposit.Checked)
                                    {
                                        decCredit = decConvertRate;
                                        decDebit = 0;
                                    }
                                    else
                                    {
                                        decDebit = decConvertRate;
                                        decCredit = 0;
                                    }
                                    infoCOntraDetails.ContraMasterId = decMasterId;
                                    infoCOntraDetails.ExchangeRateId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbCurrency"].Value.ToString());
                                    bllContraVoucherDetails.ContraDetailsEdit(infoCOntraDetails);
                                    decLedgerPostId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvtxtLedgerPostingId"].Value.ToString());
                                    LedgerPostingEdit(decLedgerPostId, decLedgerId, decCredit, decDebit, decContraDetailsId, i);
                                }
                                else
                                {
                                    infoCOntraDetails.ExchangeRateId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbCurrency"].Value.ToString());
                                    decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbCurrency"].Value.ToString()));
                                    decAmount = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                                    decConvertRate = decAmount * decSelectedCurrencyRate;
                                    if (rbtnDeposit.Checked)
                                    {
                                        decCredit = decConvertRate;
                                        decDebit = 0;
                                    }
                                    else
                                    {
                                        decDebit = decConvertRate;
                                        decCredit = 0;
                                    }
                                    decContraDetailsId = bllContraVoucherDetails.ContraDetailsAddReturnWithhIdentity(infoCOntraDetails);
                                    LedgerPosting(decLedgerId, decCredit, decDebit, decContraDetailsId, i);
                                }
                            }
                        }
                        bllContraVoucherDetails.ContraMasterEdit(infoContraMaster);
                        decLedgerPostId = BllLedgerPosting.LedgerPostingIdForTotalAmount(strVoucherNo, DecContraVoucherTypeId);
                        decAmount = Convert.ToDecimal(txtTotal.Text);
                        decContraDetailsId = 0;
                        if (rbtnDeposit.Checked)
                        {
                            decDebit = decAmount;
                            decCredit = 0;
                            LedgerPostingEdit(decLedgerPostId, decLedger1Id, decCredit, decDebit, decContraDetailsId, -1);
                        }
                        else
                        {
                            decCredit = decAmount;
                            decDebit = 0;
                            LedgerPostingEdit(decLedgerPostId, decLedger1Id, decCredit, decDebit, decContraDetailsId, -1);
                        }
                        Messages.UpdatedMessage();
                        if (cbxPrintafterSave.Checked)
                        {
                            if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decMasterId);
                            }
                            else
                            {
                                Print(decMasterId);
                            }
                        }
                        this.Close();
                    }
                    else
                    {
                        Messages.InformationMessage("Cannot save total amount as 0");
                        dgvContraVoucher.Focus();
                    }
                }
                else
                {
                    Messages.InformationMessage("Cant update contra voucher without atleast one ledger with complete details");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("CV:17" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Calculating the grand total amount calculation
 /// </summary>
 private void CalculateTotalAmount()
 {
     ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
     try
     {
         decimal decTotal = 0;
         if (dgvPurchaseOrder.RowCount > 1)
         {
             foreach (DataGridViewRow dgvrow in dgvPurchaseOrder.Rows)
             {
                 if (dgvrow.Cells["dgvtxtAmount"].Value != null && dgvrow.Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                 {
                     decimal decAmt = Convert.ToDecimal(dgvrow.Cells["dgvtxtAmount"].Value.ToString());
                     decimal decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                     decimal decRowTotal = decAmt;
                     decTotal = decTotal + decRowTotal;
                     decTotal = Math.Round(decTotal, PublicVariables._inNoOfDecimalPlaces);
                     txtTotalAmount.Text = decTotal.ToString();
                 }
             }
         }
         else
         {
             decTotal = Math.Round(decTotal, PublicVariables._inNoOfDecimalPlaces);
             txtTotalAmount.Text = decTotal.ToString();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PO22:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Save function Call the ledger posting function also
        /// </summary>
        public void SaveFuction()
        {
            try
            {
                decimal decContraDetailsId = 0;
                //ContraMasterSP spContraMaster = new ContraMasterSP();
                ContraMasterInfo infoContraMaster = new ContraMasterInfo();
                //ContraDetailsSP spContraDetails = new ContraDetailsSP();
                ContraVoucherDetailsBll bllContraVoucherDetails = new ContraVoucherDetailsBll();
                ContraDetailsInfo infoCOntraDetails = new ContraDetailsInfo();
                ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
                decimal decIdentity = 0;
                decimal decLedgerId = 0;
                decimal decDebit = 0;
                decimal decCredit = 0;
                int inCount = dgvContraVoucher.RowCount;
                int inValue = 0;
                for (int i = 0; i < inCount - 1; i++)
                {
                    if (dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value != null &&
                        dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString() != null)
                    {
                        inValue++;
                    }
                }
                if (inValue > 0)
                {
                    if (Convert.ToDecimal(txtTotal.Text) != 0)
                    {
                        infoContraMaster.LedgerId = Convert.ToDecimal(cmbBankAccount.SelectedValue.ToString());
                        if (isAutomatic)
                        {
                            infoContraMaster.VoucherNo = strVoucherNo;
                        }
                        else
                        {
                            decimal decVoucherNo = bllContraVoucherDetails.ContraVoucherMasterGetMaxPlusOne(DecContraVoucherTypeId) + 1;
                            infoContraMaster.VoucherNo = Convert.ToString(decVoucherNo);
                        }
                        infoContraMaster.Date = Convert.ToDateTime(dtpContraVoucherDate.Text.ToString());
                        infoContraMaster.Narration = txtNarration.Text.Trim();
                        infoContraMaster.TotalAmount = Convert.ToDecimal(txtTotal.Text);
                        infoContraMaster.Extra1 = string.Empty;
                        infoContraMaster.Extra2 = string.Empty;

                        if (rbtnDeposit.Checked)
                        {
                            infoContraMaster.Type = "Deposit";
                        }
                        else
                        {
                            infoContraMaster.Type = "Withdraw";
                        }
                        infoContraMaster.SuffixPrefixId = decContraSuffixPrefixId;
                        infoContraMaster.VoucherTypeId = DecContraVoucherTypeId;
                        infoContraMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                        infoContraMaster.UserId = PublicVariables._decCurrentUserId;
                        if (isAutomatic)
                        {
                            infoContraMaster.InvoiceNo = strInvoiceNo;
                        }
                        else
                        {
                            infoContraMaster.InvoiceNo = txtVoucherNo.Text;
                        }
                        decIdentity = bllContraVoucherDetails.ContraMasterAdd(infoContraMaster);
                        infoCOntraDetails.ContraMasterId = decIdentity;
                        infoCOntraDetails.Extra1 = string.Empty;
                        infoCOntraDetails.Extra2 = string.Empty;
                        int inRowCount = dgvContraVoucher.RowCount;

                        //-------------------------------Saving grid details--------------------------------------------------------------------
                        for (int i = 0; i < inRowCount - 1; i++)
                        {

                            if (dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString() != string.Empty)
                            {
                                infoCOntraDetails.LedgerId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString());
                            }
                            if (dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                            {
                                infoCOntraDetails.Amount = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                            }
                            if (dgvContraVoucher.Rows[i].Cells["dgvtxtChequeNo"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                            {
                                infoCOntraDetails.ChequeNo = dgvContraVoucher.Rows[i].Cells["dgvtxtChequeNo"].Value.ToString();
                            }
                            else
                            {
                                infoCOntraDetails.ChequeNo = string.Empty;
                            }
                            if (dgvContraVoucher.Rows[i].Cells["dgvtxtChequeDate"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                            {
                                infoCOntraDetails.ChequeDate = Convert.ToDateTime(dgvContraVoucher.Rows[i].Cells["dgvtxtChequeDate"].Value.ToString());
                            }
                            else
                            {
                                infoCOntraDetails.ChequeDate = Convert.ToDateTime("1/1/1753");
                            }
                            infoCOntraDetails.ExchangeRateId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbCurrency"].Value.ToString());
                            decContraDetailsId = bllContraVoucherDetails.ContraDetailsAddReturnWithhIdentity(infoCOntraDetails);
                            //---------------------------------------------------------Ledger Posting-----------------------------------------/---------------------------------------------------/
                            if (dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString() != string.Empty)
                            {
                                decLedgerId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString());
                            }
                            if (dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                            {
                                decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbCurrency"].Value));
                                decAmount = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                                decConvertRate = decAmount * decSelectedCurrencyRate;

                                if (rbtnDeposit.Checked)
                                {
                                    decCredit = decConvertRate;
                                    decDebit = 0;
                                    LedgerPosting(decLedgerId, decCredit, decDebit, decContraDetailsId, i);
                                }
                                else
                                {
                                    decDebit = decConvertRate;
                                    decCredit = 0;
                                    LedgerPosting(decLedgerId, decCredit, decDebit, decContraDetailsId, i);
                                }
                            }
                        }
                        decAmount = Convert.ToDecimal(txtTotal.Text);
                        decContraDetailsId = 0;
                        if (rbtnDeposit.Checked)
                        {
                            decDebit = decAmount;
                            decCredit = 0;
                            LedgerPosting(infoContraMaster.LedgerId, decCredit, decDebit, decContraDetailsId, -1);
                        }
                        else
                        {
                            decCredit = decAmount;
                            decDebit = 0;
                            LedgerPosting(infoContraMaster.LedgerId, decCredit, decDebit, decContraDetailsId, -1);
                        }
                        //------------------------------------------------------------------Ledger Posting---end---------------------------------------------------------------------//
                        Messages.SavedMessage();
                        if (cbxPrintafterSave.Checked)
                        {
                            if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decIdentity);
                            }
                            else
                            {
                                Print(decIdentity);
                            }
                        }
                        Clear();
                    }
                    else
                    {
                        Messages.InformationMessage("Cannot save total debit and credit as 0");
                        dgvContraVoucher.Focus();
                    }
                }
                else
                {
                    Messages.InformationMessage("Cant save contra voucher without atleast one ledger with complete details");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("CV:16" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }
        /// <summary>
        /// TotalAmountCalculation
        /// </summary>
        /// <returns></returns>
        public decimal TotalAmountCalculation()
        {
            decimal decTotal = 0;
            decimal decSelectedCurrencyRate = 0;
            ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
            try
            {
                for (int inI = 0; inI < dgvPaymentVoucher.RowCount - 1; inI++)
                {

                    if (dgvPaymentVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")
                    {
                        decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString()));//Exchange rate of grid's row
                        decTotal = decTotal + (Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString()) * decSelectedCurrencyRate);
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("PV16:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return decTotal;
        }
        /// <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 calculate total debit and credit
        /// </summary>
        public void DebitAndCreditTotal()
        {
            ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
            int inRowCount = dgvJournalVoucher.RowCount;
            decimal decTxtTotalDebit = 0;
            decimal decTxtTotalCredit = 0;
            try
            {
                for (int inI = 0; inI < inRowCount; inI++)
                {
                    if (dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value.ToString() != string.Empty)
                    {
                        if (dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                        {
                            if (dgvJournalVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString() != string.Empty)
                            {
                                if (dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString() != ".")
                                {
                                    if (dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value.ToString() == "Dr")
                                    {

                                        //--------Currency conversion--------------//
                                        decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString()));
                                        decAmount = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                                        decConvertRate = decAmount * decSelectedCurrencyRate;
                                        //===========================================//
                                        decTxtTotalDebit = decTxtTotalDebit + decConvertRate;

                                    }
                                    else
                                    {
                                        //--------Currency conversion--------------//
                                        decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString()));
                                        decAmount = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                                        decConvertRate = decAmount * decSelectedCurrencyRate;
                                        //===========================================//
                                        decTxtTotalCredit = decTxtTotalCredit + decConvertRate;
                                    }
                                }
                            }
                        }
                    }

                    txtDebitTotal.Text = Math.Round(decTxtTotalDebit, PublicVariables._inNoOfDecimalPlaces).ToString();
                    txtCreditTotal.Text = Math.Round(decTxtTotalCredit, Convert.ToInt16(PublicVariables._inNoOfDecimalPlaces)).ToString();

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("JV12:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Function to edit the debitnote voucher
        /// </summary>
        /// <param name="decJournalMasterId"></param>
        public void Edit(decimal decJournalMasterId)
        {
            try
            {
                JournalVoucherBll bllJournalMaster = new JournalVoucherBll();
                JournalMasterInfo infoJournalMaster = new JournalMasterInfo();
                JournalVoucherBll bllJournalDetails = new JournalVoucherBll();
                JournalDetailsInfo infoJournalDetails = new JournalDetailsInfo();
                ExchangeRateBll BllExchangeRate = new ExchangeRateBll();

                /*****************Update in JournalMaster table *************/

                decimal decTotalDebit = 0;
                decimal decTotalCredit = 0;

                infoJournalMaster.JournalMasterId = decJournalMasterId;
                infoJournalMaster.VoucherNo = strVoucherNo;
                infoJournalMaster.InvoiceNo = txtVoucherNo.Text.Trim();
                infoJournalMaster.SuffixPrefixId = decJournalSuffixPrefixId;
                infoJournalMaster.Date = Convert.ToDateTime(txtDate.Text);
                infoJournalMaster.Narration = txtNarration.Text.Trim();
                infoJournalMaster.UserId = PublicVariables._decCurrentUserId;
                infoJournalMaster.VoucherTypeId = decJournalVoucherTypeId;
                infoJournalMaster.FinancialYearId = Convert.ToDecimal(PublicVariables._decCurrentFinancialYearId.ToString());
                infoJournalMaster.ExtraDate = DateTime.Now;
                infoJournalMaster.Extra1 = string.Empty;
                infoJournalMaster.Extra2 = string.Empty;

                decTotalDebit = Convert.ToDecimal(txtDebitTotal.Text.Trim());
                decTotalCredit = Convert.ToDecimal(txtCreditTotal.Text.Trim());

                infoJournalMaster.TotalAmount = decTotalDebit;
                decimal decEffectRow = bllJournalMaster.JournalMasterEdit(infoJournalMaster);

                /**********************JournalDetails Edit********************/
                if (decEffectRow > 0)
                {
                    infoJournalDetails.JournalMasterId = decJournalMasterId;
                    infoJournalDetails.ExtraDate = DateTime.Now;
                    infoJournalDetails.Extra1 = string.Empty;
                    infoJournalDetails.Extra2 = string.Empty;

                    //-----------to delete details, LedgerPosting and bankReconciliation of removed rows--------------//
                    LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();

                    foreach (object obj in arrlstOfRemove)
                    {
                        string str = Convert.ToString(obj);
                        bllJournalDetails.JournalDetailsDelete(Convert.ToDecimal(str));
                        BllLedgerPosting.LedgerPostDeleteByDetailsId(Convert.ToDecimal(str), strVoucherNo, decJournalVoucherTypeId);
                    }
                    BllLedgerPosting.LedgerPostingDeleteByVoucherNoVoucherTypeIdAndLedgerId(strVoucherNo, decJournalVoucherTypeId, 12);
                    //=============================================================================================//

                    decimal decLedgerId = 0;
                    decimal decDebit = 0;
                    decimal decCredit = 0;
                    decimal decJournalDetailsId = 0;
                    int inRowCount = dgvJournalVoucher.RowCount;
                    for (int inI = 0; inI < inRowCount; inI++)
                    {
                        if (dgvJournalVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                        {
                            infoJournalDetails.LedgerId = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString());
                            decLedgerId = infoJournalDetails.LedgerId;
                        }
                        if (dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value.ToString() != string.Empty)
                        {
                            //------------------Currency conversion------------------//
                            decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value));
                            decAmount = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                            decConvertRate = decAmount * decSelectedCurrencyRate;
                            //======================================================//

                            if (dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value.ToString() == "Dr")
                            {
                                infoJournalDetails.Debit = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                                infoJournalDetails.Credit = 0;

                                decDebit = decConvertRate;
                                decCredit = infoJournalDetails.Credit;
                            }
                            else
                            {
                                infoJournalDetails.Credit = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                                infoJournalDetails.Debit = 0;
                                decDebit = infoJournalDetails.Debit;
                                decCredit = decConvertRate;
                            }
                            infoJournalDetails.ExchangeRateId = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString());
                            if (dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                            {
                                infoJournalDetails.ChequeNo = dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString();
                            }
                            else
                            {
                                infoJournalDetails.ChequeNo = string.Empty;
                            }
                            if (dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                            {
                                infoJournalDetails.ChequeDate = Convert.ToDateTime(dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString());
                            }
                            else
                            {
                                infoJournalDetails.ChequeDate = DateTime.Now;
                            }
                            if (dgvJournalVoucher.Rows[inI].Cells["dgvtxtDetailsId"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvtxtDetailsId"].Value.ToString() != string.Empty)
                            {
                                infoJournalDetails.JournalDetailsId = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtDetailsId"].Value.ToString());
                                bllJournalDetails.JournalDetailsEdit(infoJournalDetails);
                                PartyBalanceAddOrEdit(inI);
                                decJournalDetailsId = infoJournalDetails.JournalDetailsId;
                                decimal decLedgerPostId = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value.ToString());
                                LedgerPostingEdit(decLedgerPostId, decLedgerId, decCredit, decDebit, decJournalDetailsId, inI);

                            }
                            else
                            {
                                decJournalDetailsId = bllJournalDetails.JournalDetailsAdd(infoJournalDetails);
                                PartyBalanceAddOrEdit(inI);
                                LedgerPosting(decLedgerId, decCredit, decDebit, decJournalDetailsId, inI);
                            }

                        }

                    }
                    DeletePartyBalanceOfRemovedRow();
                    Messages.UpdatedMessage();
                    if (cbxPrintAfterSave.Checked)
                    {
                        if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                        {
                            PrintForDotMatrix(infoJournalMaster.JournalMasterId);
                        }
                        else
                        {
                            Print(infoJournalMaster.JournalMasterId);
                        }
                    }
                    if (journalRegisterObj != null)
                    {
                        this.Close();
                        journalRegisterObj.Enabled = true;
                    }
                    else if (frmJournalReportObj != null)
                    {
                        this.Close();
                        frmJournalReportObj.Enabled = true;
                    }
                    else if (frmDayBookObj != null)
                    {
                        this.Close();

                    }
                    else if (frmBillallocationObj != null)
                    {
                        this.Close();

                    }
                }
                //----------------If print after save is enable-----------------------//

                //===================================================================//
            }
            catch (Exception ex)
            {
                MessageBox.Show("JV16:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Function to Save the voucher
        /// </summary>
        public void Save()
        {
            try
            {
                decimal decTotalDebit = 0;
                decimal decTotalCredit = 0;

                decTotalDebit = Convert.ToDecimal(txtDebitTotal.Text.Trim());
                decTotalCredit = Convert.ToDecimal(txtCreditTotal.Text.Trim());

                JournalVoucherBll bllJournalMaster = new JournalVoucherBll();
                JournalVoucherBll bllJournalVoucher = new JournalVoucherBll();
                JournalMasterInfo infoJournalMaster = new JournalMasterInfo();
                JournalDetailsInfo infoJournalDetails = new JournalDetailsInfo();
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
                ExchangeRateBll BllExchangeRate = new ExchangeRateBll();

                infoJournalMaster.VoucherNo = strVoucherNo;
                infoJournalMaster.InvoiceNo = txtVoucherNo.Text;
                infoJournalMaster.SuffixPrefixId = decJournalSuffixPrefixId;
                infoJournalMaster.Date = Convert.ToDateTime(txtDate.Text);
                infoJournalMaster.Narration = txtNarration.Text.Trim();
                infoJournalMaster.UserId = PublicVariables._decCurrentUserId;
                infoJournalMaster.VoucherTypeId = decJournalVoucherTypeId;
                infoJournalMaster.FinancialYearId = Convert.ToDecimal(PublicVariables._decCurrentFinancialYearId.ToString());

                infoJournalMaster.Extra1 = string.Empty;
                infoJournalMaster.Extra2 = string.Empty;
                infoJournalMaster.ExtraDate = DateTime.Now;

                infoJournalMaster.TotalAmount = decTotalDebit;
                decimal decJournalMasterId = bllJournalMaster.JournalMasterAdd(infoJournalMaster);

                /*******************JournalDetailsAdd and LedgerPosting*************************/
                infoJournalDetails.JournalMasterId = decJournalMasterId;
                infoJournalDetails.ExtraDate = DateTime.Now;
                infoJournalDetails.Extra1 = string.Empty;
                infoJournalDetails.Extra2 = string.Empty;

                decimal decLedgerId = 0;
                decimal decDebit = 0;
                decimal decCredit = 0;
                int inRowCount = dgvJournalVoucher.RowCount;
                for (int inI = 0; inI < inRowCount - 1; inI++)
                {
                    if (dgvJournalVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                    {
                        infoJournalDetails.LedgerId = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString());
                        decLedgerId = infoJournalDetails.LedgerId;
                    }
                    if (dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value.ToString() != string.Empty)
                    {
                        if (dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                        {
                            //--------Currency conversion--------------//
                            decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString()));
                            decAmount = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                            decConvertRate = decAmount * decSelectedCurrencyRate;
                            //===========================================//
                            if (dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value.ToString() == "Dr")
                            {
                                infoJournalDetails.Debit = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                                infoJournalDetails.Credit = 0;
                                decDebit = decConvertRate;
                                decCredit = infoJournalDetails.Credit;
                            }
                            else
                            {
                                infoJournalDetails.Credit = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                                infoJournalDetails.Debit = 0;
                                decDebit = infoJournalDetails.Debit;
                                decCredit = decConvertRate;
                            }
                        }
                        infoJournalDetails.ExchangeRateId = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString());
                        if (dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                        {
                            infoJournalDetails.ChequeNo = dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString();
                        }
                        else
                        {
                            infoJournalDetails.ChequeNo = string.Empty;
                        }
                        if (dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                        {
                            infoJournalDetails.ChequeDate = Convert.ToDateTime(dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString());
                        }
                        else
                        {
                            infoJournalDetails.ChequeDate = DateTime.Now;
                        }
                        decimal decJournalDetailsId = bllJournalVoucher.JournalDetailsAdd(infoJournalDetails);
                        if (decJournalDetailsId != 0)
                        {
                            PartyBalanceAddOrEdit(inI);
                            LedgerPosting(decLedgerId, decCredit, decDebit, decJournalDetailsId, inI);
                        }
                    }

                }

                Messages.SavedMessage();

                //----------------If print after save is enable-----------------------//
                if (cbxPrintAfterSave.Checked)
                {
                    if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                    {
                        PrintForDotMatrix(decJournalMasterId);
                    }
                    else
                    {
                        Print(decJournalMasterId);
                    }
                }

                //===================================================================//
            }
            catch (Exception ex)
            {
                MessageBox.Show("JV14:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Function for ledger posting
        /// </summary>
        /// <param name="decId"></param>
        /// <param name="decCredit"></param>
        /// <param name="decDebit"></param>
        /// <param name="decDetailsId"></param>
        /// <param name="inA"></param>
        public void LedgerPosting(decimal decId, decimal decCredit, decimal decDebit, decimal decDetailsId, int inA)
        {
            LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
            LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
            ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
            decimal decOldExchange = 0;
            decimal decNewExchangeRate = 0;
            decimal decNewExchangeRateId = 0;
            decimal decOldExchangeId = 0;
            try
            {

                if (!dgvCreditNote.Rows[inA].Cells["dgvtxtAmount"].ReadOnly)
                {
                    infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.VoucherTypeId = decCreditNoteVoucherTypeId;
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.DetailsId = decDetailsId;
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.InvoiceNo = txtVoucherNo.Text.Trim();

                    if (dgvCreditNote.Rows[inA].Cells["dgvtxtChequeNo"].Value != null && dgvCreditNote.Rows[inA].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                    {
                        infoLedgerPosting.ChequeNo = dgvCreditNote.Rows[inA].Cells["dgvtxtChequeNo"].Value.ToString();
                        if (dgvCreditNote.Rows[inA].Cells["dgvtxtChequeDate"].Value != null && dgvCreditNote.Rows[inA].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                        {
                            infoLedgerPosting.ChequeDate = Convert.ToDateTime(dgvCreditNote.Rows[inA].Cells["dgvtxtChequeDate"].Value.ToString());
                        }
                        else
                            infoLedgerPosting.ChequeDate = DateTime.Now;

                    }
                    else
                    {
                        infoLedgerPosting.ChequeNo = string.Empty;
                        infoLedgerPosting.ChequeDate = DateTime.Now;
                    }

                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;

                    infoLedgerPosting.LedgerId = decId;
                    infoLedgerPosting.Credit = decCredit;
                    infoLedgerPosting.Debit = decDebit;

                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                }
                else
                {
                    infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.VoucherTypeId = decCreditNoteVoucherTypeId;
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.DetailsId = decDetailsId;
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.InvoiceNo = txtVoucherNo.Text.Trim();

                    if (dgvCreditNote.Rows[inA].Cells["dgvtxtChequeNo"].Value != null && dgvCreditNote.Rows[inA].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                    {
                        infoLedgerPosting.ChequeNo = dgvCreditNote.Rows[inA].Cells["dgvtxtChequeNo"].Value.ToString();
                        if (dgvCreditNote.Rows[inA].Cells["dgvtxtChequeDate"].Value != null && dgvCreditNote.Rows[inA].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                        {
                            infoLedgerPosting.ChequeDate = Convert.ToDateTime(dgvCreditNote.Rows[inA].Cells["dgvtxtChequeDate"].Value.ToString());
                        }
                        else
                            infoLedgerPosting.ChequeDate = DateTime.Now;

                    }
                    else
                    {
                        infoLedgerPosting.ChequeNo = string.Empty;
                        infoLedgerPosting.ChequeDate = DateTime.Now;
                    }

                    infoLedgerPosting.ExtraDate = DateTime.Now;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    infoLedgerPosting.LedgerId = decId;

                    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);

                        }
                    }

                    if (decCredit == 0)
                    {
                        infoLedgerPosting.Credit = 0;
                        infoLedgerPosting.Debit = decConvertRate;
                    }
                    else
                    {
                        infoLedgerPosting.Debit = 0;
                        infoLedgerPosting.Credit = decConvertRate;
                    }

                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);

                    infoLedgerPosting.LedgerId = 12;
                    foreach (DataRow dr in dtblPartyBalance.Rows)
                    {
                        if (Convert.ToDecimal(dgvCreditNote.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 (dr["DebitOrCredit"].ToString() == "Dr")
                                {
                                    if (decForexAmount >= 0)
                                    {

                                        infoLedgerPosting.Debit = decForexAmount;
                                        infoLedgerPosting.Credit = 0;
                                    }
                                    else
                                    {
                                        infoLedgerPosting.Credit = -1 * decForexAmount;
                                        infoLedgerPosting.Debit = 0;
                                    }
                                }
                                else
                                {
                                    if (decForexAmount >= 0)
                                    {

                                        infoLedgerPosting.Credit = decForexAmount;
                                        infoLedgerPosting.Debit = 0;
                                    }
                                    else
                                    {
                                        infoLedgerPosting.Debit = -1 * decForexAmount;
                                        infoLedgerPosting.Credit = 0;
                                    }
                                }
                                BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                            }
                        }

                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("CRNT:18" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to calculate total amount
 /// </summary>
 public void TotalAmount()
 {
     ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
     try
     {
         decimal decTotalAmount = 0;
         int inRowCount = dgvPartyBalance.RowCount;
         if (inRowCount > 1)
         {
             decimal decSelectedCurrencyRate = 0;
             foreach (DataGridViewRow dr in dgvPartyBalance.Rows)
             {
                 if (dr.Cells["dgvtxtAmount"].Value != null && dr.Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                 {
                     if (dr.Cells["dgvtxtAmount"].Value.ToString() != ".")
                     {
                         if (dr.Cells["dgvcmbCurrency"].Value != null && dr.Cells["dgvcmbCurrency"].Value.ToString() != string.Empty && Convert.ToDecimal(dr.Cells["dgvcmbCurrency"].Value.ToString())!=0)
                         {
                             decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dr.Cells["dgvcmbCurrency"].Value.ToString()));//Exchange rate of grid's row
                             decTotalAmount = decTotalAmount + (Convert.ToDecimal(dr.Cells["dgvtxtAmount"].Value.ToString()) * decSelectedCurrencyRate);
                         }
                         else
                         {
                             decTotalAmount = decTotalAmount + Convert.ToDecimal(dr.Cells["dgvtxtAmount"].Value.ToString());
                         }
                     }
                 }
             }
             txtTotalAmount.Text = Math.Round(decTotalAmount, Convert.ToInt32(PublicVariables._inNoOfDecimalPlaces.ToString())).ToString();
         }
         else
         {
             decTotalAmount = 0;
             txtTotalAmount.Text = Math.Round(decTotalAmount, Convert.ToInt32(PublicVariables._inNoOfDecimalPlaces.ToString())).ToString();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PB:6" + ex.Message, "Open Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// On cellLeave of dgvProduct
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvProduct_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            BatchBll BllBatch = new BatchBll();
            PurchaseOrderBll BllPurchaseOrder = new PurchaseOrderBll();

            try
            {
                if (isValueChange)
                {
                    string strBarcode = string.Empty;
                    string strProductCode = string.Empty;
                    if (e.RowIndex > -1 && e.ColumnIndex > -1)
                    {
                        CheckInvalidEntries(e);
                        if (e.ColumnIndex == dgvProduct.Columns["dgvcmbBatch"].Index)
                        {
                            if (dgvProduct.Rows[e.RowIndex].Cells["productId"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["productId"].Value.ToString() != string.Empty)
                            {
                                if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
                                {
                                    if (Convert.ToString(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value) != string.Empty &&
                                       Convert.ToString(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value) != "0")
                                    {
                                        decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value);
                                        strProductCode = dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString();
                                        strBarcode = BllBatch.ProductBatchBarcodeViewByBatchId(decBatchId);
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = strBarcode;
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = strProductCode;
                                    }
                                }
                            }
                        }
                        else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit")
                        {
                            if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() != string.Empty)
                            {
                                UnitConvertionBll bllUnitByProduct = new UnitConvertionBll();
                                List<DataTable> listUnitByProduct = new List<DataTable>();
                                listUnitByProduct = bllUnitByProduct.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value.ToString());
                                foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows)
                                {
                                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                                    {
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                                        if (isDoAfterGridFill)
                                        {
                                            decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                                            decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate;
                                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, 2);
                                            NewAmountCalculation("dgvtxtQty", e.RowIndex);
                                            CalculateTotalAmount();
                                        }
                                    }
                                }
                                CheckInvalidEntries(e);
                            }
                        }
                        else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbGodown")
                        {
                            if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value.ToString() != string.Empty)
                            {
                                decGodownId = Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvcmbGodown"].Value);
                                RackComboFill(decGodownId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].ColumnIndex);
                                List<DataTable> listObj = new List<DataTable>();
                                RackBll BllRack = new RackBll();
                                listObj = BllRack.RackNamesCorrespondingToGodownId(decGodownId);
                                dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = Convert.ToDecimal(listObj[0].Rows[0]["rackId"].ToString());
                            }
                            CheckInvalidEntries(e);
                        }
                        else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvCmbCurrency" && isAmountcalc)
                        {
                            ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
                            if (dgvProduct.Rows[e.RowIndex].Cells["dgvCmbCurrency"].Value != null && Convert.ToString(dgvProduct.Rows[e.RowIndex].Cells["dgvCmbCurrency"].Value) != string.Empty)
                            {
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtExchangeRate"].Value = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(Convert.ToString(dgvProduct.Rows[e.RowIndex].Cells["dgvCmbCurrency"].Value)));
                            }
                            else
                            {
                                dgvProduct.Rows[e.RowIndex].Cells["dgvCmbCurrency"].Value = BllPurchaseOrder.ExchangeRateIdByCurrencyId(PublicVariables._decCurrencyId);
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtExchangeRate"].Value = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(Convert.ToString(dgvProduct.Rows[e.RowIndex].Cells["dgvCmbCurrency"].Value)));
                            }
                            CheckInvalidEntries(e);
                        }
                        //----------while changing Qty,corresponding change in amount--------
                        else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtQty" && isAmountcalc)
                        {
                            if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value != null)
                            {
                                if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value.ToString() != string.Empty)
                                {
                                    NewAmountCalculation("dgvtxtQty", e.RowIndex);
                                    CalculateTotalAmount();
                                }
                            }
                            CheckInvalidEntries(e);
                        }
                        //---------------while changing Qty,corresponding change in amount----
                        else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtRate" && isAmountcalc)
                        {
                            NewAmountCalculation("dgvtxtRate", e.RowIndex);
                            CalculateTotalAmount();
                            CheckInvalidEntries(e);
                        }
                        //----while changing amount ,corresponding chnage in total amount-------
                        else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtAmount" && isAmountcalc)
                        {
                            if (cmbcurrency.Text != string.Empty)
                            {
                                CalculateTotalAmount();
                            }
                        }
                        //}
                    }
                }
                CheckInvalidEntries(e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("MR72:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Ledger posting save function
        /// </summary>
        public void LedgerPosting()
        {
            try
            {
                LedgerPostingInfo InfoPosting = new LedgerPostingInfo();
                LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                AccountLedgerBll bllAcoountLedger = new AccountLedgerBll();
                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;
                if (!btnAgainstRef.Enabled)
                {

                    infoLedgerPosting.VoucherTypeId = decPDCpayableVoucherTypeId;
                    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 = Convert.ToDecimal(txtAmount.Text.ToString());
                    infoLedgerPosting.Credit = 0;
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtChequeDate.Text);
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);

                }
                else
                {
                    infoLedgerPosting.VoucherTypeId = decPDCpayableVoucherTypeId;
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.LedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString());
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.Credit = 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.Debit = decConvertRate;
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtChequeDate.Text);
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    BllLedgerPosting.LedgerPostingAdd(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.Debit = decForexAmount;
                                    infoLedgerPosting.Credit = 0;
                                }
                                else
                                {
                                    infoLedgerPosting.Credit = -1 * decForexAmount;
                                    infoLedgerPosting.Debit = 0;
                                }
                                BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                            }
                        }

                    }
                }
                infoLedgerPosting.LedgerId = 6;
                infoLedgerPosting.VoucherNo = strVoucherNo;
                infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                infoLedgerPosting.Debit = 0;
                infoLedgerPosting.Credit = Convert.ToDecimal(txtAmount.Text);
                infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtChequeDate.Text);
                infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                infoLedgerPosting.Extra1 = string.Empty;
                infoLedgerPosting.Extra2 = string.Empty;
                BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
            }
            catch (Exception ex)
            {
                MessageBox.Show("PP16:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }