<?php

namespace Modules\Facture\Repository;

use Helpers\QueryBuilder\AbsRepository;

class IndicateurFacture extends AbsRepository
{
    
    public function nbFactureByMois($annee)
    {
        $req="Select substring(ssper.DATE_DEB,5,2) mois ,sum(fac.TOTAL_HT) as MONTANT,count(NUM_FACT) as NBRE_FACTURE from FAC_ENT fac with (nolock)
              join SSPERIOD ssper with (nolock) on substring (ssper.DATE_DEB,1,6)=substring (fac.DATE_PER,1,6)
              where ssper.CODE_PER=:value1 group by ssper.LIBELLE,ssper.DATE_DEB order by ssper.DATE_DEB";
        
        $arrayReq = [
            ':value1' => $annee,
        ];
        
        return $this->fetchAssocAll($req, $arrayReq);
    }
    
    public function nbIncidentByMois($annee)
    {
        $req="select substring (ssper.DATE_DEB,5,2) mois ,count(IDUNIQUE)NOMBRE_INCIDENT from FOURNINC fic with (nolock)
                join SSPERIOD ssper with (nolock) on substring (ssper.DATE_DEB,1,6)=substring (fic.DTE_OCCUR,1,6)
                where CODE='LITFACT' and ssper.CODE_PER=:value1 group by ssper.LIBELLE,ssper.DATE_DEB order by ssper.DATE_DEB";
        
        $arrayReq = [
            ':value1' => $annee,
        ];
        
        return $this->fetchAssocAll($req, $arrayReq);
    }
}
