SELECT  
        `pl`.`status` AS `Status`,
        `period_liquidation_iva`.`id` AS `IdLiquidacionIVA`,
        `period_liquidation_iva`.`period_liquidation_id` AS `period_liquidation_id`,
        `period_liquidation_iva`.`period_id` AS `IdPeriodo`,
        `period_liquidation_iva`.`person_id` AS `IdEmpresa`,
        `b`.`document` AS `DocumentoEmpresa`,
        `b`.`field_name1` AS `NombreEmpresa`,
        `p`.`date_from` AS `Desde`,
        `p`.`date_to` AS `Hasta`,
        `p`.`code` AS `Periodo`,
        `period_liquidation_iva`.`total_debit` AS `total_debit`,
        `period_liquidation_iva`.`total_credit` AS `total_credit`,
        `period_liquidation_iva`.`previous_technical` AS `previous_technical`,
        `period_liquidation_iva`.`previous_free_availability` AS `previous_free_availability`,
        `period_liquidation_iva`.`retention_amount` AS `retention_amount`,
        `period_liquidation_iva`.`perception_amount` AS `perception_amount`,
        `period_liquidation_iva`.`compensation_amount` AS `compensation_amount`,
        `period_liquidation_iva`.`total_perceptions_retentions` AS `total_perceptions_retentions`,
        `period_liquidation_iva`.`free_availability_balance` AS `free_availability_balance`,
        `period_liquidation_iva`.`negative_amount` AS `A_PAGAR`,
        `period_liquidation_iva`.`positive_amount` AS `SaldoTecnicoAFavor`,
        `period_liquidation_iva`.`total_free_availability` AS `SaldoLibreDisponibilidadAFavor`


    FROM `period_liquidation_iva`
        LEFT JOIN `persons` `b` ON `period_liquidation_iva`.`person_id` = `b`.`id`
        LEFT JOIN `periods` `p` ON `period_liquidation_iva`.`period_id` = `p`.`id`
        LEFT JOIN `period_liquidations` `pl` ON `period_liquidation_iva`.`period_liquidation_id` = `pl`.`id`
        
    order by Periodo,NombreEmpresa