feat add attestation absence pacemacker

This commit is contained in:
Tolotsoa 2025-09-30 14:23:03 +03:00
parent cfe88df7ba
commit 1a4068481f
8 changed files with 703 additions and 352 deletions

View File

@ -99,6 +99,7 @@ return [
// generation attestation pacemaker, rapport de soins, de bijoux
['name' => 'page#saveAttestationPacemaker', 'url' => '/saveAttestationPacemaker', 'verb' => 'POST'],
['name' => 'page#saveAttestationAbsentPacemaker', 'url' => '/saveAttestationAbsentPacemaker', 'verb' => 'POST'],
['name' => 'page#saveRapportSoin', 'url' => '/saveRapportSoin', 'verb' => 'POST'],
['name' => 'page#saveRapportBijoux', 'url' => '/saveRapportBijoux', 'verb' => 'POST'],

File diff suppressed because one or more lines are too long

View File

@ -2028,265 +2028,268 @@ class PageController extends Controller
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function apiReloadFec() {
$this->reloadFec();
return new DataResponse("", 200, ['Content-Type' => 'application/json']);
}
* @NoAdminRequired
* @NoCSRFRequired
*/
public function apiReloadFec()
{
$this->reloadFec();
return new DataResponse("", 200, ['Content-Type' => 'application/json']);
}
private function reloadFec(){
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
$clean_folder = html_entity_decode($current_config[0]->path).'/';
private function reloadFec()
{
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
$clean_folder = html_entity_decode($current_config[0]->path).'/';
try {
try {
$data_factures = array();
$factures = json_decode($this->myDb->getFacturesListWithDependencies());
foreach ($factures as $key => $facture) {
$factureIsSingle = $facture->facture_type == FactureTypeConstant::TYPE_SINGLE;
$facture_temp = array(
'num' => $facture->num,
'client' => $facture->entreprise,
'nom_client' => $facture->nom,
'date' => $facture->date,
'date_facture' => $facture->date_paiement,
'defunt' => $facture->nom_defunt,
'montant_htc' => 0,
'tva' => $current_config[0]->tva_default,
'montant_tva' => 0,
'montant_ttc' => 0,
);
if($factureIsSingle){
$produits = json_decode($this->getProduitsById($facture->id_devis));
foreach ($produits as $key => $produit) {
$htPrice = $produit->prix_unitaire;
if($facture->fk_client_group_id != null || $facture->fk_client_group_id != 0){
$price = $this->myDb->getProductPriceByClientGroupId($facture->fk_client_group_id,$produit->id);
if($price != null){
$htPrice = $price;
}
}
$facture_temp['montant_htc'] += $htPrice * $produit->quantite;
};
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva'])/100;
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
}
else{
$devis = $this->myDb->getDevisByFkFactureId($facture->id);
$factureGroupIsRelatedToAnyDevis = $devis != null;
$mentionFilters = [
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED
];
try {
try {
$data_factures = array();
$factures = json_decode($this->myDb->getFacturesListWithDependencies());
foreach ($factures as $key => $facture) {
$factureIsSingle = $facture->facture_type == FactureTypeConstant::TYPE_SINGLE;
$facture_temp = array(
'num' => $facture->num,
'client' => $facture->entreprise,
'nom_client' => $facture->nom,
'date' => $facture->date,
'date_facture' => $facture->date_paiement,
'defunt' => $facture->nom_defunt,
'montant_htc' => 0,
'tva' => $current_config[0]->tva_default,
'montant_tva' => 0,
'montant_ttc' => 0,
);
if($factureIsSingle) {
$produits = json_decode($this->getProduitsById($facture->id_devis));
foreach ($produits as $key => $produit) {
$htPrice = $produit->prix_unitaire;
if($facture->fk_client_group_id != null || $facture->fk_client_group_id != 0) {
$price = $this->myDb->getProductPriceByClientGroupId($facture->fk_client_group_id, $produit->id);
if($price != null) {
$htPrice = $price;
}
}
$facture_temp['montant_htc'] += $htPrice * $produit->quantite;
};
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva']) / 100;
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
} else {
$devis = $this->myDb->getDevisByFkFactureId($facture->id);
$factureGroupIsRelatedToAnyDevis = $devis != null;
$mentionFilters = [
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED
];
$isFactureGroupForSingleClient = $facture->facture_client_id != null && $facture->facture_client_id != 0;
if($isFactureGroupForSingleClient){
$facture_temp["client"] = $facture->facture_client_entreprise;
$facture_temp["nom_client"] = $facture->facture_client_name;
if(!$factureGroupIsRelatedToAnyDevis ){
$devisList = $this->myDb->getDevisByClientIdAndMonthYear(
$facture->facture_client_id,
$facture->facture_month,
$facture->facture_year,
$mentionFilters
);
}
}
else{
$facture_temp["client"] = $facture->group_code_comptable ??'-';
$facture_temp["nom_client"] = $facture->facture_group_name;
if(!$factureGroupIsRelatedToAnyDevis ){
$devisList = $this->myDb->getDevisByClientGroupFacturationIdAndMonthYear(
$facture->facture_client_group_facturation_id,
$facture->facture_month,
$facture->facture_year,
[
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED
]
);
}
}
if($factureGroupIsRelatedToAnyDevis){
$devisList = $this->myDb->getDevisByClientIdByFactureId($facture->id, $mentionFilters );
}
$isFactureGroupForSingleClient = $facture->facture_client_id != null && $facture->facture_client_id != 0;
if($isFactureGroupForSingleClient) {
$facture_temp["client"] = $facture->facture_client_entreprise;
$facture_temp["nom_client"] = $facture->facture_client_name;
foreach($devisList as $currentDevis){
$produits = json_decode($this->getProduitsById($currentDevis['id']));
foreach ($produits as $key => $produit) {
$htPrice = $produit->prix_unitaire;
if($currentDevis["fk_client_group_id"] != null || $currentDevis["fk_client_group_id"] != 0){
$price = $this->myDb->getProductPriceByClientGroupId($currentDevis["fk_client_group_id"],$produit->id);
if($price != null){
$htPrice = $price;
}
}
$facture_temp['montant_htc'] += $htPrice * $produit->quantite;
};
}
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva'])/100;
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
}
array_push($data_factures, $facture_temp);
};
$data_temp = array();
foreach ($data_factures as $key => $facture) {
$datesplit = explode('-', $facture['date_facture']);
if($data_temp[strval($datesplit[0])]==NULL) {
$data_temp[strval($datesplit[0])][strval($datesplit[1])] = array(0=>$facture);
} else {
if($data_temp[strval($datesplit[0])][strval($datesplit[1])]==NULL) {
$data_temp[strval($datesplit[0])][strval($datesplit[1])] = array(0=>$facture);
} else {
array_push($data_temp[strval($datesplit[0])][strval($datesplit[1])], $facture);
}
}
}
$fec_headers_txt = [
utf8_decode('JOURNALCODE'),
utf8_decode('JOURNALLIB'),
utf8_decode('ECRITURENUM'),
utf8_decode('ECRITUREDATE'),
utf8_decode('COMPTENUM'),
utf8_decode('COMPTELIB'),
utf8_decode('COMPAUXLIB'),
utf8_decode('COMPAUXNUM'),
utf8_decode('PIECEREF'),
utf8_decode('PIECEDATE'),
utf8_decode('ECRITURELIB'),
utf8_decode('DEBIT'),
utf8_decode('CREDIT'),
utf8_decode('ECRITURELET'),
utf8_decode('DATELET'),
utf8_decode('VALIDDATE'),
utf8_decode('MONTANTDEVISE'),
utf8_decode('IDEVISE'),
];
//parcours annee
foreach ($data_temp as $key_annee => $annee) {
//parcours annee
$_clean_folder = $clean_folder.'FEC/'.$key_annee.'/';
try {
$this->storage->newFolder($_clean_folder);
} catch(\OCP\Files\NotPermittedException $e) { }
foreach ($annee as $key_mois => $mois) {
// Initialize FEC headers
$fec_temp_txt = implode(TAB1, $fec_headers_txt) . PHP_EOL . PHP_EOL;
$fec_temp = implode(';', $fec_headers_txt) . "\n\n";
foreach ($mois as $key => $facture) {
// Define FEC entry data
$fec_entries = [
[
'journal' => 'VT',
'journal_lib' => 'VENTES',
'ecriturenum' => '',
'date' => $facture['date_facture'],
'compte' => $facture['client'],
'libelle_compte' => $facture['client'],
'compauxlib' => '',
'compauxnum' => '',
'piece' => $facture['num'],
'piece_date' => '',
'libelle_ecriture' => $facture['nom_client'],
'debit' => $facture['montant_ttc'],
'credit' => '0',
'ecriture_lettrage' => '',
'date_lettrage' => '',
'valid_date' => '',
'montant_devise' => '',
'devise' => 'EUR',
],
[
'journal' => 'VT',
'journal_lib' => 'VENTES',
'ecriturenum' => '',
'date' => $facture['date_facture'],
'compte' => '706000',
'libelle_compte' => 'VENTES DE MARCHANDISES',
'compauxlib' => '',
'compauxnum' => '',
'piece' => $facture['num'],
'piece_date' => '',
'libelle_ecriture' => $facture['client'],
'debit' => '0',
'credit' => $facture['montant_htc'],
'ecriture_lettrage' => '',
'date_lettrage' => '',
'valid_date' => '',
'montant_devise' => '',
'devise' => 'EUR',
],
[
'journal' => 'VT',
'journal_lib' => 'VENTES',
'ecriturenum' => '',
'date' => $facture['date_facture'],
'compte' => '445710',
'compauxlib' => '',
'compauxnum' => '',
'libelle_compte' => '',
'piece' => $facture['num'],
'piece_date' => '',
'libelle_ecriture' => $facture['client'],
'debit' => '',
'credit' => $facture['montant_tva'],
'ecriture_lettrage' => '',
'date_lettrage' => '',
'valid_date' => '',
'montant_devise' => '',
'devise' => 'EUR',
]
];
// Generate FEC entries
foreach ($fec_entries as $entry) {
$fec_line_txt = [
$entry['journal'], $entry['journal_lib'], $entry['ecriturenum'], $entry['date'],
$entry['compte'], $entry['libelle_compte'],
$entry['compauxlib'], $entry['compauxnum'],
$entry['piece'], $entry['piece_date'],
$entry['libelle_ecriture'], $entry['debit'],$entry['credit'],$entry['ecriture_lettrage'],
$entry['date_lettrage'], $entry['valid_date'], $entry['montant_devise'], $entry['devise']
];
$fec_line_csv = [
$entry['journal'], $entry['journal_lib'], $entry['ecriturenum'], $entry['date'],
$entry['compte'], $entry['libelle_compte'],
$entry['compauxlib'], $entry['compauxnum'],
$entry['piece'], $entry['piece_date'],
$entry['libelle_ecriture'], $entry['debit'],$entry['credit'],$entry['ecriture_lettrage'],
$entry['date_lettrage'], $entry['valid_date'], $entry['montant_devise'], $entry['devise']
];
$fec_temp_txt .= implode(TAB1, $fec_line_txt) . PHP_EOL . PHP_EOL;
$fec_temp .= implode(';', $fec_line_csv) . "\n\n";
}
}
$ff = $_clean_folder.'FEC_'.$key_mois.'_'.$key_annee.'.csv';
$this->storage->newFile($ff);
$file = $this->storage->get($ff);
$file->putContent($fec_temp);
if(!$factureGroupIsRelatedToAnyDevis) {
$devisList = $this->myDb->getDevisByClientIdAndMonthYear(
$facture->facture_client_id,
$facture->facture_month,
$facture->facture_year,
$mentionFilters
);
}
} else {
$facture_temp["client"] = $facture->group_code_comptable ?? '-';
$facture_temp["nom_client"] = $facture->facture_group_name;
$ff_txt = $_clean_folder.'FEC_'.$key_mois.'_'.$key_annee.'.txt';
$this->storage->newFile($ff_txt);
$file_txt = $this->storage->get($ff_txt);
$file_txt->putContent($fec_temp_txt);
// $file->putContent(implode(';', array('Jane Smith', 'janesmith@example.com', '555-5678')) . "\n");
}
}
} catch(\OCP\Files\NotFoundException $e) { }
if(!$factureGroupIsRelatedToAnyDevis) {
$devisList = $this->myDb->getDevisByClientGroupFacturationIdAndMonthYear(
$facture->facture_client_group_facturation_id,
$facture->facture_month,
$facture->facture_year,
[
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED
]
);
}
}
if($factureGroupIsRelatedToAnyDevis) {
$devisList = $this->myDb->getDevisByClientIdByFactureId($facture->id, $mentionFilters);
}
} catch(\OCP\Files\NotPermittedException $e) { }
}
foreach($devisList as $currentDevis) {
$produits = json_decode($this->getProduitsById($currentDevis['id']));
foreach ($produits as $key => $produit) {
$htPrice = $produit->prix_unitaire;
if($currentDevis["fk_client_group_id"] != null || $currentDevis["fk_client_group_id"] != 0) {
$price = $this->myDb->getProductPriceByClientGroupId($currentDevis["fk_client_group_id"], $produit->id);
if($price != null) {
$htPrice = $price;
}
}
$facture_temp['montant_htc'] += $htPrice * $produit->quantite;
};
}
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva']) / 100;
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
}
array_push($data_factures, $facture_temp);
};
$data_temp = array();
foreach ($data_factures as $key => $facture) {
$datesplit = explode('-', $facture['date_facture']);
if($data_temp[strval($datesplit[0])] == null) {
$data_temp[strval($datesplit[0])][strval($datesplit[1])] = array(0 => $facture);
} else {
if($data_temp[strval($datesplit[0])][strval($datesplit[1])] == null) {
$data_temp[strval($datesplit[0])][strval($datesplit[1])] = array(0 => $facture);
} else {
array_push($data_temp[strval($datesplit[0])][strval($datesplit[1])], $facture);
}
}
}
$fec_headers_txt = [
utf8_decode('JOURNALCODE'),
utf8_decode('JOURNALLIB'),
utf8_decode('ECRITURENUM'),
utf8_decode('ECRITUREDATE'),
utf8_decode('COMPTENUM'),
utf8_decode('COMPTELIB'),
utf8_decode('COMPAUXLIB'),
utf8_decode('COMPAUXNUM'),
utf8_decode('PIECEREF'),
utf8_decode('PIECEDATE'),
utf8_decode('ECRITURELIB'),
utf8_decode('DEBIT'),
utf8_decode('CREDIT'),
utf8_decode('ECRITURELET'),
utf8_decode('DATELET'),
utf8_decode('VALIDDATE'),
utf8_decode('MONTANTDEVISE'),
utf8_decode('IDEVISE'),
];
//parcours annee
foreach ($data_temp as $key_annee => $annee) {
//parcours annee
$_clean_folder = $clean_folder.'FEC/'.$key_annee.'/';
try {
$this->storage->newFolder($_clean_folder);
} catch(\OCP\Files\NotPermittedException $e) {
}
foreach ($annee as $key_mois => $mois) {
// Initialize FEC headers
$fec_temp_txt = implode(TAB1, $fec_headers_txt) . PHP_EOL . PHP_EOL;
$fec_temp = implode(';', $fec_headers_txt) . "\n\n";
foreach ($mois as $key => $facture) {
// Define FEC entry data
$fec_entries = [
[
'journal' => 'VT',
'journal_lib' => 'VENTES',
'ecriturenum' => '',
'date' => $facture['date_facture'],
'compte' => $facture['client'],
'libelle_compte' => $facture['client'],
'compauxlib' => '',
'compauxnum' => '',
'piece' => $facture['num'],
'piece_date' => '',
'libelle_ecriture' => $facture['nom_client'],
'debit' => $facture['montant_ttc'],
'credit' => '0',
'ecriture_lettrage' => '',
'date_lettrage' => '',
'valid_date' => '',
'montant_devise' => '',
'devise' => 'EUR',
],
[
'journal' => 'VT',
'journal_lib' => 'VENTES',
'ecriturenum' => '',
'date' => $facture['date_facture'],
'compte' => '706000',
'libelle_compte' => 'VENTES DE MARCHANDISES',
'compauxlib' => '',
'compauxnum' => '',
'piece' => $facture['num'],
'piece_date' => '',
'libelle_ecriture' => $facture['client'],
'debit' => '0',
'credit' => $facture['montant_htc'],
'ecriture_lettrage' => '',
'date_lettrage' => '',
'valid_date' => '',
'montant_devise' => '',
'devise' => 'EUR',
],
[
'journal' => 'VT',
'journal_lib' => 'VENTES',
'ecriturenum' => '',
'date' => $facture['date_facture'],
'compte' => '445710',
'compauxlib' => '',
'compauxnum' => '',
'libelle_compte' => '',
'piece' => $facture['num'],
'piece_date' => '',
'libelle_ecriture' => $facture['client'],
'debit' => '',
'credit' => $facture['montant_tva'],
'ecriture_lettrage' => '',
'date_lettrage' => '',
'valid_date' => '',
'montant_devise' => '',
'devise' => 'EUR',
]
];
// Generate FEC entries
foreach ($fec_entries as $entry) {
$fec_line_txt = [
$entry['journal'], $entry['journal_lib'], $entry['ecriturenum'], $entry['date'],
$entry['compte'], $entry['libelle_compte'],
$entry['compauxlib'], $entry['compauxnum'],
$entry['piece'], $entry['piece_date'],
$entry['libelle_ecriture'], $entry['debit'],$entry['credit'],$entry['ecriture_lettrage'],
$entry['date_lettrage'], $entry['valid_date'], $entry['montant_devise'], $entry['devise']
];
$fec_line_csv = [
$entry['journal'], $entry['journal_lib'], $entry['ecriturenum'], $entry['date'],
$entry['compte'], $entry['libelle_compte'],
$entry['compauxlib'], $entry['compauxnum'],
$entry['piece'], $entry['piece_date'],
$entry['libelle_ecriture'], $entry['debit'],$entry['credit'],$entry['ecriture_lettrage'],
$entry['date_lettrage'], $entry['valid_date'], $entry['montant_devise'], $entry['devise']
];
$fec_temp_txt .= implode(TAB1, $fec_line_txt) . PHP_EOL . PHP_EOL;
$fec_temp .= implode(';', $fec_line_csv) . "\n\n";
}
}
$ff = $_clean_folder.'FEC_'.$key_mois.'_'.$key_annee.'.csv';
$this->storage->newFile($ff);
$file = $this->storage->get($ff);
$file->putContent($fec_temp);
$ff_txt = $_clean_folder.'FEC_'.$key_mois.'_'.$key_annee.'.txt';
$this->storage->newFile($ff_txt);
$file_txt = $this->storage->get($ff_txt);
$file_txt->putContent($fec_temp_txt);
// $file->putContent(implode(';', array('Jane Smith', 'janesmith@example.com', '555-5678')) . "\n");
}
}
} catch(\OCP\Files\NotFoundException $e) {
}
} catch(\OCP\Files\NotPermittedException $e) {
}
}
private function refreshFEC()
{
@ -3659,6 +3662,29 @@ class PageController extends Controller
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param int $defuntId
*/
public function saveAttestationAbsentPacemaker($defuntId, $email = '')
{
try {
$careCertificateFilename = $this->certificateService->generatePacemakerAbsentCertificate($defuntId, $this->idNextcloud);
if($careCertificateFilename != null && trim($email) != '') {
//send email
$this->sendAttachmentToClientByDefunt($defuntId, $careCertificateFilename, $email, "Retrait de pile", "Vous trouverez en pièce jointe l'attestation de retrait de pile ", true);
}
return $careCertificateFilename;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired

View File

@ -29,119 +29,124 @@ namespace OCA\Gestion\Service\Certificate;
use DateTime;
use DateTimeImmutable;
use OCA\Gestion\Db\Bdd;
use OCP\Files\IRootFolder;
use OCA\Gestion\Helpers\DateHelpers;
use OCA\Gestion\Service\Certificate\PdfHandler\CareCertificatePdfHandler;
use OCA\Gestion\Service\Certificate\PdfHandler\PacemakerCertificatePdfHandler;
use OCP\Files\IRootFolder;
use OCA\Gestion\Service\Certificate\PdfHandler\PacemakerAbsentCertificatePdfHandler;
class CertificateService {
/** @var Bdd */
private $gestionBdd;
class CertificateService
{
/** @var Bdd */
private $gestionBdd;
/** @var IRootFolder */
private $rootFolder;
private $rootFolder;
private const DEFAULT_NEXTCLOUD_ADMIN = "admin";
public function __construct(
Bdd $gestionBdd,
IRootFolder $rootFolder) {
public function __construct(
Bdd $gestionBdd,
IRootFolder $rootFolder
) {
$this->gestionBdd = $gestionBdd;
$this->rootFolder = $rootFolder;
}
}
private function signatureImageExists(){
private function signatureImageExists()
{
$storage = $this->rootFolder->getUserFolder(self::DEFAULT_NEXTCLOUD_ADMIN);
try{
if(isset($storage)){
$storage->get("/.gestion/sign.png");
try {
if(isset($storage)) {
$storage->get("/.gestion/sign.png");
$signatureExist = true;
}else{
$signatureExist = false;
}
}
catch(\OCP\Files\NotFoundException $e) {
$signatureExist = false;
}
return $signatureExist;
}
private function tamponImageExist(){
} else {
$signatureExist = false;
}
} catch(\OCP\Files\NotFoundException $e) {
$signatureExist = false;
}
return $signatureExist;
}
private function tamponImageExist()
{
$storage = $this->rootFolder->getUserFolder(self::DEFAULT_NEXTCLOUD_ADMIN);
try{
if(isset($storage)){
$storage->get("/.gestion/sign.jpg"); // tampon image
try {
if(isset($storage)) {
$storage->get("/.gestion/sign.jpg"); // tampon image
$signatureExist = true;
}else{
$signatureExist = false;
}
}
catch(\OCP\Files\NotFoundException $e) {
$signatureExist = false;
}
return $signatureExist;
}
} else {
$signatureExist = false;
}
} catch(\OCP\Files\NotFoundException $e) {
$signatureExist = false;
}
return $signatureExist;
}
private function getLogo(){
private function getLogo()
{
$storage = $this->rootFolder->getUserFolder(self::DEFAULT_NEXTCLOUD_ADMIN);
try{
try {
if(isset($storage)){
$file = $storage->get('/.gestion/logo.png');
}else{
return "nothing";
}
} catch(\OCP\Files\NotFoundException $e) {
$file = $storage->get('/.gestion/logo.jpeg');
}
}
catch(\OCP\Files\NotFoundException $e) {
return "nothing";
}
return base64_encode($file->getContent());
}
try {
try {
if(isset($storage)) {
$file = $storage->get('/.gestion/logo.png');
} else {
return "nothing";
}
} catch(\OCP\Files\NotFoundException $e) {
$file = $storage->get('/.gestion/logo.jpeg');
}
} catch(\OCP\Files\NotFoundException $e) {
return "nothing";
}
return base64_encode($file->getContent());
}
private function setDevisOfDefuntDefaultValue($devisOfDefunt){
private function setDevisOfDefuntDefaultValue($devisOfDefunt)
{
$devisOfDefunt["devis_date"] = new DateTimeImmutable($devisOfDefunt["devis_date"]);
$locationOfDevis = "";
if($devisOfDefunt['lieu_nom'] != null){
if($devisOfDefunt['lieu_nom'] != null) {
$locationOfDevis .= $devisOfDefunt['lieu_nom'];
}
if($devisOfDefunt['lieu_adresse'] != null){
if($devisOfDefunt['lieu_adresse'] != null) {
$locationOfDevis .= " ". $devisOfDefunt['lieu_adresse'];
}
$devisOfDefunt['location_of_devis'] = $locationOfDevis;
if($devisOfDefunt['thanato_nom'] == null){
if($devisOfDefunt['thanato_nom'] == null) {
$devisOfDefunt['thanato_nom'] = "";
}
if($devisOfDefunt['thanato_prenom'] == null){
if($devisOfDefunt['thanato_prenom'] == null) {
$devisOfDefunt['thanato_prenom'] = "";
}
if($devisOfDefunt['thanato_reference'] == null){
if($devisOfDefunt['thanato_reference'] == null) {
$devisOfDefunt['thanato_reference'] = "";
}
if($devisOfDefunt['client_nom'] == null){
if($devisOfDefunt['client_nom'] == null) {
$devisOfDefunt['client_nom'] = "";
}
if($devisOfDefunt['client_prenom'] == null){
if($devisOfDefunt['client_prenom'] == null) {
$devisOfDefunt['client_prenom'] = "";
}
if($devisOfDefunt['client_entreprise'] == null){
if($devisOfDefunt['client_entreprise'] == null) {
$devisOfDefunt['client_entreprise'] = "";
}
if($devisOfDefunt['client_adresse'] == null){
if($devisOfDefunt['client_adresse'] == null) {
$devisOfDefunt['client_adresse'] = "";
}
return $devisOfDefunt;
}
public function generateCareCertificate($defuntId,$idNextCloud){
public function generateCareCertificate($defuntId, $idNextCloud)
{
$storage = $this->rootFolder->getUserFolder($idNextCloud);
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$currentConfig = $configs[0];
$logo = $this->getLogo();
$devisOfDefunt = $this->gestionBdd->getDevisOfDefunt($defuntId);
if($devisOfDefunt == null){
return null;
}
$currentConfig = $configs[0];
$logo = $this->getLogo();
$devisOfDefunt = $this->gestionBdd->getDevisOfDefunt($defuntId);
if($devisOfDefunt == null) {
return null;
}
$devisOfDefunt["configuration"] = $currentConfig;
$devisOfDefunt = $this->setDevisOfDefuntDefaultValue($devisOfDefunt);
$clean_folder = html_entity_decode(string: $currentConfig->path).'/';
@ -150,63 +155,67 @@ class CertificateService {
$pdfFilename = $this->GetCareCertificateFilename($devisOfDefunt);
$filenamePath = $clean_folder.$careCertificateFolder.$pdfFilename.'.pdf';
$pdf = new CareCertificatePdfHandler();
$pdf->AddFont('ComicSans','','Comic Sans MS.php');
$pdf->AddFont('ComicSans','B','comic-sans-bold.php');
$pdf->AddFont('ComicSans', '', 'Comic Sans MS.php');
$pdf->AddFont('ComicSans', 'B', 'comic-sans-bold.php');
$signatureImageExist = $this->signatureImageExists();
$tamponImageExist = $this->tamponImageExist();
$pdf->SetCareCertificateData($devisOfDefunt,$logo,$signatureImageExist ,$tamponImageExist);
$pdf->SetCareCertificateData($devisOfDefunt, $logo, $signatureImageExist, $tamponImageExist);
$pdf->SetCareCertificate();
try {
$storage->newFolder($folderDestination);
}
catch(\OCP\Files\NotPermittedException $e) {
} catch(\OCP\Files\NotPermittedException $e) {
}
$pdfContent = $pdf->Output('','S');
$pdfContent = $pdf->Output('', 'S');
$storage->newFile($filenamePath);
$pdfFile = $storage->get($filenamePath);
$pdfFile->putContent($pdfContent);
return $filenamePath;
}
private function getCareCertificateFolder($devisOfDefunt){
private function getCareCertificateFolder($devisOfDefunt)
{
$careCertificateFolder = 'CLIENTS/'
.mb_strtoupper($devisOfDefunt["client_nom"],'UTF-8')
.mb_strtoupper($devisOfDefunt["client_nom"], 'UTF-8')
.'/DEFUNTS/'
.mb_strtoupper($devisOfDefunt["defunt_nom"],'UTF-8').'/'
.mb_strtoupper($devisOfDefunt["defunt_nom"], 'UTF-8').'/'
.'ATTESTATION/';
return $careCertificateFolder;
}
private function GetCareCertificateFilename($devisOfDefunt){
$filename = 'ATTESTATION_SOIN_'.mb_strtoupper($devisOfDefunt['defunt_nom'],'UTF-8');
private function GetCareCertificateFilename($devisOfDefunt)
{
$filename = 'ATTESTATION_SOIN_'.mb_strtoupper($devisOfDefunt['defunt_nom'], 'UTF-8');
return $filename;
}
private function getPacemakerCertificateFolder($devisOfDefunt){
private function getPacemakerCertificateFolder($devisOfDefunt)
{
$folder = 'CLIENTS/'
.mb_strtoupper($devisOfDefunt["client_nom"],'UTF-8')
.mb_strtoupper($devisOfDefunt["client_nom"], 'UTF-8')
.'/DEFUNTS/'
.mb_strtoupper($devisOfDefunt["defunt_nom"],'UTF-8').'/'
.mb_strtoupper($devisOfDefunt["defunt_nom"], 'UTF-8').'/'
.'ATTESTATION/';
return $folder;
}
private function getPacemakerCertificateFilename($devisOfDefunt){
$filename = 'ATTESTATION_PACEMAKER_'.mb_strtoupper($devisOfDefunt['defunt_nom'],'UTF-8');
private function getPacemakerCertificateFilename($devisOfDefunt)
{
$filename = 'ATTESTATION_PACEMAKER_'.mb_strtoupper($devisOfDefunt['defunt_nom'], 'UTF-8');
return $filename;
}
public function generatePacemakerCertificate($defuntId,$idNextCloud){
public function generatePacemakerCertificate($defuntId, $idNextCloud)
{
$storage = $this->rootFolder->getUserFolder($idNextCloud);
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$currentConfig = $configs[0];
$logo = $this->getLogo();
$devisOfDefunt = $this->gestionBdd->getDevisOfDefunt($defuntId);
if($devisOfDefunt == null){
return null;
}
$currentConfig = $configs[0];
$logo = $this->getLogo();
$devisOfDefunt = $this->gestionBdd->getDevisOfDefunt($defuntId);
if($devisOfDefunt == null) {
return null;
}
$devisOfDefunt["configuration"] = $currentConfig;
$devisOfDefunt = $this->setDevisOfDefuntDefaultValue($devisOfDefunt);
$clean_folder = html_entity_decode(string: $currentConfig->path).'/';
@ -215,18 +224,58 @@ class CertificateService {
$pdfFilename = $this->getPacemakerCertificateFilename($devisOfDefunt);
$filenamePath = $clean_folder.$pacemakerCertificateFolder.$pdfFilename.'.pdf';
$pdf = new PacemakerCertificatePdfHandler();
$pdf->AddFont('ComicSans','','Comic Sans MS.php');
$pdf->AddFont('ComicSans','B','comic-sans-bold.php');
$pdf->AddFont('ComicSans', '', 'Comic Sans MS.php');
$pdf->AddFont('ComicSans', 'B', 'comic-sans-bold.php');
$signatureImageExist = $this->signatureImageExists();
$tamponImageExist = $this->tamponImageExist();
$pdf->SetPacemakerCertificateData($devisOfDefunt,$logo,$signatureImageExist ,$tamponImageExist);
$pdf->SetPacemakerCertificateData($devisOfDefunt, $logo, $signatureImageExist, $tamponImageExist);
$pdf->SetPacemakerCertificate();
try {
$storage->newFolder($folderDestination);
}
catch(\OCP\Files\NotPermittedException $e) {
} catch(\OCP\Files\NotPermittedException $e) {
}
$pdfContent = $pdf->Output('','S');
$pdfContent = $pdf->Output('', 'S');
$storage->newFile($filenamePath);
$pdfFile = $storage->get($filenamePath);
$pdfFile->putContent($pdfContent);
return $filenamePath;
}
private function getPacemakerAbsentCertificateFilename($devisOfDefunt)
{
$filename = 'ATTESTATION_ABSENCE_PACEMAKER_'.mb_strtoupper($devisOfDefunt['defunt_nom'], 'UTF-8');
return $filename;
}
public function generatePacemakerAbsentCertificate($defuntId, $idNextCloud)
{
$storage = $this->rootFolder->getUserFolder($idNextCloud);
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$currentConfig = $configs[0];
$logo = $this->getLogo();
$devisOfDefunt = $this->gestionBdd->getDevisOfDefunt($defuntId);
if($devisOfDefunt == null) {
return null;
}
$devisOfDefunt["configuration"] = $currentConfig;
$devisOfDefunt = $this->setDevisOfDefuntDefaultValue($devisOfDefunt);
$clean_folder = html_entity_decode(string: $currentConfig->path).'/';
$pacemakerCertificateFolder = $this->getPacemakerCertificateFolder($devisOfDefunt);
$folderDestination = $clean_folder.$pacemakerCertificateFolder;
$pdfFilename = $this->getPacemakerAbsentCertificateFilename($devisOfDefunt);
$filenamePath = $clean_folder.$pacemakerCertificateFolder.$pdfFilename.'.pdf';
$pdf = new PacemakerAbsentCertificatePdfHandler();
$pdf->AddFont('ComicSans', '', 'Comic Sans MS.php');
$pdf->AddFont('ComicSans', 'B', 'comic-sans-bold.php');
$signatureImageExist = $this->signatureImageExists();
$tamponImageExist = $this->tamponImageExist();
$pdf->SetPacemakerCertificateData($devisOfDefunt, $logo, $signatureImageExist, $tamponImageExist);
$pdf->SetPacemakerCertificate();
try {
$storage->newFolder($folderDestination);
} catch(\OCP\Files\NotPermittedException $e) {
}
$pdfContent = $pdf->Output('', 'S');
$storage->newFile($filenamePath);
$pdfFile = $storage->get($filenamePath);
$pdfFile->putContent($pdfContent);

View File

@ -0,0 +1,239 @@
<?php
declare(strict_types=1);
/**
* Calendar App
*
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Gestion\Service\Certificate\PdfHandler;
use DateTime;
use FPDF;
use OCA\Gestion\Helpers\DateHelpers;
use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Helpers\PriceHelpers;
class PacemakerAbsentCertificatePdfHandler extends FPDF
{
private $devisOfDefunt = [];
private $logo = null;
private $signatureImageExist = false;
private $tamponImageExist = false;
private $imagePath = "/var/www/html/data/admin/files/.gestion/";
public function Header()
{
if ($this->logo != "nothing") {
$this->Image($this->imagePath . "logo.png", 10, 10, 50, 35);
}
// En-tête avec les informations de l'entreprise - SOUS le logo
$this->SetXY(10, 50); // Position sous le logo
$this->SetFont('Arial', 'B', 12);
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport($this->devisOfDefunt['configuration']->entreprise), 0, 1);
$this->SetFont('Arial', '', 10);
$this->MultiCell(0, 4, FileExportHelpers::FormatTextForExport($this->devisOfDefunt['configuration']->adresse), 0, 'L');
if (isset($this->devisOfDefunt['configuration']->telephone)) {
$this->Cell(0, 4, 'Tel : ' . FileExportHelpers::FormatTextForExport($this->devisOfDefunt['configuration']->telephone), 0, 1);
}
if (isset($this->devisOfDefunt['thanato_reference'])) {
$this->Cell(0, 4, 'Habilitation : ' . FileExportHelpers::FormatTextForExport($this->devisOfDefunt['thanato_reference']), 0, 1);
}
if (isset($this->devisOfDefunt['configuration']->siret)) {
$this->Cell(0, 4, 'Siret : ' . FileExportHelpers::FormatTextForExport($this->devisOfDefunt['configuration']->siret), 0, 1);
}
}
public function Footer()
{
$this->SetY(-15);
$this->MultiCell(0, 5, utf8_decode(html_entity_decode($this->devisOfDefunt['configuration']->legal_one)), 0, 'C');
$this->MultiCell(0, 5, utf8_decode(html_entity_decode($this->devisOfDefunt['configuration']->adresse)), 0, 'C');
}
public function SetPacemakerCertificateData(array $devisOfDefunt, $logo = null, $signatureImageExist = false, $tamponImageExist = false)
{
$this->devisOfDefunt = $devisOfDefunt;
$this->logo = $logo;
$this->signatureImageExist = $signatureImageExist;
$this->tamponImageExist = $tamponImageExist;
}
public function SetPacemakerCertificate()
{
$this->AddPage();
$this->SetMargins(left: 20, top: 0, right: 20);
$this->SetPacemakerCertificateTitle();
$this->SetPacemakerCertificateContent();
}
private function SetPacemakerCertificateContent()
{
$this->SetY(100); // Position réduite après le titre
$this->SetFont('Arial', '', 12);
// Déterminer le genre selon la civilité
$civilite = isset($this->devisOfDefunt['thanato_civilite']) ? $this->devisOfDefunt['thanato_civilite'] : 'Madame';
$pronom = 'Je soussignée';
$profession = 'thanatopractrice diplômée';
// Adaptation selon la civilité
if (strtolower($civilite) === 'monsieur' || strtolower($civilite) === 'm.' || strtolower($civilite) === 'mr') {
$pronom = 'Je soussigné';
$profession = 'thanatopracteur diplômé';
}
// Texte principal avec genre adapté
$mainText = $pronom . ', ' . $civilite . ' ' .
mb_convert_encoding(html_entity_decode($this->devisOfDefunt['thanato_prenom']), 'ISO-8859-1', 'UTF-8'). ' ' .mb_convert_encoding(html_entity_decode($this->devisOfDefunt['thanato_nom']), 'ISO-8859-1', 'UTF-8').
', ' . $profession . ', certifie ne pas avoir constaté, à la palpation, la présence d\'un pacemaker pour :';
$this->MultiCell(0, 6, FileExportHelpers::FormatTextForExport($mainText));
$this->Ln(8);
// Nom du défunt
$this->SetFont('Arial', 'B', 12);
$this->Cell(20, 8, 'Nom :', 0, 0);
$this->SetFont('Arial', '', 12);
$this->Cell(0, 8, FileExportHelpers::FormatTextForExport(mb_convert_encoding(html_entity_decode($this->devisOfDefunt['defunt_nom']), 'ISO-8859-1', 'UTF-8')), 0, 1);
$this->Ln(3);
// Date
$this->SetFont('Arial', 'B', 12);
$this->Cell(20, 8, 'Date :', 0, 0);
$this->SetFont('Arial', '', 12);
if (isset($this->devisOfDefunt['devis_date'])) {
$this->Cell(0, 8, $this->devisOfDefunt['devis_date']->format('d/m/Y'), 0, 1);
} else {
$this->Cell(0, 8, '', 0, 1);
}
$this->Ln(3);
// Lieu d'intervention
$this->SetFont('Arial', 'B', 12);
$this->Cell(40, 8, 'Lieu d\'intervention :', 0, 0);
$this->SetFont('Arial', '', 12);
$lieu = isset($this->devisOfDefunt['lieu_intervention']) ?
$this->devisOfDefunt['lieu_intervention'] :
$this->devisOfDefunt['location_of_devis'];
// Utiliser MultiCell pour permettre le retour à la ligne
$this->SetX(20); // Retour au début de la ligne
$this->SetFont('Arial', 'B', 12);
$this->Cell(40, 8, 'Lieu d\'intervention :', 0, 1); // 1 pour aller à la ligne suivante
$this->SetFont('Arial', '', 12);
$this->MultiCell(0, 6, FileExportHelpers::FormatTextForExport($lieu), 0, 'L');
// Signatures et cachet - juste après le lieu d'intervention
$this->Ln(15); // Petit espace après le lieu d'intervention
if ($this->signatureImageExist) {
$this->Image($this->imagePath."sign.png", 140, $this->GetY(), 40, 16);
}
if($this->tamponImageExist) {
$this->SetXY(120, $this->GetY() + 20); // Augmenté de 5 à 20 pour plus d'espace
$this->Image($this->imagePath."sign.jpg", 120, $this->GetY(), 80, 35);
}
}
private function SetPacemakerCertificateTitle()
{
$this->SetY(y: 85); // Titre plus bas pour éviter l'en-tête
$this->SetFont('Arial', 'B', 16);
$this->Cell(0, 10, FileExportHelpers::FormatTextForExport('ATTESTATION D\'ABSENCE DE PACEMAKER'), 0, 1, 'C');
$this->Ln(5); // Espace réduit après le titre
}
public function MultiAlignCell($w, $h, $text, $border = 0, $ln = 0, $align = 'L', $fill = false)
{
// Store reset values for (x,y) positions
$x = $this->GetX() + $w;
$y = $this->GetY();
// Make a call to FPDF's MultiCell
$this->MultiCell($w, $h, $text, $border, $align, $fill);
// Reset the line position to the right, like in Cell
if ($ln == 0) {
$this->SetXY($x, $y);
}
}
public function NbLines($w, $txt)
{
// Compute the number of lines a MultiCell of width w will take
if (!isset($this->CurrentFont)) {
$this->Error('No font has been set');
}
$cw = $this->CurrentFont['cw'];
if ($w == 0) {
$w = $this->w - $this->rMargin - $this->x;
}
$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;
$s = str_replace("\r", '', (string) $txt);
$nb = strlen($s);
if ($nb > 0 && $s[$nb - 1] == "\n") {
$nb--;
}
$sep = -1;
$i = 0;
$j = 0;
$l = 0;
$nl = 1;
while ($i < $nb) {
$c = $s[$i];
if ($c == "\n") {
$i++;
$sep = -1;
$j = $i;
$l = 0;
$nl++;
continue;
}
if ($c == ' ') {
$sep = $i;
}
$l += $cw[$c];
if ($l > $wmax) {
if ($sep == -1) {
if ($i == $j) {
$i++;
}
} else {
$i = $sep + 1;
}
$sep = -1;
$j = $i;
$l = 0;
$nl++;
} else {
$i++;
}
}
return $nl;
}
}

View File

@ -4,7 +4,7 @@ import "datatables.net-dt/css/jquery.dataTables.css";
import "../css/mycss.css";
import "./listener/main_listener";
import { getBibliotheques, exportCareCertificate,getBijouxById, getHypodermiquesyId, getObservationsById, getproduits, saveAttestationPacemaker, saveRapportBijoux, saveRapportSoin, setBijouxPhoto, setDefuntCover, setDefuntPacemakerPhoto, updateDB } from "./modules/ajaxRequest.mjs";
import { getBibliotheques, exportCareCertificate,getBijouxById, getHypodermiquesyId, getObservationsById, getproduits, saveAttestationPacemaker, saveAttestationAbsentPacemaker, saveRapportBijoux, saveRapportSoin, setBijouxPhoto, setDefuntCover, setDefuntPacemakerPhoto, updateDB } from "./modules/ajaxRequest.mjs";
import { globalConfiguration } from "./modules/mainFunction.mjs";
let bibliotheques = [];
@ -77,6 +77,7 @@ window.addEventListener("DOMContentLoaded", function () {
});
var pacemakerBtn = document.getElementById("pacemakerBtn");
var pacemakerAbsentBtn = document.getElementById("pacemakerAbsentBtn");
var rapportSoinBtn = document.getElementById("rapportSoinBtn");
var exportCareCertificateButton = document.getElementById("exportCareCertificate");
var setDefuntCoverButton = this.document.getElementById("coverProductsSetButton");
@ -144,6 +145,9 @@ window.addEventListener("DOMContentLoaded", function () {
case 'pacemaker':
saveAttestationPacemaker({ defuntId: defuntid ,email: isSendEmail ? email: ''});
break;
case 'pacemakerAbsent':
saveAttestationAbsentPacemaker({ defuntId: defuntid ,email: isSendEmail ? email: ''});
break;
case 'rapport-soin':
saveRapportSoin({ numdefunt: defuntid ,email: isSendEmail ? email: ''});
break;
@ -182,6 +186,12 @@ window.addEventListener("DOMContentLoaded", function () {
modalElement.modal('show')
// saveAttestationPacemaker({ defuntId: defuntid });
});
pacemakerAbsentBtn.addEventListener("click", function(){
modalTitle.text("Générer l'attestation d'absence pacemaker")
modalElement.data('export-type', 'pacemakerAbsent')
modalElement.modal('show')
// saveAttestationPacemaker({ defuntId: defuntid });
});
rapportSoinBtn.addEventListener("click", function(){
modalElement.data('export-type', 'rapport-soin')

View File

@ -678,6 +678,31 @@ export function saveAttestationPacemaker(myData) {
});
};
/**
* Save pdf in nextcloud
* @param {*} myData
*/
export function saveAttestationAbsentPacemaker(myData) {
showLoader();
$.ajax({
url: baseUrl + '/saveAttestationAbsentPacemaker',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(myData)
}).done(function (response) {
if(!response) {
showMessage('Ce defunt n\'appartient à aucun devis.');
} else {
showSuccess('Sauvegardé dans '+ response);
}
}).fail(function (response, code) {
showMessage(t('gestion', 'Erreur dans la génération d\'attestation pacemaker'));
}).always(function () {
hideLoader();
});
};
/**
* Save pdf in nextcloud
* @param {*} myData

View File

@ -30,6 +30,7 @@ $coverProducts = $_['coverProducts'];
<div class="div">
<button id="exportCareCertificate" class="btn btn-secondary" type="button">Générer l'attestation de soins</button>
<button id="pacemakerBtn" class="btn btn-secondary" type="button">Générer l'attestation retrait de pile</button>
<button id="pacemakerAbsentBtn" class="btn btn-secondary" type="button">Générer l'attestation d'Absence de Pacemacker</button>
<button id="rapportSoinBtn" class="btn btn-secondary" type="button">Générer le rapport de soins</button>
<button id="showRapportBijouxExportModal" class="btn btn-secondary" type="button" data-toggle="modal" data-target="#saveRapportBijouxModal">Générer le rapport des bijoux</button>
</div>