Compare commits
No commits in common. "production-hfc" and "develop-tolotsoa" have entirely different histories.
production
...
develop-to
@ -161,6 +161,7 @@
|
||||
:is-read-only="isReadOnly"
|
||||
:prop-model="rfcProps.absenceType"
|
||||
:noWrap='true'
|
||||
sle
|
||||
@update:value="updateAbsenceType" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -99,7 +99,6 @@ 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
@ -2028,268 +2028,265 @@ 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;
|
||||
|
||||
$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->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 );
|
||||
}
|
||||
|
||||
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;
|
||||
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->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);
|
||||
}
|
||||
$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) { }
|
||||
|
||||
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) {
|
||||
}
|
||||
}
|
||||
} catch(\OCP\Files\NotPermittedException $e) { }
|
||||
}
|
||||
|
||||
private function refreshFEC()
|
||||
{
|
||||
@ -3662,29 +3659,6 @@ 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
|
||||
|
||||
@ -2615,7 +2615,7 @@ class Bdd
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getThanatoDevisListByDateSave($thanatoId, $date)
|
||||
private function getThanatoDevisListByDate($thanatoId, $date)
|
||||
{
|
||||
$dateFormatted = $date->format('Y-m-d');
|
||||
$sql = "SELECT
|
||||
@ -2656,42 +2656,6 @@ class Bdd
|
||||
return $devisList;
|
||||
}
|
||||
|
||||
private function getThanatoDevisListByDate($thanatoId, $date)
|
||||
{
|
||||
$dateFormatted = $date->format('Y-m-d');
|
||||
$sql = "SELECT
|
||||
devis.id,
|
||||
devis.date,
|
||||
devis.mentions,
|
||||
devis.num as calendar_uuid,
|
||||
devis.id_defunt as id_defunt,
|
||||
devis.id_lieu as id_lieu,
|
||||
devis.id_client as id_client,
|
||||
devis.id_thanato as id_thanato,
|
||||
thanato.nom as nom_thanato,
|
||||
thanato.prenom as prenom_thanato,
|
||||
defunt.nom as nom_defunt,
|
||||
lieu.nom as nom_lieu,
|
||||
lieu.latitude as lieu_latitude,
|
||||
lieu.longitude as lieu_longitude,
|
||||
client.nom as nom_client,
|
||||
client.entreprise as client_entreprise,
|
||||
client.adresse as client_adresse
|
||||
FROM ".$this->tableprefix."devis as devis
|
||||
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
||||
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
|
||||
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
||||
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
||||
WHERE devis.date = ? AND
|
||||
devis.id_thanato = ?
|
||||
ORDER BY devis.date ASC;";
|
||||
$devisList = $this->execSQLNoJsonReturn(
|
||||
$sql,
|
||||
[$dateFormatted,$thanatoId]
|
||||
);
|
||||
return $devisList;
|
||||
}
|
||||
|
||||
public function getThanatoById($thanatoId)
|
||||
{
|
||||
$sql = "SELECT id, nom, prenom,fk_user_uuid FROM ".$this->tableprefix."thanato WHERE id = ? LIMIT 1;";
|
||||
@ -3189,7 +3153,7 @@ class Bdd
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function getClientFactureStatisticPerMonthSave($clientId, array $produitList)
|
||||
private function getClientFactureStatisticPerMonth($clientId, array $produitList)
|
||||
{
|
||||
$currentYear = date('Y');
|
||||
$monthLists = range(1, 12);
|
||||
@ -3210,11 +3174,12 @@ class Bdd
|
||||
LEFT JOIN ".$this->tableprefix."devis as devis on facture.id_devis = devis.id
|
||||
WHERE YEAR(facture.date_paiement) = ? AND
|
||||
MONTH(facture.date_paiement) = ? AND
|
||||
devis.id_client = ?
|
||||
devis.id_client = ? AND
|
||||
(devis.mentions = ? OR devis.mentions = ?)
|
||||
ORDER BY facture.date_paiement ASC;";
|
||||
$factureList = $this->execSQLNoJsonReturn(
|
||||
$sql,
|
||||
[$currentYear,$monthValue,$clientId]
|
||||
[$currentYear,$monthValue,$clientId,DevisMentionConstant::FACTURED,DevisMentionConstant::FACTURED_FORMATTED]
|
||||
);
|
||||
|
||||
$factureDevisIds = [];
|
||||
@ -3244,58 +3209,6 @@ class Bdd
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getClientFactureStatisticPerMonth($clientId, array $produitList, $clientGroupId = null)
|
||||
{
|
||||
$currentYear = date('Y');
|
||||
$monthLists = range(1, 12);
|
||||
$data = [] ;
|
||||
foreach($monthLists as $monthValue) {
|
||||
if(!isset($data[$monthValue])) {
|
||||
$data[$monthValue] = [];
|
||||
}
|
||||
$sql = "SELECT
|
||||
devis.id as devis_id,
|
||||
devis.id_client as devis_client_id,
|
||||
devis.date as devis_date,
|
||||
devis.mentions as devis_mention
|
||||
FROM ".$this->tableprefix."devis as devis
|
||||
WHERE YEAR(devis.date) = ? AND
|
||||
MONTH(devis.date) = ? AND
|
||||
devis.id_client = ?
|
||||
ORDER BY devis.date ASC;";
|
||||
$factureList = $this->execSQLNoJsonReturn(
|
||||
$sql,
|
||||
[$currentYear,$monthValue,$clientId]
|
||||
);
|
||||
|
||||
$factureDevisIds = [];
|
||||
foreach($factureList as $facture) {
|
||||
$factureDevisIds[] = $facture['devis_id'];
|
||||
}
|
||||
|
||||
$defuntCount = count($factureList);
|
||||
$produitsPrice = 0;
|
||||
$statisticForeachProductPerMonth = [];
|
||||
foreach($produitList as $produit) {
|
||||
if(!isset($statisticForeachProductPerMonth[$produit['id']])) {
|
||||
$statisticForeachProductPerMonth[$produit['id']] = 0;
|
||||
}
|
||||
$productTotalCount = $this->getDevisProductsQuantityByDevisListAndProductId($factureDevisIds, $produit['id']);
|
||||
$prixUnitaire = is_null($clientGroupId) ? $produit["prix_unitaire"] : $this->getProductPriceByClientGroupId($clientGroupId, $produit['id']);
|
||||
$totalWithoutVat = $productTotalCount * $prixUnitaire;
|
||||
$statisticForeachProductPerMonth[$produit['id']] += $productTotalCount;
|
||||
$produitsPrice += $totalWithoutVat;
|
||||
}
|
||||
$data[$monthValue] = [
|
||||
"defunt_count" => $defuntCount,
|
||||
"total_price" => $produitsPrice,
|
||||
"year" => $currentYear,
|
||||
"products" => $statisticForeachProductPerMonth
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getExportClientStatData(array $clientIds)
|
||||
{
|
||||
$data = [];
|
||||
@ -3309,10 +3222,9 @@ class Bdd
|
||||
$client = $this->getClientById($clientId);
|
||||
if($client != null) {
|
||||
$clientName = trim($client["client_nom"]) . '-' .trim($client['client_entreprise']);
|
||||
$clientGroupId = $client['fk_client_group_id'];
|
||||
}
|
||||
$data[$clientId]["client_name"] = $clientName;
|
||||
$data[$clientId]["client_data"] = $this->getClientFactureStatisticPerMonth($clientId, $produitList, $clientGroupId);
|
||||
$data[$clientId]["client_data"] = $this->getClientFactureStatisticPerMonth($clientId, $produitList);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
@ -3572,7 +3484,6 @@ class Bdd
|
||||
devis.comment as devis_comment,
|
||||
devis.id_client as devis_id_client,
|
||||
devis.devis_full_number,
|
||||
devis.mentions,
|
||||
client.nom as client_nom,
|
||||
client.entreprise as client_entreprise,
|
||||
client.adresse as client_adresse,
|
||||
@ -3627,7 +3538,6 @@ class Bdd
|
||||
devis.comment as devis_comment,
|
||||
devis.id_client as devis_id_client,
|
||||
devis.devis_full_number,
|
||||
devis.mentions,
|
||||
client.nom as client_nom,
|
||||
client.entreprise as client_entreprise,
|
||||
client.adresse as client_adresse,
|
||||
|
||||
@ -29,124 +29,119 @@ 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 OCA\Gestion\Service\Certificate\PdfHandler\PacemakerAbsentCertificatePdfHandler;
|
||||
use OCP\Files\IRootFolder;
|
||||
|
||||
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).'/';
|
||||
@ -155,67 +150,63 @@ 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).'/';
|
||||
@ -224,58 +215,18 @@ 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');
|
||||
$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');
|
||||
$pdfContent = $pdf->Output('','S');
|
||||
$storage->newFile($filenamePath);
|
||||
$pdfFile = $storage->get($filenamePath);
|
||||
$pdfFile->putContent($pdfContent);
|
||||
|
||||
@ -1,239 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@ -23,11 +23,6 @@ class DevisDataProcessor
|
||||
$data_devis = [];
|
||||
|
||||
foreach ($devisData as $devis) {
|
||||
// Exclure les devis annulés des récapitulatifs
|
||||
if (isset($devis['mentions']) && $devis['mentions'] === 'CANCELED') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$devis_temp = $this->createDevisStructure($devis, $currentConfig);
|
||||
$devis_temp = $this->calculateDevisAmounts($devis_temp, $devis, $filter, $idNextCloud);
|
||||
$data_devis[] = $devis_temp;
|
||||
@ -46,8 +41,6 @@ class DevisDataProcessor
|
||||
'devis_date' => $devis['devis_date'],
|
||||
'lieu_nom' => $devis['lieu_nom'],
|
||||
'lieu_adresse' => $devis['lieu_adresse'],
|
||||
'thanato_nom' => $devis['thanato_nom'],
|
||||
'thanato_prenom' => $devis['thanato_prenom'],
|
||||
'defunt_nom' => $devis['defunt_nom'],
|
||||
'defunt_sexe' => $devis['defunt_sexe'],
|
||||
'client_nom' => $devis['client_nom'],
|
||||
@ -85,9 +78,9 @@ class DevisDataProcessor
|
||||
}
|
||||
|
||||
// Traitement identique aux factures
|
||||
// $produitsReferenceArray = array_unique($produitsReferenceArray);
|
||||
$produitsReferenceArray = array_unique($produitsReferenceArray);
|
||||
$produitsReferenceAsString = implode("-", $produitsReferenceArray);
|
||||
$devis_temp['article'] = !empty($produitsReferenceAsString) ? $produitsReferenceAsString : '';
|
||||
$devis_temp['article'] = !empty($produitsReferenceAsString) ? $produitsReferenceAsString : 'SOINS';
|
||||
|
||||
$devis_temp['montant_tva'] = ($devis_temp['montant_htc'] * $devis_temp['tva']) / 100;
|
||||
$devis_temp['montant_ttc'] = $devis_temp['montant_tva'] + $devis_temp['montant_htc'];
|
||||
|
||||
@ -81,31 +81,16 @@ class DevisPdfGenerator
|
||||
|
||||
private function calculatePagination($totalItems)
|
||||
{
|
||||
if ($totalItems <= 8) {
|
||||
// Tout sur 1 page
|
||||
return [
|
||||
'nb_pages' => 1,
|
||||
'items_per_page' => 15,
|
||||
'current_index' => 0
|
||||
];
|
||||
}
|
||||
|
||||
// Réserver 8 items pour dernière page
|
||||
$itemsAvantDernierePage = $totalItems - 8;
|
||||
$nbPagesNormales = ceil($itemsAvantDernierePage / 15);
|
||||
|
||||
return [
|
||||
'nb_pages' => $nbPagesNormales + 1,
|
||||
'items_per_page' => 15,
|
||||
'nb_pages' => ceil($totalItems / 12), // RÉDUIRE à 12 par page
|
||||
'items_per_page' => 12,
|
||||
'current_index' => 0
|
||||
];
|
||||
}
|
||||
|
||||
// VOICI LA FONCTION CORRIGÉE - 4 paramètres au lieu de 10
|
||||
private function generateSinglePage(PageContext $context, $num_page, &$pagination, &$totals)
|
||||
{
|
||||
$startIndex = $pagination['current_index'];
|
||||
$remainingItems = count($context->dataDevis) - $startIndex;
|
||||
|
||||
$context->pdf->AddPage();
|
||||
$context->pdf->SetAutoPagebreak(false);
|
||||
$context->pdf->SetMargins(0, 0, 10);
|
||||
@ -115,17 +100,7 @@ class DevisPdfGenerator
|
||||
$this->layoutManager->addClientInfoSection($context->pdf, $context->clientInfo, $context->dataDevis[0]);
|
||||
$this->layoutManager->addDocumentTitle($context->pdf, $context->dataDevis[0], $context->year);
|
||||
|
||||
// ✅ Calculer items
|
||||
$isLastPage = ($num_page == $pagination['nb_pages']);
|
||||
$hasAmounts = !$context->montant;
|
||||
|
||||
if ($isLastPage && $hasAmounts) {
|
||||
// Dernière page avec totaux : max 8 items
|
||||
$itemsToProcess = min(8, $remainingItems);
|
||||
} else {
|
||||
// Pages normales : 15 items
|
||||
$itemsToProcess = min(15, $remainingItems);
|
||||
}
|
||||
$itemsToProcess = min($pagination['items_per_page'], count($context->dataDevis) - $pagination['current_index']);
|
||||
|
||||
$config = [
|
||||
'pagination' => $pagination,
|
||||
@ -136,7 +111,7 @@ class DevisPdfGenerator
|
||||
'sansMontant' => $context->montant
|
||||
];
|
||||
|
||||
$finalY = $this->tableRenderer->createDevisTable(
|
||||
$this->tableRenderer->createDevisTable(
|
||||
$context->pdf,
|
||||
$context->dataDevis,
|
||||
$config
|
||||
|
||||
@ -63,18 +63,17 @@ class DevisPdfLayoutManager
|
||||
);
|
||||
}
|
||||
|
||||
public function addLegalFooter($pdf, $config, $tableEndY = 0)
|
||||
public function addLegalFooter($pdf, $config)
|
||||
{
|
||||
$y0 = 280;
|
||||
|
||||
$y0 = 260;
|
||||
$pageWidth = $pdf->GetPageWidth();
|
||||
|
||||
$pdf->SetFont('Arial', '', 6);
|
||||
$pdf->SetXY(1, $y0);
|
||||
$pdf->Cell($pageWidth, 5, mb_convert_encoding(html_entity_decode($config->legal_one), 'ISO-8859-1', 'UTF-8'), 0, 0, 'C');
|
||||
$pdf->SetXY(1, $y0 + 4);
|
||||
$pdf->Cell($pageWidth, 5, mb_convert_encoding(html_entity_decode($config->legal_two), 'ISO-8859-1', 'UTF-8'), 0, 0, 'C');
|
||||
$pdf->Cell($pageWidth, 5, mb_convert_encoding(html_entity_decode($config->legal_one), 'ISO-8859-1', 'UTF-8'), 0, 0, 'C');
|
||||
$pdf->SetXY(1, $y0 + 8);
|
||||
$pdf->Cell($pageWidth, 5, mb_convert_encoding(html_entity_decode($config->legal_two), 'ISO-8859-1', 'UTF-8'), 0, 0, 'C');
|
||||
$pdf->SetXY(1, $y0 + 12);
|
||||
$pdf->Cell($pageWidth, 5, mb_convert_encoding(html_entity_decode($config->telephone), 'ISO-8859-1', 'UTF-8'), 0, 0, 'C');
|
||||
}
|
||||
|
||||
|
||||
@ -13,59 +13,41 @@ class DevisPdfTableRenderer
|
||||
$totals = &$config['totals'];
|
||||
$sansMontant = $config['sansMontant'] ?? false;
|
||||
|
||||
// Système de pagination comme les factures
|
||||
$maxItemsPerPage = 22; // Nombre maximum d'éléments par page
|
||||
$startIndex = $pagination['current_index'];
|
||||
$itemsThisPage = min($itemsToProcess, count($dataDevis) - $startIndex);
|
||||
|
||||
$tableEndY = $this->drawTableStructure($pdf, $numPage, $nbPage, $sansMontant, $itemsThisPage);
|
||||
$this->drawTableStructure($pdf, $numPage, $nbPage, $sansMontant);
|
||||
$this->addTableHeaders($pdf, $sansMontant);
|
||||
$this->populateTableData($pdf, $dataDevis, $startIndex, $itemsThisPage, $totals, $sansMontant);
|
||||
|
||||
// Totaux seulement sur la dernière page
|
||||
if ($numPage == $nbPage && !$sansMontant) {
|
||||
$finalY = $this->addTableTotals($pdf, $totals, $tableEndY);
|
||||
} else {
|
||||
$finalY = $tableEndY;
|
||||
$this->addTableTotals($pdf, $totals);
|
||||
}
|
||||
|
||||
return $finalY;
|
||||
}
|
||||
|
||||
private function drawTableStructure($pdf, $numPage, $nbPage, $sansMontant, $itemsOnPage)
|
||||
private function drawTableStructure($pdf, $numPage, $nbPage, $sansMontant)
|
||||
{
|
||||
$pdf->SetLineWidth(0.2);
|
||||
|
||||
$headerHeight = 10;
|
||||
$rowHeight = 10;
|
||||
|
||||
$tableHeight = $headerHeight + ($itemsOnPage * $rowHeight);
|
||||
$endY = 105 + $tableHeight;
|
||||
|
||||
$isLastPage = ($numPage == $nbPage);
|
||||
$hasAmounts = !$sansMontant;
|
||||
|
||||
if ($isLastPage && $hasAmounts) {
|
||||
// Dessiner 3 côtés seulement (haut, gauche, droite)
|
||||
$pdf->Line(5, 105, 205, 105); // Haut
|
||||
$pdf->Line(5, 105, 5, $endY); // Gauche
|
||||
$pdf->Line(205, 105, 205, $endY); // Droite
|
||||
// Pas de ligne du bas - elle sera tracée dans addTableTotals
|
||||
} else {
|
||||
// Dessiner rectangle complet
|
||||
$pdf->Rect(5, 105, 200, $tableHeight, "D");
|
||||
}
|
||||
|
||||
$pdf->Rect(5, 105, 200, 130, "D");
|
||||
$pdf->Line(5, 115, 205, 115);
|
||||
|
||||
$endY = ($numPage == $nbPage && !$sansMontant) ? 225 : 235;
|
||||
|
||||
if (!$sansMontant) {
|
||||
$verticalLines = [24, 41, 58, 77, 102, 127, 147, 167, 178, 189];
|
||||
// Ajustement final des positions des lignes verticales
|
||||
// Article et Défunt de même taille, TTC réduit
|
||||
$verticalLines = [22, 39, 56, 75, 105, 135, 155, 170, 185];
|
||||
} else {
|
||||
$verticalLines = [27, 47, 67, 85, 110, 135, 160];
|
||||
// Pour sans montant: Article et Défunt de même taille
|
||||
$verticalLines = [27, 47, 67, 85, 115, 145];
|
||||
}
|
||||
|
||||
foreach ($verticalLines as $x) {
|
||||
$pdf->Line($x, 105, $x, $endY);
|
||||
}
|
||||
|
||||
return $endY;
|
||||
}
|
||||
|
||||
private function addTableHeaders($pdf, $sansMontant)
|
||||
@ -74,17 +56,16 @@ class DevisPdfTableRenderer
|
||||
|
||||
if (!$sansMontant) {
|
||||
$headers = [
|
||||
[5, 19, "N° Devis"],
|
||||
[24, 17, "N° Dossier"],
|
||||
[41, 17, "N° Commande"],
|
||||
[58, 19, "Date"],
|
||||
[77, 25, "Article"],
|
||||
[102, 25, "Lieu du soin"],
|
||||
[127, 20, "Thanato"],
|
||||
[147, 20, "Défunt"],
|
||||
[167, 11, "H.T."],
|
||||
[178, 11, "TVA"],
|
||||
[189, 16, "T.T.C"]
|
||||
[5, 17, "N° Devis"],
|
||||
[22, 17, "N° Dossier"],
|
||||
[39, 17, "N° Commande"],
|
||||
[56, 19, "Date"],
|
||||
[75, 30, "Article"], // Taille augmentée
|
||||
[105, 30, "Lieu du soin"],
|
||||
[135, 20, "Défunt"], // Taille réduite pour équilibrer
|
||||
[155, 15, "H.T."],
|
||||
[170, 15, "TVA"],
|
||||
[185, 15, "T.T.C"] // Taille réduite
|
||||
];
|
||||
} else {
|
||||
$headers = [
|
||||
@ -92,10 +73,9 @@ class DevisPdfTableRenderer
|
||||
[27, 20, "N° Dossier"],
|
||||
[47, 20, "N° Commande"],
|
||||
[67, 18, "Date"],
|
||||
[85, 25, "Article"],
|
||||
[110, 25, "Lieu du soin"],
|
||||
[135, 25, "Thanato"],
|
||||
[160, 45, "Défunt"]
|
||||
[85, 30, "Article"], // Même taille que Défunt
|
||||
[115, 30, "Lieu du soin"],
|
||||
[145, 30, "Défunt"] // Même taille que Article
|
||||
];
|
||||
}
|
||||
|
||||
@ -146,34 +126,28 @@ class DevisPdfTableRenderer
|
||||
}
|
||||
};
|
||||
|
||||
// Préparer le nom complet du thanatopracteur
|
||||
$thanatoNom = trim(($devis['thanato_prenom'] ?? '') . ' ' . ($devis['thanato_nom'] ?? ''));
|
||||
$thanatoNom = \OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($thanatoNom);
|
||||
|
||||
if (!$sansMontant) {
|
||||
$addSmartCell($pdf, 6, $yDevis, 18, $devis['devis_full_number']);
|
||||
$addSmartCell($pdf, 25, $yDevis, 16, $devis['case_number'] ?? '');
|
||||
$addSmartCell($pdf, 42, $yDevis, 16, $devis['order_number'] ?? '');
|
||||
// LARGEURS ÉQUILIBRÉES avec Article et Défunt de même taille
|
||||
$addSmartCell($pdf, 6, $yDevis, 16, $devis['devis_full_number']);
|
||||
$addSmartCell($pdf, 23, $yDevis, 16, $devis['case_number'] ?? '');
|
||||
$addSmartCell($pdf, 40, $yDevis, 16, $devis['order_number'] ?? '');
|
||||
|
||||
$addSmartCell($pdf, 59, $yDevis, 18, mb_convert_encoding($formatterDate->format($dateSoin), 'ISO-8859-1', 'UTF-8'));
|
||||
$addSmartCell($pdf, 57, $yDevis, 18, mb_convert_encoding($formatterDate->format($dateSoin), 'ISO-8859-1', 'UTF-8'));
|
||||
|
||||
$articleText = \OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($devis['article'] ?? 'SOINS');
|
||||
$addSmartCell($pdf, 78, $yDevis, 24, $articleText);
|
||||
$addSmartCell($pdf, 76, $yDevis, 29, $articleText); // Article agrandi
|
||||
|
||||
$lieuText = \OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($devis['lieu_nom'] ?? '');
|
||||
$addSmartCell($pdf, 103, $yDevis, 24, $lieuText);
|
||||
$addSmartCell($pdf, 106, $yDevis, 29, $lieuText);
|
||||
|
||||
// COLONNE Thanatopracteur (après Lieu du soin)
|
||||
$addSmartCell($pdf, 128, $yDevis, 19, $thanatoNom);
|
||||
|
||||
// COLONNE Défunt (après Thanato)
|
||||
$defuntText = \OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($devis['defunt_nom'] ?? '');
|
||||
$addSmartCell($pdf, 148, $yDevis, 19, $defuntText);
|
||||
$addSmartCell($pdf, 136, $yDevis, 19, $defuntText); // Défunt réduit
|
||||
|
||||
$addSmartCell($pdf, 168, $yDevis, 10, number_format($devis['montant_htc'], 2, '.', '') . chr(128), 'R');
|
||||
$addSmartCell($pdf, 179, $yDevis, 10, number_format($devis['montant_tva'], 2, '.', '') . chr(128), 'R');
|
||||
$addSmartCell($pdf, 190, $yDevis, 15, number_format($devis['montant_ttc'], 2, '.', '') . chr(128), 'R');
|
||||
$addSmartCell($pdf, 156, $yDevis, 14, number_format($devis['montant_htc'], 2, '.', '') . chr(128), 'R');
|
||||
$addSmartCell($pdf, 171, $yDevis, 14, number_format($devis['montant_tva'], 2, '.', '') . chr(128), 'R');
|
||||
$addSmartCell($pdf, 186, $yDevis, 14, number_format($devis['montant_ttc'], 2, '.', '') . chr(128), 'R'); // TTC réduit
|
||||
} else {
|
||||
// Pour sans montant: Article et Défunt de même taille
|
||||
$addSmartCell($pdf, 6, $yDevis, 21, $devis['devis_full_number']);
|
||||
$addSmartCell($pdf, 28, $yDevis, 19, $devis['case_number'] ?? '');
|
||||
$addSmartCell($pdf, 48, $yDevis, 19, $devis['order_number'] ?? '');
|
||||
@ -181,58 +155,52 @@ class DevisPdfTableRenderer
|
||||
$addSmartCell($pdf, 68, $yDevis, 17, mb_convert_encoding($formatterDate->format($dateSoin), 'ISO-8859-1', 'UTF-8'));
|
||||
|
||||
$articleText = \OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($devis['article'] ?? 'SOINS');
|
||||
$addSmartCell($pdf, 86, $yDevis, 24, $articleText);
|
||||
$addSmartCell($pdf, 86, $yDevis, 29, $articleText); // Article agrandi
|
||||
|
||||
$lieuText = \OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($devis['lieu_nom'] ?? '');
|
||||
$addSmartCell($pdf, 111, $yDevis, 24, $lieuText);
|
||||
$addSmartCell($pdf, 116, $yDevis, 29, $lieuText);
|
||||
|
||||
// COLONNE Thanatopracteur (après Lieu du soin)
|
||||
$addSmartCell($pdf, 136, $yDevis, 24, $thanatoNom);
|
||||
|
||||
// COLONNE Défunt (après Thanato)
|
||||
$defuntText = \OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($devis['defunt_nom'] ?? '');
|
||||
$addSmartCell($pdf, 161, $yDevis, 44, $defuntText);
|
||||
$addSmartCell($pdf, 146, $yDevis, 29, $defuntText); // Défunt réduit
|
||||
}
|
||||
}
|
||||
|
||||
private function addTableTotals($pdf, $totals, $tableEndY)
|
||||
private function addTableTotals($pdf, $totals)
|
||||
{
|
||||
$totalEndY = $tableEndY + 8;
|
||||
|
||||
$pdf->SetLineWidth(0.2);
|
||||
|
||||
// Juste les lignes horizontales haut et bas
|
||||
$pdf->Line(5, $tableEndY, 205, $tableEndY);
|
||||
$pdf->Line(5, $totalEndY, 205, $totalEndY);
|
||||
|
||||
$pdf->Line(5, $tableEndY, 5, $totalEndY);
|
||||
$pdf->Line(205, $tableEndY, 205, $totalEndY);
|
||||
|
||||
$pdf->Line(5, 225, 205, 225);
|
||||
$pdf->SetFont('Arial', 'B', 8);
|
||||
|
||||
$pdf->SetXY(5, $tableEndY);
|
||||
$pdf->Cell(162, 8, 'TOTAL', 0, 0, 'C');
|
||||
// Alignement des totaux avec les colonnes HT, TVA, TTC
|
||||
$pdf->SetXY(5, 225);
|
||||
$pdf->Cell(130, 8, 'TOTAL', 0, 0, 'C');
|
||||
|
||||
$pdf->SetXY(167, $tableEndY);
|
||||
$pdf->Cell(9, 8, number_format($totals['ht'], 2, '.', '') . chr(128), 0, 0, 'R');
|
||||
// POSITIONS alignées avec les colonnes du tableau
|
||||
$pdf->SetXY(155, 225);
|
||||
$pdf->Cell(15, 8, number_format($totals['ht'], 2, '.', '') . chr(128), 0, 0, 'R');
|
||||
$pdf->SetXY(170, 225);
|
||||
$pdf->Cell(15, 8, number_format($totals['tva'], 2, '.', '') . chr(128), 0, 0, 'R');
|
||||
$pdf->SetXY(185, 225);
|
||||
$pdf->Cell(15, 8, number_format($totals['ttc'], 2, '.', '') . chr(128), 0, 0, 'R');
|
||||
|
||||
$pdf->SetXY(181, $tableEndY);
|
||||
$pdf->Cell(9, 8, number_format($totals['tva'], 2, '.', '') . chr(128), 0, 0, 'R');
|
||||
// CADRE TOTAL TTC - Texte à l'intérieur du cadre aligné à droite
|
||||
$pdf->SetXY(155, 240);
|
||||
$pdf->Cell(30, 8, 'TOTAL TTC', 0, 0, 'C');
|
||||
|
||||
$pdf->SetXY(189, $tableEndY);
|
||||
$pdf->Cell(16, 8, number_format($totals['ttc'], 2, '.', '') . chr(128), 0, 0, 'R');
|
||||
// Valeur alignée avec la fin du tableau tout à droite
|
||||
$pdf->SetXY(185, 240);
|
||||
$pdf->Cell(15, 8, number_format($totals['ttc'], 2, '.', '') . chr(128), 0, 0, 'R');
|
||||
|
||||
$cadreY = $totalEndY + 3;
|
||||
// Cadre TOTAL TTC aligné avec la fin du tableau (205)
|
||||
$lines = [
|
||||
[155, 240, 155, 248], // Ligne verticale gauche
|
||||
[185, 240, 185, 248], // Ligne de séparation
|
||||
[205, 240, 205, 248], // Ligne verticale droite (alignée avec fin du tableau)
|
||||
[155, 240, 205, 240], // Ligne horizontale haute
|
||||
[155, 248, 205, 248] // Ligne horizontale basse
|
||||
];
|
||||
|
||||
$pdf->SetXY(170, $cadreY + 1);
|
||||
$pdf->Cell(19, 6, 'TOTAL TTC', 0, 0, 'C');
|
||||
|
||||
$pdf->SetXY(189, $cadreY + 1);
|
||||
$pdf->Cell(16, 6, number_format($totals['ttc'], 2, '.', '') . chr(128), 0, 0, 'C');
|
||||
|
||||
$pdf->Rect(170, $cadreY, 35, 8, 'D');
|
||||
$pdf->Line(189, $cadreY, 189, $cadreY + 8);
|
||||
|
||||
return $cadreY + 8;
|
||||
foreach ($lines as $line) {
|
||||
$pdf->Line($line[0], $line[1], $line[2], $line[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,102 +30,94 @@ use OCA\Gestion\Db\Bdd;
|
||||
use OCA\Gestion\Helpers\FileExportHelpers;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ExportClientStatisticService
|
||||
{
|
||||
/** @var Bdd */
|
||||
private $gestionBdd;
|
||||
class ExportClientStatisticService {
|
||||
/** @var Bdd */
|
||||
private $gestionBdd;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
public function __construct(
|
||||
Bdd $gestionBdd,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->gestionBdd = $gestionBdd;
|
||||
}
|
||||
public function __construct(
|
||||
Bdd $gestionBdd,
|
||||
LoggerInterface $logger) {
|
||||
$this->logger = $logger;
|
||||
$this->gestionBdd = $gestionBdd;
|
||||
}
|
||||
|
||||
public function getFileName(array $clientIds)
|
||||
{
|
||||
public function getFileName(array $clientIds){
|
||||
$filename = "";
|
||||
$clients = $this->gestionBdd->getClientsByClientsID($clientIds);
|
||||
foreach($clients as $client) {
|
||||
foreach($clients as $client){
|
||||
$filename .= $client['client_nom'] . '-' . $client['client_entreprise'] . '--';
|
||||
}
|
||||
$filename = rtrim($filename, '-');
|
||||
$filename = str_replace(' ', '-', $filename);
|
||||
$filename = str_replace(' ', '-', $filename);
|
||||
$filename = str_replace(' ','-', $filename);
|
||||
$filename = str_replace(' ','-', $filename);
|
||||
return $filename;
|
||||
}
|
||||
|
||||
public function getExportClientFileHeader(): string
|
||||
{
|
||||
$fileHeader =
|
||||
'CLIENT'.';'.
|
||||
public function getExportClientFileHeader(): string{
|
||||
$fileHeader =
|
||||
'CLIENT'.';'.
|
||||
'MOIS'.';'.
|
||||
'ANNEE'.';'.
|
||||
'NB DE DEFUNTS'.';';
|
||||
'NB DE DEFUNTS'.';';
|
||||
|
||||
$produitList = $this->gestionBdd->getProduitsListAsArray();
|
||||
foreach($produitList as $produit) {
|
||||
$fileHeader .= FileExportHelpers::FormatTextForExport($produit['reference']).';';
|
||||
}
|
||||
$fileHeader .= 'TOTAL HT'.';'."\n";
|
||||
return $fileHeader;
|
||||
}
|
||||
$produitList = $this->gestionBdd->getProduitsListAsArray();
|
||||
foreach($produitList as $produit){
|
||||
$fileHeader .= FileExportHelpers::FormatTextForExport($produit['reference']).';';
|
||||
}
|
||||
$fileHeader .= 'TOTAL HT'.';'."\n";
|
||||
return $fileHeader;
|
||||
}
|
||||
|
||||
public function populateExportDataIntoFileContent(array $exportData, string $fileContent): string
|
||||
{
|
||||
foreach($exportData as $clientId => $clientData) {
|
||||
$clientName = $clientData["client_name"];
|
||||
$clientStatPerMonth = $clientData["client_data"];
|
||||
$totalPrice = 0;
|
||||
if(!empty($clientStatPerMonth)) {
|
||||
foreach($clientStatPerMonth as $month => $stat) {
|
||||
$stat["client_name"] = $clientName;
|
||||
$totalPrice += $stat["total_price"];
|
||||
$fileContent = $this->populateClientStatDataIntoFileContent($fileContent, $month, $stat);
|
||||
}
|
||||
$fileContent = $this->populateTotalPriceIntoFileContent($fileContent, $totalPrice, count($stat["products"]));
|
||||
}
|
||||
}
|
||||
return $fileContent;
|
||||
}
|
||||
public function populateExportDataIntoFileContent(array $exportData,string $fileContent): string{
|
||||
foreach($exportData as $clientId => $clientData){
|
||||
$clientName = $clientData["client_name"];
|
||||
$clientStatPerMonth = $clientData["client_data"];
|
||||
$totalPrice = 0;
|
||||
if(!empty($clientStatPerMonth)){
|
||||
foreach($clientStatPerMonth as $month => $stat){
|
||||
$stat["client_name"] = $clientName;
|
||||
$totalPrice+=$stat["total_price"];
|
||||
$fileContent = $this->populateClientStatDataIntoFileContent($fileContent,$month,$stat);
|
||||
}
|
||||
$fileContent = $this->populateTotalPriceIntoFileContent($fileContent,$totalPrice,count($stat["products"]));
|
||||
}
|
||||
}
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
private function populateTotalPriceIntoFileContent(string $fileContent, $totalPrice, $productsCount)
|
||||
{
|
||||
$fileContent = $fileContent.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';';
|
||||
while($productsCount > 0) {
|
||||
$fileContent .= ''.';';
|
||||
$productsCount--;
|
||||
}
|
||||
$fileContent .= "$totalPrice".";"."\n";
|
||||
return $fileContent;
|
||||
}
|
||||
private function populateTotalPriceIntoFileContent(string $fileContent,$totalPrice,$productsCount){
|
||||
$fileContent = $fileContent.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';';
|
||||
while($productsCount > 0){
|
||||
$fileContent .= ''.';';
|
||||
$productsCount--;
|
||||
}
|
||||
$fileContent .= "$totalPrice".";"."\n";
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
private function populateClientStatDataIntoFileContent(string $fileContent, $month, array $statPerMonth)
|
||||
{
|
||||
$yearValue = $statPerMonth["year"];
|
||||
$defuntCount = $statPerMonth["defunt_count"];
|
||||
$products = $statPerMonth["products"];
|
||||
$priceTotal = $statPerMonth["total_price"];
|
||||
private function populateClientStatDataIntoFileContent(string $fileContent,$month,array $statPerMonth){
|
||||
$yearValue = $statPerMonth["year"];
|
||||
$defuntCount = $statPerMonth["defunt_count"];
|
||||
$products = $statPerMonth["products"];
|
||||
|
||||
$fileContent = $fileContent.
|
||||
FileExportHelpers::FormatTextForExport($statPerMonth['client_name']).';'.
|
||||
"$month".';'.
|
||||
"$yearValue".';'.
|
||||
"$defuntCount".';';
|
||||
|
||||
$fileContent = $fileContent.
|
||||
FileExportHelpers::FormatTextForExport($statPerMonth['client_name']).';'.
|
||||
"$month".';'.
|
||||
"$yearValue".';'.
|
||||
"$defuntCount".';';
|
||||
foreach($products as $productCount){
|
||||
$fileContent .= "$productCount".";";
|
||||
}
|
||||
$fileContent .= "\n";
|
||||
return $fileContent;
|
||||
|
||||
foreach($products as $productCount) {
|
||||
$fileContent .= "$productCount".";";
|
||||
}
|
||||
$fileContent .= "$priceTotal".';'."\n";
|
||||
return $fileContent;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,158 +34,149 @@ use OCA\Gestion\Constants\BddConstant;
|
||||
use OCA\Gestion\Helpers\FileExportHelpers;
|
||||
use OCA\Gestion\Constants\AbsenceTypeConstant;
|
||||
|
||||
class ExportThanatoStatisticService
|
||||
{
|
||||
/** @var Bdd */
|
||||
private $gestionBdd;
|
||||
class ExportThanatoStatisticService {
|
||||
/** @var Bdd */
|
||||
private $gestionBdd;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
private $geoService;
|
||||
private $geoService;
|
||||
|
||||
public function __construct(
|
||||
Bdd $gestionBdd,
|
||||
LoggerInterface $logger,
|
||||
IRootFolder $rootFolder,
|
||||
GeoService $geoService
|
||||
) {
|
||||
$this->geoService = $geoService;
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->logger = $logger;
|
||||
$this->gestionBdd = $gestionBdd;
|
||||
}
|
||||
public function __construct(
|
||||
Bdd $gestionBdd,
|
||||
LoggerInterface $logger,
|
||||
IRootFolder $rootFolder,
|
||||
GeoService $geoService) {
|
||||
$this->geoService = $geoService;
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->logger = $logger;
|
||||
$this->gestionBdd = $gestionBdd;
|
||||
}
|
||||
|
||||
private function getFilename($thanatoName, $thanatoLastName, $month, $year)
|
||||
{
|
||||
$filename = "$year-$month-";
|
||||
$filename .= $thanatoName . '-' . $thanatoLastName;
|
||||
$filename = str_replace(' ', '-', $filename);
|
||||
$filename = str_replace(' ', '-', $filename);
|
||||
private function getFilename($thanatoName,$thanatoLastName,$month,$year){
|
||||
$filename = "$year-$month-";
|
||||
$filename .= $thanatoName . '-' . $thanatoLastName;
|
||||
$filename = str_replace(' ','-', $filename);
|
||||
$filename = str_replace(' ','-', $filename);
|
||||
return $filename;
|
||||
}
|
||||
}
|
||||
|
||||
private function exportThanatoStatistic($thanatoId, $month, $year, $idNextcloud)
|
||||
{
|
||||
$thanato = $this->gestionBdd->getThanatoById($thanatoId);
|
||||
if($thanato == null) {
|
||||
return null;
|
||||
}
|
||||
$exportData = $this->gestionBdd->getExportThanatoStatisticData($thanatoId, $month, $year);
|
||||
if(empty($exportData)) {
|
||||
return null;
|
||||
}
|
||||
$defaultConfig = json_decode($this->gestionBdd->getConfiguration(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD));
|
||||
$racineFolder = html_entity_decode($defaultConfig[0]->path).'/';
|
||||
$thanatoFolder = $racineFolder.'STATISTIQUES/THANATOS/';
|
||||
$fileHeader = $this->getExportThanatoFileHeader();
|
||||
$fileContent = $this->populateExportDataIntoFileContent($exportData, $fileHeader);
|
||||
$storage = $this->rootFolder->getUserFolder($idNextcloud);
|
||||
try {
|
||||
$storage->newFolder($thanatoFolder);
|
||||
} catch(\OCP\Files\NotPermittedException $e) {
|
||||
private function exportThanatoStatistic($thanatoId,$month,$year,$idNextcloud){
|
||||
$thanato = $this->gestionBdd->getThanatoById($thanatoId);
|
||||
if($thanato == null){
|
||||
return null;
|
||||
}
|
||||
$exportData = $this->gestionBdd->getExportThanatoStatisticData($thanatoId,$month,$year);
|
||||
if(empty($exportData)){
|
||||
return null;
|
||||
}
|
||||
$defaultConfig = json_decode($this->gestionBdd->getConfiguration(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD));
|
||||
$racineFolder = html_entity_decode($defaultConfig[0]->path).'/';
|
||||
$thanatoFolder = $racineFolder.'STATISTIQUES/THANATOS/';
|
||||
$fileHeader = $this->getExportThanatoFileHeader();
|
||||
$fileContent = $this->populateExportDataIntoFileContent($exportData,$fileHeader);
|
||||
$storage = $this->rootFolder->getUserFolder($idNextcloud);
|
||||
try{
|
||||
$storage->newFolder($thanatoFolder);
|
||||
}
|
||||
catch(\OCP\Files\NotPermittedException $e) {
|
||||
|
||||
}
|
||||
$filename = $this->getFilename($thanato["nom"],$thanato["prenom"],$month,$year);
|
||||
$fileNamePath = $thanatoFolder."STAT-THANATO-" . $filename . '.csv';
|
||||
$storage->newFile($fileNamePath);
|
||||
$file = $storage->get($fileNamePath);
|
||||
$file->putContent($fileContent);
|
||||
return $fileNamePath;
|
||||
}
|
||||
|
||||
}
|
||||
$filename = $this->getFilename($thanato["nom"], $thanato["prenom"], $month, $year);
|
||||
$fileNamePath = $thanatoFolder."STAT-THANATO-" . $filename . '.csv';
|
||||
$storage->newFile($fileNamePath);
|
||||
$file = $storage->get($fileNamePath);
|
||||
$file->putContent($fileContent);
|
||||
return $fileNamePath;
|
||||
}
|
||||
public function exportThanatosListStatistic(array $thanatoIds,$month,$year,$idNextcloud){
|
||||
$filenames = [];
|
||||
foreach($thanatoIds as $thanatoId){
|
||||
$filename = $this->exportThanatoStatistic($thanatoId,$month,$year,$idNextcloud);
|
||||
if($filename != null){
|
||||
$filenames[] = $filename;
|
||||
}
|
||||
}
|
||||
return $filenames;
|
||||
}
|
||||
|
||||
public function exportThanatosListStatistic(array $thanatoIds, $month, $year, $idNextcloud)
|
||||
{
|
||||
$filenames = [];
|
||||
foreach($thanatoIds as $thanatoId) {
|
||||
$filename = $this->exportThanatoStatistic($thanatoId, $month, $year, $idNextcloud);
|
||||
if($filename != null) {
|
||||
$filenames[] = $filename;
|
||||
}
|
||||
}
|
||||
return $filenames;
|
||||
}
|
||||
public function getExportThanatoFileHeader(): string{
|
||||
$fileHeader =
|
||||
'FACTURE'.';'.
|
||||
'THANATOPRACTEUR'.';'.
|
||||
'DATE'.';'.
|
||||
'HEURE DE DEBUT'.';'.
|
||||
'HEURE DE FIN'.';'.
|
||||
'SOINS'.';'.
|
||||
'JOUR/FERIE'.';'.
|
||||
'CONGE'.';'.
|
||||
'REPOS'.';'.
|
||||
'MALADIE'.';'.
|
||||
'NOM ET PRENOM'.';'.
|
||||
'LIEU'.';'.
|
||||
'POMPES FUNEBRES'.';'.
|
||||
'ADRESSE'.';'.
|
||||
'DISTANCE TOTALE KM'.';'.
|
||||
'HEURES TOTAL DE SOIN'.';'.
|
||||
'HEURES TOTAL DE CONGE'.';'.
|
||||
'HEURES TOTAL DE REPOS'.';'.
|
||||
'HEURES TOTAL DE MALADIE'.';'.
|
||||
'HEURES TOTAL DE TRAVAIL'.';'.
|
||||
'HEURES TOTAL DE PARCOURS ENTRE DEVIS'.';'.
|
||||
'NOMBRE DE SOINS ET TOILETTES'.';'.
|
||||
"\n";
|
||||
return $fileHeader;
|
||||
}
|
||||
|
||||
public function getExportThanatoFileHeader(): string
|
||||
{
|
||||
$fileHeader =
|
||||
'DEVIS'.';'.
|
||||
'THANATOPRACTEUR'.';'.
|
||||
'DATE'.';'.
|
||||
'HEURE DE DEBUT'.';'.
|
||||
'HEURE DE FIN'.';'.
|
||||
'SOINS'.';'.
|
||||
'JOUR/FERIE'.';'.
|
||||
'CONGE'.';'.
|
||||
'REPOS'.';'.
|
||||
'MALADIE'.';'.
|
||||
'NOM ET PRENOM'.';'.
|
||||
'LIEU'.';'.
|
||||
'POMPES FUNEBRES'.';'.
|
||||
'ADRESSE'.';'.
|
||||
'DISTANCE TOTALE KM'.';'.
|
||||
'HEURES TOTAL DE SOIN'.';'.
|
||||
'HEURES TOTAL DE CONGE'.';'.
|
||||
'HEURES TOTAL DE REPOS'.';'.
|
||||
'HEURES TOTAL DE MALADIE'.';'.
|
||||
'HEURES TOTAL DE TRAVAIL'.';'.
|
||||
'HEURES TOTAL DE PARCOURS ENTRE DEVIS'.';'.
|
||||
'NOMBRE DE SOINS ET TOILETTES'.';'.
|
||||
"\n";
|
||||
return $fileHeader;
|
||||
}
|
||||
private function populateNoDevisDataInADay(string $fileContent,$leave){
|
||||
$startTimeValue = "";
|
||||
$endTimeValue = "";
|
||||
$leaveValue = "Non";
|
||||
if($leave["onLeave"]){
|
||||
$startTimeValue = $leave["startTime"];
|
||||
$endTimeValue = $leave["endTime"];
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::LEAVE){
|
||||
$leaveValue = "Oui";
|
||||
}
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::DISEASE){
|
||||
$diseaseValue = "Oui";
|
||||
}
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::REST){
|
||||
$restValue = "Oui";
|
||||
}
|
||||
}
|
||||
$fileContent = $fileContent.
|
||||
''.';'.
|
||||
FileExportHelpers::FormatTextForExport($leave['thanatoName']).';'.
|
||||
$leave['date'].';'.
|
||||
$startTimeValue.';'.
|
||||
$endTimeValue.';'.
|
||||
''.';'.
|
||||
DateHelpers::getPublicHolidayText($leave['isPublicHoliday']).';'.
|
||||
$leaveValue.';'.
|
||||
$restValue.';'.
|
||||
$diseaseValue.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'."\n";
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
private function populateNoDevisDataInADay(string $fileContent, $leave)
|
||||
{
|
||||
$startTimeValue = "";
|
||||
$endTimeValue = "";
|
||||
$leaveValue = "Non";
|
||||
$restValue = "Non"; // AJOUTER CETTE LIGNE
|
||||
$diseaseValue = "Non"; // AJOUTER CETTE LIGNE
|
||||
if($leave["onLeave"]) {
|
||||
$startTimeValue = $leave["startTime"];
|
||||
$endTimeValue = $leave["endTime"];
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::LEAVE) {
|
||||
$leaveValue = "Oui";
|
||||
}
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::DISEASE) {
|
||||
$diseaseValue = "Oui";
|
||||
}
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::REST) {
|
||||
$restValue = "Oui";
|
||||
}
|
||||
}
|
||||
$fileContent = $fileContent.
|
||||
''.';'.
|
||||
FileExportHelpers::FormatTextForExport($leave['thanatoName']).';'.
|
||||
$leave['date'].';'.
|
||||
$startTimeValue.';'.
|
||||
$endTimeValue.';'.
|
||||
''.';'.
|
||||
DateHelpers::getPublicHolidayText($leave['isPublicHoliday']).';'.
|
||||
$leaveValue.';'.
|
||||
$restValue.';'.
|
||||
$diseaseValue.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'."\n";
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
public function populateExportDataIntoFileContent(array $exportData, string $fileContent): string
|
||||
{
|
||||
public function populateExportDataIntoFileContent(array $exportData,string $fileContent): string{
|
||||
|
||||
$g_totalDistance = 0;
|
||||
$g_totalDevisHours = 0;
|
||||
@ -194,81 +185,81 @@ class ExportThanatoStatisticService
|
||||
$g_totalTravelingHoursBetweenDevisLocation = 0;
|
||||
$g_totalDiseaseHours = 0;
|
||||
$g_totalRestHours = 0;
|
||||
$g_totalDevisCount = 0;
|
||||
$g_totalDevisCount = 0;
|
||||
|
||||
foreach($exportData as $devisDate => $devisData) {
|
||||
$totalDevisHours = 0;
|
||||
$totalWorkedHours = 8;
|
||||
$totalLeaveHours = 0;
|
||||
$totalDiseaseHours = 0;
|
||||
$totalRestHours = 0;
|
||||
$totalDistance = 0;
|
||||
$totalDevisCount = 0;
|
||||
$totalTravelingHoursBetweenDevisLocation = 0;
|
||||
$hasDevisInTheCurrentDate = $devisData['hasDevis'];
|
||||
if($hasDevisInTheCurrentDate === false) {
|
||||
$leaves = $devisData["leaves"];
|
||||
foreach($leaves as $leave) {
|
||||
$fileContent = $this->populateNoDevisDataInADay($fileContent, $leave);
|
||||
if($leave["onLeave"]) {
|
||||
$totalLeaveHoursInsideWorkingHours = $leave["totalWorkedHours"];
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::LEAVE) {
|
||||
$totalLeaveHours += $totalLeaveHoursInsideWorkingHours;
|
||||
}
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::REST) {
|
||||
$totalRestHours += $totalLeaveHoursInsideWorkingHours;
|
||||
}
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::DISEASE) {
|
||||
$totalDiseaseHours += $totalLeaveHoursInsideWorkingHours;
|
||||
}
|
||||
}
|
||||
}
|
||||
$totalAbsenceHours = $totalLeaveHours + $totalRestHours + $totalDiseaseHours;
|
||||
$totalWorkedHours -= $totalAbsenceHours;
|
||||
} else {
|
||||
$totalDevisCount += count($devisData["devisId"]);
|
||||
$routeLines = $this->gestionBdd->getRouteLinesByDevisIdList($devisData["devisId"]);
|
||||
$totalDistanceAndTotalTravelingHoursBetweenDevis = $this->geoService->getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLines($routeLines);
|
||||
$totalDistance = $totalDistanceAndTotalTravelingHoursBetweenDevis["totalDistance"];
|
||||
$totalTravelingHoursBetweenDevisLocation = $totalDistanceAndTotalTravelingHoursBetweenDevis["totalTravelingHours"];
|
||||
$devisList = $devisData["devis"];
|
||||
$leaves = $devisData["leaves"];
|
||||
if(!empty($devisList)) {
|
||||
foreach($devisList as $devis) {
|
||||
$fileContent = $this->populateDevisDataIntoThanatoExportFileContent($fileContent, $devis);
|
||||
$totalDevisHours += $devis["totalHours"];
|
||||
}
|
||||
}
|
||||
foreach($leaves as $leave) {
|
||||
$fileContent = $this->populateNoDevisDataInADay($fileContent, $leave);
|
||||
if($leave["onLeave"]) {
|
||||
$totalLeaveHoursInsideWorkingHours = $leave["totalWorkedHours"];
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::LEAVE) {
|
||||
$totalLeaveHours += $totalLeaveHoursInsideWorkingHours;
|
||||
}
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::REST) {
|
||||
$totalRestHours += $totalLeaveHoursInsideWorkingHours;
|
||||
}
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::DISEASE) {
|
||||
$totalDiseaseHours += $totalLeaveHoursInsideWorkingHours;
|
||||
}
|
||||
}
|
||||
}
|
||||
$totalAbsenceHours = $totalLeaveHours + $totalRestHours + $totalDiseaseHours;
|
||||
$totalWorkedHours -= $totalAbsenceHours;
|
||||
}
|
||||
foreach($exportData as $devisDate => $devisData){
|
||||
$totalDevisHours = 0;
|
||||
$totalWorkedHours = 8;
|
||||
$totalLeaveHours = 0;
|
||||
$totalDiseaseHours = 0;
|
||||
$totalRestHours = 0;
|
||||
$totalDistance = 0;
|
||||
$totalDevisCount = 0;
|
||||
$totalTravelingHoursBetweenDevisLocation = 0;
|
||||
$hasDevisInTheCurrentDate = $devisData['hasDevis'];
|
||||
if($hasDevisInTheCurrentDate === false){
|
||||
$leaves = $devisData["leaves"];
|
||||
foreach($leaves as $leave){
|
||||
$fileContent = $this->populateNoDevisDataInADay($fileContent,$leave);
|
||||
if($leave["onLeave"]){
|
||||
$totalLeaveHoursInsideWorkingHours = $leave["totalWorkedHours"];
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::LEAVE ){
|
||||
$totalLeaveHours += $totalLeaveHoursInsideWorkingHours;
|
||||
}
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::REST){
|
||||
$totalRestHours += $totalLeaveHoursInsideWorkingHours;
|
||||
}
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::DISEASE){
|
||||
$totalDiseaseHours += $totalLeaveHoursInsideWorkingHours;
|
||||
}
|
||||
}
|
||||
}
|
||||
$totalAbsenceHours = $totalLeaveHours + $totalRestHours + $totalDiseaseHours;
|
||||
$totalWorkedHours -= $totalAbsenceHours;
|
||||
}
|
||||
else{
|
||||
$totalDevisCount += count($devisData["devisId"]);
|
||||
$routeLines = $this->gestionBdd->getRouteLinesByDevisIdList($devisData["devisId"]);
|
||||
$totalDistanceAndTotalTravelingHoursBetweenDevis = $this->geoService->getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLines($routeLines);
|
||||
$totalDistance = $totalDistanceAndTotalTravelingHoursBetweenDevis["totalDistance"];
|
||||
$totalTravelingHoursBetweenDevisLocation = $totalDistanceAndTotalTravelingHoursBetweenDevis["totalTravelingHours"];
|
||||
$devisList = $devisData["devis"];
|
||||
$leaves = $devisData["leaves"];
|
||||
if(!empty($devisList)){
|
||||
foreach($devisList as $devis){
|
||||
$fileContent = $this->populateDevisDataIntoThanatoExportFileContent($fileContent,$devis);
|
||||
$totalDevisHours += $devis["totalHours"];
|
||||
}
|
||||
}
|
||||
foreach($leaves as $leave){
|
||||
$fileContent = $this->populateNoDevisDataInADay($fileContent,$leave);
|
||||
if($leave["onLeave"]){
|
||||
$totalLeaveHoursInsideWorkingHours = $leave["totalWorkedHours"];
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::LEAVE){
|
||||
$totalLeaveHours += $totalLeaveHoursInsideWorkingHours;
|
||||
}
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::REST){
|
||||
$totalRestHours += $totalLeaveHoursInsideWorkingHours;
|
||||
}
|
||||
if($leave["absenceTypeKey"] == AbsenceTypeConstant::DISEASE){
|
||||
$totalDiseaseHours += $totalLeaveHoursInsideWorkingHours;
|
||||
}
|
||||
}
|
||||
}
|
||||
$totalAbsenceHours = $totalLeaveHours + $totalRestHours + $totalDiseaseHours;
|
||||
$totalWorkedHours -= $totalAbsenceHours;
|
||||
}
|
||||
|
||||
$fileContent = $this->populateLastRecapForTheLine(
|
||||
$fileContent,
|
||||
$totalDistance,
|
||||
$totalDevisHours,
|
||||
$totalWorkedHours,
|
||||
$totalLeaveHours,
|
||||
$totalTravelingHoursBetweenDevisLocation,
|
||||
$totalDiseaseHours,
|
||||
$totalRestHours,
|
||||
$totalDevisCount
|
||||
);
|
||||
$fileContent = $this->populateLastRecapForTheLine(
|
||||
$fileContent,
|
||||
$totalDistance,
|
||||
$totalDevisHours,
|
||||
$totalWorkedHours,
|
||||
$totalLeaveHours,
|
||||
$totalTravelingHoursBetweenDevisLocation,
|
||||
$totalDiseaseHours,
|
||||
$totalRestHours,$totalDevisCount
|
||||
);
|
||||
|
||||
$g_totalDistance += $totalDistance;
|
||||
$g_totalDevisHours += $totalDevisHours;
|
||||
@ -277,8 +268,8 @@ class ExportThanatoStatisticService
|
||||
$g_totalTravelingHoursBetweenDevisLocation += $totalTravelingHoursBetweenDevisLocation;
|
||||
$g_totalDiseaseHours += $totalDiseaseHours;
|
||||
$g_totalRestHours += $totalRestHours;
|
||||
$g_totalDevisCount += $totalDevisCount;
|
||||
}
|
||||
$g_totalDevisCount += $totalDevisCount;
|
||||
}
|
||||
|
||||
$fileContent = $this->populateLastRecapForTheLine(
|
||||
$fileContent,
|
||||
@ -288,113 +279,77 @@ class ExportThanatoStatisticService
|
||||
$g_totalLeaveHours,
|
||||
$g_totalTravelingHoursBetweenDevisLocation,
|
||||
$g_totalDiseaseHours,
|
||||
$g_totalRestHours,
|
||||
$g_totalDevisCount
|
||||
$g_totalRestHours,$g_totalDevisCount
|
||||
);
|
||||
|
||||
return $fileContent;
|
||||
}
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
private function populateLastRecapForTheLine(string $fileContent, $distance, $totalDevisHours, $totalWorkedHours, $totalLeaveHours, $totalTravelingHours, $totalDiseaseHours = 0, $totalRestHours = 0, $totalDevisCount = 0)
|
||||
{
|
||||
$fileContent = $fileContent.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
"$distance".';'.
|
||||
"$totalDevisHours".';'.
|
||||
"$totalLeaveHours".';'.
|
||||
"$totalRestHours".';'.
|
||||
"$totalDiseaseHours".';'.
|
||||
"$totalWorkedHours".';'.
|
||||
"$totalTravelingHours".';'.
|
||||
"$totalDevisCount"."\n";
|
||||
return $fileContent;
|
||||
}
|
||||
private function populateLastRecapForTheLine(string $fileContent,$distance,$totalDevisHours,$totalWorkedHours,$totalLeaveHours,$totalTravelingHours ,$totalDiseaseHours = 0,$totalRestHours = 0,$totalDevisCount = 0){
|
||||
$fileContent = $fileContent.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
"$distance".';'.
|
||||
"$totalDevisHours".';'.
|
||||
"$totalLeaveHours".';'.
|
||||
"$totalRestHours".';'.
|
||||
"$totalDiseaseHours".';'.
|
||||
"$totalWorkedHours".';'.
|
||||
"$totalTravelingHours".';'.
|
||||
"$totalDevisCount"."\n";
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
private function getFormatDevisProduitsAsString($devisProduits)
|
||||
{
|
||||
$result = '';
|
||||
foreach ($devisProduits as $produit) {
|
||||
$result .= $produit['produit_reference'] . '-' . $produit['produit_description'] . '--';
|
||||
}
|
||||
// Remove the trailing "--" at the end
|
||||
$result = rtrim($result, '-');
|
||||
return $result;
|
||||
}
|
||||
private function getFormatDevisProduitsAsString($devisProduits){
|
||||
$result = '';
|
||||
foreach ($devisProduits as $produit) {
|
||||
$result .= $produit['produit_reference'] . '-' . $produit['produit_description'] . '--';
|
||||
}
|
||||
// Remove the trailing "--" at the end
|
||||
$result = rtrim($result, '-');
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function populateDevisDataIntoThanatoExportFileContentSave(string $fileContent, array $devis)
|
||||
{
|
||||
$produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]);
|
||||
$factureNum = $devis["facture_num"] ?? $devis["facture_on_group_num"] ?? "";
|
||||
$fileContent = $fileContent.
|
||||
FileExportHelpers::FormatTextForExport($factureNum).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis['nom_thanato'] . ' ' . $devis['prenom_thanatho']).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["date"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["startTime"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["endTime"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($produitAsString).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["dayType"]).';'.
|
||||
FileExportHelpers::FormatTextForExport('Non').';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_defunt"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_lieu"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_client"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["client_adresse"] ?? "").
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'."\n";
|
||||
private function populateDevisDataIntoThanatoExportFileContent(string $fileContent,array $devis){
|
||||
$produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]);
|
||||
$factureNum = $devis["facture_num"] ?? $devis["facture_on_group_num"] ?? "";
|
||||
$fileContent = $fileContent.
|
||||
FileExportHelpers::FormatTextForExport($factureNum).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis['nom_thanato'] . ' ' . $devis['prenom_thanatho']).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["date"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["startTime"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["endTime"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($produitAsString).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["dayType"]).';'.
|
||||
FileExportHelpers::FormatTextForExport('Non').';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_defunt"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_lieu"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_client"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["client_adresse"] ?? "").
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'."\n";
|
||||
|
||||
return $fileContent;
|
||||
|
||||
return $fileContent;
|
||||
|
||||
}
|
||||
|
||||
private function populateDevisDataIntoThanatoExportFileContent(string $fileContent, array $devis)
|
||||
{
|
||||
$produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]);
|
||||
$devisNum = (string)($devis["calendar_uuid"] ?? "");
|
||||
|
||||
$fileContent = $fileContent.
|
||||
FileExportHelpers::FormatTextForExport($devisNum).';'.
|
||||
FileExportHelpers::FormatTextForExport(($devis['nom_thanato'] ?? '') . ' ' . ($devis['prenom_thanato'] ?? '')).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["date"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["startTime"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["endTime"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($produitAsString).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["dayType"] ?? "").';'.
|
||||
'Non'.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_defunt"] ?? "").';'. // ICI
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_lieu"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_client"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["client_adresse"] ?? "").';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'."\n";
|
||||
|
||||
return $fileContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,31 +30,28 @@ use Exception;
|
||||
use OCA\Gestion\Constants\GeoConstant;
|
||||
use OCA\Gestion\Helpers\GeoHelpers;
|
||||
|
||||
class GeoService
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
class GeoService {
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcul la distance entre les deux points à vol d'oiseau
|
||||
*/
|
||||
private function getDistanceInKmBetweenTwoPoints($lat1, $lon1, $lat2, $lon2)
|
||||
{
|
||||
private function getDistanceInKmBetweenTwoPoints($lat1, $lon1, $lat2, $lon2) {
|
||||
$R = 6371; // Rayon moyen de la Terre en kilomètres
|
||||
$dLat = deg2rad($lat2 - $lat1);
|
||||
$dLon = deg2rad($lon2 - $lon1);
|
||||
$a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($dLon / 2) * sin($dLon / 2);
|
||||
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
|
||||
$a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($dLon/2) * sin($dLon/2);
|
||||
$c = 2 * atan2(sqrt($a), sqrt(1-$a));
|
||||
$d = $R * $c;
|
||||
return round($d, 2);
|
||||
}
|
||||
|
||||
private function getTravelingHourBetweenTwoPoints(array $origin, array $destination, $mode = "driving")
|
||||
{
|
||||
private function getTravelingHourBetweenTwoPoints(array $origin,array $destination,$mode = "driving"){
|
||||
$baseUrl = "https://api.geoapify.com/v1/routing";
|
||||
$originPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($origin["latitude"], $origin["longitude"]);
|
||||
$destinationPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($destination["latitude"], $destination["longitude"]);
|
||||
$originPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($origin["latitude"],$origin["longitude"]);
|
||||
$destinationPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($destination["latitude"],$destination["longitude"]);
|
||||
|
||||
$fullUrl = $baseUrl."?waypoints=$originPoints|$destinationPoints&mode=$mode&apiKey=9e23d93e7f454c988344f9171bf867aa";
|
||||
$curl = curl_init();
|
||||
@ -69,11 +66,11 @@ class GeoService
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => 'GET',
|
||||
));
|
||||
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
|
||||
if ($response === false) {
|
||||
return 0;
|
||||
} else {
|
||||
@ -82,45 +79,45 @@ class GeoService
|
||||
$travelTimeHours = round($travelTimeHours, 2);
|
||||
return $travelTimeHours;
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
}
|
||||
catch(Exception $e){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLinesSave(array $routeLines)
|
||||
{
|
||||
public function getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLines(array $routeLines){
|
||||
$distanceCumul = 0;
|
||||
$totalTravelingHoursBetweenTwoDevisLocation = 0;
|
||||
$lastPoint = null;
|
||||
for ($i = 0; $i < sizeof($routeLines); $i++) {
|
||||
$lastPoint = NULL;
|
||||
for ($i=0; $i < sizeof($routeLines); $i++) {
|
||||
$currentDistance = 0;
|
||||
if($routeLines[$i]['lieu_id'] != null) {
|
||||
if($routeLines[$i]['lieu_id'] != NULL){
|
||||
$lastPoint = $routeLines[$i];
|
||||
}
|
||||
if($lastPoint['lieu_id'] != null && $routeLines[$i + 1]['lieu_id'] != null) {
|
||||
}
|
||||
if($lastPoint['lieu_id'] != NULL && $routeLines[$i+1]['lieu_id'] != NULL){
|
||||
$currentDistance = $this->getDistanceInKmBetweenTwoPoints(
|
||||
floatval(value: $lastPoint['latitude']),
|
||||
floatval($lastPoint['longitude']),
|
||||
floatval($routeLines[$i + 1]['latitude']),
|
||||
floatval($routeLines[$i + 1]['longitude'])
|
||||
floatval(value: $lastPoint['latitude']),
|
||||
floatval($lastPoint['longitude']),
|
||||
floatval($routeLines[$i+1]['latitude']),
|
||||
floatval($routeLines[$i+1]['longitude'])
|
||||
);
|
||||
$targetIsBetweenTwoDevisLocation = $lastPoint['source'] != "siege" && $routeLines[$i + 1]["source"] != "siege";
|
||||
if($targetIsBetweenTwoDevisLocation) {
|
||||
$targetIsBetweenTwoDevisLocation = $lastPoint['source'] != "siege" && $routeLines[$i+1]["source"] != "siege";
|
||||
if($targetIsBetweenTwoDevisLocation){
|
||||
$originPoints = [
|
||||
"latitude" => $lastPoint["latitude"],
|
||||
"longitude" => $lastPoint["longitude"]
|
||||
];
|
||||
$destinationPoints = [
|
||||
"latitude" => $routeLines[$i + 1]["latitude"],
|
||||
"longitude" => $routeLines[$i + 1]["longitude"]
|
||||
"latitude" => $routeLines[$i+1]["latitude"],
|
||||
"longitude" => $routeLines[$i+1]["longitude"]
|
||||
];
|
||||
$totalTravelingHoursBetweenTwoDevisLocation += $this->getTravelingHourBetweenTwoPoints(
|
||||
$totalTravelingHoursBetweenTwoDevisLocation+= $this->getTravelingHourBetweenTwoPoints(
|
||||
$originPoints,
|
||||
$destinationPoints,
|
||||
GeoConstant::DRIVING_MODE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$distanceCumul += $currentDistance;
|
||||
}
|
||||
return [
|
||||
@ -128,65 +125,4 @@ class GeoService
|
||||
"totalTravelingHours" => $totalTravelingHoursBetweenTwoDevisLocation
|
||||
];
|
||||
}
|
||||
|
||||
public function getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLines(array $routeLines)
|
||||
{
|
||||
$distanceCumul = 0;
|
||||
$totalTravelingHoursBetweenTwoDevisLocation = 0;
|
||||
$lastPoint = null;
|
||||
|
||||
for ($i = 0; $i < sizeof($routeLines); $i++) {
|
||||
$currentDistance = 0;
|
||||
|
||||
// Vérifier que l'élément actuel existe
|
||||
if(!isset($routeLines[$i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($routeLines[$i]['lieu_id'] != null) {
|
||||
$lastPoint = $routeLines[$i];
|
||||
}
|
||||
|
||||
// Vérifier que $i+1 existe ET que $lastPoint n'est pas null
|
||||
if($lastPoint !== null &&
|
||||
isset($routeLines[$i + 1]) &&
|
||||
isset($lastPoint['lieu_id']) &&
|
||||
isset($routeLines[$i + 1]['lieu_id']) &&
|
||||
$lastPoint['lieu_id'] != null &&
|
||||
$routeLines[$i + 1]['lieu_id'] != null) {
|
||||
|
||||
$currentDistance = $this->getDistanceInKmBetweenTwoPoints(
|
||||
floatval($lastPoint['latitude']),
|
||||
floatval($lastPoint['longitude']),
|
||||
floatval($routeLines[$i + 1]['latitude']),
|
||||
floatval($routeLines[$i + 1]['longitude'])
|
||||
);
|
||||
|
||||
$targetIsBetweenTwoDevisLocation = $lastPoint['source'] != "siege" && $routeLines[$i + 1]["source"] != "siege";
|
||||
|
||||
if($targetIsBetweenTwoDevisLocation) {
|
||||
$originPoints = [
|
||||
"latitude" => $lastPoint["latitude"],
|
||||
"longitude" => $lastPoint["longitude"]
|
||||
];
|
||||
$destinationPoints = [
|
||||
"latitude" => $routeLines[$i + 1]["latitude"],
|
||||
"longitude" => $routeLines[$i + 1]["longitude"]
|
||||
];
|
||||
$totalTravelingHoursBetweenTwoDevisLocation += $this->getTravelingHourBetweenTwoPoints(
|
||||
$originPoints,
|
||||
$destinationPoints,
|
||||
GeoConstant::DRIVING_MODE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$distanceCumul += $currentDistance;
|
||||
}
|
||||
|
||||
return [
|
||||
"totalDistance" => round($distanceCumul, 2),
|
||||
"totalTravelingHours" => round($totalTravelingHoursBetweenTwoDevisLocation, 2)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -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, saveAttestationAbsentPacemaker, saveRapportBijoux, saveRapportSoin, setBijouxPhoto, setDefuntCover, setDefuntPacemakerPhoto, updateDB } from "./modules/ajaxRequest.mjs";
|
||||
import { getBibliotheques, exportCareCertificate,getBijouxById, getHypodermiquesyId, getObservationsById, getproduits, saveAttestationPacemaker, saveRapportBijoux, saveRapportSoin, setBijouxPhoto, setDefuntCover, setDefuntPacemakerPhoto, updateDB } from "./modules/ajaxRequest.mjs";
|
||||
import { globalConfiguration } from "./modules/mainFunction.mjs";
|
||||
|
||||
let bibliotheques = [];
|
||||
@ -77,7 +77,6 @@ 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");
|
||||
@ -145,9 +144,6 @@ 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;
|
||||
@ -186,12 +182,6 @@ 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')
|
||||
|
||||
@ -678,31 +678,6 @@ 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
|
||||
|
||||
@ -30,7 +30,6 @@ $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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user