<?php

namespace Modules\GlobalApplication\Repository;

use Helpers\QueryBuilder\AbsRepository;

class Documents extends AbsRepository
{

    /**
     * getFormulaireSimple
     * @return array<mixed>
     */
    public function getFormulaireSimple() : ?array
    {
        $reqSql = "SELECT * 
            FROM FO_ENTET with (nolock) 
            WHERE FO_ENTET.DATEDEB <= '".date('Ymd')."' 
            AND (FO_ENTET.DATEFIN = '00000000' OR FO_ENTET.DATEFIN >= '".date('Ymd')."') 
            AND (
                FO_ENTET.ACCETOUS = 0x54  
                OR EXISTS (
                    SELECT * FROM FO_UTILIS with (nolock) 
                    WHERE FO_UTILIS.CODEFORM = FO_ENTET.NO_CDE AND FO_UTILIS.CODEUTIL = '".$_SESSION['Session_Login']."'
                )
            ) ";
        
        if (!$_SESSION['Session_UsrMultiSoc']) {
            $reqSql .= " AND FO_ENTET.CODE_STE = '".$_SESSION['Session_SocUsr']."' ";
        }
        
        return $this->fetchAssocAll($reqSql, []);
    }
}
