2004-10-19 22:35:36 +02:00
< ? php
2003-03-18 16:22:05 +01:00
/* Copyright ( C ) 2001 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2020-01-20 02:18:00 +01:00
* Copyright ( C ) 2004 - 2019 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2013 Regis Houssin < regis . houssin @ inodbox . com >
2015-04-18 23:11:17 +02:00
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
2017-04-05 20:50:18 +02:00
* Copyright ( C ) 2017 Patrick Delcroix < pmpdelcroix @ gmail . com >
2019-11-06 20:50:02 +01:00
* Copyright ( C ) 2019 Nicolas ZABOURI < info @ inovea - conseil . com >
2002-06-18 19:18:44 +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 19:18:44 +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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2003-03-18 16:22:05 +01:00
*/
2009-04-09 20:49:17 +02:00
2005-01-31 15:49:39 +01:00
/**
2009-04-09 20:49:17 +02:00
* \file htdocs / compta / bank / releve . php
* \ingroup banque
2016-10-23 23:13:03 +02:00
* \brief Page to show a bank statement report
2009-04-09 20:49:17 +02:00
*/
2004-10-10 17:04:56 +02:00
2018-07-26 11:57:25 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php' ;
2013-06-05 16:24:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/chargesociales.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/paiementfourn.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
2016-02-14 22:53:00 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/cheque/class/remisecheque.class.php' ;
2017-04-08 14:03:38 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php' ;
2020-01-03 16:35:02 +01:00
require_once DOL_DOCUMENT_ROOT . '/don/class/paymentdonation.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/loan/class/paymentloan.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/paymentvarious.class.php' ;
2017-04-05 20:50:18 +02:00
//show files
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php' ;
2013-06-05 16:24:32 +02:00
2018-05-27 09:40:17 +02:00
// Load translation files required by the page
2020-01-04 14:20:25 +01:00
$langs -> loadLangs ( array ( " banks " , " categories " , " companies " , " bills " , " trips " , " donations " , " loan " ));
2019-11-12 00:15:34 +01:00
$action = GETPOST ( 'action' , 'alpha' );
2020-02-24 00:41:25 +01:00
$id = GETPOST ( 'account' , 'int' ) ? GETPOST ( 'account' , 'int' ) : GETPOST ( 'id' , 'int' );
2019-11-12 00:15:34 +01:00
$ref = GETPOST ( 'ref' , 'alpha' );
$dvid = GETPOST ( 'dvid' , 'alpha' );
$numref = GETPOST ( 'num' , 'alpha' );
$ve = GETPOST ( " ve " , 'alpha' );
$brref = GETPOST ( 'brref' , 'alpha' );
$oldbankreceipt = GETPOST ( 'oldbankreceipt' , 'alpha' );
$newbankreceipt = GETPOST ( 'newbankreceipt' , 'alpha' );
2012-10-13 10:39:16 +02:00
2009-05-05 14:43:51 +02:00
// Security check
2019-11-12 00:15:34 +01:00
$fieldid = ( ! empty ( $ref ) ? $ref : $id );
$fieldname = isset ( $ref ) ? 'ref' : 'rowid' ;
if ( $user -> socid ) $socid = $user -> socid ;
$result = restrictedArea ( $user , 'banque' , $fieldid , 'bank_account' , '' , '' , $fieldname );
2004-10-10 17:04:56 +02:00
2019-11-12 00:15:34 +01:00
if ( $user -> rights -> banque -> consolidate && $action == 'dvnext' && ! empty ( $dvid ))
2004-04-06 09:21:07 +02:00
{
2012-02-15 12:16:33 +01:00
$al = new AccountLine ( $db );
2012-10-13 10:39:16 +02:00
$al -> datev_next ( $dvid );
2004-04-06 09:21:07 +02:00
}
2019-11-12 00:15:34 +01:00
if ( $user -> rights -> banque -> consolidate && $action == 'dvprev' && ! empty ( $dvid ))
2004-04-06 09:21:07 +02:00
{
2012-02-15 12:16:33 +01:00
$al = new AccountLine ( $db );
2012-10-13 10:39:16 +02:00
$al -> datev_previous ( $dvid );
2004-04-06 09:21:07 +02:00
}
2004-01-18 21:29:34 +01:00
2019-11-12 00:15:34 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2019-01-27 11:55:16 +01:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2019-01-27 11:55:16 +01:00
$pageplusone = GETPOST ( " pageplusone " , 'int' );
2016-10-29 17:46:11 +02:00
if ( $pageplusone ) $page = $pageplusone - 1 ;
2017-06-06 10:53:53 +02:00
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
2016-10-29 17:46:11 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2019-11-12 00:15:34 +01:00
if ( ! $sortorder ) $sortorder = " ASC " ;
if ( ! $sortfield ) $sortfield = " s.nom " ;
2006-08-13 02:34:16 +02:00
2016-10-29 17:46:11 +02:00
$object = new Account ( $db );
2019-11-12 00:15:34 +01:00
if ( $id > 0 || ! empty ( $ref ))
2016-10-29 17:46:11 +02:00
{
2019-11-12 00:15:34 +01:00
$result = $object -> fetch ( $id , $ref );
$account = $object -> id ; // Force the search field on id of account
2016-10-29 17:46:11 +02:00
}
// Initialize technical object to manage context to save list fields
2019-11-12 00:15:34 +01:00
$contextpage = 'banktransactionlist' . ( empty ( $object -> ref ) ? '' : '-' . $object -> id );
2017-04-06 23:28:06 +02:00
2017-10-13 21:25:27 +02:00
// Define number of receipt to show (current, previous or next one ?)
2019-11-12 00:15:34 +01:00
$found = false ;
2017-10-13 21:25:27 +02:00
if ( $_GET [ " rel " ] == 'prev' )
{
// Recherche valeur pour num = numero releve precedent
$sql = " SELECT DISTINCT(b.num_releve) as num " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " WHERE b.num_releve < ' " . $db -> escape ( $numref ) . " ' " ;
$sql .= " AND b.fk_account = " . $object -> id ;
$sql .= " ORDER BY b.num_releve DESC " ;
2017-10-13 21:25:27 +02:00
dol_syslog ( " htdocs/compta/bank/releve.php " , LOG_DEBUG );
$resql = $db -> query ( $sql );
if ( $resql )
{
$numrows = $db -> num_rows ( $resql );
if ( $numrows > 0 )
{
$obj = $db -> fetch_object ( $resql );
$numref = $obj -> num ;
2019-11-12 00:15:34 +01:00
$found = true ;
2017-10-13 21:25:27 +02:00
}
}
2020-05-21 15:05:19 +02:00
} elseif ( $_GET [ " rel " ] == 'next' )
2017-10-13 21:25:27 +02:00
{
// Recherche valeur pour num = numero releve precedent
$sql = " SELECT DISTINCT(b.num_releve) as num " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " WHERE b.num_releve > ' " . $db -> escape ( $numref ) . " ' " ;
$sql .= " AND b.fk_account = " . $object -> id ;
$sql .= " ORDER BY b.num_releve ASC " ;
2017-10-13 21:25:27 +02:00
dol_syslog ( " htdocs/compta/bank/releve.php " , LOG_DEBUG );
$resql = $db -> query ( $sql );
if ( $resql )
{
$numrows = $db -> num_rows ( $resql );
if ( $numrows > 0 )
{
$obj = $db -> fetch_object ( $resql );
$numref = $obj -> num ;
2019-11-12 00:15:34 +01:00
$found = true ;
2017-10-13 21:25:27 +02:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 21:25:27 +02:00
// On veut le releve num
2019-11-12 00:15:34 +01:00
$found = true ;
2017-10-13 21:25:27 +02:00
}
2017-04-08 14:03:38 +02:00
$sql = " SELECT b.rowid, b.dateo as do, b.datev as dv, " ;
2019-11-12 00:15:34 +01:00
$sql .= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, " ;
$sql .= " b.fk_bordereau, " ;
$sql .= " bc.ref, " ;
$sql .= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " bank_account as ba " ;
$sql .= " , " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bordereau_cheque as bc ON bc.rowid=b.fk_bordereau' ;
$sql .= " WHERE b.num_releve=' " . $db -> escape ( $numref ) . " ' " ;
if ( empty ( $numref )) $sql .= " OR b.num_releve is null " ;
$sql .= " AND b.fk_account = " . $object -> id ;
$sql .= " AND b.fk_account = ba.rowid " ;
$sql .= $db -> order ( " b.datev, b.datec " , " ASC " ); // We add date of creation to have correct order when everything is done the same day
2017-04-08 14:03:38 +02:00
$sqlrequestforbankline = $sql ;
/*
* Actions
*/
2017-04-06 23:28:06 +02:00
2019-11-12 00:15:34 +01:00
if ( $action == 'confirm_editbankreceipt' && ! empty ( $oldbankreceipt ) && ! empty ( $newbankreceipt ))
2017-10-13 23:38:57 +02:00
{
// TODO Add a test to check newbankreceipt does not exists yet
2020-05-19 15:35:37 +02:00
$sqlupdate = 'UPDATE ' . MAIN_DB_PREFIX . 'bank SET num_releve = "' . $db -> escape ( $newbankreceipt ) . '" WHERE num_releve = "' . $db -> escape ( $oldbankreceipt ) . '" AND fk_account = ' . $id ;
2017-10-13 23:38:57 +02:00
$result = $db -> query ( $sqlupdate );
if ( $result < 0 ) dol_print_error ( $db );
2019-11-12 00:15:34 +01:00
$action = 'view' ;
2017-10-13 23:38:57 +02:00
}
2006-08-13 02:34:16 +02:00
2009-04-09 20:49:17 +02:00
/*
* View
*/
2016-08-29 21:49:34 +02:00
$title = $langs -> trans ( " FinancialAccount " ) . ' - ' . $langs -> trans ( " AccountStatements " );
$helpurl = " " ;
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $title , $helpurl );
2003-08-26 12:10:42 +02:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2019-11-12 00:15:34 +01:00
$societestatic = new Societe ( $db );
$chargestatic = new ChargeSociales ( $db );
$memberstatic = new Adherent ( $db );
$paymentstatic = new Paiement ( $db );
$paymentsupplierstatic = new PaiementFourn ( $db );
$paymentvatstatic = new TVA ( $db );
$bankstatic = new Account ( $db );
$banklinestatic = new AccountLine ( $db );
2016-02-14 22:53:00 +01:00
$remisestatic = new RemiseCheque ( $db );
2020-04-10 10:59:32 +02:00
$paymentdonationstatic = new PaymentDonation ( $db );
$paymentloanstatic = new PaymentLoan ( $db );
$paymentvariousstatic = new PaymentVarious ( $db );
2004-02-07 02:10:54 +01:00
2016-10-29 17:46:11 +02:00
// Must be before button action
2019-11-12 00:15:34 +01:00
$param = '' ;
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) $param .= '&contextpage=' . $contextpage ;
if ( $limit > 0 && $limit != $conf -> liste_limit ) $param .= '&limit=' . $limit ;
if ( $id > 0 ) $param .= '&id=' . urlencode ( $id );
2016-10-29 17:46:11 +02:00
2004-02-07 02:10:54 +01:00
2017-04-06 22:31:45 +02:00
if ( empty ( $numref ))
2003-03-18 16:22:05 +01:00
{
2019-11-12 00:15:34 +01:00
$sortfield = 'numr' ;
$sortorder = 'DESC' ;
2017-12-10 15:46:35 +01:00
2017-04-06 23:28:06 +02:00
// List of all standing receipts
2009-05-05 14:43:51 +02:00
$sql = " SELECT DISTINCT(b.num_releve) as numr " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " WHERE b.fk_account = " . $object -> id ;
$sql .= $db -> order ( $sortfield , $sortorder );
2017-12-10 15:46:35 +01:00
// Count total nb of records
$nbtotalofrecords = '' ;
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST ))
{
$result = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $result );
}
2009-08-07 20:39:01 +02:00
2019-11-12 00:15:34 +01:00
$sql .= $db -> plimit ( $conf -> liste_limit + 1 , $offset );
2006-08-13 02:34:16 +02:00
$result = $db -> query ( $sql );
if ( $result )
2003-03-18 16:22:05 +01:00
{
2006-08-13 02:34:16 +02:00
$numrows = $db -> num_rows ( $result );
$i = 0 ;
// Onglets
2019-11-12 00:15:34 +01:00
$head = bank_prepare_head ( $object );
2019-01-27 11:55:16 +01:00
dol_fiche_head ( $head , 'statement' , $langs -> trans ( " FinancialAccount " ), 0 , 'account' );
2002-05-11 20:53:13 +02:00
2017-10-03 16:00:52 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/compta/bank/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-07-15 21:19:39 +02:00
2020-07-10 13:40:33 +02:00
$morehtmlref = '' ;
2016-10-22 13:20:14 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref , '' , 0 , '' , '' , 1 );
2017-07-15 21:19:39 +02:00
2015-05-15 12:53:14 +02:00
dol_fiche_end ();
2009-04-09 20:49:17 +02:00
2017-07-15 21:19:39 +02:00
2015-08-28 20:11:16 +02:00
print '<div class="tabsAction">' ;
2016-03-05 14:05:00 +01:00
if ( $object -> canBeConciliated () > 0 ) {
2015-08-28 20:11:16 +02:00
// If not cash account and can be reconciliate
2016-03-05 14:05:00 +01:00
if ( $user -> rights -> banque -> consolidate ) {
2019-07-05 13:11:30 +02:00
print '<a class="butAction" href="' . DOL_URL_ROOT . '/compta/bank/bankentries_list.php?action=reconcile&sortfield=b.datev,b.dateo,b.rowid&sortorder=asc,asc,asc&search_conciliated=0&search_account=' . $id . $param . '">' . $langs -> trans ( " Conciliate " ) . '</a>' ;
2016-03-05 14:05:00 +01:00
} else {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" title="' . $langs -> trans ( " NotEnoughPermissions " ) . '" href="#">' . $langs -> trans ( " Conciliate " ) . '</a>' ;
2015-08-28 20:11:16 +02:00
}
}
print '</div>' ;
2017-07-15 21:19:39 +02:00
2009-04-09 20:49:17 +02:00
2019-01-27 11:55:16 +01:00
print_barre_liste ( '' , $page , $_SERVER [ " PHP_SELF " ], " &account= " . $object -> id , $sortfield , $sortorder , '' , $numrows , $totalnboflines , '' );
2006-08-13 17:20:25 +02:00
2019-10-08 15:47:47 +02:00
print '<form name="aaa" action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-13 23:38:57 +02:00
print '<input type="hidden" name="action" value="confirm_editbankreceipt">' ;
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">' ;
print '<input type="hidden" name="account" value="' . $object -> id . '">' ;
2019-10-08 15:47:47 +02:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
2017-10-13 23:38:57 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2013-05-12 20:10:16 +02:00
print '<tr class="liste_titre">' ;
2017-12-10 15:46:35 +01:00
print '<td>' . $langs -> trans ( " Ref " ) . '</td>' ;
2019-01-24 10:02:06 +01:00
print '<td class="right">' . $langs -> trans ( " InitialBankBalance " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " EndBankBalance " ) . '</td>' ;
2017-10-13 23:38:57 +02:00
print '<td></td>' ;
2015-02-07 23:32:46 +01:00
print '</tr>' ;
2019-11-12 00:15:34 +01:00
$balancestart = array ();
$content = array ();
2006-08-13 02:34:16 +02:00
2019-01-27 11:55:16 +01:00
while ( $i < min ( $numrows , $conf -> liste_limit ))
2006-08-13 02:34:16 +02:00
{
$objp = $db -> fetch_object ( $result );
2017-04-06 22:31:45 +02:00
2019-11-12 00:15:34 +01:00
if ( ! isset ( $objp -> numr ))
2006-08-13 02:34:16 +02:00
{
//
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 23:38:57 +02:00
print '<tr class="oddeven">' ;
print '<td>' ;
if ( $action != 'editbankreceipt' || $objp -> numr != $brref )
{
print '<a href="releve.php?num=' . $objp -> numr . '&account=' . $object -> id . '">' . $objp -> numr . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 23:38:57 +02:00
print '<input type="hidden" name="oldbankreceipt" value="' . $objp -> numr . '">' ;
print '<input type="text" name="newbankreceipt" value="' . $objp -> numr . '">' ;
print '<input type="submit" class="button" name="actionnewbankreceipt" value="' . $langs -> trans ( " Rename " ) . '">' ;
print '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
}
print '</td>' ;
2015-02-07 23:32:46 +01:00
// Calculate start amount
$sql = " SELECT sum(b.amount) as amount " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " WHERE b.num_releve < ' " . $db -> escape ( $objp -> numr ) . " ' " ;
$sql .= " AND b.fk_account = " . $object -> id ;
$resql = $db -> query ( $sql );
2015-02-07 23:32:46 +01:00
if ( $resql )
{
2019-11-12 00:15:34 +01:00
$obj = $db -> fetch_object ( $resql );
2015-02-07 23:32:46 +01:00
$balancestart [ $objp -> numr ] = $obj -> amount ;
$db -> free ( $resql );
}
2019-01-27 11:55:16 +01:00
print '<td class="right">' . price ( $balancestart [ $objp -> numr ], '' , $langs , 1 , - 1 , - 1 , $conf -> currency ) . '</td>' ;
2015-02-07 23:32:46 +01:00
// Calculate end amount
$sql = " SELECT sum(b.amount) as amount " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " WHERE b.num_releve = ' " . $db -> escape ( $objp -> numr ) . " ' " ;
$sql .= " AND b.fk_account = " . $object -> id ;
$resql = $db -> query ( $sql );
2015-02-07 23:32:46 +01:00
if ( $resql )
{
2019-11-12 00:15:34 +01:00
$obj = $db -> fetch_object ( $resql );
2015-02-07 23:32:46 +01:00
$content [ $objp -> numr ] = $obj -> amount ;
$db -> free ( $resql );
}
2019-11-12 00:15:34 +01:00
print '<td class="right">' . price (( $balancestart [ $objp -> numr ] + $content [ $objp -> numr ]), '' , $langs , 1 , - 1 , - 1 , $conf -> currency ) . '</td>' ;
2015-02-07 23:32:46 +01:00
2019-02-23 22:56:38 +01:00
print '<td class="center">' ;
2017-10-13 23:38:57 +02:00
if ( $user -> rights -> banque -> consolidate && $action != 'editbankreceipt' ) {
2019-10-08 15:48:29 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?account=' . $object -> id . ( $page > 0 ? '&page=' . $page : '' ) . '&action=editbankreceipt&brref=' . $objp -> numr . '">' . img_edit () . '</a>' ;
2017-10-13 23:38:57 +02:00
}
print '</td>' ;
2015-02-07 23:32:46 +01:00
print '</tr>' . " \n " ;
2006-08-13 02:34:16 +02:00
}
$i ++ ;
}
print " </table> \n " ;
2017-10-13 23:38:57 +02:00
print '</form>' ;
2009-04-09 20:49:17 +02:00
2006-08-13 02:34:16 +02:00
print " \n </div> \n " ;
2020-05-21 15:05:19 +02:00
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2006-08-13 02:34:16 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2006-08-13 02:34:16 +02:00
/**
2020-01-19 20:33:55 +01:00
* Show list of record into a bank statement
2009-04-09 20:49:17 +02:00
*/
2006-08-13 02:34:16 +02:00
2019-11-05 13:51:52 +01:00
// Onglets
2019-11-12 00:15:34 +01:00
$head = account_statement_prepare_head ( $object , $numref );
2020-01-20 02:18:00 +01:00
dol_fiche_head ( $head , 'statement' , $langs -> trans ( " AccountStatement " ), - 1 , 'account' );
2019-11-05 13:51:52 +01:00
2020-07-10 13:40:33 +02:00
$morehtmlright = '' ;
$morehtmlright .= '<div class="pagination"><ul>' ;
$morehtmlright .= '<li class="pagination"><a class="paginationnext" href="' . $_SERVER [ " PHP_SELF " ] . '?rel=prev&num=' . $numref . '&ve=' . $ve . '&account=' . $object -> id . '"><i class="fa fa-chevron-left" title="' . dol_escape_htmltag ( $langs -> trans ( " Previous " )) . '"></i></a></li>' ;
$morehtmlright .= '<li class="pagination"><span class="active">' . $langs -> trans ( " AccountStatement " ) . " " . $numref . '</span></li>' ;
$morehtmlright .= '<li class="pagination"><a class="paginationnext" href="' . $_SERVER [ " PHP_SELF " ] . '?rel=next&num=' . $numref . '&ve=' . $ve . '&account=' . $object -> id . '"><i class="fa fa-chevron-right" title="' . dol_escape_htmltag ( $langs -> trans ( " Next " )) . '"></i></a></li>' ;
$morehtmlright .= '</ul></div>' ;
2017-07-15 21:19:39 +02:00
2019-11-12 00:15:34 +01:00
$title = $langs -> trans ( " AccountStatement " ) . ' ' . $numref . ' - ' . $langs -> trans ( " BankAccount " ) . ' ' . $object -> getNomUrl ( 1 , 'receipts' );
2020-07-10 13:40:33 +02:00
print load_fiche_titre ( $title , $morehtmlright , '' );
2020-04-09 16:36:39 +02:00
//print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, 0, $nbtotalofrecords, 'bank_account', 0, '', '', 0, 1);
2006-08-13 02:34:16 +02:00
print " <form method= \" post \" action= \" releve.php \" > " ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2018-04-09 00:03:13 +02:00
print '<input type="hidden" name="action" value="add">' ;
2006-08-13 02:34:16 +02:00
2017-01-18 15:49:12 +01:00
print '<div class="div-table-responsive">' ;
2019-02-23 22:56:38 +01:00
print '<table class="noborder centpercent">' ;
2006-08-13 02:34:16 +02:00
print '<tr class="liste_titre">' ;
2019-02-23 22:56:38 +01:00
print '<td class="center">' . $langs -> trans ( " DateOperationShort " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " DateValueShort " ) . '</td>' ;
2006-08-13 02:34:16 +02:00
print '<td>' . $langs -> trans ( " Type " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
2019-01-24 10:02:06 +01:00
print '<td class="right" width="60">' . $langs -> trans ( " Debit " ) . '</td>' ;
print '<td class="right" width="60">' . $langs -> trans ( " Credit " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " Balance " ) . '</td>' ;
2006-08-13 02:34:16 +02:00
print '<td> </td>' ;
print " </tr> \n " ;
2009-05-05 14:43:51 +02:00
// Calcul du solde de depart du releve
$sql = " SELECT sum(b.amount) as amount " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " WHERE b.num_releve < ' " . $db -> escape ( $numref ) . " ' " ;
$sql .= " AND b.fk_account = " . $object -> id ;
2009-08-07 20:39:01 +02:00
2019-11-12 00:15:34 +01:00
$resql = $db -> query ( $sql );
2006-08-13 02:34:16 +02:00
if ( $resql )
{
2019-11-12 00:15:34 +01:00
$obj = $db -> fetch_object ( $resql );
2006-08-13 02:34:16 +02:00
$total = $obj -> amount ;
$db -> free ( $resql );
}
2009-05-05 14:43:51 +02:00
// Recherche les ecritures pour le releve
2017-04-08 14:03:38 +02:00
$sql = $sqlrequestforbankline ;
2017-07-15 21:19:39 +02:00
2006-08-13 02:34:16 +02:00
$result = $db -> query ( $sql );
if ( $result )
{
$numrows = $db -> num_rows ( $result );
$i = 0 ;
2009-04-09 20:49:17 +02:00
// Ligne Solde debut releve
2017-04-08 14:03:38 +02:00
print '<tr class="oddeven"><td colspan="3"></td>' ;
print '<td colspan="3"><b>' . $langs -> trans ( " InitialBankBalance " ) . " :</b></td> " ;
print '<td class="right"><b>' . price ( $total ) . '</b></td><td> </td>' ;
2017-01-18 15:23:37 +01:00
print " </tr> \n " ;
2006-08-13 02:34:16 +02:00
while ( $i < $numrows )
{
$objp = $db -> fetch_object ( $result );
$total = $total + $objp -> amount ;
2017-04-07 16:44:43 +02:00
print '<tr class="oddeven">' ;
2006-08-13 02:34:16 +02:00
// Date operation
2019-02-23 22:56:38 +01:00
print '<td class="nowrap center">' . dol_print_date ( $db -> jdate ( $objp -> do ), " day " ) . '</td>' ;
2006-08-13 02:34:16 +02:00
// Date de valeur
2019-02-23 22:56:38 +01:00
print '<td valign="center" class="center nowrap">' ;
2019-11-12 00:15:34 +01:00
print dol_print_date ( $db -> jdate ( $objp -> dv ), " day " ) . ' ' ;
2020-01-19 20:33:55 +01:00
print '<a class="ajax reposition" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=dvprev&num=' . $numref . '&account=' . $object -> id . '&dvid=' . $objp -> rowid . '">' ;
2019-11-12 00:15:34 +01:00
print img_edit_remove () . " </a> " ;
2020-01-19 20:33:55 +01:00
print '<a class="ajax reposition" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=dvnext&num=' . $numref . '&account=' . $object -> id . '&dvid=' . $objp -> rowid . '">' ;
2019-11-12 00:15:34 +01:00
print img_edit_add () . " </a> " ;
2006-08-13 02:34:16 +02:00
print " </td> \n " ;
2017-07-15 21:19:39 +02:00
2013-07-13 17:25:10 +02:00
// Type and num
2014-05-01 16:32:04 +02:00
if ( $objp -> fk_type == 'SOLD' ) {
2019-11-12 00:15:34 +01:00
$type_label = ' ' ;
2014-05-01 16:32:04 +02:00
} else {
2019-11-12 00:15:34 +01:00
$type_label = ( $langs -> trans ( " PaymentTypeShort " . $objp -> fk_type ) != " PaymentTypeShort " . $objp -> fk_type ) ? $langs -> trans ( " PaymentTypeShort " . $objp -> fk_type ) : $objp -> fk_type ;
2014-05-01 16:32:04 +02:00
}
2019-11-12 00:15:34 +01:00
$link = '' ;
if ( $objp -> fk_bordereau > 0 ) {
2016-02-14 22:53:00 +01:00
$remisestatic -> id = $objp -> fk_bordereau ;
2016-04-22 11:44:23 +02:00
$remisestatic -> ref = $objp -> ref ;
2016-02-14 22:53:00 +01:00
$link = ' ' . $remisestatic -> getNomUrl ( 1 );
}
2019-11-12 00:15:34 +01:00
print '<td class="nowrap">' . $type_label . ' ' . ( $objp -> num_chq ? $objp -> num_chq : '' ) . $link . '</td>' ;
2006-08-13 02:34:16 +02:00
2013-07-13 17:25:10 +02:00
// Description
2020-01-19 19:33:57 +01:00
print '<td valign="center">' ;
print '<a href="' . DOL_URL_ROOT . '/compta/bank/line.php?rowid=' . $objp -> rowid . '&account=' . $object -> id . '">' ;
2019-11-12 00:15:34 +01:00
$reg = array ();
preg_match ( '/\((.+)\)/i' , $objp -> label , $reg ); // Si texte entoure de parenthese on tente recherche de traduction
if ( $reg [ 1 ] && $langs -> trans ( $reg [ 1 ]) != $reg [ 1 ]) print $langs -> trans ( $reg [ 1 ]);
2006-06-25 21:24:25 +02:00
else print $objp -> label ;
2006-08-13 02:34:16 +02:00
print '</a>' ;
/*
2009-04-09 20:49:17 +02:00
* Ajout les liens ( societe , company ... )
*/
2019-11-12 00:15:34 +01:00
$newline = 1 ;
2015-08-28 20:11:16 +02:00
$links = $object -> get_url ( $objp -> rowid );
2019-11-12 00:15:34 +01:00
foreach ( $links as $key => $val )
2006-08-13 02:34:16 +02:00
{
2019-11-12 00:15:34 +01:00
if ( ! $newline ) print ' - ' ;
2006-08-13 02:34:16 +02:00
else print '<br>' ;
2019-11-12 00:15:34 +01:00
if ( $links [ $key ][ 'type' ] == 'payment' )
2006-08-13 02:34:16 +02:00
{
2019-11-12 00:15:34 +01:00
$paymentstatic -> id = $links [ $key ][ 'url_id' ];
$paymentstatic -> ref = $langs -> trans ( " Payment " );
2013-05-12 20:10:16 +02:00
print ' ' . $paymentstatic -> getNomUrl ( 1 );
2019-11-12 00:15:34 +01:00
$newline = 0 ;
2020-05-21 15:05:19 +02:00
} elseif ( $links [ $key ][ 'type' ] == 'payment_supplier' )
2013-05-12 20:10:16 +02:00
{
2019-11-12 00:15:34 +01:00
$paymentsupplierstatic -> id = $links [ $key ][ 'url_id' ];
$paymentsupplierstatic -> ref = $langs -> trans ( " Payment " );
2013-05-12 20:10:16 +02:00
print ' ' . $paymentsupplierstatic -> getNomUrl ( 1 );
2019-11-12 00:15:34 +01:00
$newline = 0 ;
2020-05-21 15:05:19 +02:00
} elseif ( $links [ $key ][ 'type' ] == 'payment_sc' )
2013-05-12 20:10:16 +02:00
{
2014-09-18 21:18:25 +02:00
print '<a href="' . DOL_URL_ROOT . '/compta/payment_sc/card.php?id=' . $links [ $key ][ 'url_id' ] . '">' ;
2019-01-27 11:55:16 +01:00
print ' ' . img_object ( $langs -> trans ( 'ShowPayment' ), 'payment' ) . ' ' ;
2013-06-05 16:24:32 +02:00
print $langs -> trans ( " SocialContributionPayment " );
print '</a>' ;
2019-11-12 00:15:34 +01:00
$newline = 0 ;
2020-05-21 15:05:19 +02:00
} elseif ( $links [ $key ][ 'type' ] == 'payment_vat' )
2013-06-05 16:24:32 +02:00
{
2019-11-12 00:15:34 +01:00
$paymentvatstatic -> id = $links [ $key ][ 'url_id' ];
$paymentvatstatic -> ref = $langs -> trans ( " Payment " );
2013-07-13 17:25:10 +02:00
print ' ' . $paymentvatstatic -> getNomUrl ( 1 );
2020-05-21 15:05:19 +02:00
} elseif ( $links [ $key ][ 'type' ] == 'payment_salary' )
2017-04-06 23:28:06 +02:00
{
2019-07-19 23:08:24 +02:00
print '<a href="' . DOL_URL_ROOT . '/salaries/card.php?id=' . $links [ $key ][ 'url_id' ] . '">' ;
2019-01-27 11:55:16 +01:00
print ' ' . img_object ( $langs -> trans ( 'ShowPayment' ), 'payment' ) . ' ' ;
2017-04-06 23:28:06 +02:00
print $langs -> trans ( " Payment " );
print '</a>' ;
2019-11-12 00:15:34 +01:00
$newline = 0 ;
2020-05-21 15:05:19 +02:00
} elseif ( $links [ $key ][ 'type' ] == 'payment_donation' )
2020-01-03 16:35:02 +01:00
{
2020-04-10 10:59:32 +02:00
$paymentdonationstatic -> id = $links [ $key ][ 'url_id' ];
$paymentdonationstatic -> ref = $langs -> trans ( " Payment " );
2020-01-03 16:35:02 +01:00
print ' ' . $paymentdonationstatic -> getNomUrl ( 1 );
$newline = 0 ;
2020-05-21 15:05:19 +02:00
} elseif ( $links [ $key ][ 'type' ] == 'payment_loan' )
2020-01-03 16:35:02 +01:00
{
2020-04-10 10:59:32 +02:00
$paymentloanstatic -> id = $links [ $key ][ 'url_id' ];
$paymentloanstatic -> ref = $langs -> trans ( " Payment " );
2020-01-03 16:35:02 +01:00
print ' ' . $paymentloanstatic -> getNomUrl ( 1 );
$newline = 0 ;
2020-05-21 15:05:19 +02:00
} elseif ( $links [ $key ][ 'type' ] == 'payment_various' )
2020-01-03 16:35:02 +01:00
{
2020-04-10 10:59:32 +02:00
$paymentvariousstatic -> id = $links [ $key ][ 'url_id' ];
$paymentvariousstatic -> ref = $langs -> trans ( " Payment " );
2020-01-03 16:35:02 +01:00
print ' ' . $paymentvariousstatic -> getNomUrl ( 1 );
$newline = 0 ;
2020-05-21 15:05:19 +02:00
} elseif ( $links [ $key ][ 'type' ] == 'banktransfert' ) {
2013-06-05 16:24:32 +02:00
// Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail.
if ( $objp -> amount > 0 )
{
$banklinestatic -> fetch ( $links [ $key ][ 'url_id' ]);
2019-11-12 00:15:34 +01:00
$bankstatic -> id = $banklinestatic -> fk_account ;
$bankstatic -> label = $banklinestatic -> bank_account_label ;
2013-06-05 16:24:32 +02:00
print ' (' . $langs -> trans ( " from " ) . ' ' ;
2019-01-27 11:55:16 +01:00
print $bankstatic -> getNomUrl ( 1 , 'transactions' );
2013-06-05 16:24:32 +02:00
print ' ' . $langs -> trans ( " toward " ) . ' ' ;
2019-11-12 00:15:34 +01:00
$bankstatic -> id = $objp -> bankid ;
$bankstatic -> label = $objp -> bankref ;
2019-01-27 11:55:16 +01:00
print $bankstatic -> getNomUrl ( 1 , '' );
2013-06-05 16:24:32 +02:00
print ')' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 00:15:34 +01:00
$bankstatic -> id = $objp -> bankid ;
$bankstatic -> label = $objp -> bankref ;
2013-06-05 16:24:32 +02:00
print ' (' . $langs -> trans ( " from " ) . ' ' ;
2019-01-27 11:55:16 +01:00
print $bankstatic -> getNomUrl ( 1 , '' );
2013-06-05 16:24:32 +02:00
print ' ' . $langs -> trans ( " toward " ) . ' ' ;
$banklinestatic -> fetch ( $links [ $key ][ 'url_id' ]);
2019-11-12 00:15:34 +01:00
$bankstatic -> id = $banklinestatic -> fk_account ;
$bankstatic -> label = $banklinestatic -> bank_account_label ;
2019-01-27 11:55:16 +01:00
print $bankstatic -> getNomUrl ( 1 , 'transactions' );
2013-06-05 16:24:32 +02:00
print ')' ;
}
2020-05-21 15:05:19 +02:00
} elseif ( $links [ $key ][ 'type' ] == 'company' ) {
2015-01-25 01:20:58 +01:00
$societestatic -> id = $links [ $key ][ 'url_id' ];
$societestatic -> name = $links [ $key ][ 'label' ];
print $societestatic -> getNomUrl ( 1 , 'company' , 24 );
2019-11-12 00:15:34 +01:00
$newline = 0 ;
2020-05-21 15:05:19 +02:00
} elseif ( $links [ $key ][ 'type' ] == 'member' ) {
2014-09-18 21:18:25 +02:00
print '<a href="' . DOL_URL_ROOT . '/adherents/card.php?rowid=' . $links [ $key ][ 'url_id' ] . '">' ;
2019-01-27 11:55:16 +01:00
print img_object ( $langs -> trans ( 'ShowMember' ), 'user' ) . ' ' ;
2007-11-05 00:08:52 +01:00
print $links [ $key ][ 'label' ];
print '</a>' ;
2019-11-12 00:15:34 +01:00
$newline = 0 ;
2020-05-21 15:05:19 +02:00
} elseif ( $links [ $key ][ 'type' ] == 'user' ) {
2017-11-24 14:23:25 +01:00
print '<a href="' . DOL_URL_ROOT . '/user/card.php?id=' . $links [ $key ][ 'url_id' ] . '">' ;
2019-01-27 11:55:16 +01:00
print img_object ( $langs -> trans ( 'ShowUser' ), 'user' ) . ' ' ;
2017-04-06 23:28:06 +02:00
print $links [ $key ][ 'label' ];
print '</a>' ;
2019-11-12 00:15:34 +01:00
$newline = 0 ;
2020-05-21 15:05:19 +02:00
} elseif ( $links [ $key ][ 'type' ] == 'sc' ) {
2016-08-22 13:43:49 +02:00
print '<a href="' . DOL_URL_ROOT . '/compta/sociales/card.php?id=' . $links [ $key ][ 'url_id' ] . '">' ;
2019-01-27 11:55:16 +01:00
print img_object ( $langs -> trans ( 'ShowBill' ), 'bill' ) . ' ' ;
2013-05-12 20:10:16 +02:00
print $langs -> trans ( " SocialContribution " );
print '</a>' ;
2019-11-12 00:15:34 +01:00
$newline = 0 ;
2020-05-21 15:05:19 +02:00
} else {
2006-08-13 02:34:16 +02:00
print '<a href="' . $links [ $key ][ 'url' ] . $links [ $key ][ 'url_id' ] . '">' ;
print $links [ $key ][ 'label' ];
print '</a>' ;
2019-11-12 00:15:34 +01:00
$newline = 0 ;
2006-08-13 02:34:16 +02:00
}
}
2009-04-09 20:49:17 +02:00
// Categories
2006-08-13 02:34:16 +02:00
if ( $ve )
{
2009-05-05 14:43:51 +02:00
$sql = " SELECT label " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank_categ as ct " ;
$sql .= " , " . MAIN_DB_PREFIX . " bank_class as cl " ;
$sql .= " WHERE ct.rowid = cl.fk_categ " ;
$sql .= " AND ct.entity = " . $conf -> entity ;
$sql .= " AND cl.lineid = " . $objp -> rowid ;
2009-08-07 20:39:01 +02:00
2006-08-13 02:34:16 +02:00
$resc = $db -> query ( $sql );
if ( $resc )
{
$numc = $db -> num_rows ( $resc );
$ii = 0 ;
2019-11-12 00:15:34 +01:00
if ( $numc && ! $newline ) print '<br>' ;
2006-08-13 02:34:16 +02:00
while ( $ii < $numc )
{
$objc = $db -> fetch_object ( $resc );
2018-04-09 00:01:15 +02:00
print " <br>- <i> " . $objc -> label . " </i> " ;
2006-08-13 02:34:16 +02:00
$ii ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2006-08-13 02:34:16 +02:00
}
}
2017-10-13 21:25:27 +02:00
2006-08-13 02:34:16 +02:00
print " </td> " ;
if ( $objp -> amount < 0 )
{
$totald = $totald + abs ( $objp -> amount );
2019-02-04 13:44:02 +01:00
print '<td class="nowrap right">' . price ( $objp -> amount * - 1 ) . " </td><td> </td> \n " ;
2020-05-21 15:05:19 +02:00
} else {
2006-08-13 02:34:16 +02:00
$totalc = $totalc + abs ( $objp -> amount );
2019-02-04 13:44:02 +01:00
print '<td> </td><td class="nowrap right">' . price ( $objp -> amount ) . " </td> \n " ;
2006-08-13 02:34:16 +02:00
}
2019-02-04 13:44:02 +01:00
print '<td class="nowrap right">' . price ( price2num ( $total , 'MT' )) . " </td> \n " ;
2006-08-13 02:34:16 +02:00
2007-12-14 10:35:15 +01:00
if ( $user -> rights -> banque -> modifier || $user -> rights -> banque -> consolidate )
2006-08-13 02:34:16 +02:00
{
2020-07-10 13:59:54 +02:00
print '<td class="center"><a class="editfielda reposition" href="' . DOL_URL_ROOT . '/compta/bank/line.php?rowid=' . $objp -> rowid . '&account=' . $object -> id . '&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?account=' . $object -> id . '&num=' . $numref ) . '">' ;
2006-08-13 02:34:16 +02:00
print img_edit ();
print " </a></td> " ;
2020-05-21 15:05:19 +02:00
} else {
2019-02-23 22:56:38 +01:00
print " <td class= \" center \" > </td> " ;
2006-08-13 02:34:16 +02:00
}
print " </tr> " ;
$i ++ ;
}
$db -> free ( $result );
}
2011-04-17 17:13:10 +02:00
// Line Total
2019-02-23 22:56:38 +01:00
print " \n " . '<tr class="liste_total"><td class="right" colspan="4">' . $langs -> trans ( " Total " ) . " :</td><td class= \" right \" > " . price ( $totald ) . " </td><td class= \" right \" > " . price ( $totalc ) . " </td><td> </td><td> </td></tr> " ;
2006-08-13 02:34:16 +02:00
2011-04-17 17:13:10 +02:00
// Line Balance
2018-04-09 00:01:15 +02:00
print " \n <tr> " ;
2019-02-23 22:56:38 +01:00
print " <td class= \" right \" colspan= \" 3 \" > </td><td colspan= \" 3 \" ><b> " . $langs -> trans ( " EndBankBalance " ) . " :</b></td> " ;
2018-04-09 00:01:15 +02:00
print '<td class="right"><b>' . price ( price2num ( $total , 'MT' )) . " </b></td><td> </td> " ;
2017-01-18 15:23:37 +01:00
print " </tr> \n " ;
2017-01-18 15:49:12 +01:00
print " </table> " ;
2019-10-02 18:14:41 +02:00
2017-01-18 15:49:12 +01:00
print " </div> " ;
2017-07-15 21:19:39 +02:00
2017-01-18 15:49:12 +01:00
print " </form> \n " ;
2002-05-11 20:53:13 +02:00
}
2006-08-13 02:34:16 +02:00
2018-07-29 19:16:28 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2015-08-28 20:11:16 +02:00
$db -> close ();