diff --git a/gestion/lib/Controller/PageController.php b/gestion/lib/Controller/PageController.php index 8d466da..9a1400d 100644 --- a/gestion/lib/Controller/PageController.php +++ b/gestion/lib/Controller/PageController.php @@ -31,6 +31,9 @@ class PageController extends Controller { private $myDb; // private $src_path = "/var/www/html/apps/gestion/img/"; private $src_path = "/var/www/html/custom_apps/gestion/img/"; + + private const HYTHA_35_DEFAULT_ADMIN = "Johann"; + private const H2F_DEFAULT_ADMIN = "Emmanuelle"; private $urlGenerator; private $mailer; private $config; @@ -2658,6 +2661,8 @@ class PageController extends Controller { public function exportFactureToPdf($factureId){ try{ + //for HYTHA 35 , the default admin idnextcloud is Johann, for H2F it is Emmanuelle + $this->idNextcloud = self::HYTHA_35_DEFAULT_ADMIN; $factureFilenames = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->idNextcloud); return json_encode($factureFilenames); } diff --git a/gestion/lib/Service/InvoicePdfService.php b/gestion/lib/Service/InvoicePdfService.php index f5baebb..332f8d6 100644 --- a/gestion/lib/Service/InvoicePdfService.php +++ b/gestion/lib/Service/InvoicePdfService.php @@ -35,30 +35,28 @@ class InvoicePdfService { /** @var Bdd */ private $gestionBdd; - /** @var IRootStorage */ - private $storage; + /** @var IRootFolder */ + private $rootFolder; + private const DEFAULT_NEXTCLOUD_ADMIN = "admin"; public function __construct( Bdd $gestionBdd, IRootFolder $rootFolder) { $this->gestionBdd = $gestionBdd; - try{ - $this->storage = $rootFolder->getUserFolder('admin'); - }catch(\OC\User\NoUserException $e){ - - } + $this->rootFolder = $rootFolder; } private function getLogo(){ + $storage = $this->rootFolder->getUserFolder(self::DEFAULT_NEXTCLOUD_ADMIN); try{ try { - if(isset($this->storage)){ - $file = $this->storage->get('/.gestion/logo.png'); + if(isset($storage)){ + $file = $storage->get('/.gestion/logo.png'); }else{ return "nothing"; } } catch(\OCP\Files\NotFoundException $e) { - $file = $this->storage->get('/.gestion/logo.jpeg'); + $file = $storage->get('/.gestion/logo.jpeg'); } } catch(\OCP\Files\NotFoundException $e) { @@ -69,7 +67,8 @@ class InvoicePdfService { } public function generateFacturePdfByFactureId($factureId,$idNextCloud){ - $configs = json_decode($this->gestionBdd->getConfiguration($idNextCloud)); + $storage = $this->rootFolder->getUserFolder($idNextCloud); + $configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN)); $currentConfig = $configs[0]; $logo = $this->getLogo(); $invoicePdfData = $this->gestionBdd->getInvoicePdfData($factureId,$currentConfig); @@ -85,13 +84,13 @@ class InvoicePdfService { $filenames = []; foreach($factureFolders as $folder){ try { - $this->storage->newFolder($folder); + $storage->newFolder($folder); } catch(\OCP\Files\NotPermittedException $e) { } $ff_pdf = $folder.$pdfFilename.'.pdf'; - $this->storage->newFile($ff_pdf); - $file_pdf = $this->storage->get($ff_pdf); + $storage->newFile($ff_pdf); + $file_pdf = $storage->get($ff_pdf); $file_pdf->putContent($pdfContent); $filenames[] = $ff_pdf; }