-- https://www.phpmyadmin.net/
--

START TRANSACTION;



--
-- Database: `cbox_practice`
--

-- --------------------------------------------------------

--
-- Structure for view `ver_citi_ventas`
--

CREATE ALGORITHM=UNDEFINED DEFINER=`cbox`@`localhost` SQL SECURITY DEFINER VIEW `ver_citi_ventas`  AS
SELECT
    `comprobantes`.`id_fk_factura`      AS `codfactura`,
    `comprobantes`.`fecha_comp`         AS `fecha_envio_comprobante`,
    `comprobantes`.`nro_comp`           AS `nro_comp`,
    `comprobantes`.`cae`                AS `cae`,
    `tipo_comprobante`.`tipo_comp_afip` AS `tipo_comp`,
    `cliente`.`cuenta`                  AS `cuenta`,
    `cliente`.`apenom`                  AS `nom_cliente`,
    `cliente`.`dni`                     AS `dni`,
    `cliente`.`cuilt`                   AS `cuilt`,
    `cond_iva`.`condicion`              AS `condicion_iva`,
    `provincias`.`descripcion_pro`      AS `provincia`,
    `comprobantes`.`importe_total`      AS `importe_total`,
    `comprobantes`.`neto_21`            AS `neto_21`,
    `comprobantes`.`neto_105`           AS `neto_105`,
    0                                   AS `neto_0`,
    IF(`comprobantes`.`neto_21`>0,`comprobantes`.`importe_total` - `comprobantes`.`neto_21`,0) AS `iva_21`,
    IF(`comprobantes`.`neto_105`>0,`comprobantes`.`importe_total` - `comprobantes`.`neto_105`,0) AS `iva_105`,
    `comprobantes`.`fecha_vto`          AS `fecha_vencimiento`
FROM ((((((((`factulinea`
    LEFT JOIN `facturas`
    ON ((`factulinea`.`codfactura` = `facturas`.`codfactura`)))
    LEFT JOIN `cliente`
    ON ((`facturas`.`id_cliente` = `cliente`.`cuenta`)))
    LEFT JOIN `cond_iva`
    ON ((`cliente`.`cond_iva_id` = `cond_iva`.`id`)))
    LEFT JOIN `localidades`
    ON ((`cliente`.`localidad_id` = `localidades`.`id`)))
    LEFT JOIN `provincias`
    ON ((`localidades`.`provincia_id` = `provincias`.`id`)))
    LEFT JOIN `comprobantes`
    ON ((`facturas`.`codfactura` = `comprobantes`.`id_fk_factura`)))
    LEFT JOIN `talonarios`
    ON ((`talonarios`.`id_talonario` = `comprobantes`.`id_talonario`)))
         LEFT JOIN `tipo_comprobante`
                   ON ((`tipo_comprobante`.`id_tipo_comp` = `talonarios`.`id_tipo_comp_afip`)))
GROUP BY `factulinea`.`codfactura`,`comprobantes`.`cae`

--
-- VIEW  `ver_citi_ventas`
-- Data: None
--

COMMIT;

