diff --git a/gestion/lib/Constants/OrderStatusConstant.php b/gestion/lib/Constants/OrderStatusConstant.php index ed7b798..d5209a1 100644 --- a/gestion/lib/Constants/OrderStatusConstant.php +++ b/gestion/lib/Constants/OrderStatusConstant.php @@ -5,4 +5,5 @@ namespace OCA\Gestion\Constants; abstract class OrderStatusConstant { const ORDERED_KEY = "ORDERED"; + const CANCELED_KEY = "CANCELED"; } \ No newline at end of file diff --git a/gestion/lib/Db/OrderBdd.php b/gestion/lib/Db/OrderBdd.php index 333238e..c7bff6a 100644 --- a/gestion/lib/Db/OrderBdd.php +++ b/gestion/lib/Db/OrderBdd.php @@ -119,4 +119,12 @@ class OrderBdd { $order = $this->getOrderByCalendarUuid($calendarUuid); return $order['id']; } + + public function updateOrderStatus($orderId,$statusKey){ + $sql= "UPDATE ".$this->orderTablePrefix."orders as orders + SET orders.fk_order_status_key = ? + WHERE orders.id = ?"; + + $this->execSQLNoData($sql,[$statusKey,$orderId]); + } } \ No newline at end of file diff --git a/gestion/lib/Service/GestionService.php b/gestion/lib/Service/GestionService.php index 2ea3d1f..0e10736 100644 --- a/gestion/lib/Service/GestionService.php +++ b/gestion/lib/Service/GestionService.php @@ -27,6 +27,7 @@ declare(strict_types=1); namespace OCA\Gestion\Service; use OCA\Gestion\Constants\DevisMentionConstant; +use OCA\Gestion\Constants\OrderStatusConstant; use OCA\Gestion\Constants\ThanatoTypeConstant; use OCA\Gestion\Db\Bdd; use OCA\Gestion\Db\OrderBdd; @@ -249,10 +250,23 @@ class GestionService { } public function HandleCalendarObjectMovedToTrash(string $vCalendarString){ + $thanato = $this->GetThanatoFromVCalendarString($vCalendarString); + if($thanato == null){ + return; + } $calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString); - $devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid); - if($devis != null){ - $this->gestionBdd->updateDevisMentionToCanceled($devis['id']); + $thanatoIsSubcontractor = $thanato["fk_thanato_type_key"] === ThanatoTypeConstant::THANATO_TYPE_SUBCONTRACTOR; + if($thanatoIsSubcontractor){ + $order = $this->orderBdd->getOrderByCalendarUuid($calendarUuid); + if($order != null){ + $this->orderBdd->updateOrderStatus($order['id'],OrderStatusConstant::CANCELED_KEY); + } + } + else{ + $devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid); + if($devis != null){ + $this->gestionBdd->updateDevisMentionToCanceled($devis['id']); + } } return true; }