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);
}
}
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@";
}
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;
}
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;
}
Aggregations