/// <summary>
        /// Function to reset form
        /// </summary>
        /// 
        public void invoiceNumberfill()
        {
            decimal decVoucherTypeId = 0;
            List<DataTable> ListObj = new List<DataTable>();
            try
            {
                if (cmpvoucherType.SelectedIndex > -1)
                {
                    if (cmpvoucherType.SelectedValue.ToString() != "System.Data.DataRowView" && cmpvoucherType.Text != "System.Data.DataRowView")
                    {

                        SalesReturnBll bllSalesReturn = new SalesReturnBll();
                        decVoucherTypeId = Convert.ToDecimal(cmpvoucherType.SelectedValue.ToString());
                        ListObj = bllSalesReturn.invoicenumberviewallforvouchertypeIdforSR(decVoucherTypeId);
                        DataRow drow = ListObj[0].NewRow();
                        drow["invoiceNo"] = "All";
                        ListObj[0].Rows.InsertAt(drow, 0);
                        cmbInvoiceNo.DataSource = ListObj;
                        cmbInvoiceNo.ValueMember = "salesReturnMasterId";
                        cmbInvoiceNo.DisplayMember = "invoiceNo";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("SRR16:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// FunctionforVouchertypecombofill
 /// </summary>
 public void VoucherTypeCombofill()
 {
     try
     {
         List<DataTable> ListObj = new List<DataTable>();
         SalesReturnBll bllSalesReturn = new SalesReturnBll();
         ListObj = bllSalesReturn.vouchertypecompofill();
         cmbVoucherType.DataSource = ListObj[0];
         cmbVoucherType.ValueMember = "voucherTypeId";
         cmbVoucherType.DisplayMember = "voucherTypeName";
     }
     catch (Exception ex)
     {
         MessageBox.Show("SR:67" + 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>
        /// Function to save an item into table
        /// </summary>
        public void Save()
        {
            ExchangeRateBll BllExchangeRate = new ExchangeRateBll();

            SalesReturnBll bllSalesReturn = new SalesReturnBll();

            StockPostingBll BllStockPosting = new StockPostingBll();
            StockPostingBll BllStockPostingf = new StockPostingBll();
            LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
            PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
            UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
            UnitBll bllUnit = new UnitBll();
            try
            {
                if (txtReturnNo.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("Enter return no", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtReturnNo.Focus();
                }
                else if (bllSalesReturn.SalesReturnNumberCheckExistence(txtReturnNo.Text.Trim(), 0, decSalesReturnVoucherTypeId) == true && btnSave.Text == "Save")
                {
                    Messages.InformationMessage("Return  number already exist");
                    txtReturnNo.Focus();
                }
                else if (txtDate.Text == "")
                {
                    MessageBox.Show("Select a date in between financial year", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtDate.Focus();
                }
                else if (cmbCashOrParty.SelectedValue == null)
                {
                    MessageBox.Show("Select cash/party", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cmbCashOrParty.Focus();
                }
                else if (cmbSalesAccount.SelectedValue == null)
                {
                    MessageBox.Show("Select sales account", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cmbSalesAccount.Focus();
                }
                else if (cmbCurrency.SelectedValue == null)
                {
                    MessageBox.Show("Select currency", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cmbCurrency.Focus();
                }
                else
                {
                    if (isAutomatic)
                    {
                        if (strVoucherNo != string.Empty)
                        {
                            infoSalesReturnMaster.VoucherNo = strVoucherNo;
                        }
                        if (txtReturnNo.Text != string.Empty)
                        {
                            infoSalesReturnMaster.InvoiceNo = txtReturnNo.Text;
                        }
                    }
                    else
                    {
                        infoSalesReturnMaster.VoucherNo = txtReturnNo.Text;
                        infoSalesReturnMaster.InvoiceNo = txtReturnNo.Text;
                    }
                    if (decSalesReturnVoucherTypeId != 0)
                    {
                        infoSalesReturnMaster.VoucherTypeId = decSalesReturnVoucherTypeId;
                    }
                    if (decSalesReturnSuffixPrefixId != 0)
                    {
                        infoSalesReturnMaster.SuffixPrefixId = decSalesReturnSuffixPrefixId;
                    }
                    if (cmbCashOrParty.SelectedValue != null)
                    {
                        infoSalesReturnMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
                    }
                    if (cmbInvoiceNo.SelectedValue != null)
                    {
                        infoSalesReturnMaster.SalesMasterId = Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString());
                    }
                    else
                    {
                        infoSalesReturnMaster.SalesMasterId = 0;
                    }
                    if (cmbSalesAccount.SelectedValue != null)
                    {
                        infoSalesReturnMaster.SalesAccount = Convert.ToDecimal(cmbSalesAccount.SelectedValue.ToString());
                    }
                    if (cmbPricingLevel.SelectedValue != null)
                    {
                        infoSalesReturnMaster.PricinglevelId = Convert.ToDecimal(cmbPricingLevel.SelectedValue.ToString());
                    }
                    else
                    {
                        infoSalesReturnMaster.PricinglevelId = 0;
                    }
                    if (cmbSalesMan.SelectedValue != null)
                    {
                        infoSalesReturnMaster.EmployeeId = Convert.ToDecimal(cmbSalesMan.SelectedValue.ToString());
                    }
                    else
                    {
                        infoSalesReturnMaster.EmployeeId = 0;
                    }
                    if (cmbCurrency.SelectedValue != null)
                    {
                        infoSalesReturnMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                        decExchangeRate = BllExchangeRate.ExchangeRateViewByExchangeRateId(infoSalesReturnMaster.ExchangeRateId);
                    }
                    infoSalesReturnMaster.Narration = txtNarration.Text.Trim();
                    infoSalesReturnMaster.UserId = PublicVariables._decCurrentUserId;
                    infoSalesReturnMaster.LrNo = txtLRNo.Text.Trim();
                    infoSalesReturnMaster.TransportationCompany = txtTransportationComp.Text.Trim();
                    infoSalesReturnMaster.Date = Convert.ToDateTime(txtDate.Text);
                    if (txtTotalAmount.Text != string.Empty)
                    {
                        infoSalesReturnMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
                    }
                    if (txtGrandTotal.Text != string.Empty)
                    {
                        infoSalesReturnMaster.grandTotal = Convert.ToDecimal(txtGrandTotal.Text);
                    }
                    if (lblTaxAmount.Text != string.Empty)
                    {
                        infoSalesReturnMaster.TaxAmount = Convert.ToDecimal(lblTaxAmount.Text);
                    }
                    infoSalesReturnMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                    infoSalesReturnMaster.Extra1 = string.Empty;
                    infoSalesReturnMaster.Extra2 = string.Empty;
                    if (txtBillDiscount.Text != string.Empty)
                    {
                        infoSalesReturnMaster.Discount = Convert.ToDecimal(txtBillDiscount.Text);
                    }
                    else
                    {
                        infoSalesReturnMaster.Discount = 0;
                    }
                    decimal decNetTotal = 0;
                    decimal decGrandTotal = 0;
                    string strQuantities = string.Empty;
                    if (btnSave.Text == "Update")
                    {
                        infoSalesReturnMaster.SalesReturnMasterId = decSalesReturnMasterId;
                        bllSalesReturn.SalesReturnMasterEdit(infoSalesReturnMaster);
                        BllLedgerPosting.LedgerPostingAndPartyBalanceDeleteByVoucherTypeIdAndLedgerIdAndVoucherNo(decSalesReturnVoucherTypeId, strVoucherNo, txtReturnNo.Text);
                        BllLedgerPosting.LedgerPostingAndPartyBalanceDeleteByVoucherTypeIdAndLedgerIdAndVoucherNo(decSalesReturnVoucherTypeId, strVoucherNo, txtReturnNo.Text);
                        BllStockPosting.StockPostingDeleteByVoucherTypeAndVoucherNo(strVoucherNo, decSalesReturnVoucherTypeId);
                        bllSalesReturnBill.SalesReturnBillTaxDeleteBySalesReturnMasterId(decSalesReturnMasterId);
                    }
                    else
                    {
                        decSalesReturnMasterId = bllSalesReturn.SalesReturnMasterAdd(infoSalesReturnMaster);
                    }
                    SalesReturnDetailsInfo infoSalesReturnDetailsInfo = new SalesReturnDetailsInfo();
                    infoSalesReturnDetailsInfo.Extra1 = string.Empty;
                    infoSalesReturnDetailsInfo.Extra2 = string.Empty;
                    if (btnSave.Text == "Update")
                    {
                        foreach (var strId in lstArrOfRemove)
                        {
                            decimal decDeleteId = Convert.ToDecimal(strId);
                            bllSalesReturn.SalesReturnDetailsDelete(decDeleteId);
                        }
                    }
                    foreach (DataGridViewRow DGVSalesReturn in dgvSalesReturn.Rows)
                    {
                        if (DGVSalesReturn.Cells["productId"].Value != null && DGVSalesReturn.Cells["productId"].Value.ToString() != string.Empty)
                        {
                            infoSalesReturnDetailsInfo.SalesReturnMasterId = decSalesReturnMasterId;
                            infoSalesReturnDetailsInfo.ProductId = Convert.ToDecimal(DGVSalesReturn.Cells["productId"].Value.ToString());
                            if (DGVSalesReturn.Cells["dgvTextQty"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.Qty = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextQty"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvTextRate"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.Rate = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextRate"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvCmbUnit"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.UnitId = Convert.ToDecimal(DGVSalesReturn.Cells["dgvCmbUnit"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["unitConversionId"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.UnitConversionId = Convert.ToDecimal(DGVSalesReturn.Cells["unitConversionId"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvTextDiscountAmount"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.Discount = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextDiscountAmount"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvCmbTax"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.TaxId = Convert.ToDecimal(DGVSalesReturn.Cells["dgvCmbTax"].Value.ToString());
                            }
                            else
                            {
                                infoSalesReturnDetailsInfo.TaxId = 0;
                            }
                            if (DGVSalesReturn.Cells["dgvCmbBatch"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.BatchId = Convert.ToDecimal(DGVSalesReturn.Cells["dgvCmbBatch"].Value.ToString());
                            }
                            else
                            {
                                infoSalesReturnDetailsInfo.BatchId = 0;
                            }
                            if (DGVSalesReturn.Cells["dgvCmbBatch"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.BatchId = Convert.ToDecimal(DGVSalesReturn.Cells["dgvCmbBatch"].Value.ToString());
                            }
                            else
                            {
                                infoSalesReturnDetailsInfo.BatchId = 0;
                            }
                            if (DGVSalesReturn.Cells["dgvCmbGodown"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.GodownId = Convert.ToDecimal(DGVSalesReturn.Cells["dgvCmbGodown"].Value.ToString());
                            }
                            else
                            {
                                infoSalesReturnDetailsInfo.GodownId = 0;
                            }
                            if (DGVSalesReturn.Cells["dgvCmbRack"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.RackId = Convert.ToDecimal(DGVSalesReturn.Cells["dgvCmbRack"].Value.ToString());
                            }
                            else
                            {
                                infoSalesReturnDetailsInfo.RackId = 0;
                            }
                            if (DGVSalesReturn.Cells["dgvTextTaxAmount"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.TaxAmount = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextTaxAmount"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvTextGrossValue"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.GrossAmount = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextGrossValue"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvTextNetValue"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.NetAmount = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextNetValue"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvTextAmount1"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.Amount = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextAmount1"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvSNo"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.SlNo = Convert.ToInt32(DGVSalesReturn.Cells["dgvSNo"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["salesDetailsId"].Value != null && cmbInvoiceNo.SelectedValue != null)
                            {
                                infoSalesReturnDetailsInfo.SalesDetailsId = Convert.ToDecimal(DGVSalesReturn.Cells["salesDetailsId"].Value.ToString());
                            }
                            else
                            {
                                infoSalesReturnDetailsInfo.SalesDetailsId = 0;
                            }
                            if (DGVSalesReturn.Cells["salesReturnDetailsId"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.SalesReturnDetailsId = Convert.ToDecimal(DGVSalesReturn.Cells["salesReturnDetailsId"].Value.ToString());
                                bllSalesReturn.SalesReturnDetailsEdit(infoSalesReturnDetailsInfo);
                            }
                            else
                            {
                                decSalesReturnDetailId = bllSalesReturn.SalesReturnDetailsAdd(infoSalesReturnDetailsInfo);
                            }
                            StockPostingInfo infoStockPosting = new StockPostingInfo();
                            infoStockPosting.Date = infoSalesReturnMaster.Date;
                            if (DGVSalesReturn.Cells["voucherTypeId"].Value != null)
                            {
                                infoStockPosting.VoucherTypeId = Convert.ToDecimal(DGVSalesReturn.Cells["voucherTypeId"].Value.ToString());
                                decAgainstVoucherTypeId = infoStockPosting.VoucherTypeId;
                                infoStockPosting.AgainstVoucherTypeId = decSalesReturnVoucherTypeId;
                            }
                            else
                            {
                                infoStockPosting.VoucherTypeId = decSalesReturnVoucherTypeId;
                                infoStockPosting.AgainstVoucherTypeId = 0;
                            }
                            if (DGVSalesReturn.Cells["voucherNo"].Value != null)
                            {
                                infoStockPosting.VoucherNo = DGVSalesReturn.Cells["voucherNo"].Value.ToString();
                                strAgainstVoucherNo = infoStockPosting.VoucherNo;
                                infoStockPosting.AgainstVoucherNo = strVoucherNo;
                            }
                            else
                            {
                                infoStockPosting.VoucherNo = strVoucherNo;
                                infoStockPosting.AgainstVoucherNo = "NA";
                            }
                            if (DGVSalesReturn.Cells["invoiceNo"].Value != null)
                            {
                                infoStockPosting.InvoiceNo = DGVSalesReturn.Cells["invoiceNo"].Value.ToString();
                                strAgainstInvoiceNo = infoStockPosting.InvoiceNo;
                                infoStockPosting.AgainstInvoiceNo = txtReturnNo.Text.Trim();
                            }
                            else
                            {
                                infoStockPosting.InvoiceNo = txtReturnNo.Text;
                                infoStockPosting.AgainstInvoiceNo = "NA";
                            }
                            infoStockPosting.ProductId = infoSalesReturnDetailsInfo.ProductId;
                            infoStockPosting.BatchId = infoSalesReturnDetailsInfo.BatchId;
                            infoStockPosting.UnitId = infoSalesReturnDetailsInfo.UnitId;
                            infoStockPosting.GodownId = infoSalesReturnDetailsInfo.GodownId;
                            infoStockPosting.RackId = infoSalesReturnDetailsInfo.RackId;
                            if (infoSalesReturnDetailsInfo.ProductId != 0 && infoSalesReturnDetailsInfo.UnitId != 0)
                            {
                                decimal decUnitConvertionRate = 0;
                                infoProduct = BllProductCreation.ProductView(infoSalesReturnDetailsInfo.ProductId);
                               List< DataTable> list = bllUnitConvertion.DGVUnitConvertionRateByUnitId(infoSalesReturnDetailsInfo.UnitId, infoProduct.ProductName);
                                foreach (DataRow drowDetails in list[0].Rows)
                                {
                                    decUnitConvertionRate = Convert.ToDecimal(drowDetails["conversionRate"].ToString());
                                }
                                strQuantities = bllUnit.UnitConversionCheck(infoSalesReturnDetailsInfo.UnitId, infoSalesReturnDetailsInfo.ProductId);
                                if (strQuantities != string.Empty)
                                {
                                    infoStockPosting.InwardQty = infoSalesReturnDetailsInfo.Qty / decUnitConvertionRate;
                                }
                                else
                                {
                                    infoStockPosting.InwardQty = infoSalesReturnDetailsInfo.Qty;
                                }
                            }
                            infoStockPosting.OutwardQty = 0;
                            infoStockPosting.Rate = infoSalesReturnDetailsInfo.Rate;
                            infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                            infoStockPosting.Extra1 = string.Empty;
                            infoStockPosting.Extra2 = string.Empty;
                           BllStockPosting.StockPostingAdd(infoStockPosting);
                        }
                    }
                    decGrandTotal = Convert.ToDecimal(txtGrandTotal.Text);
                    decNetTotal = TotalNetAmountForLedgerPosting();
                    LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
                    infoLedgerPosting.Date = infoSalesReturnMaster.Date;
                    infoLedgerPosting.ChequeDate = infoSalesReturnMaster.Date;
                    infoLedgerPosting.ChequeNo = String.Empty;
                    infoLedgerPosting.VoucherTypeId = infoSalesReturnMaster.VoucherTypeId;
                    infoLedgerPosting.VoucherNo = infoSalesReturnMaster.VoucherNo;
                    infoLedgerPosting.LedgerId = infoSalesReturnMaster.LedgerId;
                    infoLedgerPosting.Debit = 0;
                    infoLedgerPosting.Credit = (decGrandTotal * decExchangeRate);
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.InvoiceNo = infoSalesReturnMaster.InvoiceNo;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                    infoLedgerPosting.LedgerId = infoSalesReturnMaster.SalesAccount;
                    infoLedgerPosting.Debit = (decNetTotal * decExchangeRate);
                    infoLedgerPosting.Credit = 0;
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                    if (Convert.ToDecimal(txtBillDiscount.Text == string.Empty ? "0" : txtBillDiscount.Text) > 0)
                    {
                        infoLedgerPosting.LedgerId = 8;
                        infoLedgerPosting.Debit = 0;
                        infoLedgerPosting.Credit = (Convert.ToDecimal(txtBillDiscount.Text) * decExchangeRate);
                        BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                    }
                    LedegrPostingForTax();
                    PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
                    infoPartyBalance.Date = infoSalesReturnMaster.Date;
                    infoPartyBalance.LedgerId = infoSalesReturnMaster.LedgerId;
                    if (decAgainstVoucherTypeId != 0)
                    {
                        infoPartyBalance.VoucherTypeId = decAgainstVoucherTypeId;
                        infoPartyBalance.VoucherNo = strAgainstVoucherNo;
                        infoPartyBalance.InvoiceNo = strAgainstInvoiceNo;
                        infoPartyBalance.AgainstVoucherTypeId = infoSalesReturnMaster.VoucherTypeId;
                        infoPartyBalance.AgainstVoucherNo = infoSalesReturnMaster.VoucherNo;
                        infoPartyBalance.AgainstInvoiceNo = infoSalesReturnMaster.InvoiceNo;
                        infoPartyBalance.ReferenceType = "Against";
                    }
                    else
                    {
                        infoPartyBalance.VoucherTypeId = infoSalesReturnMaster.VoucherTypeId;
                        infoPartyBalance.VoucherNo = infoSalesReturnMaster.VoucherNo;
                        infoPartyBalance.InvoiceNo = infoSalesReturnMaster.InvoiceNo;
                        infoPartyBalance.AgainstVoucherTypeId = 0;
                        infoPartyBalance.AgainstVoucherNo = "NA";
                        infoPartyBalance.AgainstInvoiceNo = "NA";
                        infoPartyBalance.ReferenceType = "New";
                    }

                    infoPartyBalance.Credit = infoSalesReturnMaster.TotalAmount;
                    infoPartyBalance.Debit = 0;
                    infoPartyBalance.CreditPeriod = 0;
                    infoPartyBalance.ExchangeRateId = infoSalesReturnMaster.ExchangeRateId;
                    infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                    infoPartyBalance.Extra1 = string.Empty;
                    infoPartyBalance.Extra2 = string.Empty;
                    BllPartyBalance.PartyBalanceAdd(infoPartyBalance);
                    SalesReturnBillTaxInfo infoSalesReturnBillTax = new SalesReturnBillTaxInfo();
                    foreach (DataGridViewRow item in dgvSalesReturn2.Rows)
                    {
                        if (item.Cells["dgvTextTaxId"].Value != null)
                        {
                            infoSalesReturnBillTax.SalesReturnMasterId = decSalesReturnMasterId;
                            infoSalesReturnBillTax.TaxId = Convert.ToDecimal(item.Cells["dgvTextTaxId"].Value.ToString());
                            infoSalesReturnBillTax.TaxAmount = Convert.ToDecimal(item.Cells["dgvTextAmount"].Value.ToString());
                            infoSalesReturnBillTax.Extra1 = string.Empty;
                            infoSalesReturnBillTax.Extra2 = string.Empty;
                            bllSalesReturnBill.SalesReturnBillTaxAdd(infoSalesReturnBillTax);
                        }
                    }
                    if (btnSave.Text == "Save")
                    {
                        Messages.SavedMessage();
                        if (cbxPrintAfterSave.Checked == true)
                        {
                            if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decSalesReturnMasterId);
                            }
                            else
                            {
                                Print(decSalesReturnMasterId);
                            }
                        }
                        clear();
                    }
                    else
                    {
                        Messages.UpdatedMessage();
                        if (cbxPrintAfterSave.Checked == true)
                        {
                            if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decSalesReturnMasterId);
                            }
                            else
                            {
                                Print(decSalesReturnMasterId);
                            }
                        }
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("SR36:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to generate Voucher number as per settings
 /// </summary>
 public void VoucherNumberGeneration()
 {
     try
     {
         TransactionsGeneralFillBll obj = new TransactionsGeneralFillBll();
         SalesReturnBll bllSalesReturn = new SalesReturnBll();
         string strPrefix = string.Empty;
         string strSuffix = string.Empty;
         string strReturnNo = string.Empty;
         string tableName = "SalesReturnMaster";
         if (strVoucherNo == string.Empty)
         {
             strVoucherNo = "0";
         }
         strVoucherNo = obj.VoucherNumberAutomaicGeneration(decSalesReturnVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpDate.Value, tableName);
         if (Convert.ToDecimal(strVoucherNo) != bllSalesReturn.SalesReturnMasterGetMaxPlusOne(decSalesReturnVoucherTypeId))
         {
             strVoucherNo = bllSalesReturn.SalesReturnMasterGetMax(decSalesReturnVoucherTypeId).ToString();
             strVoucherNo = obj.VoucherNumberAutomaicGeneration(decSalesReturnVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpDate.Value, tableName);
             if (bllSalesReturn.SalesReturnMasterGetMax(decSalesReturnVoucherTypeId) == "0")
             {
                 strVoucherNo = "0";
                 strVoucherNo = obj.VoucherNumberAutomaicGeneration(decSalesReturnVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpDate.Value, tableName);
             }
         }
         if (isAutomatic)
         {
             SuffixPrefixSettingsBll BllSuffixPrefixSettings = new SuffixPrefixSettingsBll();
             SuffixPrefixInfo infoSuffixPrefix = new SuffixPrefixInfo();
             infoSuffixPrefix = BllSuffixPrefixSettings.GetSuffixPrefixDetails(decSalesReturnVoucherTypeId, dtpDate.Value);
             strPrefix = infoSuffixPrefix.Prefix;
             strSuffix = infoSuffixPrefix.Suffix;
             decSalesReturnSuffixPrefixId = infoSuffixPrefix.SuffixprefixId;
             strReturnNo = strPrefix + strVoucherNo + strSuffix;
             txtReturnNo.Text = strReturnNo;
             txtReturnNo.ReadOnly = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SR69:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to use the SalesReturn InvoiceNo ComboFill
 /// </summary>
 /// <param name="decVoucherTypeId"></param>
 /// <param name="salesReturnMasterId"></param>
 /// <param name="decledgerId"></param>
 public void SalesReturnInvoiceNoComboFill(decimal decVoucherTypeId, decimal salesReturnMasterId, decimal decledgerId)
 {
     try
     {
         SalesReturnBll bllSalesReturn = new SalesReturnBll();
         List<DataTable> ListObj = new List<DataTable>();
         ListObj = bllSalesReturn.SalesReturnInvoiceNoComboFill(decVoucherTypeId, salesReturnMasterId, decledgerId);
         cmbInvoiceNo.DataSource = ListObj[0];
         if (cmbInvoiceNo.DataSource != null)
         {
             cmbInvoiceNo.ValueMember = "salesMasterId";
             cmbInvoiceNo.DisplayMember = "invoiceNo";
             cmbInvoiceNo.SelectedIndex = -1;
         }
         isEnterIntoComboSelectn = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show("SR55:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to use the SalesReturn VoucherType ComboFill
 /// </summary>
 /// <param name="ledgerIdFromCashOrPartyCombo"></param>
 public void SalesReturnVoucherTypeComboFill(decimal ledgerIdFromCashOrPartyCombo)
 {
     try
     {
         SalesReturnBll bllSalesReturn = new SalesReturnBll();
         List<DataTable> ListObj = new List<DataTable>();
         ListObj = bllSalesReturn.SalesReturnVoucherTypeComboFill(ledgerIdFromCashOrPartyCombo);
         cmbVoucherType.DataSource = ListObj[0];
         if (cmbVoucherType.DataSource != null)
         {
             DataRow dr = ListObj[0].NewRow();
             dr["voucherTypeId"] = 0;
             dr["voucherTypeName"] = "NA";
             ListObj[0].Rows.InsertAt(dr, 0);
             cmbVoucherType.ValueMember = "voucherTypeId";
             cmbVoucherType.DisplayMember = "voucherTypeName";
             cmbVoucherType.SelectedIndex = -1;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SR56:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// FunctionToRemoveIncmpletedRow
        /// </summary>
        /// <returns></returns>
        public bool RemoveIncompleteRowsFromGrid()
        {
            SalesReturnBll bllSalesReturn = new SalesReturnBll();
            bool isOk = true;
            try
            {
                string strMessage = "Rows";
                int inC = 0, inForFirst = 0;
                int inRowcount = dgvSalesReturn.RowCount;
                int inLastRow = 1;
                if (inRowcount <= 2)
                {
                    if (dgvSalesReturn.Rows[0].Cells["dgvTextProductName"].Value == null || dgvSalesReturn.Rows[0].Cells["dgvTextProductName"].Value.ToString() == string.Empty ||
                        dgvSalesReturn.Rows[0].Cells["dgvTextProductCode"].Value == null || dgvSalesReturn.Rows[0].Cells["dgvTextProductCode"].Value.ToString() == string.Empty ||
                         dgvSalesReturn.Rows[0].Cells["dgvTextQty"].Value == null || dgvSalesReturn.Rows[0].Cells["dgvTextQty"].Value.ToString().Trim() == string.Empty ||
                          Convert.ToDecimal(dgvSalesReturn.Rows[0].Cells["dgvTextQty"].Value.ToString()) == 0 || dgvSalesReturn.Rows[0].Cells["dgvTextRate"].Value == null || dgvSalesReturn.Rows[0].Cells["dgvTextRate"].Value.ToString().Trim() == string.Empty ||

                        (BllSettings.SettingsStatusCheck("AllowZeroValueEntry") == "No" && Convert.ToDecimal(dgvSalesReturn.CurrentRow.Cells["dgvTextRate"].Value) == 0))
                    {
                        MessageBox.Show("Can't save purchase return without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        dgvSalesReturn.ClearSelection();
                        dgvSalesReturn.Focus();
                        isOk = false;
                    }
                }
                else
                {
                    foreach (DataGridViewRow dgvrowCur in dgvSalesReturn.Rows)
                    {
                        if (inLastRow < inRowcount)
                        {
                            if (dgvrowCur.HeaderCell.Value != null)
                            {
                                if (dgvrowCur.HeaderCell.Value.ToString() == "X" || dgvrowCur.Cells["dgvTextProductName"].Value == null)
                                {
                                    isOk = false;
                                    if (inC == 0)
                                    {
                                        strMessage = strMessage + Convert.ToString(dgvrowCur.Index + 1);
                                        inForFirst = dgvrowCur.Index;
                                        inC++;
                                    }
                                    else
                                    {
                                        strMessage = strMessage + ", " + Convert.ToString(dgvrowCur.Index + 1);
                                    }
                                }
                            }
                        }
                        inLastRow++;
                    }
                    inLastRow = 1;
                    if (!isOk)
                    {
                        strMessage = strMessage + " contains invalid entries. Do you want to continue?";
                        if (MessageBox.Show(strMessage, "OpenMiracle", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                        {
                            isOk = true;
                            for (int inK = 0; inK < dgvSalesReturn.Rows.Count; inK++)
                            {
                                if (dgvSalesReturn.Rows[inK].HeaderCell.Value != null && dgvSalesReturn.Rows[inK].HeaderCell.Value.ToString() == "X")
                                {
                                    if (!dgvSalesReturn.Rows[inK].IsNewRow)
                                    {
                                        dgvSalesReturn.Rows.RemoveAt(inK);
                                        inK--;

                                    }
                                }
                            }
                        }
                        else
                        {
                            isOk = false;
                            dgvSalesReturn.Rows[inForFirst].Cells["dgvTextProductName"].Selected = true;
                            dgvSalesReturn.CurrentCell = dgvSalesReturn.Rows[inForFirst].Cells["dgvTextProductName"];
                            dgvSalesReturn.Focus();
                        }
                    }
                }
                //SerialNo();
            }
            catch (Exception ex)
            {
                MessageBox.Show("SR:4" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return isOk;
        }
        /// <summary>
        ///FunctionToFill ProductDetales
        /// </summary>
        /// <param name="strProduct"></param>
        /// <param name="inRowIndex"></param>
        /// <param name="strFillMode"></param>
        public void ProductDetailsFill(string strProduct, int inRowIndex, string strFillMode)
        {
            try
            {
                string barcode = string.Empty;
                decimal decCurrentConversionRate = 0;
                List<DataTable> listObj = new List<DataTable>();
                UnitConvertionBll bllUnitConversion = new UnitConvertionBll();
                SalesReturnBll bllSalesReturn = new SalesReturnBll();
                BatchBll BllBatch = new BatchBll();
                ProductCreationBll BllProductCreation = new ProductCreationBll();
                if (strFillMode == "dgvTextBarcode")
                {
                    listObj = bllSalesReturn.productviewbybarcodeforSR(strProduct, decSalesReturnVoucherTypeId);
                }
                if (strFillMode == "dgvTextProductName")
                {
                    listObj = BllProductCreation.ProductCodeViewByProductName(strProduct, decSalesReturnVoucherTypeId);
                }
                if (strFillMode == "dgvTextProductCode")
                {
                    listObj = BllProductCreation.ProductNameViewByProductCode(strProduct, decSalesReturnVoucherTypeId);
                }
                if (listObj[0].Rows.Count != 0)
                {
                    DGVGodownComboFill();

                    //  SerialNo();
                    dgvSalesReturn.Rows[inRowIndex].Cells["productId"].Value = listObj[0].Rows[0]["productId"];
                    decimal decProductId = Convert.ToDecimal(dgvSalesReturn.Rows[inRowIndex].Cells["productId"].Value.ToString());
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextBarcode"].Value = listObj[0].Rows[0]["barcode"];
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextProductCode"].Value = listObj[0].Rows[0]["productCode"];
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextProductName"].Value = listObj[0].Rows[0]["productName"];
                    // dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextQty"].Value = dtbl.Rows[0]["qty"];
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextQty"].Value = string.Empty;
                    UnitComboFill(decProductId, inRowIndex, dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbUnit"].ColumnIndex);
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbUnit"].Value = Convert.ToDecimal(listObj[0].Rows[0]["unitId"].ToString());
                    dgvSalesReturn.Rows[inRowIndex].Cells["unitConversionId"].Value = listObj[0].Rows[0]["unitConversionId"];
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbGodown"].Value = Convert.ToDecimal(listObj[0].Rows[0]["godownId"].ToString());
                    RackComboFill(Convert.ToDecimal(listObj[0].Rows[0]["godownId"].ToString()), inRowIndex, dgvSalesReturn.CurrentRow.Cells["dgvCmbRack"].ColumnIndex);
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbRack"].Value = Convert.ToDecimal(listObj[0].Rows[0]["rackId"].ToString());
                    BatchComboFill(decProductId, inRowIndex, dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbBatch"].ColumnIndex);
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbBatch"].Value = Convert.ToDecimal(listObj[0].Rows[0]["batchId"].ToString());
                    decimal decBatchId = Convert.ToDecimal(dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbBatch"].Value.ToString());
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextRate"].Value = Math.Round(Convert.ToDecimal(listObj[0].Rows[0]["salesRate"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                    getProductRate(inRowIndex, decProductId, decBatchId);
                    TaxGridFill();
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbTax"].Value = Convert.ToDecimal(listObj[0].Rows[0]["taxId"].ToString());
                    dgvSalesReturn.Rows[inRowIndex].Cells["conversionRate"].Value = listObj[0].Rows[0]["conversionRate"];
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextDiscountPercentage"].Value = listObj[0].Rows[0]["discountPercent"].ToString();
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextDiscountAmount"].Value = Math.Round(Convert.ToDecimal(listObj[0].Rows[0]["discount"]), PublicVariables._inNoOfDecimalPlaces);
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextDiscountAmount"].ReadOnly = true;
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextNetValue"].Value = Math.Round(Convert.ToDecimal(listObj[0].Rows[0]["netvalue"]), PublicVariables._inNoOfDecimalPlaces);
                    GrossValueCalculation(inRowIndex);
                    DiscountCalculationfordiscountpercentage(inRowIndex, 12);
                    DiscountCalculation(inRowIndex, 13);
                    TotalAmountCalculation();
                    TaxAmountCalculation(inRowIndex);
                    taxamountfill();
                    CessTaxamountCalculation();
                    TotalBillTaxCalculation();
                    TotalTaxAmtCalculation();
                    GrandTotalCalculation();
                    taxAndGridTotalAmountCalculation(inRowIndex);
                    decCurrentConversionRate = Convert.ToDecimal(listObj[0].Rows[0]["conversionRate"].ToString());
                    dgvSalesReturn.Rows[inRowIndex].HeaderCell.Value = "X";
                    dgvSalesReturn.Rows[inRowIndex].HeaderCell.Style.ForeColor = Color.Red;
                }
                else
                {
                    if (dgvSalesReturn.CurrentRow.Index < dgvSalesReturn.RowCount - 1)
                    {
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextBarcode"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextProductCode"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextProductName"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextQty"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbUnit"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbGodown"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbBatch"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbRack"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextRate"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbTax"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextDiscountPercentage"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextDiscountAmount"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextNetValue"].Value = string.Empty;
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("SR74" + ex.Message, "openmiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// print function
 /// </summary>
 /// <param name="decSalesReturnMasterId"></param>
 public void Print(decimal decSalesReturnMasterId)
 {
     try
     {
         SalesReturnBll bllSalesReturn = new SalesReturnBll();
         DataSet dsSalesReturn = bllSalesReturn.SalesReturnPrinting(decSalesReturnMasterId);
         frmReport frmReport = new frmReport();
         frmReport.MdiParent = formMDI.MDIObj;
         frmReport.SalesReturnPrinting(dsSalesReturn);
     }
     catch (Exception ex)
     {
         MessageBox.Show("SR31:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// FunctionToreturn fromregisterclick
        /// </summary>
        public void FillRegisterOrReport()
        {
            SalesReturnBll bllSalesReturn = new SalesReturnBll();
            try
            {
                isFromOther = true;
                btnSave.Text = "Update";
                btnDelete.Enabled = true;
                CashOrPartyUnderSundryDebitorComboFill(cmbCashOrParty);
                DataTable dtblSalesMaster = new DataTable();
                List<DataTable> ListObjMaster = new List<DataTable>();
                ListObjMaster = bllSalesReturn.SalesReturnMasterViewBySalesReturnMasterId(salesReturnMasterId);
                decSalesReturnMasterId = salesReturnMasterId;
                DecSalesReturnVoucherTypeId = Convert.ToDecimal(ListObjMaster[0].Rows[0]["voucherTypeId"].ToString());
                VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
                infoVoucherType = BllVoucherType.VoucherTypeView(DecSalesReturnVoucherTypeId);
                this.Text = infoVoucherType.VoucherTypeName;
                if (infoVoucherType.MethodOfVoucherNumbering == "Manual")
                {
                    txtReturnNo.Text = ListObjMaster[0].Rows[0]["invoiceNo"].ToString();
                    ManualReturnNo = ListObjMaster[0].Rows[0]["invoiceNo"].ToString();
                    txtReturnNo.Enabled = true;
                }
                else
                {
                    txtReturnNo.Text = ListObjMaster[0].Rows[0]["invoiceNo"].ToString();
                    txtReturnNo.Enabled = false;
                }
                if (ListObjMaster[0].Rows.Count > 0)
                {
                    txtDate.Text = ListObjMaster[0].Rows[0]["date"].ToString();
                    dtpDate.Value = Convert.ToDateTime(txtDate.Text);
                    if (ListObjMaster[0].Rows[0]["grandTotal"].ToString() != string.Empty)
                    {
                        txtGrandTotal.Text = ListObjMaster[0].Rows[0]["grandTotal"].ToString();
                    }
                    strVoucherNo = ListObjMaster[0].Rows[0]["voucherNo"].ToString();
                    if (ListObjMaster[0].Rows[0]["ledgerId"].ToString() != string.Empty)
                    {
                        cmbCashOrParty.SelectedValue = ListObjMaster[0].Rows[0]["ledgerId"].ToString();
                    }
                    cmbVoucherTypeComboFill();
                    if (ListObjMaster[0].Rows[0]["SMVoucherTypeId"].ToString() != string.Empty)
                    {
                        cmbVoucherType.SelectedValue = ListObjMaster[0].Rows[0]["SMVoucherTypeId"].ToString();
                    }
                    else
                    {
                        cmbVoucherType.SelectedValue = 0;
                    }
                    cmbInvoiceComboFill();
                    if (ListObjMaster[0].Rows[0]["pricingLevelId"].ToString() != string.Empty)
                    {
                        cmbPricingLevel.SelectedValue = ListObjMaster[0].Rows[0]["pricingLevelId"].ToString();
                    }
                    if (ListObjMaster[0].Rows[0]["salesAccount"].ToString() != string.Empty)
                    {
                        cmbSalesAccount.SelectedValue = ListObjMaster[0].Rows[0]["salesAccount"].ToString();
                    }
                    if (ListObjMaster[0].Rows[0]["employeeId"].ToString() != string.Empty)
                    {
                        cmbSalesMan.SelectedValue = ListObjMaster[0].Rows[0]["employeeId"].ToString();
                    }
                    if (ListObjMaster[0].Rows[0]["exchangeRateId"].ToString() != string.Empty)
                    {
                        cmbCurrency.SelectedValue = ListObjMaster[0].Rows[0]["exchangeRateId"].ToString();
                    }
                    txtNarration.Text = ListObjMaster[0].Rows[0]["narration"].ToString();
                    txtLRNo.Text = ListObjMaster[0].Rows[0]["lrNo"].ToString();
                    txtTransportationComp.Text = ListObjMaster[0].Rows[0]["transportationCompany"].ToString();
                    if (ListObjMaster[0].Rows[0]["salesMasterId"].ToString() != string.Empty && Convert.ToDecimal(ListObjMaster[0].Rows[0]["salesMasterId"].ToString()) != 0)
                    {
                        cmbInvoiceNo.SelectedValue = ListObjMaster[0].Rows[0]["salesMasterId"].ToString();
                        decinvoiceno = Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString());
                        dtblSalesReturnMasterViewBySMID = bllSalesReturn.SalesReturnMasterViewBySalesMasterId(Convert.ToDecimal(ListObjMaster[0].Rows[0]["salesMasterId"].ToString()));
                    }
                    isInvoiceFill = false;
                    if (ListObjMaster[0].Rows[0]["voucherTypeId"].ToString() != string.Empty)
                    {
                        decSalesReturnVoucherTypeId = Convert.ToDecimal(ListObjMaster[0].Rows[0]["voucherTypeId"].ToString());
                    }
                    TaxGridFill();
                    if (cmbInvoiceNo.SelectedValue != null)
                    {
                        infoSalesMaster = BllSalesInvoice.SalesMasterViewBySalesMasterId(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()));
                    }
                    List<DataTable> ListObj1 = new List<DataTable>();
                    ListObj1 = bllSalesReturn.SalesReturnDetailsViewBySalesReturnMasterId(salesReturnMasterId);
                    dtblSalesInvoice = ListObj1[0];
                    foreach (DataRow drowDetails in ListObj1[0].Rows)
                    {
                        dgvSalesReturn.Rows.Add();
                        if (drowDetails["salesReturnDetailsId"].ToString() != string.Empty)
                        {
                            dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["salesReturnDetailsId"].Value = Convert.ToDecimal(drowDetails["salesReturnDetailsId"].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.SalesReturnGrideFillNewByProductId(Convert.ToDecimal(drowDetails["productId"].ToString()));
                            foreach (DataRow drowDetails1 in listObj[0].Rows)
                            {
                                if (drowDetails1["barcode"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextBarcode"].Value = drowDetails1["barcode"].ToString();
                                }
                                if (drowDetails1["productCode"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductCode"].Value = drowDetails1["productCode"].ToString();
                                }
                                if (drowDetails1["productName"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductName"].Value = drowDetails1["productName"].ToString();
                                }
                                if (cmbInvoiceNo.Visible == true)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].ReadOnly = true;
                                }
                                if (drowDetails["unitId"].ToString() != string.Empty)
                                {
                                    decProductId = decimal.Parse(dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["productId"].Value.ToString());
                                    UnitComboFill(decProductId, dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].ColumnIndex);
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString());
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].Value = 1;
                                }
                                if (drowDetails["goDownId"].ToString() != string.Empty)
                                {
                                    DGVGodownComboFill();
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value = Convert.ToDecimal(drowDetails["goDownId"].ToString());
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value = 1;
                                }
                                if (drowDetails["rackId"].ToString() != string.Empty)
                                {
                                    RackComboFill(Convert.ToDecimal(dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value.ToString()), dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].ColumnIndex);
                                    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;
                                }
                                if (drowDetails["batchId"].ToString() != string.Empty)
                                {
                                    BatchComboFill(decProductId, dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].ColumnIndex);
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString());
                                }
                                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;
                                }
                                if (ListObjMaster[0].Rows[0]["SMVoucherTypeId"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].ReadOnly = true;
                                }
                                if (drowDetails["taxId"].ToString() != string.Empty)
                                {
                                    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.00;
                                    decQty = 0;
                                }
                                if (drowDetails["rate"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextRate"].Value = Math.Round(Convert.ToDecimal(drowDetails["rate"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    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;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountPercentage"].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;
                                }
                                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);
                                    //dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = true;
                                }
                                else
                                {
                                    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;
                                }
                                dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["conversionRate"].Value = drowDetails["conversionRate"].ToString();
                                foreach (DataGridViewRow item1 in dgvSalesReturn2.Rows)
                                {
                                    if (item1.Cells["dgvTextTaxId"].Value != null)
                                    {
                                        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 - 2].Cells["productId"].Value = 0;
                        }
                        TotalAmountCalculation();
                    }
                    if (!isSalesReturnFormActive)
                    {
                        ListObj = bllSalesReturnBill.TaxDetailsViewBySalesReturnMasterId(salesReturnMasterId);
                        foreach (DataRow item1 in ListObj[0].Rows)
                        {
                            dgvSalesReturn2.Rows.Add();
                            dgvSalesReturn2.Rows[dgvSalesReturn2.Rows.Count - 2].Cells["dgvTextTaxName"].Value = item1["taxName"].ToString();
                            dgvSalesReturn2.Rows[dgvSalesReturn2.Rows.Count - 2].Cells["dgvTextAmount"].Value = Math.Round(Convert.ToDecimal(item1["taxAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                            dgvSalesReturn2.Rows[dgvSalesReturn2.Rows.Count - 2].Cells["dgvRate"].Value = item1["rate"].ToString();
                            dgvSalesReturn2.Rows[dgvSalesReturn2.Rows.Count - 2].Cells["dgvTextTaxId"].Value = item1["taxId"].ToString();
                        }
                    }
                    txtBillDiscount.Text = Convert.ToString(Math.Round(Convert.ToDecimal(ListObjMaster[0].Rows[0]["discount"].ToString()), PublicVariables._inNoOfDecimalPlaces));
                    SerialNo2();

                    TotalBillTaxCalculation();
                    CessTaxamountCalculation();
                    TotalTaxAmtCalculation();
                    if (txtBillDiscount.Text != string.Empty)
                    {
                        decimal decDiscount = Convert.ToDecimal(txtBillDiscount.Text);
                        decimal decTotalAmt = Convert.ToDecimal(txtTotalAmount.Text);
                        if (decTotalAmt > decDiscount)
                        {
                            decimal decGrandTotal = decTotalAmt + decTotalBillTaxAmount + decTotalCessTaxamount - decDiscount;
                            decGrandTotal = Math.Round(decGrandTotal, PublicVariables._inNoOfDecimalPlaces);
                            txtGrandTotal.Text = decGrandTotal.ToString();
                        }
                    }
                    // SerialNo();
                }
                else
                {
                    MessageBox.Show("No record exists", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("SR28:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Function to delete an item from database
        /// </summary>
        public void Delete()
        {
            try
            {
                SalesReturnBll bllSalesReturn = new SalesReturnBll();
                bllSalesReturn.SalesReturnDelete(salesReturnMasterId, decSalesReturnVoucherTypeId, strVoucherNo);
                Messages.DeletedMessage();
                if (objFromSalesReturnRegister != null)
                {
                    if (isFromOther)
                    {
                        this.Close();
                        objFromSalesReturnRegister.Enabled = true;
                        objFromSalesReturnRegister.SalesReturnGrideFill();
                    }
                }
                else if (objFromSalesReturnReport != null)
                {
                    if (isFromOther)
                    {
                        this.Close();
                        objFromSalesReturnReport.Enabled = true;
                        objFromSalesReturnReport.SalesReturnReportGrideFill();
                    }
                }
                else if (objVoucherSearch != null)
                {

                    objVoucherSearch.GridFill();
                    this.Close();
                }
                else if (frmDayBookObj != null)
                {
                    this.Close();
                }
                else
                {
                    clear();
                }
                if (frmLedgerDetailsObj != null)
                {
                    this.Close();
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("SR30:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }