/// <summary>
 /// Party balance Add function, here adding the balance amount into the party balance table
 /// </summary>
 public void PartyBalanceAddOrEdit()
 {
     int inTableRowCount = dtblPartyBalance.Rows.Count;
     PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
     PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
     try
     {
         InfopartyBalance.CreditPeriod = 0;
         InfopartyBalance.Date = dtpVoucherDate.Value;
         InfopartyBalance.LedgerId = Convert.ToDecimal(strledgerId);
         InfopartyBalance.ReferenceType = "New";
         InfopartyBalance.VoucherTypeId = decPDCclearanceVoucherTypeId;
         InfopartyBalance.InvoiceNo = txtvoucherNo.Text.ToString();
         InfopartyBalance.VoucherNo = strVoucherNo;
         InfopartyBalance.AgainstInvoiceNo = "0";
         InfopartyBalance.AgainstVoucherNo = "0";
         InfopartyBalance.AgainstVoucherTypeId = 0;
         InfopartyBalance.Extra1 = string.Empty;
         InfopartyBalance.Extra2 = string.Empty;
         InfopartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         InfopartyBalance.ExchangeRateId = 1;
         if (strVoucherType == "PDC Payable")
         {
             InfopartyBalance.Debit = 0;
             InfopartyBalance.Credit = Convert.ToDecimal(txtAmount.Text.ToString());
             BllPartyBalance.PartyBalanceAdd(InfopartyBalance);
         }
         else if (strVoucherType == "PDC Receivable")
         {
             InfopartyBalance.Debit = Convert.ToDecimal(txtAmount.Text.ToString());
             InfopartyBalance.Credit = 0;
             BllPartyBalance.PartyBalanceAdd(InfopartyBalance);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PC13:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// To fill combo with all ledgers to whome interest enabled is true
 /// </summary>
 public void FillInterestEnabledLedgersCombo()
 {
     try
     {
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         List<DataTable> listCashOrParty = BllPartyBalance.AccountLedgerGetByDebtorAndCreditorWithBalance();
         DataRow dr1 = listCashOrParty[0].NewRow();
         dr1["ledgerName"] = "All";
         dr1["ledgerId"] = 0;
         listCashOrParty[0].Rows.InsertAt(dr1, 0);
         cmbLedger.DataSource = listCashOrParty[0];
         cmbLedger.DisplayMember = "ledgerName";
         cmbLedger.ValueMember = "ledgerId";
     }
     catch (Exception ex)
     {
         MessageBox.Show("AR2:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <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>
 /// Delete Function, Checking the References and Check other forms are opend or not
 /// </summary>
 /// <param name="decPDCReceivableMasterId"></param>
 public void DeleteFunction(decimal decPDCReceivableMasterId)
 {
     try
     {
         PDCRecivebleBll BllPdcRecieveble = new PDCRecivebleBll();
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
         if (!BllPartyBalance.PartyBalanceCheckReference(decPDCReceivableVoucherTypeId, strVoucherNo))
         {
             BllPdcRecieveble.PDCReceivableDeleteMaster(decPDCReceivableMasterId, decPDCReceivableVoucherTypeId, strVoucherNo);
             Messages.DeletedMessage();
         }
         else
         {
             Messages.InformationMessage("Reference exist. Cannot delete");
             txtVoucherDate.Focus();
         }
         if (PDCReceivableRegisterObj != null)
         {
             this.Close();
             PDCReceivableRegisterObj.Show();
         }
         else if (PDCReceivableReportObj != null)
         {
             this.Close();
             PDCReceivableReportObj.Show();
         }
         else if (frmLedgerDetailsObj != null)
         {
             this.Close();
             frmLedgerDetailsObj.Show();
         }
         else if (objVoucherSearch != null)
         {
             this.Close();
             objVoucherSearch.GridFill();
         }
         else
         {
             ClearFunction();
         }
         if (frmDayBookObj != null)
         {
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PR20:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Party balance Update function
 /// </summary>
 /// <param name="decPartyBalanceId"></param>
 /// <param name="inJ"></param>
 public void PartyBalanceEdit(decimal decPartyBalanceId, int inJ)
 {
     PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
     PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
     try
     {
         InfopartyBalance.PartyBalanceId = decPartyBalanceId;
         InfopartyBalance.CreditPeriod = 0;//
         InfopartyBalance.Date = dtpVoucherDate.Value;
         InfopartyBalance.LedgerId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["LedgerId"].ToString());
         InfopartyBalance.ReferenceType = dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString();
         if (dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString() == "New" || dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString() == "OnAccount")
         {
             InfopartyBalance.AgainstInvoiceNo = dtblPartyBalance.Rows[inJ]["AgainstInvoiceNo"].ToString();
             InfopartyBalance.AgainstVoucherNo = dtblPartyBalance.Rows[inJ]["AgainstVoucherNo"].ToString();
             InfopartyBalance.AgainstVoucherTypeId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["AgainstVoucherTypeId"].ToString());//decPaymentVoucherTypeId;
             InfopartyBalance.VoucherTypeId = decPDCReceivableVoucherTypeId;
             InfopartyBalance.InvoiceNo = strInvoiceNo;
             InfopartyBalance.VoucherNo = strVoucherNo;
         }
         else
         {
             InfopartyBalance.ExchangeRateId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["OldExchangeRate"].ToString());
             InfopartyBalance.AgainstInvoiceNo = strInvoiceNo;
             InfopartyBalance.AgainstVoucherNo = strVoucherNo;
             InfopartyBalance.AgainstVoucherTypeId = decPDCReceivableVoucherTypeId;
             InfopartyBalance.VoucherTypeId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["AgainstVoucherTypeId"].ToString());
             InfopartyBalance.VoucherNo = dtblPartyBalance.Rows[inJ]["AgainstVoucherNo"].ToString();
             InfopartyBalance.InvoiceNo = dtblPartyBalance.Rows[inJ]["AgainstInvoiceNo"].ToString();
         }
         InfopartyBalance.Credit = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["Amount"].ToString());
         InfopartyBalance.Debit = 0;
         InfopartyBalance.ExchangeRateId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["CurrencyId"].ToString());
         InfopartyBalance.Extra1 = string.Empty;
         InfopartyBalance.Extra2 = string.Empty;
         InfopartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         BllPartyBalance.PartyBalanceEdit(InfopartyBalance);
     }
     catch (Exception ex)
     {
         MessageBox.Show("PR14:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Delete function, deleting all are the details here
 /// </summary>
 /// <param name="SalesMasterId"></param>
 public void DeleteFunction(decimal SalesMasterId)
 {
     //SalesMasterSP spSalesMaster = new SalesMasterSP();
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     try
     {
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         if (!BllSalesInvoice.SalesReturnCheckReferenceForSIDelete(decSalesInvoiceIdToEdit))
         {
             if (!BllPartyBalance.PartyBalanceCheckReference(DecSalesInvoiceVoucherTypeId, strVoucherNo))
             {
                 BllSalesInvoice.SalesInvoiceDelete(decSalesInvoiceIdToEdit, DecSalesInvoiceVoucherTypeId, strVoucherNo);
                 Messages.DeletedMessage();
                 if (frmSalesinvoiceRegisterObj != null)
                 {
                     this.Close();
                     frmSalesinvoiceRegisterObj.Enabled = true;
                 }
                 else if (frmSalesReportObj != null)
                 {
                     this.Close();
                     frmSalesReportObj.Enabled = true;
                 }
                 else if (objVoucherSearch != null)
                 {
                     this.Close();
                     objVoucherSearch.GridFill();
                 }
                 else if (frmDayBookObj != null)
                 {
                     this.Close();
                 }
                 else if (frmledgerDetailsObj != null)
                 {
                     this.Close();
                 }
                 else
                 {
                     Clear();
                 }
             }
             else
             {
                 Messages.InformationMessage("Reference exist. Cannot delete");
                 txtDate.Focus();
             }
         }
         else
         {
             Messages.InformationMessage("Reference exist. Cannot delete");
             txtDate.Focus();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 85" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Function to fill the grid based on the Search keys
        /// </summary>
        public void BillAllocationGridFill()
        {
            try
            {
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                if (cmbAccountGroup.SelectedIndex > -1 && cmbAccountLedger.SelectedIndex > -1)
                {
                    if (cmbAccountGroup.SelectedItem.ToString() != "System.Data.DataRowView" || cmbAccountGroup.Text != "System.Data.DataRowView" && cmbAccountLedger.SelectedItem.ToString() != "System.Data.DataRowView" || cmbAccountLedger.Text != "System.Data.DataRowView")
                    {
                        if (Convert.ToDateTime(txtfromdate.Text) <= Convert.ToDateTime(txttodate.Text))
                        {
                            List<DataTable> listObj = new List<DataTable>();
                            listObj = BllPartyBalance.BillAllocationSearch(Convert.ToDateTime(txtfromdate.Text), Convert.ToDateTime(txttodate.Text), cmbAccountGroup.Text, cmbAccountLedger.Text);
                            dgvBillAllocation.DataSource = listObj[0];
                        }
                        else
                        {

                            Messages.InformationMessage("Fromdate should be less than or equal to todate");
                            txttodate.Focus();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("BA:06" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// function to delete voucher
        /// </summary>
        /// <param name="decJournalMasterId"></param>
        public void DeleteFunction(decimal decJournalMasterId)
        {
            try
            {
                JournalVoucherBll bllJournalMaster = new JournalVoucherBll();
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();

                if (!BllPartyBalance.PartyBalanceCheckReference(decJournalVoucherTypeId, strVoucherNo))
                {
                    bllJournalMaster.JournalVoucherDelete(decJournalMasterId, decJournalVoucherTypeId, strVoucherNo);

                    Messages.DeletedMessage();
                    if (journalRegisterObj != null)
                    {
                        this.Close();
                        journalRegisterObj.Enabled = true;
                    }
                    else if (frmJournalReportObj != null)
                    {
                        this.Close();
                        frmJournalReportObj.Enabled = true;
                    }
                    else if (frmLedgerDetailsObj != null)
                    {
                        this.Close();
                    }
                    else if (objVoucherSearch != null)
                    {
                        this.Close();
                        objVoucherSearch.GridFill();
                    }
                    else if (frmDayBookObj != null)
                    {
                        this.Close();
                    }
                    else if (frmBillallocationObj != null)
                    {
                        this.Close();
                    }
                    else
                    {
                        clear();
                    }
                }
                else
                {
                    Messages.InformationMessage("Reference exist. Cannot delete");
                    txtDate.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("JV19:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Grid Fill function while coming from other form to update or delete
 /// </summary>
 public void FillFunction()
 {
     try
     {
         //PaymentMasterSP SpPaymentMaster = new PaymentMasterSP();
         PaymentMasterInfo InfoPaymentMaster = new PaymentMasterInfo();
         //PaymentDetailsSP SpPaymentDetails = new PaymentDetailsSP();
         PaymentVoucherBll BllPaymentVoucher = new PaymentVoucherBll();
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
         VoucherTypeBll BllVoucherType = new VoucherTypeBll();
         AccountGroupBll bllAccountGroup = new AccountGroupBll();
         AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
         InfoPaymentMaster = BllPaymentVoucher.PaymentMasterViewByMasterId(decPaymentmasterId);//view master details
         isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(InfoPaymentMaster.VoucherTypeId);
         if (isAutomatic)
         {
             txtVoucherNo.ReadOnly = true;
             txtVoucherNo.Text = InfoPaymentMaster.InvoiceNo;
             txtDate.Focus();
         }
         else
         {
             txtVoucherNo.ReadOnly = false;
             txtVoucherNo.Text = InfoPaymentMaster.InvoiceNo;
             txtVoucherNo.Focus();
         }
         dtpDate.Text = InfoPaymentMaster.Date.ToString();
         cmbBankorCash.SelectedValue = InfoPaymentMaster.LedgerId;
         txtNarration.Text = InfoPaymentMaster.Narration;
         txtTotal.Text = InfoPaymentMaster.TotalAmount.ToString();
         decDailySuffixPrefixId = InfoPaymentMaster.SuffixPrefixId;
         decPaymentVoucherTypeId = InfoPaymentMaster.VoucherTypeId;
         strVoucherNo = InfoPaymentMaster.VoucherNo;
         strInvoiceNo = InfoPaymentMaster.InvoiceNo;
         //DataTable dtbl = new DataTable();
         List<DataTable> listObj1 = new List<DataTable>();
         listObj1 = BllPaymentVoucher.PaymentDetailsViewByMasterId(decPaymentmasterId);//view details details
         for (int inI = 0; inI < listObj1[0].Rows.Count; inI++)
         {
             dgvPaymentVoucher.Rows.Add();
             dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value = Convert.ToDecimal(listObj1[0].Rows[inI]["ledgerId"].ToString());
             dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentMasterId"].Value = listObj1[0].Rows[inI]["paymentMasterId"].ToString();
             dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].Value = listObj1[0].Rows[inI]["paymentDetailsId"].ToString();
             dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].Value = listObj1[0].Rows[inI]["amount"].ToString();
             dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(listObj1[0].Rows[inI]["exchangeRateId"].ToString());
             decimal decDetailsId1 = Convert.ToDecimal(listObj1[0].Rows[inI]["paymentDetailsId"].ToString());
             decimal decLedgerPostingId = BllLedgerPosting.LedgerPostingIdFromDetailsId(decDetailsId1, strVoucherNo, decPaymentVoucherTypeId);
             dgvPaymentVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value = decLedgerPostingId.ToString();
             decimal decLedgerId = Convert.ToDecimal(listObj1[0].Rows[inI]["ledgerId"].ToString());
             bool IsBankAccount = bllAccountGroup.AccountGroupwithLedgerId(decLedgerId);
             decimal decI = Convert.ToDecimal(bllAccountLedger.AccountGroupIdCheck(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].FormattedValue.ToString()));
             if (decI > 0)//to make amount and currency read only when party is choosen as ledger
             {
                 dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].ReadOnly = true;
                 dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].ReadOnly = true;
             }
             else
             {
                 dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].ReadOnly = false;
                 dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].ReadOnly = false;
             }
             dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value = listObj1[0].Rows[inI]["ChequeNo"].ToString();
             if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
             {
                 dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value = Convert.ToDateTime(listObj1[0].Rows[inI]["ChequeDate"].ToString()).ToString("dd-MMM-yyyy");
             }
             dgvPaymentVoucher.Rows[inI].HeaderCell.Value = string.Empty;
         }
         List<DataTable> listObj = new List<DataTable>();
         listObj = BllPartyBalance.PartyBalanceViewByVoucherNoAndVoucherType(decPaymentVoucherTypeId, strVoucherNo, InfoPaymentMaster.Date);
         dtblPartyBalance = listObj[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("PV36:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Function to save partybalance
        /// </summary>
        /// <param name="inRowIndex"></param>
        /// <param name="inJ"></param>
        public void PartyBalanceAdd(int inRowIndex, int inJ)
        {
            int inTableRowCount = dtblPartyBalance.Rows.Count;
            PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
            PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
            try
            {
                InfopartyBalance.CreditPeriod = 0;//
                InfopartyBalance.Date = dtpVoucherDate.Value;
                InfopartyBalance.LedgerId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["LedgerId"].ToString());
                InfopartyBalance.ReferenceType = dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString();
                if (dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString() == "New" || dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString() == "OnAccount")
                {
                    InfopartyBalance.AgainstInvoiceNo = "0";// dtblPartyBalance.Rows[inJ]["AgainstInvoiceNo"].ToString();
                    InfopartyBalance.AgainstVoucherNo = "0";// dtblPartyBalance.Rows[inJ]["AgainstVoucherNo"].ToString();
                    InfopartyBalance.AgainstVoucherTypeId = 0;// Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["AgainstVoucherTypeId"].ToString());//decPaymentVoucherTypeId;
                    InfopartyBalance.VoucherTypeId = decJournalVoucherTypeId;
                    InfopartyBalance.InvoiceNo = strInvoiceNo;
                    InfopartyBalance.VoucherNo = strVoucherNo;
                }
                else
                {
                    InfopartyBalance.ExchangeRateId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["OldExchangeRate"].ToString());
                    InfopartyBalance.AgainstInvoiceNo = strInvoiceNo;
                    InfopartyBalance.AgainstVoucherNo = strVoucherNo;
                    InfopartyBalance.AgainstVoucherTypeId = decJournalVoucherTypeId;
                    InfopartyBalance.VoucherTypeId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["AgainstVoucherTypeId"].ToString());
                    InfopartyBalance.VoucherNo = dtblPartyBalance.Rows[inJ]["AgainstVoucherNo"].ToString();
                    InfopartyBalance.InvoiceNo = dtblPartyBalance.Rows[inJ]["AgainstInvoiceNo"].ToString();
                }
                if (dgvJournalVoucher.Rows[inRowIndex].Cells["dgvcmbDrOrCr"].Value.ToString() == "Dr")
                {
                    InfopartyBalance.Debit = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["Amount"].ToString());
                    InfopartyBalance.Credit = 0;
                }
                else
                {
                    InfopartyBalance.Credit = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["Amount"].ToString());
                    InfopartyBalance.Debit = 0;
                }
                InfopartyBalance.ExchangeRateId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["CurrencyId"].ToString());
                InfopartyBalance.Extra1 = string.Empty;
                InfopartyBalance.Extra2 = string.Empty;
                InfopartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                BllPartyBalance.PartyBalanceAdd(InfopartyBalance);

            }
            catch (Exception ex)
            {
                MessageBox.Show("JV22:" + 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 to fill the fields for edit or delete
        /// </summary>
        public void FillFunction()
        {
            try
            {
                JournalMasterInfo infoJournalMaster = new JournalMasterInfo();
                JournalVoucherBll bllJournalMaster = new JournalVoucherBll();
                infoJournalMaster = bllJournalMaster.JournalMasterView(decJournalMasterIdForEdit);

                VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
                VoucherTypeBll BllVoucherType = new VoucherTypeBll();
                infoVoucherType = BllVoucherType.VoucherTypeView(infoJournalMaster.VoucherTypeId);
                this.Text = infoVoucherType.VoucherTypeName;

                txtVoucherNo.ReadOnly = false;
                strVoucherNo = infoJournalMaster.VoucherNo;
                strInvoiceNo = infoJournalMaster.InvoiceNo;
                txtVoucherNo.Text = strInvoiceNo;
                decJournalSuffixPrefixId = infoJournalMaster.SuffixPrefixId;
                decJournalVoucherTypeId = infoJournalMaster.VoucherTypeId;
                dtpVoucherDate.Value = infoJournalMaster.Date;
                txtNarration.Text = infoJournalMaster.Narration;

                isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(decJournalVoucherTypeId);
                if (isAutomatic)
                {
                    txtVoucherNo.ReadOnly = true;
                }
                else
                {
                    txtVoucherNo.ReadOnly = false;
                }

                //GridFill
                List<DataTable> ListObj = new List<DataTable>();
                JournalVoucherBll bllJournalDetailsSp = new JournalVoucherBll();
                ListObj = bllJournalDetailsSp.JournalDetailsViewByMasterId(decJournalMasterIdForEdit);
                AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
                LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                for (int inI = 0; inI < ListObj[0].Rows.Count; inI++)
                {
                    dgvJournalVoucher.Rows.Add();
                    dgvJournalVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value = Convert.ToDecimal(ListObj[0].Rows[inI]["ledgerId"].ToString());

                    if (Convert.ToDecimal(ListObj[0].Rows[inI]["debit"].ToString()) == 0)
                    {
                        dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value = "Cr";
                        dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value = Convert.ToDecimal(ListObj[0].Rows[inI]["credit"].ToString());
                    }
                    else
                    {
                        dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value = "Dr";
                        dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value = Convert.ToDecimal(ListObj[0].Rows[inI]["debit"].ToString());
                    }
                    dgvJournalVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(ListObj[0].Rows[inI]["exchangeRateId"].ToString());
                    if (ListObj[0].Rows[inI]["chequeNo"].ToString() != string.Empty)
                    {
                        dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value = ListObj[0].Rows[inI]["chequeNo"].ToString();
                        dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value = (Convert.ToDateTime(ListObj[0].Rows[inI]["chequeDate"].ToString())).ToString("dd-MMM-yyyy");
                    }
                    dgvJournalVoucher.Rows[inI].Cells["dgvtxtDetailsId"].Value = ListObj[0].Rows[inI]["journalDetailsId"].ToString();

                    decimal decDetailsId1 = Convert.ToDecimal(ListObj[0].Rows[inI]["journalDetailsId"].ToString());
                    decimal decLedgerPostingId = BllLedgerPosting.LedgerPostingIdFromDetailsId(decDetailsId1, strVoucherNo, decJournalVoucherTypeId);
                    dgvJournalVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value = decLedgerPostingId.ToString();
                    btnSave.Text = "Update";

                }

                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                List<DataTable> listObj = new List<DataTable>();
                listObj = BllPartyBalance.PartyBalanceViewByVoucherNoAndVoucherType(decJournalVoucherTypeId, strVoucherNo, infoJournalMaster.Date);

                dtblPartyBalance = listObj[0];
                dgvJournalVoucher.ClearSelection();
                txtDate.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show("JV37:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to save values to partyBalance table
 /// </summary>
 public void partyBalance()
 {
     try
     {
         PartyBalanceInfo infoPatryBalance = new PartyBalanceInfo();
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
         ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
         if (decOpeningBlnc > 0)
         {
             if (cmbBillbyBill.Text == "Yes")
             {
                 infoPatryBalance.Date = PublicVariables._dtFromDate;
                 infoPatryBalance.LedgerId = decledgerid;
                 infoPatryBalance.VoucherTypeId = 1;
                 infoPatryBalance.VoucherNo = decledgerid.ToString();
                 infoPatryBalance.AgainstVoucherTypeId = 0;
                 infoPatryBalance.AgainstVoucherNo = "0";
                 infoPatryBalance.ReferenceType = "New";
                 if (cmbDrorCr.Text == "Dr")
                 {
                     infoPatryBalance.Debit = decOpeningBlnc;
                     infoPatryBalance.Credit = 0;
                 }
                 else
                 {
                     infoPatryBalance.Debit = 0;
                     infoPatryBalance.Credit = decOpeningBlnc;
                 }
                 infoPatryBalance.InvoiceNo = decledgerid.ToString();
                 infoPatryBalance.AgainstInvoiceNo = "0";
                 infoPatryBalance.CreditPeriod = 0;
                 infoPatryBalance.ExchangeRateId = BllExchangeRate.ExchangerateViewByCurrencyId(PublicVariables._decCurrencyId);
                 infoPatryBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoPatryBalance.Extra1 = string.Empty;
                 infoPatryBalance.Extra2 = string.Empty;
             }
             BllPartyBalance.PartyBalanceAdd(infoPatryBalance);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Cus15:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Function for Save and Edit
        /// </summary>  
        public void SaveOrEdit()
        {
            try
            {
                PurchaseInvoiceBll BllPurchaseInvoice = new PurchaseInvoiceBll();
                PurchaseReturnBll BllPurchaseReturn = new PurchaseReturnBll();
                PurchaseReturnDetailsInfo infoPurchaseReturnDetails = new PurchaseReturnDetailsInfo();
                StockPostingInfo infoStockPosting = new StockPostingInfo();
                //StockPostingSP spStockPosting = new StockPostingSP();
                StockPostingBll BllStockPosting = new StockPostingBll();
                UnitConvertionBll BllUnitConvertion = new UnitConvertionBll();
                LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
                ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
                AccountLedgerInfo infoAccountLedger = new AccountLedgerInfo();
                AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
                PurchaseReturnBilltaxInfo infoPurchaseReturnBillTax = new PurchaseReturnBilltaxInfo();

                SettingsBll BllSettings = new SettingsBll();
                UnitBll bllUnit = new UnitBll();
                List<DataTable> ListObj = new List<DataTable>();
                string strAgainstVoucherNo = string.Empty;
                string strAgainstInvoiceNo = string.Empty;
                decimal decPurchaseReturnMasterIds = 0;
                decimal decPurchaseMasterId = 0;
                decimal decDiscount = 0;
                decimal decExchangeRate = 0;
                decimal decDis = 0;

                if (isAutomatic)
                {
                    if (strVoucherNo != string.Empty)
                    {
                        infoPurchaseReturnMaster.VoucherNo = strVoucherNo;
                    }
                    if (txtReturnNo.Text != string.Empty)
                    {
                        infoPurchaseReturnMaster.InvoiceNo = txtReturnNo.Text;
                    }
                }
                else
                {
                    infoPurchaseReturnMaster.VoucherNo = strVoucherNo;
                    infoPurchaseReturnMaster.InvoiceNo = txtReturnNo.Text;
                }
                if (decPurchaseReturnVoucherTypeId != 0)
                {
                    infoPurchaseReturnMaster.VoucherTypeId = decPurchaseReturnVoucherTypeId;
                }
                infoPurchaseReturnMaster.SuffixPrefixId = (decPurchaseReturnSuffixPrefixId != 0) ? decPurchaseReturnSuffixPrefixId : 0;
                infoPurchaseReturnMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
                infoPurchaseReturnMaster.PurchaseAccount = Convert.ToDecimal(cmbPurchaseAccount.SelectedValue.ToString());
                if (cmbInvoiceNo.SelectedValue != null && cmbInvoiceNo.Visible == true)
                {
                    infoPurchaseReturnMaster.PurchaseMasterId = Convert.ToDecimal((cmbInvoiceNo.SelectedValue.ToString()));
                    decPurchaseMasterId = Convert.ToDecimal((cmbInvoiceNo.SelectedValue.ToString()));
                }
                else
                {
                    infoPurchaseReturnMaster.PurchaseMasterId = 0;
                }
                infoPurchaseReturnMaster.ExchangeRateId = (cmbCurrency.SelectedValue != null) ? Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()) : 0;
                infoPurchaseReturnMaster.Narration = txtNarration.Text.Trim();
                infoPurchaseReturnMaster.UserId = PublicVariables._decCurrentUserId;
                infoPurchaseReturnMaster.LrNo = txtLrlNo.Text.Trim();
                infoPurchaseReturnMaster.TransportationCompany = txtTransportationCompany.Text.Trim();
                infoPurchaseReturnMaster.Date = Convert.ToDateTime(txtDate.Text);
                infoPurchaseReturnMaster.TotalAmount = (txtTotalAmount.Text != string.Empty) ? Convert.ToDecimal(txtTotalAmount.Text) : 0;
                infoPurchaseReturnMaster.TotalTax = (lblTaxAmount.Text != string.Empty) ? Convert.ToDecimal(lblTaxAmount.Text) : 0;
                infoPurchaseReturnMaster.Discount = (txtBillDiscount.Text != string.Empty) ? Convert.ToDecimal(txtBillDiscount.Text) : 0;
                infoPurchaseReturnMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                infoPurchaseReturnMaster.Extra1 = string.Empty;
                infoPurchaseReturnMaster.Extra2 = string.Empty;
                infoPurchaseReturnMaster.ExtraDate = DateTime.Now;
                infoPurchaseReturnMaster.GrandTotal = (txtGrandTotal.Text != string.Empty) ? Convert.ToDecimal(txtGrandTotal.Text) : 0;
                if (btnSave.Text == "Save")
                {
                    decPurchaseReturnMasterIds = BllPurchaseReturn.PurchaseReturnMasterAddWithReturnIdentity(infoPurchaseReturnMaster);
                }
                else
                {
                    infoPurchaseReturnMaster.PurchaseReturnMasterId = decPurchaseReturnMasterId;
                    decExchangeRate = BllExchangeRate.ExchangeRateViewByExchangeRateId(infoPurchaseReturnMaster.ExchangeRateId);
                    BllPurchaseReturn.PurchaseReturnMasterEdit(infoPurchaseReturnMaster);
                    infoPurchaseMaster = BllPurchaseInvoice.PurchaseMasterView(infoPurchaseReturnMaster.PurchaseMasterId);
                    BllLedgerPosting.LedgerPostDelete(strVoucherNo, decPurchaseReturnVoucherTypeId);
                    bllAccountLedger.PartyBalanceDeleteByVoucherTypeVoucherNoAndReferenceType(strVoucherNo, decPurchaseReturnVoucherTypeId);
                }

                infoLedgerPosting.Date = infoPurchaseReturnMaster.Date;
                infoLedgerPosting.VoucherTypeId = infoPurchaseReturnMaster.VoucherTypeId;
                infoLedgerPosting.VoucherNo = infoPurchaseReturnMaster.VoucherNo;
                infoLedgerPosting.ChequeNo = string.Empty;
                infoLedgerPosting.ChequeDate = DateTime.Now;
                infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                infoLedgerPosting.InvoiceNo = infoPurchaseReturnMaster.InvoiceNo;
                infoLedgerPosting.Extra1 = string.Empty;
                infoLedgerPosting.Extra2 = string.Empty;

                infoLedgerPosting.LedgerId = infoPurchaseReturnMaster.PurchaseAccount;
                infoLedgerPosting.Debit = 0;
                if (btnSave.Text == "Save")
                {
                    infoLedgerPosting.Credit = TotalNetAmountCalculation() * BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                    infoLedgerPosting.ExtraDate = DateTime.Now;
                }
                else
                {
                    infoLedgerPosting.Credit = TotalNetAmountCalculation();
                }
                BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);

                infoLedgerPosting.LedgerId = infoPurchaseReturnMaster.LedgerId;
                if (btnSave.Text == "Save")
                {
                    infoLedgerPosting.Debit = Convert.ToDecimal(txtGrandTotal.Text) * BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                    infoLedgerPosting.ExtraDate = DateTime.Now;
                }
                else
                {
                    infoLedgerPosting.Debit = Convert.ToDecimal(txtGrandTotal.Text);
                }
                infoLedgerPosting.Credit = 0;
                BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);

                foreach (DataGridViewRow dgvrow in dgvPurchaseReturnTax.Rows)
                {
                    if (dgvrow.Cells["dgvtxtTaxId"].Value != null && dgvrow.Cells["dgvtxtTaxId"].Value.ToString() != string.Empty)
                    {
                        infoLedgerPosting.LedgerId = Convert.ToDecimal(dgvrow.Cells["dgvtxtledgerId"].Value.ToString());
                        infoLedgerPosting.Credit = (dgvrow.Cells["dgvtxtAmounts"].Value == null) ? 0 : Convert.ToDecimal(dgvrow.Cells["dgvtxtAmounts"].Value.ToString());
                        infoLedgerPosting.Debit = 0;
                        infoLedgerPosting.ExtraDate = DateTime.Now;
                        BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                    }
                }

                if (txtBillDiscount.Text.Trim() != string.Empty)
                {
                    decDis = Convert.ToDecimal(txtBillDiscount.Text);
                }
                if (decDis >= 0)
                {
                    infoLedgerPosting.Debit = 0;
                    infoLedgerPosting.Credit = decDis;
                    infoLedgerPosting.LedgerId = 9;
                    infoLedgerPosting.ExtraDate = DateTime.Now;
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                }

                if (btnSave.Text == "Update")
                {
                    infoPurchaseReturnMaster = BllPurchaseReturn.PurchaseReturnMasterView(decPurchaseReturnMasterId);
                    if (infoPurchaseReturnMaster.PurchaseMasterId == 0)
                    {
                        BllStockPosting.StockPostingDeleteByagainstVoucherTypeIdAndagainstVoucherNoAndVoucherNoAndVoucherType(0, "NA", infoPurchaseReturnMaster.VoucherNo, infoPurchaseReturnMaster.VoucherTypeId);
                    }
                    if (infoPurchaseReturnMaster.PurchaseMasterId != 0)
                    {
                        infoPurchaseMaster = BllPurchaseInvoice.PurchaseMasterView(infoPurchaseReturnMaster.PurchaseMasterId);
                        BllStockPosting.StockPostingDeleteByagainstVoucherTypeIdAndagainstVoucherNoAndVoucherNoAndVoucherType(infoPurchaseMaster.VoucherTypeId, strInvoiceNo, strVoucherNo, infoPurchaseReturnMaster.VoucherTypeId);
                    }
                }

                foreach (DataGridViewRow dgvrow in dgvPurchaseReturn.Rows)
                {
                    if (dgvrow.Cells["dgvtxtProductId"].Value != null && dgvrow.Cells["dgvtxtProductId"].Value.ToString() != string.Empty)
                    {
                        infoPurchaseReturnDetails.ExtraDate = DateTime.Now;
                        infoPurchaseReturnDetails.Extra1 = string.Empty;
                        infoPurchaseReturnDetails.Extra2 = string.Empty;
                        infoPurchaseReturnDetails.PurchaseReturnMasterId = (btnSave.Text == "Save") ? decPurchaseReturnMasterIds : decPurchaseReturnMasterId;
                        infoPurchaseReturnDetails.ProductId = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtproductId"].Value));
                        infoPurchaseReturnDetails.Qty = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtqty"].Value));
                        infoPurchaseReturnDetails.Rate = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtrate"].Value));
                        if (btnSave.Text == "Save")
                        {
                            infoPurchaseReturnDetails.UnitId = Convert.ToDecimal(dgvrow.Cells["dgvcmbUnit"].Value.ToString());
                            infoPurchaseReturnDetails.UnitConversionId = BllUnitConvertion.UnitconversionIdViewByUnitIdAndProductId(infoPurchaseReturnDetails.UnitId, infoPurchaseReturnDetails.ProductId);
                        }
                        else
                        {
                            if (Convert.ToDecimal(dgvrow.Cells["dgvtxtPurchaseReturnDetailsId"].Value) == 0)
                            {
                                try
                                {
                                    infoPurchaseReturnDetails.UnitId = Convert.ToDecimal(dgvrow.Cells["dgvcmbUnit"].Value.ToString());
                                }
                                catch
                                {
                                    infoPurchaseReturnDetails.UnitId = bllUnit.UnitIdByUnitName(Convert.ToString(dgvrow.Cells["dgvcmbUnit"].Value.ToString()));
                                }
                                infoPurchaseReturnDetails.UnitConversionId = BllUnitConvertion.UnitconversionIdViewByUnitIdAndProductId(infoPurchaseReturnDetails.UnitId, infoPurchaseReturnDetails.ProductId);
                            }
                            else
                            {
                                try
                                {
                                    infoPurchaseReturnDetails.UnitId = Convert.ToDecimal(dgvrow.Cells["dgvcmbUnit"].Value.ToString());
                                }
                                catch
                                {
                                    infoPurchaseReturnDetails.UnitId = bllUnit.UnitIdByUnitName(Convert.ToString(dgvrow.Cells["dgvcmbUnit"].Value.ToString()));
                                }
                            }
                            infoPurchaseReturnDetails.UnitConversionId = Convert.ToDecimal(dgvrow.Cells["dgvtxtUnitConversionId"].Value);
                        }
                        infoPurchaseReturnDetails.Discount = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtdiscount"].Value));
                        if (dgvrow.Cells["dgvcmbTax"].Value != null && Convert.ToString(dgvrow.Cells["dgvcmbTax"].Value) != string.Empty && dgvrow.Cells["dgvcmbTax"].Value as string != "NA")
                        {
                            infoPurchaseReturnDetails.TaxId = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvcmbTax"].Value));
                            if (strTaxComboFill != string.Empty)
                            {
                                infoPurchaseReturnDetails.TaxAmount = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtTaxAmount"].Value));
                            }
                        }
                        else
                        {
                            infoPurchaseReturnDetails.TaxId = 0;
                        }
                        if (dgvrow.Cells["dgvcmbBatch"].Value != null && Convert.ToString(dgvrow.Cells["dgvcmbBatch"].Value) != string.Empty)
                        {
                            infoPurchaseReturnDetails.BatchId = Convert.ToDecimal(dgvrow.Cells["dgvcmbBatch"].Value);
                        }
                        else
                        {
                            infoPurchaseReturnDetails.GodownId = 0;
                        }
                        if (dgvrow.Cells["dgvcmbGodown"].Value != null && Convert.ToString(dgvrow.Cells["dgvcmbGodown"].Value) != string.Empty)
                        {
                            infoPurchaseReturnDetails.GodownId = Convert.ToDecimal(dgvrow.Cells["dgvcmbGodown"].Value);
                        }
                        else
                        {
                            infoPurchaseReturnDetails.RackId = 0;
                        }
                        if (dgvrow.Cells["dgvcmbRack"].Value != null && Convert.ToString(dgvrow.Cells["dgvcmbRack"].Value) != string.Empty)
                        {
                            infoPurchaseReturnDetails.RackId = Convert.ToDecimal(dgvrow.Cells["dgvcmbRack"].Value);
                        }
                        infoPurchaseReturnDetails.GrossAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtgrossValue"].Value.ToString());
                        infoPurchaseReturnDetails.NetAmount = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtNetAmount"].Value));
                        infoPurchaseReturnDetails.Amount = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtAmount"].Value));
                        infoPurchaseReturnDetails.SlNo = Convert.ToInt32(Convert.ToString(dgvrow.Cells["dgvtxtSlNo"].Value));
                        infoPurchaseReturnDetails.PurchaseDetailsId = (dgvrow.Cells["dgvtxtPurchaseDetailsId"].Value != null) ? Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtPurchaseDetailsId"].Value)) : 0;
                        if (dgvrow.Cells["dgvtxtPurchaseReturnDetailsId"].Value != null)
                        {
                            if (dgvrow.Cells["dgvtxtPurchaseReturnDetailsId"].Value.ToString() == "0" || dgvrow.Cells["dgvtxtPurchaseReturnDetailsId"].Value.ToString() == string.Empty)
                            {
                                BllPurchaseReturn.PurchaseReturnDetailsAddWithReturnIdentity(infoPurchaseReturnDetails);
                            }
                            else
                            {
                                infoPurchaseReturnDetails.PurchaseReturnDetailsId = Convert.ToDecimal(dgvrow.Cells["dgvtxtPurchaseReturnDetailsId"].Value.ToString());
                                BllPurchaseReturn.PurchaseReturnDetailsEdit(infoPurchaseReturnDetails);
                            }
                        }
                        else
                        {
                            BllPurchaseReturn.PurchaseReturnDetailsAddWithReturnIdentity(infoPurchaseReturnDetails);
                        }

                        if (btnSave.Text == "Save")
                        {
                            infoPurchaseMaster = BllPurchaseInvoice.PurchaseMasterView(infoPurchaseReturnMaster.PurchaseMasterId);
                        }
                        infoStockPosting.Date = infoPurchaseReturnMaster.Date;
                        infoStockPosting.ProductId = infoPurchaseReturnDetails.ProductId;
                        infoStockPosting.BatchId = infoPurchaseReturnDetails.BatchId;
                        infoStockPosting.UnitId = infoPurchaseReturnDetails.UnitId;
                        infoStockPosting.GodownId = infoPurchaseReturnDetails.GodownId;
                        infoStockPosting.RackId = infoPurchaseReturnDetails.RackId;
                        decimal decConversionId = BllUnitConvertion.UnitConversionRateByUnitConversionId(infoPurchaseReturnDetails.UnitConversionId);
                        //infoStockPosting.OutwardQty = infoPurchaseReturnDetails.Qty / (decConversionId == 0 ? 1 : decConversionId);
                        infoStockPosting.OutwardQty = infoPurchaseReturnDetails.Qty;
                        infoStockPosting.InwardQty = 0;
                        infoStockPosting.Rate = infoPurchaseReturnDetails.Rate;
                        infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                        infoStockPosting.Extra1 = string.Empty;
                        infoStockPosting.Extra2 = string.Empty;
                        if (infoPurchaseReturnDetails.PurchaseDetailsId != 0)
                        {
                            infoStockPosting.AgainstVoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                            infoStockPosting.AgainstVoucherNo = infoPurchaseMaster.VoucherNo;
                            infoStockPosting.AgainstInvoiceNo = infoPurchaseMaster.InvoiceNo;
                            infoStockPosting.VoucherNo = strVoucherNo;
                            infoStockPosting.InvoiceNo = txtReturnNo.Text.Trim();
                            infoStockPosting.VoucherTypeId = decPurchaseReturnVoucherTypeId;
                            decAgainstVoucherTypeId = infoStockPosting.VoucherTypeId;
                        }
                        else
                        {
                            infoStockPosting.AgainstVoucherTypeId = 0;
                            infoStockPosting.AgainstVoucherNo = "NA";
                            infoStockPosting.AgainstInvoiceNo = "NA";
                            infoStockPosting.VoucherNo = infoPurchaseReturnMaster.VoucherNo;
                            infoStockPosting.InvoiceNo = infoPurchaseReturnMaster.InvoiceNo;
                            infoStockPosting.VoucherTypeId = decPurchaseReturnVoucherTypeId;
                            decAgainstVoucherTypeId = 0;
                        }
                        BllStockPosting.StockPostingAdd(infoStockPosting);
                    }
                }
                if (btnSave.Text == "Update")
                {
                    removePurchaseReturnDetails();
                }

                infoAccountLedger = bllAccountLedger.AccountLedgerView(infoPurchaseReturnMaster.LedgerId);
                if (infoAccountLedger.BillByBill == true)
                {
                    infoPartyBalance.Date = infoPurchaseReturnMaster.Date;
                    infoPartyBalance.LedgerId = infoPurchaseReturnMaster.LedgerId;
                    if (decAgainstVoucherTypeId != 0)
                    {
                        infoPartyBalance.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                        infoPartyBalance.VoucherNo = infoPurchaseMaster.VoucherNo;
                        infoPartyBalance.InvoiceNo = infoPurchaseMaster.InvoiceNo;
                        infoPartyBalance.AgainstVoucherTypeId = infoPurchaseReturnMaster.VoucherTypeId;
                        infoPartyBalance.AgainstVoucherNo = infoPurchaseReturnMaster.VoucherNo;
                        infoPartyBalance.AgainstInvoiceNo = infoPurchaseReturnMaster.InvoiceNo;
                        infoPartyBalance.ReferenceType = "Against";
                    }
                    else
                    {
                        infoPartyBalance.VoucherTypeId = infoPurchaseReturnMaster.VoucherTypeId;
                        infoPartyBalance.VoucherNo = infoPurchaseReturnMaster.VoucherNo;
                        infoPartyBalance.InvoiceNo = infoPurchaseReturnMaster.InvoiceNo;
                        infoPartyBalance.AgainstVoucherTypeId = 0;
                        infoPartyBalance.AgainstVoucherNo = "NA";
                        infoPartyBalance.AgainstInvoiceNo = "NA";
                        infoPartyBalance.ReferenceType = "New";
                    }
                    infoPartyBalance.Debit = infoPurchaseReturnMaster.TotalAmount;
                    infoPartyBalance.Credit = 0;
                    infoPartyBalance.CreditPeriod = 0;
                    infoPartyBalance.ExchangeRateId = infoPurchaseReturnMaster.ExchangeRateId;
                    infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                    infoPartyBalance.Extra1 = string.Empty;
                    infoPartyBalance.Extra2 = string.Empty;
                    BllPartyBalance.PartyBalanceAdd(infoPartyBalance);
                }

                foreach (DataGridViewRow item in dgvPurchaseReturnTax.Rows)
                {
                    if (item.Cells["dgvtxtTaxId"].Value != null)
                    {
                        if (Convert.ToDecimal(item.Cells["dgvtxtAmounts"].Value.ToString()) > 0)
                        {
                            infoPurchaseReturnBillTax.PurchaseReturnMasterId = (btnSave.Text == "Save") ? decPurchaseReturnMasterIds : decPurchaseReturnMasterIds;
                            infoPurchaseReturnBillTax.TaxId = Convert.ToDecimal(item.Cells["dgvtxtTaxId"].Value.ToString());
                            infoPurchaseReturnBillTax.TaxAmount = (item.Cells["dgvtxtAmounts"].Value == null) ? 0 : Convert.ToDecimal(item.Cells["dgvtxtAmounts"].Value.ToString());
                            infoPurchaseReturnBillTax.Extra1 = string.Empty;
                            infoPurchaseReturnBillTax.Extra2 = string.Empty;
                            BllPurchaseReturn.PurchaseReturnBilltaxAdd(infoPurchaseReturnBillTax);
                        }
                    }
                }
                if (btnSave.Text == "Save")
                {
                    Messages.SavedMessage();
                    if (cbxPrintAfterSave.Checked)
                    {
                        if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                        {
                            PrintForDotMatrix(decPurchaseReturnMasterIds);
                        }
                        else
                        {
                            Print(decPurchaseReturnMasterIds);
                        }
                    }
                    Clear();
                }
                else
                {
                    decDiscount = Convert.ToDecimal(txtBillDiscount.Text);
                    Messages.UpdatedMessage();
                    if (cbxPrintAfterSave.Checked)
                    {
                        if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                        {
                            PrintForDotMatrix(decPurchaseReturnMasterId);
                        }
                        else
                        {
                            Print(decPurchaseReturnMasterId);
                        }
                    }
                    if (frmPurchaseReturnRegisterObj != null)
                    {
                        frmPurchaseReturnRegisterObj.GridFill();
                        frmPurchaseReturnRegisterObj.Enabled = true;
                    }

                    if (ObjPurchaseReturnReport != null)
                    {
                        ObjPurchaseReturnReport.PurchaseReturnReportGridFill();
                        ObjPurchaseReturnReport.Enabled = true;
                    }
                    if (frmLedgerDetailsObj != null)
                    {
                        frmLedgerDetailsObj.LedgerDetailsView();
                        frmLedgerDetailsObj.Enabled = true;
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PR:49" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 public int PartyBalanceCheckWithReference()
 {
     int inF1 = 0;
     decimal decPartyBalanceAmount = 0;
     decimal decGrandTotal = 0;
     try
     {
         bool isRef = false;
         AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         isRef = bllAccountLedger.PartyBalanceAgainstReferenceCheck(strVoucherNo, DecSalesInvoiceVoucherTypeId);
         if (isRef)
         {
             decPartyBalanceAmount = BllPartyBalance.PartyBalanceAmountViewForSalesInvoice(strVoucherNo, DecSalesInvoiceVoucherTypeId, "Against");
             decGrandTotal = Convert.ToDecimal(txtGrandTotal.Text);
             if (decGrandTotal >= decPartyBalanceAmount)
             {
                 inF1 = 1;
             }
             else
             {
                 inF1 = 0;
                 Messages.InformationMessage("There is a Receipt voucher against this invoice so grand total should not be less than " + decPartyBalanceAmount);
             }
         }
         else
         {
             inF1 = 1;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI36:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     return inF1;
 }
        /// <summary>
        /// Party balance Save Or Edit
        /// </summary>
        /// <param name="inJ"></param>
        public void PartyBalanceAddOrEdit(int inJ)
        {
            try
            {

                int inTableRowCount = dtblPartyBalance.Rows.Count;
                PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                InfopartyBalance.Credit = 0;
                InfopartyBalance.CreditPeriod = 0;
                InfopartyBalance.Date = dtpDate.Value;
                InfopartyBalance.Debit = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["Amount"].ToString());
                InfopartyBalance.ExchangeRateId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["CurrencyId"].ToString());
                InfopartyBalance.Extra1 = string.Empty;
                InfopartyBalance.Extra2 = string.Empty;
                InfopartyBalance.ExtraDate = DateTime.Now;
                InfopartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                InfopartyBalance.LedgerId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["LedgerId"].ToString());
                InfopartyBalance.ReferenceType = dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString();
                if (dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString() == "New" || dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString() == "OnAccount")
                {
                    InfopartyBalance.AgainstInvoiceNo = "0";
                    InfopartyBalance.AgainstVoucherNo = "0";
                    InfopartyBalance.AgainstVoucherTypeId = 0;
                    InfopartyBalance.VoucherTypeId = decPaymentVoucherTypeId;
                    InfopartyBalance.InvoiceNo = strInvoiceNo;
                    if (!isAutomatic)
                    {
                        InfopartyBalance.VoucherNo = txtVoucherNo.Text.Trim();
                    }
                    else
                    {
                        InfopartyBalance.VoucherNo = strVoucherNo;
                    }
                }
                else
                {
                    InfopartyBalance.ExchangeRateId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["OldExchangeRate"].ToString());
                    InfopartyBalance.AgainstInvoiceNo = strInvoiceNo;
                    if (!isAutomatic)
                    {
                        InfopartyBalance.AgainstVoucherNo = txtVoucherNo.Text.Trim();
                    }
                    else
                    {
                        InfopartyBalance.AgainstVoucherNo = strVoucherNo;
                    }
                    InfopartyBalance.AgainstVoucherTypeId = decPaymentVoucherTypeId;
                    InfopartyBalance.VoucherTypeId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["AgainstVoucherTypeId"].ToString());
                    InfopartyBalance.VoucherNo = dtblPartyBalance.Rows[inJ]["AgainstVoucherNo"].ToString();
                    InfopartyBalance.InvoiceNo = dtblPartyBalance.Rows[inJ]["AgainstInvoiceNo"].ToString();
                }
                if (dtblPartyBalance.Rows[inJ]["PartyBalanceId"].ToString() == "0")
                {
                    BllPartyBalance.PartyBalanceAdd(InfopartyBalance);
                }
                else
                {
                    InfopartyBalance.PartyBalanceId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["partyBalanceId"]);
                    BllPartyBalance.PartyBalanceEdit(InfopartyBalance);
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show("PV15:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Fill function for edit
 /// </summary>
 public void SalesInvoiceDetailsEditFill()
 {
     //SalesMasterSP spSalesMaster = new SalesMasterSP();
     //SalesDetailsSP spSalesDetails = new SalesDetailsSP();
     PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
     SalesDetailsInfo InfoSalesDetails = new SalesDetailsInfo();
     StockPostingInfo infoStockPosting = new StockPostingInfo();
     SalesMasterInfo InfoSalesMaster = new SalesMasterInfo();
     StockPostingBll BllStockPosting = new StockPostingBll();
     PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
     AdditionalCostInfo infoAdditionalCost = new AdditionalCostInfo();
     AditionalCostBll bllAditionalCost = new AditionalCostBll();
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     SalesBillTaxInfo infoSalesBillTax = new SalesBillTaxInfo();
     UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
     try
     {
         string strAgainstInvoiceN0 = txtInvoiceNo.Text.Trim();
         for (int inI = 0; inI < dgvSalesInvoice.Rows.Count - 1; inI++)
         {
             decimal decRefStatus = BllSalesInvoice.SalesInvoiceReferenceCheckForEdit(decSalesInvoiceIdToEdit);
             if (decRefStatus != 0)
             {
                 dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductCode"].ReadOnly = true;
                 dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductName"].ReadOnly = true;
                 dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceBarcode"].ReadOnly = true;
                 dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].ReadOnly = true;
                 dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].ReadOnly = true;
             }
             if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value == null || dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value.ToString() == string.Empty || dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value.ToString() == "0")   // here check the  row added or editing current row
             {
                 InfoSalesDetails.SalesMasterId = decSalesInvoiceIdToEdit;
                 InfoSalesDetails.ExtraDate = DateTime.Now;
                 InfoSalesDetails.Extra1 = string.Empty;
                 InfoSalesDetails.Extra2 = string.Empty;
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductName"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductName"].Value.ToString() != string.Empty)
                 {
                     if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQty"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQty"].Value.ToString() != string.Empty)
                     {
                         if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSISalesOrderDetailsId"].Value != null)
                         {
                             InfoSalesDetails.OrderDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSISalesOrderDetailsId"].Value.ToString());
                         }
                         else
                         {
                             InfoSalesDetails.OrderDetailsId = 0;
                         }
                         if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value != null)
                         {
                             InfoSalesDetails.DeliveryNoteDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value.ToString());
                         }
                         else
                         {
                             InfoSalesDetails.DeliveryNoteDetailsId = 0;
                         }
                         if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQuotationDetailsId"].Value != null)
                         {
                             InfoSalesDetails.QuotationDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQuotationDetailsId"].Value.ToString());
                         }
                         else
                         {
                             InfoSalesDetails.QuotationDetailsId = 0;
                         }
                         InfoSalesDetails.SlNo = Convert.ToInt32(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceSlno"].Value.ToString());
                         InfoSalesDetails.ProductId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductId"].Value.ToString());
                         decimal decQty = BllSalesInvoice.SalesInvoiceQuantityDetailsAgainstSalesReturn(DecSalesInvoiceVoucherTypeId, strVoucherNo);
                         if (Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQty"].Value.ToString()) < decQty)
                         {
                             dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQty"].Value = 0;
                             decRefStatus = 1;
                             MessageBox.Show("Quantity should be greater than " + decQty, "Open_Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             dgvSalesInvoice.Focus();
                         }
                         else
                         {
                             InfoSalesDetails.Qty = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQty"].Value.ToString());
                             InfoSalesDetails.Rate = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceRate"].Value.ToString());
                             InfoSalesDetails.UnitId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoicembUnitName"].Value.ToString());
                             InfoSalesDetails.UnitConversionId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceUnitConversionId"].Value.ToString());
                             InfoSalesDetails.Discount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDiscountAmount"].Value.ToString());
                             if (dgvSalesInvoice.Columns["dgvcmbSalesInvoiceTaxName"].Visible)
                             {
                                 InfoSalesDetails.TaxId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceTaxName"].Value.ToString());
                                 InfoSalesDetails.TaxAmount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceTaxAmount"].Value.ToString());
                             }
                             else
                             {
                                 InfoSalesDetails.TaxId = 0;
                                 InfoSalesDetails.TaxAmount = 0;
                             }
                             if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString() != string.Empty)
                             {
                                 InfoSalesDetails.BatchId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString());
                             }
                             else
                             {
                                 InfoSalesDetails.BatchId = 0;
                             }
                             if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString() != string.Empty)
                             {
                                 InfoSalesDetails.GodownId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString());
                             }
                             else
                             {
                                 InfoSalesDetails.GodownId = 0;
                             }
                             if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value.ToString() != string.Empty)
                             {
                                 InfoSalesDetails.RackId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value.ToString());
                             }
                             else
                             {
                                 InfoSalesDetails.RackId = 0;
                             }
                             InfoSalesDetails.GrossAmount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceGrossValue"].Value.ToString());
                             InfoSalesDetails.NetAmount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceNetAmount"].Value.ToString());
                             InfoSalesDetails.Amount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceAmount"].Value.ToString());
                             BllSalesInvoice.SalesDetailsAdd(InfoSalesDetails);
                         }
                     }
                 }
             }
             else
             {
                 InfoSalesDetails.SalesMasterId = decSalesInvoiceIdToEdit;
                 InfoSalesDetails.SalesDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value);
                 InfoSalesDetails.SlNo = Convert.ToInt32(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceSlno"].Value.ToString());
                 InfoSalesDetails.ProductId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductId"].Value.ToString());
                 InfoSalesDetails.Qty = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQty"].Value.ToString());
                 InfoSalesDetails.UnitId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoicembUnitName"].Value.ToString());
                 InfoSalesDetails.UnitConversionId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceUnitConversionId"].Value.ToString());
                 InfoSalesDetails.Rate = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceRate"].Value.ToString());
                 InfoSalesDetails.Discount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDiscountAmount"].Value.ToString());
                 if (dgvSalesInvoice.Columns["dgvcmbSalesInvoiceTaxName"].Visible)
                 {
                     InfoSalesDetails.TaxId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceTaxName"].Value.ToString());
                     InfoSalesDetails.TaxAmount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceTaxAmount"].Value.ToString());
                 }
                 else
                 {
                     InfoSalesDetails.TaxId = 0;
                     InfoSalesDetails.TaxAmount = 0;
                 }
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString() != string.Empty)
                 {
                     InfoSalesDetails.BatchId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString());
                 }
                 else
                 {
                     InfoSalesDetails.BatchId = 0;
                 }
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString() != string.Empty)
                 {
                     InfoSalesDetails.GodownId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString());
                     RackComboFill(InfoSalesDetails.GodownId, inI, dgvSalesInvoice.Columns["dgvcmbSalesInvoiceRack"].Index);
                 }
                 else
                 {
                     InfoSalesDetails.GodownId = 0;
                 }
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value.ToString() != string.Empty)
                 {
                     InfoSalesDetails.RackId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value.ToString());
                 }
                 else
                 {
                     InfoSalesDetails.RackId = 0;
                 }
                 InfoSalesDetails.GrossAmount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceGrossValue"].Value.ToString());
                 InfoSalesDetails.NetAmount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceNetAmount"].Value.ToString());
                 InfoSalesDetails.Amount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceAmount"].Value.ToString());
                 InfoSalesDetails.ExtraDate = DateTime.Now;
                 InfoSalesDetails.Extra1 = string.Empty;
                 InfoSalesDetails.Extra2 = string.Empty;
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSISalesOrderDetailsId"].Value != null)
                 {
                     InfoSalesDetails.OrderDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSISalesOrderDetailsId"].Value.ToString());
                 }
                 else
                 {
                     InfoSalesDetails.OrderDetailsId = 0;
                 }
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value != null)
                 {
                     InfoSalesDetails.DeliveryNoteDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value.ToString());
                 }
                 else
                 {
                     InfoSalesDetails.DeliveryNoteDetailsId = 0;
                 }
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQuotationDetailsId"].Value != null)
                 {
                     InfoSalesDetails.QuotationDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQuotationDetailsId"].Value.ToString());
                 }
                 else
                 {
                     InfoSalesDetails.QuotationDetailsId = 0;
                 }
                 BllSalesInvoice.SalesDetailsEdit(InfoSalesDetails);
             }
             infoStockPosting.Date = Convert.ToDateTime(txtDate.Text.Trim().ToString());
             infoStockPosting.ProductId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductId"].Value.ToString());
             infoStockPosting.BatchId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString());
             infoStockPosting.UnitId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoicembUnitName"].Value.ToString());
             if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString() != string.Empty)
             {
                 infoStockPosting.GodownId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString());
             }
             else
             {
                 infoStockPosting.GodownId = 0;
             }
             if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value.ToString() != string.Empty)
             {
                 infoStockPosting.RackId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value.ToString());
             }
             else
             {
                 infoStockPosting.RackId = 0;
             }
             if (Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceVoucherTypeId"].Value) == 0)
             {
                 decimal decResult =BllStockPosting.StockPostingDeleteForSalesInvoiceAgainstDeliveryNote(0, "NA", strVoucherNo, DecSalesInvoiceVoucherTypeId);
             }
             else
             {
                 decimal decResult = BllStockPosting.StockPostingDeleteForSalesInvoiceAgainstDeliveryNote(DecSalesInvoiceVoucherTypeId, strVoucherNo, strVoucherNoTostockPost, decVouchertypeIdTostockPost);
             }
             infoStockPosting.Rate = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceRate"].Value.ToString());
             infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
             infoStockPosting.ExtraDate = DateTime.Now;
             infoStockPosting.Extra1 = string.Empty;
             infoStockPosting.Extra2 = string.Empty;
             if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value != null)
             {
                 if (Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value.ToString()) != 0)
                 {
                     infoStockPosting.InwardQty = InfoSalesDetails.Qty / bllUnitConvertion.UnitConversionRateByUnitConversionId(InfoSalesDetails.UnitConversionId);
                     infoStockPosting.OutwardQty = 0;
                     infoStockPosting.VoucherNo = strVoucherNoTostockPost;
                     infoStockPosting.AgainstVoucherNo = strVoucherNo;
                     infoStockPosting.InvoiceNo = strInvoiceNoTostockPost;
                     infoStockPosting.AgainstInvoiceNo = strAgainstInvoiceN0;
                     infoStockPosting.VoucherTypeId = decVouchertypeIdTostockPost;
                     infoStockPosting.AgainstVoucherTypeId = DecSalesInvoiceVoucherTypeId;
                     BllStockPosting.StockPostingAdd(infoStockPosting);
                 }
             }
             infoStockPosting.InwardQty = 0;
             infoStockPosting.OutwardQty = InfoSalesDetails.Qty / bllUnitConvertion.UnitConversionRateByUnitConversionId(InfoSalesDetails.UnitConversionId);
             infoStockPosting.VoucherNo = strVoucherNo;
             infoStockPosting.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
             infoStockPosting.InvoiceNo = strAgainstInvoiceN0;
             infoStockPosting.AgainstInvoiceNo = "NA";
             infoStockPosting.AgainstVoucherNo = "NA";
             infoStockPosting.AgainstVoucherTypeId = 0;
             BllStockPosting.StockPostingAdd(infoStockPosting);
         }
         int inAddRowCount = dgvSalesInvoiceLedger.RowCount;
         infoAdditionalCost.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
         if (isAutomatic)
         {
             infoAdditionalCost.VoucherNo = strVoucherNo;
         }
         else
         {
             infoAdditionalCost.VoucherNo = txtInvoiceNo.Text;
         }
         infoAdditionalCost.ExtraDate = DateTime.Now;
         infoAdditionalCost.Extra1 = string.Empty;
         infoAdditionalCost.Extra2 = string.Empty;
         for (int inIAdc = 0; inIAdc < inAddRowCount; inIAdc++)
         {
             if (dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvCmbAdditionalCostledgerName"].Value != null && dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvCmbAdditionalCostledgerName"].Value.ToString() != string.Empty)
             {
                 if (dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvtxtAdditionalCoastledgerAmount"].Value != null && dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString() != string.Empty)
                 {
                     infoAdditionalCost.LedgerId = Convert.ToInt32(dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvCmbAdditionalCostledgerName"].Value.ToString());
                     if (cmbDrorCr.SelectedItem.ToString() != "Dr")
                     {
                         infoAdditionalCost.Debit = 0;
                         infoAdditionalCost.Credit = Convert.ToDecimal(dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString());
                     }
                     else
                     {
                         infoAdditionalCost.Debit = Convert.ToDecimal(dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString());
                         infoAdditionalCost.Credit = 0;
                     }
                     if (dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvtxtAdditionalCostId"].Value != null && dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvtxtAdditionalCostId"].Value.ToString() != string.Empty)
                     {
                         bllAditionalCost.AdditionalCostEditByVoucherTypeIdAndVoucherNo(infoAdditionalCost);
                     }
                     else
                     {
                         bllAditionalCost.AdditionalCostAdd(infoAdditionalCost);
                     }
                 }
             }
         }
         if (cmbDrorCr.SelectedItem.ToString() != "Dr")               // here we are debit the cash or bank
         {
             decimal decCAshOrPartyId = 0;
             decCAshOrPartyId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
             decimal decTotalAddAmount = Convert.ToDecimal(lblLedgerTotalAmount.Text.Trim().ToString());
             infoAdditionalCost.Debit = decTotalAddAmount;
             infoAdditionalCost.Credit = 0;
             infoAdditionalCost.LedgerId = decCAshOrPartyId;
             infoAdditionalCost.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
             infoAdditionalCost.VoucherNo = strVoucherNo;
             infoAdditionalCost.ExtraDate = DateTime.Now;
             infoAdditionalCost.Extra1 = string.Empty;
             infoAdditionalCost.Extra2 = string.Empty;
             bllAditionalCost.AdditionalCostEditByVoucherTypeIdAndVoucherNo(infoAdditionalCost);
         }
         else
         {
             decimal decCAshOrBankId = 0;                    // here we are credit the cash or bank
             decCAshOrBankId = Convert.ToDecimal(cmbCashOrbank.SelectedValue.ToString());
             decimal decTotalAddAmount = Convert.ToDecimal(lblLedgerTotalAmount.Text.Trim().ToString());
             infoAdditionalCost.Debit = 0;
             infoAdditionalCost.Credit = decTotalAddAmount;
             infoAdditionalCost.LedgerId = decCAshOrBankId;
             infoAdditionalCost.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
             infoAdditionalCost.VoucherNo = strVoucherNo;
             infoAdditionalCost.ExtraDate = DateTime.Now;
             infoAdditionalCost.Extra1 = string.Empty;
             infoAdditionalCost.Extra2 = string.Empty;
             bllAditionalCost.AdditionalCostEditByVoucherTypeIdAndVoucherNo(infoAdditionalCost);
         }
         removeSalesInvoiceAdditionalDetails();
         if (dgvSalesInvoice.Columns["dgvcmbSalesInvoiceTaxName"].Visible)
         {
             int inTaxRowCount = dgvSalesInvoiceTax.RowCount;
             infoSalesBillTax.SalesMasterId = decSalesInvoiceIdToEdit;
             infoSalesBillTax.ExtraDate = DateTime.Now;
             infoSalesBillTax.Extra1 = string.Empty;
             infoSalesBillTax.Extra2 = string.Empty;
             for (int inTax = 0; inTax < inTaxRowCount; inTax++)
             {
                 if (dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxId"].Value != null && dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxId"].Value.ToString() != string.Empty)
                 {
                     if (dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxAmount"].Value != null && dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxAmount"].Value.ToString() != string.Empty)
                     {
                         decimal decAmount = Convert.ToDecimal(dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxAmount"].Value);
                         if (decAmount > 0)
                         {
                             infoSalesBillTax.TaxId = Convert.ToInt32(dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxId"].Value.ToString());
                             infoSalesBillTax.TaxAmount = Convert.ToDecimal(dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxAmount"].Value.ToString());
                             BllSalesInvoice.SalesBillTaxEditBySalesMasterIdAndTaxId(infoSalesBillTax);
                         }
                     }
                 }
             }
         }
         if (BllSalesInvoice.SalesInvoiceInvoicePartyCheckEnableBillByBillOrNot(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString())))
         {
             infoPartyBalance.Date = Convert.ToDateTime(txtDate.Text.ToString());
             infoPartyBalance.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
             infoPartyBalance.VoucherNo = strVoucherNo;
             infoPartyBalance.InvoiceNo = txtInvoiceNo.Text.Trim();
             infoPartyBalance.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
             infoPartyBalance.AgainstVoucherTypeId = 0;
             infoPartyBalance.AgainstVoucherNo = "0";
             infoPartyBalance.AgainstInvoiceNo = "0";
             infoPartyBalance.ReferenceType = "New";
             infoPartyBalance.Debit = Convert.ToDecimal(txtGrandTotal.Text.Trim().ToString());
             decimal decBalAmount = BllSalesInvoice.SalesInvoiceReciptVoucherDetailsAgainstSI(DecSalesInvoiceVoucherTypeId, strVoucherNo);
             decimal decCurrentAmount = Convert.ToDecimal(txtGrandTotal.Text.ToString());
             if (decCurrentAmount < decBalAmount)
             {
                 MessageBox.Show("Amount should be greater than " + decBalAmount, "Open_Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 dgvSalesInvoice.Focus();
             }
             else
             {
                 infoPartyBalance.Credit = 0;
                 infoPartyBalance.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text.ToString());
                 infoPartyBalance.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue);
                 infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoPartyBalance.ExtraDate = DateTime.Now;
                 infoPartyBalance.Extra1 = string.Empty;
                 infoPartyBalance.Extra2 = string.Empty;
                 BllPartyBalance.PartyBalanceEditByVoucherNoVoucherTypeIdAndReferenceType(infoPartyBalance);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 81" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Save Function
        /// </summary>
        public void Save()
        {
            try
            {
                int inGridRowCount = dgvPaymentVoucher.RowCount;
                int inTableRowCount = dtblPartyBalance.Rows.Count;
                int inB = 0;
                PaymentMasterInfo InfoPaymentMaster = new PaymentMasterInfo();
                //PaymentMasterSP SpPaymentMaster = new PaymentMasterSP();
                PaymentDetailsInfo InfoPaymentDetails = new PaymentDetailsInfo();
                //PaymentDetailsSP SpPaymentDetails = new PaymentDetailsSP();
                PaymentVoucherBll BllPaymentVoucher = new PaymentVoucherBll();
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
                DateValidation objVal = new DateValidation();
                TextBox txtDate1 = new TextBox();
                InfoPaymentMaster.Date = dtpDate.Value;
                InfoPaymentMaster.Extra1 = string.Empty;
                InfoPaymentMaster.Extra2 = string.Empty;
                InfoPaymentMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                InfoPaymentMaster.InvoiceNo = txtVoucherNo.Text.Trim(); ;
                InfoPaymentMaster.LedgerId = Convert.ToDecimal(cmbBankorCash.SelectedValue.ToString());
                InfoPaymentMaster.Narration = txtNarration.Text.Trim();
                InfoPaymentMaster.SuffixPrefixId = decDailySuffixPrefixId;
                decimal decTotalAmount = TotalAmountCalculation();
                InfoPaymentMaster.TotalAmount = decTotalAmount;
                InfoPaymentMaster.UserId = PublicVariables._decCurrentUserId;
                InfoPaymentMaster.VoucherNo = strVoucherNo;
                InfoPaymentMaster.VoucherTypeId = decPaymentVoucherTypeId;
                decimal decPaymentMasterId = BllPaymentVoucher.PaymentMasterAdd(InfoPaymentMaster);
                if (decPaymentMasterId != 0)
                {
                    MasterLedgerPosting();
                }
                for (int inI = 0; inI < inGridRowCount - 1; inI++)
                {
                    if (dgvPaymentVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")
                    {
                        InfoPaymentDetails.Amount = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                        InfoPaymentDetails.ExchangeRateId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString());
                        InfoPaymentDetails.Extra1 = string.Empty;
                        InfoPaymentDetails.Extra2 = string.Empty;
                        InfoPaymentDetails.LedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString());
                        InfoPaymentDetails.PaymentMasterId = decPaymentMasterId;
                        if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                        {
                            InfoPaymentDetails.LedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString());
                        }
                        if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                        {
                            InfoPaymentDetails.ChequeNo = dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString();

                            if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                            {
                                InfoPaymentDetails.ChequeDate = Convert.ToDateTime(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value);
                            }
                            else
                            {
                                InfoPaymentDetails.ChequeDate = DateTime.Now;
                            }
                        }
                        else
                        {
                            InfoPaymentDetails.ChequeNo = string.Empty;
                            InfoPaymentDetails.ChequeDate = DateTime.Now;
                        }
                        decimal decPaymentDetailsId = BllPaymentVoucher.PaymentDetailsAdd(InfoPaymentDetails);
                        if (decPaymentDetailsId != 0)
                        {
                            for (int inJ = 0; inJ < inTableRowCount; inJ++)
                            {
                                if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString())
                                {
                                    PartyBalanceAddOrEdit(inJ);
                                }
                            }
                            inB++;
                            DetailsLedgerPosting(inI, decPaymentDetailsId);
                        }
                    }
                }
                Messages.SavedMessage();
                if (cbxPrintafterSave.Checked)
                {
                    if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                    {
                        PrintForDotMatrix(decPaymentmasterId);
                    }
                    else
                    {
                        Print(decPaymentMasterId);
                    }
                }
                Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("PV17:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #19
0
 /// <summary>
 /// Function to delete an item from table
 /// </summary>
 /// <param name="decSalesInvoiceid"></param>
 public void DeleteFunction(decimal decSalesInvoiceid)
 {
     try
     {
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         BllSalesInvoice.SalesInvoiceDelete(decSalesMasterId, DecPOSVoucherTypeId, strVoucherNo);
         Messages.DeletedMessage();
         if (objfrmSalesInvoiceRegister != null)
         {
             this.Close();
             objfrmSalesInvoiceRegister.Enabled = true;
             objfrmSalesInvoiceRegister.gridFill();
         }
         else if (frmSalesReportObj != null)
         {
             this.Close();
             frmSalesReportObj.Enabled = true;
             frmSalesReportObj.gridFill();
         }
         else if (frmDayBookObj != null)
         {
             this.Close();
         }
         else
         {
             Clear();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("POS: 57" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Delete Function
        /// </summary>
        /// <param name="decMasterId"></param>
        public void Delete(decimal decMasterId)
        {
            try
            {
                //PaymentMasterSP SpPaymentMaster = new PaymentMasterSP();
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                PaymentVoucherBll BllPaymentVoucher = new PaymentVoucherBll();
                if (!BllPartyBalance.PartyBalanceCheckReference(decPaymentVoucherTypeId, strVoucherNo))
                {
                    BllPaymentVoucher.PaymentVoucherDelete(decPaymentmasterId, decPaymentVoucherTypeId, strVoucherNo);
                    Messages.DeletedMessage();
                    if (frmPaymentRegisterObj != null)
                    {
                        this.Close();
                        frmPaymentRegisterObj.CallFromPaymentVoucher(this);
                    }
                    else if (frmPaymentReportObj != null)
                    {
                        this.Close();
                        frmPaymentReportObj.CallFromPaymentVoucher(this);
                    }
                    else if (frmLedgerDetailsObj != null)
                    {
                        this.Close();
                    }
                    if (_frmVoucherSearch != null)
                    {
                        this.Close();
                        _frmVoucherSearch.GridFill();
                    }
                    if (frmDayBookObj != null)
                    {
                        this.Close();
                    }
                    if (frmBillallocationObj != null)
                    {
                        this.Close();
                    }

                }
                else
                {
                    Messages.InformationMessage("Reference exist. Cannot delete");
                    txtDate.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PV19:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Save function
        /// </summary>
        public void SaveFunction()
        {
            try
            {
                DateValidation Objdatevalidation = new DateValidation();
                OtherDateValidationFunction ObjotherdateValidation = new OtherDateValidationFunction();
                Objdatevalidation.DateValidationFunction(txtVoucherDate);
                ObjotherdateValidation.DateValidationFunction(txtCheckDate, false);
                DataTable dtblMaster = new DataTable();
                SettingsBll BllSettings = new SettingsBll();
                PDCRecivebleBll BllPdcreceivable = new PDCRecivebleBll();
                PDCReceivableMasterInfo InfopdcRecivable = new PDCReceivableMasterInfo();
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                InfopdcRecivable.VoucherNo = strVoucherNo;
                InfopdcRecivable.InvoiceNo = txtVoucherNo.Text.Trim();
                InfopdcRecivable.Date = DateTime.Parse(txtVoucherDate.Text);
                InfopdcRecivable.LedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString());
                InfopdcRecivable.Amount = decimal.Parse(txtAmount.Text);
                InfopdcRecivable.Narration = txtNarration.Text;
                if (txtcheckNo.Text != string.Empty)
                    InfopdcRecivable.ChequeNo = txtcheckNo.Text;
                else
                    InfopdcRecivable.ChequeNo = string.Empty;
                if (txtCheckDate.Text != string.Empty)
                    InfopdcRecivable.ChequeDate = Convert.ToDateTime(txtCheckDate.Text);
                else
                    InfopdcRecivable.ChequeDate = DateTime.Now;
                InfopdcRecivable.UserId = PublicVariables._decCurrentUserId;
                InfopdcRecivable.VoucherTypeId = decPDCReceivableVoucherTypeId;
                if (cmbBank.SelectedValue != null && cmbBank.SelectedValue.ToString() != string.Empty)
                {
                    InfopdcRecivable.BankId = Convert.ToDecimal(cmbBank.SelectedValue.ToString());
                }
                else
                    InfopdcRecivable.BankId = 0;
                InfopdcRecivable.ExtraDate = DateTime.Now;
                InfopdcRecivable.Extra1 = string.Empty;
                InfopdcRecivable.Extra2 = string.Empty;
                if (!isInEditMode)
                {
                    decimal decIdentity = BllPdcreceivable.PDCReceivableMasterAdd(InfopdcRecivable);
                    LedgerPosting();
                    PartyBalanceAddOrEdit();
                    Messages.SavedMessage();
                    if (cbxPrint.Checked)
                    {
                        if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                        {
                            PrintForDotMatrix(decIdentity);
                        }
                        else
                        {
                            Print(decIdentity);
                        }
                    }
                    ClearFunction();
                }
                else
                {

                    decimal decIdentity = decPDCReceivableEditId;
                    InfopdcRecivable.PdcReceivableMasterId = decPDCReceivableEditId;
                    BllPdcreceivable.PDCReceivableMasterEdit(InfopdcRecivable);

                    LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                    BllLedgerPosting.LedgerPostingDeleteByVoucherNoVoucherTypeIdAndLedgerId(strVoucherNo, decPDCReceivableVoucherTypeId, 12);
                    BllPartyBalance.PartyBalanceDeleteByVoucherTypeAndVoucherNo(decPDCReceivableVoucherTypeId, strVoucherNo);
                    PartyBalanceAddOrEdit();
                    LedgerPostingEdit(decPDCReceivableEditId);
                    Messages.UpdatedMessage();
                    if (cbxPrint.Checked)
                    {
                        if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                        {
                            PrintForDotMatrix(decIdentity);
                        }
                        else
                        {
                            Print(decIdentity);
                        }
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PR9:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Delete party balance entry while click remove button
 /// </summary>
 public void DeletePartyBalanceOfRemovedRow()
 {
     PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
     try
     {
         foreach (object obj in arrlstOfDeletedPartyBalanceRow)
         {
             string str = Convert.ToString(obj);
             BllPartyBalance.PartyBalanceDelete(Convert.ToDecimal(str));
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PV:12" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Fill function to updation
 /// </summary>
 public void FillFunction()
 {
     try
     {
         PDCRecivebleBll BllPdcRecieveble = new PDCRecivebleBll();
         PDCReceivableMasterInfo infopdcrecivable = new PDCReceivableMasterInfo();
         infopdcrecivable = BllPdcRecieveble.PDCReceivableMasterView(decPDCReceivableEditId);
         txtVoucherNo.ReadOnly = false;
         strVoucherNo = infopdcrecivable.VoucherNo;
         strInvoiceNo = infopdcrecivable.InvoiceNo;
         txtVoucherNo.Text = strInvoiceNo;
         decSufixprefixPdcReceivableID = infopdcrecivable.SuffixPrefixId;
         decPDCReceivableVoucherTypeId = infopdcrecivable.VoucherTypeId;
         VoucherTypeBll BllVoucherType = new VoucherTypeBll();
         isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(decPDCReceivableVoucherTypeId);
         if (isAutomatic)
         {
             txtVoucherNo.ReadOnly = true;
         }
         else
         {
             txtVoucherNo.ReadOnly = false;
             lblVoucherNoManualValidator.Visible = false;
         }
         if (infopdcrecivable.PdcReceivableMasterId != 0)
         {
             txtVoucherNo.Text = infopdcrecivable.InvoiceNo;
             dtpVoucherDate.Value = infopdcrecivable.Date;
             txtVoucherDate.Text = dtpVoucherDate.Value.ToString("dd-MMM-yyyy");
             txtNarration.Text = infopdcrecivable.Narration;
             cmbAccountLedger.SelectedValue = infopdcrecivable.LedgerId;
             txtAmount.Text = infopdcrecivable.Amount.ToString();
             if (infopdcrecivable.BankId != 0)
                 cmbBank.SelectedValue = infopdcrecivable.BankId;
             else
                 cmbBank.SelectedValue = string.Empty;
             txtcheckNo.Text = infopdcrecivable.ChequeNo;
             txtCheckDate.Text = infopdcrecivable.ChequeDate.ToString("dd-MMM-yyyy");
             btnSave.Text = "Update";
             PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
             List<DataTable> listObj = new List<DataTable>();
             listObj = BllPartyBalance.PartyBalanceViewByVoucherNoAndVoucherType(decPDCReceivableVoucherTypeId, strVoucherNo, infopdcrecivable.Date);
             dtblPartyBalance = listObj[0];
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PP24:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Edit Function
        /// </summary>
        /// <param name="decMasterId"></param>
        public void Edit(decimal decMasterId)
        {
            try
            {
                int inRowCount = dgvPaymentVoucher.RowCount;
                int inTableRowCount = dtblPartyBalance.Rows.Count;
                int inB = 0;
                PaymentMasterInfo InfoPaymentMaster = new PaymentMasterInfo();
                //PaymentMasterSP SpPaymentMaster = new PaymentMasterSP();
                PaymentDetailsInfo InfoPaymentDetails = new PaymentDetailsInfo();
                //PaymentDetailsSP SpPaymentDetails = new PaymentDetailsSP();
                PaymentVoucherBll BllPaymentVoucher = new PaymentVoucherBll();
                LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                LedgerPostingInfo InfoLegerPosting = new LedgerPostingInfo();
                PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                BankReconciliationBll BllBankReconcilation = new BankReconciliationBll();
                InfoPaymentMaster.Date = dtpDate.Value;
                InfoPaymentMaster.PaymentMasterId = decMasterId;
                InfoPaymentMaster.Extra1 = string.Empty;
                InfoPaymentMaster.Extra2 = string.Empty;
                InfoPaymentMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                InfoPaymentMaster.InvoiceNo = txtVoucherNo.Text.Trim();
                InfoPaymentMaster.LedgerId = Convert.ToDecimal(cmbBankorCash.SelectedValue.ToString());
                InfoPaymentMaster.Narration = txtNarration.Text.Trim();
                InfoPaymentMaster.SuffixPrefixId = decDailySuffixPrefixId;
                decimal decTotalAmount = TotalAmountCalculation();
                InfoPaymentMaster.TotalAmount = decTotalAmount;
                InfoPaymentMaster.UserId = PublicVariables._decCurrentUserId;

                InfoPaymentMaster.VoucherNo = strVoucherNo;

                InfoPaymentMaster.VoucherTypeId = decPaymentVoucherTypeId;
                decimal decPaymentMasterId = BllPaymentVoucher.PaymentMasterEdit(InfoPaymentMaster);
                if (decPaymentmasterId != 0)
                {
                    MasterLedgerPostingEdit();
                }
                foreach (object obj in arrlstOfRemove)
                {
                    string str = Convert.ToString(obj);
                    BllPaymentVoucher.PaymentDetailsDelete(Convert.ToDecimal(str));
                    BllLedgerPosting.LedgerPostDeleteByDetailsId(Convert.ToDecimal(str), strVoucherNo, decPaymentVoucherTypeId);
                }
                BllLedgerPosting.LedgerPostingDeleteByVoucherNoVoucherTypeIdAndLedgerId(strVoucherNo, decPaymentVoucherTypeId, 12);
                decimal decPaymentDetailsId1 = 0;
                for (int inI = 0; inI < inRowCount - 1; inI++)
                {
                    InfoPaymentDetails.Amount = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                    InfoPaymentDetails.ExchangeRateId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString());
                    InfoPaymentDetails.Extra1 = string.Empty;
                    InfoPaymentDetails.Extra2 = string.Empty;
                    if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                    {
                        InfoPaymentDetails.LedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString());
                    }
                    if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                    {
                        InfoPaymentDetails.ChequeNo = dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString();
                        if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                        {
                            InfoPaymentDetails.ChequeDate = Convert.ToDateTime(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value);
                        }
                        else
                        {
                            InfoPaymentDetails.ChequeDate = DateTime.Now;
                        }
                    }
                    else
                    {
                        InfoPaymentDetails.ChequeNo = string.Empty;
                        InfoPaymentDetails.ChequeDate = DateTime.Now;
                    }
                    InfoPaymentDetails.PaymentMasterId = decPaymentMasterId;
                    if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].FormattedValue.ToString() == "0")//if new rows are added
                    {
                        if (dgvPaymentVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")//add new rows added which are completed
                        {
                            decimal decPaymentDetailsId = BllPaymentVoucher.PaymentDetailsAdd(InfoPaymentDetails);//to add new rows in payment details
                            if (decPaymentDetailsId != 0)
                            {
                                for (int inJ = 0; inJ < inTableRowCount; inJ++)
                                {
                                    if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString())
                                    {
                                        PartyBalanceAddOrEdit(inJ);
                                    }
                                }
                                inB++;
                                DetailsLedgerPosting(inI, decPaymentDetailsId);//to add new ledger posting
                            }
                        }
                    }
                    else
                    {
                        if (dgvPaymentVoucher.Rows[inI].HeaderCell.Value != null && dgvPaymentVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")//add new rows updated which are completed
                        {
                            InfoPaymentDetails.PaymentDetailsId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].Value.ToString());
                            decimal decPaymentDetailsId = BllPaymentVoucher.PaymentDetailsEdit(InfoPaymentDetails);//to edit rows
                            if (decPaymentDetailsId != 0)
                            {
                                for (int inJ = 0; inJ < inTableRowCount; inJ++)
                                {
                                    if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString())
                                    {
                                        PartyBalanceAddOrEdit(inJ);
                                    }
                                }
                                inB++;
                                decPaymentDetailsId1 = InfoPaymentDetails.PaymentDetailsId;
                                decimal decLedgerPostId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value.ToString());
                                DetailsLedgerPostingEdit(inI, decLedgerPostId, decPaymentDetailsId1);
                            }
                        }
                        else
                        {
                            decimal decDetailsId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].Value.ToString());
                            BllPaymentVoucher.PaymentDetailsDelete(decDetailsId);
                            BllLedgerPosting.LedgerPostDeleteByDetailsId(decDetailsId, strVoucherNo, decPaymentVoucherTypeId);
                            for (int inJ = 0; inJ < dtblPartyBalance.Rows.Count; inJ++)
                            {
                                if (dtblPartyBalance.Rows.Count == inJ)
                                {
                                    break;
                                }
                                if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                                {
                                    if (dtblPartyBalance.Rows[inJ]["LedgerId"].ToString() == dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString())
                                    {
                                        if (dtblPartyBalance.Rows[inJ]["PartyBalanceId"].ToString() != "0")
                                        {
                                            arrlstOfDeletedPartyBalanceRow.Add(dtblPartyBalance.Rows[inJ]["PartyBalanceId"]);
                                        }
                                    }
                                }
                            }
                        }
                    }

                }
                DeletePartyBalanceOfRemovedRow();
                isUpdated = true;
                Messages.UpdatedMessage();
                if (cbxPrintafterSave.Checked)
                {
                    if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                    {
                        PrintForDotMatrix(decPaymentmasterId);
                    }
                    else
                    {
                        Print(decPaymentMasterId);
                    }
                }
                if (frmPaymentRegisterObj != null)
                {
                    this.Close();
                    frmPaymentRegisterObj.CallFromPaymentVoucher(this);
                }
                if (frmPaymentReportObj != null)
                {
                    this.Close();
                    frmPaymentReportObj.CallFromPaymentVoucher(this);
                }
                if (frmDayBookObj != null)
                {
                    this.Close();
                }
                if (frmBillallocationObj != null)
                {
                    this.Close();
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("PV18:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// To fill grid
        /// </summary>
        public void FillGrid()
        {
            try
            {
                if (!isFormLoad)
                {
                    PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                    List<DataTable> listObj = new List<DataTable>();
                    cmbLedger.Enabled = true;
                    string p = string.Empty;
                    if (cmbLedger.SelectedValue != null)
                        p = cmbLedger.SelectedValue.ToString().ToString();
                    if (cmbLedger.SelectedValue != null)
                    {
                        if (rbtnVoucher.Checked)
                        {

                            fillby = "Voucher";
                        }
                        else if (rbtnLedgerWise.Checked)
                        {
                            fillby = "Ledger";
                        }
                        if (rbtnReceivable.Checked && rbtnLedgerWise.Checked)
                            listObj = BllPartyBalance.AgeingReportLedgerReceivable(DateTime.Parse(dtpAgeingDate.Text), Convert.ToDecimal(cmbLedger.SelectedValue.ToString()));
                        else if (rbtnReceivable.Checked && rbtnVoucher.Checked)
                            listObj = BllPartyBalance.AgeingReportVoucherReceivable(DateTime.Parse(dtpAgeingDate.Text), Convert.ToDecimal(cmbLedger.SelectedValue.ToString()));
                        else if (rbtnPayable.Checked && rbtnLedgerWise.Checked)
                            listObj = BllPartyBalance.AgeingReportLedgerPayable(DateTime.Parse(dtpAgeingDate.Text), Convert.ToDecimal(cmbLedger.SelectedValue.ToString()));
                        else if (rbtnPayable.Checked && rbtnVoucher.Checked)
                            listObj = BllPartyBalance.AgeingReportVoucherPayable(DateTime.Parse(dtpAgeingDate.Text), Convert.ToDecimal(cmbLedger.SelectedValue.ToString()));
                    }
                    decimal dcTotOne = 0m;
                    decimal dcTotTwo = 0m;
                    decimal dcTotThree = 0m;
                    decimal dcTotFour = 0m;
                    if (listObj[0].Rows.Count > 0)
                    {
                        dcTotOne = decimal.Parse(listObj[0].Compute("Sum([1 to 30])", string.Empty).ToString());
                        dcTotTwo = decimal.Parse(listObj[0].Compute("Sum([31 to 60])", string.Empty).ToString());
                        dcTotThree = decimal.Parse(listObj[0].Compute("Sum([61 to 90])", string.Empty).ToString());
                        dcTotFour = decimal.Parse(listObj[0].Compute("Sum([90 above])", string.Empty).ToString());
                    }
                    listObj[0].Rows.Add();
                    listObj[0].Rows[listObj[0].Rows.Count - 1]["Account Ledger"] = "Total :";
                    listObj[0].Rows[listObj[0].Rows.Count - 1]["1 to 30"] = dcTotOne;
                    listObj[0].Rows[listObj[0].Rows.Count - 1]["31 to 60"] = dcTotTwo;
                    listObj[0].Rows[listObj[0].Rows.Count - 1]["61 to 90"] = dcTotThree;
                    listObj[0].Rows[listObj[0].Rows.Count - 1]["90 above"] = dcTotFour;
                    dgvReport.DataSource = listObj[0];
                    if (dgvReport.Columns.Count > 0)
                    {
                        if (rbtnLedgerWise.Checked == true)
                        {
                            dgvReport.Columns["ledgerId"].Visible = false;
                            dgvReport.Columns["masterId"].Visible = false;
                            dgvReport.Columns["voucherTypeId"].Visible = false;
                            dgvReport.Columns["VoucherType"].Visible = false;
                            dgvReport.Columns["VoucherNo"].Visible = false;
                            dgvReport.Columns["Date"].Visible = true;
                            dgvReport.Columns["Account Ledger"].Visible = true;
                        }
                        else
                        {
                            dgvReport.Columns["masterId"].Visible = false;
                            dgvReport.Columns["ledgerId"].Visible = false;
                            dgvReport.Columns["voucherTypeId"].Visible = false;
                            dgvReport.Columns["VoucherType"].Visible = true;
                            dgvReport.Columns["VoucherNo"].Visible = true;
                            dgvReport.Columns["Date"].Visible = true;
                            dgvReport.Columns["Account Ledger"].Visible = false;
                        }
                    }
                    dgvReport.Columns["1 to 30"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    dgvReport.Columns["31 to 60"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    dgvReport.Columns["61 to 90"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    dgvReport.Columns["90 above"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    lblTotOne.Text = "1 to 30: " + dcTotOne.ToString();
                    lblTotTwo.Text = "31 to 60: " + dcTotTwo.ToString();
                    lblTotThree.Text = "61 to 90: " + dcTotThree.ToString();
                    lblTotFour.Text = "90 above: " + dcTotFour.ToString();
                    ledgerId = string.Empty;
                    if (inCurrenRowIndex >= 0 && dgvReport.Rows.Count > 0 && inCurrenRowIndex < dgvReport.Rows.Count)
                    {
                        dgvReport.CurrentCell = dgvReport.Rows[inCurrenRowIndex].Cells["1 to 30"];
                        dgvReport.CurrentCell.Selected = true;
                    }
                    inCurrenRowIndex = 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("AR3:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Fill function from coming from register or report or other forms
 /// </summary>
 public void FillRegisterOrReport()
 {
     //SalesMasterSP spSalesMaster = new SalesMasterSP();
     //SalesDetailsSP spSalesDetails = new SalesDetailsSP();
     VoucherTypeBll BllVoucherType = new VoucherTypeBll();
     //SalesBillTaxSP spSalesBillTax = new SalesBillTaxSP();
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     try
     {
         isFromEditMode = true;
         btnSave.Text = "Update";
         btnDelete.Enabled = true;
         txtInvoiceNo.ReadOnly = true;
         List<DataTable> listMaster = BllSalesInvoice.SalesInvoiceSalesMasterViewBySalesMasterId(decSalesInvoiceIdToEdit);
         DecSalesInvoiceVoucherTypeId = Convert.ToDecimal(listMaster[0].Rows[0]["voucherTypeId"].ToString());
         VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
         infoVoucherType = BllVoucherType.VoucherTypeView(DecSalesInvoiceVoucherTypeId);
         this.Text = infoVoucherType.VoucherTypeName;
         txtDate.Text = listMaster[0].Rows[0]["date"].ToString();
         dtpDate.Value = DateTime.Parse(txtDate.Text);
         CurrencyComboFill();
         txtInvoiceNo.Text = listMaster[0].Rows[0]["invoiceNo"].ToString();
         txtCreditPeriod.Text = listMaster[0].Rows[0]["creditPeriod"].ToString();
         strVoucherNo = listMaster[0].Rows[0]["voucherNo"].ToString();
         decSalseInvoiceSuffixPrefixId = Convert.ToDecimal(listMaster[0].Rows[0]["suffixPrefixId"].ToString());
         isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(DecSalesInvoiceVoucherTypeId);
         cmbCashOrParty.SelectedValue = listMaster[0].Rows[0]["ledgerId"].ToString();
         cmbSalesAccount.SelectedValue = listMaster[0].Rows[0]["salesAccount"].ToString();
         cmbSalesMan.SelectedValue = listMaster[0].Rows[0]["employeeId"].ToString();
         txtCustomer.Text = listMaster[0].Rows[0]["customerName"].ToString();
         txtTransportCompany.Text = listMaster[0].Rows[0]["transportationCompany"].ToString();
         txtVehicleNo.Text = listMaster[0].Rows[0]["lrNo"].ToString();
         txtNarration.Text = listMaster[0].Rows[0]["narration"].ToString();
         cmbCurrency.SelectedValue = Convert.ToDecimal(listMaster[0].Rows[0]["exchangeRateId"].ToString());
         txtTotalAmount.Text = listMaster[0].Rows[0]["totalAmount"].ToString();
         lblTaxTotalAmount.Text = listMaster[0].Rows[0]["taxAmount"].ToString();
         cmbPricingLevel.SelectedValue = Convert.ToDecimal(listMaster[0].Rows[0]["pricingLevelId"].ToString());
         if (listMaster[0].Rows[0]["quotationMasterId"].ToString() != "0")
         {
             cmbSalesMode.Text = "Against Quotation";
             againstOrderComboFill();
             cmbSalesModeOrderNo.SelectedValue = listMaster[0].Rows[0]["quotationMasterId"].ToString();
             lblSalesModeOrderNo.Text = "Quotation No";
             cmbCurrency.Enabled = false;
             cmbPricingLevel.Enabled = false;
         }
         else if (listMaster[0].Rows[0]["orderMasterId"].ToString() != "0")
         {
             cmbSalesMode.Text = "Against SalesOrder";
             againstOrderComboFill();
             cmbSalesModeOrderNo.SelectedValue = listMaster[0].Rows[0]["orderMasterId"].ToString();
             lblSalesModeOrderNo.Text = "Order No";
             cmbCurrency.Enabled = false;
             cmbPricingLevel.Enabled = false;
         }
         else if (listMaster[0].Rows[0]["deliveryNoteMasterId"].ToString() != "0")
         {
             cmbSalesMode.Text = "Against Delivery Note";
             againstOrderComboFill();
             cmbSalesModeOrderNo.SelectedValue = listMaster[0].Rows[0]["deliveryNoteMasterId"].ToString();
             lblSalesModeOrderNo.Text = "Delivery Note No";
             cmbCurrency.Enabled = false;
             cmbPricingLevel.Enabled = false;
         }
         else
         {
             cmbSalesMode.SelectedText = "NA";
         }
         if (txtInvoiceNo.Enabled)
         {
             txtDate.Focus();
         }
         else
         {
             txtInvoiceNo.Focus();
         }
         //DataTable dtblDetails = new DataTable();
         List<DataTable> listObj = new List<DataTable>();
         listObj = BllSalesInvoice.SalesInvoiceSalesDetailsViewBySalesMasterId(decSalesInvoiceIdToEdit);
         dgvSalesInvoiceTaxComboFill();
         dgvSalesInvoice.Rows.Clear();
         for (int i = 0; i < listObj[0].Rows.Count; i++)
         {
             dgvSalesInvoice.Rows.Add();
             IsSetGridValueChange = false;
             dgvSalesInvoice.Rows[i].HeaderCell.Value = string.Empty;
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value = Convert.ToDecimal(listObj[0].Rows[i]["salesDetailsId"].ToString());
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceSlno"].Value = listObj[0].Rows[i]["slNo"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceBarcode"].Value = listObj[0].Rows[i]["barcode"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceProductCode"].Value = listObj[0].Rows[i]["productCode"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceProductName"].Value = listObj[0].Rows[i]["productName"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceProductId"].Value = listObj[0].Rows[i]["productId"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceBrand"].Value = listObj[0].Rows[i]["brandName"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceQty"].Value = listObj[0].Rows[i]["qty"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoicePurchaseRate"].Value = listObj[0].Rows[i]["purchaseRate"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceAmount"].Value = listObj[0].Rows[i]["amount"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceGrossValue"].Value = listObj[0].Rows[i]["grossAmount"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoicembUnitName"].Value = Convert.ToDecimal(listObj[0].Rows[i]["unitId"].ToString());
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceRate"].Value = listObj[0].Rows[i]["rate"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvcmbSalesInvoiceGodown"].Value = Convert.ToDecimal(listObj[0].Rows[i]["godownId"].ToString());
             RackComboFill(Convert.ToDecimal(dgvSalesInvoice.Rows[i].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString()), i, dgvSalesInvoice.Rows[i].Cells["dgvcmbSalesInvoiceRack"].ColumnIndex);
             dgvSalesInvoice.Rows[i].Cells["dgvcmbSalesInvoiceRack"].Value = Convert.ToDecimal(listObj[0].Rows[i]["rackId"].ToString());
             if (listObj[0].Rows[i]["batchId"] != null && listObj[0].Rows[i]["batchId"].ToString() != string.Empty)
             {
                 dgvSalesInvoice.Rows[i].Cells["dgvcmbSalesInvoiceBatch"].Value = Convert.ToDecimal(listObj[0].Rows[i]["batchId"].ToString());
             }
             else
             {
                 dgvSalesInvoice.Rows[i].Cells["dgvcmbSalesInvoiceBatch"].Value = string.Empty;
             }
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceMrp"].Value = listObj[0].Rows[i]["mrp"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceSalesRate"].Value = listObj[0].Rows[i]["salesRate"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceDiscountAmount"].Value = listObj[0].Rows[i]["discount"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceNetAmount"].Value = listObj[0].Rows[i]["netAmount"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvcmbSalesInvoiceTaxName"].Value = Convert.ToDecimal(listObj[0].Rows[i]["taxId"].ToString());
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceTaxAmount"].Value = listObj[0].Rows[i]["taxAmount"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceUnitConversionId"].Value = listObj[0].Rows[i]["unitConversionId"].ToString();
             lblTotalQuantitydisplay.Text = listObj[0].Rows[i]["qty"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSISalesOrderDetailsId"].Value = Convert.ToDecimal(listObj[0].Rows[i]["orderDetailsId"].ToString());  // here get fill the grid colum for the editing prps
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value = listObj[0].Rows[i]["deliveryNoteDetailsId"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceQuotationDetailsId"].Value = listObj[0].Rows[i]["quotationDetailsId"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceVoucherTypeId"].Value = Convert.ToDecimal(listObj[0].Rows[i]["voucherTypeRefNo"].ToString());  // here get fill the grid colum for the editing prps
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceVoucherNo"].Value = listObj[0].Rows[i]["voucherRefNo"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceInvoiceNo"].Value = listObj[0].Rows[i]["invoiceRefNo"].ToString();
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceBarcode"].ReadOnly = true;
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceProductCode"].ReadOnly = true;
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceProductName"].ReadOnly = true;
             dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceBrand"].ReadOnly = true;
             dgvSalesInvoice.Rows[i].Cells["dgvcmbSalesInvoiceBatch"].ReadOnly = true;
             if (cmbSalesMode.SelectedIndex != 0)
             {
                 strVoucherNoTostockPost = dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceVoucherNo"].Value.ToString();
                 strInvoiceNoTostockPost = dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceInvoiceNo"].Value.ToString();
                 decVouchertypeIdTostockPost = Convert.ToDecimal(dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceVoucherTypeId"].Value);
             }
             GrossValueCalculation(i);
             DiscountCalculation(i, dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceDiscountAmount"].ColumnIndex);
             taxAndGridTotalAmountCalculation(i);
             decCurrentRate = Convert.ToDecimal(dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceRate"].Value.ToString());
             decCurrentConversionRate = Convert.ToDecimal(listObj[0].Rows[i]["conversionRate"].ToString());
             UnitConversionCalc(i);
             if (cmbSalesModeOrderNo.Visible == true)
             {
                 dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoicembUnitName"].ReadOnly = true;
             }
         }
         List<DataTable> listAdditionalCost = new List<DataTable>();
         listAdditionalCost = BllSalesInvoice.SalesInvoiceAdditionalCostViewByVoucherNoUnderVoucherType(DecSalesInvoiceVoucherTypeId, strVoucherNo);
         for (int i = 0; i < listAdditionalCost[0].Rows.Count; i++)
         {
             dgvSalesInvoiceLedger.Rows.Add();
             dgvSalesInvoiceLedger.Rows[i].Cells["dgvtxtAdditionalCostId"].Value = listAdditionalCost[0].Rows[i]["additionalCostId"].ToString();
             dgvSalesInvoiceLedger.Rows[i].Cells["dgvCmbAdditionalCostledgerName"].Value = Convert.ToDecimal(listAdditionalCost[0].Rows[i]["ledgerId"].ToString());
             dgvSalesInvoiceLedger.Rows[i].Cells["dgvtxtAdditionalCoastledgerAmount"].Value = listAdditionalCost[0].Rows[i]["amount"].ToString();
             List<DataTable> ListObj = new List<DataTable>();
             AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
             ListObj = bllAccountLedger.AccountLedgerViewForAdditionalCost();
             DataGridViewComboBoxCell dgvccVoucherType = (DataGridViewComboBoxCell)dgvSalesInvoiceLedger[dgvSalesInvoiceLedger.Columns["dgvCmbAdditionalCostledgerName"].Index, i];
             dgvccVoucherType.DataSource = ListObj[0];
             dgvccVoucherType.ValueMember = "ledgerId";
             dgvccVoucherType.DisplayMember = "ledgerName";
         }
         List<DataTable> ListDrOrCr = BllSalesInvoice.salesinvoiceAdditionalCostCheckdrOrCrforSiEdit(DecSalesInvoiceVoucherTypeId, strVoucherNo);
         if (ListDrOrCr[0].Rows.Count > 0)
         {
             if (Convert.ToDecimal(ListDrOrCr[0].Rows[0]["credit"].ToString()) != 0)
             {
                 cmbCashOrbank.SelectedValue = Convert.ToDecimal(ListDrOrCr[0].Rows[0]["ledgerId"].ToString());
                 cmbCashOrbank.Visible = true;
                 lblcashOrBank.Visible = true;
                 cmbDrorCr.SelectedIndex = 0;
                 decBankOrCashIdForEdit = Convert.ToDecimal(cmbCashOrbank.SelectedValue.ToString());
             }
             else
             {
                 cmbDrorCr.SelectedIndex = 1;
             }
         }
         taxGridFill();
         List<DataTable> listTax = new List<DataTable>();
         listTax = BllSalesInvoice.SalesInvoiceSalesBillTaxViewAllBySalesMasterId(decSalesInvoiceIdToEdit);
         foreach (DataGridViewRow dgvrowTax in dgvSalesInvoiceTax.Rows)
         {
             for (int ini = 0; ini < listTax[0].Rows.Count; ini++)
             {
                 if (dgvrowTax.Cells["dgvtxtTtaxId"].Value != null && dgvrowTax.Cells["dgvtxtTtaxId"].Value.ToString() != string.Empty)
                 {
                     decimal decId = Convert.ToDecimal(listTax[0].Rows[ini]["taxId"].ToString());
                     if (dgvrowTax.Cells["dgvtxtTtaxId"].Value.ToString() == decId.ToString())
                     {
                         dgvrowTax.Cells["dgvtxtTtaxAmount"].Value = listTax[0].Rows[ini]["taxAmount"].ToString();
                         break;
                     }
                     else
                     {
                         dgvrowTax.Cells["dgvtxtTtaxAmount"].Value = "0.00";
                     }
                 }
             }
         }
         LedgerGridTotalAmountCalculation();
         SiGridTotalAmountCalculation();
         txtGrandTotal.Text = listMaster[0].Rows[0]["grandTotal"].ToString();
         txtBillDiscount.Text = listMaster[0].Rows[0]["billDiscount"].ToString();
         bool isPartyBalanceRef = false;
         AccountLedgerBll bllAccountLedger1 = new AccountLedgerBll();
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         isPartyBalanceRef = bllAccountLedger1.PartyBalanceAgainstReferenceCheck(strVoucherNo, DecSalesInvoiceVoucherTypeId);
         if (isPartyBalanceRef)
         {
             cmbCashOrParty.Enabled = false;
         }
         else
         {
             cmbCashOrParty.Enabled = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 77" + 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>
 /// Party balance save function
 /// </summary>
 public void partyBalanceAdd()
 {
     PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
     SalesMasterInfo InfoSalesMaster = new SalesMasterInfo();
     PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
     try
     {
         infoPartyBalance.Date = Convert.ToDateTime(txtDate.Text.ToString());
         infoPartyBalance.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         infoPartyBalance.VoucherNo = strVoucherNo;
         infoPartyBalance.InvoiceNo = txtInvoiceNo.Text.Trim();
         infoPartyBalance.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
         infoPartyBalance.AgainstVoucherTypeId = 0;
         infoPartyBalance.AgainstVoucherNo = "0";
         infoPartyBalance.AgainstInvoiceNo = "0";
         infoPartyBalance.ReferenceType = "New";
         infoPartyBalance.Debit = Convert.ToDecimal(txtGrandTotal.Text.Trim().ToString());
         infoPartyBalance.Credit = 0;
         infoPartyBalance.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text.ToString());
         infoPartyBalance.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
         infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         infoPartyBalance.ExtraDate = DateTime.Now;
         infoPartyBalance.Extra1 = string.Empty;
         infoPartyBalance.Extra2 = string.Empty;
         BllPartyBalance.PartyBalanceAdd(infoPartyBalance);
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 72" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill the fields for edit or delete
 /// </summary>
 public void FillFunction()
 {
     try
     {
         ServicesBll BllService = new ServicesBll();
         //ServiceMasterSP spServiceMaster = new ServiceMasterSP();
         ServiceMasterInfo infoServiceMaster = new ServiceMasterInfo();
         LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
         VoucherTypeBll BllVoucherType = new VoucherTypeBll();
         VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
         decServiceMasterId = decMasterId;
         infoServiceMaster = BllService.ServiceMasterView(decServiceMasterId);
         infoVoucherType = BllVoucherType.VoucherTypeView(infoServiceMaster.VoucherTypeId);
         this.Text = infoVoucherType.VoucherTypeName;
         isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(infoServiceMaster.VoucherTypeId);
         txtInvoiceNumber.ReadOnly = true;
         strVoucherNo = infoServiceMaster.VoucherNo.ToString();
         txtInvoiceNumber.Text = infoServiceMaster.InvoiceNo;
         txtCreditPeriod.Text = infoServiceMaster.CreditPeriod.ToString();
         strInvoiceNo = infoServiceMaster.InvoiceNo.ToString();
         decServiceSuffixPrefixId = Convert.ToDecimal(infoServiceMaster.SuffixPrefixId.ToString());
         DecServicetVoucherTypeId = Convert.ToDecimal(infoServiceMaster.VoucherTypeId.ToString());
         int inDecimalPlace = PublicVariables._inNoOfDecimalPlaces;
         txtVoucherDate.Text = infoServiceMaster.Date.ToString("dd-MMM-yyyy");
         dtpVoucherDate.Value = Convert.ToDateTime(infoServiceMaster.Date);
         cmbCashParty.SelectedValue = infoServiceMaster.LedgerId;
         cmbServiceAC.SelectedValue = infoServiceMaster.ServiceAccount;
         cmbSalesman.SelectedValue = infoServiceMaster.EmployeeId;
         txtCustomer.Text = infoServiceMaster.Customer;
         txtNarration.Text = infoServiceMaster.Narration;
         List<DataTable> listObjServiceDetails = new List<DataTable>();
         listObjServiceDetails = BllService.ServiceDetailsViewWithMasterId(decServiceMasterId);
         for (int i = 0; i < listObjServiceDetails[0].Rows.Count; i++)
         {
             dgvServiceVoucher.Rows.Add();
             dgvServiceVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value = Convert.ToDecimal(listObjServiceDetails[0].Rows[i]["serviceDetailsId"].ToString());
             dgvServiceVoucher.Rows[i].Cells["dgvtxtServiceMasterId"].Value = Convert.ToDecimal(listObjServiceDetails[0].Rows[i]["serviceMasterId"].ToString());
             dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value = Convert.ToDecimal(listObjServiceDetails[0].Rows[i]["serviceId"].ToString());
             dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value = listObjServiceDetails[0].Rows[i]["measure"].ToString();
             dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value = listObjServiceDetails[0].Rows[i]["amount"].ToString();
             decimal decDetailsId1 = Convert.ToDecimal(listObjServiceDetails[0].Rows[i]["serviceDetailsId"].ToString());
             decimal decLedgerPostingId = BllLedgerPosting.LedgerPostingIdFromDetailsId(decDetailsId1, strVoucherNo, DecServicetVoucherTypeId);
             dgvServiceVoucher.Rows[i].Cells["dgvtxtLedgerPostingId"].Value = decLedgerPostingId.ToString();
         }
         cmbCurrency.SelectedValue = infoServiceMaster.ExchangeRateId;
         txtTotalAmount.Text = infoServiceMaster.TotalAmount.ToString();
         txtDiscount.Text = infoServiceMaster.Discount.ToString();
         txtGrandTotal.Text = infoServiceMaster.GrandTotal.ToString();
         infoPartyBalance = BllPartyBalance.PartyBalanceViewByVoucherNoAndVoucherTypeId(DecServicetVoucherTypeId, strVoucherNo, infoServiceMaster.Date);
         decPartyBalanceId = infoPartyBalance.PartyBalanceId;
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 32 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to call frmPdcReceivable form to set amount for sundry creditors or sundry debtors
 /// </summary>
 /// <param name="frmPDCreceivable"></param>
 /// <param name="decId"></param>
 /// <param name="dtblPartyBalance"></param>
 /// <param name="decPdcReceivableVoucherTypeId"></param>
 /// <param name="strVoucherNo"></param>
 /// <param name="date"></param>
 public void CallThisFormFromPDCReceivable(frmPdcReceivable frmPDCreceivable, decimal decId, DataTable dtblPartyBalance, decimal decPdcReceivableVoucherTypeId, string strVoucherNo, DateTime date)
 {
     try
     {
         decVoucherTypeId = decPdcReceivableVoucherTypeId;
         this.strVoucherNo = strVoucherNo;
         decLedgerId = decId;
         // inRowIndex = inIndex;
         this.dtblPartyBalance = dtblPartyBalance;
         strDebitOrCredit = "Cr";
         base.Show();
         this.frmPdcReceivableObj = frmPDCreceivable;
         frmPdcReceivableObj.Enabled = false;
         int inTableRowCount = dtblPartyBalance.Rows.Count;
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         PartyBalanceInfo InfoPartyBalance = new PartyBalanceInfo();
         List<DataTable> listObj = new List<DataTable>();
         if (inTableRowCount > 0)
         {
             int inK = 0;
             for (int inI = 0; inI < inTableRowCount; inI++)
             {
                 if (decLedgerId == Convert.ToDecimal(dtblPartyBalance.Rows[inI]["LedgerId"].ToString()))
                 {
                     if (strDebitOrCredit == dtblPartyBalance.Rows[inI]["DebitOrCredit"].ToString())
                     {
                         dgvPartyBalance.Rows.Add();
                         dgvPartyBalance.Rows[inK].Cells["dgvcmbReference"].Value = dtblPartyBalance.Rows[inI]["ReferenceType"].ToString();
                         if (dgvPartyBalance.Rows[inK].Cells["dgvcmbReference"].Value.ToString() == "Against")
                         {
                             //----------------------------------------------------------------------------//
                             dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].ReadOnly = false;
                             listObj = BllPartyBalance.PartyBalanceComboViewByLedgerId(decLedgerId, strDebitOrCredit, decVoucherTypeId, strVoucherNo);
                             DataGridViewComboBoxCell dgvccVoucherType = (DataGridViewComboBoxCell)dgvPartyBalance[dgvPartyBalance.Columns["dgvcmbVoucherType"].Index, dgvPartyBalance.CurrentRow.Index - 1];
                             dgvccVoucherType.DataSource = listObj[0];
                             dgvccVoucherType.ValueMember = "value";
                             dgvccVoucherType.DisplayMember = "display";
                             //============================================================================//
                             dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value = dtblPartyBalance.Rows[inI]["AgainstVoucherTypeId"].ToString() + "_" + dtblPartyBalance.Rows[inI]["AgainstVoucherNo"].ToString();
                             dgvPartyBalance.Rows[inK].Cells["dgvtxtVoucherNo"].Value = dtblPartyBalance.Rows[inI]["AgainstVoucherNo"].ToString();
                             dgvPartyBalance.Rows[inK].Cells["dgvtxtInvoiceNo"].Value = dtblPartyBalance.Rows[inI]["AgainstInvoiceNo"].ToString();
                             if (dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value != null && dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value.ToString() != string.Empty)
                             {
                                 for (int inD = 0; inD < listObj[0].Rows.Count; inD++)
                                 {
                                     if (dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value.ToString() == listObj[0].Rows[inD]["value"].ToString())
                                     {
                                         dgvPartyBalance.Rows[inK].Cells["dgvtxtpending"].Value = Math.Round(Convert.ToDecimal(listObj[0].Rows[inD]["balance"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                         break;
                                     }
                                 }
                             }
                             dgvPartyBalance.Rows[inK].Cells["dgvcmbCurrency"].ReadOnly = true;
                         }
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtAmount"].Value = Math.Round(Convert.ToDecimal(dtblPartyBalance.Rows[inI]["Amount"].ToString()), Convert.ToInt32(PublicVariables._inNoOfDecimalPlaces)).ToString();
                         dgvPartyBalance.Rows[inK].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(dtblPartyBalance.Rows[inI]["CurrencyId"].ToString());
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtCrDr"].Value = strDebitOrCredit;
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtPartyBalanceId"].Value = dtblPartyBalance.Rows[inI]["partyBalanceId"].ToString();
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtOldExchangeRateId"].Value = dtblPartyBalance.Rows[inI]["OldExchangeRate"].ToString();
                         inK++;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PB:13" + ex.Message, "Open Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }