use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class InvoiceCreateFrom method doIt.
@Override
protected String doIt() throws Exception {
// Valid Record Identifier
if (getRecord_ID() == 0)
return "";
// Get Shipment
MInvoice invoice = new MInvoice(getCtx(), getRecord_ID(), get_TrxName());
AtomicInteger referenceId = new AtomicInteger(0);
AtomicInteger created = new AtomicInteger(0);
List<Integer> recordIds = getSelectionKeys();
String createFromType = recordIds.size() > 0 ? getSelectionAsString(recordIds.get(0), "CF_CreateFromType") : null;
log.fine("CreateFromType=" + createFromType);
if (createFromType == null || createFromType.length() == 0)
throw new AdempiereException("@CreateFromType@ @NotFound@");
// Loop
recordIds.stream().forEach(key -> {
int productId = getSelectionAsInt(key, "CF_M_Product_ID");
int chargeId = getSelectionAsInt(key, "CF_C_Charge_ID");
int uomId = getSelectionAsInt(key, "CF_C_UOM_ID");
BigDecimal qtyEntered = getSelectionAsBigDecimal(key, "CF_QtyEntered");
log.fine("Line QtyEntered=" + qtyEntered + ", Product=" + productId + ", CreateFromType=" + createFromType + ", Key=" + key);
MInvoiceLine invoiceLine = new MInvoiceLine(invoice);
BigDecimal qtyInvoiced = null;
int precision = 2;
if (productId > 0) {
MProduct product = MProduct.get(Env.getCtx(), productId);
if (product != null) {
invoiceLine.setM_Product_ID(product.getM_Product_ID(), uomId);
precision = product.getUOMPrecision();
if (product.getC_UOM_ID() != uomId) {
qtyEntered = qtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
qtyInvoiced = MUOMConversion.convertProductFrom(Env.getCtx(), productId, uomId, qtyEntered);
}
}
} else if (chargeId != 0) {
invoiceLine.setC_Charge_ID(chargeId);
}
qtyEntered = qtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
if (qtyInvoiced == null)
qtyInvoiced = qtyEntered;
invoiceLine.setQty(qtyEntered);
invoiceLine.setQtyInvoiced(qtyInvoiced);
if (createFromType.equals(ORDER)) {
MOrderLine orderLine = new MOrderLine(getCtx(), key, get_TrxName());
referenceId.set(orderLine.getC_Order_ID());
String whereClause = "EXISTS (SELECT 1 " + "FROM M_InOut io " + "WHERE io.M_InOut_ID = M_InOutLine.M_InOut_ID " + "AND io.DocStatus IN ('CO','CL'))";
MInOutLine[] inOutLines = MInOutLine.getOfOrderLine(Env.getCtx(), key, whereClause, get_TrxName());
log.fine("Receipt Lines with OrderLine = #" + inOutLines.length);
final BigDecimal qty = qtyEntered;
MInOutLine inOutLine = Arrays.stream(inOutLines).filter(ioLine -> ioLine != null && ioLine.getQtyEntered().compareTo(qty) == 0).findFirst().orElse(inOutLines.length > 0 ? inOutLines[0] : null);
if (inOutLine != null)
invoiceLine.setShipLine(inOutLine);
else
invoiceLine.setOrderLine(orderLine);
} else if (createFromType.equals(INVOICE)) {
MInvoiceLine fromLine = new MInvoiceLine(getCtx(), key, get_TrxName());
referenceId.set(invoiceLine.getParent().getC_Invoice_ID());
PO.copyValues(fromLine, invoiceLine);
invoiceLine.setC_Invoice_ID(invoiceLine.getParent().getC_Invoice_ID());
invoiceLine.setAD_Org_ID(fromLine.getAD_Org_ID());
invoiceLine.setC_OrderLine_ID(0);
invoiceLine.setRef_InvoiceLine_ID(0);
invoiceLine.setM_InOutLine_ID(0);
invoiceLine.setA_Asset_ID(0);
invoiceLine.setM_AttributeSetInstance_ID(0);
invoiceLine.setS_ResourceAssignment_ID(0);
if (invoiceLine.getParent().getC_BPartner_ID() != fromLine.getC_Invoice().getC_BPartner_ID())
invoiceLine.setTax();
invoiceLine.setProcessed(false);
} else if (createFromType.equals(RMA)) {
MRMALine rmaLine = new MRMALine(getCtx(), key, get_TrxName());
referenceId.set(rmaLine.getM_RMA_ID());
invoiceLine.setRMALine(rmaLine);
} else if (createFromType.equals(RECEIPT)) {
MInOutLine inOutLine = new MInOutLine(getCtx(), key, get_TrxName());
referenceId.set(inOutLine.getM_InOut_ID());
invoiceLine.setShipLine(inOutLine);
}
invoiceLine.saveEx();
if (createFromType.equals(INVOICE)) {
MInvoiceLine fromLine = new MInvoiceLine(getCtx(), key, get_TrxName());
invoiceLine.copyLandedCostFrom(fromLine);
invoiceLine.allocateLandedCosts();
}
created.updateAndGet(createNo -> createNo + 1);
});
// Add reference to Order / Invoice / RMA
addReference(invoice, createFromType, referenceId.get());
return "@Created@ " + created.get();
}
use of org.compiere.model.MOrderLine 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.MOrderLine in project adempiere by adempiere.
the class ScanBar method getSource.
protected LinkedHashMap<Integer, ArrayList<Object>> getSource() {
if (source != null)
return source;
PO po = getParent();
int C_Order_ID = po.get_ValueAsInt(MOrder.COLUMNNAME_C_Order_ID);
if (C_Order_ID > 0) {
StringBuilder whereClause = new StringBuilder();
whereClause.append(MOrderLine.COLUMNNAME_C_Order_ID).append("=? AND ");
whereClause.append("(").append(MOrderLine.COLUMNNAME_QtyOrdered).append("-");
whereClause.append(MOrderLine.COLUMNNAME_QtyDelivered).append(")>0");
List<MOrderLine> orderLines = new Query(Env.getCtx(), MOrderLine.Table_Name, whereClause.toString(), null).setClient_ID().setParameters(C_Order_ID).list();
source = new LinkedHashMap<Integer, ArrayList<Object>>();
for (MOrderLine line : orderLines) {
if (line.getQtyOrdered().subtract(line.getQtyDelivered()).signum() > 0) {
ArrayList<Object> parameters = new ArrayList<Object>();
parameters.add(ID, line.getC_OrderLine_ID());
parameters.add(PRODUCT_ID, line.getM_Product_ID());
parameters.add(QTY_ORDERED, line.getQtyOrdered().subtract(line.getQtyDelivered()));
parameters.add(QTY_PICKED, line.getQtyOrdered().subtract(line.getQtyDelivered()));
source.put(line.get_ID(), parameters);
}
}
} else {
StringBuilder whereClause = new StringBuilder();
whereClause.append(getTable().getKeyColumns()[0]).append("=? ");
List<PO> lines = new Query(Env.getCtx(), getTable().getTableName(), whereClause.toString(), null).setClient_ID().setParameters(getRecord_ID()).list();
source = new LinkedHashMap<Integer, ArrayList<Object>>();
for (PO line : lines) {
if (line.get_ValueAsInt(MProduct.COLUMNNAME_M_Product_ID) > 0) {
ArrayList<Object> parameters = new ArrayList<Object>();
parameters.add(ID, line.get_ID());
parameters.add(PRODUCT_ID, line.get_ValueAsInt(MProduct.COLUMNNAME_M_Product_ID));
parameters.add(QTY_ORDERED, line.get_Value(MInOutLine.COLUMNNAME_PickedQty));
parameters.add(QTY_PICKED, line.get_Value(MInOutLine.COLUMNNAME_PickedQty));
source.put(line.get_ID(), parameters);
}
}
}
return source;
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class CostResult method createPurchaseOrder.
public MOrder createPurchaseOrder(Timestamp orderDate, BigDecimal qty, BigDecimal price) {
//Create Purchase Order
MOrder order = new MOrder(getCtx(), 0, trxName);
order.setAD_Org_ID(Env.getAD_Org_ID(getCtx()));
order.setC_BPartner_ID(bp.getC_BPartner_ID());
order.setIsSOTrx(false);
order.setDateOrdered(orderDate);
order.setDateAcct(orderDate);
order.setM_Warehouse_ID(w.getM_Warehouse_ID());
order.setSalesRep_ID(u.getAD_User_ID());
order.setC_DocTypeTarget_ID(MDocType.getDocType(MDocType.DOCBASETYPE_PurchaseOrder));
order.saveEx();
// Create Line
MOrderLine orderLine = new MOrderLine(order);
orderLine.setM_Product_ID(product.getM_Product_ID());
orderLine.setPrice(price);
orderLine.setQtyEntered(qty);
orderLine.saveEx();
// Complete Purchase Order
order.setDocAction(DocAction.ACTION_Complete);
order.setDocStatus(DocAction.STATUS_Drafted);
order.processIt(DocAction.ACTION_Complete);
order.saveEx();
return order;
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class LiberoValidator method docValidate.
// modelChange
public String docValidate(PO po, int timing) {
log.info(po.get_TableName() + " Timing: " + timing);
if (po instanceof MOrder && timing == TIMING_BEFORE_COMPLETE) {
MOrder order = (MOrder) po;
MPPMRP.C_Order(order);
}
if (po instanceof MInOut && timing == TIMING_AFTER_COMPLETE) {
MInOut inout = (MInOut) po;
if (inout.isSOTrx()) {
for (MInOutLine outline : inout.getLines()) {
updateMPPOrder(outline);
}
} else //Purchase Receipt
{
for (MInOutLine line : inout.getLines()) {
final String whereClause = "C_OrderLine_ID=? AND PP_Cost_Collector_ID IS NOT NULL";
Collection<MOrderLine> olines = new Query(po.getCtx(), MOrderLine.Table_Name, whereClause, po.get_TrxName()).setParameters(new Object[] { line.getC_OrderLine_ID() }).list();
for (MOrderLine oline : olines) {
if (oline.getQtyOrdered().compareTo(oline.getQtyDelivered()) >= 0) {
MPPCostCollector cc = new MPPCostCollector(po.getCtx(), oline.getPP_Cost_Collector_ID(), po.get_TrxName());
String docStatus = cc.completeIt();
cc.setDocStatus(docStatus);
cc.setDocAction(MPPCostCollector.DOCACTION_Close);
cc.saveEx();
return null;
}
}
}
}
} else // Update Distribution Order Line
if (po instanceof MMovement && timing == TIMING_AFTER_COMPLETE) {
MMovement move = (MMovement) po;
for (MMovementLine line : move.getLines(false)) {
if (line.getDD_OrderLine_ID() > 0) {
MDDOrderLine oline = new MDDOrderLine(line.getCtx(), line.getDD_OrderLine_ID(), po.get_TrxName());
MLocator locator_to = MLocator.get(line.getCtx(), line.getM_LocatorTo_ID());
MWarehouse warehouse = MWarehouse.get(line.getCtx(), locator_to.getM_Warehouse_ID());
if (warehouse.isInTransit()) {
oline.setQtyInTransit(oline.getQtyInTransit().add(line.getMovementQty()));
oline.setConfirmedQty(Env.ZERO);
} else {
oline.setQtyInTransit(oline.getQtyInTransit().subtract(line.getMovementQty()));
oline.setQtyDelivered(oline.getQtyDelivered().add(line.getMovementQty()));
}
oline.saveEx();
}
}
if (move.getDD_Order_ID() > 0) {
MDDOrder order = new MDDOrder(move.getCtx(), move.getDD_Order_ID(), move.get_TrxName());
order.setIsInTransit(isInTransting(order));
order.reserveStock(order.getLines(true, null));
order.saveEx();
}
}
return null;
}
Aggregations