2012-08-22 23:27:53 +02:00
< ? php
2005-01-19 15:38:59 +01:00
/* Copyright ( C ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2005-09-10 16:24:10 +02:00
* Copyright ( C ) 2005 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-02-29 18:56:54 +01:00
* Copyright ( C ) 2010 - 2012 Juanjo Menent < jmenent @ 2 byte . es >
2005-01-19 15:38:59 +01: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
2005-01-19 15:38:59 +01: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 />.
2008-11-05 23:34:14 +01:00
*/
2010-04-29 10:38:58 +02:00
/**
* \file htdocs / compta / prelevement / fiche - stat . php
2012-08-05 14:37:45 +02:00
* \ingroup prelevement
2020-07-27 19:33:24 +02:00
* \brief Debit order or credit transfer statistics
2005-01-19 15:38:59 +01:00
*/
2005-09-10 16:24:10 +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/prelevement.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/ligneprelevement.class.php' ;
2013-06-05 16:24:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
2019-11-08 10:53:31 +01:00
$langs -> loadLangs ( array ( " banks " , " categories " , 'withdrawals' , 'bills' ));
2005-01-19 15:38:59 +01:00
2011-05-06 15:49:34 +02:00
// Get supervariables
2022-04-15 16:17:03 +02:00
$id = GETPOST ( 'id' , 'int' );
2017-09-15 18:39:10 +02:00
$ref = GETPOST ( 'ref' , 'alpha' );
2017-09-15 16:40:52 +02:00
2020-05-27 20:14:11 +02:00
$type = GETPOST ( 'type' , 'aZ09' );
2017-09-15 16:40:52 +02:00
// Load variable for pagination
2019-11-08 10:53:31 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-23 21:09:01 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2017-09-15 16:40:52 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2020-05-07 12:14:45 +02:00
$object = new BonPrelevement ( $db );
2017-09-15 16:40:52 +02:00
2020-07-27 19:33:24 +02:00
// Load object
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php' ; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
2021-10-04 04:36:58 +02:00
// Security check
if ( $user -> socid > 0 ) {
2020-07-27 19:33:24 +02:00
accessforbidden ();
}
2021-10-04 04:36:58 +02:00
$type = $object -> type ;
if ( $type == 'bank-transfer' ) {
$result = restrictedArea ( $user , 'paymentbybanktransfer' , '' , '' , '' );
} else {
$result = restrictedArea ( $user , 'prelevement' , '' , '' , 'bons' );
2020-07-27 19:33:24 +02:00
}
2008-11-05 23:34:14 +01:00
/*
* View
*/
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $langs -> trans ( " WithdrawalsReceipts " ));
2005-01-19 15:38:59 +01:00
2022-04-15 16:17:03 +02:00
if ( $id > 0 || $ref ) {
if ( $object -> fetch ( $id , $ref ) >= 0 ) {
2017-09-15 16:40:52 +02:00
$head = prelevement_prepare_head ( $object );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'statistics' , $langs -> trans ( " WithdrawalsReceipts " ), - 1 , 'payment' );
2010-03-27 15:40:39 +01:00
2020-09-25 10:05:59 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/compta/prelevement/orders_list.php?restore_lastsearch_values=1' . ( $object -> type != 'bank-transfer' ? '' : '&type=bank-transfer' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-12-15 17:24:36 +01:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' );
2010-03-27 15:40:39 +01:00
2017-09-15 16:40:52 +02:00
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
2019-11-12 17:43:27 +01:00
print '<table class="border centpercent tableforfield">' . " \n " ;
2017-09-15 16:40:52 +02:00
2021-09-27 22:12:08 +02:00
//print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " Date " ) . '</td><td>' . dol_print_date ( $object -> datec , 'day' ) . '</td></tr>' ;
2022-03-31 11:47:18 +02:00
print '<tr><td>' . $langs -> trans ( " Amount " ) . '</td><td><span class="amount">' . price ( $object -> amount ) . '</span></td></tr>' ;
2013-05-03 00:15:02 +02:00
2021-02-23 21:09:01 +01:00
if ( $object -> date_trans <> 0 ) {
2011-01-05 10:57:55 +01:00
$muser = new User ( $db );
2017-09-15 16:40:52 +02:00
$muser -> fetch ( $object -> user_trans );
2013-05-03 00:15:02 +02:00
2017-02-21 13:16:28 +01:00
print '<tr><td>' . $langs -> trans ( " TransData " ) . '</td><td>' ;
2019-01-27 11:55:16 +01:00
print dol_print_date ( $object -> date_trans , 'day' );
2022-03-31 11:47:18 +02:00
print ' <span class="opacitymedium">' . $langs -> trans ( " By " ) . '</span> ' . $muser -> getNomUrl ( - 1 ) . '</td></tr>' ;
2017-02-21 13:16:28 +01:00
print '<tr><td>' . $langs -> trans ( " TransMetod " ) . '</td><td>' ;
2017-09-15 16:40:52 +02:00
print $object -> methodes_trans [ $object -> method_trans ];
2011-01-05 10:57:55 +01:00
print '</td></tr>' ;
}
2021-02-23 21:09:01 +01:00
if ( $object -> date_credit <> 0 ) {
2017-02-21 13:16:28 +01:00
print '<tr><td>' . $langs -> trans ( 'CreditDate' ) . '</td><td>' ;
2019-01-27 11:55:16 +01:00
print dol_print_date ( $object -> date_credit , 'day' );
2011-01-05 10:57:55 +01:00
print '</td></tr>' ;
}
2013-05-03 00:15:02 +02:00
2010-08-09 18:07:23 +02:00
print '</table>' ;
2013-05-03 00:15:02 +02:00
2012-12-01 15:45:05 +01:00
print '<br>' ;
2013-05-03 00:15:02 +02:00
2017-09-15 16:40:52 +02:00
print '<div class="underbanner clearboth"></div>' ;
2019-11-12 17:43:27 +01:00
print '<table class="border centpercent tableforfield">' ;
2017-09-15 16:40:52 +02:00
$acc = new Account ( $db );
2019-11-08 10:53:31 +01:00
$result = $acc -> fetch ( $conf -> global -> PRELEVEMENT_ID_BANKACCOUNT );
2017-09-15 16:40:52 +02:00
2021-09-27 22:12:08 +02:00
print '<tr><td class="titlefieldcreate">' ;
2020-07-27 19:33:24 +02:00
$labelofbankfield = " BankToReceiveWithdraw " ;
2021-02-23 21:09:01 +01:00
if ( $object -> type == 'bank-transfer' ) {
$labelofbankfield = 'BankToPayCreditTransfer' ;
}
2020-07-27 19:33:24 +02:00
print $langs -> trans ( $labelofbankfield );
2017-09-15 16:40:52 +02:00
print '</td>' ;
print '<td>' ;
2021-02-23 21:09:01 +01:00
if ( $acc -> id > 0 ) {
2017-09-15 16:40:52 +02:00
print $acc -> getNomUrl ( 1 );
2021-02-23 21:09:01 +01:00
}
2017-09-15 16:40:52 +02:00
print '</td>' ;
print '</tr>' ;
print '<tr><td class="titlefield">' ;
2020-07-27 19:33:24 +02:00
$labelfororderfield = 'WithdrawalFile' ;
2021-02-23 21:09:01 +01:00
if ( $object -> type == 'bank-transfer' ) {
$labelfororderfield = 'CreditTransferFile' ;
}
2020-07-27 19:33:24 +02:00
print $langs -> trans ( $labelfororderfield ) . '</td><td>' ;
2017-09-15 16:40:52 +02:00
$relativepath = 'receipts/' . $object -> ref . '.xml' ;
2020-07-27 19:33:24 +02:00
$modulepart = 'prelevement' ;
2021-02-23 21:09:01 +01:00
if ( $object -> type == 'bank-transfer' ) {
$modulepart = 'paymentbybanktransfer' ;
}
2022-03-31 11:47:18 +02:00
print '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?type=text/plain&modulepart=' . $modulepart . '&file=' . urlencode ( $relativepath ) . '">' . $relativepath ;
print img_picto ( '' , 'download' , 'class="paddingleft"' );
print '</a>' ;
2012-12-01 15:45:05 +01:00
print '</td></tr></table>' ;
2013-05-03 00:15:02 +02:00
2017-09-15 16:40:52 +02:00
print '</div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2020-05-21 15:05:19 +02:00
} else {
2020-07-27 19:33:24 +02:00
dol_print_error ( $db );
2005-01-19 15:38:59 +01:00
}
2010-03-27 15:40:39 +01:00
2010-08-09 18:07:23 +02:00
/*
* Stats
*/
2020-07-27 19:33:24 +02:00
$line = new LignePrelevement ( $db );
2012-08-05 14:37:45 +02:00
2010-08-09 18:07:23 +02:00
$sql = " SELECT sum(pl.amount), pl.statut " ;
2019-11-08 10:53:31 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " prelevement_lignes as pl " ;
2021-03-30 17:53:25 +02:00
$sql .= " WHERE pl.fk_prelevement_bons = " . (( int ) $object -> id );
2019-11-08 10:53:31 +01:00
$sql .= " GROUP BY pl.statut " ;
2010-08-09 18:07:23 +02:00
2019-11-08 10:53:31 +01:00
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $resql ) {
2010-08-09 18:07:23 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2019-01-27 11:55:16 +01:00
print load_fiche_titre ( $langs -> trans ( " StatisticsByLineStatus " ), '' , '' );
2017-09-15 16:40:52 +02:00
2010-08-09 18:07:23 +02:00
print " \n <!-- debut table --> \n " ;
2022-03-31 11:47:18 +02:00
print '<div class="div-table-responsive-no-min">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="noborder centpercent">' ;
2010-08-09 18:07:23 +02:00
print '<tr class="liste_titre">' ;
2019-02-10 16:05:06 +01:00
print '<td>' . $langs -> trans ( " Status " ) . '</td><td class="right">' . $langs -> trans ( " Amount " ) . '</td><td class="right">%</td></tr>' ;
2010-08-09 18:07:23 +02:00
2021-02-23 21:09:01 +01:00
while ( $i < $num ) {
2010-08-09 18:07:23 +02:00
$row = $db -> fetch_row ( $resql );
2017-05-10 16:41:19 +02:00
print '<tr class="oddeven"><td>' ;
2012-08-05 14:37:45 +02:00
2020-07-27 19:33:24 +02:00
print $line -> LibStatut ( $row [ 1 ], 1 );
2010-08-09 18:07:23 +02:00
2022-03-31 11:47:18 +02:00
print '</td>' ;
print '<td class="right"><span class="amount">' ;
2010-08-09 18:07:23 +02:00
print price ( $row [ 0 ]);
2022-03-31 11:47:18 +02:00
print '</span></td>' ;
2010-08-09 18:07:23 +02:00
2022-03-31 11:47:18 +02:00
print '<td class="right">' ;
2021-02-23 21:09:01 +01:00
if ( $object -> amount ) {
print round ( $row [ 0 ] / $object -> amount * 100 , 2 ) . " % " ;
}
2010-08-09 18:07:23 +02:00
print '</td>' ;
print " </tr> \n " ;
2017-09-15 16:40:52 +02:00
2010-08-09 18:07:23 +02:00
$i ++ ;
}
print " </table> " ;
2022-03-31 11:47:18 +02:00
print " </div> " ;
2010-08-09 18:07:23 +02:00
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 10:53:31 +01:00
print $db -> error () . ' ' . $sql ;
2010-08-09 18:07:23 +02:00
}
2005-01-19 15:38:59 +01:00
}
2018-08-08 12:29:36 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2015-12-11 14:19:38 +01:00
$db -> close ();