Ajout divers champs pour facture/devis

This commit is contained in:
Jean-Christophe Engel 2025-03-23 18:27:47 +01:00
parent 950a6b8b2c
commit aff20099aa
7 changed files with 93 additions and 28 deletions

View File

@ -89,6 +89,7 @@ $form->runIf(f('save') && !$form->hasErrors(),
'reglee' => f('reglee') == 1?1:0,
'archivee' => f('archivee') == 1?1:0,
'moyen_paiement' => f('moyen_paiement'),
'nom_contact' => f('nom_contact'),
'toto' => 0
];
$data['type_facture'] = f('type');
@ -114,6 +115,10 @@ $form->runIf(f('save') && !$form->hasErrors(),
if (! isset($data['contenu'])) {
throw new UserException("Aucune désignation ni aucun prix saisi !!");
}
if (f('type') == FACT) {
$data['numero_commande'] = f('numero_commande');
$data['reference_acheteur'] = f('reference_acheteur');
}
}
elseif ( f('type') == CERFA )
{
@ -276,6 +281,9 @@ else
$doc['date_emission'] = f('date_emission') ?: $f->date_emission;
$doc['date_echeance'] = f('date_echeance')?: $f->date_echeance; // Smarty m'a saoulé pour utiliser form_field|date_fr:---
$doc['nom_contact'] = $f->nom_contact;
$doc['numero_commande'] = $f->numero_commande;
$doc['reference_acheteur'] = $f->reference_acheteur;
/* modif DD -- CERFA -------------------------------------- */
if ( $f->type_facture == CERFA ) {
$doc['total'] = $f->total;

View File

@ -128,12 +128,17 @@ if ($f->type_facture != CERFA)
$receveur =
$txtdest.'<br>'.
'<b>'.$nom_client.'</b><br>'.
(($t = $f->nom_contact)?"Contact : $t<br>":'').
$c->adresse."<br>".
$c->code_postal.' '.$c->ville."<br>".
(($t = $c->siret)?"SIREN/SIRET : " . implode(' ', str_split($t, 3)) . "<br>":'').
(($t = $c->email)?"Email : $t<br>":'').
(($t = $c->telephone)?"Tel : $t<br>":'');
if ($f->type_facture == FACT) {
$receveur .=
(($t = $f->numero_commande)?"Commande N° : $t<br>":'').
(($t = $f->reference_acheteur)?"Référence : $t<br>":'');
}
$total = Utils::money_format($f->total, ',', ' ');
// Devis et facture

View File

@ -10,7 +10,10 @@ CREATE TABLE IF NOT EXISTS plugin_facturation_factures (
archivee INTEGER DEFAULT 0, -- bool
moyen_paiement TEXT NOT NULL,
contenu TEXT NOT NULL,
total INTEGER DEFAULT 0
total INTEGER DEFAULT 0,
nom_contact TEXT,
numero_commande TEXT,
reference_acheteur TEXT
-- FOREIGN KEY(moyen_paiement) REFERENCES compta_moyens_paiement(code)
);

View File

@ -30,7 +30,10 @@ class Facture
'archivee',
'moyen_paiement',
'contenu',
'total'
'total',
'nom_contact',
'numero_commande',
'reference_acheteur'
];
public $types = [
@ -65,7 +68,7 @@ class Facture
if(!is_array($data) && null !== $data){
$datas[$k] = trim($data);
}
if ($datas[$k] === '' && $k != 'numero')
if ($datas[$k] === '' && ! in_array($k, ['numero', 'nom_contact', 'numero_commande', 'reference_acheteur']))
{
throw new UserException("La valeur de $k est vide");
}

View File

@ -1,8 +1,8 @@
name="Facturation"
description="Permet d'éditer des factures, devis et reçus à ses membres ainsi qu'à une base de clients supplémentaire."
description="Permet d'éditer des factures et devis à ses membres ainsi qu'à une base de clients supplémentaire."
author="zou ; adapté par jce"
url="https://git.roflcopter.fr/lesanges/paheko-plugin-facturation"
version="0.12"
version="0.14"
menu=true
restrict_section="accounting"
restrict_level="read"

View File

@ -30,7 +30,7 @@
<dd class="help">
{if $require_number}
Chaque document doit comporter un numéro unique délivré chronologiquement et de façon continue. Il faut que le système adopté par l'association garantisse que deux factures émises la même année ne peuvent pas porter le même numéro.
Chaque document doit comporter un numéro unique délivré chronologiquement et de façon continue. Il faut que le système adopté par l'association garantisse que deux factures émises la même année ne puissent pas porter le même numéro.
{else}
Laisser vide pour qu'un numéro soit automatiquement affecté au format <code>{$number_pattern}</code>.
{/if}
@ -57,7 +57,7 @@
</fieldset>
<fieldset data-types="t0 t1 t2">
<legend>Client</legend>
<legend>Destinataire</legend>
<dl>
<dt><label>Document adressé à :</label></dt>
@ -82,6 +82,15 @@
{/if}
</fieldset>
<fieldset data-types="t0 t1">
<legend>Autres informations</legend>
{input type="text" name="nom_contact" label="Nom du contact" source=$doc}
<div data-types="t1">
{input type="text" name="numero_commande" label="Numéro de commande" source=$doc}
{input type="text" name="reference_acheteur" label="Référence acheteur" source=$doc}
</div>
</fieldset>
<fieldset data-types="t0 t1">
<legend>Contenu</legend>

View File

@ -6,7 +6,7 @@ use Paheko\Entities\Files\File;
$db = DB::getInstance();
$old_version = $plugin->oldVersion();
error_log("upgrade::version = " . $old_version);
error_log("upgrade:: à partir de la version = " . $old_version);
// 0.2.0 - Stock le contenu en json plutôt qu'en serialized
if (version_compare($old_version, '0.2.0', '<'))
@ -74,7 +74,7 @@ if (version_compare($old_version, '0.4.0', '<'))
ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures;
EOT
);
);
}
@ -252,8 +252,10 @@ EOT
);
}
// version 0.15 (?) Ajout champ note à la table client
if (version_compare($old_version, '0.15', '<'))
// version 0.14
// Ajout champ note à la table clients
// Ajout divers champs à la table factures
if (version_compare($old_version, '0.14', '<'))
{
$db->exec(<<<EOT
CREATE TABLE IF NOT EXISTS plugin_facturation_clients_tmp
@ -269,7 +271,7 @@ if (version_compare($old_version, '0.15', '<'))
email TEXT,
note TEXT
);
EOT
EOT
);
// copier les clients dans la table temporaire
$sql = 'SELECT * FROM plugin_facturation_clients';
@ -281,6 +283,41 @@ if (version_compare($old_version, '0.15', '<'))
$db->exec(<<<EOT
DROP TABLE plugin_facturation_clients;
ALTER TABLE plugin_facturation_clients_tmp RENAME TO plugin_facturation_clients;
EOT
EOT
);
$db->exec(<<<EOT
CREATE TABLE IF NOT EXISTS plugin_facturation_factures_tmp(
id INTEGER PRIMARY KEY,
type_facture INTEGER NOT NULL DEFAULT 0,
numero TEXT NOT NULL UNIQUE,
receveur_membre INTEGER NOT NULL, -- bool
receveur_id INTEGER NOT NULL,
date_emission TEXT NOT NULL, -- CHECK (date(date_emission) IS NOT NULL AND date(date_emission) = date_emission),
date_echeance TEXT NOT NULL, -- CHECK (date(date_echeance) IS NOT NULL AND date(date_echeance) = date_echeance),
reglee INTEGER DEFAULT 0, -- bool
archivee INTEGER DEFAULT 0, -- bool
moyen_paiement TEXT NOT NULL,
contenu TEXT NOT NULL,
total INTEGER DEFAULT 0,
nom_contact TEXT,
numero_commande TEXT,
reference_acheteur TEXT
);
EOT
);
// copier les factures dans la table temporaire
$sql = 'SELECT * FROM plugin_facturation_factures';
foreach ($db->iterate($sql) as $facture)
{
$db->insert('plugin_facturation_factures_tmp', $facture);
}
// remplacer l'ancienne table par la nouvelle
$db->exec(<<<EOT
DROP TABLE plugin_facturation_factures;
ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures;
EOT
);
}