dolibarr/htdocs/compta/tva/index.php

271 lines
7.6 KiB
PHP
Raw Normal View History

<?php
2003-06-20 16:30:08 +02:00
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 <EFBFBD>ric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
2002-06-18 20:21:12 +02:00
*
* 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.
*
2002-06-19 13:16:45 +02:00
* $Id$
* $Source$
*
2002-06-18 20:21:12 +02:00
*/
/**
\file htdocs/compta/tva/index.php
\ingroup compta
\brief Page des societes
\version $Revision$
*/
2003-09-11 22:18:51 +02:00
require("./pre.inc.php");
require("../../tva.class.php");
2002-06-18 20:21:12 +02:00
2005-08-16 01:39:04 +02:00
$modecompta = $conf->compta->mode;
2002-06-18 20:21:12 +02:00
/*
2005-08-16 01:39:04 +02:00
* On r<EFBFBD>cup<EFBFBD>re la tva <EFBFBD> collecter
2002-06-18 20:21:12 +02:00
*/
2005-08-16 01:39:04 +02:00
function tva_coll($db, $y,$m)
{
if ($modecompta=="CREANCES-DETTES")
{
// Si on paye la tva sur les factures dues (non brouillon)
$sql = "SELECT sum(f.tva) as amount";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " WHERE ";
$sql.= " f.fk_statut = 1";
$sql.= " AND date_format(f.datef,'%Y') = $y";
$sql.= " AND date_format(f.datef,'%m') = $m";
}
else
{
// Si on paye la tva sur les payments
// \todo a ce jour on se sait pas la compter car le montant tva d'un payment
// n'est pas stock<63> dans la table des payments.
// Il faut quand un payment a lieu, stocker en plus du montant du paiement le
// detail part tva et part ht.
// En attendant, on renvoi tva sur factures pay<61>s
$sql = "SELECT sum(f.tva) as amount";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " WHERE ";
$sql.= " f.paye = 1";
$sql.= " AND date_format(f.datef,'%Y') = $y";
$sql.= " AND date_format(f.datef,'%m') = $m";
}
2002-06-20 15:23:17 +02:00
2005-08-16 01:39:04 +02:00
$resql = $db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
return $obj->amount;
}
else
{
dolibarr_print_error($db);
}
2002-06-20 15:23:17 +02:00
}
2005-08-16 01:39:04 +02:00
2002-06-20 15:23:17 +02:00
/*
2005-08-16 01:39:04 +02:00
* On r<EFBFBD>cup<EFBFBD>re la tva <EFBFBD> payer
2002-06-20 15:23:17 +02:00
*/
2003-06-20 16:30:08 +02:00
function tva_paye($db, $y,$m)
{
2005-08-16 01:39:04 +02:00
if ($modecompta=="CREANCES-DETTES")
{
// Si on paye la tva sur les factures dues (non brouillon)
$sql = "SELECT sum(f.total_tva) as amount";
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
$sql.= " WHERE ";
$sql.= " f.fk_statut = 1";
$sql.= " AND date_format(f.datef,'%Y') = $y";
$sql.= " AND date_format(f.datef,'%m') = $m";
}
else
{
// Si on paye la tva sur les payments
// \todo a ce jour on se sait pas la compter car le montant tva d'un payment
// n'est pas stock<63> dans la table des payments.
// Il faut quand un payment a lieu, stocker en plus du montant du paiement le
// detail part tva et part ht.
// En attendant, on renvoi tva sur factures pay<61>s
$sql = "SELECT sum(f.total_tva) as amount";
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
// $sql.= " WHERE ";
$sql .= " WHERE f.fk_statut = 1";
// $sql.= " f.paye = 1";
$sql.= " AND date_format(f.datef,'%Y') = $y";
$sql.= " AND date_format(f.datef,'%m') = $m";
//print "xx $sql";
2005-08-16 01:39:04 +02:00
}
2002-06-20 15:23:17 +02:00
2005-08-16 01:39:04 +02:00
$resql = $db->query($sql);
if ($resql)
2003-06-20 16:30:08 +02:00
{
2005-08-16 01:39:04 +02:00
$obj = $db->fetch_object($resql);
return $obj->amount;
}
else
{
dolibarr_print_error($db);
2003-06-20 16:30:08 +02:00
}
2002-06-20 15:23:17 +02:00
}
2002-06-18 20:21:12 +02:00
2005-08-16 01:39:04 +02:00
2002-06-18 20:21:12 +02:00
function pt ($db, $sql, $date) {
global $bc,$langs;
$result = $db->query($sql);
if ($result) {
$num = $db->num_rows($result);
$i = 0;
$total = 0;
print "<table class=\"noborder\" width=\"100%\">";
print "<tr class=\"liste_titre\">";
print "<td nowrap width=\"60%\">$date</td>";
print "<td align=\"right\">".$langs->trans("Amount")."</td>";
print "<td>&nbsp;</td>\n";
print "</tr>\n";
$var=True;
while ($i < $num) {
$obj = $db->fetch_object($result);
$var=!$var;
print "<tr $bc[$var]>";
print "<td nowrap>$obj->dm</td>\n";
$total = $total + $obj->amount;
print "<td nowrap align=\"right\">".price($obj->amount)."</td><td nowrap align=\"right\">".$total."</td>\n";
print "</tr>\n";
$i++;
}
print "<tr class=\"liste_total\"><td align=\"right\">".$langs->trans("Total")." :</td><td nowrap align=\"right\"><b>".price($total)."</b></td><td>&nbsp;</td></tr>";
print "</table>";
$db->free($result);
} else {
dolibar_print_error($db);
}
2002-06-18 20:21:12 +02:00
}
2002-06-18 20:21:12 +02:00
/*
*
*/
llxHeader();
$tva = new Tva($db);
$year=$_GET["year"];
2002-06-20 15:23:17 +02:00
if ($year == 0 ) {
$year_current = strftime("%Y",time());
$year_start = $year_current;
} else {
$year_current = $year;
$year_start = $year;
}
2004-07-30 12:32:27 +02:00
$textprevyear="<a href=\"index.php?year=" . ($year_current-1) . "\">".img_previous()."</a>";
$textnextyear=" <a href=\"index.php?year=" . ($year_current+1) . "\">".img_next()."</a>";
print_fiche_titre($langs->trans("VAT"),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear");
2002-06-18 20:21:12 +02:00
echo '<table width="100%">';
echo '<tr><td>';
print_fiche_titre($langs->trans("VATSummary"));
echo '</td><td>';
print_fiche_titre($langs->trans("VATPayed"));
echo '</td></tr>';
2002-06-18 20:21:12 +02:00
2002-06-20 15:23:17 +02:00
for ($y = $year_current ; $y >= $year_start ; $y=$y-1 ) {
2002-06-18 20:21:12 +02:00
echo '<tr><td width="50%" valign="top">';
print "<table class=\"noborder\" width=\"100%\">";
print "<tr class=\"liste_titre\">";
print "<td width=\"30%\">".$langs->trans("Year")." $y</td>";
print "<td align=\"right\">".$langs->trans("VATToPay")."</td>";
print "<td align=\"right\">".$langs->trans("VATToCollect")."</td>";
2005-05-08 23:47:19 +02:00
print "<td align=\"right\">".$langs->trans("TotalToPay")."</td>";
print "</tr>\n";
2002-06-20 15:23:17 +02:00
$var=True;
2002-06-20 21:25:15 +02:00
$total = 0; $subtotal = 0;
$i=0;
2002-06-20 15:23:17 +02:00
for ($m = 1 ; $m < 13 ; $m++ ) {
$var=!$var;
print "<tr $bc[$var]>";
print '<td nowrap>'.strftime("%b %Y",mktime(0,0,0,$m,1,$y)).'</td>';
2002-06-20 15:23:17 +02:00
$x_coll = tva_coll($db, $y, $m);
print "<td nowrap align=\"right\">".price($x_coll)."</td>";
2002-06-20 15:23:17 +02:00
$x_paye = tva_paye($db, $y, $m);
print "<td nowrap align=\"right\">".price($x_paye)."</td>";
2002-06-20 15:23:17 +02:00
$diff = $x_coll - $x_paye;
$total = $total + $diff;
2002-06-20 21:25:15 +02:00
$subtotal = $subtotal + $diff;
2002-06-20 15:23:17 +02:00
print "<td nowrap align=\"right\">".price($diff)."</td>\n";
print "</tr>\n";
2002-06-20 15:23:17 +02:00
$i++;
2002-06-20 21:25:15 +02:00
if ($i > 2) {
print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("SubTotal").':</td><td nowrap align="right">'.price($subtotal).'</td></tr>';
2002-06-20 21:25:15 +02:00
$i = 0;
$subtotal = 0;
}
2002-06-20 15:23:17 +02:00
}
print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("TotalToPay").':</td><td nowrap align="right"><b>'.price($total).'</b></td>';
2002-09-26 16:38:57 +02:00
print "<td>&nbsp;</td>\n";
print "</table>";
2002-06-18 20:21:12 +02:00
echo '</td><td valign="top" width="50%">';
2002-09-26 16:38:57 +02:00
2002-06-18 20:21:12 +02:00
/*
2002-09-26 16:38:57 +02:00
* R<EFBFBD>gl<EFBFBD>e
2002-06-18 20:21:12 +02:00
*/
$sql = "SELECT amount, date_format(f.datev,'%Y-%m') as dm";
$sql .= " FROM ".MAIN_DB_PREFIX."tva as f WHERE f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' ";
2002-06-18 20:21:12 +02:00
$sql .= " GROUP BY dm DESC";
pt($db, $sql,$langs->trans("Year")." $y");
2002-06-18 20:21:12 +02:00
print "</td></tr></table>";
echo '</td></tr>';
}
echo '</table>';
$db->close();
llxFooter('$Date$ - $Revision$');
2002-06-18 20:21:12 +02:00
?>