/// <summary>
        ///	    Process Line
        /// </summary>
        /// <param name="rLine">request line</param>
        private void Process(MRequisitionLine rLine)
        {
            if (rLine.GetM_Product_ID() == 0 && rLine.GetC_Charge_ID() == 0)
            {
                log.Warning("Ignored Line" + rLine.GetLine()
                            + " " + rLine.GetDescription()
                            + " - " + rLine.GetLineNetAmt());
                return;
            }

            if (!_ConsolidateDocument &&
                rLine.GetM_Requisition_ID() != _m_M_Requisition_ID)
            {
                CloseOrder();
            }
            if (_orderLine == null ||
                rLine.GetM_Product_ID() != _m_M_Product_ID ||
                rLine.GetM_AttributeSetInstance_ID() != _m_M_AttributeSetInstance_ID ||
                rLine.GetC_Charge_ID() != 0)            //	single line per charge
            {
                NewLine(rLine);
            }

            //	Update Order Line
            _orderLine.SetQty(Decimal.Add(_orderLine.GetQtyOrdered(), rLine.GetQty()));

            //	Update Requisition Line
            rLine.SetC_OrderLine_ID(_orderLine.GetC_OrderLine_ID());
            if (!rLine.Save())
            {
                throw new Exception("Cannot update Request Line");
            }
        }
Exemple #2
0
 /// <summary>
 /// After Delete
 /// </summary>
 /// <param name="sucess">new</param>
 /// <returns>true if can be deleted</returns>
 /// SI_0682_1 Need to update the reserved qty on requisition line by internal use line save aslo and should work as work in inventory move.
 protected override bool AfterDelete(bool success)
 {
     if (Env.IsModuleInstalled("DTD001_") && IsInternalUse())
     {
         if (GetM_RequisitionLine_ID() != 0)
         {
             MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx());        // Trx used to handle query stuck problem
             requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() - qtyReserved);
             if (!requisition.Save())
             {
                 return(false);
             }
             storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());      // Trx used to handle query stuck problem
             if (storage == null)
             {
                 storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());         // Trx used to handle query stuck problem
             }
             storage.SetQtyReserved(storage.GetQtyReserved() - qtyReserved);
             if (!storage.Save())
             {
                 return(false);
             }
         }
     }
     return(true);
 }
        }       //	createPO

        /// <summary>
        /// Create Requisition
        /// </summary>
        private void CreateRequisition()
        {
            int    noReqs = 0;
            String info   = "";
            //
            MRequisition requisition = null;
            MWarehouse   wh          = null;

            X_T_Replenish[] replenishs = GetReplenish(_M_WareSource);
            for (int i = 0; i < replenishs.Length; i++)
            {
                X_T_Replenish replenish = replenishs[i];
                if (wh == null || wh.GetM_Warehouse_ID() != replenish.GetM_Warehouse_ID())
                {
                    wh = MWarehouse.Get(GetCtx(), replenish.GetM_Warehouse_ID());
                }
                //
                if (requisition == null ||
                    requisition.GetM_Warehouse_ID() != replenish.GetM_Warehouse_ID())
                {
                    requisition = new MRequisition(GetCtx(), 0, Get_TrxName());
                    requisition.SetAD_User_ID(GetAD_User_ID());
                    requisition.SetC_DocType_ID(_C_DocType_ID);
                    requisition.SetDescription(Msg.GetMsg(GetCtx(), "Replenishment"));
                    //	Set Org/WH
                    int _CountDTD001 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='DTD001_'"));
                    if (_CountDTD001 > 0)
                    {
                        requisition.SetDTD001_MWarehouseSource_ID(wh.GetM_WarehouseSource_ID());
                    }
                    requisition.SetAD_Org_ID(wh.GetAD_Org_ID());
                    requisition.SetM_Warehouse_ID(wh.GetM_Warehouse_ID());

                    if (!requisition.Save())
                    {
                        return;
                    }
                    _DocNo = requisition.GetDocumentNo() + ","; //dtd
                    log.Fine(requisition.ToString());
                    noReqs++;
                    info += " - " + requisition.GetDocumentNo();
                }
                //
                MRequisitionLine line = new MRequisitionLine(requisition);
                line.SetM_Product_ID(replenish.GetM_Product_ID());
                line.SetC_BPartner_ID(replenish.GetC_BPartner_ID());
                line.SetQty(replenish.GetQtyToOrder());
                line.SetPrice();
                line.Save();
            }
            _DocNo = _DocNo.Substring(0, _DocNo.Length - 1);//dtd
            _info  = "#" + noReqs + info;
            log.Info(_info);
        }       //	createRequisition
 /// <summary>
 /// Create new Order
 /// </summary>
 /// <param name="rLine">request line</param>
 private void NewOrder(MRequisitionLine rLine, int C_BPartner_ID)
 {
     if (_order != null)
     {
         CloseOrder();
     }
     //	BPartner
     if (_m_bpartner == null || C_BPartner_ID != _m_bpartner.GetC_BPartner_ID())
     {
         _m_bpartner = new MBPartner(GetCtx(), C_BPartner_ID, null);
     }
     //	Order
     _order = new MOrder(GetCtx(), 0, Get_TrxName());
     _order.SetIsSOTrx(false);
     _order.SetC_DocTypeTarget_ID();
     _order.SetBPartner(_m_bpartner);
     //	default po document type
     if (!_ConsolidateDocument)
     {
         _order.SetDescription(Msg.GetElement(GetCtx(), "M_Requisition_ID")
                               + ": " + rLine.GetParent().GetDocumentNo());
     }
     //	Prepare Save
     _m_M_Requisition_ID = rLine.GetM_Requisition_ID();
     if (!_order.Save())
     {
         throw new Exception("Cannot save Order");
     }
     else
     {
         if (String.IsNullOrEmpty(createdPO))
         {
             createdPO = _order.GetDocumentNo();
         }
         else
         {
             createdPO += " , " + _order.GetDocumentNo();
         }
     }
 }
        /// <summary>
        /// Load Requisition Lines
        /// </summary>
        /// <param name="req">requisition</param>
        /// <returns>DocLine Array</returns>
        private DocLine[] LoadLines(MRequisition req)
        {
            List <DocLine> list = new List <DocLine>();

            MRequisitionLine[] lines = req.GetLines();
            for (int i = 0; i < lines.Length; i++)
            {
                MRequisitionLine line    = lines[i];
                DocLine          docLine = new DocLine(line, this);
                Decimal          Qty     = line.GetQty();
                docLine.SetQty(Qty, false);
                //	Decimal PriceActual =
                line.GetPriceActual();
                Decimal LineNetAmt = line.GetLineNetAmt();
                docLine.SetAmount(LineNetAmt);   // DR
                list.Add(docLine);
            }
            // Return Array
            DocLine[] dls = new DocLine[list.Count];
            dls = list.ToArray();
            return(dls);
        }
        /// <summary>
        /// New Order Line (different Product)
        /// </summary>
        /// <param name="rLine">request line</param>
        private void NewLine(MRequisitionLine rLine)
        {
            if (_orderLine != null)
            {
                if (!_orderLine.Save())
                {
                    throw new Exception("Cannot update Order Line");
                }
            }
            _orderLine = null;
            MProduct product = null;

            //	Get Business Partner
            int C_BPartner_ID = rLine.GetC_BPartner_ID();

            if (C_BPartner_ID != 0)
            {
                ;
            }
            else if (rLine.GetC_Charge_ID() != 0)
            {
                MCharge charge = MCharge.Get(GetCtx(), rLine.GetC_Charge_ID());
                C_BPartner_ID = charge.GetC_BPartner_ID();
                if (C_BPartner_ID == 0)
                {
                    throw new Exception("No Vendor for Charge " + charge.GetName());
                }
            }
            else
            {
                //	Find Vendor from Produt
                product = MProduct.Get(GetCtx(), rLine.GetM_Product_ID());
                MProductPO[] ppos = MProductPO.GetOfProduct(GetCtx(), product.GetM_Product_ID(), null);
                for (int i = 0; i < ppos.Length; i++)
                {
                    if (ppos[i].IsCurrentVendor() && ppos[i].GetC_BPartner_ID() != 0)
                    {
                        C_BPartner_ID = ppos[i].GetC_BPartner_ID();
                        break;
                    }
                }
                if (C_BPartner_ID == 0 && ppos.Length > 0)
                {
                    C_BPartner_ID = ppos[0].GetC_BPartner_ID();
                }
                if (C_BPartner_ID == 0)
                {
                    throw new Exception("No Vendor for " + product.GetName());
                }
            }

            //	New Order - Different Vendor
            if (_order == null ||
                _order.GetC_BPartner_ID() != C_BPartner_ID)
            {
                NewOrder(rLine, C_BPartner_ID);
            }

            //	No Order Line
            _orderLine = new MOrderLine(_order);
            if (product != null)
            {
                _orderLine.SetProduct(product);
                _orderLine.SetM_AttributeSetInstance_ID(rLine.GetM_AttributeSetInstance_ID());
            }
            else
            {
                _orderLine.SetC_Charge_ID(rLine.GetC_Charge_ID());
                _orderLine.SetPriceActual(rLine.GetPriceActual());
            }
            _orderLine.SetAD_Org_ID(rLine.GetAD_Org_ID());


            //	Prepare Save
            _m_M_Product_ID = rLine.GetM_Product_ID();
            _m_M_AttributeSetInstance_ID = rLine.GetM_AttributeSetInstance_ID();
            if (!_orderLine.Save())
            {
                throw new Exception("Cannot save Order Line");
            }
        }
Exemple #7
0
        /// <summary>
        /// Load Requisitions
        /// </summary>
        /// <returns>requisition lines of Order</returns>
        private DocLine[] LoadRequisitions()
        {
            MOrder order = (MOrder)GetPO();

            MOrderLine[] oLines            = order.GetLines();
            Dictionary <int, Decimal> qtys = new Dictionary <int, Decimal>();

            for (int i = 0; i < oLines.Length; i++)
            {
                MOrderLine line = oLines[i];
                qtys.Add(Utility.Util.GetValueOfInt(line.GetC_OrderLine_ID()), line.GetQtyOrdered());
            }
            //
            List <DocLine> list = new List <DocLine>();
            String         sql  = "SELECT * FROM M_RequisitionLine rl "
                                  + "WHERE EXISTS (SELECT * FROM C_Order o "
                                  + " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID) "
                                  + "WHERE ol.C_OrderLine_ID=rl.C_OrderLine_ID"
                                  + " AND o.C_Order_ID=" + order.GetC_Order_ID() + ") "
                                  + "ORDER BY rl.C_OrderLine_ID";
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                while (idr.Read())
                {
                    MRequisitionLine line    = new MRequisitionLine(GetCtx(), idr, null);
                    DocLine          docLine = new DocLine(line, this);
                    //	Quantity - not more then OrderLine
                    //	Issue: Split of Requisition to multiple POs & different price
                    int     key    = line.GetC_OrderLine_ID();
                    Decimal maxQty = qtys[key];
                    Decimal Qty    = Math.Max(line.GetQty(), maxQty);
                    if (Env.Signum(Qty) == 0)
                    {
                        continue;
                    }
                    docLine.SetQty(Qty, false);
                    if (qtys.ContainsKey(key))
                    {
                        qtys.Remove(key);
                    }
                    qtys.Add(key, Decimal.Subtract(maxQty, Qty));
                    //
                    Decimal PriceActual = line.GetPriceActual();
                    Decimal LineNetAmt  = line.GetLineNetAmt();
                    if (line.GetQty().CompareTo(Qty) != 0)
                    {
                        LineNetAmt = Decimal.Multiply(PriceActual, Qty);
                    }
                    docLine.SetAmount(LineNetAmt);       // DR
                    list.Add(docLine);
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                log.Log(Level.SEVERE, sql, e);
            }

            // Return Array
            DocLine[] dls = new DocLine[list.Count];
            dls = list.ToArray();
            return(dls);
        }
Exemple #8
0
        /// <summary>
        /// After Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <param name="success">success</param>
        /// <returns>true</returns>
        protected override bool AfterSave(bool newRecord, bool success)
        {
            if (!success)
            {
                return(success);
            }

            //	Create MA
            if (newRecord && success &&
                _isManualEntry && GetM_AttributeSetInstance_ID() == 0)
            {
                CreateMA(true);
            }

            if (!IsInternalUse())
            {
                MInventory inv = new MInventory(GetCtx(), GetM_Inventory_ID(), Get_Trx());
                inv.SetIsAdjusted(false);
                if (!inv.Save())
                {
                }
            }
            else                // SI_0682_1 Need to update the reserved qty on requisition line by internal use line save aslo and should work as work in inventory move.
            {
                if (Env.IsModuleInstalled("DTD001_"))
                {
                    if (!newRecord && GetM_RequisitionLine_ID() != 0)
                    {
                        MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx());
                        requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + (GetQtyInternalUse() - qtyReserved));
                        if (!requisition.Save())
                        {
                            return(false);
                        }
                        storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());
                        if (storage == null)
                        {
                            storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());
                        }
                        storage.SetQtyReserved(storage.GetQtyReserved() + (GetQtyInternalUse() - qtyReserved));
                        if (!storage.Save())
                        {
                            return(false);
                        }
                    }

                    if (newRecord && GetM_RequisitionLine_ID() != 0 && GetDescription() != "RC")
                    {
                        MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx());
                        requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + GetQtyInternalUse());
                        if (!requisition.Save())
                        {
                            return(false);
                        }
                        storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());
                        if (storage == null)
                        {
                            storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());
                        }
                        storage.SetQtyReserved(storage.GetQtyReserved() + GetQtyInternalUse());
                        if (!storage.Save())
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }