/// <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;
 }