<?php

namespace Modules\DemandeAchat\Repository;

class FormulaireDemandeAchat
{
    
    private $pdo;
    
    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
    }
    
    /* retourne la liste des mode de transport avec traduction */
    /**
     * enteteFormulaire
     * @param string $code
     * @return array<string>
     */
    public function enteteFormulaire(String $code) : ?array
    {
        $req =
        "SELECT FO_ENTET.*, MEMOS.CONTMEMO COMMENTAIRE
        FROM FO_ENTET with (nolock)
        LEFT JOIN MEMOS with (nolock) on MEMOS.NODEMEMO=FO_ENTET.NMCOMMEN
        WHERE NO_CDE = :idFormulaire";

        $arrayReq[':idFormulaire']=$code;
        
        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);
        
        return $requete->fetch($this->pdo::FETCH_ASSOC);
    }
    
    /* retourne la liste des mode de transport avec traduction */
    public function lignesFormulaire($code)
    {
        $req =
        "SELECT FO_LIGNE.*, MEMOS.CONTMEMO DESIGNCOMP
        FROM FO_LIGNE with (nolock)
        LEFT JOIN MEMOS with (nolock) on MEMOS.NODEMEMO = FO_LIGNE.NM_DCOMP 
        WHERE NO_CDE = :idFormulaire";

        $arrayReq[':idFormulaire']=$code;
        
        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);
        
        return $requete->fetchAll($this->pdo::FETCH_ASSOC);
    }
}
