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