dolibarr 21.0.0-beta
accounting-files.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2017 Pierre-Henry Favre <support@atm-consulting.fr>
5 * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
6 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
7 * Copyright (C) 2022-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31if ((array_key_exists('action', $_GET) && $_GET['action'] == 'dl') || (array_key_exists('action', $_POST) && $_POST['action'] == 'dl')) { // To not replace token when downloading file. Keep $_GET and $_POST here
32 if (!defined('NOTOKENRENEWAL')) {
33 define('NOTOKENRENEWAL', '1');
34 }
35}
36
37// Load Dolibarr environment
38require '../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
43require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
44require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
45require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
46require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
47require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
48require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
49require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
50require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
51require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
52require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
53
54if (isModEnabled('project')) {
55 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
56 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
57}
58
59// Constant to define payment sens
60const PAY_DEBIT = 0;
61const PAY_CREDIT = 1;
62
72$langs->loadLangs(array("accountancy", "bills", "companies", "salaries", "compta", "trips", "banks", "loan"));
73
74$date_start = GETPOST('date_start', 'alpha');
75$date_startDay = GETPOSTINT('date_startday');
76$date_startMonth = GETPOSTINT('date_startmonth');
77$date_startYear = GETPOSTINT('date_startyear');
78$date_start = dol_mktime(0, 0, 0, $date_startMonth, $date_startDay, $date_startYear, 'tzuserrel');
79$date_stop = GETPOST('date_stop', 'alpha');
80$date_stopDay = GETPOSTINT('date_stopday');
81$date_stopMonth = GETPOSTINT('date_stopmonth');
82$date_stopYear = GETPOSTINT('date_stopyear');
83$date_stop = dol_mktime(23, 59, 59, $date_stopMonth, $date_stopDay, $date_stopYear, 'tzuserrel');
84$action = GETPOST('action', 'aZ09');
85$projectid = GETPOSTINT('projectid');
86
87// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
88$hookmanager->initHooks(array('comptafileslist', 'globallist'));
89
90// Load variable for pagination
91$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
92$sortfield = GETPOST('sortfield', 'aZ09comma');
93$sortorder = GETPOST('sortorder', 'aZ09comma');
94$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
95if (empty($page) || $page == -1) {
96 $page = 0;
97} // If $page is not defined, or '' or -1
98$offset = $limit * $page;
99$pageprev = $page - 1;
100$pagenext = $page + 1;
101if (!$sortfield) {
102 $sortfield = "date,item"; // Set here default search field
103}
104if (!$sortorder) {
105 $sortorder = "DESC";
106}
107
108
109$arrayfields = array(
110 'type' => array('label' => "Type", 'checked' => 1),
111 'date' => array('label' => "Date", 'checked' => 1),
112 'date_due' => array('label' => "DateDue", 'checked' => 1),
113 'ref' => array('label' => "Ref", 'checked' => 1),
114 'documents' => array('label' => "Documents", 'checked' => 1),
115 'paid' => array('label' => "Paid", 'checked' => 1),
116 'total_ht' => array('label' => "TotalHT", 'checked' => 1),
117 'total_ttc' => array('label' => "TotalTTC", 'checked' => 1),
118 'total_vat' => array('label' => "TotalVAT", 'checked' => 1),
119 //...
120);
121
122// Security check
123if (!isModEnabled('comptabilite') && !isModEnabled('accounting')) {
125}
126if ($user->socid > 0) {
128}
129
130// Define $arrayofentities if multientity is set.
131$arrayofentities = array();
132if (isModEnabled('multicompany') && is_object($mc)) {
133 $arrayofentities = $mc->getEntitiesList();
134}
135
136$entity = (GETPOSTISSET('entity') ? GETPOSTINT('entity') : (GETPOSTISSET('search_entity') ? GETPOSTINT('search_entity') : $conf->entity));
137if (isModEnabled('multicompany') && is_object($mc)) {
138 if (empty($entity) && getDolGlobalString('MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES')) {
139 $entity = '0,'.implode(',', array_keys($arrayofentities));
140 }
141}
142if (empty($entity)) {
143 $entity = $conf->entity;
144}
145
146$error = 0;
147
148$listofchoices = array(
149 'selectinvoices' => array('label' => 'Invoices', 'picto' => 'bill', 'lang' => 'bills', 'enabled' => isModEnabled('invoice'), 'perms' => $user->hasRight('facture', 'lire')),
150 'selectsupplierinvoices' => array('label' => 'BillsSuppliers', 'picto' => 'supplier_invoice', 'lang' => 'bills', 'enabled' => isModEnabled('supplier_invoice'), 'perms' => $user->hasRight('fournisseur', 'facture', 'lire')),
151 'selectexpensereports' => array('label' => 'ExpenseReports', 'picto' => 'expensereport', 'lang' => 'trips', 'enabled' => isModEnabled('expensereport'), 'perms' => $user->hasRight('expensereport', 'lire')),
152 'selectdonations' => array('label' => 'Donations', 'picto' => 'donation', 'lang' => 'donation', 'enabled' => isModEnabled('don'), 'perms' => $user->hasRight('don', 'lire')),
153 'selectsocialcontributions' => array('label' => 'SocialContributions', 'picto' => 'bill', 'enabled' => isModEnabled('tax'), 'perms' => $user->hasRight('tax', 'charges', 'lire')),
154 'selectpaymentsofsalaries' => array('label' => 'SalariesPayments', 'picto' => 'salary', 'lang' => 'salaries', 'enabled' => isModEnabled('salaries'), 'perms' => $user->hasRight('salaries', 'read')),
155 'selectvariouspayment' => array('label' => 'VariousPayment', 'picto' => 'payment', 'enabled' => isModEnabled('bank'), 'perms' => $user->hasRight('banque', 'lire')),
156 'selectloanspayment' => array('label' => 'PaymentLoan','picto' => 'loan', 'enabled' => isModEnabled('don'), 'perms' => $user->hasRight('loan', 'read')),
157);
158
159
160
161/*
162 * Actions
163 */
164
165//$parameters = array('socid' => $id);
166//$reshook = $hookmanager->executeHooks('doActions', $parameters, $object); // Note that $object may have been modified by some hooks
167//if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
168
169$filesarray = array();
170
171'@phan-var-force array<string,array{id:string,entity:string,date:string,date_due:string,paid:float|int,amount_ht:float|int,amount_ttc:float|int,amount_vat:float|int,amount_localtax1:float|int,amount_localtax2:float|int,amount_revenuestamp:float|int,ref:string,fk:string,item:string,thirdparty_name:string,thirdparty_code:string,country_code:string,vatnum:string,sens:string,currency:string,line?:string,name?:string,files?:mixed}> $filesarray';
172
173$result = false;
174if ($action == 'searchfiles' || $action == 'dl') { // Test on permission not required here. Test is done per object type later.
175 if (empty($date_start)) {
176 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateStart")), null, 'errors');
177 $error++;
178 }
179 if (empty($date_stop)) {
180 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');
181 $error++;
182 }
183
184 if (!$error) {
185 $sql = '';
186
187 $wheretail = " '".$db->idate($date_start)."' AND '".$db->idate($date_stop)."'";
188
189 // Customer invoices
190 if (GETPOST('selectinvoices') && !empty($listofchoices['selectinvoices']['perms'])) {
191 if (!empty($sql)) {
192 $sql .= " UNION ALL";
193 }
194 $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,";
195 $sql .= " t.localtax1, t.localtax2, t.revenuestamp,";
196 $sql .= " 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";
197 $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";
198 $sql .= " WHERE datef between ".$wheretail;
199 $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
200 $sql .= " AND t.fk_statut <> ".Facture::STATUS_DRAFT;
201 if (!empty($projectid)) {
202 $sql .= " AND fk_projet = ".((int) $projectid);
203 }
204 }
205 // Vendor invoices
206 if (GETPOST('selectsupplierinvoices') && !empty($listofchoices['selectsupplierinvoices']['perms'])) {
207 if (!empty($sql)) {
208 $sql .= " UNION ALL";
209 }
210 $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,";
211 $sql .= " t.localtax1, t.localtax2, 0 as revenuestamp,";
212 $sql .= " 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";
213 $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";
214 $sql .= " WHERE datef between ".$wheretail;
215 $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
216 $sql .= " AND t.fk_statut <> ".FactureFournisseur::STATUS_DRAFT;
217 if (!empty($projectid)) {
218 $sql .= " AND fk_projet = ".((int) $projectid);
219 }
220 }
221 // Expense reports
222 if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms'])) {
223 if (!empty($sql)) {
224 $sql .= " UNION ALL";
225 }
226 // if project filter is used on an expense report,
227 // show only total_ht/total_tva/total_ttc of the line considered by the project
228 if (!empty($projectid)) {
229 $sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paid, SUM(td.total_ht) as total_ht, SUM(td.total_ttc) as total_ttc, SUM(td.total_tva) as total_vat,";
230 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
231 $sql .= " td.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";
232 $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport as t";
233 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "expensereport_det as td ON t.rowid = td.fk_expensereport";
234 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = t.fk_user_author";
235 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as c ON c.rowid = u.fk_country";
236 $sql .= " WHERE date_fin between " . $wheretail;
237 $sql .= " AND t.entity IN (" . $db->sanitize($entity == 1 ? '0,1' : $entity) . ')';
238 $sql .= " AND t.fk_statut <> " . ExpenseReport::STATUS_DRAFT;
239 $sql .= " AND fk_projet = ".((int) $projectid);
240 } else {
241 $sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paid, t.total_ht, t.total_ttc, t.total_tva as total_vat,";
242 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
243 $sql .= " 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";
244 $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";
245 $sql .= " WHERE date_fin between " . $wheretail;
246 $sql .= " AND t.entity IN (" . $db->sanitize($entity == 1 ? '0,1' : $entity) . ')';
247 $sql .= " AND t.fk_statut <> " . ExpenseReport::STATUS_DRAFT;
248 }
249 }
250 // Donations
251 if (GETPOST('selectdonations') && !empty($listofchoices['selectdonations']['perms'])) {
252 if (!empty($sql)) {
253 $sql .= " UNION ALL";
254 }
255 $sql .= " SELECT t.rowid as id, t.entity, t.ref, paid, amount as total_ht, amount as total_ttc, 0 as total_vat,";
256 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
257 $sql .= " '".$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";
258 $sql .= " FROM ".MAIN_DB_PREFIX."don as t LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = t.fk_country";
259 $sql .= " WHERE datedon between ".$wheretail;
260 $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
261 $sql .= " AND t.fk_statut <> ".Don::STATUS_DRAFT;
262 if (!empty($projectid)) {
263 $sql .= " AND fk_projet = ".((int) $projectid);
264 }
265 }
266 // Payments of salaries
267 if (GETPOST('selectpaymentsofsalaries') && !empty($listofchoices['selectpaymentsofsalaries']['perms'])) {
268 if (!empty($sql)) {
269 $sql .= " UNION ALL";
270 }
271 $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,";
272 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
273 $sql .= " '".$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";
274 $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";
275 $sql .= " WHERE datep between ".$wheretail;
276 $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
277 //$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT;
278 if (!empty($projectid)) {
279 $sql .= " AND fk_projet = ".((int) $projectid);
280 }
281 }
282 // Social contributions
283 if (GETPOST('selectsocialcontributions') && !empty($listofchoices['selectsocialcontributions']['perms'])) {
284 if (!empty($sql)) {
285 $sql .= " UNION ALL";
286 }
287 $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,";
288 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
289 $sql .= " '".$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";
290 $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as t";
291 $sql .= " WHERE t.date_ech between ".$wheretail;
292 $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
293 //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_UNPAID;
294 if (!empty($projectid)) {
295 $sql .= " AND fk_projet = ".((int) $projectid);
296 }
297 }
298 // Various payments
299 if (GETPOST('selectvariouspayment') && !empty($listofchoices['selectvariouspayment']['perms'])) {
300 if (!empty($sql)) {
301 $sql .= " UNION ALL";
302 }
303 $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,";
304 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
305 $sql .= " '".$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";
306 $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as t";
307 $sql .= " WHERE datep between ".$wheretail;
308 $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
309 if (!empty($projectid)) {
310 $sql .= " AND fk_projet = ".((int) $projectid);
311 }
312 }
313 // Loan payments
314 if (GETPOST('selectloanspayment') && !empty($listofchoices['selectloanspayment']['perms']) && empty($projectid)) {
315 if (!empty($sql)) {
316 $sql .= " UNION ALL";
317 }
318 $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,";
319 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
320 $sql .= " '".$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";
321 $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as t LEFT JOIN ".MAIN_DB_PREFIX."loan as l ON l.rowid = t.fk_loan";
322 $sql .= " WHERE datep between ".$wheretail;
323 $sql .= " AND l.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
324 }
325
326 if ($sql) {
327 $sql .= $db->order($sortfield, $sortorder);
328 //print $sql;
329
330 $resd = $db->query($sql);
331 $files = array();
332 $link = '';
333
334 if ($resd) {
335 $numd = $db->num_rows($resd);
336
337 $tmpinvoice = new Facture($db);
338 $tmpinvoicesupplier = new FactureFournisseur($db);
339 $tmpdonation = new Don($db);
340
341 $upload_dir = '';
342 $i = 0;
343 while ($i < $numd) {
344 $objd = $db->fetch_object($resd);
345
346 switch ($objd->item) {
347 case "Invoice":
348 $subdir = '';
349 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
350 $upload_dir = $conf->facture->dir_output.'/'.$subdir;
351 $link = "document.php?modulepart=facture&file=".str_replace('/', '%2F', $subdir).'%2F';
352 $modulepart = "facture";
353 break;
354 case "SupplierInvoice":
355 $tmpinvoicesupplier->fetch($objd->id);
356 $subdir = get_exdir($tmpinvoicesupplier->id, 2, 0, 1, $tmpinvoicesupplier, 'invoice_supplier'); // TODO Use first file
357 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
358 $upload_dir = $conf->fournisseur->facture->dir_output.'/'.$subdir;
359 $link = "document.php?modulepart=facture_fournisseur&file=".str_replace('/', '%2F', $subdir).'%2F';
360 $modulepart = "facture_fournisseur";
361 break;
362 case "ExpenseReport":
363 $subdir = '';
364 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
365 $upload_dir = $conf->expensereport->dir_output.'/'.$subdir;
366 $link = "document.php?modulepart=expensereport&file=".str_replace('/', '%2F', $subdir).'%2F';
367 $modulepart = "expensereport";
368 break;
369 case "SalaryPayment":
370 $subdir = '';
371 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
372 $upload_dir = $conf->salaries->dir_output.'/'.$subdir;
373 $link = "document.php?modulepart=salaries&file=".str_replace('/', '%2F', $subdir).'%2F';
374 $modulepart = "salaries";
375 break;
376 case "Donation":
377 $tmpdonation->fetch($objd->id);
378 $subdir = get_exdir(0, 0, 0, 0, $tmpdonation, 'donation');
379 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
380 $upload_dir = $conf->don->dir_output.'/'.$subdir;
381 $link = "document.php?modulepart=don&file=".str_replace('/', '%2F', $subdir).'%2F';
382 $modulepart = "don";
383 break;
384 case "SocialContributions":
385 $subdir = '';
386 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
387 $upload_dir = $conf->tax->dir_output.'/'.$subdir;
388 $link = "document.php?modulepart=tax&file=".str_replace('/', '%2F', $subdir).'%2F';
389 $modulepart = "tax";
390 break;
391 case "VariousPayment":
392 $subdir = '';
393 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
394 $upload_dir = $conf->bank->dir_output.'/'.$subdir;
395 $link = "document.php?modulepart=banque&file=".str_replace('/', '%2F', $subdir).'%2F';
396 $modulepart = "banque";
397 break;
398 case "LoanPayment":
399 // Loan payment has no linked file
400 $subdir = '';
401 $upload_dir = $conf->loan->dir_output.'/'.$subdir;
402 $link = "";
403 $modulepart = "";
404 break;
405 default:
406 $subdir = '';
407 $upload_dir = '';
408 $link = '';
409 break;
410 }
411
412 if (!empty($upload_dir)) {
413 $result = true;
414
415 $files = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', '', SORT_ASC, 1);
416 //var_dump($upload_dir);
417 //var_dump($files);
418 if (count($files) < 1) {
419 $nofile = array();
420 $nofile['id'] = (int) $objd->id;
421 $nofile['entity'] = (int) $objd->entity;
422 $nofile['date'] = $db->jdate($objd->date);
423 $nofile['date_due'] = $db->jdate($objd->date_due);
424 $nofile['paid'] = (int) $objd->paid;
425 $nofile['amount_ht'] = $objd->total_ht;
426 $nofile['amount_ttc'] = $objd->total_ttc;
427 $nofile['amount_vat'] = $objd->total_vat;
428 $nofile['amount_localtax1'] = $objd->localtax1;
429 $nofile['amount_localtax2'] = $objd->localtax2;
430 $nofile['amount_revenuestamp'] = $objd->revenuestamp;
431 $nofile['ref'] = ($objd->ref ? $objd->ref : $objd->id);
432 $nofile['fk'] = $objd->fk_soc;
433 $nofile['item'] = $objd->item;
434 $nofile['thirdparty_name'] = $objd->thirdparty_name;
435 $nofile['thirdparty_code'] = $objd->thirdparty_code;
436 $nofile['country_code'] = $objd->country_code;
437 $nofile['vatnum'] = $objd->vatnum;
438 $nofile['sens'] = $objd->sens;
439 $nofile['currency'] = $objd->currency;
440 $nofile['link'] = '';
441 $nofile['name'] = '';
442
443
444 $filesarray[$nofile['item'].'_'.$nofile['id']] = $nofile;
445 } else {
446 foreach ($files as $key => $file) {
447 $file['id'] = (int) $objd->id;
448 $file['entity'] = (int) $objd->entity;
449 $file['date'] = $db->jdate($objd->date);
450 $file['date_due'] = $db->jdate($objd->date_due);
451 $file['paid'] = (int) $objd->paid;
452 $file['amount_ht'] = $objd->total_ht;
453 $file['amount_ttc'] = $objd->total_ttc;
454 $file['amount_vat'] = $objd->total_vat;
455 $file['amount_localtax1'] = $objd->localtax1;
456 $file['amount_localtax2'] = $objd->localtax2;
457 $file['amount_revenuestamp'] = $objd->revenuestamp;
458 $file['ref'] = ($objd->ref ? $objd->ref : $objd->id);
459 $file['fk'] = $objd->fk_soc;
460 $file['item'] = $objd->item;
461 $file['thirdparty_name'] = $objd->thirdparty_name;
462 $file['thirdparty_code'] = $objd->thirdparty_code;
463 $file['country_code'] = $objd->country_code;
464 $file['vatnum'] = $objd->vatnum;
465 $file['sens'] = $objd->sens;
466 $file['currency'] = $objd->currency;
467
468 // Save record into array (only the first time it is found)
469 if (empty($filesarray[$file['item'].'_'.$file['id']])) {
470 $filesarray[$file['item'].'_'.$file['id']] = $file;
471 }
472
473 // Add or concat file
474 if (empty($filesarray[$file['item'].'_'.$file['id']]['files'])) {
475 $filesarray[$file['item'].'_'.$file['id']]['files'] = array();
476 }
477 $filesarray[$file['item'].'_'.$file['id']]['files'][] = array(
478 'link' => $link.urlencode($file['name']),
479 'name' => $file['name'],
480 'ref' => $file['ref'],
481 'fullname' => $file['fullname'],
482 'relpath' => '/'.$file['name'],
483 'relpathnamelang' => $langs->trans($file['item']).'/'.$file['name'],
484 'modulepart' => $modulepart,
485 'subdir' => $subdir,
486 'currency' => $file['currency']
487 );
488 //var_dump($file['item'].'_'.$file['id']);
489 //var_dump($filesarray[$file['item'].'_'.$file['id']]['files']);
490 }
491 }
492 }
493
494 $i++;
495 }
496 } else {
497 dol_print_error($db);
498 }
499
500 $db->free($resd);
501 } else {
502 setEventMessages($langs->trans("ErrorSelectAtLeastOne"), null, 'errors');
503 $error++;
504 }
505 }
506}
507
508// zip creation
509
510$dirfortmpfile = (!empty($conf->accounting->dir_temp) ? $conf->accounting->dir_temp : $conf->comptabilite->dir_temp);
511if (empty($dirfortmpfile)) {
512 setEventMessages($langs->trans("ErrorNoAccountingModuleEnabled"), null, 'errors');
513 $error++;
514}
515
516if ($result && $action == "dl" && !$error) { // Test on permission not required here. Test is done per object type later.
517 if (!extension_loaded('zip')) {
518 setEventMessages('PHPZIPExtentionNotLoaded', null, 'errors');
519 } else {
520 dol_mkdir($dirfortmpfile);
521
522 $log = $langs->transnoentitiesnoconv("Type");
523 if (isModEnabled('multicompany') && is_object($mc)) {
524 $log .= ','.$langs->transnoentitiesnoconv("Entity");
525 }
526 $log .= ','.$langs->transnoentitiesnoconv("Date");
527 $log .= ','.$langs->transnoentitiesnoconv("DateDue");
528 $log .= ','.$langs->transnoentitiesnoconv("Ref");
529 $log .= ','.$langs->transnoentitiesnoconv("TotalHT");
530 $log .= ','.$langs->transnoentitiesnoconv("TotalTTC");
531 $log .= ','.$langs->transnoentitiesnoconv("TotalVAT");
532 $log .= ','.$langs->transcountrynoentities("TotalLT1", $mysoc->country_code);
533 $log .= ','.$langs->transcountrynoentities("TotalLT2", $mysoc->country_code);
534 $log .= ','.$langs->transnoentitiesnoconv("RevenueStamp");
535 $log .= ','.$langs->transnoentitiesnoconv("Paid");
536 $log .= ','.$langs->transnoentitiesnoconv("Document");
537 $log .= ','.$langs->transnoentitiesnoconv("ItemID");
538 $log .= ','.$langs->transnoentitiesnoconv("ThirdParty");
539 $log .= ','.$langs->transnoentitiesnoconv("Code");
540 $log .= ','.$langs->transnoentitiesnoconv("Country");
541 $log .= ','.$langs->transnoentitiesnoconv("VATIntra");
542 $log .= ','.$langs->transnoentitiesnoconv("Sens")."\n";
543 $zipname = $dirfortmpfile.'/'.dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel');
544 if (!empty($projectid)) {
545 $project = new Project($db);
546 $project->fetch($projectid);
547 if ($project->ref) {
548 $zipname .= '_'.$project->ref;
549 }
550 }
551 $zipname .= '_export.zip';
552
553 dol_delete_file($zipname);
554
555 $zip = new ZipArchive();
556 $res = $zip->open($zipname, ZipArchive::OVERWRITE | ZipArchive::CREATE);
557 if ($res) {
558 foreach ($filesarray as $key => $file) {
559 if (!empty($file['files'])) {
560 foreach ($file['files'] as $filecursor) {
561 if (file_exists($filecursor["fullname"])) {
562 $zip->addFile($filecursor["fullname"], $filecursor["relpathnamelang"]);
563 }
564 }
565 }
566
567 $log .= '"'.$langs->transnoentitiesnoconv($file['item']).'"';
568 if (isModEnabled('multicompany') && is_object($mc)) {
569 $log .= ',"'.(empty($arrayofentities[$file['entity']]) ? $file['entity'] : $arrayofentities[$file['entity']]).'"';
570 }
571 $log .= ','.dol_print_date($file['date'], 'dayrfc');
572 $log .= ','.dol_print_date($file['date_due'], 'dayrfc');
573 $log .= ',"'.$file['ref'].'"';
574 $log .= ','.$file['amount_ht'];
575 $log .= ','.$file['amount_ttc'];
576 $log .= ','.$file['amount_vat'];
577 $log .= ','.$file['amount_localtax1'];
578 $log .= ','.$file['amount_localtax2'];
579 $log .= ','.$file['amount_revenuestamp'];
580 $log .= ','.$file['paid'];
581 $log .= ',"'.$file["name"].'"';
582 $log .= ','.$file['fk'];
583 $log .= ',"'.$file['thirdparty_name'].'"';
584 $log .= ',"'.$file['thirdparty_code'].'"';
585 $log .= ',"'.$file['country_code'].'"';
586 $log .= ',"'.$file['vatnum'].'"';
587 $log .= ',"'.$file['sens'].'"';
588 $log .= "\n";
589 }
590 $zip->addFromString('transactions.csv', $log);
591 $zip->close();
592
593 // Then download the zipped file.
594 header('Content-Type: application/zip');
595 header('Content-disposition: attachment; filename='.basename($zipname));
596 header('Content-Length: '.filesize($zipname));
597 readfile($zipname);
598
599 dol_delete_file($zipname);
600
601 exit();
602 } else {
603 setEventMessages($langs->trans("FailedToOpenFile", $zipname), null, 'errors');
604 }
605 }
606}
607
608
609/*
610 * View
611 */
612
613$form = new Form($db);
614$formfile = new FormFile($db);
615$userstatic = new User($db);
616$invoice = new Facture($db);
617$supplier_invoice = new FactureFournisseur($db);
618$expensereport = new ExpenseReport($db);
619$don = new Don($db);
620$salary_payment = new PaymentSalary($db);
621$charge_sociales = new ChargeSociales($db);
622$various_payment = new PaymentVarious($db);
623$payment_loan = new PaymentLoan($db);
624
625$title = $langs->trans("ComptaFiles").' - '.$langs->trans("List");
626$help_url = '';
627
628llxHeader('', $title, $help_url);
629
630$h = 0;
631$head = array();
632$head[$h][0] = $_SERVER["PHP_SELF"];
633$head[$h][1] = $langs->trans("AccountantFiles");
634$head[$h][2] = 'AccountancyFiles';
635
636print dol_get_fiche_head($head, 'AccountancyFiles');
637
638
639print '<form name="searchfiles" action="?action=searchfiles" method="POST">'."\n";
640print '<input type="hidden" name="token" value="'.newToken().'">';
641
642print '<span class="opacitymedium">'.$langs->trans("ExportAccountingSourceDocHelp");
643if (isModEnabled('accounting')) {
644 print ' '.$langs->trans("ExportAccountingSourceDocHelp2", $langs->transnoentitiesnoconv("Accounting"), $langs->transnoentitiesnoconv("Journals"));
645}
646print '</span><br>';
647print '<br>';
648
649print $langs->trans("ReportPeriod").': ';
650print $form->selectDate($date_start, 'date_start', 0, 0, 0, "", 1, 1, 0, '', '', '', '', 1, '', '', 'tzuserrel');
651print ' - ';
652print $form->selectDate($date_stop, 'date_stop', 0, 0, 0, "", 1, 1, 0, '', '', '', '', 1, '', '', 'tzuserrel');
653print "\n";
654
655// Export is for current company only
656$socid = 0;
657if (isModEnabled('multicompany') && is_object($mc)) {
658 $mc->getInfo($conf->entity);
659 print ' &nbsp; <span class="marginleftonly marginrightonly'.(!getDolGlobalString('MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES') ? ' opacitymedium' : '').'">'.$langs->trans("Entity").' : ';
660 if (getDolGlobalString('MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES')) {
661 $socid = $mc->id;
662 print $mc->select_entities(GETPOSTISSET('search_entity') ? GETPOSTINT('search_entity') : $mc->id, 'search_entity', '', false, false, false, false, true);
663 } else {
664 print $mc->label;
665 }
666 print "</span>\n";
667}
668
669print '<br>';
670
671// Project filter
672if (isModEnabled('project')) {
673 $formproject = new FormProjets($db);
674 $langs->load('projects');
675 print '<span class="marginrightonly">'.$langs->trans('Project').":</span>";
676 print img_picto('', 'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 1, 0, '');
677 print '<span class="classfortooltip" style="padding: 0px; padding: 0px; padding-right: 3px !important;" title="'.$langs->trans('ExportAccountingProjectHelp').'"><span class="fas fa-info-circle em088 opacityhigh" style=" vertical-align: middle; cursor: help"></span></span>';
678 print '<br>';
679}
680
681$i = 0;
682foreach ($listofchoices as $choice => $val) {
683 if (empty($val['enabled'])) {
684 continue; // list not qualified
685 }
686 $disabled = '';
687 if (empty($val['perms'])) {
688 $disabled = ' disabled';
689 }
690 $checked = (((!GETPOSTISSET('search') && $action != 'searchfiles') || GETPOST($choice)) ? ' checked="checked"' : '');
691 print '<div class="inline-block marginrightonlylarge paddingright margintoponly"><input type="checkbox" id="'.$choice.'" name="'.$choice.'" value="1"'.$checked.$disabled.'><label for="'.$choice.'"> ';
692 print img_picto($langs->trans($val['label']), $val['picto'], 'class=""').' '.$langs->trans($val['label']);
693 print '</label></div>';
694 $i++;
695}
696
697print '<input type="submit" class="button small" name="search" value="'.$langs->trans("Search").'">';
698
699print '</form>'."\n";
700
701print dol_get_fiche_end();
702
703$param = '';
704if (!empty($date_start) && !empty($date_stop)) {
705 $param .= '&date_startday='.GETPOSTINT('date_startday');
706 $param .= '&date_startmonth='.GETPOSTINT('date_startmonth');
707 $param .= '&date_startyear='.GETPOSTINT('date_startyear');
708 $param .= '&date_stopday='.GETPOSTINT('date_stopday');
709 $param .= '&date_stopmonth='.GETPOSTINT('date_stopmonth');
710 $param .= '&date_stopyear='.GETPOSTINT('date_stopyear');
711 foreach ($listofchoices as $choice => $val) {
712 if (GETPOSTINT($choice)) {
713 $param .= '&'.$choice.'=1';
714 }
715 }
716
717 $TData = dol_sort_array($filesarray, $sortfield, $sortorder);
718 '@phan-var-force array<string,array{id:string,entity:string,date:string,date_due:string,paid:float|int,amount_ht:float|int,amount_ttc:float|int,amount_vat:float|int,amount_localtax1:float|int,amount_localtax2:float|int,amount_revenuestamp:float|int,ref:string,fk:string,item:string,thirdparty_name:string,thirdparty_code:string,country_code:string,vatnum:string,sens:string,currency:string,line?:string,name?:string,files?:mixed}> $TData';
719
720
721 $filename = dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel').'_export.zip';
722
723 echo dol_print_date($date_start, 'day', 'tzuserrel')." - ".dol_print_date($date_stop, 'day', 'tzuserrel');
724
725 print '<a class="marginleftonly small'.(empty($TData) ? ' butActionRefused' : ' butAction').'" href="'.$_SERVER["PHP_SELF"].'?action=dl&token='.currentToken().'&projectid='.((int) $projectid).'&output=file&file='.urlencode($filename).$param.'"';
726 if (empty($TData)) {
727 print " disabled";
728 }
729 print '>'."\n";
730 print $langs->trans("Download");
731 print '</a><br>';
732
733 $param .= '&action=searchfiles';
734
735 /*
736 print '<input type="hidden" name="token" value="'.currentToken().'">';
737 print '<input type="hidden" name="date_startday" value="'.GETPOST('date_startday', 'int').'" />';
738 print '<input type="hidden" name="date_startmonth" value="'.GETPOST('date_startmonth', 'int').'" />';
739 print '<input type="hidden" name="date_startyear" value="'.GETPOST('date_startyear', 'int').'" />';
740 print '<input type="hidden" name="date_stopday" value="'.GETPOST('date_stopday', 'int').'" />';
741 print '<input type="hidden" name="date_stopmonth" value="'.GETPOST('date_stopmonth', 'int').'" />';
742 print '<input type="hidden" name="date_stopyear" value="'.GETPOST('date_stopyear', 'int').'" />';
743 foreach ($listofchoices as $choice => $val) {
744 print '<input type="hidden" name="'.$choice.'" value="'.GETPOST($choice).'">';
745 }
746
747 print '<input class="butAction butDownload small marginleftonly" type="submit" value="'.$langs->trans("Download").'"';
748 if (empty($TData)) {
749 print " disabled";
750 }
751 print '/>';
752 print '</form>'."\n";
753 */
754
755 print '<br>';
756
757 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
758 print '<table class="noborder centpercent">';
759 print '<tr class="liste_titre">';
760 print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "item", "", $param, '', $sortfield, $sortorder, 'nowrap ');
761 print_liste_field_titre($arrayfields['date']['label'], $_SERVER["PHP_SELF"], "date", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
762 print_liste_field_titre($arrayfields['date_due']['label'], $_SERVER["PHP_SELF"], "date_due", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
763 print_liste_field_titre($arrayfields['ref']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'nowraponall ');
764 print '<th>'.$langs->trans("Document").'</th>';
765 print '<th>'.$langs->trans("Paid").'</th>';
766 print '<th class="right">'.$langs->trans("TotalHT").(isModEnabled('multicurrency') ? ' ('.$langs->getCurrencySymbol($conf->currency).')' : '').'</th>';
767 print '<th class="right">'.$langs->trans("TotalTTC").(isModEnabled('multicurrency') ? ' ('.$langs->getCurrencySymbol($conf->currency).')' : '').'</th>';
768 print '<th class="right">'.$langs->trans("TotalVAT").(isModEnabled('multicurrency') ? ' ('.$langs->getCurrencySymbol($conf->currency).')' : '').'</th>';
769
770 print '<th>'.$langs->trans("ThirdParty").'</th>';
771 print '<th class="center">'.$langs->trans("Code").'</th>';
772 print '<th class="center">'.$langs->trans("Country").'</th>';
773 print '<th class="center">'.$langs->trans("VATIntra").'</th>';
774 if (isModEnabled('multicurrency')) {
775 print '<th class="center">'.$langs->trans("Currency").'</th>';
776 }
777 print '</tr>';
778
779 if (empty($TData)) {
780 print '<tr class="oddeven"><td colspan="13"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td>';
781 if (isModEnabled('multicurrency')) {
782 print '<td></td>';
783 }
784 print '</tr>';
785 } else {
786 // Sort array by date ASC to calculate balance
787
788 $totalET_debit = 0;
789 $totalIT_debit = 0;
790 $totalVAT_debit = 0;
791 $totalET_credit = 0;
792 $totalIT_credit = 0;
793 $totalVAT_credit = 0;
794
795 // Display array
796 foreach ($TData as $data) {
797 $html_class = '';
798 //if (!empty($data['fk_facture'])) $html_class = 'facid-'.$data['fk_facture'];
799 //elseif (!empty($data['fk_paiement'])) $html_class = 'payid-'.$data['fk_paiement'];
800 print '<tr class="oddeven '.$html_class.'">';
801
802 // Type
803 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($langs->trans($data['item'])).'">'.$langs->trans($data['item']).'</td>';
804
805 // Date
806 print '<td class="center">';
807 print dol_print_date($data['date'], 'day');
808 print "</td>\n";
809
810 // Date due
811 print '<td class="center">';
812 print dol_print_date($data['date_due'], 'day');
813 print "</td>\n";
814
815 // Ref
816 print '<td class="nowraponall tdoverflowmax150">';
817
818 if ($data['item'] == 'Invoice') {
819 $invoice->id = (int) $data['id'];
820 $invoice->ref = $data['ref'];
821 $invoice->total_ht = $data['amount_ht'];
822 $invoice->total_ttc = $data['amount_ttc'];
823 $invoice->total_tva = $data['amount_vat'];
824 $invoice->total_localtax1 = $data['amount_localtax1'];
825 $invoice->total_localtax2 = $data['amount_localtax2'];
826 $invoice->revenuestamp = $data['amount_revenuestamp'];
827 $invoice->multicurrency_code = $data['currency'];
828 print $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0);
829 } elseif ($data['item'] == 'SupplierInvoice') {
830 $supplier_invoice->id = (int) $data['id'];
831 $supplier_invoice->ref = $data['ref'];
832 $supplier_invoice->total_ht = $data['amount_ht'];
833 $supplier_invoice->total_ttc = $data['amount_ttc'];
834 $supplier_invoice->total_tva = $data['amount_vat'];
835 $supplier_invoice->total_localtax1 = $data['amount_localtax1'];
836 $supplier_invoice->total_localtax2 = $data['amount_localtax2'];
837 $supplier_invoice->revenuestamp = $data['amount_revenuestamp'];
838 $supplier_invoice->multicurrency_code = $data['currency'];
839 print $supplier_invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0);
840 } elseif ($data['item'] == 'ExpenseReport') {
841 $expensereport->id = (int) $data['id'];
842 $expensereport->ref = $data['ref'];
843 print $expensereport->getNomUrl(1, 0, 0, 0, 0, 0);
844 } elseif ($data['item'] == 'SalaryPayment') {
845 $salary_payment->id = (int) $data['id'];
846 $salary_payment->ref = $data['ref'];
847 print $salary_payment->getNomUrl(1);
848 } elseif ($data['item'] == 'Donation') {
849 $don->id = (int) $data['id'];
850 $don->ref = $data['ref'];
851 print $don->getNomUrl(1, 0, '', 0);
852 } elseif ($data['item'] == 'SocialContributions') {
853 $charge_sociales->id = (int) $data['id'];
854 $charge_sociales->ref = $data['ref'];
855 print $charge_sociales->getNomUrl(1, 0, 0, 0, 0);
856 } elseif ($data['item'] == 'VariousPayment') {
857 $various_payment->id = (int) $data['id'];
858 $various_payment->ref = $data['ref'];
859 print $various_payment->getNomUrl(1, '', 0, 0);
860 } elseif ($data['item'] == 'LoanPayment') {
861 $payment_loan->id = (int) $data['id'];
862 $payment_loan->ref = $data['ref'];
863 print $payment_loan->getNomUrl(1, 0, 0, '', 0);
864 } else {
865 print $data['ref'];
866 }
867 print '</td>';
868
869 // File link
870 print '<td class="tdoverflowmax150">';
871 if (!empty($data['files'])) {
872 foreach ($data['files'] as $id => $filecursor) {
873 $tmppreview = $formfile->showPreview($filecursor, $filecursor['modulepart'], $filecursor['subdir'].'/'.$filecursor['name'], 0);
874 if ($tmppreview) {
875 print $tmppreview;
876 }
877 $filename = ($filecursor['name'] ? $filecursor['name'] : $filecursor['ref']);
878 print '<a href='.DOL_URL_ROOT.'/'.$filecursor['link'].' target="_blank" rel="noopener noreferrer" title="'.dol_escape_htmltag($filename).'">';
879 if (empty($tmppreview)) {
880 print img_picto('', 'generic', '', 0, 0, 0, '', 'pictonopreview pictofixedwidth paddingright');
881 }
882 print $filename;
883 print '</a><br>';
884 }
885 }
886 print "</td>\n";
887
888 // Paid
889 print '<td class="center">'.($data['paid'] ? yn($data['paid']) : '').'</td>';
890
891 // Total WOT
892 print '<td class="right"><span class="amount">'.price(price2num($data['sens'] ? $data['amount_ht'] : -$data['amount_ht'], 'MT'))."</span></td>\n";
893 // Total INCT
894 print '<td class="right"><span class="amount">';
895 $tooltip = $langs->trans("TotalVAT").' : '.price(price2num($data['sens'] ? $data['amount_vat'] : -$data['amount_vat'], 'MT'));
896 if (!empty($data['amount_localtax1'])) {
897 $tooltip .= '<br>'.$langs->transcountrynoentities("TotalLT1", $mysoc->country_code).' : '.price(price2num($data['sens'] ? $data['amount_localtax1'] : -$data['amount_localtax1'], 'MT'));
898 }
899 if (!empty($data['amount_localtax2'])) {
900 $tooltip .= '<br>'.$langs->transcountrynoentities("TotalLT2", $mysoc->country_code).' : '.price(price2num($data['sens'] ? $data['amount_localtax2'] : -$data['amount_localtax2'], 'MT'));
901 }
902 if (!empty($data['amount_revenuestamp'])) {
903 $tooltip .= '<br>'.$langs->trans("RevenueStamp").' : '.price(price2num($data['sens'] ? $data['amount_revenuestamp'] : -$data['amount_revenuestamp'], 'MT'));
904 }
905 print '<span class="classfortooltip" title="'.dol_escape_htmltag($tooltip).'">'.price(price2num($data['sens'] ? $data['amount_ttc'] : -$data['amount_ttc'], 'MT')).'</span>';
906 print "</span></td>\n";
907 // Total VAT
908 print '<td class="right"><span class="amount">'.price(price2num($data['sens'] ? $data['amount_vat'] : -$data['amount_vat'], 'MT'))."</span></td>\n";
909
910 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($data['thirdparty_name']).'">'.dol_escape_htmltag($data['thirdparty_name'])."</td>\n";
911
912 print '<td class="center">'.$data['thirdparty_code']."</td>\n";
913
914 print '<td class="center">'.$data['country_code']."</td>\n";
915
916 // VAT number
917 print '<td class="tdoverflowmax150 right" title="'.dol_escape_htmltag($data['vatnum']).'">'.dol_escape_htmltag($data['vatnum'])."</td>\n";
918
919 if ($data['sens']) {
920 $totalET_credit += $data['amount_ht'];
921 $totalIT_credit += $data['amount_ttc'];
922 $totalVAT_credit += $data['amount_vat'];
923 } else {
924 $totalET_debit -= $data['amount_ht'];
925 $totalIT_debit -= $data['amount_ttc'];
926 $totalVAT_debit -= $data['amount_vat'];
927 }
928
929 if (isModEnabled('multicurrency')) {
930 print '<td class="center">'.$data['currency']."</td>\n";
931 }
932
933 print "</tr>\n";
934 }
935
936 // Total credits
937 print '<tr class="liste_total">';
938 print '<td colspan="6" class="right">'.$langs->trans('Total').' '.$langs->trans('Income').'</td>';
939 print '<td class="right">'.price(price2num($totalET_credit, 'MT')).'</td>';
940 print '<td class="right">'.price(price2num($totalIT_credit, 'MT')).'</td>';
941 print '<td class="right">'.price(price2num($totalVAT_credit, 'MT')).'</td>';
942 print '<td colspan="4"></td>';
943 if (isModEnabled('multicurrency')) {
944 print '<td></td>';
945 }
946 print "</tr>\n";
947 // Total debits
948 print '<tr class="liste_total">';
949 print '<td colspan="6" class="right">'.$langs->trans('Total').' '.$langs->trans('Outcome').'</td>';
950 print '<td class="right">'.price(price2num($totalET_debit, 'MT')).'</td>';
951 print '<td class="right">'.price(price2num($totalIT_debit, 'MT')).'</td>';
952 print '<td class="right">'.price(price2num($totalVAT_debit, 'MT')).'</td>';
953 print '<td colspan="4"></td>';
954 if (isModEnabled('multicurrency')) {
955 print '<td></td>';
956 }
957 print "</tr>\n";
958 // Balance
959 print '<tr class="liste_total">';
960 print '<td colspan="6" class="right">'.$langs->trans('Total').'</td>';
961 print '<td class="right">'.price(price2num($totalET_credit + $totalET_debit, 'MT')).'</td>';
962 print '<td class="right">'.price(price2num($totalIT_credit + $totalIT_debit, 'MT')).'</td>';
963 print '<td class="right">'.price(price2num($totalVAT_credit + $totalVAT_debit, 'MT')).'</td>';
964 print '<td colspan="4"></td>';
965 if (isModEnabled('multicurrency')) {
966 print '<td></td>';
967 }
968 print "</tr>\n";
969 }
970
971 print "</table>";
972 print '</div>';
973}
974
975
976llxFooter();
977$db->close();
$id
Definition account.php:48
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class for managing the social charges.
Class to manage donations.
Definition don.class.php:41
Class to manage Trips and Expenses.
const STATUS_DRAFT
Draft status.
Class to manage suppliers invoices.
Class to manage invoices.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
Class to manage payments of loans.
Class to manage payments of salaries.
Class to manage various payments.
Class to manage projects.
Class to manage Dolibarr users.
llxFooter()
Footer empty.
Definition document.php:107
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
currentToken()
Return the value of token currently saved into session with name 'token'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.