use of org.compiere.model.MProductCategoryAcct in project adempiere by adempiere.
the class CostEngine method clearAccounting.
/**
* Clear Accounting
* @param accountSchema
* @param costType
* @param model
* @param productId
* @param dateAcct
* @return true clean
*/
public boolean clearAccounting(MAcctSchema accountSchema, I_M_CostType costType, PO model, int productId, Timestamp dateAcct) {
// check if costing type need reset accounting
if (!accountSchema.getCostingMethod().equals(costType.getCostingMethod())) {
MProduct product = MProduct.get(accountSchema.getCtx(), productId);
MProductCategoryAcct productCategoryAcct = MProductCategoryAcct.get(accountSchema.getCtx(), product.getM_Product_Category_ID(), accountSchema.get_ID(), model.get_TrxName());
if (productCategoryAcct == null || !costType.getCostingMethod().equals(productCategoryAcct.getCostingMethod()))
return false;
}
final String docBaseType;
// check if account period is open
if (model instanceof MMatchInv)
docBaseType = MPeriodControl.DOCBASETYPE_MatchInvoice;
else if (model instanceof MMatchPO)
docBaseType = MPeriodControl.DOCBASETYPE_MatchPO;
else if (model instanceof MProduction)
docBaseType = MPeriodControl.DOCBASETYPE_MaterialProduction;
else {
MDocType docType = MDocType.get(model.getCtx(), model.get_ValueAsInt(MDocType.COLUMNNAME_C_DocType_ID));
docBaseType = docType.getDocBaseType();
}
Boolean openPeriod = MPeriod.isOpen(model.getCtx(), dateAcct, docBaseType, model.getAD_Org_ID());
if (!openPeriod) {
System.out.println("Period closed.");
return false;
}
final String sqlUpdate = "UPDATE " + model.get_TableName() + " SET Posted = 'N' WHERE " + model.get_TableName() + "_ID=?";
DB.executeUpdate(sqlUpdate, new Object[] { model.get_ID() }, false, model.get_TrxName());
//Delete account
final String sqldelete = "DELETE FROM Fact_Acct WHERE Record_ID =? AND AD_Table_ID=?";
DB.executeUpdate(sqldelete, new Object[] { model.get_ID(), model.get_Table_ID() }, false, model.get_TrxName());
return true;
}
use of org.compiere.model.MProductCategoryAcct in project adempiere by adempiere.
the class InventoryUtil method getCreateProductCategory.
public static MProductCategory getCreateProductCategory(String value, String MMPolicy, String CostingLevel, String CostingMethod) {
if (Util.isEmpty(value, true))
throw new IllegalArgumentException("Value is null");
if (MMPolicy == null)
MMPolicy = MProductCategory.MMPOLICY_FiFo;
Properties ctx = Env.getCtx();
String whereClause = MProductCategory.COLUMNNAME_Value + "=?";
MProductCategory pc = new Query(ctx, MProductCategory.Table_Name, whereClause, null).setParameters(new Object[] { value }).setOnlyActiveRecords(true).setClient_ID().firstOnly();
if (pc == null) {
pc = new MProductCategory(ctx, 0, null);
}
pc.setValue(value);
pc.setName(value);
setGeneratedTag(pc);
pc.setMMPolicy(MMPolicy);
//
pc.saveEx();
//
int C_AcctSchema_ID = MClientInfo.get(ctx).getC_AcctSchema1_ID();
MProductCategoryAcct pca = MProductCategoryAcct.get(ctx, pc.get_ID(), C_AcctSchema_ID, null);
pca.setCostingLevel(CostingLevel);
pca.setCostingMethod(CostingMethod);
pca.saveEx();
//
return pc;
}
Aggregations