1<?php
2/* Copyright (C) 2020       Maxime Kohlhaas         <maxime@atm-consulting.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18/**
19 *       \file        htdocs/compta/stats/supplier_ca_by_thirdparty.php
20 *       \brief       Page reporting purchase turnover by thirdparty
21 */
22
23require '../../main.inc.php';
24require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
25require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
26require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
30require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
31
32// Load translation files required by the page
33$langs->loadLangs(array('companies', 'categories', 'bills', 'compta'));
34
35// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
36$modecompta = $conf->global->ACCOUNTING_MODE;
37if (GETPOST("modecompta")) $modecompta = GETPOST("modecompta");
38
39$sortorder = isset($_GET["sortorder"]) ? $_GET["sortorder"] : $_POST["sortorder"];
40$sortfield = isset($_GET["sortfield"]) ? $_GET["sortfield"] : $_POST["sortfield"];
41if (!$sortorder) $sortorder = "asc";
42if (!$sortfield) $sortfield = "nom";
43
44$socid = GETPOST('socid', 'int');
45
46// Category
47$selected_cat = (int) GETPOST('search_categ', 'int');
48$subcat = false;
49if (GETPOST('subcat', 'alpha') === 'yes') {
50	$subcat = true;
51}
52
53// Hook
54$hookmanager->initHooks(array('supplierturnoverbythirdpartylist'));
55
56// Security check
57if ($user->socid > 0) $socid = $user->socid;
58if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat');
59if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
60
61// Date range
62$year = GETPOST("year", 'int');
63$month = GETPOST("month", 'int');
64$search_societe = GETPOST("search_societe", 'alpha');
65$search_zip = GETPOST("search_zip", 'alpha');
66$search_town = GETPOST("search_town", 'alpha');
67$search_country = GETPOST("search_country", 'alpha');
68$date_startyear = GETPOST("date_startyear", 'alpha');
69$date_startmonth = GETPOST("date_startmonth", 'alpha');
70$date_startday = GETPOST("date_startday", 'alpha');
71$date_endyear = GETPOST("date_endyear", 'alpha');
72$date_endmonth = GETPOST("date_endmonth", 'alpha');
73$date_endday = GETPOST("date_endday", 'alpha');
74if (empty($year))
75{
76	$year_current = strftime("%Y", dol_now());
77	$month_current = strftime("%m", dol_now());
78	$year_start = $year_current;
79} else {
80	$year_current = $year;
81	$month_current = strftime("%m", dol_now());
82	$year_start = $year;
83}
84$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
85$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
86// Quarter
87if (empty($date_start) || empty($date_end)) // We define date_start and date_end
88{
89	$q = GETPOST("q", "int") ?GETPOST("q", "int") : 0;
90	if (empty($q))
91	{
92		// We define date_start and date_end
93		$month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
94		$year_end = $year_start;
95		$month_end = $month_start;
96		if (!GETPOST("month"))	// If month not forced
97		{
98			if (!GETPOST('year') && $month_start > $month_current)
99			{
100				$year_start--;
101				$year_end--;
102			}
103			$month_end = $month_start - 1;
104			if ($month_end < 1) $month_end = 12;
105			else $year_end++;
106		}
107		$date_start = dol_get_first_day($year_start, $month_start, false); $date_end = dol_get_last_day($year_end, $month_end, false);
108	}
109	if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); }
110	if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); }
111	if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); }
112	if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
113} else {
114	// TODO We define q
115}
116
117// $date_start and $date_end are defined. We force $year_start and $nbofyear
118$tmps = dol_getdate($date_start);
119$year_start = $tmps['year'];
120$tmpe = dol_getdate($date_end);
121$year_end = $tmpe['year'];
122$nbofyear = ($year_end - $year_start) + 1;
123
124$commonparams = array();
125$commonparams['modecompta'] = $modecompta;
126$commonparams['sortorder'] = $sortorder;
127$commonparams['sortfield'] = $sortfield;
128
129$headerparams = array();
130$headerparams['date_startyear'] = $date_startyear;
131$headerparams['date_startmonth'] = $date_startmonth;
132$headerparams['date_startday'] = $date_startday;
133$headerparams['date_endyear'] = $date_endyear;
134$headerparams['date_endmonth'] = $date_endmonth;
135$headerparams['date_endday'] = $date_endday;
136$headerparams['q'] = $q;
137
138$tableparams = array();
139$tableparams['search_categ'] = $selected_cat;
140$tableparams['search_societe'] = $search_societe;
141$tableparams['search_zip'] = $search_zip;
142$tableparams['search_town'] = $search_town;
143$tableparams['search_country'] = $search_country;
144$tableparams['subcat'] = ($subcat === true) ? 'yes' : '';
145
146// Adding common parameters
147$allparams = array_merge($commonparams, $headerparams, $tableparams);
148$headerparams = array_merge($commonparams, $headerparams);
149$tableparams = array_merge($commonparams, $tableparams);
150
151foreach ($allparams as $key => $value) {
152	$paramslink .= '&'.$key.'='.$value;
153}
154
155
156/*
157 * View
158 */
159
160llxHeader();
161
162$form = new Form($db);
163$thirdparty_static = new Societe($db);
164$formother = new FormOther($db);
165
166// TODO Report from bookkeeping not yet available, so we switch on report on business events
167if ($modecompta == "BOOKKEEPING") $modecompta = "CREANCES-DETTES";
168if ($modecompta == "BOOKKEEPINGCOLLECTED") $modecompta = "RECETTES-DEPENSES";
169
170// Show report header
171if ($modecompta == "CREANCES-DETTES")
172{
173	$name = $langs->trans("PurchaseTurnover").', '.$langs->trans("ByThirdParties");
174	$calcmode = $langs->trans("CalcModeDebt");
175	//$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
176	$description = $langs->trans("RulesPurchaseTurnoverDue");
177	$builddate = dol_now();
178	//$exportlink=$langs->trans("NotYetAvailable");
179} elseif ($modecompta == "RECETTES-DEPENSES")
180{
181	$name = $langs->trans("PurchaseTurnoverCollected").', '.$langs->trans("ByThirdParties");
182	$calcmode = $langs->trans("CalcModeEngagement");
183	//$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
184	$description = $langs->trans("RulesPurchaseTurnoverIn");
185	$builddate = dol_now();
186	//$exportlink=$langs->trans("NotYetAvailable");
187} elseif ($modecompta == "BOOKKEEPING")
188{
189} elseif ($modecompta == "BOOKKEEPINGCOLLECTED")
190{
191}
192$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
193if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) $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>';
194else $periodlink = '';
195
196report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
197
198if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING')
199{
200	print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
201}
202
203// Show Array
204$catotal = 0;
205$catotal_ht = 0;
206$name = array();
207$amount = array();
208$amount_ht = array();
209if ($modecompta == 'CREANCES-DETTES') {
210	$sql = "SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,";
211	$sql .= " sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
212	$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s";
213	if ($selected_cat === -2)	// Without any category
214	{
215		$sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
216	} elseif ($selected_cat) 	// Into a specific category
217	{
218		$sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
219	}
220	$sql .= " WHERE f.fk_statut in (1,2)";
221	$sql .= " AND f.type IN (0,2)";
222	$sql .= " AND f.fk_soc = s.rowid";
223	if ($date_start && $date_end) {
224		$sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
225	}
226	if ($selected_cat === -2)	// Without any category
227	{
228		$sql .= " AND cs.fk_soc is null";
229	} elseif ($selected_cat) {	// Into a specific category
230		$sql .= " AND (c.rowid = ".$db->escape($selected_cat);
231		if ($subcat) $sql .= " OR c.fk_parent = ".$db->escape($selected_cat);
232		$sql .= ")";
233		$sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
234	}
235} else {
236	$sql = "SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
237	$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
238	$sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
239	$sql .= ", ".MAIN_DB_PREFIX."paiementfourn as p";
240	$sql .= ", ".MAIN_DB_PREFIX."societe as s";
241	if ($selected_cat === -2)	// Without any category
242	{
243		$sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
244	} elseif ($selected_cat) 	// Into a specific category
245	{
246		$sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
247	}
248	$sql .= " WHERE p.rowid = pf.fk_paiementfourn";
249	$sql .= " AND pf.fk_facturefourn = f.rowid";
250	$sql .= " AND f.fk_soc = s.rowid";
251	if ($date_start && $date_end) {
252		$sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
253	}
254	if ($selected_cat === -2)	// Without any category
255	{
256		$sql .= " AND cs.fk_soc is null";
257	} elseif ($selected_cat) {	// Into a specific category
258		$sql .= " AND (c.rowid = ".$selected_cat;
259		if ($subcat) $sql .= " OR c.fk_parent = ".$selected_cat;
260		$sql .= ")";
261		$sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
262	}
263}
264if (!empty($search_societe))  $sql .= natural_search('s.nom', $search_societe);
265if (!empty($search_zip))      $sql .= natural_search('s.zip', $search_zip);
266if (!empty($search_town))     $sql .= natural_search('s.town', $search_town);
267if ($search_country > 0)      $sql .= ' AND s.fk_pays = '.$search_country.'';
268$sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
269if ($socid) $sql .= " AND f.fk_soc = ".$socid;
270$sql .= " GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays";
271$sql .= " ORDER BY s.rowid";
272//echo $sql;
273
274dol_syslog("supplier_turnover_by_thirdparty", LOG_DEBUG);
275$result = $db->query($sql);
276if ($result) {
277	$num = $db->num_rows($result);
278	$i = 0;
279	while ($i < $num) {
280		$obj = $db->fetch_object($result);
281			$amount_ht[$obj->socid] = $obj->amount;
282			$amount[$obj->socid] = $obj->amount_ttc;
283			$name[$obj->socid] = $obj->name.' '.$obj->firstname;
284			$address_zip[$obj->socid] = $obj->zip;
285			$address_town[$obj->socid] = $obj->town;
286			$address_pays[$obj->socid] = getCountry($obj->fk_pays);
287			$catotal_ht += $obj->amount;
288			$catotal += $obj->amount_ttc;
289			$i++;
290	}
291} else {
292	dol_print_error($db);
293}
294
295// Show array
296$i = 0;
297print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
298print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
299// Extra parameters management
300foreach ($headerparams as $key => $value)
301{
302	 print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
303}
304
305$moreforfilter = '';
306
307print '<div class="div-table-responsive">';
308print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
309
310// Category filter
311print '<tr class="liste_titre">';
312print '<td>';
313print $langs->trans("Category").': '.$formother->select_categories(Categorie::TYPE_SUPPLIER, $selected_cat, 'search_categ', true);
314print ' ';
315print $langs->trans("SubCats").'? ';
316print '<input type="checkbox" name="subcat" value="yes"';
317if ($subcat) {
318	print ' checked';
319}
320print'></td>';
321print '<td colspan="7" class="right">';
322print '<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")).'">';
323print '</td>';
324print '</tr>';
325
326print '<tr class="liste_titre">';
327print '<td class="liste_titre left">';
328print '<input class="flat" size="6" type="text" name="search_societe" value="'.$search_societe.'">';
329print '</td>';
330print '<td class="liste_titre left">';
331print '<input class="flat" size="6" type="text" name="search_zip" value="'.$search_zip.'">';
332print '</td>';
333print '<td class="liste_titre left">';
334print '<input class="flat" size="6" type="text" name="search_town" value="'.$search_town.'">';
335print '</td>';
336print '<td class="liste_titre left">';
337print $form->select_country($search_country, 'search_country');
338//print '<input class="flat" size="6" type="text" name="search_country" value="'.$search_country.'">';
339print '</td>';
340print '<td class="liste_titre">&nbsp;</td>';
341print '<td class="liste_titre">&nbsp;</td>';
342print '<td class="liste_titre">&nbsp;</td>';
343print '<td class="liste_titre">&nbsp;</td>';
344print '</tr>';
345
346// Array titles
347print "<tr class='liste_titre'>";
348print_liste_field_titre(
349	$langs->trans("Company"),
350	$_SERVER["PHP_SELF"],
351	"nom",
352	"",
353	$paramslink,
354	"",
355	$sortfield, $sortorder
356	);
357print_liste_field_titre(
358	$langs->trans("Zip"),
359	$_SERVER["PHP_SELF"],
360	"zip",
361	"",
362	$paramslink,
363	"",
364	$sortfield, $sortorder
365	);
366print_liste_field_titre(
367	$langs->trans("Town"),
368	$_SERVER["PHP_SELF"],
369	"town",
370	"",
371	$paramslink,
372	"",
373	$sortfield, $sortorder
374	);
375print_liste_field_titre(
376	$langs->trans("Country"),
377	$_SERVER["PHP_SELF"],
378	"country",
379	"",
380	$paramslink,
381	"",
382	$sortfield, $sortorder
383	);
384if ($modecompta == 'CREANCES-DETTES') {
385	print_liste_field_titre(
386		   $langs->trans('AmountHT'),
387		   $_SERVER["PHP_SELF"],
388		   "amount_ht",
389		   "",
390		   $paramslink,
391		   'class="right"',
392		   $sortfield,
393		   $sortorder
394	);
395} else {
396	print_liste_field_titre('');
397}
398print_liste_field_titre(
399	$langs->trans("AmountTTC"),
400	$_SERVER["PHP_SELF"],
401	"amount_ttc",
402	"",
403	$paramslink,
404	'class="right"',
405	$sortfield,
406	$sortorder
407);
408print_liste_field_titre(
409	$langs->trans("Percentage"),
410	$_SERVER["PHP_SELF"],
411	"amount_ttc",
412	"",
413	$paramslink,
414	'class="right"',
415	$sortfield,
416	$sortorder
417);
418print_liste_field_titre(
419	$langs->trans("OtherStatistics"),
420	$_SERVER["PHP_SELF"],
421	"",
422	"",
423	"",
424	'align="center" width="20%"'
425);
426print "</tr>\n";
427
428
429if (count($amount)) {
430	$arrayforsort = $name;
431	// Defining array arrayforsort
432	if ($sortfield == 'nom' && $sortorder == 'asc') {
433		asort($name);
434		$arrayforsort = $name;
435	}
436	if ($sortfield == 'nom' && $sortorder == 'desc') {
437		arsort($name);
438		$arrayforsort = $name;
439	}
440	if ($sortfield == 'amount_ht' && $sortorder == 'asc') {
441		asort($amount_ht);
442		$arrayforsort = $amount_ht;
443	}
444	if ($sortfield == 'amount_ht' && $sortorder == 'desc') {
445		arsort($amount_ht);
446		$arrayforsort = $amount_ht;
447	}
448	if ($sortfield == 'amount_ttc' && $sortorder == 'asc') {
449		asort($amount);
450		$arrayforsort = $amount;
451	}
452	if ($sortfield == 'amount_ttc' && $sortorder == 'desc') {
453		arsort($amount);
454		$arrayforsort = $amount;
455	}
456	if ($sortfield == 'zip' && $sortorder == 'asc') {
457		asort($address_zip);
458		$arrayforsort = $address_zip;
459	}
460	if ($sortfield == 'zip' && $sortorder == 'desc') {
461		arsort($address_zip);
462		$arrayforsort = $address_zip;
463	}
464	if ($sortfield == 'town' && $sortorder == 'asc') {
465		asort($address_town);
466		$arrayforsort = $address_town;
467	}
468	if ($sortfield == 'town' && $sortorder == 'desc') {
469		arsort($address_town);
470		$arrayforsort = $address_town;
471	}
472	if ($sortfield == 'country' && $sortorder == 'asc') {
473		asort($address_pays);
474		$arrayforsort = $address_town;
475	}
476	if ($sortfield == 'country' && $sortorder == 'desc') {
477		arsort($address_pays);
478		$arrayforsort = $address_town;
479	}
480
481	foreach ($arrayforsort as $key=>$value) {
482		print '<tr class="oddeven">';
483
484		// Third party
485		$fullname = $name[$key];
486		if ($key > 0) {
487			$thirdparty_static->id = $key;
488			$thirdparty_static->name = $fullname;
489			$thirdparty_static->client = 1;
490			$linkname = $thirdparty_static->getNomUrl(1, 'supplier');
491		} else {
492			$linkname = $langs->trans("PaymentsNotLinkedToInvoice");
493		}
494		print "<td>".$linkname."</td>\n";
495
496		print '<td>';
497		print $address_zip[$key];
498		print '</td>';
499
500		print '<td>';
501		print $address_town[$key];
502		print '</td>';
503
504		print '<td>';
505		print $address_pays[$key];
506		print '</td>';
507
508		// Amount w/o VAT
509		print '<td class="right">';
510		if ($modecompta != 'CREANCES-DETTES') {
511			if ($key > 0) {
512				print '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement/list.php?socid='.$key.'">';
513			} else {
514				print '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement/list.php?socid=-1">';
515			}
516		} else {
517			if ($key > 0) {
518				print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$key.'">';
519			} else {
520				print '<a href="#">';
521			}
522			print price($amount_ht[$key]);
523		}
524		print '</td>';
525
526		// Amount with VAT
527		print '<td class="right">';
528		if ($modecompta != 'CREANCES-DETTES') {
529			if ($key > 0) {
530				print '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement/list.php?socid='.$key.'">';
531			} else {
532				print '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement/list.php?orphelins=1">';
533			}
534		} else {
535			if ($key > 0) {
536				print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$key.'">';
537			} else {
538				print '<a href="#">';
539			}
540		}
541		print price($amount[$key]);
542		print '</a>';
543		print '</td>';
544
545		// Percent;
546		print '<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : '&nbsp;').'</td>';
547
548		// Other stats
549		print '<td class="center">';
550		if (!empty($conf->supplier_proposal->enabled) && $key > 0) {
551			print '&nbsp;<a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("ProposalStats"), "stats").'</a>&nbsp;';
552		}
553		if (!empty($conf->fournisseur->enabled) && $key > 0) {
554			print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/stats/index.php?mode=supplier&socid='.$key.'">'.img_picto($langs->trans("OrderStats"), "stats").'</a>&nbsp;';
555		}
556		if (!empty($conf->fournisseur->enabled) && $key > 0) {
557			print '&nbsp;<a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?mode=supplier&socid='.$key.'">'.img_picto($langs->trans("InvoiceStats"), "stats").'</a>&nbsp;';
558		}
559		print '</td>';
560		print "</tr>\n";
561		$i++;
562	}
563
564	// Total
565	print '<tr class="liste_total">';
566	print '<td>'.$langs->trans("Total").'</td>';
567	print '<td>&nbsp;</td>';
568	print '<td>&nbsp;</td>';
569	print '<td>&nbsp;</td>';
570	if ($modecompta != 'CREANCES-DETTES') {
571		print '<td></td>';
572	} else {
573		print '<td class="right">'.price($catotal_ht).'</td>';
574	}
575	print '<td class="right">'.price($catotal).'</td>';
576	print '<td>&nbsp;</td>';
577	print '<td>&nbsp;</td>';
578	print '</tr>';
579
580	$db->free($result);
581}
582
583print "</table>";
584print "</div>";
585
586print '</form>';
587
588// End of page
589llxFooter();
590$db->close();
591