2018-07-05 21:34:36 +02:00
< ? php
2022-08-19 06:46:59 +02:00
/* Copyright ( C ) 2001 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2019 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2017 Pierre - Henry Favre < support @ atm - consulting . fr >
* Copyright ( C ) 2020 Maxime DEMAREST < maxime @ indelog . fr >
* Copyright ( C ) 2021 Gauthier VERDOL < gauthier . verdol @ atm - consulting . fr >
* Copyright ( C ) 2022 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2018-07-05 21:34:36 +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 3 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2018-07-05 21:34:36 +02:00
*/
2020-03-19 10:52:07 +01:00
2022-04-03 17:12:45 +02:00
/**
* \file htdocs / compta / accounting - files . php
* \ingroup compta
* \brief Page to show portoflio and files of a thirdparty and download it
*/
2020-03-19 10:52:07 +01:00
2020-04-24 19:01:08 +02:00
if (( array_key_exists ( 'action' , $_GET ) && $_GET [ 'action' ] == 'dl' ) || ( array_key_exists ( 'action' , $_POST ) && $_POST [ 'action' ] == 'dl' )) { // To not replace token when downloading file
2021-02-23 21:09:01 +01:00
if ( ! defined ( 'NOTOKENRENEWAL' )) {
define ( 'NOTOKENRENEWAL' , '1' );
}
2020-03-19 10:52:07 +01:00
}
2018-07-05 21:34:36 +02:00
require '../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2021-03-19 14:12:08 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2018-07-05 21:34:36 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php' ;
2019-07-19 23:08:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/salaries/class/paymentsalary.class.php' ;
2018-07-05 21:34:36 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/chargesociales.class.php' ;
2019-01-17 00:09:05 +01:00
require_once DOL_DOCUMENT_ROOT . '/don/class/don.class.php' ;
2019-03-07 13:02:51 +01:00
require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php' ;
2020-05-12 13:15:49 +02:00
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/paymentvarious.class.php' ;
2020-05-13 15:01:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2020-05-13 17:47:30 +02:00
require_once DOL_DOCUMENT_ROOT . '/loan/class/paymentloan.class.php' ;
2018-09-28 10:42:42 +02:00
2020-05-13 16:54:53 +02:00
// Constant to define payment sens
const PAY_DEBIT = 0 ;
const PAY_CREDIT = 1 ;
2020-05-13 17:47:30 +02:00
$langs -> loadLangs ( array ( " accountancy " , " bills " , " companies " , " salaries " , " compta " , " trips " , " banks " , " loan " ));
2018-09-28 10:42:42 +02:00
2019-11-12 00:15:34 +01:00
$date_start = GETPOST ( 'date_start' , 'alpha' );
$date_startDay = GETPOST ( 'date_startday' , 'int' );
$date_startMonth = GETPOST ( 'date_startmonth' , 'int' );
$date_startYear = GETPOST ( 'date_startyear' , 'int' );
2021-11-08 20:39:52 +01:00
$date_start = dol_mktime ( 0 , 0 , 0 , $date_startMonth , $date_startDay , $date_startYear , 'tzuserrel' );
2019-11-12 00:15:34 +01:00
$date_stop = GETPOST ( 'date_stop' , 'alpha' );
$date_stopDay = GETPOST ( 'date_stopday' , 'int' );
$date_stopMonth = GETPOST ( 'date_stopmonth' , 'int' );
$date_stopYear = GETPOST ( 'date_stopyear' , 'int' );
2021-11-08 20:39:52 +01:00
$date_stop = dol_mktime ( 23 , 59 , 59 , $date_stopMonth , $date_stopDay , $date_stopYear , 'tzuserrel' );
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2019-01-17 00:32:43 +01:00
2018-07-05 21:34:36 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2019-11-12 00:15:34 +01:00
$hookmanager -> initHooks ( array ( 'comptafileslist' , 'globallist' ));
2019-01-17 00:32:43 +01:00
2018-07-05 21:34:36 +02:00
// Load variable for pagination
2019-11-12 00:15:34 +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
2018-07-05 21:34:36 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-23 21:09:01 +01:00
if ( ! $sortfield ) {
$sortfield = " date,item " ; // Set here default search field
}
if ( ! $sortorder ) {
$sortorder = " DESC " ;
}
2019-01-17 00:32:43 +01:00
2019-11-12 00:15:34 +01:00
$arrayfields = array (
2020-10-31 14:32:18 +01:00
'type' => array ( 'label' => " Type " , 'checked' => 1 ),
'date' => array ( 'label' => " Date " , 'checked' => 1 ),
2020-03-02 16:00:07 +01:00
'date_due' => array ( 'label' => " DateDue " , 'checked' => 1 ),
'ref' => array ( 'label' => " Ref " , 'checked' => 1 ),
'documents' => array ( 'label' => " Documents " , 'checked' => 1 ),
'paid' => array ( 'label' => " Paid " , 'checked' => 1 ),
'total_ht' => array ( 'label' => " TotalHT " , 'checked' => 1 ),
'total_ttc' => array ( 'label' => " TotalTTC " , 'checked' => 1 ),
'total_vat' => array ( 'label' => " TotalVAT " , 'checked' => 1 ),
//...
2018-07-05 21:34:36 +02:00
);
2018-09-28 10:42:42 +02:00
2019-01-17 00:32:43 +01:00
// Security check
2022-08-29 11:56:02 +02:00
if ( ! isModEnabled ( 'comptabilite' ) && ! isModEnabled ( 'accounting' )) {
2020-10-31 14:32:18 +01:00
accessforbidden ();
2019-01-17 00:32:43 +01:00
}
2019-10-31 20:46:31 +01:00
if ( $user -> socid > 0 ) {
2020-10-31 14:32:18 +01:00
accessforbidden ();
2019-06-18 18:07:47 +02:00
}
2019-01-17 00:32:43 +01:00
2020-02-19 16:08:33 +01:00
// Define $arrayofentities if multientity is set.
$arrayofentities = array ();
2022-08-29 11:56:02 +02:00
if ( isModEnabled ( 'multicompany' ) && is_object ( $mc )) {
2020-02-19 16:08:33 +01:00
$arrayofentities = $mc -> getEntitiesList ();
}
2020-02-19 15:51:27 +01:00
$entity = ( GETPOSTISSET ( 'entity' ) ? GETPOST ( 'entity' , 'int' ) : ( GETPOSTISSET ( 'search_entity' ) ? GETPOST ( 'search_entity' , 'int' ) : $conf -> entity ));
2022-08-29 11:56:02 +02:00
if ( isModEnabled ( 'multicompany' ) && is_object ( $mc )) {
2020-02-21 17:53:37 +01:00
if ( empty ( $entity ) && ! empty ( $conf -> global -> MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES )) {
2020-02-19 16:08:33 +01:00
$entity = '0,' . join ( ',' , array_keys ( $arrayofentities ));
}
2020-02-19 15:51:27 +01:00
}
2021-02-23 21:09:01 +01:00
if ( empty ( $entity )) {
$entity = $conf -> entity ;
}
2020-02-19 15:51:27 +01:00
2020-02-19 16:08:33 +01:00
$error = 0 ;
2021-03-19 14:12:08 +01:00
$listofchoices = array (
2022-06-11 09:46:28 +02:00
'selectinvoices' => array ( 'label' => 'Invoices' , 'lang' => 'bills' , 'enabled' => isModEnabled ( 'facture' ), 'perms' => ! empty ( $user -> rights -> facture -> lire )),
2022-08-29 11:56:02 +02:00
'selectsupplierinvoices' => array ( 'label' => 'BillsSuppliers' , 'lang' => 'bills' , 'enabled' => isModEnabled ( 'supplier_invoice' ), 'perms' => ! empty ( $user -> rights -> fournisseur -> facture -> lire )),
2022-08-31 17:32:38 +02:00
'selectexpensereports' => array ( 'label' => 'ExpenseReports' , 'lang' => 'trips' , 'enabled' => isModEnabled ( 'expensereport' ), 'perms' => ! empty ( $user -> rights -> expensereport -> lire )),
2022-08-29 11:56:02 +02:00
'selectdonations' => array ( 'label' => 'Donations' , 'lang' => 'donation' , 'enabled' => isModEnabled ( 'don' ), 'perms' => ! empty ( $user -> rights -> don -> lire )),
'selectsocialcontributions' => array ( 'label' => 'SocialContributions' , 'enabled' => isModEnabled ( 'tax' ), 'perms' => ! empty ( $user -> rights -> tax -> charges -> lire )),
'selectpaymentsofsalaries' => array ( 'label' => 'SalariesPayments' , 'lang' => 'salaries' , 'enabled' => isModEnabled ( 'salaries' ), 'perms' => ! empty ( $user -> rights -> salaries -> read )),
2022-08-29 11:20:47 +02:00
'selectvariouspayment' => array ( 'label' => 'VariousPayment' , 'enabled' => isModEnabled ( 'banque' ), 'perms' => ! empty ( $user -> rights -> banque -> lire )),
2022-08-29 11:56:02 +02:00
'selectloanspayment' => array ( 'label' => 'PaymentLoan' , 'enabled' => isModEnabled ( 'don' ), 'perms' => ! empty ( $user -> rights -> loan -> read )),
2021-03-19 14:12:08 +01:00
);
2019-01-17 00:32:43 +01:00
2018-09-28 10:42:42 +02:00
2018-07-05 21:34:36 +02:00
/*
* Actions
*/
2018-09-28 10:42:42 +02:00
2019-02-12 18:15:30 +01:00
2018-07-05 21:34:36 +02:00
//$parameters = array('socid' => $id);
//$reshook = $hookmanager->executeHooks('doActions', $parameters, $object); // Note that $object may have been modified by some hooks
//if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2018-09-28 10:42:42 +02:00
2019-11-12 00:15:34 +01:00
$filesarray = array ();
$result = false ;
2020-03-19 10:52:07 +01:00
if (( $action == 'searchfiles' || $action == 'dl' )) {
2021-02-23 21:09:01 +01:00
if ( empty ( $date_start )) {
2019-06-17 17:53:43 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " DateStart " )), null , 'errors' );
$error ++ ;
}
2021-02-23 21:09:01 +01:00
if ( empty ( $date_stop )) {
2019-06-17 17:53:43 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " DateEnd " )), null , 'errors' );
$error ++ ;
}
2021-02-23 21:09:01 +01:00
if ( ! $error ) {
2020-02-22 12:19:46 +01:00
$sql = '' ;
2019-11-12 00:15:34 +01:00
$wheretail = " ' " . $db -> idate ( $date_start ) . " ' AND ' " . $db -> idate ( $date_stop ) . " ' " ;
2019-12-18 23:07:26 +01:00
// Customer invoices
2021-03-19 14:12:08 +01:00
if ( GETPOST ( 'selectinvoices' ) && ! empty ( $listofchoices [ 'selectinvoices' ][ 'perms' ])) {
2021-02-23 21:09:01 +01:00
if ( ! empty ( $sql )) {
$sql .= " UNION ALL " ;
}
2021-06-15 17:53:25 +02:00
$sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paye as paid, t.total_ht, t.total_ttc, t.total_tva as total_vat, t.multicurrency_code as currency, t.fk_soc, t.datef as date, t.date_lim_reglement as date_due, 'Invoice' as item, s.nom as thirdparty_name, s.code_client as thirdparty_code, c.code as country_code, s.tva_intra as vatnum, " . PAY_CREDIT . " as sens " ;
2020-10-31 14:32:18 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as t LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON s.rowid = t.fk_soc LEFT JOIN " . MAIN_DB_PREFIX . " c_country as c ON c.rowid = s.fk_pays " ;
$sql .= " WHERE datef between " . $wheretail ;
2021-03-22 12:00:41 +01:00
$sql .= " AND t.entity IN ( " . $db -> sanitize ( $entity == 1 ? '0,1' : $entity ) . ')' ;
2020-10-31 14:32:18 +01:00
$sql .= " AND t.fk_statut <> " . Facture :: STATUS_DRAFT ;
2020-02-21 14:18:18 +01:00
}
2020-10-31 14:32:18 +01:00
// Vendor invoices
2021-03-19 14:12:08 +01:00
if ( GETPOST ( 'selectsupplierinvoices' ) && ! empty ( $listofchoices [ 'selectsupplierinvoices' ][ 'perms' ])) {
2021-02-23 21:09:01 +01:00
if ( ! empty ( $sql )) {
$sql .= " UNION ALL " ;
}
2020-10-06 09:53:29 +02:00
$sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paye as paid, t.total_ht, t.total_ttc, t.total_tva as total_vat, t.multicurrency_code as currency, t.fk_soc, t.datef as date, t.date_lim_reglement as date_due, 'SupplierInvoice' as item, s.nom as thirdparty_name, s.code_fournisseur as thirdparty_code, c.code as country_code, s.tva_intra as vatnum, " . PAY_DEBIT . " as sens " ;
2020-10-31 14:32:18 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture_fourn as t LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON s.rowid = t.fk_soc LEFT JOIN " . MAIN_DB_PREFIX . " c_country as c ON c.rowid = s.fk_pays " ;
$sql .= " WHERE datef between " . $wheretail ;
2021-03-22 12:00:41 +01:00
$sql .= " AND t.entity IN ( " . $db -> sanitize ( $entity == 1 ? '0,1' : $entity ) . ')' ;
2020-10-31 14:32:18 +01:00
$sql .= " AND t.fk_statut <> " . FactureFournisseur :: STATUS_DRAFT ;
2020-02-21 14:18:18 +01:00
}
2020-10-31 14:32:18 +01:00
// Expense reports
2021-03-19 14:12:08 +01:00
if ( GETPOST ( 'selectexpensereports' ) && ! empty ( $listofchoices [ 'selectexpensereports' ][ 'perms' ])) {
2021-02-23 21:09:01 +01:00
if ( ! empty ( $sql )) {
$sql .= " UNION ALL " ;
}
2020-10-06 09:53:29 +02:00
$sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paid, t.total_ht, t.total_ttc, t.total_tva as total_vat, t.multicurrency_code as currency, t.fk_user_author as fk_soc, t.date_fin as date, t.date_fin as date_due, 'ExpenseReport' as item, CONCAT(CONCAT(u.lastname, ' '), u.firstname) as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum, " . PAY_DEBIT . " as sens " ;
2020-10-31 14:32:18 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " expensereport as t LEFT JOIN " . MAIN_DB_PREFIX . " user as u ON u.rowid = t.fk_user_author LEFT JOIN " . MAIN_DB_PREFIX . " c_country as c ON c.rowid = u.fk_country " ;
$sql .= " WHERE date_fin between " . $wheretail ;
2021-03-22 12:00:41 +01:00
$sql .= " AND t.entity IN ( " . $db -> sanitize ( $entity == 1 ? '0,1' : $entity ) . ')' ;
2020-10-31 14:32:18 +01:00
$sql .= " AND t.fk_statut <> " . ExpenseReport :: STATUS_DRAFT ;
2020-02-21 14:18:18 +01:00
}
2020-10-31 14:32:18 +01:00
// Donations
2021-03-19 14:12:08 +01:00
if ( GETPOST ( 'selectdonations' ) && ! empty ( $listofchoices [ 'selectdonations' ][ 'perms' ])) {
2021-02-23 21:09:01 +01:00
if ( ! empty ( $sql )) {
$sql .= " UNION ALL " ;
}
2020-10-06 09:53:29 +02:00
$sql .= " SELECT t.rowid as id, t.entity, t.ref, paid, amount as total_ht, amount as total_ttc, 0 as total_vat, ' " . $db -> escape ( $conf -> currency ) . " ' as currency, 0 as fk_soc, t.datedon as date, t.datedon as date_due, 'Donation' as item, t.societe as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum, " . PAY_CREDIT . " as sens " ;
2020-10-31 14:32:18 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " don as t LEFT JOIN " . MAIN_DB_PREFIX . " c_country as c ON c.rowid = t.fk_country " ;
$sql .= " WHERE datedon between " . $wheretail ;
2021-03-22 12:00:41 +01:00
$sql .= " AND t.entity IN ( " . $db -> sanitize ( $entity == 1 ? '0,1' : $entity ) . ')' ;
2020-10-31 14:32:18 +01:00
$sql .= " AND t.fk_statut <> " . Don :: STATUS_DRAFT ;
2020-02-21 14:18:18 +01:00
}
2020-10-31 14:32:18 +01:00
// Payments of salaries
2021-03-19 14:12:08 +01:00
if ( GETPOST ( 'selectpaymentsofsalaries' ) && ! empty ( $listofchoices [ 'selectpaymentsofsalaries' ][ 'perms' ])) {
2021-02-23 21:09:01 +01:00
if ( ! empty ( $sql )) {
$sql .= " UNION ALL " ;
}
2020-10-06 09:53:29 +02:00
$sql .= " SELECT t.rowid as id, t.entity, t.label as ref, 1 as paid, amount as total_ht, amount as total_ttc, 0 as total_vat, ' " . $db -> escape ( $conf -> currency ) . " ' as currency, t.fk_user as fk_soc, t.datep as date, t.dateep as date_due, 'SalaryPayment' as item, CONCAT(CONCAT(u.lastname, ' '), u.firstname) as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum, " . PAY_DEBIT . " as sens " ;
2020-10-31 14:32:18 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " payment_salary as t LEFT JOIN " . MAIN_DB_PREFIX . " user as u ON u.rowid = t.fk_user LEFT JOIN " . MAIN_DB_PREFIX . " c_country as c ON c.rowid = u.fk_country " ;
$sql .= " WHERE datep between " . $wheretail ;
2021-03-22 12:00:41 +01:00
$sql .= " AND t.entity IN ( " . $db -> sanitize ( $entity == 1 ? '0,1' : $entity ) . ')' ;
2020-10-31 14:32:18 +01:00
//$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT;
2020-02-21 14:18:18 +01:00
}
2020-10-31 14:32:18 +01:00
// Social contributions
2021-03-19 14:12:08 +01:00
if ( GETPOST ( 'selectsocialcontributions' ) && ! empty ( $listofchoices [ 'selectsocialcontributions' ][ 'perms' ])) {
2021-02-23 21:09:01 +01:00
if ( ! empty ( $sql )) {
$sql .= " UNION ALL " ;
}
2020-10-06 09:53:29 +02:00
$sql .= " SELECT t.rowid as id, t.entity, t.libelle as ref, t.paye as paid, t.amount as total_ht, t.amount as total_ttc, 0 as total_vat, ' " . $db -> escape ( $conf -> currency ) . " ' as currency, 0 as fk_soc, t.date_ech as date, t.periode as date_due, 'SocialContributions' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum, " . PAY_DEBIT . " as sens " ;
2020-10-31 14:32:18 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " chargesociales as t " ;
$sql .= " WHERE t.date_ech between " . $wheretail ;
2021-03-22 12:00:41 +01:00
$sql .= " AND t.entity IN ( " . $db -> sanitize ( $entity == 1 ? '0,1' : $entity ) . ')' ;
2020-10-31 14:32:18 +01:00
//$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT;
2020-02-21 14:18:18 +01:00
}
2020-10-31 14:32:18 +01:00
// Various payments
2021-03-19 14:12:08 +01:00
if ( GETPOST ( 'selectvariouspayment' ) && ! empty ( $listofchoices [ 'selectvariouspayment' ][ 'perms' ])) {
2021-02-23 21:09:01 +01:00
if ( ! empty ( $sql )) {
$sql .= " UNION ALL " ;
}
2020-10-07 00:49:19 +02:00
$sql .= " SELECT t.rowid as id, t.entity, t.ref, 1 as paid, t.amount as total_ht, t.amount as total_ttc, 0 as total_vat, ' " . $db -> escape ( $conf -> currency ) . " ' as currency, 0 as fk_soc, t.datep as date, t.datep as date_due, 'VariousPayment' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum, sens " ;
2020-10-31 14:32:18 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " payment_various as t " ;
$sql .= " WHERE datep between " . $wheretail ;
2021-03-22 12:00:41 +01:00
$sql .= " AND t.entity IN ( " . $db -> sanitize ( $entity == 1 ? '0,1' : $entity ) . ')' ;
2020-05-12 13:15:49 +02:00
}
2020-10-31 14:32:18 +01:00
// Loan payments
2021-03-19 14:12:08 +01:00
if ( GETPOST ( 'selectloanspayment' ) && ! empty ( $listofchoices [ 'selectloanspayment' ][ 'perms' ])) {
2021-02-23 21:09:01 +01:00
if ( ! empty ( $sql )) {
$sql .= " UNION ALL " ;
}
2020-10-06 09:53:29 +02:00
$sql .= " SELECT t.rowid as id, l.entity, l.label as ref, 1 as paid, (t.amount_capital+t.amount_insurance+t.amount_interest) as total_ht, (t.amount_capital+t.amount_insurance+t.amount_interest) as total_ttc, 0 as total_vat, ' " . $db -> escape ( $conf -> currency ) . " ' as currency, 0 as fk_soc, t.datep as date, t.datep as date_due, 'LoanPayment' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum, " . PAY_DEBIT . " as sens " ;
2020-10-31 14:32:18 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " payment_loan as t LEFT JOIN " . MAIN_DB_PREFIX . " loan as l ON l.rowid = t.fk_loan " ;
$sql .= " WHERE datep between " . $wheretail ;
2021-03-22 12:00:41 +01:00
$sql .= " AND l.entity IN ( " . $db -> sanitize ( $entity == 1 ? '0,1' : $entity ) . ')' ;
2020-05-13 17:47:30 +02:00
}
2020-02-21 14:18:18 +01:00
2020-02-22 12:19:46 +01:00
if ( $sql ) {
2020-10-31 14:32:18 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2020-02-22 12:19:46 +01:00
//print $sql;
2020-10-31 14:32:18 +01:00
$resd = $db -> query ( $sql );
$files = array ();
$link = '' ;
2021-02-23 21:09:01 +01:00
if ( $resd ) {
2020-10-31 14:32:18 +01:00
$numd = $db -> num_rows ( $resd );
$tmpinvoice = new Facture ( $db );
$tmpinvoicesupplier = new FactureFournisseur ( $db );
$tmpdonation = new Don ( $db );
$upload_dir = '' ;
$i = 0 ;
2021-02-23 21:09:01 +01:00
while ( $i < $numd ) {
2020-10-31 14:32:18 +01:00
$objd = $db -> fetch_object ( $resd );
2021-02-23 21:09:01 +01:00
switch ( $objd -> item ) {
2020-10-31 14:32:18 +01:00
case " Invoice " :
$subdir = '' ;
$subdir .= ( $subdir ? '/' : '' ) . dol_sanitizeFileName ( $objd -> ref );
$upload_dir = $conf -> facture -> dir_output . '/' . $subdir ;
$link = " document.php?modulepart=facture&file= " . str_replace ( '/' , '%2F' , $subdir ) . '%2F' ;
$modulepart = " facture " ;
break ;
case " SupplierInvoice " :
$tmpinvoicesupplier -> fetch ( $objd -> id );
$subdir = get_exdir ( $tmpinvoicesupplier -> id , 2 , 0 , 1 , $tmpinvoicesupplier , 'invoice_supplier' ); // TODO Use first file
$subdir .= ( $subdir ? '/' : '' ) . dol_sanitizeFileName ( $objd -> ref );
$upload_dir = $conf -> fournisseur -> facture -> dir_output . '/' . $subdir ;
$link = " document.php?modulepart=facture_fournisseur&file= " . str_replace ( '/' , '%2F' , $subdir ) . '%2F' ;
$modulepart = " facture_fournisseur " ;
break ;
case " ExpenseReport " :
$subdir = '' ;
$subdir .= ( $subdir ? '/' : '' ) . dol_sanitizeFileName ( $objd -> ref );
$upload_dir = $conf -> expensereport -> dir_output . '/' . $subdir ;
$link = " document.php?modulepart=expensereport&file= " . str_replace ( '/' , '%2F' , $subdir ) . '%2F' ;
$modulepart = " expensereport " ;
break ;
case " SalaryPayment " :
$subdir = '' ;
$subdir .= ( $subdir ? '/' : '' ) . dol_sanitizeFileName ( $objd -> id );
$upload_dir = $conf -> salaries -> dir_output . '/' . $subdir ;
$link = " document.php?modulepart=salaries&file= " . str_replace ( '/' , '%2F' , $subdir ) . '%2F' ;
$modulepart = " salaries " ;
break ;
case " Donation " :
$tmpdonation -> fetch ( $objp -> id );
$subdir = get_exdir ( 0 , 0 , 0 , 0 , $tmpdonation , 'donation' );
$subdir .= ( $subdir ? '/' : '' ) . dol_sanitizeFileName ( $objd -> id );
$upload_dir = $conf -> don -> dir_output . '/' . $subdir ;
$link = " document.php?modulepart=don&file= " . str_replace ( '/' , '%2F' , $subdir ) . '%2F' ;
$modulepart = " don " ;
break ;
case " SocialContributions " :
$subdir = '' ;
$subdir .= ( $subdir ? '/' : '' ) . dol_sanitizeFileName ( $objd -> id );
$upload_dir = $conf -> tax -> dir_output . '/' . $subdir ;
$link = " document.php?modulepart=tax&file= " . str_replace ( '/' , '%2F' , $subdir ) . '%2F' ;
$modulepart = " tax " ;
break ;
case " VariousPayment " :
$subdir = '' ;
$subdir .= ( $subdir ? '/' : '' ) . dol_sanitizeFileName ( $objd -> id );
$upload_dir = $conf -> bank -> dir_output . '/' . $subdir ;
$link = " document.php?modulepart=banque&file= " . str_replace ( '/' , '%2F' , $subdir ) . '%2F' ;
$modulepart = " banque " ;
break ;
case " LoanPayment " :
// Loan payment has no linked file
$subdir = '' ;
$upload_dir = $conf -> loan -> dir_output . '/' . $subdir ;
$link = " " ;
$modulepart = " " ;
break ;
default :
$subdir = '' ;
$upload_dir = '' ;
$link = '' ;
break ;
}
2021-02-23 21:09:01 +01:00
if ( ! empty ( $upload_dir )) {
2020-10-31 14:32:18 +01:00
$result = true ;
$files = dol_dir_list ( $upload_dir , " files " , 0 , '' , '(\.meta|_preview.*\.png)$' , '' , SORT_ASC , 1 );
//var_dump($upload_dir);
//var_dump($files);
2021-02-23 21:09:01 +01:00
if ( count ( $files ) < 1 ) {
2020-10-31 14:32:18 +01:00
$nofile = array ();
$nofile [ 'id' ] = $objd -> id ;
$nofile [ 'entity' ] = $objd -> entity ;
2021-11-08 20:11:32 +01:00
$nofile [ 'date' ] = $db -> jdate ( $objd -> date );
$nofile [ 'date_due' ] = $db -> jdate ( $objd -> date_due );
2020-10-31 14:32:18 +01:00
$nofile [ 'paid' ] = $objd -> paid ;
$nofile [ 'amount_ht' ] = $objd -> total_ht ;
$nofile [ 'amount_ttc' ] = $objd -> total_ttc ;
$nofile [ 'amount_vat' ] = $objd -> total_vat ;
$nofile [ 'ref' ] = ( $objd -> ref ? $objd -> ref : $objd -> id );
$nofile [ 'fk' ] = $objd -> fk_soc ;
$nofile [ 'item' ] = $objd -> item ;
$nofile [ 'thirdparty_name' ] = $objd -> thirdparty_name ;
$nofile [ 'thirdparty_code' ] = $objd -> thirdparty_code ;
$nofile [ 'country_code' ] = $objd -> country_code ;
$nofile [ 'vatnum' ] = $objd -> vatnum ;
$nofile [ 'sens' ] = $objd -> sens ;
$filesarray [ $nofile [ 'item' ] . '_' . $nofile [ 'id' ]] = $nofile ;
} else {
2021-02-23 21:09:01 +01:00
foreach ( $files as $key => $file ) {
2020-10-31 14:32:18 +01:00
$file [ 'id' ] = $objd -> id ;
$file [ 'entity' ] = $objd -> entity ;
2021-11-08 20:11:32 +01:00
$file [ 'date' ] = $db -> jdate ( $objd -> date );
$file [ 'date_due' ] = $db -> jdate ( $objd -> date_due );
2020-10-31 14:32:18 +01:00
$file [ 'paid' ] = $objd -> paid ;
$file [ 'amount_ht' ] = $objd -> total_ht ;
$file [ 'amount_ttc' ] = $objd -> total_ttc ;
$file [ 'amount_vat' ] = $objd -> total_vat ;
$file [ 'ref' ] = ( $objd -> ref ? $objd -> ref : $objd -> id );
$file [ 'fk' ] = $objd -> fk_soc ;
$file [ 'item' ] = $objd -> item ;
$file [ 'thirdparty_name' ] = $objd -> thirdparty_name ;
$file [ 'thirdparty_code' ] = $objd -> thirdparty_code ;
$file [ 'country_code' ] = $objd -> country_code ;
$file [ 'vatnum' ] = $objd -> vatnum ;
$file [ 'sens' ] = $objd -> sens ;
// Save record into array (only the first time it is found)
if ( empty ( $filesarray [ $file [ 'item' ] . '_' . $file [ 'id' ]])) {
$filesarray [ $file [ 'item' ] . '_' . $file [ 'id' ]] = $file ;
}
// Add or concat file
if ( empty ( $filesarray [ $file [ 'item' ] . '_' . $file [ 'id' ]][ 'files' ])) {
$filesarray [ $file [ 'item' ] . '_' . $file [ 'id' ]][ 'files' ] = array ();
}
$filesarray [ $file [ 'item' ] . '_' . $file [ 'id' ]][ 'files' ][] = array (
'link' => $link . urlencode ( $file [ 'name' ]),
'name' => $file [ 'name' ],
'ref' => $file [ 'ref' ],
'fullname' => $file [ 'fullname' ],
'relpath' => '/' . $file [ 'name' ],
'relpathnamelang' => $langs -> trans ( $file [ 'item' ]) . '/' . $file [ 'name' ],
'modulepart' => $modulepart ,
'subdir' => $subdir ,
);
//var_dump($file['item'].'_'.$file['id']);
//var_dump($filesarray[$file['item'].'_'.$file['id']]['files']);
}
}
}
$i ++ ;
}
} else {
dol_print_error ( $db );
}
$db -> free ( $resd );
2020-05-21 15:05:19 +02:00
} else {
2020-02-22 12:19:46 +01:00
setEventMessages ( $langs -> trans ( " ErrorSelectAtLeastOne " ), null , 'errors' );
$error ++ ;
}
2020-02-21 14:18:18 +01:00
}
2018-07-05 21:34:36 +02:00
}
2019-01-17 00:09:05 +01:00
2019-06-18 14:30:13 +02:00
2018-07-05 21:34:36 +02:00
/*
2019-02-12 19:55:54 +01:00
* ZIP creation
*/
2019-01-17 00:09:05 +01:00
2019-06-18 14:30:13 +02:00
$dirfortmpfile = ( $conf -> accounting -> dir_temp ? $conf -> accounting -> dir_temp : $conf -> comptabilite -> dir_temp );
2021-02-23 21:09:01 +01:00
if ( empty ( $dirfortmpfile )) {
2019-06-18 14:30:13 +02:00
setEventMessages ( $langs -> trans ( " ErrorNoAccountingModuleEnabled " ), null , 'errors' );
$error ++ ;
}
2019-03-07 13:02:51 +01:00
2019-06-18 14:30:13 +02:00
2021-02-23 21:09:01 +01:00
if ( $result && $action == " dl " && ! $error ) {
if ( ! extension_loaded ( 'zip' )) {
2019-06-18 14:30:13 +02:00
setEventMessages ( 'PHPZIPExtentionNotLoaded' , null , 'errors' );
exit ;
}
2019-02-12 23:12:33 +01:00
2020-10-31 14:32:18 +01:00
dol_mkdir ( $dirfortmpfile );
$log = $langs -> transnoentitiesnoconv ( " Type " );
2022-08-29 11:56:02 +02:00
if ( isModEnabled ( 'multicompany' ) && is_object ( $mc )) {
2020-10-31 14:32:18 +01:00
$log .= ',' . $langs -> transnoentitiesnoconv ( " Entity " );
}
$log .= ',' . $langs -> transnoentitiesnoconv ( " Date " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " DateDue " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " Ref " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " TotalHT " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " TotalTTC " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " TotalVAT " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " Paid " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " Document " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " ItemID " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " ThirdParty " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " Code " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " Country " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " VATIntra " );
$log .= ',' . $langs -> transnoentitiesnoconv ( " Sens " ) . " \n " ;
2021-11-08 20:39:52 +01:00
$zipname = $dirfortmpfile . '/' . dol_print_date ( $date_start , 'dayrfc' , 'tzuserrel' ) . " - " . dol_print_date ( $date_stop , 'dayrfc' , 'tzuserrel' ) . '_export.zip' ;
2020-10-31 14:32:18 +01:00
dol_delete_file ( $zipname );
$zip = new ZipArchive ;
$res = $zip -> open ( $zipname , ZipArchive :: OVERWRITE | ZipArchive :: CREATE );
2021-02-23 21:09:01 +01:00
if ( $res ) {
foreach ( $filesarray as $key => $file ) {
2020-10-31 14:32:18 +01:00
if ( ! empty ( $file [ 'files' ])) {
foreach ( $file [ 'files' ] as $filecursor ) {
if ( file_exists ( $filecursor [ " fullname " ])) {
$zip -> addFile ( $filecursor [ " fullname " ], $filecursor [ " relpathnamelang " ]);
}
}
}
$log .= '"' . $langs -> trans ( $file [ 'item' ]) . '"' ;
2022-08-29 11:56:02 +02:00
if ( isModEnabled ( 'multicompany' ) && is_object ( $mc )) {
2020-10-31 14:32:18 +01:00
$log .= ',"' . ( empty ( $arrayofentities [ $file [ 'entity' ]]) ? $file [ 'entity' ] : $arrayofentities [ $file [ 'entity' ]]) . '"' ;
}
$log .= ',' . dol_print_date ( $file [ 'date' ], 'dayrfc' );
$log .= ',' . dol_print_date ( $file [ 'date_due' ], 'dayrfc' );
$log .= ',"' . $file [ 'ref' ] . '"' ;
$log .= ',' . $file [ 'amount_ht' ];
$log .= ',' . $file [ 'amount_ttc' ];
$log .= ',' . $file [ 'amount_vat' ];
$log .= ',' . $file [ 'paid' ];
$log .= ',"' . $file [ " name " ] . '"' ;
$log .= ',' . $file [ 'fk' ];
$log .= ',"' . $file [ 'thirdparty_name' ] . '"' ;
$log .= ',"' . $file [ 'thirdparty_code' ] . '"' ;
$log .= ',"' . $file [ 'country_code' ] . '"' ;
$log .= ',"' . $file [ 'vatnum' ] . '"' ;
$log .= ',"' . $file [ 'sens' ] . '"' ;
$log .= " \n " ;
}
$zip -> addFromString ( 'transactions.csv' , $log );
$zip -> close ();
2021-11-28 19:25:58 +01:00
// Then download the zipped file.
2020-10-31 14:32:18 +01:00
header ( 'Content-Type: application/zip' );
header ( 'Content-disposition: attachment; filename=' . basename ( $zipname ));
header ( 'Content-Length: ' . filesize ( $zipname ));
readfile ( $zipname );
dol_delete_file ( $zipname );
exit ();
} else {
setEventMessages ( $langs -> trans ( " FailedToOpenFile " , $zipname ), null , 'errors' );
}
2018-07-05 21:34:36 +02:00
}
2019-01-17 00:09:05 +01:00
2018-07-05 21:34:36 +02:00
/*
2019-01-17 00:09:05 +01:00
* View
2018-07-05 21:34:36 +02:00
*/
2018-11-10 15:35:56 +01:00
2020-05-13 15:01:32 +02:00
$form = new form ( $db );
$formfile = new FormFile ( $db );
2019-11-12 00:15:34 +01:00
$userstatic = new User ( $db );
2020-03-02 16:00:07 +01:00
$invoice = new Facture ( $db );
$supplier_invoice = new FactureFournisseur ( $db );
2020-05-12 13:15:49 +02:00
$expensereport = new ExpenseReport ( $db );
$don = new Don ( $db );
$salary_payment = new PaymentSalary ( $db );
$charge_sociales = new ChargeSociales ( $db );
$various_payment = new PaymentVarious ( $db );
2020-05-13 17:47:30 +02:00
$payment_loan = new PaymentLoan ( $db );
2019-02-12 19:47:46 +01:00
2019-11-12 00:15:34 +01:00
$title = $langs -> trans ( " ComptaFiles " ) . ' - ' . $langs -> trans ( " List " );
2020-02-19 16:08:33 +01:00
$help_url = '' ;
2019-02-12 19:47:46 +01:00
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $title , $help_url );
2018-11-10 15:35:56 +01:00
2019-11-12 00:15:34 +01:00
$h = 0 ;
2020-02-19 16:08:33 +01:00
$head = array ();
$head [ $h ][ 0 ] = $_SERVER [ " PHP_SELF " ];
2019-02-20 04:55:35 +01:00
$head [ $h ][ 1 ] = $langs -> trans ( " AccountantFiles " );
2019-02-12 19:47:46 +01:00
$head [ $h ][ 2 ] = 'AccountancyFiles' ;
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'AccountancyFiles' );
2019-01-17 00:09:05 +01:00
2019-12-18 23:07:26 +01:00
print '<form name="searchfiles" action="?action=searchfiles" method="POST">' . " \n " ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2021-06-26 02:07:18 +02:00
print '<span class="opacitymedium">' . $langs -> trans ( " ExportAccountingSourceDocHelp " );
2022-08-29 11:20:47 +02:00
if ( isModEnabled ( 'accounting' )) {
2021-06-26 02:07:18 +02:00
print ' ' . $langs -> trans ( " ExportAccountingSourceDocHelp2 " , $langs -> transnoentitiesnoconv ( " Accounting " ), $langs -> transnoentitiesnoconv ( " Journals " ));
}
print '</span><br>' ;
2020-10-06 12:17:33 +02:00
print '<br>' ;
2021-03-19 14:12:08 +01:00
print $langs -> trans ( " ReportPeriod " ) . ': ' ;
print $form -> selectDate ( $date_start , 'date_start' , 0 , 0 , 0 , " " , 1 , 1 , 0 , '' , '' , '' , '' , 1 , '' , '' , 'tzuserrel' );
print ' - ' ;
print $form -> selectDate ( $date_stop , 'date_stop' , 0 , 0 , 0 , " " , 1 , 1 , 0 , '' , '' , '' , '' , 1 , '' , '' , 'tzuserrel' );
print " \n " ;
2019-06-17 17:20:22 +02:00
2020-02-19 15:51:27 +01:00
// Export is for current company only
2022-08-29 11:56:02 +02:00
if ( isModEnabled ( 'multicompany' ) && is_object ( $mc )) {
2020-02-19 15:51:27 +01:00
$mc -> getInfo ( $conf -> entity );
2020-03-12 12:45:44 +01:00
print '<span class="marginleftonly marginrightonly' . ( empty ( $conf -> global -> MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES ) ? ' opacitymedium' : '' ) . '">(' . $langs -> trans ( " Entity " ) . ' : ' ;
2020-02-19 15:51:27 +01:00
print " <td> " ;
2020-02-21 17:53:37 +01:00
if ( ! empty ( $conf -> global -> MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES )) {
2020-02-19 15:51:27 +01:00
print $mc -> select_entities ( GETPOSTISSET ( 'search_entity' ) ? GETPOST ( 'search_entity' , 'int' ) : $mc -> id , 'search_entity' , '' , false , false , false , false , true );
} else {
print $mc -> label ;
}
print " </td> " ;
2019-06-18 14:30:13 +02:00
print " )</span> \n " ;
2019-02-12 18:15:30 +01:00
}
2019-02-12 23:12:33 +01:00
2020-02-21 14:18:18 +01:00
print '<br>' ;
2020-03-12 12:45:44 +01:00
foreach ( $listofchoices as $choice => $val ) {
2021-02-23 21:09:01 +01:00
if ( empty ( $val [ 'enabled' ])) {
2021-10-25 22:07:31 +02:00
continue ; // list not qualified
2021-02-23 21:09:01 +01:00
}
2021-03-19 14:12:08 +01:00
$disabled = '' ;
if ( empty ( $val [ 'perms' ])) {
$disabled = ' disabled' ;
}
2020-03-12 12:45:44 +01:00
$checked = ((( ! GETPOSTISSET ( 'search' ) && $action != 'searchfiles' ) || GETPOST ( $choice )) ? ' checked="checked"' : '' );
2021-03-19 14:12:08 +01:00
print '<div class="paddingleft inline-block marginrightonly"><input type="checkbox" id="' . $choice . '" name="' . $choice . '" value="1"' . $checked . $disabled . '> <label for="' . $choice . '">' . $langs -> trans ( $val [ 'label' ]) . '</label></div>' ;
2020-02-21 14:18:18 +01:00
}
2022-04-03 17:12:45 +02:00
print '<input type="submit" class="button small" name="search" value="' . $langs -> trans ( " Search " ) . '">' ;
2019-06-17 17:53:43 +02:00
print '</form>' . " \n " ;
2019-01-17 00:09:05 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2019-01-17 00:09:05 +01:00
2022-08-19 06:46:59 +02:00
$param = '' ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_stop )) {
2020-10-31 14:32:18 +01:00
$param .= '&date_startday=' . GETPOST ( 'date_startday' , 'int' );
$param .= '&date_startmonth=' . GETPOST ( 'date_startmonth' , 'int' );
$param .= '&date_startyear=' . GETPOST ( 'date_startyear' , 'int' );
$param .= '&date_stopday=' . GETPOST ( 'date_stopday' , 'int' );
$param .= '&date_stopmonth=' . GETPOST ( 'date_stopmonth' , 'int' );
$param .= '&date_stopyear=' . GETPOST ( 'date_stopyear' , 'int' );
foreach ( $listofchoices as $choice => $val ) {
2022-04-03 17:12:45 +02:00
if ( GETPOST ( $choice , 'int' )) {
$param .= '&' . $choice . '=1' ;
}
2020-10-31 14:32:18 +01:00
}
2022-04-03 17:12:45 +02:00
$TData = dol_sort_array ( $filesarray , $sortfield , $sortorder );
$filename = dol_print_date ( $date_start , 'dayrfc' , 'tzuserrel' ) . " - " . dol_print_date ( $date_stop , 'dayrfc' , 'tzuserrel' ) . '_export.zip' ;
2020-10-31 14:32:18 +01:00
2021-11-08 20:39:52 +01:00
echo dol_print_date ( $date_start , 'day' , 'tzuserrel' ) . " - " . dol_print_date ( $date_stop , 'day' , 'tzuserrel' );
2020-10-31 14:32:18 +01:00
2022-09-28 08:16:50 +02:00
print '<a class="marginleftonly small' . ( empty ( $TData ) ? ' butActionRefused' : ' butAction' ) . '" href="' . $_SERVER [ " PHP_SELF " ] . '?action=dl&token=' . currentToken () . '&output=file&file=' . urlencode ( $filename ) . $param . '"' ;
2022-04-03 17:12:45 +02:00
if ( empty ( $TData )) {
print " disabled " ;
}
print '>' . " \n " ;
print $langs -> trans ( " Download " );
print '</a><br>' ;
$param .= '&action=searchfiles' ;
/*
print '<input type="hidden" name="token" value="' . currentToken () . '">' ;
2021-11-08 20:07:03 +01:00
print '<input type="hidden" name="date_startday" value="' . GETPOST ( 'date_startday' , 'int' ) . '" />' ;
print '<input type="hidden" name="date_startmonth" value="' . GETPOST ( 'date_startmonth' , 'int' ) . '" />' ;
print '<input type="hidden" name="date_startyear" value="' . GETPOST ( 'date_startyear' , 'int' ) . '" />' ;
print '<input type="hidden" name="date_stopday" value="' . GETPOST ( 'date_stopday' , 'int' ) . '" />' ;
print '<input type="hidden" name="date_stopmonth" value="' . GETPOST ( 'date_stopmonth' , 'int' ) . '" />' ;
print '<input type="hidden" name="date_stopyear" value="' . GETPOST ( 'date_stopyear' , 'int' ) . '" />' ;
2020-10-31 14:32:18 +01:00
foreach ( $listofchoices as $choice => $val ) {
print '<input type="hidden" name="' . $choice . '" value="' . GETPOST ( $choice ) . '">' ;
}
2022-04-03 17:12:45 +02:00
print '<input class="butAction butDownload small marginleftonly" type="submit" value="' . $langs -> trans ( " Download " ) . '"' ;
if ( empty ( $TData )) {
print " disabled " ;
}
print '/>' ;
2020-10-31 14:32:18 +01:00
print '</form>' . " \n " ;
2022-04-03 17:12:45 +02:00
*/
2020-10-31 14:32:18 +01:00
print '<br>' ;
print '<div class="div-table-responsive">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="noborder centpercent">' ;
print '<tr class="liste_titre">' ;
print_liste_field_titre ( $arrayfields [ 'type' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " item " , " " , $param , '' , $sortfield , $sortorder , 'nowrap ' );
print_liste_field_titre ( $arrayfields [ 'date' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " date " , " " , $param , '' , $sortfield , $sortorder , 'center nowrap ' );
print_liste_field_titre ( $arrayfields [ 'date_due' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " date_due " , " " , $param , '' , $sortfield , $sortorder , 'center nowrap ' );
print_liste_field_titre ( $arrayfields [ 'ref' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " " , " " , $param , '' , $sortfield , $sortorder , 'nowraponall ' );
print '<td>' . $langs -> trans ( " Document " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Paid " ) . '</td>' ;
2022-08-29 11:56:02 +02:00
print '<td align="right">' . $langs -> trans ( " TotalHT " ) . ( isModEnabled ( 'multicurrency' ) ? ' (' . $conf -> currency . ')' : '' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " TotalTTC " ) . ( isModEnabled ( 'multicurrency' ) ? ' (' . $conf -> currency . ')' : '' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " TotalVAT " ) . ( isModEnabled ( 'multicurrency' ) ? ' (' . $conf -> currency . ')' : '' ) . '</td>' ;
2019-06-18 14:30:13 +02:00
print '<td>' . $langs -> trans ( " ThirdParty " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " Code " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " Country " ) . '</td>' ;
2020-10-31 14:32:18 +01:00
print '<td class="center">' . $langs -> trans ( " VATIntra " ) . '</td>' ;
2022-08-29 11:56:02 +02:00
if ( isModEnabled ( 'multicurrency' )) {
2021-02-23 21:09:01 +01:00
print '<td class="center">' . $langs -> trans ( " Currency " ) . '</td>' ;
}
2020-10-31 14:32:18 +01:00
print '</tr>' ;
2022-04-03 17:12:45 +02:00
if ( empty ( $TData )) {
print '<tr class="oddeven"><td colspan="13"><span class="opacitymedium">' . $langs -> trans ( " NoRecordFound " ) . '</span></td>' ;
2022-08-29 11:56:02 +02:00
if ( isModEnabled ( 'multicurrency' )) {
2022-04-03 17:12:45 +02:00
print '<td></td>' ;
}
print '</tr>' ;
} else {
// Sort array by date ASC to calculate balance
$totalET_debit = 0 ;
$totalIT_debit = 0 ;
$totalVAT_debit = 0 ;
$totalET_credit = 0 ;
$totalIT_credit = 0 ;
$totalVAT_credit = 0 ;
// Display array
foreach ( $TData as $data ) {
$html_class = '' ;
//if (!empty($data['fk_facture'])) $html_class = 'facid-'.$data['fk_facture'];
//elseif (!empty($data['fk_paiement'])) $html_class = 'payid-'.$data['fk_paiement'];
print '<tr class="oddeven ' . $html_class . '">' ;
// Type
print '<td class="tdoverflowmax150" title="' . dol_escape_htmltag ( $langs -> trans ( $data [ 'item' ])) . '">' . $langs -> trans ( $data [ 'item' ]) . '</td>' ;
// Date
print '<td class="center">' ;
print dol_print_date ( $data [ 'date' ], 'day' );
print " </td> \n " ;
// Date due
print '<td class="center">' ;
print dol_print_date ( $data [ 'date_due' ], 'day' );
print " </td> \n " ;
// Ref
print '<td class="nowraponall tdoverflowmax150">' ;
if ( $data [ 'item' ] == 'Invoice' ) {
$invoice -> id = $data [ 'id' ];
$invoice -> ref = $data [ 'ref' ];
$invoice -> total_ht = $data [ 'amount_ht' ];
$invoice -> total_ttc = $data [ 'amount_ttc' ];
$invoice -> total_tva = $data [ 'amount_vat' ];
$invoice -> multicurrency_code = $data [ 'currency' ];
print $invoice -> getNomUrl ( 1 , '' , 0 , 0 , '' , 0 , 0 , 0 );
} elseif ( $data [ 'item' ] == 'SupplierInvoice' ) {
$supplier_invoice -> id = $data [ 'id' ];
$supplier_invoice -> ref = $data [ 'ref' ];
$supplier_invoice -> total_ht = $data [ 'amount_ht' ];
$supplier_invoice -> total_ttc = $data [ 'amount_ttc' ];
$supplier_invoice -> total_tva = $data [ 'amount_vat' ];
$supplier_invoice -> multicurrency_code = $data [ 'currency' ];
print $supplier_invoice -> getNomUrl ( 1 , '' , 0 , 0 , '' , 0 , 0 , 0 );
} elseif ( $data [ 'item' ] == 'ExpenseReport' ) {
$expensereport -> id = $data [ 'id' ];
$expensereport -> ref = $data [ 'ref' ];
print $expensereport -> getNomUrl ( 1 , 0 , 0 , '' , 0 , 0 );
} elseif ( $data [ 'item' ] == 'SalaryPayment' ) {
$salary_payment -> id = $data [ 'id' ];
$salary_payment -> ref = $data [ 'ref' ];
print $salary_payment -> getNomUrl ( 1 );
} elseif ( $data [ 'item' ] == 'Donation' ) {
$don -> id = $data [ 'id' ];
$don -> ref = $data [ 'ref' ];
print $don -> getNomUrl ( 1 , 0 , '' , 0 );
} elseif ( $data [ 'item' ] == 'SocialContributions' ) {
$charge_sociales -> id = $data [ 'id' ];
$charge_sociales -> ref = $data [ 'ref' ];
print $charge_sociales -> getNomUrl ( 1 , 0 , 0 , 0 , 0 );
} elseif ( $data [ 'item' ] == 'VariousPayment' ) {
$various_payment -> id = $data [ 'id' ];
$various_payment -> ref = $data [ 'ref' ];
print $various_payment -> getNomUrl ( 1 , '' , 0 , 0 );
} elseif ( $data [ 'item' ] == 'LoanPayment' ) {
$payment_loan -> id = $data [ 'id' ];
$payment_loan -> ref = $data [ 'ref' ];
print $payment_loan -> getNomUrl ( 1 , 0 , 0 , '' , 0 );
} else {
print $data [ 'ref' ];
2020-10-31 14:32:18 +01:00
}
2022-04-03 17:12:45 +02:00
print '</td>' ;
// File link
print '<td class="tdoverflowmax150">' ;
if ( ! empty ( $data [ 'files' ])) {
foreach ( $data [ 'files' ] as $id => $filecursor ) {
$tmppreview = $formfile -> showPreview ( $filecursor , $filecursor [ 'modulepart' ], $filecursor [ 'subdir' ] . '/' . $filecursor [ 'name' ], 0 );
if ( $tmppreview ) {
print $tmppreview ;
}
$filename = ( $filecursor [ 'name' ] ? $filecursor [ 'name' ] : $filecursor [ 'ref' ]);
print '<a href=' . DOL_URL_ROOT . '/' . $filecursor [ 'link' ] . ' target="_blank" rel="noopener noreferrer" title="' . dol_escape_htmltag ( $filename ) . '">' ;
if ( empty ( $tmppreview )) {
print img_picto ( '' , 'generic' , '' , false , 0 , 0 , '' , 'pictonopreview pictofixedwidth paddingright' );
2020-10-31 14:32:18 +01:00
}
2022-04-03 17:12:45 +02:00
print $filename ;
print '</a><br>' ;
2020-10-31 14:32:18 +01:00
}
2022-04-03 17:12:45 +02:00
}
print " </td> \n " ;
2020-10-31 14:32:18 +01:00
2022-04-03 17:12:45 +02:00
// Paid
print '<td class="center">' . ( $data [ 'paid' ] ? yn ( $data [ 'paid' ]) : '' ) . '</td>' ;
2020-10-31 14:32:18 +01:00
2022-04-03 17:12:45 +02:00
// Total ET
print '<td align="right"><span class="amount">' . price ( price2num ( $data [ 'sens' ] ? $data [ 'amount_ht' ] : - $data [ 'amount_ht' ], 'MT' )) . " </span></td> \n " ;
// Total IT
print '<td align="right"><span class="amount">' . price ( price2num ( $data [ 'sens' ] ? $data [ 'amount_ttc' ] : - $data [ 'amount_ttc' ], 'MT' )) . " </span></td> \n " ;
// Total VAT
print '<td align="right"><span class="amount">' . price ( price2num ( $data [ 'sens' ] ? $data [ 'amount_vat' ] : - $data [ 'amount_vat' ], 'MT' )) . " </span></td> \n " ;
2020-10-31 14:32:18 +01:00
2022-04-03 17:12:45 +02:00
print '<td class="tdoverflowmax150" title="' . dol_escape_htmltag ( $data [ 'thirdparty_name' ]) . '">' . dol_escape_htmltag ( $data [ 'thirdparty_name' ]) . " </td> \n " ;
2020-10-31 14:32:18 +01:00
2022-04-03 17:12:45 +02:00
print '<td class="center">' . $data [ 'thirdparty_code' ] . " </td> \n " ;
2020-10-31 14:32:18 +01:00
2022-04-03 17:12:45 +02:00
print '<td class="center">' . $data [ 'country_code' ] . " </td> \n " ;
2020-10-31 14:32:18 +01:00
2022-04-03 17:12:45 +02:00
// VAT number
print '<td class="tdoverflowmax150 right" title="' . dol_escape_htmltag ( $data [ 'vatnum' ]) . '">' . dol_escape_htmltag ( $data [ 'vatnum' ]) . " </td> \n " ;
2020-10-31 14:32:18 +01:00
2022-04-03 17:12:45 +02:00
if ( $data [ 'sens' ]) {
$totalET_credit += $data [ 'amount_ht' ];
$totalIT_credit += $data [ 'amount_ttc' ];
$totalVAT_credit += $data [ 'amount_vat' ];
} else {
$totalET_debit -= $data [ 'amount_ht' ];
$totalIT_debit -= $data [ 'amount_ttc' ];
$totalVAT_debit -= $data [ 'amount_vat' ];
2020-10-31 14:32:18 +01:00
}
2022-08-29 11:56:02 +02:00
if ( isModEnabled ( 'multicurrency' )) {
2022-04-03 17:12:45 +02:00
print '<td class="center">' . $data [ 'currency' ] . " </td> \n " ;
2020-10-31 14:32:18 +01:00
}
2022-04-03 17:12:45 +02:00
2020-10-31 14:32:18 +01:00
print " </tr> \n " ;
}
2022-04-03 17:12:45 +02:00
// Total credits
print '<tr class="liste_total">' ;
print '<td colspan="6" class="right">' . $langs -> trans ( 'Total' ) . ' ' . $langs -> trans ( 'Income' ) . '</td>' ;
print '<td align="right">' . price ( price2num ( $totalET_credit , 'MT' )) . '</td>' ;
print '<td align="right">' . price ( price2num ( $totalIT_credit , 'MT' )) . '</td>' ;
print '<td align="right">' . price ( price2num ( $totalVAT_credit , 'MT' )) . '</td>' ;
print '<td colspan="4"></td>' ;
2022-08-29 11:56:02 +02:00
if ( isModEnabled ( 'multicurrency' )) {
2022-04-03 17:12:45 +02:00
print '<td></td>' ;
}
print " </tr> \n " ;
// Total debits
print '<tr class="liste_total">' ;
print '<td colspan="6" class="right">' . $langs -> trans ( 'Total' ) . ' ' . $langs -> trans ( 'Outcome' ) . '</td>' ;
print '<td align="right">' . price ( price2num ( $totalET_debit , 'MT' )) . '</td>' ;
print '<td align="right">' . price ( price2num ( $totalIT_debit , 'MT' )) . '</td>' ;
print '<td align="right">' . price ( price2num ( $totalVAT_debit , 'MT' )) . '</td>' ;
print '<td colspan="4"></td>' ;
2022-08-29 11:56:02 +02:00
if ( isModEnabled ( 'multicurrency' )) {
2022-04-03 17:12:45 +02:00
print '<td></td>' ;
}
print " </tr> \n " ;
// Balance
print '<tr class="liste_total">' ;
print '<td colspan="6" class="right">' . $langs -> trans ( 'Total' ) . '</td>' ;
print '<td align="right">' . price ( price2num ( $totalET_credit + $totalET_debit , 'MT' )) . '</td>' ;
print '<td align="right">' . price ( price2num ( $totalIT_credit + $totalIT_debit , 'MT' )) . '</td>' ;
print '<td align="right">' . price ( price2num ( $totalVAT_credit + $totalVAT_debit , 'MT' )) . '</td>' ;
print '<td colspan="4"></td>' ;
2022-08-29 11:56:02 +02:00
if ( isModEnabled ( 'multicurrency' )) {
2022-04-03 17:12:45 +02:00
print '<td></td>' ;
}
print " </tr> \n " ;
2020-10-31 14:32:18 +01:00
}
2022-04-03 17:12:45 +02:00
2020-10-31 14:32:18 +01:00
print " </table> " ;
print '</div>' ;
2018-11-10 15:35:56 +01:00
}
2018-07-05 21:34:36 +02:00
2019-06-18 14:30:13 +02:00
2018-09-11 21:53:47 +02:00
llxFooter ();
2018-07-05 21:34:36 +02:00
$db -> close ();