use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class GenerateShipmentOutBound method createShipment.
/**
* Create Shipment to Out Bound Order
* @param outBoundLine
*/
public void createShipment(MWMInOutBoundLine outBoundLine) {
// Generate Shipment based on Outbound Order
if (outBoundLine.getC_OrderLine_ID() > 0) {
MOrderLine orderLine = outBoundLine.getOrderLine();
if (outBoundLine.getPickedQty().subtract(orderLine.getQtyDelivered()).signum() <= 0 && !isIncludeNotAvailable())
return;
MLocator standing = getStandingLocator(outBoundLine);
BigDecimal qtyDelivered = getQtyDelivered(outBoundLine, orderLine.getQtyDelivered());
MInOut shipment = getShipment(orderLine);
MInOutLine shipmentLine = new MInOutLine(outBoundLine.getCtx(), 0, outBoundLine.get_TrxName());
shipmentLine.setM_InOut_ID(shipment.getM_InOut_ID());
shipmentLine.setM_Locator_ID(standing.getM_Locator_ID());
shipmentLine.setM_Product_ID(outBoundLine.getM_Product_ID());
shipmentLine.setQtyEntered(qtyDelivered);
shipmentLine.setMovementQty(qtyDelivered);
shipmentLine.setC_OrderLine_ID(orderLine.getC_OrderLine_ID());
shipmentLine.saveEx();
}
// Generate Delivery Movement
if (outBoundLine.getDD_OrderLine_ID() > 0) {
MDDOrderLine distributionOrderLine = (MDDOrderLine) outBoundLine.getDD_OrderLine();
if (distributionOrders.get(distributionOrderLine.getDD_Order_ID()) == null)
distributionOrders.put(distributionOrderLine.getDD_Order_ID(), distributionOrderLine.getDD_Order());
distributionOrderLine.setConfirmedQty(outBoundLine.getPickedQty());
distributionOrderLine.saveEx();
}
// Generate Delivery Manufacturing Order
if (outBoundLine.getPP_Order_BOMLine_ID() > 0) {
MPPOrderBOMLine orderBOMLine = (MPPOrderBOMLine) outBoundLine.getPP_Order_BOMLine();
if (outBoundLine.getPickedQty().subtract(orderBOMLine.getQtyDelivered()).signum() <= 0 && !isIncludeNotAvailable())
return;
MLocator standing = getStandingLocator(outBoundLine);
MStorage[] storage = MStorage.getAll(getCtx(), orderBOMLine.getM_Product_ID(), standing.getM_Locator_ID(), get_TrxName());
BigDecimal qtyDelivered = getQtyDelivered(outBoundLine, orderBOMLine.getQtyDelivered());
List<MPPCostCollector> issues = MPPOrder.createIssue(orderBOMLine.getParent(), orderBOMLine, getMovementDate(), qtyDelivered, BigDecimal.ZERO, BigDecimal.ZERO, storage, true);
issues.stream().forEach(costCollector -> {
if (manufacturingIssues.get(costCollector.getPP_Cost_Collector_ID()) == null)
manufacturingIssues.put(costCollector.getPP_Cost_Collector_ID(), costCollector);
});
}
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class Doc_InOut method loadLines.
// loadDocumentDetails
/**
* Load InOut Line
* @param inout shipment/receipt
* @return DocLine Array
*/
private DocLine[] loadLines(MInOut inout) {
ArrayList<DocLine> list = new ArrayList<DocLine>();
MInOutLine[] lines = inout.getLines(false);
for (int i = 0; i < lines.length; i++) {
MInOutLine line = lines[i];
if (line.isDescription() || line.getM_Product_ID() == 0 || line.getMovementQty().signum() == 0) {
log.finer("Ignored: " + line);
continue;
}
DocLine docLine = new DocLine(line, this);
BigDecimal Qty = line.getMovementQty();
docLine.setReversalLine_ID(line.getReversalLine_ID());
// sets Trx and Storage Qty
docLine.setQty(Qty, getDocumentType().equals(DOCTYPE_MatShipment));
//Define if Outside Processing
String sql = "SELECT PP_Cost_Collector_ID FROM C_OrderLine WHERE C_OrderLine_ID=? AND PP_Cost_Collector_ID IS NOT NULL";
int PP_Cost_Collector_ID = DB.getSQLValueEx(getTrxName(), sql, new Object[] { line.getC_OrderLine_ID() });
docLine.setPP_Cost_Collector_ID(PP_Cost_Collector_ID);
//
log.fine(docLine.toString());
list.add(docLine);
}
// Return Array
DocLine[] dls = new DocLine[list.size()];
list.toArray(dls);
return dls;
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class Doc_MatchPO method createFacts.
// getBalance
/**
* Create Facts (the accounting logic) for
* MXP.
* <pre>
* Product PPV <difference>
* PPV_Offset <difference>
* </pre>
* @param as accounting schema
* @return Fact
*/
public ArrayList<Fact> createFacts(MAcctSchema as) {
ArrayList<Fact> facts = new ArrayList<Fact>();
//
if (// Nothing to do if no Product
getM_Product_ID() == 0 || getQty().signum() == 0 || // No posting if not matched to Shipment
m_M_InOutLine_ID == 0) {
log.fine("No Product/Qty - M_Product_ID=" + getM_Product_ID() + ",Qty=" + getQty());
return facts;
}
// create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual);
setC_Currency_ID(as.getC_Currency_ID());
boolean isInterOrg = isInterOrg(as);
// Purchase Order Line
BigDecimal poCost = m_oLine.getPriceCost();
if (poCost == null || poCost.signum() == 0)
poCost = m_oLine.getPriceActual();
MInOutLine receiptLine = new MInOutLine(getCtx(), m_M_InOutLine_ID, getTrxName());
MInOut inOut = receiptLine.getParent();
boolean isReturnTrx = inOut.getMovementType().equals(X_M_InOut.MOVEMENTTYPE_VendorReturns);
// calculate po cost
// Delivered so far
poCost = poCost.multiply(getQty());
// Different currency
if (m_oLine.getC_Currency_ID() != as.getC_Currency_ID()) {
MOrder order = m_oLine.getParent();
Timestamp dateAcct = order.getDateAcct();
BigDecimal rate = MConversionRate.getRate(order.getC_Currency_ID(), as.getC_Currency_ID(), dateAcct, order.getC_ConversionType_ID(), m_oLine.getAD_Client_ID(), m_oLine.getAD_Org_ID());
if (rate == null) {
p_Error = "Purchase Order not convertible - " + as.getName();
return null;
}
poCost = poCost.multiply(rate);
if (poCost.scale() > as.getCostingPrecision())
poCost = poCost.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
}
// Calculate PPV for standard costing
//get standard cost and also make sure cost for other costing method is updated
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MCostType ct = MCostType.get(as, getM_Product_ID(), getAD_Org_ID());
String costingMethod = ct.getCostingMethod();
MInOutLine ioLine = new MInOutLine(getCtx(), m_M_InOutLine_ID, getTrxName());
BigDecimal costs = Env.ZERO;
for (MTransaction transaction : MTransaction.getByInOutLine(ioLine)) {
MCostElement element = MCostElement.getByMaterialCostElementType(transaction);
MCostDetail cd = MCostDetail.getByTransaction(ioLine, transaction, as.getC_AcctSchema_ID(), ct.getM_CostType_ID(), element.getM_CostElement_ID());
if (cd != null)
costs = costs.add(MCostDetail.getTotalCost(cd, as));
}
if (MCostType.COSTINGMETHOD_StandardCosting.equals(costingMethod)) {
// No Costs yet - no PPV
if (costs == null || costs.signum() == 0) {
// TODO make these a translatable message
p_Error = "No Standard Cost information was found for " + product.getName() + ". Please add a standard cost for material and repost this document.";
log.log(Level.SEVERE, p_Error);
return null;
}
// Difference
BigDecimal difference = poCost.subtract(costs.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP));
// Nothing to post
if (difference.signum() == 0) {
log.log(Level.FINE, "No Cost Difference for M_Product_ID=" + getM_Product_ID());
return facts;
}
// Product PPV
FactLine cr = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_PPV, as), as.getC_Currency_ID(), isReturnTrx ? difference.negate() : difference);
if (cr != null) {
cr.setQty(isReturnTrx ? getQty().negate() : getQty());
cr.setC_BPartner_ID(m_oLine.getC_BPartner_ID());
cr.setC_Activity_ID(m_oLine.getC_Activity_ID());
cr.setC_Campaign_ID(m_oLine.getC_Campaign_ID());
cr.setC_Project_ID(m_oLine.getC_Project_ID());
cr.setC_ProjectPhase_ID(m_oLine.getC_ProjectPhase_ID());
cr.setC_ProjectTask_ID(m_oLine.getC_ProjectTask_ID());
cr.setC_UOM_ID(m_oLine.getC_UOM_ID());
cr.setUser1_ID(m_oLine.getUser1_ID());
cr.setUser2_ID(m_oLine.getUser2_ID());
cr.setUser3_ID(m_oLine.getUser3_ID());
cr.setUser4_ID(m_oLine.getUser4_ID());
}
// PPV Offset
FactLine dr = fact.createLine(null, getAccount(Doc.ACCTTYPE_PPVOffset, as), as.getC_Currency_ID(), isReturnTrx ? difference : difference.negate());
if (dr != null) {
dr.setQty(isReturnTrx ? getQty() : getQty().negate());
dr.setC_BPartner_ID(m_oLine.getC_BPartner_ID());
dr.setC_Activity_ID(m_oLine.getC_Activity_ID());
dr.setC_Campaign_ID(m_oLine.getC_Campaign_ID());
dr.setC_Project_ID(m_oLine.getC_Project_ID());
dr.setC_ProjectPhase_ID(m_oLine.getC_ProjectPhase_ID());
dr.setC_ProjectTask_ID(m_oLine.getC_ProjectTask_ID());
dr.setC_UOM_ID(m_oLine.getC_UOM_ID());
dr.setUser1_ID(m_oLine.getUser1_ID());
dr.setUser2_ID(m_oLine.getUser2_ID());
dr.setUser3_ID(m_oLine.getUser3_ID());
dr.setUser4_ID(m_oLine.getUser4_ID());
}
// Avoid usage of clearing accounts
// If both accounts Purchase Price Variance and Purchase Price Variance Offset are equal
// then remove the posting
// PPV
MAccount acct_db = dr.getAccount();
// PPV Offset
MAccount acct_cr = cr.getAccount();
if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr) && (!isInterOrg)) {
BigDecimal debit = dr.getAmtSourceDr();
BigDecimal credit = cr.getAmtSourceCr();
if (debit.compareTo(credit) == 0) {
fact.remove(dr);
fact.remove(cr);
}
}
// End Avoid usage of clearing accounts
//
facts.add(fact);
return facts;
} else {
return facts;
}
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class GenerateCostDetail method generateCostDetail.
public void generateCostDetail(MAcctSchema accountSchema, MCostType costType, MCostElement costElement, MTransaction transaction) {
//Create Cost Detail for this Transaction
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, transaction.getDocumentLine(), true);
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).clearAccounting(accountSchema, transaction);
// invoices
if (MTransaction.MOVEMENTTYPE_VendorReceipts.equals(transaction.getMovementType())) {
MInOutLine line = (MInOutLine) transaction.getDocumentLine();
if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
//get purchase matches
List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
orderMatches.stream().forEach(match -> {
if (match.getM_Product_ID() == transaction.getM_Product_ID() && match.getDateAcct().after(getAccountDate()) && match.getDateAcct().before(getAccountDateTo())) {
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
});
//get invoice matches
List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
invoiceMatches.forEach(match -> {
if (match.getM_Product_ID() == transaction.getM_Product_ID() && match.getDateAcct().after(getAccountDate()) && match.getDateAcct().before(getAccountDateTo())) {
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
});
}
//get landed allocation cost
MLandedCostAllocation.getOfInOutline(line, costElement.getM_CostElement_ID()).stream().forEach(allocation -> {
if (allocation.getDateAcct().after(getAccountDate()) && allocation.getDateAcct().before(getAccountDateTo()))
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, allocation, true);
});
}
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class InventoryUtil method createInOut.
public static MInOut createInOut(MMDocument doc, String trxName) {
MOrder order;
if (MDocType.DOCBASETYPE_MaterialReceipt.equals(doc.DocBaseType)) {
order = (MOrder) doc.scenario.get(MDocType.DOCBASETYPE_PurchaseOrder, doc.PODocumentNo).document;
} else if (MDocType.DOCBASETYPE_MaterialDelivery.equals(doc.DocBaseType)) {
order = (MOrder) doc.scenario.get(MDocType.DOCBASETYPE_SalesOrder, doc.PODocumentNo).document;
} else {
throw new IllegalArgumentException("DocBaseType not supported - " + doc);
}
// if (trxName != null && trxName.equals(order.get_TrxName()))
// throw new AdempiereException("Internal exception - not same trxName");
MInOut io = new MInOut(order, 0, doc.Date);
setGeneratedTag(io);
io.saveEx();
//
MInOutLine iol = null;
for (MOrderLine oline : order.getLines(true, null)) {
iol = new MInOutLine(io);
iol.setOrderLine(oline, 0, doc.Qty);
iol.setQty(doc.Qty);
iol.saveEx();
break;
}
//
doc.document = io;
processDocument(doc, MInOut.DOCACTION_Complete, MInOut.DOCSTATUS_Completed);
if (!Util.isEmpty(doc.ASI)) {
iol.load(trxName);
doc.scenario.registerASICode(doc.ASI, iol.getM_AttributeSetInstance_ID(), !io.isSOTrx());
}
return io;
}
Aggregations