diff --git a/htdocs/compta/tva/fiche.php b/htdocs/compta/tva/fiche.php index 827deb9f6b2a1d5157624f5c74805dd662288ff8..feaec25d3adb4536f1e99cb59b08633f878afa24 100644 --- a/htdocs/compta/tva/fiche.php +++ b/htdocs/compta/tva/fiche.php @@ -18,7 +18,6 @@ * * $Id$ * $Source$ - * */ /** @@ -57,11 +56,12 @@ if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) { $db->commit(); Header ("Location: reglement.php"); + exit; } else { $db->rollback(); - $message=$langs->trans("Error"); + $message='<div class="error">'.$tva->error.'</div>'; $_GET["action"]="create"; } } @@ -80,7 +80,7 @@ if ($_GET["action"] == 'create') print_fiche_titre($langs->trans("NewVATPayment")); - if ($message) print '<br>'.$message.'</br>'; + if ($message) print $message; print '<table class="border" width="100%">'; @@ -97,13 +97,16 @@ if ($_GET["action"] == 'create') $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>'; - + if ($conf->banque->enabled) + { + print '<tr><td>'.$langs->trans("Account").'</td><td>'; + $html->select_comptes($charge->accountid,"accountid",0,"courant=1",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> </td><td><input type="submit" value="'.$langs->trans("Save").'"> '; - print '<input type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>'; + print '<tr><td> </td><td><input type="submit" class="button" value="'.$langs->trans("Save").'"> '; + print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>'; print '</table>'; print '</form>'; } diff --git a/htdocs/tva.class.php b/htdocs/tva.class.php index 747a56a1e2bb5c2aea68fe7ea1388bc0cef3c710..ff4a65eeb39c247340a55304a50783f01e21d167 100644 --- a/htdocs/tva.class.php +++ b/htdocs/tva.class.php @@ -194,12 +194,33 @@ class Tva function add_payement($user) { + global $conf,$langs; + + $this->db->begin(); + + // Validation parameteres + $this->amount=price2num($this->amount); + if ($conf->banque->enabled) + { + if (! $this->accountid) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Account")); + return -3; + } + } + if ($this->amount <= 0) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); + return -4; + } + + // Insertion dans table des paiement tva $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); + $sql.= "'".$this->db->idate($this->datev)."'," . $this->amount; if ($this->note) $sql.=", '".addslashes($this->note)."'"; if ($this->label) $sql.=", '".addslashes($this->label)."'"; $sql.= ")"; @@ -207,37 +228,48 @@ class Tva $result = $this->db->query($sql); if ($result) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); // \todo devrait s'appeler paiementtva 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; + if ($conf->banque->enabled) + { + // Insertion dans llx_bank + + require_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php'); + + $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_paiementtva. 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); + //} + } + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -2; + } } else { $this->error=$this->db->error(); + $this->db->rollback(); return -1; } }