use of org.compiere.model.Query in project adempiere by adempiere.
the class UserPreference method loadPreference.
/**
* load user preference
* @param AD_User_ID
*/
public void loadPreference(int AD_User_ID) {
if (AD_User_ID > 0) {
m_AD_User_ID = AD_User_ID;
props = new Properties();
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, "AD_User_ID = ? AND Attribute = ? AND AD_Window_ID Is NULL", null);
for (int i = 0; i < PROPERTIES.length; i++) {
String attribute = PROPERTIES[i];
String value = VALUES[i];
MPreference preference = query.setParameters(new Object[] { m_AD_User_ID, attribute }).firstOnly();
if (preference != null) {
value = preference.getValue();
}
props.setProperty(attribute, value);
}
}
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class UserPreference method savePreference.
/**
* save user preference
*/
public void savePreference() {
if (m_AD_User_ID > 0) {
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, "AD_User_ID = ? AND Attribute = ? AND AD_Window_ID Is NULL", null);
for (int i = 0; i < PROPERTIES.length; i++) {
String attribute = PROPERTIES[i];
String value = props.getProperty(attribute);
MPreference preference = query.setParameters(new Object[] { m_AD_User_ID, attribute }).firstOnly();
if (preference == null) {
preference = new MUserPreference(Env.getCtx(), 0, null);
preference.setAD_User_ID(m_AD_User_ID);
preference.setAttribute(attribute);
} else {
if (preference.getAD_Client_ID() > 0 || preference.getAD_Org_ID() > 0) {
preference = new MUserPreference(Env.getCtx(), preference.getAD_Preference_ID(), null);
}
}
preference.setValue(value);
preference.saveEx();
}
}
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class CostEngine method getParentActualCostByCostType.
/**
* Get Actual Cost of Parent Product Based on Cost Type
* @param accountSchema
* @param costTypeId
* @param costElementId
* @param costCollector
* @return
*/
public static BigDecimal getParentActualCostByCostType(MAcctSchema accountSchema, int costTypeId, int costElementId, MPPCostCollector costCollector) {
StringBuffer whereClause = new StringBuffer().append(MCostDetail.COLUMNNAME_C_AcctSchema_ID).append("=? AND ").append(MCostDetail.COLUMNNAME_M_CostType_ID + "=? AND ").append(MCostDetail.COLUMNNAME_M_CostElement_ID + "=? AND ").append(MCostDetail.COLUMNNAME_PP_Cost_Collector_ID).append(" IN (SELECT PP_Cost_Collector_ID FROM PP_Cost_Collector cc WHERE cc.PP_Order_ID=? AND ").append(" cc.CostCollectorType <> '").append(MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt).append("')");
BigDecimal actualCost = new Query(costCollector.getCtx(), MCostDetail.Table_Name, whereClause.toString(), costCollector.get_TrxName()).setClient_ID().setParameters(accountSchema.getC_AcctSchema_ID(), costTypeId, costElementId, costCollector.getPP_Order_ID()).sum("(" + MCostDetail.COLUMNNAME_Amt + "+" + MCostDetail.COLUMNNAME_CostAmtLL + ")");
whereClause = new StringBuffer();
whereClause.append(" EXISTS (SELECT 1 FROM PP_Cost_Collector cc ").append(" WHERE PP_Cost_Collector_ID=M_Transaction.PP_Cost_Collector_ID AND cc.PP_Order_ID=? AND cc.M_Product_ID=? )");
BigDecimal qtyDelivered = new Query(costCollector.getCtx(), I_M_Transaction.Table_Name, whereClause.toString(), costCollector.get_TrxName()).setClient_ID().setParameters(costCollector.getPP_Order_ID(), costCollector.getM_Product_ID()).sum(MTransaction.COLUMNNAME_MovementQty);
if (actualCost == null)
actualCost = Env.ZERO;
if (qtyDelivered.signum() != 0)
actualCost = actualCost.divide(qtyDelivered, accountSchema.getCostingPrecision(), BigDecimal.ROUND_HALF_DOWN);
BigDecimal rate = MConversionRate.getRate(costCollector.getC_Currency_ID(), costCollector.getC_Currency_ID(), costCollector.getDateAcct(), costCollector.getC_ConversionType_ID(), costCollector.getAD_Client_ID(), costCollector.getAD_Org_ID());
if (rate != null) {
actualCost = actualCost.multiply(rate);
if (actualCost.scale() > accountSchema.getCostingPrecision())
actualCost = actualCost.setScale(accountSchema.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
}
return actualCost;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class FifoLifoCostingMethod method get.
public static MTransaction get(MCostDetail cd) {
final String whereClause = I_M_Transaction.COLUMNNAME_M_Product_ID + "=? AND " + I_M_Transaction.COLUMNNAME_M_Transaction_ID + "=? AND " + I_M_Transaction.COLUMNNAME_MovementQty + "=?";
MTransaction trx = new Query(cd.getCtx(), MTransaction.Table_Name, whereClause, cd.get_TrxName()).setClient_ID().setParameters(cd.getM_Product_ID(), cd.getM_Transaction_ID(), cd.getQty()).firstOnly();
return trx;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class AverageInvoiceCostingMethod method createUpdateAverageCostDetail.
public void createUpdateAverageCostDetail(MPPCostCollector costCollectorVariance, BigDecimal costVarianceThisLevel, BigDecimal costVarianceLowLevel, MProduct product, MAcctSchema acctSchema, MCostType costType, MCostElement costElement) {
String whereClause = " exists (select 1 from pp_cost_collector pc" + " where pc.pp_cost_collector_ID=m_transaction.pp_Cost_collector_ID and costcollectortype =? " + " and pc.pp_order_ID=?)";
MTransaction mtrx = new Query(costCollectorVariance.getCtx(), MTransaction.Table_Name, whereClause, costCollectorVariance.get_TrxName()).setParameters(MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt, costCollectorVariance.getPP_Order_ID()).setOrderBy("M_Transaction_ID desc").first();
BigDecimal costThisLevel = Env.ZERO;
BigDecimal costLowLevel = Env.ZERO;
String costingLevel = MProduct.get(mtrx.getCtx(), mtrx.getM_Product_ID()).getCostingLevel(acctSchema, mtrx.getAD_Org_ID());
costCollectorVariance.set_ValueOfColumn("Cost", costVarianceThisLevel.compareTo(Env.ZERO) != 0 ? costVarianceThisLevel : costVarianceLowLevel);
costCollectorVariance.saveEx();
IDocumentLine model = costCollectorVariance;
MCost cost = MCost.validateCostForCostType(acctSchema, costType, costElement, product.getM_Product_ID(), 0, 0, 0, mtrx.get_TrxName());
final ICostingMethod method = CostingMethodFactory.get().getCostingMethod(costType.getCostingMethod());
method.setCostingMethod(acctSchema, mtrx, model, cost, costThisLevel, costLowLevel, model.isSOTrx());
method.process();
}
Aggregations