Exemplo n.º 1
0
        /// <summary>
        /// GetOrderLine
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public Dictionary <String, String> GetOrderLine(Ctx ctx, string param)
        {
            string[] paramValue = param.Split(',');

            Dictionary <String, String> retDic = new Dictionary <string, string>();

            //Assign parameter value
            int id;

            id = Util.GetValueOfInt(paramValue[0].ToString());
            //End Assign parameter value

            MOrderLine orderline = new MOrderLine(ctx, id, null);

            retDic["C_Tax_ID"]                  = Util.GetValueOfString(orderline.GetC_Tax_ID());
            retDic["PriceList"]                 = Util.GetValueOfString(orderline.GetPriceList());
            retDic["PriceLimit"]                = Util.GetValueOfString(orderline.GetPriceLimit());
            retDic["PriceActual"]               = Util.GetValueOfString(orderline.GetPriceActual());
            retDic["PriceEntered"]              = Util.GetValueOfString(orderline.GetPriceEntered());
            retDic["C_Currency_ID"]             = Util.GetValueOfString(orderline.GetC_Currency_ID());
            retDic["Discount"]                  = Util.GetValueOfString(orderline.GetDiscount());
            retDic["Discount"]                  = Util.GetValueOfString(orderline.GetDiscount());
            retDic["M_Product_ID"]              = Util.GetValueOfString(orderline.GetM_Product_ID());
            retDic["Qty"]                       = Util.GetValueOfString(orderline.GetQtyEntered());
            retDic["C_UOM_ID"]                  = Util.GetValueOfString(orderline.GetC_UOM_ID());
            retDic["C_BPartner_ID"]             = Util.GetValueOfString(orderline.GetC_BPartner_ID());
            retDic["PlannedHours"]              = Util.GetValueOfString(orderline.GetQtyOrdered());
            retDic["M_AttributeSetInstance_ID"] = Util.GetValueOfString(orderline.GetM_AttributeSetInstance_ID());
            retDic["QtyOrdered"]                = Util.GetValueOfString(orderline.GetQtyOrdered());
            retDic["QtyDelivered"]              = Util.GetValueOfString(orderline.GetQtyDelivered());
            retDic["QtyEntered"]                = Util.GetValueOfString(orderline.GetQtyEntered());
            retDic["C_Activity_ID"]             = Util.GetValueOfString(orderline.GetC_Activity_ID());
            retDic["C_Campaign_ID"]             = Util.GetValueOfString(orderline.GetC_Campaign_ID());
            retDic["C_Project_ID"]              = Util.GetValueOfString(orderline.GetC_Project_ID());
            retDic["C_ProjectPhase_ID"]         = Util.GetValueOfString(orderline.GetC_ProjectPhase_ID());
            retDic["C_ProjectTask_ID"]          = Util.GetValueOfString(orderline.GetC_ProjectTask_ID());
            retDic["AD_OrgTrx_ID"]              = Util.GetValueOfString(orderline.GetAD_OrgTrx_ID());
            retDic["User1_ID"]                  = Util.GetValueOfString(orderline.GetUser1_ID());
            retDic["User2_ID"]                  = Util.GetValueOfString(orderline.GetUser2_ID());
            retDic["IsReturnTrx"]               = Util.GetValueOfString(orderline.GetParent().IsReturnTrx()).ToLower();
            retDic["Orig_InOutLine_ID"]         = Util.GetValueOfString(orderline.GetOrig_InOutLine_ID());
            retDic["Orig_OrderLine_ID"]         = Util.GetValueOfString(orderline.GetOrig_OrderLine_ID());
            retDic["GetID"]                     = Util.GetValueOfString(orderline.Get_ID());

            return(retDic);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create Facts (the accounting logic) for
        ///  MXP.
        ///  <pre>
        ///      Product PPV     <difference>
        ///      PPV_Offset                  <difference>
        ///  </pre>
        /// </summary>
        /// <param name="as1"></param>
        /// <returns></returns>
        public override List <Fact> CreateFacts(MAcctSchema as1)
        {
            List <Fact> facts = new List <Fact>();

            //
            if (GetM_Product_ID() == 0 ||       //  Nothing to do if no Product
                Env.Signum(Utility.Util.GetValueOfDecimal(GetQty())) == 0 ||
                _M_InOutLine_ID == 0)           //  No posting if not matched to Shipment
            {
                log.Fine("No Product/Qty - M_Product_ID=" + GetM_Product_ID()
                         + ",Qty=" + GetQty());
                return(facts);
            }

            //  create Fact Header
            Fact fact = new Fact(this, as1, Fact.POST_Actual);

            SetC_Currency_ID(as1.GetC_Currency_ID());

            //	Purchase Order Line
            Decimal poCost = _oLine.GetPriceCost();

            if (Env.Signum(poCost) == 0)
            {
                poCost = _oLine.GetPriceActual();
            }
            poCost = Decimal.Multiply(poCost, Utility.Util.GetValueOfDecimal(GetQty()));                 //	Delivered so far
            //	Different currency
            if (_oLine.GetC_Currency_ID() != as1.GetC_Currency_ID())
            {
                MOrder  order = _oLine.GetParent();
                Decimal rate  = MConversionRate.GetRate(
                    order.GetC_Currency_ID(), as1.GetC_Currency_ID(),
                    order.GetDateAcct(), order.GetC_ConversionType_ID(),
                    _oLine.GetAD_Client_ID(), _oLine.GetAD_Org_ID());
                if (rate.ToString() == null)
                {
                    _error = "Purchase Order not convertible - " + as1.GetName();
                    return(null);
                }
                poCost = Decimal.Multiply(poCost, rate);
                if (Env.Scale(poCost) > as1.GetCostingPrecision())
                {
                    poCost = Decimal.Round(poCost, as1.GetCostingPrecision(), MidpointRounding.AwayFromZero);
                }
            }

            MOrder order1      = _oLine.GetParent();
            bool   isReturnTrx = order1.IsReturnTrx();

            log.Fine("Temp");

            if (!IsPosted())
            {
                //	Create PO Cost Detail Record firs
                MCostDetail.CreateOrder(as1, _oLine.GetAD_Org_ID(),
                                        GetM_Product_ID(), _M_AttributeSetInstance_ID,
                                        _C_OrderLine_ID, 0,                                                                                                                                               //	no cost element
                                        isReturnTrx ? Decimal.Negate(poCost) : poCost, isReturnTrx ? Decimal.Negate(Utility.Util.GetValueOfDecimal(GetQty())) : Utility.Util.GetValueOfDecimal(GetQty()), //	Delivered
                                        _oLine.GetDescription(), GetTrx(), GetRectifyingProcess());
            }


            //	Current Costs
            String               costingMethod = as1.GetCostingMethod();
            MProduct             product       = MProduct.Get(GetCtx(), GetM_Product_ID());
            MProductCategoryAcct pca           = MProductCategoryAcct.Get(GetCtx(),
                                                                          product.GetM_Product_Category_ID(), as1.GetC_AcctSchema_ID(), GetTrx());

            if (pca.GetCostingMethod() != null)
            {
                costingMethod = pca.GetCostingMethod();
            }
            Decimal?costs = _pc.GetProductCosts(as1, GetAD_Org_ID(), costingMethod, _C_OrderLine_ID, false);    //	non-zero costs

            //	No Costs yet - no PPV
            if (costs == null || Env.Signum(Utility.Util.GetValueOfDecimal(costs)) == 0)
            {
                _error = "Resubmit - No Costs for " + product.GetName();
                log.Log(Level.SEVERE, _error);
                return(null);
            }

            //	Difference
            Decimal difference = Decimal.Subtract(poCost, Utility.Util.GetValueOfDecimal(costs));


            /***********************************************************************************/
            //05,Sep,2011
            //Special Check to restic Price varience posting in case of
            //AvarageInvoice Selected on product Category.Then Neglact the AverageInvoice Cost

            try
            {
                if (as1.IsNotPostPOVariance())
                {
                    difference = 0;
                }
            }
            catch (Exception ex)
            {
                log.SaveError("AccountSchemaColumnError", ex);
            }
            /***********************************************************************************/
            //	Nothing to post
            if (Env.Signum(difference) == 0)
            {
                log.Log(Level.FINE, "No Cost Difference for M_Product_ID=" + GetM_Product_ID());
                facts.Add(fact);
                return(facts);
            }

            //  Product PPV
            FactLine cr = fact.CreateLine(null,
                                          _pc.GetAccount(ProductCost.ACCTTYPE_P_PPV, as1),
                                          as1.GetC_Currency_ID(), difference);

            if (cr != null)
            {
                cr.SetQty(GetQty());
                cr.SetC_BPartner_ID(_oLine.GetC_BPartner_ID());
                cr.SetC_Activity_ID(_oLine.GetC_Activity_ID());
                cr.SetC_Campaign_ID(_oLine.GetC_Campaign_ID());
                cr.SetC_Project_ID(_oLine.GetC_Project_ID());
                cr.SetC_UOM_ID(_oLine.GetC_UOM_ID());
                cr.SetUser1_ID(_oLine.GetUser1_ID());
                cr.SetUser2_ID(_oLine.GetUser2_ID());
            }

            //  PPV Offset
            FactLine dr = fact.CreateLine(null,
                                          GetAccount(Doc.ACCTTYPE_PPVOffset, as1),
                                          as1.GetC_Currency_ID(), Decimal.Negate(difference));

            if (dr != null)
            {
                dr.SetQty((Decimal?)Decimal.Negate(Utility.Util.GetValueOfDecimal(GetQty())));

                dr.SetC_BPartner_ID(_oLine.GetC_BPartner_ID());
                dr.SetC_Activity_ID(_oLine.GetC_Activity_ID());
                dr.SetC_Campaign_ID(_oLine.GetC_Campaign_ID());
                dr.SetC_Project_ID(_oLine.GetC_Project_ID());
                dr.SetC_UOM_ID(_oLine.GetC_UOM_ID());
                dr.SetUser1_ID(_oLine.GetUser1_ID());
                dr.SetUser2_ID(_oLine.GetUser2_ID());
            }
            //
            facts.Add(fact);
            return(facts);
        }
Exemplo n.º 3
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());
                }
                if (!_shipment.Save())
                {
                    throw new Exception("Could not create Shipment");
                }
            }
            //	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(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("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);
            }
        }