finish generate photos bijou on rapport bijoux, wip frontend

This commit is contained in:
Tiavina 2025-01-29 10:27:33 +03:00
parent 7e452b0e27
commit 5591a21ac2
5 changed files with 138 additions and 21 deletions

View File

@ -161,5 +161,7 @@ return [
//producttype
['name' => 'page#getProductTypes', 'url' => '/product/getProductTypes', 'verb' => 'PROPFIND'],
//producttype
['name' => 'page#uploadFileToBijoux', 'url' => '/defunt/uploadFileToBijoux', 'verb' => 'POST'],
]
];

View File

@ -2229,25 +2229,23 @@ class PageController extends Controller {
* @NoCSRFRequired
* @param string $numdefunt
*/
public function saveRapportBijoux($numdefunt){
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
public function saveRapportBijoux($numdefunt,$withPhotos = false){
if($withPhotos != null && $withPhotos == 1){
$withPhotos = true;
}
else{
$withPhotos = false;
}
$defaultConfig = json_decode($this->myDb->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$defunt = json_decode($this->myDb->getOneDefunt($numdefunt, $this->idNextcloud))[0];
$bijoux = json_decode($this->myDb->getListBijoux($numdefunt, $this->idNextcloud));
try {
$nomDefunt = $defunt->nom_defunt;
$date_naissance_temp = date("t-m-Y", strtotime(date($defunt->date_naissance)));
$date_deces_temp = date("t-m-Y", strtotime(date($defunt->date_defunt)));
$date_temp = date("t-m-Y", strtotime(date('Y-m-d')));
$date_habilitation_temp = date("t-m-Y", strtotime(date($defunt->date_habilitation)));
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
$today = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_temp));
$date_habilitation = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_habilitation_temp));
$date_naissance = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_naissance_temp));
$date_deces = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_deces_temp));
$folderDestination = html_entity_decode($current_config[0]->path).'/CLIENTS/'.strtoupper($defunt->entreprise).'/DEFUNTS/'.strtoupper($nomDefunt).'/RAPPORTS/';
$folderDestination = html_entity_decode($defaultConfig[0]->path).'/CLIENTS/'.strtoupper($defunt->entreprise).'/DEFUNTS/'.strtoupper($nomDefunt).'/RAPPORTS/';
try {
$this->storage->newFolder($folderDestination);
@ -2265,13 +2263,13 @@ class PageController extends Controller {
// logo : 80 de largeur et 55 de hauteur
$logo = $this->getLogo();
if($logo != 'nothing'){
$pdf->Image($this->defaultImagePath."logo.png", 10, 10, 55, 30);
$pdf->Image($this->defaultImagePath."logo.png", 10, 10, 75, 25);
}
$pdf->SetY(55); $pdf->SetFont('ComicSans', 'B', 15); $pdf->Cell(0, 10, utf8_decode(html_entity_decode("ATTESTATION BIJOU(X)")), 0, 0, 'C');
$pdf->SetY(45); $pdf->SetFont('ComicSans', 'B', 15); $pdf->Cell(0, 10, utf8_decode(html_entity_decode("ATTESTATION BIJOU(X)")), 0, 0, 'C');
$pdf->SetMargins(15,15,15);
$pdf->SetY(80); $pdf->SetFont('ComicSans', '', 10);
$pdf->SetY(65); $pdf->SetFont('ComicSans', '', 10);
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Je soussignée ".$defunt->prenom_thanato." ".strtoupper($defunt->nom_thanato).", Thanatopracteur, agissant pour le compte de la société ".strtoupper($current_config[0]->entreprise)." titulaire de l'habilitation n° ".$defunt->reference_habilitation." atteste par la présente que :
".(strcmp($defunt->sexe, 'm')==0 ? 'Monsieur' : 'Madame').". ".$defunt->nom_defunt."
a été pris(e) en charge par nos services pour des soins mortuaires.")), '','J',0);
@ -2287,6 +2285,38 @@ class PageController extends Controller {
$pdf->SetFont('ComicSans', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($bijou->designation)), 'LTRB', 'L');
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('ComicSans', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($bijou->commentaire)), 'LTRB', 'L');
}
$photosCount = 0;
if($withPhotos){
$photosCountLimitToGoToNewLine = 3;
$currentUserFolder = "/var/www/html/data/$this->idNextcloud/files/";
$clientName = $defunt->nom;
if($clientName != null){
$bijouxPhotosFolder = FileExportHelpers::GetBijouxOfDefuntFolder($clientName,$defunt->nom_defunt,$defaultConfig[0]->path);
$pdf->setXY($pdf->GetX(),$pdf->GetY()+5);
$pdf->Cell(0,5,"Photos :",0,1);
$pdf->setXY($pdf->GetX(),$pdf->GetY()+5);
foreach ($bijoux as $key => $bijou) {
if($bijou->photo == null){
continue;
}
try{
$fullPhotoPath = $currentUserFolder.$bijouxPhotosFolder.$bijou->photo;
$pdf->Image($fullPhotoPath,$pdf->GetX(),$pdf->GetY(),50,30);
$pdf->SetXY($pdf->GetX() + 60,$pdf->GetY());
$photosCount++;
if($photosCount == $photosCountLimitToGoToNewLine){
$pdf->SetY($pdf->GetY() + 35);
}
}
catch(Exception){
}
}
}
if($photosCount > 0){
$pdf->SetY($pdf->GetY()+30);
}
}
$pdf->setY($pdf->GetY()+10);
@ -2297,21 +2327,20 @@ class PageController extends Controller {
// signature
$pdf->SetFont('ComicSans','',11);
$pdf->setY($pdf->GetY()+10);
$pdf->Cell( $pdf->GetPageWidth()-30, 0, utf8_decode(html_entity_decode($current_config[0]->nom).' '.html_entity_decode($current_config[0]->prenom)), 0, 0, 'L');
$pdf->Cell( $pdf->GetPageWidth()-30, 0, utf8_decode(html_entity_decode($defaultConfig[0]->nom).' '.html_entity_decode($defaultConfig[0]->prenom)), 0, 0, 'L');
$pdf->setY($pdf->GetY()+5);
$signatureExist = $this->signatureImageExists('sign.png');
if ($signatureExist) {
$pdf->Image($this->defaultImagePath."sign.png", 15, $pdf->GetY(), 55, 30);
$pdf->Image($this->defaultImagePath."sign.png", 5, $pdf->GetY(), 60, 40);
}
$pdf->setY($pdf->GetY()-5);
$pdf->SetFont('ComicSans','',11); $pdf->Cell( $pdf->GetPageWidth()-80, 0, "Pour :", 0, 0, 'R');
$pdf->SetY(-30); $pdf->SetFont('ComicSans', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_one))), '', 'C');
$pdf->SetFont('ComicSans', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_two))), '', 'C');
$pdf->SetFont('ComicSans', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->telephone))), '', 'C');
$pdf->SetY(-15); $pdf->SetFont('ComicSans', '', 8);
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode($defaultConfig[0]->legal_one)), 0, 'C');
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode($defaultConfig[0]->adresse)), 0,'C');
$ff_pdf = $folderDestination.'RAPPORT_BIJOUX_'.strtoupper($nomDefunt).'.pdf';
$this->storage->newFile($ff_pdf);
@ -2719,4 +2748,44 @@ class PageController extends Controller {
}
catch(\OCP\Files\NotFoundException $e) { }
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function uploadFileToBijoux($bijouxId){
try{
$configs = json_decode($this->myDb->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$currentConfig = $configs[0];
$bijoux = $this->myDb->getBijouxWithDefuntByBijouxId($bijouxId);
if($bijoux == null){
return false;
}
if($bijoux["defunt_id"] == null){
return false;
}
$defuntId = $bijoux["defunt_id"];
$devisOfDefunt = $this->myDb->getDevisOfDefunt($defuntId);
if($devisOfDefunt == null){
return false;
}
$folder = FileExportHelpers::GetBijouxOfDefuntFolder($devisOfDefunt["client_nom"],$bijoux["defunt_nom"],$currentConfig->path);
try {
$this->storage->newFolder($folder);
}
catch(\OCP\Files\NotPermittedException $e) {
}
$photoName = basename($_FILES["photo"]["name"]);
$filename = uniqid() . "_" .$photoName;
$fullPath = $folder.$filename;
$fileContent = file_get_contents($_FILES["photo"]["tmp_name"]);
$this->storage->newFile($fullPath,$fileContent);
$this->myDb->saveBijouxPhoto($bijouxId,$filename,$photoName);
return true;
}
catch(\OCP\Files\NotFoundException $e) { }
}
}

View File

@ -783,7 +783,7 @@ class Bdd {
}
public function getListBijoux($numdefunt, $idNextcloud) {
$sql = "SELECT ".$this->tableprefix."bijou_defunt.id as bdid, designation, commentaire FROM "
$sql = "SELECT ".$this->tableprefix."bijou_defunt.id as bdid, designation, commentaire,photo,photo_name FROM "
.$this->tableprefix."bijou_defunt, ".$this->tableprefix."defunt
WHERE ".$this->tableprefix."defunt.id = defunt_id AND ".$this->tableprefix."defunt.id = ?";
return $this->execSQL($sql, array($numdefunt));
@ -3707,4 +3707,34 @@ class Bdd {
WHERE devis.id = ?;";
$this->execSQLNoData($sql,[$mention,$devisId]);
}
public function getBijouxWithDefuntByBijouxId($bijouxId){
$sql = "SELECT
bijou.id,
bijou.defunt_id,
bijou.designation,
bijou.commentaire,
bijou.photo,
defunt.nom as defunt_nom
FROM ".$this->tableprefix."bijou_defunt as bijou
LEFT JOIN ".$this->tableprefix."defunt as defunt on bijou.defunt_id = defunt.id
WHERE bijou.id = ? ;";
$bijoux = $this->execSQLNoJsonReturn($sql,[$bijouxId,]);
if(!empty($bijoux)){
return $bijoux[0];
}
return null;
}
public function saveBijouxPhoto($bijouxId,$photo,$photoRealName){
$sql = "UPDATE ".$this->tableprefix."bijou_defunt as bijou_defunt
SET bijou_defunt.photo = ?,bijou_defunt.photo_name = ?
WHERE bijou_defunt.id = ? ;";
$this->execSQLNoData(
$sql,
[$photo,$photoRealName,$bijouxId]);
return true;
}
}

View File

@ -48,4 +48,18 @@ class FileExportHelpers
return strtr( $str, $unwanted_array );
}
public static function GetClientsFolder($clientName,$racinePath){
return $racinePath.'CLIENTS/'.mb_strtoupper($clientName,'UTF-8').'/';
}
public static function GetDefuntsFolder($clientName,$defuntName,$racinePath){
$clientsFolder = self::GetClientsFolder($clientName,$racinePath);
return $clientsFolder.'DEFUNTS/'.mb_strtoupper($defuntName,'UTF-8').'/';
}
public static function GetBijouxOfDefuntFolder($clientName,$defuntName,$racinePath){
$defuntFolder = self::GetDefuntsFolder($clientName,$defuntName,$racinePath);
return $defuntFolder.'BIJOUX/';
}
}

View File

@ -0,0 +1,2 @@
alter table oc_gestion_bijou_defunt add photo VARCHAR(255) DEFAULT NULL;
alter table oc_gestion_bijou_defunt add photo_name VARCHAR(255) DEFAULT NULL;