dolibarr 20.0.2
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 = getDolGlobalString('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 = GETPOSTINT('socid');
59
60// Category
61$selected_cat = GETPOSTINT('search_categ');
62if ($selected_cat == -1) {
63 $selected_cat = 0;
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 = GETPOSTINT("year");
86$month = GETPOSTINT("month");
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", 'aZ09');
91$date_startyear = GETPOSTINT("date_startyear");
92$date_startmonth = GETPOSTINT("date_startmonth");
93$date_startday = GETPOSTINT("date_startday");
94$date_endyear = GETPOSTINT("date_endyear");
95$date_endmonth = GETPOSTINT("date_endmonth");
96$date_endday = GETPOSTINT("date_endday");
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 = GETPOSTINT("q") ? GETPOSTINT("q") : 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("CalcModePayment");
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$amount_ht = array();
358$address_zip = array();
359$address_town = array();
360$address_pays = array();
361
362dol_syslog("casoc", LOG_DEBUG);
363$result = $db->query($sql);
364if ($result) {
365 $num = $db->num_rows($result);
366 $i = 0;
367 while ($i < $num) {
368 $obj = $db->fetch_object($result);
369
370 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
371 $amount[$obj->socid] = $obj->amount_ttc;
372 $fullname = $obj->name;
373 if (!empty($obj->name_alias)) {
374 $fullname .= ' ('.$obj->name_alias.')';
375 }
376 $name[$obj->socid] = $fullname;
377
378 $address_zip[$obj->socid] = $obj->zip;
379 $address_town[$obj->socid] = $obj->town;
380 $address_pays[$obj->socid] = getCountry($obj->fk_pays);
381
382 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
383 $catotal += $obj->amount_ttc;
384
385 $i++;
386 }
387} else {
388 dol_print_error($db);
389}
390
391// We add the old versions of payments, not linked by table llx_paiement_facture
392if ($modecompta == "RECETTES-DEPENSES") {
393 $sql = "SELECT '0' as socid, 'Autres' as name, sum(p.amount) as amount_ttc";
394 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
395 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
396 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
397 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
398 $sql .= " WHERE pf.rowid IS NULL";
399 $sql .= " AND p.fk_bank = b.rowid";
400 $sql .= " AND b.fk_account = ba.rowid";
401 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
402 if ($date_start && $date_end) {
403 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
404 }
405 $sql .= " GROUP BY socid, name";
406 $sql .= " ORDER BY name";
407
408 $result = $db->query($sql);
409 if ($result) {
410 $num = $db->num_rows($result);
411 $i = 0;
412 while ($i < $num) {
413 $obj = $db->fetch_object($result);
414
415 if (empty($amount[$obj->socid])) {
416 $amount[$obj->socid] = $obj->amount_ttc;
417 } else {
418 $amount[$obj->socid] += $obj->amount_ttc;
419 }
420
421 $name[$obj->socid] = $obj->name;
422 $address_zip[$obj->socid] = '';
423 $address_town[$obj->socid] = '';
424 $address_pays[$obj->socid] = '';
425
426 $catotal += $obj->amount_ttc;
427
428 $i++;
429 }
430 } else {
431 dol_print_error($db);
432 }
433}
434
435
436// Show array
437$i = 0;
438print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
439print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
440// Extra parameters management
441foreach ($headerparams as $key => $value) {
442 print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
443}
444
445$moreforfilter = '';
446
447print '<div class="div-table-responsive">';
448print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
449
450// Category filter
451print '<tr class="liste_titre">';
452print '<td class="nowraponall">';
453print img_picto('', 'category', 'class="paddingrightonly"');
454print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat, 'search_categ', 0, $langs->trans("Category"));
455print ' ';
456print $langs->trans("SubCats").'? ';
457print '<input type="checkbox" name="subcat" value="yes"';
458if ($subcat) {
459 print ' checked';
460}
461print'></td>';
462print '<td colspan="7" class="right">';
463print '<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")).'">';
464print '</td>';
465print '</tr>';
466
467print '<tr class="liste_titre">';
468print '<td class="liste_titre left">';
469print '<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
470print '</td>';
471print '<td class="liste_titre left">';
472print '<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'">';
473print '</td>';
474print '<td class="liste_titre left">';
475print '<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'">';
476print '</td>';
477print '<td class="liste_titre left">';
478print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
479//print '<input class="flat" size="6" type="text" name="search_country" value="'.$search_country.'">';
480print '</td>';
481print '<td class="liste_titre">&nbsp;</td>';
482print '<td class="liste_titre">&nbsp;</td>';
483print '<td class="liste_titre">&nbsp;</td>';
484print '<td class="liste_titre">&nbsp;</td>';
485print '</tr>';
486
487// Array titles
488print "<tr class='liste_titre'>";
490 $langs->trans("Company"),
491 $_SERVER["PHP_SELF"],
492 "nom",
493 "",
494 $paramslink,
495 "",
496 $sortfield,
497 $sortorder
498);
500 $langs->trans("Zip"),
501 $_SERVER["PHP_SELF"],
502 "zip",
503 "",
504 $paramslink,
505 "",
506 $sortfield,
507 $sortorder
508);
510 $langs->trans("Town"),
511 $_SERVER["PHP_SELF"],
512 "town",
513 "",
514 $paramslink,
515 "",
516 $sortfield,
517 $sortorder
518);
520 $langs->trans("Country"),
521 $_SERVER["PHP_SELF"],
522 "country",
523 "",
524 $paramslink,
525 "",
526 $sortfield,
527 $sortorder
528);
529if ($modecompta == 'CREANCES-DETTES') {
531 $langs->trans('AmountHT'),
532 $_SERVER["PHP_SELF"],
533 "amount_ht",
534 "",
535 $paramslink,
536 'class="right"',
537 $sortfield,
538 $sortorder
539 );
540} else {
542}
544 $langs->trans("AmountTTC"),
545 $_SERVER["PHP_SELF"],
546 "amount_ttc",
547 "",
548 $paramslink,
549 'class="right"',
550 $sortfield,
551 $sortorder
552);
554 $langs->trans("Percentage"),
555 $_SERVER["PHP_SELF"],
556 "amount_ttc",
557 "",
558 $paramslink,
559 'class="right"',
560 $sortfield,
561 $sortorder
562);
564 $langs->trans("OtherStatistics"),
565 $_SERVER["PHP_SELF"],
566 "",
567 "",
568 "",
569 'align="center" width="20%"'
570);
571print "</tr>\n";
572
573
574if (count($amount)) {
575 $arrayforsort = $name;
576 // Defining array arrayforsort
577 if ($sortfield == 'nom' && $sortorder == 'asc') {
578 asort($name);
579 $arrayforsort = $name;
580 }
581 if ($sortfield == 'nom' && $sortorder == 'desc') {
582 arsort($name);
583 $arrayforsort = $name;
584 }
585 if ($sortfield == 'amount_ht' && $sortorder == 'asc') {
586 asort($amount_ht);
587 $arrayforsort = $amount_ht;
588 }
589 if ($sortfield == 'amount_ht' && $sortorder == 'desc') {
590 arsort($amount_ht);
591 $arrayforsort = $amount_ht;
592 }
593 if ($sortfield == 'amount_ttc' && $sortorder == 'asc') {
594 asort($amount);
595 $arrayforsort = $amount;
596 }
597 if ($sortfield == 'amount_ttc' && $sortorder == 'desc') {
598 arsort($amount);
599 $arrayforsort = $amount;
600 }
601 if ($sortfield == 'zip' && $sortorder == 'asc') {
602 asort($address_zip);
603 $arrayforsort = $address_zip;
604 }
605 if ($sortfield == 'zip' && $sortorder == 'desc') {
606 arsort($address_zip);
607 $arrayforsort = $address_zip;
608 }
609 if ($sortfield == 'town' && $sortorder == 'asc') {
610 asort($address_town);
611 $arrayforsort = $address_town;
612 }
613 if ($sortfield == 'town' && $sortorder == 'desc') {
614 arsort($address_town);
615 $arrayforsort = $address_town;
616 }
617 if ($sortfield == 'country' && $sortorder == 'asc') {
618 asort($address_pays);
619 $arrayforsort = $address_town;
620 }
621 if ($sortfield == 'country' && $sortorder == 'desc') {
622 arsort($address_pays);
623 $arrayforsort = $address_town;
624 }
625
626 foreach ($arrayforsort as $key => $value) {
627 print '<tr class="oddeven">';
628
629 // Third party
630 $fullname = $name[$key];
631 if ($key > 0) {
632 $thirdparty_static->id = $key;
633 $thirdparty_static->name = $fullname;
634 $thirdparty_static->client = 1;
635 $linkname = $thirdparty_static->getNomUrl(1, 'customer');
636 } else {
637 $linkname = $langs->trans("PaymentsNotLinkedToInvoice");
638 }
639 print '<td class="tdoverflowmax150">'.$linkname."</td>\n";
640
641 print '<td>';
642 print $address_zip[$key];
643 print '</td>';
644
645 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_town[$key]).'">';
646 print $address_town[$key];
647 print '</td>';
648
649 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_pays[$key]).'">';
650 print $address_pays[$key];
651 print '</td>';
652
653 // Amount w/o VAT
654 print '<td class="right">';
655 if ($modecompta != 'CREANCES-DETTES') {
656 if ($key > 0) {
657 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid='.$key.'">';
658 } else {
659 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid=-1">';
660 }
661 } else {
662 if ($key > 0) {
663 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$key.'">';
664 } else {
665 print '<a href="#">';
666 }
667 print price($amount_ht[$key]);
668 }
669 print '</td>';
670
671 // Amount with VAT
672 print '<td class="right">';
673 if ($modecompta != 'CREANCES-DETTES') {
674 if ($key > 0) {
675 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid='.$key.'">';
676 } else {
677 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?orphelins=1">';
678 }
679 } else {
680 if ($key > 0) {
681 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$key.'">';
682 } else {
683 print '<a href="#">';
684 }
685 }
686 print price($amount[$key]);
687 print '</a>';
688 print '</td>';
689
690 // Percent;
691 print '<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : '&nbsp;').'</td>';
692
693 // Other stats
694 print '<td class="center">';
695 if (isModEnabled("propal") && $key > 0) {
696 print '&nbsp;<a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("ProposalStats"), "stats").'</a>&nbsp;';
697 }
698 if (isModEnabled('order') && $key > 0) {
699 print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("OrderStats"), "stats").'</a>&nbsp;';
700 }
701 if (isModEnabled('invoice') && $key > 0) {
702 print '&nbsp;<a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("InvoiceStats"), "stats").'</a>&nbsp;';
703 }
704 print '</td>';
705 print "</tr>\n";
706 $i++;
707 }
708
709 // Total
710 print '<tr class="liste_total">';
711 print '<td>'.$langs->trans("Total").'</td>';
712 print '<td>&nbsp;</td>';
713 print '<td>&nbsp;</td>';
714 print '<td>&nbsp;</td>';
715 if ($modecompta != 'CREANCES-DETTES') {
716 print '<td></td>';
717 } else {
718 print '<td class="right">'.price($catotal_ht).'</td>';
719 }
720 print '<td class="right">'.price($catotal).'</td>';
721 print '<td>&nbsp;</td>';
722 print '<td>&nbsp;</td>';
723 print '</tr>';
724
725 $db->free($result);
726}
727
728print "</table>";
729print "</div>";
730
731print '</form>';
732
733// End of page
734llxFooter();
735$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.
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:595
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:614
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 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.