diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index e02e3935abddeb56cfb5d52d6b998d4650f406f3..d6216622daf83d7c8ba8325e137f281fe0b589f9 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 '<input type="submit" class="button" value="'.$langs->trans("Modify").'">' print "</td></tr>\n"; print '</form>'; +// Active la possibilit� d'�diter/supprimer une facture valid�e sans paiement +$var=! $var; +print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'; +print '<input type="hidden" name="action" value="set_enable_editdelete">'; +print '<tr '.$bc[$var].'><td>'; +print $langs->trans("EnableEditDeleteValidInvoice"); +print '</td><td width="60" align="center">'; +print $html->selectyesno("enable_editdelete",$conf->global->FACTURE_ENABLE_EDITDELETE,1); +print '</td><td align="right">'; +print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">'; +print "</td></tr>\n"; +print '</form>'; + print '</table>'; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 5298791dc55a9313746dc8867f7bac6a77384545..17d3aa07a906e3af3d1a46ff5d40c051d1644b8b 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -161,6 +161,16 @@ if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user-> } } +if ($_GET['action'] == 'modif' && $user->rights->facture->modifier && $conf->global->FACTURE_ENABLE_EDITDELETE) +{ + /* + * Repasse la facture en mode brouillon + */ + $fac = new Facture($db); + $fac->fetch($_GET['facid']); + $fac->reopen($user); +} + if ($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) { if ($user->rights->facture->creer) @@ -1361,7 +1371,16 @@ else */ if ($_GET['action'] == 'valid') { - $numfa = $fac->getNextNumRef($soc); + // on v�rifie si la facture est en num�rotation provisoire + $facref = substr($fac->ref, 1, 4); + if ($facref == PROV) + { + $numfa = $fac->getNextNumRef($soc); + } + else + { + $numfa = $fac->ref; + } $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ValidateBill'),$langs->trans('ConfirmValidateBill',$numfa),'confirm_valid'); print '<br />'; } @@ -2074,6 +2093,16 @@ else { print '<div class="tabsAction">'; + // 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 '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$fac->id.'&action=modif">'.$langs->trans('Edit').'</a>'; + } + } + // 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 '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&action=delete">'.$langs->trans('Delete').'</a>'; - } + // 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 '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&action=delete">'.$langs->trans('Delete').'</a>'; + } + } + 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 '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&action=delete">'.$langs->trans('Delete').'</a>'; + } + } + } // Envoyer if ($fac->statut == 1 && $user->rights->facture->envoyer) diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 9b9e4cd1331dcab3a39a4a07612dd8cab0f2afe1..ee8bd52ea5e0c9f1e894c60b5e0584625ebf9858 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); - - if (rename($dirsource, $dirdest)) - { - dolibarr_syslog("Renommage ok"); - // Suppression ancien fichier PDF dans nouveau rep - dol_delete_file($conf->facture->dir_output.'/'.$snumfa.'/'.$facref.'.*'); - } + // 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.'.*'); + } + } } @@ -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 188ccce373464ac1a1536a4fd996603eec5e3324..080535d2112fba0053529e3404d5a9207ce18a19 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 e36febe917e2a42dfb5e1635a486c593d77bd646..29565b170b8e39f3bb39ada6b0ffd656533f77c4 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 145a7d93cc828d99ecf5e0a4368a685d38783b71..5d95232383d986ee21de32cac57cdc9b42d2bf9b 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