예제 #1
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);
        }
예제 #2
0
        /// <summary>
        /// Constructor called from BOM Drop
        /// </summary>
        /// <param name="workorder"></param>
        /// <param name="workorderoperation"></param>
        /// <param name="product"></param>
        /// <param name="QtyRequired"></param>
        /// <param name="SupplyType"></param>
        /// <param name="locator"></param>
        public MVAMFGMWorkOrderComponent(ViennaAdvantage.Model.MVAMFGMWorkOrder workorder, MVAMFGMWorkOrderOperation workorderoperation, ViennaAdvantage.Model.MProduct product, Decimal QtyRequired,
                                         String SupplyType, int M_AttributeSetInstance_ID, VAdvantage.Model.MLocator locator)
            : this(workorderoperation.GetCtx(), 0, workorderoperation.Get_TrxName())
        {
            if (workorderoperation.Get_ID() == 0)
            {
                throw new Exception("Header not saved");
            }
            SetVAMFG_M_WorkOrderOperation_ID(workorderoperation.GetVAMFG_M_WorkOrderOperation_ID());    //	parent
            SetM_Product_ID(product.GetM_Product_ID());
            SetC_UOM_ID(product.GetC_UOM_ID());
            SetVAMFG_QtyRequired(QtyRequired);
            SetVAMFG_SupplyType(SupplyType);
            // Changes done b y Vivek Kumar assigned by Mukesh on 16/11/2017
            // Changes done to save AttributesetInstance at Work Order component
            SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
            if (locator != null)
            {
                SetM_Locator_ID(locator.GetM_Locator_ID());
            }

            SetWorkOrder(workorder);
        }
        /**
         *  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 (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);
        }
        // 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_' "));

            Set_Value("VAFAM_AssetType", _assetGroup.Get_Value("VAFAM_AssetType").ToString());
            if (countVA038 > 0)
            {
                Set_Value("VA038_AmortizationTemplate_ID", VAdvantage.Utility.Util.GetValueOfInt(_assetGroup.Get_Value("VA038_AmortizationTemplate_ID")));
            }
            Set_Value("VAFAM_DepreciationType_ID", VAdvantage.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);
            }
        }