/// <summary>
        /// Criteria apply
        /// </summary>
        /// <param name="Value">amt or qty</param>
        /// <param name="M_Product_ID">product</param>
        /// <param name="M_Product_Category_ID">category</param>
        /// <returns>true if criteria met</returns>
        public bool Applies(Decimal Value, int M_Product_ID, int M_Product_Category_ID)
        {
            if (!IsActive())
            {
                return(false);
            }

            //	below break value
            if (Value.CompareTo(GetBreakValue()) < 0)
            {
                return(false);
            }

            //	No Product / Category
            if (GetM_Product_ID() == 0 &&
                GetM_Product_Category_ID() == 0)
            {
                return(true);
            }

            //	Product
            if (GetM_Product_ID() == M_Product_ID)
            {
                return(true);
            }

            //	Category
            if (M_Product_Category_ID != 0)
            {
                return(GetM_Product_Category_ID() == M_Product_Category_ID);
            }

            //	Look up Category of Product
            return(MProductCategory.IsCategory(GetM_Product_Category_ID(), M_Product_ID));
        }
        /// <summary>
        /// Is the product included?
        /// </summary>
        /// <param name="M_Product_ID">product</param>
        /// <returns>true if no restrictions or included in "positive" only list</returns>
        public bool IsIncluded(int M_Product_ID)
        {
            //	No restrictions
            if (GetRestrictions(false).Length == 0)
            {
                return(true);
            }

            for (int i = 0; i < _restrictions.Length; i++)
            {
                MRfQTopicSubscriberOnly restriction = _restrictions[i];
                if (!restriction.IsActive())
                {
                    continue;
                }
                //	Product
                if (restriction.GetM_Product_ID() == M_Product_ID)
                {
                    return(true);
                }
                //	Product Category
                if (MProductCategory.IsCategory(restriction.GetM_Product_Category_ID(), M_Product_ID))
                {
                    return(true);
                }
            }
            //	must be on "positive" list
            return(false);
        }
 /**
 * 	Create One Asset Per UOM
 *	@return individual asset
 */
 public bool IsOneAssetPerUOM()
 {
     MProductCategory pc = MProductCategory.Get(GetCtx(), GetM_Product_Category_ID());
     if (pc.GetA_Asset_Group_ID() == 0)
         return false;
     MAssetGroup ag = MAssetGroup.Get(GetCtx(), pc.GetA_Asset_Group_ID());
     return ag.IsOneAssetPerUOM();
 }
 public bool UpdateCategory(Int32 id, string name, VAdvantage.Utility.Ctx ctx)
 {
     VAdvantage.Model.MProductCategory pcat = new VAdvantage.Model.MProductCategory(ctx, id, null);
     pcat.SetName(name);
     if (pcat.Save())
     {
         return(true);
     }
     return(false);
 }
示例#5
0
        /*  Get from Cache
         *	@param ctx context
         *	@param M_Product_Category_ID id
         *	@return category
         */
        public static MProductCategory Get(Ctx ctx, int M_Product_Category_ID)
        {
            int ii = M_Product_Category_ID;
            MProductCategory pc = (MProductCategory)s_cache[ii];

            if (pc == null)
            {
                pc = new MProductCategory(ctx, M_Product_Category_ID, null);
            }
            return(pc);
        }
示例#6
0
        /// <summary>
        /// Is used to check costing method belongs to PO costing method  like (Average PO, Weighted Average PO or Last PO)
        /// Firts we check costing method on Product category, if not found then we will check on Primary Accounting Schema
        /// </summary>
        /// <param name="ctx">current context</param>
        /// <param name="AD_Client_ID">Client reference</param>
        /// <param name="M_Product_ID">Product whom costing method is to be determine</param>
        /// <param name="trxName">Transaction</param>
        /// <returns>True/False</returns>
        public static bool IsPOCostingmethod(Ctx ctx, int AD_Client_ID, int M_Product_ID, Trx trxName)
        {
            MProductCategory pc = null;
            bool             isPOcostingMethod = false;
            string           costingMethod     = null;
            MClient          client            = MClient.Get(ctx, AD_Client_ID);
            MProduct         product           = MProduct.Get(ctx, M_Product_ID);

            if (product != null)
            {
                pc = MProductCategory.Get(product.GetCtx(), product.GetM_Product_Category_ID());
                if (pc != null)
                {
                    // check costing method from product category
                    costingMethod = pc.GetCostingMethod();
                    if (costingMethod == "C")
                    {
                        costingMethod = Util.GetValueOfString(DB.ExecuteScalar(@"SELECT costingmethod FROM M_CostElement WHERE M_CostElement_ID IN 
                                        (SELECT CAST(M_Ref_CostElement AS INTEGER) FROM M_CostElementLine WHERE M_CostElement_ID=" + pc.GetM_CostElement_ID() + @" )
                                        AND CostingMethod IS NOT NULL", null, trxName));
                    }
                }
                if (String.IsNullOrEmpty(costingMethod))
                {
                    // check costing method against primary accounting schema
                    MClientInfo clientInfo = MClientInfo.Get(ctx, AD_Client_ID);
                    MAcctSchema actSchema  = MAcctSchema.Get(ctx, clientInfo.GetC_AcctSchema1_ID());
                    if (actSchema != null)
                    {
                        costingMethod = actSchema.GetCostingMethod();
                        if (costingMethod == "C")
                        {
                            costingMethod = Util.GetValueOfString(DB.ExecuteScalar(@"SELECT costingmethod FROM M_CostElement WHERE M_CostElement_ID IN 
                                        (SELECT CAST(M_Ref_CostElement AS INTEGER) FROM M_CostElementLine WHERE M_CostElement_ID=" + actSchema.GetM_CostElement_ID() + @" )
                                        AND CostingMethod IS NOT NULL", null, trxName));
                        }
                    }
                }
            }
            if (costingMethod.Equals(COSTINGMETHOD_WeightedAveragePO) ||
                costingMethod.Equals(COSTINGMETHOD_AveragePO) ||
                costingMethod.Equals(COSTINGMETHOD_LastPOPrice))
            {
                isPOcostingMethod = true;
            }
            else
            {
                isPOcostingMethod = false;
            }

            return(isPOcostingMethod);
        }
        public KeyNamePair AddCategory(string name, VAdvantage.Utility.Ctx ctx)
        {
            KeyNamePair category = null;

            VAdvantage.Model.MProductCategory pcat = new VAdvantage.Model.MProductCategory(ctx, 0, null);
            pcat.SetAD_Client_ID(ctx.GetAD_Client_ID());
            pcat.SetAD_Org_ID(ctx.GetAD_Org_ID());
            pcat.SetName(name);
            if (pcat.Save())
            {
                category = new KeyNamePair(pcat.Get_ID(), name);
                return(category);
            }
            return(category);
        }
示例#8
0
        // Added by Mohit 20-8-2015 VAWMS
        public static MProductCategory GetOfProduct(Ctx ctx, int M_Product_ID)
        {
            MProductCategory retValue = null;

            //PreparedStatement pstmt = null;
            //ResultSet rs = null;
            SqlParameter[] param = null;
            IDataReader    idr   = null;
            DataTable      dt    = new DataTable();
            String         sql   = "SELECT * FROM M_Product_Category pc "
                                   + "WHERE EXISTS (SELECT * FROM M_Product p "
                                   + "WHERE p.M_Product_ID=@param1 AND p.M_Product_Category_ID=pc.M_Product_Category_ID)";

            try
            {
                //pstmt = DB.prepareStatement(sql, (Trx)null);
                //pstmt.setInt(1, M_Product_ID);
                //rs = pstmt.executeQuery();
                //if (rs.next())
                param    = new SqlParameter[1];
                param[0] = new SqlParameter("@param1", M_Product_ID);
                idr      = DB.ExecuteReader(sql, param, null);
                dt.Load(idr);
                idr.Close();
                if (dt.Rows.Count > 0)
                {
                    retValue = new MProductCategory(ctx, dt.Rows[0], null);
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            //finally
            //{
            //    DB.closeResultSet(rs);
            //    DB.closeStatement(pstmt);
            //}
            return(retValue);
        }
        public bool UpdateCategory(Int32 id, String Name, String Value, String Producttype, String matPolicy, String Desc, Int32 attrSet, Int32 taxcat, Int32 assetGrp, Boolean Consumable, Int32 image_ID, VAdvantage.Utility.Ctx ctx)
        {
            VAdvantage.Model.MProductCategory pcat = new VAdvantage.Model.MProductCategory(ctx, id, null);
            pcat.SetName(Name);
            pcat.SetValue(Value);
            pcat.SetProductType(Producttype);
            pcat.SetMMPolicy(matPolicy);
            pcat.SetDescription(Desc);
            pcat.SetM_AttributeSet_ID(attrSet);
            pcat.SetC_TaxCategory_ID(taxcat);
            pcat.SetA_Asset_Group_ID(assetGrp);
            pcat.SetAD_Image_ID(image_ID);
            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                pcat.SetDTD001_IsConsumable(Consumable);
            }
            if (pcat.Save())
            {
                return(true);
            }
            return(false);
        }
        public static bool InsertForeignCostMatchOrder(Ctx ctx, MOrderLine orderLine, decimal matchQty, int ASI, Trx trx)
        {
            int                  acctSchema_ID    = 0;
            int                  M_CostElement_ID = 0;
            int                  AD_Org_ID        = 0;
            int                  M_ASI_ID         = 0;
            MProduct             product          = null;
            MAcctSchema          acctSchema       = null;
            MCostForeignCurrency foreignCost      = null;
            dynamic              pc    = null;
            String               cl    = null;
            MOrder               order = null;

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

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

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

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

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

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

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

                            foreignCost = MCostForeignCurrency.Get(product, M_ASI_ID, AD_Org_ID, M_CostElement_ID, order.GetC_BPartner_ID(), order.GetC_Currency_ID());
                            foreignCost.SetC_Order_ID(order.GetC_Order_ID());
                            foreignCost.SetCumulatedQty(Decimal.Add(foreignCost.GetCumulatedQty(), matchQty));
                            foreignCost.SetCumulatedAmt(Decimal.Add(foreignCost.GetCumulatedAmt(), Decimal.Multiply(orderLine.GetPriceActual(), matchQty)));
                            if (foreignCost.GetCumulatedQty() != 0)
                            {
                                foreignCost.SetCostPerUnit(Decimal.Round(Decimal.Divide(foreignCost.GetCumulatedAmt(), foreignCost.GetCumulatedQty()), acctSchema.GetCostingPrecision()));
                            }
                            else
                            {
                                foreignCost.SetCostPerUnit(0);
                            }
                            if (!foreignCost.Save(trx))
                            {
                                ValueNamePair pp = VLogger.RetrieveError();
                                _log.Severe("Error occured during updating M_Cost_ForeignCurrency. Error name : " + pp.GetName() +
                                            " AND Error Value : " + pp.GetValue() + " , For Invoice line : " + orderLine.GetC_OrderLine_ID() +
                                            " , AND Ad_Client_ID : " + orderLine.GetAD_Client_ID());
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Log(Level.SEVERE, "", ex);
                return(false);
            }
            return(true);
        }
        public static bool InsertForeignCostAverageInvoice(Ctx ctx, MInvoice invoice, MInvoiceLine invoiceLine, Trx trx)
        {
            int                  acctSchema_ID    = 0;
            int                  M_CostElement_ID = 0;
            int                  AD_Org_ID        = 0;
            int                  M_ASI_ID         = 0;
            MProduct             product          = null;
            MAcctSchema          acctSchema       = null;
            MCostForeignCurrency foreignCost      = null;
            dynamic              pc = null;
            String               cl = null;

            try
            {
                // if cost is calculated then not to calculate again
                if (invoiceLine.IsFutureCostCalculated())
                {
                    return(true);
                }

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

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

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

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

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

                        if (cl == "C" || cl == "B")
                        {
                            AD_Org_ID = 0;
                        }
                        else
                        {
                            AD_Org_ID = invoice.GetAD_Org_ID();
                        }
                        if (cl != "B")
                        {
                            M_ASI_ID = 0;
                        }
                        else
                        {
                            M_ASI_ID = invoiceLine.GetM_AttributeSetInstance_ID();
                        }

                        foreignCost = MCostForeignCurrency.Get(product, M_ASI_ID, AD_Org_ID, M_CostElement_ID, invoice.GetC_BPartner_ID(), invoice.GetC_Currency_ID());
                        foreignCost.SetC_Invoice_ID(invoice.GetC_Invoice_ID());
                        foreignCost.SetCumulatedQty(Decimal.Add(foreignCost.GetCumulatedQty(), invoiceLine.GetQtyInvoiced()));
                        foreignCost.SetCumulatedAmt(Decimal.Add(foreignCost.GetCumulatedAmt(), invoiceLine.GetLineNetAmt()));
                        if (foreignCost.GetCumulatedQty() != 0)
                        {
                            foreignCost.SetCostPerUnit(Decimal.Round(Decimal.Divide(foreignCost.GetCumulatedAmt(), foreignCost.GetCumulatedQty()), acctSchema.GetCostingPrecision()));
                        }
                        else
                        {
                            foreignCost.SetCostPerUnit(0);
                        }
                        if (!foreignCost.Save(trx))
                        {
                            ValueNamePair pp = VLogger.RetrieveError();
                            _log.Severe("Error occured during updating M_Cost_ForeignCurrency. Error name : " + pp.GetName() +
                                        " AND Error Value : " + pp.GetValue() + " , For Invoice line : " + invoiceLine.GetC_InvoiceLine_ID() +
                                        " , AND Ad_Client_ID : " + invoiceLine.GetAD_Client_ID());
                            return(false);
                        }
                        else
                        {
                            invoiceLine.SetIsFutureCostCalculated(true);
                            if (!invoiceLine.Save(trx))
                            {
                                ValueNamePair pp = VLogger.RetrieveError();
                                _log.Severe("Error occured during updating Is Foreign Cost On C_invoice. Error name : " + pp.GetName() +
                                            " AND Error Value : " + pp.GetValue() + " , For Invoice line : " + invoiceLine.GetC_InvoiceLine_ID() +
                                            " , AND Ad_Client_ID : " + invoiceLine.GetAD_Client_ID());
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Log(Level.SEVERE, "", ex);
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true</returns>
        protected override bool BeforeSave(bool newRecord)
        {
            if (GetLine() == 0)
            {
                SetLine();
            }

            // Work done for Purchase Price and Mergin calculation
            if (Env.IsModuleInstalled("VA077_") && Get_ColumnIndex("VA077_PurchasePrice") >= 0 && Util.GetValueOfDecimal(Get_Value("VA077_PurchasePrice")).Equals(0))
            {
                if (GetProject() != null && _parent.IsOpportunity() && Util.GetValueOfInt(_parent.Get_Value("PO_PriceList_ID")) > 0)
                {
                    Set_Value("VA077_PurchasePrice", GetPurchasePrice());

                    // Calculate Purchase Amount
                    Decimal purchaseAmt = Decimal.Multiply(GetPlannedQty(), Util.GetValueOfDecimal(Get_Value("VA077_PurchasePrice")));
                    if (Env.Scale(purchaseAmt) > GetCurPrecision())
                    {
                        purchaseAmt = Decimal.Round(purchaseAmt, GetCurPrecision(), MidpointRounding.AwayFromZero);
                    }
                    Set_Value("VA077_PurchaseAmt", purchaseAmt);
                }

                // Calculate Margin Amount
                Decimal marginEach = Decimal.Subtract(GetPlannedPrice(), Util.GetValueOfDecimal(Get_Value("VA077_PurchasePrice")));
                Set_Value("VA077_MarginAmt", Decimal.Multiply(marginEach, GetPlannedQty()));

                // Calculate Margin Percentage
                Decimal marginPer = 0;
                if (GetPlannedPrice() > 0)
                {
                    marginPer = Decimal.Round(Decimal.Multiply(Decimal.Divide(marginEach, GetPlannedPrice())
                                                               , Env.ONEHUNDRED), GetCurPrecision(), MidpointRounding.AwayFromZero);
                }
                Set_Value("VA077_MarginPercent", marginPer);
            }

            //	Planned Amount	- Currency Precision
            Decimal plannedAmt = Decimal.Multiply(GetPlannedQty(), GetPlannedPrice());

            if (Env.Scale(plannedAmt) > GetCurPrecision())
            {
                //plannedAmt.setScale(GetCurPrecision(), Decimal.ROUND_HALF_UP);
                Decimal.Round(plannedAmt, GetCurPrecision(), MidpointRounding.AwayFromZero);
            }
            SetPlannedAmt(plannedAmt);

            //	Planned Margin
            if (Is_ValueChanged("M_Product_ID") || Is_ValueChanged("M_Product_Category_ID") ||
                Is_ValueChanged("PlannedQty") || Is_ValueChanged("PlannedPrice"))
            {
                if (GetM_Product_ID() != 0)
                {
                    Decimal marginEach = Decimal.Subtract(GetPlannedPrice(), GetLimitPrice());
                    SetPlannedMarginAmt(Decimal.Multiply(marginEach, GetPlannedQty()));
                }
                else if (GetM_Product_Category_ID() != 0)
                {
                    MProductCategory category   = MProductCategory.Get(GetCtx(), GetM_Product_Category_ID());
                    Decimal          marginEach = category.GetPlannedMargin();
                    SetPlannedMarginAmt(Decimal.Multiply(marginEach, GetPlannedQty()));
                }
            }

            //	Phase/Task
            if (Is_ValueChanged("C_ProjectTask_ID") && GetC_ProjectTask_ID() != 0)
            {
                MProjectTask pt = new MProjectTask(GetCtx(), GetC_ProjectTask_ID(), Get_TrxName());
                if (pt == null || pt.Get_ID() == 0)
                {
                    log.Warning("Project Task Not Found - ID=" + GetC_ProjectTask_ID());
                    return(false);
                }
                else
                {
                    SetC_ProjectPhase_ID(pt.GetC_ProjectPhase_ID());
                }
            }
            if (Is_ValueChanged("C_ProjectPhase_ID") && GetC_ProjectPhase_ID() != 0)
            {
                MProjectPhase pp = new MProjectPhase(GetCtx(), GetC_ProjectPhase_ID(), Get_TrxName());
                if (pp == null || pp.Get_ID() == 0)
                {
                    log.Warning("Project Phase Not Found - " + GetC_ProjectPhase_ID());
                    return(false);
                }
                else
                {
                    SetC_Project_ID(pp.GetC_Project_ID());
                }
            }

            return(true);
        }
示例#13
0
        /**
         *  Create Asset for this product
         *	@return true if asset is created
         */
        public bool IsCreateAsset()
        {
            MProductCategory pc = MProductCategory.Get(GetCtx(), GetM_Product_Category_ID());

            return(pc.GetA_Asset_Group_ID() != 0);
        }
示例#14
0
        /**
         *  Create Asset Group for this product
         *	@return asset group id
         */
        public int GetA_Asset_Group_ID()
        {
            MProductCategory pc = MProductCategory.Get(GetCtx(), GetM_Product_Category_ID());

            return(pc.GetA_Asset_Group_ID());
        }
        /**
         * 	Before Save
         *	@param newRecord new
         *	@return true
         */
        protected override bool BeforeSave(bool newRecord)
        {
            // Set Search Key from Serial No defined on Product Category.
            MProductCategory pc = new MProductCategory(GetCtx(), GetM_Product_Category_ID(), Get_TrxName());
            if (newRecord && pc.Get_ColumnIndex("M_SerNoCtl_ID") >= 0 && pc.GetM_SerNoCtl_ID() > 0)
            {
                string name = "";
                MSerNoCtl ctl = new MSerNoCtl(GetCtx(), pc.GetM_SerNoCtl_ID(), Get_TrxName());

                // if Organization level check box is true on Serila No Control, then Get Current next from Serila No tab.
                if (ctl.Get_ColumnIndex("IsOrgLevelSequence") >= 0)
                {
                    name = ctl.CreateDefiniteSerNo(this);
                }
                else
                {
                    name = ctl.CreateSerNo();
                }
                SetValue(name);
            }

            //	Check Storage
            if (!newRecord && 	//
                ((Is_ValueChanged("IsActive") && !IsActive())		//	now not active
                || (Is_ValueChanged("IsStocked") && !IsStocked())	//	now not stocked
                || (Is_ValueChanged("ProductType") 					//	from Item
                    && PRODUCTTYPE_Item.Equals(Get_ValueOld("ProductType")))))
            {
                MStorage[] storages = MStorage.GetOfProduct(GetCtx(), Get_ID(), Get_TrxName());
                Decimal OnHand = Env.ZERO;
                Decimal Ordered = Env.ZERO;
                Decimal Reserved = Env.ZERO;
                for (int i = 0; i < storages.Length; i++)
                {
                    OnHand = Decimal.Add(OnHand, (storages[i].GetQtyOnHand()));
                    Ordered = Decimal.Add(OnHand, (storages[i].GetQtyOrdered()));
                    Reserved = Decimal.Add(OnHand, (storages[i].GetQtyReserved()));
                }
                String errMsg = "";
                if (Env.Signum(OnHand) != 0)
                    errMsg = "@QtyOnHand@ = " + OnHand;
                if (Env.Signum(Ordered) != 0)
                    errMsg += " - @QtyOrdered@ = " + Ordered;
                if (Env.Signum(Reserved) != 0)
                    errMsg += " - @QtyReserved@" + Reserved;
                if (errMsg.Length > 0)
                {
                    log.SaveError("Error", Msg.ParseTranslation(GetCtx(), errMsg));
                    return false;
                }
            }	//	storage

            //	Reset Stocked if not Item
            if (IsStocked() && !PRODUCTTYPE_Item.Equals(GetProductType()))
                SetIsStocked(false);

            //	UOM reset
            if (_precision != null && Is_ValueChanged("C_UOM_ID"))
                _precision = null;
            if (Util.GetValueOfInt(Env.GetCtx().GetContext("#AD_User_ID")) != 100)
            {
                if (Is_ValueChanged("C_UOM_ID") || Is_ValueChanged("M_AttributeSet_ID"))
                {
                    string uqry = "SELECT SUM(cc) as count FROM  (SELECT COUNT(*) AS cc FROM M_MovementLine WHERE M_Product_ID = " + GetM_Product_ID() + @"  UNION
                SELECT COUNT(*) AS cc FROM M_InventoryLine WHERE M_Product_ID = " + GetM_Product_ID() + " UNION SELECT COUNT(*) AS cc FROM C_OrderLine WHERE M_Product_ID = " + GetM_Product_ID() +
                    " UNION  SELECT COUNT(*) AS cc FROM M_InOutLine WHERE M_Product_ID = " + GetM_Product_ID() + ") t";
                    int no = Util.GetValueOfInt(DB.ExecuteScalar(uqry));
                    if (no == 0 || IsBOM())
                    {
                        uqry = "SELECT count(*) FROM M_ProductionPlan WHERE M_Product_ID = " + GetM_Product_ID();
                        no = Util.GetValueOfInt(DB.ExecuteScalar(uqry));
                    }
                    if (no > 0)
                    {
                        log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "Could not Save Record. Transactions available in System."));
                        return false;
                    }
                }
            }
            if (newRecord)
            {
                //string sql = "SELECT UPCUNIQUE('p','" + GetUPC() + "') as productID FROM Dual";
                //int manu_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));

                int manu_ID = UpcUniqueClientWise(GetAD_Client_ID(), GetUPC());
                if (manu_ID > 0)
                {
                    _log.SaveError("UPCUnique", "");
                    return false;
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(GetUPC()) &&
                   Util.GetValueOfString(Get_ValueOld("UPC")) != GetUPC())
                {
                    //string sql = "SELECT UPCUNIQUE('p','" + GetUPC() + "') as productID FROM Dual";
                    //int manu_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));
                    //if (manu_ID != 0 && manu_ID != GetM_Product_ID())

                    int manu_ID = UpcUniqueClientWise(GetAD_Client_ID(), GetUPC());
                    if (manu_ID > 0)
                    {
                        _log.SaveError("UPCUnique", "");
                        return false;
                    }
                }
            }
            return true;
        }
示例#16
0
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true</returns>
        protected override bool BeforeSave(bool newRecord)
        {
            if (GetLine() == 0)
            {
                SetLine();
            }

            //	Planned Amount	- Currency Precision
            Decimal plannedAmt = Decimal.Multiply(GetPlannedQty(), GetPlannedPrice());

            if (Env.Scale(plannedAmt) > GetCurPrecision())
            {
                //plannedAmt.setScale(GetCurPrecision(), Decimal.ROUND_HALF_UP);
                Decimal.Round(plannedAmt, GetCurPrecision(), MidpointRounding.AwayFromZero);
            }
            SetPlannedAmt(plannedAmt);

            //	Planned Margin
            if (Is_ValueChanged("M_Product_ID") || Is_ValueChanged("M_Product_Category_ID") ||
                Is_ValueChanged("PlannedQty") || Is_ValueChanged("PlannedPrice"))
            {
                if (GetM_Product_ID() != 0)
                {
                    Decimal marginEach = Decimal.Subtract(GetPlannedPrice(), GetLimitPrice());
                    SetPlannedMarginAmt(Decimal.Multiply(marginEach, GetPlannedQty()));
                }
                else if (GetM_Product_Category_ID() != 0)
                {
                    MProductCategory category   = MProductCategory.Get(GetCtx(), GetM_Product_Category_ID());
                    Decimal          marginEach = category.GetPlannedMargin();
                    SetPlannedMarginAmt(Decimal.Multiply(marginEach, GetPlannedQty()));
                }
            }

            //	Phase/Task
            if (Is_ValueChanged("C_ProjectTask_ID") && GetC_ProjectTask_ID() != 0)
            {
                MProjectTask pt = new MProjectTask(GetCtx(), GetC_ProjectTask_ID(), Get_TrxName());
                if (pt == null || pt.Get_ID() == 0)
                {
                    log.Warning("Project Task Not Found - ID=" + GetC_ProjectTask_ID());
                    return(false);
                }
                else
                {
                    SetC_ProjectPhase_ID(pt.GetC_ProjectPhase_ID());
                }
            }
            if (Is_ValueChanged("C_ProjectPhase_ID") && GetC_ProjectPhase_ID() != 0)
            {
                MProjectPhase pp = new MProjectPhase(GetCtx(), GetC_ProjectPhase_ID(), Get_TrxName());
                if (pp == null || pp.Get_ID() == 0)
                {
                    log.Warning("Project Phase Not Found - " + GetC_ProjectPhase_ID());
                    return(false);
                }
                else
                {
                    SetC_Project_ID(pp.GetC_Project_ID());
                }
            }

            return(true);
        }