示例#1
0
 /**
  *  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);
 }
示例#2
0
        /**
         *	Prepare Document
         *  @return new status (In Progress or Invalid)
         */
        public String PrepareIt()
        {
            try
            {
                log.Info(ToString());
                _processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE);
                if (_processMsg != null)
                {
                    return(DocActionVariables.STATUS_INVALID);
                }
                MRequisitionLine[] lines = GetLines();

                //	Invalid
                if (GetAD_User_ID() == 0 ||
                    GetM_PriceList_ID() == 0 ||
                    GetM_Warehouse_ID() == 0 ||
                    lines.Length == 0)
                {
                    return(DocActionVariables.STATUS_INVALID);
                }

                //	Std Period open?
                if (!MPeriod.IsOpen(GetCtx(), GetDateDoc(), MDocBaseType.DOCBASETYPE_PURCHASEREQUISITION))
                {
                    _processMsg = "@PeriodClosed@";
                    return(DocActionVariables.STATUS_INVALID);
                }

                // is Non Business Day?
                if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateDoc()))
                {
                    _processMsg = Common.Common.NONBUSINESSDAY;
                    return(DocActionVariables.STATUS_INVALID);
                }



                //	Add up Amounts
                int     precision  = MPriceList.GetStandardPrecision(GetCtx(), GetM_PriceList_ID());
                Decimal totalLines = Env.ZERO;
                for (int i = 0; i < lines.Length; i++)
                {
                    MRequisitionLine line    = lines[i];
                    Decimal          lineNet = Decimal.Multiply(line.GetQty(), line.GetPriceActual());
                    lineNet = Decimal.Round(lineNet, precision);//, MidpointRounding.AwayFromZero);
                    if (lineNet.CompareTo(line.GetLineNetAmt()) != 0)
                    {
                        line.SetLineNetAmt(lineNet);
                        line.Save();
                    }
                    totalLines = Decimal.Add(totalLines, line.GetLineNetAmt());
                }
                if (totalLines.CompareTo(GetTotalLines()) != 0)
                {
                    SetTotalLines(totalLines);
                    Save();
                }
                _justPrepared = true;
            }
            catch (Exception ex)
            {
                // MessageBox.Show("MRequisition--PrepareIt");
                log.Severe(ex.ToString());
            }
            return(DocActionVariables.STATUS_INPROGRESS);
        }