/// <summary>
 /// Save or edit function checking the invalid entries of Form
 /// </summary>
 public void SaveOrEdit()
 {
     decimal decEdit = 0;
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     try
     {
         dgvSalesInvoice.ClearSelection();
         int inRow = dgvSalesInvoice.RowCount;
         if (txtInvoiceNo.Text.Trim() == string.Empty)
         {
             Messages.InformationMessage("Enter voucher number");
             txtInvoiceNo.Focus();
         }
         else if (BllSalesInvoice.SalesInvoiceInvoiceNumberCheckExistence(txtInvoiceNo.Text.Trim(), 0, DecSalesInvoiceVoucherTypeId) == true && btnSave.Text == "Save")
         {
             Messages.InformationMessage("Invoice number already exist");
             txtInvoiceNo.Focus();
         }
         else if (txtDate.Text.Trim() == string.Empty)
         {
             Messages.InformationMessage("Select a date in between financial year");
             txtDate.Focus();
         }
         else if (cmbCashOrParty.SelectedValue == null)
         {
             Messages.InformationMessage("Select Cash/Party");
             cmbCashOrParty.Focus();
         }
         else if (cmbCurrency.SelectedValue == null)
         {
             Messages.InformationMessage("Select Currency");
             cmbCurrency.Focus();
         }
         else if (cmbSalesMode.SelectedText == "NA" && cmbSalesModeOrderNo.SelectedValue == null)
         {
             Messages.InformationMessage("Select a Order No");
             cmbSalesModeOrderNo.Focus();
         }
         else if (cmbSalesAccount.SelectedValue == null)
         {
             Messages.InformationMessage("Select SalesAccount");
             cmbSalesAccount.Focus();
         }
         else if (cmbSalesMan.SelectedValue == null)
         {
             Messages.InformationMessage("Select SalesMan");
             cmbSalesMan.Focus();
         }
         else if (txtDate.Text.Trim() == string.Empty)
         {
             Messages.InformationMessage("Select Credit period");
             txtCreditPeriod.Focus();
         }
         else if (inRow - 1 == 0 || dgvSalesInvoice.Rows[0].Cells["dgvtxtSalesInvoiceProductId"].Value as string == string.Empty)
         {
             Messages.InformationMessage("Can't save Sales Invoice without atleast one product with complete details");
             dgvSalesInvoice.Focus();
         }
         else
         {
             if (RemoveIncompleteRowsFromGrid())
             {
                 if (dgvSalesInvoice.Rows[0].Cells["dgvtxtSalesInvoiceProductName"].Value == null && dgvSalesInvoice.Rows[0].Cells["dgvtxtSalesInvoiceQty"].Value == null)
                 {
                     MessageBox.Show("Can't save Sales Invoice without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     dgvSalesInvoice.ClearSelection();
                     dgvSalesInvoice.Focus();
                 }
                 else
                 {
                     if (btnSave.Text == "Save")
                     {
                         if (dgvSalesInvoice.Rows[0].Cells["dgvtxtSalesInvoiceProductName"].Value == null)
                         {
                             MessageBox.Show("Can't save Sales Invoice without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             dgvSalesInvoice.ClearSelection();
                             dgvSalesInvoice.Focus();
                         }
                         else
                         {
                             if (PublicVariables.isMessageAdd)
                             {
                                 if (Messages.SaveMessage())
                                 {
                                     RemoveIncompleteRowsFromAdditionalCostGrid();
                                     SaveFunction();
                                 }
                             }
                             else
                             {
                                 RemoveIncompleteRowsFromAdditionalCostGrid();
                                 SaveFunction();
                             }
                         }
                     }
                     if (btnSave.Text == "Update")
                     {
                         if (QuantityCheckWithReference() == 1 && PartyBalanceCheckWithReference() == 1)
                         {
                             if (dgvSalesInvoice.Rows[0].Cells["dgvtxtSalesInvoiceProductName"].Value == null)
                             {
                                 MessageBox.Show("Can't Edit Sales Invoice without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                 dgvSalesInvoice.ClearSelection();
                                 dgvSalesInvoice.Focus();
                             }
                             else if (decEdit == 1)
                             {
                                 MessageBox.Show("Can't Edit SalesInvoice with Invalid Quantity", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                 dgvSalesInvoice.ClearSelection();
                                 dgvSalesInvoice.Focus();
                             }
                             else
                             {
                                 if (PublicVariables.isMessageEdit)
                                 {
                                     if (Messages.UpdateMessage())
                                     {
                                         EditFunction();
                                     }
                                 }
                                 else
                                 {
                                     EditFunction();
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 69" + 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 SaveFunction()
 {
     StockPostingInfo infoStockPosting = new StockPostingInfo();
     SalesMasterInfo InfoSalesMaster = new SalesMasterInfo();
     SalesDetailsInfo InfoSalesDetails = new SalesDetailsInfo();
     StockPostingBll BllStockPosting = new StockPostingBll();
     AdditionalCostInfo infoAdditionalCost = new AdditionalCostInfo();
     AditionalCostBll bllAditionalCost = new AditionalCostBll();
     SalesBillTaxInfo infoSalesBillTax = new SalesBillTaxInfo();
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
     try
     {
         InfoSalesMaster.AdditionalCost = Convert.ToDecimal(lblLedgerTotalAmount.Text);
         InfoSalesMaster.BillDiscount = Convert.ToDecimal(txtBillDiscount.Text.Trim());
         InfoSalesMaster.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text.Trim().ToString());
         InfoSalesMaster.CustomerName = txtCustomer.Text.Trim();
         InfoSalesMaster.Date = Convert.ToDateTime(txtDate.Text.ToString());
         InfoSalesMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
         InfoSalesMaster.EmployeeId = Convert.ToDecimal(cmbSalesMan.SelectedValue.ToString());
         InfoSalesMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         InfoSalesMaster.GrandTotal = Convert.ToDecimal(txtGrandTotal.Text.Trim());
         InfoSalesMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         InfoSalesMaster.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
         if (isAutomatic)
         {
             InfoSalesMaster.InvoiceNo = txtInvoiceNo.Text.Trim();
             InfoSalesMaster.VoucherNo = strVoucherNo;
             InfoSalesMaster.SuffixPrefixId = decSalseInvoiceSuffixPrefixId;
         }
         else
         {
             InfoSalesMaster.InvoiceNo = txtInvoiceNo.Text.Trim();
             InfoSalesMaster.VoucherNo = strVoucherNo;
             InfoSalesMaster.SuffixPrefixId = 0;
         }
         if (cmbSalesMode.Text == "Against SalesOrder")
         {
             InfoSalesMaster.OrderMasterId = Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString());
         }
         else
         {
             InfoSalesMaster.OrderMasterId = 0;
         }
         if (cmbSalesMode.Text == "Against Delivery Note")
         {
             InfoSalesMaster.DeliveryNoteMasterId = Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString());
         }
         else
         {
             InfoSalesMaster.DeliveryNoteMasterId = 0;
         }
         if (cmbSalesMode.Text == "Against Quotation")
         {
             InfoSalesMaster.QuotationMasterId = Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString());
         }
         else
         {
             InfoSalesMaster.QuotationMasterId = 0;
         }
         InfoSalesMaster.Narration = txtNarration.Text.Trim();
         InfoSalesMaster.PricinglevelId = Convert.ToDecimal(cmbPricingLevel.SelectedValue.ToString());
         InfoSalesMaster.SalesAccount = Convert.ToDecimal(cmbSalesAccount.SelectedValue.ToString());
         InfoSalesMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text.Trim());
         if (dgvSalesInvoice.Columns["dgvcmbSalesInvoiceTaxName"].Visible)
         {
             InfoSalesMaster.TaxAmount = Convert.ToDecimal(lblTaxTotalAmount.Text.Trim());
         }
         else
         {
             InfoSalesMaster.TaxAmount = 0;
         }
         InfoSalesMaster.UserId = PublicVariables._decCurrentUserId;
         InfoSalesMaster.LrNo = txtVehicleNo.Text;
         InfoSalesMaster.TransportationCompany = txtTransportCompany.Text.Trim();
         InfoSalesMaster.POS = false;
         InfoSalesMaster.CounterId = 0;
         InfoSalesMaster.ExtraDate = DateTime.Now;
         InfoSalesMaster.Extra1 = string.Empty;
         InfoSalesMaster.Extra2 = string.Empty;
         decimal decSalesMasterId = BllSalesInvoice.SalesMasterAdd(InfoSalesMaster);
         int inRowCount = dgvSalesInvoice.RowCount;
         InfoSalesDetails.SalesMasterId = decSalesMasterId;
         InfoSalesDetails.ExtraDate = DateTime.Now;
         InfoSalesDetails.Extra1 = string.Empty;
         InfoSalesDetails.Extra2 = string.Empty;
         string strAgainstInvoiceN0 = txtInvoiceNo.Text.Trim();
         for (int inI = 0; inI < inRowCount - 1; inI++)
         {
             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 (cmbSalesMode.Text == "Against SalesOrder")
                     {
                         InfoSalesDetails.OrderDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSISalesOrderDetailsId"].Value.ToString());
                     }
                     else
                     {
                         InfoSalesDetails.OrderDetailsId = 0;
                     }
                     if (cmbSalesMode.Text == "Against Delivery Note")
                     {
                         InfoSalesDetails.DeliveryNoteDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value.ToString());
                     }
                     else
                     {
                         InfoSalesDetails.DeliveryNoteDetailsId = 0;
                     }
                     if (cmbSalesMode.Text == "Against Quotation")
                     {
                         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());
                     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());
                     InfoSalesDetails.BatchId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString());
                     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;
                     }
                     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 = 1;
                         InfoSalesDetails.TaxAmount = 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);
                     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;
                     }
                     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 = InfoSalesMaster.VoucherNo; ;
                     infoStockPosting.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
                     infoStockPosting.InvoiceNo = InfoSalesMaster.InvoiceNo;
                     infoStockPosting.AgainstInvoiceNo = "NA";
                     infoStockPosting.AgainstVoucherNo = "NA";
                     infoStockPosting.AgainstVoucherTypeId = 0;
                     infoStockPosting.Extra1 = string.Empty;
                     infoStockPosting.Extra2 = string.Empty;
                     BllStockPosting.StockPostingAdd(infoStockPosting);
                 }
             }
         }
         if (dgvSalesInvoice.Columns["dgvcmbSalesInvoiceTaxName"].Visible)
         {
             int inTaxRowCount = dgvSalesInvoiceTax.RowCount;
             infoSalesBillTax.SalesMasterId = decSalesMasterId;
             infoSalesBillTax.ExtraDate = DateTime.Now;
             infoSalesBillTax.Extra1 = string.Empty;
             infoSalesBillTax.Extra2 = string.Empty;
             for (int inI = 0; inI < inTaxRowCount; inI++)
             {
                 if (dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxId"].Value != null && dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxId"].Value.ToString() != string.Empty)
                 {
                     if (dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxAmount"].Value != null && dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxAmount"].Value.ToString() != string.Empty)
                     {
                         decimal decAmount = Convert.ToDecimal(dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxAmount"].Value);
                         if (decAmount > 0)
                         {
                             infoSalesBillTax.TaxId = Convert.ToInt32(dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxId"].Value.ToString());
                             infoSalesBillTax.TaxAmount = Convert.ToDecimal(dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxAmount"].Value.ToString());
                             BllSalesInvoice.SalesBillTaxAdd(infoSalesBillTax);
                         }
                     }
                 }
             }
         }
         int inAddRowCount = dgvSalesInvoiceLedger.RowCount;
         infoAdditionalCost.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
         infoAdditionalCost.VoucherNo = strVoucherNo;
         infoAdditionalCost.ExtraDate = DateTime.Now;
         infoAdditionalCost.Extra1 = string.Empty;
         infoAdditionalCost.Extra2 = string.Empty;
         for (int inI = 0; inI < inAddRowCount; inI++)
         {
             if (dgvSalesInvoiceLedger.Rows[inI].Cells["dgvCmbAdditionalCostledgerName"].Value != null && dgvSalesInvoiceLedger.Rows[inI].Cells["dgvCmbAdditionalCostledgerName"].Value.ToString() != string.Empty)
             {
                 if (dgvSalesInvoiceLedger.Rows[inI].Cells["dgvtxtAdditionalCoastledgerAmount"].Value != null && dgvSalesInvoiceLedger.Rows[inI].Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString() != string.Empty)
                 {
                     infoAdditionalCost.LedgerId = Convert.ToInt32(dgvSalesInvoiceLedger.Rows[inI].Cells["dgvCmbAdditionalCostledgerName"].Value.ToString());
                     if (!cmbCashOrbank.Visible)
                     {
                         infoAdditionalCost.Debit = 0;
                         infoAdditionalCost.Credit = Convert.ToDecimal(dgvSalesInvoiceLedger.Rows[inI].Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString());
                     }
                     else
                     {
                         infoAdditionalCost.Debit = Convert.ToDecimal(dgvSalesInvoiceLedger.Rows[inI].Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString());
                         infoAdditionalCost.Credit = 0;
                     }
                     bllAditionalCost.AdditionalCostAdd(infoAdditionalCost);
                 }
             }
         }
         if (!cmbCashOrbank.Visible)
         {
             decimal decCAshOrBankId = 0;
             decCAshOrBankId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
             decimal decTotalAddAmount = Convert.ToDecimal(lblLedgerTotalAmount.Text.Trim().ToString());
             if (decTotalAddAmount > 0)
             {
                 infoAdditionalCost.Debit = decTotalAddAmount;
                 infoAdditionalCost.Credit = 0;
                 infoAdditionalCost.LedgerId = decCAshOrBankId;
                 infoAdditionalCost.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
                 infoAdditionalCost.VoucherNo = strVoucherNo;
                 infoAdditionalCost.ExtraDate = DateTime.Now;
                 infoAdditionalCost.Extra1 = string.Empty;
                 infoAdditionalCost.Extra2 = string.Empty;
                 bllAditionalCost.AdditionalCostAdd(infoAdditionalCost);
             }
         }
         else
         {
             if (cmbCashOrbank.Visible)
             {
                 decimal decCAshOrBankId = 0;
                 decCAshOrBankId = Convert.ToDecimal(cmbCashOrbank.SelectedValue.ToString());
                 decimal decTotalAddAmount = Convert.ToDecimal(lblLedgerTotalAmount.Text.Trim().ToString());
                 if (decTotalAddAmount > 0)
                 {
                     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.AdditionalCostAdd(infoAdditionalCost);
                 }
             }
         }
         ledgerPostingAdd();
         if (BllSalesInvoice.SalesInvoiceInvoicePartyCheckEnableBillByBillOrNot(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString())))
         {
             partyBalanceAdd();
         }
         Messages.SavedMessage();
         if (cbxPrintAfterSave.Checked == true)
         {
             SettingsBll BllSettings = new SettingsBll();
             if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
             {
                 PrintForDotMatrix(decSalesMasterId);
             }
             else
             {
                 Print(decSalesMasterId);
             }
         }
         Clear();
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 70" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill the Tax grid
 /// </summary>
 public void taxGridFill()
 {
     try
     {
         TaxBll bllTax = new TaxBll();
         List<DataTable> ListObj = new List<DataTable>();
         SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
         ListObj = bllTax.TaxViewAllByVoucherTypeId(DecPOSVoucherTypeId);
         dgvPOSTax.DataSource = ListObj[0];
         this.dgvPOSTax.Columns["dgvtxtTaxAmt"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;
     }
     catch (Exception ex)
     {
         MessageBox.Show("POS:20" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to use the Combo Selection By using InvoiceNo
 /// </summary>
 public void ComboSelectionByInvoiceNo()
 {
     //DataTable dtblComboSelection = new DataTable();
     List<DataTable> listComboSelection = new List<DataTable>();
     SalesReturnBll bllSalesReturn = new SalesReturnBll();
     try
     {
         if (!isEnterIntoComboSelectn == false)
         {
             if (cmbInvoiceNo.SelectedIndex != -1)
             {
                 if (cmbInvoiceNo.SelectedValue.ToString() != "System.Data.DataRowView" && cmbInvoiceNo.Text != "System.Data.DataRowView")
                 {
                     DGVGodownComboFill();
                     DGVUnitComboFill();
                     decTotalAmounForSaveCheck = 0;
                     //SalesMasterSP spSaleMaster = new SalesMasterSP();
                     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
                     dgvSalesReturn.Rows.Clear();
                     listComboSelection = BllSalesInvoice.SalesMasterViewByInvoiceNoForComboSelection(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()));
                     if (listComboSelection[0] != null)
                     {
                         cmbPricingLevel.SelectedValue = listComboSelection[0].Rows[0]["pricingLevelId"];
                         cmbSalesAccount.SelectedValue = listComboSelection[0].Rows[0]["salesAccount"];
                         cmbSalesAccount.Enabled = true;
                         txtTransportationComp.Text = listComboSelection[0].Rows[0]["transportationCompany"].ToString();
                         txtLRNo.Text = listComboSelection[0].Rows[0]["lrNo"].ToString();
                     }
                     List<DataTable> listSalesReturnGrideFill = BllSalesInvoice.SalesDetailsViewForSalesReturnGrideFill(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()), salesReturnMasterId);
                     dtblSalesInvoice = listSalesReturnGrideFill[0];
                     foreach (DataRow drowDetails in listSalesReturnGrideFill[0].Rows)
                     {
                         decimal decproductId = Convert.ToDecimal(drowDetails["productId"].ToString());
                         TaxGridFill();
                         dgvSalesReturn.Rows.Add();
                         if (drowDetails["S.No"].ToString() != string.Empty)
                         {
                             dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvSNo"].Value = drowDetails["S.No"].ToString();
                         }
                         if (drowDetails["salesDetailsId"].ToString() != string.Empty)
                         {
                             dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["salesDetailsId"].Value = drowDetails["salesDetailsId"].ToString();
                         }
                         else
                         {
                             dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["salesDetailsId"].Value = 0;
                         }
                         if (drowDetails["productId"].ToString() != string.Empty)
                         {
                             dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["productId"].Value = drowDetails["productId"].ToString();
                             List<DataTable> listObj = BllSalesInvoice.SalesDetailsViewForSalesReturnGrideFill1(Convert.ToDecimal(drowDetails["productId"].ToString()));
                             foreach (DataRow drowDetails1 in listObj[0].Rows)
                             {
                                 if (listComboSelection[0].Rows[0]["voucherTypeId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["voucherTypeId"].Value = Convert.ToDecimal(listComboSelection[0].Rows[0]["voucherTypeId"].ToString());
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["voucherTypeId"].Value = 0;
                                 }
                                 if (listComboSelection[0].Rows[0]["voucherNo"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["voucherNo"].Value = listComboSelection[0].Rows[0]["voucherNo"].ToString();
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["voucherNo"].Value = 0;
                                 }
                                 if (listComboSelection[0].Rows[0]["invoiceNo"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["invoiceNo"].Value = listComboSelection[0].Rows[0]["invoiceNo"].ToString();
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["invoiceNo"].Value = 0;
                                 }
                                 if (drowDetails1["barcode"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextBarcode"].Value = drowDetails1["barcode"].ToString();
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextBarcode"].ReadOnly = true;
                                 }
                                 if (drowDetails1["productCode"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductCode"].Value = drowDetails1["productCode"].ToString();
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductCode"].ReadOnly = true;
                                 }
                                 if (drowDetails1["productName"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductName"].Value = drowDetails1["productName"].ToString();
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductName"].ReadOnly = true;
                                 }
                                 if (drowDetails["unitId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString());
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].ReadOnly = true;
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].Value = 1;
                                 }
                                 if (drowDetails["goDownId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value = Convert.ToDecimal(drowDetails["goDownId"].ToString());
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].ReadOnly = false;
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value = 1;
                                 }
                                 RackComboFill(Convert.ToDecimal(dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value), dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].ColumnIndex);
                                 if (drowDetails["rackId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].Value = Convert.ToDecimal(drowDetails["rackId"].ToString());
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].Value = 1;
                                 }
                                 BatchComboFill(Convert.ToDecimal(dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["productId"].Value), dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].ColumnIndex);
                                 if (drowDetails["batchId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString());
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].ReadOnly = true;
                                 }
                                 if (drowDetails["unitConversionId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["unitConversionId"].Value = drowDetails["unitConversionId"].ToString();
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["unitConversionId"].Value = 0;
                                 }
                                 dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["conversionRate"].Value = drowDetails["conversionRate"].ToString();
                                 if (drowDetails["taxId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTaxId"].Value = 0;
                                     if (Convert.ToDecimal(drowDetails["taxId"].ToString()) != 0)
                                     {
                                         dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTaxId"].Value = Convert.ToDecimal(drowDetails["taxId"].ToString());
                                         dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value = Convert.ToDecimal(drowDetails["taxId"].ToString());
                                         strTaxRate = bllSalesReturn.TaxRateFindForTaxAmmountCalByTaxId(Convert.ToDecimal(drowDetails["taxId"].ToString()));
                                     }
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value = 1;
                                 }
                                 if (drowDetails["qty"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextQty"].Value = Math.Round(Convert.ToDecimal(drowDetails["qty"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                     decQty = Math.Round(Convert.ToDecimal(drowDetails["qty"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextQty"].Value = 0;
                                     decQty = 0;
                                 }
                                 if (drowDetails["rate"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextRate"].Value = Convert.ToDecimal(drowDetails["rate"].ToString());
                                     decRate = Convert.ToDecimal(drowDetails["rate"].ToString());
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextRate"].Value = 0.00;
                                     decRate = 0;
                                 }
                                 if (drowDetails["grossAmount"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].Value = Math.Round(Convert.ToDecimal(drowDetails["grossAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = true;
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].Value = 0.00;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = true;
                                 }
                                 if (drowDetails["discount"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountPercentage"].Value = 0.00;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountAmount"].Value = Math.Round(Convert.ToDecimal(drowDetails["discount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountAmount"].Value = 0.00;
                                 }
                                 if (drowDetails["netAmount"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].Value = Math.Round(Convert.ToDecimal(drowDetails["netAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = true;
                                     txtBillDiscount.Text = "0.00";
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].Value = 0.00;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = true;
                                 }
                                 if (drowDetails["taxAmount"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].Value = Math.Round(Convert.ToDecimal(drowDetails["taxAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].Value = 0.00;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = true;
                                 }
                                 if (drowDetails["amount"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].Value = Math.Round(Convert.ToDecimal(drowDetails["amount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].ReadOnly = true;
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].Value = 0.00;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].ReadOnly = true;
                                 }
                                 if (cmbInvoiceNo.Visible == true)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextBarcode"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextProductCode"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextProductName"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextQty"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbUnit"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbGodown"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbRack"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbBatch"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextRate"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextDiscountPercentage"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbTax"].ReadOnly = true;
                                 }
                                 foreach (DataGridViewRow item1 in dgvSalesReturn2.Rows)
                                 {
                                     if (item1.Cells["dgvTextTaxId"].Value != null)
                                     {
                                         if (dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value != null && dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value.ToString() != string.Empty)
                                         {
                                             if (dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value.ToString() == item1.Cells["dgvTextTaxId"].Value.ToString())
                                             {
                                                 item1.Cells["dgvTextAmount"].Value = dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].Value;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         else
                         {
                             dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["productId"].Value = 0;
                         }
                     }
                     txtNarration.Text = listComboSelection[0].Rows[0]["narration"].ToString();
                     GrossValueCalculation(dgvSalesReturn.Rows.Count - 2);
                     DiscountCalculationfordiscountpercentage(dgvSalesReturn.Rows.Count - 2, 12);
                     DiscountCalculation(dgvSalesReturn.Rows.Count - 2, 13);
                     TaxAmountCalculation(dgvSalesReturn.Rows.Count - 2);
                     TotalAmtCalculation();
                     TotalBillTaxCalculation();
                     GrandTotalCalculation();
                     taxamountfill();
                     taxAndGridTotalAmountCalculation(dgvSalesReturn.Rows.Count - 2);
                     CessTaxamountCalculation();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SR46:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Cleare function and Generate the voucher no based on settings
        /// </summary>
        public void Clear()
        {
            try
            {
                TransactionsGeneralFillBll obj = new TransactionsGeneralFillBll();
                //SalesMasterSP spSalesMaster = new SalesMasterSP();
                SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
                if (isAutomatic)
                {
                    if (strVoucherNo == string.Empty)
                    {
                        strVoucherNo = "0";
                    }
                    strVoucherNo = TransactionGeneralFillObj.VoucherNumberAutomaicGeneration(DecSalesInvoiceVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpDate.Value, "SalesMaster");
                    if (Convert.ToDecimal(strVoucherNo) != (BllSalesInvoice.SalesMasterVoucherMax(DecSalesInvoiceVoucherTypeId)))
                    {
                        strVoucherNo = BllSalesInvoice.SalesMasterVoucherMax(DecSalesInvoiceVoucherTypeId).ToString();
                        strVoucherNo = TransactionGeneralFillObj.VoucherNumberAutomaicGeneration(DecSalesInvoiceVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpDate.Value, "SalesMaster");
                        if (BllSalesInvoice.SalesMasterVoucherMax(DecSalesInvoiceVoucherTypeId) == 0)
                        {
                            strVoucherNo = "0";
                            strVoucherNo = TransactionGeneralFillObj.VoucherNumberAutomaicGeneration(DecSalesInvoiceVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpDate.Value, "SalesMaster");
                        }
                    }
                    SuffixPrefixSettingsBll BllSuffixPrefixSettings = new SuffixPrefixSettingsBll();
                   // SuffixPrefixSP spSuffisprefix = new SuffixPrefixSP();
                    SuffixPrefixInfo infoSuffixPrefix = new SuffixPrefixInfo();
                    infoSuffixPrefix = BllSuffixPrefixSettings.GetSuffixPrefixDetails(DecSalesInvoiceVoucherTypeId, dtpDate.Value);
                    strPrefix = infoSuffixPrefix.Prefix;
                    strSuffix = infoSuffixPrefix.Suffix;
                    strInvoiceNo = strPrefix + strVoucherNo + strSuffix;
                    txtInvoiceNo.Text = strInvoiceNo;
                    txtInvoiceNo.ReadOnly = true;
                    decSalseInvoiceSuffixPrefixId = infoSuffixPrefix.SuffixprefixId;
                }
                else
                {
                    txtInvoiceNo.ReadOnly = false;
                    txtInvoiceNo.Text = string.Empty;
                    strVoucherNo = string.Empty;
                    strInvoiceNo = strVoucherNo;
                }
                if (PrintAfetrSave())
                {
                    cbxPrintAfterSave.Checked = true;
                }
                else
                {
                    cbxPrintAfterSave.Checked = false;
                }
                cmbPricingLevel.SelectedIndex = 0;
                cmbSalesAccount.SelectedIndex = 0;
                cmbCashOrParty.SelectedIndex = 0;
                cmbSalesMan.SelectedIndex = 0;
                cmbSalesMode.SelectedIndex = 0;
                cmbDrorCr.SelectedIndex = 0;
                cmbCashOrbank.SelectedIndex = 0;
                cmbCurrency.Enabled = true;
                txtCustomer.Text = cmbCashOrParty.Text;
                txtTransportCompany.Text = string.Empty;
                txtVehicleNo.Text = string.Empty;
                txtNarration.Text = string.Empty;
                txtCreditPeriod.Text = "0";
                txtTotalAmount.Text = "0.00";
                txtBillDiscount.Text = "0";
                txtGrandTotal.Text = "0.00";
                lblTaxTotalAmount.Text = "0.00";
                lblLedgerTotalAmount.Text = "0.00";
                btnSave.Text = "Save";
                btnDelete.Enabled = false;
                dtpDate.MinDate = PublicVariables._dtFromDate;
                dtpDate.MaxDate = PublicVariables._dtToDate;
                dtpDate.Value = PublicVariables._dtCurrentDate;
                txtDate.Text = dtpDate.Value.ToString("dd-MMM-yyyy");
                dgvSalesInvoiceLedger.Rows.Clear();
                isFromEditMode = false;
                if (dgvSalesInvoice.DataSource != null)
                {
                    ((DataTable)dgvSalesInvoice.DataSource).Rows.Clear();
                }
                else
                {
                    dgvSalesInvoice.Rows.Clear();
                }
                gridCombofill();
                if (dgvSalesInvoiceTax.DataSource != null)
                {
                    ((DataTable)dgvSalesInvoiceTax.DataSource).Rows.Clear();
                }
                else
                {
                    dgvSalesInvoiceTax.Rows.Clear();
                }
                taxGridFill();
                if (!txtInvoiceNo.ReadOnly)
                {
                    txtInvoiceNo.Focus();
                }
                else
                {
                    txtDate.Select();
                }

                txtTotalAmount.Text = "0.00";
                txtGrandTotal.Text = "0.00";
                lblTotalQuantitydisplay.Text = "0";
            }
            catch (Exception ex)
            {
                MessageBox.Show("SI : 01" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// On print button click
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnPrint_Click(object sender, EventArgs e)
 {
     DataSet dsfree = new DataSet();
     try
     {
         //SalesMasterSP spSalesMaster = new SalesMasterSP();
         SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
         DateTime fromDate, toDate;
         fromDate = Convert.ToDateTime(txtFromDate.Text);
         toDate = Convert.ToDateTime(txtToDate.Text);
         string voucherNo = txtVoucherNo.Text.ToString();
         decimal voucherTypeId = Convert.ToDecimal(cmbVoucherType.SelectedValue.ToString());
         decimal groupId = Convert.ToDecimal(cmbProductGroup.SelectedValue.ToString());
         decimal companyId = 1;
         decimal ledgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         decimal employeeId = Convert.ToDecimal(cmbSalesMan.SelectedValue.ToString());
         string productCode = cmbProductCode.Text.ToString();
         dsfree = BllSalesInvoice.FreeSaleReportPrint(fromDate, toDate, voucherNo, voucherTypeId, groupId, productCode, ledgerId, employeeId, companyId);
         frmReport frmReport = new frmReport();
         frmReport.MdiParent = formMDI.MDIObj;
         if (dgvFreeSalesReport.Rows.Count > 0)
         {
             frmReport.freeSaleReport(dsfree);
         }
         else
         {
             Messages.InformationMessage("No data found");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("FSR :17" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Grid fill function Againest SalseOrderDetails
 /// </summary>
 public void gridFillAgainestSalseOrderDetails()
 {
     BrandBll BllBrand = new BrandBll();
     //SalesOrderBll bllSalesOrder = new SalesOrderBll();
     SalesOrderBll bllSalesOrder = new SalesOrderBll();
     ProductInfo infoproduct = new ProductInfo();
     //SalesMasterSP spSalesMaster = new SalesMasterSP();
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     BrandInfo InfoBrand = new BrandInfo();
     TaxInfo infoTax = new TaxInfo();
     TaxBll bllTax = new TaxBll();
     try
     {
         if (cmbSalesModeOrderNo.SelectedIndex > 0)
         {
             inMaxCount = 0;
             isValueChange = false;
             for (int i = 0; i < dgvSalesInvoice.RowCount - 1; i++)
             {
                 if (dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value != null && dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value.ToString() != string.Empty)
                 {
                     lstArrOfRemove.Add(dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value.ToString());
                 }
             }
             dgvSalesInvoice.Rows.Clear();
             isValueChange = true;
             List<DataTable> ListObj= bllSalesOrder.SalesInvoiceGridfillAgainestSalesOrder(Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString()));
             cmbPricingLevel.SelectedValue = Convert.ToDecimal(ListObj[0].Rows[0]["pricingLevelId"].ToString());
             cmbCurrency.SelectedValue = Convert.ToDecimal(ListObj[0].Rows[0]["exchangeRateId"].ToString());
             if (ListObj[0].Rows[0]["employeeId"].ToString() != string.Empty)
             {
                 strSalesManId = ListObj[0].Rows[0]["employeeId"].ToString();
                 cmbSalesMan.SelectedValue = strSalesManId;
                 if (cmbSalesMan.SelectedValue == null)
                 {
                     salesManComboFill();
                     cmbSalesMan.SelectedValue = ListObj[0].Rows[0]["employeeId"].ToString();
                 }
             }
             cmbPricingLevel.Enabled = false;
             btnNewPricingLevel.Enabled = false;
             cmbCurrency.Enabled = false;
              ListObj = bllSalesOrder.SalesInvoiceGridfillAgainestSalesOrderUsingSalesDetails(Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString()), Convert.ToDecimal(decSalesInvoiceIdToEdit), DecSalesInvoiceVoucherTypeId);
             int inRowIndex = 0;
             foreach (DataRow drowDetails in ListObj[0].Rows)
             {
                 dgvSalesInvoice.Rows.Add();
                 isValueChange = false;
                 IsSetGridValueChange = false;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSISalesOrderDetailsId"].Value = drowDetails["salesOrderDetailsId"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceProductCode"].Value = drowDetails["productCode"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceBarcode"].Value = drowDetails["barcode"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvcmbSalesInvoiceBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString());
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceVoucherNo"].Value = drowDetails["voucherNo"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceInvoiceNo"].Value = drowDetails["invoiceNo"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceVoucherTypeId"].Value = drowDetails["voucherTypeId"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceDiscountPercentage"].Value = "0";
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceInRowIndex"].Value = drowDetails["salesOrderDetailsId"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceProductId"].Value = drowDetails.ItemArray[2].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceUnitConversionId"].Value = drowDetails["unitConversionId"].ToString();
                 infoproduct = BllSalesInvoice.ProductViewByProductIdforSalesInvoice(Convert.ToDecimal(dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceProductId"].Value).ToString());
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceProductName"].Value = infoproduct.ProductName;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceMrp"].Value = infoproduct.Mrp;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoicePurchaseRate"].Value = infoproduct.PurchaseRate;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceSalesRate"].Value = infoproduct.SalesRate;
                 InfoBrand = BllBrand.BrandView(infoproduct.BrandId);
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceBrand"].Value = InfoBrand.BrandName;
                 infoTax = bllTax.TaxViewByProductId(Convert.ToDecimal(dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceProductId"].Value).ToString());
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvcmbSalesInvoiceTaxName"].Value = infoTax.TaxId;
                 isValueChange = false;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoicembUnitName"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString());
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoicembUnitName"].ReadOnly = true;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceQty"].Value = drowDetails["Qty"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceRate"].Value = drowDetails["rate"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceAmount"].Value = drowDetails["amount"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceConversionRate"].Value = drowDetails["conversionRate"].ToString();
                 isFromAgainest = true;
                 gridColumnMakeEnables();
                 int intIndex = 0;
                 intIndex = Convert.ToInt32(drowDetails["salesOrderDetailsId"].ToString());
                 if (inMaxCount < intIndex)
                     inMaxCount = intIndex;
                 inRowIndex++;
                 isValueChange = true;
                 isFromAgainest = false;
                 GrossValueCalculation(dgvSalesInvoice.Rows.Count - 2);
                 discountCalculation(dgvSalesInvoice.Rows.Count - 2);
                 taxAndGridTotalAmountCalculation(dgvSalesInvoice.Rows.Count - 2);
             }
             IsSetGridValueChange = true;
             for (int i = inRowIndex; i < dgvSalesInvoice.Rows.Count; ++i)
                 dgvSalesInvoice["dgvtxtSalesInvoiceInRowIndex", i].Value = GetNextinRowIndex().ToString();
             SerialNoforSalesInvoice();
             strVoucherNoTostockPost = dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceVoucherNo"].Value.ToString();
             strInvoiceNoTostockPost = dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceInvoiceNo"].Value.ToString();
             decVouchertypeIdTostockPost = Convert.ToDecimal(dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceVoucherTypeId"].Value);
         }
         else
         {
             SiGridTotalAmountCalculation();
             ClearGridAgainest();
         }
         SiGridTotalAmountCalculation();
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 51" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Print function in crystal report
 /// </summary>
 /// <param name="decSalesMasterId"></param>
 public void Print(decimal decSalesMasterId)
 {
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     SalesMasterInfo InfoSalesMaster = new SalesMasterInfo();
     try
     {
         DataSet dsSalesInvoice = BllSalesInvoice.salesInvoicePrintAfterSave(decSalesMasterId, 1, InfoSalesMaster.OrderMasterId, InfoSalesMaster.DeliveryNoteMasterId, InfoSalesMaster.QuotationMasterId);
         frmReport frmReport = new frmReport();
         frmReport.MdiParent = formMDI.MDIObj;
         frmReport.SalesInvoicePrinting(dsSalesInvoice);
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 73" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Edit Function
 /// </summary>
 public void EditFunction()
 {
     try
     {
         removeSalesInvoiceDetails();
         SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
         SalesMasterInfo InfoSalesMaster = new SalesMasterInfo();
         InfoSalesMaster = BllSalesInvoice.SalesMasterView(decSalesInvoiceIdToEdit);
         if (InfoSalesMaster.DeliveryNoteMasterId != 0)
         {
             DeliveryNoteMasterInfo infoDeliveryNote = new DeliveryNoteMasterInfo();
             infoDeliveryNote = new DeliveryNoteBll().DeliveryNoteMasterView(InfoSalesMaster.DeliveryNoteMasterId);
             new StockPostingBll().StockPostingDeleteForSalesInvoiceAgainstDeliveryNote
                 (InfoSalesMaster.VoucherTypeId, InfoSalesMaster.VoucherNo,
                 infoDeliveryNote.VoucherNo, infoDeliveryNote.VoucherTypeId);
         }
         new StockPostingBll().StockPostingDeleteByagainstVoucherTypeIdAndagainstVoucherNoAndVoucherNoAndVoucherType
                 (0, "NA", InfoSalesMaster.VoucherNo, InfoSalesMaster.VoucherTypeId);
         InfoSalesMaster.SalesMasterId = decSalesInvoiceIdToEdit;
         InfoSalesMaster.AdditionalCost = Convert.ToDecimal(lblLedgerTotalAmount.Text);
         InfoSalesMaster.BillDiscount = Convert.ToDecimal(txtBillDiscount.Text.Trim());
         InfoSalesMaster.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text.Trim().ToString());
         InfoSalesMaster.CustomerName = txtCustomer.Text.Trim();
         InfoSalesMaster.Date = Convert.ToDateTime(txtDate.Text.ToString());
         InfoSalesMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
         InfoSalesMaster.EmployeeId = Convert.ToDecimal(cmbSalesMan.SelectedValue.ToString());
         InfoSalesMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         InfoSalesMaster.GrandTotal = Convert.ToDecimal(txtGrandTotal.Text.Trim());
         InfoSalesMaster.InvoiceNo = txtInvoiceNo.Text.Trim();
         InfoSalesMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         InfoSalesMaster.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
         InfoSalesMaster.VoucherNo = strVoucherNo;
         if (isAutomatic)
         {
             InfoSalesMaster.SuffixPrefixId = decSalseInvoiceSuffixPrefixId;
         }
         else
         {
             InfoSalesMaster.SuffixPrefixId = 0;
         }
         if (cmbSalesMode.Text == "Against SalesOrder")
         {
             InfoSalesMaster.OrderMasterId = Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString());
         }
         else
         {
             InfoSalesMaster.OrderMasterId = 0;
         }
         if (cmbSalesMode.Text == "Against Delivery Note")
         {
             InfoSalesMaster.DeliveryNoteMasterId = Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString());
         }
         else
         {
             InfoSalesMaster.DeliveryNoteMasterId = 0;
         }
         if (cmbSalesMode.Text == "Against Quotation")
         {
             InfoSalesMaster.QuotationMasterId = Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString());
         }
         else
         {
             InfoSalesMaster.QuotationMasterId = 0;
         }
         InfoSalesMaster.Narration = txtNarration.Text.Trim();
         InfoSalesMaster.PricinglevelId = Convert.ToDecimal(cmbPricingLevel.SelectedValue.ToString());
         InfoSalesMaster.SalesAccount = Convert.ToDecimal(cmbSalesAccount.SelectedValue.ToString());
         InfoSalesMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text.Trim());
         if (dgvSalesInvoice.Columns["dgvcmbSalesInvoiceTaxName"].Visible)
         {
             InfoSalesMaster.TaxAmount = Convert.ToDecimal(lblTaxTotalAmount.Text.Trim());
         }
         else
         {
             InfoSalesMaster.TaxAmount = 0;
         }
         InfoSalesMaster.UserId = PublicVariables._decCurrentUserId;
         InfoSalesMaster.LrNo = txtVehicleNo.Text;
         InfoSalesMaster.TransportationCompany = txtTransportCompany.Text.Trim();
         InfoSalesMaster.POS = false;
         InfoSalesMaster.CounterId = 0;
         InfoSalesMaster.ExtraDate = DateTime.Now;
         InfoSalesMaster.Extra1 = string.Empty;
         InfoSalesMaster.Extra2 = string.Empty;
         BllSalesInvoice.SalesMasterEdit(InfoSalesMaster);
         removeSalesInvoiceDetails();
         SalesInvoiceDetailsEditFill();
         if (cmbCashOrParty.Enabled)
         {
             LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
             BllLedgerPosting.LedgerPostDelete(strVoucherNo, DecSalesInvoiceVoucherTypeId);
             ledgerPostingAdd();
         }
         else
         {
             ledgerPostingEdit();
         }
         Messages.UpdatedMessage();
         if (cbxPrintAfterSave.Checked)
         {
             SettingsBll BllSettings = new SettingsBll();
             if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
             {
                 PrintForDotMatrix(decSalesInvoiceIdToEdit);
             }
             else
             {
                 Print(decSalesInvoiceIdToEdit);
             }
         }
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 78" + 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>
        /// Call Corresponding Voucher to View details for updation in edit mode
        /// </summary>
        public void GotoSalesInvoice()
        {
            try
            {
                //SalesMasterSP SpMaster = new SalesMasterSP();
                SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
                SalesMasterInfo InfoMaster = new SalesMasterInfo();
                InfoMaster = BllSalesInvoice.SalesMasterView(Convert.ToDecimal(dgvVoucherSearch.CurrentRow.Cells["Id"].Value.ToString()));
                if (InfoMaster.POS == true)
                {
                    frmPOS objfrm = new frmPOS();

                    objfrm.WindowState = FormWindowState.Normal;
                    objfrm.MdiParent = formMDI.MDIObj;
                    objfrm.Show();
                    objfrm.CallFromVoucherSearch(this, Convert.ToDecimal(dgvVoucherSearch.CurrentRow.Cells["Id"].Value.ToString()));
                }
                else
                {
                    frmSalesInvoice objfrmSalesInvoice = new frmSalesInvoice();
                    frmSalesInvoice open = Application.OpenForms["frmSalesInvoice"] as frmSalesInvoice;
                    if (open == null)
                    {
                        objfrmSalesInvoice.WindowState = FormWindowState.Normal;
                        objfrmSalesInvoice.MdiParent = formMDI.MDIObj;
                        objfrmSalesInvoice.Show();
                        objfrmSalesInvoice.CallFromVoucherSearch(this, Convert.ToDecimal(dgvVoucherSearch.CurrentRow.Cells["Id"].Value.ToString()));
                    }
                    else
                    {
                        open.MdiParent = formMDI.MDIObj;
                        if (open.WindowState == FormWindowState.Minimized)
                        {
                            open.WindowState = FormWindowState.Normal;
                        }
                        else
                        {
                            open.Activate();
                        }
                        open.CallFromVoucherSearch(this, Convert.ToDecimal(dgvVoucherSearch.CurrentRow.Cells["Id"].Value.ToString()));
                        open.BringToFront();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("VS24:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Cell double click in grid to view the curresponding item in that form and open the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvVoucherwiseProductSearch_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex!=-1)
                {
                    int inI = dgvVoucherwiseProductSearch.CurrentCell.RowIndex;
                    foreach (DataGridViewRow dgv in dgvVoucherwiseProductSearch.Rows)
                    {
                        decMasterId = decimal.Parse(dgv.Cells["dgvtxtmasterId"].Value.ToString());
                        strVoucherType = dgv.Cells["dgvtxtTypeOfVoucher"].Value.ToString();
                        decVoucherTypeId = Convert.ToDecimal(dgv.Cells["dgvtxtvoucherTypeId"].Value.ToString());
                        if (dgv.Index == inI)
                        {
                            break;
                        }

                    }

                    if (decMasterId != 0 && strVoucherType == "Material Receipt")
                    {
                        frmMaterialReceipt objReceipt = new frmMaterialReceipt();
                        objReceipt.WindowState = FormWindowState.Normal;
                        objReceipt.MdiParent = formMDI.MDIObj;
                        objReceipt.CallFromVoucherWiseProductSearch(this, decMasterId);
                        this.Enabled = false;

                    }

                    else if (decMasterId != 0 && strVoucherType == "Physical Stock")
                    {
                        frmPhysicalStock objPhysical = new frmPhysicalStock();
                        objPhysical.WindowState = FormWindowState.Normal;
                        objPhysical.MdiParent = formMDI.MDIObj;
                        objPhysical.CallFromVoucherWiseProductSearch(this, decMasterId);
                        this.Enabled = false;
                    }

                    else if (decMasterId != 0 && strVoucherType == "Purchase Invoice")
                    {
                        frmPurchaseInvoice objpurchase = new frmPurchaseInvoice();
                        objpurchase.WindowState = FormWindowState.Normal;
                        objpurchase.MdiParent = formMDI.MDIObj;
                        objpurchase.CallFromVoucherWiseProductSearch(this, decMasterId);
                        this.Enabled = false;
                    }

                    else if (decMasterId != 0 && strVoucherType == "Rejection Out")
                    {
                        frmRejectionOut objRejection = new frmRejectionOut();
                        objRejection.WindowState = FormWindowState.Normal;
                        objRejection.MdiParent = formMDI.MDIObj;
                        objRejection.CallFromVoucherWiseProductSearch(this, decMasterId);
                        this.Enabled = false;
                    }

                    else if (decMasterId != 0 && strVoucherType == "Rejection In")
                    {
                        frmRejectionIn objRejection = new frmRejectionIn();
                        objRejection.WindowState = FormWindowState.Normal;
                        objRejection.MdiParent = formMDI.MDIObj;
                        objRejection.CallFromVoucherWiseProductSearch(this, decMasterId);
                        this.Enabled = false;
                    }
                    else if (decMasterId != 0 && strVoucherType == "Purchase Return")
                    {
                        frmPurchaseReturn objPurchase = new frmPurchaseReturn();
                        objPurchase.WindowState = FormWindowState.Normal;
                        objPurchase.MdiParent = formMDI.MDIObj;
                        objPurchase.CallFromVoucherWiseProductSearch(this, decMasterId);
                        this.Enabled = false;
                    }
                    else if (decMasterId != 0 && strVoucherType == "Sales Return")
                    {
                        frmSalesReturn frmObj = new frmSalesReturn();
                        frmObj.WindowState = FormWindowState.Normal;
                        frmObj.MdiParent = formMDI.MDIObj;
                        frmObj.CallFromVoucherWiseProductSearch(this, decMasterId, true);
                        this.Enabled = false;
                    }

                    else if (decMasterId != 0 && strVoucherType == "Delivery Note")
                    {
                        frmDeliveryNote objDeliveryReport = new frmDeliveryNote();
                        objDeliveryReport.WindowState = FormWindowState.Normal;
                        objDeliveryReport.MdiParent = formMDI.MDIObj;
                        objDeliveryReport.CallFromVoucherWiseProductSearch(this, decMasterId);
                        this.Enabled = false;
                    }

                    else if (decMasterId != 0 && strVoucherType == "Sales Order")
                    {
                        frmSalesOrder dbjfrmSalesorder = new frmSalesOrder();
                        dbjfrmSalesorder.WindowState = FormWindowState.Normal;
                        dbjfrmSalesorder.MdiParent = formMDI.MDIObj;
                        dbjfrmSalesorder.CallFromVoucherWiseProductSearch(this, decMasterId);
                        this.Enabled = false;

                    }

                    else if (decMasterId != 0 && strVoucherType == "Purchase Order")
                    {

                        frmPurchaseOrder objfrmPurchaseorder = new frmPurchaseOrder();

                        objfrmPurchaseorder.WindowState = FormWindowState.Normal;
                        objfrmPurchaseorder.MdiParent = formMDI.MDIObj;
                        objfrmPurchaseorder.CallFromVoucherWiseProductSearch(this, decMasterId);
                        this.Enabled = false;

                    }

                    else if (decMasterId != 0 && strVoucherType == "Sales Quotation")
                    {
                        frmSalesQuotation objfrmSalesquotation = new frmSalesQuotation();

                        objfrmSalesquotation.WindowState = FormWindowState.Normal;
                        objfrmSalesquotation.MdiParent = formMDI.MDIObj;
                        objfrmSalesquotation.CallFromVoucherWiseProductSearch(this, decMasterId);
                        this.Enabled = false;

                    }

                    else if (decMasterId != 0 && strVoucherType == "Sales Invoice")
                    {
                        frmSalesInvoice objSalesReport = new frmSalesInvoice();
                        //SalesMasterSP spSalesMaster = new SalesMasterSP();
                        SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
                        objSalesReport.WindowState = FormWindowState.Normal;
                        objSalesReport.MdiParent = formMDI.MDIObj;
                        bool blPOS = BllSalesInvoice.DayBookSalesInvoiceOrPOS(decMasterId, decVoucherTypeId);
                        frmSalesInvoice frmSalesInvoice = new frmSalesInvoice();
                        frmPOS frmPOS = new frmPOS();
                        if (blPOS == true)
                        {
                            frmPOS = Application.OpenForms["frmPOS"] as frmPOS;
                            if (frmPOS == null)
                            {
                                frmPOS = new frmPOS();
                                frmPOS.MdiParent = formMDI.MDIObj;

                                frmPOS.callFromVoucherWiseProductSearch(this, decMasterId);

                            }
                        }
                        else
                        {
                            frmSalesInvoice = Application.OpenForms["frmSalesInvoice"] as frmSalesInvoice;
                            if (frmSalesInvoice == null)
                            {
                                frmSalesInvoice = new frmSalesInvoice();
                                frmSalesInvoice.MdiParent = formMDI.MDIObj;
                                objSalesReport.CallFromVoucherWiseProductSearch(this, decMasterId);
                            }
                        }

                        this.Enabled = false;
                    }
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show("VPS :11" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// When doubleclicking on the grid
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvDayBook_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         string strVoucherType = string.Empty;
         decimal decMasterId = 0;
         //SalesMasterSP spSalesMaster = new SalesMasterSP();
         SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
         if (dgvDayBook.CurrentRow.Index == e.RowIndex)
         {
             int inI = dgvDayBook.CurrentCell.RowIndex;
             int inCount = dgvDayBook.Rows.Count;
             if (dgvDayBook.CurrentCell.RowIndex < dgvDayBook.Rows[inCount - 3].Cells["Date"].RowIndex)
             {
                 foreach (DataGridViewRow dgv in dgvDayBook.Rows)
                 {
                     if (dgv.Cells["Date"].Value.ToString() != string.Empty)
                     {
                         strVoucherType = dgv.Cells["typeOfVoucher"].Value.ToString();
                         decMasterId = Convert.ToDecimal(dgv.Cells["MasterId"].Value.ToString());
                     }
                     if (dgv.Index == inI)
                     {
                         break;
                     }
                 }
                 if (strVoucherType == "Contra Voucher")
                 {
                     frmContraVoucher frmContraVoucher = new frmContraVoucher();
                     frmContraVoucher open = Application.OpenForms["frmContraVoucher"] as frmContraVoucher;
                     if (open == null)
                     {
                         frmContraVoucher.WindowState = FormWindowState.Normal;
                         frmContraVoucher.MdiParent = formMDI.MDIObj;
                         frmContraVoucher.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         open.callFromDayBook(this, decMasterId);
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                     }
                 }
                 else if (strVoucherType == "Payment Voucher")
                 {
                     frmPaymentVoucher frmPaymentVoucher = new frmPaymentVoucher();
                     frmPaymentVoucher open = Application.OpenForms["frmPaymentVoucher"] as frmPaymentVoucher;
                     if (open == null)
                     {
                         frmPaymentVoucher.WindowState = FormWindowState.Normal;
                         frmPaymentVoucher.MdiParent = formMDI.MDIObj;
                         frmPaymentVoucher.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         open.callFromDayBook(this, decMasterId);
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                     }
                 }
                 else if (strVoucherType == "Receipt Voucher")
                 {
                     frmReceiptVoucher frmReceiptVoucher = new frmReceiptVoucher();
                     frmReceiptVoucher open = Application.OpenForms["frmReceiptVoucher"] as frmReceiptVoucher;
                     if (open == null)
                     {
                         frmReceiptVoucher.WindowState = FormWindowState.Normal;
                         frmReceiptVoucher.MdiParent = formMDI.MDIObj;
                         frmReceiptVoucher.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Journal Voucher")
                 {
                     frmJournalVoucher frmJournalVoucher = new frmJournalVoucher();
                     frmJournalVoucher open = Application.OpenForms["frmJournalVoucher"] as frmJournalVoucher;
                     if (open == null)
                     {
                         frmJournalVoucher.WindowState = FormWindowState.Normal;
                         frmJournalVoucher.MdiParent = formMDI.MDIObj;
                         frmJournalVoucher.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         open.callFromDayBook(this, decMasterId);
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                     }
                 }
                 else if (strVoucherType == "PDC Payable")
                 {
                     frmPdcPayable frmPdcPayable = new frmPdcPayable();
                     frmPdcPayable open = Application.OpenForms["frmPdcPayable"] as frmPdcPayable;
                     if (open == null)
                     {
                         frmPdcPayable.WindowState = FormWindowState.Normal;
                         frmPdcPayable.MdiParent = formMDI.MDIObj;
                         frmPdcPayable.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "PDC Receivable")
                 {
                     frmPdcReceivable frmPdcReceivable = new frmPdcReceivable();
                     frmPdcReceivable open = Application.OpenForms["frmPdcReceivable"] as frmPdcReceivable;
                     if (open == null)
                     {
                         frmPdcReceivable.WindowState = FormWindowState.Normal;
                         frmPdcReceivable.MdiParent = formMDI.MDIObj;
                         frmPdcReceivable.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Purchase Invoice")
                 {
                     frmPurchaseInvoice frmPurchaseInvoice = new frmPurchaseInvoice();
                     frmPurchaseInvoice open = Application.OpenForms["frmPurchaseInvoice"] as frmPurchaseInvoice;
                     if (open == null)
                     {
                         frmPurchaseInvoice.WindowState = FormWindowState.Normal;
                         frmPurchaseInvoice.MdiParent = formMDI.MDIObj;
                         frmPurchaseInvoice.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Purchase Return")
                 {
                     frmPurchaseReturn frmPurchaseReturn = new frmPurchaseReturn();
                     frmPurchaseReturn open = Application.OpenForms["frmPurchaseReturn"] as frmPurchaseReturn;
                     if (open == null)
                     {
                         frmPurchaseReturn.WindowState = FormWindowState.Normal;
                         frmPurchaseReturn.MdiParent = formMDI.MDIObj;
                         frmPurchaseReturn.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Sales Invoice")
                 {
                     decimal decSalesId = Convert.ToDecimal(dgvDayBook.CurrentRow.Cells["MasterId"].Value.ToString());
                     decimal decVoucherId = Convert.ToDecimal(dgvDayBook.CurrentRow.Cells["voucherTypeId"].Value.ToString());
                     bool isPOS = BllSalesInvoice.DayBookSalesInvoiceOrPOS(decSalesId, decVoucherId);
                     if (isPOS == true)
                     {
                         frmPOS frmPOSObj = new frmPOS();
                         frmPOS open = Application.OpenForms["frmPOS"] as frmPOS;
                         if (open == null)
                         {
                             frmPOSObj.WindowState = FormWindowState.Normal;
                             frmPOSObj.MdiParent = formMDI.MDIObj;
                             frmPOSObj.callFromDayBook(this, decMasterId);
                         }
                         else
                         {
                             if (open.WindowState == FormWindowState.Minimized)
                             {
                                 open.WindowState = FormWindowState.Normal;
                             }
                             open.callFromDayBook(this, decMasterId);
                         }
                     }
                     else
                     {
                         frmSalesInvoice frmSalesInvoiceObj = new frmSalesInvoice();
                         frmSalesInvoice open = Application.OpenForms["frmSalesInvoice"] as frmSalesInvoice;
                         if (open == null)
                         {
                             frmSalesInvoiceObj.WindowState = FormWindowState.Normal;
                             frmSalesInvoiceObj.MdiParent = formMDI.MDIObj;
                             frmSalesInvoiceObj.callFromDayBook(this, decMasterId);
                         }
                         else
                         {
                             if (open.WindowState == FormWindowState.Minimized)
                             {
                                 open.WindowState = FormWindowState.Normal;
                             }
                             open.callFromDayBook(this, decMasterId);
                         }
                     }
                 }
                 else if (strVoucherType == "Sales Return")
                 {
                     frmSalesReturn frmSalesReturn = new frmSalesReturn();
                     frmSalesReturn open = Application.OpenForms["frmSalesReturn"] as frmSalesReturn;
                     if (open == null)
                     {
                         frmSalesReturn.WindowState = FormWindowState.Normal;
                         frmSalesReturn.MdiParent = formMDI.MDIObj;
                         frmSalesReturn.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Service Voucher")
                 {
                     frmServiceVoucher frmServiceVoucher = new frmServiceVoucher();
                     frmServiceVoucher open = Application.OpenForms["frmServiceVoucher"] as frmServiceVoucher;
                     if (open == null)
                     {
                         frmServiceVoucher.WindowState = FormWindowState.Normal;
                         frmServiceVoucher.MdiParent = formMDI.MDIObj;
                         frmServiceVoucher.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Credit Note")
                 {
                     frmCreditNote frmCreditNote = new frmCreditNote();
                     frmCreditNote open = Application.OpenForms["frmCreditNote"] as frmCreditNote;
                     if (open == null)
                     {
                         frmCreditNote.WindowState = FormWindowState.Normal;
                         frmCreditNote.MdiParent = formMDI.MDIObj;
                         frmCreditNote.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Debit Note")
                 {
                     frmDebitNote frmDebitNote = new frmDebitNote();
                     frmDebitNote open = Application.OpenForms["frmDebitNote"] as frmDebitNote;
                     if (open == null)
                     {
                         frmDebitNote.WindowState = FormWindowState.Normal;
                         frmDebitNote.MdiParent = formMDI.MDIObj;
                         frmDebitNote.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Rejection In")
                 {
                     frmRejectionIn frmRejectionIn = new frmRejectionIn();
                     frmRejectionIn open = Application.OpenForms["frmRejectionIn"] as frmRejectionIn;
                     if (open == null)
                     {
                         frmRejectionIn.WindowState = FormWindowState.Normal;
                         frmRejectionIn.MdiParent = formMDI.MDIObj;
                         frmRejectionIn.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Rejection Out")
                 {
                     frmRejectionOut frmRejectionOut = new frmRejectionOut();
                     frmRejectionOut open = Application.OpenForms["frmRejectionOut"] as frmRejectionOut;
                     if (open == null)
                     {
                         frmRejectionOut.WindowState = FormWindowState.Normal;
                         frmRejectionOut.MdiParent = formMDI.MDIObj;
                         frmRejectionOut.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Delivery Note")
                 {
                     frmDeliveryNote frmDeliveryNote = new frmDeliveryNote();
                     frmDeliveryNote open = Application.OpenForms["frmDeliveryNote"] as frmDeliveryNote;
                     if (open == null)
                     {
                         frmDeliveryNote.WindowState = FormWindowState.Normal;
                         frmDeliveryNote.MdiParent = formMDI.MDIObj;
                         frmDeliveryNote.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Material Receipt")
                 {
                     frmMaterialReceipt frmMaterialReceipt = new frmMaterialReceipt();
                     frmMaterialReceipt open = Application.OpenForms["frmMaterialReceipt"] as frmMaterialReceipt;
                     if (open == null)
                     {
                         frmMaterialReceipt.WindowState = FormWindowState.Normal;
                         frmMaterialReceipt.MdiParent = formMDI.MDIObj;
                         frmMaterialReceipt.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "PDC Clearance")
                 {
                     frmPdcClearance frmPdcClearance = new frmPdcClearance();
                     frmPdcClearance open = Application.OpenForms["frmPdcClearance"] as frmPdcClearance;
                     if (open == null)
                     {
                         frmPdcClearance.WindowState = FormWindowState.Normal;
                         frmPdcClearance.MdiParent = formMDI.MDIObj;
                         frmPdcClearance.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Purchase Order")
                 {
                     frmPurchaseOrder frmPurchaseOrder = new frmPurchaseOrder();
                     frmPurchaseOrder open = Application.OpenForms["frmPurchaseOrder"] as frmPurchaseOrder;
                     if (open == null)
                     {
                         frmPurchaseOrder.WindowState = FormWindowState.Normal;
                         frmPurchaseOrder.MdiParent = formMDI.MDIObj;
                         frmPurchaseOrder.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Sales Order")
                 {
                     frmSalesOrder frmSalesOrder = new frmSalesOrder();
                     frmSalesOrder open = Application.OpenForms["frmSalesOrder"] as frmSalesOrder;
                     if (open == null)
                     {
                         frmSalesOrder.WindowState = FormWindowState.Normal;
                         frmSalesOrder.MdiParent = formMDI.MDIObj;
                         frmSalesOrder.callfromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callfromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Sales Quotation")
                 {
                     frmSalesQuotation frmSalesQuotation = new frmSalesQuotation();
                     frmSalesQuotation open = Application.OpenForms["frmSalesQuotation"] as frmSalesQuotation;
                     if (open == null)
                     {
                         frmSalesQuotation.WindowState = FormWindowState.Normal;
                         frmSalesQuotation.MdiParent = formMDI.MDIObj;
                         frmSalesQuotation.callfromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callfromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Physical Stock")
                 {
                     frmPhysicalStock frmPhysicalStock = new frmPhysicalStock();
                     frmPhysicalStock open = Application.OpenForms["frmPhysicalStock"] as frmPhysicalStock;
                     if (open == null)
                     {
                         frmPhysicalStock.WindowState = FormWindowState.Normal;
                         frmPhysicalStock.MdiParent = formMDI.MDIObj;
                         frmPhysicalStock.callFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.callFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Stock Journal")
                 {
                     frmStockJournal frmStockJournal = new frmStockJournal();
                     frmStockJournal open = Application.OpenForms["frmStockJournal"] as frmStockJournal;
                     if (open == null)
                     {
                         frmStockJournal.WindowState = FormWindowState.Normal;
                         frmStockJournal.MdiParent = formMDI.MDIObj;
                         frmStockJournal.CallFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.CallFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Daily Salary Voucher")
                 {
                     frmDailySalaryVoucher frmDailySalaryVoucher = new frmDailySalaryVoucher();
                     frmDailySalaryVoucher open = Application.OpenForms["frmDailySalaryVoucher"] as frmDailySalaryVoucher;
                     if (open == null)
                     {
                         frmDailySalaryVoucher.WindowState = FormWindowState.Normal;
                         frmDailySalaryVoucher.MdiParent = formMDI.MDIObj;
                         frmDailySalaryVoucher.CallFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.CallFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Monthly Salary Voucher")
                 {
                     frmMonthlySalaryVoucher frmMonthlySalaryVoucher = new frmMonthlySalaryVoucher();
                     frmMonthlySalaryVoucher open = Application.OpenForms["frmMonthlySalaryVoucher"] as frmMonthlySalaryVoucher;
                     if (open == null)
                     {
                         frmMonthlySalaryVoucher.WindowState = FormWindowState.Normal;
                         frmMonthlySalaryVoucher.MdiParent = formMDI.MDIObj;
                         frmMonthlySalaryVoucher.CallFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.CallFromDayBook(this, decMasterId);
                     }
                 }
                 else if (strVoucherType == "Advance Payment")
                 {
                     frmAdvancePayment frmAdvancePayment = new frmAdvancePayment();
                     frmAdvancePayment open = Application.OpenForms["frmAdvancePayment"] as frmAdvancePayment;
                     if (open == null)
                     {
                         frmAdvancePayment.WindowState = FormWindowState.Normal;
                         frmAdvancePayment.MdiParent = formMDI.MDIObj;
                         frmAdvancePayment.CallFromDayBook(this, decMasterId);
                     }
                     else
                     {
                         if (open.WindowState == FormWindowState.Minimized)
                         {
                             open.WindowState = FormWindowState.Normal;
                         }
                         open.CallFromDayBook(this, decMasterId);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("DB18:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Vouchertype combofill function
 /// </summary>
 public void VoucherTypeComboFill()
 {
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     try
     {
         string typeOfVoucher = string.Empty;
         if (cmbSalesMode.Text == "Against SalesOrder")
         {
             typeOfVoucher = "Sales Order";
         }
         else if (cmbSalesMode.Text == "Against Delivery Note")
         {
             typeOfVoucher = "Delivery Note";
         }
         else if (cmbSalesMode.Text == "Against Quotation")
         {
             typeOfVoucher = "Sales Quotation";
         }
         List<DataTable> listObj = new List<DataTable>();
         listObj = BllSalesInvoice.VoucherTypesBasedOnTypeOfVouchers(typeOfVoucher);
         cmbVoucherType.DataSource = listObj[0];
         cmbVoucherType.ValueMember = "voucherTypeId";
         cmbVoucherType.DisplayMember = "voucherTypeName";
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 09" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Product Details fill in the grid here
 /// </summary>
 /// <param name="strProduct"></param>
 /// <param name="inRowIndex"></param>
 /// <param name="strFillMode"></param>
 public void ProductDetailsFill(string strProduct, int inRowIndex, string strFillMode)
 {
     PurchaseInvoiceBll BllPurchaseInvoice = new PurchaseInvoiceBll();
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     List<DataTable> listObj = new List<DataTable>();
     try
     {
         gridCombofill();
         if (strFillMode == "ProductCode")
         {
             listObj = BllSalesInvoice.SalesInvoiceDetailsViewByProductCodeForSI(DecSalesInvoiceVoucherTypeId, strProduct);
         }
         else if (strFillMode == "ProductName")
         {
             listObj = BllSalesInvoice.SalesInvoiceDetailsViewByProductNameForSI(DecSalesInvoiceVoucherTypeId, strProduct);
         }
         else if (strFillMode == "Barcode")
         {
             listObj = BllSalesInvoice.SalesInvoiceDetailsViewByBarcodeForSI(DecSalesInvoiceVoucherTypeId, strProduct);
         }
         if (listObj[0].Rows.Count != 0)
         {
             IsSetGridValueChange = false;
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value = listObj[0].Rows[0]["salseDetailsId"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSISalesOrderDetailsId"].Value = listObj[0].Rows[0]["salesOrderDetailsId"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value = listObj[0].Rows[0]["deliveryNoteDetailsId"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceQuotationDetailsId"].Value = listObj[0].Rows[0]["salesQuotationDetailsId"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceProductId"].Value = listObj[0].Rows[0]["productId"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceBrand"].Value = listObj[0].Rows[0]["brandName"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoicePurchaseRate"].Value = listObj[0].Rows[0]["purchaseRate"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceSalesRate"].Value = listObj[0].Rows[0]["salesRate"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceMrp"].Value = listObj[0].Rows[0]["Mrp"];
             decimal decProductId = Convert.ToDecimal(dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceProductId"].Value.ToString());
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceBarcode"].Value = listObj[0].Rows[0]["barcode"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceProductCode"].Value = listObj[0].Rows[0]["productCode"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceProductName"].Value = listObj[0].Rows[0]["productName"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoicembUnitName"].Value = Convert.ToDecimal(listObj[0].Rows[0]["unitId"].ToString());
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceUnitConversionId"].Value = listObj[0].Rows[0]["unitConversionId"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvcmbSalesInvoiceBatch"].Value = Convert.ToDecimal(listObj[0].Rows[0]["batchId"].ToString());
             decimal decBatchId = Convert.ToDecimal(dgvSalesInvoice.Rows[inRowIndex].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString());
             getProductRate(inRowIndex, decProductId, decBatchId);
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvcmbSalesInvoiceGodown"].Value = Convert.ToDecimal(listObj[0].Rows[0]["godownId"].ToString());
             RackComboFill(Convert.ToDecimal(dgvSalesInvoice.Rows[inRowIndex].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString()), inRowIndex, dgvSalesInvoice.Rows[inRowIndex].Cells["dgvcmbSalesInvoiceRack"].ColumnIndex);
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvcmbSalesInvoiceRack"].Value = Convert.ToDecimal(listObj[0].Rows[0]["rackId"].ToString());
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceDiscountPercentage"].Value = listObj[0].Rows[0]["discountPercent"].ToString();
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceDiscountAmount"].Value = listObj[0].Rows[0]["discount"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceNetAmount"].Value = listObj[0].Rows[0]["netvalue"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvcmbSalesInvoiceTaxName"].Value = listObj[0].Rows[0]["taxId"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceTaxAmount"].Value = listObj[0].Rows[0]["taxAmount"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceAmount"].Value = listObj[0].Rows[0]["amount"];
             dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceConversionRate"].Value = listObj[0].Rows[0]["conversionRate"];
             GrossValueCalculation(inRowIndex);
             DiscountCalculation(inRowIndex, 22);
             DiscountCalculation(inRowIndex, 23);
             taxAndGridTotalAmountCalculation(inRowIndex);
             decCurrentRate = Convert.ToDecimal(dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceRate"].Value.ToString());
             decCurrentConversionRate = Convert.ToDecimal(listObj[0].Rows[0]["conversionRate"].ToString());
             UnitConversionCalc(inRowIndex);
             SiGridTotalAmountCalculation();
             IsSetGridValueChange = true;
         }
         //else
         //{
             //if (strProductCode != string.Empty)
             //{
             //    ProductDetailsFill(strProduct, inRowIndex, "ProductCode");
             //}
             else
             {
                 if (dgvSalesInvoice.CurrentRow.Index < dgvSalesInvoice.RowCount - 1)
                 {
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSISalesOrderDetailsId"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceQuotationDetailsId"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceProductId"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceBarcode"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceProductCode"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceProductName"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceBrand"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceQty"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceUnitConversionId"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoicePurchaseRate"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceSalesRate"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceMrp"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceDiscountAmount"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceNetAmount"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceBrand"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceTaxAmount"].Value = string.Empty;
                     dgvSalesInvoice.Rows[inRowIndex].Cells["dgvtxtSalesInvoiceAmount"].Value = string.Empty;
                     SerialNoforSalesInvoice();
                 }
             }
         //}
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 60" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Cash and bank combofill function
 /// </summary>
 public void cashAndBAnkCombofill()
 {
     List<DataTable> listObj = new List<DataTable>();
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     try
     {
         listObj = BllSalesInvoice.BankOrCashComboFill();
         cmbCashOrbank.DataSource = listObj[0];
         cmbCashOrbank.ValueMember = "ledgerId";
         cmbCashOrbank.DisplayMember = "ledgerName";
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 08" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 /// <summary>
 /// Function to check quantity with reference
 /// </summary>
 /// <returns></returns>
 public int QuantityCheckWithReference()
 {
     decimal decQtySalesInvoice = 0;
     decimal decQtySalesReturn = 0;
     int inRef = 0;
     int inF1 = 1;
     decimal decSalesDetailsId = 0;
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     try
     {
         foreach (DataGridViewRow dgvrow in dgvSalesInvoice.Rows)
         {
             if (dgvrow.Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value != null)
             {
                 if (dgvrow.Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value.ToString() != "0" || dgvrow.Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value.ToString() != string.Empty)
                 {
                     decSalesDetailsId = Convert.ToDecimal(dgvrow.Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value.ToString());
                     inRef = BllSalesInvoice.SalseMasterReferenceCheck(decSalesInvoiceIdToEdit, decSalesDetailsId);
                     if (inRef == 1)
                     {
                         if (inF1 == 1)
                         {
                             if (dgvrow.Cells["dgvtxtSalesInvoiceQty"].Value != null)
                             {
                                 if (dgvrow.Cells["dgvtxtSalesInvoiceQty"].Value.ToString() != "0" && dgvrow.Cells["dgvtxtSalesInvoiceQty"].Value.ToString() != string.Empty)
                                 {
                                     decQtySalesInvoice = Convert.ToDecimal(dgvrow.Cells["dgvtxtSalesInvoiceQty"].Value.ToString());
                                     decQtySalesReturn = Math.Round(BllSalesInvoice.SalesReturnDetailsQtyViewBySalesDetailsId(decSalesDetailsId), PublicVariables._inNoOfDecimalPlaces);
                                     if (decQtySalesInvoice >= decQtySalesReturn)
                                     {
                                         inF1 = 1;
                                     }
                                     else
                                     {
                                         inF1 = 0;
                                         Messages.InformationMessage("Quantity in row " + (dgvrow.Index + 1) + " should be greater than " + decQtySalesReturn);
                                     }
                                 }
                                 else
                                 {
                                     inF1 = 0;
                                     Messages.InformationMessage("Quantity in row " + (dgvrow.Index + 1) + " should be greater than " + decQtySalesReturn);
                                 }
                             }
                             else
                             {
                                 inF1 = 0;
                                 Messages.InformationMessage("Quantity in row " + (dgvrow.Index + 1) + " should be greater than " + decQtySalesReturn);
                             }
                         }
                     }
                     else
                     {
                         inF1 = 1;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI35:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     return inF1;
 }
 /// <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>
 /// Delete all sales invoice details here
 /// </summary>
 public void removeSalesInvoiceDetails()
 {
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     try
     {
         foreach (var strId in lstArrOfRemove)
         {
             decimal decDeleteId = Convert.ToDecimal(strId);
             BllSalesInvoice.SalesDetailsDelete(decDeleteId);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 79" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill the grid
 /// </summary>
 public void GridFill()
 {
     try
     {
         List<DataTable> listObj = new List<DataTable>();
         SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
         DataTable dtbl = new DataTable();
         DateTime fromDate, toDate;
         fromDate = Convert.ToDateTime(txtFromDate.Text);
         toDate = Convert.ToDateTime(txtToDate.Text);
         string voucherNo = txtVoucherNo.Text.ToString();
         decimal voucherTypeId = Convert.ToDecimal(cmbVoucherType.SelectedValue.ToString());
         decimal groupId = Convert.ToDecimal(cmbProductGroup.SelectedValue.ToString());
         decimal ledgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         decimal employeeId = Convert.ToDecimal(cmbSalesMan.SelectedValue.ToString());
         string productCode = cmbProductCode.Text.ToString();
         listObj = BllSalesInvoice.FreeSaleReportGridFill(fromDate, toDate, voucherNo, voucherTypeId, groupId, productCode, ledgerId, employeeId);
         dgvFreeSalesReport.DataSource = listObj[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("FSR :01" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 /// <summary>
 /// Sales account combofill function
 /// </summary>
 /// <param name="cmbSalesAccount"></param>
 public void SalesAccountComboFill(ComboBox cmbSalesAccount)
 {
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     List<DataTable> listObj = new List<DataTable>();
     try
     {
         listObj = BllSalesInvoice.SalesInvoiceSalesAccountModeComboFill();
         cmbSalesAccount.DataSource = listObj[0];
         cmbSalesAccount.DisplayMember = "ledgerName";
         cmbSalesAccount.ValueMember = "ledgerId";
         cmbSalesAccount.SelectedIndex = 0;
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 06" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        /// <summary>
        /// When doubleclicking on the grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvReport_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            decimal decVouchertypeId = 0;
            string strVoucherNo = string.Empty;
            try
            {
                if (dgvReport.CurrentRow.Index == e.RowIndex)
                {
                    if ((dgvReport.CurrentRow.Cells["voucherTypeId"].Value != null && dgvReport.CurrentRow.Cells["voucherTypeId"].Value.ToString() != string.Empty))
                    {
                        int inI = dgvReport.CurrentCell.RowIndex;
                        foreach (DataGridViewRow dgv in dgvReport.Rows)
                        {
                            if (dgv.Cells["VoucherNo"].Value != null && dgv.Cells["VoucherNo"].Value.ToString() != string.Empty &&
                                   dgv.Cells["voucherTypeId"].Value != null && dgv.Cells["voucherTypeId"].Value.ToString() != string.Empty)
                            {
                                strVoucherType = dgv.Cells["VoucherType"].Value.ToString();
                                decVouchertypeId = Convert.ToDecimal(dgv.Cells["voucherTypeId"].Value.ToString());
                                strVoucherNo = dgv.Cells["VoucherNo"].Value.ToString();
                            }
                            else
                            {
                                if (dgv.Cells["ledgerId"].Value.ToString() != string.Empty)
                                {
                                    decledgerId = decimal.Parse(dgv.Cells["ledgerId"].Value.ToString());
                                    strVoucherType = dgv.Cells["Account Ledger"].Value.ToString();
                                    frmLedgerDetails frmLedger = new frmLedgerDetails();
                                    frmLedger = Application.OpenForms["frmLedgerDetails"] as frmLedgerDetails;
                                    if (frmLedger == null)
                                    {
                                        frmLedger = new frmLedgerDetails();
                                        frmLedger.MdiParent = formMDI.MDIObj;
                                        frmLedger.callFromAgeing(this, decledgerId);
                                        this.Enabled = false;
                                    }
                                }

                            }
                            if (dgv.Index == inI)
                            {
                                break;
                            }
                        }
                        if (strVoucherType == "Payment Voucher")
                        {
                            PaymentVoucherBll BllPaymentVoucher = new PaymentVoucherBll();
                            decMasterId = BllPaymentVoucher.paymentMasterIdView(decVouchertypeId, strVoucherNo);
                            frmPaymentVoucher frmPaymentVoucher = new frmPaymentVoucher();
                            frmPaymentVoucher = Application.OpenForms["frmPaymentVoucher"] as frmPaymentVoucher;
                            if (frmPaymentVoucher == null)
                            {
                                frmPaymentVoucher = new frmPaymentVoucher();
                                frmPaymentVoucher.MdiParent = formMDI.MDIObj;
                                frmPaymentVoucher.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "Receipt Voucher")
                        {
                            RecieptVoucherBll bllRecieptVoucher = new RecieptVoucherBll();
                            //ReceiptMasterSP spRecieptMaster = new ReceiptMasterSP();
                            decMasterId = bllRecieptVoucher.ReceiptMasterIdView(decVouchertypeId, strVoucherNo);
                            frmReceiptVoucher frmReceiptVoucher = new frmReceiptVoucher();
                            frmReceiptVoucher = Application.OpenForms["frmReceiptVoucher"] as frmReceiptVoucher;
                            if (frmReceiptVoucher == null)
                            {
                                frmReceiptVoucher = new frmReceiptVoucher();
                                frmReceiptVoucher.MdiParent = formMDI.MDIObj;
                                frmReceiptVoucher.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "Journal Voucher")
                        {
                            JournalVoucherBll bllJournalMaster = new JournalVoucherBll();
                            decMasterId = bllJournalMaster.JournalMasterIdView(decVouchertypeId, strVoucherNo);
                            frmJournalVoucher frmJournalVoucher = new frmJournalVoucher();
                            frmJournalVoucher = Application.OpenForms["frmJournalVoucher"] as frmJournalVoucher;
                            if (frmJournalVoucher == null)
                            {
                                frmJournalVoucher = new frmJournalVoucher();
                                frmJournalVoucher.MdiParent = formMDI.MDIObj;
                                frmJournalVoucher.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "PDC Receivable")
                        {
                            PDCRecivebleBll BllPDCReciveble = new PDCRecivebleBll();
                            decMasterId = BllPDCReciveble.PdcReceivableMasterIdView(decVouchertypeId, strVoucherNo);
                            frmPdcReceivable frmPdcReceivable = new frmPdcReceivable();
                            frmPdcReceivable = Application.OpenForms["frmPdcReceivable"] as frmPdcReceivable;
                            if (frmPdcReceivable == null)
                            {
                                frmPdcReceivable = new frmPdcReceivable();
                                frmPdcReceivable.MdiParent = formMDI.MDIObj;
                                frmPdcReceivable.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "PDC Payable")
                        {
                            PDCPayableBll BllPDCPayable = new PDCPayableBll();
                            decMasterId = BllPDCPayable.PdcPayableMasterIdView(decVouchertypeId, strVoucherNo);
                            frmPdcPayable frmPdcPayable = new frmPdcPayable();
                            frmPdcPayable = Application.OpenForms["frmPdcPayable"] as frmPdcPayable;
                            if (frmPdcPayable == null)
                            {
                                frmPdcPayable = new frmPdcPayable();
                                frmPdcPayable.MdiParent = formMDI.MDIObj;
                                frmPdcPayable.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "Sales Invoice")
                        {
                            //SalesMasterSP spMaster = new SalesMasterSP();
                            SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
                            decMasterId = BllSalesInvoice.SalesMasterIdViewByvoucherNoAndVoucherType(decVouchertypeId, strVoucherNo);
                            //SalesMasterSP spSalesMaster = new SalesMasterSP();
                            bool blPOS = BllSalesInvoice.DayBookSalesInvoiceOrPOS(decMasterId, decVouchertypeId);
                            frmSalesInvoice frmSalesInvoice = new frmSalesInvoice();
                            frmPOS frmPOS = new frmPOS();
                            if (blPOS == true)
                            {
                                frmPOS = Application.OpenForms["frmPOS"] as frmPOS;
                                if (frmPOS == null)
                                {
                                    frmPOS = new frmPOS();
                                    frmPOS.MdiParent = formMDI.MDIObj;
                                    frmPOS.callFromAgeing(this, decMasterId);
                                    this.Enabled = false;
                                }
                            }
                            else
                            {
                                frmSalesInvoice = Application.OpenForms["frmSalesInvoice"] as frmSalesInvoice;
                                if (frmSalesInvoice == null)
                                {
                                    frmSalesInvoice = new frmSalesInvoice();
                                    frmSalesInvoice.MdiParent = formMDI.MDIObj;
                                    frmSalesInvoice.callFromAgeing(this, decMasterId);
                                    this.Enabled = false;
                                }
                            }
                        }
                        else if (strVoucherType == "Purchase Invoice")
                        {
                            PurchaseInvoiceBll BllPurchaseInvoice = new PurchaseInvoiceBll();
                            decMasterId = BllPurchaseInvoice.PurchaseMasterIdViewByvoucherNoAndVoucherType(decVouchertypeId, strVoucherNo);
                            frmPurchaseInvoice objpurchase = new frmPurchaseInvoice();
                            objpurchase.WindowState = FormWindowState.Normal;
                            objpurchase.MdiParent = formMDI.MDIObj;
                            objpurchase.callFromAgeing(this, decMasterId);
                            this.Enabled = false;
                        }
                        else if (strVoucherType == "Credit Note")
                        {
                            CreditNoteBll BllCreditNoteMaster = new CreditNoteBll();
                            decMasterId = BllCreditNoteMaster.CreditNoteMasterIdView(decVouchertypeId, strVoucherNo);
                            frmCreditNote objpurchase = new frmCreditNote();
                            objpurchase.WindowState = FormWindowState.Normal;
                            objpurchase.MdiParent = formMDI.MDIObj;
                            objpurchase.callFromAgeing(this, decMasterId);
                            this.Enabled = false;
                        }
                        else if (strVoucherType == "Debit Note")
                        {
                            //DebitNoteMasterSP spDebitNote = new DebitNoteMasterSP();
                            DebitNoteBll bllDebitNote = new DebitNoteBll();
                            decMasterId = bllDebitNote.DebitNoteMasterIdView(decVouchertypeId, strVoucherNo);
                            frmDebitNote objpurchase = new frmDebitNote();
                            objpurchase.WindowState = FormWindowState.Normal;
                            objpurchase.MdiParent = formMDI.MDIObj;
                            objpurchase.callFromAgeing(this, decMasterId);
                            this.Enabled = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("AR17:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// When doubleclicking on the grid
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvVatreturn_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (dgvVatreturn.Rows.Count > 1)
         {
             if (dgvVatreturn.CurrentRow.Cells["dgvtxtsalesmasterid"].Value != null)
             {
                 //SalesMasterSP spSale = new SalesMasterSP();
                 SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
                 strVoucherName = dgvVatreturn.CurrentRow.Cells["dgvtxtvoucherName"].Value.ToString();
                 dcSalesId = Convert.ToDecimal(dgvVatreturn.CurrentRow.Cells["dgvtxtsalesmasterid"].Value.ToString());
                 if (dgvVatreturn.CurrentRow.Cells["dgvtxtvoucherName"].Value != null)
                 {
                     string strpos = BllSalesInvoice.SaleMasterGetPos(dcSalesId, strVoucherName);
                     if (strpos == "0")
                     {
                         frmSalesInvoice objfrmsaleInvoice;
                         objfrmsaleInvoice = Application.OpenForms["frmSalesInvoice"] as frmSalesInvoice;
                         if (objfrmsaleInvoice == null)
                         {
                             objfrmsaleInvoice = new frmSalesInvoice();
                             objfrmsaleInvoice.MdiParent = formMDI.MDIObj;
                             objfrmsaleInvoice.callFromVatReturnReport(this, dcSalesId);
                         }
                         else
                         {
                             objfrmsaleInvoice.callFromVatReturnReport(this, dcSalesId);
                         }
                     }
                     if (strpos == "1")
                     {
                         frmPOS objfrmpos;
                         objfrmpos = Application.OpenForms["frmPOS"] as frmPOS;
                         if (objfrmpos == null)
                         {
                             objfrmpos = new frmPOS();
                             objfrmpos.MdiParent = formMDI.MDIObj;
                             objfrmpos.callFromVatReturnReport(this, dcSalesId);
                         }
                         else
                         {
                             objfrmpos.callFromVatReturnReport(this, dcSalesId);
                         }
                     }
                     if (strpos == "a")
                     {
                         frmPurchaseInvoice objfrmPurchaseInvoice;
                         objfrmPurchaseInvoice = Application.OpenForms["frmPurchaseInvoice"] as frmPurchaseInvoice;
                         if (objfrmPurchaseInvoice == null)
                         {
                             objfrmPurchaseInvoice = new frmPurchaseInvoice();
                             objfrmPurchaseInvoice.MdiParent = formMDI.MDIObj;
                             objfrmPurchaseInvoice.CallFromVatReturnReport(this, dcSalesId);
                         }
                         else
                         {
                             objfrmPurchaseInvoice.CallFromVatReturnReport(this, dcSalesId);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("VRR:15" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }