Thanasoft-H2F/gestion/templates/content/apercustoutesfactures.php

215 lines
14 KiB
PHP

<div class="d-flex flex-column w-100 p-4">
<?php $factures = []; $showRecapButton=false;?>
<div class="d-flex justify-content-between">
<form method="get" class="d-flex flex-row align-items-center">
<select name="cli" id="clientselector">
<option value='0' <?php if( $_GET['cli'] == 0) echo 'selected' ?>>COGF</option>
<?php
foreach ($_['clients'] as $key => $client) {
?>
<option <?php if($_GET['cli'] == $client->id) echo 'selected' ?> value='<?php echo $client->id ?>'><?php echo strtoupper(html_entity_decode($client->prenom.' '.$client->nom)); ?></option>
<?php
}
?>
</select>&nbsp;&nbsp;
<select name="annee" id="yearselector">
<option value="-1" <?php if ((int)$_GET['annee'] == -1) echo 'selected' ?>>Toutes les années</option>
<?php
$currentYear = date('Y');
for ($year = $currentYear; $year >= $currentYear - 10; $year--) {
echo '<option value="' . $year . '"';
if ((int)$_GET['annee'] == $year) echo ' selected';
echo '>' . $year . '</option>';
}
?>
</select>&nbsp;&nbsp;
<select name="mois" id="monthselector">
<option value="0" <?php if((int) $_GET['mois'] == 0) echo 'selected' ?>>Tous les mois</option>
<option value="1" <?php if((int) $_GET['mois'] == 1) echo 'selected' ?>>Janvier</option>
<option value="2" <?php if((int) $_GET['mois'] == 2) echo 'selected' ?>>Fevrier</option>
<option value="3" <?php if((int) $_GET['mois'] == 3) echo 'selected' ?>>Mars</option>
<option value="4" <?php if((int) $_GET['mois'] == 4) echo 'selected' ?>>Avril</option>
<option value="5" <?php if((int) $_GET['mois'] == 5) echo 'selected' ?>>Mai</option>
<option value="6" <?php if((int) $_GET['mois'] == 6) echo 'selected' ?>>Juin</option>
<option value="7" <?php if((int) $_GET['mois'] == 7) echo 'selected' ?>>Juillet</option>
<option value="8" <?php if((int) $_GET['mois'] == 8) echo 'selected' ?>>Août</option>
<option value="9" <?php if((int) $_GET['mois'] == 9) echo 'selected' ?>>Septembre</option>
<option value="10" <?php if((int) $_GET['mois'] == 10) echo 'selected' ?>>Octobre</option>
<option value="11" <?php if((int) $_GET['mois'] == 11) echo 'selected' ?>>Novembre</option>
<option value="12" <?php if((int) $_GET['mois'] == 12) echo 'selected' ?>>Decembre</option>
</select>&nbsp;&nbsp;
<input type="submit" value="Filtrer"/>
</form>
<div class="d-flex flex-row">
<?php
if($_SERVER['REQUEST_METHOD'] == 'GET') {
if(intval($_GET['mois'])!=0 && intval($_GET['annee'])!=0) $showRecapButton = true;
$factures = array_filter($_['factures'], function($f) {
$datesplit = explode("-", $f->date_paiement);
$year = (int) $datesplit[0];
$month = (int) $datesplit[1];
$checkClient = false;
if(intval($_GET['cli'])==0) {
$checkClient = (strcmp(strtolower($f->entreprise), 'cogf')==0);
} else {
$checkClient = ($f->id_cli==intval($_GET['cli']));
}
$checkYear = ((int) ($_GET['annee']) == -1)?(true):($year==((int) $_GET['annee']));
$checkMounth = (((int) $_GET['mois']) == 0)? (true): ($month==((int) $_GET['mois']));
return $checkClient && $checkYear && $checkMounth;
});
if(sizeof($factures)>0) {
?>
<?php if($showRecapButton) {?><button class="btn btn-secondary" type="button" id="documentrecap">Generer le document recapitulatif</button><?php }?>
<button class="btn btn-secondary ml-2" type="button" id="exportMultipleFactureToPdf"><?php p($l->t('Save in Nextcloud'));?></button>
<?php
}
}
?>
</div>
</div>
<hr>
<div class="canvas_div_pdf">
<?php
if($_SERVER['REQUEST_METHOD'] == 'GET') {
if(sizeof($factures)==0) echo "Aucune facture trouvée.";
};
foreach ($factures as $key => $facture) {
?>
<div class="bootstrap-iso d-flex flex-column justify-content-between">
<div class="d-flex flex-column w-100">
<h2 class="mt-3 mb-3 text-center"><?php p($l->t('Invoice #'));?>
<div class="factureclass" style="display:inline"><?php echo $facture->num;?></div>
</h2>
<hr/>
<div class="row">
<div class="col-5 h-100 m-0" style="min-height:250px;">
<?php $res = json_decode($_['configuration'])[0]; ?>
<h5 class="p-3 m-0 text-dark text-center border border-2 border-dark"><?php p($l->t('FROM'));?> <?php echo $res->entreprise; ?></h5>
<p class="p-3 m-0 h-auto text-center text-dark text-center border border-top-0 border-2 border-dark">
<?php echo $res->prenom . " " . $res->nom; ?><br />
<?php echo $res->adresse; ?><br />
<?php echo $res->mail; ?><br />
<?php echo $res->telephone; ?><br/>
<span id="nothing"></span><br />
</p>
</div>
<div class="col-2 h-100 m-0" style="min-height:250px;">
<?php
if(isset($_['logo']) && $_['logo'] !== "nothing"){
echo "<center><a><img alt='".$l->t('Company logo')."' class=\"img-fluid\" src=\"data:image/png;base64, ".$_['logo']."\"/></a></center>";
}else{
echo "<span style='font-size:12px' id='Company-logo' data-html2canvas-ignore><b><center>".$l->t('You can add your company logo here.')."</center></b><br/><i>".$l->t('To add a logo, drop the logo.png file in ".gestion" folder at the root of your Nextcloud Files app. Remember to set "Show hidden files".')."</i><br/><br/><center>".$l->t('This message will not appear on generated PDF.')."</center></span>";
}
?>
</div>
<div class="col-5 h-100 m-0" style="min-height:250px;">
<h5 class="p-3 m-0 text-dark text-center border border-2 border-dark"><?php p($l->t('TO'));?> <span id="entreprise"><?php echo $facture->entreprise ?></span></h6>
<p class="p-3 m-0 h-auto text-center text-dark text-center border border-top-0 border-2 border-dark">
<span id="nomprenom" data-id="0" data-table="devis" data-column="id_client"><?php echo $facture->prenom.' '.$facture->nom ?></span><br />
<span id="adresse"><?php echo $facture->adresse_cli ?></span><br />
<span id="mail"><?php echo $facture->mail_cli ?></span><br />
<span id="telephone"><?php echo $facture->telephone_cli ?></span><br />
<span id="legal_one"><?php echo $facture->legalone_cli ?></span><br />
<span id="dateContext" style="display: none"><?php echo $facture->date ?></span>
<span id="nomcli" style="display: none"><?php echo $facture->prenom.' '.$facture->nom ?></span>
<span id="idcli" style="display: none"><?php echo $facture->id_cli ?></span>
<span id="etp" style="display: none"><?php echo $facture->entreprise ?></span>
<span class="pdf" style="display: none"><?php echo $facture->entreprise."_".$facture->id."_v".$facture->version?></span>
</p>
</div>
</div>
<div class="row">
<div class="col col-md">
<hr/>
<div class="col col-xl text-center">
<span>Date de facture : <b><?php echo (new DateTime($facture->date_paiement))->format('d-m-Y');?></b>, </span><span><?php p($l->t('Date of service'));?> : <b><?php echo (new DateTime($facture->date))->format('d-m-Y');?></b></span><br/>
<span id="devisid" data-id=<?php echo $facture->id_devis;?>>Défunt associé : <b><?php echo $facture->nom_defunt;?></b>, </span><span><?php p($l->t('Means of payment'));?> : <b><?php echo $facture->type_paiement;?></b></span><br/>
<span>Lieu : <b><?php echo $facture->lieu;?> (<?php echo $facture->adresse_soin;?>)</b>
</div>
</div>
</div>
<div class="row">
<div class="col col-md">
<hr />
<div class="col col-xl mb-3 text-center" style="display:inline" ><?php echo ($facture->dcomment == "" ) ? "-" : $facture->dcomment ; ?></div>
<hr />
</div>
</div>
<div class="table-responsive">
<table id="produits" data-type="facture" class="table table-striped">
<thead>
<tr>
<th><?php p($l->t('Reference'));?></th>
<th><?php p($l->t('Designation'));?></th>
<th><?php p($l->t('Comment'));?></th>
<th><?php p($l->t('Quantity'));?></th>
<th><?php p($l->t('Unit price without VAT'));?></th>
<th><?php p($l->t('Total without VAT'));?></th>
</tr>
</thead>
<tbody>
<?php foreach ($facture->dproduits as $key => $produit) { ?>
<tr>
<td><?php echo $produit->reference ?></td>
<td><?php echo $produit->description ?></td>
<td><?php echo $produit->comment ?></td>
<td><?php echo $produit->quantite ?></td>
<td>&euro;<?php echo number_format($produit->prix_unitaire, 2) ?></td>
<td>&euro;<?php echo number_format($produit->prix_unitaire*$produit->quantite, 2) ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="mt-0 table-responsive">
<table id="totaldevis" class="table table-striped table-xl">
<thead class="bg-dark text-white">
<tr>
<th class="text-center"><?php p($l->t('Total without VAT'));?></th>
<th class="text-center"><?php p($l->t('VAT Rate'));?></th>
<th class="text-center"><?php p($l->t('Total VAT'));?></th>
<th class="text-center"><?php p($l->t('Total Price'));?></th>
</tr>
</thead>
<tbody>
<?php
$totalhtc = 0;
$tva = json_decode($_['configuration'])[0]->tva_default;
$totalttc = 0;
$totalprice = 0;
foreach ($facture->dproduits as $key => $produit) {
$totalhtc = $totalhtc + ($produit->quantite*$produit->prix_unitaire);
}
$totalttc = ($totalhtc * $tva)/100;
$totalprice = $totalhtc + $totalttc;
?>
<tr>
<td>&euro;<?php echo number_format($totalhtc, 2) ?></td>
<td><?php echo $tva ?> &percnt;</td>
<td>&euro;<?php echo number_format($totalttc, 2) ?></td>
<td>&euro;<?php echo number_format($totalprice, 2) ?></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="d-flex flex-column w-100">
<div class="col m-0 pb-0 alert alert-info text-center">
<p><span id="mentions_default"><?php p($l->t('Please set in global configuration'));?></span></p>
</div>
<hr />
<div class="col m-0 pb-0 alert alert-info text-center">
<p><?php echo $res->entreprise; ?><br /><?php echo $res->adresse; ?><br /><?php echo $res->legal_one; ?><br/><?php echo $res->legal_two; ?></p>
</div>
</div>
</div>
<hr data-html2canvas-ignore>
<hr data-html2canvas-ignore>
<hr data-html2canvas-ignore>
<?php
}
?>
</div>
</div>