📄 masset.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.model;
import java.util.*;
import java.sql.*;
import java.math.*;
import java.io.*;
import java.net.*;
import org.compiere.util.*;
/**
* Asset Model
*
* @author Jorg Janke
* @version $Id: MAsset.java,v 1.3 2003/04/28 04:18:58 jjanke Exp $
*/
public class MAsset extends PO
{
/**
* Asset Constructor
* @param ctx context
* @param A_Asset_ID asset
*/
public MAsset (Properties ctx, int A_Asset_ID)
{
super (ctx, A_Asset_ID);
if (A_Asset_ID == 0)
{
setIsDepreciated (false);
setIsFullyDepreciated (false);
setValue (null);
setName (null);
setIsInPosession (false);
setIsOwned (false);
setA_Asset_Group_ID (0);
setA_Asset_ID (0);
setIsDisposed (false);
}
} // MAsset
/**
* Load Constructor
* @param ctx context
* @param rs result set record
*/
public MAsset (Properties ctx, ResultSet rs)
{
super (ctx, rs);
} // MAsset
/** Description URL */
private String m_DescriptionURL = null;
protected POInfo initPO (Properties ctx)
{
int AD_Table_ID = 539;
POInfo poi = POInfo.getPOInfo (ctx, AD_Table_ID);
return poi;
}
public boolean save ()
{
log.debug ("save");
return super.save ();
}
public String toString ()
{
StringBuffer sb = new StringBuffer ("MAsset[").append (getID ()).append ("]");
return sb.toString ();
}
public void setUseLifeMonths (int UseLifeMonths)
{
setValue ("UseLifeMonths", new Integer (UseLifeMonths));
}
public int getUseLifeMonths ()
{
Integer ii = (Integer)getValue ("UseLifeMonths");
if (ii == null)
return 0;
return ii.intValue ();
}
void setUseUnits (int UseUnits)
{
setValueNoCheck ("UseUnits", new Integer (UseUnits));
}
public int getUseUnits ()
{
Integer ii = (Integer)getValue ("UseUnits");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setSerNo (String SerNo)
{
setValue ("SerNo", SerNo);
}
public String getSerNo ()
{
return (String)getValue ("SerNo");
}
public void setAssetDisposalDate (Timestamp AssetDisposalDate)
{
setValue ("AssetDisposalDate", AssetDisposalDate);
}
public Timestamp getAssetDisposalDate ()
{
return (Timestamp)getValue ("AssetDisposalDate");
}
public void setC_Location_ID (int C_Location_ID)
{
setValue ("C_Location_ID", new Integer (C_Location_ID));
}
public int getC_Location_ID ()
{
Integer ii = (Integer)getValue ("C_Location_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setVersionNo (String VersionNo)
{
setValue ("VersionNo", VersionNo);
}
public String getVersionNo ()
{
return (String)getValue ("VersionNo");
}
public void setDescription (String Description)
{
setValue ("Description", Description);
}
public String getDescription ()
{
return (String)getValue ("Description");
}
public void setLifeUseUnits (int LifeUseUnits)
{
setValue ("LifeUseUnits", new Integer (LifeUseUnits));
}
public int getLifeUseUnits ()
{
Integer ii = (Integer)getValue ("LifeUseUnits");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setProcessing (String Processing)
{
setValue ("Processing", Processing);
}
public String getProcessing ()
{
return (String)getValue ("Processing");
}
public void setHelp (String Help)
{
setValue ("Help", Help);
}
public String getHelp ()
{
return (String)getValue ("Help");
}
public void setGuaranteeDate (Timestamp GuaranteeDate)
{
setValue ("GuaranteeDate", GuaranteeDate);
}
public Timestamp getGuaranteeDate ()
{
return (Timestamp)getValue ("GuaranteeDate");
}
public void setAssetServiceDate (Timestamp AssetServiceDate)
{
setValue ("AssetServiceDate", AssetServiceDate);
}
public Timestamp getAssetServiceDate ()
{
return (Timestamp)getValue ("AssetServiceDate");
}
public void setIsDepreciated (boolean IsDepreciated)
{
setValue ("IsDepreciated", new Boolean (IsDepreciated));
}
public boolean isDepreciated ()
{
Boolean bb = (Boolean)getValue ("IsDepreciated");
if (bb != null)
return bb.booleanValue ();
return false;
}
public void setC_BPartner_Location_ID (int C_BPartner_Location_ID)
{
setValue ("C_BPartner_Location_ID", new Integer (C_BPartner_Location_ID));
}
public int getC_BPartner_Location_ID ()
{
Integer ii = (Integer)getValue ("C_BPartner_Location_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
void setIsFullyDepreciated (boolean IsFullyDepreciated)
{
setValueNoCheck ("IsFullyDepreciated", new Boolean (IsFullyDepreciated));
}
public boolean isFullyDepreciated ()
{
Boolean bb = (Boolean)getValue ("IsFullyDepreciated");
if (bb != null)
return bb.booleanValue ();
return false;
}
public void setValue (String Value)
{
if (Value == null)
throw new IllegalArgumentException ("Value is mandatory");
setValue ("Value", Value);
}
public String getValue ()
{
return (String)getValue ("Value");
}
public void setName (String Name)
{
if (Name == null)
throw new IllegalArgumentException ("Name is mandatory");
setValue ("Name", Name);
}
public String getName ()
{
return (String)getValue ("Name");
}
public void setC_BPartner_ID (int C_BPartner_ID)
{
setValue ("C_BPartner_ID", new Integer (C_BPartner_ID));
}
public int getC_BPartner_ID ()
{
Integer ii = (Integer)getValue ("C_BPartner_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
void setM_Product_ID (int M_Product_ID)
{
setValueNoCheck ("M_Product_ID", new Integer (M_Product_ID));
}
public int getM_Product_ID ()
{
Integer ii = (Integer)getValue ("M_Product_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setIsInPosession (boolean IsInPosession)
{
setValue ("IsInPosession", new Boolean (IsInPosession));
}
public boolean isInPosession ()
{
Boolean bb = (Boolean)getValue ("IsInPosession");
if (bb != null)
return bb.booleanValue ();
return false;
}
public void setIsOwned (boolean IsOwned)
{
setValue ("IsOwned", new Boolean (IsOwned));
}
public boolean isOwned ()
{
Boolean bb = (Boolean)getValue ("IsOwned");
if (bb != null)
return bb.booleanValue ();
return false;
}
public void setLocationComment (String LocationComment)
{
setValue ("LocationComment", LocationComment);
}
public String getLocationComment ()
{
return (String)getValue ("LocationComment");
}
public void setUseLifeYears (int UseLifeYears)
{
setValue ("UseLifeYears", new Integer (UseLifeYears));
}
public int getUseLifeYears ()
{
Integer ii = (Integer)getValue ("UseLifeYears");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setA_Asset_Group_ID (int A_Asset_Group_ID)
{
setValue ("A_Asset_Group_ID", new Integer (A_Asset_Group_ID));
}
public int getA_Asset_Group_ID ()
{
Integer ii = (Integer)getValue ("A_Asset_Group_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
void setA_Asset_ID (int A_Asset_ID)
{
setValueNoCheck ("A_Asset_ID", new Integer (A_Asset_ID));
}
public int getA_Asset_ID ()
{
Integer ii = (Integer)getValue ("A_Asset_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setAssetDepreciationDate (Timestamp AssetDepreciationDate)
{
setValue ("AssetDepreciationDate", AssetDepreciationDate);
}
public Timestamp getAssetDepreciationDate ()
{
return (Timestamp)getValue ("AssetDepreciationDate");
}
public void setLot (String Lot)
{
setValue ("Lot", Lot);
}
public String getLot ()
{
return (String)getValue ("Lot");
}
public void setC_BPartner_Contact_ID (int C_BPartner_Contact_ID)
{
setValue ("C_BPartner_Contact_ID", new Integer (C_BPartner_Contact_ID));
}
public int getC_BPartner_Contact_ID ()
{
Integer ii = (Integer)getValue ("C_BPartner_Contact_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setIsDisposed (boolean IsDisposed)
{
setValue ("IsDisposed", new Boolean (IsDisposed));
}
public boolean isDisposed ()
{
Boolean bb = (Boolean)getValue ("IsDisposed");
if (bb != null)
return bb.booleanValue ();
return false;
}
public void setM_Locator_ID (int M_Locator_ID)
{
setValue ("M_Locator_ID", new Integer (M_Locator_ID));
}
public int getM_Locator_ID ()
{
Integer ii = (Integer)getValue ("M_Locator_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
/*************************************************************************/
/**
* Get Deliveriew
* @return deliveriew
*/
public MAsset_Delivery[] getDeliveries()
{
ArrayList list = new ArrayList();
String sql = "SELECT * FROM A_Asset_Delivery WHERE A_Asset_ID=?";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, getA_Asset_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next())
list.add(new MAsset_Delivery(getCtx(), rs));
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.error("getDeliveriew", e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
//
MAsset_Delivery[] retValue = new MAsset_Delivery[list.size()];
list.toArray(retValue);
return retValue;
} // getDeliveries
/*************************************************************************/
/**
* Can we download.
* Based on guarantee date and availability of download
* @return true if downloadable
*/
public boolean isDownloadable()
{
Timestamp now = new Timestamp (System.currentTimeMillis());
Timestamp guarantee = getGuaranteeDate();
if (guarantee == null)
return false;
// valid
if (now.before(guarantee))
{
String where = getDownloadURL(); // do we have a link
return (where != null && where.length() > 0);
}
//
return false;
} // isDownloadable
/**
* Get Download URL
* @return download URL
*/
public String getDownloadURL()
{
if (m_DescriptionURL != null)
return m_DescriptionURL;
//
String sql = "SELECT DescriptionURL "
+ "FROM A_Asset a"
+ " INNER JOIN M_Product p ON (a.M_Product_ID=p.M_Product_ID) "
+ "WHERE A_Asset_ID=?";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, getA_Asset_ID());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
m_DescriptionURL = rs.getString(1);
else
m_DescriptionURL = "";
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.error("getDownloadURL", e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
return m_DescriptionURL;
} // getDownloadURL
/**
* Get Download URL
* @return download URL
*/
public String getDownloadName()
{
if (!isDownloadable())
return null;
String name = getDownloadURL ();
int pos = Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\'));
if (pos != -1)
return name.substring(pos+1);
return name;
} // getDownloadName
/**
* Get Download (file or url)
* @param directory optional directory
* @return input stream
*/
public InputStream getDownload(String directory)
{
if (!isDownloadable())
return null;
InputStream in = null;
String where = getDownloadURL();
try
{
if (where.indexOf ("://") != -1)
{
URL url = new URL (where);
in = url.openStream();
}
else // file
{
File file = new File (where); // absolute file
if (!file.exists())
{
if (directory == null || directory.length() == 0)
{
log.error("getDownload - Not found " + where);
return null;
}
String where2 = directory;
if (!where2.endsWith(File.separator))
where2 += File.separator;
where2 += where;
file = new File (where2);
if (!file.exists())
{
log.error("getDownload - Not found " + where + " + " + where2);
return null;
}
}
in = new FileInputStream (file);
}
}
catch (Exception ex)
{
log.error("getDownload - " + where, ex);
return null;
}
return in;
} // getDownload
} // MAsset
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -