<?php

namespace Modules\GlobalApplication\Repository;

class PieceJointe
{
    /**
     * @var \PDO $pdo
     */
    private $pdo;

    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
    }

    /**
     * @return string
     */
    public function getMaxOrderFacPijo(string $numFac)
    {
        $req = "SELECT MAX(NO_ORDRE) maxOrder 
        FROM FAC_PIJO WITH (NOLOCK) 
        WHERE NO_FAC = :noFac";
        $arrayReq = [':noFac' => $numFac];

        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);

        return $requete->fetch()['maxOrder'] ?? '0';
    }

    /**
     * @return string
     */
    public function getMaxOrderCaPijo(string $idCde)
    {
        $req = "SELECT MAX(NO_ORDRE) maxOrder 
        FROM CA_PIJO WITH (NOLOCK) 
        WHERE NO_CA = :idCde";
        $arrayReq = [':idCde' => $idCde];

        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);

        return $requete->fetch()['maxOrder'] ?? '0';
    }

    /**
     * @return string
     */
    public function getMaxOrderDaPijo(string $idDA)
    {
        $req = "SELECT MAX(NO_ORDRE) maxOrder 
        FROM DA_PIJO WITH (NOLOCK) 
        WHERE NO_DA = :idDA";
        $arrayReq = [':idDA' => $idDA];

        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);

        return $requete->fetch()['maxOrder'] ?? '0';
    }
}
