public static bool CreateCostElementDetail(Ctx ctx, int AD_Client_ID, int AD_Org_ID, MProduct Product, int M_ASI_ID,
                                            MAcctSchema mas, int M_costElement_ID, string windowName, MCostDetail cd, decimal amt, decimal qty)
 {
     try
     {
         MCostElementDetail ced = new MCostElementDetail(ctx, 0, cd.Get_Trx());
         ced.SetAD_Client_ID(AD_Client_ID);
         ced.SetAD_Org_ID(AD_Org_ID);
         ced.SetC_AcctSchema_ID(mas.GetC_AcctSchema_ID());
         ced.SetM_CostElement_ID(M_costElement_ID);
         ced.SetM_Product_ID(Product.GetM_Product_ID());
         ced.SetM_AttributeSetInstance_ID(M_ASI_ID);
         ced.SetQty(qty);
         ced.SetAmt(amt);
         //Refrences
         ced.SetC_OrderLine_ID(cd.GetC_OrderLine_ID());
         ced.SetM_InOutLine_ID(cd.GetM_InOutLine_ID());
         if (windowName == "Material Receipt" || windowName == "Customer Return" || windowName == "Shipment" || windowName == "Return To Vendor")
         {
             // not to bind Invoiceline refernece on cost element detail
         }
         else
         {
             ced.SetC_InvoiceLine_ID(cd.GetC_InvoiceLine_ID());
         }
         ced.Set_Value("VAFAM_AssetDisposal_ID", cd.Get_Value("VAFAM_AssetDisposal_ID"));
         ced.SetM_InventoryLine_ID(cd.GetM_InventoryLine_ID());
         ced.SetM_MovementLine_ID(cd.GetM_MovementLine_ID());
         ced.SetC_ProjectIssue_ID(cd.GetC_ProjectIssue_ID());
         ced.SetIsSOTrx(cd.IsSOTrx());
         ced.SetA_Asset_ID(cd.GetA_Asset_ID());
         ced.SetM_ProductionLine_ID(cd.GetM_ProductionLine_ID());
         ced.SetM_WorkOrderResourceTxnLine_ID(cd.GetM_WorkOrderResourceTxnLine_ID());
         ced.SetM_WorkOrderTransactionLine_ID(cd.GetM_WorkOrderTransactionLine_ID());
         if (Env.IsModuleInstalled("VAMFG_"))
         {
             if (ced.Get_ColumnIndex("VAMFG_M_WrkOdrRscTxnLine_ID") > -1)
             {
                 ced.Set_Value("VAMFG_M_WrkOdrRscTxnLine_ID", cd.GetVAMFG_M_WrkOdrRscTxnLine_ID());
             }
             if (ced.Get_ColumnIndex("VAMFG_M_WrkOdrTrnsctionLine_ID") > -1)
             {
                 ced.Set_Value("VAMFG_M_WrkOdrTrnsctionLine_ID", cd.GetVAMFG_M_WrkOdrTrnsctionLine_ID());
             }
         }
         ced.SetM_Warehouse_ID(cd.GetM_Warehouse_ID());
         if (!ced.Save())
         {
             ValueNamePair pp = VLogger.RetrieveError();
             _log.Info("Error Occured during costing " + pp.ToString());
             return(false);
         }
     }
     catch (Exception ex)
     {
         _log.Info("Error Occured during costing " + ex.ToString());
         return(false);
     }
     return(true);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Get BOM Lines for Product. Default to Current Active, Master BOM
        /// BOM Lines are Ordered By Ascending Order of Product Names.
        /// </summary>
        /// <param name="product">product</param>
        /// <param name="bomType">bomtype</param>
        /// <param name="bomUse">bomuse</param>
        /// <param name="isAscending">true if ascending, false if descending</param>
        /// <returns>array of BOMs</returns>
        /// <writer>raghu</writer>
        /// <date>08-march-2011</date>
        public static MBOMProduct[] GetBOMLinesOrderByProductName(MProduct product, String bomType, String bomUse, Boolean isAscending)
        {
            // return lines for Current Active, Master BOM
            String sql = "SELECT M_BOM_ID FROM M_BOM WHERE M_Product_ID= " + product.GetM_Product_ID() +
                         "AND BOMType ='" + bomType + "' AND BOMUse ='" + bomUse + "' AND IsActive = 'Y'";
            Trx         trx   = product.Get_Trx();
            int         bomID = 0;
            IDataReader idr   = null;

            try
            {
                idr = DB.ExecuteReader(sql, null, trx);
                if (idr.Read())
                {
                    bomID = Util.GetValueOfInt(idr[0]);
                }
                idr.Close();
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
            }
            return(GetBOMLinesOrderByProductName(MBOM.Get(product.GetCtx(), bomID), isAscending));
        }
Exemplo n.º 3
0
 /**
  *  Parent Constructor (old)
  *	@param product parent
  *	@param C_AcctSchema_ID accounting schema
  */
 public MProductCosting(MProduct product, int C_AcctSchema_ID)
     : base(product.GetCtx(), 0, product.Get_TrxName())
 {
     SetClientOrg(product);
     SetM_Product_ID(product.GetM_Product_ID());
     SetC_AcctSchema_ID(C_AcctSchema_ID);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Get Cost Queue Records in Lifo/Fifo order
        /// </summary>
        /// <param name="product">product</param>
        /// <param name="M_ASI_ID">costing level ASI</param>
        /// <param name="mas">accounting schema</param>
        /// <param name="Org_ID">costing level org</param>
        /// <param name="ce">Cost Element</param>
        /// <param name="trxName">transaction</param>
        /// <returns>cost queue or null</returns>
        public static MCostQueue[] GetQueue(MProduct product, int M_ASI_ID, MAcctSchema mas,
                                            int Org_ID, MCostElement ce, Trx trxName)
        {
            List <MCostQueue> list = new List <MCostQueue>();
            String            sql  = "SELECT * FROM M_CostQueue "
                                     + "WHERE AD_Client_ID=@client AND AD_Org_ID=@org"
                                     + " AND M_Product_ID=@prod"
                                     + " AND M_CostType_ID=@ct AND C_AcctSchema_ID=@accs"
                                     + " AND M_CostElement_ID=@ce";

            if (M_ASI_ID != 0)
            {
                sql += " AND M_AttributeSetInstance_ID=@asi";
            }
            sql += " AND CurrentQty<>0 "
                   + "ORDER BY M_AttributeSetInstance_ID ";
            if (!ce.IsFifo())
            {
                sql += "DESC";
            }
            try
            {
                SqlParameter[] param = null;
                if (M_ASI_ID != 0)
                {
                    param = new SqlParameter[7];
                }
                else
                {
                    param = new SqlParameter[6];
                }
                param[0] = new SqlParameter("@client", product.GetAD_Client_ID());
                param[1] = new SqlParameter("@org", Org_ID);
                param[2] = new SqlParameter("@prod", product.GetM_Product_ID());
                param[3] = new SqlParameter("@ct", mas.GetM_CostType_ID());
                param[4] = new SqlParameter("@accs", mas.GetC_AcctSchema_ID());
                param[5] = new SqlParameter("@ce", ce.GetM_CostElement_ID());
                if (M_ASI_ID != 0)
                {
                    param[6] = new SqlParameter("@asi", M_ASI_ID);
                }
                DataSet ds = DataBase.DB.ExecuteDataset(sql, param, trxName);
                if (ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        list.Add(new MCostQueue(product.GetCtx(), dr, trxName));
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }

            MCostQueue[] costQ = new MCostQueue[list.Count];
            costQ = list.ToArray();
            return(costQ);
        }
        /**
         * verifyQuantity - checks that the warehouse specified in the work order transaction
         * has sufficient quantity of the product
         * @param product
         * @param wot
         * @param qty
         * @param asiID
         * @return error message if any, else Quantity Available
         */
        private String VerifyQuantity(VAdvantage.Model.MProduct product, ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction wot, Decimal qty, int asiID)
        {
            if (product.IsStocked())
            {
                ViennaAdvantage.Model.MVAMFGMWorkOrder wo = new ViennaAdvantage.Model.MVAMFGMWorkOrder(wot.GetCtx(), wot.GetVAMFG_M_WorkOrder_ID(), wot.Get_TrxName());
                int M_Warehouse_ID = wo.GetM_Warehouse_ID();

                //logic change by Raghu
                //Decimal available = ViennaAdvantage.Model.Storage.GetQtyAvailable
                //(M_Warehouse_ID, product.GetM_Product_ID(), asiID, null);

                // during creation of production execution line, reserverd qty to be checked or not
                Decimal?available = 0.0M;
                if (VAdvantage.Utility.Util.GetValueOfString(wot.GetConsiderReservedQty()) == "N")
                {
                    try
                    {
                        available = MStorage.GetQtyAvailableWithoutReserved
                                        (M_Warehouse_ID, product.GetM_Product_ID(), asiID, null);
                    }
                    catch
                    {
                        return(Msg.GetMsg(wot.GetCtx(), "PleaseUpdateVAFramework"));
                    }
                }
                else
                {
                    available = MStorage.GetQtyAvailable
                                    (M_Warehouse_ID, product.GetM_Product_ID(), asiID, null);
                }

                if (available == null)
                {
                    available = Env.ZERO;
                }
                if (Env.Signum(available.Value) == 0)
                {
                    return(Msg.GetMsg(wot.GetCtx(), "NoQtyAvailable", "0"));
                }
                else if (available.Value.CompareTo(qty) < 0)
                {
                    return(Msg.GetMsg(wot.GetCtx(), "InsufficientQtyAvailable", available.ToString()));
                }
            }
            return(Msg.GetMsg(wot.GetCtx(), "QtyAvailable"));
        } // verifyQuantity
Exemplo n.º 6
0
 /// <summary>
 /// Parent Constructor
 /// </summary>
 /// <param name="parent"></param>
 public MUOMConversion(MProduct parent)
     : this(parent.GetCtx(), 0, parent.Get_TrxName())
 {
     SetClientOrg(parent);
     SetC_UOM_ID(parent.GetC_UOM_ID());
     SetM_Product_ID(parent.GetM_Product_ID());
     SetC_UOM_To_ID(parent.GetC_UOM_ID());
     SetMultiplyRate(Env.ONE);
     SetDivideRate(Env.ONE);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Parent Constructor
 /// </summary>
 /// <param name="product">product</param>
 /// <param name="M_AttributeSetInstance_ID">Attribute Set Instance</param>
 /// <param name="mas">Acct Schema</param>
 /// <param name="AD_Org_ID">org</param>
 /// <param name="M_CostElement_ID">cost element</param>
 /// <param name="trxName">transaction</param>
 public MCostQueue(MProduct product, int M_AttributeSetInstance_ID,
                   MAcctSchema mas, int AD_Org_ID, int M_CostElement_ID, Trx trxName)
     : this(product.GetCtx(), 0, trxName)
 {
     SetClientOrg(product.GetAD_Client_ID(), AD_Org_ID);
     SetC_AcctSchema_ID(mas.GetC_AcctSchema_ID());
     SetM_CostType_ID(mas.GetM_CostType_ID());
     SetM_Product_ID(product.GetM_Product_ID());
     SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
     SetM_CostElement_ID(M_CostElement_ID);
 }
 public MCostForeignCurrency(int AD_Org_ID, MProduct product, int M_AttributeSetInstance_ID,
                             int M_CostElement_ID, int C_BPartner_ID, int C_Currency_ID)
     : this(product.GetCtx(), 0, product.Get_TrxName())
 {
     SetClientOrg(product.GetAD_Client_ID(), AD_Org_ID);
     SetM_Product_ID(product.GetM_Product_ID());
     SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
     SetM_CostElement_ID(M_CostElement_ID);
     SetC_BPartner_ID(C_BPartner_ID);
     SetC_Currency_ID(C_Currency_ID);
 }
 /// <summary>
 /// Set Product
 /// </summary>
 /// <param name="product">product product</param>
 public void SetProduct(VAdvantage.Model.MProduct product)
 {
     if (product != null)
     {
         SetM_Product_ID(product.GetM_Product_ID());
         SetC_UOM_ID(product.GetC_UOM_ID());
     }
     else
     {
         SetM_Product_ID(0);
         Set_ValueNoCheck("C_UOM_ID", null);
     }
     SetM_AttributeSetInstance_ID(0);
 }       //	setProduct
Exemplo n.º 10
0
 /*	Set Product
  *	@param product product
  */
 public void SetProduct(MProduct product)
 {
     _product = product;
     if (_product != null)
     {
         SetM_Product_ID(_product.GetM_Product_ID());
         SetC_UOM_ID(_product.GetC_UOM_ID());
     }
     else
     {
         SetM_Product_ID(0);
         SetC_UOM_ID(0);
     }
     SetM_AttributeSetInstance_ID(0);
 }
        /// <summary>
        /// Get Product
        /// </summary>
        /// <returns>product or null if not defined</returns>
        public MProduct GetProduct()
        {
            int M_Product_ID = GetM_Product_ID();

            if (M_Product_ID == 0)
            {
                return(null);
            }
            if (_product != null && _product.GetM_Product_ID() != M_Product_ID)
            {
                _product = null;        //	reset
            }
            if (_product == null)
            {
                _product = MProduct.Get(GetCtx(), M_Product_ID);
            }
            return(_product);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Get/Create Cost Queue Record.
        ///	CostingLevel is not validated
        /// </summary>
        /// <param name="product">product</param>
        /// <param name="M_AttributeSetInstance_ID">real asi</param>
        /// <param name="mas">accounting schema</param>
        /// <param name="AD_Org_ID">real org</param>
        /// <param name="M_CostElement_ID">element</param>
        /// <param name="trxName">transaction</param>
        /// <returns>cost queue or null</returns>
        public static MCostQueue Get(MProduct product, int M_AttributeSetInstance_ID,
                                     MAcctSchema mas, int AD_Org_ID, int M_CostElement_ID, Trx trxName)
        {
            MCostQueue costQ = null;
            String     sql   = "SELECT * FROM M_CostQueue "
                               + "WHERE AD_Client_ID=@client AND AD_Org_ID=@org"
                               + " AND M_Product_ID=@pro"
                               + " AND M_AttributeSetInstance_ID=@asi"
                               + " AND M_CostType_ID=@ct AND C_AcctSchema_ID=@accs"
                               + " AND M_CostElement_ID=@ce";

            try
            {
                SqlParameter[] param = new SqlParameter[7];
                param[0] = new SqlParameter("@client", product.GetAD_Client_ID());
                param[1] = new SqlParameter("@org", AD_Org_ID);
                param[2] = new SqlParameter("@pro", product.GetM_Product_ID());
                param[3] = new SqlParameter("@asi", M_AttributeSetInstance_ID);
                param[4] = new SqlParameter("@ct", mas.GetM_CostType_ID());
                param[5] = new SqlParameter("@accs", mas.GetC_AcctSchema_ID());
                param[6] = new SqlParameter("@ce", M_CostElement_ID);

                DataSet ds = DataBase.DB.ExecuteDataset(sql, param);
                if (ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        costQ = new MCostQueue(product.GetCtx(), dr, trxName);
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }

            //	New
            if (costQ == null)
            {
                costQ = new MCostQueue(product, M_AttributeSetInstance_ID,
                                       mas, AD_Org_ID, M_CostElement_ID, trxName);
            }
            return(costQ);
        }
        public static MCostForeignCurrency Get(MProduct product, int M_AttributeSetInstance_ID, int AD_Org_ID, int M_CostElement_ID,
                                               int C_BPartner_ID, int C_Currency_ID)
        {
            MCostForeignCurrency foreignCurrency = null;
            String sql = "SELECT * "
                         + "FROM M_Cost_ForeignCurrency c "
                         + "WHERE AD_Client_ID=" + product.GetAD_Client_ID() + " AND AD_Org_ID=" + AD_Org_ID
                         + " AND M_Product_ID=" + product.GetM_Product_ID()
                         + " AND NVL(M_AttributeSetInstance_ID , 0) =" + M_AttributeSetInstance_ID
                         + " AND M_CostElement_ID=" + M_CostElement_ID
                         + " AND C_BPartner_ID = " + C_BPartner_ID
                         + " AND C_Currency_ID = " + C_Currency_ID;
            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                idr = DB.ExecuteReader(sql, null, product.Get_TrxName());
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    foreignCurrency = new MCostForeignCurrency(product.GetCtx(), dr, product.Get_TrxName());
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally { dt = null; }

            //	New
            if (foreignCurrency == null)
            {
                foreignCurrency = new MCostForeignCurrency(AD_Org_ID, product, M_AttributeSetInstance_ID,
                                                           M_CostElement_ID, C_BPartner_ID, C_Currency_ID);
            }
            return(foreignCurrency);
        }
Exemplo n.º 14
0
        /**
         *  Shipment Constructor
         *  @param shipment shipment
         *	@param shipLine shipment line
         *	@param deliveryCount 0 or number of delivery
         */
        public MAsset(MInOut shipment, MInOutLine shipLine, int deliveryCount)
            : this(shipment.GetCtx(), 0, shipment.Get_TrxName())
        {
            SetClientOrg(shipment);

            SetValueNameDescription(shipment, shipLine, deliveryCount);
            //	Header

            // SetIsOwned(true);
            SetC_BPartner_ID(shipment.GetC_BPartner_ID());
            SetC_BPartner_Location_ID(shipment.GetC_BPartner_Location_ID());
            SetAD_User_ID(shipment.GetAD_User_ID());
            SetM_Locator_ID(shipLine.GetM_Locator_ID());
            SetIsInPosession(true);
            SetAssetServiceDate(shipment.GetDateAcct());

            //	Line
            MProduct product = shipLine.GetProduct();

            SetM_Product_ID(product.GetM_Product_ID());
            SetA_Asset_Group_ID(product.GetA_Asset_Group_ID());

            //////////////////////////////*
            //Changes for vafam
            // SetAssetServiceDate(shipment.GetMovementDate());
            //SetGuaranteeDate(TimeUtil.AddDays(shipment.GetMovementDate(), product.GetGuaranteeDays()));
            MAssetGroup _assetGroup = new MAssetGroup(GetCtx(), GetA_Asset_Group_ID(), shipment.Get_TrxName());

            if (_assetGroup.IsOwned())
            {
                SetIsOwned(true);
                //SetC_BPartner_ID(0);
            }
            if (_assetGroup.IsDepreciated())
            {
                SetIsDepreciated(true);
                SetIsFullyDepreciated(false);
            }

            //Change by Sukhwinder for setting Asset type and amortization template on Asset window, MANTIS ID:1762
            int countVA038 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA038_' "));
            int countVAFAM = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VAFAM_' "));

            if (countVA038 > 0)
            {
                Set_Value("VA038_AmortizationTemplate_ID", Utility.Util.GetValueOfInt(_assetGroup.Get_Value("VA038_AmortizationTemplate_ID")));
            }
            if (countVAFAM > 0)
            {
                Set_Value("VAFAM_AssetType", _assetGroup.Get_Value("VAFAM_AssetType").ToString());
                Set_Value("VAFAM_DepreciationType_ID", Utility.Util.GetValueOfInt(_assetGroup.Get_Value("VAFAM_DepreciationType_ID")));
            }
            ////////////////////////////////////


            //	Guarantee & Version
            SetGuaranteeDate(TimeUtil.AddDays(shipment.GetMovementDate(), product.GetGuaranteeDays()));
            SetVersionNo(product.GetVersionNo());
            if (shipLine.GetM_AttributeSetInstance_ID() != 0)           //	Instance
            {
                MAttributeSetInstance asi = new MAttributeSetInstance(GetCtx(), shipLine.GetM_AttributeSetInstance_ID(), Get_TrxName());
                SetM_AttributeSetInstance_ID(asi.GetM_AttributeSetInstance_ID());
                SetLot(asi.GetLot());
                SetSerNo(asi.GetSerNo());
            }
            SetHelp(shipLine.GetDescription());
            //	Qty
            int units = product.GetSupportUnits();

            if (units == 0)
            {
                units = 1;
            }
            if (deliveryCount != 0)             //	one asset per UOM
            {
                SetQty(shipLine.GetMovementQty(), units);
            }
            else
            {
                SetQty((Decimal)units);
            }
            SetM_InOutLine_ID(shipLine.GetM_InOutLine_ID());

            //	Activate
            MAssetGroup ag = MAssetGroup.Get(GetCtx(), GetA_Asset_Group_ID());

            if (!ag.IsCreateAsActive())
            {
                SetIsActive(false);
            }

            //Check if the Software Industry module installed, update following fields on Asset window
            if (Env.IsModuleInstalled("VA077_"))
            {
                //Set default values
                SetIsInPosession(false);
                SetIsOwned(false);
                SetIsActive(true);
                SetIsDisposed(false);

                Set_Value("VA077_SerialNo", shipLine.Get_Value("VA077_SerialNo"));
                Set_Value("VA077_CNAutodesk", shipLine.Get_Value("VA077_CNAutodesk"));
                Set_Value("VA077_RegEmail", shipLine.Get_Value("VA077_RegEmail"));
                Set_Value("VA077_IsCustAsset", "Y");
                Set_Value("VA077_OldSN", shipLine.Get_Value("VA077_OldSN"));
                Set_Value("VA077_UserRef_ID", shipLine.Get_Value("VA077_UserRef_ID"));
                Set_Value("VA077_ProductInfo", shipLine.Get_Value("VA077_ProductInfo"));
                Set_Value("VA077_ServiceContract_ID", shipLine.Get_Value("VA077_ServiceContract_ID"));
                Set_Value("AD_OrgTrx_ID", shipLine.Get_Value("AD_OrgTrx_ID"));

                if (Util.GetValueOfBool(product.Get_Value("VA077_LicenceTracked")))
                {
                    Set_Value("VA077_LicenceTracked", "Y");
                }
                else
                {
                    Set_Value("VA077_LicenceTracked", "N");
                }
            }
        }
Exemplo n.º 15
0
        /**
         *  Create Trial Asset
         *	@param ctx context
         *	@param user user
         *	@param entityType entity type
         *	@return asset or null if no product found
         */
        public static MAsset GetTrial(Ctx ctx, MUser user, String entityType)
        {
            if (user == null)
            {
                _log.Warning("Cannot create Trial - No User");
                return(null);
            }
            if (Utility.Util.IsEmpty(entityType))
            {
                _log.Warning("Cannot create Trial - No Entity Type");
                return(null);
            }
            MProduct product = MProduct.GetTrial(ctx, entityType);

            if (product == null)
            {
                _log.Warning("No Trial for Entity Type=" + entityType);
                return(null);
            }
            //
            DateTime now = Convert.ToDateTime(CommonFunctions.CurrentTimeMillis());
            //
            MAsset asset = new MAsset(ctx, 0, null);

            asset.SetClientOrg(user);
            asset.SetAssetServiceDate(now);
            asset.SetIsOwned(false);
            asset.SetIsTrialPhase(true);
            //
            MBPartner partner    = new MBPartner(ctx, user.GetC_BPartner_ID(), null);
            String    documentNo = "Trial";
            //	Value
            String value = partner.GetValue() + "_" + product.GetValue();

            if (value.Length > 40 - documentNo.Length)
            {
                value = value.Substring(0, 40 - documentNo.Length) + documentNo;
            }
            asset.SetValue(value);
            //	Name		MProduct.afterSave
            String name = "Trial " + partner.GetName() + " - " + product.GetName();

            if (name.Length > 60)
            {
                name = name.Substring(0, 60);
            }
            asset.SetName(name);
            //	Description
            String description = product.GetDescription();

            asset.SetDescription(description);

            //	User
            asset.SetAD_User_ID(user.GetAD_User_ID());
            asset.SetC_BPartner_ID(user.GetC_BPartner_ID());
            //	Product
            asset.SetM_Product_ID(product.GetM_Product_ID());
            asset.SetA_Asset_Group_ID(product.GetA_Asset_Group_ID());
            asset.SetQty(new Decimal(product.GetSupportUnits()));
            //	Guarantee & Version
            asset.SetGuaranteeDate(TimeUtil.AddDays(now, product.GetTrialPhaseDays()));
            asset.SetVersionNo(product.GetVersionNo());
            //
            return(asset);
        }
        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);
        }
        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);
        }
Exemplo n.º 18
0
        // Create Asset From Invoice Mohit

        /**
         *  Shipment Constructor
         *  @param Invoice
         *	@param shipLine shipment line
         *	@param deliveryCount 0 or number of delivery
         */
        public MAsset(MInvoice invoice, MInvoiceLine invoiceline, int deliveryCount)
            : this(invoiceline.GetCtx(), 0, invoiceline.Get_TrxName())
        {
            SetClientOrg(invoiceline);

            SetValueNameDescription(invoice, invoiceline, deliveryCount);
            //	Header

            //SetIsOwned(true);
            SetC_BPartner_ID(invoice.GetC_BPartner_ID());
            SetC_BPartner_Location_ID(invoice.GetC_BPartner_Location_ID());
            SetAD_User_ID(invoice.GetAD_User_ID());
            //SetM_Locator_ID(invoice.GetM_Locator_ID());
            SetIsInPosession(true);


            SetAssetServiceDate(invoice.GetDateAcct());


            //	Line
            MProduct product = invoiceline.GetProduct();

            SetM_Product_ID(product.GetM_Product_ID());
            SetA_Asset_Group_ID(product.GetA_Asset_Group_ID());

            //////////////////////////////*
            //Changes for vafam
            // SetAssetServiceDate(shipment.GetMovementDate());
            //SetGuaranteeDate(TimeUtil.AddDays(shipment.GetMovementDate(), product.GetGuaranteeDays()));
            MAssetGroup _assetGroup = new MAssetGroup(GetCtx(), GetA_Asset_Group_ID(), invoice.Get_TrxName());

            if (_assetGroup.IsOwned())
            {
                SetIsOwned(true);
                //SetC_BPartner_ID(0);
            }
            if (_assetGroup.IsDepreciated())
            {
                SetIsDepreciated(true);
                SetIsFullyDepreciated(false);
            }
            ////////////////////////////////////
            //Change by Sukhwinder for setting Asset type and amortization template on Asset window, MANTIS ID:1762
            int countVA038 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA038_' "));
            int countVAFAM = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VAFAM_' "));

            if (countVA038 > 0)
            {
                Set_Value("VA038_AmortizationTemplate_ID", Utility.Util.GetValueOfInt(_assetGroup.Get_Value("VA038_AmortizationTemplate_ID")));
            }
            if (countVAFAM > 0)
            {
                Set_Value("VAFAM_AssetType", _assetGroup.Get_Value("VAFAM_AssetType").ToString());
                Set_Value("VAFAM_DepreciationType_ID", Utility.Util.GetValueOfInt(_assetGroup.Get_Value("VAFAM_DepreciationType_ID")));
            }

            ////////////////////////////////////

            //	Guarantee & Version
            SetGuaranteeDate(TimeUtil.AddDays(invoice.GetDateInvoiced(), product.GetGuaranteeDays()));
            SetVersionNo(product.GetVersionNo());
            if (invoiceline.GetM_AttributeSetInstance_ID() != 0)                //	Instance
            {
                MAttributeSetInstance asi = new MAttributeSetInstance(GetCtx(), invoiceline.GetM_AttributeSetInstance_ID(), Get_TrxName());
                SetM_AttributeSetInstance_ID(asi.GetM_AttributeSetInstance_ID());
                SetLot(asi.GetLot());
                SetSerNo(asi.GetSerNo());
            }
            SetHelp(invoiceline.GetDescription());
            //	Qty
            int units = product.GetSupportUnits();

            if (units == 0)
            {
                units = 1;
            }
            if (deliveryCount != 0)             //	one asset per UOM
            {
                SetQty(invoiceline.GetQtyEntered(), units);
            }
            else
            {
                SetQty((Decimal)units);
            }
            SetM_InOutLine_ID(invoiceline.GetM_InOutLine_ID());
            Set_Value("C_InvoiceLine_ID", invoiceline.GetC_InvoiceLine_ID());

            //	Activate
            MAssetGroup ag = MAssetGroup.Get(GetCtx(), GetA_Asset_Group_ID());

            if (!ag.IsCreateAsActive())
            {
                SetIsActive(false);
            }
        }
Exemplo n.º 19
0
        /**
         *  Shipment Constructor
         *  @param shipment shipment
         *	@param shipLine shipment line
         *	@param deliveryCount 0 or number of delivery
         */
        public MAsset(MInOut shipment, MInOutLine shipLine, int deliveryCount)
            : this(shipment.GetCtx(), 0, shipment.Get_TrxName())
        {
            SetClientOrg(shipment);

            SetValueNameDescription(shipment, shipLine, deliveryCount);
            //	Header

            SetIsOwned(true);
            SetC_BPartner_ID(shipment.GetC_BPartner_ID());
            SetC_BPartner_Location_ID(shipment.GetC_BPartner_Location_ID());
            SetAD_User_ID(shipment.GetAD_User_ID());
            SetM_Locator_ID(shipLine.GetM_Locator_ID());
            SetIsInPosession(true);

            //	Line
            MProduct product = shipLine.GetProduct();

            SetM_Product_ID(product.GetM_Product_ID());
            SetA_Asset_Group_ID(product.GetA_Asset_Group_ID());

            //////////////////////////////*
            //Changes for vafam
            // SetAssetServiceDate(shipment.GetMovementDate());
            //SetGuaranteeDate(TimeUtil.AddDays(shipment.GetMovementDate(), product.GetGuaranteeDays()));
            MAssetGroup _assetGroup = new MAssetGroup(GetCtx(), GetA_Asset_Group_ID(), shipment.Get_TrxName());

            if (_assetGroup.IsOwned())
            {
                SetIsOwned(true);
                //SetC_BPartner_ID(0);
            }
            if (_assetGroup.IsDepreciated())
            {
                SetIsDepreciated(true);
                SetIsFullyDepreciated(false);
            }
            ////////////////////////////////////


            //	Guarantee & Version
            SetGuaranteeDate(TimeUtil.AddDays(shipment.GetMovementDate(), product.GetGuaranteeDays()));
            SetVersionNo(product.GetVersionNo());
            if (shipLine.GetM_AttributeSetInstance_ID() != 0)           //	Instance
            {
                MAttributeSetInstance asi = new MAttributeSetInstance(GetCtx(), shipLine.GetM_AttributeSetInstance_ID(), Get_TrxName());
                SetM_AttributeSetInstance_ID(asi.GetM_AttributeSetInstance_ID());
                SetLot(asi.GetLot());
                SetSerNo(asi.GetSerNo());
            }
            SetHelp(shipLine.GetDescription());
            //	Qty
            int units = product.GetSupportUnits();

            if (units == 0)
            {
                units = 1;
            }
            if (deliveryCount != 0)             //	one asset per UOM
            {
                SetQty(shipLine.GetMovementQty(), units);
            }
            else
            {
                SetQty((Decimal)units);
            }
            SetM_InOutLine_ID(shipLine.GetM_InOutLine_ID());

            //	Activate
            MAssetGroup ag = MAssetGroup.Get(GetCtx(), GetA_Asset_Group_ID());

            if (!ag.IsCreateAsActive())
            {
                SetIsActive(false);
            }
        }
        /**
         *  Get First M_Locator_ID for product and Warehouse ordered by priority of Locator
         *	@param product product
         *	@param M_Warehouse_ID wh
         *	@return locator or 0 if none
         */
        public static int GetFirstM_Locator_ID(MProduct product, int M_Warehouse_ID)
        {
            if (product == null || M_Warehouse_ID == 0)
            {
                return(0);
            }
            //
            int    M_Locator_ID = 0;
            String sql          = "SELECT M_Locator_ID FROM M_Locator l "
                                  + "WHERE l.IsActive='Y'"
                                  + " AND (M_Locator_ID IN (SELECT M_Locator_ID FROM M_Product WHERE M_Product_ID=" + product.GetM_Product_ID() + ")"
                                  + " OR M_Locator_ID IN (SELECT M_Locator_ID FROM M_ProductLocator WHERE M_Product_ID=" + product.GetM_Product_ID() + " AND IsActive='Y'))"
                                  + " AND M_Warehouse_ID= " + M_Warehouse_ID
                                  + "ORDER BY PriorityNo DESC";
            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, product.Get_TrxName());
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    M_Locator_ID = Convert.ToInt32(dr[0]);// rs.getInt(1);
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally {
                if (idr != null)
                {
                    idr.Close();
                }
                dt = null;
            }
            return(M_Locator_ID);
        }
        /**
         *  Get array of active Locators for Product and warehouse ordered by priority
         *	@param product product
         *	@param M_Warehouse_ID wh
         *	@return product locators
         */
        public static MLocator[] GetLocators(MProduct product, int M_Warehouse_ID)
        {
            List <MLocator> list = new List <MLocator>();
            String          sql  = "SELECT * FROM M_Locator l "
                                   + "WHERE l.IsActive='Y'"
                                   + " AND (M_Locator_ID IN (SELECT M_Locator_ID FROM M_Product WHERE M_Product_ID=" + product.GetM_Product_ID() + ")"
                                   + " OR M_Locator_ID IN (SELECT M_Locator_ID FROM M_ProductLocator WHERE M_Product_ID=" + product.GetM_Product_ID() + " AND IsActive='Y'))"
                                   + " AND M_Warehouse_ID=" + M_Warehouse_ID
                                   + "ORDER BY PriorityNo DESC";
            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, product.Get_TrxName());
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(new MLocator(product.GetCtx(), dr, product.Get_TrxName()));
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally {
                if (idr != null)
                {
                    idr.Close();
                }
                dt = null;
            }
            MLocator[] retValue = new MLocator[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
Exemplo n.º 22
0
 /**
  *  Get BOM Lines for Product
  *	@param product product
  *	@return array of BOMs
  */
 public static MProductBOM[] GetBOMLines(MProduct product)
 {
     return(GetBOMLines(product.GetCtx(), product.GetM_Product_ID(), product.Get_TrxName()));
 }