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