dolibarr 18.0.6
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) $selected_cat = '';
63$subcat = false;
64if (GETPOST('subcat', 'alpha') === 'yes') {
65 $subcat = true;
66}
67
68// Security check
69if ($user->socid > 0) {
70 $socid = $user->socid;
71}
72if (isModEnabled('comptabilite')) {
73 $result = restrictedArea($user, 'compta', '', '', 'resultat');
74}
75if (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');
95if (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
107if (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();
163if (!empty($date_startyear)) {
164 $headerparams['date_startyear'] = $date_startyear;
165}
166if (!empty($date_startmonth)) {
167 $headerparams['date_startmonth'] = $date_startmonth;
168}
169if (!empty($date_startday)) {
170 $headerparams['date_startday'] = $date_startday;
171}
172if (!empty($date_endyear)) {
173 $headerparams['date_endyear'] = $date_endyear;
174}
175if (!empty($date_endmonth)) {
176 $headerparams['date_endmonth'] = $date_endmonth;
177}
178if (!empty($date_endday)) {
179 $headerparams['date_endday'] = $date_endday;
180}
181if (!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="";
199foreach ($allparams as $key => $value) {
200 $paramslink .= '&'.$key.'='.$value;
201}
202
203
204/*
205 * View
206 */
207
208llxHeader();
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
215if ($modecompta == "BOOKKEEPING") {
216 $modecompta = "CREANCES-DETTES";
217}
218if ($modecompta == "BOOKKEEPINGCOLLECTED") {
219 $modecompta = "RECETTES-DEPENSES";
220}
221
222$exportlink="";
223$namelink="";
224
225// Show report header
226if ($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');
252if ($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
258report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
259
260if (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
271if ($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}
334if (!empty($search_societe)) {
335 $sql .= natural_search('s.nom', $search_societe);
336}
337if (!empty($search_zip)) {
338 $sql .= natural_search('s.zip', $search_zip);
339}
340if (!empty($search_town)) {
341 $sql .= natural_search('s.town', $search_town);
342}
343if ($search_country > 0) {
344 $sql .= ' AND s.fk_pays = '.((int) $search_country);
345}
346$sql .= " AND f.entity IN (".getEntity('invoice').")";
347if ($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
356dol_syslog("casoc", LOG_DEBUG);
357$result = $db->query($sql);
358if ($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
386if ($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 if (empty($amount[$obj->socid])) {
410 $amount[$obj->socid] = $obj->amount_ttc;
411 } else {
412 $amount[$obj->socid] += $obj->amount_ttc;
413 }
414
415 $name[$obj->socid] = $obj->name;
416 $address_zip[$obj->socid] = '';
417 $address_town[$obj->socid] = '';
418 $address_pays[$obj->socid] = 0;
419
420 $catotal += $obj->amount_ttc;
421
422 $i++;
423 }
424 } else {
425 dol_print_error($db);
426 }
427}
428
429
430// Show array
431$i = 0;
432print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
433print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
434// Extra parameters management
435foreach ($headerparams as $key => $value) {
436 print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
437}
438
439$moreforfilter = '';
440
441print '<div class="div-table-responsive">';
442print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
443
444// Category filter
445print '<tr class="liste_titre">';
446print '<td class="nowraponall">';
447print img_picto('', 'category', 'class="paddingrightonly"');
448print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat, 'search_categ', 0, $langs->trans("Category"));
449print ' ';
450print $langs->trans("SubCats").'? ';
451print '<input type="checkbox" name="subcat" value="yes"';
452if ($subcat) {
453 print ' checked';
454}
455print'></td>';
456print '<td colspan="7" class="right">';
457print '<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")).'">';
458print '</td>';
459print '</tr>';
460
461print '<tr class="liste_titre">';
462print '<td class="liste_titre left">';
463print '<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
464print '</td>';
465print '<td class="liste_titre left">';
466print '<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'">';
467print '</td>';
468print '<td class="liste_titre left">';
469print '<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'">';
470print '</td>';
471print '<td class="liste_titre left">';
472print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
473//print '<input class="flat" size="6" type="text" name="search_country" value="'.$search_country.'">';
474print '</td>';
475print '<td class="liste_titre">&nbsp;</td>';
476print '<td class="liste_titre">&nbsp;</td>';
477print '<td class="liste_titre">&nbsp;</td>';
478print '<td class="liste_titre">&nbsp;</td>';
479print '</tr>';
480
481// Array titles
482print "<tr class='liste_titre'>";
484 $langs->trans("Company"),
485 $_SERVER["PHP_SELF"],
486 "nom",
487 "",
488 $paramslink,
489 "",
490 $sortfield,
491 $sortorder
492);
494 $langs->trans("Zip"),
495 $_SERVER["PHP_SELF"],
496 "zip",
497 "",
498 $paramslink,
499 "",
500 $sortfield,
501 $sortorder
502);
504 $langs->trans("Town"),
505 $_SERVER["PHP_SELF"],
506 "town",
507 "",
508 $paramslink,
509 "",
510 $sortfield,
511 $sortorder
512);
514 $langs->trans("Country"),
515 $_SERVER["PHP_SELF"],
516 "country",
517 "",
518 $paramslink,
519 "",
520 $sortfield,
521 $sortorder
522);
523if ($modecompta == 'CREANCES-DETTES') {
525 $langs->trans('AmountHT'),
526 $_SERVER["PHP_SELF"],
527 "amount_ht",
528 "",
529 $paramslink,
530 'class="right"',
531 $sortfield,
532 $sortorder
533 );
534} else {
536}
538 $langs->trans("AmountTTC"),
539 $_SERVER["PHP_SELF"],
540 "amount_ttc",
541 "",
542 $paramslink,
543 'class="right"',
544 $sortfield,
545 $sortorder
546);
548 $langs->trans("Percentage"),
549 $_SERVER["PHP_SELF"],
550 "amount_ttc",
551 "",
552 $paramslink,
553 'class="right"',
554 $sortfield,
555 $sortorder
556);
558 $langs->trans("OtherStatistics"),
559 $_SERVER["PHP_SELF"],
560 "",
561 "",
562 "",
563 'align="center" width="20%"'
564);
565print "</tr>\n";
566
567
568if (count($amount)) {
569 $arrayforsort = $name;
570 // Defining array arrayforsort
571 if ($sortfield == 'nom' && $sortorder == 'asc') {
572 asort($name);
573 $arrayforsort = $name;
574 }
575 if ($sortfield == 'nom' && $sortorder == 'desc') {
576 arsort($name);
577 $arrayforsort = $name;
578 }
579 if ($sortfield == 'amount_ht' && $sortorder == 'asc') {
580 asort($amount_ht);
581 $arrayforsort = $amount_ht;
582 }
583 if ($sortfield == 'amount_ht' && $sortorder == 'desc') {
584 arsort($amount_ht);
585 $arrayforsort = $amount_ht;
586 }
587 if ($sortfield == 'amount_ttc' && $sortorder == 'asc') {
588 asort($amount);
589 $arrayforsort = $amount;
590 }
591 if ($sortfield == 'amount_ttc' && $sortorder == 'desc') {
592 arsort($amount);
593 $arrayforsort = $amount;
594 }
595 if ($sortfield == 'zip' && $sortorder == 'asc') {
596 asort($address_zip);
597 $arrayforsort = $address_zip;
598 }
599 if ($sortfield == 'zip' && $sortorder == 'desc') {
600 arsort($address_zip);
601 $arrayforsort = $address_zip;
602 }
603 if ($sortfield == 'town' && $sortorder == 'asc') {
604 asort($address_town);
605 $arrayforsort = $address_town;
606 }
607 if ($sortfield == 'town' && $sortorder == 'desc') {
608 arsort($address_town);
609 $arrayforsort = $address_town;
610 }
611 if ($sortfield == 'country' && $sortorder == 'asc') {
612 asort($address_pays);
613 $arrayforsort = $address_town;
614 }
615 if ($sortfield == 'country' && $sortorder == 'desc') {
616 arsort($address_pays);
617 $arrayforsort = $address_town;
618 }
619
620 foreach ($arrayforsort as $key => $value) {
621 print '<tr class="oddeven">';
622
623 // Third party
624 $fullname = $name[$key];
625 if ($key > 0) {
626 $thirdparty_static->id = $key;
627 $thirdparty_static->name = $fullname;
628 $thirdparty_static->client = 1;
629 $linkname = $thirdparty_static->getNomUrl(1, 'customer');
630 } else {
631 $linkname = $langs->trans("PaymentsNotLinkedToInvoice");
632 }
633 print "<td>".$linkname."</td>\n";
634
635 print '<td>';
636 print $address_zip[$key];
637 print '</td>';
638
639 print '<td>';
640 print $address_town[$key];
641 print '</td>';
642
643 print '<td>';
644 print $address_pays[$key];
645 print '</td>';
646
647 // Amount w/o VAT
648 print '<td class="right">';
649 if ($modecompta != 'CREANCES-DETTES') {
650 if ($key > 0) {
651 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid='.$key.'">';
652 } else {
653 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid=-1">';
654 }
655 } else {
656 if ($key > 0) {
657 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$key.'">';
658 } else {
659 print '<a href="#">';
660 }
661 print price($amount_ht[$key]);
662 }
663 print '</td>';
664
665 // Amount with VAT
666 print '<td class="right">';
667 if ($modecompta != 'CREANCES-DETTES') {
668 if ($key > 0) {
669 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid='.$key.'">';
670 } else {
671 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?orphelins=1">';
672 }
673 } else {
674 if ($key > 0) {
675 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$key.'">';
676 } else {
677 print '<a href="#">';
678 }
679 }
680 print price($amount[$key]);
681 print '</a>';
682 print '</td>';
683
684 // Percent;
685 print '<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : '&nbsp;').'</td>';
686
687 // Other stats
688 print '<td class="center">';
689 if (isModEnabled("propal") && $key > 0) {
690 print '&nbsp;<a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("ProposalStats"), "stats").'</a>&nbsp;';
691 }
692 if (isModEnabled('commande') && $key > 0) {
693 print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("OrderStats"), "stats").'</a>&nbsp;';
694 }
695 if (isModEnabled('facture') && $key > 0) {
696 print '&nbsp;<a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("InvoiceStats"), "stats").'</a>&nbsp;';
697 }
698 print '</td>';
699 print "</tr>\n";
700 $i++;
701 }
702
703 // Total
704 print '<tr class="liste_total">';
705 print '<td>'.$langs->trans("Total").'</td>';
706 print '<td>&nbsp;</td>';
707 print '<td>&nbsp;</td>';
708 print '<td>&nbsp;</td>';
709 if ($modecompta != 'CREANCES-DETTES') {
710 print '<td></td>';
711 } else {
712 print '<td class="right">'.price($catotal_ht).'</td>';
713 }
714 print '<td class="right">'.price($catotal).'</td>';
715 print '<td>&nbsp;</td>';
716 print '<td>&nbsp;</td>';
717 print '</tr>';
718
719 $db->free($result);
720}
721
722print "</table>";
723print "</div>";
724
725print '</form>';
726
727// End of page
728llxFooter();
729$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.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:578
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:123
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:597
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.
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.
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.