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