2677 lines
117 KiB
PHP
2677 lines
117 KiB
PHP
<?php
|
|
namespace OCA\Gestion\Controller;
|
|
|
|
use OCA\Gestion\Service\InvoicePdfHandler;
|
|
defined("TAB1") or define("TAB1", "\t");
|
|
|
|
use OCP\IGroupManager;
|
|
use OCP\IRequest;
|
|
use OCP\IUserSession;
|
|
use OCP\Mail\IMailer;
|
|
use OCP\Files\IRootFolder;
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
use OCP\AppFramework\Controller;
|
|
use OCA\Gestion\Db\Bdd;
|
|
use OCP\IURLGenerator;
|
|
use OCP\IConfig;
|
|
use \Datetime;
|
|
use \DatetimeImmutable;
|
|
use \IntlDateFormatter;
|
|
use \FPDF;
|
|
use OCA\Gestion\Service\ExportClientStatisticService;
|
|
use OCA\Gestion\Service\ExportThanatoStatisticService;
|
|
use OCA\Gestion\Service\InvoicePdfService;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
date_default_timezone_set('Europe/Paris');
|
|
|
|
class PageController extends Controller {
|
|
private $idNextcloud;
|
|
private $myDb;
|
|
// private $src_path = "/var/www/html/apps/gestion/img/";
|
|
private $src_path = "/var/www/html/custom_apps/gestion/img/";
|
|
private $urlGenerator;
|
|
private $mailer;
|
|
private $config;
|
|
|
|
/** @var IRootStorage */
|
|
private $storage;
|
|
|
|
private $user;
|
|
private $groups = [];
|
|
|
|
/** @var ExportThanatoStatisticService */
|
|
private $exportThanatoStatisticService;
|
|
|
|
/** @var \OCA\Gestion\Service\ExportClientStatisticService */
|
|
private $exportClientStatisticService;
|
|
|
|
/** @var InvoicePdfService */
|
|
private $invoicePdfService;
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct($AppName,
|
|
IRequest $request,
|
|
$UserId,
|
|
Bdd $myDb,
|
|
IRootFolder $rootFolder,
|
|
IURLGenerator $urlGenerator,
|
|
IMailer $mailer,
|
|
Iconfig $config,
|
|
IUserSession $userSession,
|
|
IGroupManager $groupManager,
|
|
ExportThanatoStatisticService $exportThanatoStatisticService,
|
|
ExportClientStatisticService $exportClientStatisticService,
|
|
InvoicePdfService $invoicePdfService) {
|
|
|
|
parent::__construct($AppName, $request);
|
|
|
|
$this->idNextcloud = $UserId;
|
|
$this->myDb = $myDb;
|
|
$this->urlGenerator = $urlGenerator;
|
|
$this->mailer = $mailer;
|
|
$this->config = $config;
|
|
$this->exportThanatoStatisticService = $exportThanatoStatisticService;
|
|
$this->exportClientStatisticService = $exportClientStatisticService;
|
|
$this->invoicePdfService = $invoicePdfService;
|
|
//$this->fpdf = $fpdf;
|
|
|
|
if ($userSession->isLoggedIn()) {
|
|
$this->user = $userSession->getUser();
|
|
}
|
|
|
|
if ($this->user != null) {
|
|
$groups = $groupManager->getUserGroups($this->user);
|
|
$this->groups = [];
|
|
foreach ($groups as $group) {
|
|
$this->groups[] = $group->getGID();
|
|
}
|
|
}
|
|
|
|
try{
|
|
$this->storage = $rootFolder->getUserFolder($this->idNextcloud);
|
|
}catch(\OC\User\NoUserException $e){
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*
|
|
*/
|
|
public function index() {
|
|
return new TemplateResponse('gestion', 'index', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/index.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*
|
|
*/
|
|
public function defunt() {
|
|
return new TemplateResponse('gestion', 'defunt', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/thanatopracteur.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*
|
|
*/
|
|
public function thanatopracteur() {
|
|
$this->denyIfNotAdmin();
|
|
return new TemplateResponse('gestion', 'thanatopracteur', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/thanatopracteur.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function devis() {
|
|
return new TemplateResponse('gestion', 'devis', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/devis.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function trajet() {
|
|
$this->denyIfNotAdmin();
|
|
return new TemplateResponse('gestion', 'trajet', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/trajet.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function lieu() {
|
|
return new TemplateResponse('gestion', 'lieu', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/lieu.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function facture() {
|
|
$this->denyIfNotAdmin();
|
|
return new TemplateResponse('gestion', 'facture', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/facture.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function article() {
|
|
$this->denyIfNotAdmin();
|
|
return new TemplateResponse('gestion', 'article', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/produit.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function produit() {
|
|
$this->denyIfNotAdmin();
|
|
return new TemplateResponse('gestion', 'produit', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/produit.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function bibliotheque() {
|
|
$this->denyIfNotAdmin();
|
|
return new TemplateResponse('gestion', 'bibliotheque', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/produit.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function statistique() {
|
|
$this->denyIfNotAdmin();
|
|
return new TemplateResponse('gestion', 'statistique', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/statistique.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function legalnotice($page) {
|
|
return new TemplateResponse('gestion', 'legalnotice', array('groups' => $this->groups, 'user' => $this->user, 'page' => 'content/legalnotice', 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/legalnotice.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function france() {
|
|
return new TemplateResponse('gestion', 'legalnotice', array('groups' => $this->groups, 'user' => $this->user, 'page' => 'legalnotice/france', 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/legalnotice.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function config() {
|
|
$this->myDb->checkConfig($this->idNextcloud);
|
|
return new TemplateResponse('gestion', 'configuration', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/configuration.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numdevis
|
|
*/
|
|
public function devisshow($numdevis) {
|
|
$devis = $this->myDb->getOneDevis($numdevis,$this->idNextcloud);
|
|
$articles = $this->myDb->getListArticle($numdevis, $this->idNextcloud);
|
|
$produits = $this->myDb->getListProduit($numdevis, $this->idNextcloud);
|
|
return new TemplateResponse('gestion', 'devisshow', array( 'groups' => $this->groups, 'user' => $this->user, 'configuration'=> $this->getConfiguration(),
|
|
'devis'=>json_decode($devis),
|
|
'produit'=>json_decode($produits),
|
|
'article'=>json_decode($articles),
|
|
'path' => $this->idNextcloud,
|
|
'url' => $this->getNavigationLink(),
|
|
'logo' => $this->getLogo()
|
|
));
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numdefunt
|
|
*/
|
|
public function defuntshow($numdefunt) {
|
|
$defunt = $this->myDb->getOneDefunt($numdefunt,$this->idNextcloud);
|
|
return new TemplateResponse('gestion', 'defuntshow', array( 'groups' => $this->groups, 'user' => $this->user, 'configuration'=> $this->getConfiguration(),
|
|
'defunt'=>json_decode($defunt),
|
|
'path' => $this->idNextcloud,
|
|
'url' => $this->getNavigationLink(),
|
|
'logo' => $this->getLogo()
|
|
));
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numtrajet
|
|
*/
|
|
public function trajetdetails($numtrajet) {
|
|
$this->denyIfNotAdmin();
|
|
$trajet = $this->myDb->getTrajetById($numtrajet, $this->idNextcloud);
|
|
return new TemplateResponse('gestion', 'trajetdetails', array(
|
|
'groups' => $this->groups, 'user' => $this->user,
|
|
'path' => $this->idNextcloud,
|
|
'url' => $this->getNavigationLink(),
|
|
'trajet' => json_decode($trajet)
|
|
));// templates/trajetdetails.php
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numfacture
|
|
*/
|
|
public function factureshow($numfacture) {
|
|
$this->denyIfNotAdmin();
|
|
$facture = $this->myDb->getOneFacture($numfacture,$this->idNextcloud);
|
|
return new TemplateResponse('gestion', 'factureshow', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud,
|
|
'configuration'=> $this->getConfiguration(),
|
|
'facture'=>json_decode($facture),
|
|
'url' => $this->getNavigationLink(),
|
|
'logo' => $this->getLogo()
|
|
));
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function apercustousdevis() {
|
|
$devis = json_decode($this->myDb->getDevis($this->idNextcloud));
|
|
foreach ($devis as $key => $d) {
|
|
$d->dproduits = [];
|
|
$produits = json_decode($this->myDb->getListProduit($d->id, $this->idNextcloud));
|
|
$d->dproduits = $produits;
|
|
}
|
|
$clients = json_decode($this->myDb->getClients($this->idNextcloud));
|
|
return new TemplateResponse('gestion', 'apercustousdevis', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud,
|
|
'configuration'=> $this->getConfiguration(),
|
|
'devis'=> $devis,
|
|
'clients'=> $clients,
|
|
'url' => $this->getNavigationLink(),
|
|
'logo' => $this->getLogo()
|
|
));
|
|
}
|
|
|
|
protected function denyIfNotAdmin() {
|
|
/*
|
|
if(empty($this->groups) || !in_array("admin", $this->groups)) {
|
|
http_response_code(403);
|
|
echo "Forbidden: You need administrative privileges.";
|
|
exit;
|
|
}
|
|
*/
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function apercustoutesfactures() {
|
|
$this->denyIfNotAdmin();
|
|
$factures = json_decode($this->myDb->getFactures($this->idNextcloud));
|
|
foreach ($factures as $key => $facture) {
|
|
$facture->dproduits = [];
|
|
$produits = json_decode($this->myDb->getListProduit($facture->id_devis, $this->idNextcloud));
|
|
$facture->dproduits = $produits;
|
|
}
|
|
$clients = json_decode($this->myDb->getClients($this->idNextcloud));
|
|
$clients_final = [];
|
|
foreach ($clients as $key => $client) {
|
|
if(!in_array(strtolower($client->entreprise), $clients_final)) array_push($clients_final, strtolower($client->entreprise));
|
|
}
|
|
return new TemplateResponse('gestion', 'apercustoutesfactures', array( 'groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud,
|
|
'configuration'=> $this->getConfiguration(),
|
|
'factures'=> $factures,
|
|
'clients'=> $clients,
|
|
'url' => $this->getNavigationLink(),
|
|
'logo' => $this->getLogo()
|
|
));
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function isConfig() {
|
|
return $this->myDb->isConfig($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getNavigationLink(){
|
|
return array(
|
|
"index" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.index"),
|
|
"defunt" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.defunt"),
|
|
"devis" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.devis"),
|
|
"thanatopracteur" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.thanatopracteur"),
|
|
"trajet" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.trajet"),
|
|
"lieu" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.lieu"),
|
|
"facture" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.facture"),
|
|
"produit" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.produit"),
|
|
"article" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.article"),
|
|
"bibliotheque" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.bibliotheque"),
|
|
"config" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.config"),
|
|
"isConfig" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.isConfig"),
|
|
"statistique" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.statistique"),
|
|
"legalnotice" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.legalnotice"),
|
|
"france" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.france"),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getClients() {
|
|
// $this->myDb->init_trajets_data($this->idNextcloud);
|
|
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
|
// if(strcmp(strtolower($current_config[0]->id_nextcloud), 'delphine')!=0) {
|
|
// $today = date('d-m-Y');
|
|
// $lastDayThisMonth = date('t-m-Y');
|
|
// if ($today == $lastDayThisMonth) {
|
|
// $this->generer_document_comptable($today);
|
|
// $this->generer_recap_ogf($today);
|
|
// }
|
|
// }
|
|
return $this->myDb->getClients($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getThanatopracteurs() {
|
|
return $this->myDb->getThanatopracteurs($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function ajaxGetThanatopracteurs() {
|
|
return $this->myDb->getThanatopracteurs($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function insertThanatopracteur() {
|
|
return $this->myDb->insertThanatopracteur($this->idNextcloud);
|
|
}
|
|
|
|
private function generer_indemnite_kilometrique($date) {
|
|
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
|
$clean_folder = html_entity_decode($current_config[0]->path).'/';
|
|
|
|
$formatter_ds = new IntlDateFormatter('fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
|
|
$formatter_ds->setPattern('dd-MMM');
|
|
|
|
try {
|
|
try {
|
|
$data_trajets = json_decode($this->myDb->getCurrentMonthTrajet($this->idNextcloud, $date));
|
|
$data_trajets = array_filter($data_trajets, function($trajet) {return $trajet->lieu_depart !=NULL && $trajet->lieu_arrivee != NULL;});
|
|
|
|
$ik_txt = 'Date'.TAB1.utf8_decode('Départ').TAB1.utf8_decode('Arrivée').TAB1.'Distance'.PHP_EOL;
|
|
$ik_csv = 'Date'.';'.utf8_decode('Départ').';'.utf8_decode('Arrivée').';'.'Distance'.';'."\n";
|
|
|
|
$date_trajet = $data_trajets[0]->date;
|
|
$annee = explode('-', $date_trajet)[0];
|
|
$mois = explode('-', $date_trajet)[1];
|
|
|
|
$_clean_folder = $clean_folder.'INDEMNITES KILOMETRIQUES/'.$annee.'/'.strtoupper($trajet->id_nextcloud).'/';
|
|
|
|
try {
|
|
$this->storage->newFolder($_clean_folder);
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
|
|
foreach ($data_trajets as $key => $trajet) {
|
|
|
|
$date_trajet_temp = new DateTime($trajet->date);
|
|
|
|
$ik_txt = $ik_txt.utf8_decode($formatter_ds->format($date_trajet_temp)).TAB1.$trajet->lieu_depart.TAB1.$trajet->lieu_arrivee.TAB1.$trajet->distance.PHP_EOL;
|
|
$ik_csv = $ik_csv.utf8_decode($formatter_ds->format($date_trajet_temp)).';'.$trajet->lieu_depart.';'.$trajet->lieu_arrivee.';'.$trajet->distance."\n";
|
|
|
|
}
|
|
$ff = $_clean_folder.'IK_'.strtoupper($trajet->id_nextcloud).'_'.$mois.'_'.$annee.'.csv';
|
|
$this->storage->newFile($ff);
|
|
$file = $this->storage->get($ff);
|
|
$file->putContent($ik_csv);
|
|
|
|
$ff_txt = $_clean_folder.'IK_'.strtoupper($trajet->id_nextcloud).'_'.$mois.'_'.$annee.'.txt';
|
|
$this->storage->newFile($ff_txt);
|
|
$file_txt = $this->storage->get($ff_txt);
|
|
$file_txt->putContent($ik_txt);
|
|
|
|
} catch(\OCP\Files\NotFoundException $e) { }
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
}
|
|
|
|
private function generer_recap_ogf($date) {
|
|
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
|
try {
|
|
try {
|
|
$data_factures = array();
|
|
$factures = json_decode($this->myDb->getCurrentMonthFactures_COGF($this->idNextcloud, $date));
|
|
$factures = array_filter($factures, function($facture) {return $facture->id_client != NULL; });
|
|
foreach ($factures as $key => $facture) {
|
|
$facture_temp = array(
|
|
'num' => $facture->num,
|
|
'id_client' => $facture->id_client,
|
|
'client' => $facture->entreprise,
|
|
'adresse_client' => $facture->adresse_client,
|
|
'adresse_devis' => $facture->lieu,
|
|
'nom_client' => html_entity_decode($facture->nom),
|
|
'prenoms_client' => html_entity_decode($facture->prenom),
|
|
'date_soin' => $facture->date_soin,
|
|
'numero_commande' => $facture->numero_commande,
|
|
'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,
|
|
);
|
|
$produits = json_decode($this->getProduitsById($facture->id_devis));
|
|
foreach ($produits as $key => $produit) {
|
|
$facture_temp['montant_htc'] += $produit->prix_unitaire * $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])][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);
|
|
}
|
|
}
|
|
|
|
foreach ($data_temp as $key_annee => $annee) {
|
|
foreach ($annee as $key_mois => $mois) {
|
|
$pdf = new FPDF();
|
|
|
|
$date_facture = $mois[0]['date_facture'];
|
|
$date_temp = date("t-m-Y", strtotime($date_facture));
|
|
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
|
|
$date_formated = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_temp));
|
|
|
|
try {
|
|
$this->storage->newFolder(html_entity_decode($current_config[0]->path).'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'/');
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
|
|
$pdf->AddPage();
|
|
// on sup les 2 cm en bas
|
|
$pdf->SetAutoPagebreak(False);
|
|
$pdf->SetMargins(0,0,0);
|
|
|
|
// logo : 80 de largeur et 55 de hauteur
|
|
$pdf->Image($this->src_path."logo.png", 10, 10, 55, 30);
|
|
// adresse du facture
|
|
$pdf->SetFont('Arial','B',11); $_x = 122 ; $_y = 40;
|
|
$pdf->SetXY( $_x, $_y ); $pdf->Cell( 100, 8, utf8_decode('Groupe COGF'), 0, 0, ''); $_y += 8;
|
|
// date facture
|
|
$pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 60 );
|
|
$pdf->Cell( 60, 8, "Croth le, ".utf8_decode($date_formated), 0, 0, '');
|
|
|
|
// observations
|
|
$pdf->SetFont( "Arial", "BU", 10 ); $pdf->SetXY( 10, 85 ) ; $pdf->Cell($pdf->GetStringWidth("Objet:"), 0, "Objet:", 0, "L");
|
|
$objet = utf8_decode("Récapitulatif Facturation du mois de ").strtoupper($this->convert_special_char(explode(' ', $date_formated)[1]));
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 85 ) ; $pdf->Cell($pdf->GetStringWidth($objet), 0, $objet, 0, "L");
|
|
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 95 ); $pdf->Cell($pdf->GetStringWidth("Madame, Monsieur"), 0, "Madame, Monsieur", 0, "L");
|
|
|
|
$text1 = utf8_decode("Veuillez trouver ci-dessous le récapitulatif de la facturation du mois de ").strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).".";
|
|
$text2 = utf8_decode("Vous en souhaitant bonne réception.");
|
|
$text3 = utf8_decode("Veuillez agréer, Madame, Monsieur, mes salutations les meilleures.");
|
|
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 105 ) ; $pdf->Cell($pdf->GetStringWidth($text1), 0, $text1, 0, "L");
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 110 ) ; $pdf->Cell($pdf->GetStringWidth($text2), 0, $text2, 0, "L");
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 120 ) ; $pdf->Cell($pdf->GetStringWidth($text3), 0, $text3, 0, "L");
|
|
|
|
// signature
|
|
$pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 145 );
|
|
$pdf->Cell( $pdf->GetStringWidth($current_config[0]->nom.' '.$current_config[0]->prenom), 0, utf8_decode(html_entity_decode($current_config[0]->nom.' '.$current_config[0]->prenom)), 0, 0, 'L');
|
|
$pdf->Image($this->src_path."sign.png", 122, 150, 55, 30);
|
|
|
|
$y0 = 260;
|
|
$pageWidth = $pdf->GetPageWidth();
|
|
//Positionnement en bas et tout centrer
|
|
$pdf->SetFont('Arial','',6);
|
|
|
|
$pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C');
|
|
$pdf->SetXY( 1, $y0 + 8 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C');
|
|
$pdf->SetXY( 1, $y0 + 12 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->telephone)), 0, 0, 'C');
|
|
|
|
/*$pdf->SetXY( 1, $y0 + 16 );
|
|
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
|
|
|
|
$num_page = 1;
|
|
$nb_page = ceil(sizeof($mois) / 26);
|
|
$index_facture_position = 0;
|
|
$max_nb_toget = (sizeof($mois)<=26)?sizeof($mois):26;
|
|
|
|
$montant_ht_total = 0;
|
|
$montant_tva_total = 0;
|
|
$montant_ttc_total = 0;
|
|
|
|
while ($num_page <= $nb_page) {
|
|
$pdf->AddPage();
|
|
// on sup les 2 cm en bas
|
|
$pdf->SetAutoPagebreak(False);
|
|
$pdf->SetMargins(0,0,0);
|
|
|
|
$pdf->Image($this->src_path."logo.png", 10, 10, 55, 30);
|
|
|
|
// n° page en haute à droite
|
|
if($nb_page>1){
|
|
$pdf->SetXY( 120, 5 ); $pdf->SetFont( "Arial", "B", 9 ); $pdf->Cell( 160, 8, $num_page . '/' . $nb_page, 0, 0, 'C');
|
|
}
|
|
|
|
// date facture
|
|
$pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 15 );
|
|
$pdf->Cell( 60, 8, "Croth le, ".utf8_decode($date_formated), 0, 0, '');
|
|
|
|
// n° facture, date echeance et reglement et obs
|
|
$pdf->SetLineWidth(0.1); $pdf->SetFillColor(255); $pdf->Rect(100, 30, 85, 8, "DF");
|
|
$pdf->SetXY( 100, 30 ); $pdf->SetFont( "Arial", "B", 12 ); $pdf->Cell( 85, 8, 'FACTURE N'.utf8_decode('°').' ETS/'.$key_annee.'/'.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])), 0, 0, 'C');
|
|
|
|
// adresse du facture
|
|
$pdf->SetFont('Arial','B',11); $x = 122 ; $y = 50;
|
|
// $pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, 'doit', 0, 0, ''); $y += 8;
|
|
$pdf->SetXY( $x, $y ); $pdf->MultiCell( 80, 4, 'Groupe OGF', 0, 0, '');
|
|
|
|
// ***********************
|
|
// le cadre des articles
|
|
// ***********************
|
|
// cadre avec 18 lignes max ! et 118 de hauteur --> 80 + 118 = 198 pour les traits verticaux
|
|
$pdf->SetLineWidth(0.1); $pdf->Rect(5, 80, 200, 153, "D");
|
|
// cadre titre des colonnes
|
|
$pdf->Line(5, 90, 205, 90);
|
|
// les traits verticaux colonnes
|
|
$pdf->Line(145, 80, 145, 233); $pdf->Line(163, 80, 163, 233);
|
|
if($num_page == $nb_page) $pdf->Line(183, 80, 183, 240);
|
|
else $pdf->Line(183, 80, 183, 233);
|
|
// titre colonne
|
|
$pdf->SetXY( 1, 81 ); $pdf->SetFont('Arial','B',8); $pdf->Cell( 140, 8, "OBJET", 0, 0, 'C');
|
|
$pdf->SetXY( 147, 81 ); $pdf->SetFont('Arial','B',8); $pdf->Cell( 13, 8, "H.T.", 0, 0, 'C');
|
|
$pdf->SetXY( 168, 81 ); $pdf->SetFont('Arial','B',8); $pdf->Cell( 10, 8, "TVA 20%", 0, 0, 'C');
|
|
$pdf->SetXY( 183, 81 ); $pdf->SetFont('Arial','B',8); $pdf->Cell( 22, 8, "T.T.C", 0, 0, 'C');
|
|
|
|
// (new DateTime($facture['date_soin']))->format('d-M')
|
|
$formatter_ds = new IntlDateFormatter('fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
|
|
|
|
// Set the pattern for the formatter to "d-MMMM" to display the day and month name in French
|
|
$formatter_ds->setPattern('dd-MMM');
|
|
|
|
//recuperation des factures
|
|
$y_facture = 90;
|
|
|
|
$init_index = $index_facture_position;
|
|
|
|
for ($index_facture_position; $index_facture_position < ($init_index + $max_nb_toget) ; $index_facture_position++) {
|
|
$date_soin_temp = new DateTime($mois[$index_facture_position]['date_soin']);
|
|
|
|
$pdf->SetXY( 6, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, $mois[$index_facture_position]['num'], 0, 0, '');
|
|
$pdf->SetXY( 32, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, $mois[$index_facture_position]['numero_commande'], 0, 0, '');
|
|
$pdf->SetXY( 53, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 18, 8, utf8_decode($formatter_ds->format($date_soin_temp)), 0, 0, '');
|
|
$pdf->SetXY( 65, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 38, 8, $mois[$index_facture_position]['prenoms_client'].' '.$mois[$index_facture_position]['nom_client'], 0, 0, '');
|
|
$pdf->SetXY( 100, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, utf8_decode(html_entity_decode($mois[$index_facture_position]['defunt'])), 0, 0, '');
|
|
$pdf->SetXY( 147, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 13, 8, $mois[$index_facture_position]['montant_htc'].chr(128), 0, 0, 'C');
|
|
$pdf->SetXY( 168, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 10, 8, $mois[$index_facture_position]['montant_tva'].chr(128), 0, 0, 'C');
|
|
$pdf->SetXY( 183, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 22, 8, $mois[$index_facture_position]['montant_ttc'].chr(128), 0, 0, 'C');
|
|
|
|
$montant_ht_total = $montant_ht_total+$mois[$index_facture_position]['montant_htc'];
|
|
$montant_tva_total = $montant_tva_total+$mois[$index_facture_position]['montant_tva'];
|
|
$montant_ttc_total = $montant_ttc_total+$mois[$index_facture_position]['montant_ttc'];
|
|
|
|
$y_facture=$y_facture+5;
|
|
}
|
|
|
|
$nb_facture_chargee = $index_facture_position+1;
|
|
$reste_a_chargee = sizeof($mois) - $nb_facture_chargee;
|
|
$max_nb_toget = ($reste_a_chargee <= 26) ? $reste_a_chargee+1 : 26;
|
|
|
|
// si derniere page alors afficher cadre des TVA
|
|
if ($num_page == $nb_page)
|
|
{
|
|
$pdf->Line(5, 225, 205, 225);
|
|
$pdf->SetFont('Arial','B',8); $pdf->SetXY( 5, 225 ); $pdf->Cell( 140, 8, 'TOTAL', 0, 0, 'C');
|
|
$pdf->SetFont('Arial','',8); $pdf->SetXY( 147, 225 ); $pdf->Cell( 13, 8, $montant_ht_total.chr(128), 0, 0, 'C');
|
|
$pdf->SetFont('Arial','',8); $pdf->SetXY( 168, 225 ); $pdf->Cell( 10, 8, $montant_tva_total.chr(128), 0, 0, 'C');
|
|
$pdf->SetFont('Arial','',8); $pdf->SetXY( 183, 225 ); $pdf->Cell( 22, 8, $montant_ttc_total.chr(128), 0, 0, 'C');
|
|
|
|
$pdf->Rect(145, 233, 60, 7, "D");
|
|
$pdf->SetFont('Arial','B',8); $pdf->SetXY( 147, 233 ); $pdf->Cell( 30, 6.5, 'TOTAL TTC', 0, 0, 'C');
|
|
$pdf->SetFont('Arial','B',8); $pdf->SetXY( 183, 233 ); $pdf->SetFillColor(255, 255, 0); $pdf->SetTextColor(255, 0, 0); $pdf->Cell( 22, 6.5, $montant_ttc_total.chr(128), 0, 0, 'C', true);
|
|
}
|
|
|
|
$y1 = 245;
|
|
|
|
$pdf->SetFillColor(255);
|
|
$pdf->SetTextColor(0, 0, 0);
|
|
|
|
$pdf->SetFont('Arial','',9);
|
|
|
|
$pdf->SetXY( 10, $y1 ); $pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Loi N° 92-442 du 31 décembre 1992: La présente facture est payable en comptant a réception."), 0, 0, 'L');
|
|
$pdf->SetXY( 10, $y1 + 4 ); $pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Indemnité forfaitaire pour frais de recouvrement due en cas de retard de paiement: 40").chr(128), 0, 0, 'L');
|
|
$pdf->SetXY( 10, $y1 + 8 ); $pdf->Multicell( $pdf->GetPageWidth()-20, 4, utf8_decode("Toute somme non payée dans les trente jours est susceptible de porter intérets à un taux égal à une fois et demi le taux de l'intéret légal."), 0, 0, 'L');
|
|
|
|
// **************************
|
|
// pied de page
|
|
// **************************
|
|
|
|
$pdf->SetFont('Arial','',6);
|
|
$pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C');
|
|
$pdf->SetXY( 1, $y0 + 8 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C');
|
|
$pdf->SetXY( 1, $y0 + 12 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->telephone)), 0, 0, 'C');
|
|
|
|
/*$pdf->SetXY( 1, $y0 + 16 );
|
|
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
|
|
|
|
$num_page++;
|
|
}
|
|
|
|
$ff_pdf = html_entity_decode($current_config[0]->path).'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'/GROUPE_OGF_RECAP_FACTURE_'.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'_'.$key_annee.'.pdf';
|
|
$this->storage->newFile($ff_pdf);
|
|
$pdfContent = $pdf->Output('','S');
|
|
|
|
$file_pdf = $this->storage->get($ff_pdf);
|
|
$file_pdf->putContent($pdfContent);
|
|
}
|
|
}
|
|
|
|
} catch(\OCP\Files\NotFoundException $e) { }
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
}
|
|
|
|
private function generer_document_comptable_client($date, $idclient) {
|
|
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
|
try {
|
|
try {
|
|
$data_factures = array();
|
|
$factures = json_decode($this->myDb->getCurrentMonthFactures_byClient($this->idNextcloud, $date, $idclient));
|
|
$factures = array_filter($factures, function($facture) {return $facture->id_client != NULL; });
|
|
foreach ($factures as $key => $facture) {
|
|
$facture_temp = array(
|
|
'num' => $facture->num,
|
|
'id_client' => $facture->id_client,
|
|
'client' => $facture->entreprise,
|
|
'adresse_client' => $facture->adresse_client,
|
|
'mail_client' => $facture->mail_client,
|
|
'adresse_devis' => $facture->lieu,
|
|
'nom_client' => html_entity_decode($facture->nom),
|
|
'prenoms_client' => html_entity_decode($facture->prenom),
|
|
'numero_commande' => $facture->numero_commande,
|
|
'date_soin' => $facture->date_soin,
|
|
'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,
|
|
);
|
|
$produits = json_decode($this->getProduitsById($facture->id_devis));
|
|
foreach ($produits as $key => $produit) {
|
|
$facture_temp['montant_htc'] += $produit->prix_unitaire * $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])][strval($datesplit[1])][$facture['id_client']]==NULL) {
|
|
$data_temp[strval($datesplit[0])][strval($datesplit[1])][$facture['id_client']] = array(0=>$facture);
|
|
} else {
|
|
array_push($data_temp[strval($datesplit[0])][strval($datesplit[1])][$facture['id_client']], $facture);
|
|
}
|
|
}
|
|
foreach ($data_temp as $key_annee => $annee) {
|
|
foreach ($annee as $key_mois => $mois) {
|
|
foreach ($mois as $key_client => $client) {
|
|
$pdf = new FPDF();
|
|
|
|
$current_client = '';
|
|
$adresse = '';
|
|
$date_facture;
|
|
$j=1;
|
|
foreach ($client as $key => $facture) {
|
|
if($j==1) {
|
|
$current_client = $facture['prenoms_client'].' '.$facture['nom_client'];
|
|
$adresse = $facture['adresse_client'];
|
|
$date_facture = $facture['date_facture'];
|
|
}
|
|
$j++;
|
|
}
|
|
$date_temp = date("t-m-Y", strtotime($date_facture));
|
|
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
|
|
$date_formated = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_temp));
|
|
|
|
try {
|
|
$this->storage->newFolder(html_entity_decode($current_config[0]->path).'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'/');
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
|
|
$pdf->AddPage();
|
|
// on sup les 2 cm en bas
|
|
$pdf->SetAutoPagebreak(False);
|
|
$pdf->SetMargins(0,0,0);
|
|
|
|
// logo : 80 de largeur et 55 de hauteur
|
|
$pdf->Image($this->src_path."logo.png", 10, 10, 55, 30);
|
|
// adresse du facture
|
|
$pdf->SetFont('Arial','B',11); $_x = 122 ; $_y = 40;
|
|
$pdf->SetXY( $_x, $_y ); $pdf->Cell( 100, 8, utf8_decode($current_client), 0, 0, ''); $_y += 8;
|
|
$pdf->SetXY( $_x, $_y ); $pdf->MultiCell( 80, 4, utf8_decode(html_entity_decode($adresse)), 0, 0, '');
|
|
// date facture
|
|
$pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 60 );
|
|
$pdf->Cell( 60, 8, "Croth le, ".utf8_decode($date_formated), 0, 0, '');
|
|
|
|
// observations
|
|
$pdf->SetFont( "Arial", "BU", 10 ); $pdf->SetXY( 10, 85 ) ; $pdf->Cell($pdf->GetStringWidth("Objet:"), 0, "Objet:", 0, "L");
|
|
$objet = utf8_decode("Récapitulatif Facturation du mois de ").strtoupper($this->convert_special_char(explode(' ', $date_formated)[1]));
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 85 ) ; $pdf->Cell($pdf->GetStringWidth($objet), 0, $objet, 0, "L");
|
|
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 95 ); $pdf->Cell($pdf->GetStringWidth("Madame, Monsieur"), 0, "Madame, Monsieur", 0, "L");
|
|
|
|
$text1 = utf8_decode("Veuillez trouver ci-dessous le récapitulatif de la facturation du mois de ").strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).".";
|
|
$text2 = utf8_decode("Vous en souhaitant bonne réception.");
|
|
$text3 = utf8_decode("Veuillez agréer, Madame, Monsieur, mes salutations les meilleures.");
|
|
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 105 ) ; $pdf->Cell($pdf->GetStringWidth($text1), 0, $text1, 0, "L");
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 110 ) ; $pdf->Cell($pdf->GetStringWidth($text2), 0, $text2, 0, "L");
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 120 ) ; $pdf->Cell($pdf->GetStringWidth($text3), 0, $text3, 0, "L");
|
|
|
|
// signature
|
|
$pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 145 );
|
|
$pdf->Cell( $pdf->GetStringWidth($current_config[0]->nom.' '.$current_config[0]->prenom), 0, utf8_decode(html_entity_decode($current_config[0]->nom.' '.$current_config[0]->prenom)), 0, 0, 'L');
|
|
$pdf->Image($this->src_path."sign.png", 122, 150, 55, 30);
|
|
|
|
$y0 = 260;
|
|
$pageWidth = $pdf->GetPageWidth();
|
|
//Positionnement en bas et tout centrer
|
|
$pdf->SetFont('Arial','',6);
|
|
$pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C');
|
|
$pdf->SetXY( 1, $y0 + 8 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C');
|
|
$pdf->SetXY( 1, $y0 + 12 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->telephone)), 0, 0, 'C');
|
|
|
|
/*$pdf->SetXY( 1, $y0 + 16 );
|
|
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
|
|
|
|
$num_page = 1;
|
|
$nb_page = ceil(sizeof($client) / 26);
|
|
$index_facture_position = 0;
|
|
$max_nb_toget = (sizeof($client)<=26)?sizeof($client):26;
|
|
|
|
$montant_ht_total = 0;
|
|
$montant_tva_total = 0;
|
|
$montant_ttc_total = 0;
|
|
|
|
while ($num_page <= $nb_page) {
|
|
$pdf->AddPage();
|
|
// on sup les 2 cm en bas
|
|
$pdf->SetAutoPagebreak(False);
|
|
$pdf->SetMargins(0,0,0);
|
|
|
|
$pdf->Image($this->src_path."logo.png", 10, 10, 55, 30);
|
|
|
|
// n° page en haute à droite
|
|
if($nb_page>1){
|
|
$pdf->SetXY( 120, 5 ); $pdf->SetFont( "Arial", "B", 9 ); $pdf->Cell( 160, 8, $num_page . '/' . $nb_page, 0, 0, 'C');
|
|
}
|
|
|
|
// date facture
|
|
$pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 15 );
|
|
$pdf->Cell( 60, 8, "Croth le, ".utf8_decode($date_formated), 0, 0, '');
|
|
|
|
// n° facture, date echeance et reglement et obs
|
|
$pdf->SetLineWidth(0.1); $pdf->SetFillColor(255); $pdf->Rect(100, 30, 85, 8, "DF");
|
|
$pdf->SetXY( 100, 30 ); $pdf->SetFont( "Arial", "B", 12 ); $pdf->Cell( 85, 8, 'FACTURE N'.utf8_decode('°').' ETS/'.$key_annee.'/'.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])), 0, 0, 'C');
|
|
|
|
// adresse du facture
|
|
$pdf->SetFont('Arial','B',11); $x = 122 ; $y = 45;
|
|
$pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, utf8_decode($current_client), 0, 0, ''); $y += 8;
|
|
$pdf->SetXY( $x, $y ); $pdf->MultiCell( 80, 4, utf8_decode(html_entity_decode($adresse)), 0, 0, ''); $y += 9;
|
|
$pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, 'Email:', 0, 0, ''); $x+=13;
|
|
$pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, utf8_decode(html_entity_decode($facture['mail_client'])), 0, 0, '');
|
|
|
|
// ***********************
|
|
// le cadre des articles
|
|
// ***********************
|
|
// cadre avec 18 lignes max ! et 118 de hauteur --> 80 + 118 = 198 pour les traits verticaux
|
|
$pdf->SetLineWidth(0.1); $pdf->Rect(5, 80, 200, 153, "D");
|
|
// cadre titre des colonnes
|
|
$pdf->Line(5, 90, 205, 90);
|
|
// les traits verticaux colonnes
|
|
$pdf->Line(145, 80, 145, 233); $pdf->Line(163, 80, 163, 233);
|
|
if($num_page == $nb_page) $pdf->Line(183, 80, 183, 240);
|
|
else $pdf->Line(183, 80, 183, 233);
|
|
// titre colonne
|
|
$pdf->SetXY( 1, 81 ); $pdf->SetFont('Arial','B',8); $pdf->Cell( 140, 8, "OBJET", 0, 0, 'C');
|
|
$pdf->SetXY( 147, 81 ); $pdf->SetFont('Arial','B',8); $pdf->Cell( 13, 8, "H.T.", 0, 0, 'C');
|
|
$pdf->SetXY( 168, 81 ); $pdf->SetFont('Arial','B',8); $pdf->Cell( 10, 8, "TVA 20%", 0, 0, 'C');
|
|
$pdf->SetXY( 183, 81 ); $pdf->SetFont('Arial','B',8); $pdf->Cell( 22, 8, "T.T.C", 0, 0, 'C');
|
|
|
|
// (new DateTime($facture['date_soin']))->format('d-M')
|
|
$formatter_ds = new IntlDateFormatter('fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
|
|
|
|
// Set the pattern for the formatter to "d-MMMM" to display the day and month name in French
|
|
$formatter_ds->setPattern('dd-MMM');
|
|
|
|
//recuperation des factures
|
|
$y_facture = 90;
|
|
|
|
$init_index = $index_facture_position;
|
|
|
|
for ($index_facture_position; $index_facture_position < ($init_index + $max_nb_toget) ; $index_facture_position++) {
|
|
$date_soin_temp = new DateTime($client[$index_facture_position]['date_soin']);
|
|
|
|
$pdf->SetXY( 6, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, $client[$index_facture_position]['num'], 0, 0, '');
|
|
$pdf->SetXY( 32, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, $client[$index_facture_position]['numero_commande'], 0, 0, '');
|
|
$pdf->SetXY( 53, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 18, 8, utf8_decode($formatter_ds->format($date_soin_temp)), 0, 0, '');
|
|
$pdf->SetXY( 65, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 38, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['adresse_devis'])), 0, 0, '');
|
|
$pdf->SetXY( 100, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['defunt'])), 0, 0, '');
|
|
$pdf->SetXY( 147, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 13, 8, $client[$index_facture_position]['montant_htc'].chr(128), 0, 0, 'C');
|
|
$pdf->SetXY( 168, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 10, 8, $client[$index_facture_position]['montant_tva'].chr(128), 0, 0, 'C');
|
|
$pdf->SetXY( 183, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 22, 8, $client[$index_facture_position]['montant_ttc'].chr(128), 0, 0, 'C');
|
|
|
|
$montant_ht_total = $montant_ht_total+$client[$index_facture_position]['montant_htc'];
|
|
$montant_tva_total = $montant_tva_total+$client[$index_facture_position]['montant_tva'];
|
|
$montant_ttc_total = $montant_ttc_total+$client[$index_facture_position]['montant_ttc'];
|
|
|
|
$y_facture=$y_facture+5;
|
|
}
|
|
|
|
$nb_facture_chargee = $index_facture_position+1;
|
|
$reste_a_chargee = sizeof($client) - $nb_facture_chargee;
|
|
$max_nb_toget = ($reste_a_chargee <= 26) ? $reste_a_chargee+1 : 26;
|
|
|
|
// si derniere page alors afficher cadre des TVA
|
|
if ($num_page == $nb_page)
|
|
{
|
|
$pdf->Line(5, 225, 205, 225);
|
|
$pdf->SetFont('Arial','B',8); $pdf->SetXY( 5, 225 ); $pdf->Cell( 140, 8, 'TOTAL', 0, 0, 'C');
|
|
$pdf->SetFont('Arial','',8); $pdf->SetXY( 147, 225 ); $pdf->Cell( 13, 8, $montant_ht_total.chr(128), 0, 0, 'C');
|
|
$pdf->SetFont('Arial','',8); $pdf->SetXY( 168, 225 ); $pdf->Cell( 10, 8, $montant_tva_total.chr(128), 0, 0, 'C');
|
|
$pdf->SetFont('Arial','',8); $pdf->SetXY( 183, 225 ); $pdf->Cell( 22, 8, $montant_ttc_total.chr(128), 0, 0, 'C');
|
|
|
|
$pdf->Rect(145, 233, 60, 7, "D");
|
|
$pdf->SetFont('Arial','B',8); $pdf->SetXY( 147, 233 ); $pdf->Cell( 30, 6.5, 'TOTAL TTC', 0, 0, 'C');
|
|
$pdf->SetFont('Arial','B',8); $pdf->SetXY( 183, 233 ); $pdf->SetFillColor(255, 255, 0); $pdf->SetTextColor(255, 0, 0); $pdf->Cell( 22, 6.5, $montant_ttc_total.chr(128), 0, 0, 'C', true);
|
|
}
|
|
|
|
$y1 = 245;
|
|
|
|
$pdf->SetFillColor(255);
|
|
$pdf->SetTextColor(0, 0, 0);
|
|
|
|
$pdf->SetFont('Arial','',9);
|
|
|
|
$pdf->SetXY( 10, $y1 );$pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Loi N° 92-442 du 31 décembre 1992: La présente facture est payable en comptant a réception."), 0, 0, 'L');
|
|
$pdf->SetXY( 10, $y1 + 4 );$pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Indemnité forfaitaire pour frais de recouvrement due en cas de retard de paiement: 40").chr(128), 0, 0, 'L');
|
|
$pdf->SetXY( 10, $y1 + 8 );$pdf->Multicell( $pdf->GetPageWidth()-20, 4, utf8_decode("Toute somme non payée dans les trente jours est susceptible de porter intérets à un taux égal à une fois et demi le taux de l'intéret légal."), 0, 0, 'L');
|
|
|
|
// **************************
|
|
// pied de page
|
|
// **************************
|
|
|
|
$pdf->SetFont('Arial','',6);
|
|
$pdf->SetXY( 1, $y0 + 4 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C');
|
|
$pdf->SetXY( 1, $y0 + 8 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C');
|
|
$pdf->SetXY( 1, $y0 + 12 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->telephone)), 0, 0, 'C');
|
|
|
|
/*$pdf->SetXY( 1, $y0 + 16 );
|
|
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
|
|
|
|
$num_page++;
|
|
}
|
|
|
|
$ff_pdf = html_entity_decode($current_config[0]->path).'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'/'.strtoupper($this->convert_special_char($current_client)).'_RECAP_FACTURE_'.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'_'.$key_annee.'.pdf';
|
|
$this->storage->newFile($ff_pdf);
|
|
$pdfContent = $pdf->Output('','S');
|
|
|
|
$file_pdf = $this->storage->get($ff_pdf);
|
|
$file_pdf->putContent($pdfContent);
|
|
}
|
|
}
|
|
}
|
|
} catch(\OCP\Files\NotFoundException $e) { }
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
}
|
|
|
|
private function generer_document_comptable($date) {
|
|
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
|
try {
|
|
try {
|
|
$data_factures = array();
|
|
$factures = json_decode($this->myDb->getCurrentMonthFactures($this->idNextcloud, $date));
|
|
$factures = array_filter($factures, function($facture) {return $facture->id_client != NULL; });
|
|
foreach ($factures as $key => $facture) {
|
|
$facture_temp = array(
|
|
'num' => $facture->num,
|
|
'id_client' => $facture->id_client,
|
|
'client' => $facture->entreprise,
|
|
'adresse_client' => $facture->adresse_client,
|
|
'mail_client' => $facture->mail_client,
|
|
'adresse_devis' => $facture->lieu,
|
|
'nom_client' => html_entity_decode($facture->nom),
|
|
'prenoms_client' => html_entity_decode($facture->prenom),
|
|
'numero_commande' => $facture->numero_commande,
|
|
'date_soin' => $facture->date_soin,
|
|
'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,
|
|
);
|
|
$produits = json_decode($this->getProduitsById($facture->id_devis));
|
|
foreach ($produits as $key => $produit) {
|
|
$facture_temp['montant_htc'] += $produit->prix_unitaire * $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])][strval($datesplit[1])][$facture['id_client']]==NULL) {
|
|
$data_temp[strval($datesplit[0])][strval($datesplit[1])][$facture['id_client']] = array(0=>$facture);
|
|
} else {
|
|
array_push($data_temp[strval($datesplit[0])][strval($datesplit[1])][$facture['id_client']], $facture);
|
|
}
|
|
}
|
|
foreach ($data_temp as $key_annee => $annee) {
|
|
foreach ($annee as $key_mois => $mois) {
|
|
foreach ($mois as $key_client => $client) {
|
|
$pdf = new FPDF();
|
|
|
|
$current_client = '';
|
|
$adresse = '';
|
|
$date_facture;
|
|
$j=1;
|
|
foreach ($client as $key => $facture) {
|
|
if($j==1) {
|
|
$current_client = $facture['prenoms_client'].' '.$facture['nom_client'];
|
|
$adresse = $facture['adresse_client'];
|
|
$date_facture = $facture['date_facture'];
|
|
}
|
|
$j++;
|
|
}
|
|
$date_temp = date("t-m-Y", strtotime($date_facture));
|
|
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
|
|
$date_formated = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_temp));
|
|
|
|
try {
|
|
$this->storage->newFolder(html_entity_decode($current_config[0]->path).'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'/');
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
|
|
$pdf->AddPage();
|
|
// on sup les 2 cm en bas
|
|
$pdf->SetAutoPagebreak(False);
|
|
$pdf->SetMargins(0,0,0);
|
|
|
|
// logo : 80 de largeur et 55 de hauteur
|
|
$pdf->Image($this->src_path."logo.png", 10, 10, 55, 30);
|
|
// adresse du facture
|
|
$pdf->SetFont('Arial','B',11); $_x = 122 ; $_y = 40;
|
|
$pdf->SetXY( $_x, $_y ); $pdf->Cell( 100, 8, utf8_decode($current_client), 0, 0, ''); $_y += 8;
|
|
$pdf->SetXY( $_x, $_y ); $pdf->MultiCell( 80, 4, utf8_decode(html_entity_decode($adresse)), 0, 0, '');
|
|
// date facture
|
|
$pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 60 );
|
|
$pdf->Cell( 60, 8, "Croth le, ".utf8_decode($date_formated), 0, 0, '');
|
|
|
|
// observations
|
|
$pdf->SetFont( "Arial", "BU", 10 ); $pdf->SetXY( 10, 85 ) ; $pdf->Cell($pdf->GetStringWidth("Objet:"), 0, "Objet:", 0, "L");
|
|
$objet = utf8_decode("Récapitulatif Facturation du mois de ").strtoupper($this->convert_special_char(explode(' ', $date_formated)[1]));
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 85 ) ; $pdf->Cell($pdf->GetStringWidth($objet), 0, $objet, 0, "L");
|
|
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 95 ); $pdf->Cell($pdf->GetStringWidth("Madame, Monsieur"), 0, "Madame, Monsieur", 0, "L");
|
|
|
|
$text1 = utf8_decode("Veuillez trouver ci-dessous le récapitulatif de la facturation du mois de ").strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).".";
|
|
$text2 = utf8_decode("Vous en souhaitant bonne réception.");
|
|
$text3 = utf8_decode("Veuillez agréer, Madame, Monsieur, mes salutations les meilleures.");
|
|
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 105 ) ; $pdf->Cell($pdf->GetStringWidth($text1), 0, $text1, 0, "L");
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 110 ) ; $pdf->Cell($pdf->GetStringWidth($text2), 0, $text2, 0, "L");
|
|
$pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 120 ) ; $pdf->Cell($pdf->GetStringWidth($text3), 0, $text3, 0, "L");
|
|
|
|
// signature
|
|
$pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 145 );
|
|
$pdf->Cell( $pdf->GetStringWidth($current_config[0]->nom.' '.$current_config[0]->prenom), 0, utf8_decode(html_entity_decode($current_config[0]->nom.' '.$current_config[0]->prenom)), 0, 0, 'L');
|
|
$pdf->Image($this->src_path."sign.png", 122, 150, 55, 30);
|
|
|
|
$y0 = 260;
|
|
$pageWidth = $pdf->GetPageWidth();
|
|
//Positionnement en bas et tout centrer
|
|
$pdf->SetFont('Arial','',6);
|
|
$pdf->SetXY( 1, $y0 + 4 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C');
|
|
$pdf->SetXY( 1, $y0 + 8 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C');
|
|
$pdf->SetXY( 1, $y0 + 12 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->telephone)), 0, 0, 'C');
|
|
|
|
/*$pdf->SetXY( 1, $y0 + 16 );
|
|
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
|
|
|
|
$num_page = 1;
|
|
$nb_page = ceil(sizeof($client) / 26);
|
|
$index_facture_position = 0;
|
|
$max_nb_toget = (sizeof($client)<=26)?sizeof($client):26;
|
|
|
|
$montant_ht_total = 0;
|
|
$montant_tva_total = 0;
|
|
$montant_ttc_total = 0;
|
|
|
|
while ($num_page <= $nb_page) {
|
|
$pdf->AddPage();
|
|
// on sup les 2 cm en bas
|
|
$pdf->SetAutoPagebreak(False);
|
|
$pdf->SetMargins(0,0,0);
|
|
|
|
$pdf->Image($this->src_path."logo.png", 10, 10, 55, 30);
|
|
|
|
// n° page en haute à droite
|
|
if($nb_page>1){
|
|
$pdf->SetXY( 120, 5 ); $pdf->SetFont( "Arial", "B", 9 ); $pdf->Cell( 160, 8, $num_page . '/' . $nb_page, 0, 0, 'C');
|
|
}
|
|
|
|
// date facture
|
|
$pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 15 );
|
|
$pdf->Cell( 60, 8, "Croth le, ".utf8_decode($date_formated), 0, 0, '');
|
|
|
|
// n° facture, date echeance et reglement et obs
|
|
$pdf->SetLineWidth(0.1); $pdf->SetFillColor(255); $pdf->Rect(100, 30, 85, 8, "DF");
|
|
$pdf->SetXY( 100, 30 ); $pdf->SetFont( "Arial", "B", 12 ); $pdf->Cell( 85, 8, 'FACTURE N'.utf8_decode('°').' ETS/'.$key_annee.'/'.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])), 0, 0, 'C');
|
|
|
|
// adresse du facture
|
|
$pdf->SetFont('Arial','B',11); $x = 122 ; $y = 45;
|
|
$pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, utf8_decode($current_client), 0, 0, ''); $y += 8;
|
|
$pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, utf8_decode(html_entity_decode($facture['mail_client'])), 0, 0, ''); $y += 8;
|
|
$pdf->SetXY( $x, $y ); $pdf->MultiCell( 80, 4, utf8_decode(html_entity_decode($adresse)), 0, 0, '');
|
|
|
|
// ***********************
|
|
// le cadre des articles
|
|
// ***********************
|
|
// cadre avec 18 lignes max ! et 118 de hauteur --> 80 + 118 = 198 pour les traits verticaux
|
|
$pdf->SetLineWidth(0.1); $pdf->Rect(5, 80, 200, 153, "D");
|
|
// cadre titre des colonnes
|
|
$pdf->Line(5, 90, 205, 90);
|
|
// les traits verticaux colonnes
|
|
$pdf->Line(145, 80, 145, 233); $pdf->Line(163, 80, 163, 233);
|
|
if($num_page == $nb_page) $pdf->Line(183, 80, 183, 240);
|
|
else $pdf->Line(183, 80, 183, 233);
|
|
// titre colonne
|
|
$pdf->SetXY( 1, 81 ); $pdf->SetFont('Arial','B',8); $pdf->Cell( 140, 8, "OBJET", 0, 0, 'C');
|
|
$pdf->SetXY( 147, 81 ); $pdf->SetFont('Arial','B',8); $pdf->Cell( 13, 8, "H.T.", 0, 0, 'C');
|
|
$pdf->SetXY( 168, 81 ); $pdf->SetFont('Arial','B',8); $pdf->Cell( 10, 8, "TVA 20%", 0, 0, 'C');
|
|
$pdf->SetXY( 183, 81 ); $pdf->SetFont('Arial','B',8); $pdf->Cell( 22, 8, "T.T.C", 0, 0, 'C');
|
|
|
|
// (new DateTime($facture['date_soin']))->format('d-M')
|
|
$formatter_ds = new IntlDateFormatter('fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
|
|
|
|
// Set the pattern for the formatter to "d-MMMM" to display the day and month name in French
|
|
$formatter_ds->setPattern('dd-MMM');
|
|
|
|
//recuperation des factures
|
|
$y_facture = 90;
|
|
|
|
$init_index = $index_facture_position;
|
|
|
|
for ($index_facture_position; $index_facture_position < ($init_index + $max_nb_toget) ; $index_facture_position++) {
|
|
$date_soin_temp = new DateTime($client[$index_facture_position]['date_soin']);
|
|
|
|
$pdf->SetXY( 6, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, $client[$index_facture_position]['num'], 0, 0, '');
|
|
$pdf->SetXY( 32, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, $client[$index_facture_position]['numero_commande'], 0, 0, '');
|
|
$pdf->SetXY( 53, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 18, 8, utf8_decode($formatter_ds->format($date_soin_temp)), 0, 0, '');
|
|
$pdf->SetXY( 65, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 38, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['adresse_devis'])), 0, 0, '');
|
|
$pdf->SetXY( 100, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['defunt'])), 0, 0, '');
|
|
$pdf->SetXY( 147, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 13, 8, $client[$index_facture_position]['montant_htc'].chr(128), 0, 0, 'C');
|
|
$pdf->SetXY( 168, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 10, 8, $client[$index_facture_position]['montant_tva'].chr(128), 0, 0, 'C');
|
|
$pdf->SetXY( 183, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 22, 8, $client[$index_facture_position]['montant_ttc'].chr(128), 0, 0, 'C');
|
|
|
|
$montant_ht_total = $montant_ht_total+$client[$index_facture_position]['montant_htc'];
|
|
$montant_tva_total = $montant_tva_total+$client[$index_facture_position]['montant_tva'];
|
|
$montant_ttc_total = $montant_ttc_total+$client[$index_facture_position]['montant_ttc'];
|
|
|
|
$y_facture=$y_facture+5;
|
|
}
|
|
|
|
$nb_facture_chargee = $index_facture_position+1;
|
|
$reste_a_chargee = sizeof($client) - $nb_facture_chargee;
|
|
$max_nb_toget = ($reste_a_chargee <= 26) ? $reste_a_chargee+1 : 26;
|
|
|
|
// si derniere page alors afficher cadre des TVA
|
|
if ($num_page == $nb_page)
|
|
{
|
|
$pdf->Line(5, 225, 205, 225);
|
|
$pdf->SetFont('Arial','B',8); $pdf->SetXY( 5, 225 ); $pdf->Cell( 140, 8, 'TOTAL', 0, 0, 'C');
|
|
$pdf->SetFont('Arial','',8); $pdf->SetXY( 147, 225 ); $pdf->Cell( 13, 8, $montant_ht_total.chr(128), 0, 0, 'C');
|
|
$pdf->SetFont('Arial','',8); $pdf->SetXY( 168, 225 ); $pdf->Cell( 10, 8, $montant_tva_total.chr(128), 0, 0, 'C');
|
|
$pdf->SetFont('Arial','',8); $pdf->SetXY( 183, 225 ); $pdf->Cell( 22, 8, $montant_ttc_total.chr(128), 0, 0, 'C');
|
|
|
|
$pdf->Rect(145, 233, 60, 7, "D");
|
|
$pdf->SetFont('Arial','B',8); $pdf->SetXY( 147, 233 ); $pdf->Cell( 30, 6.5, 'TOTAL TTC', 0, 0, 'C');
|
|
$pdf->SetFont('Arial','B',8); $pdf->SetXY( 183, 233 ); $pdf->SetFillColor(255, 255, 0); $pdf->SetTextColor(255, 0, 0); $pdf->Cell( 22, 6.5, $montant_ttc_total.chr(128), 0, 0, 'C', true);
|
|
}
|
|
|
|
$y1 = 245;
|
|
|
|
$pdf->SetFillColor(255);
|
|
$pdf->SetTextColor(0, 0, 0);
|
|
|
|
$pdf->SetFont('Arial','',9);
|
|
|
|
$pdf->SetXY( 10, $y1 ); $pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Loi N° 92-442 du 31 décembre 1992: La présente facture est payable en comptant a réception."), 0, 0, 'L');
|
|
$pdf->SetXY( 10, $y1 + 4 ); $pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Indemnité forfaitaire pour frais de recouvrement due en cas de retard de paiement: 40").chr(128), 0, 0, 'L');
|
|
$pdf->SetXY( 10, $y1 + 8 ); $pdf->Multicell( $pdf->GetPageWidth()-20, 4, utf8_decode("Toute somme non payée dans les trente jours est susceptible de porter intérets à un taux égal à une fois et demi le taux de l'intéret légal."), 0, 0, 'L');
|
|
|
|
// **************************
|
|
// pied de page
|
|
// **************************
|
|
|
|
$pdf->SetFont('Arial','',6);
|
|
$pdf->SetXY( 1, $y0 + 4 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C');
|
|
$pdf->SetXY( 1, $y0 + 8 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C');
|
|
$pdf->SetXY( 1, $y0 + 12 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->telephone)), 0, 0, 'C');
|
|
|
|
$num_page++;
|
|
}
|
|
|
|
$ff_pdf = html_entity_decode($current_config[0]->path).'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'/'.strtoupper($this->convert_special_char($current_client)).'_RECAP_FACTURE_'.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'_'.$key_annee.'.pdf';
|
|
$this->storage->newFile($ff_pdf);
|
|
$pdfContent = $pdf->Output('','S');
|
|
|
|
$file_pdf = $this->storage->get($ff_pdf);
|
|
$file_pdf->putContent($pdfContent);
|
|
}
|
|
}
|
|
}
|
|
} catch(\OCP\Files\NotFoundException $e) { }
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
}
|
|
|
|
private function convert_special_char($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 );
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getConfiguration() {
|
|
return $this->myDb->getConfiguration($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getDevis() {
|
|
return $this->myDb->getDevis($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getDevisDelphine($idtrajetdetails) {
|
|
return $this->myDb->getDevisDelphine($idtrajetdetails, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getTrajets() {
|
|
return $this->myDb->getTrajets($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numtrajet
|
|
*/
|
|
public function getTrajetsdetails($numtrajet) {
|
|
$result = $this->myDb->getTrajetsdetails($numtrajet, $this->idNextcloud);
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getLieux() {
|
|
return $this->myDb->getLieux($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function ajaxGetLieux() {
|
|
return $this->myDb->getLieux($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function ajaxGetClientsName() {
|
|
return $this->myDb->getClientsName();
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getFactures() {
|
|
//$this->synchronize_facture();
|
|
$result = $this->myDb->getFactures($this->idNextcloud);
|
|
$this->refreshFEC();
|
|
return $result;
|
|
}
|
|
|
|
private function synchronize_facture() {
|
|
$factures = json_decode($this->myDb->getFactures($this->idNextcloud));
|
|
foreach ($factures as $key => $facture) {
|
|
if($facture->id_devis) {
|
|
$deviscourant = json_decode($this->myDb->getOneDevis($facture->id_devis, $this->idNextcloud))[0];
|
|
$this->myDb->gestion_update('facture', 'date', $deviscourant->date, $facture->id, $this->idNextcloud);
|
|
$this->myDb->gestion_update('facture', 'version', html_entity_decode($deviscourant->version), $facture->id, $this->idNextcloud);
|
|
$this->myDb->gestion_update('facture', 'type_paiement', 'comptant', $facture->id, $this->idNextcloud);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getProduits() {
|
|
return $this->myDb->getProduits($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function ajaxGetProduits() {
|
|
return $this->myDb->getProduits($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numdevis
|
|
*/
|
|
public function getProduitsById($numdevis) {
|
|
return $this->myDb->getListProduit($numdevis, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getBibliotheques() {
|
|
return $this->myDb->getBibliotheques($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $id
|
|
*/
|
|
public function getClient($id) {
|
|
return $this->myDb->getClient($id, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $id
|
|
*/
|
|
public function getClientbyiddevis($id) {
|
|
return $this->myDb->getClientbyiddevis($id, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*/
|
|
public function getServerFromMail(){
|
|
return new DataResponse(['mail' => $this->config->getSystemValue('mail_from_address').'@'.$this->config->getSystemValue('mail_domain')],200, ['Content-Type' => 'application/json']);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function insertClient() {
|
|
// try {
|
|
// return new DataResponse($this->myDb->insertClient($this->idNextcloud), Http::STATUS_OK, ['Content-Type' => 'application/json']);
|
|
// }
|
|
// catch( PDOException $Exception ) {
|
|
// return new DataResponse($Exception, 500, ['Content-Type' => 'application/json']);
|
|
// }
|
|
return $this->myDb->insertClient($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*
|
|
*/
|
|
public function insertLieu(){
|
|
return $this->myDb->insertLieu($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*
|
|
*/
|
|
public function insertTrajet(){
|
|
return $this->myDb->insertTrajet($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numtrajet
|
|
*
|
|
*/
|
|
public function insertTrajetdetails($numtrajet){
|
|
return $this->myDb->insertTrajetdetails($numtrajet, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numtrajet
|
|
*
|
|
*/
|
|
public function saveTrajetdetails($numtrajet){
|
|
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
|
$clean_folder = html_entity_decode($current_config[0]->path).'/';
|
|
|
|
try {
|
|
|
|
$trajet = json_decode($this->myDb->getOneTrajet($numtrajet, $this->idNextcloud))[0];
|
|
|
|
$formatter_ds = new IntlDateFormatter('fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
|
|
// Set the pattern for the formatter to "d-MMMM" to display the day and month name in French
|
|
$formatter_ds->setPattern('dd-MMM');
|
|
|
|
$monthName = $this->month_toString(intval($trajet->mois));
|
|
$fullnameThanato = (($trajet->nom_thanato != NULL) ? $trajet->nom_thanato : '').' '.(($trajet->prenom_thanato != NULL) ? $trajet->prenom_thanato : '');
|
|
|
|
$_clean_folder = $clean_folder.'INDEMNITES KILOMETRIQUES/'.$trajet->annee.'/'.strtoupper($fullnameThanato).'/';
|
|
try {
|
|
$this->storage->newFolder($_clean_folder);
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
|
|
$trajetdetails = json_decode($this->myDb->getTrajetsdetails_orderByDate($numtrajet, $idNextcloud));
|
|
$distance_temp = 0;
|
|
$distances = array();
|
|
$last_point = NULL;
|
|
|
|
$ik_temp = 'CLIENTS'.';'.'JOUR'.';'.'LIEU'.';'.'TOTAL'."\n";
|
|
for ($i=0; $i < sizeof($trajetdetails); $i++) {
|
|
$date_temp = new DateTime($trajetdetails[$i]->date);
|
|
if(strcmp(explode('-', $trajetdetails[$i]->date)[2], explode('-', $trajetdetails[$i+1]->date)[2])!=0) {
|
|
array_push($distances, $distance_temp);
|
|
$ik_temp = $ik_temp.utf8_decode(html_entity_decode($trajetdetails[$i]->cprenoms.' '.$trajetdetails[$i]->cnom)).';'.utf8_decode($formatter_ds->format($date_temp)).';'.utf8_decode(html_entity_decode($trajetdetails[$i]->lieu)).';'.$distance_temp."\n";
|
|
$distance_temp = 0;
|
|
$last_point = NULL;
|
|
} else {
|
|
$currentDistance = 0;
|
|
if($trajetdetails[$i]->lid != NULL) $last_point = $trajetdetails[$i];
|
|
if($last_point->lid != NULL && $trajetdetails[$i+1]->lid != NULL){
|
|
$currentDistance = $this->myDb->calcul_distance(floatval($last_point->latitude), floatval($last_point->longitude), floatval($trajetdetails[$i+1]->latitude), floatval($trajetdetails[$i+1]->longitude));
|
|
$distance_temp += $currentDistance;
|
|
}
|
|
$ik_temp = $ik_temp.utf8_decode(html_entity_decode($trajetdetails[$i]->cprenoms.' '.$trajetdetails[$i]->cnom)).';'.utf8_decode($formatter_ds->format($date_temp)).';'.utf8_decode(html_entity_decode($trajetdetails[$i]->lieu)).';'.$currentDistance."\n";
|
|
}
|
|
}
|
|
|
|
// distance total
|
|
$distance_final = 0;
|
|
foreach ($distances as $key => $valdistance) {
|
|
$distance_final += $valdistance;
|
|
}
|
|
|
|
$ik_temp = $ik_temp."\n\n\n\n".''.';'.''.';'.'sous total'.';'.$distance_final;
|
|
|
|
$total_ik = $distance_final * floatval($current_config[0]->coefficient_ik);
|
|
$ik_temp = $ik_temp."\n\n".''.';'.'TOTAL'.';'.$current_config[0]->coefficient_ik.';'.$total_ik;
|
|
$ik_temp = $ik_temp."\n".''.';'.'ELECTRIQUE'.';'.''.';'.round($total_ik, 2);
|
|
|
|
$nom_thanato = html_entity_decode($trajet->nom_thanato).' '.html_entity_decode($trajet->prenom_thanato);
|
|
$ff = $_clean_folder.'IK_'.$trajet->annee.'_'.$monthName.'_'.strtoupper($fullnameThanato).'_'.strtoupper($nom_thanato).'.csv';
|
|
$this->storage->newFile($ff);
|
|
$file = $this->storage->get($ff);
|
|
$file->putContent($ik_temp);
|
|
|
|
} catch(\OCP\Files\NotFoundException $e) { }
|
|
|
|
return true;
|
|
}
|
|
|
|
private function month_toString($monthnumber) {
|
|
$result = '';
|
|
switch ($monthnumber) {
|
|
case 1:
|
|
$result = '01JANVIER';
|
|
break;
|
|
case 2:
|
|
$result = '02FEVRIER';
|
|
break;
|
|
case 3:
|
|
$result = '03MARS';
|
|
break;
|
|
case 4:
|
|
$result = '04AVRIL';
|
|
break;
|
|
case 5:
|
|
$result = '05MAI';
|
|
break;
|
|
case 6:
|
|
$result = '06JUIN';
|
|
break;
|
|
case 7:
|
|
$result = '07JUILLET';
|
|
break;
|
|
case 8:
|
|
$result = '08AOUT';
|
|
break;
|
|
case 9:
|
|
$result = '09SEPTEMBRE';
|
|
break;
|
|
case 10:
|
|
$result = '10OCTOBRE';
|
|
break;
|
|
case 11:
|
|
$result = '11NOVEMBRE';
|
|
break;
|
|
case 12:
|
|
$result = '12DECEMBRE';
|
|
break;
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*
|
|
*/
|
|
public function insertDevis(){
|
|
return $this->myDb->insertDevis($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*
|
|
*/
|
|
public function insertFacture(){
|
|
$result = $this->myDb->insertFacture($this->idNextcloud);
|
|
$this->refreshFEC();
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*
|
|
*/
|
|
public function insertProduit(){
|
|
return $this->myDb->insertProduit($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $id
|
|
*/
|
|
public function insertProduitDevis($id){
|
|
return $this->myDb->insertProduitDevis($id, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $id
|
|
*/
|
|
public function insertArticleDevis($id){
|
|
return $this->myDb->insertArticleDevis($id, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $id
|
|
*/
|
|
public function insertObservationDefunt($id){
|
|
return $this->myDb->insertObservationDefunt($id, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $id
|
|
*/
|
|
public function insertBijouDefunt($id){
|
|
return $this->myDb->insertBijouDefunt($id, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $id
|
|
*/
|
|
public function insertHypoDefunt($id){
|
|
return $this->myDb->insertHypoDefunt($id, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*
|
|
*/
|
|
public function insertBibliotheque(){
|
|
return $this->myDb->insertBibliotheque($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $table
|
|
* @param string $column
|
|
* @param string $data
|
|
* @param string $id
|
|
*/
|
|
public function update($table, $column, $data, $id) {
|
|
if(strcmp($table, 'facture')==0 || strcmp($table, 'produit')==0 || strcmp($table, 'devis')==0 || strcmp($table, 'client')==0) {
|
|
if(strcmp($column, 'id_devis')==0) {
|
|
$facturecourant = json_decode($this->myDb->getOneFacture($id, $this->idNextcloud))[0];
|
|
$this->myDb->gestion_update('devis', 'mentions', 'facturé', $data, $this->idNextcloud);
|
|
$this->myDb->gestion_update('devis', 'mentions', 'Nouveau', $facturecourant->id_devis, $this->idNextcloud);
|
|
$result = $this->myDb->gestion_update($table, $column, $data, $id, $this->idNextcloud);
|
|
|
|
} else {
|
|
$facturecourant = json_decode($this->myDb->getOneFacture($id, $this->idNextcloud))[0];
|
|
if(strcmp($column, 'date_paiement')==0) {
|
|
$datecourant = $facturecourant->date_paiement;
|
|
$nouveaudate = $data;
|
|
$result = $this->myDb->gestion_update($table, $column, $data, $id, $this->idNextcloud);
|
|
$this->generer_document_comptable($datecourant);
|
|
$this->generer_document_comptable($nouveaudate);
|
|
} else {
|
|
$result = $this->myDb->gestion_update($table, $column, $data, $id, $this->idNextcloud);
|
|
// $this->generer_document_comptable($facturecourant->date_paiement);
|
|
}
|
|
}
|
|
$this->refreshFEC();
|
|
return $result;
|
|
}
|
|
return $this->myDb->gestion_update($table, $column, $data, $id, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param array $devisToFacture
|
|
*/
|
|
public function exportDevisToFacture($devisToFacture) {
|
|
$factureIdsGenerated = $this->myDb->insertFactureForeEachDevisId($this->idNextcloud,$devisToFacture);
|
|
$this->invoicePdfService->generateFacturePdfByFactureIds($factureIdsGenerated,$this->idNextcloud);
|
|
$this->refreshFEC();
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $table
|
|
* @param string $id
|
|
*/
|
|
public function delete($table, $id) {
|
|
if(strcmp($table, 'facture')==0 || strcmp($table, 'produit')==0 || strcmp($table, 'devis')==0 || strcmp($table, 'client')==0) {
|
|
if(strcmp($table, 'facture')==0) {
|
|
$facturecourant = json_decode($this->myDb->getOneFacture($id, $this->idNextcloud))[0];
|
|
$this->myDb->gestion_update('devis', 'mentions', 'Nouveau', $facturecourant->id_devis, $this->idNextcloud);
|
|
$result = $this->myDb->gestion_delete($table, $id, $this->idNextcloud);
|
|
} else {
|
|
$result = $this->myDb->gestion_delete($table, $id, $this->idNextcloud);
|
|
}
|
|
$this->refreshFEC();
|
|
return $result;
|
|
}
|
|
return $this->myDb->gestion_delete($table, $id, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $content
|
|
* @param string $name
|
|
* @param string $subject
|
|
* @param string $body
|
|
* @param string $to
|
|
* @param string $Cc
|
|
*/
|
|
public function sendPDF($content, $name, $subject, $body, $to, $Cc){
|
|
$clean_name = html_entity_decode($name);
|
|
try {
|
|
$data = base64_decode($content);
|
|
$message = $this->mailer->createMessage();
|
|
$message->setSubject($subject);
|
|
$message->setTo((array) json_decode($to));
|
|
$myrrCc = (array) json_decode($Cc);
|
|
|
|
if($myrrCc[0] != ""){
|
|
$message->setCc($myrrCc);
|
|
}
|
|
$message->setHtmlBody($body);
|
|
$content = $this->mailer->createAttachment($data,$clean_name.".pdf","x-pdf");
|
|
$message->attach($content);
|
|
$this->mailer->send($message);
|
|
return new DataResponse("", 200, ['Content-Type' => 'application/json']);
|
|
} catch (Exception $e) {
|
|
return new DataResponse("Is your global mail server configured in Nextcloud ?", 500, ['Content-Type' => 'application/json']);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $content
|
|
* @param string $folder
|
|
* @param string $name
|
|
*/
|
|
public function savePDF($content, $folder, $name){
|
|
|
|
$clean_folder = html_entity_decode($this->convert_special_char($folder));
|
|
$clean_name = html_entity_decode($this->convert_special_char($name));
|
|
try {
|
|
$this->storage->newFolder($clean_folder);
|
|
} catch(\OCP\Files\NotPermittedException $e) {
|
|
|
|
}
|
|
|
|
try {
|
|
try {
|
|
$ff = $clean_folder . $clean_name . ".pdf";
|
|
$this->storage->newFile($ff);
|
|
$file = $this->storage->get($ff);
|
|
$data = base64_decode($content);
|
|
$file->putContent($data);
|
|
} catch(\OCP\Files\NotFoundException $e) {
|
|
|
|
}
|
|
|
|
} catch(\OCP\Files\NotPermittedException $e) {
|
|
|
|
}
|
|
|
|
//work
|
|
// try {
|
|
// try {
|
|
// $file = $this->storage->get('/test/myfile2.txt');
|
|
// } catch(\OCP\Files\NotFoundException $e) {
|
|
//
|
|
// $file = $this->storage->get('/myfile.txt');
|
|
// }
|
|
|
|
// // the id can be accessed by $file->getId();
|
|
// $file->putContent('myfile2');
|
|
|
|
// } catch(\OCP\Files\NotPermittedException $e) {
|
|
// // you have to create this exception by yourself ;)
|
|
// throw new StorageException('Cant write to file');
|
|
// }
|
|
|
|
// //
|
|
// $userFolder->touch('/test/myfile2345.txt');
|
|
// $file = $userFolder->get('/test/myfile2345.txt');
|
|
// $file->putContent('test');
|
|
// //$file = $userFolder->get('myfile2.txt');
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $idclient
|
|
* @param string $annee
|
|
* @param string $mois
|
|
*/
|
|
public function saveDocumentRecap($idclient, $annee, $mois) {
|
|
$dateString = '15-'.$mois.'-'.$annee;
|
|
$date_temp = DateTime::createFromFormat('d-m-Y', $dateString);
|
|
$date = $date_temp->format('d-m-Y');
|
|
|
|
// if(intval($idclient)==0) {
|
|
// //generer recap OGF
|
|
// $this->generer_recap_ogf($date);
|
|
// } else {
|
|
// $this->generer_document_comptable_client($date, intval($idclient));
|
|
// }
|
|
$this->generer_document_comptable_client($date, intval($idclient));
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $content
|
|
* @param array $folders
|
|
* @param string $name
|
|
*/
|
|
public function saveNewPDF($content, $folders, $name){
|
|
foreach ($folders as $key => $folder) {
|
|
$clean_folder = html_entity_decode($folder);
|
|
$clean_name = html_entity_decode($name);
|
|
try {
|
|
$this->storage->newFolder($clean_folder);
|
|
} catch(\OCP\Files\NotPermittedException $e) {
|
|
|
|
}
|
|
|
|
try {
|
|
try {
|
|
$ff = $clean_folder . $clean_name . ".pdf";
|
|
$this->storage->newFile($ff);
|
|
$file = $this->storage->get($ff);
|
|
$data = base64_decode($content);
|
|
$file->putContent($data);
|
|
} catch(\OCP\Files\NotFoundException $e) {
|
|
|
|
}
|
|
|
|
} catch(\OCP\Files\NotPermittedException $e) {
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//work
|
|
// try {
|
|
// try {
|
|
// $file = $this->storage->get('/test/myfile2.txt');
|
|
// } catch(\OCP\Files\NotFoundException $e) {
|
|
//
|
|
// $file = $this->storage->get('/myfile.txt');
|
|
// }
|
|
|
|
// // the id can be accessed by $file->getId();
|
|
// $file->putContent('myfile2');
|
|
|
|
// } catch(\OCP\Files\NotPermittedException $e) {
|
|
// // you have to create this exception by yourself ;)
|
|
// throw new StorageException('Cant write to file');
|
|
// }
|
|
|
|
// //
|
|
// $userFolder->touch('/test/myfile2345.txt');
|
|
// $file = $userFolder->get('/test/myfile2345.txt');
|
|
// $file->putContent('test');
|
|
// //$file = $userFolder->get('myfile2.txt');
|
|
}
|
|
|
|
private function refreshFEC() {
|
|
$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->getFactures($this->idNextcloud));
|
|
foreach ($factures as $key => $facture) {
|
|
$facture_temp = array(
|
|
'num' => explode('/',$facture->num)[2],
|
|
'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,
|
|
);
|
|
$produits = json_decode($this->getProduitsById($facture->id_devis));
|
|
foreach ($produits as $key => $produit) {
|
|
$facture_temp['montant_htc'] += $produit->prix_unitaire * $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);
|
|
}
|
|
}
|
|
}
|
|
// var_dump($data_temp);
|
|
//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) {
|
|
$fec_temp_txt = 'Code journal'.TAB1.utf8_decode('Date écriture').TAB1.'Code compte'.TAB1.utf8_decode('Intitulé compte').TAB1.utf8_decode('Pièce').TAB1.utf8_decode('Libellé écriture').TAB1.utf8_decode('Débit origine').TAB1.utf8_decode('Crédit origine').TAB1.utf8_decode('Débit euro').TAB1.utf8_decode('Crédit euro').TAB1.'Lettrage'.TAB1.'Lettrage n+1'.TAB1.'Lettrage partiel'.TAB1.'Monnaie'.TAB1.'ISO Monnaie'.TAB1.'taux change'.TAB1.'Section analytique 1'.TAB1.'Section analytique 2'.TAB1.'Section analytique 3'.PHP_EOL.PHP_EOL;
|
|
// $fec_temp = 'NUMERO'.';'.'CLIENT'.';'.'DEFUNT'.';'.'DATE'.';'.'MONTANTHTC'.';'.'TVA'.';'.'MONTANTTVA'.';'.'MONTANTTTC'."\n";
|
|
$fec_temp = 'Code journal'.';'.utf8_decode('Date écriture').';'.'Code compte'.';'.utf8_decode('Intitulé compte').';'.utf8_decode('Pièce').';'.utf8_decode('Libellé écriture').';'.utf8_decode('Débit origine').';'.utf8_decode('Crédit origine').';'.utf8_decode('Débit euro').';'.utf8_decode('Crédit euro').';'.'Lettrage'.';'.'Lettrage n+1'.';'.'Lettrage partiel'.';'.'Monnaie'.';'.'ISO Monnaie'.';'.'taux change'.';'.'Section analytique 1'.';'.'Section analytique 2'.';'.'Section analytique 3'."\n\n";
|
|
foreach ($mois as $key => $facture) {
|
|
$fec_temp_txt = $fec_temp_txt.'VT'.TAB1.$facture['date_facture'].TAB1.$facture['client'].TAB1.$facture['client'].TAB1.$facture['num'].TAB1.$facture['nom_client'].TAB1.$facture['montant_ttc'].TAB1.'0'.TAB1.$facture['montant_htc'].TAB1.'0'.TAB1.''.TAB1.'FAUX'.TAB1.'FAUX'.TAB1.'E'.TAB1.''.TAB1.'1'.TAB1.''.TAB1.''.TAB1.''.PHP_EOL.PHP_EOL;
|
|
$fec_temp_txt = $fec_temp_txt.'VT'.TAB1.$facture['date_facture'].TAB1.'706000'.TAB1.'VENTES DE MARCHANDISES'.TAB1.$facture['num'].TAB1.$facture['client'].TAB1.'0'.TAB1.$facture['montant_htc'].TAB1.'0'.TAB1.$facture['montant_htc'].TAB1.''.TAB1.'FAUX'.TAB1.'FAUX'.TAB1.'E'.TAB1.''.TAB1.'1'.TAB1.''.TAB1.''.TAB1.''.PHP_EOL.PHP_EOL;
|
|
$fec_temp_txt = $fec_temp_txt.'VT'.TAB1.$facture['date_facture'].TAB1.'445710'.TAB1.''.TAB1.$facture['num'].TAB1.$facture['client'].TAB1.''.TAB1.$facture['montant_tva'].TAB1.''.TAB1.$facture['montant_tva'].TAB1.''.TAB1.''.TAB1.''.TAB1.''.TAB1.''.TAB1.''.TAB1.''.TAB1.''.PHP_EOL.PHP_EOL;
|
|
|
|
$fec_temp = $fec_temp.'VT'.';'.$facture['date_facture'].';'.$facture['client'].';'.$facture['client'].';'.$facture['num'].';'.$facture['nom_client'].';'.$facture['montant_ttc'].';0;'.$facture['montant_htc'].';0;'.''.';'.'FAUX'.';'.'FAUX'.';'.'E'.';'.''.';'.'1'.';'.''.';'.''.';'.''."\n\n";
|
|
$fec_temp = $fec_temp.'VT'.';'.$facture['date_facture'].';706000;VENTES DE MARCHANDISES;'.$facture['num'].';'.$facture['client'].';0;'.$facture['montant_htc'].';0;'.$facture['montant_htc'].';'.''.';'.'FAUX'.';'.'FAUX'.';'.'E'.';'.''.';'.'1'.';'.''.';'.''.';'.''."\n\n";
|
|
$fec_temp = $fec_temp.'VT'.';'.$facture['date_facture'].';445710;;'.$facture['num'].';'.$facture['client'].';;'.$facture['montant_tva'].';;'.$facture['montant_tva'].";;;;;;;;;\n\n";
|
|
}
|
|
$ff = $_clean_folder.'FEC_'.$key_mois.'_'.$key_annee.'.csv';
|
|
$this->storage->newFile($ff);
|
|
$file = $this->storage->get($ff);
|
|
$file->putContent($fec_temp);
|
|
|
|
$ff_txt = $_clean_folder.'FEC_'.$key_mois.'_'.$key_annee.'.txt';
|
|
$this->storage->newFile($ff_txt);
|
|
$file_txt = $this->storage->get($ff_txt);
|
|
$file_txt->putContent($fec_temp_txt);
|
|
// $file->putContent(implode(';', array('Jane Smith', 'janesmith@example.com', '555-5678')) . "\n");
|
|
}
|
|
}
|
|
|
|
} catch(\OCP\Files\NotFoundException $e) { }
|
|
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
}
|
|
|
|
|
|
private function getLogo(){
|
|
try{
|
|
try {
|
|
if(isset($this->storage)){
|
|
$file = $this->storage->get('/.gestion/logo.png');
|
|
}else{
|
|
return "nothing";
|
|
}
|
|
} catch(\OCP\Files\NotFoundException $e) {
|
|
$file = $this->storage->get('/.gestion/logo.jpeg');
|
|
}
|
|
}
|
|
catch(\OCP\Files\NotFoundException $e) {
|
|
return "nothing";
|
|
}
|
|
|
|
return base64_encode($file->getContent());
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getStats(){
|
|
$res = array();
|
|
$res['client'] = json_decode($this->myDb->numberClient($this->idNextcloud))[0]->c;
|
|
$res['defunt'] = json_decode($this->myDb->numberDefunt($this->idNextcloud))[0]->c;
|
|
$res['thanato'] = json_decode($this->myDb->numberThanato($this->idNextcloud))[0]->c;
|
|
$res['devis'] = json_decode($this->myDb->numberDevis($this->idNextcloud))[0]->c;
|
|
$res['lieu'] = json_decode($this->myDb->numberLieu($this->idNextcloud))[0]->c;
|
|
$res['trajet'] = json_decode($this->myDb->numberTrajet($this->idNextcloud))[0]->c;
|
|
$res['facture'] = json_decode($this->myDb->numberFacture($this->idNextcloud))[0]->c;
|
|
$res['produit'] = json_decode($this->myDb->numberProduit($this->idNextcloud))[0]->c;
|
|
$res['article'] = json_decode($this->myDb->numberArticle($this->idNextcloud))[0]->c;
|
|
$res['bibliotheque'] = json_decode($this->myDb->numberBibliotheque($this->idNextcloud))[0]->c;
|
|
return json_encode($res);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getAnnualTurnoverPerMonthNoVat(){
|
|
return $this->myDb->getAnnualTurnoverPerMonthNoVat($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param integer $annee
|
|
*/
|
|
public function getStatArticleAnnuel($annee) {
|
|
return $this->myDb->getStatArticleAnnuel($this->idNextcloud, $annee);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param integer $annee
|
|
*/
|
|
public function getStatSoinsThanatoAnnuel($annee) {
|
|
$result = $this->myDb->getStatSoinsThanatoAnnuel($this->idNextcloud, $annee);
|
|
return html_entity_decode($result);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param integer $annee
|
|
* @param integer $mois
|
|
*/
|
|
public function getStatSoinsThanatoWeekend($annee, $mois) {
|
|
$result = $this->myDb->getStatSoinsThanatoWeekend($this->idNextcloud, $annee, $mois);
|
|
return html_entity_decode($result);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getDefunts() {
|
|
return $this->myDb->getDefunts($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getUnusedDefunts() {
|
|
return $this->myDb->getUnusedDefunts($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function insertDefunt() {
|
|
return $this->myDb->insertDefunt($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numdefunt
|
|
*/
|
|
public function getObservationsById($numdefunt) {
|
|
return $this->myDb->getListObservations($numdefunt, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numdefunt
|
|
*/
|
|
public function getHypodermiquesById($numdefunt) {
|
|
return $this->myDb->getListHypodermiques($numdefunt, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numdefunt
|
|
*/
|
|
public function getBijouxById($numdefunt) {
|
|
return $this->myDb->getListBijoux($numdefunt, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getArticles() {
|
|
return $this->myDb->getArticles($this->idNextcloud);
|
|
}
|
|
|
|
public function ajaxGetArticles() {
|
|
return $this->myDb->getArticles($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numdevis
|
|
*/
|
|
public function getArticlesById($numdevis) {
|
|
return $this->myDb->getListArticle($numdevis, $this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function insertArticle() {
|
|
return $this->myDb->insertArticle($this->idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numdevis
|
|
*/
|
|
public function getTotalDevis($numdevis) {
|
|
$total = $this->myDb->getTotalDevis($numdevis, $this->idNextcloud);
|
|
$res = array();
|
|
$res['total'] = $total;
|
|
return json_encode($res);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numdefunt
|
|
*/
|
|
public function saveAttestationPacemaker($numdefunt){
|
|
$defunt = json_decode($this->myDb->getOneDefunt($numdefunt, $this->idNextcloud))[0];
|
|
$date_deces = new DateTimeImmutable($defunt->date_defunt);
|
|
$date_naissance = new DateTimeImmutable($defunt->date_naissance);
|
|
$date_habilitation = new DateTimeImmutable($defunt->date_habilitation);
|
|
$today = new DateTimeImmutable();
|
|
|
|
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
|
if($defunt->id_devis != NULL) {
|
|
try {
|
|
$nomDefunt = $defunt->nom_defunt;
|
|
$folderDestination = html_entity_decode($current_config[0]->path).'/CLIENTS/'.strtoupper($defunt->entreprise).'/DEFUNTS/'.strtoupper($nomDefunt).'/ATTESTATION/';
|
|
try {
|
|
$this->storage->newFolder($folderDestination);
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
|
|
// TODO: init pdf
|
|
$pdf = new FPDF();
|
|
$pdf->AddPage();
|
|
|
|
// on sup les 2 cm en bas
|
|
$pdf->SetAutoPagebreak(True);
|
|
$pdf->SetMargins(0,0,0);
|
|
|
|
// logo : 80 de largeur et 55 de hauteur
|
|
$pdf->Image($this->src_path."logo.jpeg", 10, 10, 55, 30);
|
|
$pdf->SetY(55); $pdf->SetFont('Arial', 'B', 15); $pdf->Cell(0, 10, "ATTESTATION", 0, 0, 'C');
|
|
|
|
$pdf->SetMargins(15,0,15);
|
|
|
|
$pdf->SetY(80); $pdf->SetFont('Arial', '', 10);
|
|
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Je soussignée ".$defunt->prenom_thanato." ".strtoupper($defunt->nom_thanato).", Thanatopracteur, agissant pour le compte de la société ".strtoupper($current_config[0]->entreprise)." titulaire de l'habilitation n°".$defunt->reference_habilitation." du certifie avoir procédé au retrait du simulateur cardiaque ou de la prothèse fonctionnant au moyen d'une pile de référence : ".$defunt->ref_pacemaker." ainsi qu'à la reconstruction tégumentaire de :
|
|
".(strcmp($defunt->sexe, 'm')==0 ? 'Monsieur' : 'Madame').". ".$defunt->nom_defunt."
|
|
Date de naissance : ".$date_naissance->format('d/m/Y')."
|
|
Date de décès : ".utf8_decode($date_deces->format('d/m/Y')))), '','J',0);
|
|
|
|
$pdf->setY($pdf->GetY()+10);
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
|
|
$pdf->setY($pdf->GetY()+10);
|
|
|
|
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Acte effectué à l'adresse suivante:
|
|
".$defunt->nom_lieu."
|
|
".$defunt->adresse_lieu)), '','J',0);
|
|
|
|
$pdf->setY($pdf->GetY()+10);
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
|
|
$pdf->setY($pdf->GetY()+10);
|
|
|
|
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Cette attestation est remise pour faire valoir ce que de droit.
|
|
Fait à Croth le ".$today->format('d/m/Y'))), '','J',0);
|
|
|
|
$pdf->setY($pdf->GetY()+10);
|
|
// signature
|
|
$pdf->SetFont('Arial','',11);
|
|
$pdf->setY($pdf->GetY()+10);
|
|
$pdf->Cell( $pdf->GetPageWidth()-30, 0, utf8_decode(html_entity_decode($current_config[0]->nom).' '.html_entity_decode($current_config[0]->prenom)), 0, 0, 'L');
|
|
$pdf->setY($pdf->GetY()+5);
|
|
$pdf->Image($this->src_path."sign.png", 15, $pdf->GetY(), 55, 30);
|
|
|
|
$pdf->setY($pdf->GetY()-5);
|
|
$pdf->SetFont('Arial','',11); $pdf->Cell( $pdf->GetPageWidth()-80, 0, "Pour :", 0, 0, 'R');
|
|
|
|
// Positionnement à 1,5 cm du bas
|
|
$pdf->SetY(-30); $pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_one))), '', 'C');
|
|
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_two))), '', 'C');
|
|
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->telephone))), '', 'C');
|
|
|
|
$ff_pdf = $folderDestination.'ATTESTATION_PACEMAKER_'.strtoupper($nomDefunt).'.pdf';
|
|
$this->storage->newFile($ff_pdf);
|
|
$pdfContent = $pdf->Output('','S');
|
|
|
|
$file_pdf = $this->storage->get($ff_pdf);
|
|
$file_pdf->putContent($pdfContent);
|
|
|
|
$res = array();
|
|
$res['path'] = $folderDestination;
|
|
return json_encode($res);
|
|
} catch(\OCP\Files\NotFoundException $e) {
|
|
return $e;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private function calculAge($dateNaissance) {
|
|
// Convertir la date de naissance en objet DateTime
|
|
$dateNaissance = new DateTime($dateNaissance);
|
|
// Obtenir la date actuelle
|
|
$dateActuelle = new DateTime();
|
|
// Calculer la différence entre les deux dates
|
|
$difference = $dateActuelle->diff($dateNaissance);
|
|
// Renvoyer l'âge
|
|
return $difference->y;
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numdefunt
|
|
*/
|
|
public function saveRapportSoin($numdefunt){
|
|
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
|
$defunt = json_decode($this->myDb->getOneDefunt($numdefunt, $this->idNextcloud))[0];
|
|
$observations = json_decode($this->myDb->getListObservations($numdefunt, $this->idNextcloud));
|
|
$hypodermiques = json_decode($this->myDb->getListHypodermiques($numdefunt, $this->idNextcloud));
|
|
|
|
// print_r(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_one));
|
|
|
|
if($defunt->id_devis != NULL) {
|
|
try {
|
|
$numFacture = ($defunt->numero_facture==NULL)?'-':$defunt->numero_facture;
|
|
$nomDefunt = $defunt->nom_defunt;
|
|
$age = $this->calculAge($defunt->date_naissance);
|
|
|
|
$date_devis_temp = date("t-m-Y", strtotime($defunt->date));
|
|
$date_temp = date("t-m-Y", strtotime(date('Y-m-d')));
|
|
|
|
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
|
|
$date_devis = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_devis_temp));
|
|
$today = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_temp));
|
|
|
|
$folderDestination = html_entity_decode($current_config[0]->path).'/CLIENTS/'.strtoupper($defunt->entreprise).'/DEFUNTS/'.strtoupper($nomDefunt).'/RAPPORTS/';
|
|
try {
|
|
$this->storage->newFolder($folderDestination);
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
|
|
// TODO: init pdf
|
|
$pdf = new FPDF();
|
|
$pdf->AddPage();
|
|
|
|
$pdf->SetAutoPagebreak(False);
|
|
$pdf->SetMargins(15,15,15);
|
|
|
|
// logo : 80 de largeur et 55 de hauteur
|
|
$pdf->Image($this->src_path."logo.jpeg", 15, 15, 55, 30);
|
|
$pdf->setXY(15, 15); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("N : ".$numFacture)), '', 'R');
|
|
|
|
$pdf->setXY(15, 55); $pdf->SetFont('Arial', 'B', 15); $pdf->Cell(80, 10, 'RAPPORT DE SOIN', 1, 1, 'C');
|
|
|
|
$pdf->SetY(60);
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Croth le, ".$today)), '', 'R');
|
|
|
|
$pdf->SetY($pdf->GetY()+15);
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode($nomDefunt."\n".$age."ans\n".(strcmp($defunt->sexe, 'm')==0 ? 'Masculin' : 'Féminin'))), '', 'L');
|
|
$pdf->SetY($pdf->GetY()-15);
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Éffectuées le ".$date_devis."\nà ".$defunt->adresse_lieu."\nde ".$defunt->heure_debut." à ".$defunt->heure_fin)), '', 'R');
|
|
|
|
$pdf->SetY($pdf->GetY()+10);
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
|
|
$pdf->SetY($pdf->GetY()+10);
|
|
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("ÉTAT DU CORPS")), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Corpulence : ".$defunt->corpulence)), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Rigidité : ".$defunt->rigidite)), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Observations du corps : ".$defunt->observations_corps)), '', 'L');
|
|
|
|
$pdf->SetY($pdf->GetY()+10);
|
|
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("ACCÈS")), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Arteriel : ".$defunt->acces)), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Recherche : ".$defunt->acces_recherche)), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("État : ".$defunt->acces_etat)), '', 'L');
|
|
|
|
$pdf->SetY($pdf->GetY()+10);
|
|
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("INJECTION")), '', 'L');
|
|
$pdf->SetY($pdf->GetY()+3);
|
|
$col_width = round(($pdf->GetPageWidth()-30)/3);
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("")), 'LR', 'C');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("Quantité (l)")), 'LR', 'C');
|
|
$pdf->SetXY(($col_width*2)+15, $pdf->GetY()-8); $pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("Diffusion")), 'LR', 'C');
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY()); // ---
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("Pré-injection")), 'LR', 'C');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->preinjection_qte)), 'LR', 'C');
|
|
$pdf->SetXY(($col_width*2)+15, $pdf->GetY()-8); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->preinjection_diffusion)), 'LR', 'C');
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY()); // ---
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("Injection")), 'LR', 'C');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->injection_qte)), 'LR', 'C');
|
|
$pdf->SetXY(($col_width*2)+15, $pdf->GetY()-8); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->injection_diffusion)), 'LR', 'C');
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY()); // ---
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("Co-injection")), 'LR', 'C');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->coinjection_qte)), 'LR', 'C');
|
|
$pdf->SetXY(($col_width*2)+15, $pdf->GetY()-8); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->coinjection_diffusion)), 'LR', 'C');
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
|
|
|
|
$pdf->SetY($pdf->GetY()+10);
|
|
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("DRAINAGE")), '', 'L');
|
|
$pdf->SetY($pdf->GetY()+3);
|
|
$col_width = round(($pdf->GetPageWidth()-30)/3);
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("")), 'LR', 'C');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("Quantité (l)")), 'LR', 'C');
|
|
$pdf->SetXY(($col_width*2)+15, $pdf->GetY()-8); $pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("État")), 'LR', 'C');
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY()); // ---
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->drainage)), 'LR', 'C');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->drainage_qte)), 'LR', 'C');
|
|
$pdf->SetXY(($col_width*2)+15, $pdf->GetY()-8); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->drainage_etat)), 'LR', 'C');
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
|
|
|
|
$pdf->SetY(-30); $pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_one))), '', 'C');
|
|
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_two))), '', 'C');
|
|
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->telephone))), '', 'C');
|
|
|
|
$pdf->AddPage();
|
|
|
|
$pdf->SetAutoPagebreak(True);
|
|
$pdf->SetMargins(15,15,15);
|
|
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("PONCTION")), '', 'L');
|
|
$pdf->SetY($pdf->GetY()+3);
|
|
$col_width = round(($pdf->GetPageWidth()-30)/3);
|
|
$pdf->Line(15, $pdf->GetY(), ($col_width+7)*2, $pdf->GetY());
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("")), 'LR', 'C');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("Quantité (l)")), 'LR', 'C');
|
|
$pdf->Line(15, $pdf->GetY(), ($col_width+7)*2, $pdf->GetY()); // ---
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->ponction)), 'LR', 'C');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->ponction_qte)), 'LR', 'C');
|
|
$pdf->Line(15, $pdf->GetY(), ($col_width+7)*2, $pdf->GetY());
|
|
|
|
$pdf->SetY($pdf->GetY()+15);
|
|
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("CAVITÉ")), '', 'L');
|
|
$pdf->SetY($pdf->GetY()+3);
|
|
$col_width = round(($pdf->GetPageWidth()-30)/3);
|
|
$pdf->Line(15, $pdf->GetY(), ($col_width+7)*2, $pdf->GetY());
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("")), 'LR', 'C');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("Quantité (l)")), 'LR', 'C');
|
|
$pdf->Line(15, $pdf->GetY(), ($col_width+7)*2, $pdf->GetY()); // ---
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->cavite)), 'LR', 'C');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($defunt->cavite_qte)), 'LR', 'C');
|
|
$pdf->Line(15, $pdf->GetY(), ($col_width+7)*2, $pdf->GetY());
|
|
|
|
$pdf->SetY($pdf->GetY()+10);
|
|
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("AUTRES TRAITEMENTS")), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Hypodermiques : ")), '', 'L');
|
|
foreach ($hypodermiques as $key => $hypo) {
|
|
$pdf->setX($pdf->GetX()+5);
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, "- ".utf8_decode(html_entity_decode($hypo->qte." ".$hypo->designation." sur ".$hypo->endroit)), '', 'L');
|
|
}
|
|
|
|
$pdf->SetY($pdf->GetY()+10);
|
|
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("HYGIÈNE")), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Désinfection : ".$defunt->desinfection)), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Lavage : ".$defunt->lavage)), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Rasage : ".(($defunt->rasage==0)?'Non':'Oui'))), '', 'L');
|
|
|
|
$pdf->SetY($pdf->GetY()+10);
|
|
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("PRÉSENTATION")), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Cosmétiques : ".$defunt->presentation_cosmetique)), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Sur : ".$defunt->presentation_sur)), '', 'L');
|
|
|
|
$pdf->SetY($pdf->GetY()+10);
|
|
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("TEMPS")), '', 'L');
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Total : ".$this->calculHeureTotal($defunt->heure_debut, $defunt->heure_fin))), '', 'L');
|
|
|
|
$pdf->SetY($pdf->GetY()+10);
|
|
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("OBSERVATIONS")), '', 'L');
|
|
$pdf->SetY($pdf->GetY()+3);
|
|
$col_width = round(($pdf->GetPageWidth()-30)/2);
|
|
foreach ($observations as $key => $obs) {
|
|
if($pdf->getY()>=($pdf->GetPageHeight()-45)) {
|
|
$pdf->SetY(-30); $pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_one))), '', 'C');
|
|
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_two))), '', 'C');
|
|
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->telephone))), '', 'C');
|
|
$pdf->AddPage();
|
|
}
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($obs->designation)), 'LTRB', 'L');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($obs->commentaire)), 'LTRB', 'L');
|
|
}
|
|
|
|
$pdf->setY($pdf->GetY()+10);
|
|
|
|
if($pdf->getY()>=($pdf->GetPageHeight()-45)) {
|
|
$pdf->SetY(-30); $pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_one))), '', 'C');
|
|
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_two))), '', 'C');
|
|
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->telephone))), '', 'C');
|
|
$pdf->AddPage();
|
|
}
|
|
|
|
// signature
|
|
$pdf->SetFont('Arial','',11);
|
|
$pdf->setY($pdf->GetY()+10);
|
|
$pdf->Cell( $pdf->GetPageWidth()-30, 0, utf8_decode(html_entity_decode($current_config[0]->nom).' '.html_entity_decode($current_config[0]->prenom)), 0, 0, 'L');
|
|
$pdf->setY($pdf->GetY()+5);
|
|
$pdf->Image($this->src_path."sign.png", 15, $pdf->GetY(), 55, 30);
|
|
|
|
$pdf->setY($pdf->GetY()-5);
|
|
$pdf->SetFont('Arial','',11); $pdf->Cell( $pdf->GetPageWidth()-80, 0, "Pour :", 0, 0, 'R');
|
|
|
|
$pdf->SetY(-30); $pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_one))), '', 'C');
|
|
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_two))), '', 'C');
|
|
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->telephone))), '', 'C');
|
|
|
|
$pdf->AddPage();
|
|
$pdf->Image($this->src_path.(($defunt->sexe=='m'?'facehomme.jpg':'facefemme.jpg')), 0, 0, $pdf->GetPageWidth(), $pdf->GetPageHeight());
|
|
$pdf->AddPage();
|
|
$pdf->Image($this->src_path.(($defunt->sexe=='m'?'doshomme.jpg':'dosfemme.jpg')), 0, 0, $pdf->GetPageWidth(), $pdf->GetPageHeight());
|
|
|
|
$ff_pdf = $folderDestination.'RAPPORT_SOIN_'.strtoupper($nomDefunt).'.pdf';
|
|
$this->storage->newFile($ff_pdf);
|
|
$pdfContent = $pdf->Output('','S');
|
|
|
|
$file_pdf = $this->storage->get($ff_pdf);
|
|
$file_pdf->putContent($pdfContent);
|
|
|
|
$res = array();
|
|
$res['path'] = $folderDestination;
|
|
return json_encode($res);
|
|
} catch(\OCP\Files\NotFoundException $e) {
|
|
return $e;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function calculHeureTotal($heureDebut, $heureFin) {
|
|
// Extraction des heures et des minutes de l'heure de début
|
|
list($heureDebutHeures, $heureDebutMinutes) = explode(':', $heureDebut);
|
|
$heureDebutHeures = (int)$heureDebutHeures;
|
|
$heureDebutMinutes = (int)$heureDebutMinutes;
|
|
|
|
// Extraction des heures et des minutes de l'heure de fin
|
|
list($heureFinHeures, $heureFinMinutes) = explode(':', $heureFin);
|
|
$heureFinHeures = (int)$heureFinHeures;
|
|
$heureFinMinutes = (int)$heureFinMinutes;
|
|
|
|
// Calculer la différence en heures et minutes
|
|
$diffHeures = $heureFinHeures - $heureDebutHeures;
|
|
$diffMinutes = $heureFinMinutes - $heureDebutMinutes;
|
|
|
|
// Gérer le cas où la différence des minutes est négative
|
|
if ($diffMinutes < 0) {
|
|
$diffHeures--;
|
|
$diffMinutes += 60;
|
|
}
|
|
return sprintf("%02dh%02d", $diffHeures, $diffMinutes);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param string $numdefunt
|
|
*/
|
|
public function saveRapportBijoux($numdefunt){
|
|
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
|
$defunt = json_decode($this->myDb->getOneDefunt($numdefunt, $this->idNextcloud))[0];
|
|
$bijoux = json_decode($this->myDb->getListBijoux($numdefunt, $this->idNextcloud));
|
|
try {
|
|
$nomDefunt = $defunt->nom_defunt;
|
|
|
|
$date_naissance_temp = date("t-m-Y", strtotime(date($defunt->date_naissance)));
|
|
$date_deces_temp = date("t-m-Y", strtotime(date($defun->date_defunt)));
|
|
$date_temp = date("t-m-Y", strtotime(date('Y-m-d')));
|
|
$date_habilitation_temp = date("t-m-Y", strtotime(date($defunt->date_habilitation)));
|
|
|
|
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
|
|
$today = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_temp));
|
|
$date_habilitation = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_habilitation_temp));
|
|
$date_naissance = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_naissance_temp));
|
|
$date_deces = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_deces_temp));
|
|
|
|
$folderDestination = html_entity_decode($current_config[0]->path).'/CLIENTS/'.strtoupper($defunt->entreprise).'/DEFUNTS/'.strtoupper($nomDefunt).'/RAPPORTS/';
|
|
|
|
try {
|
|
$this->storage->newFolder($folderDestination);
|
|
} catch(\OCP\Files\NotPermittedException $e) { }
|
|
|
|
// TODO: init pdf
|
|
$pdf = new FPDF();
|
|
$pdf->AddPage();
|
|
|
|
// on sup les 2 cm en bas
|
|
$pdf->SetAutoPagebreak(True);
|
|
|
|
// logo : 80 de largeur et 55 de hauteur
|
|
$pdf->Image($this->src_path."logo.jpeg", 10, 10, 55, 30);
|
|
$pdf->SetY(55); $pdf->SetFont('Arial', 'B', 15); $pdf->Cell(0, 10, utf8_decode(html_entity_decode("ATTESTATION BIJOU(X)")), 0, 0, 'C');
|
|
|
|
$pdf->SetMargins(15,15,15);
|
|
|
|
$pdf->SetY(80); $pdf->SetFont('Arial', '', 10);
|
|
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Je soussignée ".$defunt->prenom_thanato." ".strtoupper($defunt->nom_thanato).", Thanatopracteur, agissant pour le compte de la société ".strtoupper($current_config[0]->entreprise)." titulaire de l'habilitation n° ".$defunt->reference_habilitation." atteste par la présente que :
|
|
".(strcmp($defunt->sexe, 'm')==0 ? 'Monsieur' : 'Madame').". ".$defunt->nom_defunt."
|
|
Date de naissance : ".utf8_decode($date_naissance)."
|
|
Date de décès : ".utf8_decode($date_deces)."
|
|
a été pris(e) en charge par nos services pour des soins mortuaires.")), '','J',0);
|
|
|
|
$pdf->setY($pdf->GetY()+10);
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
|
|
$pdf->setY($pdf->GetY()+10);
|
|
|
|
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("À la suite de notre prise en charge, une liste des bijoux appartenant au défunt a été établie comme suit :")), '','J',0);
|
|
$pdf->setY($pdf->GetY()+5);
|
|
$col_width = round(($pdf->GetPageWidth()-30)/2);
|
|
$pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("Désignation")), 'LTRB', 'C');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', 'B', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("Commentaire")), 'LTRB', 'C');
|
|
foreach ($bijoux as $key => $bijou) {
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($bijou->designation)), 'LTRB', 'L');
|
|
$pdf->SetXY($col_width+15, $pdf->GetY()-8); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($bijou->commentaire)), 'LTRB', 'L');
|
|
}
|
|
|
|
$pdf->setY($pdf->GetY()+10);
|
|
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
|
|
$pdf->setY($pdf->GetY()+5);
|
|
|
|
$pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Cette attestation est remise pour faire valoir ce que de droit.
|
|
Fait à Croth le ".$today)), '','J',0);
|
|
|
|
$pdf->setY($pdf->GetY()+10);
|
|
|
|
// signature
|
|
$pdf->SetFont('Arial','',11);
|
|
$pdf->setY($pdf->GetY()+10);
|
|
$pdf->Cell( $pdf->GetPageWidth()-30, 0, utf8_decode(html_entity_decode($current_config[0]->nom).' '.html_entity_decode($current_config[0]->prenom)), 0, 0, 'L');
|
|
$pdf->setY($pdf->GetY()+5);
|
|
$pdf->Image($this->src_path."sign.png", 15, $pdf->GetY(), 55, 30);
|
|
|
|
$pdf->setY($pdf->GetY()-5);
|
|
$pdf->SetFont('Arial','',11); $pdf->Cell( $pdf->GetPageWidth()-80, 0, "Pour :", 0, 0, 'R');
|
|
|
|
$pdf->SetY(-30); $pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_one))), '', 'C');
|
|
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_two))), '', 'C');
|
|
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->telephone))), '', 'C');
|
|
|
|
$ff_pdf = $folderDestination.'RAPPORT_BIJOUX_'.strtoupper($nomDefunt).'.pdf';
|
|
$this->storage->newFile($ff_pdf);
|
|
$pdfContent = $pdf->Output('','S');
|
|
|
|
$file_pdf = $this->storage->get($ff_pdf);
|
|
$file_pdf->putContent($pdfContent);
|
|
|
|
$res = array();
|
|
$res['path'] = $folderDestination;
|
|
return json_encode($res);
|
|
} catch(\OCP\Files\NotFoundException $e) {
|
|
return $e;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param array $thanatoIdsToExport
|
|
*
|
|
*/
|
|
|
|
public function exportThanatoStatistic($thanatoIdsToExport){
|
|
if(empty($thanatoIdsToExport)){
|
|
return "";
|
|
}
|
|
$exportData = $this->myDb->getExportThanatoStatisticData($thanatoIdsToExport);
|
|
try{
|
|
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
|
$clean_folder = html_entity_decode($current_config[0]->path).'/';
|
|
$_clean_folder = $clean_folder.'STATISTIQUES/THANATOS/';
|
|
try {
|
|
$this->storage->newFolder($_clean_folder);
|
|
}
|
|
catch(\OCP\Files\NotPermittedException $e) {
|
|
|
|
}
|
|
$fileHeader = $this->exportThanatoStatisticService->getExportThanatoFileHeader();
|
|
$fileContent = $this->exportThanatoStatisticService->populateExportDataIntoFileContent($exportData,$fileHeader);
|
|
$filename = $this->exportThanatoStatisticService->getFilename($thanatoIdsToExport);
|
|
$fileNamePath = $_clean_folder."STAT-THANATOS-" . $filename . '.csv';
|
|
$this->storage->newFile($fileNamePath);
|
|
$file = $this->storage->get($fileNamePath);
|
|
$file->putContent($fileContent);
|
|
return $fileNamePath;
|
|
}
|
|
catch(\OCP\Files\NotFoundException $e) { }
|
|
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param array $clientIdsToExport
|
|
*
|
|
*/
|
|
|
|
public function exportClientStatistic($clientIdsToExport){
|
|
if(empty($clientIdsToExport)){
|
|
return "";
|
|
}
|
|
$exportData = $this->myDb->getExportClientStatData($clientIdsToExport);
|
|
try{
|
|
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
|
$clean_folder = html_entity_decode($current_config[0]->path).'/';
|
|
$_clean_folder = $clean_folder.'STATISTIQUES/CLIENTS/';
|
|
try {
|
|
$this->storage->newFolder($_clean_folder);
|
|
}
|
|
catch(\OCP\Files\NotPermittedException $e) {
|
|
|
|
}
|
|
$fileHeader = $this->exportClientStatisticService->getExportClientFileHeader($exportData);
|
|
$fileContent = $this->exportClientStatisticService->populateExportDataIntoFileContent($exportData,$fileHeader);
|
|
$fileName = $this->exportClientStatisticService->getFileName($clientIdsToExport);
|
|
$fileNamePath = $_clean_folder."STAT-CLIENTS-" . $fileName .'.csv';
|
|
$this->storage->newFile($fileNamePath);
|
|
$file = $this->storage->get($fileNamePath);
|
|
$file->putContent($fileContent);
|
|
return $fileNamePath;
|
|
}
|
|
catch(\OCP\Files\NotFoundException $e) { }
|
|
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
* @param int $factureId
|
|
*
|
|
*/
|
|
|
|
public function generateSamplePdf($factureId){
|
|
$factureId = 1;
|
|
$configs = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
|
$currentConfig = $configs[0];
|
|
$logo = $this->getLogo();
|
|
$invoicePdfData = $this->myDb->getInvoicePdfData($factureId,$currentConfig);
|
|
if($invoicePdfData == null){
|
|
return "";
|
|
}
|
|
try{
|
|
$clean_folder = html_entity_decode($currentConfig->path).'/';
|
|
$_clean_folder = $clean_folder.'SAMPLES/';
|
|
try {
|
|
$this->storage->newFolder($_clean_folder);
|
|
}
|
|
catch(\OCP\Files\NotPermittedException $e) {
|
|
|
|
}
|
|
$pdf = new InvoicePdfHandler();
|
|
$pdf->InvoicePdfFactory($invoicePdfData,$logo);
|
|
$pdfContent = $pdf->GetFactureContent();
|
|
|
|
$pdf->Output();
|
|
$ff_pdf = $_clean_folder.Uuid::uuid4()->toString().'.pdf';
|
|
$this->storage->newFile($ff_pdf);
|
|
$file_pdf = $this->storage->get($ff_pdf);
|
|
$file_pdf->putContent($pdfContent);
|
|
|
|
$res = array();
|
|
$res['path'] = $_clean_folder;
|
|
return json_encode($res);
|
|
}
|
|
catch(\OCP\Files\NotFoundException $e) { }
|
|
|
|
}
|
|
}
|