THANASOFT-DV/gestion/lib/Helpers/FileExportHelpers.php
2025-09-03 15:58:58 +03:00

125 lines
4.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace OCA\Gestion\Helpers;
use DateTime;
use OCA\Gestion\Constants\VCalendarPropertyConstant;
class FileExportHelpers
{
public static function FormatTextForExport(string $text){
$textFormatted = str_replace('', "'", $text);
$textFormatted = utf8_decode(html_entity_decode($textFormatted));
return $textFormatted;
}
public static function GetAddressAndCityFromAddress(string $adresse){
$adresseResult = "Aucun adresse";
$cityResult = "Aucune ville";
$adresses = explode("-",$adresse);
if(isset($adresses[0])){
$adresseResult = self::RemoveSpaceFromString($adresses[0]);
}
if(isset($adresses[1])){
$cityResult = self::RemoveSpaceFromString($adresses[1]);
}
return [
"address" => $adresseResult,
"city" => $cityResult
];
}
public static function GetSexeLabel(string $sexeKey){
return $sexeKey === 'f' ? 'Mme' : 'Mr';
}
public static function RemoveSpaceFromString(string $string){
$stringWithoutSpace = trim($string);
$stringWithoutSpace = str_replace("&nbsp;",'',$stringWithoutSpace);
return $stringWithoutSpace;
}
public static function ConvertSpecialChar($str) {
$unwanted_array = array(
'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y'
);
return strtr( $str, $unwanted_array );
}
public static function GetClientsFolder($clientName,$racinePath){
return $racinePath.'CLIENTS/'.mb_strtoupper($clientName,'UTF-8').'/';
}
public static function GetFactureGroupFilename($factureNum,$clientName){
$factureNum = str_replace('/','-',$factureNum);
$clientName = str_replace('&nbsp;',' ',$clientName ?? '');
return 'FACTURE'.'_'.$factureNum.'_'.mb_strtoupper($clientName,'UTF-8').'.pdf';
}
public static function GetFactureGroupFolder($clientName,$facturationDate){
$clientRacineFolder = 'CLIENTS/'.mb_strtoupper($clientName,'UTF-8').'/';
$factureDatetime = new DateTime($facturationDate);
$factureDateYear = $factureDatetime->format('Y');
$factureMonth = DateHelpers::GetDateWithFormatDayAndMonthPlainString($facturationDate);
$factureByYearFolder = $clientRacineFolder."$factureDateYear".'/'.$factureMonth.'/'.'FACTURES'.'/';
return $factureByYearFolder;
}
public static function GetFactureGroupFileFullPath($clientName,$factureNum,$facturationDate){
$factureFolder = self::GetFactureGroupFolder($clientName,$facturationDate);
$factureFilename = self::GetFactureGroupFilename($factureNum,$clientName);
return $factureFolder.$factureFilename;
}
public static function GetDefuntsFolder($clientName,$defuntName,$racinePath){
$clientsFolder = self::GetClientsFolder($clientName,$racinePath);
return $clientsFolder.'DEFUNTS/'.mb_strtoupper($defuntName,'UTF-8').'/';
}
public static function GetBijouxOfDefuntFolder($clientName,$defuntName,$racinePath){
$defuntFolder = self::GetDefuntsFolder($clientName,$defuntName,$racinePath);
return $defuntFolder.'BIJOUX/';
}
public static function GetPacemakerPhotoFolderOfDefunt($clientName,$defuntName,$racinePath){
$defuntFolder = self::GetDefuntsFolder($clientName,$defuntName,$racinePath);
return $defuntFolder.'PACEMAKER/';
}
public static function GetLineCountForATextInAMaxWidth($pdf,$text,$maxWidth){
$words = explode(' ', $text);
$lineWidth = 0;
$lineCount = 1;
foreach ($words as $word) {
$wordWidth = $pdf->GetStringWidth($word . ' ');
if ($lineWidth + $wordWidth > $maxWidth) {
$lineCount++;
$lineWidth = $wordWidth;
} else {
$lineWidth += $wordWidth;
}
}
return $lineCount;
}
public static function GetAbsenceTypeLabelFromKey(string $key){
$label = null;
$absenceTypes = VCalendarPropertyConstant::ABSENCE_TYPES_KEYS_VALUES;
foreach($absenceTypes as $absenceTypeKey => $absenceTypeLabel){
if($absenceTypeKey == $key){
$label = $absenceTypeLabel;
break;
}
}
return $label;
}
}