91 lines
2.7 KiB
PHP
91 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace OCA\Gestion\Service\Devis;
|
|
|
|
use OCA\Gestion\Db\Bdd;
|
|
use OCP\Files\IRootFolder;
|
|
use OCA\Gestion\Constants\MultipleFactureTypeConstant;
|
|
|
|
/**
|
|
* Service principal pour la génération des récapitulatifs de devis
|
|
*/
|
|
class DevisRecapService
|
|
{
|
|
/** @var Bdd */
|
|
private $gestionBdd;
|
|
|
|
/** @var IRootFolder */
|
|
private $rootFolder;
|
|
|
|
/** @var DevisDataProcessor */
|
|
private $dataProcessor;
|
|
|
|
/** @var DevisPdfGenerator */
|
|
private $pdfGenerator;
|
|
|
|
public const DEFAULT_NEXTCLOUD_ADMIN = 'admin';
|
|
|
|
public function __construct(
|
|
Bdd $gestionBdd,
|
|
IRootFolder $rootFolder,
|
|
) {
|
|
$this->gestionBdd = $gestionBdd;
|
|
$this->rootFolder = $rootFolder;
|
|
$this->dataProcessor = new DevisDataProcessor($gestionBdd);
|
|
$this->pdfGenerator = new DevisPdfGenerator($rootFolder);
|
|
}
|
|
|
|
public function generateDevisRecap($filter, $month, $year, $idNextCloud, $filterType, $montant)
|
|
{
|
|
$storage = $this->rootFolder->getUserFolder($idNextCloud);
|
|
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
|
|
$currentConfig = $configs[0];
|
|
|
|
$devisData = $this->getDevisData($filter, $month, $year, $currentConfig, $filterType);
|
|
|
|
if (empty($devisData)) {
|
|
return null;
|
|
}
|
|
|
|
$processedData = $this->dataProcessor->prepareDevisData($devisData, $currentConfig, $filter, $idNextCloud);
|
|
$clientInfo = $this->dataProcessor->getClientInfoForDevis($processedData[0], $filterType);
|
|
|
|
return $this->pdfGenerator->generatePdfDocument(
|
|
$storage,
|
|
$currentConfig,
|
|
$processedData,
|
|
$clientInfo,
|
|
$month,
|
|
$year,
|
|
$montant
|
|
);
|
|
}
|
|
|
|
private function getDevisData($filter, $month, $year, $currentConfig, $filterType)
|
|
{
|
|
$isFilterByClient = $filterType === MultipleFactureTypeConstant::CLIENT_FILTER_TYPE;
|
|
|
|
if ($isFilterByClient) {
|
|
return $this->gestionBdd->getDevisPdfDataByClientAndMonthYear($filter, $month, $year, $currentConfig);
|
|
} else {
|
|
return $this->gestionBdd->getDevisPdfDataByClientGroupFacturationAndMonthYear($filter, $month, $year, $currentConfig);
|
|
}
|
|
}
|
|
|
|
// Méthodes utilitaires conservées pour la compatibilité CSV
|
|
public function generateCsvContent($devisData)
|
|
{
|
|
return $this->dataProcessor->generateCsvContent($devisData);
|
|
}
|
|
|
|
public function getClientNameForFolder($firstDevis, $filterType)
|
|
{
|
|
return $this->dataProcessor->getClientNameForFolder($firstDevis, $filterType);
|
|
}
|
|
|
|
public function getRecapFilename($month, $year)
|
|
{
|
|
return $this->dataProcessor->getRecapFilename($month, $year);
|
|
}
|
|
}
|