use of ar.com.ergio.print.fiscal.view.InvoiceFiscalDocumentPrintManager 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;
}
use of ar.com.ergio.print.fiscal.view.InvoiceFiscalDocumentPrintManager in project lar_361 by comitsrl.
the class InvoiceGenerateRMA method generateInvoice.
private void generateInvoice(int M_RMA_ID) {
MRMA rma = new MRMA(getCtx(), M_RMA_ID, get_TrxName());
MInvoice invoice = createInvoice(rma);
MInvoiceLine[] invoiceLines = createInvoiceLines(rma, invoice);
if (invoiceLines.length == 0) {
log.log(Level.WARNING, "No invoice lines created: M_RMA_ID=" + M_RMA_ID + ", M_Invoice_ID=" + invoice.get_ID());
}
StringBuffer processMsg = new StringBuffer(invoice.getDocumentNo());
if (!invoice.processIt(p_docAction)) {
processMsg.append(" (NOT Processed)");
log.warning("Invoice Processing failed: " + invoice + " - " + invoice.getProcessMsg());
throw new IllegalStateException("Invoice Processing failed: " + invoice + " - " + invoice.getProcessMsg());
}
if (!invoice.save()) {
throw new IllegalStateException("Could not update invoice");
} else // @fchiappano Impresion Fiscal, si se completa la factura.
{
if (p_docAction.equals(MInvoice.DOCACTION_Complete) && LAR_Utils.isFiscalDocType(invoice.getC_DocType_ID())) {
final InvoiceFiscalDocumentPrintManager manager = new InvoiceFiscalDocumentPrintManager(invoice);
manager.print();
}
}
// Add processing information to process log
addLog(invoice.getC_Invoice_ID(), invoice.getDateInvoiced(), null, invoice.getDocumentNo());
m_created++;
}
use of ar.com.ergio.print.fiscal.view.InvoiceFiscalDocumentPrintManager in project lar_361 by comitsrl.
the class OrderFiscalPrinting method doIt.
@Override
protected String doIt() throws Exception {
log.info(String.format("Procesando orden %s", order));
// Determina si la orden es POS o de Nota de Crédito para continuar con el proceso
final MDocType dtTarget = new MDocType(getCtx(), order.getC_DocTypeTarget_ID(), get_TrxName());
if (order.isSOTrx() && (dtTarget.getDocSubTypeSO().equals(MDocType.DOCSUBTYPESO_OnCreditOrder) || dtTarget.getDocSubTypeSO().equals(MDocType.DOCSUBTYPESO_POSOrder))) {
final MInvoice invoice = new MInvoice(getCtx(), order.getC_Invoice_ID(), get_TrxName());
// para imprimirla o no en el controlador fiscal
if (invoice != null && LAR_Utils.isFiscalDocType(invoice.getC_DocType_ID())) {
final InvoiceFiscalDocumentPrintManager manager = new InvoiceFiscalDocumentPrintManager(invoice);
manager.print();
}
}
return m_ResultMsg;
}
use of ar.com.ergio.print.fiscal.view.InvoiceFiscalDocumentPrintManager in project lar_361 by comitsrl.
the class InvoiceFiscalPrinting method doIt.
@Override
protected String doIt() throws Exception {
log.info(String.format("Processing invoice %s", invoice));
// Check if invoice exists and has proper doctype
if (invoice != null && LAR_Utils.isFiscalDocType(invoice.getC_DocType_ID())) {
final InvoiceFiscalDocumentPrintManager manager = new InvoiceFiscalDocumentPrintManager(invoice);
manager.print();
}
return m_ResultMsg;
}
Aggregations