<?php

class Reporte_model extends Databases {

    protected $token = false;

    public function getResumen($desde, $hasta, $radio) {
        
        if ($radio == 'resumen') {
            $sql = "SELECT  A.fev,A.fep,A.tip,A.tco,A.suc,A.nco,A.ipa,A.sal,A.fpa,A.rec,A.fer,A.pla,A.lug,A.far,A.CLI,A.anu,A.rep, 
                    cast( A.TIP as varchar(2)) + ' ' + REPLICATE('0',4-LEN(A.suc)) + Convert(varchar,A.suc) + '-' + REPLICATE('0',8-LEN(A.NCO)) + Convert(varchar,A.NCO) as ncNCO  
                    FROM acobypag A  
                    FULL OUTER JOIN AMAEFACT B ON (  A.TIP=B.TIP AND A.TCO=B.TCO AND A.SUC=B.SUC AND A.NCO=B.NCO )  
                    WHERE A.CLI = 1509 AND A.fep >= '$desde' AND A.fep <= '$hasta'    
                    ORDER By A.fep,A.fpa,A.tco asc";
        }else{
            $sql="SELECT  A.fev,A.fep,A.tip,A.tco,A.suc,A.nco,A.ipa,A.sal,A.fpa,A.rec,A.fer,A.pla,A.lug,A.far,A.CLI,A.anu,A.rep, 
                  cast( A.TIP as varchar(2)) + ' ' + REPLICATE('0',4-LEN(A.suc)) + Convert(varchar,A.suc) + '-' + REPLICATE('0',8-LEN(A.NCO)) + Convert(varchar,A.NCO) as ncNCO  
                  FROM acobypag A  
                  WHERE  NOT (a.TCO='RE' AND a.rec<>0) and anu<>'A' and fpa=2 AND A.CLI = 1509 AND  ( rec=0 OR tco='AC' or ( tco='re' AND rec > 0 and A.fer >= '$hasta' ) ) AND tco<>'RC'    
                  ORDER By A.fep,A.fpa,A.tco asc";
        }

        $data = parent::query($sql);
        if ($data && count($data) > 0) {
            return $data;
        } else {
            return FALSE;
        }
    }

}
