diff --git a/htdocs/compta/tva/fiche.php b/htdocs/compta/tva/fiche.php index 2eeae0ae5a5..7eac99da5a9 100644 --- a/htdocs/compta/tva/fiche.php +++ b/htdocs/compta/tva/fiche.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2007 Laurent Destailleur * * 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 @@ -17,7 +17,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ - * $Source$ */ /** @@ -31,6 +30,8 @@ require("../../tva.class.php"); $langs->load("compta"); +$id=$_GET["id"]; + $mesg = ''; @@ -44,14 +45,14 @@ if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) $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"]; + $tva->label=$_POST["label"]; - $ret=$tva->add_payement($user); + $ret=$tva->addPayment($user); if ($ret > 0) { $db->commit(); @@ -93,19 +94,24 @@ if ($_GET["action"] == 'create') print $html->select_date("","datep",'','','','add'); print ''; - print ''.$langs->trans("Type").''; - $html->select_types_paiements($charge->paiementtype, "paiementtype"); - print "\n"; - + // Label + print ''.$langs->trans("Label").''; + + // Amount + print ''.$langs->trans("Amount").''; + if ($conf->banque->enabled) { - print ''.$langs->trans("Account").''; + print ''.$langs->trans("Account").''; $html->select_comptes($charge->accountid,"accountid",0,"courant=1",1); // Affiche liste des comptes courant print ''; - } + + print ''.$langs->trans("Type").''; + $html->select_types_paiements($charge->paiementtype, "paiementtype"); + print "\n"; + } - print ''.$langs->trans("Amount").''; - print '    '; + print '    '; print ''; print ''; print ''; @@ -118,7 +124,52 @@ if ($_GET["action"] == 'create') /* */ /* ************************************************************************** */ -// Aucune action +if ($id) +{ + print_fiche_titre($langs->trans("VATPayment")); + + $vatpayment = new Tva($db); + + if ($vatpayment->fetch($id) > 0) + { + if ($mesg) print $mesg.'
'; + + $h = 0; + $head[$h][0] = DOL_URL_ROOT.'/compta/tva/fiche.php?id='.$tva->id; + $head[$h][1] = $langs->trans('Card'); + $head[$h][2] = 'card'; + $h++; + + dolibarr_fiche_head($head, 'card', $langs->trans("VATPayment")); + + + print ''; + + print ""; + print ''; + + print ''; + + print '\n"; + + if ($conf->banque->enabled) + { + print ''; + } + + print ''; + } + +} + $db->close(); diff --git a/htdocs/tva.class.php b/htdocs/tva.class.php index 03831112c73..63a25529282 100644 --- a/htdocs/tva.class.php +++ b/htdocs/tva.class.php @@ -17,7 +17,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ - * $Source$ */ /** @@ -32,7 +31,6 @@ /** \class Tva \brief Classe permettant la gestion de la tva */ - class Tva { var $db; @@ -190,39 +188,44 @@ class Tva /* * \brief Ajoute un paiement de TVA + * \param user Object user that insert + * \return int <0 if KO, rowid in tva table if OK */ - - function add_payement($user) + function addPayment($user) { global $conf,$langs; $this->db->begin(); - // Validation parameteres + // Check parameters $this->amount=price2num($this->amount); - if ($conf->banque->enabled) - { - if (! $this->accountid) - { - $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Account")); - return -3; - } - } + if (! $this->label) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")); + return -3; + } if ($this->amount <= 0) { - $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); + $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")); return -4; } + if ($conf->banque->enabled && ! $this->accountid) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Account")); + return -5; + } // 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.= ", fk_user_creat"; + $sql.= ") "; $sql.= " VALUES ('".$this->db->idate($this->datep)."',"; $sql.= "'".$this->db->idate($this->datev)."'," . $this->amount; if ($this->note) $sql.=", '".addslashes($this->note)."'"; if ($this->label) $sql.=", '".addslashes($this->label)."'"; + $sql.=", '".$user->id."'"; $sql.= ")"; $result = $this->db->query($sql); @@ -240,9 +243,10 @@ class Tva $acc = new Account($this->db, $this->accountid); $bank_line_id = $acc->addline($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 fk_bank dans llx_tva. On connait ainsi la ligne de tva qui a généré l'écriture bancaire + if ($bank_line_id) + { + $this->update_fk_bank($bank_line_id); } // Mise a jour liens (pour chaque charge concernée par le paiement) @@ -273,6 +277,27 @@ class Tva return -1; } } + + /** + * \brief Mise a jour du lien entre le paiement tva et la ligne générée dans llx_bank + * \param id_bank Id compte bancaire + * \return int <0 if KO, >0 if OK + */ + function update_fk_bank($id_bank) + { + $sql = 'UPDATE llx_tva set fk_bank = '.$id_bank; + $sql.= ' WHERE rowid = '.$this->id; + $result = $this->db->query($sql); + if ($result) + { + return 1; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } + } - ?> diff --git a/mysql/migration/2.1.0-2.2.0.sql b/mysql/migration/2.1.0-2.2.0.sql index ac5282bc0ef..220078b25d5 100644 --- a/mysql/migration/2.1.0-2.2.0.sql +++ b/mysql/migration/2.1.0-2.2.0.sql @@ -53,6 +53,14 @@ delete from llx_adherent_type where libelle IS NULL; alter table llx_adherent_type modify libelle varchar(50) NOT NULL; +alter table llx_tva add fk_bank integer NOT NULL; +alter table llx_tva add fk_user_creat integer; +alter table llx_tva add fk_user_modif integer; + +-- V4.1 UPDATE llx_tva as t set fk_bank = (SELECT IFNULL(MIN(rowid),0) FROM llx_bank as b WHERE b.datev = t.datev AND b.amount = -t.amount AND b.label like 'R%glement TVA') WHERE t.fk_bank = 0; +-- V4.1 UPDATE llx_tva as t set fk_user_creat = (SELECT MIN(fk_user_author) FROM llx_bank as b WHERE b.datev = t.datev AND b.amount = -t.amount AND b.label like 'R%glement TVA') WHERE t.fk_user_creat IS NULL; + + -- Extention de la gestion des catégories alter table llx_categorie ADD type int not null default '0'; -- V4 ALTER TABLE llx_categorie DROP INDEX uk_categorie_ref; @@ -901,6 +909,8 @@ ALTER TABLE llx_element_contact ADD INDEX idx_element_contact_fk_socpeople (fk_s -- Supprimme orphelins pour permettre montée de la clé -- V4 DELETE llx_fichinter FROM llx_fichinter LEFT JOIN llx_societe ON llx_fichinter.fk_soc = llx_societe.rowid WHERE llx_societe.rowid IS NULL; + + ALTER TABLE llx_societe ADD COLUMN supplier_account varchar(32) after fournisseur; drop table if exists llx_c_barcode; diff --git a/mysql/tables/llx_tva.sql b/mysql/tables/llx_tva.sql index 04aac771b03..398fcc4572c 100644 --- a/mysql/tables/llx_tva.sql +++ b/mysql/tables/llx_tva.sql @@ -28,5 +28,8 @@ create table llx_tva datev date, -- date de valeur amount real NOT NULL DEFAULT 0, label varchar(255), - note text + note text, + fk_bank integer NOT NULL, + fk_user_creat integer, -- utilisateur qui a créé l'info + fk_user_modif integer -- utilisateur qui a modifié l'info )type=innodb;
'.$langs->trans("DatePayment").''; + print dolibarr_print_date($vatpayment->date); + print '
'.$langs->trans("DateValue").''; + print $html->select_date("","datep",'','','','add'); + print '
'.$langs->trans("Type").''; + $html->select_types_paiements($charge->paiementtype, "paiementtype"); + print "
'.$langs->trans("Account").''; + $html->select_comptes($charge->accountid,"accountid",0,"courant=1",1); // Affiche liste des comptes courant + print '
'.$langs->trans("Amount").'