30require
'../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
44$langs->load(
"accountancy");
49if ($user->socid > 0) {
50 $socid = $user->socid;
52$hookmanager->initHooks([
'cabyuserreportlist']);
53if (isModEnabled(
'comptabilite')) {
56if (isModEnabled(
'accounting')) {
57 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
62 $modecompta =
GETPOST(
"modecompta");
65$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
66$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
78$date_startmonth =
GETPOSTINT(
"date_startmonth");
86 $year_start = $year_current;
88 $year_current = $year;
95if (empty($date_start) || empty($date_end)) {
100 $year_end = $year_start;
101 $month_end = $month_start;
103 if (!
GETPOST(
'year') && $month_start > $month_current) {
107 $month_end = $month_start - 1;
108 if ($month_end < 1) {
138$year_start = $tmps[
'year'];
140$year_end = $tmpe[
'year'];
141$nbofyear = ($year_end - $year_start) + 1;
143$commonparams = array();
144$commonparams[
'modecompta'] = $modecompta;
145$commonparams[
'sortorder'] = $sortorder;
146$commonparams[
'sortfield'] = $sortfield;
148$headerparams = array();
149if (!empty($date_startyear)) {
150 $headerparams[
'date_startyear'] = $date_startyear;
152if (!empty($date_startmonth)) {
153 $headerparams[
'date_startmonth'] = $date_startmonth;
155if (!empty($date_startday)) {
156 $headerparams[
'date_startday'] = $date_startday;
158if (!empty($date_endyear)) {
159 $headerparams[
'date_endyear'] = $date_endyear;
161if (!empty($date_endmonth)) {
162 $headerparams[
'date_endmonth'] = $date_endmonth;
164if (!empty($date_endday)) {
165 $headerparams[
'date_endday'] = $date_endday;
168 $headerparams[
'q'] = $q;
171$tableparams = array();
174$allparams = array_merge($commonparams, $headerparams, $tableparams);
175$headerparams = array_merge($commonparams, $headerparams);
176$tableparams = array_merge($commonparams, $tableparams);
179foreach ($allparams as $key => $value) {
180 $paramslink .=
'&'.$key.
'='.$value;
189$form =
new Form($db);
192if ($modecompta ==
"BOOKKEEPING") {
193 $modecompta =
"CREANCES-DETTES";
195if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
196 $modecompta =
"RECETTES-DEPENSES";
206if ($modecompta ==
"CREANCES-DETTES") {
207 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
208 $calcmode = $langs->trans(
"CalcModeDebt");
210 $description = $langs->trans(
"RulesCADue");
212 $description .= $langs->trans(
"DepositsAreNotIncluded");
214 $description .= $langs->trans(
"DepositsAreIncluded");
218} elseif ($modecompta ==
"RECETTES-DEPENSES") {
219 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
220 $calcmode = $langs->trans(
"CalcModePayment");
222 $description = $langs->trans(
"RulesCAIn");
223 $description .= $langs->trans(
"DepositsAreIncluded");
226} elseif ($modecompta ==
"BOOKKEEPING") {
228} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
231$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
233$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
235 $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>';
241if (!empty($modecompta)) {
242 $moreparam[
'modecompta'] = $modecompta;
245report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
247if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
248 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
255print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
256print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
258foreach ($headerparams as $key => $value) {
259 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
265if ($modecompta ==
'CREANCES-DETTES') {
266 $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";
267 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
268 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.fk_user_author = u.rowid";
269 $sql .=
" WHERE f.fk_statut in (1,2)";
271 $sql .=
" AND f.type IN (0,1,2,5)";
273 $sql .=
" AND f.type IN (0,1,2,3,5)";
275 if ($date_start && $date_end) {
276 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
278} elseif ($modecompta ==
"RECETTES-DEPENSES") {
283 $sql =
"SELECT u.rowid as rowid, u.lastname as name, u.firstname as firstname, sum(pf.amount) as amount_ttc";
284 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
285 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.fk_user_author = u.rowid ";
286 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_facture = f.rowid";
287 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement as p ON p.rowid = pf.fk_paiement";
288 $sql .=
" WHERE 1=1";
289 if ($date_start && $date_end) {
290 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
295$sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
297 $sql .=
" AND f.fk_soc = ".((int) $socid);
299$sql .=
" GROUP BY u.rowid, u.lastname, u.firstname";
300$sql .=
" ORDER BY u.rowid";
306$result = $db->query($sql);
308 $num = $db->num_rows($result);
311 $obj = $db->fetch_object($result);
313 $amount_ht[$obj->rowid] = (empty($obj->amount) ? 0 : $obj->amount);
314 $amount[$obj->rowid] = $obj->amount_ttc;
315 $name[$obj->rowid] = $obj->name.
' '.$obj->firstname;
317 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
318 $catotal += $obj->amount_ttc;
326if ($modecompta ==
'RECETTES-DEPENSES') {
327 $sql =
"SELECT -1 as rowidx, '' as name, '' as firstname, sum(DISTINCT p.amount) as amount_ttc";
328 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
329 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
330 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
331 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
332 $sql .=
" WHERE pf.rowid IS NULL";
333 $sql .=
" AND p.fk_bank = b.rowid";
334 $sql .=
" AND b.fk_account = ba.rowid";
335 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
336 if ($date_start && $date_end) {
337 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
339 $sql .=
" GROUP BY rowidx, name, firstname";
340 $sql .=
" ORDER BY rowidx";
342 $result = $db->query($sql);
344 $num = $db->num_rows($result);
347 $obj = $db->fetch_object($result);
348 $amount[$obj->rowidx] = $obj->amount_ttc;
349 $name[$obj->rowidx] = $obj->name.
' '.$obj->firstname;
350 $catotal += $obj->amount_ttc;
360print
'<div class="div-table-responsive">';
361print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
363print
"<tr class=\"liste_titre\">";
365 $langs->trans(
"User"),
366 $_SERVER[
"PHP_SELF"],
374if ($modecompta ==
'CREANCES-DETTES') {
376 $langs->trans(
'AmountHT'),
377 $_SERVER[
"PHP_SELF"],
389 $langs->trans(
"AmountTTC"),
390 $_SERVER[
"PHP_SELF"],
399 $langs->trans(
"Percentage"),
400 $_SERVER[
"PHP_SELF"],
409 $langs->trans(
"OtherStatistics"),
410 $_SERVER[
"PHP_SELF"],
414 'align="center" width="20%"'
419 $arrayforsort = $name;
422 if ($sortfield ==
'name' && $sortorder ==
'asc') {
424 $arrayforsort = $name;
426 if ($sortfield ==
'name' && $sortorder ==
'desc') {
428 $arrayforsort = $name;
430 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
432 $arrayforsort = $amount_ht;
434 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
436 $arrayforsort = $amount_ht;
438 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
440 $arrayforsort = $amount;
442 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
444 $arrayforsort = $amount;
449 foreach ($arrayforsort as $key => $value) {
450 print
'<tr class="oddeven">';
453 $fullname = $name[$key];
455 $linkname =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$fullname.
'</a>';
457 $linkname = $langs->trans(
"PaymentsNotLinkedToUser");
459 print
"<td>".$linkname.
"</td>\n";
462 print
'<td class="right">';
463 if ($modecompta ==
'RECETTES-DEPENSES') {
469 } elseif ($modecompta ==
'CREANCES-DETTES') {
471 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
475 print
price($amount_ht[$key]);
483 print
'<td class="right">';
484 if ($modecompta ==
'RECETTES-DEPENSES') {
490 } elseif ($modecompta ==
'CREANCES-DETTES') {
492 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
497 print
price($amount[$key]);
498 if ($modecompta ==
'RECETTES-DEPENSES') {
504 } elseif ($modecompta ==
'CREANCES-DETTES') {
512 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
515 print
'<td class="center">';
516 if (isModEnabled(
"propal") && $key > 0) {
517 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
519 if (isModEnabled(
'order') && $key > 0) {
520 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
522 if (isModEnabled(
'invoice') && $key > 0) {
523 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
531 print
'<tr class="liste_total">';
532 print
'<td>'.$langs->trans(
"Total").
'</td>';
533 if ($modecompta !=
'CREANCES-DETTES') {
536 print
'<td class="right">'.price($catotal_ht).
'</td>';
538 print
'<td class="right">'.price($catotal).
'</td>';
539 print
'<td> </td>';
540 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.