finish api to set defunt cover , WIP frontend part

This commit is contained in:
Tiavina 2025-01-08 10:40:41 +03:00
parent 5ef1ca3b25
commit d499696964
5 changed files with 174 additions and 3 deletions

View File

@ -136,5 +136,8 @@ return [
//certificate
['name' => 'page#exportCareCertificate', 'url' => '/defunt/exportCareCertificate', 'verb' => 'POST'],
//defuntCover
['name' => 'page#setDefuntCover', 'url' => '/defunt/setDefuntCover', 'verb' => 'POST'],
]
];

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace OCA\Gestion\Constants;
abstract class BddConstant
{
const DEFAULT_CALENDAR_UUID_FOR_DEVIS = "not-related";
const CALENDAR_TABLE_PREFIX = "*PREFIX*";
const DEFAULT_CLIENT_GROUP_NAME = "Nom du groupe";
}

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace OCA\Gestion\Constants;
abstract class ProductConstant
{
const PRODUCT_COVER_TO_RECOVER_REFERENCE = "HAR";
const PRODUCT_LEAVE_ON_COVER_REFERENCE = "HAL";
const PRODUCT_COVER_REFERENCE_LIST = [
self::PRODUCT_COVER_TO_RECOVER_REFERENCE,
self::PRODUCT_LEAVE_ON_COVER_REFERENCE
];
}

View File

@ -276,7 +276,8 @@ class PageController extends Controller {
'defunt'=>json_decode($defunt),
'path' => $this->idNextcloud,
'url' => $this->getNavigationLink(),
'logo' => $this->getLogo()
'logo' => $this->getLogo(),
'coverProducts' =>$this->myDb->getCoverProducts()
));
}
@ -2906,7 +2907,7 @@ class PageController extends Controller {
* @param int $defuntId
*/
public function exportCareCertificate($defuntId){
public function exportCareCertificate($defuntId){
try{
$careCertificateFilename = $this->certificateService->generateCareCertificate($defuntId,$this->idNextcloud);
return $careCertificateFilename;
@ -2914,4 +2915,19 @@ class PageController extends Controller {
catch(\OCP\Files\NotFoundException $e) { }
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param int $defuntId
*/
public function setDefuntCover($defuntId,$productId){
try{
$response = $this->myDb->setDefuntCover($defuntId,$productId);
return $response;
}
catch(\OCP\Files\NotFoundException $e) { }
}
}

View File

@ -5,6 +5,7 @@ use OCA\Gestion\Helpers\DateHelpers;
use OCP\IDBConnection;
use OCP\IL10N;
use \Datetime;
use OCA\Gestion\Constants\ProductConstant;
use OCA\Gestion\Helpers\FileExportHelpers;
use Psr\Log\LoggerInterface;
use OCA\Gestion\Helpers\VCalendarHelpers;
@ -14,7 +15,6 @@ class Bdd {
public const DEFAULT_CALENDAR_UUID_FOR_DEVIS = "not-related";
public const CALENDAR_TABLE_PREFIX = "*PREFIX*";
public const DEFAULT_CLIENT_GROUP_NAME = "Nom du groupe";
private IDbConnection $pdo;
private array $whiteColumn;
@ -2707,5 +2707,134 @@ class Bdd {
return null;
}
private function getDefuntById($defuntId){
$sql = "SELECT
defunt.id as id,
defunt.nom as defunt_nom,
devis.id as devis_id
FROM ".$this->tableprefix."defunt as defunt
LEFT JOIN ".$this->tableprefix."devis as devis on defunt.id = devis.id_defunt
WHERE defunt.id = ?
LIMIT 1;";
$defunt = $this->execSQLNoJsonReturn($sql,[$defuntId]);
if(!empty($defunt)){
return $defunt[0];
}
return null;
}
private function getProductAsDefuntCoverProduct($productCoverId){
$sqlConditionsPlaceholder = implode(',', array_fill(0, count(ProductConstant::PRODUCT_COVER_REFERENCE_LIST), '?'));
$sql = "SELECT
produit.id,
produit.reference
FROM ".$this->tableprefix."produit as produit
WHERE produit.id = ? AND
produit.reference IN ($sqlConditionsPlaceholder)
LIMIT 1;";
$product = $this->execSQLNoJsonReturn(
$sql,
array_merge(
[$productCoverId],
ProductConstant::PRODUCT_COVER_REFERENCE_LIST
)
);
if(!empty($product)){
return $product[0];
}
return $product;
}
private function isProductAlreadyExistInDevis($productId,$devisId){
$sql = "SELECT
produit_devis.id
FROM ".$this->tableprefix."produit_devis as produit_devis
WHERE produit_devis.produit_id = ? AND
produit_devis.devis_id = ?
LIMIT 1;";
$product = $this->execSQLNoJsonReturn($sql,[$productId,$devisId]);
if(!empty($product)){
return true;
}
return false;
}
private function removeProductFromDevis($productId,$devisId){
$sql = "DELETE
FROM ".
$this->tableprefix."produit_devis
WHERE devis_id = ? AND produit_id = ?
";
$this->execSQLNoData($sql,[$devisId,$productId]);
}
private function getProductByReference($productReference){
$sql = "SELECT
produit.id,
produit.reference
FROM ".$this->tableprefix."produit as produit
WHERE produit.reference = ?
LIMIT 1;";
$product = $this->execSQLNoJsonReturn($sql,[$productReference]);
if(!empty($product)){
return $product[0];
}
return null;
}
private function removeProductFromDevisByProductReference($productReference,$devisId){
$product = $this->getProductByReference($productReference);
if($product != null){
$this->removeProductFromDevis($product["id"],$devisId);
}
}
private function createProductDevisIfNotExist($productId,$devisId){
$isProductDevisAlreadyExist = $this->isProductAlreadyExistInDevis($productId,$devisId);
if(!$isProductDevisAlreadyExist){
$idNextcloud = "admin";
$this->insertDevisArticle(devisId: $devisId, articleId: $productId,idNextcloud: $idNextcloud);
}
}
public function setDefuntCover($defuntId, $productCoverId){
$defunt = $this->getDefuntById($defuntId);
if($defunt == null){
return null;
}
if($defunt["devis_id"] == null){
return null;
}
$product = $this->getProductAsDefuntCoverProduct($productCoverId);
if($product == null){
return null;
}
$productCoverReferencesList = ProductConstant::PRODUCT_COVER_REFERENCE_LIST;
foreach($productCoverReferencesList as $currentProductCoverReference){
if($currentProductCoverReference === $product["reference"]){
$this->createProductDevisIfNotExist($product["id"],$defunt["devis_id"]);
}
else{
$this->removeProductFromDevisByProductReference($currentProductCoverReference,$defunt["devis_id"]);
}
}
return true;
}
public function getCoverProducts(){
$sqlConditionsPlaceholder = implode(',', array_fill(0, count(ProductConstant::PRODUCT_COVER_REFERENCE_LIST), '?'));
$sql = "SELECT
produit.id,
produit.reference
FROM ".$this->tableprefix."produit as produit
WHERE produit.reference IN ($sqlConditionsPlaceholder)";
return $this->execSQL($sql,ProductConstant::PRODUCT_COVER_REFERENCE_LIST);
}
}