<?php

namespace Modules\Stock\Controller;

use DateTime;
use Entity\Model\Slotglob;
use Exception;
use GuzzleHttp\Psr7\Response;
use Skeleton\Controller\Controller;

class LotGlobalController extends Controller
{
    /**
     * @throws Exception
     */
    public function getLotGlobalAction(): Response
    {
        $post = $this->request->getParsedBody();
        if ($lotGlobal = (new Slotglob($this->pdo))->find(['NO_LOT' => $post['noLot'], 'CODE_ART' => $post['codeArt']])) {
            $lotGlobal['DTE_PEREM'] = $lotGlobal['DTE_PEREM'] === '00000000' ? null: (new DateTime($lotGlobal['DTE_PEREM']))->format('d/m/Y');
        }

        return $this->createJsonResponse(['lotGlobal' => $lotGlobal]);
    }
}
