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; 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)); 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()); 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", 10, 10, 75, 25); // 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", 10, 10, 75, 25); // 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('ComicSans','','Comic Sans MS.php'); $pdf->AddFont('ComicSans','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", 10, 10, 75, 25); // adresse du facture $pdf->SetFont('ComicSans','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('ComicSans','',11); $pdf->SetXY( 122, 60 ); $pdf->Cell( 60, 8, "Bourges France le, ".utf8_decode($date_formated), 0, 0, ''); // observations $pdf->SetFont( "ComicSans", "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( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 85 ) ; $pdf->Cell($pdf->GetStringWidth($objet), 0, $objet, 0, "L"); $pdf->SetFont( "ComicSans", "", 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( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 105 ) ; $pdf->Cell($pdf->GetStringWidth($text1), 0, $text1, 0, "L"); $pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 110 ) ; $pdf->Cell($pdf->GetStringWidth($text2), 0, $text2, 0, "L"); $pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 120 ) ; $pdf->Cell($pdf->GetStringWidth($text3), 0, $text3, 0, "L"); // signature $pdf->SetFont('ComicSans','',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('ComicSans','',6); $pdf->SetXY( 1, $y0 + 4 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C'); $pdf->SetXY( 1, $y0 + 8 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C'); $pdf->SetXY( 1, $y0 + 12 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->telephone)), 0, 0, 'C'); /*$pdf->SetXY( 1, $y0 + 16 ); $pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/ $num_page = 1; $nb_page = ceil(sizeof($client) / 26); $index_facture_position = 0; $max_nb_toget = (sizeof($client)<=26)?sizeof($client):26; $montant_ht_total = 0; $montant_tva_total = 0; $montant_ttc_total = 0; while ($num_page <= $nb_page) { $pdf->AddPage(); // on sup les 2 cm en bas $pdf->SetAutoPagebreak(False); $pdf->SetMargins(0,0,0); $pdf->Image($this->src_path."logo.png", 10, 10, 75, 25); // n° page en haute à droite if($nb_page>1){ $pdf->SetXY( 120, 5 ); $pdf->SetFont( "ComicSans", "B", 9 ); $pdf->Cell( 160, 8, $num_page . '/' . $nb_page, 0, 0, 'C'); } // date facture $pdf->SetFont('ComicSans','',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( "ComicSans", "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('ComicSans','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('ComicSans','B',8); $pdf->Cell( 140, 8, "OBJET", 0, 0, 'C'); $pdf->SetXY( 147, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 13, 8, "H.T.", 0, 0, 'C'); $pdf->SetXY( 168, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 10, 8, "TVA 20%", 0, 0, 'C'); $pdf->SetXY( 183, 81 ); $pdf->SetFont('ComicSans','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('ComicSans','',8); $pdf->Cell( 28, 8, $client[$index_facture_position]['num'], 0, 0, ''); $pdf->SetXY( 32, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 28, 8, $client[$index_facture_position]['numero_commande'], 0, 0, ''); $pdf->SetXY( 53, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 18, 8, utf8_decode($formatter_ds->format($date_soin_temp)), 0, 0, ''); $pdf->SetXY( 65, $y_facture ); $pdf->SetFont('ComicSans','',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('ComicSans','',8); $pdf->Cell( 28, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['defunt'])), 0, 0, ''); $pdf->SetXY( 147, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 13, 8, $client[$index_facture_position]['montant_htc'].chr(128), 0, 0, 'C'); $pdf->SetXY( 168, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 10, 8, $client[$index_facture_position]['montant_tva'].chr(128), 0, 0, 'C'); $pdf->SetXY( 183, $y_facture ); $pdf->SetFont('ComicSans','',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('ComicSans','B',8); $pdf->SetXY( 5, 225 ); $pdf->Cell( 140, 8, 'TOTAL', 0, 0, 'C'); $pdf->SetFont('ComicSans','',8); $pdf->SetXY( 147, 225 ); $pdf->Cell( 13, 8, $montant_ht_total.chr(128), 0, 0, 'C'); $pdf->SetFont('ComicSans','',8); $pdf->SetXY( 168, 225 ); $pdf->Cell( 10, 8, $montant_tva_total.chr(128), 0, 0, 'C'); $pdf->SetFont('ComicSans','',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('ComicSans','B',8); $pdf->SetXY( 147, 233 ); $pdf->Cell( 30, 6.5, 'TOTAL TTC', 0, 0, 'C'); $pdf->SetFont('ComicSans','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('ComicSans','',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('ComicSans','',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->refreshFEC(); return $result; } /** * @NoAdminRequired * @NoCSRFRequired */ public function getFacturesWithProduits() { $result = $this->myDb->getFacturesWithProduits(); $this->refreshFEC(); return $result; } private function synchronize_facture() { $factures = json_decode($this->myDb->getFactures($this->idNextcloud)); foreach ($factures as $key => $facture) { if($facture->id_devis) { $deviscourant = json_decode($this->myDb->getOneDevis($facture->id_devis, $this->idNextcloud))[0]; $this->myDb->gestion_update('facture', 'date', $deviscourant->date, $facture->id, $this->idNextcloud); $this->myDb->gestion_update('facture', 'version', html_entity_decode($deviscourant->version), $facture->id, $this->idNextcloud); $this->myDb->gestion_update('facture', 'type_paiement', 'comptant', $facture->id, $this->idNextcloud); } } } /** * @NoAdminRequired * @NoCSRFRequired */ public function getProduits() { return $this->myDb->getProduits($this->idNextcloud); } /** * @NoAdminRequired * @NoCSRFRequired */ public function ajaxGetProduits($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->refreshFEC(); return $result; } /** * @NoAdminRequired * @NoCSRFRequired * */ public function insertProduit(){ return $this->myDb->insertProduit($this->idNextcloud); } /** * @NoAdminRequired * @NoCSRFRequired * @param string $id */ public function insertProduitDevis($id){ return $this->myDb->insertProduitDevis($id, $this->idNextcloud); } /** * @NoAdminRequired * @NoCSRFRequired * @param string $id */ public function insertArticleDevis($id){ return $this->myDb->insertArticleDevis($id, $this->idNextcloud); } /** * @NoAdminRequired * @NoCSRFRequired * @param string $id */ public function insertObservationDefunt($id){ return $this->myDb->insertObservationDefunt($id, $this->idNextcloud); } /** * @NoAdminRequired * @NoCSRFRequired * @param string $id */ public function insertBijouDefunt($id){ return $this->myDb->insertBijouDefunt($id, $this->idNextcloud); } /** * @NoAdminRequired * @NoCSRFRequired * @param string $id */ public function insertHypoDefunt($id){ return $this->myDb->insertHypoDefunt($id, $this->idNextcloud); } /** * @NoAdminRequired * @NoCSRFRequired * */ public function insertBibliotheque(){ return $this->myDb->insertBibliotheque($this->idNextcloud); } /** * @NoAdminRequired * @NoCSRFRequired * @param string $table * @param string $column * @param string $data * @param string $id */ public function update($table, $column, $data, $id) { if(strcmp($table, 'facture')==0 || strcmp($table, 'produit')==0 || strcmp($table, 'devis')==0 || strcmp($table, 'client')==0) { if(strcmp($column, 'id_devis')==0) { $facturecourant = json_decode($this->myDb->getOneFacture($id, $this->idNextcloud))[0]; $this->myDb->gestion_update('devis', 'mentions', 'facturé', $data, $this->idNextcloud); $this->myDb->gestion_update('devis', 'mentions', 'Nouveau', $facturecourant->id_devis, $this->idNextcloud); $result = $this->myDb->gestion_update($table, $column, $data, $id, $this->idNextcloud); } else { $facturecourant = json_decode($this->myDb->getOneFacture($id, $this->idNextcloud))[0]; if(strcmp($column, 'date_paiement')==0) { $datecourant = $facturecourant->date_paiement; $nouveaudate = $data; $result = $this->myDb->gestion_update($table, $column, $data, $id, $this->idNextcloud); // $this->generer_document_comptable($datecourant); // $this->generer_document_comptable($nouveaudate); } else { 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->refreshFEC(); 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->refreshFEC(); 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->refreshFEC(); return $result; } return $this->myDb->gestion_delete($table, $id, $this->idNextcloud); } /** * @NoAdminRequired * @NoCSRFRequired * @param string $content * @param string $name * @param string $subject * @param string $body * @param string $to * @param string $Cc */ public function sendPDF($content, $name, $subject, $body, $to, $Cc){ $clean_name = html_entity_decode($name); try { $data = base64_decode($content); $message = $this->mailer->createMessage(); $message->setSubject($subject); $message->setTo((array) json_decode($to)); $myrrCc = (array) json_decode($Cc); if($myrrCc[0] != ""){ $message->setCc($myrrCc); } $message->setHtmlBody($body); $content = $this->mailer->createAttachment($data,$clean_name.".pdf","x-pdf"); $message->attach($content); $this->mailer->send($message); return new DataResponse("", 200, ['Content-Type' => 'application/json']); } catch (Exception $e) { return new DataResponse("Is your global mail server configured in Nextcloud ?", 500, ['Content-Type' => 'application/json']); } } 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; $signature = $this->mailerService->getFooterContent(); $message->setHtmlBody( "
Bonjour.
". "$body_text
". $signature ); $authUserEmail = $this->user->getEMailAddress(); if ($authUserEmail) { $message->setCc([$authUserEmail]); } $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 addSignatureEmailLogo (){ $signatureImage = $this->getSignature(); if (!$signatureImage) { return ""; } //Add html img in base 64 return "