示例#1
0
 /// <summary>
 /// Validate Old BOM Product structure
 /// </summary>
 /// <param name="product">product</param>
 /// <returns>true if valid</returns>
 private bool ValidateOldProduct(MProduct product)
 {
     if (!product.IsBOM())
     {
         return(true);
     }
     //
     if (_products.Contains(product))
     {
         log.Warning(_product.GetName() + " recursively includes " + product.GetName());
         return(false);
     }
     _products.Add(product);
     log.Fine(product.GetName());
     //
     MProductBOM[] productsBOMs = MProductBOM.GetBOMLines(product);
     for (int i = 0; i < productsBOMs.Length; i++)
     {
         MProductBOM productsBOM = productsBOMs[i];
         MProduct    pp          = new MProduct(GetCtx(), productsBOM.GetM_ProductBOM_ID(), Get_Trx());
         if (!pp.IsBOM())
         {
             log.Finer(pp.GetName());
         }
         else if (!ValidateOldProduct(pp))
         {
             return(false);
         }
     }
     return(true);
 }
示例#2
0
        /// <summary>
        /// Validate Product
        /// </summary>
        /// <param name="product">product</param>
        /// <returns>Info</returns>
        private String ValidateProduct(MProduct product)
        {
            if (!product.IsBOM())
            {
                return(product.GetName() + " @NotValid@ @M_BOM_ID@");
            }
            _product = product;
            //	Check Old Product BOM Structure
            log.Config(_product.GetName());
            _products = new List <MProduct>();
            if (!ValidateOldProduct(_product))
            {
                _product.SetIsVerified(false);
                _product.Save();
                return(_product.GetName() + " @NotValid@");
            }

            //	New Structure
            MBOM[] boms = MBOM.GetOfProduct(GetCtx(), _M_Product_ID, Get_Trx(), null);
            for (int i = 0; i < boms.Length; i++)
            {
                _products = new List <MProduct>();
                if (!ValidateBOM(boms[i]))
                {
                    _product.SetIsVerified(false);
                    _product.Save();
                    return(_product.GetName() + " " + boms[i].GetName() + " @NotValid@");
                }
            }

            //	OK
            _product.SetIsVerified(true);
            _product.Save();
            return(_product.GetName() + " @IsValid@");
        }
        /// <summary>
        /// Validate Product
        /// </summary>
        /// <param name="product">product</param>
        /// <returns>Info</returns>
        private String ValidateProduct(MProduct product)
        {
            if (!product.IsBOM())
            {
                return(product.GetName() + " @NotValid@ @M_BOM_ID@");
            }
            _product = product;
            //	Check Old Product BOM Structure
            log.Config(_product.GetName());
            _products = new List <MProduct>();
            if (!ValidateOldProduct(_product))
            {
                _product.SetIsVerified(false);
                _product.Save();
                return(_product.GetName() + " @NotValid@");
            }

            //	New Structure
            MBOM[] boms = MBOM.GetOfProduct(GetCtx(), _M_Product_ID, Get_Trx(), null);
            for (int i = 0; i < boms.Length; i++)
            {
                //When BOM Type = Manufacturing then system will not allow to verify the BOM if sum of component is less or greater then 1
                if (boms[i].GetBOMUse() == "M")
                {
                    _product = product;
                    Decimal count = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT SUM(BOMQty) FROM M_BOMProduct WHERE IsActive = 'Y' AND M_BOM_ID=" + boms[i].GetM_BOM_ID(), null, null));
                    if (count != 1)
                    {
                        _product.SetIsVerified(false);
                        _product.Save();
                        return(_product.GetName() + " " + boms[i].GetName() + " @NotValid@");
                    }
                }

                _products = new List <MProduct>();
                if (!ValidateBOM(boms[i]))
                {
                    _product.SetIsVerified(false);
                    _product.Save();
                    return(_product.GetName() + " " + boms[i].GetName() + " @NotValid@");
                }
            }

            //	OK
            _product.SetIsVerified(true);
            _product.Save();
            return(_product.GetName() + " @IsValid@");
        }
        /// <summary>
        /// Validate Product
        /// </summary>
        /// <param name="product">product</param>
        /// <returns>Info</returns>
        private String ValidateProduct(MProduct product)
        {
            count = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT COUNT(*) FROM AD_MODULEINFO WHERE IsActive = 'Y' AND PREFIX ='VAMFG_'"));

            if (!product.IsBOM())
            {
                return(product.GetName() + " @NotValid@ @M_BOM_ID@");
            }
            _product = product;
            //	Check Old Product BOM Structure
            log.Config(_product.GetName());
            _products = new List <MProduct>();
            if (!ValidateOldProduct(_product))
            {
                _product.SetIsVerified(false);
                _product.Save();
                return(_product.GetName() + " @NotValid@");
            }

            //	New Structure
            MBOM[] boms = MBOM.GetOfProduct(GetCtx(), _M_Product_ID, Get_Trx(), null);
            // if manufacturing module  exist and  BOM not contain any record against this product then not to verify Product
            if (count > 0 && boms.Length == 0)
            {
                _product.SetIsVerified(false);
                _product.Save();
                return(_product.GetName() + " @NotValid@");
            }
            for (int i = 0; i < boms.Length; i++)
            {
                _products = new List <MProduct>();
                if (!ValidateBOM(boms[i]))
                {
                    _product.SetIsVerified(false);
                    _product.Save();
                    return(_product.GetName() + " " + boms[i].GetName() + " @NotValid@");
                }
            }

            //	OK
            _product.SetIsVerified(true);
            _product.Save();
            return(_product.GetName() + " @IsValid@");
        }
        /// <summary>
        /// Validate Product
        /// </summary>
        /// <param name="product">product</param>
        /// <param name="BOMType"></param>
        /// <param name="BOMUse"></param>
        /// <returns>true if valid</returns>
        private bool ValidateProduct(MProduct product, String BOMType, String BOMUse)
        {
            if (!product.IsBOM())
            {
                return(true);
            }
            //
            String restriction = "BOMType='" + BOMType + "' AND BOMUse='" + BOMUse + "'";

            MBOM[] boms = MBOM.GetOfProduct(GetCtx(), _M_Product_ID, Get_Trx(),
                                            restriction);
            if (boms.Length != 1)
            {
                log.Warning(restriction + " - Length=" + boms.Length);
                return(false);
            }
            if (_products.Contains(product))
            {
                log.Warning(_product.GetName() + " recursively includes " + product.GetName());
                return(false);
            }
            _products.Add(product);
            log.Fine(product.GetName());
            //
            MBOM bom = boms[0];

            MBOMProduct[] BOMproducts = MBOMProduct.GetOfBOM(bom);
            for (int i = 0; i < BOMproducts.Length; i++)
            {
                MBOMProduct BOMproduct = BOMproducts[i];
                MProduct    pp         = new MProduct(GetCtx(), BOMproduct.GetM_BOMProduct_ID(), Get_Trx());
                if (pp.IsBOM())
                {
                    return(ValidateProduct(pp, bom.GetBOMType(), bom.GetBOMUse()));
                }
            }
            return(true);
        }
 /// <summary>
 /// Validate Old BOM Product structure
 /// </summary>
 /// <param name="product">product</param>
 /// <returns>true if valid</returns>
 private bool ValidateOldProduct(MProduct product)
 {
     count = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT COUNT(*) FROM AD_MODULEINFO WHERE IsActive = 'Y' AND PREFIX ='VAMFG_'"));
     if (!product.IsBOM())
     {
         return(true);
     }
     //
     if (_products.Contains(product))
     {
         log.Warning(_product.GetName() + " recursively includes " + product.GetName());
         return(false);
     }
     _products.Add(product);
     log.Fine(product.GetName());
     //
     MProductBOM[] productsBOMs = MProductBOM.GetBOMLines(product);
     // if manufacturing module not exist and Product BOM not containany record against this product thennot to verify BOM
     if (count <= 0 && productsBOMs.Length == 0)
     {
         return(false);
     }
     for (int i = 0; i < productsBOMs.Length; i++)
     {
         MProductBOM productsBOM = productsBOMs[i];
         MProduct    pp          = new MProduct(GetCtx(), productsBOM.GetM_ProductBOM_ID(), Get_Trx());
         if (!pp.IsBOM())
         {
             log.Finer(pp.GetName());
         }
         else if (!ValidateOldProduct(pp))
         {
             return(false);
         }
     }
     return(true);
 }
示例#7
0
        /// <summary>
        /// Create Main Panel.
        /// Called when changing Product
        /// </summary>
        public List <BOMLines> CreateMainPanel(Ctx ctx, int productID)
        {
            String title = Msg.GetMsg(ctx, "SelectProduct");

            _product = new MProduct(ctx, productID, null);
            if (_product != null && _product.Get_ID() > 0)
            {
                title = _product.GetName();
                if (_product.GetDescription() != null && _product.GetDescription().Length > 0)
                {
                    //this.setToolTipText(_product.getDescription());
                }
                _bomLine = 0;
                BomLines(ctx, _product, _qty);
            }
            return(lstBOMLines);
        }
示例#8
0
        /// <summary>
        /// Check Qty Availablity in warehouse when Disallow Negative Inventory = true
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="M_Warehouse_ID">warehouse refernce - for checking disallow negative inventory or not</param>
        /// <param name="M_Locator_ID">locator ref - in which locator we have to check stock</param>
        /// <param name="M_Product_ID">product ref -- to which product, need to check stock</param>
        /// <param name="M_AttributeSetInstance_ID">AttributeSetInstance -- to which ASI, need to check stock</param>
        /// <param name="MovementQty">qty to be impacted</param>
        /// <param name="trxName">system transaction</param>
        /// <returns>TRUE/False</returns>
        private bool CheckQtyAvailablity(Ctx ctx, int M_Warehouse_ID, int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID, Decimal?MovementQty, Trx trxName)
        {
            MWarehouse wh      = MWarehouse.Get(ctx, M_Warehouse_ID);
            MProduct   product = null;

            if (wh.IsDisallowNegativeInv() && M_Product_ID > 0)
            {
                product = MProduct.Get(ctx, M_Product_ID);
                string qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + M_Locator_ID + @" and m_product_id=" + M_Product_ID;
                qry += " AND NVL(M_AttributeSetInstance_ID, 0) =" + M_AttributeSetInstance_ID;
                Decimal?OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry, null, trxName));
                if (OnHandQty + MovementQty < 0)
                {
                    log.SaveError("Info", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty);
                    return(false);
                }
            }
            return(true);
        }
示例#9
0
        private void BomLines(Ctx ctx, MProduct product, Decimal qty)
        {
            lstBOMLines = new List <BOMLines>();
            MProductBOM[] bomLines = null;
            bomLines = MProductBOM.GetBOMLines(product);
            MProduct objproduct = null;

            for (int i = 0; i < bomLines.Length; i++)
            {
                AddBOMLine(ctx, bomLines[i], qty);
                objproduct = new MProduct(ctx, Util.GetValueOfInt(bomLines[i].GetM_ProductBOM_ID()), null);
                lstBOMLines.Add(new BOMLines()
                {
                    BOMType      = Util.GetValueOfString(bomLines[i].GetBOMType()),
                    BOMTypeName  = GetBOMType(Util.GetValueOfString(bomLines[i].GetBOMType())),
                    BOMQty       = Util.GetValueOfString(bomLines[i].GetBOMQty()),
                    ProductID    = Util.GetValueOfString(bomLines[i].GetM_ProductBOM_ID()),
                    ProductName  = Util.GetValueOfString(objproduct.GetName()),
                    ProductBOMID = Util.GetValueOfString(bomLines[i].GetM_Product_BOM_ID()),
                    LineNo       = Util.GetValueOfString(bomLines[i].GetLine()),
                    Description  = Util.GetValueOfString(bomLines[i].GetDescription())
                });
            }
        }
        /// <summary>
        /// New Order Line (different Product)
        /// </summary>
        /// <param name="rLine">request line</param>
        private void NewLine(MRequisitionLine rLine)
        {
            if (_orderLine != null)
            {
                if (!_orderLine.Save())
                {
                    throw new Exception("Cannot update Order Line");
                }
            }
            _orderLine = null;
            MProduct product = null;

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

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

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

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


            //	Prepare Save
            _m_M_Product_ID = rLine.GetM_Product_ID();
            _m_M_AttributeSetInstance_ID = rLine.GetM_AttributeSetInstance_ID();
            if (!_orderLine.Save())
            {
                throw new Exception("Cannot save Order Line");
            }
        }
示例#11
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);
        }
        /// <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);
        }
示例#13
0
        /// <summary>
        /// Create Orders
        /// </summary>
        /// <returns>true if created</returns>
        private bool CreateOrders()
        {
            //	Get Counter Org/BP
            int runAD_Org_ID = _run.GetAD_Org_ID();

            if (runAD_Org_ID == 0)
            {
                runAD_Org_ID = GetCtx().GetAD_Org_ID();
            }
            MOrg runOrg           = MOrg.Get(GetCtx(), runAD_Org_ID);
            int  runC_BPartner_ID = runOrg.GetLinkedC_BPartner_ID();
            bool counter          = !_run.IsCreateSingleOrder() && //	no single Order
                                    runC_BPartner_ID > 0 &&             //	Org linked to BP
                                    !_docType.IsSOTrx();                //	PO
            MBPartner runBPartner = counter ? new MBPartner(GetCtx(), runC_BPartner_ID, Get_TrxName()) : null;

            if (!counter || runBPartner == null || runBPartner.Get_ID() != runC_BPartner_ID)
            {
                counter = false;
            }
            if (counter)
            {
                log.Info("RunBP=" + runBPartner
                         + " - " + _docType);
            }
            log.Info("Single=" + _run.IsCreateSingleOrder()
                     + " - " + _docType + ",SO=" + _docType.IsSOTrx());
            log.Fine("Counter=" + counter
                     + ",C_BPartner_ID=" + runC_BPartner_ID + "," + runBPartner);
            //
            MBPartner bp          = null;
            MOrder    singleOrder = null;
            MProduct  product     = null;

            //	Consolidated Order
            if (_run.IsCreateSingleOrder())
            {
                bp = new MBPartner(GetCtx(), _run.GetC_BPartner_ID(), Get_TrxName());
                if (bp.Get_ID() == 0)
                {
                    throw new ArgumentException("Business Partner not found - C_BPartner_ID=" + _run.GetC_BPartner_ID());
                }
                //
                if (!_IsTest)
                {
                    singleOrder = new MOrder(GetCtx(), 0, Get_TrxName());
                    singleOrder.SetC_DocTypeTarget_ID(_docType.GetC_DocType_ID());
                    singleOrder.SetC_DocType_ID(_docType.GetC_DocType_ID());
                    singleOrder.SetIsReturnTrx(_docType.IsReturnTrx());
                    singleOrder.SetIsSOTrx(_docType.IsSOTrx());
                    singleOrder.SetBPartner(bp);
                    if (_run.GetC_BPartner_Location_ID() != 0)
                    {
                        singleOrder.SetC_BPartner_Location_ID(_run.GetC_BPartner_Location_ID());
                    }
                    singleOrder.SetDateOrdered(_DateOrdered);
                    singleOrder.SetDatePromised(_DatePromised);
                    if (!singleOrder.Save())
                    {
                        log.Log(Level.SEVERE, "Order not saved");
                        return(false);
                    }
                    _counter++;
                }
            }

            int    lastC_BPartner_ID          = 0;
            int    lastC_BPartner_Location_ID = 0;
            MOrder order = null;

            //	For all lines
            for (int i = 0; i < _details.Length; i++)
            {
                MDistributionRunDetail detail = _details[i];

                //	Create Order Header
                if (_run.IsCreateSingleOrder())
                {
                    order = singleOrder;
                }
                //	New Business Partner
                else if (lastC_BPartner_ID != detail.GetC_BPartner_ID() ||
                         lastC_BPartner_Location_ID != detail.GetC_BPartner_Location_ID())
                {
                    //	finish order
                    order = null;
                }
                lastC_BPartner_ID          = detail.GetC_BPartner_ID();
                lastC_BPartner_Location_ID = detail.GetC_BPartner_Location_ID();

                //	New Order
                if (order == null)
                {
                    bp = new MBPartner(GetCtx(), detail.GetC_BPartner_ID(), Get_TrxName());
                    if (!_IsTest)
                    {
                        order = new MOrder(GetCtx(), 0, Get_TrxName());
                        order.SetC_DocTypeTarget_ID(_docType.GetC_DocType_ID());
                        order.SetIsReturnTrx(_docType.IsReturnTrx());
                        order.SetC_DocType_ID(_docType.GetC_DocType_ID());
                        order.SetIsSOTrx(_docType.IsSOTrx());
                        //	Counter Doc
                        if (counter && bp.GetAD_OrgBP_ID_Int() > 0)
                        {
                            log.Fine("Counter - From_BPOrg=" + bp.GetAD_OrgBP_ID_Int()
                                     + "-" + bp + ", To_BP=" + runBPartner);
                            order.SetAD_Org_ID(bp.GetAD_OrgBP_ID_Int());
                            MOrgInfo oi = MOrgInfo.Get(GetCtx(), bp.GetAD_OrgBP_ID_Int(), null);
                            if (oi.GetM_Warehouse_ID() > 0)
                            {
                                order.SetM_Warehouse_ID(oi.GetM_Warehouse_ID());
                            }
                            order.SetBPartner(runBPartner);
                        }
                        else    //	normal
                        {
                            log.Fine("From_Org=" + runAD_Org_ID
                                     + ", To_BP=" + bp);
                            order.SetAD_Org_ID(runAD_Org_ID);
                            order.SetBPartner(bp);
                            if (detail.GetC_BPartner_Location_ID() != 0)
                            {
                                order.SetC_BPartner_Location_ID(detail.GetC_BPartner_Location_ID());
                            }
                        }
                        order.SetDateOrdered(_DateOrdered);
                        order.SetDatePromised(_DatePromised);
                        if (!order.Save())
                        {
                            log.Log(Level.SEVERE, "Order not saved");
                            return(false);
                        }
                    }
                }

                //	Line
                if (product == null || product.GetM_Product_ID() != detail.GetM_Product_ID())
                {
                    product = MProduct.Get(GetCtx(), detail.GetM_Product_ID());
                }
                if (_IsTest)
                {
                    AddLog(0, null, detail.GetActualAllocation(),
                           bp.GetName() + " - " + product.GetName());
                    continue;
                }

                //	Create Order Line
                MOrderLine line = new MOrderLine(order);
                if (counter && bp.GetAD_OrgBP_ID_Int() > 0)
                {
                    ;   //	don't overwrite counter doc
                }
                else    //	normal - optionally overwrite
                {
                    line.SetC_BPartner_ID(detail.GetC_BPartner_ID());
                    if (detail.GetC_BPartner_Location_ID() != 0)
                    {
                        line.SetC_BPartner_Location_ID(detail.GetC_BPartner_Location_ID());
                    }
                }
                //
                line.SetProduct(product);
                line.SetQty(detail.GetActualAllocation());
                line.SetPrice();
                if (!line.Save())
                {
                    log.Log(Level.SEVERE, "OrderLine not saved");
                    return(false);
                }
                AddLog(0, null, detail.GetActualAllocation(), order.GetDocumentNo()
                       + ": " + bp.GetName() + " - " + product.GetName());
            }
            //	finish order
            order = null;


            return(true);
        }
示例#14
0
        }       //	createRequisition

        /// <summary>
        /// Create Inventory Movements
        /// </summary>
        private void CreateMovements()
        {
            int    noMoves = 0;
            String info    = "";
            //
            MClient    client               = null;
            MMovement  move                 = null;
            int        M_Warehouse_ID       = 0;
            int        M_WarehouseSource_ID = 0;
            MWarehouse whSource             = null;
            MWarehouse whTarget             = null;

            string param = "";

            if (_M_WareSource != null)
            {
                param = _M_WareSource;
            }
            else
            {
                param = "M_WarehouseSource_ID IS NOT NULL";
            }
            X_T_Replenish[] replenishs = GetReplenish(param);;
            for (int i = 0; i < replenishs.Length; i++)
            {
                X_T_Replenish replenish = replenishs[i];
                if (whSource == null || whSource.GetM_WarehouseSource_ID() != replenish.GetM_WarehouseSource_ID())
                {
                    whSource = MWarehouse.Get(GetCtx(), replenish.GetM_WarehouseSource_ID());
                }
                if (whTarget == null || whTarget.GetM_Warehouse_ID() != replenish.GetM_Warehouse_ID())
                {
                    whTarget = MWarehouse.Get(GetCtx(), replenish.GetM_Warehouse_ID());
                }
                if (client == null || client.GetAD_Client_ID() != whSource.GetAD_Client_ID())
                {
                    client = MClient.Get(GetCtx(), whSource.GetAD_Client_ID());
                }
                //
                if (move == null ||
                    M_WarehouseSource_ID != replenish.GetM_WarehouseSource_ID() ||
                    M_Warehouse_ID != replenish.GetM_Warehouse_ID())
                {
                    M_WarehouseSource_ID = replenish.GetM_WarehouseSource_ID();
                    M_Warehouse_ID       = replenish.GetM_Warehouse_ID();

                    move = new MMovement(GetCtx(), 0, Get_TrxName());
                    move.SetC_DocType_ID(_C_DocType_ID);
                    move.SetDescription(Msg.GetMsg(GetCtx(), "Replenishment")
                                        + ": " + whSource.GetName() + "->" + whTarget.GetName());
                    //	Set Org
                    move.SetAD_Org_ID(whSource.GetAD_Org_ID());
                    if (!move.Save())
                    {
                        return;
                    }
                    log.Fine(move.ToString());
                    noMoves++;
                    info += " - " + move.GetDocumentNo();
                }
                MProduct product = MProduct.Get(GetCtx(), replenish.GetM_Product_ID());
                //	To
                int M_LocatorTo_ID = GetLocator_ID(product, whTarget);

                //	From: Look-up Storage
                MProductCategory pc       = MProductCategory.Get(GetCtx(), product.GetM_Product_Category_ID());
                String           MMPolicy = pc.GetMMPolicy();
                if (MMPolicy == null || MMPolicy.Length == 0)
                {
                    MMPolicy = client.GetMMPolicy();
                }
                //
                MStorage[] storages = MStorage.GetWarehouse(GetCtx(),
                                                            whSource.GetM_Warehouse_ID(), replenish.GetM_Product_ID(), 0, 0,
                                                            true, null,
                                                            MClient.MMPOLICY_FiFo.Equals(MMPolicy), Get_TrxName());
                if (storages == null || storages.Length == 0)
                {
                    AddLog("No Inventory in " + whSource.GetName()
                           + " for " + product.GetName());
                    continue;
                }
                //
                Decimal target = replenish.GetQtyToOrder();
                for (int j = 0; j < storages.Length; j++)
                {
                    MStorage storage = storages[j];
                    //if (storage.GetQtyOnHand().signum() <= 0)
                    if (Env.Signum(storage.GetQtyOnHand()) <= 0)
                    {
                        continue;
                    }
                    Decimal moveQty = target;
                    if (storage.GetQtyOnHand().CompareTo(moveQty) < 0)
                    {
                        moveQty = storage.GetQtyOnHand();
                    }
                    //
                    MMovementLine line = new MMovementLine(move);
                    line.SetM_Product_ID(replenish.GetM_Product_ID());
                    line.SetMovementQty(moveQty);
                    if (replenish.GetQtyToOrder().CompareTo(moveQty) != 0)
                    {
                        line.SetDescription("Total: " + replenish.GetQtyToOrder());
                    }
                    line.SetM_Locator_ID(storage.GetM_Locator_ID());            //	from
                    line.SetM_AttributeSetInstance_ID(storage.GetM_AttributeSetInstance_ID());
                    line.SetM_LocatorTo_ID(M_LocatorTo_ID);                     //	to
                    line.SetM_AttributeSetInstanceTo_ID(storage.GetM_AttributeSetInstance_ID());
                    line.Save();
                    //
                    //target = target.subtract(moveQty);
                    target = Decimal.Subtract(target, moveQty);
                    //if (target.signum() == 0)
                    if (Env.Signum(target) == 0)
                    {
                        break;
                    }
                }
                if (Env.Signum(target) != 0)
                {
                    AddLog("Insufficient Inventory in " + whSource.GetName()
                           + " for " + product.GetName() + " Qty=" + target);
                }
            }
            if (replenishs.Length == 0)
            {
                _info = "No Source Warehouse";
                log.Warning(_info);
            }
            else
            {
                _info = "#" + noMoves + info;
                log.Info(_info);
            }
        }       //	createRequisition
示例#15
0
        /// <summary>
        /// is used to save data in case of Full move container / full qty move
        /// </summary>
        /// <param name="movementId">movement header refernce</param>
        /// <param name="fromLocatorId">From Locator - from where we have to move product</param>
        /// <param name="fromContainerId">From Container - from which container, we have to move product</param>
        /// <param name="toLocatorId">To Locator - where we are moving product</param>
        /// <param name="toContainerId">To container - in which container we are moving product</param>
        /// <param name="lineNo"></param>
        /// <param name="isMoveFullContainerQty">Is Container also move with Product</param>
        /// <param name="trx">Self created Trx</param>
        /// <returns>Message : lines inserted or not</returns>
        public String SaveMoveLinewithFullContainer(int movementId, int fromLocatorId, int fromContainerId, int toLocatorId, int toContainerId, int lineNo, bool isMoveFullContainerQty, Trx trx)
        {
            MMovement     movement         = new MMovement(_ctx, movementId, trx);
            string        childContainerId = null;
            StringBuilder error            = new StringBuilder();

            // Get Path upto selected container
            string sql           = @"SELECT sys_connect_by_path(m_productcontainer_id,'->') tree
                            FROM m_productcontainer 
                           WHERE m_productcontainer_id = " + fromContainerId + @"
                            START WITH ref_m_container_id IS NULL CONNECT BY prior m_productcontainer_id = ref_m_container_id
                           ORDER BY tree ";
            string pathContainer = Util.GetValueOfString(DB.ExecuteScalar(sql, null, trx));

            // child records with Parent Id
            if (!isMoveFullContainerQty)
            {
                sql = @"SELECT tree, m_productcontainer_id FROM
                            (SELECT sys_connect_by_path(m_productcontainer_id,'->') tree , m_productcontainer_id
                             FROM m_productcontainer
                             START WITH ref_m_container_id IS NULL
                             CONNECT BY prior m_productcontainer_id = ref_m_container_id
                             ORDER BY tree  
                             )
                           WHERE tree LIKE ('" + pathContainer + "%') ";
                DataSet ds = DB.ExecuteDataset(sql, null, trx);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (String.IsNullOrEmpty(childContainerId))
                        {
                            childContainerId = Util.GetValueOfString(ds.Tables[0].Rows[i]["m_productcontainer_id"]);
                        }
                        else
                        {
                            childContainerId += "," + Util.GetValueOfString(ds.Tables[0].Rows[i]["m_productcontainer_id"]);
                        }
                    }
                }
                ds.Dispose();
            }
            else
            {
                childContainerId = fromContainerId.ToString();
            }

            // check is same container already moved to another container
            // Ex :: p1 -> c1 and p1 -> c2
            // OR also check -- is any other container is moving into exist target container
            // Ex :: p1 -> c1 and p2 -> p1
            if (!isMoveFullContainerQty)
            {
                if (!IsContainerMoved(movementId, pathContainer, childContainerId, toContainerId, trx))
                {
                    return(Msg.GetMsg(_ctx, "VIS_AlreadyMoved"));
                }
            }

            // not to move Parent container to its child container
            if (toContainerId > 0 && childContainerId.Contains(toContainerId.ToString()))
            {
                //Parent cant be Move to its own child
                return(Msg.GetMsg(_ctx, "VIS_cantMoveParentTochild"));
            }

            // Get All records of Parent Container and child container
            sql = @"SELECT * FROM (
                            SELECT p.M_PRODUCT_ID, p.NAME, p.C_UOM_ID, u.Name AS UomName,  t.M_ATTRIBUTESETINSTANCE_ID, t.M_ProductContainer_ID,
                            SUM(t.ContainerCurrentQty) keep (dense_rank last ORDER BY t.MovementDate, t.M_Transaction_ID) AS ContainerCurrentQty
                            FROM M_Transaction t
                            INNER JOIN M_Product p ON p.M_Product_ID = t.M_Product_ID
                            INNER JOIN C_UOM u ON u.C_UOM_ID = p.C_UOM_ID
                            WHERE t.IsActive = 'Y' AND NVL(t.M_ProductContainer_ID, 0) IN ( " + childContainerId +
                  @" ) AND t.MovementDate <=" + GlobalVariable.TO_DATE(movement.GetMovementDate(), true) + @" 
                               AND t.M_Locator_ID  = " + fromLocatorId + @"
                               AND t.AD_Client_ID  = " + movement.GetAD_Client_ID() + @"
                            GROUP BY p.M_PRODUCT_ID, p.NAME, p.C_UOM_ID, u.Name, t.M_ATTRIBUTESETINSTANCE_ID, t.M_ProductContainer_ID 
                          ) t WHERE ContainerCurrentQty <> 0 ";
            DataSet dsRecords = DB.ExecuteDataset(sql, null, trx);

            if (dsRecords != null && dsRecords.Tables.Count > 0 && dsRecords.Tables[0].Rows.Count > 0)
            {
                int           movementlineId = 0;
                MMovementLine moveline       = null;
                MProduct      product        = null;
                for (int i = 0; i < dsRecords.Tables[0].Rows.Count; i++)
                {
                    movementlineId = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT NVL(M_MovementLine_ID, 0) AS M_Movement_ID FROM M_MovementLine WHERE 
                             M_Movement_ID = " + Util.GetValueOfInt(movementId) +
                                                                         @" AND M_Product_ID = " + Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_Product_ID"]) +
                                                                         @" AND NVL(M_AttributeSetInstance_ID, 0) = " + Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_AttributeSetInstance_ID"]) +
                                                                         @" AND M_Locator_ID = " + Util.GetValueOfInt(fromLocatorId) +
                                                                         @" AND NVL(M_ProductContainer_ID, 0) = " + Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_ProductContainer_ID"]) +
                                                                         @" AND M_LocatorTo_ID = " + Util.GetValueOfInt(toLocatorId) +
                                                                         @" AND NVL(Ref_M_ProductContainerTo_ID, 0) = " + toContainerId +
                                                                         @" AND AD_Org_ID = " + movement.GetAD_Org_ID()));

                    if (movementlineId > 0)
                    {
                        moveline = new MMovementLine(_ctx, movementlineId, trx);
                    }
                    else
                    {
                        moveline = new MMovementLine(_ctx, 0, trx);
                    }
                    if (movementlineId == 0)
                    {
                        #region Create new record of movement line
                        lineNo += 10;
                        moveline.SetAD_Client_ID(movement.GetAD_Client_ID());
                        moveline.SetAD_Org_ID(movement.GetAD_Org_ID());
                        moveline.SetM_Movement_ID(movement.GetM_Movement_ID());
                        moveline.SetLine(lineNo);
                        moveline.SetM_Product_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_Product_ID"]));
                        moveline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_AttributeSetInstance_ID"]));
                        moveline.SetC_UOM_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["C_UOM_ID"]));
                        moveline.SetM_Locator_ID(fromLocatorId);
                        moveline.SetM_LocatorTo_ID(toLocatorId);
                        moveline.SetM_ProductContainer_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_ProductContainer_ID"]));
                        moveline.SetRef_M_ProductContainerTo_ID(toContainerId);
                        moveline.SetQtyEntered(Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"]));
                        moveline.SetMovementQty(Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"]));
                        moveline.SetMoveFullContainer(isMoveFullContainerQty ? false : true);
                        // when move full container, then only need to update IsParentMove and Target container (which represent - to which container we are moving)
                        // and set true value on those line which container are moving, not on its child container
                        if (!isMoveFullContainerQty)
                        {
                            moveline.SetIsParentMove(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_ProductContainer_ID"]) == fromContainerId ? true : false);
                            moveline.SetTargetContainer_ID(fromContainerId);
                        }
                        #endregion
                    }
                    else
                    {
                        #region Update record of movement line
                        moveline.SetQtyEntered(Decimal.Add(moveline.GetQtyEntered(), Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"])));
                        moveline.SetMovementQty(Decimal.Add(moveline.GetMovementQty(), Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"])));
                        moveline.SetMoveFullContainer(true);
                        #endregion
                    }
                    if (!moveline.Save(trx))
                    {
                        #region Save error catch and rollback
                        product = MProduct.Get(_ctx, Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_Product_ID"]));
                        ValueNamePair pp = VLogger.RetrieveError();
                        if (pp != null)
                        {
                            _log.SaveError("Movement line not inserted through Move Container Form : ", pp.GetName());
                            if (String.IsNullOrEmpty(error.ToString()))
                            {
                                error.Append(Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName());
                            }
                            else
                            {
                                error.Append(" , " + Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName());
                            }
                        }
                        trx.Rollback();
                        #endregion
                    }
                    else
                    {
                        trx.Commit();
                    }
                }
            }
            else
            {
                return(Msg.GetMsg(_ctx, "VIS_ContainerhaveNoRecord"));
            }

            return(String.IsNullOrEmpty(error.ToString()) ? "VIS_SuccessFullyInserted" : error.ToString());
        }
示例#16
0
        /// <summary>
        /// Is used to save data on movememt line
        /// </summary>
        /// <param name="mData"></param>
        /// <returns></returns>
        public String SaveMovementLine(List <Dictionary <string, string> > mData)
        {
            StringBuilder error = new StringBuilder();
            bool          isMoveFullContainer    = false;
            bool          isMoveFullContainerQty = false;

            Trx trx = Trx.GetTrx("Movement");

            if (mData.Count > 0)
            {
                isMoveFullContainer = Util.GetValueOfBool(mData[0]["IsFullMoveContainer"]);

                //to delete all the movement lines where MoveFullContainer is False
                if (isMoveFullContainer)
                {
                    DB.ExecuteQuery("DELETE FROM M_MovementLine WHERE M_Movement_ID = " + Util.GetValueOfInt(mData[0]["M_Movement_ID"]) + " AND MoveFullContainer= 'N' ", null, null);
                }

                // Lines not inserted, as movement line already has a full move container line.
                if (!isMoveFullContainer)
                {
                    if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT COUNT(MoveFullContainer) FROM M_MovementLine WHERE MoveFullContainer= 'Y' AND M_Movement_ID = "
                                                            + Util.GetValueOfInt(mData[0]["M_Movement_ID"]), null, trx)) > 0)
                    {
                        trx.Close();
                        return(Msg.GetMsg(_ctx, "VIS_LinehaveFullContainer"));
                    }
                }

                // Get Line No
                int lineNo = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT NVL(MAX(Line),0) AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID="
                                                                 + Util.GetValueOfInt(mData[0]["M_Movement_ID"]), null, trx));


                isMoveFullContainerQty = Util.GetValueOfBool(mData[0]["IsfullContainerQtyWise"]);

                if (!isMoveFullContainer && !isMoveFullContainerQty)
                {
                    goto moveFullContainer;
                }
                else if (isMoveFullContainer || isMoveFullContainerQty)
                {
                    error.Clear();
                    error.Append(SaveMoveLinewithFullContainer(Util.GetValueOfInt(mData[0]["M_Movement_ID"]),
                                                               Util.GetValueOfInt(mData[0]["FromLocator"]),
                                                               Util.GetValueOfInt(mData[0]["FromContainer"]),
                                                               Util.GetValueOfInt(mData[0]["ToLocator"]),
                                                               Util.GetValueOfInt(mData[0]["ToContainer"]),
                                                               lineNo, isMoveFullContainerQty,
                                                               trx));
                    trx.Close();
                    return(error.ToString());
                }

moveFullContainer:
                MMovementLine moveline = null;
                MProduct product = null;
                int      moveId  = 0;
                for (int i = 0; i < mData.Count; i++)
                {
                    #region Quantity Only
                    MMovement move = new MMovement(_ctx, Util.GetValueOfInt(mData[i]["M_Movement_ID"]), null);

                    moveId = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT NVL(M_MovementLine_ID, 0) AS M_Movement_ID FROM M_MovementLine WHERE 
                             M_Movement_ID = " + Util.GetValueOfInt(mData[i]["M_Movement_ID"]) +
                                                                 @" AND M_Product_ID = " + Util.GetValueOfInt(mData[i]["M_Product_ID"]) +
                                                                 @" AND NVL(M_AttributeSetInstance_ID, 0) = " + Util.GetValueOfInt(mData[i]["M_AttributeSetInstance_ID"]) +
                                                                 @" AND M_Locator_ID = " + Util.GetValueOfInt(mData[i]["FromLocator"]) +
                                                                 @" AND NVL(M_ProductContainer_ID, 0) = " + Util.GetValueOfInt(mData[i]["FromContainer"]) +
                                                                 @" AND M_LocatorTo_ID = " + Util.GetValueOfInt(mData[i]["ToLocator"]) +
                                                                 @" AND NVL(Ref_M_ProductContainerTo_ID, 0) = " + Util.GetValueOfInt(mData[i]["ToContainer"]) +
                                                                 @" AND AD_Org_ID = " + move.GetAD_Org_ID()));

                    if (moveId > 0)
                    {
                        moveline = new MMovementLine(_ctx, moveId, trx);
                    }
                    else
                    {
                        moveline = new MMovementLine(_ctx, 0, trx);
                    }
                    if (moveId == 0)
                    {
                        #region Create new record of movement line
                        lineNo += 10;
                        moveline.SetAD_Client_ID(move.GetAD_Client_ID());
                        moveline.SetAD_Org_ID(move.GetAD_Org_ID());
                        moveline.SetM_Movement_ID(move.GetM_Movement_ID());
                        moveline.SetLine(lineNo);
                        moveline.SetM_Product_ID(Util.GetValueOfInt(mData[i]["M_Product_ID"]));
                        moveline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(mData[i]["M_AttributeSetInstance_ID"]));
                        moveline.SetC_UOM_ID(Util.GetValueOfInt(mData[i]["C_UOM_ID"]));
                        moveline.SetM_Locator_ID(Util.GetValueOfInt(mData[i]["FromLocator"]));
                        moveline.SetM_LocatorTo_ID(Util.GetValueOfInt(mData[i]["ToLocator"]));
                        moveline.SetM_ProductContainer_ID(Util.GetValueOfInt(mData[i]["FromContainer"]));
                        moveline.SetRef_M_ProductContainerTo_ID(Util.GetValueOfInt(mData[i]["ToContainer"]));
                        moveline.SetQtyEntered(Util.GetValueOfDecimal(mData[i]["MoveQty"]));
                        moveline.SetMovementQty(Util.GetValueOfDecimal(mData[i]["MoveQty"]));
                        moveline.SetMoveFullContainer(Util.GetValueOfBool(mData[i]["IsFullMoveContainer"]));
                        #endregion
                    }
                    else
                    {
                        #region Update record of movement line
                        moveline.SetQtyEntered(Decimal.Add(moveline.GetQtyEntered(), Util.GetValueOfDecimal(mData[i]["MoveQty"])));
                        moveline.SetMovementQty(Decimal.Add(moveline.GetMovementQty(), Util.GetValueOfDecimal(mData[i]["MoveQty"])));
                        moveline.SetMoveFullContainer(Util.GetValueOfBool(mData[i]["IsFullMoveContainer"]));
                        #endregion
                    }
                    if (!moveline.Save(trx))
                    {
                        #region Save error catch and rollback
                        product = MProduct.Get(_ctx, Util.GetValueOfInt(mData[i]["M_Product_ID"]));
                        ValueNamePair pp = VLogger.RetrieveError();
                        if (pp != null)
                        {
                            _log.SaveError("Movement line not inserted through Move Container Form : ", pp.GetName());
                            if (String.IsNullOrEmpty(error.ToString()))
                            {
                                error.Append(Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName());
                            }
                            else
                            {
                                error.Append(" , " + Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName());
                            }
                        }
                        trx.Rollback();
                        #endregion
                    }
                    else
                    {
                        trx.Commit();
                    }

                    #endregion
                }
            }
            trx.Close();
            return(String.IsNullOrEmpty(error.ToString()) ? "VIS_SuccessFullyInserted" : error.ToString());
        }