use of org.compiere.model.Query in project adempiere by adempiere.
the class InventoryUtil method getCreateCharge.
public static MCharge getCreateCharge(String value) {
Properties ctx = Env.getCtx();
String whereClause = MCharge.COLUMNNAME_Name + "=?";
MCharge charge = new Query(ctx, MCharge.Table_Name, whereClause, null).setParameters(new Object[] { value }).setOnlyActiveRecords(true).setClient_ID().firstOnly();
if (charge == null) {
charge = new MCharge(ctx, 0, null);
charge.setName(value);
setGeneratedTag(charge);
charge.saveEx();
}
return charge;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class InventoryUtil method getCreatePartner.
public static MBPartner getCreatePartner(String value) {
Properties ctx = Env.getCtx();
String whereClause = MBPartner.COLUMNNAME_Value + "=?";
MBPartner bp = new Query(ctx, MBPartner.Table_Name, whereClause, null).setParameters(new Object[] { value }).setClient_ID().firstOnly();
if (bp == null) {
bp = new MBPartner(ctx, 0, null);
}
bp.setValue(value);
bp.setName(value);
setGeneratedTag(bp);
bp.setIsCustomer(true);
bp.setIsVendor(true);
bp.setC_BP_Group_ID(MBPGroup.getDefault(ctx).get_ID());
bp.saveEx();
//
if (bp.getLocations(false).length == 0) {
MLocation loc = new MLocation(ctx, 0, null);
loc.saveEx();
//
MBPartnerLocation bpl = new MBPartnerLocation(bp);
bpl.setC_Location_ID(loc.get_ID());
bpl.saveEx();
}
return bp;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class MDepreciationWorkfile method setA_Current_Period.
/**
* Set A Current Period (and Data Act) processed just after the last expense.
* Do not save.
*/
public void setA_Current_Period() {
String whereClause = MDepreciationExp.COLUMNNAME_A_Asset_ID + "=?" + " AND " + MDepreciationExp.COLUMNNAME_PostingType + "=?" + " AND " + MDepreciationExp.COLUMNNAME_Processed + "=? AND IsActive=?";
//
MDepreciationExp depexp = new Query(getCtx(), MDepreciationExp.Table_Name, whereClause, get_TrxName()).setParameters(new Object[] { getA_Asset_ID(), getPostingType(), true, true }).setOrderBy(MDepreciationExp.COLUMNNAME_A_Period + " DESC" + "," + MDepreciationExp.COLUMNNAME_DateAcct + " DESC").first();
if (depexp != null) {
setA_Current_Period(depexp.getA_Period());
setDateAcct(depexp.getDateAcct());
incA_Current_Period();
} else {
log.info("There are no records from which to infer its");
}
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class A_Depreciation_Workfile_Build method doIt.
protected String doIt() throws Exception {
int cnt_all = 0;
if (A_Depreciation_Workfile_ID > 0) {
MDepreciationWorkfile wk = new MDepreciationWorkfile(getCtx(), A_Depreciation_Workfile_ID, get_TrxName());
wk.buildDepreciation();
wk.saveEx();
cnt_all = 1;
} else {
String whereClause = MDepreciationWorkfile.COLUMNNAME_IsDepreciated + "='Y'";
POResultSet<MDepreciationWorkfile> rs = new Query(getCtx(), MDepreciationWorkfile.Table_Name, whereClause, get_TrxName()).scroll();
try {
while (rs.hasNext()) {
MDepreciationWorkfile wk = rs.next();
wk.buildDepreciation();
wk.saveEx();
}
} finally {
DB.close(rs);
rs = null;
}
}
//
return "@Processed@ #" + cnt_all;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class MAssetAcct method forA_Asset_ID.
/**
* Get asset accounting.
* @param ctx context
* @param A_Asset_ID asset
* @param postingType Posting type
* @param dateAcct check ValidFrom
* @return asset accounting for the given asset
*/
public static MAssetAcct forA_Asset_ID(Properties ctx, int A_Asset_ID, String postingType, Timestamp dateAcct, String trxName) {
MultiKey key = new MultiKey(A_Asset_ID, postingType, dateAcct);
MAssetAcct acct = null;
if (trxName == null) {
// do not use cache
//acct = s_cacheAsset.get(key);
}
if (acct != null) {
return acct;
}
//
ArrayList<Object> params = new ArrayList<Object>();
StringBuffer whereClause = new StringBuffer(COLUMNNAME_A_Asset_ID + "=? AND " + COLUMNNAME_PostingType + "=?");
params.add(A_Asset_ID);
params.add(postingType);
if (dateAcct != null) {
whereClause.append(" AND " + COLUMNNAME_ValidFrom).append("<=?");
params.add(dateAcct);
}
acct = new Query(ctx, Table_Name, whereClause.toString(), trxName).setParameters(params).setOrderBy(COLUMNNAME_ValidFrom + " DESC NULLS LAST").first();
if (trxName == null) {
addToCache(acct, key);
}
return acct;
}
Aggregations