use of org.compiere.model.MCostType in project adempiere by adempiere.
the class FrozenUnFrozenCost method doIt.
@Override
protected String doIt() throws Exception {
//Get account schema
MAcctSchema accountSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
//Get cost type
MCostType costType = MCostType.get(getCtx(), getCostTypeId());
//Get cost element to process
final List<MCostElement> costElements = getCostElementId() > 0 ? Arrays.asList(MCostElement.get(getCtx(), getCostElementId())) : MCostElement.getCostElement(getCtx(), get_TrxName());
//Iterate cost element
costElements.stream().filter(costElement -> costElement != null).forEach(costElement -> {
AtomicInteger records = new AtomicInteger(0);
Arrays.stream(getProductIds()).filter(productId -> productId > 0).forEach(productId -> {
MProduct product = MProduct.get(getCtx(), productId);
final CostDimension costDimension = new CostDimension(product, accountSchema, costType.getM_CostType_ID(), getOrganizationId(), getWarehouseId(), 0, costElement.getM_CostElement_ID());
Trx.run(trxName -> {
final List<MCost> costs = costDimension.toQuery(MCost.class, trxName).list();
costs.stream().filter(cost -> cost != null).forEach(cost -> {
cost.setIsCostFrozen(isCostFrozen());
cost.saveEx();
records.updateAndGet(record -> record + 1);
});
});
});
String message = "@M_CostElement_ID@ " + costElement.getName() + " @Records@ " + records.get() + " @IsCostFrozen@ = " + isCostFrozen();
addLog(Msg.parseTranslation(getCtx(), message));
});
return "@OK@";
}
use of org.compiere.model.MCostType in project adempiere by adempiere.
the class CopyCostTypeToCostType method doIt.
@Override
protected String doIt() throws Exception {
if (getCostTypeId() == getCostTypeIdTo())
throw new AdempiereException("@M_CostType_ID@ @NotValid@");
MAcctSchema accountSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
MCostType costTypeFrom = MCostType.get(getCtx(), getCostTypeId());
MCostType costTypeTo = MCostType.get(getCtx(), getCostTypeIdTo());
MCostElement costElementFrom = MCostElement.get(getCtx(), getCostElementId());
MCostElement costElementTo = MCostElement.get(getCtx(), getCostElementIdTo());
Arrays.stream(getProductIds()).filter(productId -> productId > 0).forEach(productId -> {
Trx.run(trxName -> {
copyCostTypeToCostType(productId, accountSchema, costTypeFrom, costTypeTo, costElementFrom, costElementTo, trxName);
});
});
return "@Ok@";
}
use of org.compiere.model.MCostType in project adempiere by adempiere.
the class CopyCostTypeToCostType method copyCostTypeToCostType.
/**
* Copy Cost Type to Cost Type
*
* @param productId
* @param accountSchema
* @param costTypeFrom
* @param costTypeTo
* @param costElementFrom
* @param costElementTo
* @param trxName
*/
private void copyCostTypeToCostType(int productId, MAcctSchema accountSchema, MCostType costTypeFrom, MCostType costTypeTo, MCostElement costElementFrom, MCostElement costElementTo, String trxName) {
MProduct product = MProduct.get(getCtx(), productId);
CostDimension costDimensionFrom = new CostDimension(product, accountSchema, costTypeFrom.get_ID(), getOrganizationId(), getWarehouseId(), 0, costElementFrom.get_ID());
Optional<MCost> costDimensionFromOptional = Optional.ofNullable(costDimensionFrom.toQuery(MCost.class, trxName).first());
CostDimension costDimensionTo = new CostDimension(product, accountSchema, costTypeTo.get_ID(), getOrganizationId(), getWarehouseId(), 0, costElementTo.get_ID());
Optional<MCost> costDimensionToOptional = Optional.ofNullable(costDimensionTo.toQuery(MCost.class, trxName).first());
if (isUpdateCosting()) {
// exist cost form and cost to or not exist cost to and exit cost from
if (costDimensionToOptional.isPresent() && costDimensionFromOptional.isPresent()) {
MCost costTo = costDimensionToOptional.get();
if (MCostType.COSTINGMETHOD_StandardCosting.equals(costTypeFrom.getCostingMethod()) && costTo.isCostFrozen())
;
else {
costTo.setCurrentCostPrice(costDimensionFromOptional.get().getCurrentCostPrice());
costTo.saveEx();
}
} else if (!costDimensionToOptional.isPresent() && costDimensionFromOptional.isPresent()) {
MCost costTo = MCost.getOrCreate(product, 0, accountSchema, getOrganizationId(), getWarehouseId(), costTypeTo.get_ID(), costElementTo.get_ID());
if (MCostType.COSTINGMETHOD_StandardCosting.equals(costTypeFrom.getCostingMethod()) && costTo.isCostFrozen())
;
else {
costDimensionFromOptional.ifPresent(costFrom -> costTo.setCurrentCostPrice(costFrom.getCurrentCostPrice()));
costTo.saveEx();
}
} else if (// cost to and not exist cost from
costDimensionToOptional.isPresent() && !costDimensionFromOptional.isPresent()) {
MCost costTo = costDimensionToOptional.get();
costTo.setCurrentCostPrice(BigDecimal.ZERO);
costTo.saveEx();
} else if (!costDimensionToOptional.isPresent() && !costDimensionFromOptional.isPresent()) {
MCost costTo = MCost.getOrCreate(product, 0, accountSchema, getOrganizationId(), getWarehouseId(), costTypeTo.get_ID(), costElementTo.get_ID());
costTo.setCurrentCostPrice(BigDecimal.ZERO);
costTo.saveEx();
}
} else if (!costDimensionToOptional.isPresent()) {
MCost costTo = MCost.getOrCreate(product, 0, accountSchema, getOrganizationId(), getWarehouseId(), costTypeTo.get_ID(), costElementTo.get_ID());
costDimensionFromOptional.ifPresent(costFrom -> costTo.setCurrentCostPrice(costFrom.getCurrentCostPrice()));
costTo.saveEx();
}
}
use of org.compiere.model.MCostType in project adempiere by adempiere.
the class ValuationEffectiveDate method doIt.
// prepare
/**
* execute the Valuation Effective Date
*/
protected String doIt() throws Exception {
setup();
for (MAcctSchema acctSchema : acctSchemas) for (MWarehouse warehouse : warehouses) for (MCostType costType : costTypes) for (MCostElement costElement : costElements) for (int productId : products) generateInventoryValue(productId, acctSchema.getC_AcctSchema_ID(), costType.getM_CostType_ID(), costElement.getM_CostElement_ID(), warehouse.getM_Warehouse_ID());
pstmt.executeBatch();
commitEx();
DB.close(pstmt);
DB.executeUpdate("UPDATE T_InventoryValue SET Cost = CASE WHEN QtyOnHand <> 0 THEN (CostAmt + CostAmtLL) / QtyOnHand ELSE 0 END , CumulatedAmt = CASE WHEN QtyOnHand <> 0 THEN CostAmt + CostAmtLL ELSE 0 END , DateValue = " + DB.TO_DATE(getValuationDate()) + " WHERE AD_PInstance_ID=?", getAD_PInstance_ID(), get_TrxName());
return "@Ok@ " + count;
}
use of org.compiere.model.MCostType in project adempiere by adempiere.
the class CostResult method createDataMaster.
public void createDataMaster() {
bp = (MBPartner) getEntity(I_C_BPartner.Table_Name, I_C_BPartner.COLUMNNAME_Value, "SeedFarm", trxName);
bpls = MBPartnerLocation.getForBPartner(getCtx(), bp.getC_BPartner_ID(), trxName);
w = (MWarehouse) getEntity(I_M_Warehouse.Table_Name, I_M_Warehouse.COLUMNNAME_Value, "HQ", trxName);
u = (MUser) getEntity(I_AD_User.Table_Name, I_AD_User.COLUMNNAME_Name, "GardenAdmin", trxName);
product = (MProduct) getEntity(I_M_Product.Table_Name, I_M_Product.COLUMNNAME_Value, "Oak", trxName);
as = MAcctSchema.get(getCtx(), 101);
today = Timestamp.valueOf("2010-01-01 00:00:00.0");
if (bp == null || w == null || u == null)
throw new AdempiereException("Object null ");
for (MCostType ct : MCostType.get(getCtx(), trxName)) {
if (!MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod())) {
ct.setIsActive(false);
}
}
}
Aggregations