From 613bb9f290b3e33229a2c01c62a1eef85fa250c8 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Sun, 8 May 2005 19:32:01 +0000
Subject: [PATCH] =?UTF-8?q?New:=20Il=20est=20possible=20de=20choisir=20le?=
 =?UTF-8?q?=20compte=20de=20d=E9bit=20lors=20d'une=20saisie=20de=20paiemen?=
 =?UTF-8?q?t=20de=20TVA.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 htdocs/compta/tva/fiche.php | 107 ++++++++++++++++++++++--------------
 htdocs/tva.class.php        |  43 +++++++++++++--
 2 files changed, 104 insertions(+), 46 deletions(-)

diff --git a/htdocs/compta/tva/fiche.php b/htdocs/compta/tva/fiche.php
index 860209e4158..8965445f732 100644
--- a/htdocs/compta/tva/fiche.php
+++ b/htdocs/compta/tva/fiche.php
@@ -21,7 +21,8 @@
  *
  */
 
-/**	    \file       htdocs/compta/tva/fiche.php
+/**
+	    \file       htdocs/compta/tva/fiche.php
 		\brief      Page des r�glements de TVA
 		\version    $Revision$
 */
@@ -29,55 +30,82 @@
 require("./pre.inc.php");
 require("../../tva.class.php");
 
+$langs->load("compta");
+
 
 $mesg = '';
 
+
+/**
+ * Action ajout paiement tva
+ */
 if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
 {
-  $tva = new Tva($db);
-
-  $tva->add_payement(mktime(12,0,0,
-			    $_POST["datevmonth"],
-			    $_POST["datevday"],
-			    $_POST["datevyear"]
-			    ),
-		     mktime(12,0,0,
-			    $_POST["datepmonth"],
-			    $_POST["datepday"],
-			    $_POST["datepyear"]
-			    ),
-		     $_POST["amount"]
-		     );
-  Header ( "Location: reglement.php");
+    $tva = new Tva($db);
+    
+    $db->begin();
+    
+    $tva->label = $langs->trans("VATPayment");
+    $tva->accountid=$_POST["accountid"];
+    $tva->paymenttype=$_POST["paiementtype"];
+    $tva->datev=mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]);
+    $tva->datep=mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]);
+    $tva->amount=$_POST["amount"];
+
+    $ret=$tva->add_payement($user);
+    if ($ret > 0)
+    {
+        $db->commit();
+        Header ("Location: reglement.php");
+    }
+    else
+    {
+        $db->rollback();
+        $message=$langs->trans("Error");
+        $_GET["action"]="create";
+    }
 }
 
+
+
 llxHeader();
 
-/*
- *
- *
- */
 $html = new Form($db);
+
+// Formulaire saisie tva
 if ($_GET["action"] == 'create')
 {
-  print "<form action=\"fiche.php\" method=\"post\">\n";
-  print '<input type="hidden" name="action" value="add">';
-
-  print '<div class="titre">Nouveau r�glement TVA</div><br>';
+    print "<form action=\"fiche.php\" method=\"post\">\n";
+    print '<input type="hidden" name="action" value="add">';
+    
+    print '<div class="titre">'.$langs->trans("NewVATPayment").'</div><br>';
       
-  print '<table class="border" width="100%">';
-  print "<tr>";
-  print '<td>'.$langs->trans("DatePayment").'</td><td>';
-  print $html->select_date("","datev");
-  print '</td></tr>';
-  print '<td>'.$langs->trans("DateValue").'</td><td>';
-  print $html->select_date("","datep");
-  print '</td></tr>';
-  print '<tr><td>'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value=""></td></tr>';    
-  print '<tr><td>&nbsp;</td><td><input type="submit" value="'.$langs->trans("Save").'">&nbsp;';
-  print '<input type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
-  print '</table>';
-  print '</form>';      
+    if ($message) print '<br>'.$message.'</br>';
+    
+    print '<table class="border" width="100%">';
+    
+    print "<tr>";
+    print '<td>'.$langs->trans("DatePayment").'</td><td>';
+    print $html->select_date("","datev");
+    print '</td></tr>';
+
+    print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
+    print $html->select_date("","datep");
+    print '</td></tr>';
+
+    print '<tr><td>'.$langs->trans("Type").'</td><td>';
+    $html->select_types_paiements($charge->paiementtype, "paiementtype");
+    print "</td>\n";
+   
+    print '<tr><td>Compte � cr�diter :</td><td>';
+    $html->select_comptes($charge->accountid, "accountid", 0, "courant=1");  // Affiche liste des comptes courant
+    print '</td></tr>';
+    
+    print '<tr><td>'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value=""></td></tr>';    
+    print '<tr><td>&nbsp;</td><td><input type="submit" value="'.$langs->trans("Save").'">&nbsp;';
+    print '<input type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
+    print '</table>';
+    print '</form>';      
 }
 
 
@@ -89,9 +117,8 @@ if ($_GET["action"] == 'create')
 
 // Aucune action
 
-
-
 $db->close();
 
-llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
+llxFooter('$Date$ - $Revision$');
+
 ?>
diff --git a/htdocs/tva.class.php b/htdocs/tva.class.php
index de2003f8f54..b7ff6603596 100644
--- a/htdocs/tva.class.php
+++ b/htdocs/tva.class.php
@@ -192,17 +192,48 @@ class Tva
      *      \brief      Ajoute un paiement de TVA
      */
 
-    function add_payement($datep, $datev, $amount)
+    function add_payement($user)
     {
-        $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (datep, datev, amount) ";
-        $sql .= " VALUES ('".$this->db->idate($datep)."',";
-        $sql .= "'".$this->db->idate($datev)."'," . ereg_replace(",",".",$amount) .")";
+        $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (datep, datev, amount";
+        if ($this->note)  $sql.=", note";
+        if ($this->label) $sql.=", label";
+        $sql.= ") ";
+        $sql.= " VALUES ('".$this->db->idate($this->datep)."',";
+        $sql.= "'".$this->db->idate($this->datev)."'," . ereg_replace(",",".",$this->amount);
+        if ($this->note)  $sql.=", '".addslashes($this->note)."'";
+        if ($this->label) $sql.=", '".addslashes($this->label)."'";
+        $sql.= ")";
 
         $result = $this->db->query($sql);
-
         if ($result)
         {
-            return 1;
+            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva");
+            if ($this->id > 0)
+            {
+
+                // Insertion dans llx_bank
+                $acc = new Account($this->db, $this->accountid);
+                $bank_line_id = $acc->addline($this->db->idate($this->datep), $this->paymenttype, $this->label, -abs($this->amount), '', '', $user);
+        	  
+                // Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi la ligne de tva qui a g�n�r� l'�criture bancaire
+                if ($bank_line_id) {
+                    // $tva->update_fk_bank($bank_line_id);
+                }
+        	  
+                // Mise a jour liens (pour chaque charge concern�e par le paiement)
+                //foreach ($paiement->amounts as $key => $value)
+        	    //{
+                //    $chid = $key;
+                //    $fac = new Facture($db);
+                //    $fac->fetch($chid);
+                //    $fac->fetch_client();
+                //    $acc->add_url_line($bank_line_id, $paiement_id, DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', "(paiement)");
+                //    $acc->add_url_line($bank_line_id, $fac->client->id, DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom);
+        	    //}
+	  
+           }
+
+           return $this->id;
         }
         else
         {
-- 
GitLab