Search in sources :

Example 11 with MMatchPO

use of org.compiere.model.MMatchPO 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 12 with MMatchPO

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

the class MatchPODelete method doIt.

//	prepare
/**
	 * 	Process
	 *	@return message
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("M_MatchPO_ID=" + p_M_MatchPO_ID);
    MMatchPO po = new MMatchPO(getCtx(), p_M_MatchPO_ID, get_TrxName());
    if (po.get_ID() == 0)
        throw new AdempiereUserError("@NotFound@ @M_MatchPO_ID@ " + p_M_MatchPO_ID);
    //
    MOrderLine orderLine = null;
    boolean isMatchReceipt = (po.getM_InOutLine_ID() != 0);
    if (isMatchReceipt) {
        orderLine = new MOrderLine(getCtx(), po.getC_OrderLine_ID(), get_TrxName());
        orderLine.setQtyReserved(orderLine.getQtyReserved().add(po.getQty()));
    }
    //
    if (po.delete(true)) {
        if (isMatchReceipt) {
            if (!orderLine.save(get_TrxName()))
                throw new AdempiereUserError("Delete MatchPO failed to restore PO's On Ordered Qty");
        }
        return "@OK@";
    }
    po.saveEx();
    return "@Error@";
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) MMatchPO(org.compiere.model.MMatchPO) MOrderLine(org.compiere.model.MOrderLine)

Example 13 with MMatchPO

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

the class Doc_MatchPO method loadDocumentDetails.

/**
	 *  Load Specific Document Details
	 *  @return error message or null
	 */
protected String loadDocumentDetails() {
    setC_Currency_ID(Doc.NO_CURRENCY);
    MMatchPO matchPO = (MMatchPO) getPO();
    setDateDoc(matchPO.getDateTrx());
    //
    m_M_AttributeSetInstance_ID = matchPO.getM_AttributeSetInstance_ID();
    setQty(matchPO.getQty());
    //
    m_C_OrderLine_ID = matchPO.getC_OrderLine_ID();
    m_oLine = new MOrderLine(getCtx(), m_C_OrderLine_ID, getTrxName());
    //
    m_M_InOutLine_ID = matchPO.getM_InOutLine_ID();
    m_ioLine = new MInOutLine(getCtx(), m_M_InOutLine_ID, getTrxName());
    m_C_InvoiceLine_ID = matchPO.getC_InvoiceLine_ID();
    //
    m_pc = new ProductCost(Env.getCtx(), getM_Product_ID(), m_M_AttributeSetInstance_ID, getTrxName());
    m_pc.setQty(getQty());
    return null;
}
Also used : ProductCost(org.compiere.model.ProductCost) MMatchPO(org.compiere.model.MMatchPO) MInOutLine(org.compiere.model.MInOutLine) MOrderLine(org.compiere.model.MOrderLine)

Example 14 with MMatchPO

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

the class Match method createMatchRecord.

//  tableLoad
/**
	 *  Create Matching Record
	 *  @param invoice true if matching invoice false if matching PO
	 *  @param M_InOutLine_ID shipment line
	 *  @param Line_ID C_InvoiceLine_ID or C_OrderLine_ID
	 *  @param qty quantity
	 *  @param trxName 
	 *  @return true if created
	 */
protected boolean createMatchRecord(boolean invoice, int M_InOutLine_ID, int Line_ID, BigDecimal qty, String trxName) {
    if (qty.compareTo(Env.ZERO) == 0)
        return true;
    log.fine("IsInvoice=" + invoice + ", M_InOutLine_ID=" + M_InOutLine_ID + ", Line_ID=" + Line_ID + ", Qty=" + qty);
    //
    boolean success = false;
    MInOutLine sLine = new MInOutLine(Env.getCtx(), M_InOutLine_ID, trxName);
    if (//	Shipment - Invoice
    invoice) {
        //	Update Invoice Line
        MInvoiceLine iLine = new MInvoiceLine(Env.getCtx(), Line_ID, trxName);
        iLine.setM_InOutLine_ID(M_InOutLine_ID);
        if (sLine.getC_OrderLine_ID() != 0)
            iLine.setC_OrderLine_ID(sLine.getC_OrderLine_ID());
        iLine.saveEx();
        //	Create Shipment - Invoice Link
        if (iLine.getM_Product_ID() != 0) {
            MMatchInv match = new MMatchInv(iLine, null, qty);
            match.setM_InOutLine_ID(M_InOutLine_ID);
            if (match.save()) {
                success = true;
                if (MClient.isClientAccountingImmediate()) {
                    String ignoreError = DocumentEngine.postImmediate(match.getCtx(), match.getAD_Client_ID(), match.get_Table_ID(), match.get_ID(), true, match.get_TrxName());
                }
            } else
                log.log(Level.SEVERE, "Inv Match not created: " + match);
        } else
            success = true;
        //	Create PO - Invoice Link = corrects PO
        if (iLine.getC_OrderLine_ID() != 0 && iLine.getM_Product_ID() != 0) {
            MMatchPO matchPO = MMatchPO.create(iLine, sLine, null, qty);
            matchPO.setC_InvoiceLine_ID(iLine);
            matchPO.setM_InOutLine_ID(M_InOutLine_ID);
            if (!matchPO.save())
                log.log(Level.SEVERE, "PO(Inv) Match not created: " + matchPO);
            if (MClient.isClientAccountingImmediate()) {
                String ignoreError = DocumentEngine.postImmediate(matchPO.getCtx(), matchPO.getAD_Client_ID(), matchPO.get_Table_ID(), matchPO.get_ID(), true, matchPO.get_TrxName());
            }
        }
    } else //	Shipment - Order
    {
        //	Update Shipment Line
        sLine.setC_OrderLine_ID(Line_ID);
        sLine.saveEx();
        //	Update Order Line
        MOrderLine oLine = new MOrderLine(Env.getCtx(), Line_ID, trxName);
        if (//	other in MInOut.completeIt
        oLine.get_ID() != 0) {
            oLine.setQtyReserved(oLine.getQtyReserved().subtract(qty));
            if (!oLine.save())
                log.severe("QtyReserved not updated - C_OrderLine_ID=" + Line_ID);
        }
        //	Create PO - Shipment Link
        if (sLine.getM_Product_ID() != 0) {
            MMatchPO match = new MMatchPO(sLine, null, qty);
            if (!match.save())
                log.log(Level.SEVERE, "PO Match not created: " + match);
            else {
                success = true;
                //	Correct Ordered Qty for Stocked Products (see MOrder.reserveStock / MInOut.processIt)
                if (sLine.getProduct() != null && sLine.getProduct().isStocked())
                    success = MStorage.add(Env.getCtx(), sLine.getM_Warehouse_ID(), sLine.getM_Locator_ID(), sLine.getM_Product_ID(), sLine.getM_AttributeSetInstance_ID(), oLine.getM_AttributeSetInstance_ID(), null, null, qty.negate(), trxName);
            }
        } else
            success = true;
    }
    return success;
}
Also used : MInOutLine(org.compiere.model.MInOutLine) MMatchPO(org.compiere.model.MMatchPO) MInvoiceLine(org.compiere.model.MInvoiceLine) MMatchInv(org.compiere.model.MMatchInv) MOrderLine(org.compiere.model.MOrderLine)

Aggregations

MMatchPO (org.compiere.model.MMatchPO)14 MInOutLine (org.compiere.model.MInOutLine)9 MMatchInv (org.compiere.model.MMatchInv)8 MLandedCostAllocation (org.compiere.model.MLandedCostAllocation)7 MCostDetail (org.compiere.model.MCostDetail)3 MInventoryLine (org.compiere.model.MInventoryLine)3 MMovementLine (org.compiere.model.MMovementLine)3 MOrderLine (org.compiere.model.MOrderLine)3 MTransaction (org.compiere.model.MTransaction)3 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 Properties (java.util.Properties)2 MAcctSchema (org.compiere.model.MAcctSchema)2 MCostElement (org.compiere.model.MCostElement)2 MCostType (org.compiere.model.MCostType)2 MProduction (org.compiere.model.MProduction)2 MProductionLine (org.compiere.model.MProductionLine)2 MPPCostCollector (org.eevolution.model.MPPCostCollector)2 ArrayList (java.util.ArrayList)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1