Search in sources :

Example 1 with MOrderPaySchedule

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

the class InvoiceGenerate method completeInvoice.

// createLine
/**
 * 	Complete Invoice
 */
private void completeInvoice() {
    if (m_invoice != null) {
        // @emmie custom
        m_invoice.set_ValueOfColumn("C_POS_ID", p_C_POS_ID);
        // @emmie custom
        MOrder order = new MOrder(getCtx(), m_invoice.getC_Order_ID(), get_TrxName());
        if (order != null) {
            m_invoice.setPaymentRule(order.getPaymentRule());
            m_invoice.setC_PaymentTerm_ID(order.getC_PaymentTerm_ID());
            m_invoice.saveEx();
            // refresh from DB
            m_invoice.load(m_invoice.get_TrxName());
            // copy payment schedule from order if invoice doesn't have a current payment schedule
            MOrderPaySchedule[] opss = MOrderPaySchedule.getOrderPaySchedule(getCtx(), order.getC_Order_ID(), 0, get_TrxName());
            MInvoicePaySchedule[] ipss = MInvoicePaySchedule.getInvoicePaySchedule(getCtx(), m_invoice.getC_Invoice_ID(), 0, get_TrxName());
            if (ipss.length == 0 && opss.length > 0) {
                BigDecimal ogt = order.getGrandTotal();
                BigDecimal igt = m_invoice.getGrandTotal();
                BigDecimal percent = Env.ONE;
                if (ogt.compareTo(igt) != 0)
                    percent = igt.divide(ogt, 10, BigDecimal.ROUND_HALF_UP);
                MCurrency cur = MCurrency.get(order.getCtx(), order.getC_Currency_ID());
                int scale = cur.getStdPrecision();
                for (MOrderPaySchedule ops : opss) {
                    MInvoicePaySchedule ips = new MInvoicePaySchedule(getCtx(), 0, get_TrxName());
                    PO.copyValues(ops, ips);
                    if (percent != Env.ONE) {
                        BigDecimal propDueAmt = ops.getDueAmt().multiply(percent);
                        if (propDueAmt.scale() > scale)
                            propDueAmt = propDueAmt.setScale(scale, BigDecimal.ROUND_HALF_UP);
                        ips.setDueAmt(propDueAmt);
                    }
                    ips.setC_Invoice_ID(m_invoice.getC_Invoice_ID());
                    ips.setAD_Org_ID(ops.getAD_Org_ID());
                    ips.setProcessing(ops.isProcessing());
                    ips.setIsActive(ops.isActive());
                    ips.saveEx();
                }
                m_invoice.validatePaySchedule();
                m_invoice.saveEx();
            }
        }
        if (!m_invoice.processIt(p_docAction)) {
            log.warning("completeInvoice - failed: " + m_invoice);
            // Elaine 2008/11/25
            addLog("completeInvoice - failed: " + m_invoice);
            throw new IllegalStateException("Invoice Process Failed: " + m_invoice + " - " + m_invoice.getProcessMsg());
        } else // @emmie custom - impresion fiscal en caso de que la operaciĆ³n sea CO (completar)
        // y la factura sea fiscal
        {
            m_invoice.saveEx();
            if (p_docAction.equals(MInvoice.DOCACTION_Complete) && LAR_Utils.isFiscalDocType(m_invoice.getC_DocType_ID())) {
                final InvoiceFiscalDocumentPrintManager manager = new InvoiceFiscalDocumentPrintManager(m_invoice);
                manager.print();
            }
        }
        // @emmie custom
        addLog(m_invoice.getC_Invoice_ID(), m_invoice.getDateInvoiced(), null, m_invoice.getDocumentNo());
        m_created++;
    }
    m_invoice = null;
    m_ship = null;
    m_line = 0;
}
Also used : MOrder(org.compiere.model.MOrder) MCurrency(org.compiere.model.MCurrency) InvoiceFiscalDocumentPrintManager(ar.com.ergio.print.fiscal.view.InvoiceFiscalDocumentPrintManager) MOrderPaySchedule(org.compiere.model.MOrderPaySchedule) MInvoicePaySchedule(org.compiere.model.MInvoicePaySchedule) BigDecimal(java.math.BigDecimal)

Aggregations

InvoiceFiscalDocumentPrintManager (ar.com.ergio.print.fiscal.view.InvoiceFiscalDocumentPrintManager)1 BigDecimal (java.math.BigDecimal)1 MCurrency (org.compiere.model.MCurrency)1 MInvoicePaySchedule (org.compiere.model.MInvoicePaySchedule)1 MOrder (org.compiere.model.MOrder)1 MOrderPaySchedule (org.compiere.model.MOrderPaySchedule)1