/**
  *  Close Document.
  *  Cancel not delivered Qunatities
  *  @return true if success
  */
 public bool CloseIt()
 {
     try
     {
         log.Info("closeIt - " + ToString());
         //	Close Not delivered Qty
         MRequisitionLine[] lines      = GetLines();
         Decimal            totalLines = Env.ZERO;
         for (int i = 0; i < lines.Length; i++)
         {
             MRequisitionLine line     = lines[i];
             Decimal          finalQty = line.GetQty();
             if (line.GetC_OrderLine_ID() == 0)
             {
                 finalQty = Env.ZERO;
             }
             else
             {
                 MOrderLine ol = new MOrderLine(GetCtx(), line.GetC_OrderLine_ID(), Get_TrxName());
                 finalQty = ol.GetQtyOrdered();
             }
             Tuple <String, String, String> mInfo = null;
             if (Env.HasModulePrefix("DTD001_", out mInfo))
             {
                 int quant = Util.GetValueOfInt(line.GetQty() - line.GetDTD001_DeliveredQty());
                 //Update storage requisition reserved qty
                 if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0)
                 {
                     if (GetDocAction() != "VO" && GetDocStatus() != "DR")
                     {
                         if (quant > 0)
                         {
                             int loc_id = GetLocation(GetM_Warehouse_ID());
                             storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), null);
                             if (storage == null)
                             {
                                 storage = MStorage.GetCreate(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), null);
                             }
                             storage.SetDTD001_QtyReserved((Decimal.Subtract(storage.GetDTD001_QtyReserved(), (Decimal)quant)));
                             storage.Save();
                         }
                     }
                 }
                 else if (GetDocAction() != "VO" && GetDocStatus() != "DR")
                 {
                     if (quant > 0)
                     {
                         int loc_id = GetLocation(GetM_Warehouse_ID());
                         storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), 0, null);
                         if (storage == null)
                         {
                             storage = MStorage.GetCreate(GetCtx(), loc_id, line.GetM_Product_ID(), 0, null);
                         }
                         storage.SetDTD001_QtyReserved((Decimal.Subtract(storage.GetDTD001_QtyReserved(), (Decimal)quant)));
                         storage.Save();
                     }
                 }
             }
             //	final qty is not line qty
             if (finalQty.CompareTo(line.GetQty()) != 0)
             {
                 String description = line.GetDescription();
                 if (description == null)
                 {
                     description = "";
                 }
                 description += " [" + line.GetQty() + "]";
                 line.SetDescription(description);
                 // Amit 9-feb-2015
                 // line.SetQty(finalQty);
                 //Amit
                 line.SetLineNetAmt();
                 line.Save();
             }
             //get Grand Total or SubTotal
             totalLines = Decimal.Add(totalLines, line.GetLineNetAmt());
         }
         if (totalLines.CompareTo(GetTotalLines()) != 0)
         {
             SetTotalLines(totalLines);
             Save();
         }
     }
     catch (Exception ex)
     {
         // MessageBox.Show("MRequisition--CloseIt");
         log.Severe(ex.ToString());
     }
     return(true);
 }