Search in sources :

Example 26 with MInOut

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

the class InOutGenerateRMA method generateShipment.

private void generateShipment(int M_RMA_ID) {
    MRMA rma = new MRMA(getCtx(), M_RMA_ID, get_TrxName());
    MInOut shipment = createShipment(rma);
    MInOutLine[] shipmentLines = createShipmentLines(rma, shipment);
    if (shipmentLines.length == 0) {
        log.log(Level.WARNING, "No shipment lines created: M_RMA_ID=" + M_RMA_ID + ", M_InOut_ID=" + shipment.get_ID());
    }
    StringBuffer processMsg = new StringBuffer(shipment.getDocumentNo());
    if (!shipment.processIt(p_docAction)) {
        processMsg.append(" (NOT Processed)");
        log.warning("Shipment Processing failed: " + shipment + " - " + shipment.getProcessMsg());
    }
    if (!shipment.save()) {
        throw new IllegalStateException("Could not update shipment");
    }
    // Add processing information to process log
    addLog(shipment.getM_InOut_ID(), shipment.getMovementDate(), null, processMsg.toString());
    m_created++;
}
Also used : MInOut(org.compiere.model.MInOut) MInOutLine(org.compiere.model.MInOutLine) MRMA(org.compiere.model.MRMA)

Example 27 with MInOut

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

the class InvoiceGenerateFromShipment method generate.

//@Trifon
private String generate(PreparedStatement pstmt) {
    ResultSet rs = null;
    MInvoice invoice = null;
    try {
        rs = pstmt.executeQuery();
        while (rs.next()) {
            MInOut inOut = new MInOut(getCtx(), rs, get_TrxName());
            if (//	ignore incomplete or reversals 
            !inOut.isComplete() || inOut.getDocStatus().equals(MInOut.DOCSTATUS_Reversed)) {
                continue;
            }
            MOrder order = new MOrder(getCtx(), inOut.getC_Order_ID(), get_TrxName());
            //	New Invoice Location
            if (!p_ConsolidateDocument || (invoice != null && invoice.getC_BPartner_Location_ID() != order.getBill_Location_ID())) {
                invoice = completeInvoice(invoice);
            }
            //				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.save();
                } 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 - Invoice per Delivery
            if (doInvoice || MOrder.INVOICERULE_AfterDelivery.equals(order.getInvoiceRule())) {
                MInOutLine[] shipLines = inOut.getLines(false);
                for (int j = 0; j < shipLines.length; j++) {
                    MInOutLine inOutLine = shipLines[j];
                    if (!inOutLine.isInvoiced()) {
                        invoice = createInvoiceLineFromShipmentLine(invoice, order, inOut, inOutLine);
                    }
                }
                m_line += 1000;
            } else //	After Order Delivered, Immediate
            {
                throw new AdempiereException("Not supported Invoice Rules[Immediate, AfterOrderDelivered]");
            }
        }
    // for all Shipments
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    } finally {
        DB.close(rs, pstmt);
        pstmt = null;
    }
    completeInvoice(invoice);
    return "@Created@ = " + m_created;
}
Also used : MInOut(org.compiere.model.MInOut) MOrder(org.compiere.model.MOrder) MInOutLine(org.compiere.model.MInOutLine) AdempiereException(org.adempiere.exceptions.AdempiereException) ResultSet(java.sql.ResultSet) MInvoice(org.compiere.model.MInvoice) MInvoiceSchedule(org.compiere.model.MInvoiceSchedule) MBPartner(org.compiere.model.MBPartner) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 28 with MInOut

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

the class SB_InOutGenerateFromOrderLine method createLine.

//	generate
/**************************************************************************
	 * 	Create Line
	 *	@param order order
	 *	@param orderLine line
	 *	@param qty qty
	 *	@param storages storage info
	 *	@param force force delivery
	 */
private void createLine(MOrder order, MOrderLine orderLine, BigDecimal qty, MStorage[] storages, boolean force) {
    //	Complete last Shipment - can have multiple shipments
    if (m_lastC_BPartner_Location_ID != orderLine.getC_BPartner_Location_ID())
        completeShipment();
    m_lastC_BPartner_Location_ID = orderLine.getC_BPartner_Location_ID();
    //	Create New Shipment
    if (m_shipment == null) {
        m_shipment = new MInOut(order, 0, m_movementDate);
        if (p_C_DocType_ID != 0)
            m_shipment.setC_DocType_ID(p_C_DocType_ID);
        //	sets Org too
        m_shipment.setM_Warehouse_ID(orderLine.getM_Warehouse_ID());
        if (order.getC_BPartner_ID() != orderLine.getC_BPartner_ID())
            m_shipment.setC_BPartner_ID(orderLine.getC_BPartner_ID());
        if (order.getC_BPartner_Location_ID() != orderLine.getC_BPartner_Location_ID())
            m_shipment.setC_BPartner_Location_ID(orderLine.getC_BPartner_Location_ID());
        if (!m_shipment.save())
            throw new IllegalStateException("Could not create Shipment");
    }
    //	Non Inventory Lines
    if (storages == null) {
        MInOutLine line = new MInOutLine(m_shipment);
        line.setOrderLine(orderLine, 0, Env.ZERO);
        //	Correct UOM
        line.setQty(qty);
        if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0)
            line.setQtyEntered(qty.multiply(orderLine.getQtyEntered()).divide(orderLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP));
        line.setLine(m_line + orderLine.getLine());
        if (!line.save())
            throw new IllegalStateException("Could not create Shipment Line");
        log.fine(line.toString());
        return;
    }
    //	Inventory Lines
    ArrayList<MInOutLine> list = new ArrayList<MInOutLine>();
    MProduct product = (MProduct) orderLine.getM_Product();
    BigDecimal toDeliver = qty;
    for (int i = 0; i < storages.length; i++) {
        MStorage storage = storages[i];
        BigDecimal deliver = toDeliver;
        //skip negative storage record
        if (storage.getQtyOnHand().signum() < 0)
            continue;
        //	Not enough On Hand
        if (deliver.compareTo(storage.getQtyOnHand()) > 0 && //	positive storage
        storage.getQtyOnHand().signum() >= 0) {
            if (//	Adjust to OnHand Qty  
            !force || //	if force not on last location
            (force && i + 1 != storages.length))
                deliver = storage.getQtyOnHand();
        }
        if (//	zero deliver
        deliver.signum() == 0)
            continue;
        int M_Locator_ID = storage.getM_Locator_ID();
        //
        MInOutLine line = null;
        if (//      find line with Locator
        orderLine.getM_AttributeSetInstance_ID() == 0) {
            for (int ll = 0; ll < list.size(); ll++) {
                MInOutLine test = (MInOutLine) list.get(ll);
                if (test.getM_Locator_ID() == M_Locator_ID && test.getM_AttributeSetInstance_ID() == 0) {
                    line = test;
                    break;
                }
            }
        }
        if (//	new line
        line == null) {
            line = new MInOutLine(m_shipment);
            line.setOrderLine(orderLine, M_Locator_ID, order.isSOTrx() ? deliver : Env.ZERO);
            line.setQty(deliver);
            if (product != null && product.isASIMandatory(order.isSOTrx(), line.getAD_Org_ID()))
                line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
            list.add(line);
        } else
            //	existing line
            line.setQty(line.getMovementQty().add(deliver));
        if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0)
            line.setQtyEntered(line.getMovementQty().multiply(orderLine.getQtyEntered()).divide(orderLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP));
        line.setLine(m_line + orderLine.getLine());
        if (!line.save())
            throw new IllegalStateException("Could not create Shipment Line");
        log.fine("ToDeliver=" + qty + "/" + deliver + " - " + line);
        toDeliver = toDeliver.subtract(deliver);
        //      Temp adjustment, actual update happen in MInOut.completeIt
        storage.setQtyOnHand(storage.getQtyOnHand().subtract(deliver));
        //
        if (toDeliver.signum() == 0)
            break;
    }
    if (toDeliver.signum() != 0) {
        if (!force) {
            throw new IllegalStateException("Not All Delivered - Remainder=" + toDeliver);
        } else {
            MInOutLine line = new MInOutLine(m_shipment);
            line.setOrderLine(orderLine, 0, order.isSOTrx() ? toDeliver : Env.ZERO);
            line.setQty(toDeliver);
            if (!line.save())
                throw new IllegalStateException("Could not create Shipment Line");
        }
    }
}
Also used : MInOut(org.compiere.model.MInOut) MProduct(org.compiere.model.MProduct) MInOutLine(org.compiere.model.MInOutLine) ArrayList(java.util.ArrayList) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal)

Example 29 with MInOut

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

the class GenerateLandedCost method doIt.

/**
     * Process - Generate Export Format
     *
     * @return info
     */
@SuppressWarnings("unchecked")
protected String doIt() throws Exception {
    String receipts = "";
    if (isCreatebyProduct()) {
        for (MInOutLine inOutLine : getRecords()) {
            createLandedCost(null, inOutLine);
            receipts = receipts.concat(inOutLine.getParent().getDocumentNo() + " " + inOutLine.getM_Product().getValue()).concat(" ");
        }
    } else {
        LinkedHashMap<Integer, MInOut> inOutList = new LinkedHashMap<Integer, MInOut>();
        for (MInOutLine inOutLine : getRecords()) {
            MInOut inOut = inOutLine.getParent();
            if (inOutList.containsKey(inOut.getM_InOut_ID()))
                continue;
            inOutList.put(inOut.getM_InOut_ID(), inOut);
        }
        for (Entry<Integer, MInOut> entry : inOutList.entrySet()) {
            MInOut inOut = entry.getValue();
            createLandedCost(inOut, null);
            receipts = receipts.concat(inOut.getDocumentNo()).concat(" ");
        }
    }
    return receipts;
}
Also used : MInOut(org.compiere.model.MInOut) MInOutLine(org.compiere.model.MInOutLine) LinkedHashMap(java.util.LinkedHashMap)

Example 30 with MInOut

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

the class InvoiceCreateInOut method getCreateHeader.

//	doIt
/**
	 * Create Shipment/Receipt header
	 * @param invoice
	 * @return Shipment/Receipt header
	 */
private MInOut getCreateHeader(MInvoice invoice) {
    if (m_inout != null)
        return m_inout;
    m_inout = new MInOut(invoice, 0, null, p_M_Warehouse_ID);
    m_inout.saveEx();
    return m_inout;
}
Also used : MInOut(org.compiere.model.MInOut)

Aggregations

MInOut (org.compiere.model.MInOut)38 MInOutLine (org.compiere.model.MInOutLine)22 BigDecimal (java.math.BigDecimal)13 MOrder (org.compiere.model.MOrder)13 MInvoice (org.compiere.model.MInvoice)10 MOrderLine (org.compiere.model.MOrderLine)9 ArrayList (java.util.ArrayList)6 MProduct (org.compiere.model.MProduct)5 MRMA (org.compiere.model.MRMA)5 ResultSet (java.sql.ResultSet)4 Timestamp (java.sql.Timestamp)4 MInvoiceLine (org.compiere.model.MInvoiceLine)4 MRMALine (org.compiere.model.MRMALine)4 MBPartner (org.compiere.model.MBPartner)3 MInOutConfirm (org.compiere.model.MInOutConfirm)3 MInvoiceSchedule (org.compiere.model.MInvoiceSchedule)3 MLocator (org.compiere.model.MLocator)3 MStorage (org.compiere.model.MStorage)3 PreparedStatement (java.sql.PreparedStatement)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2