29require
'../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
35$langs->load(
"accountancy");
40if ($user->socid > 0) {
41 $socid = $user->socid;
43$hookmanager->initHooks([
'cabyuserreportlist']);
44if (isModEnabled(
'comptabilite')) {
47if (isModEnabled(
'accounting')) {
48 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
53 $modecompta =
GETPOST(
"modecompta");
56$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
57$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
69$date_startmonth =
GETPOSTINT(
"date_startmonth");
77 $year_start = $year_current;
79 $year_current = $year;
86if (empty($date_start) || empty($date_end)) {
91 $year_end = $year_start;
92 $month_end = $month_start;
94 if (!
GETPOST(
'year') && $month_start > $month_current) {
98 $month_end = $month_start - 1;
129$year_start = $tmps[
'year'];
131$year_end = $tmpe[
'year'];
132$nbofyear = ($year_end - $year_start) + 1;
134$commonparams = array();
135$commonparams[
'modecompta'] = $modecompta;
136$commonparams[
'sortorder'] = $sortorder;
137$commonparams[
'sortfield'] = $sortfield;
139$headerparams = array();
140if (!empty($date_startyear)) {
141 $headerparams[
'date_startyear'] = $date_startyear;
143if (!empty($date_startmonth)) {
144 $headerparams[
'date_startmonth'] = $date_startmonth;
146if (!empty($date_startday)) {
147 $headerparams[
'date_startday'] = $date_startday;
149if (!empty($date_endyear)) {
150 $headerparams[
'date_endyear'] = $date_endyear;
152if (!empty($date_endmonth)) {
153 $headerparams[
'date_endmonth'] = $date_endmonth;
155if (!empty($date_endday)) {
156 $headerparams[
'date_endday'] = $date_endday;
159 $headerparams[
'q'] = $q;
162$tableparams = array();
165$allparams = array_merge($commonparams, $headerparams, $tableparams);
166$headerparams = array_merge($commonparams, $headerparams);
167$tableparams = array_merge($commonparams, $tableparams);
170foreach ($allparams as $key => $value) {
171 $paramslink .=
'&'.$key.
'='.$value;
180$form =
new Form($db);
183if ($modecompta ==
"BOOKKEEPING") {
184 $modecompta =
"CREANCES-DETTES";
186if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
187 $modecompta =
"RECETTES-DEPENSES";
194if ($modecompta ==
"CREANCES-DETTES") {
195 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
196 $calcmode = $langs->trans(
"CalcModeDebt");
198 $description = $langs->trans(
"RulesCADue");
200 $description .= $langs->trans(
"DepositsAreNotIncluded");
202 $description .= $langs->trans(
"DepositsAreIncluded");
206} elseif ($modecompta ==
"RECETTES-DEPENSES") {
207 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
208 $calcmode = $langs->trans(
"CalcModePayment");
210 $description = $langs->trans(
"RulesCAIn");
211 $description .= $langs->trans(
"DepositsAreIncluded");
214} elseif ($modecompta ==
"BOOKKEEPING") {
216} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
219$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
221$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
223 $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>';
229if (!empty($modecompta)) {
230 $moreparam[
'modecompta'] = $modecompta;
233report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
235if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
236 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
243print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
244print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
246foreach ($headerparams as $key => $value) {
247 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
253if ($modecompta ==
'CREANCES-DETTES') {
254 $sql =
"SELECT u.rowid as rowid, u.lastname as name, u.firstname as firstname, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
255 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
256 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.fk_user_author = u.rowid";
257 $sql .=
" WHERE f.fk_statut in (1,2)";
259 $sql .=
" AND f.type IN (0,1,2,5)";
261 $sql .=
" AND f.type IN (0,1,2,3,5)";
263 if ($date_start && $date_end) {
264 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
266} elseif ($modecompta ==
"RECETTES-DEPENSES") {
271 $sql =
"SELECT u.rowid as rowid, u.lastname as name, u.firstname as firstname, sum(pf.amount) as amount_ttc";
272 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
273 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.fk_user_author = u.rowid ";
274 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_facture = f.rowid";
275 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement as p ON p.rowid = pf.fk_paiement";
276 $sql .=
" WHERE 1=1";
277 if ($date_start && $date_end) {
278 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
280} elseif ($modecompta ==
"BOOKKEEPING") {
281} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
283$sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
285 $sql .=
" AND f.fk_soc = ".((int) $socid);
287$sql .=
" GROUP BY u.rowid, u.lastname, u.firstname";
288$sql .=
" ORDER BY u.rowid";
294$result = $db->query($sql);
296 $num = $db->num_rows($result);
299 $obj = $db->fetch_object($result);
301 $amount_ht[$obj->rowid] = (empty($obj->amount) ? 0 : $obj->amount);
302 $amount[$obj->rowid] = $obj->amount_ttc;
303 $name[$obj->rowid] = $obj->name.
' '.$obj->firstname;
305 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
306 $catotal += $obj->amount_ttc;
314if ($modecompta ==
'RECETTES-DEPENSES') {
315 $sql =
"SELECT -1 as rowidx, '' as name, '' as firstname, sum(DISTINCT p.amount) as amount_ttc";
316 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
317 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
318 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
319 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
320 $sql .=
" WHERE pf.rowid IS NULL";
321 $sql .=
" AND p.fk_bank = b.rowid";
322 $sql .=
" AND b.fk_account = ba.rowid";
323 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
324 if ($date_start && $date_end) {
325 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
327 $sql .=
" GROUP BY rowidx, name, firstname";
328 $sql .=
" ORDER BY rowidx";
330 $result = $db->query($sql);
332 $num = $db->num_rows($result);
335 $obj = $db->fetch_object($result);
336 $amount[$obj->rowidx] = $obj->amount_ttc;
337 $name[$obj->rowidx] = $obj->name.
' '.$obj->firstname;
338 $catotal += $obj->amount_ttc;
348print
'<div class="div-table-responsive">';
349print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
351print
"<tr class=\"liste_titre\">";
353 $langs->trans(
"User"),
354 $_SERVER[
"PHP_SELF"],
362if ($modecompta ==
'CREANCES-DETTES') {
364 $langs->trans(
'AmountHT'),
365 $_SERVER[
"PHP_SELF"],
377 $langs->trans(
"AmountTTC"),
378 $_SERVER[
"PHP_SELF"],
387 $langs->trans(
"Percentage"),
388 $_SERVER[
"PHP_SELF"],
397 $langs->trans(
"OtherStatistics"),
398 $_SERVER[
"PHP_SELF"],
402 'align="center" width="20%"'
407 $arrayforsort = $name;
410 if ($sortfield ==
'name' && $sortorder ==
'asc') {
412 $arrayforsort = $name;
414 if ($sortfield ==
'name' && $sortorder ==
'desc') {
416 $arrayforsort = $name;
418 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
420 $arrayforsort = $amount_ht;
422 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
424 $arrayforsort = $amount_ht;
426 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
428 $arrayforsort = $amount;
430 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
432 $arrayforsort = $amount;
437 foreach ($arrayforsort as $key => $value) {
438 print
'<tr class="oddeven">';
441 $fullname = $name[$key];
443 $linkname =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$fullname.
'</a>';
445 $linkname = $langs->trans(
"PaymentsNotLinkedToUser");
447 print
"<td>".$linkname.
"</td>\n";
450 print
'<td class="right">';
451 if ($modecompta ==
'RECETTES-DEPENSES') {
457 } elseif ($modecompta ==
'CREANCES-DETTES') {
459 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
463 print
price($amount_ht[$key]);
471 print
'<td class="right">';
472 if ($modecompta ==
'RECETTES-DEPENSES') {
478 } elseif ($modecompta ==
'CREANCES-DETTES') {
480 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
485 print
price($amount[$key]);
486 if ($modecompta ==
'RECETTES-DEPENSES') {
492 } elseif ($modecompta ==
'CREANCES-DETTES') {
500 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
503 print
'<td class="center">';
504 if (isModEnabled(
"propal") && $key > 0) {
505 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
507 if (isModEnabled(
'order') && $key > 0) {
508 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
510 if (isModEnabled(
'invoice') && $key > 0) {
511 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
519 print
'<tr class="liste_total">';
520 print
'<td>'.$langs->trans(
"Total").
'</td>';
521 if ($modecompta !=
'CREANCES-DETTES') {
524 print
'<td class="right">'.price($catotal_ht).
'</td>';
526 print
'<td class="right">'.price($catotal).
'</td>';
527 print
'<td> </td>';
528 print
'<td> </td>';
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.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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.