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");
37$socid =
GETPOST(
'socid',
'int');
40if ($user->socid > 0) {
41 $socid = $user->socid;
43if (isModEnabled(
'comptabilite')) {
46if (isModEnabled(
'accounting')) {
47 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
49$hookmanager->initHooks([
'cabyuserreportlist']);
51$modecompta = $conf->global->ACCOUNTING_MODE;
53 $modecompta =
GETPOST(
"modecompta");
56$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
57$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
67$month =
GETPOST(
"month",
'int');
68$date_startyear =
GETPOST(
"date_startyear",
'int');
69$date_startmonth =
GETPOST(
"date_startmonth",
'int');
70$date_startday =
GETPOST(
"date_startday",
'int');
71$date_endyear =
GETPOST(
"date_endyear",
'int');
72$date_endmonth =
GETPOST(
"date_endmonth",
'int');
73$date_endday =
GETPOST(
"date_endday",
'int');
77 $year_start = $year_current;
79 $year_current = $year;
86if (empty($date_start) || empty($date_end)) {
90 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
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");
199 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
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(
"CalcModeEngagement");
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)";
258 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
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";
293$result = $db->query($sql);
295 $num = $db->num_rows($result);
298 $obj = $db->fetch_object($result);
300 $amount_ht[$obj->rowid] = (empty($obj->amount) ? 0 : $obj->amount);
301 $amount[$obj->rowid] = $obj->amount_ttc;
302 $name[$obj->rowid] = $obj->name.
' '.$obj->firstname;
304 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
305 $catotal += $obj->amount_ttc;
313if ($modecompta ==
'RECETTES-DEPENSES') {
314 $sql =
"SELECT -1 as rowidx, '' as name, '' as firstname, sum(DISTINCT p.amount) as amount_ttc";
315 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
316 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
317 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
318 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
319 $sql .=
" WHERE pf.rowid IS NULL";
320 $sql .=
" AND p.fk_bank = b.rowid";
321 $sql .=
" AND b.fk_account = ba.rowid";
322 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
323 if ($date_start && $date_end) {
324 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
326 $sql .=
" GROUP BY rowidx, name, firstname";
327 $sql .=
" ORDER BY rowidx";
329 $result = $db->query($sql);
331 $num = $db->num_rows($result);
334 $obj = $db->fetch_object($result);
335 $amount[$obj->rowidx] = $obj->amount_ttc;
336 $name[$obj->rowidx] = $obj->name.
' '.$obj->firstname;
337 $catotal += $obj->amount_ttc;
347print
'<div class="div-table-responsive">';
348print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
350print
"<tr class=\"liste_titre\">";
352 $langs->trans(
"User"),
353 $_SERVER[
"PHP_SELF"],
361if ($modecompta ==
'CREANCES-DETTES') {
363 $langs->trans(
'AmountHT'),
364 $_SERVER[
"PHP_SELF"],
376 $langs->trans(
"AmountTTC"),
377 $_SERVER[
"PHP_SELF"],
386 $langs->trans(
"Percentage"),
387 $_SERVER[
"PHP_SELF"],
396 $langs->trans(
"OtherStatistics"),
397 $_SERVER[
"PHP_SELF"],
401 'align="center" width="20%"'
406 $arrayforsort = $name;
409 if ($sortfield ==
'name' && $sortorder ==
'asc') {
411 $arrayforsort = $name;
413 if ($sortfield ==
'name' && $sortorder ==
'desc') {
415 $arrayforsort = $name;
417 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
419 $arrayforsort = $amount_ht;
421 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
423 $arrayforsort = $amount_ht;
425 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
427 $arrayforsort = $amount;
429 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
431 $arrayforsort = $amount;
436 foreach ($arrayforsort as $key => $value) {
437 print
'<tr class="oddeven">';
440 $fullname = $name[$key];
442 $linkname =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$fullname.
'</a>';
444 $linkname = $langs->trans(
"PaymentsNotLinkedToUser");
446 print
"<td>".$linkname.
"</td>\n";
449 print
'<td class="right">';
450 if ($modecompta ==
'RECETTES-DEPENSES') {
456 } elseif ($modecompta ==
'CREANCES-DETTES') {
458 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
462 print
price($amount_ht[$key]);
470 print
'<td class="right">';
471 if ($modecompta ==
'RECETTES-DEPENSES') {
477 } elseif ($modecompta ==
'CREANCES-DETTES') {
479 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
484 print
price($amount[$key]);
485 if ($modecompta ==
'RECETTES-DEPENSES') {
491 } elseif ($modecompta ==
'CREANCES-DETTES') {
499 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
502 print
'<td class="center">';
503 if (isModEnabled(
"propal") && $key > 0) {
504 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
506 if (isModEnabled(
'commande') && $key > 0) {
507 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
509 if (isModEnabled(
'facture') && $key > 0) {
510 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
518 print
'<tr class="liste_total">';
519 print
'<td>'.$langs->trans(
"Total").
'</td>';
520 if ($modecompta !=
'CREANCES-DETTES') {
523 print
'<td class="right">'.price($catotal_ht).
'</td>';
525 print
'<td class="right">'.price($catotal).
'</td>';
526 print
'<td> </td>';
527 print
'<td> </td>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
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 informations (by default a local PHP server timestamp) Re...
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
img_next($titlealt='default', $moreatt='')
Show next logo.
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.