Search in sources :

Example 1 with MOrderLine

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

the class RMACreateOrder method doIt.

@Override
protected String doIt() throws Exception {
    // Load RMA
    MRMA rma = new MRMA(getCtx(), rmaId, get_TrxName());
    // Load Original Order
    MOrder originalOrder = rma.getOriginalOrder();
    if (rma.get_ID() == 0) {
        throw new Exception("No RMA defined");
    }
    if (originalOrder == null) {
        throw new Exception("Could not load the original order");
    }
    // Create new order and set the different values based on original order/RMA doc
    MOrder order = new MOrder(getCtx(), 0, get_TrxName());
    order.setAD_Org_ID(rma.getAD_Org_ID());
    order.setC_BPartner_ID(originalOrder.getC_BPartner_ID());
    order.setC_BPartner_Location_ID(originalOrder.getC_BPartner_Location_ID());
    order.setAD_User_ID(originalOrder.getAD_User_ID());
    order.setBill_BPartner_ID(originalOrder.getBill_BPartner_ID());
    order.setBill_Location_ID(originalOrder.getBill_Location_ID());
    order.setBill_User_ID(originalOrder.getBill_User_ID());
    order.setSalesRep_ID(rma.getSalesRep_ID());
    order.setM_PriceList_ID(originalOrder.getM_PriceList_ID());
    order.setIsSOTrx(originalOrder.isSOTrx());
    order.setM_Warehouse_ID(originalOrder.getM_Warehouse_ID());
    order.setC_DocTypeTarget_ID(originalOrder.getC_DocTypeTarget_ID());
    order.setC_PaymentTerm_ID(originalOrder.getC_PaymentTerm_ID());
    order.setDeliveryRule(originalOrder.getDeliveryRule());
    if (!order.save()) {
        throw new IllegalStateException("Could not create order");
    }
    MRMALine[] lines = rma.getLines(true);
    for (MRMALine line : lines) {
        if (line.getShipLine() != null && line.getShipLine().getC_OrderLine_ID() != 0) {
            // Create order lines if the RMA Doc line has a shipment line 
            MOrderLine orderLine = new MOrderLine(order);
            MOrderLine originalOLine = new MOrderLine(getCtx(), line.getShipLine().getC_OrderLine_ID(), null);
            orderLine.setAD_Org_ID(line.getAD_Org_ID());
            orderLine.setM_Product_ID(originalOLine.getM_Product_ID());
            orderLine.setM_AttributeSetInstance_ID(originalOLine.getM_AttributeSetInstance_ID());
            orderLine.setC_UOM_ID(originalOLine.getC_UOM_ID());
            orderLine.setC_Tax_ID(originalOLine.getC_Tax_ID());
            orderLine.setM_Warehouse_ID(originalOLine.getM_Warehouse_ID());
            orderLine.setC_Currency_ID(originalOLine.getC_Currency_ID());
            orderLine.setQty(line.getQty());
            orderLine.setC_Project_ID(originalOLine.getC_Project_ID());
            orderLine.setC_Activity_ID(originalOLine.getC_Activity_ID());
            orderLine.setC_Campaign_ID(originalOLine.getC_Campaign_ID());
            orderLine.setPrice();
            orderLine.setPrice(line.getAmt());
            if (!orderLine.save()) {
                throw new IllegalStateException("Could not create Order Line");
            }
        }
    }
    rma.setC_Order_ID(order.getC_Order_ID());
    if (!rma.save()) {
        throw new IllegalStateException("Could not update RMA document");
    }
    return "Order Created: " + order.getDocumentNo();
}
Also used : MOrder(org.compiere.model.MOrder) MRMALine(org.compiere.model.MRMALine) MOrderLine(org.compiere.model.MOrderLine) MRMA(org.compiere.model.MRMA)

Example 2 with MOrderLine

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

the class SB_InOutGenerateFromOrderLine method generate.

//	doIt
/**
	 * 	Generate Shipments
	 * 	@param pstmt Order Query
	 *	@return info
	 */
private String generate(MOrder order) {
    try {
        if (!p_ConsolidateDocument || (m_shipment != null && (m_shipment.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID() || m_shipment.getM_Shipper_ID() != order.getM_Shipper_ID())))
            completeShipment();
        log.fine("check: " + order + " - DeliveryRule=" + order.getDeliveryRule());
        //
        Timestamp minGuaranteeDate = m_movementDate;
        boolean completeOrder = MOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule());
        //	OrderLine WHERE
        String where = "";
        //	Exclude Auto Delivery if not Force
        if (!MOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule()))
            where += " AND (C_OrderLine.M_Product_ID IS NULL" + " OR EXISTS (SELECT * FROM M_Product p " + "WHERE C_OrderLine.M_Product_ID=p.M_Product_ID" + " AND IsExcludeAutoDelivery='N'))";
        //	Deadlock Prevention - Order by M_Product_ID
        MOrderLine[] lines = order.getLines(where, "C_BPartner_Location_ID, M_Product_ID");
        for (MOrderLine oLine : lines) {
            if (!getSelectionKeys().contains(oLine.getC_OrderLine_ID()))
                continue;
            log.fine("check: " + oLine);
            BigDecimal onHand = Env.ZERO;
            BigDecimal toDeliver = getQtyToDeliver(oLine);
            if (toDeliver.compareTo(Env.ZERO) == 0)
                continue;
            MProduct product = oLine.getProduct();
            //	Nothing to Deliver
            if (product != null && toDeliver.signum() == 0)
                continue;
            // or it's a charge - Bug#: 1603966 
            if (oLine.getC_Charge_ID() != 0 && toDeliver.signum() == 0)
                continue;
            //	Check / adjust for confirmations
            BigDecimal unconfirmedShippedQty = Env.ZERO;
            //	Comments & lines w/o product & services
            if ((product == null || !product.isStocked()) && (//	comments
            oLine.getQtyOrdered().signum() == 0 || //	lines w/o product
            toDeliver.signum() != 0)) {
                if (//	printed later
                !MOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule()))
                    createLine(order, oLine, toDeliver, null, false);
                continue;
            }
            //	Stored Product
            String MMPolicy = product.getMMPolicy();
            MStorage[] storages = getStorages(oLine.getM_Warehouse_ID(), oLine.getM_Product_ID(), oLine.getM_AttributeSetInstance_ID(), minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy));
            for (int j = 0; j < storages.length; j++) {
                MStorage storage = storages[j];
                onHand = onHand.add(storage.getQtyOnHand());
            }
            boolean fullLine = onHand.compareTo(toDeliver) >= 0 || toDeliver.signum() < 0;
            //	Complete Order
            if (completeOrder && !fullLine) {
                log.fine("Failed CompleteOrder - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + oLine);
                completeOrder = false;
                break;
            } else //	Complete Line
            if (fullLine && MOrder.DELIVERYRULE_CompleteLine.equals(order.getDeliveryRule())) {
                log.fine("CompleteLine - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ", ToDeliver=" + toDeliver + " - " + oLine);
                //	
                createLine(order, oLine, toDeliver, storages, false);
            } else //	Availability
            if (MOrder.DELIVERYRULE_Availability.equals(order.getDeliveryRule()) && (onHand.signum() > 0 || toDeliver.signum() < 0)) {
                BigDecimal deliver = toDeliver;
                if (deliver.compareTo(onHand) > 0)
                    deliver = onHand;
                log.fine("Available - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + oLine);
                //	
                createLine(order, oLine, deliver, storages, false);
            } else //	Force
            if (MOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule())) {
                BigDecimal deliver = toDeliver;
                log.fine("Force - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + oLine);
                //	
                createLine(order, oLine, deliver, storages, true);
            } else //	Manual
            if (MOrder.DELIVERYRULE_Manual.equals(order.getDeliveryRule()))
                log.fine("Manual - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ") - " + oLine);
            else
                log.fine("Failed: " + order.getDeliveryRule() + " - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + oLine);
        }
        //	Complete Order successful
        if (completeOrder && MOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule())) {
            for (MOrderLine oLine : lines) {
                MProduct product = oLine.getProduct();
                BigDecimal toDeliver = oLine.getQtyOrdered().subtract(oLine.getQtyDelivered());
                //
                MStorage[] storages = null;
                if (product != null && product.isStocked()) {
                    String MMPolicy = product.getMMPolicy();
                    storages = getStorages(oLine.getM_Warehouse_ID(), oLine.getM_Product_ID(), oLine.getM_AttributeSetInstance_ID(), minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy));
                }
                //	
                createLine(order, oLine, toDeliver, storages, false);
            }
        }
        m_line += 1000;
    } catch (Exception e) {
        log.log(Level.SEVERE, m_sql, e);
    }
    completeShipment();
    return "@Created@ = " + m_created;
}
Also used : MProduct(org.compiere.model.MProduct) MOrderLine(org.compiere.model.MOrderLine) Timestamp(java.sql.Timestamp) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal)

Example 3 with MOrderLine

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

the class SB_InvoiceGenerateFromOrderLine method generate.

//	doIt
/**
	 * 	Generate Shipments
	 * 	@param pstmt order query 
	 *	@return info
	 */
private String generate(MOrder order) {
    try {
        {
            //	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
                        return "";
                }
            }
            //	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 (!getSelectionKeys().contains(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];
                    if (!getSelectionKeys().contains(oLine.getC_OrderLine_ID()))
                        continue;
                    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;
                        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
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
    completeInvoice();
    return "@Created@ = " + m_created;
}
Also used : MInOut(org.compiere.model.MInOut) MInOutLine(org.compiere.model.MInOutLine) MInvoiceSchedule(org.compiere.model.MInvoiceSchedule) MBPartner(org.compiere.model.MBPartner) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Example 4 with MOrderLine

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

the class SB_InvoiceGenerateFromOrderLine method doIt.

//	prepare
/**
	 * 	Generate Invoices
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    StringBuffer orderClause = new StringBuffer();
    m_invoices = new ArrayList<MInvoice>();
    if (!p_ConsolidateDocument)
        orderClause.append("C_BPartner_ID, C_Order_ID, line");
    else
        orderClause.append("C_BPartner_ID");
    String whereClause = "EXISTS (SELECT T_Selection_ID FROM T_Selection WHERE  T_Selection.AD_PInstance_ID=? " + " AND T_Selection.T_Selection_ID=c_orderLine.C_OrderLine_ID)";
    m_records = new Query(getCtx(), MOrderLine.Table_Name, whereClause, get_TrxName()).setParameters(getAD_PInstance_ID()).setOrderBy(orderClause.toString()).setClient_ID().list();
    ordersToInvoice = new ArrayList<MOrder>();
    for (MOrderLine orderLine : m_records) {
        Boolean isadded = false;
        for (MOrder order : ordersToInvoice) {
            if (order.getC_Order_ID() == orderLine.getC_Order_ID()) {
                isadded = true;
                break;
            }
        }
        if (!isadded)
            ordersToInvoice.add(orderLine.getParent());
    }
    for (MOrder order : ordersToInvoice) {
        generate(order);
    }
    String result = "Fact. No";
    for (MInvoice inv : m_invoices) {
        Env.setContext(getCtx(), "@WhereClause@", whereClause);
        result = result + ", " + inv.getDocumentInfo();
    }
    return result;
}
Also used : MOrder(org.compiere.model.MOrder) Query(org.compiere.model.Query) MInvoice(org.compiere.model.MInvoice) MOrderLine(org.compiere.model.MOrderLine)

Example 5 with MOrderLine

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

the class CreateFromShipment method save.

/**
	 *  Save - Create Invoice Lines
	 *  @return true if saved
	 */
public boolean save(IMiniTable miniTable, String trxName) {
    /*
		dataTable.stopEditor(true);
		log.config("");
		TableModel model = dataTable.getModel();
		int rows = model.getRowCount();
		if (rows == 0)
			return false;
		//
		Integer defaultLoc = (Integer) locatorField.getValue();
		if (defaultLoc == null || defaultLoc.intValue() == 0) {
			locatorField.setBackground(AdempierePLAF.getFieldBackground_Error());
			return false;
		}
		*/
    int M_Locator_ID = defaultLocator_ID;
    if (M_Locator_ID == 0) {
        return false;
    }
    // Get Shipment
    MInOut inout = new MInOut(Env.getCtx(), m_Record_ID, trxName);
    log.config(inout + ", C_Locator_ID=" + M_Locator_ID);
    // Lines
    for (int i = 0; i < miniTable.getRowCount(); i++) {
        if (((Boolean) miniTable.getValueAt(i, 0)).booleanValue()) {
            // variable values
            // Qty
            BigDecimal QtyEntered = (BigDecimal) miniTable.getValueAt(i, 1);
            // UOM
            KeyNamePair pp = (KeyNamePair) miniTable.getValueAt(i, 2);
            int C_UOM_ID = pp.getKey();
            // Locator
            pp = (KeyNamePair) miniTable.getValueAt(i, 3);
            // If a locator is specified on the product, choose that otherwise default locator
            M_Locator_ID = pp != null && pp.getKey() != 0 ? pp.getKey() : defaultLocator_ID;
            // Product
            pp = (KeyNamePair) miniTable.getValueAt(i, 4);
            int M_Product_ID = pp.getKey();
            int C_OrderLine_ID = 0;
            // OrderLine
            pp = (KeyNamePair) miniTable.getValueAt(i, 6);
            if (pp != null)
                C_OrderLine_ID = pp.getKey();
            int M_RMALine_ID = 0;
            // RMA
            pp = (KeyNamePair) miniTable.getValueAt(i, 7);
            // If we have RMA
            if (pp != null)
                M_RMALine_ID = pp.getKey();
            int C_InvoiceLine_ID = 0;
            MInvoiceLine il = null;
            // InvoiceLine
            pp = (KeyNamePair) miniTable.getValueAt(i, 8);
            if (pp != null)
                C_InvoiceLine_ID = pp.getKey();
            if (C_InvoiceLine_ID != 0)
                il = new MInvoiceLine(Env.getCtx(), C_InvoiceLine_ID, trxName);
            //boolean isInvoiced = (C_InvoiceLine_ID != 0);
            //	Precision of Qty UOM
            int precision = 2;
            if (M_Product_ID != 0) {
                MProduct product = MProduct.get(Env.getCtx(), M_Product_ID);
                precision = product.getUOMPrecision();
            }
            QtyEntered = QtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
            //
            log.fine("Line QtyEntered=" + QtyEntered + ", Product=" + M_Product_ID + ", OrderLine=" + C_OrderLine_ID + ", InvoiceLine=" + C_InvoiceLine_ID);
            //	Credit Memo - negative Qty
            if (m_invoice != null && m_invoice.isCreditMemo())
                QtyEntered = QtyEntered.negate();
            //	Create new InOut Line
            MInOutLine iol = new MInOutLine(inout);
            //	Line UOM
            iol.setM_Product_ID(M_Product_ID, C_UOM_ID);
            //	Movement/Entered
            iol.setQty(QtyEntered);
            //
            MOrderLine ol = null;
            MRMALine rmal = null;
            if (C_OrderLine_ID != 0) {
                iol.setC_OrderLine_ID(C_OrderLine_ID);
                ol = new MOrderLine(Env.getCtx(), C_OrderLine_ID, trxName);
                if (ol.getQtyEntered().compareTo(ol.getQtyOrdered()) != 0) {
                    iol.setMovementQty(QtyEntered.multiply(ol.getQtyOrdered()).divide(ol.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
                    iol.setC_UOM_ID(ol.getC_UOM_ID());
                }
                iol.setM_AttributeSetInstance_ID(ol.getM_AttributeSetInstance_ID());
                iol.setDescription(ol.getDescription());
                //
                iol.setC_Project_ID(ol.getC_Project_ID());
                iol.setC_ProjectPhase_ID(ol.getC_ProjectPhase_ID());
                iol.setC_ProjectTask_ID(ol.getC_ProjectTask_ID());
                iol.setC_Activity_ID(ol.getC_Activity_ID());
                iol.setC_Campaign_ID(ol.getC_Campaign_ID());
                iol.setAD_OrgTrx_ID(ol.getAD_OrgTrx_ID());
                iol.setUser1_ID(ol.getUser1_ID());
                iol.setUser2_ID(ol.getUser2_ID());
                iol.setUser3_ID(ol.getUser3_ID());
                iol.setUser4_ID(ol.getUser4_ID());
            } else if (il != null) {
                if (il.getQtyEntered().compareTo(il.getQtyInvoiced()) != 0) {
                    iol.setQtyEntered(QtyEntered.multiply(il.getQtyInvoiced()).divide(il.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
                    iol.setC_UOM_ID(il.getC_UOM_ID());
                }
                iol.setDescription(il.getDescription());
                iol.setC_Project_ID(il.getC_Project_ID());
                iol.setC_ProjectPhase_ID(il.getC_ProjectPhase_ID());
                iol.setC_ProjectTask_ID(il.getC_ProjectTask_ID());
                iol.setC_Activity_ID(il.getC_Activity_ID());
                iol.setC_Campaign_ID(il.getC_Campaign_ID());
                iol.setAD_OrgTrx_ID(il.getAD_OrgTrx_ID());
                iol.setUser1_ID(il.getUser1_ID());
                iol.setUser2_ID(il.getUser2_ID());
                iol.setUser3_ID(il.getUser3_ID());
                iol.setUser4_ID(il.getUser4_ID());
            } else if (M_RMALine_ID != 0) {
                rmal = new MRMALine(Env.getCtx(), M_RMALine_ID, trxName);
                iol.setM_RMALine_ID(M_RMALine_ID);
                iol.setQtyEntered(QtyEntered);
                iol.setDescription(rmal.getDescription());
                iol.setM_AttributeSetInstance_ID(rmal.getM_AttributeSetInstance_ID());
                iol.setC_Project_ID(rmal.getC_Project_ID());
                iol.setC_ProjectPhase_ID(rmal.getC_ProjectPhase_ID());
                iol.setC_ProjectTask_ID(rmal.getC_ProjectTask_ID());
                iol.setC_Activity_ID(rmal.getC_Activity_ID());
                iol.setAD_OrgTrx_ID(rmal.getAD_OrgTrx_ID());
                iol.setUser1_ID(rmal.getUser1_ID());
                iol.setUser2_ID(rmal.getUser2_ID());
                iol.setUser3_ID(rmal.getUser3_ID());
                iol.setUser4_ID(rmal.getUser4_ID());
            }
            //	Charge
            if (M_Product_ID == 0) {
                if (//	from order
                ol != null && ol.getC_Charge_ID() != 0)
                    iol.setC_Charge_ID(ol.getC_Charge_ID());
                else if (//	from invoice
                il != null && il.getC_Charge_ID() != 0)
                    iol.setC_Charge_ID(il.getC_Charge_ID());
                else if (// from rma
                rmal != null && rmal.getC_Charge_ID() != 0)
                    iol.setC_Charge_ID(rmal.getC_Charge_ID());
            }
            // Set locator
            iol.setM_Locator_ID(M_Locator_ID);
            if (!iol.save())
                log.log(Level.SEVERE, "Line NOT created #" + i);
            else //	Create Invoice Line Link
            if (il != null) {
                il.setM_InOutLine_ID(iol.getM_InOutLine_ID());
                il.saveEx();
            }
        }
    //   if selected
    }
    /**
		 *  Update Header
		 *  - if linked to another order/invoice/rma - remove link
		 *  - if no link set it
		 */
    if (p_order != null && p_order.getC_Order_ID() != 0) {
        inout.setC_Order_ID(p_order.getC_Order_ID());
        inout.setAD_OrgTrx_ID(p_order.getAD_OrgTrx_ID());
        inout.setC_Project_ID(p_order.getC_Project_ID());
        inout.setC_Campaign_ID(p_order.getC_Campaign_ID());
        inout.setC_Activity_ID(p_order.getC_Activity_ID());
        inout.setUser1_ID(p_order.getUser1_ID());
        inout.setUser2_ID(p_order.getUser2_ID());
        inout.setUser3_ID(p_order.getUser3_ID());
        inout.setUser4_ID(p_order.getUser4_ID());
        if (p_order.isDropShip()) {
            inout.setM_Warehouse_ID(p_order.getM_Warehouse_ID());
            inout.setIsDropShip(p_order.isDropShip());
            inout.setDropShip_BPartner_ID(p_order.getDropShip_BPartner_ID());
            inout.setDropShip_Location_ID(p_order.getDropShip_Location_ID());
            inout.setDropShip_User_ID(p_order.getDropShip_User_ID());
        }
    }
    if (m_invoice != null && m_invoice.getC_Invoice_ID() != 0) {
        if (inout.getC_Order_ID() == 0)
            inout.setC_Order_ID(m_invoice.getC_Order_ID());
        inout.setC_Invoice_ID(m_invoice.getC_Invoice_ID());
        inout.setAD_OrgTrx_ID(m_invoice.getAD_OrgTrx_ID());
        inout.setC_Project_ID(m_invoice.getC_Project_ID());
        inout.setC_Campaign_ID(m_invoice.getC_Campaign_ID());
        inout.setC_Activity_ID(m_invoice.getC_Activity_ID());
        inout.setUser1_ID(m_invoice.getUser1_ID());
        inout.setUser2_ID(m_invoice.getUser2_ID());
        inout.setUser3_ID(m_invoice.getUser3_ID());
        inout.setUser4_ID(m_invoice.getUser4_ID());
    }
    if (m_rma != null && m_rma.getM_RMA_ID() != 0) {
        MInOut originalIO = m_rma.getShipment();
        inout.setIsSOTrx(m_rma.isSOTrx());
        inout.setC_Order_ID(0);
        inout.setC_Invoice_ID(0);
        inout.setM_RMA_ID(m_rma.getM_RMA_ID());
        inout.setAD_OrgTrx_ID(originalIO.getAD_OrgTrx_ID());
        inout.setC_Project_ID(originalIO.getC_Project_ID());
        inout.setC_Campaign_ID(originalIO.getC_Campaign_ID());
        inout.setC_Activity_ID(originalIO.getC_Activity_ID());
        inout.setUser1_ID(originalIO.getUser1_ID());
        inout.setUser2_ID(originalIO.getUser2_ID());
        inout.setUser3_ID(originalIO.getUser3_ID());
        inout.setUser4_ID(originalIO.getUser4_ID());
    }
    inout.saveEx();
    return true;
}
Also used : MInOut(org.compiere.model.MInOut) MProduct(org.compiere.model.MProduct) MInOutLine(org.compiere.model.MInOutLine) MInvoiceLine(org.compiere.model.MInvoiceLine) KeyNamePair(org.compiere.util.KeyNamePair) MOrderLine(org.compiere.model.MOrderLine) MRMALine(org.compiere.model.MRMALine) BigDecimal(java.math.BigDecimal)

Aggregations

MOrderLine (org.compiere.model.MOrderLine)87 BigDecimal (java.math.BigDecimal)44 MOrder (org.compiere.model.MOrder)42 MInOutLine (org.compiere.model.MInOutLine)16 MProduct (org.compiere.model.MProduct)15 MBPartner (org.compiere.model.MBPartner)14 MInOut (org.compiere.model.MInOut)11 ResultSet (java.sql.ResultSet)10 ArrayList (java.util.ArrayList)8 Query (org.compiere.model.Query)8 PreparedStatement (java.sql.PreparedStatement)7 MInvoice (org.compiere.model.MInvoice)7 MInvoiceLine (org.compiere.model.MInvoiceLine)7 AdempiereException (org.adempiere.exceptions.AdempiereException)6 SQLException (java.sql.SQLException)5 MLocator (org.compiere.model.MLocator)5 Timestamp (java.sql.Timestamp)4 MRMALine (org.compiere.model.MRMALine)4 MBPartnerLocation (org.compiere.model.MBPartnerLocation)3 MDocType (org.compiere.model.MDocType)3