Search in sources :

Example 41 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)

Example 42 with MInOut

use of org.compiere.model.MInOut 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;
}
Also used : MInOut(org.compiere.model.MInOut) Query(org.compiere.model.Query) MInOutLine(org.compiere.model.MInOutLine) MWarehouse(org.compiere.model.MWarehouse) MOrder(org.compiere.model.MOrder) MLocator(org.compiere.model.MLocator) MOrderLine(org.compiere.model.MOrderLine) MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement)

Example 43 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 44 with MInOut

use of org.compiere.model.MInOut in project lar_361 by comitsrl.

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()); @emmie
                    // 
                    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;
}
Also used : MInOut(org.compiere.model.MInOut) MInOutLine(org.compiere.model.MInOutLine) MInvoiceSchedule(org.compiere.model.MInvoiceSchedule) MBPartner(org.compiere.model.MBPartner) BigDecimal(java.math.BigDecimal) MOrder(org.compiere.model.MOrder) ResultSet(java.sql.ResultSet) MOrderLine(org.compiere.model.MOrderLine)

Example 45 with MInOut

use of org.compiere.model.MInOut in project lar_361 by comitsrl.

the class LAR_Validator method changeVoidDocumentNo.

/**
 * Change DocumentNo in order to avoid modified sequence for given document
 */
// TODO - Improve and add this behavior to ADempiere and make it configurable (ideal)
private String changeVoidDocumentNo(final PO po) {
    final Properties ctx = po.getCtx();
    PO revPo = null;
    MSequence seq = null;
    // Corrije el nro de documento de la factura anulada y su reversa asociada
    if (po.get_TableName().equals(MInvoice.Table_Name)) {
        final MInvoice invoice = (MInvoice) po;
        // Si no se tiene la referencia a la reversión, no se procesa
        if (invoice.getReversal_ID() == 0)
            return null;
        revPo = new MInvoice(ctx, invoice.getReversal_ID(), invoice.get_TrxName());
        final MInvoice revInvoice = (MInvoice) revPo;
        log.info("Change DocumentNo of " + revInvoice);
        // Intenta recuperar la secuencia "definitiva". Si no tiene, intenta
        // recupera la secuencia "normal". Si no tiene, no sea hace nada debido
        // a que le documento NO tiene secuencia configurada
        int ad_Sequence_ID = invoice.getC_DocType().getDefiniteSequence_ID();
        if (ad_Sequence_ID == 0)
            ad_Sequence_ID = invoice.getC_DocType().getDocNoSequence_ID();
        if (ad_Sequence_ID != 0)
            seq = new MSequence(ctx, ad_Sequence_ID, invoice.get_TrxName());
        // Redefine los nros de documento y las descripciones de las facturas
        String revDocumentNo = "Rev-" + invoice.getDocumentNo() + "-" + invoice.getC_Invoice_ID();
        String voidDocumentNo = "Anu-" + invoice.getDocumentNo() + "-" + invoice.getC_Invoice_ID();
        revInvoice.setDocumentNo(revDocumentNo);
        revInvoice.setDescription("(" + voidDocumentNo + "<-)");
        invoice.setDocumentNo(voidDocumentNo);
        invoice.setDescription("(" + revDocumentNo + "<-)");
        // Si la secuencia es automática, retrocede la numeración
        if (seq != null && seq.isAutoSequence())
            seq.setCurrentNext(seq.getCurrentNext() - 1);
    }
    // Corrije el nro de documento del remito anulado y su reverso asociado
    if (po.get_TableName().equals(MInOut.Table_Name)) {
        final MInOut shipment = (MInOut) po;
        // Si no se tiene la referencia a la reversión, no se procesa
        if (shipment.getReversal_ID() == 0)
            return null;
        revPo = new MInOut(ctx, shipment.getReversal_ID(), shipment.get_TrxName());
        final MInOut revShipment = (MInOut) revPo;
        log.info("Change DocumentNo of " + revShipment);
        // Intenta recuperar la secuencia "definitiva". En caso que sea nula,
        // recupera la secuencia "normal"
        int AD_Sequence_ID = shipment.getC_DocType().getDefiniteSequence_ID();
        if (AD_Sequence_ID == 0)
            AD_Sequence_ID = shipment.getC_DocType().getDocNoSequence_ID();
        if (AD_Sequence_ID != 0)
            seq = new MSequence(ctx, AD_Sequence_ID, shipment.get_TrxName());
        String revDocumentNo = "Rev-" + shipment.getDocumentNo() + "-" + shipment.getM_InOut_ID();
        String voidDocumentNo = "Anu-" + shipment.getDocumentNo() + "-" + shipment.getM_InOut_ID();
        revShipment.setDocumentNo(revDocumentNo);
        revShipment.setDescription("(" + voidDocumentNo + "<-)");
        shipment.setDocumentNo(voidDocumentNo);
        shipment.setDescription("(" + revDocumentNo + "<-)");
        // Si encontró una secuencia, y la misma es automática, retrocede la numeración
        if (seq != null && seq.isAutoSequence())
            seq.setCurrentNext(seq.getCurrentNext() - 1);
    }
    // (siempre y cuando hayan cambiado y no sean nulos)
    if (revPo != null && !revPo.save())
        return "Error al guardar el documento inverso";
    if (po.is_Changed() && !po.save())
        return "Error al guardar el documento anulado";
    if (seq != null && seq.is_Changed() && !seq.save())
        return "Error al guardar la secuencia";
    return null;
}
Also used : MInOut(org.compiere.model.MInOut) MInvoice(org.compiere.model.MInvoice) Properties(java.util.Properties) MSequence(org.compiere.model.MSequence) PO(org.compiere.model.PO)

Aggregations

MInOut (org.compiere.model.MInOut)46 MInOutLine (org.compiere.model.MInOutLine)23 MOrder (org.compiere.model.MOrder)18 BigDecimal (java.math.BigDecimal)14 MInvoice (org.compiere.model.MInvoice)14 MOrderLine (org.compiere.model.MOrderLine)11 ArrayList (java.util.ArrayList)6 ResultSet (java.sql.ResultSet)5 MBPartner (org.compiere.model.MBPartner)5 MProduct (org.compiere.model.MProduct)5 MRMA (org.compiere.model.MRMA)5 Timestamp (java.sql.Timestamp)4 MInvoiceLine (org.compiere.model.MInvoiceLine)4 MInvoiceSchedule (org.compiere.model.MInvoiceSchedule)4 MPayment (org.compiere.model.MPayment)4 MRMALine (org.compiere.model.MRMALine)4 MInOutConfirm (org.compiere.model.MInOutConfirm)3 MLocator (org.compiere.model.MLocator)3 MStorage (org.compiere.model.MStorage)3 DNFH (ar.com.ergio.print.fiscal.document.DNFH)2