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 >
2018-03-15 10:24:45 +01:00
* Copyright ( C ) 2004 - 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ capnetworks . com >
2017-05-31 05:27:39 +02:00
* Copyright ( C ) 2011 - 2017 Alexandre Spangaro < aspangaro . dolibarr @ gmail . com >
2002-09-26 16:26:32 +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-09-26 16:26:32 +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-09-26 16:26:32 +02:00
*/
2005-05-08 21:25:55 +02:00
/**
2018-03-15 10:24:45 +01:00
* \file htdocs / compta / tva / list . php
2009-10-29 18:30:29 +01:00
* \ingroup tax
2010-02-14 13:42:00 +01:00
* \brief List of VAT payments
2009-10-29 18:30:29 +01:00
*/
2005-05-08 21:25:55 +02: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 . '/compta/tva/class/tva.class.php' ;
2016-08-11 18:18:03 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
2015-04-23 07:26:09 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
2017-05-31 05:27:39 +02:00
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php' ;
2002-09-26 16:26:32 +02:00
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'compta' , 'bills' ));
2005-05-08 21:25:55 +02:00
2008-10-13 16:22:10 +02:00
// Security check
2018-04-07 15:47:13 +02:00
$socid = GETPOST ( 'socid' , 'int' );
2008-10-13 16:22:10 +02:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
$result = restrictedArea ( $user , 'tax' , '' , '' , 'charges' );
2014-11-02 14:19:28 +01:00
$search_ref = GETPOST ( 'search_ref' , 'int' );
$search_label = GETPOST ( 'search_label' , 'alpha' );
$search_amount = GETPOST ( 'search_amount' , 'alpha' );
2016-08-11 18:18:03 +02:00
$search_account = GETPOST ( 'search_account' , 'int' );
2015-04-23 07:26:09 +02:00
$month = GETPOST ( " month " , " int " );
$year = GETPOST ( " year " , " int " );
2016-02-16 17:43:05 +01:00
2018-04-21 12:16:12 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2014-05-01 07:44:10 +02:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
$page = GETPOST ( " page " , 'int' );
2017-06-06 10:53:53 +02:00
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
2016-02-16 17:43:05 +01:00
$offset = $limit * $page ;
2014-05-01 07:44:10 +02:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
if ( ! $sortfield ) $sortfield = " t.datev " ;
if ( ! $sortorder ) $sortorder = " DESC " ;
$filtre = $_GET [ " filtre " ];
if ( empty ( $_REQUEST [ 'typeid' ]))
{
$newfiltre = str_replace ( 'filtre=' , '' , $filtre );
$filterarray = explode ( '-' , $newfiltre );
foreach ( $filterarray as $val )
{
$part = explode ( ':' , $val );
if ( $part [ 0 ] == 't.fk_typepayment' ) $typeid = $part [ 1 ];
}
}
else
{
$typeid = $_REQUEST [ 'typeid' ];
}
2008-10-13 16:22:10 +02:00
2017-07-13 00:35:10 +02:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) // Both test are required to be compatible with all browsers
2014-11-02 14:19:28 +01:00
{
$search_ref = " " ;
$search_label = " " ;
$search_amount = " " ;
2016-08-11 18:18:03 +02:00
$search_account = '' ;
2015-04-23 07:26:09 +02:00
$year = " " ;
$month = " " ;
2014-11-02 14:19:28 +01:00
$typeid = " " ;
}
2016-08-11 18:18:03 +02:00
2008-10-13 16:22:10 +02:00
/*
* View
*/
2002-09-26 16:26:32 +02:00
2016-11-12 12:40:06 +01:00
llxHeader ( '' , $langs -> trans ( " VATPayments " ));
2002-09-26 16:26:32 +02:00
2014-05-01 07:44:10 +02:00
$form = new Form ( $db );
2015-04-23 07:26:09 +02:00
$formother = new FormOther ( $db );
2008-04-03 21:35:46 +02:00
$tva_static = new Tva ( $db );
2017-05-31 05:27:39 +02:00
$bankstatic = new Account ( $db );
2002-09-26 16:26:32 +02:00
2018-02-05 16:28:25 +01:00
$sql = " SELECT t.rowid, t.amount, t.label, t.datev, t.datep, t.fk_typepayment as type, t.num_payment, t.fk_bank, pst.code as payment_code, " ;
2017-05-31 05:27:39 +02:00
$sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel " ;
2014-04-30 06:37:47 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " tva as t " ;
2018-03-07 17:32:57 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_paiement as pst ON t.fk_typepayment = pst.id " ;
2016-08-11 18:18:03 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " bank as b ON t.fk_bank = b.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " bank_account as ba ON b.fk_account = ba.rowid " ;
2017-11-23 15:06:16 +01:00
$sql .= " WHERE t.entity IN ( " . getEntity ( 'tax' ) . " ) " ;
if ( $search_ref ) $sql .= natural_search ( " t.rowid " , $search_ref );
if ( $search_label ) $sql .= natural_search ( " t.label " , $search_label );
if ( $search_amount ) $sql .= natural_search ( " t.amount " , price2num ( trim ( $search_amount )), 1 );
2016-08-11 18:18:03 +02:00
if ( $search_account > 0 ) $sql .= " AND b.fk_account= " . $search_account ;
2015-04-23 07:26:09 +02:00
if ( $month > 0 )
{
if ( $year > 0 )
$sql .= " AND t.datev BETWEEN ' " . $db -> idate ( dol_get_first_day ( $year , $month , false )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $year , $month , false )) . " ' " ;
else
$sql .= " AND date_format(t.datev, '%m') = ' $month ' " ;
}
else if ( $year > 0 )
{
$sql .= " AND t.datev BETWEEN ' " . $db -> idate ( dol_get_first_day ( $year , 1 , false )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $year , 12 , false )) . " ' " ;
}
2014-05-01 07:44:10 +02:00
if ( $filtre ) {
$filtre = str_replace ( " : " , " = " , $filtre );
$sql .= " AND " . $filtre ;
}
if ( $typeid ) {
$sql .= " AND t.fk_typepayment= " . $typeid ;
}
2016-02-16 17:43:05 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2015-12-28 00:20:48 +01:00
$totalnboflines = 0 ;
$result = $db -> query ( $sql );
if ( $result )
{
$totalnboflines = $db -> num_rows ( $result );
}
2014-05-01 07:44:10 +02:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2003-06-20 16:30:08 +02:00
$result = $db -> query ( $sql );
if ( $result )
{
2005-05-08 21:25:55 +02:00
$num = $db -> num_rows ( $result );
2009-02-04 23:43:51 +01:00
$i = 0 ;
2005-05-08 21:25:55 +02:00
$total = 0 ;
2014-05-01 07:44:10 +02:00
$param = '' ;
2016-06-07 14:06:00 +02:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) $param .= '&contextpage=' . $contextpage ;
if ( $limit > 0 && $limit != $conf -> liste_limit ) $param .= '&limit=' . $limit ;
2014-05-01 07:44:10 +02:00
if ( $typeid ) $param .= '&typeid=' . $typeid ;
2014-11-21 23:52:12 +01:00
2018-03-30 16:54:38 +02:00
$newcardbutton = '' ;
if ( $user -> rights -> tax -> charges -> creer )
{
2018-04-18 03:26:15 +02:00
$newcardbutton = '<a class="butActionNew" href="' . DOL_URL_ROOT . '/compta/tva/card.php?action=create">' . $langs -> trans ( 'NewVATPayment' );
$newcardbutton .= '<span class="fa fa-plus-circle valignmiddle"></span>' ;
$newcardbutton .= '</a>' ;
2018-03-30 16:54:38 +02:00
}
2009-03-03 00:43:17 +01:00
2016-02-16 17:43:05 +01:00
print '<form method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
if ( $optioncss != '' ) print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
2017-05-21 02:43:51 +02:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
2017-06-09 09:25:15 +02:00
2018-03-30 16:54:38 +02:00
print_barre_liste ( $langs -> trans ( " VATPayments " ), $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , '' , $num , $totalnboflines , 'title_accountancy' , 0 , $newcardbutton , '' , $limit );
2017-06-09 09:25:15 +02:00
2017-04-01 12:46:47 +02:00
print '<div class="div-table-responsive">' ;
2016-02-16 17:43:05 +01:00
print '<table class="noborder" width="100%">' ;
2014-11-21 23:52:12 +01:00
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre_filter">' ;
2018-04-28 17:18:38 +02:00
print '<td class="liste_titre"><input type="text" class="flat" size="4" name="search_ref" value="' . dol_escape_htmltag ( $search_ref ) . '"></td>' ;
print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="' . dol_escape_htmltag ( $search_label ) . '"></td>' ;
2016-03-25 14:49:48 +01:00
print '<td class="liste_titre"></td>' ;
2018-04-30 20:02:16 +02:00
print '<td class="liste_titre" align="center">' ;
2018-04-29 19:52:14 +02:00
print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="month" value="' . dol_escape_htmltag ( $month ) . '">' ;
2015-04-23 07:26:09 +02:00
$syear = $year ;
$formother -> select_year ( $syear ? $syear :- 1 , 'year' , 1 , 20 , 5 );
print '</td>' ;
2014-05-01 07:44:10 +02:00
// Type
print '<td class="liste_titre" align="left">' ;
2018-03-07 19:00:38 +01:00
$form -> select_types_paiements ( $typeid , 'typeid' , '' , 0 , 1 , 1 , 16 );
2014-05-01 07:44:10 +02:00
print '</td>' ;
2016-08-11 18:41:31 +02:00
// Account
2016-08-11 18:18:03 +02:00
if ( ! empty ( $conf -> banque -> enabled ))
{
2016-12-11 16:11:42 +01:00
print '<td class="liste_titre">' ;
2016-08-11 18:18:03 +02:00
$form -> select_comptes ( $search_account , 'search_account' , 0 , '' , 1 );
print '</td>' ;
}
2014-11-02 14:19:28 +01:00
print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="' . $search_amount . '"></td>' ;
2016-02-07 15:50:48 +01:00
print '<td class="liste_titre" align="right">' ;
2017-05-14 21:06:33 +02:00
$searchpicto = $form -> showFilterAndCheckAddButtons ( 0 );
print $searchpicto ;
2016-02-07 15:50:48 +01:00
print '</td>' ;
print " </tr> \n " ;
2014-11-21 23:52:12 +01:00
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre">' ;
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " Ref " , $_SERVER [ " PHP_SELF " ], " t.rowid " , " " , $param , " " , $sortfield , $sortorder );
print_liste_field_titre ( " Label " , $_SERVER [ " PHP_SELF " ], " t.label " , " " , $param , 'align="left"' , $sortfield , $sortorder );
2018-04-28 17:18:38 +02:00
print_liste_field_titre ( " PeriodEndDate " , $_SERVER [ " PHP_SELF " ], " t.datev " , " " , $param , 'align="center"' , $sortfield , $sortorder );
2018-02-05 16:28:25 +01:00
print_liste_field_titre ( " DatePayment " , $_SERVER [ " PHP_SELF " ], " t.datep " , " " , $param , 'align="center"' , $sortfield , $sortorder );
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " Type " , $_SERVER [ " PHP_SELF " ], " type " , " " , $param , 'align="left"' , $sortfield , $sortorder );
if ( ! empty ( $conf -> banque -> enabled )) print_liste_field_titre ( " Account " , $_SERVER [ " PHP_SELF " ], " ba.label " , " " , $param , " " , $sortfield , $sortorder );
print_liste_field_titre ( " PayedByThisPayment " , $_SERVER [ " PHP_SELF " ], " t.amount " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2017-04-01 12:46:47 +02:00
print_liste_field_titre ( '' , $_SERVER [ " PHP_SELF " ], " " , '' , '' , '' , $sortfield , $sortorder , 'maxwidthsearch ' );
print " </tr> \n " ;
2017-06-09 09:25:15 +02:00
2014-05-01 07:44:10 +02:00
while ( $i < min ( $num , $limit ))
2003-06-20 16:30:08 +02:00
{
2005-05-08 21:25:55 +02:00
$obj = $db -> fetch_object ( $result );
2014-11-21 23:52:12 +01:00
2014-05-01 07:44:10 +02:00
if ( $obj -> payment_code <> '' )
{
2014-11-21 23:52:12 +01:00
$type = '<td>' . $langs -> trans ( " PaymentTypeShort " . $obj -> payment_code ) . ' ' . $obj -> num_payment . '</td>' ;
2014-05-01 07:44:10 +02:00
}
else
{
$type = '<td> </td>' ;
}
2014-11-21 23:52:12 +01:00
2017-04-01 12:46:47 +02:00
print '<tr class="oddeven">' ;
2009-02-04 23:43:51 +01:00
2008-04-03 21:35:46 +02:00
$tva_static -> id = $obj -> rowid ;
$tva_static -> ref = $obj -> rowid ;
2018-01-29 21:27:46 +01:00
// Ref
2008-04-03 21:35:46 +02:00
print " <td> " . $tva_static -> getNomUrl ( 1 ) . " </td> \n " ;
2018-01-29 21:27:46 +01:00
// Label
print " <td> " . dol_trunc ( $obj -> label , 40 ) . " </td> \n " ;
2018-02-05 16:28:25 +01:00
print '<td align="center">' . dol_print_date ( $db -> jdate ( $obj -> datev ), 'day' ) . " </td> \n " ;
print '<td align="center">' . dol_print_date ( $db -> jdate ( $obj -> datep ), 'day' ) . " </td> \n " ;
2016-03-25 14:49:48 +01:00
// Type
2014-05-01 07:44:10 +02:00
print $type ;
2016-08-11 18:18:03 +02:00
// Account
if ( ! empty ( $conf -> banque -> enabled ))
{
print '<td>' ;
if ( $obj -> fk_bank > 0 )
2017-05-31 05:27:39 +02:00
{
$bankstatic -> id = $obj -> bid ;
$bankstatic -> ref = $obj -> bref ;
$bankstatic -> number = $obj -> bnumber ;
$bankstatic -> account_number = $obj -> account_number ;
$accountingjournal = new AccountingJournal ( $db );
$accountingjournal -> fetch ( $obj -> fk_accountancy_journal );
$bankstatic -> accountancy_journal = $accountingjournal -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
$bankstatic -> label = $obj -> blabel ;
print $bankstatic -> getNomUrl ( 1 );
}
else print ' ' ;
print '</td>' ;
}
2014-04-30 06:37:47 +02:00
// Amount
2005-05-08 21:25:55 +02:00
$total = $total + $obj -> amount ;
2014-04-30 06:37:47 +02:00
print " <td align= \" right \" > " . price ( $obj -> amount ) . " </td> " ;
2016-08-11 18:18:03 +02:00
print " <td> </td> " ;
2005-05-08 21:25:55 +02:00
print " </tr> \n " ;
2009-02-04 23:43:51 +01:00
2005-05-08 21:25:55 +02:00
$i ++ ;
2003-06-20 16:30:08 +02:00
}
2017-06-09 09:25:15 +02:00
2016-08-11 18:18:03 +02:00
$colspan = 5 ;
if ( ! empty ( $conf -> banque -> enabled )) $colspan ++ ;
print '<tr class="liste_total"><td colspan="' . $colspan . '">' . $langs -> trans ( " Total " ) . '</td>' ;
2018-04-30 20:02:16 +02:00
print '<td align="right">' . price ( $total ) . '</td>' ;
2014-11-21 23:52:12 +01:00
print " <td> </td></tr> " ;
2009-02-04 23:43:51 +01:00
2005-05-08 21:25:55 +02:00
print " </table> " ;
2017-04-01 12:46:47 +02:00
print '</div>' ;
2017-06-09 09:25:15 +02:00
2014-05-01 07:44:10 +02:00
print '</form>' ;
2014-11-21 23:52:12 +01:00
2005-05-08 21:25:55 +02:00
$db -> free ( $result );
2002-09-26 16:26:32 +02:00
}
2003-06-20 16:30:08 +02:00
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2003-06-20 16:30:08 +02:00
}
2009-02-04 23:43:51 +01:00
2002-09-26 16:26:32 +02:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2014-11-21 23:52:12 +01:00
$db -> close ();