dolibarr 24.0.0-beta
casoc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
6 * Copyright (C) 2013 Antoine Iauch <aiauch@gpcsolutions.fr>
7 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
10 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
31// Load Dolibarr environment
32require '../../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
47require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
48
49// Load translation files required by the page
50$langs->loadLangs(array('companies', 'categories', 'bills', 'compta'));
51
52// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
53$modecompta = getDolGlobalString('ACCOUNTING_MODE');
54if (GETPOST("modecompta")) {
55 $modecompta = GETPOST("modecompta");
56}
57
58$sortorder = GETPOST("sortorder", 'aZ09comma');
59$sortfield = GETPOST("sortfield", 'aZ09comma');
60if (!$sortorder) {
61 $sortorder = "asc";
62}
63if (!$sortfield) {
64 $sortfield = "nom";
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}
83
84// Hook
85$hookmanager->initHooks(array('casoclist'));
86
87if (isModEnabled('comptabilite')) {
88 $result = restrictedArea($user, 'compta', '', '', 'resultat');
89}
90if (isModEnabled('accounting')) {
91 $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
92}
93
94// Date range
95$year = GETPOSTINT("year");
96$month = GETPOSTINT("month");
97$search_societe = GETPOST("search_societe", 'alpha');
98$search_zip = GETPOST("search_zip", 'alpha');
99$search_town = GETPOST("search_town", 'alpha');
100$search_country = GETPOST("search_country", 'aZ09');
101$date_startyear = GETPOSTINT("date_startyear");
102$date_startmonth = GETPOSTINT("date_startmonth");
103$date_startday = GETPOSTINT("date_startday");
104$date_endyear = GETPOSTINT("date_endyear");
105$date_endmonth = GETPOSTINT("date_endmonth");
106$date_endday = GETPOSTINT("date_endday");
107if (empty($year)) {
108 $year_current = dol_print_date(dol_now(), '%Y');
109 $month_current = dol_print_date(dol_now(), '%m');
110 $year_start = $year_current;
111} else {
112 $year_current = $year;
113 $month_current = dol_print_date(dol_now(), '%m');
114 $year_start = $year;
115}
116$date_start = dol_mktime(0, 0, 0, GETPOSTINT("date_startmonth"), GETPOSTINT("date_startday"), GETPOSTINT("date_startyear"), 'tzserver'); // We use timezone of server so report is same from everywhere
117$date_end = dol_mktime(23, 59, 59, GETPOSTINT("date_endmonth"), GETPOSTINT("date_endday"), GETPOSTINT("date_endyear"), 'tzserver'); // We use timezone of server so report is same from everywhere
118// Quarter
119if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
120 $q = GETPOSTINT("q") ? GETPOSTINT("q") : 0;
121 if (empty($q)) {
122 // We define date_start and date_end
123 $month_start = GETPOST("month") ? GETPOST("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
124 $year_end = $year_start;
125 $month_end = $month_start;
126 if (!GETPOST("month")) { // If month not forced
127 if (!GETPOST('year') && $month_start > $month_current) {
128 $year_start--;
129 $year_end--;
130 }
131 $month_end = $month_start - 1;
132 if ($month_end < 1) {
133 $month_end = 12;
134 } else {
135 $year_end++;
136 }
137 }
138 $date_start = dol_get_first_day($year_start, $month_start, false);
139 $date_end = dol_get_last_day($year_end, $month_end, false);
140 }
141 if ($q == 1) {
142 $date_start = dol_get_first_day($year_start, 1, false);
143 $date_end = dol_get_last_day($year_start, 3, false);
144 }
145 if ($q == 2) {
146 $date_start = dol_get_first_day($year_start, 4, false);
147 $date_end = dol_get_last_day($year_start, 6, false);
148 }
149 if ($q == 3) {
150 $date_start = dol_get_first_day($year_start, 7, false);
151 $date_end = dol_get_last_day($year_start, 9, false);
152 }
153 if ($q == 4) {
154 $date_start = dol_get_first_day($year_start, 10, false);
155 $date_end = dol_get_last_day($year_start, 12, false);
156 }
157} else {
158 // TODO We define q
159}
160//print dol_print_date($date_start, 'dayhour', 'gmt');
161
162// $date_start and $date_end are defined. We force $year_start and $nbofyear
163$tmps = dol_getdate($date_start);
164$year_start = $tmps['year'];
165$tmpe = dol_getdate($date_end);
166$year_end = $tmpe['year'];
167$nbofyear = ($year_end - $year_start) + 1;
168
169$commonparams = array();
170$commonparams['modecompta'] = $modecompta;
171$commonparams['sortorder'] = $sortorder;
172$commonparams['sortfield'] = $sortfield;
173
174$headerparams = array();
175if (!empty($date_startyear)) {
176 $headerparams['date_startyear'] = $date_startyear;
177}
178if (!empty($date_startmonth)) {
179 $headerparams['date_startmonth'] = $date_startmonth;
180}
181if (!empty($date_startday)) {
182 $headerparams['date_startday'] = $date_startday;
183}
184if (!empty($date_endyear)) {
185 $headerparams['date_endyear'] = $date_endyear;
186}
187if (!empty($date_endmonth)) {
188 $headerparams['date_endmonth'] = $date_endmonth;
189}
190if (!empty($date_endday)) {
191 $headerparams['date_endday'] = $date_endday;
192}
193if (!empty($q)) {
194 $headerparams['q'] = $q;
195}
196
197$tableparams = array();
198$tableparams['search_categ'] = $selected_cat;
199$tableparams['search_societe'] = $search_societe;
200$tableparams['search_zip'] = $search_zip;
201$tableparams['search_town'] = $search_town;
202$tableparams['search_country'] = $search_country;
203$tableparams['subcat'] = $subcat ? 'yes' : '';
204
205// Adding common parameters
206$allparams = array_merge($commonparams, $headerparams, $tableparams);
207$headerparams = array_merge($commonparams, $headerparams);
208$tableparams = array_merge($commonparams, $tableparams);
209
210$paramslink = "";
211foreach ($allparams as $key => $value) {
212 $paramslink .= '&'.$key.'='.$value;
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$exportlink = "";
235$namelink = "";
236$builddate = 0;
237$calcmode = '';
238$name = '';
239$description = '';
240
241// Show report header
242if ($modecompta == "CREANCES-DETTES") {
243 $name = $langs->trans("Turnover").', '.$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("RulesCADue");
247 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
248 $description .= $langs->trans("DepositsAreNotIncluded");
249 } else {
250 $description .= $langs->trans("DepositsAreIncluded");
251 }
252 $builddate = dol_now();
253 //$exportlink=$langs->trans("NotYetAvailable");
254} elseif ($modecompta == "RECETTES-DEPENSES") {
255 $name = $langs->trans("TurnoverCollected").', '.$langs->trans("ByThirdParties");
256 $calcmode = $langs->trans("CalcModePayment");
257 //$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
258 $description = $langs->trans("RulesCAIn");
259 $description .= $langs->trans("DepositsAreIncluded");
260 $builddate = dol_now();
261 //$exportlink=$langs->trans("NotYetAvailable");
262} // elseif ($modecompta == "BOOKKEEPING") {
263// } elseif ($modecompta == "BOOKKEEPINGCOLLECTED") {
264// }
265$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
266$period .= ' - ';
267$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
268if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) {
269 $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>';
270} else {
271 $periodlink = '';
272}
273
274report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
275
276if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
277 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
278}
279
280
281$name = array();
282
283// Show Array
284$catotal = 0;
285$catotal_ht = 0;
286$sql = '';
287
288if ($modecompta == 'CREANCES-DETTES') {
289 $sql = "SELECT DISTINCT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays,";
290 $sql .= " sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
291 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
292 if ($selected_cat === -2) { // Without any category
293 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
294 } elseif ($selected_cat) { // Into a specific category
295 $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
296 }
297 $sql .= " WHERE f.fk_statut in (1,2)";
298 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
299 $sql .= " AND f.type IN (0,1,2,5)";
300 } else {
301 $sql .= " AND f.type IN (0,1,2,3,5)";
302 }
303 $sql .= " AND f.fk_soc = s.rowid";
304 if ($date_start && $date_end) {
305 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
306 }
307 if ($selected_cat === -2) { // Without any category
308 $sql .= " AND cs.fk_soc is null";
309 } elseif ($selected_cat) { // Into a specific category
310 $sql .= " AND (c.rowid = ".((int) $selected_cat);
311 if ($subcat) {
312 $sql .= " OR c.fk_parent = ".((int) $selected_cat);
313 }
314 $sql .= ")";
315 $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
316 }
317} elseif ($modecompta == "RECETTES-DEPENSES") {
318 /*
319 * List of payments (old payments are not seen by this query because on older versions,
320 * they were not linked via the table llx_paiement_facture. They are added later)
321 */
322 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
323 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
324 $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
325 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
326 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
327 if ($selected_cat === -2) { // Without any category
328 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
329 } elseif ($selected_cat) { // Into a specific category
330 $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
331 }
332 $sql .= " WHERE p.rowid = pf.fk_paiement";
333 $sql .= " AND pf.fk_facture = f.rowid";
334 $sql .= " AND f.fk_soc = s.rowid";
335 if ($date_start && $date_end) {
336 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
337 }
338 if ($selected_cat === -2) { // Without any category
339 $sql .= " AND cs.fk_soc is null";
340 } elseif ($selected_cat) { // Into a specific category
341 $sql .= " AND (c.rowid = ".((int) $selected_cat);
342 if ($subcat) {
343 $sql .= " OR c.fk_parent = ".((int) $selected_cat);
344 }
345 $sql .= ")";
346 $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
347 }
348} // elseif ($modecompta == "BOOKKEEPING") {
349// } elseif ($modecompta == "BOOKKEEPINGCOLLECTED") {
350// }
351if (!empty($search_societe)) {
352 $sql .= natural_search('s.nom', $search_societe);
353}
354if (!empty($search_zip)) {
355 $sql .= natural_search('s.zip', $search_zip);
356}
357if (!empty($search_town)) {
358 $sql .= natural_search('s.town', $search_town);
359}
360if ($search_country > 0) {
361 $sql .= ' AND s.fk_pays = '.((int) $search_country);
362}
363$sql .= " AND f.entity IN (".getEntity('invoice').")";
364if ($socid) {
365 $sql .= " AND f.fk_soc = ".((int) $socid);
366}
367$sql .= " GROUP BY s.rowid, s.nom, s.name_alias, s.zip, s.town, s.fk_pays";
368$sql .= " ORDER BY s.rowid";
369//echo $sql;
370
371$amount = array();
372$amount_ht = array();
373$address_zip = array();
374$address_town = array();
375$address_pays = array();
376
377dol_syslog("casoc", LOG_DEBUG);
378$result = $db->query($sql);
379if ($result) {
380 $num = $db->num_rows($result);
381 $i = 0;
382 while ($i < $num) {
383 $obj = $db->fetch_object($result);
384
385 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
386 $amount[$obj->socid] = $obj->amount_ttc;
387 $fullname = $obj->name;
388 if (!empty($obj->name_alias)) {
389 $fullname .= ' ('.$obj->name_alias.')';
390 }
391 $name[$obj->socid] = $fullname;
392
393 $address_zip[$obj->socid] = $obj->zip;
394 $address_town[$obj->socid] = $obj->town;
395 $address_pays[$obj->socid] = getCountry($obj->fk_pays);
396
397 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
398 $catotal += $obj->amount_ttc;
399
400 $i++;
401 }
402} else {
404}
405
406// We add the old versions of payments, not linked by table llx_paiement_facture
407if ($modecompta == "RECETTES-DEPENSES") {
408 $sql = "SELECT '0' as socid, 'Autres' as name, sum(p.amount) as amount_ttc";
409 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
410 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
411 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
412 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
413 $sql .= " WHERE pf.rowid IS NULL";
414 $sql .= " AND p.fk_bank = b.rowid";
415 $sql .= " AND b.fk_account = ba.rowid";
416 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
417 if ($date_start && $date_end) {
418 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
419 }
420 $sql .= " GROUP BY socid, name";
421 $sql .= " ORDER BY name";
422
423 $result = $db->query($sql);
424 if ($result) {
425 $num = $db->num_rows($result);
426 $i = 0;
427 while ($i < $num) {
428 $obj = $db->fetch_object($result);
429
430 if (empty($amount[$obj->socid])) {
431 $amount[$obj->socid] = $obj->amount_ttc;
432 } else {
433 $amount[$obj->socid] += $obj->amount_ttc;
434 }
435
436 $name[$obj->socid] = $obj->name;
437 $address_zip[$obj->socid] = '';
438 $address_town[$obj->socid] = '';
439 $address_pays[$obj->socid] = '';
440
441 $catotal += $obj->amount_ttc;
442
443 $i++;
444 }
445 } else {
447 }
448}
449
450
451// Show array
452$i = 0;
453print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
454print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
455// Extra parameters management
456foreach ($headerparams as $key => $value) {
457 print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
458}
459
460$moreforfilter = '';
461
462print '<div class="div-table-responsive">';
463print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
464
465// Category filter
466print '<tr class="liste_titre">';
467print '<td class="nowraponall">';
468print img_picto('', 'category', 'class="paddingrightonly"');
469print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat, 'search_categ', 0, $langs->trans("Category"));
470print ' ';
471print $langs->trans("SubCats").'? ';
472print '<input type="checkbox" name="subcat" value="yes"';
473if ($subcat) {
474 print ' checked';
475}
476print'></td>';
477print '<td colspan="7" class="right">';
478print '<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")).'">';
479print '</td>';
480print '</tr>';
481
482print '<tr class="liste_titre">';
483print '<td class="liste_titre left">';
484print '<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
485print '</td>';
486print '<td class="liste_titre left">';
487print '<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'">';
488print '</td>';
489print '<td class="liste_titre left">';
490print '<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'">';
491print '</td>';
492print '<td class="liste_titre left">';
493print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
494//print '<input class="flat" size="6" type="text" name="search_country" value="'.$search_country.'">';
495print '</td>';
496print '<td class="liste_titre">&nbsp;</td>';
497print '<td class="liste_titre">&nbsp;</td>';
498print '<td class="liste_titre">&nbsp;</td>';
499print '<td class="liste_titre">&nbsp;</td>';
500print '</tr>';
501
502// Array titles
503print "<tr class='liste_titre'>";
505 $langs->trans("Company"),
506 $_SERVER["PHP_SELF"],
507 "nom",
508 "",
509 $paramslink,
510 "",
511 $sortfield,
512 $sortorder
513);
515 $langs->trans("Zip"),
516 $_SERVER["PHP_SELF"],
517 "zip",
518 "",
519 $paramslink,
520 "",
521 $sortfield,
522 $sortorder
523);
525 $langs->trans("Town"),
526 $_SERVER["PHP_SELF"],
527 "town",
528 "",
529 $paramslink,
530 "",
531 $sortfield,
532 $sortorder
533);
535 $langs->trans("Country"),
536 $_SERVER["PHP_SELF"],
537 "country",
538 "",
539 $paramslink,
540 "",
541 $sortfield,
542 $sortorder
543);
544if ($modecompta == 'CREANCES-DETTES') {
546 $langs->trans('AmountHT'),
547 $_SERVER["PHP_SELF"],
548 "amount_ht",
549 "",
550 $paramslink,
551 'class="right"',
552 $sortfield,
553 $sortorder
554 );
555} else {
557}
559 $langs->trans("AmountTTC"),
560 $_SERVER["PHP_SELF"],
561 "amount_ttc",
562 "",
563 $paramslink,
564 'class="right"',
565 $sortfield,
566 $sortorder
567);
569 $langs->trans("Percentage"),
570 $_SERVER["PHP_SELF"],
571 "amount_ttc",
572 "",
573 $paramslink,
574 'class="right"',
575 $sortfield,
576 $sortorder
577);
579 $langs->trans("OtherStatistics"),
580 $_SERVER["PHP_SELF"],
581 "",
582 "",
583 "",
584 'align="center" width="20%"'
585);
586print "</tr>\n";
587
588
589if (count($amount)) {
590 $arrayforsort = $name;
591 // Defining array arrayforsort
592 if ($sortfield == 'nom' && $sortorder == 'asc') {
593 asort($name);
594 $arrayforsort = $name;
595 }
596 if ($sortfield == 'nom' && $sortorder == 'desc') {
597 arsort($name);
598 $arrayforsort = $name;
599 }
600 if ($sortfield == 'amount_ht' && $sortorder == 'asc') {
601 asort($amount_ht);
602 $arrayforsort = $amount_ht;
603 }
604 if ($sortfield == 'amount_ht' && $sortorder == 'desc') {
605 arsort($amount_ht);
606 $arrayforsort = $amount_ht;
607 }
608 if ($sortfield == 'amount_ttc' && $sortorder == 'asc') {
609 asort($amount);
610 $arrayforsort = $amount;
611 }
612 if ($sortfield == 'amount_ttc' && $sortorder == 'desc') {
613 arsort($amount);
614 $arrayforsort = $amount;
615 }
616 if ($sortfield == 'zip' && $sortorder == 'asc') {
617 asort($address_zip);
618 $arrayforsort = $address_zip;
619 }
620 if ($sortfield == 'zip' && $sortorder == 'desc') {
621 arsort($address_zip);
622 $arrayforsort = $address_zip;
623 }
624 if ($sortfield == 'town' && $sortorder == 'asc') {
625 asort($address_town);
626 $arrayforsort = $address_town;
627 }
628 if ($sortfield == 'town' && $sortorder == 'desc') {
629 arsort($address_town);
630 $arrayforsort = $address_town;
631 }
632 if ($sortfield == 'country' && $sortorder == 'asc') {
633 asort($address_pays);
634 $arrayforsort = $address_town;
635 }
636 if ($sortfield == 'country' && $sortorder == 'desc') {
637 arsort($address_pays);
638 $arrayforsort = $address_town;
639 }
640
641 foreach ($arrayforsort as $key => $value) {
642 print '<tr class="oddeven">';
643
644 // Third party
645 $fullname = $name[$key];
646 if ($key > 0) {
647 $thirdparty_static->id = (int) $key;
648 $thirdparty_static->name = $fullname;
649 $thirdparty_static->client = 1;
650 $linkname = $thirdparty_static->getNomUrl(1, 'customer');
651 } else {
652 $linkname = $langs->trans("PaymentsNotLinkedToInvoice");
653 }
654 print '<td class="tdoverflowmax150">'.$linkname."</td>\n";
655
656 print '<td>';
657 print $address_zip[$key];
658 print '</td>';
659
660 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_town[$key]).'">';
661 print $address_town[$key];
662 print '</td>';
663
664 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_pays[$key]).'">';
665 print $address_pays[$key];
666 print '</td>';
667
668 // Amount w/o VAT
669 print '<td class="right">';
670 if ($modecompta != 'CREANCES-DETTES') {
671 if ($key > 0) {
672 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid='.$key.'">';
673 } else {
674 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid=-1">';
675 }
676 } else {
677 if ($key > 0) {
678 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$key.'">';
679 } else {
680 print '<a href="#">';
681 }
682 print price($amount_ht[$key]);
683 }
684 print '</td>';
685
686 // Amount with VAT
687 print '<td class="right">';
688 if ($modecompta != 'CREANCES-DETTES') {
689 if ($key > 0) {
690 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid='.$key.'">';
691 } else {
692 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?orphelins=1">';
693 }
694 } else {
695 if ($key > 0) {
696 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$key.'">';
697 } else {
698 print '<a href="#">';
699 }
700 }
701 print price($amount[$key]);
702 print '</a>';
703 print '</td>';
704
705 // Percent;
706 print '<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : '&nbsp;').'</td>';
707
708 // Other stats
709 print '<td class="center">';
710 if (isModEnabled("propal") && $key > 0) {
711 print '&nbsp;<a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("ProposalStats"), "stats").'</a>&nbsp;';
712 }
713 if (isModEnabled('order') && $key > 0) {
714 print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("OrderStats"), "stats").'</a>&nbsp;';
715 }
716 if (isModEnabled('invoice') && $key > 0) {
717 print '&nbsp;<a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("InvoiceStats"), "stats").'</a>&nbsp;';
718 }
719 print '</td>';
720 print "</tr>\n";
721 $i++;
722 }
723
724 // Total
725 print '<tr class="liste_total">';
726 print '<td>'.$langs->trans("Total").'</td>';
727 print '<td>&nbsp;</td>';
728 print '<td>&nbsp;</td>';
729 print '<td>&nbsp;</td>';
730 if ($modecompta != 'CREANCES-DETTES') {
731 print '<td></td>';
732 } else {
733 print '<td class="right">'.price($catotal_ht).'</td>';
734 }
735 print '<td class="right">'.price($catotal).'</td>';
736 print '<td>&nbsp;</td>';
737 print '<td>&nbsp;</td>';
738 print '</tr>';
739
740 $db->free($result);
741}
742
743print "</table>";
744print "</div>";
745
746print '</form>';
747
748// End of page
749llxFooter();
750$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:604
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:623
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...
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)
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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).
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.
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.
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...
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.