Search in sources :

Example 91 with MInvoice

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

the class FiscalDocumentPrint method saveDocumentData.

/**
 * Devuelve la descripción a imprimir para un pago según un MInvoice.
 */
// private String getInvoicePaymentDescription(MInvoice mInvoice) {
// String description = null;
// // - Nota de Crédito: NC NroNotaCrédito
// //   Ej: NC A000100004567
// if (LAR_MDocType.DOCBASETYPE_ARCreditMemo.equals(MDocType.get(ctx,
// mInvoice.getC_DocType_ID()).getDocBaseType())) {
// description = Msg.translate(ctx, "FiscalTicketCreditNotePayment")
// + " " + mInvoice.getDocumentNo();
// // - Resto de facturas (FP, Retenciones, etc): se toman como "Otros Pagos"
// } else {
// description = Msg.translate(ctx, "FiscalTicketOthersPayment");
// }
// 
// return description;
// }
private void saveDocumentData(final MInvoice mInvoice, final Document printeableDocument) {
    String dtType = printeableDocument.getDocumentType();
    // Solo para facturas, notas de crédito y débito.
    if (dtType.equals(Document.DT_INVOICE) || dtType.equals(Document.DT_CREDIT_NOTE) || dtType.equals(Document.DT_DEBIT_NOTE)) {
        // TODO - Review receipt fiscal number implementation
        // int receiptNo =
        // Integer.parseInt(printeableDocument.getDocumentNo());
        String printedFiscalReceiptNumber = printeableDocument.getDocumentNo();
        // Solo se actualiza el documento de oxp en caso de que el
        // número de comprobante emitido por la impresora fiscal
        // sead distinto al que le había asignado oxp.
        String fiscalReceiptNumber = mInvoice.get_ValueAsString("FiscalReceiptNumber");
        if (printedFiscalReceiptNumber != fiscalReceiptNumber) {
            mInvoice.set_ValueOfColumn("FiscalReceiptNumber", printedFiscalReceiptNumber);
        // Se modifica el número de documento de OXP acorde al número de
        // comprobante fiscal.
        // String documentNo = CalloutInvoiceExt.GenerarNumeroDeDocumento(
        // oxpDocument.getPuntoDeVenta(), receiptNo, oxpDocument.getLetra(), oxpDocument.isSOTrx());
        // oxpDocument.setDocumentNo(documentNo);
        }
        // la impresora haya seteado alguno.
        if (dtType.equals(Document.DT_INVOICE) || dtType.equals(Document.DT_DEBIT_NOTE)) {
            Invoice invoiceOrDN = (Invoice) printeableDocument;
            if (invoiceOrDN.hasCAINumber()) {
                // Se asigna el número del CAI.
                mInvoice.set_ValueOfColumn("CAI", invoiceOrDN.getCAINumber());
                // Se asigna la fecha del CAI como la fecha actual.
                mInvoice.set_ValueOfColumn("CAIDate", new Timestamp(System.currentTimeMillis()));
            }
        }
        // ///////////////////////////////////////////////////////////////
        // -- Documento Impreso por Impresora fiscal --
        // Se marca el documento como impreso fiscalmente para que no pueda
        // volver a imprimirse.
        mInvoice.set_ValueOfColumn("IsFiscalPrinted", true);
        // Se guardan los cambios realizados.
        if (canSaveDocument()) {
            mInvoice.save();
        }
    }
}
Also used : Invoice(ar.com.ergio.print.fiscal.document.Invoice) MInvoice(org.compiere.model.MInvoice) Timestamp(java.sql.Timestamp)

Example 92 with MInvoice

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

the class FiscalDocumentPrint method getCustomer.

/**
 * Crea un <code>Customer</code> a partir de una entidad comercial.
 * @param bPartnerID ID de la entidad comercial.
 * @return el cliente correspondiente.
 */
public Customer getCustomer(int bPartnerID) {
    // TODO - Review this implementation
    MBPartner bPartner = new MBPartner(Env.getCtx(), bPartnerID, getTrxName());
    Customer customer = new Customer();
    if (bPartner != null) {
        // Se asigna la categoría de iva del cliente.
        LAR_TaxPayerType taxPayerType = LAR_TaxPayerType.getTaxPayerType(bPartner);
        customer.setIvaResponsibility(traduceTaxPayerType(taxPayerType.getName()));
        // TODO - Parametrize this method
        MInvoice mInvoice = (MInvoice) getOxpDocument();
        // Se asigna el nombre del cliente a partir del BPartner.
        customer.setName(bPartner.getName());
        // Se asigna el domicilio.
        MLocation location = MLocation.getBPLocation(Env.getCtx(), mInvoice.getC_BPartner_Location_ID(), getTrxName());
        customer.setLocation(location.toString());
        // Bpartner.
        if (bPartner.getTaxID() != null && !bPartner.getTaxID().trim().equals("")) {
            customer.setIdentificationType(Customer.CUIT);
            customer.setIdentificationNumber(bPartner.getTaxID());
        }
    }
    return customer;
}
Also used : Customer(ar.com.ergio.print.fiscal.document.Customer) MInvoice(org.compiere.model.MInvoice) MBPartner(org.compiere.model.MBPartner) LAR_TaxPayerType(ar.com.ergio.model.LAR_TaxPayerType) MLocation(org.compiere.model.MLocation)

Example 93 with MInvoice

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

the class FiscalDocumentPrint method createCreditNote.

/**
 * Crea una nota de crédito imprimible por un controlador fiscal a partir de
 * una factura oxp parámetro. La factura original parámetro permite obtener
 * el nro de factura original.
 *
 * @param mInvoice
 *            factura oxp
 * @param originalInvoice
 *            factura original, si es null y la factura oxp parámetro
 *            contiene seteado una factura original dentro del campo
 *            C_Invoice_Orig_ID se busca desde la BD.
 * @return nota de crédito imprimible por un controlador fiscal
 */
public CreditNote createCreditNote(final MInvoice mInvoice, final MInvoice originalInvoice) {
    CreditNote creditNote = new CreditNote();
    // Se asigna el cliente.
    creditNote.setCustomer(getCustomer(mInvoice.getC_BPartner_ID()));
    // Se asigna la letra de la nota de crédito.
    creditNote.setLetter(LAR_Utils.getLetter(mInvoice));
    // Se asigna el número de factura original.
    String origInvoiceNumber = null;
    MInvoice mOriginalInvoice = originalInvoice;
    // una factura original seteada entonces la busco
    if (mOriginalInvoice == null && mInvoice.get_ValueAsInt("Source_Invoice_ID") != 0) {
        mOriginalInvoice = new MInvoice(ctx, mInvoice.get_ValueAsInt("Source_Invoice_ID"), getTrxName());
    }
    // original
    if (mOriginalInvoice != null) {
        origInvoiceNumber = mOriginalInvoice.getDocumentNo();
        // el documentNo como número de factura original.
        if (origInvoiceNumber.length() == 13) {
            // El formato es: PPPP-NNNNNNNN, Ej: 0001-00000023
            origInvoiceNumber = origInvoiceNumber.substring(1, 5) + "-" + origInvoiceNumber.substring(5, 13);
        }
    }
    creditNote.setOriginalDocumentNo(origInvoiceNumber);
    // Se agregan las líneas de la nota de crédito al documento.
    loadDocumentLines(mInvoice, creditNote);
    return creditNote;
}
Also used : CreditNote(ar.com.ergio.print.fiscal.document.CreditNote) MInvoice(org.compiere.model.MInvoice)

Example 94 with MInvoice

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

the class LAR_Callouts method copiaLineasDesdeFacturaOrigen.

// copyLines
/**
 * Callout usado en la columna Source_Invoice_ID (tabla C_Order)
 * Copia las líneas desde la factura origen
 * Funcionalidad específica para órdenes de Nota de Crédito
 */
public String copiaLineasDesdeFacturaOrigen(final Properties ctx, final int windowNo, final GridTab mTab, final GridField mField, Object value) throws AdempiereSystemError {
    Integer Source_Invoice_ID = (Integer) value;
    if (Source_Invoice_ID == null || Source_Invoice_ID.intValue() == 0)
        return "";
    if (!ADialog.ask(windowNo, Env.getWindow(windowNo), "¿Copiar las líneas desde la Factura?"))
        return "";
    if (!mTab.dataSave(false)) {
        mTab.setValue("Source_Invoice_ID", null);
        return "";
    }
    MInvoice factura = new MInvoice(ctx, Source_Invoice_ID, null);
    mTab.dataRefreshAll();
    Integer order_ID = (Integer) mTab.getValue("C_Order_ID");
    MOrder orden = new MOrder(ctx, order_ID, null);
    mTab.dataSave(false);
    this.copiarLineasDesdeFactura(factura, orden, false);
    mTab.dataRefreshAll();
    return "";
}
Also used : MOrder(org.compiere.model.MOrder) MInvoice(org.compiere.model.MInvoice)

Example 95 with MInvoice

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

the class LCO_Validator method clearInvoiceWithholdingAmtFromInvoiceLine.

private String clearInvoiceWithholdingAmtFromInvoiceLine(MInvoiceLine invline, int type) {
    if (type == ModelValidator.TYPE_BEFORE_NEW || type == ModelValidator.TYPE_BEFORE_DELETE || (type == ModelValidator.TYPE_BEFORE_CHANGE && (invline.is_ValueChanged("LineNetAmt") || invline.is_ValueChanged("M_Product_ID") || invline.is_ValueChanged("C_Charge_ID") || invline.is_ValueChanged("IsActive") || invline.is_ValueChanged("C_Tax_ID")))) {
        // Clear invoice withholding amount
        MInvoice inv = invline.getParent();
        boolean thereAreCalc;
        try {
            thereAreCalc = thereAreCalc(inv);
        } catch (SQLException e) {
            log.log(Level.SEVERE, "Error looking for calc on invoice rules", e);
            return "Error looking for calc on invoice rules";
        }
        BigDecimal curWithholdingAmt = (BigDecimal) inv.get_Value("WithholdingAmt");
        if (thereAreCalc) {
            if (curWithholdingAmt != null) {
                if (!LCO_MInvoice.setWithholdingAmtWithoutLogging(inv, null))
                    return "Error saving C_Invoice clearInvoiceWithholdingAmtFromInvoiceLine";
            }
        } else {
            if (curWithholdingAmt == null) {
                if (!LCO_MInvoice.setWithholdingAmtWithoutLogging(inv, Env.ZERO))
                    return "Error saving C_Invoice clearInvoiceWithholdingAmtFromInvoiceLine";
            }
        }
    }
    return null;
}
Also used : SQLException(java.sql.SQLException) MInvoice(org.compiere.model.MInvoice) BigDecimal(java.math.BigDecimal)

Aggregations

MInvoice (org.compiere.model.MInvoice)98 BigDecimal (java.math.BigDecimal)29 MInvoiceLine (org.compiere.model.MInvoiceLine)27 MPayment (org.compiere.model.MPayment)16 MBPartner (org.compiere.model.MBPartner)15 MOrder (org.compiere.model.MOrder)15 MInOut (org.compiere.model.MInOut)14 ResultSet (java.sql.ResultSet)13 PreparedStatement (java.sql.PreparedStatement)12 Timestamp (java.sql.Timestamp)11 MDocType (org.compiere.model.MDocType)9 MInOutLine (org.compiere.model.MInOutLine)8 MOrderLine (org.compiere.model.MOrderLine)7 SQLException (java.sql.SQLException)6 ArrayList (java.util.ArrayList)6 AdempiereException (org.adempiere.exceptions.AdempiereException)5 MClient (org.compiere.model.MClient)5 MLocation (org.compiere.model.MLocation)5 KeyNamePair (org.compiere.util.KeyNamePair)5 ValueNamePair (org.compiere.util.ValueNamePair)5