30require
'../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
41require_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']);
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;
192if ($modecompta ==
"BOOKKEEPING") {
193 $modecompta =
"CREANCES-DETTES";
195if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
196 $modecompta =
"RECETTES-DEPENSES";
207if ($modecompta ==
"CREANCES-DETTES") {
208 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
209 $calcmode = $langs->trans(
"CalcModeDebt");
211 $description = $langs->trans(
"RulesCADue");
213 $description .= $langs->trans(
"DepositsAreNotIncluded");
215 $description .= $langs->trans(
"DepositsAreIncluded");
219} elseif ($modecompta ==
"RECETTES-DEPENSES") {
220 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
221 $calcmode = $langs->trans(
"CalcModePayment");
223 $description = $langs->trans(
"RulesCAIn");
224 $description .= $langs->trans(
"DepositsAreIncluded");
227} elseif ($modecompta ==
"BOOKKEEPING") {
229} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
232$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
234$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
236 $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>';
242if (!empty($modecompta)) {
243 $moreparam[
'modecompta'] = $modecompta;
246report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
248if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
249 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
256print
'<form method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
257print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
259foreach ($headerparams as $key => $value) {
260 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
267if ($modecompta ==
'CREANCES-DETTES') {
268 $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";
269 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
270 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.fk_user_author = u.rowid";
271 $sql .=
" WHERE f.fk_statut in (1,2)";
273 $sql .=
" AND f.type IN (0,1,2,5)";
275 $sql .=
" AND f.type IN (0,1,2,3,5)";
277 if ($date_start && $date_end) {
278 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".
$db->idate($date_end).
"'";
280} elseif ($modecompta ==
"RECETTES-DEPENSES") {
285 $sql =
"SELECT u.rowid as rowid, u.lastname as name, u.firstname as firstname, sum(pf.amount) as amount_ttc";
286 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
287 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.fk_user_author = u.rowid ";
288 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_facture = f.rowid";
289 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement as p ON p.rowid = pf.fk_paiement";
290 $sql .=
" WHERE 1=1";
291 if ($date_start && $date_end) {
292 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".
$db->idate($date_end).
"'";
297$sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
299 $sql .=
" AND f.fk_soc = ".((int) $socid);
301$sql .=
" GROUP BY u.rowid, u.lastname, u.firstname";
302$sql .=
" ORDER BY u.rowid";
308$result =
$db->query($sql);
310 $num =
$db->num_rows($result);
313 $obj =
$db->fetch_object($result);
315 $amount_ht[$obj->rowid] = (empty($obj->amount) ? 0 : $obj->amount);
316 $amount[$obj->rowid] = $obj->amount_ttc;
317 $name[$obj->rowid] = $obj->name.
' '.$obj->firstname;
319 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
320 $catotal += $obj->amount_ttc;
328if ($modecompta ==
'RECETTES-DEPENSES') {
329 $sql =
"SELECT -1 as rowidx, '' as name, '' as firstname, sum(DISTINCT p.amount) as amount_ttc";
330 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
331 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
332 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
333 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
334 $sql .=
" WHERE pf.rowid IS NULL";
335 $sql .=
" AND p.fk_bank = b.rowid";
336 $sql .=
" AND b.fk_account = ba.rowid";
337 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
338 if ($date_start && $date_end) {
339 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".
$db->idate($date_end).
"'";
341 $sql .=
" GROUP BY rowidx, name, firstname";
342 $sql .=
" ORDER BY rowidx";
344 $result =
$db->query($sql);
346 $num =
$db->num_rows($result);
349 $obj =
$db->fetch_object($result);
350 $amount[$obj->rowidx] = $obj->amount_ttc;
351 $name[$obj->rowidx] = $obj->name.
' '.$obj->firstname;
352 $catotal += $obj->amount_ttc;
362print
'<div class="div-table-responsive">';
363print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
365print
"<tr class=\"liste_titre\">";
367 $langs->trans(
"User"),
368 $_SERVER[
"PHP_SELF"],
376if ($modecompta ==
'CREANCES-DETTES') {
378 $langs->trans(
'AmountHT'),
379 $_SERVER[
"PHP_SELF"],
391 $langs->trans(
"AmountTTC"),
392 $_SERVER[
"PHP_SELF"],
401 $langs->trans(
"Percentage"),
402 $_SERVER[
"PHP_SELF"],
411 $langs->trans(
"OtherStatistics"),
412 $_SERVER[
"PHP_SELF"],
416 'align="center" width="20%"'
421 $arrayforsort = $name;
424 if ($sortfield ==
'name' && $sortorder ==
'asc') {
426 $arrayforsort = $name;
428 if ($sortfield ==
'name' && $sortorder ==
'desc') {
430 $arrayforsort = $name;
432 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
434 $arrayforsort = $amount_ht;
436 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
438 $arrayforsort = $amount_ht;
440 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
442 $arrayforsort = $amount;
444 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
446 $arrayforsort = $amount;
451 foreach ($arrayforsort as $key => $value) {
452 print
'<tr class="oddeven">';
455 $fullname = $name[$key];
457 $linkname =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$fullname.
'</a>';
459 $linkname = $langs->trans(
"PaymentsNotLinkedToUser");
461 print
"<td>".$linkname.
"</td>\n";
464 print
'<td class="right">';
465 if ($modecompta ==
'RECETTES-DEPENSES') {
471 } elseif ($modecompta ==
'CREANCES-DETTES') {
473 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
477 print
price($amount_ht[$key]);
485 print
'<td class="right">';
486 if ($modecompta ==
'RECETTES-DEPENSES') {
492 } elseif ($modecompta ==
'CREANCES-DETTES') {
494 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
499 print
price($amount[$key]);
500 if ($modecompta ==
'RECETTES-DEPENSES') {
506 } elseif ($modecompta ==
'CREANCES-DETTES') {
514 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
517 print
'<td class="center">';
519 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
522 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
525 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
533 print
'<tr class="liste_total">';
534 print
'<td>'.$langs->trans(
"Total").
'</td>';
535 if ($modecompta !=
'CREANCES-DETTES') {
538 print
'<td class="right">'.price($catotal_ht).
'</td>';
540 print
'<td class="right">'.price($catotal).
'</td>';
541 print
'<td> </td>';
542 print
'<td> </td>';
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
$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...
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)
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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_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).
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.
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.
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.