set defunt cover on defunt show, WIP error message (defunt doesnt have devis, or the products does not exist)

This commit is contained in:
Tiavina 2025-01-08 12:18:10 +03:00
parent d499696964
commit 8ea19d7b87
6 changed files with 155 additions and 54 deletions

File diff suppressed because one or more lines are too long

View File

@ -271,13 +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(),
'coverProducts' =>$this->myDb->getCoverProducts()
'coverProducts' =>json_decode($coverProducts)
));
}

View File

@ -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){
@ -2829,12 +2843,36 @@ class Bdd {
$sqlConditionsPlaceholder = implode(',', array_fill(0, count(ProductConstant::PRODUCT_COVER_REFERENCE_LIST), '?'));
$sql = "SELECT
produit.id,
produit.reference
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,6 +29,7 @@
</div>
</div>
<hr>
<div class="row">
<div class="col-6" style="margin-bottom: 32px">
<h6>INFORMATIONS GÉNÉRALES</h6>
<hr>
@ -85,6 +87,25 @@
</div>
</div>
</div>
<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>
<?php endforeach; ?>
<div class="row p-2">
<button class="btn btn-secondary" id="coverProductsRadioButton"> Choisir la housse</button>
</div>
</div>
</div>
<div class="col-6" style="margin-bottom: 32px">
<h6>ÉTATS DU CORPS</h6>
<hr>