dolibarr  16.0.5
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 Frédéric France <frederic.france@netlogic.fr>
9  * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array('companies', 'categories', 'bills', 'compta'));
41 
42 // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
43 $modecompta = $conf->global->ACCOUNTING_MODE;
44 if (GETPOST("modecompta")) {
45  $modecompta = GETPOST("modecompta");
46 }
47 
48 $sortorder = GETPOST("sortorder", 'aZ09comma');
49 $sortfield = GETPOST("sortfield", 'aZ09comma');
50 if (!$sortorder) {
51  $sortorder = "asc";
52 }
53 if (!$sortfield) {
54  $sortfield = "nom";
55 }
56 
57 $socid = GETPOST('socid', 'int');
58 
59 // Category
60 $selected_cat = (int) GETPOST('search_categ', 'int');
61 if ($selected_cat == -1) $selected_cat = '';
62 $subcat = false;
63 if (GETPOST('subcat', 'alpha') === 'yes') {
64  $subcat = true;
65 }
66 
67 // Security check
68 if ($user->socid > 0) {
69  $socid = $user->socid;
70 }
71 if (isModEnabled('comptabilite')) {
72  $result = restrictedArea($user, 'compta', '', '', 'resultat');
73 }
74 if (isModEnabled('accounting')) {
75  $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
76 }
77 
78 // Hook
79 $hookmanager->initHooks(array('casoclist'));
80 
81 // Date range
82 $year = GETPOST("year", 'int');
83 $month = GETPOST("month", 'int');
84 $search_societe = GETPOST("search_societe", 'alpha');
85 $search_zip = GETPOST("search_zip", 'alpha');
86 $search_town = GETPOST("search_town", 'alpha');
87 $search_country = GETPOST("search_country", 'alpha');
88 $date_startyear = GETPOST("date_startyear", 'int');
89 $date_startmonth = GETPOST("date_startmonth", 'int');
90 $date_startday = GETPOST("date_startday", 'int');
91 $date_endyear = GETPOST("date_endyear", 'int');
92 $date_endmonth = GETPOST("date_endmonth", 'int');
93 $date_endday = GETPOST("date_endday", 'int');
94 if (empty($year)) {
95  $year_current = dol_print_date(dol_now(), '%Y');
96  $month_current = dol_print_date(dol_now(), '%m');
97  $year_start = $year_current;
98 } else {
99  $year_current = $year;
100  $month_current = dol_print_date(dol_now(), '%m');
101  $year_start = $year;
102 }
103 $date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"), 'tzserver'); // We use timezone of server so report is same from everywhere
104 $date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"), 'tzserver'); // We use timezone of server so report is same from everywhere
105 // Quarter
106 if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
107  $q = GETPOST("q", "int") ?GETPOST("q", "int") : 0;
108  if (empty($q)) {
109  // We define date_start and date_end
110  $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
111  $year_end = $year_start;
112  $month_end = $month_start;
113  if (!GETPOST("month")) { // If month not forced
114  if (!GETPOST('year') && $month_start > $month_current) {
115  $year_start--;
116  $year_end--;
117  }
118  $month_end = $month_start - 1;
119  if ($month_end < 1) {
120  $month_end = 12;
121  } else {
122  $year_end++;
123  }
124  }
125  $date_start = dol_get_first_day($year_start, $month_start, false);
126  $date_end = dol_get_last_day($year_end, $month_end, false);
127  }
128  if ($q == 1) {
129  $date_start = dol_get_first_day($year_start, 1, false);
130  $date_end = dol_get_last_day($year_start, 3, false);
131  }
132  if ($q == 2) {
133  $date_start = dol_get_first_day($year_start, 4, false);
134  $date_end = dol_get_last_day($year_start, 6, false);
135  }
136  if ($q == 3) {
137  $date_start = dol_get_first_day($year_start, 7, false);
138  $date_end = dol_get_last_day($year_start, 9, false);
139  }
140  if ($q == 4) {
141  $date_start = dol_get_first_day($year_start, 10, false);
142  $date_end = dol_get_last_day($year_start, 12, false);
143  }
144 } else {
145  // TODO We define q
146 }
147 //print dol_print_date($date_start, 'dayhour', 'gmt');
148 
149 // $date_start and $date_end are defined. We force $year_start and $nbofyear
150 $tmps = dol_getdate($date_start);
151 $year_start = $tmps['year'];
152 $tmpe = dol_getdate($date_end);
153 $year_end = $tmpe['year'];
154 $nbofyear = ($year_end - $year_start) + 1;
155 
156 $commonparams = array();
157 $commonparams['modecompta'] = $modecompta;
158 $commonparams['sortorder'] = $sortorder;
159 $commonparams['sortfield'] = $sortfield;
160 
161 $headerparams = array();
162 if (!empty($date_startyear)) {
163  $headerparams['date_startyear'] = $date_startyear;
164 }
165 if (!empty($date_startmonth)) {
166  $headerparams['date_startmonth'] = $date_startmonth;
167 }
168 if (!empty($date_startday)) {
169  $headerparams['date_startday'] = $date_startday;
170 }
171 if (!empty($date_endyear)) {
172  $headerparams['date_endyear'] = $date_endyear;
173 }
174 if (!empty($date_endmonth)) {
175  $headerparams['date_endmonth'] = $date_endmonth;
176 }
177 if (!empty($date_endday)) {
178  $headerparams['date_endday'] = $date_endday;
179 }
180 if (!empty($q)) {
181  $headerparams['q'] = $q;
182 }
183 
184 $tableparams = array();
185 $tableparams['search_categ'] = $selected_cat;
186 $tableparams['search_societe'] = $search_societe;
187 $tableparams['search_zip'] = $search_zip;
188 $tableparams['search_town'] = $search_town;
189 $tableparams['search_country'] = $search_country;
190 $tableparams['subcat'] = ($subcat === true) ? 'yes' : '';
191 
192 // Adding common parameters
193 $allparams = array_merge($commonparams, $headerparams, $tableparams);
194 $headerparams = array_merge($commonparams, $headerparams);
195 $tableparams = array_merge($commonparams, $tableparams);
196 
197 $paramslink="";
198 foreach ($allparams as $key => $value) {
199  $paramslink .= '&'.$key.'='.$value;
200 }
201 
202 
203 /*
204  * View
205  */
206 
207 llxHeader();
208 
209 $form = new Form($db);
210 $thirdparty_static = new Societe($db);
211 $formother = new FormOther($db);
212 
213 // TODO Report from bookkeeping not yet available, so we switch on report on business events
214 if ($modecompta == "BOOKKEEPING") {
215  $modecompta = "CREANCES-DETTES";
216 }
217 if ($modecompta == "BOOKKEEPINGCOLLECTED") {
218  $modecompta = "RECETTES-DEPENSES";
219 }
220 
221 $exportlink="";
222 $namelink="";
223 
224 // Show report header
225 if ($modecompta == "CREANCES-DETTES") {
226  $name = $langs->trans("Turnover").', '.$langs->trans("ByThirdParties");
227  $calcmode = $langs->trans("CalcModeDebt");
228  //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
229  $description = $langs->trans("RulesCADue");
230  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
231  $description .= $langs->trans("DepositsAreNotIncluded");
232  } else {
233  $description .= $langs->trans("DepositsAreIncluded");
234  }
235  $builddate = dol_now();
236  //$exportlink=$langs->trans("NotYetAvailable");
237 } elseif ($modecompta == "RECETTES-DEPENSES") {
238  $name = $langs->trans("TurnoverCollected").', '.$langs->trans("ByThirdParties");
239  $calcmode = $langs->trans("CalcModeEngagement");
240  //$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
241  $description = $langs->trans("RulesCAIn");
242  $description .= $langs->trans("DepositsAreIncluded");
243  $builddate = dol_now();
244  //$exportlink=$langs->trans("NotYetAvailable");
245 } elseif ($modecompta == "BOOKKEEPING") {
246 } elseif ($modecompta == "BOOKKEEPINGCOLLECTED") {
247 }
248 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
249 $period .= ' - ';
250 $period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
251 if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) {
252  $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>';
253 } else {
254  $periodlink = '';
255 }
256 
257 report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
258 
259 if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
260  print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
261 }
262 
263 
264 $name = array();
265 
266 // Show Array
267 $catotal = 0;
268 $catotal_ht = 0;
269 
270 if ($modecompta == 'CREANCES-DETTES') {
271  $sql = "SELECT DISTINCT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays,";
272  $sql .= " sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
273  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
274  if ($selected_cat === -2) { // Without any category
275  $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
276  } elseif ($selected_cat) { // Into a specific category
277  $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
278  }
279  $sql .= " WHERE f.fk_statut in (1,2)";
280  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
281  $sql .= " AND f.type IN (0,1,2,5)";
282  } else {
283  $sql .= " AND f.type IN (0,1,2,3,5)";
284  }
285  $sql .= " AND f.fk_soc = s.rowid";
286  if ($date_start && $date_end) {
287  $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
288  }
289  if ($selected_cat === -2) { // Without any category
290  $sql .= " AND cs.fk_soc is null";
291  } elseif ($selected_cat) { // Into a specific category
292  $sql .= " AND (c.rowid = ".((int) $selected_cat);
293  if ($subcat) {
294  $sql .= " OR c.fk_parent = ".((int) $selected_cat);
295  }
296  $sql .= ")";
297  $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
298  }
299 } elseif ($modecompta == "RECETTES-DEPENSES") {
300  /*
301  * List of payments (old payments are not seen by this query because on older versions,
302  * they were not linked via the table llx_paiement_facture. They are added later)
303  */
304  $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";
305  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
306  $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
307  $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
308  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
309  if ($selected_cat === -2) { // Without any category
310  $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
311  } elseif ($selected_cat) { // Into a specific category
312  $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
313  }
314  $sql .= " WHERE p.rowid = pf.fk_paiement";
315  $sql .= " AND pf.fk_facture = f.rowid";
316  $sql .= " AND f.fk_soc = s.rowid";
317  if ($date_start && $date_end) {
318  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
319  }
320  if ($selected_cat === -2) { // Without any category
321  $sql .= " AND cs.fk_soc is null";
322  } elseif ($selected_cat) { // Into a specific category
323  $sql .= " AND (c.rowid = ".((int) $selected_cat);
324  if ($subcat) {
325  $sql .= " OR c.fk_parent = ".((int) $selected_cat);
326  }
327  $sql .= ")";
328  $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
329  }
330 } elseif ($modecompta == "BOOKKEEPING") {
331 } elseif ($modecompta == "BOOKKEEPINGCOLLECTED") {
332 }
333 if (!empty($search_societe)) {
334  $sql .= natural_search('s.nom', $search_societe);
335 }
336 if (!empty($search_zip)) {
337  $sql .= natural_search('s.zip', $search_zip);
338 }
339 if (!empty($search_town)) {
340  $sql .= natural_search('s.town', $search_town);
341 }
342 if ($search_country > 0) {
343  $sql .= ' AND s.fk_pays = '.((int) $search_country);
344 }
345 $sql .= " AND f.entity IN (".getEntity('invoice').")";
346 if ($socid) {
347  $sql .= " AND f.fk_soc = ".((int) $socid);
348 }
349 $sql .= " GROUP BY s.rowid, s.nom, s.name_alias, s.zip, s.town, s.fk_pays";
350 $sql .= " ORDER BY s.rowid";
351 //echo $sql;
352 
353 $amount = array();
354 
355 dol_syslog("casoc", LOG_DEBUG);
356 $result = $db->query($sql);
357 if ($result) {
358  $num = $db->num_rows($result);
359  $i = 0;
360  while ($i < $num) {
361  $obj = $db->fetch_object($result);
362  $amount_ht[$obj->socid] = $obj->amount;
363  $amount[$obj->socid] = $obj->amount_ttc;
364  $fullname = $obj->name;
365  if (!empty($obj->name_alias)) {
366  $fullname .= ' ('.$obj->name_alias.')';
367  }
368  $name[$obj->socid] = $fullname;
369  $address_zip[$obj->socid] = $obj->zip;
370  $address_town[$obj->socid] = $obj->town;
371  $address_pays[$obj->socid] = getCountry($obj->fk_pays);
372  $catotal_ht += $obj->amount;
373  $catotal += $obj->amount_ttc;
374  $i++;
375  }
376 } else {
377  dol_print_error($db);
378 }
379 
380 // We add the old versions of payments, not linked by table llx_paiement_facture
381 if ($modecompta == "RECETTES-DEPENSES") {
382  $sql = "SELECT '0' as socid, 'Autres' as name, sum(p.amount) as amount_ttc";
383  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
384  $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
385  $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
386  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
387  $sql .= " WHERE pf.rowid IS NULL";
388  $sql .= " AND p.fk_bank = b.rowid";
389  $sql .= " AND b.fk_account = ba.rowid";
390  $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
391  if ($date_start && $date_end) {
392  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
393  }
394  $sql .= " GROUP BY socid, name";
395  $sql .= " ORDER BY name";
396 
397  $result = $db->query($sql);
398  if ($result) {
399  $num = $db->num_rows($result);
400  $i = 0;
401  while ($i < $num) {
402  $obj = $db->fetch_object($result);
403  $amount[$obj->rowid] += $obj->amount_ttc;
404  $name[$obj->rowid] = $obj->name;
405  $address_zip[$obj->rowid] = $obj->zip;
406  $address_town[$obj->rowid] = $obj->town;
407  $address_pays[$obj->rowid] = getCountry($obj->fk_pays);
408  $catotal += $obj->amount_ttc;
409  $i++;
410  }
411  } else {
412  dol_print_error($db);
413  }
414 }
415 
416 
417 // Show array
418 $i = 0;
419 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
420 print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
421 // Extra parameters management
422 foreach ($headerparams as $key => $value) {
423  print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
424 }
425 
426 $moreforfilter = '';
427 
428 print '<div class="div-table-responsive">';
429 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
430 
431 // Category filter
432 print '<tr class="liste_titre">';
433 print '<td class="nowraponall">';
434 print img_picto('', 'category', 'class="paddingrightonly"');
435 print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat, 'search_categ', 0, $langs->trans("Category"));
436 print ' ';
437 print $langs->trans("SubCats").'? ';
438 print '<input type="checkbox" name="subcat" value="yes"';
439 if ($subcat) {
440  print ' checked';
441 }
442 print'></td>';
443 print '<td colspan="7" class="right">';
444 print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
445 print '</td>';
446 print '</tr>';
447 
448 print '<tr class="liste_titre">';
449 print '<td class="liste_titre left">';
450 print '<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
451 print '</td>';
452 print '<td class="liste_titre left">';
453 print '<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'">';
454 print '</td>';
455 print '<td class="liste_titre left">';
456 print '<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'">';
457 print '</td>';
458 print '<td class="liste_titre left">';
459 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
460 //print '<input class="flat" size="6" type="text" name="search_country" value="'.$search_country.'">';
461 print '</td>';
462 print '<td class="liste_titre">&nbsp;</td>';
463 print '<td class="liste_titre">&nbsp;</td>';
464 print '<td class="liste_titre">&nbsp;</td>';
465 print '<td class="liste_titre">&nbsp;</td>';
466 print '</tr>';
467 
468 // Array titles
469 print "<tr class='liste_titre'>";
471  $langs->trans("Company"),
472  $_SERVER["PHP_SELF"],
473  "nom",
474  "",
475  $paramslink,
476  "",
477  $sortfield,
478  $sortorder
479 );
481  $langs->trans("Zip"),
482  $_SERVER["PHP_SELF"],
483  "zip",
484  "",
485  $paramslink,
486  "",
487  $sortfield,
488  $sortorder
489 );
491  $langs->trans("Town"),
492  $_SERVER["PHP_SELF"],
493  "town",
494  "",
495  $paramslink,
496  "",
497  $sortfield,
498  $sortorder
499 );
501  $langs->trans("Country"),
502  $_SERVER["PHP_SELF"],
503  "country",
504  "",
505  $paramslink,
506  "",
507  $sortfield,
508  $sortorder
509 );
510 if ($modecompta == 'CREANCES-DETTES') {
512  $langs->trans('AmountHT'),
513  $_SERVER["PHP_SELF"],
514  "amount_ht",
515  "",
516  $paramslink,
517  'class="right"',
518  $sortfield,
519  $sortorder
520  );
521 } else {
523 }
525  $langs->trans("AmountTTC"),
526  $_SERVER["PHP_SELF"],
527  "amount_ttc",
528  "",
529  $paramslink,
530  'class="right"',
531  $sortfield,
532  $sortorder
533 );
535  $langs->trans("Percentage"),
536  $_SERVER["PHP_SELF"],
537  "amount_ttc",
538  "",
539  $paramslink,
540  'class="right"',
541  $sortfield,
542  $sortorder
543 );
545  $langs->trans("OtherStatistics"),
546  $_SERVER["PHP_SELF"],
547  "",
548  "",
549  "",
550  'align="center" width="20%"'
551 );
552 print "</tr>\n";
553 
554 
555 if (count($amount)) {
556  $arrayforsort = $name;
557  // Defining array arrayforsort
558  if ($sortfield == 'nom' && $sortorder == 'asc') {
559  asort($name);
560  $arrayforsort = $name;
561  }
562  if ($sortfield == 'nom' && $sortorder == 'desc') {
563  arsort($name);
564  $arrayforsort = $name;
565  }
566  if ($sortfield == 'amount_ht' && $sortorder == 'asc') {
567  asort($amount_ht);
568  $arrayforsort = $amount_ht;
569  }
570  if ($sortfield == 'amount_ht' && $sortorder == 'desc') {
571  arsort($amount_ht);
572  $arrayforsort = $amount_ht;
573  }
574  if ($sortfield == 'amount_ttc' && $sortorder == 'asc') {
575  asort($amount);
576  $arrayforsort = $amount;
577  }
578  if ($sortfield == 'amount_ttc' && $sortorder == 'desc') {
579  arsort($amount);
580  $arrayforsort = $amount;
581  }
582  if ($sortfield == 'zip' && $sortorder == 'asc') {
583  asort($address_zip);
584  $arrayforsort = $address_zip;
585  }
586  if ($sortfield == 'zip' && $sortorder == 'desc') {
587  arsort($address_zip);
588  $arrayforsort = $address_zip;
589  }
590  if ($sortfield == 'town' && $sortorder == 'asc') {
591  asort($address_town);
592  $arrayforsort = $address_town;
593  }
594  if ($sortfield == 'town' && $sortorder == 'desc') {
595  arsort($address_town);
596  $arrayforsort = $address_town;
597  }
598  if ($sortfield == 'country' && $sortorder == 'asc') {
599  asort($address_pays);
600  $arrayforsort = $address_town;
601  }
602  if ($sortfield == 'country' && $sortorder == 'desc') {
603  arsort($address_pays);
604  $arrayforsort = $address_town;
605  }
606 
607  foreach ($arrayforsort as $key => $value) {
608  print '<tr class="oddeven">';
609 
610  // Third party
611  $fullname = $name[$key];
612  if ($key > 0) {
613  $thirdparty_static->id = $key;
614  $thirdparty_static->name = $fullname;
615  $thirdparty_static->client = 1;
616  $linkname = $thirdparty_static->getNomUrl(1, 'customer');
617  } else {
618  $linkname = $langs->trans("PaymentsNotLinkedToInvoice");
619  }
620  print "<td>".$linkname."</td>\n";
621 
622  print '<td>';
623  print $address_zip[$key];
624  print '</td>';
625 
626  print '<td>';
627  print $address_town[$key];
628  print '</td>';
629 
630  print '<td>';
631  print $address_pays[$key];
632  print '</td>';
633 
634  // Amount w/o VAT
635  print '<td class="right">';
636  if ($modecompta != 'CREANCES-DETTES') {
637  if ($key > 0) {
638  print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid='.$key.'">';
639  } else {
640  print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid=-1">';
641  }
642  } else {
643  if ($key > 0) {
644  print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$key.'">';
645  } else {
646  print '<a href="#">';
647  }
648  print price($amount_ht[$key]);
649  }
650  print '</td>';
651 
652  // Amount with VAT
653  print '<td class="right">';
654  if ($modecompta != 'CREANCES-DETTES') {
655  if ($key > 0) {
656  print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid='.$key.'">';
657  } else {
658  print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?orphelins=1">';
659  }
660  } else {
661  if ($key > 0) {
662  print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$key.'">';
663  } else {
664  print '<a href="#">';
665  }
666  }
667  print price($amount[$key]);
668  print '</a>';
669  print '</td>';
670 
671  // Percent;
672  print '<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : '&nbsp;').'</td>';
673 
674  // Other stats
675  print '<td class="center">';
676  if (isModEnabled('propal') && $key > 0) {
677  print '&nbsp;<a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("ProposalStats"), "stats").'</a>&nbsp;';
678  }
679  if (isModEnabled('commande') && $key > 0) {
680  print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("OrderStats"), "stats").'</a>&nbsp;';
681  }
682  if (isModEnabled('facture') && $key > 0) {
683  print '&nbsp;<a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("InvoiceStats"), "stats").'</a>&nbsp;';
684  }
685  print '</td>';
686  print "</tr>\n";
687  $i++;
688  }
689 
690  // Total
691  print '<tr class="liste_total">';
692  print '<td>'.$langs->trans("Total").'</td>';
693  print '<td>&nbsp;</td>';
694  print '<td>&nbsp;</td>';
695  print '<td>&nbsp;</td>';
696  if ($modecompta != 'CREANCES-DETTES') {
697  print '<td></td>';
698  } else {
699  print '<td class="right">'.price($catotal_ht).'</td>';
700  }
701  print '<td class="right">'.price($catotal).'</td>';
702  print '<td>&nbsp;</td>';
703  print '<td>&nbsp;</td>';
704  print '</tr>';
705 
706  $db->free($result);
707 }
708 
709 print "</table>";
710 print "</div>";
711 
712 print '</form>';
713 
714 // End of page
715 llxFooter();
716 $db->close();
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2713
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
img_next
img_next($titlealt='default', $moreatt='')
Show next logo.
Definition: functions.lib.php:4557
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dol_get_first_day
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:551
dol_get_last_day
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:570
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4800
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
dol_time_plus_duree
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
natural_search
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...
Definition: functions.lib.php:9420
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
price
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.
Definition: functions.lib.php:5541
getCountry
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
Definition: company.lib.php:489
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
img_previous
img_previous($titlealt='default', $moreatt='')
Show previous logo.
Definition: functions.lib.php:4576
report_header
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
Definition: report.lib.php:41
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59