diff --git a/htdocs/compta/bank/rappro.php b/htdocs/compta/bank/rappro.php
index 5222c58b026..237ba7b3766 100644
--- a/htdocs/compta/bank/rappro.php
+++ b/htdocs/compta/bank/rappro.php
@@ -44,225 +44,246 @@ llxHeader();
*/
if ($_POST["action"] == 'rappro')
{
- if ($_POST["num_releve"] > 0) {
-
+ if ($_POST["num_releve"] > 0)
+ {
+ $db->begin();
+
$valrappro=1;
- $sql = "UPDATE ".MAIN_DB_PREFIX."bank set rappro=$valrappro, num_releve=".$_POST["num_releve"];
- if ($_POST["rappro"]) {
- # Si on fait un rapprochement, le user de rapprochement est inclus dans l'update
- $sql .= ", fk_user_rappro=".$user->id;
- }
- $sql .= " WHERE rowid=".$_POST["rowid"];
+ $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
+ $sql.= " set rappro=".$valrappro.", num_releve=".$_POST["num_releve"].",";
+ $sql.= " fk_user_rappro=".$user->id;
+ $sql.= " WHERE rowid=".$_POST["rowid"];
$result = $db->query($sql);
- if ($result) {
- if ($cat1 && $_POST["action"]) {
+ if ($result)
+ {
+ if ($cat1 && $_POST["action"])
+ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES ($rowid, $cat1)";
$result = $db->query($sql);
- }
- } else {
- dolibarr_print_error($db);
- }
- }
- else {
- $msg="Erreur: Saisissez le relevé qui référence la transaction pour la rapprocher.";
- }
- }
-
- /*
- * Action suppression ecriture
- */
- if ($_GET["action"] == 'del') {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".$_GET["rowid"];
- $result = $db->query($sql);
- if (! $result) {
- dolibarr_print_error($db);
- }
- }
-
- $sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ ORDER BY label";
- $result = $db->query($sql);
- $options="";
- if ($result) {
- $var=True;
- $num = $db->num_rows($result);
- $i = 0;
- while ($i < $num) {
- if ($options == "") { $options = ""; }
- $obj = $db->fetch_object($result);
- $options .= "\n"; $i++;
- }
- $db->free($result);
- }
-
-
- /*
- * Affichage liste des transactions à rapprocher
- */
- $acct = new Account($db);
- $acct->fetch($_GET["account"]);
-
- $sql = "SELECT b.rowid,".$db->pdate("b.dateo")." as do, ".$db->pdate("b.datev")." as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type as type";
- $sql .= " FROM ".MAIN_DB_PREFIX."bank as b WHERE rappro=0 AND fk_account=".$_GET["account"];
- $sql .= " ORDER BY dateo";
- $sql .= " ASC LIMIT ".$conf->liste_limit;
-
- $result = $db->query($sql);
- if ($result)
- {
- $var=True;
- $num = $db->num_rows($result);
-
- if ($num == 0) {
- header("Location: /compta/bank/account.php?account=".$_GET["account"]);
- exit;
- }
- else {
-
- print_titre('Rapprochement compte bancaire : '.$acct->label.'');
- print '
';
-
- if ($msg) {
- print "$msg
";
- }
-
- // Affiche nom des derniers relevés
- $nbmax=5;
- $liste="";
-
- $sql = "SELECT distinct num_releve FROM ".MAIN_DB_PREFIX."bank";
- $sql.= " WHERE fk_account=".$_GET["account"];
- $sql.= " ORDER BY num_releve DESC";
- $sql.= " LIMIT ".($nbmax+1);
- print $langs->trans("LastAccountStatements").' : ';
- $resultr=$db->query($sql);
- if ($resultr)
- {
- $numr=$db->num_rows($resultr);
- $i=0;
- while (($i < $numr) && ($i < $nbmax))
+
+ if ($result)
{
- $objr = $db->fetch_object($resultr);
- $last_releve = $objr->num_releve;
- $i++;
- $liste='num_releve.'">'.$objr->num_releve.' '.$liste;
- }
- if ($num >= $nbmax) $liste="... ".$liste;
- print "$liste";
- if ($num > 0) print '
';
- else print $langs->trans("None").'
';
- }
- else
- {
- dolibarr_print_error($db);
- }
-
- print '
';
- print "";
- print '| '.$langs->trans("Date").' | ';
- print ''.$langs->trans("DateValue").' | ';
- print ''.$langs->trans("Type").' | ';
- print ''.$langs->trans("Description").' | ';
- print ''.$langs->trans("Debit").' | ';
- print ''.$langs->trans("Credit").' | ';
- print ''.$langs->trans("Action").' | ';
- print ''.$langs->trans("AccountStatement").' (Ex: YYYYMM) | ';
- print "
\n";
- }
-
- $i = 0;
- while ($i < $num)
- {
- $objp = $db->fetch_object($result);
-
- $var=!$var;
- print "";
- print '
";
-
- print "";
- $i++;
}
- $db->free();
+ else
+ {
+ $db->rollback();
+ dolibarr_print_error($db);
+ }
+ }
+ else {
+ $msg="Erreur: Saisissez le relevé qui référence la transaction pour la rapprocher.";
+ }
+}
- if ($num != 0) {
- print "
";
+/*
+* Action suppression ecriture
+*/
+if ($_GET["action"] == 'del') {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".$_GET["rowid"];
+ $result = $db->query($sql);
+ if (! $result) {
+ dolibarr_print_error($db);
+ }
+}
+
+$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ ORDER BY label";
+$result = $db->query($sql);
+$options="";
+if ($result) {
+ $var=True;
+ $num = $db->num_rows($result);
+ $i = 0;
+ while ($i < $num) {
+ if ($options == "") { $options = ""; }
+ $obj = $db->fetch_object($result);
+ $options .= "\n"; $i++;
+ }
+ $db->free($result);
+}
+
+
+/*
+* Affichage liste des transactions à rapprocher
+*/
+$acct = new Account($db);
+$acct->fetch($_GET["account"]);
+
+$sql = "SELECT b.rowid,".$db->pdate("b.dateo")." as do, ".$db->pdate("b.datev")." as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type as type";
+$sql .= " FROM ".MAIN_DB_PREFIX."bank as b WHERE rappro=0 AND fk_account=".$_GET["account"];
+$sql .= " ORDER BY dateo";
+$sql .= " ASC LIMIT ".$conf->liste_limit;
+
+$result = $db->query($sql);
+if ($result)
+{
+ $var=True;
+ $num = $db->num_rows($result);
+
+ if ($num == 0)
+ {
+ header("Location: /compta/bank/account.php?account=".$_GET["account"]);
+ exit;
+ }
+ else
+ {
+
+ print_titre('Rapprochement compte bancaire : '.$acct->label.'');
+ print '
';
+
+ if ($msg) {
+ print "$msg
";
}
- } else {
+ // Affiche nom des derniers relevés
+ $nbmax=5;
+ $liste="";
+
+ $sql = "SELECT distinct num_releve FROM ".MAIN_DB_PREFIX."bank";
+ $sql.= " WHERE fk_account=".$_GET["account"];
+ $sql.= " ORDER BY num_releve DESC";
+ $sql.= " LIMIT ".($nbmax+1);
+ print $langs->trans("LastAccountStatements").' : ';
+ $resultr=$db->query($sql);
+ if ($resultr)
+ {
+ $numr=$db->num_rows($resultr);
+ $i=0;
+ while (($i < $numr) && ($i < $nbmax))
+ {
+ $objr = $db->fetch_object($resultr);
+ $last_releve = $objr->num_releve;
+ $i++;
+ $liste='num_releve.'">'.$objr->num_releve.' '.$liste;
+ }
+ if ($num >= $nbmax) $liste="... ".$liste;
+ print "$liste";
+ if ($num > 0) print '
';
+ else print $langs->trans("None").'
';
+ }
+ else
+ {
dolibarr_print_error($db);
}
- $db->close();
+ print '';
+ print "";
+ print '| '.$langs->trans("Date").' | ';
+ print ''.$langs->trans("DateValue").' | ';
+ print ''.$langs->trans("Type").' | ';
+ print ''.$langs->trans("Description").' | ';
+ print ''.$langs->trans("Debit").' | ';
+ print ''.$langs->trans("Credit").' | ';
+ print ''.$langs->trans("Action").' | ';
+ print ''.$langs->trans("AccountStatement").' (Ex: YYYYMM) | ';
+ print "
\n";
+ }
- llxFooter("Dernière modification $Date$ révision $Revision$");
- ?>
+ $i = 0;
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($result);
+
+ $var=!$var;
+ print "";
+ print '
";
+
+ print "";
+ $i++;
+ }
+ $db->free($result);
+
+ if ($num != 0) {
+ print "
";
+ }
+
+} else {
+ dolibarr_print_error($db);
+}
+
+$db->close();
+
+llxFooter('$Date$ - $Revision$');
+?>