Merge branch 'features/feature-defunt-cover' into staging

This commit is contained in:
Tiavina 2025-01-08 12:18:25 +03:00
commit a521a8011b
9 changed files with 327 additions and 55 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'],
]
];

File diff suppressed because one or more lines are too long

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

@ -271,12 +271,14 @@ class PageController extends Controller {
* @param string $numdefunt
*/
public function defuntshow($numdefunt) {
$defunt = $this->myDb->getOneDefunt($numdefunt,$this->idNextcloud);
$defunt = $this->myDb->getOneDefunt($numdefunt,$this->idNextcloud,true);
$coverProducts = $this->myDb->getCoverProducts();
return new TemplateResponse('gestion', 'defuntshow', array( 'groups' => $this->groups, 'user' => $this->user, 'configuration'=> $this->getConfiguration(),
'defunt'=>json_decode($defunt),
'path' => $this->idNextcloud,
'url' => $this->getNavigationLink(),
'logo' => $this->getLogo()
'logo' => $this->getLogo(),
'coverProducts' =>json_decode($coverProducts)
));
}
@ -2906,7 +2908,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 +2916,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;
@ -525,7 +525,7 @@ class Bdd {
return $this->execSQL($sql, array($numdevis));
}
public function getOneDefunt($numdefunt,$idNextcloud){
public function getOneDefunt($numdefunt,$idNextcloud,$includeDefuntProductCover = false){
$sql = "SELECT ".$this->tableprefix."defunt.id, ".$this->tableprefix."devis.version, ".$this->tableprefix."devis.comment, ".$this->tableprefix."devis.date, num,"
.$this->tableprefix."devis.id as id_devis,".$this->tableprefix."devis.id_client, id_lieu, id_thanato,".$this->tableprefix."devis.user_id as user_id, "
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,".$this->tableprefix."defunt.date_naissance,".$this->tableprefix."defunt.sexe,".$this->tableprefix."defunt.ref_pacemaker,"
@ -572,7 +572,21 @@ class Bdd {
LEFT JOIN ".$this->tableprefix."lieu on ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id
LEFT JOIN ".$this->tableprefix."thanato on ".$this->tableprefix."devis.id_thanato = ".$this->tableprefix."thanato.id
WHERE ".$this->tableprefix."defunt.id = ?";
return $this->execSQL($sql, array($numdefunt));
$defunts = $this->execSQLNoJsonReturn($sql,[$numdefunt]);
if($includeDefuntProductCover){
foreach($defunts as &$defunt){
$defunt["product_cover_id"] = null;
$defuntHasDevis = $defunt["id_devis"] != null;
if($defuntHasDevis){
$productCover = $this->getProductCoverByDevisId($defunt["id_devis"]);
if($productCover != null){
$defunt["product_cover_id"] = $productCover["produit_id"];
}
}
}
}
return json_encode($defunts);
}
public function getListProduit($numdevis, $idNextcloud){
@ -2707,5 +2721,158 @@ 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,
produit.description
FROM ".$this->tableprefix."produit as produit
WHERE produit.reference IN ($sqlConditionsPlaceholder)";
return $this->execSQL($sql,ProductConstant::PRODUCT_COVER_REFERENCE_LIST);
}
private function getProductCoverByDevisId($devisId){
$sqlConditionsPlaceholder = implode(',', array_fill(0, count(ProductConstant::PRODUCT_COVER_REFERENCE_LIST), '?'));
$sql = "SELECT
produit_devis.id,
produit.id as produit_id,
produit.reference,
produit.description
FROM ".$this->tableprefix."produit_devis as produit_devis
LEFT JOIN ".$this->tableprefix."produit as produit on produit_devis.produit_id = produit.id
WHERE produit_devis.devis_id = ? AND
produit.reference IN ($sqlConditionsPlaceholder) LIMIT 1";
$productCover = $this->execSQLNoJsonReturn($sql,
array_merge(
[$devisId],
ProductConstant::PRODUCT_COVER_REFERENCE_LIST
));
if($productCover){
return $productCover[0];
}
return null;
}
}

View File

@ -4,7 +4,7 @@ import "../css/mycss.css";
import { globalConfiguration } from "./modules/mainFunction.mjs";
import "./listener/main_listener";
import { getBibliotheques, getBijouxById, getHypodermiquesyId, getObservationsById, getproduits, saveAttestationPacemaker,exportCareCertificate, saveRapportBijoux, saveRapportSoin, updateDB } from "./modules/ajaxRequest.mjs";
import { setDefuntCover,getBibliotheques, getBijouxById, getHypodermiquesyId, getObservationsById, getproduits, saveAttestationPacemaker,exportCareCertificate, saveRapportBijoux, saveRapportSoin, updateDB } from "./modules/ajaxRequest.mjs";
let bibliotheques = [];
let sortedBibliotheques = [];
@ -72,7 +72,22 @@ window.addEventListener("DOMContentLoaded", function () {
var rapportSoinBtn = document.getElementById("rapportSoinBtn");
var rapportBijouxBtn = document.getElementById("rapportBijouxBtn");
var exportCareCertificateButton = document.getElementById("exportCareCertificate");
var setDefuntCoverButton = this.document.getElementById("coverProductsRadioButton");
setDefuntCoverButton.addEventListener("click",function(){
const productCoverRadios = document.getElementsByName('coverProductsRadioButton');
let selectedValue = null;
for (const radio of productCoverRadios) {
if (radio.checked) {
selectedValue = radio.value;
break;
}
}
setDefuntCover({
defuntId : defuntid,
productId : selectedValue
});
})
exportCareCertificateButton.addEventListener("click",function(){
exportCareCertificate({defuntId : defuntid});

View File

@ -745,3 +745,29 @@ export function exportCareCertificate(defuntIdPayload) {
error(response);
});
};
/**
* Set defunt cover (Housse)
* @param {*} setDefuntCoverPayload
*/
export function setDefuntCover(setDefuntCoverPayload) {
if(setDefuntCoverPayload.productId == null){
showError('Veuillez choisir une housse à appliquer');
return;
}
$.ajax({
url: baseUrl + '/defunt/setDefuntCover',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(setDefuntCoverPayload)
}).done(function (response) {
if(response == null) {
showMessage('Ce defunt n\'appartient à aucun devis.');
} else {
showSuccess('Housse appliquée au defunt avec succès');
}
}).fail(function (response, code) {
showMessage(t('gestion', 'Erreur dans l\'application de la housse'));
error(response);
});
};

View File

@ -7,6 +7,7 @@
if($i>1) $quantiteOptions[] = $i;
if($i<15) $quantiteOptions[] = $i + 0.5;
}
$coverProducts = $_['coverProducts'];
?>
<div id="contentTable">
<div id="defuntid" data-table="defunt" data-id="<?php echo $_['defunt'][0]->id; ?>"></div>
@ -28,60 +29,80 @@
</div>
</div>
<hr>
<div class="col-6" style="margin-bottom: 32px">
<h6>INFORMATIONS GÉNÉRALES</h6>
<hr>
<!-- Date -->
<div class="d-flex flex-row align-items-center col-12" style="margin-bottom: 8px">
<div class="col-3">Date de décès</div>
<div class="col-9">
<input class="gestion-input inputDate w-100" type="date" value="<?php echo $_['defunt'][0]->date_defunt ?>" data-table="defunt" data-column="date" data-id="<?php echo $_['defunt'][0]->id ?>"/>
<div class="row">
<div class="col-6" style="margin-bottom: 32px">
<h6>INFORMATIONS GÉNÉRALES</h6>
<hr>
<!-- Date -->
<div class="d-flex flex-row align-items-center col-12" style="margin-bottom: 8px">
<div class="col-3">Date de décès</div>
<div class="col-9">
<input class="gestion-input inputDate w-100" type="date" value="<?php echo $_['defunt'][0]->date_defunt ?>" data-table="defunt" data-column="date" data-id="<?php echo $_['defunt'][0]->id ?>"/>
</div>
</div>
</div>
<!-- Heure -->
<div class="d-flex flex-row align-items-center col-12" style="margin-bottom: 8px">
<div class="col-3">Heure de soin</div>
<div class="col-9">
<div class="d-flex flex-row col-12 align-items-center">
<div class="col-5">
<input class="gestion-input w-100" type="time" value="<?php echo $_['defunt'][0]->heure_debut ?>" data-table="defunt" data-column="heure_debut" data-id="<?php echo $_['defunt'][0]->id ?>"/>
</div>
<div class="d-flex col-2 justify-content-center align-items-center">à</div>
<div class="col-5">
<input class="gestion-input w-100" type="time" value="<?php echo $_['defunt'][0]->heure_fin ?>" data-table="defunt" data-column="heure_fin" data-id="<?php echo $_['defunt'][0]->id ?>"/>
<!-- Heure -->
<div class="d-flex flex-row align-items-center col-12" style="margin-bottom: 8px">
<div class="col-3">Heure de soin</div>
<div class="col-9">
<div class="d-flex flex-row col-12 align-items-center">
<div class="col-5">
<input class="gestion-input w-100" type="time" value="<?php echo $_['defunt'][0]->heure_debut ?>" data-table="defunt" data-column="heure_debut" data-id="<?php echo $_['defunt'][0]->id ?>"/>
</div>
<div class="d-flex col-2 justify-content-center align-items-center">à</div>
<div class="col-5">
<input class="gestion-input w-100" type="time" value="<?php echo $_['defunt'][0]->heure_fin ?>" data-table="defunt" data-column="heure_fin" data-id="<?php echo $_['defunt'][0]->id ?>"/>
</div>
</div>
</div>
</div>
</div>
<!-- Nom -->
<div class="d-flex flex-row align-items-center col-12" style="margin-bottom: 8px">
<div class="col-3">Nom</div>
<div class="col-9">
<input class="gestion-input w-100" type="text" value="<?php echo $_['defunt'][0]->nom_defunt ?>" data-table="defunt" data-column="nom" data-id="<?php echo $_['defunt'][0]->id ?>"/>
<!-- Nom -->
<div class="d-flex flex-row align-items-center col-12" style="margin-bottom: 8px">
<div class="col-3">Nom</div>
<div class="col-9">
<input class="gestion-input w-100" type="text" value="<?php echo $_['defunt'][0]->nom_defunt ?>" data-table="defunt" data-column="nom" data-id="<?php echo $_['defunt'][0]->id ?>"/>
</div>
</div>
<!-- Date de naissance -->
<div class="d-flex flex-row align-items-center col-12" style="margin-bottom: 8px">
<div class="col-3">Date de naissance</div>
<div class="col-9">
<input class="gestion-input w-100" type="date" value="<?php echo $_['defunt'][0]->date_naissance ?>" data-table="defunt" data-column="date_naissance" data-id="<?php echo $_['defunt'][0]->id ?>"/>
</div>
</div>
<!-- Sexe -->
<div class="d-flex flex-row align-items-center col-12" style="margin-bottom: 8px">
<div class="col-3">Sexe</div>
<div class="col-9">
<select class="gestion-select w-100" data-table="defunt" data-column="sexe" data-id="<?php echo $_['defunt'][0]->id ?>">
<option value="m" <?php if(strcmp($_['defunt'][0]->sexe, 'm')==0) echo 'selected' ?>>Masculin</option>
<option value="f" <?php if(strcmp($_['defunt'][0]->sexe, 'f')==0) echo 'selected' ?>>Féminin</option>
</select>
</div>
</div>
<!-- Référence pacemaker -->
<div class="d-flex flex-row align-items-center col-12" style="margin-bottom: 16px">
<div class="col-3">Référence pacemaker</div>
<div class="col-9">
<input class="gestion-input w-100" type="text" value="<?php echo $_['defunt'][0]->ref_pacemaker ?>" data-table="defunt" data-column="ref_pacemaker" data-id="<?php echo $_['defunt'][0]->id ?>"/>
</div>
</div>
</div>
<!-- Date de naissance -->
<div class="d-flex flex-row align-items-center col-12" style="margin-bottom: 8px">
<div class="col-3">Date de naissance</div>
<div class="col-9">
<input class="gestion-input w-100" type="date" value="<?php echo $_['defunt'][0]->date_naissance ?>" data-table="defunt" data-column="date_naissance" data-id="<?php echo $_['defunt'][0]->id ?>"/>
<div class="col-6">
<h6>Housse</h6>
<hr>
<?php foreach ($coverProducts as $currentCoverProduct): ?>
<div class="row">
<div class="d-flex align-items-center mb-2">
<input type="radio"
name="coverProductsRadioButton"
value="<?= htmlspecialchars($currentCoverProduct->id); ?>"
<?= $currentCoverProduct->id == $_['defunt'][0]->product_cover_id ? 'checked' : ''; ?>>
<label class="form-check-label"><?= htmlspecialchars($currentCoverProduct->description); ?></label>
</div>
</div>
</div>
<!-- Sexe -->
<div class="d-flex flex-row align-items-center col-12" style="margin-bottom: 8px">
<div class="col-3">Sexe</div>
<div class="col-9">
<select class="gestion-select w-100" data-table="defunt" data-column="sexe" data-id="<?php echo $_['defunt'][0]->id ?>">
<option value="m" <?php if(strcmp($_['defunt'][0]->sexe, 'm')==0) echo 'selected' ?>>Masculin</option>
<option value="f" <?php if(strcmp($_['defunt'][0]->sexe, 'f')==0) echo 'selected' ?>>Féminin</option>
</select>
</div>
</div>
<!-- Référence pacemaker -->
<div class="d-flex flex-row align-items-center col-12" style="margin-bottom: 16px">
<div class="col-3">Référence pacemaker</div>
<div class="col-9">
<input class="gestion-input w-100" type="text" value="<?php echo $_['defunt'][0]->ref_pacemaker ?>" data-table="defunt" data-column="ref_pacemaker" data-id="<?php echo $_['defunt'][0]->id ?>"/>
<?php endforeach; ?>
<div class="row p-2">
<button class="btn btn-secondary" id="coverProductsRadioButton"> Choisir la housse</button>
</div>
</div>
</div>