<?php

namespace Modules\Additional\Specifique\Client94\Modules\Facture\Controller;

use GuzzleHttp\Psr7\Response;
use Skeleton\Controller\Controller;
use Modules\Additional\Specifique\Client94\Modules\Facture\Service\AjaxFactureService;

class AjaxFactureController extends Controller
{
    /**
     * service
     *
     * @var AjaxFactureService
     */

    private $service;

    /**
     *
     * init
     *
     * @return void
     */
    public function init()
    {
        $this->service = new AjaxFactureService();
    }

    public function updateCsFacLigAction(): Response
    {
        $post = $this->request->getParsedBody();

        $cs = [];
        $csTmp = $this->service->updateCsValue($this->pdo, $post['codeComp'], $post['numFact']);
        foreach ($csTmp as $value) {
            $cs[$value['NUM_FIX']] = $value['VALEUR'];
        }

        return new Response(200, [], (string) \json_encode($cs));
    }
}
