2004-10-19 22:35:36 +02:00
< ? php
2003-06-20 16:30:08 +02:00
/* Copyright ( C ) 2001 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2010-01-15 01:17:59 +01:00
* Copyright ( C ) 2004 Eric Seigne < eric . seigne @ ryxeo . com >
2012-02-10 09:54:19 +01:00
* Copyright ( C ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ capnetworks . com >
2014-03-28 18:31:43 +01:00
* Copyright ( C ) 2014 Ferran Marcet < fmarcet @ 2 byte . es >
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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2002-06-18 20:21:12 +02:00
* ( 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
2011-08-03 02:45:22 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2002-06-18 20:21:12 +02:00
*/
2005-02-01 23:44:09 +01:00
/**
2010-01-15 01:17:59 +01:00
* \file htdocs / compta / tva / index . php
* \ingroup tax
2010-02-14 19:26:52 +01:00
* \brief Index page of VAT reports
2010-01-15 01:17:59 +01:00
*/
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/tax.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2002-06-18 20:21:12 +02:00
2006-11-29 23:03:28 +01:00
$langs -> load ( " other " );
2013-12-03 20:44:31 +01:00
$langs -> load ( " compta " );
2014-02-04 20:57:22 +01:00
$langs -> load ( " banks " );
$langs -> load ( " bills " );
2006-11-29 23:03:28 +01:00
2013-12-03 20:44:31 +01:00
$year = GETPOST ( " year " , " int " );
if ( $year == 0 )
2006-05-19 22:38:46 +02:00
{
2011-09-14 01:06:16 +02:00
$year_current = strftime ( " %Y " , time ());
$year_start = $year_current ;
2006-05-19 22:38:46 +02:00
} else {
2011-09-14 01:06:16 +02:00
$year_current = $year ;
$year_start = $year ;
2006-05-19 22:38:46 +02:00
}
2005-08-16 01:39:04 +02:00
2008-10-13 16:22:10 +02:00
// Security check
$socid = isset ( $_GET [ " socid " ]) ? $_GET [ " socid " ] : '' ;
if ( $user -> societe_id ) $socid = $user -> societe_id ;
$result = restrictedArea ( $user , 'tax' , '' , '' , 'charges' );
2009-07-29 18:13:33 +02:00
// Define modetax (0 or 1)
// 0=normal, 1=option vat for services is on debit
$modetax = $conf -> global -> TAX_MODE ;
if ( isset ( $_GET [ " modetax " ])) $modetax = $_GET [ " modetax " ];
2005-08-16 01:39:04 +02:00
2006-05-19 22:38:46 +02:00
2013-12-03 20:44:31 +01:00
/**
* pt
*
* @ param DoliDB $db Database handler
* @ param string $sql SQL Request
2014-12-28 20:12:32 +01:00
* @ param string $date Date
2013-12-03 20:44:31 +01:00
* @ return void
*/
2006-05-19 22:38:46 +02:00
function pt ( $db , $sql , $date )
{
global $conf , $bc , $langs ;
2005-05-08 21:03:00 +02:00
$result = $db -> query ( $sql );
2006-05-19 22:38:46 +02:00
if ( $result )
{
2005-05-08 21:03:00 +02:00
$num = $db -> num_rows ( $result );
$i = 0 ;
$total = 0 ;
2011-09-14 01:06:16 +02:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap" width="60%">' . $date . '</td>' ;
2011-09-14 01:06:16 +02:00
print '<td align="right">' . $langs -> trans ( " Amount " ) . '</td>' ;
print '<td> </td>' . " \n " ;
2005-05-08 21:03:00 +02:00
print " </tr> \n " ;
$var = True ;
2006-05-19 22:38:46 +02:00
while ( $i < $num )
{
2005-05-08 21:03:00 +02:00
$obj = $db -> fetch_object ( $result );
$var =! $var ;
2011-09-14 01:06:16 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap">' . $obj -> dm . " </td> \n " ;
2008-11-04 18:28:57 +01:00
$total = $total + $obj -> mm ;
2005-05-08 21:03:00 +02:00
2013-04-25 01:13:13 +02:00
print '<td class="nowrap" align="right">' . price ( $obj -> mm ) . " </td><td > </td> \n " ;
2005-05-08 21:03:00 +02:00
print " </tr> \n " ;
$i ++ ;
}
2011-09-14 01:06:16 +02:00
print '<tr class="liste_total"><td align="right">' . $langs -> trans ( " Total " ) . " :</td><td nowrap= \" nowrap \" align= \" right \" ><b> " . price ( $total ) . " </b></td><td> </td></tr> " ;
2005-05-08 21:03:00 +02:00
print " </table> " ;
$db -> free ( $result );
2002-06-18 20:21:12 +02:00
}
2006-05-19 22:38:46 +02:00
else {
2013-09-05 18:06:51 +02:00
dol_print_error ( $db );
2006-05-19 22:38:46 +02:00
}
}
2002-06-18 20:21:12 +02:00
2005-05-07 01:13:21 +02:00
2002-06-18 20:21:12 +02:00
/*
2008-10-13 16:22:10 +02:00
* View
2002-06-18 20:21:12 +02:00
*/
llxHeader ();
$tva = new Tva ( $db );
2004-01-08 00:15:20 +01:00
2004-07-30 12:32:27 +02:00
$textprevyear = " <a href= \" index.php?year= " . ( $year_current - 1 ) . " \" > " . img_previous () . " </a> " ;
2005-02-01 23:44:09 +01:00
$textnextyear = " <a href= \" index.php?year= " . ( $year_current + 1 ) . " \" > " . img_next () . " </a> " ;
2004-06-09 01:40:53 +02:00
2005-05-07 01:13:21 +02:00
print_fiche_titre ( $langs -> trans ( " VAT " ), " $textprevyear " . $langs -> trans ( " Year " ) . " $year_start $textnextyear " );
2004-06-09 01:40:53 +02:00
2010-02-14 20:38:20 +01:00
print $langs -> trans ( " VATReportBuildWithOptionDefinedInModule " ) . '<br>' ;
print '(' . $langs -> trans ( " TaxModuleSetupToModifyRules " , DOL_URL_ROOT . '/admin/taxes.php' ) . ')<br>' ;
print '<br>' ;
2004-01-08 00:23:13 +01:00
2014-05-11 06:49:11 +02:00
print '<table width="100%" class="notopnoleftnoright">' ;
print '<tr><td class="notopnoleft" width="50%">' ;
2009-02-04 23:43:51 +01:00
print_titre ( $langs -> trans ( " VATSummary " ));
2009-07-29 18:13:33 +02:00
// The report mode is the one defined by defaut in tax module setup
//print $modetax;
//print '('.$langs->trans("SeeVATReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=0">','</a>').')';
2014-05-11 06:49:11 +02:00
print '</td><td>' ;
2009-08-19 19:16:47 +02:00
print_titre ( $langs -> trans ( " VATPaid " ));
2014-05-11 06:49:11 +02:00
print '</td></tr>' ;
2002-06-18 20:21:12 +02:00
2014-05-11 06:49:11 +02:00
print '<tr><td class="notopnoleft" width="50%" valign="top">' ;
2004-06-09 01:40:53 +02:00
2012-02-10 09:54:19 +01:00
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>' ;
print '<td align="right">' . $langs -> trans ( " TotalToPay " ) . '</td>' ;
print '<td> </td>' . " \n " ;
print '</tr>' . " \n " ;
2002-06-18 20:21:12 +02:00
2009-07-29 18:13:33 +02:00
$y = $year_current ;
$var = True ;
2010-02-14 19:26:52 +01:00
$total = 0 ; $subtotalcoll = 0 ; $subtotalpaye = 0 ; $subtotal = 0 ;
2009-07-29 18:13:33 +02:00
$i = 0 ;
for ( $m = 1 ; $m < 13 ; $m ++ )
2006-05-19 22:38:46 +02:00
{
2011-09-14 01:06:16 +02:00
$coll_listsell = vat_by_date ( $db , $y , 0 , 0 , 0 , $modetax , 'sell' , $m );
$coll_listbuy = vat_by_date ( $db , $y , 0 , 0 , 0 , $modetax , 'buy' , $m );
2014-03-28 18:31:43 +01:00
$action = " tva " ;
$object = array ( & $coll_listsell , & $coll_listbuy );
$parameters [ " mode " ] = $modetax ;
$parameters [ " year " ] = $y ;
$parameters [ " month " ] = $m ;
// Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
$hookmanager -> initHooks ( array ( 'externalbalance' ));
$reshook = $hookmanager -> executeHooks ( 'addStatisticLine' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2011-09-14 01:06:16 +02:00
if ( ! is_array ( $coll_listbuy ) && $coll_listbuy == - 1 )
{
$langs -> load ( " errors " );
print '<tr><td colspan="5">' . $langs -> trans ( " ErrorNoAccountancyModuleLoaded " ) . '</td></tr>' ;
break ;
}
if ( ! is_array ( $coll_listbuy ) && $coll_listbuy == - 2 )
{
print '<tr><td colspan="5">' . $langs -> trans ( " FeatureNotYetAvailable " ) . '</td></tr>' ;
break ;
}
$var =! $var ;
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2013-07-19 14:23:42 +02:00
print '<td class="nowrap"><a href="quadri_detail.php?leftmenu=tax_vat&month=' . $m . '&year=' . $y . '">' . dol_print_date ( dol_mktime ( 0 , 0 , 0 , $m , 1 , $y ), " %b %Y " ) . '</a></td>' ;
2011-09-14 01:06:16 +02:00
$x_coll = 0 ;
foreach ( $coll_listsell as $vatrate => $val )
{
$x_coll += $val [ 'vat' ];
}
$subtotalcoll = $subtotalcoll + $x_coll ;
2013-07-19 14:23:42 +02:00
print " <td class= \" nowrap \" align= \" right \" > " . price ( $x_coll ) . " </td> " ;
2011-09-14 01:06:16 +02:00
$x_paye = 0 ;
foreach ( $coll_listbuy as $vatrate => $val )
{
$x_paye += $val [ 'vat' ];
}
$subtotalpaye = $subtotalpaye + $x_paye ;
2013-07-19 14:23:42 +02:00
print " <td class= \" nowrap \" align= \" right \" > " . price ( $x_paye ) . " </td> " ;
2011-09-14 01:06:16 +02:00
$diff = $x_coll - $x_paye ;
$total = $total + $diff ;
$subtotal = $subtotal + $diff ;
2013-07-19 14:23:42 +02:00
print " <td class= \" nowrap \" align= \" right \" > " . price ( $diff ) . " </td> \n " ;
2011-09-14 01:06:16 +02:00
print " <td> </td> \n " ;
print " </tr> \n " ;
$i ++ ;
if ( $i > 2 ) {
print '<tr class="liste_total">' ;
print '<td align="right"><a href="quadri_detail.php?leftmenu=tax_vat&q=' . ( $m / 3 ) . '&year=' . $y . '">' . $langs -> trans ( " SubTotal " ) . '</a>:</td>' ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap" align="right">' . price ( $subtotalcoll ) . '</td>' ;
print '<td class="nowrap" align="right">' . price ( $subtotalpaye ) . '</td>' ;
print '<td class="nowrap" align="right">' . price ( $subtotal ) . '</td>' ;
2011-09-14 01:06:16 +02:00
print '<td> </td></tr>' ;
$i = 0 ;
$subtotalcoll = 0 ; $subtotalpaye = 0 ; $subtotal = 0 ;
}
2006-05-19 22:38:46 +02:00
}
2010-02-14 19:26:52 +01:00
print '<tr class="liste_total"><td align="right" colspan="3">' . $langs -> trans ( " TotalToPay " ) . ':</td><td nowrap align="right">' . price ( $total ) . '</td>' ;
2009-07-29 18:13:33 +02:00
print " <td> </td> \n " ;
print '</tr>' ;
/* }
2011-09-14 01:06:16 +02:00
else
{
print '<tr><td colspan="5">' . $langs -> trans ( " FeatureNotYetAvailable " ) . '</td></tr>' ;
print '<tr><td colspan="5">' . $langs -> trans ( " FeatureIsSupportedInInOutModeOnly " ) . '</td></tr>' ;
} */
2004-06-09 01:40:53 +02:00
2006-05-19 22:38:46 +02:00
print '</table>' ;
2009-02-04 23:43:51 +01:00
2014-05-11 06:49:11 +02:00
print '</td>' ;
2012-02-10 09:54:19 +01:00
print '<td class="notopnoleftnoright" valign="top" width="50%">' ;
2009-02-04 23:43:51 +01:00
2006-05-19 22:38:46 +02:00
/*
2011-09-14 01:06:16 +02:00
* Payed
*/
2002-06-18 20:21:12 +02:00
2008-11-04 18:28:57 +01:00
$sql = " SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm " ;
2009-04-27 22:37:50 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " tva as f " ;
$sql .= " WHERE f.entity = " . $conf -> entity ;
2010-02-14 19:26:52 +01:00
$sql .= " AND f.datev >= ' " . $db -> idate ( dol_get_first_day ( $y , 1 , false )) . " ' " ;
$sql .= " AND f.datev <= ' " . $db -> idate ( dol_get_last_day ( $y , 12 , false )) . " ' " ;
2014-05-11 06:49:11 +02:00
$sql .= " GROUP BY dm ORDER BY dm ASC " ;
2005-02-01 23:44:09 +01:00
2006-05-19 22:38:46 +02:00
pt ( $db , $sql , $langs -> trans ( " Year " ) . " $y " );
2002-06-18 20:21:12 +02:00
2006-05-19 22:38:46 +02:00
print " </td></tr></table> " ;
2002-06-18 20:21:12 +02:00
2014-05-11 06:49:11 +02:00
print '</td></tr>' ;
print '</table>' ;
2002-06-18 20:21:12 +02:00
$db -> close ();
2011-08-27 16:24:16 +02:00
llxFooter ();