THANASOFT-HFC/gestion/lib/Controller/PageController.php

3975 lines
173 KiB
PHP

<?php
namespace OCA\Gestion\Controller;
use FPDF;
use Datetime;
use Exception;
use OCA\Gestion\Constants\DevisExportTypeConstant;
use OCA\Gestion\Helpers\DateHelpers;
use OCP\IConfig;
use OCP\IRequest;
defined("TAB1") or define("TAB1", "\t");
use OCP\IUserSession;
use OCP\Mail\IMailer;
use OCP\IGroupManager;
use OCP\IURLGenerator;
use DatetimeImmutable;
use IntlDateFormatter;
use OCA\Gestion\Db\Bdd;
use OCP\Files\IRootFolder;
use OCP\AppFramework\Controller;
use OCA\Gestion\Service\TalkService;
use OCA\Gestion\Constants\BddConstant;
use OCA\Gestion\Service\MailerService;
use OCP\AppFramework\Http\DataResponse;
use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Service\InvoicePdfHandler;
use OCA\Gestion\Service\InvoicePdfService;
use OCP\AppFramework\Http\TemplateResponse;
use OCA\Gestion\Constants\FactureTypeConstant;
use OCA\Gestion\Constants\DevisMentionConstant;
use OCA\Gestion\Service\Devis\Pdf\DevisPdfService;
use OCA\Gestion\Service\ExportClientStatisticService;
use OCA\Gestion\Constants\MultipleFactureTypeConstant;
use OCA\Gestion\Service\ExportThanatoStatisticService;
use OCA\Gestion\Service\Certificate\CertificateService;
use OCA\Gestion\Service\Devis\DevisRecapService;
date_default_timezone_set('Europe/Paris');
class PageController extends Controller
{
private $idNextcloud;
private Bdd $myDb;
// private $src_path = "/var/www/html/apps/gestion/img/";
private $src_path = "/var/www/html/custom_apps/gestion/img/";
private $sharedImagePath = "/var/www/html/data/";
private $defaultImagePath;
private const HYTHA_35_DEFAULT_ADMIN = "Johann";
private const H2F_DEFAULT_ADMIN = "Emmanuelle";
private const DEFAULT_NEXTCLOUD_ADMIN = "admin";
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;
/** @var CertificateService */
private $certificateService;
private $adminStorage;
/** @var TalkService */
private $talkService;
/** @var DevisPdfService */
private $devisPdfService;
private $rootFolder;
private $mailerService;
private $devisRecapService;
/**
* 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,
CertificateService $certificateService,
TalkService $talkService,
DevisPdfService $devisPdfService,
MailerService $mailerService,
DevisRecapService $devisRecapService
) {
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->certificateService = $certificateService;
$this->defaultImagePath = $this->sharedImagePath.self::DEFAULT_NEXTCLOUD_ADMIN.'/files/.gestion/';
$this->talkService = $talkService;
$this->devisPdfService = $devisPdfService;
$this->rootFolder = $rootFolder;
$this->mailerService = $mailerService;
//$this->fpdf = $fpdf;
$this->devisRecapService = $devisRecapService;
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) {
}
try {
$this->adminStorage = $rootFolder->getUserFolder(self::DEFAULT_NEXTCLOUD_ADMIN);
} 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();
$facturePaymentTypeList = $this->myDb->getFacturePaymentList();
return new TemplateResponse('gestion', 'facture', array(
'groups' => $this->groups,
'user' => $this->user,
'path' => $this->idNextcloud,
'paymentTypes' => json_decode($facturePaymentTypeList),
'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, true);
$coverProducts = $this->myDb->getCoverProducts();
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(),
'coverProducts' => json_decode($coverProducts)
));
}
/**
* @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()
{
$devisMentionsFilter = [
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED,
DevisMentionConstant::MENTION,
DevisMentionConstant::NEW
];
$devis = json_decode($this->myDb->getDevis($this->idNextcloud, $devisMentionsFilter));
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->getClientsAndClientGroupFacturations(includeClientInsideGroup:false));
usort($clients, function ($a, $b) {
return strcmp($a->nom, $b->nom);
});
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->getClientsAndClientGroupFacturations());
usort($clients, function ($a, $b) {
return strcmp($a->nom, $b->nom);
});
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()
{
$idNextcloud = "admin";
return $this->myDb->isConfig($idNextcloud);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getNavigationLink()
{
return array(
"index" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.index"),
"clientGroups" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.clientGroups"),
"clientGroupFacturation" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.clientGroupFacturation"),
"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"),
"clientGroupDiscount" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.clientGroupDiscount"),
"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", 4, 2, 50, 35);
// 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, "Bourges France 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", 4, 2, 50, 35);
// 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, "Bourges France, 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, $filter, $filterType)
{
try {
$this->invoicePdfService->generateInvoiceRecap($filter, $filterType, $date, $this->idNextcloud);
} 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();
// $pdf->AddFont('Arial','','Comic Sans MS.php');
// $pdf->AddFont('Arial','B','comic-sans-bold.php');
$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", 4, 2, 50, 35);
// 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, "Bourges France 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", 4, 2, 50, 35);
// 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, "Bourges France 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()
{
$idNextcloud = self::DEFAULT_NEXTCLOUD_ADMIN;
return $this->myDb->getConfiguration($idNextcloud);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getDevis($mentionFilters = [])
{
return $this->myDb->getDevis($this->idNextcloud, $mentionFilters);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getDevisWithProduits()
{
return $this->myDb->getDevisWithProduits($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->reloadFec();
return $result;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getFacturesWithProduits()
{
$result = $this->myDb->getFacturesWithProduits();
$this->reloadFec();
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($orderDirection = null)
{
if($orderDirection == null) {
$orderDirection = 'DESC';
}
return $this->myDb->getProduits($this->idNextcloud, $orderDirection);
}
/**
* @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->reloadFec();
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 {
if(strcmp($column, 'date') == 0) {
if(strcmp($table, 'facture')) {
$datetime = new Datetime($data);
$factureNumber = $this->myDb->getFactureNumberByDate($datetime);
$this->myDb->gestion_update($table, "facture_number", $factureNumber, $id, $this->idNextcloud);
$factureFullNumber = $this->myDb->getFactureFullNumberByDate($datetime);
$this->myDb->gestion_update($table, "num", $factureFullNumber, $id, $this->idNextcloud);
}
if(strcmp($table, 'devis')) {
$datetime = new Datetime($data);
$devisNumber = $this->myDb->getDevisNumberByDate($datetime);
$this->myDb->gestion_update($table, "devis_number", $devisNumber, $id, $this->idNextcloud);
$devisFullNumber = $this->myDb->getDevisFullNumberByDate($datetime);
$this->myDb->gestion_update($table, "num", $devisFullNumber, $id, $this->idNextcloud);
}
}
$result = $this->myDb->gestion_update($table, $column, $data, $id, $this->idNextcloud);
// $this->generer_document_comptable($facturecourant->date_paiement);
}
}
$this->reloadFec();
return $result;
}
return $this->myDb->gestion_update($table, $column, $data, $id, $this->idNextcloud);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param array $devisToFacture
* @param string $paymentDate
*/
public function exportDevisToFacture($devisToFacture, $paymentDate, $type = FactureTypeConstant::TYPE_SINGLE)
{
$response = true;
$factureIdsGenerated = [];
if($type == FactureTypeConstant::TYPE_GROUP) {
$doDevisIdsListIdsBelongsToTheSameClientFacturationGroup = $this->myDb->doDevisIdsListIdsBelongsToTheSameClientFacturationGroup($devisToFacture);
if($doDevisIdsListIdsBelongsToTheSameClientFacturationGroup == false) {
return "Les devis fournis ne sont pas dans la même groupe de facturation";
}
$factureIdsGenerated = $this->myDb->generateGroupFactureForMultipleDevis($devisToFacture, $paymentDate);
} else {
$factureIdsGenerated = $this->myDb->insertFactureForeEachDevisId($this->idNextcloud, $devisToFacture, $paymentDate);
}
$this->invoicePdfService->generateFacturePdfByFactureIds($factureIdsGenerated, $this->idNextcloud);
$this->reloadFec();
return $response;
}
/**
* @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->reloadFec();
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']);
}
}
public function sendAttachmentToClientByDefunt($defuntId, $ff_pdf, $to, $subject, $body, $addName = false)
{
$devis = $this->myDb->getDevisOfDefunt($defuntId);
if($devis != null) {
// try {
$senderEmailAddress = $this->config->getSystemValue('mail_from_address') ?? null;
$senderEmailDomain = $this->config->getSystemValue('mail_domain') ?? null;
$senderEmail = null;
if($senderEmailAddress && $senderEmailDomain) {
$senderEmail = $senderEmailAddress.'@'.$senderEmailDomain;
}
$client_email = $to;
$client_nom = $devis['client_nom'];
$data = $this->storage->get($ff_pdf)->getContent();
$message = $this->mailer->createMessage();
$message->setTo(recipients: [$client_email => $client_nom]);
// $message->setFrom([$client_email => $client_nom]);
$content = $this->mailer->createAttachment($data, basename($ff_pdf), "application/pdf");
$message->attach($content);
$message->setSubject($subject);
$body_text = $addName ? ($body." de ".$devis['defunt_nom']) : $body;
$cautionText = "MERCI DE NE PAS REPONDRE A CET EMAIL.";
$signature = $this->mailerService->getFooterContent($this->getUserNameForEmailSignature());
$message->setHtmlBody(
"<p>Bonjour.</p>".
"<p>$body_text</p>".
"<p>$cautionText</p>".
$signature
);
$appAdminEmail = BddConstant::DEFAULT_ATTESTATION_CC_EMAIL;
$message->setCc([$appAdminEmail]);
$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']);
// }
}
}
public function getUserNameForEmailSignature()
{
$configs = json_decode($this->myDb->getConfiguration(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD));
$currentConfig = $configs[0];
return $currentConfig->nom . " " . $currentConfig->prenom;
}
/**
* @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 $filter
* @param string $year
* @param string $month
* @param string $filterType
*/
public function saveDocumentRecap($filter, $year, $month, $filterType = MultipleFactureTypeConstant::CLIENT_FILTER_TYPE)
{
$dateString = '15-'.$month.'-'.$year;
$date_temp = DateTime::createFromFormat('d-m-Y', $dateString);
$date = $date_temp->format('d-m-Y');
$this->generer_document_comptable_client($date, $filter, $filterType);
}
/**
* @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');
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function apiReloadFec()
{
$this->reloadFec();
return new DataResponse("", 200, ['Content-Type' => 'application/json']);
}
private function reloadFec()
{
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
$clean_folder = html_entity_decode($current_config[0]->path).'/';
try {
try {
$data_factures = array();
$factures = json_decode($this->myDb->getFacturesListWithDependencies());
foreach ($factures as $key => $facture) {
$factureIsSingle = $facture->facture_type == FactureTypeConstant::TYPE_SINGLE;
$facture_temp = array(
'num' => $facture->num,
'client' => $facture->entreprise,
'nom_client' => $facture->nom,
'date' => $facture->date,
'date_facture' => $facture->date_paiement,
'defunt' => $facture->nom_defunt,
'montant_htc' => 0,
'tva' => $current_config[0]->tva_default,
'montant_tva' => 0,
'montant_ttc' => 0,
);
if($factureIsSingle) {
$produits = json_decode($this->getProduitsById($facture->id_devis));
foreach ($produits as $key => $produit) {
$htPrice = $produit->prix_unitaire;
if($facture->fk_client_group_id != null || $facture->fk_client_group_id != 0) {
$price = $this->myDb->getProductPriceByClientGroupId($facture->fk_client_group_id, $produit->id);
if($price != null) {
$htPrice = $price;
}
}
$facture_temp['montant_htc'] += $htPrice * $produit->quantite;
};
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva']) / 100;
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
} else {
$devis = $this->myDb->getDevisByFkFactureId($facture->id);
$factureGroupIsRelatedToAnyDevis = $devis != null;
$mentionFilters = [
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED
];
$isFactureGroupForSingleClient = $facture->facture_client_id != null && $facture->facture_client_id != 0;
if($isFactureGroupForSingleClient) {
$facture_temp["client"] = $facture->facture_client_entreprise;
$facture_temp["nom_client"] = $facture->facture_client_name;
if(!$factureGroupIsRelatedToAnyDevis) {
$devisList = $this->myDb->getDevisByClientIdAndMonthYear(
$facture->facture_client_id,
$facture->facture_month,
$facture->facture_year,
$mentionFilters
);
}
} else {
$facture_temp["client"] = $facture->group_code_comptable ?? '-';
$facture_temp["nom_client"] = $facture->facture_group_name;
if(!$factureGroupIsRelatedToAnyDevis) {
$devisList = $this->myDb->getDevisByClientGroupFacturationIdAndMonthYear(
$facture->facture_client_group_facturation_id,
$facture->facture_month,
$facture->facture_year,
[
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED
]
);
}
}
if($factureGroupIsRelatedToAnyDevis) {
$devisList = $this->myDb->getDevisByClientIdByFactureId($facture->id, $mentionFilters);
}
foreach($devisList as $currentDevis) {
$produits = json_decode($this->getProduitsById($currentDevis['id']));
foreach ($produits as $key => $produit) {
$htPrice = $produit->prix_unitaire;
if($currentDevis["fk_client_group_id"] != null || $currentDevis["fk_client_group_id"] != 0) {
$price = $this->myDb->getProductPriceByClientGroupId($currentDevis["fk_client_group_id"], $produit->id);
if($price != null) {
$htPrice = $price;
}
}
$facture_temp['montant_htc'] += $htPrice * $produit->quantite;
};
}
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva']) / 100;
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
}
array_push($data_factures, $facture_temp);
};
$data_temp = array();
foreach ($data_factures as $key => $facture) {
$datesplit = explode('-', $facture['date_facture']);
if($data_temp[strval($datesplit[0])] == null) {
$data_temp[strval($datesplit[0])][strval($datesplit[1])] = array(0 => $facture);
} else {
if($data_temp[strval($datesplit[0])][strval($datesplit[1])] == null) {
$data_temp[strval($datesplit[0])][strval($datesplit[1])] = array(0 => $facture);
} else {
array_push($data_temp[strval($datesplit[0])][strval($datesplit[1])], $facture);
}
}
}
$fec_headers_txt = [
utf8_decode('JOURNALCODE'),
utf8_decode('JOURNALLIB'),
utf8_decode('ECRITURENUM'),
utf8_decode('ECRITUREDATE'),
utf8_decode('COMPTENUM'),
utf8_decode('COMPTELIB'),
utf8_decode('COMPAUXLIB'),
utf8_decode('COMPAUXNUM'),
utf8_decode('PIECEREF'),
utf8_decode('PIECEDATE'),
utf8_decode('ECRITURELIB'),
utf8_decode('DEBIT'),
utf8_decode('CREDIT'),
utf8_decode('ECRITURELET'),
utf8_decode('DATELET'),
utf8_decode('VALIDDATE'),
utf8_decode('MONTANTDEVISE'),
utf8_decode('IDEVISE'),
];
//parcours annee
foreach ($data_temp as $key_annee => $annee) {
//parcours annee
$_clean_folder = $clean_folder.'FEC/'.$key_annee.'/';
try {
$this->storage->newFolder($_clean_folder);
} catch(\OCP\Files\NotPermittedException $e) {
}
foreach ($annee as $key_mois => $mois) {
// Initialize FEC headers
$fec_temp_txt = implode(TAB1, $fec_headers_txt) . PHP_EOL . PHP_EOL;
$fec_temp = implode(';', $fec_headers_txt) . "\n\n";
foreach ($mois as $key => $facture) {
// Define FEC entry data
$fec_entries = [
[
'journal' => 'VT',
'journal_lib' => 'VENTES',
'ecriturenum' => '',
'date' => $facture['date_facture'],
'compte' => $facture['client'],
'libelle_compte' => $facture['client'],
'compauxlib' => '',
'compauxnum' => '',
'piece' => $facture['num'],
'piece_date' => '',
'libelle_ecriture' => $facture['nom_client'],
'debit' => $facture['montant_ttc'],
'credit' => '0',
'ecriture_lettrage' => '',
'date_lettrage' => '',
'valid_date' => '',
'montant_devise' => '',
'devise' => 'EUR',
],
[
'journal' => 'VT',
'journal_lib' => 'VENTES',
'ecriturenum' => '',
'date' => $facture['date_facture'],
'compte' => '706000',
'libelle_compte' => 'VENTES DE MARCHANDISES',
'compauxlib' => '',
'compauxnum' => '',
'piece' => $facture['num'],
'piece_date' => '',
'libelle_ecriture' => $facture['client'],
'debit' => '0',
'credit' => $facture['montant_htc'],
'ecriture_lettrage' => '',
'date_lettrage' => '',
'valid_date' => '',
'montant_devise' => '',
'devise' => 'EUR',
],
[
'journal' => 'VT',
'journal_lib' => 'VENTES',
'ecriturenum' => '',
'date' => $facture['date_facture'],
'compte' => '445710',
'compauxlib' => '',
'compauxnum' => '',
'libelle_compte' => '',
'piece' => $facture['num'],
'piece_date' => '',
'libelle_ecriture' => $facture['client'],
'debit' => '',
'credit' => $facture['montant_tva'],
'ecriture_lettrage' => '',
'date_lettrage' => '',
'valid_date' => '',
'montant_devise' => '',
'devise' => 'EUR',
]
];
// Generate FEC entries
foreach ($fec_entries as $entry) {
$fec_line_txt = [
$entry['journal'], $entry['journal_lib'], $entry['ecriturenum'], $entry['date'],
$entry['compte'], $entry['libelle_compte'],
$entry['compauxlib'], $entry['compauxnum'],
$entry['piece'], $entry['piece_date'],
$entry['libelle_ecriture'], $entry['debit'],$entry['credit'],$entry['ecriture_lettrage'],
$entry['date_lettrage'], $entry['valid_date'], $entry['montant_devise'], $entry['devise']
];
$fec_line_csv = [
$entry['journal'], $entry['journal_lib'], $entry['ecriturenum'], $entry['date'],
$entry['compte'], $entry['libelle_compte'],
$entry['compauxlib'], $entry['compauxnum'],
$entry['piece'], $entry['piece_date'],
$entry['libelle_ecriture'], $entry['debit'],$entry['credit'],$entry['ecriture_lettrage'],
$entry['date_lettrage'], $entry['valid_date'], $entry['montant_devise'], $entry['devise']
];
$fec_temp_txt .= implode(TAB1, $fec_line_txt) . PHP_EOL . PHP_EOL;
$fec_temp .= implode(';', $fec_line_csv) . "\n\n";
}
}
$ff = $_clean_folder.'FEC_'.$key_mois.'_'.$key_annee.'.csv';
$this->storage->newFile($ff);
$file = $this->storage->get($ff);
$file->putContent($fec_temp);
$ff_txt = $_clean_folder.'FEC_'.$key_mois.'_'.$key_annee.'.txt';
$this->storage->newFile($ff_txt);
$file_txt = $this->storage->get($ff_txt);
$file_txt->putContent($fec_temp_txt);
// $file->putContent(implode(';', array('Jane Smith', 'janesmith@example.com', '555-5678')) . "\n");
}
}
} catch(\OCP\Files\NotFoundException $e) {
}
} catch(\OCP\Files\NotPermittedException $e) {
}
}
private function refreshFEC()
{
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
$clean_folder = html_entity_decode($current_config[0]->path).'/';
try {
try {
$data_factures = array();
$factures = json_decode($this->myDb->getFacturesListWithDependencies());
foreach ($factures as $key => $facture) {
$factureIsSingle = $facture->facture_type == FactureTypeConstant::TYPE_SINGLE;
$facture_temp = array(
'num' => $facture->num,
'client' => $facture->entreprise,
'nom_client' => $facture->nom,
'date' => $facture->date,
'date_facture' => $facture->date_paiement,
'defunt' => $facture->nom_defunt,
'montant_htc' => 0,
'tva' => $current_config[0]->tva_default,
'montant_tva' => 0,
'montant_ttc' => 0,
);
if($factureIsSingle) {
$produits = json_decode($this->getProduitsById($facture->id_devis));
foreach ($produits as $key => $produit) {
$htPrice = $produit->prix_unitaire;
if($facture->fk_client_group_id != null || $facture->fk_client_group_id != 0) {
$price = $this->myDb->getProductPriceByClientGroupId($facture->fk_client_group_id, $produit->id);
if($price != null) {
$htPrice = $price;
}
}
$facture_temp['montant_htc'] += $htPrice * $produit->quantite;
};
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva']) / 100;
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
} else {
$devis = $this->myDb->getDevisByFkFactureId($facture->id);
$factureGroupIsRelatedToAnyDevis = $devis != null;
$mentionFilters = [
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED
];
$isFactureGroupForSingleClient = $facture->facture_client_id != null && $facture->facture_client_id != 0;
if($isFactureGroupForSingleClient) {
$facture_temp["client"] = $facture->facture_client_entreprise;
$facture_temp["nom_client"] = $facture->facture_client_name;
if(!$factureGroupIsRelatedToAnyDevis) {
$devisList = $this->myDb->getDevisByClientIdAndMonthYear(
$facture->facture_client_id,
$facture->facture_month,
$facture->facture_year,
$mentionFilters
);
}
} else {
$facture_temp["client"] = $facture->group_code_comptable ?? '-';
$facture_temp["nom_client"] = $facture->facture_group_name;
if(!$factureGroupIsRelatedToAnyDevis) {
$devisList = $this->myDb->getDevisByClientGroupFacturationIdAndMonthYear(
$facture->facture_client_group_facturation_id,
$facture->facture_month,
$facture->facture_year,
[
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED
]
);
}
}
if($factureGroupIsRelatedToAnyDevis) {
$devisList = $this->myDb->getDevisByClientIdByFactureId($facture->id, $mentionFilters);
}
foreach($devisList as $currentDevis) {
$produits = json_decode($this->getProduitsById($currentDevis['id']));
foreach ($produits as $key => $produit) {
$htPrice = $produit->prix_unitaire;
if($currentDevis["fk_client_group_id"] != null || $currentDevis["fk_client_group_id"] != 0) {
$price = $this->myDb->getProductPriceByClientGroupId($currentDevis["fk_client_group_id"], $produit->id);
if($price != null) {
$htPrice = $price;
}
}
$facture_temp['montant_htc'] += $htPrice * $produit->quantite;
};
}
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva']) / 100;
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
}
array_push($data_factures, $facture_temp);
};
$data_temp = array();
foreach ($data_factures as $key => $facture) {
$datesplit = explode('-', $facture['date_facture']);
if($data_temp[strval($datesplit[0])] == null) {
$data_temp[strval($datesplit[0])][strval($datesplit[1])] = array(0 => $facture);
} else {
if($data_temp[strval($datesplit[0])][strval($datesplit[1])] == null) {
$data_temp[strval($datesplit[0])][strval($datesplit[1])] = array(0 => $facture);
} else {
array_push($data_temp[strval($datesplit[0])][strval($datesplit[1])], $facture);
}
}
}
// 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 signatureImageExists(string $signatureImageName)
{
$signatureExist = true;
try {
if(isset($this->adminStorage)) {
$file = $this->adminStorage->get("/.gestion/".$signatureImageName);
} else {
$signatureExist = false;
}
} catch(\OCP\Files\NotFoundException $e) {
$signatureExist = false;
}
return $signatureExist;
}
private function getLogo()
{
try {
if(isset($this->adminStorage)) {
$file = $this->adminStorage->get('/.gestion/logo.png');
} else {
return "nothing";
}
} catch(\OCP\Files\NotFoundException $e) {
return "nothing";
}
return base64_encode($file->getContent());
}
private function getSignature()
{
try {
if(isset($this->adminStorage)) {
$file = $this->adminStorage->get('/.gestion/sign.jpg');
return $file->getContent();
}
} catch(\OCP\Files\NotFoundException $e) {
}
return false;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getStats()
{
$isThanato = in_array('Thanatos', $this->groups);
$isAdmin = in_array('admin', $this->groups);
$isUserThanatoOnly = $isThanato && !$isAdmin;
$res = array();
$res['client'] = json_decode($this->myDb->numberClient($this->idNextcloud))[0]->c;
$res['defunt'] = $this->myDb->numberDefunt($this->idNextcloud, $isUserThanatoOnly);
$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;
$res['clientGroup'] = json_decode($this->myDb->getClientGroupCount())[0]->c;
$res['clientGroupDiscount'] = json_decode($this->myDb->getClientGroupDiscountCount())[0]->c;
$res['clientGroupFacturation'] = json_decode($this->myDb->getClientGroupFacturationCount())[0]->c;
return json_encode($res);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getAnnualTurnoverPerMonthNoVat()
{
return $this->myDb->retrieveTotalInvoicesForTheYear();
}
/**
* @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()
{
$isThanato = in_array('Thanatos', $this->groups);
$isAdmin = in_array('admin', $this->groups);
$isUserThanatoOnly = $isThanato && !$isAdmin;
return $this->myDb->getDefunts($this->idNextcloud, $isUserThanatoOnly);
}
/**
* @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);
}
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, $email = '')
{
$defaultConfig = json_decode($this->myDb->getConfiguration(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD));
$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("d-m-Y", strtotime($defunt->date));
$date_temp = date("d-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 = FileExportHelpers::GetDefuntsFolder(
$defunt->nom,
$defunt->nom_defunt,
$defaultConfig[0]->path.'/'
);
$folderDestination .= 'RAPPORTS/';
try {
$this->storage->newFolder($folderDestination);
} catch(\OCP\Files\NotPermittedException $e) {
}
// TODO: init pdf
$pdf = new FPDF();
// $pdf->AddFont('Arial','','Comic Sans MS.php');
// $pdf->AddFont('Arial','B','comic-sans-bold.php');
$pdf->AddPage();
$pdf->SetAutoPagebreak(false);
$pdf->SetMargins(15, 15, 15);
// logo : 80 de largeur et 55 de hauteur
$logo = $this->getLogo();
if($logo != 'nothing') {
$pdf->Image($this->defaultImagePath."logo.png", 4, 2, 40, 45);
}
$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(68);
$pdf->SetFont('Arial', '', 10);
$pdf->MultiCell(0, 5, FileExportHelpers::FormatTextForExport($defaultConfig[0]->adresse.", le ".$today), '', 'R');
$rapportInfoHeaderY = $pdf->GetY() + 15;
$rapportDefuntInfoY = $rapportInfoHeaderY;
$rapportDevisInfoY = $rapportInfoHeaderY;
$pdf->SetY(y: $rapportDefuntInfoY);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(0, 5, FileExportHelpers::FormatTextForExport($nomDefunt));
$rapportDefuntInfoY += 5;
$pdf->SetY($rapportDefuntInfoY);
$pdf->Cell(0, 5, FileExportHelpers::FormatTextForExport($age. " ans"));
$rapportDefuntInfoY += 5;
$pdf->SetY($rapportDefuntInfoY);
$sexeText = strcmp($defunt->sexe, 'm') == 0 ? 'Masculin' : 'Féminin';
$pdf->Cell(0, 5, FileExportHelpers::FormatTextForExport($sexeText));
//devis info
$rapportDevisInfoX = 115;
$maxWidth = $pdf->GetPageWidth();
$availableWidhtForDevisInfo = $maxWidth - 10 - $rapportDevisInfoX;
$pdf->SetXY($rapportDevisInfoX, $rapportDevisInfoY);
$pdf->MultiCell(0, 5, FileExportHelpers::FormatTextForExport("Éffectuées le ".$date_devis));
$rapportDevisInfoY += 5;
$pdf->SetXY($rapportDevisInfoX, $rapportDevisInfoY);
$addressText = "à ".$defunt->adresse_lieu;
$pdf->MultiCell(0, 5, FileExportHelpers::FormatTextForExport($addressText), 0, 'L');
$addressLineCount = FileExportHelpers::GetLineCountForATextInAMaxWidth($pdf, $addressText, $availableWidhtForDevisInfo);
$rapportDevisInfoY += 5 * $addressLineCount;
$pdf->SetXY($rapportDevisInfoX, $rapportDevisInfoY);
$pdf->Cell(0, 5, FileExportHelpers::FormatTextForExport("de ".$defunt->heure_debut." à ".$defunt->heure_fin));
$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() + 5);
$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() + 5);
$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(-20);
$pdf->SetFont('Arial', '', 8);
$pdf->MultiCell($pdf->GetPageWidth() - 30, 5, FileExportHelpers::FormatTextForExport($defaultConfig[0]->legal_one), '', 'C');
$pdf->SetFont('Arial', '', 8);
$pdf->MultiCell($pdf->GetPageWidth() - 30, 5, FileExportHelpers::FormatTextForExport($defaultConfig[0]->adresse), '', '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(-20);
$pdf->SetFont('Arial', '', 8);
$pdf->MultiCell($pdf->GetPageWidth() - 30, 5, FileExportHelpers::FormatTextForExport($defaultConfig[0]->legal_one), '', 'C');
$pdf->SetFont('Arial', '', 8);
$pdf->MultiCell($pdf->GetPageWidth() - 30, 5, FileExportHelpers::FormatTextForExport($defaultConfig[0]->adresse), '', '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(-20);
$pdf->SetFont('Arial', '', 8);
$pdf->MultiCell($pdf->GetPageWidth() - 30, 5, FileExportHelpers::FormatTextForExport($defaultConfig[0]->legal_one), '', 'C');
$pdf->SetFont('Arial', '', 8);
$pdf->MultiCell($pdf->GetPageWidth() - 30, 5, FileExportHelpers::FormatTextForExport($defaultConfig[0]->adresse), '', 'C');
$pdf->AddPage();
}
// signature
$pdf->SetFont('Arial', '', 11);
$pdf->setY($pdf->GetY() + 10);
$pdf->Cell($pdf->GetPageWidth() - 30, 0, utf8_decode(html_entity_decode($defaultConfig[0]->nom).' '.html_entity_decode($defaultConfig[0]->prenom)), 0, 0, 'L');
$pdf->setY($pdf->GetY() + 5);
$signatureExist = $this->signatureImageExists('sign.jpg');
if($signatureExist) {
$pdf->Image($this->defaultImagePath."sign.jpg", 13, $pdf->GetY() + 8, 55, 25);
}
$signatureExist = $this->signatureImageExists('sign.png');
if($signatureExist) {
$pdf->Image($this->defaultImagePath."sign.png", 13, $pdf->GetY() + 40, 40, 15);
}
$pdf->setY($pdf->GetY() - 5);
$pdf->SetFont('Arial', '', 11);
$pdf->Cell($pdf->GetPageWidth() - 80, 0, "Pour :", 0, 0, 'R');
$pdf->SetY(-20);
$pdf->SetFont('Arial', '', 8);
$pdf->MultiCell($pdf->GetPageWidth() - 30, 5, FileExportHelpers::FormatTextForExport($defaultConfig[0]->legal_one), '', 'C');
$pdf->SetFont('Arial', '', 8);
$pdf->MultiCell($pdf->GetPageWidth() - 30, 5, FileExportHelpers::FormatTextForExport($defaultConfig[0]->adresse), '', '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);
if($ff_pdf != null && trim($email) != '') {
//send email
$this->sendAttachmentToClientByDefunt($defunt->id, $ff_pdf, $email, "Rapport soins", "Vous trouverez en pièce jointe le rapport de soins de ", true);
}
$res = array();
$res['path'] = $folderDestination;
return json_encode($res);
} catch(\OCP\Files\NotFoundException $e) {
return $e;
}
} else {
return false;
}
}
public 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, $withPhotos = false, $email = '')
{
if($withPhotos != null && $withPhotos == 1) {
$withPhotos = true;
} else {
$withPhotos = false;
}
$defaultConfig = json_decode($this->myDb->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$defunt = json_decode($this->myDb->getOneDefunt($numdefunt, $this->idNextcloud))[0];
$bijoux = json_decode($this->myDb->getListBijoux($numdefunt, $this->idNextcloud));
try {
$nomDefunt = $defunt->nom_defunt;
$date_temp = new Datetime($defunt->date);
$date_temp = $date_temp->format('d-m-Y');
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
$today = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_temp));
// $folderDestination = html_entity_decode($defaultConfig[0]->path).'/CLIENTS/'.strtoupper($defunt->entreprise).'/DEFUNTS/'.strtoupper($nomDefunt).'/RAPPORTS/';
$folderDestination = FileExportHelpers::GetDefuntsFolder(
$defunt->nom,
$defunt->nom_defunt,
$defaultConfig[0]->path.'/'
);
$folderDestination .= 'RAPPORTS/';
try {
$this->storage->newFolder($folderDestination);
} catch(\OCP\Files\NotPermittedException $e) {
}
// TODO: init pdf
$pdf = new FPDF();
// $pdf->AddFont('Arial','','Comic Sans MS.php');
// $pdf->AddFont('Arial','B','comic-sans-bold.php');
$pdf->AddPage();
// on sup les 2 cm en bas
$pdf->SetAutoPagebreak(true);
// logo : 80 de largeur et 55 de hauteur
$logo = $this->getLogo();
if($logo != 'nothing') {
$pdf->Image($this->defaultImagePath."logo.png", 4, 2, 40, 45);
}
$pdf->SetY(45);
$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(65);
$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($defaultConfig[0]->entreprise)." titulaire de l'habilitation n° ".$defunt->reference_habilitation." atteste par la présente que :
".(strcmp($defunt->sexe, 'm') == 0 ? 'Monsieur' : 'Madame').". ".$defunt->nom_defunt."
a été pris(e) en charge par nos services pour des soins mortuaires.")), '', 'J', 0);
$pdf->setY($pdf->GetY() + 10);
$hasTaker = false;
foreach ($bijoux as $key => $bijou) {
$currentBijouHasTaker = $bijou->taker_name != null && $bijou->taker_name != "" && $bijou->taker_name != "-";
if($currentBijouHasTaker) {
$hasTaker = true;
break;
}
}
$columnNumber = $hasTaker ? 3 : 2;
$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) / $columnNumber);
$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');
if($hasTaker) {
$pdf->SetXY($col_width + 75, $pdf->GetY() - 8);
$pdf->SetFont('Arial', 'B', 10);
$pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode("Prise en charge des bijoux par")), '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');
if($hasTaker) {
$pdf->SetXY($col_width + 75, $pdf->GetY() - 8);
$pdf->SetFont('Arial', '', 10);
$pdf->MultiCell($col_width, 8, utf8_decode(html_entity_decode($bijou->taker_name)), 'LTRB', 'L');
}
}
$photosCount = 0;
if($withPhotos) {
$photosCountLimitToGoToNewLine = 3;
$currentUserFolder = "/var/www/html/data/".BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD."/files/";
$clientName = $defunt->nom;
if($clientName != null) {
$bijouxPhotosFolder = FileExportHelpers::GetBijouxOfDefuntFolder($clientName, $defunt->nom_defunt, $defaultConfig[0]->path);
$pdf->setXY($pdf->GetX(), $pdf->GetY() + 5);
$pdf->Cell(0, 5, "Photos :", 0, 1);
$pdf->setXY($pdf->GetX(), $pdf->GetY() + 5);
foreach ($bijoux as $key => $bijou) {
if($bijou->photo == null) {
continue;
}
try {
$fullPhotoPath = $currentUserFolder.$bijouxPhotosFolder.$bijou->photo;
$pdf->Image($fullPhotoPath, $pdf->GetX(), $pdf->GetY(), 50, 30);
$pdf->SetXY($pdf->GetX() + 60, $pdf->GetY());
$photosCount++;
if($photosCount == $photosCountLimitToGoToNewLine) {
$pdf->SetY($pdf->GetY() + 35);
}
} catch(Exception) {
}
}
}
if($photosCount > 0) {
$pdf->SetY($pdf->GetY() + 30);
}
}
$pdf->setY($pdf->GetY() + 10);
$pdf->SetFont('Arial', '', 10);
$pdf->MultiCell(0, 5, FileExportHelpers::FormatTextForExport("Cette attestation est remise pour faire valoir ce que de droit.
Fait à ".$defaultConfig[0]->adresse.", le ".$today), '', 'J', 0);
$pdf->setY($pdf->GetY() + 10);
// signature
$pdf->SetFont('Arial', '', 11);
$pdf->Cell($pdf->GetPageWidth() - 30, 0, utf8_decode(html_entity_decode($defaultConfig[0]->nom).' '.html_entity_decode($defaultConfig[0]->prenom)), 0, 0, 'L');
$pdf->setY($pdf->GetY() + 5);
$signatureExist = $this->signatureImageExists('sign.jpg');
if($signatureExist) {
$pdf->Image($this->defaultImagePath."sign.jpg", 10, $pdf->GetY() + 5, 55, 25);
}
$signatureExist = $this->signatureImageExists('sign.png');
if ($signatureExist) {
$pdf->Image($this->defaultImagePath."sign.png", 10, $pdf->GetY() + 35, 40, 15);
}
$pdf->setY($pdf->GetY() - 5);
$pdf->SetFont('Arial', '', 11);
$pdf->Cell($pdf->GetPageWidth() - 80, 0, "Pour :", 0, 0, 'R');
$pdf->SetY(-15);
$pdf->SetFont('Arial', '', 8);
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode($defaultConfig[0]->legal_one)), 0, 'C');
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode($defaultConfig[0]->adresse)), 0, 'C');
$ff_pdf = $folderDestination.'RAPPORT_BIJOUX_'.strtoupper($nomDefunt).'.pdf';
$this->storage->newFile($ff_pdf);
$pdfContent = $pdf->Output('', 'S');
$file_pdf = $this->storage->get($ff_pdf);
$file_pdf->putContent($pdfContent);
if($ff_pdf != null && trim($email) != '') {
//send email
$this->sendAttachmentToClientByDefunt($defunt->id, $ff_pdf, $email, "Rapport des bijoux", "Vous trouverez en pièce jointe le rapport des bijoux de ", true);
}
$res = array();
$res['path'] = $folderDestination;
return json_encode($res);
} catch(\OCP\Files\NotFoundException $e) {
return $e;
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param array $thanatoIdsToExport
* @param string $month
* @param string $year
*
*/
public function exportThanatoStatistic($thanatoIdsToExport, $month, $year)
{
if(empty($thanatoIdsToExport)) {
return "";
}
$month = $month ?? date('m');
$year = $year ?? date('Y');
try {
$filenames = $this->exportThanatoStatisticService->exportThanatosListStatistic($thanatoIdsToExport, $month, $year, $this->idNextcloud);
return $filenames;
} 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();
$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 exportFactureToPdf($factureId)
{
try {
$factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId, $this->idNextcloud);
return json_encode($factureGeneratedResponse["filenames"]);
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param string $filter
* @param string $month
* @param string $year
* @param string $filterType // client|group
*
*/
public function exportFactureByClientAndMonthYearToPdf($filter, $month, $year, $filterType = "client")
{
try {
$factureFilename = $this->invoicePdfService->generateMultipleInvoicePdfByClientAndMonthYear(
filter: $filter,
month: $month,
year: $year,
idNextCloud: $this->idNextcloud,
filterType: $filterType
);
return $factureFilename;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param string $clientId
* @param string $month
* @param string $year
* @param string $filterType // client|group
*
*/
public function exportDevisRecap()
{
try {
// Lire le JSON brut depuis php://input
$data = json_decode(file_get_contents('php://input'), true);
$clientId = $data['clientId'] ?? null;
$month = $data['month'] ?? null;
$year = $data['year'] ?? null;
$filterType = $data['clientType'] ?? 'client';
$montant = $data['montant'] ?? null;
$devisFilename = $this->devisRecapService->generateDevisRecap(
filter: $clientId,
month: $month,
year: $year,
idNextCloud: $this->idNextcloud,
filterType: $filterType,
montant : $montant
);
return $devisFilename;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function addDevisNumberColumn()
{
try {
$this->myDb->addNumberColumnOnDevis();
return true;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function addFactureNumberColumn()
{
try {
$this->myDb->addNumberColumnOnFacture();
return true;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getClientGroupDiscounts()
{
return $this->myDb->getClientGroupDiscounts();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function clientGroupDiscount()
{
return new TemplateResponse('gestion', 'clientGroupDiscount', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/thanatopracteur.php
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function clientGroups()
{
return new TemplateResponse('gestion', 'clientGroup', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); // templates/thanatopracteur.php
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getClientGroups()
{
return $this->myDb->getClientGroups();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function createDefaultClientGroup()
{
return $this->myDb->createDefaultClientGroup();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function createDefaultClientGroupDiscount()
{
return $this->myDb->createDefaultClientGroupDiscount();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function addClientGroupDiscountFeatureTables()
{
try {
$this->myDb->addClientGroupDiscountFeatureTables();
return true;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param int $defuntId
*/
public function exportCareCertificate($defuntId, $email = '')
{
try {
$careCertificateFilename = $this->certificateService->generateCareCertificate($defuntId, $this->idNextcloud);
if($careCertificateFilename != null && trim($email) != '') {
//send email
$this->sendAttachmentToClientByDefunt($defuntId, $careCertificateFilename, $email, "Attestation de soins", " Vous trouverez en pièce jointe l'attestation de soins ", true);
}
return $careCertificateFilename;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param int $defuntId
* @param int $productId
*/
public function setDefuntCover($defuntId, $productId)
{
try {
$response = $this->myDb->setDefuntCover($defuntId, $productId);
return $response;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getUserConnectedGroups()
{
try {
return json_encode($this->groups);
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function testTalk()
{
try {
$message = $this->myDb->getDevisTalkRoomMessage(1, $this->idNextcloud);
// $message ="FROM API";
$this->talkService->sendDevisTalkNotifications($message, $this->idNextcloud);
return true;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getCoverProducts()
{
try {
$coverProducts = $this->myDb->getCoverProducts();
return $coverProducts;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param int $devisId
*
*/
public function exportDevisToPdf($devisId)
{
try {
$devisFilenames = $this->devisPdfService->generateDevisPdfByDevisId($devisId, $this->idNextcloud);
return json_encode($devisFilenames);
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param string $clientId
* @param string $month
* @param string $year
*
*/
public function exportDevisByClientAndMonthYearToPdf($clientId, $month, $year, $type = DevisExportTypeConstant::TYPE_SINGLE)
{
try {
$devisFilename = $this->devisPdfService->generateMultipleDevisPdfByClientAndMonthYear($clientId, $month, $year, $type, $this->idNextcloud);
return $devisFilename;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function addClientGroupFacturationFeatureTables()
{
try {
$this->myDb->addClientGroupFacturationFeatureTables();
return true;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function clientGroupFacturation()
{
return new TemplateResponse('gestion', 'clientGroupFacturation', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink()));
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getClientGroupFacturations()
{
return $this->myDb->getClientGroupFacturations();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function createDefaultClientGroupFacturation()
{
return $this->myDb->createDefaultGroupFacturation();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param int $defuntId
*/
public function saveAttestationPacemaker($defuntId, $email = '')
{
try {
$careCertificateFilename = $this->certificateService->generatePacemakerCertificate($defuntId, $this->idNextcloud);
if($careCertificateFilename != null && trim($email) != '') {
//send email
$this->sendAttachmentToClientByDefunt($defuntId, $careCertificateFilename, $email, "Retrait de pile", "Vous trouverez en pièce jointe l'attestation de retrait de pile ", true);
}
return $careCertificateFilename;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param int $defuntId
*/
public function saveAttestationAbsentPacemaker($defuntId, $email = '')
{
try {
$careCertificateFilename = $this->certificateService->generatePacemakerAbsentCertificate($defuntId, $this->idNextcloud);
if($careCertificateFilename != null && trim($email) != '') {
//send email
$this->sendAttachmentToClientByDefunt($defuntId, $careCertificateFilename, $email, "Retrait de pile", "Vous trouverez en pièce jointe l'attestation de retrait de pile ", true);
}
return $careCertificateFilename;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function addProductTypeTables()
{
try {
$this->myDb->addProductTypeTables();
return true;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getProductTypes()
{
return $this->myDb->getProductTypes();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function addLocationCodesColumn()
{
try {
$this->myDb->addLocationCodesColumn();
return true;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function uploadFileToBijoux($bijouxId)
{
try {
$configs = json_decode($this->myDb->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$currentConfig = $configs[0];
$bijoux = $this->myDb->getBijouxWithDefuntByBijouxId($bijouxId);
if($bijoux == null) {
return false;
}
if($bijoux["defunt_id"] == null) {
return false;
}
$defuntId = $bijoux["defunt_id"];
$devisOfDefunt = $this->myDb->getDevisOfDefunt($defuntId);
if($devisOfDefunt == null) {
return false;
}
$folder = FileExportHelpers::GetBijouxOfDefuntFolder($devisOfDefunt["client_nom"], $bijoux["defunt_nom"], $currentConfig->path);
$appAdminStorage = $this->rootFolder->getUserFolder(BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD);
try {
$this->storage->newFolder($folder);
$this->adminStorage->newFolder($folder);
$appAdminStorage->newFolder($folder);
} catch(\OCP\Files\NotPermittedException $e) {
}
$photoName = basename($_FILES["photo"]["name"]);
$filename = uniqid() . "_" .$photoName;
$fullPath = $folder.$filename;
$fileContent = file_get_contents($_FILES["photo"]["tmp_name"]);
$this->storage->newFile($fullPath, $fileContent);
$this->adminStorage->newFile($fullPath, $fileContent);
try {
$appAdminStorage->newFile($fullPath, $fileContent);
} catch(\OCP\Files\NotPermittedException $e) {
}
$this->myDb->saveBijouxPhoto($bijouxId, $filename, $photoName);
return $fullPath;
} catch(\OCP\Files\NotFoundException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function uploadPacemakerPhotoToDefunts($defuntId)
{
try {
$configs = json_decode($this->myDb->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$currentConfig = $configs[0];
$devisOfDefunt = $this->myDb->getDevisOfDefunt($defuntId);
if($devisOfDefunt == null) {
return null;
}
$folder = FileExportHelpers::GetPacemakerPhotoFolderOfDefunt($devisOfDefunt["client_nom"], $devisOfDefunt["defunt_nom"], $currentConfig->path);
$appAdminStorage = $this->rootFolder->getUserFolder(BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD);
try {
$this->storage->newFolder($folder);
$this->adminStorage->newFolder($folder);
$appAdminStorage->newFolder($folder);
} catch(\OCP\Files\NotPermittedException $e) {
}
$photoName = basename($_FILES["photo"]["name"]);
$filename = uniqid() . "_" .$photoName;
$fullPath = $folder.$filename;
$fileContent = file_get_contents($_FILES["photo"]["tmp_name"]);
$this->storage->newFile($fullPath, $fileContent);
$this->adminStorage->newFile($fullPath, $fileContent);
try {
$appAdminStorage->newFile($fullPath, $fileContent);
} catch(\OCP\Files\NotPermittedException $e) {
}
$this->myDb->saveDefuntPacemakerPhoto($defuntId, $filename, $photoName);
return $fullPath;
} catch(\OCP\Files\NotFoundException $e) {
return null;
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function payInvoices($factureIds, $facturePaymentTypeId, $paymentDate)
{
try {
$result = $this->myDb->payInvoices($factureIds, $facturePaymentTypeId, $paymentDate);
return $result;
} catch(Exception) {
return false;
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function getUsersNotLinkedToThanato()
{
try {
$result = $this->myDb->getUsersNotLinkedToThanato();
return $result;
} catch(Exception $e) {
return json_encode([]);
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function exportGroupOfDevisIntoFacture($clientId, $clientType, $month, $year, $facturationDate)
{
try {
$result = $this->invoicePdfService->exportGroupOfDevisIntoFacture(
$clientId,
$clientType,
$month,
$year,
$facturationDate,
$this->idNextcloud
);
if ($result) {
return json_encode($result);
}
return json_encode([]);
} catch(Exception $e) {
return json_encode([]);
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function getClientTemplateTypes()
{
return $this->myDb->getClientTemplateTypes();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function factureGroupDetails($numfacture)
{
$this->denyIfNotAdmin();
$facture = $this->myDb->getFactureGroupByFactureIdWithDetails($numfacture);
$facture["path_to_file"] = $this->idNextcloud.'/'.FileExportHelpers::GetFactureGroupFileFullPath(
clientName:$facture['group_name'],
factureNum: $facture['num'],
facturationDate: $facture['date_paiement']
);
return new TemplateResponse('gestion', 'factureGroupDetails', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud,
'configuration' => $this->getConfiguration(),
'facture' => json_decode(json_encode($facture)),
'url' => $this->getNavigationLink(),
'logo' => $this->getLogo()
));
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param int $defuntId
*/
public function updateDevisLigneTrajet($idNextcloud, $mois, $annee)
{
//get all devis id from month and year
if(!$idNextcloud || !$mois || !$mois) {
return null;
}
$idsNextcloud = explode(',', $idNextcloud);
foreach($idsNextcloud as $id) {
$this->updateLigneTrajet($id, $mois, $annee);
}
return "update successfully";
}
public function updateLigneTrajet($idNextcloud, $mois, $annee)
{
$all_devis = $this->myDb->getAllDevisByMonthAndYear($idNextcloud, $mois, $annee);
foreach($all_devis as $devis) {
$ligne_trajet = json_decode($this->myDb->getOneTrajetdetails_byIdDevis($devis['id'], $idNextcloud))[0];
if($ligne_trajet != null) {
$this->myDb->gestion_delete('ligne_trajet', $ligne_trajet->id, $idNextcloud);
$ligne_trajet = null;
}
$devisObject = json_decode($this->myDb->getOneDevis($devis['id'], $idNextcloud))[0];
$this->myDb->generate_ligneTrajet($devisObject, $idNextcloud);
$ligne_trajet = json_decode(json: $this->myDb->getOneTrajetdetails_byIdDevis($devisObject->devisid, $idNextcloud))[0];
$this->myDb->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
$this->myDb->calculer_distance_trajet(numtrajet: $ligne_trajet->id_trajet, idNextcloud: $idNextcloud);
}
$this->deleteUnusedLigneTrajet($idNextcloud, $mois, $annee);
return true;
}
public function deleteUnusedLigneTrajet($idNextcloud, $mois, $annee)
{
$dateOfMonths = DateHelpers::getDatesOfMonth($annee, $mois);
$thanato = $this->myDb->getThanatoByUserUuid($idNextcloud);
$trajet = $this->myDb->getTrajetByThanatoAndMonthYear($thanato['id'], $mois, $annee);
if($trajet == null) {
return;
}
foreach($dateOfMonths as $currentDate) {
$currentDateFormatted = $currentDate->format('Y-m-d');
$thereIsThanatoDevisRattachedToLigneTrajetForADate = $this->myDb->thereIsThanatoDevisRattachedToLigneTrajetForADate($currentDateFormatted, $trajet['id']);
if(!$thereIsThanatoDevisRattachedToLigneTrajetForADate) {
$this->myDb->deleteThanatoLigneTrajetForADateWithoutDevisByTrajetId($currentDateFormatted, $trajet['id']);
} else {
$devisRelatedToLigneTrajetButNotRelatedToCurrentThanato = $this->myDb->getLigneTrajetsWithDevisNotRelatedToThanato($currentDateFormatted, $thanato['id'], $trajet['id']);
if($devisRelatedToLigneTrajetButNotRelatedToCurrentThanato != null && count($devisRelatedToLigneTrajetButNotRelatedToCurrentThanato) > 0) {
foreach($devisRelatedToLigneTrajetButNotRelatedToCurrentThanato as $currentLigneTrajet) {
$this->myDb->gestion_delete('ligne_trajet', $currentLigneTrajet['id'], $idNextcloud);
}
$thereIsThanatoDevisRattachedToLigneTrajetForADate = $this->myDb->thereIsThanatoDevisRattachedToLigneTrajetForADate($currentDateFormatted, $trajet['id']);
if(!$thereIsThanatoDevisRattachedToLigneTrajetForADate) {
$this->myDb->deleteThanatoLigneTrajetForADateWithoutDevisByTrajetId($currentDateFormatted, $trajet['id']);
}
}
}
}
}
}