Search in sources :

Example 1 with MProduction

use of org.compiere.model.MProduction in project adempiere by adempiere.

the class ReplenishReportProduction method createProduction.

//	create Distribution Order
/**
	 * 	Create Production
	 */
private void createProduction() {
    int noProds = 0;
    String info = "";
    //
    MProduction production = null;
    MWarehouse wh = null;
    X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NULL " + "AND EXISTS (SELECT * FROM M_Product p WHERE p.M_Product_ID=T_Replenish.M_Product_ID " + "AND p.IsBOM='Y' AND p.IsManufactured='Y') ");
    for (int i = 0; i < replenishs.length; i++) {
        X_T_Replenish replenish = replenishs[i];
        if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
            wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
        BigDecimal batchQty = null;
        BigDecimal qtyToProduce = replenish.getQtyToOrder();
        while (qtyToProduce.compareTo(Env.ZERO) > 0) {
            BigDecimal qty = qtyToProduce;
            if (batchQty != null && batchQty.compareTo(Env.ZERO) > 0 && qtyToProduce.compareTo(batchQty) > 0) {
                qty = batchQty;
                qtyToProduce = qtyToProduce.subtract(batchQty);
            } else {
                qtyToProduce = Env.ZERO;
            }
            production = new MProduction(getCtx(), 0, get_TrxName());
            production.setDescription(Msg.getMsg(getCtx(), "Replenishment"));
            //	Set Org/WH
            production.setAD_Org_ID(wh.getAD_Org_ID());
            production.setM_Locator_ID(wh.getDefaultLocator().get_ID());
            production.setM_Product_ID(replenish.getM_Product_ID());
            production.setProductionQty(qty);
            production.setMovementDate(Env.getContextAsDate(getCtx(), "#Date"));
            production.saveEx();
            //	Process
            production.setDocAction(DocAction.ACTION_Complete);
            production.processIt(DocAction.ACTION_Complete);
            production.saveEx(get_TrxName());
            log.fine(production.toString());
            noProds++;
            info += " - " + production.getDocumentNo();
        }
    }
    m_info = "#" + noProds + info;
    log.info(m_info);
}
Also used : X_T_Replenish(org.compiere.model.X_T_Replenish) MProduction(org.compiere.model.MProduction) MWarehouse(org.compiere.model.MWarehouse) BigDecimal(java.math.BigDecimal)

Example 2 with MProduction

use of org.compiere.model.MProduction 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 3 with MProduction

use of org.compiere.model.MProduction in project adempiere by adempiere.

the class CostEngine method getParentActualCostByCostType.

public static BigDecimal getParentActualCostByCostType(MAcctSchema accountSchema, MCostType costType, MCostElement costElement, I_M_Production production) {
    //	Get BOM Cost - Sum of individual lines
    BigDecimal totalCost = Env.ZERO;
    for (MProductionLine productionLine : ((MProduction) production).getLines()) {
        if (productionLine.isParent())
            continue;
        String productType = productionLine.getM_Product().getProductType();
        BigDecimal cost = BigDecimal.ZERO;
        if (X_M_Product.PRODUCTTYPE_Item.equals(productType)) {
            cost = MCostDetail.getCostByModel(accountSchema.getC_AcctSchema_ID(), costType.getM_CostType_ID(), costElement.getM_CostElement_ID(), productionLine);
        } else if (X_M_Product.PRODUCTTYPE_Resource.equals(productType)) {
            MCost costDimension = MCost.validateCostForCostType(accountSchema, costType, costElement, productionLine.getM_Product_ID(), productionLine.getAD_Org_ID(), productionLine.getM_Locator().getM_Warehouse_ID(), productionLine.getM_AttributeSetInstance_ID(), productionLine.get_TrxName());
            if (costDimension != null && costDimension.getCurrentCostPrice().signum() != 0)
                cost = costDimension.getCurrentCostPrice().multiply(productionLine.getMovementQty().negate());
        }
        if (cost != null && cost.signum() != 0)
            totalCost = totalCost.add(cost);
    }
    BigDecimal unitCost = Env.ZERO;
    if (production.getProductionQty().signum() != 0 && totalCost.signum() != 0)
        unitCost = totalCost.divide(production.getProductionQty(), accountSchema.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
    return unitCost;
}
Also used : MProductionLine(org.compiere.model.MProductionLine) MCost(org.compiere.model.MCost) BigDecimal(java.math.BigDecimal) MProduction(org.compiere.model.MProduction)

Example 4 with MProduction

use of org.compiere.model.MProduction in project adempiere by adempiere.

the class CostEngine method clearAccounting.

/**
     * clear Accounting
     * @param accountSchema
     * @param transaction
     */
public void clearAccounting(MAcctSchema accountSchema, MTransaction transaction) {
    if (transaction.getM_InOutLine_ID() > 0) {
        MInOutLine line = (MInOutLine) transaction.getM_InOutLine();
        if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
            return;
        // get Purchase matches
        List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
        for (MMatchPO match : orderMatches) {
            if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), match, transaction.getM_Product_ID(), line.getDateAcct()))
                return;
        }
        // get invoice matches
        List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
        for (MMatchInv match : invoiceMatches) {
            if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), match, transaction.getM_Product_ID(), line.getDateAcct()))
                return;
        }
    } else if (transaction.getC_ProjectIssue_ID() > 0) {
        MProjectIssue line = (MProjectIssue) transaction.getC_ProjectIssue();
        if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getMovementDate()))
            return;
    } else if (transaction.getM_InventoryLine_ID() > 0) {
        MInventoryLine line = (MInventoryLine) transaction.getM_InventoryLine();
        if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
            return;
    } else if (transaction.getM_MovementLine_ID() > 0) {
        MMovementLine line = (MMovementLine) transaction.getM_MovementLine();
        if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
            return;
    } else if (transaction.getM_ProductionLine_ID() > 0) {
        MProductionLine line = (MProductionLine) transaction.getM_ProductionLine();
        MProduction production = (MProduction) line.getM_ProductionPlan().getM_Production();
        if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), production, transaction.getM_Product_ID(), production.getMovementDate()))
            return;
    } else if (transaction.getPP_Cost_Collector_ID() > 0) {
        MPPCostCollector costCollector = (MPPCostCollector) transaction.getPP_Cost_Collector();
        if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), costCollector, costCollector.getM_Product_ID(), costCollector.getDateAcct()))
            ;
        return;
    } else {
        log.info("Document does not exist :" + transaction);
    }
}
Also used : MProjectIssue(org.compiere.model.MProjectIssue) MInOutLine(org.compiere.model.MInOutLine) MMatchPO(org.compiere.model.MMatchPO) MInventoryLine(org.compiere.model.MInventoryLine) MProductionLine(org.compiere.model.MProductionLine) MMatchInv(org.compiere.model.MMatchInv) MPPCostCollector(org.eevolution.model.MPPCostCollector) MMovementLine(org.compiere.model.MMovementLine) MProduction(org.compiere.model.MProduction)

Example 5 with MProduction

use of org.compiere.model.MProduction in project adempiere by adempiere.

the class CalculateReplenishPlan method createProductionOrder.

/**
	 * Create Planned Production Order
	 * 
	 * @param mrp
	 * @param qty
	 * @param date
	 */
private void createProductionOrder(MiniMRPProduct mrp, BigDecimal qty, Timestamp date) {
    MProduction mProd = new MProduction(ctx, 0, trx);
    //mProd.setAD_Client_ID(AD_Client_ID);
    mProd.setAD_Org_ID(AD_Org_ID);
    mProd.setM_Product_ID(mrp.getM_Product_ID());
    mProd.setProductionQty(qty);
    mProd.setM_Locator_ID(M_LocatorID);
    mProd.setC_DocType_ID(docType_PlannedOrder);
    mProd.setName("Planned Production Order");
    mProd.setDescription("Creating from MiniMRP");
    mProd.setDatePromised(date);
    mProd.setMovementDate(date);
    mProd.setDocumentNo("<>");
    mProd.saveEx();
    mProd.createLines(false);
    mProd.setIsCreated(true);
    mProd.saveEx();
    countProd++;
    productionDocs.append(mProd.getDocumentNo()).append(",");
}
Also used : MProduction(org.compiere.model.MProduction)

Aggregations

MProduction (org.compiere.model.MProduction)7 BigDecimal (java.math.BigDecimal)4 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 MMatchInv (org.compiere.model.MMatchInv)2 MMatchPO (org.compiere.model.MMatchPO)2 MProductionLine (org.compiere.model.MProductionLine)2 X_M_ReplenishPlanLine (org.compiere.model.X_M_ReplenishPlanLine)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 MCost (org.compiere.model.MCost)1 MDocType (org.compiere.model.MDocType)1 MInOutLine (org.compiere.model.MInOutLine)1 MInventoryLine (org.compiere.model.MInventoryLine)1 MMovementLine (org.compiere.model.MMovementLine)1 MOrder (org.compiere.model.MOrder)1