diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php
index e02e3935abd..d6216622daf 100644
--- a/htdocs/admin/facture.php
+++ b/htdocs/admin/facture.php
@@ -145,6 +145,11 @@ if ($_POST["action"] == 'set_disable_repeatable')
dolibarr_set_const($db, "FACTURE_DISABLE_RECUR",$_POST["disable_repeatable"]);
}
+if ($_POST["action"] == 'set_enable_editdelete')
+{
+ dolibarr_set_const($db, "FACTURE_ENABLE_EDITDELETE",$_POST["enable_editdelete"]);
+}
+
if ($_POST["action"] == 'update' || $_POST["action"] == 'add')
{
if (! dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],0,isset($_POST["constnote"])?$_POST["constnote"]:''));
@@ -502,6 +507,19 @@ print ''
print "\n";
print '';
+// Active la possibilité d'éditer/supprimer une facture validée sans paiement
+$var=! $var;
+print '
';
+ // Editer une facture déjà validée et sans paiement
+ if ($fac->statut == 1)
+ {
+ if ($conf->global->FACTURE_ENABLE_EDITDELETE && $user->rights->facture->modifier
+ && ($resteapayer == $fac->total_ttc && $fac->paye == 0))
+ {
+ print '
'.$langs->trans('Edit').'';
+ }
+ }
+
// Récurrente
if (! $conf->global->FACTURE_DISABLE_RECUR)
{
@@ -2104,11 +2133,37 @@ else
}
}
- // Supprimer
- if ($fac->statut == 0 && $user->rights->facture->supprimer && $_GET['action'] != 'delete')
- {
- print '
id.'&action=delete">'.$langs->trans('Delete').'';
- }
+ // on vérifie si la facture est en numérotation provisoire
+ $facref = substr($fac->ref, 1, 4);
+ if ($facref == PROV)
+ {
+ // Supprimer
+ if ($fac->statut == 0 && $user->rights->facture->supprimer && $_GET['action'] != 'delete')
+ {
+ print '
id.'&action=delete">'.$langs->trans('Delete').'';
+ }
+ }
+ else if ($conf->global->FACTURE_ENABLE_EDITDELETE)
+ {
+ if ($fac->statut == 0 && $user->rights->facture->supprimer && $_GET['action'] != 'delete')
+ {
+ // On ne peut supprimer que la dernière facture validée
+ // pour ne pas avoir de trou dans les numéros
+ $sql = "SELECT MAX(facnumber)";
+ $sql.= " FROM ".MAIN_DB_PREFIX."facture";
+
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $maxfacnumber = $db->fetch_row($resql);
+ }
+
+ if ($maxfacnumber[0] == $fac->ref)
+ {
+ print '
id.'&action=delete">'.$langs->trans('Delete').'';
+ }
+ }
+ }
// Envoyer
if ($fac->statut == 1 && $user->rights->facture->envoyer)
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index 9b9e4cd1331..ee8bd52ea5e 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -830,15 +830,22 @@ class Facture extends CommonObject
{
$this->db->begin();
+ // on vérifie si la facture est en numérotation provisoire
+ $facref = substr($this->ref, 1, 4);
+
$action_notify = 2; // ne pas modifier cette valeur
if ($force_number)
{
$numfa = $force_number;
}
- else
+ else if ($facref == PROV)
{
$numfa = $this->getNextNumRef($soc);
}
+ else
+ {
+ $numfa = $this->ref;
+ }
$this->update_price($this->id);
@@ -868,22 +875,26 @@ class Facture extends CommonObject
}
- // On renomme repertoire facture ($this->ref = ancienne ref, $numfa = nouvelle ref)
- // afin de ne pas perdre les fichiers attachés
- $facref = sanitize_string($this->ref);
- $snumfa = sanitize_string($numfa);
- $dirsource = $conf->facture->dir_output.'/'.$facref;
- $dirdest = $conf->facture->dir_output.'/'.$snumfa;
- if (file_exists($dirsource))
+ // On vérifie si la facture était une provisoire
+ if ($facref == PROV)
{
- dolibarr_syslog("Facture::set_valid() renommage rep ".$dirsource." en ".$dirdest);
+ // On renomme repertoire facture ($this->ref = ancienne ref, $numfa = nouvelle ref)
+ // afin de ne pas perdre les fichiers attachés
+ $facref = sanitize_string($this->ref);
+ $snumfa = sanitize_string($numfa);
+ $dirsource = $conf->facture->dir_output.'/'.$facref;
+ $dirdest = $conf->facture->dir_output.'/'.$snumfa;
+ if (file_exists($dirsource))
+ {
+ dolibarr_syslog("Facture::set_valid() renommage rep ".$dirsource." en ".$dirdest);
- if (rename($dirsource, $dirdest))
- {
- dolibarr_syslog("Renommage ok");
- // Suppression ancien fichier PDF dans nouveau rep
- dol_delete_file($conf->facture->dir_output.'/'.$snumfa.'/'.$facref.'.*');
- }
+ if (rename($dirsource, $dirdest))
+ {
+ dolibarr_syslog("Renommage ok");
+ // Suppression ancien fichier PDF dans nouveau rep
+ dol_delete_file($conf->facture->dir_output.'/'.$snumfa.'/'.$facref.'.*');
+ }
+ }
}
@@ -932,14 +943,16 @@ class Facture extends CommonObject
}
*/
-
+ // On vérifie si la facture était une provisoire
+ if ($facref == PROV)
+ {
/*
* Pour chaque produit, on met a jour indicateur nbvente
* On crée ici une dénormalisation des données pas forcément utilisée.
*/
- $sql = 'SELECT fk_product FROM '.MAIN_DB_PREFIX.'facturedet';
- $sql.= ' WHERE fk_facture = '.$this->id;
- $sql.= ' AND fk_product > 0';
+ $sql = 'SELECT fk_product FROM '.MAIN_DB_PREFIX.'facturedet';
+ $sql.= ' WHERE fk_facture = '.$this->id;
+ $sql.= ' AND fk_product > 0';
$resql = $this->db->query($sql);
if ($resql)
@@ -958,6 +971,7 @@ class Facture extends CommonObject
{
$error++;
}
+ }
if ($error == 0)
{
@@ -976,11 +990,11 @@ class Facture extends CommonObject
* \todo Mettre notifications dans triggers
*/
$facref = sanitize_string($this->ref);
- $filepdf = $conf->facture->dir_output . '/' . $facref . '/' . $facref . '.pdf';
- $mesg = 'La facture '.$this->ref." a été validée.\n";
+ $filepdf = $conf->facture->dir_output . '/' . $facref . '/' . $facref . '.pdf';
+ $mesg = 'La facture '.$this->ref." a été validée.\n";
- $notify = New Notify($this->db);
- $notify->send($action_notify, $this->socidp, $mesg, 'facture', $rowid, $filepdf);
+ $notify = New Notify($this->db);
+ $notify->send($action_notify, $this->socidp, $mesg, 'facture', $rowid, $filepdf);
$this->db->commit();
@@ -994,6 +1008,25 @@ class Facture extends CommonObject
}
}
}
+
+ /**
+ *
+ *
+ */
+ function reopen($userid)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_statut = 0";
+ $sql .= " WHERE rowid = $this->id;";
+
+ if ($this->db->query($sql) )
+ {
+ return 1;
+ }
+ else
+ {
+ dolibarr_print_error($this->db);
+ }
+ }
/*
*
diff --git a/htdocs/includes/modules/modFacture.class.php b/htdocs/includes/modules/modFacture.class.php
index 188ccce3734..080535d2112 100644
--- a/htdocs/includes/modules/modFacture.class.php
+++ b/htdocs/includes/modules/modFacture.class.php
@@ -129,10 +129,17 @@ class modFacture extends DolibarrModules
$r++;
$this->rights[$r][0] = 12;
- $this->rights[$r][1] = 'Créer/modifier les factures';
+ $this->rights[$r][1] = 'Créer les factures';
$this->rights[$r][2] = 'a';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'creer';
+
+ $r++;
+ $this->rights[$r][0] = 13;
+ $this->rights[$r][1] = 'Modifier les factures';
+ $this->rights[$r][2] = 'a';
+ $this->rights[$r][3] = 0;
+ $this->rights[$r][4] = 'modifier';
$r++;
$this->rights[$r][0] = 14;
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index e36febe917e..29565b170b8 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -142,7 +142,8 @@ Module700Desc=Donations' management
Module1780Name=Categories
Module1780Desc=Categories' management
Permission11=Read invoices
-Permission12=Create/modify invoices
+Permission12=Create invoices
+Permission13=Modify invoices
Permission14=Validate invoices
Permission15=Send invoices by email
Permission16=Create payments for invoices
@@ -404,6 +405,7 @@ CreditNotes=Credit notes
ForceInvoiceDate=Force invoice date to validation date
DisableRepeatable=Disable repeatable invoices
SuggestedPaymentModesIfNotDefinedInInvoice=Suggested Payments mode on invoices if not explicitely defined
+EnableEditDeleteValidInvoice=Enable the possibility to edit/delete valid invoice with no payment
##### Proposals #####
PropalSetup=Commercial proposals module setup
CreateForm=Create forms
diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang
index 145a7d93cc8..5d95232383d 100644
--- a/htdocs/langs/fr_FR/admin.lang
+++ b/htdocs/langs/fr_FR/admin.lang
@@ -142,7 +142,8 @@ Module700Desc=Gestion des dons
Module1780Name=Catégories
Module1780Desc=Gestion des catégories
Permission11=Consulter les factures
-Permission12=Créer/modifier les factures
+Permission12=Créer les factures
+Permission13=Modifier les factures
Permission14=Valider les factures
Permission15=Envoyer les factures par courriel
Permission16=Émettre des paiements sur les factures
@@ -404,6 +405,7 @@ CreditNotes=Avoirs
ForceInvoiceDate=Forcer la date de facture à la date de validation
DisableRepeatable=Désactiver les factures récurrentes
SuggestedPaymentModesIfNotDefinedInInvoice=Modes de paiements suggérés sur les factures si non défini explicitement
+EnableEditDeleteValidInvoice=Activer la possibilité d'éditer/supprimer une facture validée sans paiement
##### Proposals #####
PropalSetup=Configuration du module Propositions Commerciales
CreateForm=Création formulaire