use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class GenerateInOutBound method doIt.
/**
* Process - Generate Export Format
* @return info
*/
protected String doIt() throws Exception {
// Create Outbound Order
MWMInOutBound outBoundOrder = null;
// Based on Sales Order Line
if ("ol".equals(getAliasForTableSelection())) {
outBoundOrder = createOutBoundOrder();
createBasedOnSalesOrders(outBoundOrder, (List<MOrderLine>) getInstancesForSelection(get_TrxName()));
}
// Based on MRP
if ("demand".equals(getAliasForTableSelection())) {
getProcessInfo().setTableSelectionId(MPPMRP.Table_ID);
outBoundOrder = createOutBoundOrder();
createBasedOnDemand(outBoundOrder, (List<MPPMRP>) getInstancesForSelection(get_TrxName()));
}
return "@DocumentNo@ " + outBoundOrder.getDocumentNo();
}
use of org.compiere.model.MOrderLine 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.MOrderLine in project adempiere by adempiere.
the class ReleaseInOutBound method createRequisition.
/**
* Create Requisition when the Is create supply is define as yes
* @param outBoundOrderLine
* @param product Product
* @param QtyPlanned Qty Planned
*/
public void createRequisition(MWMInOutBoundLine outBoundOrderLine, MProduct product, BigDecimal QtyPlanned) {
//s_log.info("Create Requisition");
int partnerId = 0;
int priceListId = 0;
MProductPO productPOLast;
MProductPO[] productPOs = MProductPO.getOfProduct(getCtx(), product.getM_Product_ID(), null);
Arrays.stream(productPOs).forEach(productPO -> {
if (productPO.isCurrentVendor() && productPO.getC_BPartner_ID() != 0) {
}
});
if (partnerId == 0 && productPOs.length > 0) {
partnerId = productPOs[0].getC_BPartner_ID();
}
if (partnerId == 0) {
throw new NoVendorForProductException(product.getName());
}
final String sql = "SELECT COALESCE(bp." + MBPartner.COLUMNNAME_PO_PriceList_ID + ",bpg." + X_C_BP_Group.COLUMNNAME_PO_PriceList_ID + ")" + " FROM C_BPartner bp" + " INNER JOIN C_BP_Group bpg ON (bpg.C_BP_Group_ID=bp.C_BP_Group_ID)" + " WHERE bp.C_BPartner_ID=?";
priceListId = DB.getSQLValueEx(get_TrxName(), sql, partnerId);
MRequisition requisition = new MRequisition(getCtx(), 0, get_TrxName());
requisition.setAD_Org_ID(outBoundLocator.getAD_Org_ID());
requisition.setAD_User_ID(getAD_User_ID());
requisition.setDateRequired(outBoundOrderLine.getPickDate());
// TODO: add translation
requisition.setDescription("Generate from Outbound Order");
requisition.setM_Warehouse_ID(outBoundLocator.getM_Warehouse_ID());
requisition.setC_DocType_ID(MDocType.getDocType(MDocType.DOCBASETYPE_PurchaseRequisition));
if (priceListId > 0)
requisition.setM_PriceList_ID(priceListId);
requisition.saveEx();
MRequisitionLine reqline = new MRequisitionLine(requisition);
reqline.setLine(10);
reqline.setAD_Org_ID(outBoundLocator.getAD_Org_ID());
reqline.setC_BPartner_ID(partnerId);
reqline.setM_Product_ID(product.getM_Product_ID());
reqline.setPrice();
reqline.setPriceActual(Env.ZERO);
reqline.setQty(QtyPlanned);
reqline.saveEx();
MOrderLine orderLine = new MOrderLine(getCtx(), outBoundOrderLine.getC_OrderLine_ID(), get_TrxName());
orderLine.setDescription(orderLine.getDescription() + " " + Msg.translate(getCtx(), MRequisition.COLUMNNAME_M_Requisition_ID) + " : " + requisition.getDocumentNo());
orderLine.saveEx();
outBoundOrderLine.setDescription(outBoundOrderLine.getDescription() + " " + Msg.translate(outBoundOrderLine.getCtx(), MRequisition.COLUMNNAME_M_Requisition_ID) + " : " + requisition.getDocumentNo());
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class InOutCreateFrom method doIt.
@Override
protected String doIt() throws Exception {
// Valid Record Identifier
if (getRecord_ID() == 0)
return "";
AtomicInteger referenceId = new AtomicInteger(0);
AtomicInteger created = new AtomicInteger(0);
// Get Shipment
MInOut inout = new MInOut(getCtx(), getRecord_ID(), get_TrxName());
log.config(inout + ", C_Locator_ID=" + getLocator());
// Get Default Locator
MLocator defaultLocator = MLocator.getDefault((MWarehouse) inout.getM_Warehouse());
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");
int locatorId = getSelectionAsInt(key, "CF_M_Locator_ID");
BigDecimal qtyEntered = getSelectionAsBigDecimal(key, "CF_QtyEntered");
locatorId = getValidLocator(locatorId, defaultLocator);
MInvoiceLine invoiceLine = null;
int precision = 2;
if (productId != 0) {
MProduct product = MProduct.get(getCtx(), productId);
precision = product.getUOMPrecision();
}
qtyEntered = qtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
log.fine("Line QtyEntered=" + qtyEntered + ", Product=" + productId + ", Key=" + key);
MInOutLine inOutLine = new MInOutLine(inout);
inOutLine.setM_Product_ID(productId, uomId);
inOutLine.setQty(qtyEntered);
if (createFromType.equals(ORDER)) {
MOrderLine orderLine = new MOrderLine(getCtx(), key, get_TrxName());
referenceId.set(orderLine.getC_Order_ID());
inOutLine.setC_OrderLine_ID(key);
if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0) {
inOutLine.setMovementQty(qtyEntered.multiply(orderLine.getQtyOrdered()).divide(orderLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
inOutLine.setC_UOM_ID(orderLine.getC_UOM_ID());
}
inOutLine.setM_AttributeSetInstance_ID(orderLine.getM_AttributeSetInstance_ID());
inOutLine.setDescription(orderLine.getDescription());
inOutLine.setC_Project_ID(orderLine.getC_Project_ID());
inOutLine.setC_ProjectPhase_ID(orderLine.getC_ProjectPhase_ID());
inOutLine.setC_ProjectTask_ID(orderLine.getC_ProjectTask_ID());
inOutLine.setC_Activity_ID(orderLine.getC_Activity_ID());
inOutLine.setC_Campaign_ID(orderLine.getC_Campaign_ID());
inOutLine.setAD_OrgTrx_ID(orderLine.getAD_OrgTrx_ID());
inOutLine.setUser1_ID(orderLine.getUser1_ID());
inOutLine.setUser2_ID(orderLine.getUser2_ID());
inOutLine.setUser3_ID(orderLine.getUser3_ID());
inOutLine.setUser4_ID(orderLine.getUser4_ID());
} else if (createFromType.equals(INVOICE)) {
invoiceLine = new MInvoiceLine(getCtx(), key, get_TrxName());
MInvoice invoice = invoiceLine.getParent();
referenceId.getAndSet(invoice.getC_Invoice_ID());
if (invoice.isCreditMemo()) {
qtyEntered = qtyEntered.negate();
inOutLine.setQty(qtyEntered);
}
if (invoiceLine.getQtyEntered().compareTo(invoiceLine.getQtyInvoiced()) != 0) {
inOutLine.setMovementQty(qtyEntered.multiply(invoiceLine.getQtyInvoiced()).divide(invoiceLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
inOutLine.setC_UOM_ID(invoiceLine.getC_UOM_ID());
}
inOutLine.setDescription(invoiceLine.getDescription());
inOutLine.setC_Project_ID(invoiceLine.getC_Project_ID());
inOutLine.setC_ProjectPhase_ID(invoiceLine.getC_ProjectPhase_ID());
inOutLine.setC_ProjectTask_ID(invoiceLine.getC_ProjectTask_ID());
inOutLine.setC_Activity_ID(invoiceLine.getC_Activity_ID());
inOutLine.setC_Campaign_ID(invoiceLine.getC_Campaign_ID());
inOutLine.setAD_OrgTrx_ID(invoiceLine.getAD_OrgTrx_ID());
inOutLine.setUser1_ID(invoiceLine.getUser1_ID());
inOutLine.setUser2_ID(invoiceLine.getUser2_ID());
inOutLine.setUser3_ID(invoiceLine.getUser3_ID());
inOutLine.setUser4_ID(invoiceLine.getUser4_ID());
} else if (createFromType.equals(RMA)) {
MRMALine rmal = new MRMALine(getCtx(), key, get_TrxName());
referenceId.set(rmal.getM_RMA_ID());
inOutLine.setM_RMALine_ID(key);
inOutLine.setQtyEntered(qtyEntered);
inOutLine.setDescription(rmal.getDescription());
inOutLine.setM_AttributeSetInstance_ID(rmal.getM_AttributeSetInstance_ID());
inOutLine.setC_Project_ID(rmal.getC_Project_ID());
inOutLine.setC_ProjectPhase_ID(rmal.getC_ProjectPhase_ID());
inOutLine.setC_ProjectTask_ID(rmal.getC_ProjectTask_ID());
inOutLine.setC_Activity_ID(rmal.getC_Activity_ID());
inOutLine.setAD_OrgTrx_ID(rmal.getAD_OrgTrx_ID());
inOutLine.setUser1_ID(rmal.getUser1_ID());
inOutLine.setUser2_ID(rmal.getUser2_ID());
inOutLine.setUser3_ID(rmal.getUser3_ID());
inOutLine.setUser4_ID(rmal.getUser4_ID());
}
if (chargeId != 0)
inOutLine.setC_Charge_ID(chargeId);
inOutLine.setM_Locator_ID(locatorId);
inOutLine.saveEx();
if (invoiceLine != null) {
invoiceLine.setM_InOutLine_ID(inOutLine.getM_InOutLine_ID());
invoiceLine.saveEx();
}
created.updateAndGet(createNo -> createNo + 1);
});
// Add reference to Order / Invoice / RMA
addReference(inout, createFromType, referenceId.get());
//
return "@Created@ " + created.get();
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class InvoiceGenerate method generate.
// doIt
/**
* Generate Shipments
* @param pstmt order query
* @return info
*/
private String generate(PreparedStatement pstmt) {
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
MOrder order = new MOrder(getCtx(), rs, get_TrxName());
// New Invoice Location
if (!p_ConsolidateDocument || (m_invoice != null && m_invoice.getC_BPartner_Location_ID() != order.getBill_Location_ID()))
completeInvoice();
boolean completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.equals(order.getInvoiceRule());
// Schedule After Delivery
boolean doInvoice = false;
if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.equals(order.getInvoiceRule())) {
m_bp = new MBPartner(getCtx(), order.getBill_BPartner_ID(), null);
if (m_bp.getC_InvoiceSchedule_ID() == 0) {
log.warning("BPartner has no Schedule - set to After Delivery");
order.setInvoiceRule(MOrder.INVOICERULE_AfterDelivery);
order.saveEx();
} else {
MInvoiceSchedule is = MInvoiceSchedule.get(getCtx(), m_bp.getC_InvoiceSchedule_ID(), get_TrxName());
if (is.canInvoice(order.getDateOrdered(), order.getGrandTotal()))
doInvoice = true;
else
continue;
}
}
// After Delivery
if (doInvoice || MOrder.INVOICERULE_AfterDelivery.equals(order.getInvoiceRule())) {
MInOut[] shipments = order.getShipments();
for (int i = 0; i < shipments.length; i++) {
MInOut ship = shipments[i];
if (// ignore incomplete or reversals
!ship.isComplete() || ship.getDocStatus().equals(MInOut.DOCSTATUS_Reversed))
continue;
MInOutLine[] shipLines = ship.getLines(false);
for (int j = 0; j < shipLines.length; j++) {
MInOutLine shipLine = shipLines[j];
if (!order.isOrderLine(shipLine.getC_OrderLine_ID()))
continue;
if (!shipLine.isInvoiced())
createLine(order, ship, shipLine);
}
m_line += 1000;
}
} else // After Order Delivered, Immediate
{
MOrderLine[] oLines = order.getLines(true, null);
for (int i = 0; i < oLines.length; i++) {
MOrderLine oLine = oLines[i];
BigDecimal toInvoice = oLine.getQtyOrdered().subtract(oLine.getQtyInvoiced());
if (toInvoice.compareTo(Env.ZERO) == 0 && oLine.getM_Product_ID() != 0)
continue;
BigDecimal notInvoicedShipment = oLine.getQtyDelivered().subtract(oLine.getQtyInvoiced());
//
boolean fullyDelivered = oLine.getQtyOrdered().compareTo(oLine.getQtyDelivered()) == 0;
// Complete Order
if (completeOrder && !fullyDelivered) {
log.fine("Failed CompleteOrder - " + oLine);
// Elaine 2008/11/25
addLog("Failed CompleteOrder - " + oLine);
completeOrder = false;
break;
} else // Immediate
if (MOrder.INVOICERULE_Immediate.equals(order.getInvoiceRule())) {
log.fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine);
BigDecimal qtyEntered = toInvoice;
// Correct UOM for QtyEntered
if (oLine.getQtyEntered().compareTo(oLine.getQtyOrdered()) != 0)
qtyEntered = toInvoice.multiply(oLine.getQtyEntered()).divide(oLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP);
createLine(order, oLine, toInvoice, qtyEntered);
} else {
log.fine("Failed: " + order.getInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine);
addLog("Failed: " + order.getInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine);
}
}
// for all order lines
if (MOrder.INVOICERULE_Immediate.equals(order.getInvoiceRule()))
m_line += 1000;
}
// Complete Order successful
if (completeOrder && MOrder.INVOICERULE_AfterOrderDelivered.equals(order.getInvoiceRule())) {
MInOut[] shipments = order.getShipments();
for (int i = 0; i < shipments.length; i++) {
MInOut ship = shipments[i];
if (// ignore incomplete or reversals
!ship.isComplete() || ship.getDocStatus().equals(MInOut.DOCSTATUS_Reversed))
continue;
MInOutLine[] shipLines = ship.getLines(false);
for (int j = 0; j < shipLines.length; j++) {
MInOutLine shipLine = shipLines[j];
if (!order.isOrderLine(shipLine.getC_OrderLine_ID()))
continue;
if (!shipLine.isInvoiced())
createLine(order, ship, shipLine);
}
m_line += 1000;
}
}
// complete Order
}
// for all orders
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
completeInvoice();
return "@Created@ = " + m_created;
}
Aggregations