/// <summary> /// Get Trial Products for Entity Type /// </summary> /// <param name="ctx">ctx</param> /// <param name="entityType">entity type</param> /// <returns>trial product or null</returns> public static MProduct GetTrial(Ctx ctx, String entityType) { if (Util.IsEmpty(entityType)) { _log.Warning("No Entity Type"); return(null); } MProduct retValue = null; String sql = "SELECT * FROM M_Product " + "WHERE LicenseInfo LIKE '%" + entityType + "%' AND TrialPhaseDays > 0 AND IsActive='Y'"; //String entityTypeLike = "%" + entityType + "%"; //pstmt.setString(1, entityTypeLike); DataSet ds = new DataSet(); try { ds = DB.ExecuteDataset(sql, null, null); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { DataRow dr = ds.Tables[0].Rows[i]; retValue = new MProduct(ctx, dr, null); } ds = null; } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } if (retValue != null && retValue.GetAD_Client_ID() != ctx.GetAD_Client_ID()) { _log.Warning("ProductClient_ID=" + retValue.GetAD_Client_ID() + " <> EnvClient_ID=" + ctx.GetAD_Client_ID()); } if (retValue != null && retValue.GetA_Asset_Group_ID() == 0) { _log.Warning("Product has no Asset Group - " + retValue); return(null); } if (retValue == null) { _log.Warning("No Product for EntityType - " + entityType); } return(retValue); }
/** * 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); } }