dolibarr 21.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-2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
10 * Copyright (C) 2024 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';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
39require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
40
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
240// Show report header
241if ($modecompta == "CREANCES-DETTES") {
242 $name = $langs->trans("Turnover").', '.$langs->trans("ByThirdParties");
243 $calcmode = $langs->trans("CalcModeDebt");
244 //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
245 $description = $langs->trans("RulesCADue");
246 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
247 $description .= $langs->trans("DepositsAreNotIncluded");
248 } else {
249 $description .= $langs->trans("DepositsAreIncluded");
250 }
251 $builddate = dol_now();
252 //$exportlink=$langs->trans("NotYetAvailable");
253} elseif ($modecompta == "RECETTES-DEPENSES") {
254 $name = $langs->trans("TurnoverCollected").', '.$langs->trans("ByThirdParties");
255 $calcmode = $langs->trans("CalcModePayment");
256 //$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
257 $description = $langs->trans("RulesCAIn");
258 $description .= $langs->trans("DepositsAreIncluded");
259 $builddate = dol_now();
260 //$exportlink=$langs->trans("NotYetAvailable");
261} // elseif ($modecompta == "BOOKKEEPING") {
262// } elseif ($modecompta == "BOOKKEEPINGCOLLECTED") {
263// }
264$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
265$period .= ' - ';
266$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
267if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) {
268 $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>';
269} else {
270 $periodlink = '';
271}
272
273report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
274
275if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
276 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
277}
278
279
280$name = array();
281
282// Show Array
283$catotal = 0;
284$catotal_ht = 0;
285
286if ($modecompta == 'CREANCES-DETTES') {
287 $sql = "SELECT DISTINCT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays,";
288 $sql .= " sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
289 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
290 if ($selected_cat === -2) { // Without any category
291 $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
292 } elseif ($selected_cat) { // Into a specific category
293 $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
294 }
295 $sql .= " WHERE f.fk_statut in (1,2)";
296 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
297 $sql .= " AND f.type IN (0,1,2,5)";
298 } else {
299 $sql .= " AND f.type IN (0,1,2,3,5)";
300 }
301 $sql .= " AND f.fk_soc = s.rowid";
302 if ($date_start && $date_end) {
303 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
304 }
305 if ($selected_cat === -2) { // Without any category
306 $sql .= " AND cs.fk_soc is null";
307 } elseif ($selected_cat) { // Into a specific category
308 $sql .= " AND (c.rowid = ".((int) $selected_cat);
309 if ($subcat) {
310 $sql .= " OR c.fk_parent = ".((int) $selected_cat);
311 }
312 $sql .= ")";
313 $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
314 }
315} elseif ($modecompta == "RECETTES-DEPENSES") {
316 /*
317 * List of payments (old payments are not seen by this query because on older versions,
318 * they were not linked via the table llx_paiement_facture. They are added later)
319 */
320 $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";
321 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
322 $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
323 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
324 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
325 if ($selected_cat === -2) { // Without any category
326 $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
327 } elseif ($selected_cat) { // Into a specific category
328 $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
329 }
330 $sql .= " WHERE p.rowid = pf.fk_paiement";
331 $sql .= " AND pf.fk_facture = f.rowid";
332 $sql .= " AND f.fk_soc = s.rowid";
333 if ($date_start && $date_end) {
334 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
335 }
336 if ($selected_cat === -2) { // Without any category
337 $sql .= " AND cs.fk_soc is null";
338 } elseif ($selected_cat) { // Into a specific category
339 $sql .= " AND (c.rowid = ".((int) $selected_cat);
340 if ($subcat) {
341 $sql .= " OR c.fk_parent = ".((int) $selected_cat);
342 }
343 $sql .= ")";
344 $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
345 }
346} // elseif ($modecompta == "BOOKKEEPING") {
347// } elseif ($modecompta == "BOOKKEEPINGCOLLECTED") {
348// }
349if (!empty($search_societe)) {
350 $sql .= natural_search('s.nom', $search_societe);
351}
352if (!empty($search_zip)) {
353 $sql .= natural_search('s.zip', $search_zip);
354}
355if (!empty($search_town)) {
356 $sql .= natural_search('s.town', $search_town);
357}
358if ($search_country > 0) {
359 $sql .= ' AND s.fk_pays = '.((int) $search_country);
360}
361$sql .= " AND f.entity IN (".getEntity('invoice').")";
362if ($socid) {
363 $sql .= " AND f.fk_soc = ".((int) $socid);
364}
365$sql .= " GROUP BY s.rowid, s.nom, s.name_alias, s.zip, s.town, s.fk_pays";
366$sql .= " ORDER BY s.rowid";
367//echo $sql;
368
369$amount = array();
370$amount_ht = array();
371$address_zip = array();
372$address_town = array();
373$address_pays = array();
374
375dol_syslog("casoc", LOG_DEBUG);
376$result = $db->query($sql);
377if ($result) {
378 $num = $db->num_rows($result);
379 $i = 0;
380 while ($i < $num) {
381 $obj = $db->fetch_object($result);
382
383 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
384 $amount[$obj->socid] = $obj->amount_ttc;
385 $fullname = $obj->name;
386 if (!empty($obj->name_alias)) {
387 $fullname .= ' ('.$obj->name_alias.')';
388 }
389 $name[$obj->socid] = $fullname;
390
391 $address_zip[$obj->socid] = $obj->zip;
392 $address_town[$obj->socid] = $obj->town;
393 $address_pays[$obj->socid] = getCountry($obj->fk_pays);
394
395 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
396 $catotal += $obj->amount_ttc;
397
398 $i++;
399 }
400} else {
401 dol_print_error($db);
402}
403
404// We add the old versions of payments, not linked by table llx_paiement_facture
405if ($modecompta == "RECETTES-DEPENSES") {
406 $sql = "SELECT '0' as socid, 'Autres' as name, sum(p.amount) as amount_ttc";
407 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
408 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
409 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
410 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
411 $sql .= " WHERE pf.rowid IS NULL";
412 $sql .= " AND p.fk_bank = b.rowid";
413 $sql .= " AND b.fk_account = ba.rowid";
414 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
415 if ($date_start && $date_end) {
416 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
417 }
418 $sql .= " GROUP BY socid, name";
419 $sql .= " ORDER BY name";
420
421 $result = $db->query($sql);
422 if ($result) {
423 $num = $db->num_rows($result);
424 $i = 0;
425 while ($i < $num) {
426 $obj = $db->fetch_object($result);
427
428 if (empty($amount[$obj->socid])) {
429 $amount[$obj->socid] = $obj->amount_ttc;
430 } else {
431 $amount[$obj->socid] += $obj->amount_ttc;
432 }
433
434 $name[$obj->socid] = $obj->name;
435 $address_zip[$obj->socid] = '';
436 $address_town[$obj->socid] = '';
437 $address_pays[$obj->socid] = '';
438
439 $catotal += $obj->amount_ttc;
440
441 $i++;
442 }
443 } else {
444 dol_print_error($db);
445 }
446}
447
448
449// Show array
450$i = 0;
451print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
452print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
453// Extra parameters management
454foreach ($headerparams as $key => $value) {
455 print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
456}
457
458$moreforfilter = '';
459
460print '<div class="div-table-responsive">';
461print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
462
463// Category filter
464print '<tr class="liste_titre">';
465print '<td class="nowraponall">';
466print img_picto('', 'category', 'class="paddingrightonly"');
467print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat, 'search_categ', 0, $langs->trans("Category"));
468print ' ';
469print $langs->trans("SubCats").'? ';
470print '<input type="checkbox" name="subcat" value="yes"';
471if ($subcat) {
472 print ' checked';
473}
474print'></td>';
475print '<td colspan="7" class="right">';
476print '<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")).'">';
477print '</td>';
478print '</tr>';
479
480print '<tr class="liste_titre">';
481print '<td class="liste_titre left">';
482print '<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
483print '</td>';
484print '<td class="liste_titre left">';
485print '<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'">';
486print '</td>';
487print '<td class="liste_titre left">';
488print '<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'">';
489print '</td>';
490print '<td class="liste_titre left">';
491print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
492//print '<input class="flat" size="6" type="text" name="search_country" value="'.$search_country.'">';
493print '</td>';
494print '<td class="liste_titre">&nbsp;</td>';
495print '<td class="liste_titre">&nbsp;</td>';
496print '<td class="liste_titre">&nbsp;</td>';
497print '<td class="liste_titre">&nbsp;</td>';
498print '</tr>';
499
500// Array titles
501print "<tr class='liste_titre'>";
503 $langs->trans("Company"),
504 $_SERVER["PHP_SELF"],
505 "nom",
506 "",
507 $paramslink,
508 "",
509 $sortfield,
510 $sortorder
511);
513 $langs->trans("Zip"),
514 $_SERVER["PHP_SELF"],
515 "zip",
516 "",
517 $paramslink,
518 "",
519 $sortfield,
520 $sortorder
521);
523 $langs->trans("Town"),
524 $_SERVER["PHP_SELF"],
525 "town",
526 "",
527 $paramslink,
528 "",
529 $sortfield,
530 $sortorder
531);
533 $langs->trans("Country"),
534 $_SERVER["PHP_SELF"],
535 "country",
536 "",
537 $paramslink,
538 "",
539 $sortfield,
540 $sortorder
541);
542if ($modecompta == 'CREANCES-DETTES') {
544 $langs->trans('AmountHT'),
545 $_SERVER["PHP_SELF"],
546 "amount_ht",
547 "",
548 $paramslink,
549 'class="right"',
550 $sortfield,
551 $sortorder
552 );
553} else {
555}
557 $langs->trans("AmountTTC"),
558 $_SERVER["PHP_SELF"],
559 "amount_ttc",
560 "",
561 $paramslink,
562 'class="right"',
563 $sortfield,
564 $sortorder
565);
567 $langs->trans("Percentage"),
568 $_SERVER["PHP_SELF"],
569 "amount_ttc",
570 "",
571 $paramslink,
572 'class="right"',
573 $sortfield,
574 $sortorder
575);
577 $langs->trans("OtherStatistics"),
578 $_SERVER["PHP_SELF"],
579 "",
580 "",
581 "",
582 'align="center" width="20%"'
583);
584print "</tr>\n";
585
586
587if (count($amount)) {
588 $arrayforsort = $name;
589 // Defining array arrayforsort
590 if ($sortfield == 'nom' && $sortorder == 'asc') {
591 asort($name);
592 $arrayforsort = $name;
593 }
594 if ($sortfield == 'nom' && $sortorder == 'desc') {
595 arsort($name);
596 $arrayforsort = $name;
597 }
598 if ($sortfield == 'amount_ht' && $sortorder == 'asc') {
599 asort($amount_ht);
600 $arrayforsort = $amount_ht;
601 }
602 if ($sortfield == 'amount_ht' && $sortorder == 'desc') {
603 arsort($amount_ht);
604 $arrayforsort = $amount_ht;
605 }
606 if ($sortfield == 'amount_ttc' && $sortorder == 'asc') {
607 asort($amount);
608 $arrayforsort = $amount;
609 }
610 if ($sortfield == 'amount_ttc' && $sortorder == 'desc') {
611 arsort($amount);
612 $arrayforsort = $amount;
613 }
614 if ($sortfield == 'zip' && $sortorder == 'asc') {
615 asort($address_zip);
616 $arrayforsort = $address_zip;
617 }
618 if ($sortfield == 'zip' && $sortorder == 'desc') {
619 arsort($address_zip);
620 $arrayforsort = $address_zip;
621 }
622 if ($sortfield == 'town' && $sortorder == 'asc') {
623 asort($address_town);
624 $arrayforsort = $address_town;
625 }
626 if ($sortfield == 'town' && $sortorder == 'desc') {
627 arsort($address_town);
628 $arrayforsort = $address_town;
629 }
630 if ($sortfield == 'country' && $sortorder == 'asc') {
631 asort($address_pays);
632 $arrayforsort = $address_town;
633 }
634 if ($sortfield == 'country' && $sortorder == 'desc') {
635 arsort($address_pays);
636 $arrayforsort = $address_town;
637 }
638
639 foreach ($arrayforsort as $key => $value) {
640 print '<tr class="oddeven">';
641
642 // Third party
643 $fullname = $name[$key];
644 if ($key > 0) {
645 $thirdparty_static->id = $key;
646 $thirdparty_static->name = $fullname;
647 $thirdparty_static->client = 1;
648 $linkname = $thirdparty_static->getNomUrl(1, 'customer');
649 } else {
650 $linkname = $langs->trans("PaymentsNotLinkedToInvoice");
651 }
652 print '<td class="tdoverflowmax150">'.$linkname."</td>\n";
653
654 print '<td>';
655 print $address_zip[$key];
656 print '</td>';
657
658 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_town[$key]).'">';
659 print $address_town[$key];
660 print '</td>';
661
662 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_pays[$key]).'">';
663 print $address_pays[$key];
664 print '</td>';
665
666 // Amount w/o VAT
667 print '<td class="right">';
668 if ($modecompta != 'CREANCES-DETTES') {
669 if ($key > 0) {
670 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid='.$key.'">';
671 } else {
672 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid=-1">';
673 }
674 } else {
675 if ($key > 0) {
676 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$key.'">';
677 } else {
678 print '<a href="#">';
679 }
680 print price($amount_ht[$key]);
681 }
682 print '</td>';
683
684 // Amount with VAT
685 print '<td class="right">';
686 if ($modecompta != 'CREANCES-DETTES') {
687 if ($key > 0) {
688 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid='.$key.'">';
689 } else {
690 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?orphelins=1">';
691 }
692 } else {
693 if ($key > 0) {
694 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$key.'">';
695 } else {
696 print '<a href="#">';
697 }
698 }
699 print price($amount[$key]);
700 print '</a>';
701 print '</td>';
702
703 // Percent;
704 print '<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : '&nbsp;').'</td>';
705
706 // Other stats
707 print '<td class="center">';
708 if (isModEnabled("propal") && $key > 0) {
709 print '&nbsp;<a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("ProposalStats"), "stats").'</a>&nbsp;';
710 }
711 if (isModEnabled('order') && $key > 0) {
712 print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("OrderStats"), "stats").'</a>&nbsp;';
713 }
714 if (isModEnabled('invoice') && $key > 0) {
715 print '&nbsp;<a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("InvoiceStats"), "stats").'</a>&nbsp;';
716 }
717 print '</td>';
718 print "</tr>\n";
719 $i++;
720 }
721
722 // Total
723 print '<tr class="liste_total">';
724 print '<td>'.$langs->trans("Total").'</td>';
725 print '<td>&nbsp;</td>';
726 print '<td>&nbsp;</td>';
727 print '<td>&nbsp;</td>';
728 if ($modecompta != 'CREANCES-DETTES') {
729 print '<td></td>';
730 } else {
731 print '<td class="right">'.price($catotal_ht).'</td>';
732 }
733 print '<td class="right">'.price($catotal).'</td>';
734 print '<td>&nbsp;</td>';
735 print '<td>&nbsp;</td>';
736 print '</tr>';
737
738 $db->free($result);
739}
740
741print "</table>";
742print "</div>";
743
744print '</form>';
745
746// End of page
747llxFooter();
748$db->close();
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:71
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre 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:600
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:619
llxFooter()
Footer empty.
Definition document.php:107
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...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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_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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
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.