/// <summary>
 /// Stock posting add function
 /// </summary>
 /// <param name="decProductId"></param>
 /// <param name="strMaster"></param>
 public void AddtoStockPosting(decimal decProductId, string strMaster)
 {
     try
     {
         // StockPostingSP spStockPosting = new StockPostingSP();
         StockPostingBll BllStockPosting = new StockPostingBll();
         StockPostingInfo infoStockPosting = new StockPostingInfo();
         decimal decCurrentQty = infoPhysicalStockDetails.Qty;
         decimal decGId = infoPhysicalStockDetails.GodownId;
         decimal decBId = infoPhysicalStockDetails.BatchId;
         decimal decRId = infoPhysicalStockDetails.RackId;
         decimal decOldStock = BllStockPosting.ProductGetCurrentStock(decProductId, decGId, decBId, decRId);
         if (decCurrentQty >= 0)
         {
             if (decOldStock >= 0)
             {
                 decimal decBalance = decCurrentQty - decOldStock;
                 if (decBalance >= 0)
                 {
                     infoStockPosting.InwardQty = decBalance;
                     infoStockPosting.OutwardQty = 0;
                 }
                 else
                 {
                     infoStockPosting.InwardQty = 0;
                     infoStockPosting.OutwardQty = -decBalance;
                 }
             }
             else
             {
                 infoStockPosting.InwardQty = -decOldStock + decCurrentQty;
                 infoStockPosting.OutwardQty = 0;
             }
         }
         else
         {
             if (decOldStock >= 0)
             {
                 infoStockPosting.InwardQty = 0;
                 infoStockPosting.OutwardQty = -decCurrentQty + decOldStock;
             }
             else
             {
                 decimal decBalance = -decCurrentQty + decOldStock;
                 if (decBalance >= 0)
                 {
                     infoStockPosting.InwardQty = 0;
                     infoStockPosting.OutwardQty = decBalance;
                 }
                 else
                 {
                     infoStockPosting.InwardQty = -decBalance;
                     infoStockPosting.OutwardQty = 0;
                 }
             }
         }
         infoStockPosting.VoucherNo = strMaster;
         infoStockPosting.BatchId = infoPhysicalStockDetails.BatchId;
         infoStockPosting.Date = Convert.ToDateTime(txtDate.Text);
         infoStockPosting.Extra1 = string.Empty;
         infoStockPosting.Extra2 = string.Empty;
         infoStockPosting.GodownId = infoPhysicalStockDetails.GodownId;
         infoStockPosting.ProductId = decProductId;
         infoStockPosting.Rate = infoPhysicalStockDetails.Rate;
         infoStockPosting.UnitId = infoPhysicalStockDetails.UnitId;
         infoStockPosting.RackId = infoPhysicalStockDetails.RackId;
         infoStockPosting.AgainstVoucherTypeId = 0;
         infoStockPosting.AgainstVoucherNo = "NA";
         infoStockPosting.AgainstInvoiceNo = "NA";
         infoStockPosting.VoucherTypeId = decPhysicalStockVoucherTypeId;
         infoStockPosting.InvoiceNo = strMaster;
         BllStockPosting.StockPostingAdd(infoStockPosting);
     }
     catch (Exception ex)
     {
         MessageBox.Show("PS:21" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }