Search in sources :

Example 1 with MProductCategoryAcct

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;
}
Also used : MProduct(org.compiere.model.MProduct) MDocType(org.compiere.model.MDocType) MMatchPO(org.compiere.model.MMatchPO) MMatchInv(org.compiere.model.MMatchInv) MProductCategoryAcct(org.compiere.model.MProductCategoryAcct) MProduction(org.compiere.model.MProduction)

Example 2 with MProductCategoryAcct

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

Aggregations

MProductCategoryAcct (org.compiere.model.MProductCategoryAcct)2 Properties (java.util.Properties)1 MDocType (org.compiere.model.MDocType)1 MMatchInv (org.compiere.model.MMatchInv)1 MMatchPO (org.compiere.model.MMatchPO)1 MProduct (org.compiere.model.MProduct)1 MProductCategory (org.compiere.model.MProductCategory)1 MProduction (org.compiere.model.MProduction)1 Query (org.compiere.model.Query)1