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