Search in sources :

Example 1 with X_LCO_TaxPayerType

use of org.globalqss.model.X_LCO_TaxPayerType in project lar_361 by comitsrl.

the class WsfeV1 method createInputFile.

/**
 * @author: Horacio Alvarez
 * @descripcion: Crea el archivo de entrada para el WSFE.PY.
 * Setea los valores necesarios con el objeto MInvoice.
 */
@Override
protected void createInputFile() {
    try {
        StringBuffer line = new StringBuffer();
        // *****NRO. COMPROBANTE
        if (this.getInvoice().getNumeroComprobante() == 0) {
            this.setMessageError(Msg.translate(this.getM_ctx(), "CaeNoNumeroComprobante"));
            return;
        }
        line.append(this.getInvoice().getNumeroComprobante() + "\n");
        // *****PUNTO DE VENTA
        final MPOS pos = new MPOS(getM_ctx(), this.getInvoice().get_ValueAsInt("C_Pos_ID"), getTrxName());
        if (pos.get_ValueAsInt("PosNumber") == 0) {
            this.setMessageError(Msg.translate(this.getM_ctx(), "CaeNoPuntoDeVenta"));
            return;
        }
        line.append(pos.get_ValueAsInt("PosNumber") + "\n");
        // *****TIPO DE COMPROBANTE
        MDocType docType = new MDocType(Env.getCtx(), this.getInvoice().getC_DocTypeTarget_ID(), getTrxName());
        line.append(docType.getdocsubtypecae() + "\n");
        // *****TIPO DOC: 80 CUIT / 96 DNI
        MBPartner partner = new MBPartner(this.getM_ctx(), this.getInvoice().getC_BPartner_ID(), getTrxName());
        final X_LCO_TaxPayerType taxPayerType = new X_LCO_TaxPayerType(getM_ctx(), partner.get_ValueAsInt("LCO_TaxPayerType_ID"), getTrxName());
        if (taxPayerType.getName().equals("ConsumidorFinal")) {
            line.append("96" + "\n");
            line.append("1" + "\n");
        } else {
            line.append("80" + "\n");
            if (partner.getTaxID() == null || partner.getTaxID().equals("")) {
                this.setMessageError(Msg.translate(this.getM_ctx(), "CaeNoCUIT"));
                return;
            }
            line.append(partner.getTaxID().replaceAll("-", "") + "\n");
        }
        // *****IMPORTE TOTAL
        // line.append(this.getInvoice().getGrandTotal().toString().replace(".", "")+"\n");
        line.append(this.getInvoice().getGrandTotal().setScale(2, BigDecimal.ROUND_HALF_UP) + "\n");
        // *****IMPORTE NETO
        // line.append(this.getInvoice().getTotalLines().toString().replace(".", "")+"\n");
        line.append(this.getInvoice().getTotalLines().setScale(2, BigDecimal.ROUND_HALF_UP) + "\n");
        // *****FECHA
        if (this.getInvoice().getDateAcct() == null) {
            this.setMessageError(Msg.translate(this.getM_ctx(), "CaeNoDateAcct"));
            return;
        }
        line.append(formatTime(this.getInvoice().getDateAcct(), "yyyyMMdd") + "\n");
        // *****PRESTA SERVICIOS 0-->NO  1-->SI
        line.append(MSysConfig.getValue("LAR_PrestaServicios_FE", Env.getAD_Client_ID(Env.getCtx())) + "\n");
        // *****MONEDA
        MCurrency currency = new MCurrency(this.getM_ctx(), this.getInvoice().getC_Currency_ID(), getTrxName());
        line.append(currency.get_ValueAsString("WSFECode") + "\n");
        // *****CONVERSION
        // Se debe convertir a la moneda del comprobante desde la moneda de la compañía
        BigDecimal cotizacion = MCurrency.currencyConvert(Env.ONE, Env.getContextAsInt(this.getM_ctx(), "$C_Currency_ID"), this.getInvoice().getC_Currency_ID(), this.getInvoice().getDateInvoiced(), 0, this.getM_ctx());
        line.append(cotizacion + "\n");
        // *****IMPUESTO
        BigDecimal total_Impuesto = BigDecimal.ZERO;
        MInvoiceTax[] taxes = this.getInvoice().getTaxes(false);
        MTax tax = null;
        int size = taxes.length;
        boolean firstLineAppended = false;
        for (int i = 0; i < size; i++) {
            tax = MTax.get(this.getM_ctx(), taxes[i].getC_Tax_ID());
            if (!tax.get_ValueAsBoolean("IsPerception")) {
                total_Impuesto = total_Impuesto.add(taxes[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP));
                taxes[i].getTaxAmt();
                taxes[i].getTaxBaseAmt();
                tax.get_ValueAsString("WSFECode");
                if (firstLineAppended) {
                    line.append(";");
                }
                line.append(tax.get_ValueAsString("WSFECode") + ":" + (getTaxBaseAmt(taxes[i].getTaxBaseAmt(), this.getInvoice().getGrandTotal(), getTaxesAmt(this.getInvoice()))).setScale(2, BigDecimal.ROUND_HALF_UP) + ":" + taxes[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP));
                firstLineAppended = true;
            }
        }
        line.append("\n");
        // *****MONTO TOTAL DE IMPUESTOS
        line.append(total_Impuesto + "\n");
        // *****IMPUESTOS PERCEPCIONES
        BigDecimal total_Perception = BigDecimal.ZERO;
        MInvoiceTax[] taxesPerc = this.getInvoice().getTaxes(true);
        MTax taxPerc = null;
        int sizePerc = taxesPerc.length;
        boolean firstLineAppended2 = false;
        for (int i = 0; i < sizePerc; i++) {
            taxPerc = MTax.get(this.getM_ctx(), taxesPerc[i].getC_Tax_ID());
            if (taxPerc.get_ValueAsBoolean("IsPerception")) {
                total_Perception = total_Perception.add(taxesPerc[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP));
                taxesPerc[i].getTaxAmt();
                taxesPerc[i].getTaxBaseAmt();
                taxPerc.get_ValueAsInt("WSFECode");
                if (firstLineAppended2) {
                    line.append(";");
                }
                BigDecimal alic = (taxPerc.getRate().setScale(2, BigDecimal.ROUND_HALF_UP)).negate();
                line.append(taxPerc.get_ValueAsInt("WSFECode") + ":" + (getTaxBaseAmt(taxesPerc[i].getTaxBaseAmt(), this.getInvoice().getGrandTotal(), getTaxesAmt(this.getInvoice()))).setScale(2, BigDecimal.ROUND_HALF_UP) + ":" + taxesPerc[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP) + ":" + alic);
                firstLineAppended2 = true;
            }
        }
        if (total_Perception.equals(Env.ZERO))
            line.append("0");
        line.append("\n");
        // *****MONTO TOTAL DE PERCEPCIONES
        line.append(total_Perception + "\n");
        // *****C_INVOICE_ID para seguimiento
        line.append(this.getInvoice().getC_Invoice_ID() + "\n");
        File textFile = new File(getPath() + "entrada.txt");
        FileWriter textOut;
        textOut = new FileWriter(textFile);
        textOut.write(line.toString());
        textOut.close();
    } catch (Exception ex) {
        this.setMessageError(Msg.translate(this.getM_ctx(), "caeErrorCreateInputFile"));
        log.log(Level.SEVERE, this.getMessageError(), ex);
    }
}
Also used : MDocType(org.compiere.model.MDocType) MPOS(org.compiere.model.MPOS) MCurrency(org.compiere.model.MCurrency) FileWriter(java.io.FileWriter) MBPartner(org.compiere.model.MBPartner) BigDecimal(java.math.BigDecimal) X_LCO_TaxPayerType(org.globalqss.model.X_LCO_TaxPayerType) MTax(org.compiere.model.MTax) MInvoiceTax(org.compiere.model.MInvoiceTax) File(java.io.File)

Example 2 with X_LCO_TaxPayerType

use of org.globalqss.model.X_LCO_TaxPayerType in project lar_361 by comitsrl.

the class LAR_TaxPayerTypeTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    taxPayerType_OK = new X_LCO_TaxPayerType(getCtx(), 0, getTrxName());
    taxPayerType_OK.setName("Exento");
    taxPayerType_OK.save();
    taxPayerType_WRONG = new X_LCO_TaxPayerType(getCtx(), 0, getTrxName());
    taxPayerType_WRONG.setName("TipoErroneo");
    taxPayerType_WRONG.save();
    // Joe Block
    bpartner_OK = new MBPartner(getCtx(), 118, getTrxName());
    bpartner_OK.set_ValueOfColumn("LCO_TaxPayerType_ID", taxPayerType_OK.get_ID());
    // Seed Farm Inc.
    bpartner_WRONG = new MBPartner(getCtx(), 120, getTrxName());
    bpartner_WRONG.set_ValueOfColumn("LCO_TaxPayerType_ID", taxPayerType_WRONG.get_ID());
    commit();
}
Also used : X_LCO_TaxPayerType(org.globalqss.model.X_LCO_TaxPayerType) MBPartner(org.compiere.model.MBPartner)

Aggregations

MBPartner (org.compiere.model.MBPartner)2 X_LCO_TaxPayerType (org.globalqss.model.X_LCO_TaxPayerType)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 BigDecimal (java.math.BigDecimal)1 MCurrency (org.compiere.model.MCurrency)1 MDocType (org.compiere.model.MDocType)1 MInvoiceTax (org.compiere.model.MInvoiceTax)1 MPOS (org.compiere.model.MPOS)1 MTax (org.compiere.model.MTax)1