public Dictionary <string, string> GetProduct(Ctx ctx, string fields)
        {
            string[] paramValue = fields.Split(',');

            //Assign parameter value
            int M_Product_ID   = Util.GetValueOfInt(paramValue[0].ToString());
            int M_Warehouse_ID = 0;

            if (paramValue.Length > 1)
            {
                M_Warehouse_ID = Util.GetValueOfInt(paramValue[1].ToString());
            }
            //End Assign parameter value

            MProduct product = MProduct.Get(ctx, M_Product_ID);
            Dictionary <string, string> result = new Dictionary <string, string>();

            result["C_UOM_ID"]  = product.GetC_UOM_ID().ToString();
            result["IsStocked"] = product.IsStocked() ? "Y" : "N";
            if (M_Product_ID > 0)
            {
                if (M_Warehouse_ID > 0)
                {
                    result["M_Locator_ID"] = MProductLocator.GetFirstM_Locator_ID(product, M_Warehouse_ID).ToString();
                }
            }
            return(result);
        }
        public JsonResult GetProduct(string fields)
        {
            string retError = "";
            string retJSON  = "";

            if (Session["ctx"] != null)
            {
                VAdvantage.Utility.Ctx ctx = Session["ctx"] as Ctx;
                string[] paramValue        = fields.Split(',');
                int      M_Product_ID;

                //Assign parameter value
                M_Product_ID = Util.GetValueOfInt(paramValue[0].ToString());
                MProduct product = MProduct.Get(ctx, M_Product_ID);


                Dictionary <String, String> retPDic = new Dictionary <string, string>();
                retPDic["IsStocked"] = product.IsStocked().ToString();
                //retlst.Add(retValue);

                //retVal.Add(notReserved);


                retJSON = JsonConvert.SerializeObject(retPDic);
            }
            else
            {
                retError = "Session Expired";
            }
            return(Json(new { result = retJSON, error = retError }, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// GetProductPricing
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public ProductDataOut GetProductPricing(Ctx ctx, string fields)
        {
            string[] paramValue = fields.Split(',');
            int      M_Product_ID, C_BPartner_ID, M_PriceList_ID, M_PriceList_Version_ID, M_AttributeSetInstance_ID = 0, countED011 = 0, C_UOM_ID = 0;
            decimal  Qty;
            bool     isSOTrx;

            //Assign parameter value
            M_Product_ID           = Util.GetValueOfInt(paramValue[0].ToString());
            C_BPartner_ID          = Util.GetValueOfInt(paramValue[1].ToString());
            Qty                    = Util.GetValueOfDecimal(paramValue[2].ToString());
            isSOTrx                = Convert.ToBoolean(paramValue[3]);
            M_PriceList_ID         = Util.GetValueOfInt(paramValue[4].ToString());
            M_PriceList_Version_ID = Util.GetValueOfInt(paramValue[5].ToString());
            DateTime?orderDate  = Util.GetValueOfDateTime(paramValue[6]);
            DateTime?orderDate1 = Util.GetValueOfDateTime(paramValue[7]);

            //if (paramValue.Length > 8)
            if (paramValue.Length == 9 || paramValue.Length == 11)
            {
                M_AttributeSetInstance_ID = Util.GetValueOfInt(paramValue[8].ToString());
            }

            if (paramValue.Length > 9)
            {
                if (paramValue.Length == 11)
                {
                    C_UOM_ID   = Util.GetValueOfInt(paramValue[9].ToString());
                    countED011 = Util.GetValueOfInt(paramValue[10].ToString());
                }
                else if (paramValue.Length == 10)
                {
                    C_UOM_ID   = Util.GetValueOfInt(paramValue[8].ToString());
                    countED011 = Util.GetValueOfInt(paramValue[9].ToString());
                }
            }

            /** Price List - ValidFrom date validation ** Dt:01/02/2021 ** Modified By: Kumar **/
            if (!string.IsNullOrEmpty(Util.GetValueOfString(orderDate)))
            {
                StringBuilder sbparams = new StringBuilder();
                sbparams.Append(Util.GetValueOfInt(M_PriceList_ID));
                sbparams.Append(",").Append(Convert.ToDateTime(orderDate).ToString("MM-dd-yyyy"));
                sbparams.Append(",").Append(Util.GetValueOfInt(M_Product_ID));
                sbparams.Append(",").Append(Util.GetValueOfInt(C_UOM_ID));
                sbparams.Append(",").Append(Util.GetValueOfInt(M_AttributeSetInstance_ID));
                MPriceListVersionModel objPriceList = new MPriceListVersionModel();
                M_PriceList_Version_ID = objPriceList.GetM_PriceList_Version_ID_On_Transaction_Date(ctx, sbparams.ToString());
            }

            //End Assign parameter value

            MProductPricing pp = new MProductPricing(ctx.GetAD_Client_ID(), ctx.GetAD_Org_ID(),
                                                     M_Product_ID, C_BPartner_ID, Qty, isSOTrx);

            //var M_PriceList_ID = ctx.GetContextAsInt(WindowNo, "M_PriceList_ID");
            pp.SetM_PriceList_ID(M_PriceList_ID);
            /** PLV is only accurate if PL selected in header */
            //var M_PriceList_Version_ID = ctx.GetContextAsInt(WindowNo, "M_PriceList_Version_ID");
            pp.SetM_PriceList_Version_ID(M_PriceList_Version_ID);

            //if (paramValue.Length > 8)
            if (paramValue.Length == 9 || paramValue.Length == 11)
            {
                pp.SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
            }
            //var orderDate = System.Convert.ToDateTime(mTab.getValue("DateOrdered"));
            pp.SetPriceDate(orderDate);
            pp.SetPriceDate1(orderDate1);

            if (countED011 > 0)
            {
                pp.SetC_UOM_ID(C_UOM_ID);
            }

            //Get product stock
            MProduct product = MProduct.Get(ctx, M_Product_ID);


            ProductDataOut objInfo = new ProductDataOut
            {
                //** Price List - ValidFrom date : return 0 when plv is not available ** Dt:03/26/2021 ** Modified By: Kumar **//

                PriceList     = (M_PriceList_Version_ID == 0 ? 0: pp.GetPriceList()),
                PriceLimit    = (M_PriceList_Version_ID == 0 ? 0 : pp.GetPriceLimit()),
                PriceActual   = (M_PriceList_Version_ID == 0 ? 0 : pp.GetPriceStd()),
                PriceEntered  = (M_PriceList_Version_ID == 0 ? 0 : pp.GetPriceStd()),
                PriceStd      = (M_PriceList_Version_ID == 0 ? 0 : pp.GetPriceStd()),
                LineAmt       = pp.GetLineAmt(2),
                C_Currency_ID = System.Convert.ToInt32(pp.GetC_Currency_ID()),
                Discount      = pp.GetDiscount(),
                C_UOM_ID      = System.Convert.ToInt32(pp.GetC_UOM_ID()),
                //QtyOrdered= mTab.GetValue("QtyEntered"));
                EnforcePriceLimit = pp.IsEnforcePriceLimit(),
                DiscountSchema    = pp.IsDiscountSchema(),
                IsStocked         = product.IsStocked()
            };

            product = null;
            pp      = null;
            return(objInfo);
        }
        /// <summary>
        /// GetProductPricing
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public ProductDataOut GetProductPricing(Ctx ctx, string fields)
        {
            string[] paramValue = fields.Split(',');
            int      M_Product_ID, C_BPartner_ID, M_PriceList_ID, M_PriceList_Version_ID, M_AttributeSetInstance_ID = 0;
            decimal  Qty;
            bool     isSOTrx;

            //Assign parameter value
            M_Product_ID           = Util.GetValueOfInt(paramValue[0].ToString());
            C_BPartner_ID          = Util.GetValueOfInt(paramValue[1].ToString());
            Qty                    = Util.GetValueOfDecimal(paramValue[2].ToString());
            isSOTrx                = Convert.ToBoolean(paramValue[3]);
            M_PriceList_ID         = Util.GetValueOfInt(paramValue[4].ToString());
            M_PriceList_Version_ID = Util.GetValueOfInt(paramValue[5].ToString());
            DateTime?orderDate  = Util.GetValueOfDateTime(paramValue[6]);
            DateTime?orderDate1 = Util.GetValueOfDateTime(paramValue[7]);

            if (paramValue.Length > 8)
            {
                M_AttributeSetInstance_ID = Util.GetValueOfInt(paramValue[8].ToString());
            }
            //End Assign parameter value

            MProductPricing pp = new MProductPricing(ctx.GetAD_Client_ID(), ctx.GetAD_Org_ID(),
                                                     M_Product_ID, C_BPartner_ID, Qty, isSOTrx);

            //var M_PriceList_ID = ctx.GetContextAsInt(WindowNo, "M_PriceList_ID");
            pp.SetM_PriceList_ID(M_PriceList_ID);
            /** PLV is only accurate if PL selected in header */
            //var M_PriceList_Version_ID = ctx.GetContextAsInt(WindowNo, "M_PriceList_Version_ID");
            pp.SetM_PriceList_Version_ID(M_PriceList_Version_ID);
            if (paramValue.Length > 8)
            {
                pp.SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
            }
            //var orderDate = System.Convert.ToDateTime(mTab.getValue("DateOrdered"));
            pp.SetPriceDate(orderDate);
            pp.SetPriceDate1(orderDate1);

            //Get product stock
            MProduct product = MProduct.Get(ctx, M_Product_ID);


            ProductDataOut objInfo = new ProductDataOut
            {
                PriceList     = pp.GetPriceList(),
                PriceLimit    = pp.GetPriceLimit(),
                PriceActual   = pp.GetPriceStd(),
                PriceEntered  = pp.GetPriceStd(),
                PriceStd      = pp.GetPriceStd(),
                LineAmt       = pp.GetLineAmt(2),
                C_Currency_ID = System.Convert.ToInt32(pp.GetC_Currency_ID()),
                Discount      = pp.GetDiscount(),
                C_UOM_ID      = System.Convert.ToInt32(pp.GetC_UOM_ID()),
                //QtyOrdered= mTab.GetValue("QtyEntered"));
                EnforcePriceLimit = pp.IsEnforcePriceLimit(),
                DiscountSchema    = pp.IsDiscountSchema(),
                IsStocked         = product.IsStocked()
            };

            product = null;
            pp      = null;
            return(objInfo);
        }
        /// <summary>
        /// Create Facts (the accounting logic) for
        /// MMS, MMR.
        /// <pre>
        /// Shipment
        /// CoGS (RevOrg)   DR
        /// Inventory               CR
        /// Shipment of Project Issue
        /// CoGS            DR
        /// Project                 CR
        /// Receipt
        /// Inventory       DR
        /// NotInvoicedReceipt      CR
        /// </pre>
        /// </summary>
        /// <param name="as1">accounting schema</param>
        /// <returns>Fact</returns>
        public override List <Fact> CreateFacts(MAcctSchema as1)
        {
            //  create Fact Header
            Fact fact = new Fact(this, as1, Fact.POST_Actual);

            SetC_Currency_ID(as1.GetC_Currency_ID());

            //  Line pointers
            FactLine dr = null;
            FactLine cr = null;

            //  *** Sales - Shipment
            if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_MATERIALDELIVERY))
            {
                for (int i = 0; i < _lines.Length; i++)
                {
                    DocLine    line  = _lines[i];
                    MInOutLine sLine = new MInOutLine(GetCtx(), line.Get_ID(), null);
                    Decimal    costs = 0;
                    if (sLine.GetA_Asset_ID() > 0)
                    {
                        costs = Util.GetValueOfDecimal(DB.ExecuteScalar(@"SELECT cost.CUrrentcostPrice
                                                                            FROM m_cost cost
                                                                            INNER JOIN A_Asset ass
                                                                            ON(ass.a_asset_ID=cost.a_asset_ID)
                                                                            INNER JOIN M_InOutLine IOL
                                                                            ON(IOL.A_Asset_ID       =ass.A_Asset_ID)
                                                                            WHERE IOL.M_InOutLine_ID=" + sLine.GetM_InOutLine_ID() + @"
                                                                              ORDER By cost.created desc"));
                        // Change if Cost not found against Asset then get Product Cost
                        if (Env.Signum(costs) == 0)     //	zero costs OK
                        {
                            costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), true);
                        }
                    }
                    else
                    {
                        costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), true);
                    }

                    if (Env.Signum(costs) == 0) //	zero costs OK
                    {
                        MProduct product = line.GetProduct();
                        if (product.IsStocked())
                        {
                            _error = "No Costs for " + line.GetProduct().GetName();
                            log.Log(Level.WARNING, _error);
                            return(null);
                        }
                        else    //	ignore service
                        {
                            continue;
                        }
                    }

                    if (!IsReturnTrx())
                    {
                        //  CoGS            DR
                        dr = fact.CreateLine(line,
                                             line.GetAccount(ProductCost.ACCTTYPE_P_Cogs, as1),
                                             as1.GetC_Currency_ID(), costs, null);
                        if (dr == null)
                        {
                            _error = "FactLine DR not created: " + line;
                            log.Log(Level.WARNING, _error);
                            return(null);
                        }
                        dr.SetM_Locator_ID(line.GetM_Locator_ID());
                        dr.SetLocationFromLocator(line.GetM_Locator_ID(), true);        //  from Loc
                        dr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); //  to Loc
                        dr.SetAD_Org_ID(line.GetOrder_Org_ID());                        //	Revenue X-Org
                        dr.SetQty(Decimal.Negate(line.GetQty().Value));

                        //  Inventory               CR
                        cr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1),
                                             as1.GetC_Currency_ID(), null, costs);
                        if (cr == null)
                        {
                            _error = "FactLine CR not created: " + line;
                            log.Log(Level.WARNING, _error);
                            return(null);
                        }
                        cr.SetM_Locator_ID(line.GetM_Locator_ID());
                        cr.SetLocationFromLocator(line.GetM_Locator_ID(), true);        // from Loc
                        cr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc
                    }
                    else // Reverse accounting entries for returns
                    {
                        //				  CoGS            CR
                        cr = fact.CreateLine(line,
                                             line.GetAccount(ProductCost.ACCTTYPE_P_Cogs, as1),
                                             as1.GetC_Currency_ID(), null, costs);
                        if (cr == null)
                        {
                            _error = "FactLine CR not created: " + line;
                            log.Log(Level.WARNING, _error);
                            return(null);
                        }
                        cr.SetM_Locator_ID(line.GetM_Locator_ID());
                        cr.SetLocationFromLocator(line.GetM_Locator_ID(), true);        //  from Loc
                        cr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); //  to Loc
                        cr.SetAD_Org_ID(line.GetOrder_Org_ID());                        //	Revenue X-Org
                        cr.SetQty(Decimal.Negate(line.GetQty().Value));

                        //  Inventory               DR
                        dr = fact.CreateLine(line,
                                             line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1),
                                             as1.GetC_Currency_ID(), costs, null);
                        if (dr == null)
                        {
                            _error = "FactLine DR not created: " + line;
                            log.Log(Level.WARNING, _error);
                            return(null);
                        }
                        dr.SetM_Locator_ID(line.GetM_Locator_ID());
                        dr.SetLocationFromLocator(line.GetM_Locator_ID(), true);        // from Loc
                        dr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc
                    }
                    //
                    if (line.GetM_Product_ID() != 0)
                    {
                        if (!IsPosted())
                        {
                            MCostDetail.CreateShipment(as1, line.GetAD_Org_ID(),
                                                       line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(),
                                                       line.Get_ID(), 0,
                                                       costs, IsReturnTrx() ? Decimal.Negate(line.GetQty().Value) : line.GetQty().Value,
                                                       line.GetDescription(), true, GetTrx(), GetRectifyingProcess());
                        }
                    }
                }       //	for all lines

                if (!IsPosted())
                {
                    UpdateProductInfo(as1.GetC_AcctSchema_ID()); //  only for SO!
                }
            }                                                    //	Shipment

            //  *** Purchasing - Receipt
            else if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_MATERIALRECEIPT))
            {
                for (int i = 0; i < _lines.Length; i++)
                {
                    Decimal  costs   = 0;
                    DocLine  line    = _lines[i];
                    MProduct product = line.GetProduct();
                    /***********************************************************/
                    //05,Sep,2011
                    //Special Check to restic Price varience posting in case of
                    //AvarageInvoice Selected on product Category.Then Neglact the AverageInvoice Cost
                    MProductCategoryAcct pca = MProductCategoryAcct.Get(product.GetCtx(),
                                                                        product.GetM_Product_Category_ID(), as1.GetC_AcctSchema_ID(), null);
                    try
                    {
                        if (as1.IsNotPostPOVariance() && line.GetC_OrderLine_ID() > 0)
                        {
                            MOrderLine oLine         = new MOrderLine(product.GetCtx(), line.GetC_OrderLine_ID(), null);
                            MOrder     order         = new MOrder(product.GetCtx(), oLine.GetC_Order_ID(), null);
                            Decimal    convertedCost = MConversionRate.Convert(product.GetCtx(),
                                                                               oLine.GetPriceEntered(), order.GetC_Currency_ID(), as1.GetC_Currency_ID(),
                                                                               line.GetDateAcct(), order.GetC_ConversionType_ID(),
                                                                               oLine.GetAD_Client_ID(), line.GetAD_Org_ID());

                            costs = Decimal.Multiply(convertedCost, oLine.GetQtyEntered());
                        }
                        else
                        {
                            costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false);      //	non-zero costs
                        }
                    }
                    catch (Exception ex)
                    {
                        log.SaveError("AccountSchemaColumnError", ex);
                        costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false);  //	non-zero costs
                    }
                    /***********************************************************/

                    //Decimal costs = costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false);	//	non-zero costs

                    if (Env.Signum(costs) == 0)
                    {
                        _error = "Resubmit - No Costs for " + product.GetName();
                        log.Log(Level.WARNING, _error);
                        return(null);
                    }
                    //  Inventory/Asset			DR
                    MAccount assets = line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1);
                    if (product.IsService())
                    {
                        assets = line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1);
                    }

                    if (!IsReturnTrx())
                    {
                        //  Inventory/Asset			DR
                        dr = fact.CreateLine(line, assets,
                                             as1.GetC_Currency_ID(), costs, null);
                        if (dr == null)
                        {
                            _error = "DR not created: " + line;
                            log.Log(Level.WARNING, _error);
                            return(null);
                        }
                        dr.SetM_Locator_ID(line.GetM_Locator_ID());
                        dr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc
                        dr.SetLocationFromLocator(line.GetM_Locator_ID(), false);      // to Loc
                        //  NotInvoicedReceipt				CR
                        cr = fact.CreateLine(line,
                                             GetAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as1),
                                             as1.GetC_Currency_ID(), null, costs);
                        if (cr == null)
                        {
                            _error = "CR not created: " + line;
                            log.Log(Level.WARNING, _error);
                            return(null);
                        }
                        cr.SetM_Locator_ID(line.GetM_Locator_ID());
                        cr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); //  from Loc
                        cr.SetLocationFromLocator(line.GetM_Locator_ID(), false);      //  to Loc
                        cr.SetQty(Decimal.Negate(line.GetQty().Value));
                    }
                    else // reverse accounting entries for returns
                    {
                        //  Inventory/Asset			CR
                        cr = fact.CreateLine(line, assets,
                                             as1.GetC_Currency_ID(), null, costs);
                        if (cr == null)
                        {
                            _error = "CR not created: " + line;
                            log.Log(Level.WARNING, _error);
                            return(null);
                        }
                        cr.SetM_Locator_ID(line.GetM_Locator_ID());
                        cr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc
                        cr.SetLocationFromLocator(line.GetM_Locator_ID(), false);      // to Loc
                        //  NotInvoicedReceipt				DR
                        dr = fact.CreateLine(line,
                                             GetAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as1),
                                             as1.GetC_Currency_ID(), costs, null);
                        if (dr == null)
                        {
                            _error = "DR not created: " + line;
                            log.Log(Level.WARNING, _error);
                            return(null);
                        }
                        dr.SetM_Locator_ID(line.GetM_Locator_ID());
                        dr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); //  from Loc
                        dr.SetLocationFromLocator(line.GetM_Locator_ID(), false);      //  to Loc
                        dr.SetQty(Decimal.Negate(line.GetQty().Value));
                    }
                }
            }   //	Receipt
            else
            {
                _error = "DocumentType unknown: " + GetDocumentType();
                log.Log(Level.SEVERE, _error);
                return(null);
            }
            //
            List <Fact> facts = new List <Fact>();

            facts.Add(fact);
            return(facts);
        }
Exemple #6
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);
        }
Exemple #7
0
        public JsonResult GetProductPricing(string fields)
        {
            string retError = "";
            string retJSON  = "";

            if (Session["ctx"] != null)
            {
                VAdvantage.Utility.Ctx ctx = Session["ctx"] as Ctx;
                string[] paramValue = fields.Split(',');
                int      M_Product_ID, C_BPartner_ID, M_PriceList_ID, M_PriceList_Version_ID;
                decimal  Qty;
                bool     isSOTrx;

                //Assign parameter value
                M_Product_ID           = Util.GetValueOfInt(paramValue[0].ToString());
                C_BPartner_ID          = Util.GetValueOfInt(paramValue[1].ToString());
                Qty                    = Util.GetValueOfDecimal(paramValue[2].ToString());
                isSOTrx                = Util.GetValueOfBool(paramValue[3].ToString());
                M_PriceList_ID         = Util.GetValueOfInt(paramValue[4].ToString());
                M_PriceList_Version_ID = Util.GetValueOfInt(paramValue[5].ToString());
                DateTime orderDate = System.Convert.ToDateTime(paramValue[6].ToString());

                //End Assign parameter value

                MProductPricing pp = new MProductPricing(ctx.GetAD_Client_ID(), ctx.GetAD_Org_ID(),
                                                         M_Product_ID, C_BPartner_ID, Qty, isSOTrx);

                //var M_PriceList_ID = ctx.GetContextAsInt(WindowNo, "M_PriceList_ID");
                pp.SetM_PriceList_ID(M_PriceList_ID);
                /** PLV is only accurate if PL selected in header */
                //var M_PriceList_Version_ID = ctx.GetContextAsInt(WindowNo, "M_PriceList_Version_ID");
                pp.SetM_PriceList_Version_ID(M_PriceList_Version_ID);

                //var orderDate = System.Convert.ToDateTime(mTab.getValue("DateOrdered"));
                pp.SetPriceDate(orderDate);

                //Get product stock
                MProduct product = MProduct.Get(ctx, M_Product_ID);


                VIS.DataContracts.ProductDataOut objInfo = new VIS.DataContracts.ProductDataOut
                {
                    PriceList     = pp.GetPriceList(),
                    PriceLimit    = pp.GetPriceLimit(),
                    PriceActual   = pp.GetPriceStd(),
                    PriceEntered  = pp.GetPriceStd(),
                    PriceStd      = pp.GetPriceStd(),
                    C_Currency_ID = System.Convert.ToInt32(pp.GetC_Currency_ID()),
                    Discount      = pp.GetDiscount(),

                    C_UOM_ID = System.Convert.ToInt32(pp.GetC_UOM_ID()),
                    //QtyOrdered= mTab.GetValue("QtyEntered"));
                    EnforcePriceLimit = pp.IsEnforcePriceLimit(),
                    DiscountSchema    = pp.IsDiscountSchema(),
                    IsStocked         = product.IsStocked()
                };
                product = null;
                pp      = null;
                retJSON = JsonConvert.SerializeObject(objInfo);
            }
            else
            {
                retError = "Session Expired";
            }
            return(Json(new { result = retJSON, error = retError }, JsonRequestBehavior.AllowGet));
        }