From bbe88121ab4dd477f0edf998f2a9009b5bb7c649 Mon Sep 17 00:00:00 2001
From: Rodolphe Quiedeville <rodolphe@quiedeville.org>
Date: Tue, 24 Dec 2002 00:08:44 +0000
Subject: [PATCH] too late to remember

---
 htdocs/compta/bank/account.class.php | 120 ++++++--
 htdocs/compta/bank/account.php3      | 393 +++++++++++++++------------
 htdocs/compta/bank/config.php3       |  39 +--
 htdocs/compta/bank/fiche.php         | 220 +++++++++++++++
 htdocs/cyberpaiement.class.php       | 234 ++++++++++++++++
 htdocs/public/dons/testretour.php    |  10 +-
 htdocs/retourbplc.class.php          | 222 ++++++++++++++-
 mysql/tables/llx_bank_account.sql    |   4 +-
 8 files changed, 1018 insertions(+), 224 deletions(-)
 create mode 100644 htdocs/compta/bank/fiche.php
 create mode 100644 htdocs/cyberpaiement.class.php

diff --git a/htdocs/compta/bank/account.class.php b/htdocs/compta/bank/account.class.php
index b563d184ff6..19a14a55d5f 100644
--- a/htdocs/compta/bank/account.class.php
+++ b/htdocs/compta/bank/account.class.php
@@ -21,6 +21,7 @@
 
 class Account {
   var $rowid;
+
   var $bank;
   var $label;
 
@@ -40,40 +41,117 @@ class Account {
     
     return 1;
   }
-
-  Function fetch($id) {
+  /*
+   *
+   *
+   */
+  /*
+   *
+   *
+   *
+   */
+  Function create()
+    {
+      $sql = "INSERT INTO llx_bank_account (datec, label) values (now(),'$this->label');";
+      if ($this->db->query($sql))
+	{
+	  if ($this->db->affected_rows()) 
+	    {
+	      $this->id = $this->db->last_insert_id();
+	      $this->update();
+	      return $this->id;      
+	    }
+	}
+      else
+	{
+	  print $this->db->error();
+	}
+    }
+  /*
+   *
+   *
+   */
+
+  Function update()
+    {      
+      $sql = "UPDATE llx_bank_account SET ";
+
+      $sql .= " bank = '" .$this->bank ."'";
+      $sql .= ",label = '".$this->label ."'";
+
+      $sql .= ",code_banque='".$this->code_banque."'";
+      $sql .= ",code_guichet='".$this->code_guichet."'";
+      $sql .= ",number='".$this->number."'";
+      $sql .= ",cle_rib='".$this->cle_rib."'";
+      $sql .= ",bic='".$this->bic."'";
+      $sql .= ",courant = ".$this->courant;
+
+      $sql .= " WHERE rowid = $this->id";
+      
+      $result = $this->db->query($sql);
+	      
+      if ($result) 
+	{
+	  if ($this->db->affected_rows()) 
+	    {
+	      return 1;		      
+	    }		  
+	}
+      else
+	{
+	  print $this->db->error();
+	}
+    }
+  /*
+   *
+   *
+   */
+  Function fetch($id)
+  {
     $this->id = $id; 
-    $sql = "SELECT rowid, label, bank, number, courant FROM llx_bank_account";
+    $sql = "SELECT rowid, label, bank, number, courant, code_banque,code_guichet,cle_rib FROM llx_bank_account";
     $sql .= " WHERE rowid  = ".$id;
 
     $result = $this->db->query($sql);
 
-    if ($result) {
-      if ($this->db->num_rows()) {
-	$obj = $this->db->fetch_object($result , 0);
-
-	$this->bank = $obj->bank;
-	$this->label = $obj->label;
-	$this->number = $obj->number;
-	$this->courant = $obj->courant;
+    if ($result)
+      {
+	if ($this->db->num_rows())
+	  {
+	    $obj = $this->db->fetch_object($result , 0);
+	    
+	    $this->bank    = $obj->bank;
+	    $this->label   = $obj->label;
+	    $this->courant = $obj->courant;
+
+	    $this->code_banque  = $obj->code_banque;
+	    $this->code_guichet = $obj->code_guichet;
+	    $this->number       = $obj->number;
+	    $this->cle_rib      = $obj->cle_rib;
+	  }
+	$this->db->free();
       }
-      $this->db->free();
-    }
   }
-
-  Function solde() {
+  /*
+   *
+   *
+   */
+  Function solde()
+  {
     $sql = "SELECT sum(amount) FROM llx_bank WHERE fk_account=$this->id AND dateo <=" . $this->db->idate(time() );
 
     $result = $this->db->query($sql);
 
-    if ($result) {
-      if ($this->db->num_rows()) {
-	$solde = $this->db->result(0,0);
+    if ($result)
+      {
+	if ($this->db->num_rows())
+	  {
+	    $solde = $this->db->result(0,0);
 
-	return $solde;
+	    return $solde;
+	  }
+	$this->db->free();
       }
-      $this->db->free();
-    }
   }
 
 
diff --git a/htdocs/compta/bank/account.php3 b/htdocs/compta/bank/account.php3
index d595a60ee8b..1e8c02d405e 100644
--- a/htdocs/compta/bank/account.php3
+++ b/htdocs/compta/bank/account.php3
@@ -28,62 +28,80 @@
 require("./pre.inc.php3");
 
 require("./bank.lib.php3");
-llxHeader();
-$db = new Db();
-
 
+$db = new Db();
 
-if ($account) {
-
-  if ($action == 'add') {
-    $author = $GLOBALS["REMOTE_USER"];
-    if ($credit > 0) {
+if ($HTTP_POST_VARS["action"] == 'add' && $account)
+{
+    
+  if ($credit > 0)
+    {
       $amount = $credit ;
-    } else {
-    $amount = - $debit ;
     }
-
-    $dateop = "$dateoy" . "$dateo";
-    
-    if ($num_chq) {
+  else
+    {
+      $amount = - $debit ;
+    }
+  
+  $dateop = "$dateoy" . "$dateo";
+  
+  if ($num_chq)
+    {
       $sql = "INSERT INTO llx_bank (datec, dateo, label, amount, author, num_chq,fk_account, fk_type)";
       $sql .= " VALUES (now(), $dateop, '$label', $amount,'$author',$num_chq,$account,'$operation')";
-    } else {
+    }
+  else
+    {
       $sql = "INSERT INTO llx_bank (datec, dateo, label, amount, author,fk_account,fk_type)";
       $sql .= " VALUES (now(), $dateop, '$label', $amount,'$author',$account,'$operation')";
     }
-
-    $result = $db->query($sql);
-    if ($result) {
+  
+  $result = $db->query($sql);
+  if ($result)
+    {
       $rowid = $db->last_insert_id();
-      if ($cat1) {
-	$sql = "INSERT INTO llx_bank_class (lineid, fk_categ) VALUES ($rowid, $cat1)";
-	$result = $db->query($sql);
-      }
-    } else {
+      if ($cat1)
+	{
+	  $sql = "INSERT INTO llx_bank_class (lineid, fk_categ) VALUES ($rowid, $cat1)";
+	  $result = $db->query($sql);
+	}
+      Header("Location: $PHP_SELF?account=$account");
+    }
+  else
+    {
       print $db->error();
       print "<p>$sql";
     }
-    
-  }
-  if ($action == 'del') {
-    bank_delete_line($db, $rowid);
-  }
+  
+}
+if ($action == 'del' && $account)
+{
+  bank_delete_line($db, $rowid);
+}
 
-  if ($vline) {
-    $viewline = $vline;
-  } else {
-    $viewline = 20;
-  }
 
-  print "<b>Bank</b> - <a href=\"$PHP_SELF\">Reload</a>&nbsp;-";
+llxHeader();
+
+if ($account)
+{
+
+  if ($vline)
+    {
+      $viewline = $vline;
+    }
+  else
+    {
+      $viewline = 20;
+    }
+
+  print "<b>Bank</b> - &nbsp;-";
   print "<a href=\"$PHP_SELF?viewall=1&account=$account\">Voir tout</a>";
   
   print "<form method=\"post\" action=\"$PHP_SELF?viewall=$viewall&vline=$vline&account=$account\">";
   print "<input type=\"hidden\" name=\"action\" value=\"add\">";
   print "<TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">";
   print "<TR class=\"liste_titre\">";
-  print "<td>Date</td><td>chq</td><td>Description</TD>";
+  print "<td>Date</td><td>Type</td><td>Description</TD>";
   print "<td align=\"right\">Debit</TD>";
   print "<td align=\"right\">Credit</TD>";
   print "<td align=\"right\">Solde</TD>";
@@ -93,30 +111,36 @@ if ($account) {
   
   $sql = "SELECT count(*) FROM llx_bank";
   if ($account) { $sql .= " WHERE fk_account=$account"; }
-  if ( $db->query($sql) ) {
-    $nbline = $db->result (0, 0);
-    $db->free();
+  if ( $db->query($sql) )
+    {
+      $nbline = $db->result (0, 0);
+      $db->free();
     
-    if ($nbline > $viewline ) {
-      $limit = $nbline - $viewline ;
-    } else {
-      $limit = $viewline;
+      if ($nbline > $viewline )
+	{
+	  $limit = $nbline - $viewline ;
+	}
+      else
+	{
+	  $limit = $viewline;
+	}
     }
-  }
   
   $sql = "SELECT rowid, label FROM llx_bank_categ;";
   $result = $db->query($sql);
-  if ($result) {
-    $var=True;  
-    $num = $db->num_rows();
-    $i = 0;
-    $options = "<option value=\"0\" SELECTED></option>";
-    while ($i < $num) {
-      $obj = $db->fetch_object($i);
-      $options .= "<option value=\"$obj->rowid\">$obj->label</option>\n"; $i++;
+  if ($result)
+    {
+      $var=True;  
+      $num = $db->num_rows();
+      $i = 0;
+      $options = "<option value=\"0\" SELECTED></option>";
+      while ($i < $num)
+	{
+	  $obj = $db->fetch_object($i);
+	  $options .= "<option value=\"$obj->rowid\">$obj->label</option>\n"; $i++;
+	}
+      $db->free();
     }
-    $db->free();
-  }
   
   
   if ($viewall) { $nbline=0; }
@@ -128,128 +152,157 @@ if ($account) {
 
   $sql = "SELECT b.rowid,".$db->pdate("b.dateo")." as do, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type";
   $sql .= " FROM llx_bank as b "; if ($account) { $sql .= " WHERE fk_account=$account"; }
-  if ($vue) {
-    if ($vue == 'credit') {
-      $sql .= " AND b.amount >= 0 ";
-    } else {
-      $sql .= " AND b.amount < 0 ";
-  }
-  }
+  if ($vue)
+    {
+      if ($vue == 'credit')
+	{
+	  $sql .= " AND b.amount >= 0 ";
+	}
+      else
+	{
+	  $sql .= " AND b.amount < 0 ";
+	}
+    }
   $sql .= " ORDER BY b.dateo ASC";
   
   $result = $db->query($sql);
-  if ($result) {
-    $var=True;  
-    $num = $db->num_rows();
-    $i = 0; $total = 0;
-  
-    $sep = 0;
-  
-    while ($i < $num) {
-      $objp = $db->fetch_object( $i);
-      $total = $total + $objp->amount;
-      $time = time();
-      if ($i > ($nbline - $viewline)) {
-
-	if (!$psol) {
-	  print "<tr $bc[$var]><td colspan=\"4\">&nbsp;</td>";
-	  print "<td align=\"right\">".price($total)."</b></td>";
-	  print "<td align=\"right\">".francs($total)."</td>\n";
-	  print '<td colspan="2">&nbsp;</td></tr>';
-	  $psol = 1;
-
-	} else {
-	  $var=!$var;
-
-	  if ($objp->do > $time && !$sep) {
-	    $sep = 1 ;
-	    print "<tr><td align=\"right\" colspan=\"5\">Total :</td>";
-	    print "<td align=\"right\"><b>".price($total - $objp->amount)."</b></td>";
-	    print "<td></td>";
-	    print '<td align="right"><small>'.francs($total - $objp->amount).'</small></td>';
-	    print '</tr><tr>';
-	    print '<td><input name="dateoy" type="text" size="4" value="'.strftime("%Y",time()).'" maxlength="4">';
-	    print '<input name="dateo" type="text" size="4" maxlength="4"></td>';
-	    print '<td></td>';
-	    print "<td>CHQ<input name=\"num_chq\" type=\"text\" size=4>&nbsp;-";
-	    print "<input name=\"label\" type=\"text\" size=40></td>";
-	    print "<td><input name=\"debit\" type=\"text\" size=8></td>";
-	    print "<td><input name=\"credit\" type=\"text\" size=8></td>";
-	    print "<td colspan=\"3\" align=\"center\"><select name=\"cat1\">$options</select></td>";
-	    print "</tr><tr><td colspan=\"3\"><small>YYYYMMDD</small></td><td>0000.00</td>";
-	    print '<td colspan="4" align="center"><input type="submit" value="ajouter"></td></tr>';
-	  }
-
-	  print "<tr $bc[$var]>";
-	  print "<td>".strftime("%d %b %y",$objp->do)."</TD>\n";
-	  print "<td>".$objp->fk_type."</TD>\n";
-
-	  if ($objp->num_chq) {
-	    print "<td>CHQ $objp->num_chq - $objp->label</td>";
-	  } else {
-	    print "<td>$objp->label&nbsp;</td>";
-	  }
-
-	  if ($objp->amount < 0) {
-	    print "<td align=\"right\">".price($objp->amount * -1)."</TD><td>&nbsp;</td>\n";
-	  } else {
-	    print "<td>&nbsp;</td><td align=\"right\">".price($objp->amount)."</TD>\n";
-	  }
-	
-	  if ($total > 0) {
-	    print "<td align=\"right\">".price($total)."</TD>\n";
-	  } else {
-	    print "<td align=\"right\"><b>".price($total)."</b></TD>\n";
-	  }
-
-	  if ($objp->rappro) {
-	    print "<td align=\"center\"><a href=\"releve.php3?num=$objp->num_releve&account=$account\">$objp->num_releve</a></td>";
-	  } else {
-	    print "<td align=\"center\"><a href=\"$PHP_SELF?action=del&rowid=$objp->rowid&account=$account\">[Del]</a></td>";
-	  }
-
-	  print "<td align=\"right\"><small>".francs($objp->amount)."</small></TD>\n";
-
-	  print "</tr>";
-
+  if ($result)
+    {
+      $var=True;  
+      $num = $db->num_rows();
+      $i = 0; $total = 0;
+      
+      $sep = 0;
+      
+      while ($i < $num)
+	{
+	  $objp = $db->fetch_object( $i);
+	  $total = $total + $objp->amount;
+	  $time = time();
+	  if ($i > ($nbline - $viewline))
+	    {
+
+	      if (!$psol)
+		{
+		  print "<tr $bc[$var]><td colspan=\"4\">&nbsp;</td>";
+		  print "<td align=\"right\">".price($total)."</b></td><td>&nbsp;</td>";
+		  print "<td align=\"right\">".francs($total)."</td>\n";
+		  print '<td colspan="2">&nbsp;</td></tr>';
+		  $psol = 1;
+		  
+		}
+	      else
+		{
+		  $var=!$var;
+
+		  if ($objp->do > $time && !$sep)
+		    {
+		      $sep = 1 ;
+		      print "<tr><td align=\"right\" colspan=\"5\">&nbsp;</td>";
+		      print "<td align=\"right\"><b>".price($total - $objp->amount)."</b></td>";
+		      print "<td>&nbsp;</td>";
+		      print '<td align="right"><small>'.francs($total - $objp->amount).'</small></td>';
+		      print '</tr><tr>';
+		      print '<td><input name="dateoy" type="text" size="4" value="'.strftime("%Y",time()).'" maxlength="4">';
+		      print '<input name="dateo" type="text" size="4" maxlength="4"></td>';
+		      print '<td></td>';
+		      print "<td>CHQ<input name=\"num_chq\" type=\"text\" size=4>&nbsp;-";
+		      print "<input name=\"label\" type=\"text\" size=40></td>";
+		      print "<td><input name=\"debit\" type=\"text\" size=8></td>";
+		      print "<td><input name=\"credit\" type=\"text\" size=8></td>";
+		      print "<td colspan=\"3\" align=\"center\"><select name=\"cat1\">$options</select></td>";
+		      print "</tr><tr><td colspan=\"3\"><small>YYYYMMDD</small></td><td>0000.00</td>";
+		      print '<td colspan="4" align="center"><input type="submit" value="ajouter"></td></tr>';
+		    }
+		  
+		  print "<tr $bc[$var]>";
+		  print "<td>".strftime("%d %b %y",$objp->do)."</TD>\n";
+		  print "<td>".$objp->fk_type."</TD>\n";
+		  
+		  if ($objp->num_chq)
+		    {
+		      print "<td>CHQ $objp->num_chq - $objp->label</td>";
+		    }
+		  else
+		    {
+		      print "<td>$objp->label&nbsp;</td>";
+		    }
+
+		  if ($objp->amount < 0)
+		    {
+		      print "<td align=\"right\">".price($objp->amount * -1)."</TD><td>&nbsp;</td>\n";
+		    }
+		  else
+		    {
+		      print "<td>&nbsp;</td><td align=\"right\">".price($objp->amount)."</TD>\n";
+		    }
+		  
+		  if ($total > 0)
+		    {
+		      print "<td align=\"right\">".price($total)."</TD>\n";
+		    }
+		  else
+		    {
+		      print "<td align=\"right\"><b>".price($total)."</b></TD>\n";
+		    }
+
+		  if ($objp->rappro)
+		    {
+		      print "<td align=\"center\"><a href=\"releve.php3?num=$objp->num_releve&account=$account\">$objp->num_releve</a></td>";
+		    }
+		  else
+		    {
+		      print "<td align=\"center\"><a href=\"$PHP_SELF?action=del&rowid=$objp->rowid&account=$account\">[Del]</a></td>";
+		    }
+		  
+		  print "<td align=\"right\"><small>".francs($objp->amount)."</small></TD>\n";
+		  
+		  print "</tr>";
+		  
+		}
+	    }
+	  
+	  
+	  $i++;
 	}
-      }
-
-
-      $i++;
+      $db->free();
     }
-    $db->free();
-  }
-
-  if ($sep) {
-    print "<tr><td align=\"right\" colspan=\"5\">Total :</td>";
-    print "<td align=\"right\"><b>".price($total)."</b></td><td align=\"right\">".francs($total)."</td></tr>\n";
-  } else {
-
-    print "<tr><td align=\"right\" colspan=\"5\">Total :</td>";
-    print "<td align=\"right\"><b>".price($total)."</b></td><td align=\"right\">".francs($total)."</td></tr>\n";
-    print "<tr>";
-    print '<td><input name="dateoy" type="text" size="4" value="'.strftime("%Y",time()).'" maxlength="4">';
-    print '<input name="dateo" type="text" size="4" maxlength="4"></td>';
-    print "<td>";
-
-    print '<select name="operation">';
-    print '<option value="CB">CB';
-    print '<option value="CHQ">CHQ';
-    print '<option value="DEP">DEP';
-    print '<option value="TIP">TIP';
-    print '<option value="PRE">PRE';
-    print '<option value="VIR">VIR';
-    print '</select></td>';
-    print "<td><input name=\"num_chq\" type=\"text\" size=4>";
-    print "<input name=\"label\" type=\"text\" size=40></td>";
-    print "<td><input name=\"debit\" type=\"text\" size=8></td>";
-    print "<td><input name=\"credit\" type=\"text\" size=8></td>";
-    print "<td colspan=\"2\" align=\"center\"><select name=\"cat1\">$options</select></td>";
-    print '</tr><tr><td colspan="2"><small>YYYYMMDD</small></td><td>0000.00</td>';
-
-    print '<td colspan="4" align="center"><input type="submit" value="ajouter"></td></tr>';
-
+  /*
+   * Op�rations futures
+   *
+   */
+  if ($sep)
+    {
+      print "<tr><td align=\"right\" colspan=\"5\">&nbsp;</td>";
+      print "<td align=\"right\"><b>".price($total)."</b></td><td>&nbsp;</td><td align=\"right\">".francs($total)."</td></tr>\n";
+    }
+  else
+    {
+
+      print "<tr><td align=\"right\" colspan=\"5\">&nbsp;</td>";
+      print "<td align=\"right\"><b>".price($total)."</b></td><td>&nbsp;</td><td align=\"right\">".francs($total)."</td></tr>\n";
+      print "<tr>";
+      print '<td><input name="dateoy" type="text" size="4" value="'.strftime("%Y",time()).'" maxlength="4">';
+      print '<input name="dateo" type="text" size="4" maxlength="4"></td>';
+      print "<td>";
+      
+      print '<select name="operation">';
+      print '<option value="CB">CB';
+      print '<option value="CHQ">CHQ';
+      print '<option value="DEP">DEP';
+      print '<option value="TIP">TIP';
+      print '<option value="PRE">PRE';
+      print '<option value="VIR">VIR';
+      print '</select></td>';
+      print "<td><input name=\"num_chq\" type=\"text\" size=4>";
+      print "<input name=\"label\" type=\"text\" size=40></td>";
+      print "<td><input name=\"debit\" type=\"text\" size=8></td>";
+      print "<td><input name=\"credit\" type=\"text\" size=8></td>";
+      print "<td colspan=\"3\" align=\"center\"><select name=\"cat1\">$options</select></td>";
+      print '</tr><tr><td colspan="2"><small>YYYYMMDD</small></td><td>0000.00</td>';
+      
+      print '<td colspan="4" align="center"><input type="submit" value="ajouter"></td></tr>';
+      
   }
 
   print "</table></form>";
diff --git a/htdocs/compta/bank/config.php3 b/htdocs/compta/bank/config.php3
index 32a3c1b1244..ca46563a09f 100644
--- a/htdocs/compta/bank/config.php3
+++ b/htdocs/compta/bank/config.php3
@@ -25,14 +25,6 @@ require("./bank.lib.php3");
 llxHeader();
 $db = new Db();
 
-if ($action == 'add')
-{
-  $author = $GLOBALS["REMOTE_USER"];
-  
-  $sql = "INSERT INTO llx_bank_account (label, number, bank) VALUES ('$label','$number','$bank')";
-  $result = $db->query($sql);
-}
-
 print_titre("Configuration");
 
 print "<TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">";
@@ -55,7 +47,7 @@ if ($result) {
     $objp = $db->fetch_object( $i);
 
 
-    print "<tr><td>$objp->rowid</td><td>$objp->label</td><td>$objp->bank</td><td>$objp->number</td></tr>";
+    print "<tr><td>$objp->rowid</td><td><a href=\"fiche.php?id=$objp->rowid\">$objp->label</a></td><td>$objp->bank</td><td>$objp->number</td></tr>";
 
 
     $i++;
@@ -63,16 +55,27 @@ if ($result) {
   $db->free();
 }
 print "</table>";
-echo '<br><br>';
-print "<form method=\"post\" action=\"$PHP_SELF?viewall=$viewall&vline=$vline\">";
-print "<input type=\"hidden\" name=\"action\" value=\"add\">";
-print "<TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">";
-echo '<tr><td>Label&nbsp;:&nbsp;<input type="text" name="label"></td>';
-echo '<td>Bank&nbsp;:&nbsp;<input type="text" name="bank"></td>';
-echo '<td>Number&nbsp;:&nbsp;<input type="text" name="number"></td>';
-echo '<td><input type="submit" value="ajouter"></td></tr>';
 
-print "</table></form>";
+
+print "<p><TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\"><tr>";
+
+/*
+ * Case 1
+ */
+
+print "<td align=\"center\" width=\"25%\">";
+print '<a href="fiche.php?action=create">Nouveau compte</a></td>';	
+/*
+ * Case 2
+ */
+
+print "<td align=\"center\" width=\"25%\">-</td>";
+print "<td align=\"center\" width=\"25%\">-</td>";
+print "<td align=\"center\" width=\"25%\">-</td>";
+
+print "</table>";
+
+
 
 
 $db->close();
diff --git a/htdocs/compta/bank/fiche.php b/htdocs/compta/bank/fiche.php
new file mode 100644
index 00000000000..83c841119fd
--- /dev/null
+++ b/htdocs/compta/bank/fiche.php
@@ -0,0 +1,220 @@
+<?PHP
+/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ * $Source$
+ */
+
+require("./pre.inc.php3");
+
+llxHeader();
+
+$db = new Db();
+
+if ($HTTP_POST_VARS["action"] == 'add')
+{
+  $account = new Account($db,0);
+
+  $account->bank         = $HTTP_POST_VARS["bank"];
+  $account->label        = $HTTP_POST_VARS["label"];
+
+  $account->courant      = $HTTP_POST_VARS["courant"];
+
+  $account->code_banque  = $HTTP_POST_VARS["code_banque"];
+  $account->code_guichet = $HTTP_POST_VARS["code_guichet"];
+  $account->number       = $HTTP_POST_VARS["number"];
+  $account->cle_rib      = $HTTP_POST_VARS["cle_rib"];
+  $account->bic          = $HTTP_POST_VARS["bic"];
+
+  $id = $account->create($user->id);
+
+}
+
+if ($action == 'update')
+{
+  $account = new User($db, $id);
+  $account->fetch();
+
+  $account->nom = $nom;
+  $account->prenom = $prenom;
+  $account->login = $login;
+  $account->email = $email;
+
+  if (! $account->update($id, $user))
+    {
+      print $account->error();
+    }
+}
+
+
+
+/* ************************************************************************** */
+/*                                                                            */
+/* Nouvel compte                                                              */
+/*                                                                            */
+/* ************************************************************************** */
+
+if ($action == 'create')
+{
+
+  print '<div class="titre">Nouveau compte bancaire</div><br>';
+  print '<p><form action="'.$PHP_SELF.'" method="post">';
+  print '<input type="hidden" name="action" value="add">';
+
+  print '<table border="1" cellpadding="3" cellspacing="0">';
+
+  print '<tr><td valign="top">Banque</td>';
+  print '<td colspan="3"><input size="30" type="text" name="bank" value=""></td></tr>';
+
+  print '<tr><td valign="top">Libell�</td>';
+  print '<td colspan="3"><input size="30" type="text" name="label" value=""></td></tr>';
+
+  print '<tr><td>Code Banque</td><td>Code Guichet</td><td>Num�ro</td><td>Cl� RIB</td></tr>';
+  print '<tr><td><input size="8" type="text" name="code_banque"></td>';
+  print '<td><input size="8" type="text" name="code_guichet"></td>';
+  print '<td><input size="15" type="text" name="number"></td>';
+  print '<td><input size="3" type="text" name="cle_rib"></td></tr>';
+  
+  print '<tr><td valign="top">Cl� IBAN</td>';
+  print '<td colspan="3"><input size="5" type="text" name="iban" value=""></td></tr>';
+
+  print '<tr><td valign="top">Identifiant BIC</td>';
+  print '<td colspan="3"><input size="12" type="text" name="bic" value=""></td></tr>';
+
+  print '<tr><td valign="top">Compte Courant</td>';
+  print '<td colspan="3"><select name="courant">';
+  print '<option value="0">non<option value="1">oui</select></td></tr>';
+
+  print '<tr><td valign="top">Description</td><td colspan="3">';
+  print "<textarea name=\"desc\" rows=\"12\" cols=\"40\">";
+  print $user->description;
+  print "</textarea></td></tr>";
+      
+  print '<tr><td align="center" colspan="4"><input value="Enregistrer" type="submit"></td></tr>';
+  print '</form>';
+  print '</table>';
+}
+/* ************************************************************************** */
+/*                                                                            */
+/* Visu et edition                                                            */
+/*                                                                            */
+/* ************************************************************************** */
+else
+{
+  if ($id) 
+    {
+      $account = new Account($db, $id);
+      $account->fetch($id);
+
+      print '<div class="titre">Compte bancaire</div><br>';
+
+      print '<table border="1" cellpadding="3" cellspacing="0">';
+      
+      print '<tr><td valign="top">Banque</td>';
+      print '<td colspan="3">'.$account->bank.'</td></tr>';
+
+      print '<tr><td valign="top">Libell�</td>';
+      print '<td colspan="3">'.$account->label.'</td></tr>';
+
+      print '<tr><td>Code Banque</td><td>Code Guichet</td><td>Num�ro</td><td>Cl� RIB</td></tr>';
+      print '<tr><td>'.$account->code_banque.'</td>';
+      print '<td>'.$account->code_guichet.'</td>';
+      print '<td>'.$account->number.'</td>';
+      print '<td>'.$account->cle_rib.'</td></tr>';
+      
+      print '<tr><td valign="top">Cl� IBAN</td>';
+      print '<td colspan="3"><input size="5" type="text" name="iban" value=""></td></tr>';
+      
+      print '<tr><td valign="top">Identifiant BIC</td>';
+      print '<td colspan="3"><input size="12" type="text" name="bic" value=""></td></tr>';
+      
+      print '<tr><td valign="top">Compte Courant</td>';
+      print '<td colspan="3"><select name="courant">';
+      print '<option value="0">non<option value="1">oui</select></td></tr>';
+            
+      
+      print '<tr><td align="center" colspan="4"><input value="Enregistrer" type="submit"></td></tr>';
+      
+      print '</table>';
+
+      print '<br><table width="100%" border="1" cellspacing="0" cellpadding="2">';
+
+      if ($user->admin) 
+	{
+	  print '<td width="25%" bgcolor="#e0E0E0" align="center">[<a href="fiche.php3?action=edit&id='.$id.'">Editer</a>]</td>';
+	}
+      else
+	{
+	  print '<td width="25%" align="center">-</td>';
+	}
+
+      print '<td width="25%" align="center">-</td>';
+      print '<td width="25%" align="center">-</td>';
+      print '<td width="25%" align="center">-</td>';
+      
+
+      print '</table><br>';
+
+      /* ************************************************************************** */
+      /*                                                                            */
+      /* Edition                                                                    */
+      /*                                                                            */
+      /* ************************************************************************** */
+      
+      if ($action == 'edit' && $user->admin) 
+	{
+	  print '<hr><div class="titre">Edition de l\'utilisateur</div><br>';
+	  print '<form action="'.$PHP_SELF.'?id='.$id.'" method="post">';
+	  print '<input type="hidden" name="action" value="update">';
+	  print '<table border="1" cellpadding="3" cellspacing="0">';
+	  
+	  print '<tr><td valign="top">Id</td>';
+	  print '<td>'.$fuser->id.'</td></tr>';
+	  
+	  print '<tr><td valign="top">Nom</td>';
+	  print '<td><input size="30" type="text" name="nom" value="'.$fuser->nom.'"></td></tr>';
+	  
+	  print '<tr><td valign="top">Pr�nom</td>';
+	  print '<td><input size="20" type="text" name="prenom" value="'.$fuser->prenom.'"></td></tr>';
+	  
+	  print '<tr><td valign="top">Login</td>';
+	  print '<td><input size="10" maxlength="8" type="text" name="login" value="'.$fuser->login.'"></td></tr>';
+	  
+	  print '<tr><td valign="top">Email</td>';
+	  print '<td><input size="30" type="text" name="email" value="'.$fuser->email.'"></td></tr>';
+	  
+	  
+	  print '<tr><td valign="top">Description</td><td>';
+	  print "<textarea name=\"desc\" rows=\"12\" cols=\"40\">";
+	  print $fuser->description;
+	  print "</textarea></td></tr>";
+	  
+	  print '<tr><td align="center" colspan="2"><input value="Enregistrer" type="submit"></td></tr>';
+	  print '</form>';
+	  print '</table>';
+	}
+            
+    }
+  
+}
+
+
+
+$db->close();
+
+llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
+?>
diff --git a/htdocs/cyberpaiement.class.php b/htdocs/cyberpaiement.class.php
new file mode 100644
index 00000000000..3abe67cc6b8
--- /dev/null
+++ b/htdocs/cyberpaiement.class.php
@@ -0,0 +1,234 @@
+<?PHP
+/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ * $Source$
+ *
+ */
+
+class Cyberpaiement
+{
+
+  Function Cyberpaiement($conf) 
+    /*
+     *   Initialisation des valeurs par d�faut
+     */
+  {
+
+    /* Num�ro abonn� Internet : 6 chiffres */
+    
+    $this->champ000 = $conf->bplc->numabonne;
+    
+    /* Code activit� commercant : 4 chiffres */
+      
+    $this->champ001 = $conf->bplc->code_activite;
+
+    /* Num�ro de contrat : 10 chiffres */
+      
+    $this->champ002 = $conf->bplc->num_contrat;
+      
+    /* Type de paiement */
+        
+    $this->champ003 = $conf->bplc->typepaiement;
+      
+    /* Nom du serveur commercant, champ purement informatif */
+      
+    $this->champ004 = trim($conf->bplc->nom_serveur);
+    
+    /* Url du CGI de retour */
+    
+    $this->champ005 = $conf->bplc->cgi_retour;
+    
+    /* Nom du commercant */
+    
+    $this->champ006 = $conf->bplc->nom_commercant;
+      
+    /* url retour */
+    
+    $this->champ007 = $conf->bplc->url_retour;
+      
+    /* Email confirmation commercant*/
+    
+    $this->champ008 = trim($conf->bplc->email_commercant);
+    
+    /* Devise : EUR*/
+      
+    $this->champ202 = $conf->bplc->devise;
+    
+    /* Adh�rent : 01 */
+    
+    $this->champ900 = $conf->bplc->adherent;
+    
+
+    /* *********************************************** */
+    /* Initialisation � vide des valeurs qui ne seront */
+    /* pas transmises                                  */
+    /* *********************************************** */
+
+    $this->champ100 = ".";
+    $this->champ101 = ".";
+    $this->champ102 = ".";    
+    $this->champ103 = ".";
+    $this->champ104 = ".";
+    $this->champ106 = ".";
+    $this->champ107 = ".";
+    $this->champ108 = ".";
+    $this->champ109 = ".";
+    $this->champ110 = ".";
+
+
+  }
+
+  /* ********************** */
+  /*                        */
+  /* Client                 */
+  /*                        */
+  /* ********************** */
+
+  Function set_client($nom,$prenom,$email,$societe='')
+  {          
+    /* Nom */
+    
+    $this->champ100 = $nom;
+    
+    /* Prenom */
+    
+    $this->champ101 = $prenom;
+    
+    /* Soci�t� */
+    if (strlen(trim($societe)))
+      {
+	$this->champ102 = $societe;
+      }
+    /* T�l�phone */
+    if (strlen(trim($telephone)))
+      {
+	$this->champ103 = $telephone;
+      }
+    
+    /* Adresse email */
+    
+    $this->champ104 = trim($email);
+    
+    /* Fax */
+    if (strlen(trim($fax)))
+      {
+	$this->champ106 = $fax;
+      }
+    
+    /* Adresse num�ro et rue */
+    if (strlen(trim($adresse)))
+      {
+	$this->champ107 = $adresse;
+      }
+    
+    /* Ville */
+    if (strlen(trim($ville)))
+      {
+	$this->champ108 = $ville;
+      }
+    
+    /* Code Postal */
+    if (strlen(trim($cp)))
+      {
+	$this->champ109 = trim($cp);
+      }
+    
+    /* Code Pays : purement Informatif */
+    if (strlen(trim($pays)))
+      {
+	$this->champ110 = trim($pays);
+      }
+  }
+  /* ********************** */
+  /*                        */
+  /* Commande               */
+  /*                        */
+  /* ********************** */
+  
+  Function set_commande($ref, $montant)
+  {          
+    /* R�f�rence */
+    
+    $this->champ200 = $ref;
+    
+    /* Montant */
+    
+    $this->champ201 = $montant;         
+  }
+  /*
+   *
+   *
+   *
+   */
+  Function print_hidden()
+  {
+      print '<input type="hidden" name="CHAMP000" value="'.$this->champ000.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP001" value="'.$this->champ001.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP002" value="'.$this->champ002.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP003" value="'.$this->champ003.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP004" value="'.$this->champ004.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP005" value="'.$this->champ005.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP006" value="'.$this->champ006.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP007" value="'.$this->champ007.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP008" value="'.$this->champ008.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP100" value="'.$this->champ100.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP101" value="'.$this->champ101.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP102" value="'.$this->champ102.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP103" value="'.$this->champ103.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP104" value="'.$this->champ104.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP106" value="'.$this->champ106.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP107" value="'.$this->champ107.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP108" value="'.$this->champ108.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP109" value="'.$this->champ109.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP110" value="'.$this->champ110.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP200" value="'.$this->champ200.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP201" value="'.$this->champ201.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP202" value="'.$this->champ202.'">';
+      print "\n";
+      print '<input type="hidden" name="CHAMP900" value="'.$this->champ900.'">';
+      print "\n";
+  }
+  /*
+   *
+   *
+   *
+   */
+
+}
+?>
diff --git a/htdocs/public/dons/testretour.php b/htdocs/public/dons/testretour.php
index 30773b6c58c..7edf05fe535 100644
--- a/htdocs/public/dons/testretour.php
+++ b/htdocs/public/dons/testretour.php
@@ -23,14 +23,16 @@
 <form action="bplc.php" method="post">
 
 <input type="hidden" name="CHAMP105" value="80.64.52.12">
-<input type="hidden" name="CHAMP901" value="590165">
-<input type="hidden" name="CHAMP902" value="20021222">
+<input type="hidden" name="CHAMP901" value="7654321">
+<input type="hidden" name="CHAMP902" value="20202022">
 <input type="hidden" name="CHAMP903" value="023252">
 <input type="hidden" name="CHAMP904" value="05423252">
-<input type="hidden" name="CHAMP905" value="Y2154">
+<input type="hidden" name="CHAMP905" value="Y4768">
 <input type="hidden" name="CHAMP906" value="0000">
 
-<input type="hidden" name="CHAMP200" value="0000DGFEZ2">
+<input type="hidden" name="CHAMP002" value="1234567890">
+<input type="hidden" name="CHAMP200" value="123456789012345">
+<input type="hidden" name="CHAMP201" value="200">
 
 <input type="submit" value="Test Retour">
 </form>
diff --git a/htdocs/retourbplc.class.php b/htdocs/retourbplc.class.php
index 5eda2b0ef0c..cc97b880fc9 100644
--- a/htdocs/retourbplc.class.php
+++ b/htdocs/retourbplc.class.php
@@ -26,6 +26,10 @@ class Retourbplc
   var $db;
 
   var $ipclient;
+  var $montant;
+  var $num_compte;
+  var $ref_commande;
+  var $num_contrat;
   var $num_transaction;
   var $date_transaction;
   var $heure_transaction;
@@ -49,30 +53,228 @@ class Retourbplc
   Function insertdb()
   {
 
-    $sql = "INSERT INTO transaction_bplc";
-    $sql .= " (  ipclient, num_transaction, date_transaction, heure_transaction, num_autorisation, cle_acceptation, code_retour, ref_commande)";
-    $sql .= " VALUES ('$this->ipclient','$this->num_transaction','$this->date_transaction','$this->heure_transaction','$this->num_autorisation','$this->cle_acceptation','$this->code_retour','$this->ref_commande')";
+    if ($this->check_key($this->cle_acceptation))
+      {
 
-    $result = $this->db->query($sql);
-      
-    if ($result) 
+	$sql = "INSERT INTO transaction_bplc";
+	$sql .= " (ipclient, 
+                   num_transaction, 
+                   date_transaction, 
+                   heure_transaction, 
+                   num_autorisation, 
+                   cle_acceptation, 
+                   code_retour, 
+                   ref_commande)";
+    
+	$sql .= " VALUES ('$this->ipclient',
+                          '$this->num_transaction',
+                          '$this->date_transaction',
+                          '$this->heure_transaction',
+                          '$this->num_autorisation',
+                          '$this->cle_acceptation',
+                          '$this->code_retour',
+                          '$this->ref_commande')";
+
+	$result = $this->db->query($sql);
+	
+	if ($result) 
+	  {
+	    return 1;
+	  }
+	else
+	  {
+	    print $this->db->error();
+	    print "<h2><br>$sql<br></h2>";
+	    return 0;
+	  }         
+      } 
+  }
+  /*
+   *
+   *
+   *
+   */
+  Function check_key($key)
+  {
+
+    $A = $this->montant;
+    $B = $this->num_contrat;
+    $C = $this->num_transaction;
+    $D = $this->ref_commande;
+    $E = $this->num_compte;
+
+    /*
+     * Etape 1
+     *
+     */
+    $A1 = $A . $E;
+    $B1 = $B . $E;
+    $C1 = $C . $E;
+    $D1 = $D . $E;
+
+    $map = range(0, 9);
+
+    $L1= $this->cle_luhn($A1, $map);
+
+    $L2= $this->cle_luhn($B1, $map);
+
+    $L3= $this->cle_luhn($C1, $map);
+
+    $L4= $this->cle_luhn($D1, $map);
+    /*
+     * Etape 2
+     *
+     */
+
+    $N1 = $L1 . $L2 . $L3 . $L4;
+    $N0 = $L1 + $L2 + $L3 + $L4;
+
+    $C5 = $this->corres($N0);
+    /*
+     * Comparaison
+     *
+     */
+
+    if ($key == $this->calcul_pos($N1,$N0, $C5))
       {
 	return 1;
       }
-    else
+    else 
       {
-	print $this->db->error();
-	print "<h2><br>$sql<br></h2>";
 	return 0;
-      }         
+      }
   }
+  /*
+   *
+   *
+   */
+  Function corres($value)
+  {
+    $map[0] = 0;
+
+    for ($i = 65 ; $i < 91 ; $i++)
+      {
+	$map[$i-64] = chr($i);
+      }
+
+    for ($i = 0 ; $i < 10 ; $i++)
+      {
+	$map[27+$i] = $i;
+      }
 
+    return $map[$value];
 
+  }
   /*
    *
    *
    *
+   *
    */
+  Function cle_luhn($cle, $map)
+  {
+    $buffer = $this->array_reverse($cle);
+ 
+    $totalVal = 0;
+    $flip = 1;
+ 
+    reset ($buffer);
+
+    while (list($key, $posVal) = each ($buffer))
+      {
 
+	if (!isset($map[$posVal])){
+	  return FALSE;
+	}
+
+	$posVal = $map[$posVal];
+
+	if ( $flip = !$flip)
+	  {
+	    $posVal *= 2;
+	  }
+      
+	while ($posVal>0)
+	  {
+	    $totalVal += $posVal % 10;
+	    $posVal = floor($posVal / 10);
+	  }
+    }
+
+    return substr($totalVal, strlen($totalVal)-1, 1);
+  }
+  /*
+   * Postion de C5 dans N0
+   *
+   *
+   */
+  Function calcul_pos($N1, $N0, $C5)
+  {
+    if ($N0 >= 0 && $N0 <= 6)
+      {
+	/* cl� = 2 premiers de N0 . C5 . 2 derniers de N0 */
+
+	$cle = substr($N1,0,2) . $C5 . substr($N1,2,2);
+
+      }
+    elseif ($N0 >= 7 && $N0 <= 14)
+      {
+	/* cl� = 4 premiers de N0 . C5 */
+
+	$cle = substr($N1,0,4) . $C5;
+
+      }
+    elseif ($N0 >= 15 && $N0 <= 21)
+      {
+	/* cl� = premier de N1 . C5 . 3 derniers de N1 */
+
+	$cle = substr($N1,0,1) . $C5 . substr($N1,1,3);
+
+      }
+    elseif ($N0 >= 22 && $N0 <= 29)
+      {
+	/* cl� = C5 . 4 derniers de N1 */
+
+	$cle = $C5 . substr($N1,0,4);
+
+      }
+    elseif ($N0 >= 30 && $N0 <= 36)
+      {
+	/* cl� = 3 premiers de N1 . C5 . dernier de N1 */
+
+	$cle = substr($N1,0,3) . $C5 . substr($N1,1,1);
+
+      }
+    else
+      {
+	$cle = "ERREUR";
+      }
+
+    return $cle;
+
+  }
+  /*
+   * Retournement du tableau
+   *
+   *
+   */
+  Function array_reverse($string)
+  {
+
+    $len = strlen($string);
+
+    $i = $len;
+    $j = 0;
+    $rever = array();
+    while ($i > 0)
+      {
+	$rever[$j]= substr($string, $i-1, 1);
+	$i = $i - 1;
+	$j = $j + 1;
+      }
+
+
+    return $rever;
+  }
 }
 ?>
diff --git a/mysql/tables/llx_bank_account.sql b/mysql/tables/llx_bank_account.sql
index 8e7a9e46bc0..473a10cf9b9 100644
--- a/mysql/tables/llx_bank_account.sql
+++ b/mysql/tables/llx_bank_account.sql
@@ -23,12 +23,14 @@
 create table llx_bank_account
 (
   rowid          integer AUTO_INCREMENT PRIMARY KEY,
+  datec          datetime,
+  tms            timestamp,
   label          varchar(30),
   bank           varchar(255),
-  number         varchar(255),
 
   code_banque    varchar(7),
   code_guichet   varchar(6),
+  number         varchar(255),
   cle_rib        varchar(5),
   bic            varchar(10),
 
-- 
GitLab