<?php

namespace Modules\DemandeAchat\Controller;

use Skeleton\Controller\Controller;
use Modules\DemandeAchat\WebService\DemandeAchat;

class SuppressionDemandeAchatController extends Controller
{
    public function supprimerAction(): string
    {
        $numDA = $this->request->getAttribute('idDA');
        $trad = $this->getTranslationService();

        $xmlResult = (new DemandeAchat())
            ->suppresionDemande($numDA);
        $reponse = new \SimpleXMLElement($xmlResult->responseData);

        if ($reponse->Statut == "O") {
            $message =  $trad->t('La demande d\'achat a bien été supprimée');
        } else {
            $message =  $reponse->MsgErreur;
        }

        return $this->renderer->render('@DemandeAchat/Popup/popupConfirmation', [
            'message' => $message,
            'path' => $this->router->generateUri('DemandeAchat.GestionDemandeAchat.index'),
        ]);
    }
}
