From 1ebba35536fef8253f44156f7012df539c13eecd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@users.sourceforge.net> Date: Sat, 14 May 2005 15:43:26 +0000 Subject: [PATCH] New: Ajout fonction delete pour supprimer un compte --- htdocs/compta/bank/account.class.php | 19 +++++++++ htdocs/compta/bank/fiche.php | 63 ++++++++++++++++++++-------- htdocs/compta/index.php | 36 +++++++++------- 3 files changed, 87 insertions(+), 31 deletions(-) diff --git a/htdocs/compta/bank/account.class.php b/htdocs/compta/bank/account.class.php index 01f91262d11..7e8d13d0595 100644 --- a/htdocs/compta/bank/account.class.php +++ b/htdocs/compta/bank/account.class.php @@ -323,6 +323,25 @@ class Account /* + * \brief Efface le compte + * + */ + function delete() + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account"; + $sql .= " WHERE rowid = ".$this->rowid; + $result = $this->db->query($sql); + if ($result) { + return 1; + } + else { + dolibarr_print_error($this->db); + return -1; + } + } + + + /* * \brief Renvoi si un compte peut etre supprimer ou non (sans mouvements) * \return boolean vrai si peut etre supprim�, faux sinon */ diff --git a/htdocs/compta/bank/fiche.php b/htdocs/compta/bank/fiche.php index 2b61a4c22eb..3cebc79e529 100644 --- a/htdocs/compta/bank/fiche.php +++ b/htdocs/compta/bank/fiche.php @@ -38,9 +38,9 @@ if (!$user->admin && !$user->rights->banque) accessforbidden(); -llxHeader(); - - +/* + * Actions + */ if ($_POST["action"] == 'add') { // Creation compte @@ -101,27 +101,42 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"]) $account->proprio = $_POST["proprio"]; $account->adresse_proprio = $_POST["adresse_proprio"]; - if ($account->label) { + if ($account->label) + { $result = $account->update($user); - if (! $result) { + if (! $result) + { $message=$account->error(); $_GET["action"]='edit'; // Force chargement page edition } - else { + else + { $_GET["id"]=$_POST["id"]; // Force chargement page en mode visu } - } else { - $message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("LabelBankCashAccount")).'</div>'; - $_GET["action"]='create'; // Force chargement page en mode creation - } - + } else { + $message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("LabelBankCashAccount")).'</div>'; + $_GET["action"]='create'; // Force chargement page en mode creation } +} +if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer) +{ + // Modification + $account = new Account($db, $_GET["id"]); + $account->delete($_GET["id"]); + header("Location: ".DOL_URL_ROOT."/compta/bank/index.php"); + exit; +} + + +llxHeader(); + +$form = new Form($db); /* ************************************************************************** */ /* */ -/* Nouvel compte */ +/* Affichage page en mode cr�ation */ /* */ /* ************************************************************************** */ @@ -212,6 +227,15 @@ else dolibarr_fiche_head($head, $hselected, $langs->trans("FinancialAccount")." ".$account->number); + /* + * Confirmation de la suppression + */ + if ($_GET["action"] == 'delete') + { + $form->form_confirm($_SERVER["PHP_SELF"]."?id=$account->id",$langs->trans("DeleteAccount"),$langs->trans("ConfirmDeleteAccount"),"confirm_delete"); + print '<br />'; + } + print '<table class="border" width="100%">'; print '<tr><td valign="top">'.$langs->trans("Label").'</td>'; @@ -256,16 +280,23 @@ else print '<br>'; print '</div>'; - + + /* * Barre d'actions * */ print '<div class="tabsAction">'; - if ($user->rights->banque->configurer) + if ($user->rights->banque->configurer) { - print '<a class="tabAction" href="fiche.php?action=edit&id='.$account->id.'">'.$langs->trans("Edit").'</a>'; + print '<a class="butAction" href="fiche.php?action=edit&id='.$account->id.'">'.$langs->trans("Edit").'</a>'; + } + + $canbedeleted=$account->can_be_deleted(); // Renvoi vrai si compte sans mouvements + if ($user->rights->banque->configurer && $canbedeleted) + { + print '<a class="butActionDelete" href="fiche.php?action=delete&id='.$account->id.'">'.$langs->trans("Delete").'</a>'; } print '</div>'; @@ -284,8 +315,6 @@ else $account = new Account($db, $_GET["id"]); $account->fetch($_GET["id"]); - $form = new Form($db); - print_titre($langs->trans("EditFinancialAccount")); print "<br>"; diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index 44455d32a4f..f68b6e31405 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -131,7 +131,7 @@ if ($conf->facture->enabled && $user->rights->facture->lire) $obj = $db->fetch_object($resql); $var=!$var; print '<tr '.$bc[$var].'><td><a href="facture.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.'</a></td>'; - print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("Showcompany"),"company").' '.$obj->nom.'</a></td></tr>'; + print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("Showcompany"),"company").' '.dolibarr_trunc($obj->nom,50).'</a></td></tr>'; $i++; } @@ -279,7 +279,7 @@ if ($conf->commande->enabled && $user->rights->commande->lire) print "<a href=\"commande/fiche.php?id=$obj->rowid\">".$obj->ref.'</a></td>'; print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").'</a> '; - print '<a href="fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td>'; + print '<a href="fiche.php?socid='.$obj->idp.'">'.dolibarr_trunc($obj->nom,50).'</a></td>'; print '<td align="right">'.price($obj->total_ht).'</td>'; print '<td align="right">'.price($obj->total_ttc).'</td>'; print '<td align="right">'.price($obj->total_ttc-$obj->tot_fttc).'</td></tr>'; @@ -289,10 +289,11 @@ if ($conf->commande->enabled && $user->rights->commande->lire) $i++; } $var=!$var; - print '<tr '.$bc[$var].'><td colspan="2" align="left"><i>'.$langs->trans("Total").' ('.$langs->trans("RemainderToBill").': '.price($tot_tobill).')</i></td>'; - print '<td align="right"><i>'.price($tot_ht).'</i></td>'; - print '<td align="right"><i>'.price($tot_ttc).'</i></td>'; - print '<td align="right"><i>'.price($tot_tobill).'</i></td>'; + + print '<tr class="liste_total"><td colspan="2" align="right">'.$langs->trans("Total").' <font style="font-weight: normal">('.$langs->trans("RemainderToBill").': '.price($tot_tobill).')</font> </td>'; + print '<td align="right">'.price($tot_ht).'</td>'; + print '<td align="right">'.price($tot_ttc).'</td>'; + print '<td align="right">'.price($tot_tobill).'</td>'; print '</tr>'; print '</table><br>'; } @@ -345,7 +346,7 @@ if ($conf->facture->enabled && $user->rights->facture->lire) { $var=!$var; print '<tr '.$bc[$var].'><td nowrap><a href="facture.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.'</a></td>'; - print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCustomer"),"company").' '.$obj->nom.'</a></td>'; + print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCustomer"),"company").' '.dolibarr_trunc($obj->nom,50).'</a></td>'; print '<td align="right">'.price($obj->total).'</td>'; print '<td align="right">'.price($obj->total_ttc).'</td>'; print '<td align="right">'.price($obj->am).'</td></tr>'; @@ -357,9 +358,12 @@ if ($conf->facture->enabled && $user->rights->facture->lire) } $var=!$var; - print '<tr '.$bc[$var].'><td colspan="2" align="left"><i>'.$langs->trans("Total").' ('.$langs->trans("RemainderToTake").': '.price($total_ttc-$totalam).')</i></td><td align="right"><i>'.price($total)."</i></td><td align=\"right\"><i>".price($total_ttc)."</i></td><td align=\"right\"><i>".price($totalam)."</i></td></tr>"; - - print "</table><br>"; + print '<tr class="liste_total"><td colspan="2" align="right">'.$langs->trans("Total").' <font style="font-weight: normal">('.$langs->trans("RemainderToTake").': '.price($total_ttc-$totalam).')</font> </td>'; + print '<td align="right">'.price($total).'</td>'; + print '<td align="right">'.price($total_ttc).'</td>'; + print '<td align="right">'.price($totalam).'</td>'; + print '</tr>'; + print '</table><br>'; } $db->free($resql); } @@ -423,7 +427,7 @@ if ($conf->facture->enabled) { $obj = $db->fetch_object($result); $var = !$var; print '<tr '.$bc[$var].'><td><a href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.'</a></td>'; - print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowSupplier"),"company").' '.$obj->nom.'</a></td>'; + print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowSupplier"),"company").' '.dolibarr_trunc($obj->nom,50).'</a></td>'; print '<td align="right">'.price($obj->total_ht).'</td>'; print '<td align="right">'.price($obj->total_ttc).'</td>'; print '</tr>'; @@ -433,8 +437,11 @@ if ($conf->facture->enabled) { $i++; } $var=!$var; - print '<tr '.$bc[$var].'><td colspan="2" align="left"><i>'.$langs->trans("Total").' ('.$langs->trans("RemainderToPay").': '.price($total_ttc-$totalam).')</td>'; - print '<td align="right"><i>'.price($total).'</i></td><td align="right"><i>'.price($total_ttc).'</i></td></tr>'; + + print '<tr class="liste_total"><td colspan="2" align="right">'.$langs->trans("Total").' <font style="font-weight: normal">('.$langs->trans("RemainderToPay").': '.price($total_ttc-$totalam).')</font> </td>'; + print '<td align="right">'.price($total).'</td>'; + print '<td align="right">'.price($total_ttc).'</td>'; + print '</tr>'; print '</table><br>'; } } @@ -452,6 +459,7 @@ print '</td></tr>'; print '</table>'; $db->close(); + -llxFooter("<em>Dernière modification $Date$ révision $Revision$</em>"); +llxFooter('$Date$ - $Revision$'); ?> -- GitLab