Skip to content

Commit

Permalink
Pagination factures (afup#1624)
Browse files Browse the repository at this point in the history
  • Loading branch information
stakovicz authored Feb 10, 2025
1 parent 363c834 commit 7c77159
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
9 changes: 7 additions & 2 deletions htdocs/pages/administration/compta_facture.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

// Impossible to access the file itself
use Afup\Site\Comptabilite\Comptabilite;
use Afup\Site\Comptabilite\Facture;
use Afup\Site\Utils\Logs;
use Afup\Site\Utils\Pays;
Expand All @@ -26,15 +27,19 @@
//$sens_valides = array('asc', 'desc');
$smarty->assign('action', $action);


$compta = new Comptabilite($bdd);
$comptaFact = new Facture($bdd);

if ($action == 'lister') {
$ecritures = $comptaFact->obtenirFacture();
$periodes = $compta->obtenirListPeriode();
$id_periode = isset($_GET['id_periode']) && $_GET['id_periode'] ? $_GET['id_periode'] : end($periodes)['id'];
$ecritures = $comptaFact->obtenirFacture($id_periode);
foreach ($ecritures as &$e) {
$e['link'] = urlencode(Utils::cryptFromText($e['id']));
}
$smarty->assign('id_periode', $id_periode);
$smarty->assign('ecritures', $ecritures);
$smarty->assign('listPeriode', $periodes);
} elseif ($action == 'telecharger_facture') {
$comptaFact->genererFacture($_GET['ref']);
} elseif ($action == 'envoyer_facture') {
Expand Down
18 changes: 18 additions & 0 deletions htdocs/templates/administration/compta_facture.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ <h2>Factures</h2>
<p>Il faut obligatoirement passer par la saisie d'un devis.</p>
</div>

<div class="ui green segment">
<form method="GET" name="forum">
<input type="hidden" name="page" value="compta_facture" />
<div class="ui form">
<div class="inline fields">
<div class="field">
<label>Année comptable</label>
<select name="id_periode" onchange="this.form.submit(); return false;">
{foreach from=$listPeriode item=periode}
<option value="{$periode.id}"{if $id_periode == $periode.id} selected{/if}>{$periode.date_debut} - {$periode.date_fin}</option>
{/foreach}
</select>
</div>
</div>
</div>
</form>
</div>

<table class="ui table striped compact celled afup-tab-filterable">
<thead>
<tr>
Expand Down
8 changes: 7 additions & 1 deletion sources/Afup/Comptabilite/Facture.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function obtenirDevisDetails($id)
return $this->_bdd->obtenirTous($requete);
}

public function obtenirFacture()
public function obtenirFacture($idPeriode = null)
{
$requete = 'SELECT ';
$requete .= ' acf.*, sum(quantite * pu) prix ';
Expand All @@ -85,6 +85,12 @@ public function obtenirFacture()
$requete .= ' acfd.idafup_compta_facture = acf.id ';
$requete .= 'WHERE ';
$requete .= ' numero_facture != "" ';

if (null !== $idPeriode) {
$requete .= sprintf(' AND acf.date_facture >= (select date_debut from compta_periode where id = %s)', $this->_bdd->echapper($idPeriode));
$requete .= sprintf(' AND acf.date_facture <= (select date_fin from compta_periode where id = %s)', $this->_bdd->echapper($idPeriode));
}

$requete .= 'GROUP BY ';
$requete .= ' acf.id, date_devis, numero_devis, date_facture, numero_facture, societe, service, adresse, code_postal, ville, id_pays, email, observation, ref_clt1, ref_clt2, ref_clt3, nom, prenom, tel, etat_paiement, date_paiement, devise_facture ';
$requete .= 'ORDER BY ';
Expand Down
2 changes: 1 addition & 1 deletion sources/Afup/Forum/AppelConferencier.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public function modifierJoindinSession($id, $joindin)
$value = $this->_bdd->echapper($joindin);
}
$requete = 'UPDATE afup_sessions SET ';
$requete .= ' joindin = ' . $this->_bdd->echapper($joindin);
$requete .= ' joindin = ' . $value;
$requete .= ' WHERE session_id = ' . (int) $id;

return $this->_bdd->executer($requete);
Expand Down
4 changes: 2 additions & 2 deletions tests/behat/features/Admin/Tresorerie/DevisFactures.feature
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Feature: Administration - Trésorerie - Devis/Facture
@vat
Scenario: Test du PDF de facture avant 2024
Given I am logged in as admin and on the Administration
When I go to "/pages/administration/index.php?page=compta_facture"
When I go to "/pages/administration/index.php?page=compta_facture&id_periode=14"
Then the ".content h2" element should contain "Factures"
And I should see "Il n'est pas possible de créer directement une facture"
When I follow the button of tooltip "Télécharger la facture 2023-01"
Expand All @@ -112,7 +112,7 @@ Feature: Administration - Trésorerie - Devis/Facture
@vat
Scenario: Test du PDF de facture après 2024
Given I am logged in as admin and on the Administration
When I go to "/pages/administration/index.php?page=compta_facture"
When I go to "/pages/administration/index.php?page=compta_facture&id_periode=15"
Then the ".content h2" element should contain "Factures"
And I should see "Il n'est pas possible de créer directement une facture"
When I follow the button of tooltip "Télécharger la facture 2024-02"
Expand Down

0 comments on commit 7c77159

Please sign in to comment.