Upload plugin files but mPDF folder

This commit is contained in:
ramoloss 2019-11-02 16:53:27 +00:00
parent ba5c48b8e8
commit 9ac4bbce8a
36 changed files with 2864 additions and 0 deletions

12
www/admin/_inc.php Normal file
View file

@ -0,0 +1,12 @@
<?php
namespace Garradin;
use Garradin\Plugin\Facturation\Config;
use Garradin\Plugin\Facturation\Facture;
use Garradin\Plugin\Facturation\Client;
$cfg = Config::getInstance();
$client = new Client;
$facture = new Facture;

22
www/admin/client.php Normal file
View file

@ -0,0 +1,22 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess('compta', Membres::DROIT_ACCES);
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
$client = $client->get($id);
if (!$client)
{
throw new UserException("Ce client n'existe pas.");
}
$tpl->assign('docs', $facture->listUserDoc(0, $id));
$tpl->assign('client', $client);
$tpl->display(PLUGIN_ROOT . '/templates/client.tpl');

View file

@ -0,0 +1,54 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess('compta', Membres::DROIT_ECRITURE);
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
$c = $client->get($id);
if (!$c)
{
throw new UserException("Ce client n'existe pas.");
}
if(f('save'))
{
$form->check('edit_client', [
'nom' => 'required|string',
'adresse' => 'required|string',
'code_postal' => 'required|string',
'ville' => 'required|string',
'telephone' => 'string',
'email' => 'email'
]);
if (!$form->hasErrors())
{
try
{
$r = $client->edit($id,[
'nom' => f('nom'),
'adresse' => f('adresse'),
'code_postal' => f('code_postal'),
'ville' => f('ville'),
'telephone' => f('telephone'),
'email' => f('email')
]);
$r ? Utils::redirect(PLUGIN_URL . 'client.php?id='.(int)$id):'';
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
}
$tpl->assign('client', $c);
$tpl->display(PLUGIN_ROOT . '/templates/client_modifier.tpl');

View file

@ -0,0 +1,40 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess('compta', Membres::DROIT_ADMIN);
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
$c = $client->get($id);
if (!$client)
{
throw new UserException("Ce client n'existe pas.");
}
if (f('delete'))
{
$form->check('delete_client_'.$c->id);
if (!$form->hasErrors())
{
try {
var_dump($client->delete($c->id));
Utils::redirect(PLUGIN_URL . 'clients.php');
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
}
$tpl->assign('deletable', $client->isDeletable($id));
$tpl->assign('client', $client->get($id));
$tpl->display(PLUGIN_ROOT . '/templates/client_supprimer.tpl');

57
www/admin/clients.php Normal file
View file

@ -0,0 +1,57 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess('compta', Membres::DROIT_ACCES);
if(f('add'))
{
$form->check('add_client', [
'nom' => 'required|string',
'adresse' => 'required|string',
'code_postal' => 'required|string',
'ville' => 'required|string',
'telephone' => 'string',
'email' => 'email'
]);
if (!$form->hasErrors())
{
try
{
$id = $client->add([
'nom' => f('nom'),
'adresse' => f('adresse'),
'code_postal' => f('code_postal'),
'ville' => f('ville'),
'telephone' => f('telephone'),
'email' => f('email')
]);
$id ? Utils::redirect(PLUGIN_URL . 'client.php?id='.(int)$id):'';
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
}
// var_dump($client->listAll());
$tpl->assign('clients', $client->listAll());
$tpl->assign('champs',
[
'id' => 'id',
'nom' => 'Nom',
'adresse' => 'Adresse',
'code_postal' => 'Code postal',
'ville' => 'Ville',
'telephone' => 'Numéro de téléphone',
'email' => 'Adresse mail'
]
);
$tpl->display(PLUGIN_ROOT . '/templates/clients.tpl');

34
www/admin/config.php Normal file
View file

@ -0,0 +1,34 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess('compta', Membres::DROIT_ADMIN);
if (f('save') && $form->check('facturation_config'))
{
try {
$cfg->set('siret_asso', f('siret_asso'));
$cfg->set('validate_cp', f('validate_cp'));
$cfg->set('unique_client_name', f('unique_name'));
$cfg->set('footer', f('footer'));
$cfg->save();
Utils::redirect(PLUGIN_URL . 'config.php?ok');
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
$tpl->assign('ok', qg('ok') !== null);
$tpl->assign('siret_asso', $cfg->get('siret_asso') ?: '');
$tpl->assign('footer', $cfg->get('footer') ?: '');
$tpl->assign('validate_cp', $cfg->get('validate_cp') ? 'checked':'');
$tpl->assign('unique_name', $cfg->get('unique_client_name') ? 'checked':'');
$tpl->display(PLUGIN_ROOT . '/templates/config.tpl');

57
www/admin/facture.php Normal file
View file

@ -0,0 +1,57 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess('compta', Membres::DROIT_ACCES);
use Garradin\Membres;
$membres = new Membres;
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
$f = $facture->get($id);
if (!$f)
{
throw new UserException("Ce document n'existe pas.");
}
$cats = new Compta\Categories;
$tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
$tpl->assign('moyen_paiement', $cats->getMoyenPaiement($f->moyen_paiement));
try
{
if ($f->receveur_membre)
{
$c = $membres->get($f->receveur_id);
foreach(['ville','code_postal','adresse'] as $v)
{
if($c->$v == '')
{
$c->$v = '[A RENSEIGNER DANS LA FICHE MEMBRE]';
}
}
}
else
{
$c = $client->get($f->receveur_id);
}
$tpl->assign('facture', $f);
$tpl->assign('client', $c);
}
catch(UserException $e)
{
$form->addError("Pas de document correspondant à cet id trouvée.");
}
$tpl->assign('id', $id);
$tpl->assign('footer', $cfg->get('footer')?:'');
$tpl->assign('siret_asso', $cfg->get('siret_asso')?:'');
$tpl->display(PLUGIN_ROOT . '/templates/facture.tpl');

View file

@ -0,0 +1,122 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess('compta', Membres::DROIT_ECRITURE);
use Garradin\DB;
$cats = new Compta\Categories;
$tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
if (f('add'))
{
$form->check('ajout_facture', [
'type' => 'required|in:facture,devis',
'numero_facture' => 'required|string',
'date_emission' => 'required|date',
'date_echeance' => 'required|date',
// 'reglee' => '',
// 'archivee' => '',
'base_receveur' => 'required|in:membre,client',
// 'client' => '',
// 'membre' => '',
'moyen_paiement' => 'required|in:' . implode(',', array_keys($cats->listMoyensPaiement())),
'designation' => 'array|required',
'prix' => 'array|required'
]);
if (!$form->hasErrors())
{
try
{
if ( count(f('designation')) !== count(f('prix')) )
{
throw new UserException('Nombre de désignations et de prix reçus différent.');
}
$truc = [
'numero' =>f('numero_facture'),
'date_emission' => f('date_emission'),
'date_echeance' => f('date_echeance'),
'reglee' => f('reglee') == 'on'?1:0,
'archivee' => f('archivee') == 'on'?1:0,
'moyen_paiement' => f('moyen_paiement'),
'toto' => 0
];
if (f('type') == 'facture')
{
$truc['type_facture'] = 1;
}
elseif (f('type') == 'devis')
{
$truc['type_facture'] = 0;
}
foreach(f('designation') as $k=>$value)
{
$truc['contenu'][$k]['designation'] = $value;
$truc['contenu'][$k]['prix'] = f('prix')[$k];
$truc['toto'] += f('prix')[$k];
}
$truc['total'] = $truc['toto'];
unset($truc['toto']);
if (f('base_receveur') == 'client')
{
$truc['receveur_membre'] = 0;
$truc['receveur_id'] = f('client');
}
elseif (f('base_receveur') == 'membre')
{
$truc['receveur_membre'] = 1;
$truc['receveur_id'] = f('membre');
}
$id = $facture->add($truc);
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
}
catch(UserException $e)
{
$form->addError($e->getMessage());
}
}
}
$tpl->assign('type', f('type') ?: '');
$tpl->assign('numero_facture', f('numero_facture') ?: '');
$tpl->assign('date_emission', f('date_emission') ?: '');
$tpl->assign('date_echeance', f('date_echeance') ?: '');
$tpl->assign('reglee', f('reglee') ?: 'off');
$tpl->assign('base_receveur', f('base_receveur') ?: '');
$tpl->assign('client_id', f('client') ?: -1);
$tpl->assign('membre_id', f('membre') ?: -1);
$designations = [];
$prix = [];
if (($d = f('designation')) && ($p = f('prix')))
{
foreach($d as $k=>$v)
{
if ($v == '' && $p[$k] == 0)
{
continue;
}
$designations[] = $v;
$prix[] = $p[$k];
}
}
$tpl->assign('designations', $designations);
$tpl->assign('prix', $prix);
$tpl->assign('membres', (array)DB::getInstance()->get('SELECT id, nom FROM membres WHERE id_categorie != -2 NOT IN (SELECT id FROM membres_categories WHERE cacher = 1);'));
$tpl->assign('clients', $client->listAll());
$tpl->display(PLUGIN_ROOT . '/templates/facture_ajouter.tpl');

View file

@ -0,0 +1,145 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess('compta', Membres::DROIT_ECRITURE);
use Garradin\DB;
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
$f = $facture->get($id);
if (!$f)
{
throw new UserException("Ce document n'existe pas.");
}
$cats = new Compta\Categories;
$tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: $f->moyen_paiement);
if(f('save'))
{
$form->check('modifier_facture', [
'type' => 'required|in:facture,devis',
'numero_facture' => 'required|string',
'date_emission' => 'required|date',
'date_echeance' => 'required|date',
// 'reglee' => '',
// 'archivee' => '',
'base_receveur' => 'required|in:membre,client',
// 'client' => '',
// 'membre' => '',
'moyen_paiement' => 'required|in:' . implode(',', array_keys($cats->listMoyensPaiement())),
'designation' => 'array|required',
'prix' => 'array|required'
]);
if (!$form->hasErrors())
{
try
{
if ( count(f('designation')) !== count(f('prix')) )
{
throw new UserException('Nombre de désignations et de prix reçus différent.');
}
$truc = [
'numero' => f('numero_facture'),
'date_emission' => f('date_emission'),
'date_echeance' => f('date_echeance'),
'reglee' => f('reglee') == 'on'?1:0,
'archivee' => f('archivee') == 'on'?1:0,
'moyen_paiement' => f('moyen_paiement'),
'toto' => 0
];
if (f('type') == 'facture')
{
$truc['type_facture'] = 1;
}
elseif (f('type') == 'devis')
{
$truc['type_facture'] = 0;
}
foreach(f('designation') as $k=>$value)
{
$truc['contenu'][$k]['designation'] = $value;
$truc['contenu'][$k]['prix'] = f('prix')[$k];
$truc['toto'] += f('prix')[$k];
}
$truc['total'] = $truc['toto'];
unset($truc['toto']);
if (f('base_receveur') == 'client')
{
$truc['receveur_membre'] = 0;
$truc['receveur_id'] = f('client');
}
elseif (f('base_receveur') == 'membre')
{
$truc['receveur_membre'] = 1;
$truc['receveur_id'] = f('membre');
}
$r = $facture->edit($id, $truc);
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
}
catch(UserException $e)
{
$form->addError($e->getMessage());
}
}
}
$tpl->assign('type', f('type') ?: ($f->type_facture ?'facture':'devis'));
$tpl->assign('numero_facture', f('numero_facture') ?: $f->numero);
$tpl->assign('date_emission', strtotime(f('date_emission')) ?: $f->date_emission);
$tpl->assign('date_echeance', strtotime(f('date_echeance')) ?: $f->date_echeance);
$tpl->assign('reglee', f('reglee') ?: ($f->reglee?'on':'off'));
$tpl->assign('base_receveur', f('base_receveur') ?: ($f->receveur_membre?'membre':'client'));
$tpl->assign('client_id', f('client') ?: $f->receveur_id);
$tpl->assign('membre_id', f('membre') ?: $f->receveur_id);
if (($d = f('designation')) && ($p = f('prix')))
{
foreach($d as $k=>$v)
{
if ($v == '' && $p[$k] == 0)
{
continue;
}
$designations[] = $v;
$prix[] = $p[$k];
}
}
else
{
foreach($f->contenu as $k=>$v)
{
if ($v['designation'] == '' && $v['prix'] == 0)
{
continue;
}
$designations[] = $v['designation'];
$prix[] = $v['prix'];
}
}
$tpl->assign('designations', $designations);
$tpl->assign('prix', $prix);
$tpl->assign('membres', (array)DB::getInstance()->get('SELECT id, nom FROM membres WHERE id_categorie != -2 NOT IN (SELECT id FROM membres_categories WHERE cacher = 1);'));
$tpl->assign('clients', $client->listAll());
$tpl->assign('facture', $f);
$tpl->display(PLUGIN_ROOT . '/templates/facture_modifier.tpl');

233
www/admin/facture_pdf.php Normal file
View file

@ -0,0 +1,233 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
require_once PLUGIN_ROOT . '/lib/MPDF/vendor/autoload.php';
$session->requireAccess('compta', Membres::DROIT_ACCES);
$membres = new Membres;
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
$f = $facture->get($id);
if (!$f)
{
throw new UserException("Ce document n'existe pas.");
}
$cats = new Compta\Categories;
$moyen_paiement = $cats->getMoyenPaiement($f->moyen_paiement);
try
{
if ($f->receveur_membre)
{
$c = $membres->get($f->receveur_id);
foreach(['ville','code_postal','adresse'] as $v)
{
if($c->$v == '')
{
$c->$v = '[A RENSEIGNER DANS LA FICHE MEMBRE]';
}
}
}
else
{
$c = $client->get($f->receveur_id);
}
}
catch(UserException $e)
{
$form->addError("Pas de document correspondant à cet id trouvée.");
}
// Création du PDF
$pdf = new \Mpdf\Mpdf([
'default_font_size' => 10,
'default_font' => 'dejavusans',
// 'tempDir' => PLUGINS_ROOT . '/mpdf-tmp/'
]);
$pdf->SetAuthor($config->get('nom_asso'));
ob_start();
$doc = ($f->type_facture?'Facture':'Devis').' n°'.$f->numero;
$emission = date('d/m/Y' ,$f->date_emission);
$pdf->SetTitle($doc.' - '.$emission);
$asso =
// 'Émis par :<br><br>'.
'<b>'.$config->get('nom_asso')."</b><br>".
str_replace("\n", '<br>', $config->get('adresse_asso'))."<br>".
(($t = $cfg->get('siret_asso'))?"SIRET : $t<br>":'').
(($t = $config->get('email_asso'))?"Email : $t<br>":'').
(($t = $config->get('site_asso'))?"Site web : $t<br>":'');
$receveur =
'Adressé à :<br><br>'.
'<b>'.$c->nom.'</b><br>'.
$c->adresse."<br>".
$c->code_postal.' '.$c->ville."<br>".
(($t = $c->email)?"Email : $t<br>":'').
(($t = $c->telephone)?"Tel : $t<br>":'');
$total = number_format($f->total, 2, ',', ' ');
$echeance = date('d/m/Y' ,$f->date_echeance);
$echeance = ($f->type_facture?'Échéance de paiement':'Échéance du devis')." : ".$echeance;
$reglee = !$f->reglee?'Cette facture est en attente de règlement.':'Cette facture a été reglée.';
$footer = str_replace("\n", '<br>', $cfg->get('footer'));
echo <<<EOF
<!-- STYLE -->
<style>
.titre {
text-align: center;
font-size: 8pt;
position: absolute;
top: 6mm;
width: 180mm;
}
.h2 {
margin: 25 20 0 20;
}
.h2 span {
font-weight: bold;
font-size: 15pt;
}
hr {
margin: 5 0 20 0;
}
.adressage {
font-size: 11pt;
}
.adressage td {
width: 95mm;
vertical-align: top;
}
.contenu td, .contenu th {
vertical-align: top;
padding: 8 10;
margin : 0;
border-collapse: collapse;
}
.contenu tr th, .contenu tr td {
text-align: right;
width: 16%;
}
.contenu tr td:nth-child(1), .contenu tr th:nth-child(1) {
text-align: left;
width: 84%;
}
.contenu thead tr, .contenu tfoot tr {
background-color: #CCE;
border: 10px solid black;
}
.contenu tbody tr:nth-child(even) {
background-color: #DDF;
}
footer {
position: absolute;
bottom: 0;
margin: 14mm 0;
}
</style>
<!-- CONTENU -->
<p class="titre">
$doc - Émis le $emission
</p>
<table class="adressage">
<tr>
<td>$asso</td>
<td>$receveur</td>
</tr>
</table>
<br>
<div class="h2">
<span>Contenu</span> - $doc
</div>
<hr>
<table class="contenu">
<thead>
<tr>
<th>
Désignations
</th>
<th>
Prix
</th>
</tr>
</thead>
<tbody>
EOF;
$i = 1;
foreach($f->contenu as $k=>$v)
{
echo '<tr><td>';
echo str_replace("\n", '<br>', $v['designation']);
echo '</td><td>';
echo number_format($v['prix'], 2, ',', ' ').'€';
echo '</td></tr>';
$i++;
}
echo <<<EOF
</tbody>
<tfoot>
<tr>
<td><h3>Total</h3>Net à payer</td>
<td><b>$total </b> (HT)</td>
</tr>
</tfoot>
</table>
<footer>
<div class="h2"><span>Détails</span></div>
<hr>
$echeance <br>
$reglee
Moyen de paiement : $moyen_paiement
<p>
$footer
</p>
</footer>
EOF;
$html = ob_get_clean();
$pdf->WriteHTML($html);
if(qg('d') !== null)
{
$t = \Mpdf\Output\Destination::DOWNLOAD;
}
else
{
$t = \Mpdf\Output\Destination::INLINE;
}
$pdf->Output(
($f->type_facture?'Facture':'Devis').' '.$f->numero
. ' du '.date('d-m-Y' ,$f->date_emission)
.'.pdf', $t);

23
www/admin/index.php Normal file
View file

@ -0,0 +1,23 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess('compta', Membres::DROIT_ACCES);
$membres = new Membres;
$cats = new Compta\Categories;
$tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
foreach($factures = $facture->listAll() as $k=>$f)
{
$factures[$k]->receveur = $f->receveur_membre? $membres->get($f->receveur_id) : $client->get($f->receveur_id);
$factures[$k]->moyen_paiement = $cats->getMoyenPaiement($f->moyen_paiement);
}
$tpl->assign('factures', $factures);
$tpl->assign('clients', $client->listAll());
$tpl->display(PLUGIN_ROOT . '/templates/index.tpl');