dolibarr 25.0.0-alpha
supplier_turnover_by_thirdparty.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2020 Maxime Kohlhaas <maxime@atm-consulting.fr>
3 * Copyright (C) 2023 Ferran Marcet <fmarcet@2byte.es>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
45
46// Load translation files required by the page
47$langs->loadLangs(array('companies', 'categories', 'bills', 'compta'));
48
49// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
50$modecompta = getDolGlobalString('ACCOUNTING_MODE');
51if (GETPOST("modecompta")) {
52 $modecompta = GETPOST("modecompta");
53}
54
55// Sort Order
56$sortorder = GETPOST("sortorder", 'aZ09comma');
57$sortfield = GETPOST("sortfield", 'aZ09comma');
58if (!$sortorder) {
59 $sortorder = "asc";
60}
61if (!$sortfield) {
62 $sortfield = "nom";
63}
64
65
66$socid = GETPOSTINT('socid');
67
68// Category
69$selected_cat = GETPOSTINT('search_categ');
70if ($selected_cat == -1) {
71 $selected_cat = 0;
72}
73$subcat = false;
74if (GETPOST('subcat', 'alpha') === 'yes') {
75 $subcat = true;
76}
77
78// Security check
79if ($user->socid > 0) {
80 $socid = $user->socid;
81}
82if (isModEnabled('comptabilite')) {
83 $result = restrictedArea($user, 'compta', '', '', 'resultat');
84}
85if (isModEnabled('accounting')) {
86 $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
87}
88
89// Hook
90$hookmanager->initHooks(array('supplierturnoverbythirdpartylist'));
91
92
93// Search Parameters
94$search_societe = GETPOST("search_societe", 'alpha');
95$search_zip = GETPOST("search_zip", 'alpha');
96$search_town = GETPOST("search_town", 'alpha');
97$search_country = GETPOST("search_country", 'aZ09');
98
99$date_startyear = GETPOST("date_startyear", 'alpha');
100$date_startmonth = GETPOST("date_startmonth", 'alpha');
101$date_startday = GETPOST("date_startday", 'alpha');
102$date_endyear = GETPOST("date_endyear", 'alpha');
103$date_endmonth = GETPOST("date_endmonth", 'alpha');
104$date_endday = GETPOST("date_endday", 'alpha');
105
106$nbofyear = 1;
107
108// Date range
109$year = GETPOSTINT("year");
110$month = GETPOSTINT("month");
111if (empty($year)) {
112 $year_current = (int) dol_print_date(dol_now(), "%Y");
113 $month_current = (int) dol_print_date(dol_now(), "%m");
114 $year_start = $year_current - ($nbofyear - 1);
115} else {
116 $year_current = $year;
117 $month_current = (int) dol_print_date(dol_now(), "%m");
118 $year_start = $year - $nbofyear + (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
119}
120$date_start = dol_mktime(0, 0, 0, (int) $date_startmonth, (int) $date_startday, (int) $date_startyear, 'tzserver'); // We use timezone of server so report is same from everywhere
121$date_end = dol_mktime(23, 59, 59, (int) $date_endmonth, (int) $date_endday, (int) $date_endyear, 'tzserver'); // We use timezone of server so report is same from everywhere
122
123// We define date_start and date_end
124if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
125 $q = GETPOSTINT("q");
126 if (empty($q)) {
127 // We define date_start and date_end
128 $year_end = $year_start + $nbofyear - (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
129 $month_start = GETPOSTISSET("month") ? GETPOSTINT("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
130 if (!GETPOST("month")) { // If month not forced
131 if (!$year && $month_start > $month_current) {
132 $year_start--;
133 $year_end--;
134 }
135 $month_end = $month_start - 1;
136 if ($month_end < 1) {
137 $month_end = 12;
138 }
139 } else {
140 $month_end = $month_start;
141 }
142 $date_start = dol_get_first_day($year_start, $month_start, false);
143 $date_end = dol_get_last_day($year_end, $month_end, false);
144 }
145 if ($q == 1) {
146 $date_start = dol_get_first_day($year_start, 1, false);
147 $date_end = dol_get_last_day($year_start, 3, false);
148 }
149 if ($q == 2) {
150 $date_start = dol_get_first_day($year_start, 4, false);
151 $date_end = dol_get_last_day($year_start, 6, false);
152 }
153 if ($q == 3) {
154 $date_start = dol_get_first_day($year_start, 7, false);
155 $date_end = dol_get_last_day($year_start, 9, false);
156 }
157 if ($q == 4) {
158 $date_start = dol_get_first_day($year_start, 10, false);
159 $date_end = dol_get_last_day($year_start, 12, false);
160 }
161}
162
163// $date_start and $date_end are defined. We force $year_start and $nbofyear
164$tmps = dol_getdate($date_start);
165$year_start = $tmps['year'];
166$tmpe = dol_getdate($date_end);
167$year_end = $tmpe['year'];
168$nbofyear = ($year_end - $year_start) + 1;
169
170$commonparams = array();
171$commonparams['modecompta'] = $modecompta;
172$commonparams['sortorder'] = $sortorder;
173$commonparams['sortfield'] = $sortfield;
174
175$headerparams = array();
176if (!empty($date_startyear)) {
177 $headerparams['date_startyear'] = $date_startyear;
178}
179if (!empty($date_startmonth)) {
180 $headerparams['date_startmonth'] = $date_startmonth;
181}
182if (!empty($date_startday)) {
183 $headerparams['date_startday'] = $date_startday;
184}
185if (!empty($date_endyear)) {
186 $headerparams['date_endyear'] = $date_endyear;
187}
188if (!empty($date_endmonth)) {
189 $headerparams['date_endmonth'] = $date_endmonth;
190}
191if (!empty($date_endday)) {
192 $headerparams['date_endday'] = $date_endday;
193}
194
195$tableparams = array();
196$tableparams['search_categ'] = $selected_cat;
197$tableparams['search_societe'] = $search_societe;
198$tableparams['search_zip'] = $search_zip;
199$tableparams['search_town'] = $search_town;
200$tableparams['search_country'] = $search_country;
201$tableparams['subcat'] = $subcat ? 'yes' : '';
202
203// Adding common parameters
204$allparams = array_merge($commonparams, $headerparams, $tableparams);
205$headerparams = array_merge($commonparams, $headerparams);
206$tableparams = array_merge($commonparams, $tableparams);
207
208$paramslink = '';
209foreach ($allparams as $key => $value) {
210 $paramslink .= '&'.$key.'='.$value;
211}
212
213
214
215
216/*
217 * View
218 */
219
220llxHeader();
221
222$form = new Form($db);
223$thirdparty_static = new Societe($db);
224$formother = new FormOther($db);
225
226// TODO Report from bookkeeping not yet available, so we switch on report on business events
227if ($modecompta == "BOOKKEEPING") {
228 $modecompta = "CREANCES-DETTES";
229}
230if ($modecompta == "BOOKKEEPINGCOLLECTED") {
231 $modecompta = "RECETTES-DEPENSES";
232}
233
234
235$calcmode = '';
236$name = '';
237$namelink = '';
238$builddate = dol_now();
239$description = '';
240
241// Show report header
242if ($modecompta == "CREANCES-DETTES") {
243 $name = $langs->trans("PurchaseTurnover").', '.$langs->trans("ByThirdParties");
244 $calcmode = $langs->trans("CalcModeDebt");
245 //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
246 $description = $langs->trans("RulesPurchaseTurnoverDue");
247 $builddate = dol_now();
248} elseif ($modecompta == "RECETTES-DEPENSES") {
249 $name = $langs->trans("PurchaseTurnoverCollected").', '.$langs->trans("ByThirdParties");
250 $calcmode = $langs->trans("CalcModePayment");
251 //$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
252 $description = $langs->trans("RulesPurchaseTurnoverIn");
253
254 $builddate = dol_now();
255} elseif ($modecompta == "BOOKKEEPING") {
256 $name = $langs->trans("PurchaseTurnover").', '.$langs->trans("ByThirdParties");
257 $calcmode = $langs->trans("CalcModeBookkeeping");
258 $description = $langs->trans("RulesPurchaseTurnoverDue");
259 $builddate = dol_now();
260}
261
262$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
263$period .= ' - ';
264$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
265if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) {
266 $periodlink = '<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_start - 1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year_start + 1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
267} else {
268 $periodlink = '';
269}
270
271$exportlink = '';
272
273report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
274
275if (isModEnabled('accounting')) {
276 if ($modecompta != 'BOOKKEEPING') {
277 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
278 } else {
279 // Test if there is at least one line in bookkeeping
280 $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS');
281 $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
282 if (empty($pcgvercode)) {
283 $pcgvercode = $pcgverid;
284 }
285
286 $sql = "SELECT b.rowid ";
287 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,";
288 $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa";
289 $sql .= " WHERE b.entity = ".((int) $conf->entity); // In module double party accounting, we never share entities
290 $sql .= " AND b.numero_compte = aa.account_number";
291 $sql .= " AND aa.entity = ".((int) $conf->entity);
292 $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'";
293 $sql .= $db->plimit(1);
294
295 $resql = $db->query($sql);
296 $nb = $db->num_rows($resql);
297 if ($nb == 0) {
298 $langs->load("errors");
299 print info_admin($langs->trans("WarningNoDataTransferedInAccountancyYet"), 0, 0, '1');
300 }
301 }
302}
303
304// Show Array
305$catotal = 0;
306$catotal_ht = 0;
307$name = array();
308$amount = array();
309$amount_ht = array();
310$address_zip = array();
311$address_town = array();
312$address_pays = array();
313$sql = '';
314
315if ($modecompta == 'CREANCES-DETTES') {
316 $sql = "SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,";
317 $sql .= " sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
318 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s";
319 if ($selected_cat === -2) { // Without any category
320 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
321 } elseif ($selected_cat) { // Into a specific category
322 $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_fournisseur as cs";
323 }
324 $sql .= " WHERE f.fk_statut in (1,2)";
325 $sql .= " AND f.type IN (0,2)";
326 $sql .= " AND f.fk_soc = s.rowid";
327 if ($date_start && $date_end) {
328 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
329 }
330 if ($selected_cat === -2) { // Without any category
331 $sql .= " AND cs.fk_soc is null";
332 } elseif ($selected_cat) { // Into a specific category
333 $sql .= " AND (c.rowid = ".((int) $selected_cat);
334 if ($subcat) {
335 $sql .= " OR c.fk_parent = ".((int) $selected_cat);
336 }
337 $sql .= ")";
338 $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
339 }
340} elseif ($modecompta == "RECETTES-DEPENSES") {
341 $sql = "SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
342 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
343 $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
344 $sql .= ", ".MAIN_DB_PREFIX."paiementfourn as p";
345 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
346 if ($selected_cat === -2) { // Without any category
347 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
348 } elseif ($selected_cat) { // Into a specific category
349 $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_fournisseur as cs";
350 }
351 $sql .= " WHERE p.rowid = pf.fk_paiementfourn";
352 $sql .= " AND pf.fk_facturefourn = f.rowid";
353 $sql .= " AND f.fk_soc = s.rowid";
354 if ($date_start && $date_end) {
355 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
356 }
357 if ($selected_cat === -2) { // Without any category
358 $sql .= " AND cs.fk_soc is null";
359 } elseif ($selected_cat) { // Into a specific category
360 $sql .= " AND (c.rowid = ".((int) $selected_cat);
361 if ($subcat) {
362 $sql .= " OR c.fk_parent = ".((int) $selected_cat);
363 }
364 $sql .= ")";
365 $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
366 }
367} elseif ($modecompta == "BOOKKEEPING") {
368 // Purchase turnover computed from the accounting ledger. HT is the sum of postings on
369 // EXPENSE-type accounts; TTC is the amount posted on the supplier subledger line of the invoice.
370 // Thirdparty_code is set at transfer time from societe.code_fournisseur (see
371 // accountancy/journal/purchasesjournal.php).
372 $charofaccountstring = dol_getIdFromCode($db, getDolGlobalString('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
373
374 $sql = "SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,";
375 $sql .= " SUM(CASE WHEN b.subledger_account IS NOT NULL AND b.subledger_account != '' THEN b.credit - b.debit ELSE 0 END) as amount_ttc,";
376 $sql .= " SUM(CASE WHEN aa.pcg_type = 'EXPENSE' THEN b.debit - b.credit ELSE 0 END) as amount";
377 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b";
378 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.account_number = b.numero_compte AND aa.entity = b.entity AND aa.fk_pcg_version = '".$db->escape($charofaccountstring)."'";
379 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.code_fournisseur = b.thirdparty_code";
380 $sql .= " WHERE b.doc_type = 'supplier_invoice'";
381 $sql .= " AND b.thirdparty_code IS NOT NULL AND b.thirdparty_code != ''";
382 if ($date_start && $date_end) {
383 $sql .= " AND b.doc_date >= '".$db->idate($date_start)."' AND b.doc_date <= '".$db->idate($date_end)."'";
384 }
385}
386if (!empty($search_societe)) {
387 $sql .= natural_search('s.nom', $search_societe);
388}
389if (!empty($search_zip)) {
390 $sql .= natural_search('s.zip', $search_zip);
391}
392if (!empty($search_town)) {
393 $sql .= natural_search('s.town', $search_town);
394}
395if ($search_country > 0) {
396 $sql .= ' AND s.fk_pays = '.((int) $search_country);
397}
398if ($modecompta == 'BOOKKEEPING') {
399 $sql .= " AND b.entity = ".((int) $conf->entity);
400 if ($socid) {
401 $sql .= " AND s.rowid = ".((int) $socid);
402 }
403} else {
404 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
405 if ($socid) {
406 $sql .= " AND f.fk_soc = ".((int) $socid);
407 }
408}
409$sql .= " GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays";
410$sql .= " ORDER BY s.rowid";
411//echo $sql;
412
413$catotal_ht = 0;
414$catotal = 0;
415
416dol_syslog("supplier_turnover_by_thirdparty", LOG_DEBUG);
417$resql = $db->query($sql);
418if ($resql) {
419 $num = $db->num_rows($resql);
420 $i = 0;
421 while ($i < $num) {
422 $obj = $db->fetch_object($resql);
423
424 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
425 $amount[$obj->socid] = $obj->amount_ttc;
426 $name[$obj->socid] = $obj->name;
427
428 $address_zip[$obj->socid] = $obj->zip;
429 $address_town[$obj->socid] = $obj->town;
430 $address_pays[$obj->socid] = getCountry($obj->fk_pays);
431
432 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
433 $catotal += $obj->amount_ttc;
434
435 $i++;
436 }
437} else {
439}
440
441// Show array
442$i = 0;
443print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
444print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
445// Extra parameters management
446foreach ($headerparams as $key => $value) {
447 print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
448}
449
450$moreforfilter = '';
451
452print '<div class="div-table-responsive">';
453print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
454
455// Category filter
456print '<tr class="liste_titre">';
457print '<td>';
458print img_picto('', 'category', 'class="paddingrightonly"');
459print $formother->select_categories(Categorie::TYPE_SUPPLIER, $selected_cat, 'search_categ', 0, $langs->trans("Category"));
460print ' ';
461print '<label for="subcat" class="marginleftonly">'.$langs->trans("SubCats").'?</label> ';
462print '<input type="checkbox" id="subcat" name="subcat" value="yes"';
463if ($subcat) {
464 print ' checked';
465}
466print'></td>';
467print '<td colspan="7" class="right">';
468print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', 0, 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
469print '</td>';
470print '</tr>';
471
472print '<tr class="liste_titre">';
473print '<td class="liste_titre left">';
474print '<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
475print '</td>';
476print '<td class="liste_titre left">';
477print '<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'">';
478print '</td>';
479print '<td class="liste_titre left">';
480print '<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'">';
481print '</td>';
482print '<td class="liste_titre left">';
483print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth150');
484//print '<input class="flat" size="6" type="text" name="search_country" value="'.$search_country.'">';
485print '</td>';
486print '<td class="liste_titre">&nbsp;</td>';
487print '<td class="liste_titre">&nbsp;</td>';
488print '<td class="liste_titre">&nbsp;</td>';
489print '<td class="liste_titre">&nbsp;</td>';
490print '</tr>';
491
492// Array titles
493print "<tr class='liste_titre'>";
495 $langs->trans("Company"),
496 $_SERVER["PHP_SELF"],
497 "nom",
498 "",
499 $paramslink,
500 "",
501 $sortfield,
502 $sortorder
503);
505 $langs->trans("Zip"),
506 $_SERVER["PHP_SELF"],
507 "zip",
508 "",
509 $paramslink,
510 "",
511 $sortfield,
512 $sortorder
513);
515 $langs->trans("Town"),
516 $_SERVER["PHP_SELF"],
517 "town",
518 "",
519 $paramslink,
520 "",
521 $sortfield,
522 $sortorder
523);
525 $langs->trans("Country"),
526 $_SERVER["PHP_SELF"],
527 "country",
528 "",
529 $paramslink,
530 "",
531 $sortfield,
532 $sortorder
533);
534if ($modecompta == 'CREANCES-DETTES') {
536 $langs->trans('AmountHT'),
537 $_SERVER["PHP_SELF"],
538 "amount_ht",
539 "",
540 $paramslink,
541 'class="right"',
542 $sortfield,
543 $sortorder
544 );
545} else {
547}
549 $langs->trans("AmountTTC"),
550 $_SERVER["PHP_SELF"],
551 "amount_ttc",
552 "",
553 $paramslink,
554 'class="right"',
555 $sortfield,
556 $sortorder
557);
559 $langs->trans("Percentage"),
560 $_SERVER["PHP_SELF"],
561 "amount_ttc",
562 "",
563 $paramslink,
564 'class="right"',
565 $sortfield,
566 $sortorder
567);
569 $langs->trans("OtherStatistics"),
570 $_SERVER["PHP_SELF"],
571 "",
572 "",
573 "",
574 'align="center" width="20%"'
575);
576print "</tr>\n";
577
578
579if (count($amount)) {
580 $arrayforsort = $name;
581 // Defining array arrayforsort
582 if ($sortfield == 'nom' && $sortorder == 'asc') {
583 asort($name);
584 $arrayforsort = $name;
585 }
586 if ($sortfield == 'nom' && $sortorder == 'desc') {
587 arsort($name);
588 $arrayforsort = $name;
589 }
590 if ($sortfield == 'amount_ht' && $sortorder == 'asc') {
591 asort($amount_ht);
592 $arrayforsort = $amount_ht;
593 }
594 if ($sortfield == 'amount_ht' && $sortorder == 'desc') {
595 arsort($amount_ht);
596 $arrayforsort = $amount_ht;
597 }
598 if ($sortfield == 'amount_ttc' && $sortorder == 'asc') {
599 asort($amount);
600 $arrayforsort = $amount;
601 }
602 if ($sortfield == 'amount_ttc' && $sortorder == 'desc') {
603 arsort($amount);
604 $arrayforsort = $amount;
605 }
606 if ($sortfield == 'zip' && $sortorder == 'asc') {
607 asort($address_zip);
608 $arrayforsort = $address_zip;
609 }
610 if ($sortfield == 'zip' && $sortorder == 'desc') {
611 arsort($address_zip);
612 $arrayforsort = $address_zip;
613 }
614 if ($sortfield == 'town' && $sortorder == 'asc') {
615 asort($address_town);
616 $arrayforsort = $address_town;
617 }
618 if ($sortfield == 'town' && $sortorder == 'desc') {
619 arsort($address_town);
620 $arrayforsort = $address_town;
621 }
622 if ($sortfield == 'country' && $sortorder == 'asc') {
623 asort($address_pays);
624 $arrayforsort = $address_town;
625 }
626 if ($sortfield == 'country' && $sortorder == 'desc') {
627 arsort($address_pays);
628 $arrayforsort = $address_town;
629 }
630
631 foreach ($arrayforsort as $key => $value) {
632 print '<tr class="oddeven">';
633
634 // Third party
635 $fullname = $name[$key];
636 if ($key > 0) {
637 $thirdparty_static->id = (int) $key;
638 $thirdparty_static->name = $fullname;
639 $thirdparty_static->client = 1;
640 $linkname = $thirdparty_static->getNomUrl(1, 'supplier');
641 } else {
642 $linkname = $langs->trans("PaymentsNotLinkedToInvoice");
643 }
644 print "<td>".$linkname."</td>\n";
645
646 print '<td>';
647 print $address_zip[$key];
648 print '</td>';
649
650 print '<td>';
651 print $address_town[$key];
652 print '</td>';
653
654 print '<td>';
655 print $address_pays[$key];
656 print '</td>';
657
658 // Amount w/o VAT
659 print '<td class="right">';
660 if ($modecompta == 'RECETTES-DEPENSES') {
661 if ($key > 0) {
662 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement/list.php?socid='.$key.'">';
663 } else {
664 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement/list.php?socid=-1">';
665 }
666 } else {
667 if ($key > 0) {
668 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$key.'">';
669 } else {
670 print '<a href="#">';
671 }
672 print price($amount_ht[$key]);
673 }
674 print '</td>';
675
676 // Amount with VAT
677 print '<td class="right">';
678 if ($modecompta == 'RECETTES-DEPENSES') {
679 if ($key > 0) {
680 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement/list.php?socid='.$key.'">';
681 } else {
682 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement/list.php?orphelins=1">';
683 }
684 } else {
685 if ($key > 0) {
686 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$key.'">';
687 } else {
688 print '<a href="#">';
689 }
690 }
691 print price($amount[$key]);
692 print '</a>';
693 print '</td>';
694
695 // Percent;
696 print '<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : '&nbsp;').'</td>';
697
698 // Other stats
699 print '<td class="center">';
700 if (isModEnabled('supplier_proposal') && $key > 0) {
701 print '&nbsp;<a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("ProposalStats"), "stats").'</a>&nbsp;';
702 }
703 if (isModEnabled("supplier_order") && $key > 0) {
704 print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/stats/index.php?mode=supplier&socid='.$key.'">'.img_picto($langs->trans("OrderStats"), "stats").'</a>&nbsp;';
705 }
706 if (isModEnabled("supplier_invoice") && $key > 0) {
707 print '&nbsp;<a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?mode=supplier&socid='.$key.'">'.img_picto($langs->trans("InvoiceStats"), "stats").'</a>&nbsp;';
708 }
709 print '</td>';
710 print "</tr>\n";
711 $i++;
712 }
713
714 // Total
715 print '<tr class="liste_total">';
716 print '<td>'.$langs->trans("Total").'</td>';
717 print '<td></td>';
718 print '<td></td>';
719 print '<td></td>';
720 if ($modecompta == 'RECETTES-DEPENSES') {
721 print '<td></td>';
722 } else {
723 print '<td class="right">'.price($catotal_ht).'</td>';
724 }
725 print '<td class="right">'.price($catotal).'</td>';
726 print '<td></td>';
727 print '<td></td>';
728 print '</tr>';
729
730 $db->free($resql);
731} else {
732 print '<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
733}
734
735print "</table>";
736print "</div>";
737
738print '</form>';
739
740// End of page
741llxFooter();
742$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components Only common components are here.
Class to manage third parties objects (customers, suppliers, prospects...)
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:605
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:126
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:624
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
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.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_previous($titlealt='default', $moreatt='')
Show previous logo.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
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...
Definition html.lib.php:172
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.