<?php

namespace Modules\DemandeAchat\Repository;

use Helpers\Outil\Sql;
use Helpers\QueryBuilder\AbsRepository;

class ValidationDemandeAchat extends AbsRepository
{

    public function listeSignat($code)
    {
        $req =
        "SELECT * FROM SIG_DA with (nolock) 
        LEFT JOIN HASTUTIL with (nolock) on HASTUTIL.CODE = SIG_DA.SIGNAT
        WHERE NO_DA = :value";
        
        $arrayReq = [':value' => $code];
        
        return $this->fetchAssocAll($req, $arrayReq);
    }
    
    public function insertNewSignat($array)
    {
        $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        
        $req =
        "INSERT INTO SIG_DA (SIGNAT, NO_DA, DTE_MISE, ORDRE, SIGNABLE, DAROLES, INFORME)
        VALUES(:value1, :value2, :value3, ".$array['ORDRE'].", ".sql::setBoolSql($array['SIGNABLE']).", :value6, ".sql::setBoolSql($array['INFORME']).")";
        
        $arrayReq= [
            ':value1' => $array['SIGNAT'],
            ':value2' => $array['NO_DA'],
            ':value3' => $array['DTE_MISE'],
            ':value6' => $array['DAROLES'],
        ];
        
        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);
    }
}
