CONCAT_WS('', UPPER(serie), UPPER(folio)) AS SerieFolio, uuid, UPPER(razon_social_cliente), CONCAT_WS('', UPPER(rfc_cliente), IF(curp_cliente IS NOT NULL, CONCAT(' CURP ', curp_cliente), '')) AS RFCCliente, CONCAT_WS('', fiscal_calle_cliente, ' No. ', fiscal_numexterior_cliente, IF(fiscal_numinterior_cliente IS NOT NULL, CONCAT(' Int ', fiscal_numinterior_cliente), ''), '. ', fiscal_colonia_cliente, '. CODIGO POSTAL ', fiscal_cp_cliente) AS DireccionCliente, CONCAT_WS('', (SELECT tbmunicipios.nombre FROM tbmunicipios WHERE tbmunicipios.id = tbfacturas.fiscal_ciudad_cliente), ', ', (SELECT tbestados.nombre FROM tbestados WHERE tbestados.id = tbfacturas.fiscal_estado_cliente), '. ', (SELECT tbpaises.nombre FROM tbpaises WHERE tbpaises.id = tbfacturas.fiscal_pais_cliente)) AS CiudadCliente, CONCAT_WS('', (SELECT tbmunicipios.nombre FROM tbmunicipios WHERE tbmunicipios.id = tbfacturas.fiscal_ciudad_cliente), ', ', (SELECT tbestados.nombre FROM tbestados WHERE tbestados.id = tbfacturas.fiscal_estado_cliente), '. ', DATE_FORMAT(fecha, '%Y-%m-%d %H:%i:%s')) AS LugarFecha, DATE_FORMAT(vencimiento, '%Y-%m-%d %H:%i:%s'), FORMAT(subtotal, 2), FORMAT(descuento, 2), FORMAT(iva, 2), FORMAT(total, 2), UPPER(condiciones_pago), (SELECT CONCAT(UPPER(tbformaspagofacturas.codigo_sat), ' ', (tbformaspagofacturas.nombre)) FROM tbformaspagofacturas WHERE tbformaspagofacturas.id = tbfacturas.forma_pago) AS FormaPago, CONCAT_WS('', metodo_pago, ' ', (SELECT UPPER(tbmetodospagofacturas.nombre) FROM tbmetodospagofacturas WHERE tbmetodospagofacturas.id = tbfacturas.metodo_pago), ' ', IF(metodo_pago <> '99', comprobante_pago, '')) AS MetodoPago, CONCAT_WS('', (SELECT tbbancos.nombre FROM tbbancos WHERE tbbancos.id = (SELECT tbcuentas_bancarias.id_banco FROM tbcuentas_bancarias WHERE tbcuentas_bancarias.id = tbfacturas.cuentapago)), ' CTA ', cuentapago) AS CuentaPago, IF(status = 0, (SELECT tbcuentas_cobrar.saldo FROM tbcuentas_cobrar WHERE tbcuentas_cobrar.id_docto = tbfacturas.id), 0.00) AS Saldos, DATE_FORMAT(vencimiento, '%Y-%m-%d %H:%i:%s'), UPPER(datosextras), SerieCertificadoTimbrado, SelloDigitalCFDI, SelloDigitalSAT, CadenaOriginal, Fechatimbrado, tipo_cfdi, rfc_cliente, total