use of org.globalqss.model.X_LCO_TaxIdType in project lar_361 by comitsrl.
the class ProcesadorCOT method cargarDatosCabecera.
// generarTXT
/**
* Crear el string buffer y cargarlo con todos los datos referidos a la
* cabecera del remito.
*
* @author fchiappano
* @return
*/
private StringBuffer cargarDatosCabecera() {
StringBuffer cabecera = new StringBuffer();
// @fchiappano linea cabecera.
cabecera.append("01" + separador + cuitOrg + finalLinea);
MBPartner cliente = remito.getBPartner();
MWarehouse deposito = new MWarehouse(ctx, remito.getM_Warehouse_ID(), remito.get_TrxName());
// @fchiappano validar que se haya seleccionado un transporte.
int transporte_ID = remito.get_ValueAsInt("M_Shipper_ID");
if (transporte_ID <= 0) {
msgError = "Por favor, ingrese un transportista valido.";
return null;
}
MShipper transporte = new MShipper(ctx, transporte_ID, remito.get_TrxName());
// @fchiappano Validar que el transporte tenga vinculado un Socio del Negocio.
int bpTransporte_ID = transporte.getC_BPartner_ID();
if (bpTransporte_ID <= 0) {
msgError = "El transportista seleccionado, no posee un Socio del Negocio valido asignado.";
return null;
}
MBPartner bpTransporte = new MBPartner(ctx, bpTransporte_ID, remito.get_TrxName());
// @fchiappano linea descripción del remito.
String fechaEmision = getFecha(remito.getMovementDate());
cabecera.append("02" + separador + fechaEmision);
// @fchiappano Codigo unico del documento (DocSubTypeCAE + pdv + documentno).
String codigoUnico = generarCodigoUnicoRemito();
if (codigoUnico == null)
return null;
cabecera.append(separador + codigoUnico);
// @fchiappano Fecha de salida.
cabecera.append(separador + getFecha(remito.getPickDate()));
// @fchiappano Hora de salida
cabecera.append(separador + " ");
// @fchiappano Sujeto Generador (E: Emisor. D: Destinatario).
cabecera.append(separador + sujetoGenerador);
// @fchiappano parametro es consumidor final.
LAR_TaxPayerType taxPayerType = LAR_TaxPayerType.getTaxPayerType(cliente);
boolean esConsumidorFinal = taxPayerType.equals(LAR_TaxPayerType.CONSUMIDOR_FINAL);
cabecera.append(separador + (esConsumidorFinal ? "1" : "0"));
// @fchiappano tipo de documento cliente (DNI, CL,CUIL, etc. No informar si no se trata de un CF)
if (esConsumidorFinal) {
X_LCO_TaxIdType tipoDoc = new X_LCO_TaxIdType(ctx, cliente.get_ValueAsInt("LCO_TaxIDType_ID"), remito.get_TrxName());
cabecera.append(separador + tipoDoc.getName());
} else
cabecera.append(separador + " ");
// @fchiappano nro de documento del cliente (CF).
String cuit_cliente = cliente.getTaxID();
if (cuit_cliente == null) {
msgError = "El cliente no posee un número de identificación valido";
return null;
}
cabecera.append(separador + (esConsumidorFinal ? cuit_cliente.replaceAll("-", "") : " "));
// @fchiappano numero de cuit del cliente (si no es CF)
cabecera.append(separador + (!esConsumidorFinal ? cuit_cliente.replaceAll("-", "") : " "));
// @fchiappano Razon social del cliente.
String razonSocial = cliente.getName();
cabecera.append(separador + (razonSocial.length() > 50 ? razonSocial.substring(0, 49) : razonSocial));
// @fchiappano Destinatario Tenedor (depende de la condición de IVA del cliente)
cabecera.append(separador + (esConsumidorFinal ? "0" : "1"));
// @fchiappano Datos de la direccion destino.
MLocation direccion;
if (remito.get_ValueAsBoolean("EntregaTransporte"))
direccion = (MLocation) new MBPartnerLocation(ctx, remito.get_ValueAsInt("Shipper_Location_ID"), remito.get_TrxName()).getC_Location();
else
direccion = (MLocation) remito.getC_BPartner_Location().getC_Location();
String calle = direccion.getAddress1();
if (calle != null && !calle.equals(""))
cabecera.append(separador + (calle.length() > 40 ? calle.substring(0, 39) : calle));
else
cabecera.append(separador + "");
// Numero
cabecera.append(separador + nroDirec);
// Destino_Domicilio_Comple
cabecera.append(separador + direc_completa);
// Piso
cabecera.append(separador + " ");
// Departamento
cabecera.append(separador + " ");
// Barrio
cabecera.append(separador + " ");
// Codigo Postal
cabecera.append(separador + direccion.getPostal());
// Ciudad
String ciudad = direccion.getCity();
if (ciudad != null && !ciudad.equals(""))
cabecera.append(separador + (ciudad.length() > 50 ? ciudad.substring(0, 49) : ciudad));
else
cabecera.append(separador + " ");
// Codigo Provincia
cabecera.append(separador + ((MRegion) direccion.getC_Region()).get_ValueAsString("CodigoCOT"));
// PROPIO_DESTINO_DOMICILIO_CODIGO
cabecera.append(separador + " ");
// @fchiappano Entrega domicilio Origen.
cabecera.append(separador + "NO");
// @fchiappano cuit origen (Si Sujeto_Generador = E, entonces debe ir el
// CUIT de la org. Sino, CUIT del SdN).
cabecera.append(separador + cuitOrg);
// @fchiappano Razon social del emisor
razonSocial = MClient.get(ctx).getName();
cabecera.append(separador + (razonSocial.length() > 50 ? razonSocial.substring(0, 49) : razonSocial));
// @fachiappano Emisor Tenedor.
cabecera.append(separador + "1");
// @mzuniga Datos de dirección origen.
// Se recupera la diracción del depósito
// Calle
MLocation direcOrigen = (MLocation) deposito.getC_Location();
if (calle != null && !calle.equals(""))
cabecera.append(separador + (calle.length() > 40 ? calle.substring(0, 39) : calle));
else
cabecera.append(separador + " ");
// Numero
cabecera.append(separador + nroDirec);
// ORIGEN_DOMICILIO_COMPLE
cabecera.append(separador + direc_completa);
// Piso
cabecera.append(separador + " ");
// Departamento
cabecera.append(separador + " ");
// Barrio
cabecera.append(separador + " ");
// Codigo postal
cabecera.append(separador + direcOrigen.getPostal());
// Localidad
ciudad = direcOrigen.getCity();
if (ciudad != null && !ciudad.equals(""))
cabecera.append(separador + (ciudad.length() > 50 ? ciudad.substring(0, 49) : ciudad));
else
cabecera.append(separador + " ");
// Cod Provincia
cabecera.append(separador + ((MRegion) direcOrigen.getC_Region()).get_ValueAsString("CodigoCOT"));
// @fchiappano Cuit del transportista.
String cuit_transporte = bpTransporte.getTaxID();
if (cuit_transporte == null) {
msgError = "El trasnportista seleccionado, no posee un número de identificación valido";
return null;
}
cabecera.append(separador + cuit_transporte.replaceAll("-", ""));
// @fchiappano Tipo Recorrido (‘U’, ‘R’, ‘M’ o ‘ ’).
cabecera.append(separador + " ");
// @fchiappano Localidad del Recorrido.
cabecera.append(separador + " ");
// @fchiappano Calle del Recorrido.
cabecera.append(separador + " ");
// @fchiappano Ruta del Recorrido.
cabecera.append(separador + " ");
// @fchiappano Patente del vehiculo.
String patente = (String) remito.get_Value("Patente");
if (patente == null)
patente = "";
cabecera.append(separador + patente.replaceAll("\\s", ""));
// @fchiappano Patente del Acoplado del vehiculo.
String patenteAcop = (String) remito.get_Value("Patente");
if (patenteAcop == null)
patenteAcop = "";
cabecera.append(separador + patenteAcop.replaceAll("\\s", ""));
// @fchiappano Es devolucion
cabecera.append(separador + esDevolucion);
// @rchiappano Importe total remito (descontando impuestos = neto)
cabecera.append(separador + formatearBigDecimal(remito.getC_Order().getTotalLines()));
// @fchiappano Agregar final de Linea.
cabecera.append(finalLinea);
return cabecera;
}
use of org.globalqss.model.X_LCO_TaxIdType 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());
// @fchiappano Recuperar el tipo de identificación, desde el Socio del Negocio.
final X_LCO_TaxIdType tipoIdentificacion = new X_LCO_TaxIdType(getM_ctx(), partner.get_ValueAsInt("LCO_TaxIdType_ID"), getTrxName());
line.append(tipoIdentificacion.getLCO_TaxCodeDian() + "\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;
if (currency.getC_Currency_ID() != LAR_Utils.getMonedaPredeterminada(getM_ctx(), getInvoice().getAD_Client_ID(), getTrxName()))
cotizacion = (BigDecimal) getInvoice().get_Value("TasaDeCambio");
else
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");
// @fchiappano Agregar Fecha de Vencimiento de Pago.
Timestamp fechaPago = (Timestamp) this.getInvoice().get_Value("FechaPago");
if (fechaPago != null)
line.append(formatTime(fechaPago, "yyyyMMdd") + "\n");
else
line.append(formatTime(new Timestamp(System.currentTimeMillis()), "yyyyMMdd") + "\n");
// @fchiappano Agregar datos opcionales (CBU y Alias).
int c_BankAccount_ID = MOrgInfo.get(this.getM_ctx(), this.getInvoice().getAD_Org_ID()).get_ValueAsInt("C_BankAccount_ID");
MBankAccount cuentaBancaria = new MBankAccount(getM_ctx(), c_BankAccount_ID, getTrxName());
// ****** CBU
line.append(cuentaBancaria.get_Value("CBU") + "\n");
// ****** ALIAS
line.append(cuentaBancaria.get_Value("Alias") + "\n");
// @fchiappano se agregan datos para NC y ND (FCE).
if (getInvoice().get_ValueAsInt("Source_Invoice_ID") > 0) {
MInvoice facturaOrigen = new MInvoice(getM_ctx(), getInvoice().get_ValueAsInt("Source_Invoice_ID"), getTrxName());
// ****** Tipo de Doc. Factura Origen.
MDocType tipoDoc = (MDocType) facturaOrigen.getC_DocTypeTarget();
line.append(tipoDoc.getdocsubtypecae() + "\n");
// ****** Punto de Venta Factura Origen.
MPOS pdv = new MPOS(getM_ctx(), facturaOrigen.get_ValueAsInt("C_Pos_ID"), getTrxName());
line.append(pdv.get_ValueAsInt("PosNumber") + "\n");
// ****** Nro. Doc. Factura Origen.
line.append(facturaOrigen.getNumeroComprobante() + "\n");
// ****** Fecha Facturación Factura Origen
Date fecha = new Date(facturaOrigen.getDateInvoiced().getTime());
line.append(fecha.toString().replace("-", "") + "\n");
// ****** Codigo de Cancelación
boolean cancelado = getInvoice().get_ValueAsBoolean("Cancelacion");
if (cancelado)
line.append("S" + "\n");
else
line.append("N" + "\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);
}
}
use of org.globalqss.model.X_LCO_TaxIdType in project lar_361 by comitsrl.
the class LAR_Validator method modelChange.
// initialize
/**
* Model Change of a monitored Table. Called after
* PO.beforeSave/PO.beforeDelete when you called addModelChange for the
* table
*
* @param po
* persistent object
* @param type
* TYPE_
* @return error message or null
* @exception Exception
* if the recipient wishes the change to be not accept.
*/
public String modelChange(final PO po, int type) throws Exception {
log.info(po.get_TableName() + " Type: " + type);
String msg;
// Changes on BPartners
if (po.get_TableName().equals(MBPartner.Table_Name) && (type == TYPE_BEFORE_CHANGE || type == TYPE_BEFORE_NEW)) {
MBPartner bp = (MBPartner) po;
// @fchiappano Validar según el tipo de identificación y no según
// la condicion de iva del sdn.
int lco_TaxIDType_ID = bp.get_ValueAsInt("LCO_TaxIDType_ID");
if (lco_TaxIDType_ID <= 0)
return "ERROR: En neceserario especificar un tipo de identificación valido.";
String tipoIdentificacion = new X_LCO_TaxIdType(Env.getCtx(), lco_TaxIDType_ID, bp.get_TrxName()).getName().toUpperCase();
if (MSysConfig.getBooleanValue("LAR_ValidarCuitSdN", true, Env.getAD_Client_ID(Env.getCtx()))) {
if (tipoIdentificacion.equals("CUIT") || tipoIdentificacion.equals("CUIL")) {
// Check CUIT number
String cuit = bp.get_ValueAsString("TaxID");
if (!LAR_Utils.validateCUIT(cuit)) {
return "ERROR: CUIT/CUIL invalido";
}
} else // @fchiappano Validar largo del DNI.
if (tipoIdentificacion.equals("DNI")) {
String dni = bp.get_ValueAsString("TaxID");
if (dni != null && !dni.equals("")) {
int cantCaracteres = dni.length();
if (cantCaracteres < 7 || cantCaracteres > 8)
return "ERROR: Cantidad de caracteres invalida para tipo de identificación DNI.";
}
}
}
String checkDuplicidad = MSysConfig.getValue("LAR_PermitirDuplicidadCuit/Dni", "N", Env.getAD_Client_ID(Env.getCtx()));
if ((checkDuplicidad.equals("N") || (checkDuplicidad.equals("A") && type == TYPE_BEFORE_NEW)) && LAR_Utils.checkDuplicateCUIT(bp.getTaxID(), bp.getC_BPartner_ID()))
return "ERROR: CUIT/DNI Duplicado";
}
// Changes on OrderLines
if (po.get_TableName().equals(MOrderLine.Table_Name) && (type == TYPE_AFTER_NEW || type == TYPE_AFTER_DELETE || type == TYPE_AFTER_CHANGE)) {
MOrderLine ol = (MOrderLine) po;
int c_BPartner_ID = ol.getC_BPartner_ID();
MBPartner bp = new MBPartner(ol.getCtx(), c_BPartner_ID, ol.get_TrxName());
msg = LAR_CalcularPercepcion.calculateWhithholdingLine(bp, ol, type);
if (msg != null) {
return msg;
}
}
// Changes on Order
if (po.get_TableName().equals(MOrder.Table_Name) && type == TYPE_BEFORE_DELETE) {
MOrder order = (MOrder) po;
msg = LAR_CalcularPercepcion.deleteWhithholdingLine(order);
if (msg != null) {
return msg;
}
}
// con el asignado en su orden de remito origen
if (po.get_TableName().equals(MInOut.Table_Name) && type == TYPE_BEFORE_NEW) {
msg = changeShipmentDocumentNo((MInOut) po);
if (msg != null)
return msg;
}
// Elimina la retención sobre los pagos cuando se modifica el header
if (po.get_TableName().equals(MLARPaymentHeader.Table_Name) && type == TYPE_AFTER_CHANGE) {
msg = clearPaymentWithholdingFromHeader((MLARPaymentHeader) po);
if (msg != null) {
return msg;
}
}
// Determine letter for sales invoices (from PosOrders)
if (po.get_TableName().equals(MInvoice.Table_Name) && type == TYPE_AFTER_NEW) {
MInvoice invoice = (MInvoice) po;
msg = changeDocTypeForInvoice(invoice);
if (msg != null) {
return msg;
}
}
// Despues de modificar un pago, se actualiza la retención y el total de al cabecera
if (po.get_TableName().equals(MPayment.Table_Name) && (type == TYPE_AFTER_NEW || type == TYPE_AFTER_CHANGE || type == TYPE_AFTER_DELETE)) {
msg = clearPaymentWithholdingFromPayments((MPayment) po, type);
if (msg != null)
return msg;
msg = updatePaymentHeaderTotalAmt((MPayment) po, type);
if (msg != null)
return msg;
}
// Despues de modificar/agregar una factura se actualiza la retención y el total de la cabecera
if (po.get_TableName().equals(MPaymentAllocate.Table_Name) && (type == TYPE_AFTER_NEW || type == TYPE_AFTER_CHANGE || type == TYPE_AFTER_DELETE)) {
msg = clearPaymentWithholdingFromPaymentAllocate((MPaymentAllocate) po, type);
if (msg != null)
return msg;
}
// {
if (po.get_TableName().equals(MPayment.Table_Name) && (type == ModelValidator.TYPE_BEFORE_NEW || type == ModelValidator.TYPE_BEFORE_CHANGE)) {
MPayment pay = (MPayment) po;
Integer source = (Integer) pay.get_Value("LAR_PaymentSource_ID");
if ((source == null) || (source <= 0))
return null;
msg = setReconciled(source, "N", pay.get_TrxName());
if (msg != null)
return msg;
// Marcos Zúñiga -Excludes payment source from drawer (when is not reversal payment)
if (pay.getReversal_ID() == 0) {
msg = setIsOnDrawer(source, "N", pay.get_TrxName());
if (msg != null)
return msg;
}
/* @fchiappano Se comenta codigo, ya que se define si debe quedar conciliado el pago/cobro,
en cada uno de los procesos que intervienen en la funcionalidad de cajas.
msg=setReconciled(pay.getC_Payment_ID(),"N", pay.get_TrxName());
if(msg!=null)
return msg;
*/
}
if (po.get_TableName().equals(MPayment.Table_Name) && (type == ModelValidator.TYPE_BEFORE_DELETE)) {
MPayment pay = (MPayment) po;
Integer source = (Integer) pay.get_Value("LAR_PaymentSource_ID");
if ((source == null) || (source <= 0))
return null;
msg = setReconciled(source, "N", pay.get_TrxName());
if (msg != null)
return msg;
// Marcos Zúñiga
msg = setIsOnDrawer(source, "Y", pay.get_TrxName());
if (msg != null)
return msg;
}
return null;
}
use of org.globalqss.model.X_LCO_TaxIdType in project lar_361 by comitsrl.
the class ProcesadorWSFE method getFECAEDetRequest.
// ProcesadorWSFE
/**
* Crear Detalle del Documento.
* @author fchiappano
*/
private FECAEDetRequest getFECAEDetRequest(final int nroComprobante) {
// @fchiappano Agregar impuesto y tributos.
MInvoiceTax[] taxes = factura.getTaxes(true);
MTax tax = null;
BigDecimal total_Tributos = BigDecimal.ZERO;
BigDecimal total_Impuesto = BigDecimal.ZERO;
for (int i = 0; i < taxes.length; i++) {
tax = MTax.get(ctx, taxes[i].getC_Tax_ID());
// @fchiappano Tributo.
if (tax.get_ValueAsBoolean("IsPerception") || tax.get_ValueAsBoolean("EsImpuestoInterno")) {
total_Tributos = total_Tributos.add(taxes[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP));
MTax taxPerc = MTax.get(ctx, taxes[i].getC_Tax_ID());
double alic = (taxPerc.getRate().negate().doubleValue());
Tributo tributo = new Tributo(Short.parseShort(tax.get_ValueAsString("WSFECode")), tax.getTaxIndicator(), taxes[i].getTaxBaseAmt().setScale(2, RoundingMode.HALF_UP).doubleValue(), alic, taxes[i].getTaxAmt().setScale(2, RoundingMode.HALF_UP).doubleValue());
tributos.add(tributo);
} else // @fchiappano Impuesto.
{
total_Impuesto = total_Impuesto.add(taxes[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP));
AlicIva impuesto = new AlicIva(tax.get_ValueAsInt("WSFECode"), taxes[i].getTaxBaseAmt().setScale(2, RoundingMode.HALF_UP).doubleValue(), taxes[i].getTaxAmt().setScale(2, RoundingMode.HALF_UP).doubleValue());
impuestos.add(impuesto);
}
}
int tipoDoc = 0;
long nroDoc = 0;
MBPartner cliente = (MBPartner) factura.getC_BPartner();
// @fchiappano Recuperar el tipo de identificación, desde el Socio del
// Negocio.
final X_LCO_TaxIdType tipoIdentificacion = new X_LCO_TaxIdType(ctx, cliente.get_ValueAsInt("LCO_TaxIdType_ID"), factura.get_TrxName());
String tipoDoc_Str = tipoIdentificacion.getLCO_TaxCodeDian();
if (tipoDoc_Str == null || tipoDoc_Str.equals("")) {
msgError = "El tipo de identifiación del cliente, no posee un codigo asociado valido.";
return null;
}
tipoDoc = Integer.parseInt(tipoDoc_Str);
if (cliente.getTaxID() == null || cliente.getTaxID().equals("")) {
msgError = Msg.translate(ctx, "CaeNoCUIT");
return null;
}
nroDoc = Long.parseLong(cliente.getTaxID().replaceAll("-", "").replaceAll(" ", ""));
int tipoCbte = getDocSubTypeCAE(factura);
String fechaVecPago = getFecha((Timestamp) factura.get_Value("FechaPago"));
// @fchiappano Si el tipo de doc es NC o ND, no informar fecha de pago y agregar comprobante asociado.
if (// @fchiappano Notas de Creditoo
factura.getC_DocTypeTarget().getDocBaseType().equals(MDocType.DOCBASETYPE_ARCreditMemo) || tipoCbte == 2 || tipoCbte == 7 || tipoCbte == 52 || tipoCbte == 202 || tipoCbte == 207 || // @fchiappano Tipos de Nota de Debito
tipoCbte == 212) {
if (!agregarDocAsociado(tipoCbte))
return null;
}
// @fchiappano Si es FCE, agregar CBU y OpcionTransferenciaFCE.
if (tipoCbte == 201 || tipoCbte == 206 || tipoCbte == 211) {
agregarCBU();
Opcional opcional = new Opcional("27", factura.get_ValueAsString("OpcionTransferenciaFCE"));
opcionales.add(opcional);
}
String fechaComprobante = formatTime(factura.getDateInvoiced(), "yyyyMMdd");
String fechaActual = formatTime(new Timestamp(System.currentTimeMillis()), "yyyyMMdd");
// @fchiappano Si el concepto es 1, no es necesario informar fecha de servicio.
int concepto = ProcesadorWSAA.getConcepto();
if (concepto == 1) {
fechaActual = "";
// @fchiappano Si ademas no se trata de una factura MiPyme, no informar fecha de pago.
if (tipoCbte != 201 && tipoCbte != 206 && tipoCbte != 211)
fechaVecPago = "";
} else // @fchiappano si el concepto es 2 o 3, en el unico caso que no se debe infomar fecha de pago, es en ND y NC MiPyme.
if (// @fchiappano ND MiPyme
tipoCbte == 202 || tipoCbte == 207 || tipoCbte == 212 || tipoCbte == 203 || tipoCbte == 208 || // @fchiappano NC MiPyme
tipoCbte == 213)
fechaVecPago = "";
// @fchiappano Convertir las listas en arreglos.
convertirArray();
// @fchiappano Creo el archivo xml Request.
FECAEDetRequest detRequest = new FECAEDetRequest(concepto, tipoDoc, nroDoc, nroComprobante + 1, nroComprobante + 1, fechaComprobante, factura.getGrandTotal().setScale(2, RoundingMode.HALF_UP).doubleValue(), Env.ZERO.doubleValue(), factura.getTotalLines().setScale(2, RoundingMode.HALF_UP).doubleValue(), Env.ZERO.doubleValue(), total_Tributos.setScale(2, RoundingMode.HALF_UP).doubleValue(), total_Impuesto.setScale(2, RoundingMode.HALF_UP).doubleValue(), fechaActual, fechaActual, fechaVecPago, getCodMoneda(), getCotizacion(), array_asoc, array_trib, array_imp, array_opc);
return detRequest;
}
Aggregations