generate devis pdf when creating or updating agenda

This commit is contained in:
Tiavina 2025-03-05 14:03:06 +03:00
parent 9247f2dd4d
commit 6597688b17

View File

@ -32,7 +32,9 @@ use OCA\Gestion\Constants\OrderStatusConstant;
use OCA\Gestion\Constants\ThanatoTypeConstant;
use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Db\OrderBdd;
use OCA\Gestion\Service\Devis\Pdf\DevisPdfService;
use OCA\Gestion\Service\Order\OrderPdfService;
use OCP\DB\Exception;
use Psr\Log\LoggerInterface;
use OCA\Gestion\Helpers\VCalendarHelpers;
@ -47,16 +49,19 @@ class GestionService {
private $orderBdd;
private $orderPdfService;
private $devisPdfService;
public function __construct(
Bdd $gestionBdd,
OrderBdd $orderBdd,
LoggerInterface $logger,
OrderPdfService $orderPdfService) {
OrderPdfService $orderPdfService,
DevisPdfService $devisPdfService) {
$this->orderBdd = $orderBdd;
$this->logger = $logger;
$this->gestionBdd = $gestionBdd;
$this->orderPdfService = $orderPdfService;
$this->devisPdfService = $devisPdfService;
}
private function GetCalendarSummaryFromVCalendarString(string $vCalendarString): string
@ -152,44 +157,51 @@ class GestionService {
}
public function HandleCreatedCalendarObject(string $vCalendarString){
$thanato = $this->GetThanatoFromVCalendarString($vCalendarString);
if($thanato != null){
$thanatoId = $thanato["id"];
}
else{
$thanatoId = 0;
}
$calendarSummary = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
$clientId = $this->GetClientIdFromVCalendarString($vCalendarString);
$locationId = $this->GetLocationIdFromVCalendarString($vCalendarString);
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
$userName = $this->GetThanatoNameFromVCalendarString($vCalendarString);
$devisAlreadyCreated = $this->IsDevisAlreadyCreated($clientId,$locationId,$thanatoId,$calendarSummary,$calendarUuid);
if($devisAlreadyCreated){
return;
}
$defuntId = $this->gestionBdd->insertDefuntByNameAndReturnId($calendarSummary);
$calendarStartDate = $this->GetCalendarDateFromVCalendarString($vCalendarString);
$devisDate = $calendarStartDate->format('Y-m-d');
$devisId = $this->gestionBdd->insertDevisFromVCalendarAndReturnId($thanatoId,$clientId,$locationId,$defuntId,$calendarUuid,$devisDate,$userName);
$articlesValue = $this->GetArticlesNameFromVCalendarString($vCalendarString);
if(!empty($articlesValue)){
$articleIds = $this->gestionBdd->getArticleIdsByArticleReferences($articlesValue);
$this->gestionBdd->insertDevisArticleFromDevisIdAndArticlesIdArray($devisId, $articleIds);
}
$thanatoIsSubcontractor = $thanato["fk_thanato_type_key"] === ThanatoTypeConstant::THANATO_TYPE_SUBCONTRACTOR;
if($thanatoIsSubcontractor){
$orderCreated = $this->orderBdd->createOrderFromDevisIdAndDate($devisId,$calendarStartDate,$userName);
if($orderCreated){
$order = $this->orderBdd->getOrderByDevisId($devisId);
$this->logger->debug(json_encode($order));
if($order != null){
$this->orderPdfService->generateOrderPdfByOrderId($order['id'],BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD);
$this->orderPdfService->generateOrderPdfByOrderId($order['id'],BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
try{
$thanato = $this->GetThanatoFromVCalendarString($vCalendarString);
if($thanato != null){
$thanatoId = $thanato["id"];
}
else{
$thanatoId = 0;
}
$calendarSummary = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
$clientId = $this->GetClientIdFromVCalendarString($vCalendarString);
$locationId = $this->GetLocationIdFromVCalendarString($vCalendarString);
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
$userName = $this->GetThanatoNameFromVCalendarString($vCalendarString);
$devisAlreadyCreated = $this->IsDevisAlreadyCreated($clientId,$locationId,$thanatoId,$calendarSummary,$calendarUuid);
if($devisAlreadyCreated){
return;
}
$defuntId = $this->gestionBdd->insertDefuntByNameAndReturnId($calendarSummary);
$calendarStartDate = $this->GetCalendarDateFromVCalendarString($vCalendarString);
$devisDate = $calendarStartDate->format('Y-m-d');
$devisId = $this->gestionBdd->insertDevisFromVCalendarAndReturnId($thanatoId,$clientId,$locationId,$defuntId,$calendarUuid,$devisDate,$userName);
$articlesValue = $this->GetArticlesNameFromVCalendarString($vCalendarString);
if(!empty($articlesValue)){
$articleIds = $this->gestionBdd->getArticleIdsByArticleReferences($articlesValue);
$this->gestionBdd->insertDevisArticleFromDevisIdAndArticlesIdArray($devisId, $articleIds);
}
$thanatoIsSubcontractor = $thanato["fk_thanato_type_key"] === ThanatoTypeConstant::THANATO_TYPE_SUBCONTRACTOR;
if($thanatoIsSubcontractor){
$orderCreated = $this->orderBdd->createOrderFromDevisIdAndDate($devisId,$calendarStartDate,$userName);
if($orderCreated){
$order = $this->orderBdd->getOrderByDevisId($devisId);
$this->logger->debug(json_encode($order));
if($order != null){
$this->orderPdfService->generateOrderPdfByOrderId($order['id'],BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD);
$this->orderPdfService->generateOrderPdfByOrderId($order['id'],BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
}
}
}
$this->devisPdfService->generateDevisPdfByDevisId($devisId,BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD);
$this->devisPdfService->generateDevisPdfByDevisId($devisId,BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
$this->gestionBdd->createDevisTrajetFromVCalendar($devisId,$userName);
}
catch(Exception $e){
$this->logger->debug("error creating devis");
}
$this->gestionBdd->createDevisTrajetFromVCalendar($devisId,$userName);
}
private function GetThanatoNameFromVCalendarString($vCalendarString){
@ -291,16 +303,23 @@ class GestionService {
}
public function HandleUpdatedCalendarObject(string $vCalendarString){
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
if($devis != null){
$this->gestionBdd->updateDevisMention($devis['id'],DevisMentionConstant::NEW);
$isDevisAlreadyUpdated = $this->CheckIfDevisIsAlreadyUpdated($devis,$vCalendarString);
if($isDevisAlreadyUpdated){
return true;
try{
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
if($devis != null){
$this->gestionBdd->updateDevisMention($devis['id'],DevisMentionConstant::NEW);
$isDevisAlreadyUpdated = $this->CheckIfDevisIsAlreadyUpdated($devis,$vCalendarString);
if($isDevisAlreadyUpdated){
return true;
}
$this->UpdateDevisDataByVCalendarString($devis,$vCalendarString);
}
$this->UpdateDevisDataByVCalendarString($devis,$vCalendarString);
$this->devisPdfService->generateDevisPdfByDevisId($devis['id'],BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD);
$this->devisPdfService->generateDevisPdfByDevisId($devis['id'],BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
return true;
}
catch(Exception $e){
$this->logger->debug("error creating devis");
}
return true;
}
}