Search in sources :

Example 6 with Query

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;
}
Also used : Query(org.compiere.model.Query) MCharge(org.compiere.model.MCharge) Properties(java.util.Properties)

Example 7 with Query

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;
}
Also used : Query(org.compiere.model.Query) MBPartner(org.compiere.model.MBPartner) Properties(java.util.Properties) MLocation(org.compiere.model.MLocation) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Example 8 with Query

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");
    }
}
Also used : Query(org.compiere.model.Query)

Example 9 with Query

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;
}
Also used : MDepreciationWorkfile(org.compiere.model.MDepreciationWorkfile) Query(org.compiere.model.Query)

Example 10 with Query

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;
}
Also used : MultiKey(org.apache.commons.collections.keyvalue.MultiKey) Query(org.compiere.model.Query) ArrayList(java.util.ArrayList)

Aggregations

Query (org.compiere.model.Query)212 ArrayList (java.util.ArrayList)49 BigDecimal (java.math.BigDecimal)25 Properties (java.util.Properties)22 MProduct (org.compiere.model.MProduct)20 AdempiereException (org.adempiere.exceptions.AdempiereException)13 MTable (org.compiere.model.MTable)12 MOrderLine (org.compiere.model.MOrderLine)8 MWarehouse (org.compiere.model.MWarehouse)8 PO (org.compiere.model.PO)8 MBPartner (org.compiere.model.MBPartner)6 MQuery (org.compiere.model.MQuery)6 MPPProductBOM (org.eevolution.model.MPPProductBOM)6 MColumn (org.compiere.model.MColumn)5 MLocation (org.compiere.model.MLocation)5 MPPProductBOMLine (org.eevolution.model.MPPProductBOMLine)5 SQLException (java.sql.SQLException)4 Timestamp (java.sql.Timestamp)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 MClient (org.compiere.model.MClient)4