コード例 #1
0
        /// <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");
            }
        }
コード例 #2
0
 /// <summary>
 /// Get Order Line
 /// </summary>
 /// <returns>order line or null</returns>
 public MOrderLine GetOrderLine()
 {
     if ((_oLine == null && GetC_OrderLine_ID() != 0) ||
         GetC_OrderLine_ID() != _oLine.GetC_OrderLine_ID())
     {
         _oLine = new MOrderLine(GetCtx(), GetC_OrderLine_ID(), Get_Trx());
     }
     return(_oLine);
 }
コード例 #3
0
 /// <summary>
 /// Set C_OrderLine_ID
 /// </summary>
 /// <param name="line">line</param>
 public void SetC_OrderLine_ID(MOrderLine line)
 {
     _oLine = line;
     if (line == null)
     {
         SetC_OrderLine_ID(0);
     }
     else
     {
         SetC_OrderLine_ID(line.GetC_OrderLine_ID());
     }
 }
コード例 #4
0
        /**
         *  Set Order Line.
         *  Does not set Quantity!
         *	@param oLine order line
         *	@param M_Locator_ID locator
         *  @param Qty used only to find suitable locator
         */
        public void SetOrderLine(MOrderLine oLine, int M_Locator_ID, Decimal Qty)
        {
            SetC_OrderLine_ID(oLine.GetC_OrderLine_ID());
            SetLine(oLine.GetLine());
            SetC_UOM_ID(oLine.GetC_UOM_ID());
            MProduct product = oLine.GetProduct();

            if (product == null)
            {
                SetM_Product_ID(0);
                SetM_AttributeSetInstance_ID(0);
                base.SetM_Locator_ID(0);
            }
            else
            {
                SetM_Product_ID(oLine.GetM_Product_ID());
                SetM_AttributeSetInstance_ID(oLine.GetM_AttributeSetInstance_ID());
                //
                if (product.IsItem())
                {
                    if (M_Locator_ID == 0)
                    {
                        SetM_Locator_ID(Qty);   //	requires warehouse, product, asi
                    }
                    else
                    {
                        SetM_Locator_ID(M_Locator_ID);
                    }
                }
                else
                {
                    base.SetM_Locator_ID(0);
                }
            }
            SetC_Charge_ID(oLine.GetC_Charge_ID());
            SetDescription(oLine.GetDescription());
            SetIsDescription(oLine.IsDescription());
            //
            SetC_Project_ID(oLine.GetC_Project_ID());
            SetC_ProjectPhase_ID(oLine.GetC_ProjectPhase_ID());
            SetC_ProjectTask_ID(oLine.GetC_ProjectTask_ID());
            SetC_Activity_ID(oLine.GetC_Activity_ID());
            SetC_Campaign_ID(oLine.GetC_Campaign_ID());
            SetAD_OrgTrx_ID(oLine.GetAD_OrgTrx_ID());
            SetUser1_ID(oLine.GetUser1_ID());
            SetUser2_ID(oLine.GetUser2_ID());
        }
コード例 #5
0
        public static bool InsertForeignCostMatchOrder(Ctx ctx, MOrderLine orderLine, decimal matchQty, int ASI, Trx trx)
        {
            int                  acctSchema_ID    = 0;
            int                  M_CostElement_ID = 0;
            int                  AD_Org_ID        = 0;
            int                  M_ASI_ID         = 0;
            MProduct             product          = null;
            MAcctSchema          acctSchema       = null;
            MCostForeignCurrency foreignCost      = null;
            dynamic              pc    = null;
            String               cl    = null;
            MOrder               order = null;

            try
            {
                order = new MOrder(ctx, orderLine.GetC_Order_ID(), trx);

                if (!order.IsSOTrx() && !order.IsReturnTrx())
                {
                    acctSchema_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT asch.c_acctschema_id FROM c_acctschema asch INNER JOIN ad_clientinfo ci
                                    ON ci.c_acctschema1_id = asch.c_acctschema_id WHERE ci.ad_client_id  = " + order.GetAD_Client_ID()));
                    acctSchema    = new MAcctSchema(ctx, acctSchema_ID, trx);

                    if (acctSchema.GetC_Currency_ID() != order.GetC_Currency_ID())
                    {
                        // Get Costing Element of Av. PO
                        M_CostElement_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT M_CostElement_ID FROM M_CostElement WHERE AD_Client_ID = "
                                                                               + order.GetAD_Client_ID() + " AND IsActive = 'Y' AND CostingMethod = 'A'"));

                        product = new MProduct(ctx, orderLine.GetM_Product_ID(), trx);

                        if (product != null && product.GetProductType() == "I" && product.GetM_Product_ID() > 0) // for Item Type product
                        {
                            pc = MProductCategory.Get(product.GetCtx(), product.GetM_Product_Category_ID());

                            // Get Costing Level
                            if (pc != null)
                            {
                                cl = pc.GetCostingLevel();
                            }
                            if (cl == null)
                            {
                                cl = acctSchema.GetCostingLevel();
                            }

                            if (cl == "C" || cl == "B")
                            {
                                AD_Org_ID = 0;
                            }
                            else
                            {
                                AD_Org_ID = order.GetAD_Org_ID();
                            }
                            if (cl != "B")
                            {
                                M_ASI_ID = 0;
                            }
                            else
                            {
                                M_ASI_ID = ASI;
                            }

                            foreignCost = MCostForeignCurrency.Get(product, M_ASI_ID, AD_Org_ID, M_CostElement_ID, order.GetC_BPartner_ID(), order.GetC_Currency_ID());
                            foreignCost.SetC_Order_ID(order.GetC_Order_ID());
                            foreignCost.SetCumulatedQty(Decimal.Add(foreignCost.GetCumulatedQty(), matchQty));
                            foreignCost.SetCumulatedAmt(Decimal.Add(foreignCost.GetCumulatedAmt(), Decimal.Multiply(orderLine.GetPriceActual(), matchQty)));
                            if (foreignCost.GetCumulatedQty() != 0)
                            {
                                foreignCost.SetCostPerUnit(Decimal.Round(Decimal.Divide(foreignCost.GetCumulatedAmt(), foreignCost.GetCumulatedQty()), acctSchema.GetCostingPrecision()));
                            }
                            else
                            {
                                foreignCost.SetCostPerUnit(0);
                            }
                            if (!foreignCost.Save(trx))
                            {
                                ValueNamePair pp = VLogger.RetrieveError();
                                _log.Severe("Error occured during updating M_Cost_ForeignCurrency. Error name : " + pp.GetName() +
                                            " AND Error Value : " + pp.GetValue() + " , For Invoice line : " + orderLine.GetC_OrderLine_ID() +
                                            " , AND Ad_Client_ID : " + orderLine.GetAD_Client_ID());
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Log(Level.SEVERE, "", ex);
                return(false);
            }
            return(true);
        }
コード例 #6
0
        }       //	doIt

        /// <summary>
        /// Process Expense Line
        /// </summary>
        /// <param name="te">header</param>
        /// <param name="tel">line</param>
        /// <param name="bp">bp</param>
        private void ProcessLine(MTimeExpense te, MTimeExpenseLine tel, MBPartner bp)
        {
            if (_order == null)
            {
                log.Info("New Order for " + bp + ", Project=" + tel.GetC_Project_ID());
                _order = new MOrder(GetCtx(), 0, Get_TrxName());
                _order.SetAD_Org_ID(tel.GetAD_Org_ID());
                _order.SetC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard);
                //
                _order.SetBPartner(bp);
                if (_order.GetC_BPartner_Location_ID() == 0)
                {
                    log.Log(Level.SEVERE, "No BP Location: " + bp);
                    AddLog(0, te.GetDateReport(),
                           null, "No Location: " + te.GetDocumentNo() + " " + bp.GetName());
                    _order = null;
                    return;
                }
                _order.SetM_Warehouse_ID(te.GetM_Warehouse_ID());

                ////Added By Arpit asked by Surya Sir..................29-12-2015
                //_order.SetSalesRep_ID(GetCtx().GetAD_User_ID());
                //End
                if (tel.GetC_Activity_ID() != 0)
                {
                    _order.SetC_Activity_ID(tel.GetC_Activity_ID());
                }
                if (tel.GetC_Campaign_ID() != 0)
                {
                    _order.SetC_Campaign_ID(tel.GetC_Campaign_ID());
                }
                if (tel.GetC_Project_ID() != 0)
                {
                    _order.SetC_Project_ID(tel.GetC_Project_ID());
                    //	Optionally Overwrite BP Price list from Project
                    MProject project = new MProject(GetCtx(), tel.GetC_Project_ID(), Get_TrxName());
                    if (project.GetM_PriceList_ID() != 0)
                    {
                        _order.SetM_PriceList_ID(project.GetM_PriceList_ID());
                    }
                }
                _order.SetSalesRep_ID(te.GetDoc_User_ID());
                //
                if (!_order.Save())
                {
                    throw new Exception("Cannot save Order");
                }
            }
            else
            {
                //	Update Header info
                if (tel.GetC_Activity_ID() != 0 && tel.GetC_Activity_ID() != _order.GetC_Activity_ID())
                {
                    _order.SetC_Activity_ID(tel.GetC_Activity_ID());
                }
                if (tel.GetC_Campaign_ID() != 0 && tel.GetC_Campaign_ID() != _order.GetC_Campaign_ID())
                {
                    _order.SetC_Campaign_ID(tel.GetC_Campaign_ID());
                }
                if (!_order.Save())
                {
                    new Exception("Cannot save Order");
                }
            }

            //	OrderLine
            MOrderLine ol = new MOrderLine(_order);

            //
            if (tel.GetM_Product_ID() != 0)
            {
                ol.SetM_Product_ID(tel.GetM_Product_ID(),
                                   tel.GetC_UOM_ID());
            }
            if (tel.GetS_ResourceAssignment_ID() != 0)
            {
                ol.SetS_ResourceAssignment_ID(tel.GetS_ResourceAssignment_ID());
            }
            // Set charge ID
            if (tel.GetC_Charge_ID() != 0)
            {
                ol.SetC_Charge_ID(tel.GetC_Charge_ID());
                ol.SetPriceActual(tel.GetExpenseAmt());
                ol.SetQty(tel.GetQty());
            }
            ol.SetQty(tel.GetQtyInvoiced());                    //
            ol.SetDescription(tel.GetDescription());
            //
            ol.SetC_Project_ID(tel.GetC_Project_ID());
            ol.SetC_ProjectPhase_ID(tel.GetC_ProjectPhase_ID());
            ol.SetC_ProjectTask_ID(tel.GetC_ProjectTask_ID());
            ol.SetC_Activity_ID(tel.GetC_Activity_ID());
            ol.SetC_Campaign_ID(tel.GetC_Campaign_ID());
            //
            Decimal price = tel.GetPriceInvoiced();     //

            if (price.CompareTo(Env.ZERO) != 0)
            {
                if (tel.GetC_Currency_ID() != _order.GetC_Currency_ID())
                {
                    price = MConversionRate.Convert(GetCtx(), price,
                                                    tel.GetC_Currency_ID(), _order.GetC_Currency_ID(),
                                                    _order.GetAD_Client_ID(), _order.GetAD_Org_ID());
                }
                ol.SetPrice(price);
            }
            else
            {
                ol.SetPrice();
            }
            if (tel.GetC_UOM_ID() != 0 && ol.GetC_UOM_ID() == 0)
            {
                ol.SetC_UOM_ID(tel.GetC_UOM_ID());
            }
            ol.SetTax();
            if (!ol.Save())
            {
                throw new Exception("Cannot save Order Line");
            }
            //	Update TimeExpense Line
            tel.SetC_OrderLine_ID(ol.GetC_OrderLine_ID());
            if (tel.Save())
            {
                log.Fine("Updated " + tel + " with C_OrderLine_ID");
            }
            else
            {
                log.Log(Level.SEVERE, "Not Updated " + tel + " with C_OrderLine_ID");
            }
        }       //	processLine
コード例 #7
0
        }   //	doIt

        /// <summary>
        /// Process Expense Line
        /// </summary>
        /// <param name="te">header</param>
        /// <param name="tel">line</param>
        /// <param name="bp">bp</param>
        private void ProcessLine(MTimeExpense te, MTimeExpenseLine tel, MBPartner bp)
        {
            if (_order == null)
            {
                log.Info("New Order for " + bp + ", Project=" + tel.GetC_Project_ID());
                _order = new MOrder(GetCtx(), 0, Get_TrxName());
                _order.SetAD_Org_ID(tel.GetAD_Org_ID());
                _order.SetC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard);
                //
                _order.SetBPartner(bp);
                if (_order.GetC_BPartner_Location_ID() == 0)
                {
                    log.Log(Level.SEVERE, "No BP Location: " + bp);
                    AddLog(0, te.GetDateReport(),
                           null, "No Location: " + te.GetDocumentNo() + " " + bp.GetName());
                    _order = null;
                    return;
                }
                _order.SetM_Warehouse_ID(te.GetM_Warehouse_ID());
                //Bhupendra: Add payment term
                // to check for if payment term is null
                if (bp.GetC_PaymentTerm_ID() == 0)
                {
                    // set the default payment method as check
                    int payTerm = GetPaymentTerm();
                    if (payTerm <= 0)
                    {
                        message = Msg.GetMsg(GetCtx(), "IsActivePaymentTerm");
                        return;
                    }
                    else
                    {
                        _order.SetC_PaymentTerm_ID(payTerm);
                    }
                }
                else
                {
                    //check weather paymentterm is active or not
                    if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM C_PaymentTerm WHERE C_PaymentTerm_ID=" + bp.GetC_PaymentTerm_ID(), null, Get_Trx())).Equals("Y"))
                    {
                        _order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID());
                    }
                    else
                    {
                        message = Msg.GetMsg(GetCtx(), "IsActivePaymentTerm");
                        return;
                    }
                }
                // Bhupendra: added a cond to check for payment method if null
                // Added by mohit - to set payment method and sales rep id.
                if (bp.GetVA009_PaymentMethod_ID() == 0)
                {
                    // set the default payment method as check
                    int paymethod = GetPaymentMethod();
                    if (paymethod <= 0)
                    {
                        message = Msg.GetMsg(GetCtx(), "IsActivePaymentMethod");
                        return;
                    }
                    else
                    {
                        _order.SetVA009_PaymentMethod_ID(paymethod);
                    }
                }
                else
                {
                    //check weather the PaymentMethod is active or not
                    if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM VA009_PaymentMethod WHERE VA009_PaymentMethod_ID=" + bp.GetVA009_PaymentMethod_ID(), null, Get_Trx())).Equals("Y"))
                    {
                        _order.SetVA009_PaymentMethod_ID(bp.GetVA009_PaymentMethod_ID());
                    }
                    else
                    {
                        message = Msg.GetMsg(GetCtx(), "IsActivePaymentMethod");
                        return;
                    }
                }
                _order.SetSalesRep_ID(te.GetDoc_User_ID());

                ////Added By Arpit asked by Surya Sir..................29-12-2015
                //_order.SetSalesRep_ID(GetCtx().GetAD_User_ID());
                //End
                if (tel.GetC_Activity_ID() != 0)
                {
                    _order.SetC_Activity_ID(tel.GetC_Activity_ID());
                }
                if (tel.GetC_Campaign_ID() != 0)
                {
                    _order.SetC_Campaign_ID(tel.GetC_Campaign_ID());
                }
                if (tel.GetC_Project_ID() != 0)
                {
                    _order.SetC_Project_ID(tel.GetC_Project_ID());
                    //	Optionally Overwrite BP Price list from Project
                    MProject project = new MProject(GetCtx(), tel.GetC_Project_ID(), Get_TrxName());
                    if (project.GetM_PriceList_ID() != 0)
                    {
                        //check weather the PriceList is active or not
                        if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM M_PriceList WHERE M_PriceList_ID=" + project.GetM_PriceList_ID(), null, Get_Trx())).Equals("Y"))
                        {
                            _order.SetM_PriceList_ID(project.GetM_PriceList_ID());
                        }
                        else
                        {
                            message = Msg.GetMsg(GetCtx(), "IsActivePriceList");
                            return;
                        }
                    }
                }
                else
                {
                    if (bp.GetM_PriceList_ID() != 0)
                    {
                        if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM M_PriceList WHERE M_PriceList_ID=" + bp.GetM_PriceList_ID(), null, Get_Trx())).Equals("Y"))
                        {
                            _order.SetM_PriceList_ID(bp.GetM_PriceList_ID());
                        }
                        else
                        {
                            message = Msg.GetMsg(GetCtx(), "IsActivePriceList");
                            return;
                        }
                    }
                }
                _order.SetSalesRep_ID(te.GetDoc_User_ID());
                //
                if (!_order.Save())
                {
                    Rollback();
                    ValueNamePair pp = VLogger.RetrieveError();
                    if (pp != null)
                    {
                        message = pp.GetName();
                        //if GetName is Empty then it will check GetValue
                        if (string.IsNullOrEmpty(message))
                        {
                            message = Msg.GetMsg("", pp.GetValue());
                        }
                    }
                    if (string.IsNullOrEmpty(message))
                    {
                        message = Msg.GetMsg(GetCtx(), "CantSaveOrder");
                    }
                    return;
                    //throw new Exception("Cannot save Order");
                }
            }
            else
            {
                //	Update Header info
                if (tel.GetC_Activity_ID() != 0 && tel.GetC_Activity_ID() != _order.GetC_Activity_ID())
                {
                    _order.SetC_Activity_ID(tel.GetC_Activity_ID());
                }
                if (tel.GetC_Campaign_ID() != 0 && tel.GetC_Campaign_ID() != _order.GetC_Campaign_ID())
                {
                    _order.SetC_Campaign_ID(tel.GetC_Campaign_ID());
                }
                if (!_order.Save())
                {
                    Rollback();
                    //get error message from ValueNamePair
                    ValueNamePair pp = VLogger.RetrieveError();
                    if (pp != null)
                    {
                        message = pp.GetName();
                        //if GetName is Empty then it will check GetValue
                        if (string.IsNullOrEmpty(message))
                        {
                            message = Msg.GetMsg("", pp.GetValue());
                        }
                    }
                    //it will check message is null or not
                    if (string.IsNullOrEmpty(message))
                    {
                        message = Msg.GetMsg(GetCtx(), "CantSaveOrder");
                    }
                    return;
                    //new Exception("Cannot save Order");
                }
            }

            //	OrderLine
            MOrderLine ol = new MOrderLine(_order);

            //
            if (tel.GetM_Product_ID() != 0)
            {
                ol.SetM_Product_ID(tel.GetM_Product_ID(),
                                   tel.GetC_UOM_ID());
            }
            if (tel.GetS_ResourceAssignment_ID() != 0)
            {
                ol.SetS_ResourceAssignment_ID(tel.GetS_ResourceAssignment_ID());
            }
            // Set charge ID
            if (tel.GetC_Charge_ID() != 0)
            {
                ol.SetC_Charge_ID(tel.GetC_Charge_ID());
                ol.SetPriceActual(tel.GetExpenseAmt());
                ol.SetQty(tel.GetQty());
            }
            ol.SetQty(tel.GetQtyInvoiced());        //
            ol.SetDescription(tel.GetDescription());
            //
            ol.SetC_Project_ID(tel.GetC_Project_ID());
            ol.SetC_ProjectPhase_ID(tel.GetC_ProjectPhase_ID());
            ol.SetC_ProjectTask_ID(tel.GetC_ProjectTask_ID());
            ol.SetC_Activity_ID(tel.GetC_Activity_ID());
            ol.SetC_Campaign_ID(tel.GetC_Campaign_ID());
            //
            Decimal price = tel.GetPriceInvoiced(); //

            if (price.CompareTo(Env.ZERO) != 0)
            {
                if (tel.GetC_Currency_ID() != _order.GetC_Currency_ID())
                {
                    price = MConversionRate.Convert(GetCtx(), price,
                                                    tel.GetC_Currency_ID(), _order.GetC_Currency_ID(),
                                                    _order.GetAD_Client_ID(), _order.GetAD_Org_ID());
                }
                ol.SetPrice(price);
                // added by Bhupendra to set the entered price
                ol.SetPriceEntered(price);
            }
            else
            {
                ol.SetPrice();
            }
            if (tel.GetC_UOM_ID() != 0 && ol.GetC_UOM_ID() == 0)
            {
                ol.SetC_UOM_ID(tel.GetC_UOM_ID());
            }
            ol.SetTax();
            if (!ol.Save())
            {
                Rollback();
                //get error message from ValueNamePair
                ValueNamePair pp = VLogger.RetrieveError();
                if (pp != null)
                {
                    message = pp.GetName();
                    //if GetName is Empty then it will check GetValue
                    if (string.IsNullOrEmpty(message))
                    {
                        message = Msg.GetMsg("", pp.GetValue());
                    }
                }
                //it will check message is null or not
                if (string.IsNullOrEmpty(message))
                {
                    message = Msg.GetMsg(GetCtx(), "CantSaveOrderLine");
                }
                return;
                //throw new Exception("Cannot save Order Line");
            }
            //	Update TimeExpense Line
            tel.SetC_OrderLine_ID(ol.GetC_OrderLine_ID());
            if (tel.Save())
            {
                log.Fine("Updated " + tel + " with C_OrderLine_ID");
            }
            else
            {
                log.Log(Level.SEVERE, "Not Updated " + tel + " with C_OrderLine_ID");
            }
        }   //	processLine
コード例 #8
0
        /// <summary>
        /// Generate Shipments
        /// </summary>
        /// <param name="idr">Order Query</param>
        /// <returns>info</returns>
        private String Generate(IDataReader idr)
        {
            DataTable dt     = new DataTable();
            MClient   client = MClient.Get(GetCtx());

            try
            {
                dt.Load(idr);
                idr.Close();
                //ResultSet dr = pstmt.executeQuery();
                foreach (DataRow dr in dt.Rows)//  while (dr.next ())		//	Order
                {
                    MOrder order = new MOrder(GetCtx(), dr, Get_TrxName());
                    //	New Header different Shipper, Shipment Location
                    if (!_consolidateDocument ||
                        (_shipment != null &&
                         (_shipment.GetC_BPartner_Location_ID() != order.GetC_BPartner_Location_ID() ||
                          _shipment.GetM_Shipper_ID() != order.GetM_Shipper_ID())))
                    {
                        CompleteShipment();
                    }
                    log.Fine("check: " + order + " - DeliveryRule=" + order.GetDeliveryRule());
                    //
                    DateTime?minGuaranteeDate = _movementDate;
                    bool     completeOrder    = MOrder.DELIVERYRULE_CompleteOrder.Equals(order.GetDeliveryRule());
                    //	OrderLine WHERE
                    String where = " AND M_Warehouse_ID=" + _M_Warehouse_ID;
                    if (_datePromised != null)
                    {
                        where += " AND (TRUNC(DatePromised,'DD')<=" + DB.TO_DATE((DateTime?)_datePromised, true)
                                 + " OR DatePromised IS NULL)";
                        //where += " AND (TRUNC(DatePromised,'DD')<='" + String.Format("{0:dd-MMM-yy}", _datePromised)
                        //    + "' OR DatePromised IS NULL)";
                    }
                    //	Exclude Auto Delivery if not Force
                    if (!MOrder.DELIVERYRULE_Force.Equals(order.GetDeliveryRule()))
                    {
                        where += " AND (C_OrderLine.M_Product_ID IS NULL"
                                 + " OR EXISTS (SELECT * FROM M_Product p "
                                 + "WHERE C_OrderLine.M_Product_ID=p.M_Product_ID"
                                 + " AND IsExcludeAutoDelivery='N'))";
                    }
                    //	Exclude Unconfirmed
                    if (!_isUnconfirmedInOut)
                    {
                        where += " AND NOT EXISTS (SELECT * FROM M_InOutLine iol"
                                 + " INNER JOIN M_InOut io ON (iol.M_InOut_ID=io.M_InOut_ID) "
                                 + "WHERE iol.C_OrderLine_ID=C_OrderLine.C_OrderLine_ID AND io.DocStatus IN ('IP','WC'))";
                    }
                    //	Deadlock Prevention - Order by M_Product_ID
                    MOrderLine[] lines = order.GetLines(where, "ORDER BY C_BPartner_Location_ID, M_Product_ID");
                    for (int i = 0; i < lines.Length; i++)
                    {
                        MOrderLine line = lines[i];
                        if (line.GetM_Warehouse_ID() != _M_Warehouse_ID)
                        {
                            continue;
                        }
                        log.Fine("check: " + line);
                        Decimal onHand    = Env.ZERO;
                        Decimal toDeliver = Decimal.Subtract(line.GetQtyOrdered(),
                                                             line.GetQtyDelivered());
                        MProduct product = line.GetProduct();
                        //	Nothing to Deliver
                        if (product != null && Env.Signum(toDeliver) == 0)
                        {
                            continue;
                        }

                        //	Check / adjust for confirmations
                        Decimal unconfirmedShippedQty = Env.ZERO;
                        if (_isUnconfirmedInOut && product != null && Env.Signum(toDeliver) != 0)
                        {
                            String       where2 = "EXISTS (SELECT * FROM M_InOut io WHERE io.M_InOut_ID=M_InOutLine.M_InOut_ID AND io.DocStatus IN ('IP','WC'))";
                            MInOutLine[] iols   = MInOutLine.GetOfOrderLine(GetCtx(),
                                                                            line.GetC_OrderLine_ID(), where2, null);
                            for (int j = 0; j < iols.Length; j++)
                            {
                                unconfirmedShippedQty = Decimal.Add(unconfirmedShippedQty, iols[j].GetMovementQty());
                            }
                            String logInfo = "Unconfirmed Qty=" + unconfirmedShippedQty
                                             + " - ToDeliver=" + toDeliver + "->";
                            toDeliver = Decimal.Subtract(toDeliver, unconfirmedShippedQty);
                            logInfo  += toDeliver;
                            if (Env.Signum(toDeliver) < 0)
                            {
                                toDeliver = Env.ZERO;
                                logInfo  += " (set to 0)";
                            }
                            //	Adjust On Hand
                            onHand = Decimal.Subtract(onHand, unconfirmedShippedQty);
                            log.Fine(logInfo);
                        }

                        //	Comments & lines w/o product & services
                        if ((product == null || !product.IsStocked()) &&
                            (Env.Signum(line.GetQtyOrdered()) == 0 ||                               //	comments
                             Env.Signum(toDeliver) != 0))                                           //	lines w/o product
                        {
                            if (!MOrder.DELIVERYRULE_CompleteOrder.Equals(order.GetDeliveryRule())) //	printed later
                            {
                                CreateLine(order, line, toDeliver, null, false);
                            }
                            continue;
                        }

                        //	Stored Product
                        MProductCategory pc       = MProductCategory.Get(order.GetCtx(), product.GetM_Product_Category_ID());
                        String           MMPolicy = pc.GetMMPolicy();
                        if (MMPolicy == null || MMPolicy.Length == 0)
                        {
                            MMPolicy = client.GetMMPolicy();
                        }
                        //
                        MStorage[] storages = GetStorages(line.GetM_Warehouse_ID(),
                                                          line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(),
                                                          product.GetM_AttributeSet_ID(),
                                                          line.GetM_AttributeSetInstance_ID() == 0,
                                                          (DateTime?)minGuaranteeDate,
                                                          MClient.MMPOLICY_FiFo.Equals(MMPolicy));

                        for (int j = 0; j < storages.Length; j++)
                        {
                            MStorage storage = storages[j];
                            onHand = Decimal.Add(onHand, storage.GetQtyOnHand());
                        }
                        bool fullLine = onHand.CompareTo(toDeliver) >= 0 ||
                                        Env.Signum(toDeliver) < 0;

                        //	Complete Order
                        if (completeOrder && !fullLine)
                        {
                            log.Fine("Failed CompleteOrder - OnHand=" + onHand
                                     + " (Unconfirmed=" + unconfirmedShippedQty
                                     + "), ToDeliver=" + toDeliver + " - " + line);
                            completeOrder = false;
                            break;
                        }
                        //	Complete Line
                        else if (fullLine && MOrder.DELIVERYRULE_CompleteLine.Equals(order.GetDeliveryRule()))
                        {
                            log.Fine("CompleteLine - OnHand=" + onHand
                                     + " (Unconfirmed=" + unconfirmedShippedQty
                                     + ", ToDeliver=" + toDeliver + " - " + line);
                            //
                            CreateLine(order, line, toDeliver, storages, false);
                        }
                        //	Availability
                        else if (MOrder.DELIVERYRULE_Availability.Equals(order.GetDeliveryRule()) &&
                                 (Env.Signum(onHand) > 0 ||
                                  Env.Signum(toDeliver) < 0))
                        {
                            Decimal deliver = toDeliver;
                            if (deliver.CompareTo(onHand) > 0)
                            {
                                deliver = onHand;
                            }
                            log.Fine("Available - OnHand=" + onHand
                                     + " (Unconfirmed=" + unconfirmedShippedQty
                                     + "), ToDeliver=" + toDeliver
                                     + ", Delivering=" + deliver + " - " + line);
                            //
                            CreateLine(order, line, deliver, storages, false);
                        }
                        //	Force
                        else if (MOrder.DELIVERYRULE_Force.Equals(order.GetDeliveryRule()))
                        {
                            Decimal deliver = toDeliver;
                            log.Fine("Force - OnHand=" + onHand
                                     + " (Unconfirmed=" + unconfirmedShippedQty
                                     + "), ToDeliver=" + toDeliver
                                     + ", Delivering=" + deliver + " - " + line);
                            //
                            CreateLine(order, line, deliver, storages, true);
                        }
                        //	Manual
                        else if (MOrder.DELIVERYRULE_Manual.Equals(order.GetDeliveryRule()))
                        {
                            log.Fine("Manual - OnHand=" + onHand
                                     + " (Unconfirmed=" + unconfirmedShippedQty
                                     + ") - " + line);
                        }
                        else
                        {
                            log.Fine("Failed: " + order.GetDeliveryRule() + " - OnHand=" + onHand
                                     + " (Unconfirmed=" + unconfirmedShippedQty
                                     + "), ToDeliver=" + toDeliver + " - " + line);
                        }
                    }   //	for all order lines

                    //	Complete Order successful
                    if (completeOrder && MOrder.DELIVERYRULE_CompleteOrder.Equals(order.GetDeliveryRule()))
                    {
                        for (int i = 0; i < lines.Length; i++)
                        {
                            MOrderLine line = lines[i];
                            if (line.GetM_Warehouse_ID() != _M_Warehouse_ID)
                            {
                                continue;
                            }
                            MProduct product   = line.GetProduct();
                            Decimal  toDeliver = Decimal.Subtract(line.GetQtyOrdered(), line.GetQtyDelivered());
                            //
                            MStorage[] storages = null;
                            if (product != null && product.IsStocked())
                            {
                                MProductCategory pc       = MProductCategory.Get(order.GetCtx(), product.GetM_Product_Category_ID());
                                String           MMPolicy = pc.GetMMPolicy();
                                if (MMPolicy == null || MMPolicy.Length == 0)
                                {
                                    MMPolicy = client.GetMMPolicy();
                                }
                                //
                                storages = GetStorages(line.GetM_Warehouse_ID(),
                                                       line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(),
                                                       product.GetM_AttributeSet_ID(),
                                                       line.GetM_AttributeSetInstance_ID() == 0, (DateTime?)minGuaranteeDate,
                                                       MClient.MMPOLICY_FiFo.Equals(MMPolicy));
                            }
                            //
                            CreateLine(order, line, toDeliver, storages, false);
                        }
                    }
                    _line += 1000;
                }       //	while order
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, _sql, e);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                }
                dt = null;
            }
            CompleteShipment();
            return("@Created@ = " + _created);
        }
コード例 #9
0
        /// <summary>
        /// Create Line
        /// </summary>
        /// <param name="order">order</param>
        /// <param name="orderLine">line</param>
        /// <param name="qty">Quantity</param>
        /// <param name="storages">storage info</param>
        /// <param name="force">force delivery</param>
        private void CreateLine(MOrder order, MOrderLine orderLine, Decimal qty,
                                MStorage[] storages, bool force)
        {
            //	Complete last Shipment - can have multiple shipments
            if (_lastC_BPartner_Location_ID != orderLine.GetC_BPartner_Location_ID())
            {
                CompleteShipment();
            }
            _lastC_BPartner_Location_ID = orderLine.GetC_BPartner_Location_ID();
            //	Create New Shipment
            if (_shipment == null)
            {
                _shipment = new MInOut(order, 0, _movementDate);
                _shipment.SetM_Warehouse_ID(orderLine.GetM_Warehouse_ID());     //	sets Org too
                if (order.GetC_BPartner_ID() != orderLine.GetC_BPartner_ID())
                {
                    _shipment.SetC_BPartner_ID(orderLine.GetC_BPartner_ID());
                }
                if (order.GetC_BPartner_Location_ID() != orderLine.GetC_BPartner_Location_ID())
                {
                    _shipment.SetC_BPartner_Location_ID(orderLine.GetC_BPartner_Location_ID());
                }

                // Added by Bharat on 29 Jan 2018 to set Inco Term from Order

                if (_shipment.Get_ColumnIndex("C_IncoTerm_ID") > 0)
                {
                    _shipment.SetC_IncoTerm_ID(order.GetC_IncoTerm_ID());
                }

                if (!_shipment.Save())
                {
                    //throw new Exception("Could not create Shipment");
                    log.Fine("Failed: Could not create Shipment against Order No : " + order.GetDocumentNo());
                    return;
                }
            }
            //	Non Inventory Lines
            if (storages == null)
            {
                MInOutLine line = new MInOutLine(_shipment);
                line.SetOrderLine(orderLine, 0, Env.ZERO);
                line.SetQty(qty);       //	Correct UOM
                if (orderLine.GetQtyEntered().CompareTo(orderLine.GetQtyOrdered()) != 0)
                {
                    line.SetQtyEntered(Decimal.Round(Decimal.Divide(Decimal.Multiply(qty,
                                                                                     orderLine.GetQtyEntered()), orderLine.GetQtyOrdered()),
                                                     12, MidpointRounding.AwayFromZero));
                }
                line.SetLine(_line + orderLine.GetLine());
                //Amit 27-jan-2014
                if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='DTD001_'")) > 0)
                {
                    line.SetDTD001_IsAttributeNo(true);
                }
                if (!line.Save())
                {
                    //throw new Exception("Could not create Shipment Line");
                    log.Fine("Failed: Could not create Shipment Line against Order No : " + order.GetDocumentNo() + " for orderline id : " + orderLine.GetC_OrderLine_ID());
                    return;
                }
                log.Fine(line.ToString());
                return;
            }

            //	Product
            MProduct product    = orderLine.GetProduct();
            bool     linePerASI = false;

            if (product.GetM_AttributeSet_ID() != 0)
            {
                MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                linePerASI = mas.IsInstanceAttribute();
            }

            //	Inventory Lines
            List <MInOutLine> list      = new List <MInOutLine>();
            Decimal           toDeliver = qty;

            for (int i = 0; i < storages.Length; i++)
            {
                MStorage storage = storages[i];
                Decimal  deliver = toDeliver;
                //	Not enough On Hand
                if (deliver.CompareTo(storage.GetQtyOnHand()) > 0 &&
                    Env.Signum(storage.GetQtyOnHand()) >= 0)            //	positive storage
                {
                    if (!force || //	Adjust to OnHand Qty
                        (i + 1 != storages.Length))     //	if force don't adjust last location
                    {
                        deliver = storage.GetQtyOnHand();
                    }
                }
                if (Env.Signum(deliver) == 0)   //	zero deliver
                {
                    continue;
                }

                int M_Locator_ID = storage.GetM_Locator_ID();
                //
                MInOutLine line = null;
                if (!linePerASI)        //	find line with Locator
                {
                    for (int n = 0; n < list.Count; n++)
                    {
                        MInOutLine test = (MInOutLine)list[n];
                        if (test.GetM_Locator_ID() == M_Locator_ID)
                        {
                            line = test;
                            break;
                        }
                    }
                }
                if (line == null)       //	new line
                {
                    line = new MInOutLine(_shipment);
                    line.SetOrderLine(orderLine, M_Locator_ID, order.IsSOTrx() ? deliver : Env.ZERO);
                    line.SetQty(deliver);
                    list.Add(line);
                }
                else
                {
                    //	existing line
                    line.SetQty(Decimal.Add(line.GetMovementQty(), deliver));
                }
                if (orderLine.GetQtyEntered().CompareTo(orderLine.GetQtyOrdered()) != 0)
                {
                    line.SetQtyEntered(Decimal.Round(Decimal.Divide(Decimal.Multiply(line.GetMovementQty(), orderLine.GetQtyEntered()),
                                                                    orderLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero));
                }

                line.SetLine(_line + orderLine.GetLine());
                if (linePerASI)
                {
                    line.SetM_AttributeSetInstance_ID(storage.GetM_AttributeSetInstance_ID());
                }

                //Amit 27-jan-2014
                if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='DTD001_'")) > 0)
                {
                    line.SetDTD001_IsAttributeNo(true);
                }

                if (!line.Save())
                {
                    //throw new Exception("Could not create Shipment Line");
                    log.Fine("Failed: Could not create Shipment Line against Order No : " + order.GetDocumentNo() + " for orderline id : " + orderLine.GetC_OrderLine_ID());
                }
                log.Fine("ToDeliver=" + qty + "/" + deliver + " - " + line);
                toDeliver = Decimal.Subtract(toDeliver, deliver);
                //	Temp adjustment
                storage.SetQtyOnHand(Decimal.Subtract(storage.GetQtyOnHand(), deliver));
                //
                if (Env.Signum(toDeliver) == 0)
                {
                    break;
                }
            }
            if (Env.Signum(toDeliver) != 0)
            {
                throw new Exception("Not All Delivered - Remainder=" + toDeliver);
            }
        }
コード例 #10
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);
        }