diff --git a/htdocs/compta/bank/account.class.php b/htdocs/compta/bank/account.class.php index 470d003ce4f..dc584a0276f 100644 --- a/htdocs/compta/bank/account.class.php +++ b/htdocs/compta/bank/account.class.php @@ -42,10 +42,12 @@ class Account { global $config; - $this->clos = 0; $this->db = $DB; $this->rowid = $rowid; + + $this->clos = 0; $this->solde = 0; + return 1; } @@ -169,7 +171,7 @@ class Account } else { - print $this->db->error().' in '.$sql; + dolibarr_print_error($this->db); return ''; } } @@ -186,7 +188,7 @@ class Account if (! verif_rib($this->code_banque,$this->code_guichet,$this->number,$this->cle_rib)) { $this->error="Le contrôle de la clé indique que les informations de votre compte bancaire sont incorrectes."; - return false; + return 0; } if (! $pcgnumber) { @@ -213,7 +215,8 @@ class Account } else { - print $this->db->error(); + dolibarr_print_error($this->db); + return 0; } } @@ -221,19 +224,17 @@ class Account * * */ - Function error() + Function update($user='') { - return $this->error; - } - - /* - * - * - */ - Function update() - { - if (strlen($this->label)==0) - $this->label = "???"; + // Chargement librairie pour acces fonction controle RIB + require_once DOL_DOCUMENT_ROOT . '/compta/bank/bank.lib.php'; + + if (! verif_rib($this->code_banque,$this->code_guichet,$this->number,$this->cle_rib)) { + $this->error="Le contrôle de la clé indique que les informations de votre compte bancaire sont incorrectes."; + return 0; + } + + if (! $this->label) $this->label = "???"; $sql = "UPDATE ".MAIN_DB_PREFIX."bank_account SET "; @@ -252,24 +253,21 @@ class Account $sql .= ",courant = ".$this->courant; $sql .= ",clos = ".$this->clos; - $sql .= " WHERE rowid = $this->id"; + $sql .= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); if ($result) { - if ($this->db->affected_rows()) - { - return 1; - } + return 1; } else { - print $this->db->error(); - print "

$sql

"; + dolibarr_print_error($this->db); return 0; } } + /* * * @@ -306,9 +304,19 @@ class Account } else { - print $this->db->error(); + dolibarr_print_error($this->db); } } + + /* + * + * + */ + Function error() + { + return $this->error; + } + /* * * diff --git a/htdocs/compta/bank/fiche.php b/htdocs/compta/bank/fiche.php index f93c7518acf..e9145cedf1d 100644 --- a/htdocs/compta/bank/fiche.php +++ b/htdocs/compta/bank/fiche.php @@ -22,22 +22,24 @@ */ require("./pre.inc.php"); -$user->getrights('compta'); +$user->getrights('banque'); -if (!$user->admin && !$user->rights->compta->bank) +if (!$user->admin && !$user->rights->banque) accessforbidden(); + llxHeader(); if ($_POST["action"] == 'add') { + // Creation compte $account = new Account($db,0); $account->bank = $_POST["bank"]; $account->label = $_POST["label"]; - $account->courant = $_POST["courant"]=='yes'?1:0; + $account->courant = $_POST["courant"]; $account->clos = $_POST["clos"]; $account->code_banque = $_POST["code_banque"]; @@ -57,17 +59,18 @@ if ($_POST["action"] == 'add') $id = $account->create($user->id); if (! $id) { $message=$account->error(); - $_GET["action"]='create'; // Force chargement page creation + $_GET["action"]='create'; // Force chargement page en mode creation } else { - $_GET["id"]=$id; // Force chargement page en mode edition + $_GET["id"]=$id; // Force chargement page en mode visu } } -if ($_POST["action"] == 'update') +if ($_POST["action"] == 'update' && ! $_POST["cancel"]) { - $account = new Account($db, $_GET["id"]); - $account->fetch($_GET["id"]); + // Modification + $account = new Account($db, $_POST["id"]); + $account->fetch($_POST["id"]); $account->bank = $_POST["bank"]; $account->label = $_POST["label"]; @@ -83,7 +86,15 @@ if ($_POST["action"] == 'update') $account->proprio = $_POST["proprio"]; $account->adresse_proprio = $_POST["adresse_proprio"]; - $account->update($_GET["id"], $user); + $result = $account->update($user); + if (! $result) { + $message=$account->error(); + $_GET["action"]='edit'; // Force chargement page edition + } + else { + $_GET["id"]=$_POST["id"]; // Force chargement page en mode visu + } + } @@ -127,7 +138,7 @@ if ($_GET["action"] == 'create') print 'Compte Courant'; print ''; $form=new Form($db); - print $form->selectyesno("courant",isset($_POST["courant"])?$_POST["courant"]:1); + print $form->selectyesnonum("courant",isset($_POST["courant"])?$_POST["courant"]:1); print ''; print 'Domiciliation'; @@ -198,33 +209,28 @@ else print 'Identifiant BIC'; print ''.$account->bic.''; - /* - print 'Domiciliation'; - print ''.$account->domiciliation.''; - */ - - print 'Compte Courant'; - print ''.$yn[$account->courant].''; - - print 'Compte Clos'; - print ''.$yn[$account->clos].''; - - print 'Domiciliation'; - print $account->domiciliation; - print "\n"; - - print 'Nom propriétaire du compte'; - print $account->proprio; - print "\n"; - - print 'Adresse propriétaire du compte'; - print $account->adresse_proprio; - print "\n"; - - print ''; - print '
'; - - print ''; + print 'Compte Courant'; + print ''.yn($account->courant).''; + + print 'Compte Clos'; + print ''.yn($account->clos).''; + + print 'Domiciliation'; + print $account->domiciliation; + print "\n"; + + print 'Nom propriétaire du compte'; + print $account->proprio; + print "\n"; + + print 'Adresse propriétaire du compte'; + print $account->adresse_proprio; + print "\n"; + + print ''; + print '
'; + + print ''; /* * Barre d'actions @@ -232,7 +238,7 @@ else */ print '
'; - if ($user->admin) + if ($user->rights->banque->configurer) { print ''.$langs->trans("Edit").''; } @@ -247,7 +253,7 @@ else /* */ /* ************************************************************************** */ - if ($_GET["id"] && $_GET["action"] == 'edit' && $user->admin) + if ($_GET["id"] && $_GET["action"] == 'edit' && $user->rights->banque->configurer) { $account = new Account($db, $_GET["id"]); @@ -255,10 +261,14 @@ else $form = new Form($db); - print '
Compte bancaire

'; + print_titre("Edition compte bancaire"); + print "
"; + + if ($message) { print "$message

\n"; } print '
'; print ''; + print ''; print ''; @@ -280,11 +290,6 @@ else print ''; print ''; - /* - print ''; - print ''; - */ - print ''; print '"; - print ''; + print ''; print ''; print '
Identifiant BIC
Domiciliation
Compte Courant'; $form->selectyesnonum("courant",$account->courant); @@ -309,7 +314,9 @@ else print $account->adresse_proprio; print "
'; + print '   '; + print '
'; }