diff --git a/htdocs/compta/bank/index.php3 b/htdocs/compta/bank/index.php3 index e07353fac4c..a7232147578 100644 --- a/htdocs/compta/bank/index.php3 +++ b/htdocs/compta/bank/index.php3 @@ -26,8 +26,10 @@ * */ require("./pre.inc.php3"); - require("./bank.lib.php3"); + +require("../../tva.class.php3"); + llxHeader(); $db = new Db(); @@ -51,13 +53,10 @@ if ($result) { $db->free(); } - - - print ""; print ""; print ""; -print ""; +print ""; print "\n"; $total = 0; for ($i = 0 ; $i < sizeof($accounts) ; $i++) { @@ -65,22 +64,37 @@ for ($i = 0 ; $i < sizeof($accounts) ; $i++) { $acc->fetch($accounts[$i]); $solde = $acc->solde(); - print ""; - - - print ''; + print ''; $total += $solde; } -print ''; +print ''; + +print ''; +/* + * TVA + */ +$tva = new Tva($db); + +$tva_solde = $tva->solde(); + +$total = $total + $tva_solde; + +print ''; +/* + * + */ + +print ''; + print "
LabelBanqueNuméroSoldeNuméroSolde 
"; print ''.$acc->label.''; print "$acc->bank$acc->number'.price($solde).'
'.price($solde).' 
Total'.price($total).'
Total'.price($total).'euros HT
Dettes
TVA'.price($tva_solde).' 
Total'.price($total).'euros HT
"; diff --git a/htdocs/compta/pre.inc.php3 b/htdocs/compta/pre.inc.php3 index 5448f47dd4a..987bd81b692 100644 --- a/htdocs/compta/pre.inc.php3 +++ b/htdocs/compta/pre.inc.php3 @@ -44,7 +44,8 @@ function llxHeader($head = "") { $menu->add_submenu("casoc.php3","Par société"); $menu->add_submenu("pointmort.php3","Point mort"); - $menu->add_submenu("tva.php3","TVA"); + + $menu->add("tva/index.php3","TVA"); $menu->add("/compta/propal.php3","Propales"); diff --git a/htdocs/compta/tva/index.php3 b/htdocs/compta/tva/index.php3 new file mode 100644 index 00000000000..e9809ede685 --- /dev/null +++ b/htdocs/compta/tva/index.php3 @@ -0,0 +1,131 @@ + + * + * $Id$ + * $Source$ + * + * 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. + * + */ +require("./pre.inc.php3"); +require("../../tva.class.php3"); + +/* + * + * + */ + +function pt ($db, $sql, $date) { + global $bc; + + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows(); + $i = 0; $total = 0 ; + print "

"; + print ""; + print ""; + print ""; + print "\n"; + print "\n"; + $var=True; + while ($i < $num) { + $obj = $db->fetch_object( $i); + $var=!$var; + print ""; + print "\n"; + print "\n"; + print "\n"; + + $total = $total + $obj->amount; + + $i++; + } + print ""; + + print "
$dateMontant 
$obj->dm".price($obj->amount)." 
Total :".price($total)."euros HT
"; + $db->free(); + } else { + print $db->error(); + } +} + +/* + * + */ + +llxHeader(); + +$db = new Db(); + +$tva = new Tva($db); + +print "Solde :" . price($tva->solde()); + +$yearc = strftime("%Y",time()); + + +echo ''; +echo ''; +echo ''; + +for ($y = $yearc ; $y >= $conf->years ; $y=$y-1 ) { + + echo ''; +} + + + + + +echo '
TVA collectéeTva Payée
'; + /* + * Collectée + */ + print ""; + print "
"; + + $sql = "SELECT sum(f.tva) as amount , date_format(f.datef,'%Y-%m') as dm"; + $sql .= " FROM llx_facture as f WHERE f.paye = 1 AND f.datef >= '$y-01-01' AND f.datef <= '$y-12-31' "; + $sql .= " GROUP BY dm DESC"; + + pt($db, $sql,"Année $y"); + + print "
"; + + echo '
'; + /* + * Payée + */ + + print ""; + print "
"; + + $sql = "SELECT amount, date_format(f.datev,'%Y-%m') as dm"; + $sql .= " FROM llx_tva as f WHERE f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' "; + $sql .= " GROUP BY dm DESC"; + + pt($db, $sql,"Année $y"); + + print "
"; + + echo '
'; + + + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?> diff --git a/htdocs/compta/tva/pre.inc.php3 b/htdocs/compta/tva/pre.inc.php3 new file mode 100644 index 00000000000..842eaf1abde --- /dev/null +++ b/htdocs/compta/tva/pre.inc.php3 @@ -0,0 +1,50 @@ + + * + * $Id$ + * $Source$ + * + * 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. + * + */ +require("../../main.inc.php3"); + +function llxHeader($head = "") { + global $user, $conf; + + + /* + * + * + */ + top_menu($head); + + $menu = new Menu(); + + $menu->add("/compta/facture.php3","Factures"); + + + $menu->add("../ca.php3","Chiffres d'affaires"); + + $menu->add("index.php3","TVA"); + + + $menu->add("/compta/bank/index.php3","Bank"); + + left_menu($menu->liste); + +} + +?> diff --git a/htdocs/tva.class.php3 b/htdocs/tva.class.php3 new file mode 100644 index 00000000000..fea76d4015c --- /dev/null +++ b/htdocs/tva.class.php3 @@ -0,0 +1,122 @@ + + * + * 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$ + */ + +/* + * La tva collectée n'est calculée que sur les factures payées. + * + * + * + * + * + * + * + */ +class Tva { + var $db; + + var $note; + + Function Tva($DB) { + global $config; + + $this->db = $DB; + + return 1; + } + + Function solde($year = 0) { + + $payee = $this->tva_sum_payee($year); + $collectee = $this->tva_sum_collectee($year); + + $solde = $payee - $collectee; + + return $solde; + + } + /* + * Tva collectée + * + * + */ + Function tva_sum_collectee($year = 0) { + + $sql = "SELECT sum(f.tva) as amount"; + $sql .= " FROM llx_facture as f WHERE f.paye = 1"; + + if ($year) { + $sql .= " AND f.datef >= '$y-01-01' AND f.datef <= '$y-12-31' "; + } + + $result = $this->db->query($sql); + + if ($result) { + if ($this->db->num_rows()) { + $obj = $this->db->fetch_object(0); + return $obj->amount; + } else { + return 0; + } + + $this->db->free(); + + } else { + print $this->db->error(); + return -1; + } + } + /* + * Tva payée + * + * + */ + Function tva_sum_payee($year = 0) { + + $sql = "SELECT sum(f.amount) as amount"; + $sql .= " FROM llx_tva as f"; + + if ($year) { + $sql .= " WHERE f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' "; + } + + $result = $this->db->query($sql); + + if ($result) { + if ($this->db->num_rows()) { + $obj = $this->db->fetch_object(0); + return $obj->amount; + } else { + return 0; + } + + $this->db->free(); + + } else { + print $this->db->error(); + return -1; + } + } +} +/* + * $Id$ + * $Source$ + */ +?>