CONCAT_WS ('', ' 0) AND (tbfacturas.tipo_cfdi IN (1, 4))), CONCAT(' Descuento=\"', tbfacturas.descuento, '\"'), ''), ' Moneda=\"', IF(tbfacturas.tipo_cfdi IN (1, 3, 4), (SELECT tbmonedas.indicativo_letra FROM tbmonedas WHERE tbmonedas.id = tbfacturas.moneda_cliente), 'XXX'), '\"', IF(tbfacturas.tipo_cfdi IN (1, 3, 4), CONCAT(' TipoCambio=\"', IF(tbfacturas.tipo_cambio = 1.00, 1, tbfacturas.tipo_cambio), '\"'), ''), ' Total=\"', IF(tbfacturas.tipo_cfdi IN (1, 3, 4), tbfacturas.total, '0'), '\" TipoDeComprobante=\"', IF(tbfacturas.tipo_cfdi IN (1, 4), 'I', IF(tbfacturas.tipo_cfdi = 2, 'P', 'E')), '\"', IF(tbfacturas.tipo_cfdi IN (1, 3, 4), CONCAT(' MetodoPago=\"', (SELECT tbformaspagofacturas.codigo_sat FROM tbformaspagofacturas WHERE tbformaspagofacturas.id = tbfacturas.forma_pago), '\"'), ''), ' LugarExpedicion=\"', (SELECT tbempresa.fiscal_cp FROM tbempresa WHERE tbempresa.id = 1), '\"', IF((tbfacturas.confirmacion IS NOT NULL AND tbfacturas.confirmacion <> ''), CONCAT(' Confirmacion=\"', tbfacturas.confirmacion, '\"'), ''),'>', IF((tbfacturas.cfdi_relacionado IS NOT NULL AND tbfacturas.cfdi_relacionado <> ''), CONCAT(''), ''), ' 1, CONCAT(' ResidenciaFiscal=\"', (SELECT tbpaises.codigo_sat FROM tbpaises WHERE tbpaises.id = tbfacturas.fiscal_pais_cliente), '\"'), ''), IF(tbfacturas.fiscal_pais_cliente <> 1, CONCAT(' NumRegIdTrib=\"', (SELECT tbclientes.tax_id FROM tbclientes WHERE tbclientes.id = tbfacturas.id_cliente), '\"'), ''), ' UsoCFDI=\"', tbfacturas.uso_cfdi, '\"/>', IF(tbfacturas.tipo_cfdi IN (1, 3, 4), '[TextoRenglones]', CONCAT('')), '', IF (((tbfacturas.iva <> 0) AND (tbfacturas.tipo_cfdi <> 2)), CONCAT(''), ''), '[Pagos][ComercioExterior]') AS Documento
tbfacturas_renglones.id_factura, GROUP_CONCAT(' 0, CONCAT_WS('', '>'), ' />') SEPARATOR '') AS Detalle
CONCAT_WS('', ' ''), CONCAT(' MotivoTraslado="', tbfacturas.motivo_traslado, '" '), ''), 'TipoOperacion=\"2\" ClaveDePedimento=\"A1\" CertificadoOrigen=\"', IF((SELECT tbempresa.certificado_origen FROM tbempresa WHERE tbempresa.id = 1) = '', '0', '1'), '\" ', IF((SELECT tbempresa.certificado_origen FROM tbempresa WHERE tbempresa.id = 1) = '', CONCAT('NumCertificadoOrigen=\"', (SELECT tbempresa.certificado_origen FROM tbempresa WHERE tbempresa.id = 1), '\" '), ''), IF((SELECT tbempresa.num_exportador FROM tbempresa WHERE tbempresa.id = 1) = '', '', CONCAT('NumeroExportadorConfiable=\"', (SELECT tbempresa.num_exportador FROM tbempresa WHERE tbempresa.id = 1), '\" ')), 'Incoterm=\"', tbfacturas.id_incoterm, '\" Subdivision=\"0\" ', IF(tbfacturas.datosextras = '', '', CONCAT('Observaciones=\"', tbfacturas.datosextras, '\" ')), 'TipoCambioUSD=\"', tbfacturas.tipo_cambio,'\" TotalUSD=\"', tbfacturas.total, '\">[RenglonesComExt]') AS ComplementoComercioExterior
tbfacturas_renglones.id_factura, GROUP_CONCAT('' SEPARATOR '') AS RenglonesComExt
CONCAT_WS('', ' 1, CONCAT_WS('', ' TipoCambioP=\"', tbfacturas.tipo_cambio, '\"'), ''), ' Monto=\"', tbfacturas.total, '\"', IF(tbfacturas.metodo_pago <> '01', CONCAT(' NumOperacion=\"', tbfacturas.comprobante_pago, '\"'), ''), IF(((tbfacturas.metodo_pago <> '01') OR (tbfacturas.rfc_cliente = 'XEXX010101000')), CONCAT_WS('', ' RfcEmisorCtaOrd=\"', (SELECT tbclientes.rfc_cuenta_ordenante FROM tbclientes WHERE tbclientes.id = tbfacturas.id_cliente), '\" NomBancoOrdExt=\"', (SELECT tbclientes.banco_ordenante FROM tbclientes WHERE tbclientes.id = tbfacturas.id_cliente), '\" CtaOrdenante=\"', (SELECT tbclientes.cuenta_ordenante FROM tbclientes WHERE tbclientes.id = tbfacturas.id_cliente), '\" RfcEmisorCtaBen=\"', (SELECT tbbancos.rfc FROM tbbancos WHERE tbbancos.id = (SELECT tbcuentas_bancarias.id_banco FROM tbcuentas_bancarias WHERE tbcuentas_bancarias.id = tbfacturas.cuentapago)), '\" CtaBeneficiario=\"', tbfacturas.cuentapago, '\"', IF(tbfacturas.tipo_cadpago <> NULL, CONCAT_WS('', ' TipoCadPago=\"', tbfacturas.tipo_cadpago, '\" CertPago=\"', tbfacturas.certificado_pago, '\" CadPago=\"', tbfacturas.cadena_pago, '\" SelloPago=\"', tbfacturas.sello_pago, '\"'), '')), ''), '>') AS ComplementoPagos