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