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