alors voici la structure de la page qui liste les factures :
{$uid=feu_smarty::get_current_userid()}
{$expired=feu_smarty::user_expired($uid)}
{if $expired || $uid == ''}
<h1> Vous n'êtes plus connecté </h1>
{cms_selflink href='home' assign='requested_url'}
{$requested_url=$requested_url scope=global}
<script>
$(location).attr('href', '{$requested_url}');
</script>
{redirect_url to=$requested_url}
{/if}
{authPDF OKPDF='TRUE'}
{*$smarty.session|@print_r*}
{*{get_documents where="DOC_NUMERO='0000247038'"}
{assign var='title' value='0000247038' scope=global}
{$count_doc}
{$documents|print_r}
{get_lignes where="DOC_NUMERO='0000247038'"}
{$lignes|@print_r}
{$count_lig}*}
{*
{$smarty.now|date_format:'%B %Y'}
{$smarty.now|date_format:'%d-%m-%Y %H:%M:%S'}
*}
{$userprops=feu_smarty::get_user_properties()}
{$time = $smarty.now|date_format:'%Y-%m-%d'}
{if $smarty.get.StartDateMonth && $smarty.get.StartDateYear}
{$time = "{$smarty.get.StartDateYear}-{$smarty.get.StartDateMonth}-01"}
{/if}
<h4 class="txtcenter">{$userprops.raison_sociale} ({feu_smarty::get_username($the_uid)})</h4>
<div class="txtcenter mbm">
{$op_annee = 0}
<a href="{$content_obj->GetURL()}?StartDateMonth={if {$time|date_format:'%m'} > 1}{{$time|date_format:'%m'}-1}{else}12{$op_annee = -1}{/if}&StartDateYear={{$time|date_format:'%Y'}+$op_annee}{if $userprops.super_utilisateur}&user_select={$smarty.get.user_select}{/if}" class="u-bigger prev-month arrow-date mrs"><i class="icon-arrow--left"></i></a>
<h2 class="inbl u-uppercase">{$time|date_format:'%B %Y'}</h2>
{$op_annee = 0}
<a href="{$content_obj->GetURL()}?StartDateMonth={if {$time|date_format:'%m'} < 12}{{$time|date_format:'%m'}+1}{else}1{$op_annee = 1}{/if}&StartDateYear={{$time|date_format:'%Y'}+$op_annee}{if $userprops.super_utilisateur}&user_select={$smarty.get.user_select}{/if}" class="u-bigger next-month arrow-date mls"><i class="icon-arrow--right"></i></a>
<form id="selectDate" action="{$content_obj->GetURL()}" method="get" class="txtcenter">
<p>{html_select_date prefix="StartDate" time=$time start_year="2023" end_year="+1" display_days=false reverse_years=true}</p>
{$selected_user = false}
{if $userprops.super_utilisateur}
<p>{$Ambapharm_members=feu_smarty::get_users_by_groupname('Axipharm')}
<label for="user_select" class="inbl mts">Choisir un compte</label>
<select name="user_select" id="user_select" class="w66">
<option value="">Tout</option>
{foreach $Ambapharm_members user}
<option value="{$user.id}"{if $user.id == $smarty.get.user_select} selected{$selected_user = feu_smarty::get_user_property('id_pharmaml',$user.id)}{/if}>{feu_smarty::get_user_property('raison_sociale',$user.id)} ({$user.username})</option>
{/foreach}
</select></p>
{else}
{$selected_user = $userprops.id_pharmaml}
{/if}
{if $selected_user !== false && $selected_user == ''}
{$selected_user = 'NOPE'}
{/if}
</form>
<script>
{literal}
$('#selectDate select').on('change', function() {
$('#selectDate').submit();
});
{/literal}
</script>
<div class="inbl tiny-w100 center bdrform" style="background-color:#f8f9fa;">
<form id="formrecherche" action="{$content_obj->GetURL()}" method="get" class="txtcenter">
<label for="recherche" class="w100">Rechercher une facture</label>
<div>
<span class="mts"><input id="recherche" class="tiny-w50" name="recherche" type="search" placeholder="FA 000000" value="{$smarty.get.recherche}"></span>
<span class="mts">
<input type="submit" value="OK" class="btn">
{if $smarty.get.recherche}<input type="reset" value="Reset" class="btn bdr">{/if}
</span>
</div>
</form>
<script>
{literal}
$('#formrecherche input:reset').bind('click', function() {
$('#selectDate').submit();
});
{/literal}
</script>
</div>
</div>
{if isset($smarty.get.recherche) && $smarty.get.recherche != '' && !$userprops.super_utilisateur}
{get_documents_search recherche = $smarty.get.recherche PCF_CODE = $selected_user}
{elseif isset($smarty.get.recherche) && $smarty.get.recherche != '' && $userprops.super_utilisateur}
{get_documents_search recherche = $smarty.get.recherche}
{else}
{capture name="where"}
YEAR(DOC_DATE) = {$time|date_format:'%Y'} AND MONTH(DOC_DATE) = {$time|date_format:'%m'} AND PCF_CODE <> '0' {if $selected_user} AND PCF_CODE = '{$selected_user}'{/if} ORDER BY DOC_DATE DESC{/capture}
{get_documents where = $smarty.capture.where}
{/if}
<table id="tableau" class="tableau display cell-border compact stripe" data-order='[[ 1, "desc" ],[ 0, "desc" ],[ 2, "desc" ],[ 3, "desc" ]]' data-page-length='50'>
<thead>
<tr>
<th class="txtcenter" data-class-name="priority">N<sup>o</sup> de facture</th>
<th class="txtcenter">Date de facture</th>
<th class="txtcenter">Date d'échéance</th>
<th class="txtcenter">Montant brut</th>
<th class="txtcenter">TVA</th>
<th class="txtcenter">Net à payer</th>
<th class="txtcenter" data-searchable='false' data-orderable='false'>Éditer la facture</th>
</tr>
</thead>
<tfoot>
<tr>
<th class="txtcenter" data-class-name="priority">N<sup>o</sup> de facture</th>
<th class="txtcenter">Date de facture</th>
<th class="txtcenter">Date d'échéance</th>
<th class="txtcenter">Montant brut</th>
<th class="txtcenter">TVA</th>
<th class="txtcenter">Net à payer</th>
<th class="txtcenter" data-searchable='false' data-orderable='false'>Éditer la facture</th>
</tr>
</tfoot>
<tbody>
{if $count_doc > 0}
{foreach $documents as $document}
<tr>
<td class="txtcenter u-bold">{$document['DOC_PIECE']}</td>
<td class="txtcenter">{$document['DOC_DATE']|date_format:"%d/%m/%y"}</td>
<td class="txtcenter">{$document['ECH_DATE']|date_format:"%d/%m/%y"}</td>
<td class="txtright tiny-txtcenter">{$document['DOC_BRUT']|number_format:2:',':''}<span class="tiny-hidden"> €</span></td>
<td class="txtright">{$document['DOC_MT_TVA']|number_format:2:',':''}<span class="tiny-hidden"> €</span></td>
<td class="txtright">{$document['DOC_MT_NET']|number_format:2:',':''}<span class="tiny-hidden"> €</span></td>
<td class="txtcenter">
<form method="post" action="facture_axipharm_pdf.php?facture={$document['DOC_PIECE']|replace:' ':''}" target="_blank">
<input type="hidden" name="PCF_CODE" value="{$document['PCF_CODE']}">
<input type="hidden" name="DOC_NUMERO" value="{$document['DOC_NUMERO']}">
<input type="hidden" name="DOC_PIECE" value="{$document['DOC_PIECE']|replace:' ':''}">
<input type="hidden" name="CLE" value="{(($document['DOC_NUMERO']+$document['PCF_CODE'])/3+2)|round}">
{*<input type="hidden" name="CLE" value="{($document['DOC_NUMERO']+$document['PCF_CODE'])}">*}
<button type="submit" name="PDF" class="btn">PDF <i class='icon-arrow--right tiny-hidden'></i></button>
</form>
</td>
</tr>
{/foreach}
{else}
<tr>
<td class="txtcenter" colspan="7">
<h3 class="txtcenter mtl mbl">{if $alerte}{$alerte}{else}IL N'Y A PAS DE FACTURE ENREGISTRÉE POUR CETTE PÉRIODE{/if}</h3>
</td>
</tr>
{/if}
</tbody>
</table>
<div class="txtcenter mtl mbl">
{$op_annee = 0}
<a href="{$content_obj->GetURL()}?StartDateMonth={if {$time|date_format:'%m'} > 1}{{$time|date_format:'%m'}-1}{else}12{$op_annee = -1}{/if}&StartDateYear={{$time|date_format:'%Y'}+$op_annee}{if $userprops.super_utilisateur}&user_select={$smarty.get.user_select}{/if}" class="u-bigger prev-month arrow-date mrs"><i class="icon-arrow--left"></i></a>
<h2 class="inbl u-uppercase">{$time|date_format:'%B %Y'}</h2>
{$op_annee = 0}
<a href="{$content_obj->GetURL()}?StartDateMonth={if {$time|date_format:'%m'} < 12}{{$time|date_format:'%m'}+1}{else}1{$op_annee = 1}{/if}&StartDateYear={{$time|date_format:'%Y'}+$op_annee}{if $userprops.super_utilisateur}&user_select={$smarty.get.user_select}{/if}" class="u-bigger next-month arrow-date mls"><i class="icon-arrow--right"></i></a>
</div>
Voici le code qui créé le PDF quand on clique sur le bouton PDF :
<?php
require_once __DIR__.'/vendor/autoload.php';
use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Exception\Html2PdfException;
use Spipu\Html2Pdf\Exception\ExceptionFormatter;
require_once __DIR__.'/config.php';
$conn = mysqli_connect($config['db_hostname'], $config['db_username'], $config['db_password'], $config['db_name']);
if (!$conn) {
//echo "Erreur : Impossible de se connecter à MySQL." . PHP_EOL;
//echo "Errno de débogage : " . mysqli_connect_errno() . PHP_EOL;
//echo "Erreur de débogage : " . mysqli_connect_error() . PHP_EOL;
exit;
}
$DOC_NUMERO = isset($_POST["DOC_NUMERO"])? $_POST["DOC_NUMERO"] : FALSE;
$PCF_CODE = isset($_POST["PCF_CODE"])? $_POST["PCF_CODE"] : FALSE;
$DOC_PIECE = isset($_POST["DOC_PIECE"])? $_POST["DOC_PIECE"] : FALSE;
if( $DOC_PIECE != $_GET["facture"]){
$DOC_PIECE = FALSE;
}
$CLE = isset($_POST["CLE"])? $_POST["CLE"] : FALSE;
//if( $CLE != ($DOC_NUMERO + $PCF_CODE) ){
if( $CLE != round(($DOC_NUMERO + $PCF_CODE)/ 3 + 2 )){
$CLE = FALSE;
}
$edit_PDF = FALSE;
while(list ($key, $val) = each ($_COOKIE)) {
if(strstr($key, 'CMSSESSID') ) {
$session_key = $key;
break;
}
}
@session_name($session_key);
session_start();
//if ($DOC_NUMERO && is_numeric($DOC_NUMERO) && $PCF_CODE && $DOC_PIECE && $CLE && $_SESSION["OKPDF"]) {
if ($DOC_NUMERO && is_numeric($DOC_NUMERO) && $PCF_CODE && is_numeric($PCF_CODE) && $DOC_PIECE && $CLE && $_SESSION["OKPDF"]) {
//if ($DOC_NUMERO && is_numeric($DOC_NUMERO) && is_numeric($PCF_CODE) && is_numeric($PCF_CODE) && $DOC_PIECE && $CLE && $_SESSION["OKPDF"]) {
//if ($DOC_NUMERO && is_numeric($DOC_NUMERO) && $PCF_CODE && is_numeric($PCF_CODE) && $DOC_PIECE && $CLE) {
$sqlVerif = "SELECT COUNT(IF(DOC_NUMERO = '".$DOC_NUMERO."' AND PCF_CODE = '".$PCF_CODE."', 1, NULL)) as 'nb_doc' FROM ambapharm_documents"; //vérification d'occurence en BD
$resultVerif = mysqli_query($conn, $sqlVerif);
$data = mysqli_fetch_assoc($resultVerif);
//echo '<br/>Résultat pour DOC_NUMERO et PCF_CODE dans la table DOCUMENTS : '.$data['nb_doc'].' élément(s) trouvé(s)<br/>';
if ($data['nb_doc'] > 0) {
$sqlVerif = "SELECT COUNT(IF(DOC_NUMERO = '".$DOC_NUMERO."', 1, NULL)) as 'nb_lig' FROM ambapharm_lignes"; //vérification d'occurence en BD
$resultVerif = mysqli_query($conn, $sqlVerif);
$data = mysqli_fetch_assoc($resultVerif);
//echo '<br/>Résultat pour DOC_NUMERO dans la table LIGNES : '.$data['nb_lig'].' élément(s) trouvé(s)<br/>';
if ($data['nb_lig'] > 0) {
$edit_PDF = TRUE;
} else {
echo "Erreur : Les valeurs de requêtes transmises ne correspondent à 1 facture archivée mais aucune ligne correspondante.";
$type = "error";
$message = "Aucune ligne dans la facture correspondante";
exit;
}
} else {
echo "Erreur : Les valeurs de requêtes transmises ne correspondent à aucune facture archivée.";
$type = "error";
$message = "Aucune facture correspondante";
exit;
}
} else {
echo "Erreur : Les valeurs de requêtes transmises sont incomplètes.";
$type = "error";
$message = "Aucune facture correspondante";
exit;
}
try {
ob_start();
include __DIR__.'/facture_axipharm_contenu.php';
$content = ob_get_clean();
$html2pdf = new Html2Pdf('P', 'A4', 'fr', true, 'UTF-8', array(0, 0, 0, 0));
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->setTestIsImage(false);
$html2pdf->setFallbackImage('./examples/res/off.png');
$html2pdf->writeHTML($content);
$html2pdf->output(str_replace(" ", "", $doc['DOC_PIECE']).'.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
Avez vous besoin du code du masque de facture qui se trouve dans facture_axipharm_contenu.php ?
Modifié par Bus (26 Mar 2025 - 20:30)