<?php

namespace Modules\Stock\Controller;

use DateTime;
use Entity\Model\CsDon;
use Entity\Model\Hastutil;
use Entity\Model\Paravrac;
use Entity\Model\Sarticle;
use Entity\Model\Sborlot;
use Entity\Model\SbsEnte;
use Entity\Model\SbsLign;
use Entity\Model\SdsEnte;
use Entity\Model\Societe;
use Entity\Model\SSiteSto;
use Entity\Model\Tiers;
use Exception;
use GuzzleHttp\Psr7\Response;
use Helpers\Ariane\Ariane;
use Helpers\ChampsSupplementaire\ChampSupp;
use Helpers\ExportTo\Outils;
use Helpers\Filter\FiltreAvance\GeneratorCs;
use Helpers\Outil\Sql;
use Helpers\Pagination\PaginatorGestion;
use Helpers\Trad\Trad;
use Modules\Stock\Enum\Operation;
use Modules\Stock\Enum\TypeEnteteEnum;
use Modules\Stock\Helper\GestionFiltreHelper;
use Modules\Stock\Helper\NumberHelper;
use Modules\Stock\MenuContextuel\BonSortieContextuel;
use Modules\Stock\MenuContextuel\LigneBonSortieContextuel;
use Modules\Stock\Repository\BonSortieRepo;
use Modules\Stock\Repository\LigneBonSortieRepo;
use Modules\Stock\Service\Export\BonSortieExportService;
use Modules\Stock\Service\Form\BonSortieFormService;
use Modules\Stock\Service\Form\LigneBonSortieFormService;
use Modules\Stock\Service\ListManagerService;
use Modules\Stock\Service\ParametrageService;
use Modules\Stock\Service\SoldeManuelService;
use Modules\Stock\Trait\Controller\BonSortieControllerTrait;
use Modules\Stock\Trait\Controller\StockContollerTrait;
use Modules\Stock\Trait\Controller\WebserviceTrait;
use Skeleton\Controller\Controller;

class BonSortieController extends Controller
{
    use WebserviceTrait;
    use StockContollerTrait;
    use BonSortieControllerTrait;

    /**
     * @throws Exception
     */
    public function gestionAction(): string
    {
        $trad = $this->getTranslationService();
        $currentUser = $this->getCurrentUser();
        $post = $this->request->getParsedBody();
        $listManager = new ListManagerService($trad);

        GestionFiltreHelper::initialiseCodeSocieteFiltre($post, 'filter_egal_SE#point#CODE_STE');
        GestionFiltreHelper::initialiseMagasinierFiltre($post, 'filter_egal_SE#point#MAG', $currentUser['CODE']);
        if (Sql::toBool($currentUser['FILT_SIT'])) {
            GestionFiltreHelper::initialiseSiteStockFiltre($post, 'filter_egal_SE#point#SITE', $currentUser['SIT_STO']);
        }

        Ariane::generate(0, $trad->t('Gestion'), [], null, $this->router->generateUri('Stock.BonSortie.gestion'));

        (new PaginatorGestion())->generate(20, 'NO_BS');
        $bonsSortie = (new BonSortieRepo($this->pdo))->listBonsSortie($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

        (new BonSortieContextuel($this->pdo, $this->router, $trad))->addMenuContextuelToEntities($bonsSortie);

        $filtreAvance = new GeneratorCs($post, 'SBS_ENTE', 'SE.NO_BS', $this->pdo, $trad);
        $filtreAvance->setFiltre('SE.DTE_CREAT', 'date', $trad->t('Date création'));
        $filtreAvance->setFiltre('SE.DTE_VALID', 'date', $trad->t('Date validation'));
        $filtreAvance->setFiltre('SL.ART', 'liste', $trad->t('Code article'), '', 'Ajax.liste.stockArticles', 'Articles');
        $filtreAvance->setFiltre('SE.TOT_BS', 'numeric', $trad->t('Total'));

        return $this->renderer->render('@Stock/BonSortie/gestion', [
            'post'             => $post,
            'menuActive'       => 'Stock',
            'bonsSortie'       => $bonsSortie,
            'infoPagination'   => $infoPagination,
            'listeFiltreEtat'  => $listManager->getEtatsList(),
            'filtreAvance'     => $filtreAvance->getFiltres(),
            'initFiltreAvance' => $filtreAvance->getInit(),
            'configAxeImp'     => (new Paravrac($this->pdo))->getCommandeAxeImpConfig()
        ]);
    }

    /**
     * @throws Exception
     */
    public function ligneAction(): string
    {
        $noBs = $this->request->getAttribute('noBs');
        $bonSortie = (new SbsEnte($this->pdo))->find(['NO_BS' => $noBs]);
        $lignesBonSortie =  (new LigneBonSortieRepo($this->pdo))->findAllFromNoBs($noBs);

        return $this->renderer->render('@Stock/BonSortie/ligne', [
            'id' => $noBs,
            'bonSortie' => $bonSortie,
            'lignesBonSortie' => $lignesBonSortie,
            'tiers' => (new Tiers($this->pdo))->find(['CODE' => $bonSortie['DEST']], ['RS']),
            'siteStock' => (new SSiteSto($this->pdo))->find(['SITE' => $bonSortie['SITE']], ['DESIGN'])
        ]);
    }

    public function popupExportAction() : string
    {
        $tables = ['Entête' => 'SBS_ENTE', 'Ligne' => 'SBS_LIGN'];
        $tab = (new BonSortieExportService($this->pdo, $this->getTranslationService()))->getTab($tables);
        asort($tab);

        return $this->renderer->render('@GlobalApplication/Popup/popupExport', [
            'pathExport' => $this->router->generateUri('Stock.BonSortie.exporter'),
            'tabObli' => ['SE.NO_BS', 'SL.NO_LIG'],
            'formFilter' => 'filtres_bon_sortie',
            'coloneExport' => $tab,
            'post' => [
                'multiSelectexportFacOBLI1' => 'SE.NO_BS',
                'multiSelectexportFacOBLI2' => 'SL.NO_LIG',
            ],
        ]);
    }

    /**
     * @throws Exception
     */
    public function exporterAction(): Response
    {
        $post = $this->request->getParsedBody();
        $postFilters = !empty($this->request->getParsedBody()['okFilter']) ? $post: [];
        $bonSortieExportService = new BonSortieExportService($this->pdo, $this->getTranslationService());

        $arrayMultiSelect = $bonSortieExportService->getArrayMultiSelect($post);
        $listeCS = $bonSortieExportService->getListeCS($arrayMultiSelect);

        $bonsSortie = (new BonSortieRepo($this->pdo))->listBonsSortieExport($postFilters, implode(',', $arrayMultiSelect));

        $entete = $bonSortieExportService->getTableEntete($arrayMultiSelect, $listeCS, 'SBS_ENTE', 'SBS_LIGN');
        $champsDate = $bonSortieExportService->getChampsParType('DATE');
        $champsBool = $bonSortieExportService->getChampsParType('BOOL');

        foreach ($bonsSortie as &$bonSortie) {
            /** @var array<int,array<string,string>> $listeCS */
            $bonSortieExportService->addChampsSupplementaireValeur($listeCS, $bonSortie, 'NO_BS', 'NO_LIG', 'SBS_LIGN');
            $bonSortieExportService->convertirDates($champsDate, $bonSortie);
            $bonSortieExportService->convertirBool($champsBool, $bonSortie);
        }

        Outils::gestionEmailAsync2(
            'export_BS_'.date('Ymd'),
            $bonsSortie,
            $this->JWTKEY,
            $this->router,
            $this->getTranslationService(),
            $entete
        );

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

    /**
     * @throws Exception
     */
    public function nouveauFormAction(): string
    {
        $trad = $this->getTranslationService();
        $post = $this->request->getParsedBody();
        [$magasinier, $currentUser, $site, $dest] = $this->getInitDataFromUser($post);
        $parametreNumerotation = (new ParametrageService($this->pdo))->getParametreNumerotation(TypeEnteteEnum::BS, $_SESSION['Session_SocUsr']);

        Ariane::generate(
            1,
            $trad->t('Création de bon de sortie'),
            [],
            null,
            $this->router->generateUri('Stock.BonSortie.nouveauForm')
        );

        return $this->renderer->render('@Stock/BonSortie/nouveau_Form', [
            'post'            => $post,
            'dest'            => $dest,
            'site'            => $site,
            'magasinier'      => $magasinier,
            'dateJour'        => date("Ymd"),
            'parametreNumerotation' => $parametreNumerotation,
            'dateCreation'    => (new DateTime('now'))->format('d/m/Y'),
            'configAxeImp'    => (new Paravrac($this->pdo))->getCommandeAxeImpConfig(),
            'siteMarkUp'      => (new SSiteSto($this->pdo))->find($site, ['MARK_UP'])['MARK_UP'],
            'codeSte'         => !$_SESSION['Session_UsrPluriSoc'] ? $currentUser['CODE_STE']: null,
        ]);
    }

    /**
     * @throws Exception
     */
    public function nouveauAction(): Response
    {
        $post = $this->request->getParsedBody();
        $validator = $this->getBonSortieValidator();
        $bonSortie = $post['SBS_ENTE'];
        $siteStock = (new SSiteSto($this->pdo))->find(['SITE' => $post['SBS_ENTE']['SITE']]);
        $parametreNumerotation = (new ParametrageService($this->pdo))->getParametreNumerotation(TypeEnteteEnum::BS, $siteStock['CODE_STE']);
        $demandeService = (new SdsEnte($this->pdo))->find(['NO_DS' => $post['NO_DS']]);

        $validator
            ->validateMag($bonSortie)
            ->validateMarkUp($bonSortie)
            ->validateDestinataire($bonSortie)
            ->validateDateCreation($bonSortie)
            ->validateSite($bonSortie, $demandeService['SITE'])
            ->validateLignes($post, 'SBS_LIGNS', $post['NO_DS'])
            ->validateNo($bonSortie, $parametreNumerotation, TypeEnteteEnum::BS, 'bon de sortie')
        ;

        if ($validator->isNonBloquant() && !isset($post['confirm'])) {
            return $this->createNonBloquantJsonErrorResponse('Confirmez-vous la création de ce bon de sortie', $validator->getErrorNonBloquant(), $parametreNumerotation);
        }
        if ($validator->isValid(true)) {
            $bonSortieFormService = new BonSortieFormService($this->pdo);
            $bonSortie = $bonSortieFormService->initEntity($bonSortie, ['SITE_STOCK' => $siteStock, 'PARAMETRE_NUMEROTATION' => $parametreNumerotation]);

            $this->pdo->beginTransaction();
            $bonSortieFormService->flushData($bonSortie, [...$post, 'operation' => Operation::CREATE]);
            $this->pdo->commit();

            return $this->createJsonResponse([
                'statut' => 'OK',
                'redirectRoute' => $this->router->generateUri('Stock.BonSortie.modifierForm', ['noBs' => $bonSortie['NO_BS']]),
            ]);
        } else {
            return $this->createBloquantJsonErrorResponse($parametreNumerotation, $validator->getError());
        }
    }

    /**
     * @throws Exception
     */
    public function modifierFormAction(): string|Response
    {
        $trad = $this->getTranslationService();
        $noBs = $this->request->getAttribute('noBs');

        if (!$bonSortie = (new SbsEnte($this->pdo))->find(['NO_BS' => $noBs])) {
            return $this->create404Response('Ce bon de sortie n\'existe pas');
        }

        $siteStock = (new SSiteSto($this->pdo))->find(['SITE' => $bonSortie['SITE']]);
        $utilisateur = (new Hastutil($this->pdo))->find(['CODE' => $bonSortie['MAG']]);

        Ariane::generate(
            1,
            $trad->t('Modification de bon de sortie'),
            [],
            null,
            $this->router->generateUri('Stock.BonSortie.modifierForm', ['noBs' => $noBs])
        );

        $lignesBonSortie = (new LigneBonSortieRepo($this->pdo))->findAllFromNoBs($noBs);
        $menuContextuel = new LigneBonSortieContextuel($this->pdo, $this->router, $trad);
        foreach ($lignesBonSortie as $key => $ligneBonSortie) {
            $lignesBonSortie[$key]['DELETE_POPUP'] = $menuContextuel->getDeletePopupConfirm($ligneBonSortie['NO_BS'], $ligneBonSortie['NO_LIG']);
        }

        return $this->renderer->render('@Stock/BonSortie/modifier_form', [
            'bonSortie' => $bonSortie,
            'siteStock' => $siteStock,
            'utilisateur' => $utilisateur,
            'dateJour' => date("Ymd"),
            'typeEntete' => TypeEnteteEnum::BS,
            'lignesBonSortie' => $lignesBonSortie,
            'post' => $this->request->getParsedBody(),
            'configAxeImp' => (new Paravrac($this->pdo))->getCommandeAxeImpConfig($bonSortie['CODE_STE']),
            'societe' => (new Societe($this->pdo))->find(['CODE_STE' => $bonSortie['CODE_STE']], ['RAIS_SOC']),
        ]);
    }

    /**
     * @throws Exception
     */
    public function modifierAction(): Response
    {
        $sbsEnte = new SbsEnte($this->pdo);
        $trad = $this->getTranslationService();
        $post = $this->request->getParsedBody();
        $validator = $this->getBonSortieValidator();
        $noBs = $this->request->getAttribute('noBs');

        if (!$bonSortie = $sbsEnte->find(['NO_BS' => $noBs])) {
            return $this->createJsonResponse(['message' => Trad::strBuild($trad->t('Le bon de sortie portant le numéro @1@ n\'existe pas'), $noBs)], 404);
        }

        $bonSortie = array_merge($bonSortie, $post['SBS_ENTE']);
        $bonSortie['NO_BS'] = $noBs;
        $siteStock = (new SSiteSto($this->pdo))->find(['SITE' => $bonSortie['SITE']]);
        $parametreNumerotation = (new ParametrageService($this->pdo))->getParametreNumerotation(TypeEnteteEnum::BE, $siteStock['CODE_STE']);

        $validator
            ->validateMag($bonSortie)
            ->validateSite($bonSortie)
            ->validateMarkUp($bonSortie)
            ->validateOrigine($bonSortie)
            ->validateDestinataire($bonSortie)
            ->validateCs('SBS_ENTE', [$bonSortie['NO_BS'], null], $post)
        ;

        if ($validator->isNonBloquant() && !isset($bonSortie['confirm'])) {
            return $this->createNonBloquantJsonErrorResponse('Confirmez-vous la modification de ce bon de sortie', $validator->getErrorNonBloquant(), $parametreNumerotation);
        }
        if ($validator->isValid(true)) {
            $this->pdo->beginTransaction();
            (new BonSortieFormService($this->pdo))->flushData($bonSortie, $post);
            $this->pdo->commit();

            return $this->createJsonResponse($this->getSuccessDataWithValidation(
                'ST_BS_VAL',
                ['noBs' => $noBs],
                'BonSortie',
                'Voulez vous valider ce bon de sortie ?',
                $_SESSION['ariane'][0]['path']
            ));
        } else {
            return $this->createBloquantJsonErrorResponse($parametreNumerotation, $validator->getError());
        }
    }

    /**
     * @throws Exception
     */
    public function dupliquerFormAction(): string|Response
    {
        $trad = $this->getTranslationService();
        $noBs = $this->request->getAttribute('noBs');
        $parametreNumerotation = (new ParametrageService($this->pdo))->getParametreNumerotation(TypeEnteteEnum::BS);

        if (!$bonSortie = (new SbsEnte($this->pdo))->find(['NO_BS' => $noBs])) {
            return $this->create404Response('Ce bon de sortie n\'existe pas');
        }

        Ariane::generate(
            1,
            $trad->t('Duplication de bon de sortie'),
            [],
            null,
            $this->router->generateUri('Stock.BonSortie.dupliquerForm', ['noBs' => $noBs])
        );

        return $this->renderer->render('@Stock/BonSortie/dupliquer_form', [
            'dateJour' => date("Ymd"),
            'bonSortie' => $bonSortie,
            'parametreNumerotation' => $parametreNumerotation,
            'dateCreation' => (new DateTime('now'))->format('d/m/Y'),
            'siteStock' => (new SSiteSto($this->pdo))->find(['SITE' => $bonSortie['SITE']]),
            'utilisateur' => (new Hastutil($this->pdo))->find(['CODE' => $bonSortie['MAG']]),
            'societe' => (new Societe($this->pdo))->find(['CODE_STE' => $bonSortie['CODE_STE']], ['RAIS_SOC'])
        ]);
    }

    /**
     * @throws Exception
     */
    public function dupliquerAction(): Response
    {
        $sarticle = new Sarticle($this->pdo);
        $post = $this->request->getParsedBody();
        $validator = $this->getBonSortieValidator();
        $siteStock = (new SSiteSto($this->pdo))->find(['SITE' => $post['SBS_ENTE']['SITE']]);
        $parametreNumerotation = (new ParametrageService($this->pdo))->getParametreNumerotation(TypeEnteteEnum::BS, $siteStock['CODE_STE']);

        $bonSortie = $post['SBS_ENTE'];

        $validator
            ->validateMag($bonSortie)
            ->validateSite($bonSortie)
            ->validateMarkUp($bonSortie)
            ->validateDateCreation($bonSortie)
            ->validateNo($bonSortie, $parametreNumerotation, TypeEnteteEnum::BS, 'bon de sortie')
        ;

        if ($validator->isNonBloquant() && !isset($post['confirm'])) {
            return $this->createNonBloquantJsonErrorResponse('Confirmez-vous la duplication de ce bon de sortie', $validator->getErrorNonBloquant(), $parametreNumerotation);
        }
        if ($validator->isValid(true)) {
            $bonSortieFormService = new BonSortieFormService($this->pdo);
            $ligneBonSortieFormService = new LigneBonSortieFormService($this->pdo);
            $bonSortieFormService->initNo($parametreNumerotation, $bonSortie);

            $this->pdo->beginTransaction();

            $bonSortieFormService->flushData($bonSortie, $post);
            $bonSortieFormService->duplicateCS($post['NO_BS_DUPLIQUE'], $bonSortie['NO_BS'], null, 'SBS_ENTE');

            $sbsLign = new SbsLign($this->pdo);
            $lignesBonSortie = $sbsLign->findAll(['NO_BS' => $post['NO_BS_DUPLIQUE']]);
            foreach ($lignesBonSortie as $ligneBonSortie) {
                $ligneBonSortie['NO_BS'] = $bonSortie['NO_BS'];
                $ligneBonSortie['NO_DS'] = '';
                $ligneBonSortie['NO_LIG_DS'] = '';
                $sbsLign->processAndMerge($ligneBonSortie);
                $bonSortieFormService->duplicateCS($post['NO_BS_DUPLIQUE'], $ligneBonSortie['NO_BS'], $ligneBonSortie['NO_LIG'], 'SBS_LIGN');
                $stockArticle = $sarticle->find(['CODE_ART' => $ligneBonSortie['ART']]);
                $qteSortieVar = 0 - NumberHelper::toFloat($ligneBonSortie['QTE_SORTI']);
                $ligneBonSortieFormService->updateQteReserveeStockArticle($stockArticle, $ligneBonSortie, $qteSortieVar);
                $ligneBonSortieFormService->updateQteReserveeStockLocal($ligneBonSortie, $qteSortieVar, $bonSortie['SITE']);
            }

            $sborlot = new Sborlot($this->pdo);
            $lotsBonSortie = $sborlot->findAll(['NO_BS' => $post['NO_BS_DUPLIQUE']]);
            foreach ($lotsBonSortie as $lotBonSortie) {
                $lotBonSortie['NO_BS'] = $bonSortie['NO_BS'];
                $sborlot->merge($lotBonSortie);
            }

            $this->pdo->commit();

            return $this->createJsonResponse([
                'statut' => 'OK',
                'redirectRoute' => $this->router->generateUri('Stock.BonSortie.modifierForm', ['noBs' => $bonSortie['NO_BS']])
            ]);
        } else {
            return $this->createBloquantJsonErrorResponse($parametreNumerotation, $validator->getError());
        }
    }

    /**
     * @throws Exception
     */
    public function supprimerAction(): Response
    {
        $csDon = new CsDon($this->pdo);
        $sbsEnte = new SbsEnte($this->pdo);
        $sbsLign = new SbsLign($this->pdo);
        $sarticle = new Sarticle($this->pdo);
        $noBs = $this->request->getAttribute('noBs');

        if (!$bonSortie = $sbsEnte->find(['NO_BS' => $noBs])) {
            return $this->createJsonResponse(['statut' => 'Not found', 'message' => Trad::strBuild($this->getTranslationService()->t('Le bon de sortie N°@1@ n\'existe pas'), $noBs)], 404);
        }

        $lignesBonSortie = (new LigneBonSortieRepo($this->pdo))->findAllFromNoBs($noBs);
        $ligneBonSortieFormService = new LigneBonSortieFormService($this->pdo);

        $this->pdo->beginTransaction();

        foreach ($lignesBonSortie as $ligneBonSortie) {
            $stockArticle = $sarticle->find(['CODE_ART' => $ligneBonSortie['ART']]);
            $codeEnrSbsLign = ChampSupp::autoCompletCodeEnr($noBs, $ligneBonSortie['NO_LIG'], 'SBS_LIGN');
            $csDon->delete(['COD_TAB' => 'SBS_LIGN', 'COD_ENR' => $codeEnrSbsLign]);

            $qteSortieVar = NumberHelper::toFloat($ligneBonSortie['QTE_SORTI']);
            $ligneBonSortieFormService->updateResteLigneDemandeService($ligneBonSortie, $qteSortieVar);
            $ligneBonSortieFormService->updateQteReserveeStockArticle($stockArticle, $ligneBonSortie, $qteSortieVar);
            $ligneBonSortieFormService->updateQteReserveeStockLocal($ligneBonSortie, $qteSortieVar, $bonSortie['SITE']);

            $sbsLign->delete(['NO_BS' => $noBs, 'NO_LIG' => $ligneBonSortie['NO_LIG']]);
        }

        (new Sborlot($this->pdo))->delete(['NO_BS' => $noBs]);

        $sbsEnte->delete(['NO_BS' => $noBs]);
        $csDon->delete(['COD_TAB' => 'SBS_ENTE', 'COD_ENR' => ChampSupp::autoCompletCodeEnr($noBs, null, 'SBS_ENTE')]);

        $this->pdo->commit();

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

    /**
     * @throws Exception
     */
    public function visualiserAction(): string|Response
    {
        $trad = $this->getTranslationService();
        $noBs = $this->request->getAttribute('noBs');

        if (!$bonSortie = (new SbsEnte($this->pdo))->find(['NO_BS' => $noBs])) {
            return $this->create404Response(Trad::strBuild($trad->t('Le bon de sortie N°@1@ n\'existe pas'), $noBs));
        }

        Ariane::generate(
            1,
            $trad->t('Visualisation de bon de sortie'),
            [],
            null,
            $this->router->generateUri('Stock.BonSortie.visualiser', ['noBs' => $noBs])
        );

        return $this->renderer->render('@Stock/BonSortie/visualiser', [
            'bonSortie' => $bonSortie,
            'initImputations' => $this->request->getQueryParams(),
            'lignesBonSortie' => (new LigneBonSortieRepo($this->pdo))->findAllFromNoBs($noBs),
            'siteStock' => (new SSiteSto($this->pdo))->find(['SITE' => $bonSortie['SITE']]),
            'destinataire' => (new Tiers($this->pdo))->find(['CODE' => $bonSortie['DEST']]),
            'utilisateur' => (new Hastutil($this->pdo))->find(['CODE' => $bonSortie['MAG']]),
            'societe' => (new Societe($this->pdo))->find(['CODE_STE' => $bonSortie['CODE_STE']], ['RAIS_SOC']),
        ]);
    }

    /**
     * @throws Exception
     */
    public function impressionValoriseeAction(): string|Response
    {
        return $this->impression(true);
    }

    /**
     * @throws Exception
     */
    public function impressionNonValoriseeAction(): string|Response
    {
        return $this->impression(false);
    }

    /**
     * @throws Exception
     */
    public function validerAction(): Response
    {
        $sbsEnte = new SbsEnte($this->pdo);
        $noBs = $this->request->getAttribute('noBs');
        $bonSortie = $sbsEnte->find($noBs);
        $post = $this->request->getParsedBody();
        $confirm = $post['confirm'] ?? false;

        if ($bonSortie['DTE_VALID'] !== '00000000') {
            return $this->createJsonResponse(['statut' => 'Forbidden'], 403);
        }

        $xml = '<BSIn LngUtilisation="'.htmlspecialchars($_SESSION['Session_Langue']).'">
                    <Confirmation>'.$confirm.'</Confirmation>
                    <NumeroBS>'.$noBs.'</NumeroBS>
                </BSIn>';

        return $this->webserviceValidationResponse(
            $xml,
            $confirm,
            'OXAPRC_VALID_BS',
            'Confirmez-vous la validation de ce bon de sortie ?',
            'Ce bon de sortie ne peut pas être validé',
            $_SESSION['ariane'][0]['path'],
            (new SoldeManuelService($this->pdo))->getSoldeAutoCallback($noBs, 'SBS_LIGN'),
        );
    }
}
