dolibarr 25.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-2026 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
10 * Copyright (C) 2024-2026 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';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
47require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
48
49// Load translation files required by the page
50$langs->loadLangs(array('companies', 'categories', 'bills', 'compta'));
51
52// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
53$modecompta = getDolGlobalString('ACCOUNTING_MODE');
54if (GETPOST("modecompta")) {
55 $modecompta = GETPOST("modecompta");
56}
57
58$sortorder = GETPOST("sortorder", 'aZ09comma');
59$sortfield = GETPOST("sortfield", 'aZ09comma');
60if (!$sortorder) {
61 $sortorder = "asc";
62}
63if (!$sortfield) {
64 $sortfield = "nom";
65}
66
67$socid = GETPOSTINT('socid');
68
69// Category
70$selected_cat = GETPOSTINT('search_categ');
71if ($selected_cat == -1) {
72 $selected_cat = 0;
73}
74$subcat = false;
75if (GETPOST('subcat', 'alpha') === 'yes') {
76 $subcat = true;
77}
78
79// Security check
80if ($user->socid > 0) {
81 $socid = $user->socid;
82}
83
84// Hook
85$hookmanager->initHooks(array('casoclist'));
86
87if (isModEnabled('comptabilite')) {
88 $result = restrictedArea($user, 'compta', '', '', 'resultat');
89}
90if (isModEnabled('accounting')) {
91 $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
92}
93
94// Date range
95$year = GETPOSTINT("year");
96$month = GETPOSTINT("month");
97$search_societe = GETPOST("search_societe", 'alpha');
98$search_zip = GETPOST("search_zip", 'alpha');
99$search_town = GETPOST("search_town", 'alpha');
100$search_country = GETPOST("search_country", 'aZ09');
101$date_startyear = GETPOSTINT("date_startyear");
102$date_startmonth = GETPOSTINT("date_startmonth");
103$date_startday = GETPOSTINT("date_startday");
104$date_endyear = GETPOSTINT("date_endyear");
105$date_endmonth = GETPOSTINT("date_endmonth");
106$date_endday = GETPOSTINT("date_endday");
107if (empty($year)) {
108 $year_current = dol_print_date(dol_now(), '%Y');
109 $month_current = dol_print_date(dol_now(), '%m');
110 $year_start = $year_current;
111} else {
112 $year_current = $year;
113 $month_current = dol_print_date(dol_now(), '%m');
114 $year_start = $year;
115}
116$date_start = dol_mktime(0, 0, 0, GETPOSTINT("date_startmonth"), GETPOSTINT("date_startday"), GETPOSTINT("date_startyear"), 'tzserver'); // We use timezone of server so report is same from everywhere
117$date_end = dol_mktime(23, 59, 59, GETPOSTINT("date_endmonth"), GETPOSTINT("date_endday"), GETPOSTINT("date_endyear"), 'tzserver'); // We use timezone of server so report is same from everywhere
118// Quarter
119if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
120 $q = GETPOSTINT("q") ? GETPOSTINT("q") : 0;
121 if (empty($q)) {
122 // We define date_start and date_end
123 $month_start = GETPOST("month") ? GETPOST("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
124 $year_end = $year_start;
125 $month_end = $month_start;
126 if (!GETPOST("month")) { // If month not forced
127 if (!GETPOST('year') && $month_start > $month_current) {
128 $year_start--;
129 $year_end--;
130 }
131 $month_end = $month_start - 1;
132 if ($month_end < 1) {
133 $month_end = 12;
134 } else {
135 $year_end++;
136 }
137 }
138 $date_start = dol_get_first_day($year_start, $month_start, false);
139 $date_end = dol_get_last_day($year_end, $month_end, false);
140 }
141 if ($q == 1) {
142 $date_start = dol_get_first_day($year_start, 1, false);
143 $date_end = dol_get_last_day($year_start, 3, false);
144 }
145 if ($q == 2) {
146 $date_start = dol_get_first_day($year_start, 4, false);
147 $date_end = dol_get_last_day($year_start, 6, false);
148 }
149 if ($q == 3) {
150 $date_start = dol_get_first_day($year_start, 7, false);
151 $date_end = dol_get_last_day($year_start, 9, false);
152 }
153 if ($q == 4) {
154 $date_start = dol_get_first_day($year_start, 10, false);
155 $date_end = dol_get_last_day($year_start, 12, false);
156 }
157} else {
158 // TODO We define q
159}
160//print dol_print_date($date_start, 'dayhour', 'gmt');
161
162// $date_start and $date_end are defined. We force $year_start and $nbofyear
163$tmps = dol_getdate($date_start);
164$year_start = $tmps['year'];
165$tmpe = dol_getdate($date_end);
166$year_end = $tmpe['year'];
167$nbofyear = ($year_end - $year_start) + 1;
168
169$commonparams = array();
170$commonparams['modecompta'] = $modecompta;
171$commonparams['sortorder'] = $sortorder;
172$commonparams['sortfield'] = $sortfield;
173
174$headerparams = array();
175if (!empty($date_startyear)) {
176 $headerparams['date_startyear'] = $date_startyear;
177}
178if (!empty($date_startmonth)) {
179 $headerparams['date_startmonth'] = $date_startmonth;
180}
181if (!empty($date_startday)) {
182 $headerparams['date_startday'] = $date_startday;
183}
184if (!empty($date_endyear)) {
185 $headerparams['date_endyear'] = $date_endyear;
186}
187if (!empty($date_endmonth)) {
188 $headerparams['date_endmonth'] = $date_endmonth;
189}
190if (!empty($date_endday)) {
191 $headerparams['date_endday'] = $date_endday;
192}
193if (!empty($q)) {
194 $headerparams['q'] = $q;
195}
196
197$tableparams = array();
198$tableparams['search_categ'] = $selected_cat;
199$tableparams['search_societe'] = $search_societe;
200$tableparams['search_zip'] = $search_zip;
201$tableparams['search_town'] = $search_town;
202$tableparams['search_country'] = $search_country;
203$tableparams['subcat'] = $subcat ? 'yes' : '';
204
205// Adding common parameters
206$allparams = array_merge($commonparams, $headerparams, $tableparams);
207$headerparams = array_merge($commonparams, $headerparams);
208$tableparams = array_merge($commonparams, $tableparams);
209
210$paramslink = "";
211foreach ($allparams as $key => $value) {
212 $paramslink .= '&'.$key.'='.$value;
213}
214
215
216/*
217 * View
218 */
219
220llxHeader();
221
222$form = new Form($db);
223$thirdparty_static = new Societe($db);
224$formother = new FormOther($db);
225
226if ($modecompta == "BOOKKEEPINGCOLLECTED") {
227 $modecompta = "RECETTES-DEPENSES";
228}
229
230$exportlink = "";
231$namelink = "";
232$builddate = 0;
233$calcmode = '';
234$name = '';
235$description = '';
236
237// Show report header
238if ($modecompta == "CREANCES-DETTES") {
239 $name = $langs->trans("Turnover").', '.$langs->trans("ByThirdParties");
240 $calcmode = $langs->trans("CalcModeDebt");
241 //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
242 $description = $langs->trans("RulesCADue");
243 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
244 $description .= $langs->trans("DepositsAreNotIncluded");
245 } else {
246 $description .= $langs->trans("DepositsAreIncluded");
247 }
248 $builddate = dol_now();
249 //$exportlink=$langs->trans("NotYetAvailable");
250} elseif ($modecompta == "RECETTES-DEPENSES") {
251 $name = $langs->trans("TurnoverCollected").', '.$langs->trans("ByThirdParties");
252 $calcmode = $langs->trans("CalcModePayment");
253 //$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
254 $description = $langs->trans("RulesCAIn");
255 $description .= $langs->trans("DepositsAreIncluded");
256 $builddate = dol_now();
257 //$exportlink=$langs->trans("NotYetAvailable");
258} elseif ($modecompta == "BOOKKEEPING") {
259 $name = $langs->trans("Turnover").', '.$langs->trans("ByThirdParties");
260 $calcmode = $langs->trans("CalcModeBookkeeping");
261 $description = $langs->trans("RulesCADue");
262 $builddate = dol_now();
263} // elseif ($modecompta == "BOOKKEEPINGCOLLECTED") {
264// }
265$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
266$period .= ' - ';
267$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
268if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) {
269 $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>';
270} else {
271 $periodlink = '';
272}
273
274report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
275
276if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
277 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
278}
279
280
281$name = array();
282
283// Show Array
284$catotal = 0;
285$catotal_ht = 0;
286$sql = '';
287
288if ($modecompta == 'CREANCES-DETTES') {
289 $sql = "SELECT DISTINCT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays,";
290 $sql .= " sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
291 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
292 if ($selected_cat === -2) { // Without any category
293 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
294 } elseif ($selected_cat) { // Into a specific category
295 $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
296 }
297 $sql .= " WHERE f.fk_statut in (1,2)";
298 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
299 $sql .= " AND f.type IN (0,1,2,5)";
300 } else {
301 $sql .= " AND f.type IN (0,1,2,3,5)";
302 }
303 $sql .= " AND f.fk_soc = s.rowid";
304 if ($date_start && $date_end) {
305 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
306 }
307 if ($selected_cat === -2) { // Without any category
308 $sql .= " AND cs.fk_soc is null";
309 } elseif ($selected_cat) { // Into a specific category
310 $sql .= " AND (c.rowid = ".((int) $selected_cat);
311 if ($subcat) {
312 $sql .= " OR c.fk_parent = ".((int) $selected_cat);
313 }
314 $sql .= ")";
315 $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
316 }
317} elseif ($modecompta == "RECETTES-DEPENSES") {
318 /*
319 * List of payments (old payments are not seen by this query because on older versions,
320 * they were not linked via the table llx_paiement_facture. They are added later)
321 */
322 $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";
323 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
324 $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
325 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
326 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
327 if ($selected_cat === -2) { // Without any category
328 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
329 } elseif ($selected_cat) { // Into a specific category
330 $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
331 }
332 $sql .= " WHERE p.rowid = pf.fk_paiement";
333 $sql .= " AND pf.fk_facture = f.rowid";
334 $sql .= " AND f.fk_soc = s.rowid";
335 if ($date_start && $date_end) {
336 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
337 }
338 if ($selected_cat === -2) { // Without any category
339 $sql .= " AND cs.fk_soc is null";
340 } elseif ($selected_cat) { // Into a specific category
341 $sql .= " AND (c.rowid = ".((int) $selected_cat);
342 if ($subcat) {
343 $sql .= " OR c.fk_parent = ".((int) $selected_cat);
344 }
345 $sql .= ")";
346 $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
347 }
348} elseif ($modecompta == "BOOKKEEPING") {
349 // Turnover computed from the accounting ledger (llx_accounting_bookkeeping): HT is the sum of
350 // postings on INCOME-type accounts, TTC is the amount posted on the thirdparty subledger line
351 // (the customer control account line of each invoice), matched back to the thirdparty by
352 // thirdparty_code (set at transfer time from societe.code_client, see accountancy/journal/sellsjournal.php).
353 $charofaccountstring = dol_getIdFromCode($db, getDolGlobalString('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
354
355 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays,";
356 $sql .= " SUM(CASE WHEN b.subledger_account IS NOT NULL AND b.subledger_account != '' THEN b.debit - b.credit ELSE 0 END) as amount_ttc,";
357 $sql .= " SUM(CASE WHEN aa.pcg_type = 'INCOME' THEN b.credit - b.debit ELSE 0 END) as amount";
358 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b";
359 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.account_number = b.numero_compte AND aa.entity = b.entity AND aa.fk_pcg_version = '".$db->escape($charofaccountstring)."'";
360 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.code_client = b.thirdparty_code";
361 if ($selected_cat === -2) { // Without any category
362 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
363 } elseif ($selected_cat) { // Into a specific category
364 $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
365 }
366 $sql .= " WHERE b.doc_type = 'customer_invoice'";
367 $sql .= " AND b.thirdparty_code IS NOT NULL AND b.thirdparty_code != ''";
368 if ($date_start && $date_end) {
369 $sql .= " AND b.doc_date >= '".$db->idate($date_start)."' AND b.doc_date <= '".$db->idate($date_end)."'";
370 }
371 if ($selected_cat === -2) { // Without any category
372 $sql .= " AND cs.fk_soc is null";
373 } elseif ($selected_cat) { // Into a specific category
374 $sql .= " AND (c.rowid = ".((int) $selected_cat);
375 if ($subcat) {
376 $sql .= " OR c.fk_parent = ".((int) $selected_cat);
377 }
378 $sql .= ")";
379 $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
380 }
381}
382if (!empty($search_societe)) {
383 $sql .= natural_search('s.nom', $search_societe);
384}
385if (!empty($search_zip)) {
386 $sql .= natural_search('s.zip', $search_zip);
387}
388if (!empty($search_town)) {
389 $sql .= natural_search('s.town', $search_town);
390}
391if ($search_country > 0) {
392 $sql .= ' AND s.fk_pays = '.((int) $search_country);
393}
394if ($modecompta == 'BOOKKEEPING') {
395 $sql .= " AND b.entity = ".((int) $conf->entity);
396 if ($socid) {
397 $sql .= " AND s.rowid = ".((int) $socid);
398 }
399} else {
400 $sql .= " AND f.entity IN (".getEntity('invoice').")";
401 if ($socid) {
402 $sql .= " AND f.fk_soc = ".((int) $socid);
403 }
404}
405$sql .= " GROUP BY s.rowid, s.nom, s.name_alias, s.zip, s.town, s.fk_pays";
406$sql .= " ORDER BY s.rowid";
407//echo $sql;
408
409$amount = array();
410$amount_ht = array();
411$address_zip = array();
412$address_town = array();
413$address_pays = array();
414
415dol_syslog("casoc", LOG_DEBUG);
416$result = $db->query($sql);
417if ($result) {
418 $num = $db->num_rows($result);
419 $i = 0;
420 while ($i < $num) {
421 $obj = $db->fetch_object($result);
422
423 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
424 $amount[$obj->socid] = $obj->amount_ttc;
425 $fullname = $obj->name;
426 if (!empty($obj->name_alias)) {
427 $fullname .= ' ('.$obj->name_alias.')';
428 }
429 $name[$obj->socid] = $fullname;
430
431 $address_zip[$obj->socid] = $obj->zip;
432 $address_town[$obj->socid] = $obj->town;
433 $address_pays[$obj->socid] = getCountry($obj->fk_pays);
434
435 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
436 $catotal += $obj->amount_ttc;
437
438 $i++;
439 }
440} else {
442}
443
444// We add the old versions of payments, not linked by table llx_paiement_facture
445if ($modecompta == "RECETTES-DEPENSES") {
446 $sql = "SELECT '0' as socid, 'Autres' as name, sum(p.amount) as amount_ttc";
447 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
448 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
449 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
450 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
451 $sql .= " WHERE pf.rowid IS NULL";
452 $sql .= " AND p.fk_bank = b.rowid";
453 $sql .= " AND b.fk_account = ba.rowid";
454 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
455 if ($date_start && $date_end) {
456 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
457 }
458 $sql .= " GROUP BY socid, name";
459 $sql .= " ORDER BY name";
460
461 $result = $db->query($sql);
462 if ($result) {
463 $num = $db->num_rows($result);
464 $i = 0;
465 while ($i < $num) {
466 $obj = $db->fetch_object($result);
467
468 if (empty($amount[$obj->socid])) {
469 $amount[$obj->socid] = $obj->amount_ttc;
470 } else {
471 $amount[$obj->socid] += $obj->amount_ttc;
472 }
473
474 $name[$obj->socid] = $obj->name;
475 $address_zip[$obj->socid] = '';
476 $address_town[$obj->socid] = '';
477 $address_pays[$obj->socid] = '';
478
479 $catotal += $obj->amount_ttc;
480
481 $i++;
482 }
483 } else {
485 }
486}
487
488
489// Show array
490$i = 0;
491print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
492print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
493// Extra parameters management
494foreach ($headerparams as $key => $value) {
495 print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
496}
497
498$moreforfilter = '';
499
500print '<div class="div-table-responsive">';
501print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
502
503// Category filter
504print '<tr class="liste_titre">';
505print '<td class="nowraponall">';
506print img_picto('', 'category', 'class="paddingrightonly"');
507print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat, 'search_categ', 0, $langs->trans("Category"));
508print ' ';
509print $langs->trans("SubCats").'? ';
510print '<input type="checkbox" name="subcat" value="yes"';
511if ($subcat) {
512 print ' checked';
513}
514print'></td>';
515print '<td colspan="7" class="right">';
516print '<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")).'">';
517print '</td>';
518print '</tr>';
519
520print '<tr class="liste_titre">';
521print '<td class="liste_titre left">';
522print '<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
523print '</td>';
524print '<td class="liste_titre left">';
525print '<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'">';
526print '</td>';
527print '<td class="liste_titre left">';
528print '<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'">';
529print '</td>';
530print '<td class="liste_titre left">';
531print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
532//print '<input class="flat" size="6" type="text" name="search_country" value="'.$search_country.'">';
533print '</td>';
534print '<td class="liste_titre">&nbsp;</td>';
535print '<td class="liste_titre">&nbsp;</td>';
536print '<td class="liste_titre">&nbsp;</td>';
537print '<td class="liste_titre">&nbsp;</td>';
538print '</tr>';
539
540// Array titles
541print "<tr class='liste_titre'>";
543 $langs->trans("Company"),
544 $_SERVER["PHP_SELF"],
545 "nom",
546 "",
547 $paramslink,
548 "",
549 $sortfield,
550 $sortorder
551);
553 $langs->trans("Zip"),
554 $_SERVER["PHP_SELF"],
555 "zip",
556 "",
557 $paramslink,
558 "",
559 $sortfield,
560 $sortorder
561);
563 $langs->trans("Town"),
564 $_SERVER["PHP_SELF"],
565 "town",
566 "",
567 $paramslink,
568 "",
569 $sortfield,
570 $sortorder
571);
573 $langs->trans("Country"),
574 $_SERVER["PHP_SELF"],
575 "country",
576 "",
577 $paramslink,
578 "",
579 $sortfield,
580 $sortorder
581);
582if ($modecompta == 'CREANCES-DETTES') {
584 $langs->trans('AmountHT'),
585 $_SERVER["PHP_SELF"],
586 "amount_ht",
587 "",
588 $paramslink,
589 'class="right"',
590 $sortfield,
591 $sortorder
592 );
593} else {
595}
597 $langs->trans("AmountTTC"),
598 $_SERVER["PHP_SELF"],
599 "amount_ttc",
600 "",
601 $paramslink,
602 'class="right"',
603 $sortfield,
604 $sortorder
605);
607 $langs->trans("Percentage"),
608 $_SERVER["PHP_SELF"],
609 "amount_ttc",
610 "",
611 $paramslink,
612 'class="right"',
613 $sortfield,
614 $sortorder
615);
617 $langs->trans("OtherStatistics"),
618 $_SERVER["PHP_SELF"],
619 "",
620 "",
621 "",
622 'align="center" width="20%"'
623);
624print "</tr>\n";
625
626
627if (count($amount)) {
628 $arrayforsort = $name;
629 // Defining array arrayforsort
630 if ($sortfield == 'nom' && $sortorder == 'asc') {
631 asort($name);
632 $arrayforsort = $name;
633 }
634 if ($sortfield == 'nom' && $sortorder == 'desc') {
635 arsort($name);
636 $arrayforsort = $name;
637 }
638 if ($sortfield == 'amount_ht' && $sortorder == 'asc') {
639 asort($amount_ht);
640 $arrayforsort = $amount_ht;
641 }
642 if ($sortfield == 'amount_ht' && $sortorder == 'desc') {
643 arsort($amount_ht);
644 $arrayforsort = $amount_ht;
645 }
646 if ($sortfield == 'amount_ttc' && $sortorder == 'asc') {
647 asort($amount);
648 $arrayforsort = $amount;
649 }
650 if ($sortfield == 'amount_ttc' && $sortorder == 'desc') {
651 arsort($amount);
652 $arrayforsort = $amount;
653 }
654 if ($sortfield == 'zip' && $sortorder == 'asc') {
655 asort($address_zip);
656 $arrayforsort = $address_zip;
657 }
658 if ($sortfield == 'zip' && $sortorder == 'desc') {
659 arsort($address_zip);
660 $arrayforsort = $address_zip;
661 }
662 if ($sortfield == 'town' && $sortorder == 'asc') {
663 asort($address_town);
664 $arrayforsort = $address_town;
665 }
666 if ($sortfield == 'town' && $sortorder == 'desc') {
667 arsort($address_town);
668 $arrayforsort = $address_town;
669 }
670 if ($sortfield == 'country' && $sortorder == 'asc') {
671 asort($address_pays);
672 $arrayforsort = $address_town;
673 }
674 if ($sortfield == 'country' && $sortorder == 'desc') {
675 arsort($address_pays);
676 $arrayforsort = $address_town;
677 }
678
679 foreach ($arrayforsort as $key => $value) {
680 print '<tr class="oddeven">';
681
682 // Third party
683 $fullname = $name[$key];
684 if ($key > 0) {
685 $thirdparty_static->id = (int) $key;
686 $thirdparty_static->name = $fullname;
687 $thirdparty_static->client = 1;
688 $linkname = $thirdparty_static->getNomUrl(1, 'customer');
689 } else {
690 $linkname = $langs->trans("PaymentsNotLinkedToInvoice");
691 }
692 print '<td class="tdoverflowmax150">'.$linkname."</td>\n";
693
694 print '<td>';
695 print $address_zip[$key];
696 print '</td>';
697
698 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_town[$key]).'">';
699 print $address_town[$key];
700 print '</td>';
701
702 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_pays[$key]).'">';
703 print $address_pays[$key];
704 print '</td>';
705
706 // Amount w/o VAT
707 print '<td class="right">';
708 if ($modecompta == 'RECETTES-DEPENSES') {
709 if ($key > 0) {
710 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid='.$key.'">';
711 } else {
712 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid=-1">';
713 }
714 } else {
715 if ($key > 0) {
716 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$key.'">';
717 } else {
718 print '<a href="#">';
719 }
720 print price($amount_ht[$key]);
721 }
722 print '</td>';
723
724 // Amount with VAT
725 print '<td class="right">';
726 if ($modecompta != 'CREANCES-DETTES') {
727 if ($key > 0) {
728 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?socid='.$key.'">';
729 } else {
730 print '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?orphelins=1">';
731 }
732 } else {
733 if ($key > 0) {
734 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$key.'">';
735 } else {
736 print '<a href="#">';
737 }
738 }
739 print price($amount[$key]);
740 print '</a>';
741 print '</td>';
742
743 // Percent;
744 print '<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : '&nbsp;').'</td>';
745
746 // Other stats
747 print '<td class="center">';
748 if (isModEnabled("propal") && $key > 0) {
749 print '&nbsp;<a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("ProposalStats"), "stats").'</a>&nbsp;';
750 }
751 if (isModEnabled('order') && $key > 0) {
752 print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("OrderStats"), "stats").'</a>&nbsp;';
753 }
754 if (isModEnabled('invoice') && $key > 0) {
755 print '&nbsp;<a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("InvoiceStats"), "stats").'</a>&nbsp;';
756 }
757 print '</td>';
758 print "</tr>\n";
759 $i++;
760 }
761
762 // Total
763 print '<tr class="liste_total">';
764 print '<td>'.$langs->trans("Total").'</td>';
765 print '<td>&nbsp;</td>';
766 print '<td>&nbsp;</td>';
767 print '<td>&nbsp;</td>';
768 if ($modecompta == 'RECETTES-DEPENSES') {
769 print '<td></td>';
770 } else {
771 print '<td class="right">'.price($catotal_ht).'</td>';
772 }
773 print '<td class="right">'.price($catotal).'</td>';
774 print '<td>&nbsp;</td>';
775 print '<td>&nbsp;</td>';
776 print '</tr>';
777
778 $db->free($result);
779}
780
781print "</table>";
782print "</div>";
783
784print '</form>';
785
786// End of page
787llxFooter();
788$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components 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:605
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:126
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:624
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
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.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_previous($titlealt='default', $moreatt='')
Show previous logo.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
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...
Definition html.lib.php:172
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.