dolibarr 21.0.0-alpha
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
63$langs->loadLangs(array("accountancy", "bills", "companies", "salaries", "compta", "trips", "banks", "loan"));
64
65$date_start = GETPOST('date_start', 'alpha');
66$date_startDay = GETPOSTINT('date_startday');
67$date_startMonth = GETPOSTINT('date_startmonth');
68$date_startYear = GETPOSTINT('date_startyear');
69$date_start = dol_mktime(0, 0, 0, $date_startMonth, $date_startDay, $date_startYear, 'tzuserrel');
70$date_stop = GETPOST('date_stop', 'alpha');
71$date_stopDay = GETPOSTINT('date_stopday');
72$date_stopMonth = GETPOSTINT('date_stopmonth');
73$date_stopYear = GETPOSTINT('date_stopyear');
74$date_stop = dol_mktime(23, 59, 59, $date_stopMonth, $date_stopDay, $date_stopYear, 'tzuserrel');
75$action = GETPOST('action', 'aZ09');
76$projectid = GETPOSTINT('projectid');
77
78// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
79$hookmanager->initHooks(array('comptafileslist', 'globallist'));
80
81// Load variable for pagination
82$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
83$sortfield = GETPOST('sortfield', 'aZ09comma');
84$sortorder = GETPOST('sortorder', 'aZ09comma');
85$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
86if (empty($page) || $page == -1) {
87 $page = 0;
88} // If $page is not defined, or '' or -1
89$offset = $limit * $page;
90$pageprev = $page - 1;
91$pagenext = $page + 1;
92if (!$sortfield) {
93 $sortfield = "date,item"; // Set here default search field
94}
95if (!$sortorder) {
96 $sortorder = "DESC";
97}
98
99
100$arrayfields = array(
101 'type' => array('label' => "Type", 'checked' => 1),
102 'date' => array('label' => "Date", 'checked' => 1),
103 'date_due' => array('label' => "DateDue", 'checked' => 1),
104 'ref' => array('label' => "Ref", 'checked' => 1),
105 'documents' => array('label' => "Documents", 'checked' => 1),
106 'paid' => array('label' => "Paid", 'checked' => 1),
107 'total_ht' => array('label' => "TotalHT", 'checked' => 1),
108 'total_ttc' => array('label' => "TotalTTC", 'checked' => 1),
109 'total_vat' => array('label' => "TotalVAT", 'checked' => 1),
110 //...
111);
112
113// Security check
114if (!isModEnabled('comptabilite') && !isModEnabled('accounting')) {
116}
117if ($user->socid > 0) {
119}
120
121// Define $arrayofentities if multientity is set.
122$arrayofentities = array();
123if (isModEnabled('multicompany') && is_object($mc)) {
124 $arrayofentities = $mc->getEntitiesList();
125}
126
127$entity = (GETPOSTISSET('entity') ? GETPOSTINT('entity') : (GETPOSTISSET('search_entity') ? GETPOSTINT('search_entity') : $conf->entity));
128if (isModEnabled('multicompany') && is_object($mc)) {
129 if (empty($entity) && getDolGlobalString('MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES')) {
130 $entity = '0,'.implode(',', array_keys($arrayofentities));
131 }
132}
133if (empty($entity)) {
134 $entity = $conf->entity;
135}
136
137$error = 0;
138
139$listofchoices = array(
140 'selectinvoices' => array('label' => 'Invoices', 'picto' => 'bill', 'lang' => 'bills', 'enabled' => isModEnabled('invoice'), 'perms' => $user->hasRight('facture', 'lire')),
141 'selectsupplierinvoices' => array('label' => 'BillsSuppliers', 'picto' => 'supplier_invoice', 'lang' => 'bills', 'enabled' => isModEnabled('supplier_invoice'), 'perms' => $user->hasRight('fournisseur', 'facture', 'lire')),
142 'selectexpensereports' => array('label' => 'ExpenseReports', 'picto' => 'expensereport', 'lang' => 'trips', 'enabled' => isModEnabled('expensereport'), 'perms' => $user->hasRight('expensereport', 'lire')),
143 'selectdonations' => array('label' => 'Donations', 'picto' => 'donation', 'lang' => 'donation', 'enabled' => isModEnabled('don'), 'perms' => $user->hasRight('don', 'lire')),
144 'selectsocialcontributions' => array('label' => 'SocialContributions', 'picto' => 'bill', 'enabled' => isModEnabled('tax'), 'perms' => $user->hasRight('tax', 'charges', 'lire')),
145 'selectpaymentsofsalaries' => array('label' => 'SalariesPayments', 'picto' => 'salary', 'lang' => 'salaries', 'enabled' => isModEnabled('salaries'), 'perms' => $user->hasRight('salaries', 'read')),
146 'selectvariouspayment' => array('label' => 'VariousPayment', 'picto' => 'payment', 'enabled' => isModEnabled('bank'), 'perms' => $user->hasRight('banque', 'lire')),
147 'selectloanspayment' => array('label' => 'PaymentLoan','picto' => 'loan', 'enabled' => isModEnabled('don'), 'perms' => $user->hasRight('loan', 'read')),
148);
149
150
151
152/*
153 * Actions
154 */
155
156//$parameters = array('socid' => $id);
157//$reshook = $hookmanager->executeHooks('doActions', $parameters, $object); // Note that $object may have been modified by some hooks
158//if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
159
160$filesarray = array();
161
162'@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';
163
164$result = false;
165if ($action == 'searchfiles' || $action == 'dl') { // Test on permission not required here. Test is done per object type later.
166 if (empty($date_start)) {
167 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateStart")), null, 'errors');
168 $error++;
169 }
170 if (empty($date_stop)) {
171 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');
172 $error++;
173 }
174
175 if (!$error) {
176 $sql = '';
177
178 $wheretail = " '".$db->idate($date_start)."' AND '".$db->idate($date_stop)."'";
179
180 // Customer invoices
181 if (GETPOST('selectinvoices') && !empty($listofchoices['selectinvoices']['perms'])) {
182 if (!empty($sql)) {
183 $sql .= " UNION ALL";
184 }
185 $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,";
186 $sql .= " t.localtax1, t.localtax2, t.revenuestamp,";
187 $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";
188 $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";
189 $sql .= " WHERE datef between ".$wheretail;
190 $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
191 $sql .= " AND t.fk_statut <> ".Facture::STATUS_DRAFT;
192 if (!empty($projectid)) {
193 $sql .= " AND fk_projet = ".((int) $projectid);
194 }
195 }
196 // Vendor invoices
197 if (GETPOST('selectsupplierinvoices') && !empty($listofchoices['selectsupplierinvoices']['perms'])) {
198 if (!empty($sql)) {
199 $sql .= " UNION ALL";
200 }
201 $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,";
202 $sql .= " t.localtax1, t.localtax2, 0 as revenuestamp,";
203 $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";
204 $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";
205 $sql .= " WHERE datef between ".$wheretail;
206 $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
207 $sql .= " AND t.fk_statut <> ".FactureFournisseur::STATUS_DRAFT;
208 if (!empty($projectid)) {
209 $sql .= " AND fk_projet = ".((int) $projectid);
210 }
211 }
212 // Expense reports
213 if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms'])) {
214 if (!empty($sql)) {
215 $sql .= " UNION ALL";
216 }
217 // if project filter is used on an expense report,
218 // show only total_ht/total_tva/total_ttc of the line considered by the project
219 if (!empty($projectid)) {
220 $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,";
221 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
222 $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";
223 $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport as t";
224 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "expensereport_det as td ON t.rowid = td.fk_expensereport";
225 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = t.fk_user_author";
226 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as c ON c.rowid = u.fk_country";
227 $sql .= " WHERE date_fin between " . $wheretail;
228 $sql .= " AND t.entity IN (" . $db->sanitize($entity == 1 ? '0,1' : $entity) . ')';
229 $sql .= " AND t.fk_statut <> " . ExpenseReport::STATUS_DRAFT;
230 $sql .= " AND fk_projet = ".((int) $projectid);
231 } else {
232 $sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paid, t.total_ht, t.total_ttc, t.total_tva as total_vat,";
233 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
234 $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";
235 $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";
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 }
240 }
241 // Donations
242 if (GETPOST('selectdonations') && !empty($listofchoices['selectdonations']['perms'])) {
243 if (!empty($sql)) {
244 $sql .= " UNION ALL";
245 }
246 $sql .= " SELECT t.rowid as id, t.entity, t.ref, paid, amount as total_ht, amount as total_ttc, 0 as total_vat,";
247 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
248 $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";
249 $sql .= " FROM ".MAIN_DB_PREFIX."don as t LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = t.fk_country";
250 $sql .= " WHERE datedon between ".$wheretail;
251 $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
252 $sql .= " AND t.fk_statut <> ".Don::STATUS_DRAFT;
253 if (!empty($projectid)) {
254 $sql .= " AND fk_projet = ".((int) $projectid);
255 }
256 }
257 // Payments of salaries
258 if (GETPOST('selectpaymentsofsalaries') && !empty($listofchoices['selectpaymentsofsalaries']['perms'])) {
259 if (!empty($sql)) {
260 $sql .= " UNION ALL";
261 }
262 $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,";
263 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
264 $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";
265 $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";
266 $sql .= " WHERE datep between ".$wheretail;
267 $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
268 //$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT;
269 if (!empty($projectid)) {
270 $sql .= " AND fk_projet = ".((int) $projectid);
271 }
272 }
273 // Social contributions
274 if (GETPOST('selectsocialcontributions') && !empty($listofchoices['selectsocialcontributions']['perms'])) {
275 if (!empty($sql)) {
276 $sql .= " UNION ALL";
277 }
278 $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,";
279 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
280 $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";
281 $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as t";
282 $sql .= " WHERE t.date_ech between ".$wheretail;
283 $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
284 //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_UNPAID;
285 if (!empty($projectid)) {
286 $sql .= " AND fk_projet = ".((int) $projectid);
287 }
288 }
289 // Various payments
290 if (GETPOST('selectvariouspayment') && !empty($listofchoices['selectvariouspayment']['perms'])) {
291 if (!empty($sql)) {
292 $sql .= " UNION ALL";
293 }
294 $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,";
295 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
296 $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";
297 $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as t";
298 $sql .= " WHERE datep between ".$wheretail;
299 $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
300 if (!empty($projectid)) {
301 $sql .= " AND fk_projet = ".((int) $projectid);
302 }
303 }
304 // Loan payments
305 if (GETPOST('selectloanspayment') && !empty($listofchoices['selectloanspayment']['perms']) && empty($projectid)) {
306 if (!empty($sql)) {
307 $sql .= " UNION ALL";
308 }
309 $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,";
310 $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
311 $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";
312 $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as t LEFT JOIN ".MAIN_DB_PREFIX."loan as l ON l.rowid = t.fk_loan";
313 $sql .= " WHERE datep between ".$wheretail;
314 $sql .= " AND l.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
315 }
316
317 if ($sql) {
318 $sql .= $db->order($sortfield, $sortorder);
319 //print $sql;
320
321 $resd = $db->query($sql);
322 $files = array();
323 $link = '';
324
325 if ($resd) {
326 $numd = $db->num_rows($resd);
327
328 $tmpinvoice = new Facture($db);
329 $tmpinvoicesupplier = new FactureFournisseur($db);
330 $tmpdonation = new Don($db);
331
332 $upload_dir = '';
333 $i = 0;
334 while ($i < $numd) {
335 $objd = $db->fetch_object($resd);
336
337 switch ($objd->item) {
338 case "Invoice":
339 $subdir = '';
340 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
341 $upload_dir = $conf->facture->dir_output.'/'.$subdir;
342 $link = "document.php?modulepart=facture&file=".str_replace('/', '%2F', $subdir).'%2F';
343 $modulepart = "facture";
344 break;
345 case "SupplierInvoice":
346 $tmpinvoicesupplier->fetch($objd->id);
347 $subdir = get_exdir($tmpinvoicesupplier->id, 2, 0, 1, $tmpinvoicesupplier, 'invoice_supplier'); // TODO Use first file
348 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
349 $upload_dir = $conf->fournisseur->facture->dir_output.'/'.$subdir;
350 $link = "document.php?modulepart=facture_fournisseur&file=".str_replace('/', '%2F', $subdir).'%2F';
351 $modulepart = "facture_fournisseur";
352 break;
353 case "ExpenseReport":
354 $subdir = '';
355 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
356 $upload_dir = $conf->expensereport->dir_output.'/'.$subdir;
357 $link = "document.php?modulepart=expensereport&file=".str_replace('/', '%2F', $subdir).'%2F';
358 $modulepart = "expensereport";
359 break;
360 case "SalaryPayment":
361 $subdir = '';
362 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
363 $upload_dir = $conf->salaries->dir_output.'/'.$subdir;
364 $link = "document.php?modulepart=salaries&file=".str_replace('/', '%2F', $subdir).'%2F';
365 $modulepart = "salaries";
366 break;
367 case "Donation":
368 $tmpdonation->fetch($objp->id);
369 $subdir = get_exdir(0, 0, 0, 0, $tmpdonation, 'donation');
370 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
371 $upload_dir = $conf->don->dir_output.'/'.$subdir;
372 $link = "document.php?modulepart=don&file=".str_replace('/', '%2F', $subdir).'%2F';
373 $modulepart = "don";
374 break;
375 case "SocialContributions":
376 $subdir = '';
377 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
378 $upload_dir = $conf->tax->dir_output.'/'.$subdir;
379 $link = "document.php?modulepart=tax&file=".str_replace('/', '%2F', $subdir).'%2F';
380 $modulepart = "tax";
381 break;
382 case "VariousPayment":
383 $subdir = '';
384 $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
385 $upload_dir = $conf->bank->dir_output.'/'.$subdir;
386 $link = "document.php?modulepart=banque&file=".str_replace('/', '%2F', $subdir).'%2F';
387 $modulepart = "banque";
388 break;
389 case "LoanPayment":
390 // Loan payment has no linked file
391 $subdir = '';
392 $upload_dir = $conf->loan->dir_output.'/'.$subdir;
393 $link = "";
394 $modulepart = "";
395 break;
396 default:
397 $subdir = '';
398 $upload_dir = '';
399 $link = '';
400 break;
401 }
402
403 if (!empty($upload_dir)) {
404 $result = true;
405
406 $files = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', '', SORT_ASC, 1);
407 //var_dump($upload_dir);
408 //var_dump($files);
409 if (count($files) < 1) {
410 $nofile = array();
411 $nofile['id'] = $objd->id;
412 $nofile['entity'] = $objd->entity;
413 $nofile['date'] = $db->jdate($objd->date);
414 $nofile['date_due'] = $db->jdate($objd->date_due);
415 $nofile['paid'] = $objd->paid;
416 $nofile['amount_ht'] = $objd->total_ht;
417 $nofile['amount_ttc'] = $objd->total_ttc;
418 $nofile['amount_vat'] = $objd->total_vat;
419 $nofile['amount_localtax1'] = $objd->localtax1;
420 $nofile['amount_localtax2'] = $objd->localtax2;
421 $nofile['amount_revenuestamp'] = $objd->revenuestamp;
422 $nofile['ref'] = ($objd->ref ? $objd->ref : $objd->id);
423 $nofile['fk'] = $objd->fk_soc;
424 $nofile['item'] = $objd->item;
425 $nofile['thirdparty_name'] = $objd->thirdparty_name;
426 $nofile['thirdparty_code'] = $objd->thirdparty_code;
427 $nofile['country_code'] = $objd->country_code;
428 $nofile['vatnum'] = $objd->vatnum;
429 $nofile['sens'] = $objd->sens;
430 $nofile['currency'] = $objd->currency;
431 $nofile['link'] = '';
432 $nofile['name'] = '';
433
434
435 $filesarray[$nofile['item'].'_'.$nofile['id']] = $nofile;
436 } else {
437 foreach ($files as $key => $file) {
438 $file['id'] = $objd->id;
439 $file['entity'] = $objd->entity;
440 $file['date'] = $db->jdate($objd->date);
441 $file['date_due'] = $db->jdate($objd->date_due);
442 $file['paid'] = $objd->paid;
443 $file['amount_ht'] = $objd->total_ht;
444 $file['amount_ttc'] = $objd->total_ttc;
445 $file['amount_vat'] = $objd->total_vat;
446 $file['amount_localtax1'] = $objd->localtax1;
447 $file['amount_localtax2'] = $objd->localtax2;
448 $file['amount_revenuestamp'] = $objd->revenuestamp;
449 $file['ref'] = ($objd->ref ? $objd->ref : $objd->id);
450 $file['fk'] = $objd->fk_soc;
451 $file['item'] = $objd->item;
452 $file['thirdparty_name'] = $objd->thirdparty_name;
453 $file['thirdparty_code'] = $objd->thirdparty_code;
454 $file['country_code'] = $objd->country_code;
455 $file['vatnum'] = $objd->vatnum;
456 $file['sens'] = $objd->sens;
457 $file['currency'] = $objd->currency;
458
459 // Save record into array (only the first time it is found)
460 if (empty($filesarray[$file['item'].'_'.$file['id']])) {
461 $filesarray[$file['item'].'_'.$file['id']] = $file;
462 }
463
464 // Add or concat file
465 if (empty($filesarray[$file['item'].'_'.$file['id']]['files'])) {
466 $filesarray[$file['item'].'_'.$file['id']]['files'] = array();
467 }
468 $filesarray[$file['item'].'_'.$file['id']]['files'][] = array(
469 'link' => $link.urlencode($file['name']),
470 'name' => $file['name'],
471 'ref' => $file['ref'],
472 'fullname' => $file['fullname'],
473 'relpath' => '/'.$file['name'],
474 'relpathnamelang' => $langs->trans($file['item']).'/'.$file['name'],
475 'modulepart' => $modulepart,
476 'subdir' => $subdir,
477 'currency' => $file['currency']
478 );
479 //var_dump($file['item'].'_'.$file['id']);
480 //var_dump($filesarray[$file['item'].'_'.$file['id']]['files']);
481 }
482 }
483 }
484
485 $i++;
486 }
487 } else {
488 dol_print_error($db);
489 }
490
491 $db->free($resd);
492 } else {
493 setEventMessages($langs->trans("ErrorSelectAtLeastOne"), null, 'errors');
494 $error++;
495 }
496 }
497}
498
499// zip creation
500
501$dirfortmpfile = (!empty($conf->accounting->dir_temp) ? $conf->accounting->dir_temp : $conf->comptabilite->dir_temp);
502if (empty($dirfortmpfile)) {
503 setEventMessages($langs->trans("ErrorNoAccountingModuleEnabled"), null, 'errors');
504 $error++;
505}
506
507if ($result && $action == "dl" && !$error) { // Test on permission not required here. Test is done per object type later.
508 if (!extension_loaded('zip')) {
509 setEventMessages('PHPZIPExtentionNotLoaded', null, 'errors');
510 } else {
511 dol_mkdir($dirfortmpfile);
512
513 $log = $langs->transnoentitiesnoconv("Type");
514 if (isModEnabled('multicompany') && is_object($mc)) {
515 $log .= ','.$langs->transnoentitiesnoconv("Entity");
516 }
517 $log .= ','.$langs->transnoentitiesnoconv("Date");
518 $log .= ','.$langs->transnoentitiesnoconv("DateDue");
519 $log .= ','.$langs->transnoentitiesnoconv("Ref");
520 $log .= ','.$langs->transnoentitiesnoconv("TotalHT");
521 $log .= ','.$langs->transnoentitiesnoconv("TotalTTC");
522 $log .= ','.$langs->transnoentitiesnoconv("TotalVAT");
523 $log .= ','.$langs->transcountrynoentities("TotalLT1", $mysoc->country_code);
524 $log .= ','.$langs->transcountrynoentities("TotalLT2", $mysoc->country_code);
525 $log .= ','.$langs->transnoentitiesnoconv("RevenueStamp");
526 $log .= ','.$langs->transnoentitiesnoconv("Paid");
527 $log .= ','.$langs->transnoentitiesnoconv("Document");
528 $log .= ','.$langs->transnoentitiesnoconv("ItemID");
529 $log .= ','.$langs->transnoentitiesnoconv("ThirdParty");
530 $log .= ','.$langs->transnoentitiesnoconv("Code");
531 $log .= ','.$langs->transnoentitiesnoconv("Country");
532 $log .= ','.$langs->transnoentitiesnoconv("VATIntra");
533 $log .= ','.$langs->transnoentitiesnoconv("Sens")."\n";
534 $zipname = $dirfortmpfile.'/'.dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel');
535 if (!empty($projectid)) {
536 $project = new Project($db);
537 $project->fetch($projectid);
538 if ($project->ref) {
539 $zipname .= '_'.$project->ref;
540 }
541 }
542 $zipname .= '_export.zip';
543
544 dol_delete_file($zipname);
545
546 $zip = new ZipArchive();
547 $res = $zip->open($zipname, ZipArchive::OVERWRITE | ZipArchive::CREATE);
548 if ($res) {
549 foreach ($filesarray as $key => $file) {
550 if (!empty($file['files'])) {
551 foreach ($file['files'] as $filecursor) {
552 if (file_exists($filecursor["fullname"])) {
553 $zip->addFile($filecursor["fullname"], $filecursor["relpathnamelang"]);
554 }
555 }
556 }
557
558 $log .= '"'.$langs->transnoentitiesnoconv($file['item']).'"';
559 if (isModEnabled('multicompany') && is_object($mc)) {
560 $log .= ',"'.(empty($arrayofentities[$file['entity']]) ? $file['entity'] : $arrayofentities[$file['entity']]).'"';
561 }
562 $log .= ','.dol_print_date($file['date'], 'dayrfc');
563 $log .= ','.dol_print_date($file['date_due'], 'dayrfc');
564 $log .= ',"'.$file['ref'].'"';
565 $log .= ','.$file['amount_ht'];
566 $log .= ','.$file['amount_ttc'];
567 $log .= ','.$file['amount_vat'];
568 $log .= ','.$file['amount_localtax1'];
569 $log .= ','.$file['amount_localtax2'];
570 $log .= ','.$file['amount_revenuestamp'];
571 $log .= ','.$file['paid'];
572 $log .= ',"'.$file["name"].'"';
573 $log .= ','.$file['fk'];
574 $log .= ',"'.$file['thirdparty_name'].'"';
575 $log .= ',"'.$file['thirdparty_code'].'"';
576 $log .= ',"'.$file['country_code'].'"';
577 $log .= ',"'.$file['vatnum'].'"';
578 $log .= ',"'.$file['sens'].'"';
579 $log .= "\n";
580 }
581 $zip->addFromString('transactions.csv', $log);
582 $zip->close();
583
584 // Then download the zipped file.
585 header('Content-Type: application/zip');
586 header('Content-disposition: attachment; filename='.basename($zipname));
587 header('Content-Length: '.filesize($zipname));
588 readfile($zipname);
589
590 dol_delete_file($zipname);
591
592 exit();
593 } else {
594 setEventMessages($langs->trans("FailedToOpenFile", $zipname), null, 'errors');
595 }
596 }
597}
598
599
600/*
601 * View
602 */
603
604$form = new Form($db);
605$formfile = new FormFile($db);
606$userstatic = new User($db);
607$invoice = new Facture($db);
608$supplier_invoice = new FactureFournisseur($db);
609$expensereport = new ExpenseReport($db);
610$don = new Don($db);
611$salary_payment = new PaymentSalary($db);
612$charge_sociales = new ChargeSociales($db);
613$various_payment = new PaymentVarious($db);
614$payment_loan = new PaymentLoan($db);
615
616$title = $langs->trans("ComptaFiles").' - '.$langs->trans("List");
617$help_url = '';
618
619llxHeader('', $title, $help_url);
620
621$h = 0;
622$head = array();
623$head[$h][0] = $_SERVER["PHP_SELF"];
624$head[$h][1] = $langs->trans("AccountantFiles");
625$head[$h][2] = 'AccountancyFiles';
626
627print dol_get_fiche_head($head, 'AccountancyFiles');
628
629
630print '<form name="searchfiles" action="?action=searchfiles" method="POST">'."\n";
631print '<input type="hidden" name="token" value="'.newToken().'">';
632
633print '<span class="opacitymedium">'.$langs->trans("ExportAccountingSourceDocHelp");
634if (isModEnabled('accounting')) {
635 print ' '.$langs->trans("ExportAccountingSourceDocHelp2", $langs->transnoentitiesnoconv("Accounting"), $langs->transnoentitiesnoconv("Journals"));
636}
637print '</span><br>';
638print '<br>';
639
640print $langs->trans("ReportPeriod").': ';
641print $form->selectDate($date_start, 'date_start', 0, 0, 0, "", 1, 1, 0, '', '', '', '', 1, '', '', 'tzuserrel');
642print ' - ';
643print $form->selectDate($date_stop, 'date_stop', 0, 0, 0, "", 1, 1, 0, '', '', '', '', 1, '', '', 'tzuserrel');
644print "\n";
645
646// Export is for current company only
647$socid = 0;
648if (isModEnabled('multicompany') && is_object($mc)) {
649 $mc->getInfo($conf->entity);
650 print ' &nbsp; <span class="marginleftonly marginrightonly'.(!getDolGlobalString('MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES') ? ' opacitymedium' : '').'">'.$langs->trans("Entity").' : ';
651 if (getDolGlobalString('MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES')) {
652 $socid = $mc->id;
653 print $mc->select_entities(GETPOSTISSET('search_entity') ? GETPOSTINT('search_entity') : $mc->id, 'search_entity', '', false, false, false, false, true);
654 } else {
655 print $mc->label;
656 }
657 print "</span>\n";
658}
659
660print '<br>';
661
662// Project filter
663if (isModEnabled('project')) {
664 $formproject = new FormProjets($db);
665 $langs->load('projects');
666 print '<span class="marginrightonly">'.$langs->trans('Project').":</span>";
667 print img_picto('', 'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 1, 0, '');
668 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>';
669 print '<br>';
670}
671
672$i = 0;
673foreach ($listofchoices as $choice => $val) {
674 if (empty($val['enabled'])) {
675 continue; // list not qualified
676 }
677 $disabled = '';
678 if (empty($val['perms'])) {
679 $disabled = ' disabled';
680 }
681 $checked = (((!GETPOSTISSET('search') && $action != 'searchfiles') || GETPOST($choice)) ? ' checked="checked"' : '');
682 print '<div class="inline-block marginrightonlylarge paddingright margintoponly"><input type="checkbox" id="'.$choice.'" name="'.$choice.'" value="1"'.$checked.$disabled.'><label for="'.$choice.'"> ';
683 print img_picto($langs->trans($val['label']), $val['picto'], 'class=""').' '.$langs->trans($val['label']);
684 print '</label></div>';
685 $i++;
686}
687
688print '<input type="submit" class="button small" name="search" value="'.$langs->trans("Search").'">';
689
690print '</form>'."\n";
691
692print dol_get_fiche_end();
693
694$param = '';
695if (!empty($date_start) && !empty($date_stop)) {
696 $param .= '&date_startday='.GETPOSTINT('date_startday');
697 $param .= '&date_startmonth='.GETPOSTINT('date_startmonth');
698 $param .= '&date_startyear='.GETPOSTINT('date_startyear');
699 $param .= '&date_stopday='.GETPOSTINT('date_stopday');
700 $param .= '&date_stopmonth='.GETPOSTINT('date_stopmonth');
701 $param .= '&date_stopyear='.GETPOSTINT('date_stopyear');
702 foreach ($listofchoices as $choice => $val) {
703 if (GETPOSTINT($choice)) {
704 $param .= '&'.$choice.'=1';
705 }
706 }
707
708 $TData = dol_sort_array($filesarray, $sortfield, $sortorder);
709 '@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';
710
711
712 $filename = dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel').'_export.zip';
713
714 echo dol_print_date($date_start, 'day', 'tzuserrel')." - ".dol_print_date($date_stop, 'day', 'tzuserrel');
715
716 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.'"';
717 if (empty($TData)) {
718 print " disabled";
719 }
720 print '>'."\n";
721 print $langs->trans("Download");
722 print '</a><br>';
723
724 $param .= '&action=searchfiles';
725
726 /*
727 print '<input type="hidden" name="token" value="'.currentToken().'">';
728 print '<input type="hidden" name="date_startday" value="'.GETPOST('date_startday', 'int').'" />';
729 print '<input type="hidden" name="date_startmonth" value="'.GETPOST('date_startmonth', 'int').'" />';
730 print '<input type="hidden" name="date_startyear" value="'.GETPOST('date_startyear', 'int').'" />';
731 print '<input type="hidden" name="date_stopday" value="'.GETPOST('date_stopday', 'int').'" />';
732 print '<input type="hidden" name="date_stopmonth" value="'.GETPOST('date_stopmonth', 'int').'" />';
733 print '<input type="hidden" name="date_stopyear" value="'.GETPOST('date_stopyear', 'int').'" />';
734 foreach ($listofchoices as $choice => $val) {
735 print '<input type="hidden" name="'.$choice.'" value="'.GETPOST($choice).'">';
736 }
737
738 print '<input class="butAction butDownload small marginleftonly" type="submit" value="'.$langs->trans("Download").'"';
739 if (empty($TData)) {
740 print " disabled";
741 }
742 print '/>';
743 print '</form>'."\n";
744 */
745
746 print '<br>';
747
748 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
749 print '<table class="noborder centpercent">';
750 print '<tr class="liste_titre">';
751 print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "item", "", $param, '', $sortfield, $sortorder, 'nowrap ');
752 print_liste_field_titre($arrayfields['date']['label'], $_SERVER["PHP_SELF"], "date", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
753 print_liste_field_titre($arrayfields['date_due']['label'], $_SERVER["PHP_SELF"], "date_due", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
754 print_liste_field_titre($arrayfields['ref']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'nowraponall ');
755 print '<th>'.$langs->trans("Document").'</th>';
756 print '<th>'.$langs->trans("Paid").'</th>';
757 print '<th class="right">'.$langs->trans("TotalHT").(isModEnabled('multicurrency') ? ' ('.$langs->getCurrencySymbol($conf->currency).')' : '').'</th>';
758 print '<th class="right">'.$langs->trans("TotalTTC").(isModEnabled('multicurrency') ? ' ('.$langs->getCurrencySymbol($conf->currency).')' : '').'</th>';
759 print '<th class="right">'.$langs->trans("TotalVAT").(isModEnabled('multicurrency') ? ' ('.$langs->getCurrencySymbol($conf->currency).')' : '').'</th>';
760
761 print '<th>'.$langs->trans("ThirdParty").'</th>';
762 print '<th class="center">'.$langs->trans("Code").'</th>';
763 print '<th class="center">'.$langs->trans("Country").'</th>';
764 print '<th class="center">'.$langs->trans("VATIntra").'</th>';
765 if (isModEnabled('multicurrency')) {
766 print '<th class="center">'.$langs->trans("Currency").'</th>';
767 }
768 print '</tr>';
769
770 if (empty($TData)) {
771 print '<tr class="oddeven"><td colspan="13"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td>';
772 if (isModEnabled('multicurrency')) {
773 print '<td></td>';
774 }
775 print '</tr>';
776 } else {
777 // Sort array by date ASC to calculate balance
778
779 $totalET_debit = 0;
780 $totalIT_debit = 0;
781 $totalVAT_debit = 0;
782 $totalET_credit = 0;
783 $totalIT_credit = 0;
784 $totalVAT_credit = 0;
785
786 // Display array
787 foreach ($TData as $data) {
788 $html_class = '';
789 //if (!empty($data['fk_facture'])) $html_class = 'facid-'.$data['fk_facture'];
790 //elseif (!empty($data['fk_paiement'])) $html_class = 'payid-'.$data['fk_paiement'];
791 print '<tr class="oddeven '.$html_class.'">';
792
793 // Type
794 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($langs->trans($data['item'])).'">'.$langs->trans($data['item']).'</td>';
795
796 // Date
797 print '<td class="center">';
798 print dol_print_date($data['date'], 'day');
799 print "</td>\n";
800
801 // Date due
802 print '<td class="center">';
803 print dol_print_date($data['date_due'], 'day');
804 print "</td>\n";
805
806 // Ref
807 print '<td class="nowraponall tdoverflowmax150">';
808
809 if ($data['item'] == 'Invoice') {
810 $invoice->id = $data['id'];
811 $invoice->ref = $data['ref'];
812 $invoice->total_ht = $data['amount_ht'];
813 $invoice->total_ttc = $data['amount_ttc'];
814 $invoice->total_tva = $data['amount_vat'];
815 $invoice->total_localtax1 = $data['amount_localtax1'];
816 $invoice->total_localtax2 = $data['amount_localtax2'];
817 $invoice->revenuestamp = $data['amount_revenuestamp'];
818 $invoice->multicurrency_code = $data['currency'];
819 print $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0);
820 } elseif ($data['item'] == 'SupplierInvoice') {
821 $supplier_invoice->id = $data['id'];
822 $supplier_invoice->ref = $data['ref'];
823 $supplier_invoice->total_ht = $data['amount_ht'];
824 $supplier_invoice->total_ttc = $data['amount_ttc'];
825 $supplier_invoice->total_tva = $data['amount_vat'];
826 $supplier_invoice->total_localtax1 = $data['amount_localtax1'];
827 $supplier_invoice->total_localtax2 = $data['amount_localtax2'];
828 $supplier_invoice->revenuestamp = $data['amount_revenuestamp'];
829 $supplier_invoice->multicurrency_code = $data['currency'];
830 print $supplier_invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0);
831 } elseif ($data['item'] == 'ExpenseReport') {
832 $expensereport->id = $data['id'];
833 $expensereport->ref = $data['ref'];
834 print $expensereport->getNomUrl(1, 0, 0, 0, 0, 0);
835 } elseif ($data['item'] == 'SalaryPayment') {
836 $salary_payment->id = $data['id'];
837 $salary_payment->ref = $data['ref'];
838 print $salary_payment->getNomUrl(1);
839 } elseif ($data['item'] == 'Donation') {
840 $don->id = $data['id'];
841 $don->ref = $data['ref'];
842 print $don->getNomUrl(1, 0, '', 0);
843 } elseif ($data['item'] == 'SocialContributions') {
844 $charge_sociales->id = $data['id'];
845 $charge_sociales->ref = $data['ref'];
846 print $charge_sociales->getNomUrl(1, 0, 0, 0, 0);
847 } elseif ($data['item'] == 'VariousPayment') {
848 $various_payment->id = $data['id'];
849 $various_payment->ref = $data['ref'];
850 print $various_payment->getNomUrl(1, '', 0, 0);
851 } elseif ($data['item'] == 'LoanPayment') {
852 $payment_loan->id = $data['id'];
853 $payment_loan->ref = $data['ref'];
854 print $payment_loan->getNomUrl(1, 0, 0, '', 0);
855 } else {
856 print $data['ref'];
857 }
858 print '</td>';
859
860 // File link
861 print '<td class="tdoverflowmax150">';
862 if (!empty($data['files'])) {
863 foreach ($data['files'] as $id => $filecursor) {
864 $tmppreview = $formfile->showPreview($filecursor, $filecursor['modulepart'], $filecursor['subdir'].'/'.$filecursor['name'], 0);
865 if ($tmppreview) {
866 print $tmppreview;
867 }
868 $filename = ($filecursor['name'] ? $filecursor['name'] : $filecursor['ref']);
869 print '<a href='.DOL_URL_ROOT.'/'.$filecursor['link'].' target="_blank" rel="noopener noreferrer" title="'.dol_escape_htmltag($filename).'">';
870 if (empty($tmppreview)) {
871 print img_picto('', 'generic', '', 0, 0, 0, '', 'pictonopreview pictofixedwidth paddingright');
872 }
873 print $filename;
874 print '</a><br>';
875 }
876 }
877 print "</td>\n";
878
879 // Paid
880 print '<td class="center">'.($data['paid'] ? yn($data['paid']) : '').'</td>';
881
882 // Total WOT
883 print '<td class="right"><span class="amount">'.price(price2num($data['sens'] ? $data['amount_ht'] : -$data['amount_ht'], 'MT'))."</span></td>\n";
884 // Total INCT
885 print '<td class="right"><span class="amount">';
886 $tooltip = $langs->trans("TotalVAT").' : '.price(price2num($data['sens'] ? $data['amount_vat'] : -$data['amount_vat'], 'MT'));
887 if (!empty($data['amount_localtax1'])) {
888 $tooltip .= '<br>'.$langs->transcountrynoentities("TotalLT1", $mysoc->country_code).' : '.price(price2num($data['sens'] ? $data['amount_localtax1'] : -$data['amount_localtax1'], 'MT'));
889 }
890 if (!empty($data['amount_localtax2'])) {
891 $tooltip .= '<br>'.$langs->transcountrynoentities("TotalLT2", $mysoc->country_code).' : '.price(price2num($data['sens'] ? $data['amount_localtax2'] : -$data['amount_localtax2'], 'MT'));
892 }
893 if (!empty($data['amount_revenuestamp'])) {
894 $tooltip .= '<br>'.$langs->trans("RevenueStamp").' : '.price(price2num($data['sens'] ? $data['amount_revenuestamp'] : -$data['amount_revenuestamp'], 'MT'));
895 }
896 print '<span class="classfortooltip" title="'.dol_escape_htmltag($tooltip).'">'.price(price2num($data['sens'] ? $data['amount_ttc'] : -$data['amount_ttc'], 'MT')).'</span>';
897 print "</span></td>\n";
898 // Total VAT
899 print '<td class="right"><span class="amount">'.price(price2num($data['sens'] ? $data['amount_vat'] : -$data['amount_vat'], 'MT'))."</span></td>\n";
900
901 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($data['thirdparty_name']).'">'.dol_escape_htmltag($data['thirdparty_name'])."</td>\n";
902
903 print '<td class="center">'.$data['thirdparty_code']."</td>\n";
904
905 print '<td class="center">'.$data['country_code']."</td>\n";
906
907 // VAT number
908 print '<td class="tdoverflowmax150 right" title="'.dol_escape_htmltag($data['vatnum']).'">'.dol_escape_htmltag($data['vatnum'])."</td>\n";
909
910 if ($data['sens']) {
911 $totalET_credit += $data['amount_ht'];
912 $totalIT_credit += $data['amount_ttc'];
913 $totalVAT_credit += $data['amount_vat'];
914 } else {
915 $totalET_debit -= $data['amount_ht'];
916 $totalIT_debit -= $data['amount_ttc'];
917 $totalVAT_debit -= $data['amount_vat'];
918 }
919
920 if (isModEnabled('multicurrency')) {
921 print '<td class="center">'.$data['currency']."</td>\n";
922 }
923
924 print "</tr>\n";
925 }
926
927 // Total credits
928 print '<tr class="liste_total">';
929 print '<td colspan="6" class="right">'.$langs->trans('Total').' '.$langs->trans('Income').'</td>';
930 print '<td class="right">'.price(price2num($totalET_credit, 'MT')).'</td>';
931 print '<td class="right">'.price(price2num($totalIT_credit, 'MT')).'</td>';
932 print '<td class="right">'.price(price2num($totalVAT_credit, 'MT')).'</td>';
933 print '<td colspan="4"></td>';
934 if (isModEnabled('multicurrency')) {
935 print '<td></td>';
936 }
937 print "</tr>\n";
938 // Total debits
939 print '<tr class="liste_total">';
940 print '<td colspan="6" class="right">'.$langs->trans('Total').' '.$langs->trans('Outcome').'</td>';
941 print '<td class="right">'.price(price2num($totalET_debit, 'MT')).'</td>';
942 print '<td class="right">'.price(price2num($totalIT_debit, 'MT')).'</td>';
943 print '<td class="right">'.price(price2num($totalVAT_debit, 'MT')).'</td>';
944 print '<td colspan="4"></td>';
945 if (isModEnabled('multicurrency')) {
946 print '<td></td>';
947 }
948 print "</tr>\n";
949 // Balance
950 print '<tr class="liste_total">';
951 print '<td colspan="6" class="right">'.$langs->trans('Total').'</td>';
952 print '<td class="right">'.price(price2num($totalET_credit + $totalET_debit, 'MT')).'</td>';
953 print '<td class="right">'.price(price2num($totalIT_credit + $totalIT_debit, 'MT')).'</td>';
954 print '<td class="right">'.price(price2num($totalVAT_credit + $totalVAT_debit, 'MT')).'</td>';
955 print '<td colspan="4"></td>';
956 if (isModEnabled('multicurrency')) {
957 print '<td></td>';
958 }
959 print "</tr>\n";
960 }
961
962 print "</table>";
963 print '</div>';
964}
965
966
967llxFooter();
968$db->close();
$id
Definition account.php:39
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:70
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...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.