/// <summary>
 /// Function to save the voucher
 /// </summary>
 public void SaveFunction()
 {
     MaterialReceiptDetailsInfo infoMaterialReceiptDetails = new MaterialReceiptDetailsInfo();
     ProductInfo infoProduct = new ProductInfo();
     MaterialReceiptMasterInfo infoMaterialReceiptMaster = new MaterialReceiptMasterInfo();
     StockPostingBll BllStockPosting = new StockPostingBll();
     //StockPostingSP spstockposting = new StockPostingSP();
     MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
     ProductCreationBll BllProductCreation = new ProductCreationBll();
     try
     {
         infoMaterialReceiptMaster.Date = Convert.ToDateTime(txtDate.Text);
         infoMaterialReceiptMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         if (isAutomatic)
         {
             infoMaterialReceiptMaster.SuffixPrefixId = decMaterialReceiptSuffixPrefixId;
             infoMaterialReceiptMaster.VoucherNo = strVoucherNo;
         }
         else
         {
             infoMaterialReceiptMaster.SuffixPrefixId = 0;
             infoMaterialReceiptMaster.VoucherNo = txtReceiptNo.Text;
         }
         infoMaterialReceiptMaster.VoucherTypeId = decMaterialReceiptVoucherTypeId;
         infoMaterialReceiptMaster.InvoiceNo = txtReceiptNo.Text;
         infoMaterialReceiptMaster.UserId = PublicVariables._decCurrentUserId;
         infoMaterialReceiptMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         infoMaterialReceiptMaster.TransportationCompany = txtTransportation.Text.Trim();
         infoMaterialReceiptMaster.LrNo = txtLRNo.Text.Trim();
         infoMaterialReceiptMaster.Narration = txtNarration.Text.Trim();
         if (cmbOrderNo.SelectedValue == null || cmbOrderNo.SelectedValue.ToString() == string.Empty)
         {
             infoMaterialReceiptMaster.OrderMasterId = 0;
         }
         else
         {
             infoMaterialReceiptMaster.OrderMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
         }
         infoMaterialReceiptMaster.exchangeRateId = Convert.ToDecimal(cmbcurrency.SelectedValue.ToString());//saving corresponding exchangeRateId as currencyId
         infoMaterialReceiptMaster.TotalAmount = Convert.ToDecimal(txtTotal.Text);
         infoMaterialReceiptMaster.Extra1 = string.Empty;
         infoMaterialReceiptMaster.Extra2 = string.Empty;
         infoMaterialReceiptMaster.ExtraDate = Convert.ToDateTime(DateTime.Now);
         decMaterialReceiptMasterIdentity = Convert.ToDecimal(bllMaterialReceiptMaster.MaterialReceiptMasterAdd(infoMaterialReceiptMaster));
         int inRowcount = dgvProduct.Rows.Count;
         for (int inI = 0; inI < inRowcount - 1; inI++)
         {
             infoMaterialReceiptDetails.MaterialReceiptMasterId = decMaterialReceiptMasterIdentity;
             if (dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty)
             {
                 infoProduct = BllProductCreation.ProductViewByCode(dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                 infoMaterialReceiptDetails.ProductId = infoProduct.ProductId;
             }
             if (dgvProduct.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value != null)
             {
                 infoMaterialReceiptDetails.OrderDetailsId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value.ToString());
             }
             else
                 infoMaterialReceiptDetails.OrderDetailsId = 0;
             if (dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString() != string.Empty)
             {
                 infoMaterialReceiptDetails.GodownId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString());
             }
             else
             {
                 infoMaterialReceiptDetails.GodownId = 1;
             }
             if (dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value != null && dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value.ToString() != string.Empty)
             {
                 infoMaterialReceiptDetails.RackId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value.ToString());
             }
             else
             {
                 infoMaterialReceiptDetails.RackId = 1;
             }
             if (dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
             {
                 infoMaterialReceiptDetails.BatchId = Convert.ToDecimal(Convert.ToString(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value));
             }
             else
             {
                 infoMaterialReceiptDetails.BatchId = 1;
             }
             if (dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString() != string.Empty)
             {
                 infoMaterialReceiptDetails.Qty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
             }
             if (dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString() != string.Empty)
             {
                 infoMaterialReceiptDetails.UnitId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
                 infoMaterialReceiptDetails.UnitConversionId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value.ToString());
             }
             infoMaterialReceiptDetails.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
             infoMaterialReceiptDetails.Amount = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
             infoMaterialReceiptDetails.Slno = Convert.ToInt32(dgvProduct.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
             infoMaterialReceiptDetails.Extra1 = string.Empty;
             infoMaterialReceiptDetails.Exta2 = string.Empty;
             infoMaterialReceiptDetails.ExtraDate = Convert.ToDateTime(DateTime.Now);
             bllMaterialReceiptMaster.MaterialReceiptDetailsAdd(infoMaterialReceiptDetails);
             //-----------------Stockposting---------------------------//
             StockPostingInfo infoStockPosting = new StockPostingInfo();
             infoStockPosting.Date = infoMaterialReceiptMaster.Date;
             infoStockPosting.ProductId = infoMaterialReceiptDetails.ProductId;
             infoStockPosting.BatchId = infoMaterialReceiptDetails.BatchId;
             infoStockPosting.UnitId = infoMaterialReceiptDetails.UnitId;
             infoStockPosting.GodownId = infoMaterialReceiptDetails.GodownId;
             infoStockPosting.RackId = infoMaterialReceiptDetails.RackId;
             if (cmbOrderNo.SelectedValue != null)
             {
                 if (dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value.ToString() != string.Empty)
                 {
                     infoStockPosting.VoucherNo = Convert.ToString(dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value.ToString());
                     infoStockPosting.AgainstVoucherNo = strVoucherNo;
                 }
                 else
                 {
                     infoStockPosting.VoucherNo = strVoucherNo;
                     infoStockPosting.AgainstVoucherNo = "NA";
                 }
                 if (dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value.ToString() != string.Empty)
                 {
                     infoStockPosting.InvoiceNo = Convert.ToString(dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value.ToString());
                     infoStockPosting.AgainstInvoiceNo = txtReceiptNo.Text;
                 }
                 else
                 {
                     infoStockPosting.InvoiceNo = txtReceiptNo.Text;
                     infoStockPosting.AgainstInvoiceNo = "NA";
                 }
                 if (dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value.ToString() != string.Empty)
                 {
                     infoStockPosting.VoucherTypeId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value.ToString());
                     infoStockPosting.AgainstVoucherTypeId = decMaterialReceiptVoucherTypeId;
                 }
                 else
                 {
                     infoStockPosting.VoucherTypeId = decMaterialReceiptVoucherTypeId;
                     infoStockPosting.AgainstVoucherTypeId = 0;
                 }
             }
             else
             {
                 infoStockPosting.InvoiceNo = txtReceiptNo.Text;
                 infoStockPosting.VoucherNo = strVoucherNo;
                 infoStockPosting.VoucherTypeId = decMaterialReceiptVoucherTypeId;
                 infoStockPosting.AgainstVoucherTypeId = 0;
                 infoStockPosting.AgainstVoucherNo = "NA";
                 infoStockPosting.AgainstInvoiceNo = "NA";
             }
             infoStockPosting.InwardQty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString()) / Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtConversionRate"].Value.ToString());
             infoStockPosting.OutwardQty = 0;
             infoStockPosting.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
             infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
             infoStockPosting.Extra1 = string.Empty;
             infoStockPosting.Extra2 = string.Empty;
             BllStockPosting.StockPostingAdd(infoStockPosting);
         }
         Messages.SavedMessage();
         if (cbxPrintAfterSave.Checked)
         {
             SettingsBll BllSettings = new SettingsBll();
             if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
             {
                 PrintForDotMatrix(decMaterialReceiptMasterIdentity);
             }
             else
             {
                 Print(decMaterialReceiptMasterIdentity, infoMaterialReceiptMaster.OrderMasterId);
             }
         }
         Clear();
     }
     catch (Exception ex)
     {
         MessageBox.Show("MR35:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Funtion to check remaining  quantity with refernce to purchaseinvoice and rejectionout
 /// </summary>
 /// <returns></returns>
 public int QuantityCheckWithReference()
 {
     decimal decQtyRejectionOutAndPurchaseInvoice = 0;
     decimal decQtyMaterialReceipt = 0;
     decimal inRef = 0;
     int inF1 = 1;
     decimal decMaterialReceiptDetailsId = 0;
     MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
     PurchaseInvoiceBll BllPurchaseInvoice = new PurchaseInvoiceBll();
     RejectionOutBll bllRejectionOut = new RejectionOutBll();
     try
     {
         foreach (DataGridViewRow dgvrow in dgvProduct.Rows)
         {
             if (dgvrow.Cells["dgvtxtmaterialReceiptDetailsId"].Value != null)
             {
                 if (dgvrow.Cells["dgvtxtmaterialReceiptDetailsId"].Value.ToString() != "0" || dgvrow.Cells["dgvtxtmaterialReceiptDetailsId"].Value.ToString() != string.Empty)
                 {
                     decMaterialReceiptDetailsId = Convert.ToDecimal(dgvrow.Cells["dgvtxtmaterialReceiptDetailsId"].Value.ToString());
                     inRef = bllMaterialReceiptMaster.MaterialReceiptDetailsReferenceCheck(decMaterialReceiptDetailsId);
                     if (inRef == 1)
                     {
                         if (inF1 == 1)
                         {
                             if (dgvrow.Cells["dgvtxtQty"].Value != null)
                             {
                                 if (dgvrow.Cells["dgvtxtQty"].Value.ToString() != "0" || dgvrow.Cells["dgvtxtQty"].Value.ToString() != string.Empty)
                                 {
                                     decQtyMaterialReceipt = Convert.ToDecimal(dgvrow.Cells["dgvtxtQty"].Value.ToString());
                                     decQtyRejectionOutAndPurchaseInvoice = Math.Round(bllMaterialReceiptMaster.MaterialReceiptQuantityDetailsAgainstPurcahseInvoiceAndRejectionOut(decMaterialReceiptDetailsId), PublicVariables._inNoOfDecimalPlaces);
                                     if (decQtyMaterialReceipt >= decQtyRejectionOutAndPurchaseInvoice)
                                     {
                                         inF1 = 1;
                                     }
                                     else
                                     {
                                         inF1 = 0;
                                         Messages.InformationMessage("Quantity in row " + (dgvrow.Index + 1) + " should be greater than " + decQtyRejectionOutAndPurchaseInvoice);
                                     }
                                 }
                                 else
                                 {
                                     inF1 = 0;
                                     Messages.InformationMessage("Quantity in row " + (dgvrow.Index + 1) + " should be greater than " + decQtyRejectionOutAndPurchaseInvoice);
                                 }
                             }
                             else
                             {
                                 inF1 = 0;
                                 Messages.InformationMessage("Quantity in row " + (dgvrow.Index + 1) + " should be greater than " + decQtyRejectionOutAndPurchaseInvoice);
                             }
                         }
                     }
                     else
                     {
                         inF1 = 1;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MR11:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     return inF1;
 }
 /// <summary>
 /// Function to remove material receipt details of removed row
 /// </summary>
 public void removeMaterialReceiptDetails()
 {
     MaterialReceiptBll bllMaterialReceiptMasterDetails = new MaterialReceiptBll();
     try
     {
         foreach (var strId in lstArrOfRemove)
         {
             decimal decDeleteId = Convert.ToDecimal(strId);
             bllMaterialReceiptMasterDetails.MaterialReceiptDetailsDelete(decDeleteId);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MR12: " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// function to fill the Grid based on the search mode
        /// </summary>
        public void GridFill()
        {
            List<DataTable> listObjVoucher = new List<DataTable>();
            MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
            try
            {

                if (dtpFromDate.Value <= dtpToDate.Value)
                {

                    if (txtVoucherNo.Text.Trim() == string.Empty)
                    {
                        strInvoiceNo = string.Empty;
                    }
                    else
                    {
                        strInvoiceNo = txtVoucherNo.Text;
                    }
                    if (cmbAccountLedger.SelectedIndex == 0 || cmbAccountLedger.SelectedIndex == -1)
                    {
                        decLedgerId = -1;
                    }
                    else
                    {
                        decLedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString());
                    }
                    if (cmbVoucherType.SelectedIndex == 0 || cmbVoucherType.SelectedIndex == -1)
                    {
                        decVoucherTypeId = -1;
                    }
                    else
                    {
                        decVoucherTypeId = Convert.ToDecimal(cmbVoucherType.SelectedValue.ToString());
                    }
                    if (cmbSalesMan.SelectedIndex == 0 || cmbSalesMan.SelectedIndex == -1)
                    {
                        decEmployeeId = -1;
                    }
                    else
                    {
                        decEmployeeId = Convert.ToDecimal(cmbSalesMan.SelectedValue.ToString());
                    }
                }
                else
                {
                    MessageBox.Show("From date should be less than to date", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                    DateTime FromDate = this.dtpFromDate.Value;
                    DateTime ToDate = this.dtpToDate.Value;
                    listObjVoucher = BllVoucherType.VoucherSearchFill(FromDate, ToDate, decVoucherTypeId, strInvoiceNo, decLedgerId, decEmployeeId);
                    dgvVoucherSearch.DataSource = listObjVoucher[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show("VS29:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Fill function for edit
 /// </summary>
 public void FillRejectionOutReportForEdit()
 {
     try
     {
         dgvProduct.Rows.Clear();
         isDoCellValueChange = false;
         isFromRegister = true;
         btnSave.Text = "Update";
         btnDelete.Enabled = true;
         txtRejectionOutNo.ReadOnly = true;
         infoRejectionOutMaster = bllRejectionOut.RejectionOutMasterView(decRejectionOutId);
         MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
         MaterialReceiptMasterInfo InfoMaterialReceiptMaster = new MaterialReceiptMasterInfo();
         VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
         InfoMaterialReceiptMaster = bllMaterialReceiptMaster.MaterialReceiptMasterView(infoRejectionOutMaster.MaterialReceiptMasterId);
         strRejectionOutVoucherNo = bllRejectionOut.GetRejectionOutVoucherNo(infoRejectionOutMaster.RejectionOutMasterId);
         txtRejectionOutNo.Text = infoRejectionOutMaster.InvoiceNo;
         strVoucherNo = infoRejectionOutMaster.VoucherNo.ToString();
         decRejectionOutSuffixPrefixId = Convert.ToDecimal(infoRejectionOutMaster.SuffixPrefixId);
         decRejectionOutVoucherTypeId = Convert.ToDecimal(infoRejectionOutMaster.VoucherTypeId);
         isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(decRejectionOutVoucherTypeId);
         infoVoucherType = BllVoucherType.VoucherTypeView(decRejectionOutVoucherTypeId);
         this.Text = infoVoucherType.VoucherTypeName;
         if (!isAutomatic)
         {
             txtRejectionOutNo.ReadOnly = false;
             txtRejectionOutNo.Focus();
         }
         else
         {
             txtRejectionOutNo.ReadOnly = true;
             txtDate.Focus();
         }
         decRejectionOutTypeId = decRejectionOutVoucherTypeId;
         txtDate.Text = infoRejectionOutMaster.Date.ToString("dd-MMM-yyyy");
         cmbCashOrParty.SelectedValue = infoRejectionOutMaster.LedgerId;
         cmbVoucherType.SelectedValue = InfoMaterialReceiptMaster.VoucherTypeId;
         cmbMaterialReceiptNo.SelectedValue = Convert.ToDecimal(infoRejectionOutMaster.MaterialReceiptMasterId.ToString());
         txtTransportationCompany.Text = infoRejectionOutMaster.TransportationCompany;
         txtNarration.Text = infoRejectionOutMaster.Narration;
         cmbCurrency.SelectedValue = infoRejectionOutMaster.ExchangeRateId;
         txtTotalAmount.Text = infoRejectionOutMaster.TotalAmount.ToString();
         txtLrNo.Text = infoRejectionOutMaster.LrNo.ToString();
         List<DataTable> listRejectionOut = bllRejectionOut.RejectionOutDetailsViewByRejectionOutMasterId(infoRejectionOutMaster.RejectionOutMasterId);
         for (int i = 0; i < listRejectionOut[0].Rows.Count; i++)
         {
             dgvProduct.Rows.Add();
             GodownComboFill();
             isAmountcalc = false;
             decRejectionOutDetailId = Convert.ToDecimal(listRejectionOut[0].Rows[i]["rejectionOutDetailsId"].ToString());
             dgvProduct.Rows[i].Cells["dgvtxtSlNo"].Value = listRejectionOut[0].Rows[i]["slno"].ToString();
             dgvProduct.Rows[i].Cells["dgvtxtProductId"].Value = listRejectionOut[0].Rows[i]["productId"].ToString();
             ProductDefaultValues(i, Convert.ToDecimal(listRejectionOut[0].Rows[i]["productId"].ToString()));
             BatchComboFill(Convert.ToDecimal(listRejectionOut[0].Rows[i]["productId"].ToString()), i, dgvProduct.Rows[i].Cells["dgvcmbBatch"].ColumnIndex);
             dgvProduct.Rows[i].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(listRejectionOut[0].Rows[i]["batchId"].ToString());
             dgvProduct.Rows[i].Cells["dgvtxtQty"].Value = listRejectionOut[0].Rows[i]["qty"].ToString();
             UnitComboFill(Convert.ToDecimal(listRejectionOut[0].Rows[i]["productId"].ToString()), i, dgvProduct.Rows[i].Cells["dgvcmbUnit"].ColumnIndex);
             isDoCellValueChange = true;
             isDoAfterGridFill = true;
             isValueChange = true;
             isAmountcalc = true;
             dgvProduct.Rows[i].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(listRejectionOut[0].Rows[i]["unitId"].ToString());
             isDoCellValueChange = false;
             isDoAfterGridFill = false;
             isValueChange = false;
             dgvProduct.Rows[i].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(listRejectionOut[0].Rows[i]["godownId"].ToString());
             RackComboFill(Convert.ToDecimal(listRejectionOut[0].Rows[i]["godownId"].ToString()), dgvProduct, i);
             dgvProduct.Rows[i].Cells["dgvcmbRack"].Value = Convert.ToDecimal(listRejectionOut[0].Rows[i]["rackId"].ToString());
             dgvProduct.Rows[i].Cells["dgvtxtBarcode"].Value = listRejectionOut[0].Rows[i]["barcode"].ToString();
             dgvProduct.Rows[i].Cells["dgvtxtRejectionOutDetailsId"].Value = decRejectionOutDetailId;
             dgvProduct.Rows[i].Cells["dgvtxtRate"].Value = listRejectionOut[0].Rows[i]["rate"].ToString();
             dgvProduct.Rows[i].Cells["dgvtxtAmount"].Value = listRejectionOut[0].Rows[i]["amount"].ToString();
             dgvProduct.Rows[i].Cells["dgvtxtunitConversionId"].Value = listRejectionOut[0].Rows[i]["UnitConversionId"].ToString();
             dgvProduct.Rows[i].Cells["dgvtxtconversionRate"].Value = listRejectionOut[0].Rows[i]["conversionRate"].ToString();
             dgvProduct.Rows[i].Cells["dgvtxtmaterialReceiptDetailsId"].Value = listRejectionOut[0].Rows[i]["materialReceiptDetailsId"].ToString();
         }
         TotalAmount();
         isAmountcalc = true;
         isDoAfterGridFill = true;
         isFromRegister = false;
         isDoCellValueChange = true;
         isValueChange = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show("RO36:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to delete material receipt
 /// </summary>
 public void Delete()
 {
     MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
     //StockPostingSP spstockposting = new StockPostingSP();
     StockPostingBll BllStockPosting = new StockPostingBll();
     try
     {
         decimal decResult1 = 0;
         decimal decReference = bllMaterialReceiptMaster.MaterialReceiptMasterReferenceCheck(decMaterialReceiptMasterId);
         if (decReference == 1)
         {
             decResult1 = bllMaterialReceiptMaster.MaterialReceiptDelete(decMaterialReceiptMasterId);
             if (decResult1 > 0)
             {
                 if (Convert.ToDecimal(dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtvouchertypeId"].Value) == 0)
                 {
                     decimal decResult3 = BllStockPosting.StockPostingDeleteByagainstVoucherTypeIdAndagainstVoucherNoAndVoucherNoAndVoucherType(0, "NA", strVoucherNo, decMaterialReceiptVoucherTypeId);
                 }
                 else
                 {
                     decimal decResult3 = BllStockPosting.StockPostingDeleteByagainstVoucherTypeIdAndagainstVoucherNoAndVoucherNoAndVoucherType(decMaterialReceiptVoucherTypeId, strVoucherNo, strAgainstVoucherNo, decAgainstVoucherTypeId);
                 }
                 Messages.DeletedMessage();
                 if (frmMaterialReceiptRegisterObj != null)
                 {
                     this.Close();
                     frmMaterialReceiptRegisterObj.GridFill();
                 }
                 if (frmMaterialReceiptReportObj != null)
                 {
                     this.Close();
                     frmMaterialReceiptReportObj.GridFill();
                 }
                 if (objVoucherSearch != null)
                 {
                     this.Close();
                     objVoucherSearch.GridFill();
                 }
                 if (frmDayBookObj != null)
                 {
                     this.Close();
                     frmDayBookObj.dayBookGridFill();
                 }
             }
         }
         else
         {
             Messages.ReferenceExistsMessage();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MR50:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Function to fill the fields for edit or delete
        /// </summary>
        public void FillRegisterOrReport()
        {
            MaterialReceiptMasterInfo infoMaterialReceiptMaster = new MaterialReceiptMasterInfo();
            MaterialReceiptDetailsInfo infoMaterialReceiptDetails = new MaterialReceiptDetailsInfo();
            VoucherTypeBll BllVoucherType = new VoucherTypeBll();
            MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
            MaterialReceiptBll bllMaterialReceiptDetails = new MaterialReceiptBll();
            PurchaseOrderBll BllPurchaseOrder = new PurchaseOrderBll();
            try
            {

                PurchaseOrderMasterInfo infoPurchaseOrder = new PurchaseOrderMasterInfo();
                decimal decTotal = 0;
                decimal decStatus = bllMaterialReceiptMaster.MaterialReceiptMasterReferenceCheck(decMaterialReceiptMasterId);
                if (decStatus == 0)
                {
                    cmbCashOrParty.Enabled = false;
                    cmbOrderNo.Enabled = false;
                    cmbcurrency.Enabled = false;
                    txtDate.Enabled = false;
                    cmbVoucherType.Enabled = false;
                }
                btnSave.Text = "Update";
                btnDelete.Enabled = true;
                txtReceiptNo.ReadOnly = true;
                infoMaterialReceiptMaster = bllMaterialReceiptMaster.MaterialReceiptMasterView(decMaterialReceiptMasterId);
                txtReceiptNo.Text = infoMaterialReceiptMaster.InvoiceNo;
                strVoucherNo = infoMaterialReceiptMaster.VoucherNo.ToString();
                decMaterialReceiptSuffixPrefixId = Convert.ToDecimal(infoMaterialReceiptMaster.SuffixPrefixId);
                decMaterialReceiptVoucherTypeId = Convert.ToDecimal(infoMaterialReceiptMaster.VoucherTypeId);
                isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(decMaterialReceiptVoucherTypeId);
                decMaterialReceiptTypeId = decMaterialReceiptVoucherTypeId;
                txtDate.Text = infoMaterialReceiptMaster.Date.ToString("dd-MMM-yyyy");
                cmbCashOrParty.SelectedValue = infoMaterialReceiptMaster.LedgerId;
                if (infoMaterialReceiptMaster.OrderMasterId != 0)
                {
                    infoPurchaseOrder = BllPurchaseOrder.PurchaseOrderMasterView(Convert.ToDecimal(infoMaterialReceiptMaster.OrderMasterId.ToString()));
                    decPurchaseOrderVoucherTypeId = infoPurchaseOrder.VoucherTypeId;
                    cmbVoucherType.SelectedValue = decPurchaseOrderVoucherTypeId;
                    cmbOrderNo.SelectedValue = infoMaterialReceiptMaster.OrderMasterId.ToString();
                    decOrderNoWhileEditMode = infoMaterialReceiptMaster.OrderMasterId;
                }
                else
                {
                    cmbVoucherType.SelectedValue = 0;
                }
                txtTransportation.Text = infoMaterialReceiptMaster.TransportationCompany;
                txtNarration.Text = infoMaterialReceiptMaster.Narration;
                txtLRNo.Text = infoMaterialReceiptMaster.LrNo;
                CurrencyComboFill();
                cmbcurrency.SelectedValue = infoMaterialReceiptMaster.exchangeRateId;
                decTotal = Convert.ToDecimal(infoMaterialReceiptMaster.TotalAmount.ToString());
                decTotal = Math.Round(decTotal, PublicVariables._inNoOfDecimalPlaces);
                txtTotal.Text = Convert.ToString(decTotal);
                List<DataTable> ListObj = new List<DataTable>();
                ListObj = bllMaterialReceiptDetails.MaterialReceiptDetailsViewByMasterId(decMaterialReceiptMasterId);
                dgvProduct.Rows.Clear();
                for (int i = 0; i < ListObj[0].Rows.Count; i++)
                {
                    isAmountcalc = false;
                    isValueChange = false;
                    dgvProduct.Rows.Add();
                    dgvProduct.Rows[i].Cells["dgvtxtMaterialReceiptdetailsId"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["materialReceiptDetailsId"].ToString());
                    decMaterialReceiptDetailId = Convert.ToDecimal(ListObj[0].Rows[i]["materialReceiptDetailsId"].ToString());
                    dgvProduct.Rows[i].Cells["dgvtxtSlNo"].Value = ListObj[0].Rows[i]["slno"].ToString();
                    dgvProduct.Rows[i].Cells["dgvtxtProductCode"].Value = ListObj[0].Rows[i]["productCode"].ToString();
                    dgvProduct.Rows[i].Cells["dgvtxtProductName"].Value = ListObj[0].Rows[i]["productName"].ToString();
                    dgvProduct.Rows[i].Cells["dgvtxtQty"].Value = ListObj[0].Rows[i]["qty"].ToString();
                    dgvProduct.Rows[i].Cells["productId"].Value = ListObj[0].Rows[i]["productId"].ToString();
                    decimal decProductId = Convert.ToDecimal(ListObj[0].Rows[i]["productId"].ToString());
                    UnitComboFill(decProductId, i, dgvProduct.Rows[i].Cells["dgvcmbUnit"].ColumnIndex);
                    dgvProduct.Rows[i].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["unitId"].ToString());
                    DGVGodownComboFill();
                    dgvProduct.Rows[i].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["godownId"].ToString());
                    decGodownId = Convert.ToDecimal(dgvProduct.Rows[i].Cells["dgvcmbGodown"].Value);
                    RackComboFill(decGodownId, i, dgvProduct.Rows[i].Cells["dgvCmbRack"].ColumnIndex);
                    if (Convert.ToDecimal(ListObj[0].Rows[i]["orderDetailsId"].ToString()) == 0)
                    {
                        dgvProduct.Rows[i].Cells["dgvtxtPurchaseOrderDetailsId"].Value = 0;
                    }
                    else
                    {
                        dgvProduct.Rows[i].Cells["dgvtxtPurchaseOrderDetailsId"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["orderDetailsId"].ToString());

                    }
                    dgvProduct.Rows[i].Cells["dgvCmbRack"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["rackId"].ToString());
                    BatchComboFill(decProductId, i, Convert.ToInt32(dgvProduct.Rows[i].Cells["dgvcmbBatch"].ColumnIndex));
                    dgvProduct.Rows[i].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["batchId"].ToString());
                    dgvProduct.Rows[i].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["unitConversionId"].ToString());
                    dgvProduct.Rows[i].Cells["dgvtxtBarcode"].Value = ListObj[0].Rows[i]["barcode"].ToString();
                    dgvProduct.Rows[i].Cells["dgvtxtRate"].Value = ListObj[0].Rows[i]["rate"].ToString();
                    dgvProduct.Rows[i].Cells["dgvtxtAmount"].Value = ListObj[0].Rows[i]["amount"].ToString();
                    dgvProduct.Rows[i].Cells["dgvtxtvouchertypeId"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["voucherTypeId"].ToString());
                    dgvProduct.Rows[i].Cells["dgvtxtvoucherNo"].Value = ListObj[0].Rows[i]["voucherNo"].ToString();
                    dgvProduct.Rows[i].Cells["dgvtxtinvoiceNo"].Value = ListObj[0].Rows[i]["invoiceNo"].ToString();
                    decAgainstVoucherTypeId = Convert.ToDecimal(dgvProduct.Rows[i].Cells["dgvtxtvouchertypeId"].Value.ToString());
                    strAgainstVoucherNo = dgvProduct.Rows[i].Cells["dgvtxtvoucherNo"].Value.ToString();
                    UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                    List<DataTable> listObjUnitByProduct = new List<DataTable>();
                    listObjUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(decProductId.ToString());
                    foreach (DataRow drUnitByProduct in listObjUnitByProduct[0].Rows)
                    {
                        if (dgvProduct.Rows[i].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                        {
                            dgvProduct.Rows[i].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                            dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                        }
                    }
                    decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[i].Cells["dgvtxtRate"].Value.ToString());
                    decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value.ToString());
                    decimal decReference = bllMaterialReceiptMaster.MaterialReceiptDetailsReferenceCheck(decMaterialReceiptDetailId);
                    if (decReference == 1 || Convert.ToDecimal(dgvProduct.Rows[i].Cells["dgvtxtPurchaseOrderDetailsId"].Value.ToString())!=0)
                    {
                        dgvProduct.Rows[i].Cells["dgvtxtProductCode"].ReadOnly = true;
                        dgvProduct.Rows[i].Cells["dgvtxtProductName"].ReadOnly = true;
                        dgvProduct.Rows[i].Cells["dgvcmbUnit"].ReadOnly = true;
                        dgvProduct.Rows[i].Cells["dgvtxtBarcode"].ReadOnly = true;
                        dgvProduct.Rows[i].Cells["dgvCmbRack"].ReadOnly = true;
                        dgvProduct.Rows[i].Cells["dgvcmbGodown"].ReadOnly = true;
                        dgvProduct.Rows[i].Cells["dgvtxtRate"].ReadOnly = true;
                        dgvProduct.Rows[i].Cells["dgvcmbBatch"].ReadOnly = true;
                    }
                    if (cmbVoucherType.Text != "NA")
                    {
                        dgvProduct.Rows[i].Cells["dgvcmbUnit"].ReadOnly = true;
                    }

                }
                isAmountcalc = true;
                isValueChange = true;
                isDoAfterGridFill = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("MR16:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to fill the grid based on the search condition
 /// </summary>
 public void GridFill()
 {
     try
     {
         List<DataTable> Listobj = new List<DataTable>();
         MaterialReceiptBll spMaterialReceiptMaster = new MaterialReceiptBll();
         if (cmbOrderNo.SelectedIndex == 0 || cmbOrderNo.SelectedIndex == -1)
         {
             decOrderId = -1;
         }
         else
         {
             decOrderId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
         }
         if (txtVoucherNo.Text.Trim() == string.Empty)
         {
             strInvoiceNo = string.Empty;
         }
         else
         {
             strInvoiceNo = txtVoucherNo.Text;
         }
         if (cmbCashOrParty.SelectedIndex == 0 || cmbCashOrParty.SelectedIndex == -1)
         {
             decLedgerId = -1;
         }
         else
         {
             decLedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         }
         if (cmbVoucherType.SelectedIndex == 0 || cmbVoucherType.SelectedIndex == -1)
         {
             decVoucherTypeId = -1;
         }
         else
         {
             decVoucherTypeId = Convert.ToDecimal(cmbVoucherType.SelectedValue.ToString());
         }
         if (txtProductCode.Text.Trim() == string.Empty)
         {
             strproductCode = string.Empty;
         }
         else
         {
             strproductCode = txtProductCode.Text;
         }
         if (cmbStatus.SelectedIndex == 0 || cmbStatus.SelectedIndex == -1)
         {
             strStatus = "All";
         }
         else
         {
             strStatus = cmbStatus.SelectedItem.ToString();
         }
         DateTime FromDate = this.dtpFromDate.Value;
         DateTime ToDate = this.dtpToDate.Value;
         Listobj = spMaterialReceiptMaster.MaterialReceiptReportViewAll(decOrderId, strInvoiceNo, decLedgerId, decVoucherTypeId, strproductCode, FromDate, ToDate, strStatus);
         dgvMaterialReceiptReport.DataSource = Listobj[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("MRR5:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 ///  Function to fill OrderNo combobox
 /// </summary>
 /// <param name="decLedger"></param>
 public void OrderNoComboFill(decimal decLedger)
 {
     try
     {
         List<DataTable> ListObj = new List<DataTable>();
         MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
         ListObj = bllMaterialReceiptMaster.GetOrderNoCorrespondingtoLedgerForMaterialReceiptRpt(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()));
         DataRow drow = ListObj[0].NewRow();
         drow["invoiceNo"] = "All";
         drow["purchaseOrderMasterId"] = -1;
         dtbl.Rows.InsertAt(drow, 0);
         if (dtbl != null)
         {
             cmbOrderNo.DataSource = ListObj[0];
             cmbOrderNo.DisplayMember = "invoiceNo";
             cmbOrderNo.ValueMember = "purchaseOrderMasterId";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MRR4:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to save purchase invoice
 /// </summary>
 public void Save()
 {
     decimal decPurchaseMasterId = 0;
     PurchaseMasterInfo infoPurchaseMaster = new PurchaseMasterInfo();
     PurchaseInvoiceBll BllPurchaseInvoice = new PurchaseInvoiceBll();
     PurchaseDetailsInfo infoPurchaseDetails = new PurchaseDetailsInfo();
     MaterialReceiptMasterInfo infoMaterialReceiptMaster = new MaterialReceiptMasterInfo();
     MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
     PurchaseOrderMasterInfo infoPurchaseOrderMaster = new PurchaseOrderMasterInfo();
     PurchaseOrderBll BllPurchaseOrder = new PurchaseOrderBll();
     StockPostingInfo infoStockPosting = new StockPostingInfo();
     StockPostingBll BllStockPosting = new StockPostingBll();
     //StockPostingSP spStockPosting = new StockPostingSP();
     LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
     LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
     PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
     //PartyBalanceSP spPartyBalance = new PartyBalanceSP();
     PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
     AdditionalCostInfo infoAdditionalCost = new AdditionalCostInfo();
     AditionalCostBll bllAdditionalCost = new AditionalCostBll();
     PurchaseBillTaxInfo infoPurchaseBillTax = new PurchaseBillTaxInfo();
     AccountLedgerInfo infoAccountLedger = new AccountLedgerInfo();
     AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
     UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
     ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
     try
     {
         /*-----------------------------------------Purchase Master Add----------------------------------------------------*/
         infoPurchaseMaster.AdditionalCost = Convert.ToDecimal(lblAdditionalCostAmount.Text);
         infoPurchaseMaster.BillDiscount = Convert.ToDecimal(txtBillDiscount.Text);
         infoPurchaseMaster.CreditPeriod = txtCreditPeriod.Text;
         infoPurchaseMaster.Date = Convert.ToDateTime(txtVoucherDate.Text);
         infoPurchaseMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
         infoPurchaseMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         infoPurchaseMaster.GrandTotal = Convert.ToDecimal(txtGrandTotal.Text);
         infoPurchaseMaster.InvoiceNo = txtVoucherNo.Text.Trim();
         if (isAutomatic)
         {
             infoPurchaseMaster.SuffixPrefixId = decPurchaseInvoiceSuffixPrefixId;
             infoPurchaseMaster.VoucherNo = strVoucherNo;
         }
         else
         {
             infoPurchaseMaster.SuffixPrefixId = 0;
             infoPurchaseMaster.VoucherNo = strVoucherNo;
         }
         infoPurchaseMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         infoPurchaseMaster.LrNo = txtLRNo.Text;
         if (cmbPurchaseMode.Text == "Against MaterialReceipt")
         {
             infoPurchaseMaster.MaterialReceiptMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
         }
         else
         {
             infoPurchaseMaster.MaterialReceiptMasterId = 0;
         }
         infoPurchaseMaster.Narration = txtNarration.Text;
         infoPurchaseMaster.PurchaseAccount = Convert.ToDecimal(cmbPurchaseAccount.SelectedValue.ToString());
         if (cmbPurchaseMode.Text == "Against PurchaseOrder")
         {
             infoPurchaseMaster.PurchaseOrderMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
         }
         else
         {
             infoPurchaseMaster.PurchaseOrderMasterId = 0;
         }
         infoPurchaseMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
         infoPurchaseMaster.TotalTax = Convert.ToDecimal(lblTaxAmount.Text);
         infoPurchaseMaster.TransportationCompany = txtTransportationCompany.Text;
         infoPurchaseMaster.UserId = PublicVariables._decCurrentUserId;
         infoPurchaseMaster.VendorInvoiceDate = Convert.ToDateTime(txtInvoiceDate.Text);
         infoPurchaseMaster.VendorInvoiceNo = txtVendorInvoiceNo.Text;
         infoPurchaseMaster.VoucherTypeId = decPurchaseInvoiceVoucherTypeId;
         infoPurchaseMaster.Extra1 = string.Empty;
         infoPurchaseMaster.Extra2 = string.Empty;
         infoPurchaseMaster.ExtraDate = Convert.ToDateTime(DateTime.Now);
         decPurchaseMasterId = BllPurchaseInvoice.PurchaseMasterAdd(infoPurchaseMaster);
         infoPurchaseOrderMaster = BllPurchaseOrder.PurchaseOrderMasterView(infoPurchaseMaster.PurchaseOrderMasterId);
         infoMaterialReceiptMaster = bllMaterialReceiptMaster.MaterialReceiptMasterView(infoPurchaseMaster.MaterialReceiptMasterId);
         foreach (DataGridViewRow dgvrow in dgvProductDetails.Rows)
         {
             if (dgvrow.Cells["dgvtxtProductId"].Value != null)
             {
                 if (dgvrow.Cells["dgvtxtProductId"].Value.ToString() != string.Empty)
                 {
                     /*-----------------------------------------Purchase Details Add----------------------------------------------------*/
                     infoPurchaseDetails.Amount = Convert.ToDecimal(dgvrow.Cells["dgvtxtAmount"].Value.ToString());
                     infoPurchaseDetails.BatchId = Convert.ToDecimal(dgvrow.Cells["dgvcmbBatch"].Value.ToString());
                     infoPurchaseDetails.Discount = Convert.ToDecimal(dgvrow.Cells["dgvtxtDiscount"].Value.ToString());
                     infoPurchaseDetails.GodownId = Convert.ToDecimal(dgvrow.Cells["dgvcmbGodown"].Value.ToString());
                     infoPurchaseDetails.GrossAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtGrossValue"].Value.ToString());
                     infoPurchaseDetails.NetAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtNetValue"].Value.ToString());
                     infoPurchaseDetails.OrderDetailsId = Convert.ToDecimal(dgvrow.Cells["dgvtxtPurchaseOrderDetailsId"].Value.ToString());
                     infoPurchaseDetails.ProductId = Convert.ToDecimal(dgvrow.Cells["dgvtxtProductId"].Value.ToString());
                     infoPurchaseDetails.PurchaseMasterId = decPurchaseMasterId;
                     infoPurchaseDetails.Qty = Convert.ToDecimal(dgvrow.Cells["dgvtxtQuantity"].Value.ToString());
                     infoPurchaseDetails.RackId = Convert.ToDecimal(dgvrow.Cells["dgvcmbRack"].Value.ToString());
                     infoPurchaseDetails.Rate = Convert.ToDecimal(dgvrow.Cells["dgvtxtRate"].Value.ToString());
                     infoPurchaseDetails.ReceiptDetailsId = Convert.ToDecimal(dgvrow.Cells["dgvtxtMaterialReceiptDetailsId"].Value.ToString());
                     infoPurchaseDetails.SlNo = Convert.ToInt32(dgvrow.Cells["dgvtxtSlNo"].Value.ToString());
                     infoPurchaseDetails.TaxAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtTaxAmount"].Value.ToString());
                     infoPurchaseDetails.TaxId = Convert.ToDecimal(dgvrow.Cells["dgvcmbTax"].Value.ToString());
                     infoPurchaseDetails.UnitConversionId = Convert.ToDecimal(dgvrow.Cells["dgvtxtUnitConversionId"].Value.ToString());
                     infoPurchaseDetails.UnitId = Convert.ToDecimal(dgvrow.Cells["dgvcmbUnit"].Value.ToString());
                     infoPurchaseDetails.Extra1 = string.Empty;
                     infoPurchaseDetails.Extra2 = string.Empty;
                     infoPurchaseDetails.ExtraDate = Convert.ToDateTime(DateTime.Today);
                     BllPurchaseInvoice.PurchaseDetailsAdd(infoPurchaseDetails);
                     /*-----------------------------------------Stock Posting----------------------------------------------------*/
                     infoStockPosting.BatchId = infoPurchaseDetails.BatchId;
                     infoStockPosting.Date = infoPurchaseMaster.Date;
                     infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                     infoStockPosting.GodownId = infoPurchaseDetails.GodownId;
                     infoStockPosting.InwardQty = infoPurchaseDetails.Qty; /// spUnitConvertion.UnitConversionRateByUnitConversionId(infoPurchaseDetails.UnitConversionId);
                     infoStockPosting.OutwardQty = 0;
                     infoStockPosting.ProductId = infoPurchaseDetails.ProductId;
                     infoStockPosting.RackId = infoPurchaseDetails.RackId;
                     infoStockPosting.Rate = infoPurchaseDetails.Rate;
                     infoStockPosting.UnitId = infoPurchaseDetails.UnitId;
                     if (infoPurchaseDetails.OrderDetailsId != 0)
                     {
                         infoStockPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
                         infoStockPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
                         infoStockPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                         infoStockPosting.AgainstInvoiceNo = "NA";
                         infoStockPosting.AgainstVoucherNo = "NA";
                         infoStockPosting.AgainstVoucherTypeId = 0;
                     }
                     else if (infoPurchaseDetails.ReceiptDetailsId != 0)
                     {
                         infoStockPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
                         infoStockPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
                         infoStockPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                         infoStockPosting.AgainstInvoiceNo = "NA";
                         infoStockPosting.AgainstVoucherNo = "NA";
                         infoStockPosting.AgainstVoucherTypeId = 0;
                     }
                     else if (infoPurchaseDetails.OrderDetailsId == 0 && infoPurchaseDetails.ReceiptDetailsId == 0)
                     {
                         infoStockPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
                         infoStockPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
                         infoStockPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                         infoStockPosting.AgainstInvoiceNo = "NA";
                         infoStockPosting.AgainstVoucherNo = "NA";
                         infoStockPosting.AgainstVoucherTypeId = 0;
                     }
                     infoStockPosting.Extra1 = string.Empty;
                     infoStockPosting.Extra2 = string.Empty;
                     infoStockPosting.ExtraDate = Convert.ToDateTime(DateTime.Today);
                     BllStockPosting.StockPostingAdd(infoStockPosting);
                     if (infoPurchaseDetails.ReceiptDetailsId != 0)
                     {
                         infoStockPosting.InvoiceNo = infoMaterialReceiptMaster.InvoiceNo;
                         infoStockPosting.VoucherNo = infoMaterialReceiptMaster.VoucherNo;
                         infoStockPosting.VoucherTypeId = infoMaterialReceiptMaster.VoucherTypeId;
                         infoStockPosting.AgainstInvoiceNo = infoPurchaseMaster.InvoiceNo;
                         infoStockPosting.AgainstVoucherNo = infoPurchaseMaster.VoucherNo;
                         infoStockPosting.AgainstVoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                         infoStockPosting.InwardQty = 0;
                         infoStockPosting.OutwardQty = infoPurchaseDetails.Qty;/// spUnitConvertion.UnitConversionRateByUnitConversionId(infoPurchaseDetails.UnitConversionId);
                         BllStockPosting.StockPostingAdd(infoStockPosting);
                     }
                 }
             }
         }
         /*-----------------------------------------Ledger Posting----------------------------------------------------*/
         infoLedgerPosting.Credit = Convert.ToDecimal(txtGrandTotal.Text) * BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
         infoLedgerPosting.Debit = 0;
         infoLedgerPosting.Date = Convert.ToDateTime(PublicVariables._dtCurrentDate);
         infoLedgerPosting.DetailsId = 0;
         infoLedgerPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
         infoLedgerPosting.LedgerId = infoPurchaseMaster.LedgerId;
         infoLedgerPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
         infoLedgerPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
         infoLedgerPosting.ChequeDate = DateTime.Now;
         infoLedgerPosting.ChequeNo = string.Empty;
         infoLedgerPosting.Extra1 = string.Empty;
         infoLedgerPosting.Extra2 = string.Empty;
         infoLedgerPosting.ExtraDate = DateTime.Now;
         BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
         decimal decBilldiscount = Convert.ToDecimal(txtBillDiscount.Text.ToString());
         if (decBilldiscount > 0)
         {
             infoLedgerPosting.Credit = decBilldiscount * BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
             infoLedgerPosting.Debit = 0;
             infoLedgerPosting.Date = Convert.ToDateTime(PublicVariables._dtCurrentDate);
             infoLedgerPosting.DetailsId = 0;
             infoLedgerPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
             infoLedgerPosting.LedgerId = 9;//ledger id of discount received
             infoLedgerPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
             infoLedgerPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
             infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
             infoLedgerPosting.ChequeDate = DateTime.Now;
             infoLedgerPosting.ChequeNo = string.Empty;
             infoLedgerPosting.Extra1 = string.Empty;
             infoLedgerPosting.Extra2 = string.Empty;
             infoLedgerPosting.ExtraDate = DateTime.Now;
             BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
         }
         infoLedgerPosting.Credit = 0;
         infoLedgerPosting.Debit = TotalNetAmount(); //* spExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
         infoLedgerPosting.Date = Convert.ToDateTime(PublicVariables._dtCurrentDate);
         infoLedgerPosting.DetailsId = 0;
         infoLedgerPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
         infoLedgerPosting.LedgerId = infoPurchaseMaster.PurchaseAccount;//ledger posting of purchase account
         infoLedgerPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
         infoLedgerPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
         infoLedgerPosting.ChequeDate = DateTime.Now;
         infoLedgerPosting.ChequeNo = string.Empty;
         infoLedgerPosting.Extra1 = string.Empty;
         infoLedgerPosting.Extra2 = string.Empty;
         infoLedgerPosting.ExtraDate = DateTime.Now;
         BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
         foreach (DataGridViewRow dgvrow in dgvAdditionalCost.Rows)
         {
             if (dgvrow.Cells["dgvcmbLedger"].Value != null)
             {
                 if (dgvrow.Cells["dgvcmbLedger"].Value.ToString() != string.Empty)
                 {
                     if (dgvrow.Cells["dgvtxtAdditionalCostAmount"].Value != null)
                     {
                         if (dgvrow.Cells["dgvtxtAdditionalCostAmount"].Value.ToString() != string.Empty)
                         {
                             /*-----------------------------------------Additional Cost Add----------------------------------------------------*/
                             infoAdditionalCost.Credit = 0;
                             infoAdditionalCost.Debit = Convert.ToDecimal(dgvrow.Cells["dgvtxtAdditionalCostAmount"].Value.ToString());
                             infoAdditionalCost.LedgerId = Convert.ToDecimal(dgvrow.Cells["dgvcmbLedger"].Value.ToString());
                             infoAdditionalCost.VoucherNo = infoPurchaseMaster.VoucherNo;
                             infoAdditionalCost.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                             infoAdditionalCost.Extra1 = string.Empty;
                             infoAdditionalCost.Extra2 = string.Empty;
                             infoAdditionalCost.ExtraDate = DateTime.Now;
                             bllAdditionalCost.AdditionalCostAdd(infoAdditionalCost);
                             /*-----------------------------------------Additional Cost Ledger Posting----------------------------------------------------*/
                             infoLedgerPosting.Credit = 0;
                             infoLedgerPosting.Debit = infoAdditionalCost.Debit * BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                             infoLedgerPosting.Date = Convert.ToDateTime(PublicVariables._dtCurrentDate);
                             infoLedgerPosting.DetailsId = 0;
                             infoLedgerPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
                             infoLedgerPosting.LedgerId = infoAdditionalCost.LedgerId;
                             infoLedgerPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
                             infoLedgerPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                             infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                             infoLedgerPosting.ChequeDate = DateTime.Now;
                             infoLedgerPosting.ChequeNo = string.Empty;
                             infoLedgerPosting.Extra1 = string.Empty;
                             infoLedgerPosting.Extra2 = string.Empty;
                             infoLedgerPosting.ExtraDate = DateTime.Now;
                             BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                         }
                     }
                 }
             }
         }
         if (dgvTax.Visible)
         {
             foreach (DataGridViewRow dgvrow in dgvTax.Rows)
             {
                 if (dgvrow.Cells["dgvtxtTaxId"].Value != null)
                 {
                     if (dgvrow.Cells["dgvtxtTaxId"].Value.ToString() != string.Empty)
                     {
                         /*-----------------------------------------PurchaseBillTax Add----------------------------------------------------*/
                         infoPurchaseBillTax.PurchaseMasterId = decPurchaseMasterId;
                         infoPurchaseBillTax.TaxAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtTotalTax"].Value.ToString());
                         infoPurchaseBillTax.TaxId = Convert.ToDecimal(dgvrow.Cells["dgvtxtTaxId"].Value.ToString());
                         infoPurchaseBillTax.Extra1 = string.Empty;
                         infoPurchaseBillTax.Extra2 = string.Empty;
                         infoPurchaseBillTax.ExtraDate = DateTime.Now;
                         BllPurchaseInvoice.PurchaseBillTaxAdd(infoPurchaseBillTax);
                         /*-----------------------------------------Tax Ledger Posting----------------------------------------------------*/
                         infoLedgerPosting.Credit = 0;
                         infoLedgerPosting.Debit = infoPurchaseBillTax.TaxAmount * BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                         infoLedgerPosting.Date = Convert.ToDateTime(PublicVariables._dtCurrentDate);
                         infoLedgerPosting.DetailsId = 0;
                         infoLedgerPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
                         infoLedgerPosting.LedgerId = Convert.ToDecimal(dgvrow.Cells["dgvtxtLedgerId"].Value.ToString());
                         infoLedgerPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
                         infoLedgerPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                         infoLedgerPosting.ChequeDate = DateTime.Now;
                         infoLedgerPosting.ChequeNo = string.Empty;
                         infoLedgerPosting.Extra1 = string.Empty;
                         infoLedgerPosting.Extra2 = string.Empty;
                         infoLedgerPosting.ExtraDate = DateTime.Now;
                         BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                     }
                 }
             }
         }
         /*-----------------------------------------PartyBalance Posting----------------------------------------------------*/
         infoAccountLedger = bllAccountLedger.AccountLedgerView(infoPurchaseMaster.LedgerId);
         if (infoAccountLedger.BillByBill == true)
         {
             infoPartyBalance.Credit = Convert.ToDecimal(txtGrandTotal.Text);
             infoPartyBalance.Debit = 0;
             if (txtCreditPeriod.Text != string.Empty)
             {
                 infoPartyBalance.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
             }
             infoPartyBalance.Date = Convert.ToDateTime(txtVoucherDate.Text);
             infoPartyBalance.ExchangeRateId = infoPurchaseMaster.ExchangeRateId;
             infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
             infoPartyBalance.LedgerId = infoPurchaseMaster.LedgerId;
             infoPartyBalance.ReferenceType = "NEW";
             infoPartyBalance.InvoiceNo = infoPurchaseMaster.InvoiceNo;
             infoPartyBalance.VoucherNo = infoPurchaseMaster.VoucherNo;
             infoPartyBalance.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
             infoPartyBalance.AgainstInvoiceNo = "NA";
             infoPartyBalance.AgainstVoucherNo = "NA";
             infoPartyBalance.AgainstVoucherTypeId = 0;
             infoPartyBalance.Extra1 = string.Empty;
             infoPartyBalance.Extra2 = string.Empty;
             infoPartyBalance.ExtraDate = DateTime.Now;
             BllPartyBalance.PartyBalanceAdd(infoPartyBalance);
         }
         Messages.SavedMessage();
         if (cbxPrintAfterSave.Checked)
         {
             if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
             {
                 PrintForDotMatrix(decPurchaseMasterId);
             }
             else
             {
                 Print(decPurchaseMasterId);
             }
         }
         Clear();
     }
     catch (Exception ex)
     {
         MessageBox.Show("PI38:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// On leave from each cell of dgvProductDetails
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvProductDetails_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            string strBarcode = string.Empty;
            decimal decDiscountPercent = 0;
            decimal decDiscount = 0;
            decimal decGrossValue = 0;
            try
            {
                BatchBll BllBatch = new BatchBll();
                if (e.ColumnIndex > -1 && e.RowIndex > -1)
                {
                    if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value != null)
                    {
                        if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString() != string.Empty && dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString() != "0")
                        {
                            if (e.ColumnIndex == dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtQuantity"].ColumnIndex)
                            {
                                if (dgvProductDetails.RowCount > 1)
                                {
                                    try
                                    {
                                        MaterialReceiptBll bllMaterialReceiptDetails = new MaterialReceiptBll();
                                        decimal decMaterialReceiptMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
                                        List<DataTable> ListObj = new List<DataTable>();
                                        ListObj = bllMaterialReceiptDetails.MaterialReceiptDetailsViewByMaterialReceiptMasterIdWithRemainingByNotInCurrPI
                                        (decMaterialReceiptMasterId, decPurchaseMasterId, decPurchaseInvoiceVoucherTypeId);
                                        if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtMaterialReceiptDetailsId"].Value != null)
                                        {
                                            if (decimal.Parse(dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtMaterialReceiptDetailsId"].Value.ToString()) > 0)
                                            {
                                                if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value != null)
                                                {
                                                    if (decimal.Parse(dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value.ToString()) > decimal.Parse(dtblMeterialReceiptQty.Rows[e.RowIndex]["qty"].ToString()))
                                                    {
                                                        dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value = dtblMeterialReceiptQty.Rows[e.RowIndex]["qty"].ToString();
                                                        if (decMeterialReceiptQty < decimal.Parse(dtblMeterialReceiptQty.Rows[e.RowIndex]["qty"].ToString()))
                                                        {
                                                            dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value = decMeterialReceiptQty;
                                                            decMeterialReceiptQty = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                            else if (e.ColumnIndex == dgvProductDetails.Columns["dgvcmbBatch"].Index)
                            {
                                if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null && dgvProductDetails.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
                                {
                                    decimal decBatchId = Convert.ToDecimal(dgvProductDetails.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value);
                                    strBarcode = BllBatch.ProductBatchBarcodeViewByBatchId(decBatchId);
                                    dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = strBarcode;
                                }
                            }
                            else if (e.ColumnIndex == dgvProductDetails.Columns["dgvtxtGrossValue"].Index)
                            {
                                dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtDiscountPercent"].Value = 0;
                                dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtDiscount"].Value = 0;
                            }
                            else if (e.ColumnIndex == dgvProductDetails.Columns["dgvtxtDiscountPercent"].Index)
                            {
                                if (dgvProductDetails.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
                                {
                                    if (dgvProductDetails.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() != string.Empty)
                                    {
                                        if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtGrossValue"].Value != null)
                                        {
                                            if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtGrossValue"].Value.ToString() != string.Empty)
                                            {
                                                decDiscountPercent = Convert.ToDecimal(dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtDiscountPercent"].Value.ToString());
                                                decGrossValue = Convert.ToDecimal(dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtGrossValue"].Value.ToString());
                                                if (decGrossValue > 0)
                                                {
                                                    decDiscount = decGrossValue * decDiscountPercent / 100;
                                                }
                                                dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtDiscount"].Value = Math.Round(decDiscount, PublicVariables._inNoOfDecimalPlaces);
                                            }
                                        }
                                    }
                                }
                            }
                            else if (e.ColumnIndex == dgvProductDetails.Columns["dgvtxtDiscount"].Index)
                            {
                                if (dgvProductDetails.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
                                {
                                    if (dgvProductDetails.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() != string.Empty)
                                    {
                                        if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtGrossValue"].Value != null)
                                        {
                                            if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtGrossValue"].Value.ToString() != string.Empty)
                                            {
                                                decDiscount = Convert.ToDecimal(dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtDiscount"].Value.ToString());
                                                decGrossValue = Convert.ToDecimal(dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtGrossValue"].Value.ToString());
                                                if (decGrossValue > 0)
                                                {
                                                    decDiscountPercent = decDiscount * 100 / decGrossValue;
                                                }
                                                dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtDiscountPercent"].Value = Math.Round(decDiscountPercent, PublicVariables._inNoOfDecimalPlaces);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    SerialNo();
                }
                CheckInvalidEntries(e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("PI85:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Function to fill material receipt details 
        /// </summary>
        public void MaterialReceiptDetailsFill()
        {
            List<DataTable> ListObj = new List<DataTable>();
            List<DataTable> ListObjDetals = new List<DataTable>();
            MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
            MaterialReceiptBll bllMaterialReceiptDetails = new MaterialReceiptBll();
            decimal decMaterialReceiptMasterId = 0;
            try
            {
                if (!isEditFill)
                {
                    if (cmbCashOrParty.SelectedValue != null)
                    {
                        if (cmbCashOrParty.SelectedValue.ToString() != "System.Data.DataRowView" && cmbCashOrParty.Text != "System.Data.DataRowView")
                        {
                            GridComboFill();
                            decMaterialReceiptMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
                            ListObj = bllMaterialReceiptMaster.MaterialReceiptMasterViewByReceiptMasterId(decMaterialReceiptMasterId);
                            if (ListObj[0].Rows.Count > 0)
                            {
                                cmbCurrency.SelectedValue = ListObj[0].Rows[0].ItemArray[7];
                            }
                            ListObjDetals = bllMaterialReceiptDetails.MaterialReceiptDetailsViewByMaterialReceiptMasterIdWithRemainingByNotInCurrPI
                                    (decMaterialReceiptMasterId, decPurchaseMasterId, decPurchaseInvoiceVoucherTypeId);
                            if (ListObjDetals[0].Rows.Count > 0)
                            {
                                if (dgvProductDetails.DataSource == null)
                                {
                                    dgvProductDetails.Rows.Clear();
                                }
                                else
                                {
                                    ((DataTable)dgvProductDetails.DataSource).Rows.Clear();

                                }

                                int i = 0;
                                foreach (DataRow dr in ListObjDetals[0].Rows)
                                {
                                    dgvProductDetails.Rows.Add();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtPurchaseDetailsId"].Value = dr["purchaseDetailsId"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtPurchaseOrderDetailsId"].Value = dr["purchaseOrderDetailsId"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtMaterialReceiptDetailsId"].Value = dr["materialReceiptDetailsId"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtProductId"].Value = dr["productId"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtBarcode"].Value = dr["barcode"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtProductCode"].Value = dr["productCode"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtProductName"].Value = dr["productName"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtQuantity"].Value = dr["qty"].ToString();
                                    UnitComboFill(Convert.ToDecimal(dr["productId"].ToString()), i, dgvProductDetails.Rows[i].Cells["dgvcmbUnit"].ColumnIndex);
                                    dgvProductDetails.Rows[i].Cells["dgvtxtUnitConversionId"].Value = dr["unitConversionId"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(dr["unitId"].ToString());
                                    dgvProductDetails.Rows[i].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(dr["godownId"].ToString()); ;
                                    dgvProductDetails.Rows[i].Cells["dgvcmbRack"].Value = Convert.ToDecimal(dr["rackId"].ToString()); ;
                                    BatchComboFill(Convert.ToDecimal(dr["productId"].ToString()), i, dgvProductDetails.Rows[i].Cells["dgvcmbBatch"].ColumnIndex);
                                    dgvProductDetails.Rows[i].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(dr["batchId"].ToString());
                                    dgvProductDetails.Rows[i].Cells["dgvtxtRate"].Value = dr["rate"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtGrossValue"].Value = dr["grossValue"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtDiscountPercent"].Value = dr["discountPercent"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtDiscount"].Value = dr["discount"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtNetValue"].Value = dr["netvalue"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvcmbTax"].Value = Convert.ToDecimal(dr["taxId"].ToString());
                                    dgvProductDetails.Rows[i].Cells["dgvtxtTaxAmount"].Value = dr["taxAmount"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvtxtAmount"].Value = dr["Amount"].ToString();
                                    dgvProductDetails.Rows[i].Cells["dgvcmbUnit"].ReadOnly = true;
                                    i++;
                                }
                                dgvProductDetails.AllowUserToAddRows = false;
                            }
                            else
                            {
                                if (dgvProductDetails.DataSource == null)
                                {
                                    dgvProductDetails.Rows.Clear();
                                }
                                else
                                {
                                    ((DataTable)dgvProductDetails.DataSource).Rows.Clear();
                                }
                            }
                            SerialNo();
                            GridviewReadOnlySettings("Against MaterialReceipt");
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PI20:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to fill the details while calling from register or report
 /// </summary>
 public void FillRegisterOrReport()
 {
     PurchaseMasterInfo infoPurchaseMaster = new PurchaseMasterInfo();
     PurchaseInvoiceBll BllPurchaseInvoice = new PurchaseInvoiceBll();
     PurchaseOrderMasterInfo infoPurchaseOrderMaster = new PurchaseOrderMasterInfo();
     PurchaseOrderBll BllPurchaseOrder = new PurchaseOrderBll();
     MaterialReceiptMasterInfo infoMaterialReceiptMaster = new MaterialReceiptMasterInfo();
     MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
     VoucherTypeBll BllVoucherType = new VoucherTypeBll();
     VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
     AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
     bool isPartyBalanceRef = false;
     try
     {
         isEditFill = true;
         btnSave.Text = "Update";
         btnDelete.Enabled = true;
         txtVoucherNo.ReadOnly = true;
         infoPurchaseMaster = BllPurchaseInvoice.PurchaseMasterView(decPurchaseMasterId);
         strVoucherNo = infoPurchaseMaster.VoucherNo;
         decPurchaseInvoiceVoucherTypeId = infoPurchaseMaster.VoucherTypeId;
         decPurchaseInvoiceSuffixPrefixId = infoPurchaseMaster.SuffixPrefixId;
         isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(decPurchaseInvoiceVoucherTypeId);
         infoVoucherType = BllVoucherType.VoucherTypeView(decPurchaseInvoiceVoucherTypeId);
         this.Text = infoVoucherType.VoucherTypeName;
         if (isAutomatic)
         {
             txtVoucherDate.Focus();
         }
         else
         {
             txtVoucherNo.Focus();
         }
         txtVoucherNo.Text = infoPurchaseMaster.InvoiceNo;
         txtVendorInvoiceNo.Text = infoPurchaseMaster.VendorInvoiceNo;
         dtpVoucherDate.Value = infoPurchaseMaster.Date;
         dtpInvoiceDate.Value = infoPurchaseMaster.VendorInvoiceDate;
         cmbCashOrParty.SelectedValue = infoPurchaseMaster.LedgerId;
         if (infoPurchaseMaster.PurchaseOrderMasterId == 0 && infoPurchaseMaster.MaterialReceiptMasterId == 0)
         {
             cmbPurchaseMode.SelectedItem = "NA";
         }
         else if (infoPurchaseMaster.PurchaseOrderMasterId != 0 && infoPurchaseMaster.MaterialReceiptMasterId == 0)
         {
             cmbPurchaseMode.SelectedItem = "Against PurchaseOrder";
             infoPurchaseOrderMaster = BllPurchaseOrder.PurchaseOrderMasterView(infoPurchaseMaster.PurchaseOrderMasterId);
             cmbVoucherType.SelectedValue = infoPurchaseOrderMaster.VoucherTypeId;
             OrderComboFill();
             cmbOrderNo.SelectedValue = infoPurchaseMaster.PurchaseOrderMasterId;
         }
         else if (infoPurchaseMaster.PurchaseOrderMasterId == 0 && infoPurchaseMaster.MaterialReceiptMasterId != 0)
         {
             cmbPurchaseMode.SelectedItem = "Against MaterialReceipt";
             infoMaterialReceiptMaster = bllMaterialReceiptMaster.MaterialReceiptMasterView(infoPurchaseMaster.MaterialReceiptMasterId);
             cmbVoucherType.SelectedValue = infoMaterialReceiptMaster.VoucherTypeId;
             OrderComboFill();
             cmbOrderNo.SelectedValue = infoPurchaseMaster.MaterialReceiptMasterId;
         }
         cmbPurchaseAccount.SelectedValue = infoPurchaseMaster.PurchaseAccount;
         txtCreditPeriod.Text = infoPurchaseMaster.CreditPeriod;
         cmbCurrency.SelectedValue = infoPurchaseMaster.ExchangeRateId;
         txtNarration.Text = infoPurchaseMaster.Narration;
         lblAdditionalCostAmount.Text = Math.Round(infoPurchaseMaster.AdditionalCost, PublicVariables._inNoOfDecimalPlaces).ToString();
         lblTaxAmount.Text = Math.Round(infoPurchaseMaster.TotalTax, PublicVariables._inNoOfDecimalPlaces).ToString();
         txtTotalAmount.Text = Math.Round(infoPurchaseMaster.TotalAmount, PublicVariables._inNoOfDecimalPlaces).ToString();
         txtBillDiscount.Text = Math.Round(infoPurchaseMaster.BillDiscount, PublicVariables._inNoOfDecimalPlaces).ToString();
         txtLRNo.Text = infoPurchaseMaster.LrNo;
         txtTransportationCompany.Text = infoPurchaseMaster.TransportationCompany;
         txtGrandTotal.Text = Math.Round(infoPurchaseMaster.GrandTotal, PublicVariables._inNoOfDecimalPlaces).ToString();
         PurchaseDetailsFill();
         TaxGridFill();
         AdditionalCostGridFill();
         isPartyBalanceRef = bllAccountLedger.PartyBalanceAgainstReferenceCheck(strVoucherNo, decPurchaseInvoiceVoucherTypeId);
         if (isPartyBalanceRef)
         {
             cmbCashOrParty.Enabled = false;
         }
         else
         {
             cmbCashOrParty.Enabled = true;
         }
         isEditFill = false;
     }
     catch (Exception ex)
     {
         MessageBox.Show("PI55:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 public void Delete()
 {
     PurchaseInvoiceBll BllPurchaseInvoice = new PurchaseInvoiceBll();
     AditionalCostBll bllAdditionalCost = new AditionalCostBll();
     AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
     StockPostingBll BllStockPosting = new StockPostingBll();
     // StockPostingSP spStockPosting = new StockPostingSP();
     LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
     PurchaseOrderBll BllPurchaseOrder = new PurchaseOrderBll();
     MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
     PurchaseOrderMasterInfo infoPurchaseOrderMaster = new PurchaseOrderMasterInfo();
     MaterialReceiptMasterInfo infoMaterialReceiptMaster = new MaterialReceiptMasterInfo();
     PurchaseMasterInfo infoPurchaseMaster = new PurchaseMasterInfo();
     /*---------------------------------Deleting previous stock posting, Ledger posting, partybalanceposting---------------------------------------*/
     infoPurchaseMaster = BllPurchaseInvoice.PurchaseMasterView(decPurchaseMasterId);
     if (infoPurchaseMaster.MaterialReceiptMasterId != 0)
     {
         infoMaterialReceiptMaster = bllMaterialReceiptMaster.MaterialReceiptMasterView(infoPurchaseMaster.MaterialReceiptMasterId);
         BllStockPosting.StockPostingDeleteForSalesInvoiceAgainstDeliveryNote
             (infoPurchaseMaster.VoucherTypeId, infoPurchaseMaster.VoucherNo,
             infoMaterialReceiptMaster.VoucherNo, infoMaterialReceiptMaster.VoucherTypeId);
     }
     BllStockPosting.StockPostingDeleteByagainstVoucherTypeIdAndagainstVoucherNoAndVoucherNoAndVoucherType
             (0, "NA", infoPurchaseMaster.VoucherNo, infoPurchaseMaster.VoucherTypeId);
     //-------------------------------------------------
     decimal decPurchaseDetailsId = 0;
     decimal decPurchaseOrderMasterId = 0;
     decimal decMaterialReceiptMasterId = 0;
     decimal decAdditionalCostId = 0;
     decimal decPurchaseBillTaxId = 0;
     int inRef = 0;
     bool isRef = false;
     try
     {
         foreach (DataGridViewRow dgvrow in dgvProductDetails.Rows)
         {
             if (dgvrow.Cells["dgvtxtPurchaseDetailsId"].Value != null)
             {
                 if (dgvrow.Cells["dgvtxtPurchaseDetailsId"].Value.ToString() != string.Empty && dgvrow.Cells["dgvtxtPurchaseDetailsId"].Value.ToString() != "0")
                 {
                     decPurchaseDetailsId = Convert.ToDecimal(dgvrow.Cells["dgvtxtPurchaseDetailsId"].Value.ToString());
                     inRef = BllPurchaseInvoice.PurchaseMasterReferenceCheck(decPurchaseMasterId, decPurchaseDetailsId);
                     if (inRef > 0 && !isRef)
                     {
                         isRef = true;
                     }
                 }
             }
         }
         if (!isRef)
         {
             isRef = bllAccountLedger.PartyBalanceAgainstReferenceCheck(strVoucherNo, decPurchaseInvoiceVoucherTypeId);
             if (!isRef)
             {
                 BllPurchaseInvoice.PurchaseMasterDelete(decPurchaseMasterId);
                 BllPurchaseInvoice.PurchaseDetailsDeleteByPurchaseMasterId(decPurchaseMasterId);
                 foreach (DataGridViewRow dgvrow in dgvAdditionalCost.Rows)
                 {
                     if (dgvrow.Cells["dgvtxtAdditionalCostId"].Value != null)
                     {
                         if (dgvrow.Cells["dgvtxtAdditionalCostId"].Value.ToString() != string.Empty &&
                             dgvrow.Cells["dgvtxtAdditionalCostId"].Value.ToString() != "0")
                         {
                             decAdditionalCostId = Convert.ToDecimal(dgvrow.Cells["dgvtxtAdditionalCostId"].Value.ToString());
                             bllAdditionalCost.AdditionalCostDelete(decAdditionalCostId);
                         }
                     }
                 }
                 if (dgvTax.Visible)
                 {
                     foreach (DataGridViewRow dgvrow in dgvTax.Rows)
                     {
                         if (dgvrow.Cells["dgvtxtPurchaseBillTaxId"].Value != null)
                         {
                             if (dgvrow.Cells["dgvtxtPurchaseBillTaxId"].Value.ToString() != string.Empty &&
                                 dgvrow.Cells["dgvtxtPurchaseBillTaxId"].Value.ToString() != "0")
                             {
                                 decPurchaseBillTaxId = Convert.ToDecimal(dgvrow.Cells["dgvtxtPurchaseBillTaxId"].Value.ToString());
                                 BllPurchaseInvoice.PurchaseBillTaxDelete(decPurchaseBillTaxId);
                             }
                         }
                     }
                 }
                 if (cmbPurchaseMode.Text == "Against PurchaseOrder")
                 {
                     decPurchaseOrderMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
                     infoPurchaseOrderMaster = BllPurchaseOrder.PurchaseOrderMasterView(decPurchaseOrderMasterId);
                 }
                 else if (cmbPurchaseMode.Text == "Against MaterialReceipt")
                 {
                     decMaterialReceiptMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
                     infoMaterialReceiptMaster = bllMaterialReceiptMaster.MaterialReceiptMasterView(decMaterialReceiptMasterId);
                 }
                 BllLedgerPosting.LedgerPostDelete(strVoucherNo, decPurchaseInvoiceVoucherTypeId);
                 if (infoPurchaseOrderMaster.PurchaseOrderMasterId != 0)
                 {
                     BllStockPosting.StockPostingDeleteByagainstVoucherTypeIdAndagainstVoucherNoAndVoucherNoAndVoucherType
                         (decPurchaseInvoiceVoucherTypeId, strVoucherNo,
                         infoPurchaseOrderMaster.VoucherNo, infoPurchaseOrderMaster.VoucherTypeId);
                 }
                 else if (infoMaterialReceiptMaster.MaterialReceiptMasterId != 0)
                 {
                     BllStockPosting.StockPostingDeleteByagainstVoucherTypeIdAndagainstVoucherNoAndVoucherNoAndVoucherType
                         (decPurchaseInvoiceVoucherTypeId, strVoucherNo,
                         infoMaterialReceiptMaster.VoucherNo, infoMaterialReceiptMaster.VoucherTypeId);
                 }
                 BllStockPosting.StockPostingDeleteByagainstVoucherTypeIdAndagainstVoucherNoAndVoucherNoAndVoucherType
                           (0, "NA", strVoucherNo, decPurchaseInvoiceVoucherTypeId);
                 bllAccountLedger.PartyBalanceDeleteByVoucherTypeVoucherNoAndReferenceType(strVoucherNo, decPurchaseInvoiceVoucherTypeId);
                 Messages.DeletedMessage();
                 Clear();
                 this.Close();
             }
             else
             {
                 Messages.InformationMessage("Cannot delete purchase invoice because there is a payment voucher against this invoice");
             }
         }
         else
         {
             Messages.InformationMessage("Cannot delete purchase invoice because reference exists");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PI41:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to call the savefunction or editfunction after checking invalid entries
 /// </summary>
 public void SaveOrEdit()
 {
     MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
     try
     {
         dgvProduct.ClearSelection();
         int inRow = dgvProduct.RowCount;
         String strInvoiceNo = txtReceiptNo.Text.Trim();
         if (txtReceiptNo.Text.Trim() == string.Empty)
         {
             Messages.InformationMessage("Enter voucher number");
             txtReceiptNo.Focus();
         }
         else if (bllMaterialReceiptMaster.MaterialReceiptNumberCheckExistence(txtReceiptNo.Text.Trim(), decMaterialReceiptVoucherTypeId) == true && btnSave.Text == "Save")
         {
             Messages.InformationMessage("Receipt number already exist");
             txtReceiptNo.Focus();
         }
         else if (txtDate.Text.Trim() == string.Empty)
         {
             Messages.InformationMessage("Select a date in between financial year");
             txtDate.Focus();
         }
         else if (cmbCashOrParty.SelectedValue == null)
         {
             Messages.InformationMessage("Select Cash/Party");
             cmbCashOrParty.Focus();
         }
         else if (cmbcurrency.SelectedValue == null)
         {
             Messages.InformationMessage("Select Currency");
             cmbcurrency.Focus();
         }
         else if (inRow - 1 == 0)
         {
             Messages.InformationMessage("Can't save material receipt without atleast one product with complete details");
         }
         else
         {
             if (RemoveIncompleteRowsFromGrid())
             {
                 if (dgvProduct.Rows[0].Cells["dgvtxtProductName"].Value == null && dgvProduct.Rows[0].Cells["dgvtxtProductCode"].Value == null)
                 {
                     MessageBox.Show("Can't save material receipt without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     dgvProduct.ClearSelection();
                     dgvProduct.Focus();
                 }
                 else
                 {
                     if (btnSave.Text == "Save")
                     {
                         if (dgvProduct.Rows[0].Cells["dgvtxtProductName"].Value == null)
                         {
                             MessageBox.Show("Can't save material receipt without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             dgvProduct.ClearSelection();
                             dgvProduct.Focus();
                         }
                         else
                         {
                             if (PublicVariables.isMessageAdd)
                             {
                                 if (Messages.SaveMessage())
                                 {
                                     SaveFunction();
                                 }
                             }
                             else
                             {
                                 SaveFunction();
                             }
                         }
                     }
                     if (btnSave.Text == "Update")
                     {
                         if (QuantityCheckWithReference() == 1)
                         {
                             if (dgvProduct.Rows[0].Cells["dgvtxtProductName"].Value == null)
                             {
                                 MessageBox.Show("Can't Edit MateraialReceipt without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                 dgvProduct.ClearSelection();
                                 dgvProduct.Focus();
                             }
                             else if (decEdit == 1)
                             {
                                 MessageBox.Show("Can't Edit MateraialReceipt with Invalid Quantity", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                 dgvProduct.ClearSelection();
                                 dgvProduct.Focus();
                             }
                             else
                             {
                                 if (PublicVariables.isMessageEdit)
                                 {
                                     if (Messages.UpdateMessage())
                                     {
                                         EditFunction();
                                     }
                                 }
                                 else
                                 {
                                     EditFunction();
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MR32:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 ///  Function to fill VoucherType combobox
 /// </summary>
 public void VoucherTypeCombofill()
 {
     try
     {
         MaterialReceiptBll bllMaterialReceiptDetails = new MaterialReceiptBll();
         List<DataTable> ListObj = new List<DataTable>();
         ListObj = bllMaterialReceiptDetails.VoucherTypeCombofillforMaterialReceipt();
         cmbVoucherType.DataSource = ListObj[0];
         cmbVoucherType.ValueMember = "voucherTypeId";
         cmbVoucherType.DisplayMember = "voucherTypeName";
         cmbVoucherType.SelectedIndex = 0;
     }
     catch (Exception ex)
     {
         MessageBox.Show("MRR2:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to generate voucherNo
 /// </summary>
 public void VoucherNumberGeneration()
 {
     try
     {
         TransactionsGeneralFillBll obj = new TransactionsGeneralFillBll();
         MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
         if (strVoucherNo == string.Empty)
         {
             strVoucherNo = "0";
         }
         strVoucherNo = obj.VoucherNumberAutomaicGeneration(decMaterialReceiptVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpDate.Value, tableName);
         if (Convert.ToDecimal(strVoucherNo) != bllMaterialReceiptMaster.MaterialReceiptMasterGetMaxPlusOne(decMaterialReceiptVoucherTypeId))
         {
             strVoucherNo = bllMaterialReceiptMaster.MaterialReceiptMasterGetMax(decMaterialReceiptVoucherTypeId).ToString();
             strVoucherNo = obj.VoucherNumberAutomaicGeneration(decMaterialReceiptVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpDate.Value, tableName);
             if (bllMaterialReceiptMaster.MaterialReceiptMasterGetMax(decMaterialReceiptVoucherTypeId) == "0")
             {
                 strVoucherNo = "0";
                 strVoucherNo = obj.VoucherNumberAutomaicGeneration(decMaterialReceiptVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpDate.Value, tableName);
             }
         }
         if (isAutomatic)
         {
             SuffixPrefixSettingsBll BllSuffixPrefixSettings = new SuffixPrefixSettingsBll();
             SuffixPrefixInfo infoSuffixPrefix = new SuffixPrefixInfo();
             infoSuffixPrefix = BllSuffixPrefixSettings.GetSuffixPrefixDetails(decMaterialReceiptVoucherTypeId, dtpDate.Value);
             strPrefix = infoSuffixPrefix.Prefix;
             strSuffix = infoSuffixPrefix.Suffix;
             decMaterialReceiptSuffixPrefixId = infoSuffixPrefix.SuffixprefixId;
             strReceiptNo = strPrefix + strVoucherNo + strSuffix;
             txtReceiptNo.Text = strReceiptNo;
             txtReceiptNo.ReadOnly = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MR1:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Print button click
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnPrint_Click(object sender, EventArgs e)
 {
     try
     {
         if (dgvMaterialReceiptReport.RowCount > 0)
         {
             MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
             DataSet dsMaterialReceiptReport = bllMaterialReceiptMaster.MaterialReceiptReportPrinting(1, strInvoiceNo, strStatus, decLedgerId, strproductCode, decVoucherTypeId, this.dtpFromDate.Value, this.dtpToDate.Value, decOrderId);
             frmReport frmReport = new frmReport();
             frmReport.MdiParent = formMDI.MDIObj;
             frmReport.MaterialReceiptReportPrinting(dsMaterialReceiptReport);
         }
         else
         {
             Messages.InformationMessage("No data found");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MRR15:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to edit the voucher
 /// </summary>
 public void EditFunction()
 {
     MaterialReceiptMasterInfo infoMaterialReceiptMaster = new MaterialReceiptMasterInfo();
     MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
     SettingsBll BllSettings = new SettingsBll();
     try
     {
         infoMaterialReceiptMaster.MaterialReceiptMasterId = decMaterialReceiptMasterId;
         infoMaterialReceiptMaster.Date = Convert.ToDateTime(txtDate.Text);
         infoMaterialReceiptMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         infoMaterialReceiptMaster.SuffixPrefixId = Convert.ToDecimal(decMaterialReceiptSuffixPrefixId);
         infoMaterialReceiptMaster.VoucherNo = strVoucherNo;
         infoMaterialReceiptMaster.VoucherTypeId = decMaterialReceiptVoucherTypeId;
         infoMaterialReceiptMaster.InvoiceNo = txtReceiptNo.Text;
         infoMaterialReceiptMaster.UserId = PublicVariables._decCurrentUserId;
         infoMaterialReceiptMaster.TransportationCompany = txtTransportation.Text.Trim();
         infoMaterialReceiptMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         infoMaterialReceiptMaster.Narration = txtNarration.Text.Trim();
         infoMaterialReceiptMaster.LrNo = txtLRNo.Text.Trim();
         infoMaterialReceiptMaster.exchangeRateId = Convert.ToDecimal(cmbcurrency.SelectedValue.ToString());
         infoMaterialReceiptMaster.TotalAmount = Convert.ToDecimal(txtTotal.Text);
         infoMaterialReceiptMaster.Extra1 = string.Empty;
         infoMaterialReceiptMaster.Extra2 = string.Empty;
         infoMaterialReceiptMaster.ExtraDate = Convert.ToDateTime(DateTime.Now);
         if (cmbOrderNo.Text == string.Empty || cmbOrderNo.SelectedValue.ToString() == string.Empty)
         {
             infoMaterialReceiptMaster.OrderMasterId = 0;
         }
         else
         {
             infoMaterialReceiptMaster.OrderMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
         }
         bllMaterialReceiptMaster.MaterialReceiptMasterEdit(infoMaterialReceiptMaster);
         removeMaterialReceiptDetails();
         MaterialReceiptDetailsEditFill();
         if (isEdit)
         {
             Messages.UpdatedMessage();
             if (frmMaterialReceiptRegisterObj != null)
             {
                 if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                 {
                     PrintForDotMatrix(decMaterialReceiptMasterId);
                 }
                 else
                 {
                     Print(decMaterialReceiptMasterId, infoMaterialReceiptMaster.OrderMasterId);
                 }
                 frmMaterialReceiptRegisterObj.GridFill();
                 frmMaterialReceiptRegisterObj.Enabled = true;
             }
             if (frmMaterialReceiptReportObj != null)
             {
                 if (cbxPrintAfterSave.Checked)
                 {
                     if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                     {
                         PrintForDotMatrix(decMaterialReceiptMasterId);
                     }
                     else
                     {
                         Print(decMaterialReceiptMasterId, infoMaterialReceiptMaster.OrderMasterId);
                     }
                 }
                 frmMaterialReceiptReportObj.GridFill();
                 frmMaterialReceiptReportObj.Enabled = true;
             }
             if (frmDayBookObj != null)
             {
                 if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                 {
                     PrintForDotMatrix(decMaterialReceiptMasterId);
                 }
                 else
                 {
                     Print(decMaterialReceiptMasterId, infoMaterialReceiptMaster.OrderMasterId);
                 }
             }
             this.Close();
             isEdit = false;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MR36:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill the voucher details for edit
 /// </summary>
 public void MaterialReceiptDetailsEditFill()
 {
     ProductInfo infoProduct = new ProductInfo();
     MaterialReceiptDetailsInfo infoMaterialReceiptDetails = new MaterialReceiptDetailsInfo();
     StockPostingBll BllStockPosting = new StockPostingBll();
     MaterialReceiptBll bllMaterialReceipt = new MaterialReceiptBll();
     ProductCreationBll BllProductCreation = new ProductCreationBll();
     try
     {
         for (int inI = 0; inI < dgvProduct.Rows.Count - 1; inI++)
         {
             decimal decStatus = bllMaterialReceipt.MaterialReceiptDetailsReferenceCheck(decMaterialReceiptDetailId);
             if (decStatus == 1)
             {
                 dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].ReadOnly = true;
                 dgvProduct.Rows[inI].Cells["dgvtxtProductName"].ReadOnly = true;
                 dgvProduct.Rows[inI].Cells["dgvcmbUnit"].ReadOnly = true;
                 dgvProduct.Rows[inI].Cells["dgvtxtBarcode"].ReadOnly = true;
                 dgvProduct.Rows[inI].Cells["dgvCmbRack"].ReadOnly = true;
                 dgvProduct.Rows[inI].Cells["dgvcmbGodown"].ReadOnly = true;
                 dgvProduct.Rows[inI].Cells["dgvtxtRate"].ReadOnly = true;
             }
             if (dgvProduct.Rows[inI].Cells["dgvtxtProductName"].Value != null)
             {
                 if (dgvProduct.Rows[inI].Cells["dgvtxtMaterialReceiptdetailsId"].Value == null || dgvProduct.Rows[inI].Cells["dgvtxtMaterialReceiptdetailsId"].Value.ToString() == string.Empty)
                 {
                     infoMaterialReceiptDetails.MaterialReceiptMasterId = decMaterialReceiptMasterId;
                     infoProduct = BllProductCreation.ProductViewByCode(dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                     infoMaterialReceiptDetails.ProductId = infoProduct.ProductId;
                     if (dgvProduct.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value != null)
                     {
                         infoMaterialReceiptDetails.OrderDetailsId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value.ToString());
                     }
                     else
                         infoMaterialReceiptDetails.OrderDetailsId = 0;
                     infoMaterialReceiptDetails.Qty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                     infoMaterialReceiptDetails.UnitId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
                     infoMaterialReceiptDetails.UnitConversionId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value);
                     if (dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString() != string.Empty)
                     {
                         infoMaterialReceiptDetails.GodownId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString());
                     }
                     else
                     {
                         infoMaterialReceiptDetails.GodownId = 1;
                     }
                     if (dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value != null && dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value.ToString() != string.Empty)
                     {
                         infoMaterialReceiptDetails.RackId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value.ToString());
                     }
                     else
                     {
                         infoMaterialReceiptDetails.RackId = 1;
                     }
                     if (dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
                     {
                         infoMaterialReceiptDetails.BatchId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString());
                     }
                     else
                     {
                         infoMaterialReceiptDetails.BatchId = 1;
                     }
                     infoMaterialReceiptDetails.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                     infoMaterialReceiptDetails.Amount = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                     infoMaterialReceiptDetails.Slno = Convert.ToInt32(dgvProduct.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
                     infoMaterialReceiptDetails.Extra1 = string.Empty;
                     infoMaterialReceiptDetails.Exta2 = string.Empty;
                     infoMaterialReceiptDetails.ExtraDate = Convert.ToDateTime(DateTime.Now);
                     bllMaterialReceipt.MaterialReceiptDetailsAdd(infoMaterialReceiptDetails);
                 }
                 else
                 {
                     infoMaterialReceiptDetails.MaterialReceiptMasterId = decMaterialReceiptMasterId;
                     infoMaterialReceiptDetails.MaterialReceiptDetailsId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtMaterialReceiptdetailsId"].Value);
                     infoProduct = BllProductCreation.ProductViewByCode(dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                     infoMaterialReceiptDetails.ProductId = infoProduct.ProductId;
                     if (dgvProduct.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value != null)
                     {
                         infoMaterialReceiptDetails.OrderDetailsId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value.ToString());
                     }
                     else
                         infoMaterialReceiptDetails.OrderDetailsId = 0;
                     infoMaterialReceiptDetails.Qty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                     infoMaterialReceiptDetails.UnitId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
                     infoMaterialReceiptDetails.UnitConversionId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value);
                     infoMaterialReceiptDetails.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                     if (dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString() != string.Empty)
                     {
                         infoMaterialReceiptDetails.GodownId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString());
                     }
                     else
                     {
                         infoMaterialReceiptDetails.GodownId = 1;
                     }
                     if (dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value != null && dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value.ToString() != string.Empty)
                     {
                         infoMaterialReceiptDetails.RackId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value.ToString());
                     }
                     else
                     {
                         infoMaterialReceiptDetails.RackId = 1;
                     }
                     if (dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
                     {
                         infoMaterialReceiptDetails.BatchId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString());
                     }
                     else
                     {
                         infoMaterialReceiptDetails.BatchId = 1;
                     }
                     infoMaterialReceiptDetails.Amount = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                     infoMaterialReceiptDetails.Slno = Convert.ToInt32(dgvProduct.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
                     infoMaterialReceiptDetails.Extra1 = string.Empty;
                     infoMaterialReceiptDetails.Exta2 = string.Empty;
                     infoMaterialReceiptDetails.ExtraDate = Convert.ToDateTime(DateTime.Now);
                     bllMaterialReceipt.MaterialReceiptDetailsEdit(infoMaterialReceiptDetails);
                 }
                 StockPostingInfo infoStockPosting = new StockPostingInfo();
                 infoStockPosting.Date = Convert.ToDateTime(txtDate.Text);
                 infoStockPosting.ProductId = infoMaterialReceiptDetails.ProductId;
                 infoStockPosting.BatchId = infoMaterialReceiptDetails.BatchId;
                 infoStockPosting.UnitId = infoMaterialReceiptDetails.UnitId;
                 infoStockPosting.GodownId = infoMaterialReceiptDetails.GodownId;
                 infoStockPosting.RackId = infoMaterialReceiptDetails.RackId;
                 if (cmbOrderNo.SelectedValue != null)
                 {
                     if (dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value.ToString() != string.Empty && dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value.ToString() != "NA")
                     {
                         infoStockPosting.VoucherNo = Convert.ToString(dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value.ToString());
                         infoStockPosting.AgainstVoucherNo = strVoucherNo;
                     }
                     else
                     {
                         infoStockPosting.VoucherNo = strVoucherNo;
                         infoStockPosting.AgainstVoucherNo = "NA";
                     }
                     if (dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value.ToString() != string.Empty && dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value.ToString() != "NA")
                     {
                         infoStockPosting.InvoiceNo = Convert.ToString(dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value.ToString());
                         infoStockPosting.AgainstInvoiceNo = txtReceiptNo.Text;
                     }
                     else
                     {
                         infoStockPosting.InvoiceNo = txtReceiptNo.Text;
                         infoStockPosting.AgainstInvoiceNo = "NA";
                     }
                     if (dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value.ToString() != string.Empty && Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value.ToString()) != 0)
                     {
                         infoStockPosting.VoucherTypeId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value.ToString());
                         infoStockPosting.AgainstVoucherTypeId = decMaterialReceiptVoucherTypeId;
                     }
                     else
                     {
                         infoStockPosting.VoucherTypeId = decMaterialReceiptVoucherTypeId;
                         infoStockPosting.AgainstVoucherTypeId = 0;
                     }
                 }
                 else
                 {
                     infoStockPosting.InvoiceNo = txtReceiptNo.Text;
                     infoStockPosting.VoucherNo = strVoucherNo;
                     infoStockPosting.VoucherTypeId = decMaterialReceiptVoucherTypeId;
                     infoStockPosting.AgainstVoucherTypeId = 0;
                     infoStockPosting.AgainstVoucherNo = "NA";
                     infoStockPosting.AgainstInvoiceNo = "NA";
                 }
                 BllStockPosting.StockPostingDeleteByVoucherTypeAndVoucherNo(strVoucherNo, decMaterialReceiptVoucherTypeId);
                 infoStockPosting.InwardQty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                 infoStockPosting.OutwardQty = 0;
                 infoStockPosting.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                 infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoStockPosting.Extra1 = string.Empty;
                 infoStockPosting.Extra2 = string.Empty;
                 BllStockPosting.StockPostingAdd(infoStockPosting);
                 isEdit = true;
             }
         }
         if (isEdit)
         {
             cmbCashOrParty.Enabled = true;
             cmbOrderNo.Enabled = true;
             cmbcurrency.Enabled = true;
             txtDate.Enabled = true;
             cmbVoucherType.Enabled = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MR37:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill Datagridview
 /// </summary>
 public void GridFill()
 {
     try
     {
         List<DataTable> ListObj = new List<DataTable>();
         MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
         if (txtMaterialReceiptNo.Text.Trim() == string.Empty)
         {
             strInvoiceNo = string.Empty;
         }
         else
         {
             strInvoiceNo = txtMaterialReceiptNo.Text;
         }
         if (cmbCashOrParty.SelectedIndex == 0 || cmbCashOrParty.SelectedIndex == -1)
         {
             decLedgerId = -1;
         }
         else
         {
             decLedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         }
         DateTime FromDate = this.dtpFromDate.Value;
         DateTime ToDate = this.dtpToDate.Value;
         ListObj = bllMaterialReceiptMaster.MaterialReceiptMasterViewAll(strInvoiceNo, decLedgerId, FromDate, ToDate);
         dgvMaterialReceiptRegister.DataSource = ListObj[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("MRREG1:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to print the voucher
 /// </summary>
 /// <param name="decReceiptMasterId"></param>
 public void Print(decimal decReceiptMasterId, decimal decOrderMasterId1)
 {
     MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
     try
     {
         DataSet dsMaterialReceipt = bllMaterialReceiptMaster.MaterialReceiptPrinting(decReceiptMasterId, 1, decOrderMasterId1);
         frmReport frmReport = new frmReport();
         frmReport.MdiParent = formMDI.MDIObj;
         frmReport.MaterialReceiptPrinting(dsMaterialReceipt);
     }
     catch (Exception ex)
     {
         MessageBox.Show("MR33:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Function to fill MaterialReceipt combobox
        /// </summary>
        public void MaterialReceiptComboFill()
        {
            try
            {
                MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll();
                List<DataTable> listobj = new List<DataTable>();
                listobj = bllMaterialReceiptMaster.MaterialReceiptNoCorrespondingToLedgerForReport(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()));
                cmbMaterialReceiptNo.DataSource = listobj[0];
                cmbMaterialReceiptNo.DisplayMember = "invoiceNo";
                cmbMaterialReceiptNo.ValueMember = "materialReceiptMasterId";
                cmbMaterialReceiptNo.SelectedIndex = -1;
            }
            catch (Exception ex)
            {
                MessageBox.Show("ROREP06:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }
 /// <summary>
 /// It is a function for Add Stock Posting
 /// </summary>
 public void AddStockPosting()
 {
     try
     {
         StockPostingInfo infoStockPosting = new StockPostingInfo();
         //StockPostingSP spStockPosting = new StockPostingSP();
         StockPostingBll BllStockPosting = new StockPostingBll();
         MaterialReceiptBll bllMaterialReceipt = new MaterialReceiptBll();
         MaterialReceiptMasterInfo infoMaterialReceiptMaster = new MaterialReceiptMasterInfo();
         infoMaterialReceiptMaster = bllMaterialReceipt.MaterialReceiptMasterView(Convert.ToDecimal(cmbMaterialReceiptNo.SelectedValue));
         infoStockPosting.Date = DateTime.Parse(txtDate.Text);
         infoStockPosting.VoucherTypeId = infoMaterialReceiptMaster.VoucherTypeId;
         infoStockPosting.VoucherNo = infoMaterialReceiptMaster.VoucherNo;
         infoStockPosting.InvoiceNo = infoMaterialReceiptMaster.InvoiceNo;
         if (isAutomatic)
         {
             infoStockPosting.AgainstVoucherNo = strVoucherNo;
             infoStockPosting.AgainstInvoiceNo = txtRejectionOutNo.Text;
         }
         else
         {
             infoStockPosting.AgainstVoucherNo = txtRejectionOutNo.Text;
             infoStockPosting.AgainstInvoiceNo = txtRejectionOutNo.Text;
         }
         if (decRejectionOutVoucherTypeId != 0)
         {
             infoStockPosting.AgainstVoucherTypeId = decRejectionOutVoucherTypeId;
         }
         if (strVoucherNo != string.Empty)
         {
             infoStockPosting.AgainstVoucherNo = strVoucherNo;
         }
         if (txtRejectionOutNo.Text != string.Empty)
         {
             infoStockPosting.AgainstInvoiceNo = txtRejectionOutNo.Text;
         }
         infoStockPosting.InwardQty = 0;
         infoStockPosting.OutwardQty = infoRejectionOutDetails.Qty;
         infoStockPosting.ProductId = infoRejectionOutDetails.ProductId;
         infoStockPosting.BatchId = infoRejectionOutDetails.BatchId;
         infoStockPosting.UnitId = infoRejectionOutDetails.UnitId;
         infoStockPosting.GodownId = infoRejectionOutDetails.GodownId;
         infoStockPosting.RackId = infoRejectionOutDetails.RackId;
         infoStockPosting.Rate = infoRejectionOutDetails.Rate;
         infoStockPosting.Extra1 = string.Empty;
         infoStockPosting.Extra2 = string.Empty;
         infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         BllStockPosting.StockPostingAdd(infoStockPosting);
     }
     catch (Exception ex)
     {
         MessageBox.Show("RO28:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }