31require
'../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
45$langs->load(
"accountancy");
50if ($user->socid > 0) {
51 $socid = $user->socid;
53$hookmanager->initHooks([
'cabyuserreportlist']);
58 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
63 $modecompta =
GETPOST(
"modecompta");
66$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
67$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
79$date_startmonth =
GETPOSTINT(
"date_startmonth");
87 $year_start = $year_current;
89 $year_current = $year;
96if (empty($date_start) || empty($date_end)) {
101 $year_end = $year_start;
102 $month_end = $month_start;
104 if (!
GETPOST(
'year') && $month_start > $month_current) {
108 $month_end = $month_start - 1;
109 if ($month_end < 1) {
139$year_start = $tmps[
'year'];
141$year_end = $tmpe[
'year'];
142$nbofyear = ($year_end - $year_start) + 1;
144$commonparams = array();
145$commonparams[
'modecompta'] = $modecompta;
146$commonparams[
'sortorder'] = $sortorder;
147$commonparams[
'sortfield'] = $sortfield;
149$headerparams = array();
150if (!empty($date_startyear)) {
151 $headerparams[
'date_startyear'] = $date_startyear;
153if (!empty($date_startmonth)) {
154 $headerparams[
'date_startmonth'] = $date_startmonth;
156if (!empty($date_startday)) {
157 $headerparams[
'date_startday'] = $date_startday;
159if (!empty($date_endyear)) {
160 $headerparams[
'date_endyear'] = $date_endyear;
162if (!empty($date_endmonth)) {
163 $headerparams[
'date_endmonth'] = $date_endmonth;
165if (!empty($date_endday)) {
166 $headerparams[
'date_endday'] = $date_endday;
169 $headerparams[
'q'] = $q;
172$tableparams = array();
175$allparams = array_merge($commonparams, $headerparams, $tableparams);
176$headerparams = array_merge($commonparams, $headerparams);
177$tableparams = array_merge($commonparams, $tableparams);
180foreach ($allparams as $key => $value) {
181 $paramslink .=
'&'.$key.
'='.$value;
190$form =
new Form($db);
192if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
193 $modecompta =
"RECETTES-DEPENSES";
204if ($modecompta ==
"CREANCES-DETTES") {
205 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
206 $calcmode = $langs->trans(
"CalcModeDebt");
208 $description = $langs->trans(
"RulesCADue");
210 $description .= $langs->trans(
"DepositsAreNotIncluded");
212 $description .= $langs->trans(
"DepositsAreIncluded");
216} elseif ($modecompta ==
"RECETTES-DEPENSES") {
217 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
218 $calcmode = $langs->trans(
"CalcModePayment");
220 $description = $langs->trans(
"RulesCAIn");
221 $description .= $langs->trans(
"DepositsAreIncluded");
224} elseif ($modecompta ==
"BOOKKEEPING") {
225 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
226 $calcmode = $langs->trans(
"CalcModeBookkeeping");
227 $description = $langs->trans(
"RulesCADue");
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)";
278 $hookmanager->initHooks(array(
'turnoverreport'));
279 $parameters = array(
'invoicealias' =>
'f',
'issupplier' => 0,
'datefield' =>
'datef');
280 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
281 $sql .= $hookmanager->resPrint;
282 if ($date_start && $date_end) {
283 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
285} elseif ($modecompta ==
"RECETTES-DEPENSES") {
290 $sql =
"SELECT u.rowid as rowid, u.lastname as name, u.firstname as firstname, sum(pf.amount) as amount_ttc";
291 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
292 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.fk_user_author = u.rowid ";
293 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_facture = f.rowid";
294 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement as p ON p.rowid = pf.fk_paiement";
295 $sql .=
" WHERE 1=1";
296 if ($date_start && $date_end) {
297 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
299} elseif ($modecompta ==
"BOOKKEEPING") {
306 $sql =
"SELECT u.rowid as rowid, u.lastname as name, u.firstname as firstname,";
307 $sql .=
" SUM(CASE WHEN b.subledger_account IS NOT NULL AND b.subledger_account != '' THEN b.debit - b.credit ELSE 0 END) as amount_ttc,";
308 $sql .=
" SUM(CASE WHEN aa.pcg_type = 'INCOME' THEN b.credit - b.debit ELSE 0 END) as amount";
309 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b";
310 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = b.fk_doc AND b.doc_type = 'customer_invoice'";
311 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = f.fk_user_author";
312 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.account_number = b.numero_compte AND aa.entity = b.entity AND aa.fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
313 $sql .=
" WHERE 1=1";
314 if ($date_start && $date_end) {
315 $sql .=
" AND b.doc_date >= '".$db->idate($date_start).
"' AND b.doc_date <= '".$db->idate($date_end).
"'";
319if ($modecompta ==
'BOOKKEEPING') {
320 $sql .=
" AND b.entity = ".((int)
$conf->entity);
322 $sql .=
" AND f.fk_soc = ".((int) $socid);
325 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
327 $sql .=
" AND f.fk_soc = ".((int) $socid);
330$sql .=
" GROUP BY u.rowid, u.lastname, u.firstname";
331$sql .=
" ORDER BY u.rowid";
337$result = $db->query($sql);
339 $num = $db->num_rows($result);
342 $obj = $db->fetch_object($result);
344 $amount_ht[$obj->rowid] = (empty($obj->amount) ? 0 : $obj->amount);
345 $amount[$obj->rowid] = $obj->amount_ttc;
346 $name[$obj->rowid] = $obj->name.
' '.$obj->firstname;
348 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
349 $catotal += $obj->amount_ttc;
353 dol_print_error($db);
357if ($modecompta ==
'RECETTES-DEPENSES') {
358 $sql =
"SELECT -1 as rowidx, '' as name, '' as firstname, sum(DISTINCT p.amount) as amount_ttc";
359 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
360 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
361 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
362 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
363 $sql .=
" WHERE pf.rowid IS NULL";
364 $sql .=
" AND p.fk_bank = b.rowid";
365 $sql .=
" AND b.fk_account = ba.rowid";
366 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
367 if ($date_start && $date_end) {
368 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
370 $sql .=
" GROUP BY rowidx, name, firstname";
371 $sql .=
" ORDER BY rowidx";
373 $result = $db->query($sql);
375 $num = $db->num_rows($result);
378 $obj = $db->fetch_object($result);
379 $amount[$obj->rowidx] = $obj->amount_ttc;
380 $name[$obj->rowidx] = $obj->name.
' '.$obj->firstname;
381 $catotal += $obj->amount_ttc;
385 dol_print_error($db);
391print
'<div class="div-table-responsive">';
392print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
394print
"<tr class=\"liste_titre\">";
396 $langs->trans(
"User"),
397 $_SERVER[
"PHP_SELF"],
405if ($modecompta ==
'CREANCES-DETTES') {
407 $langs->trans(
'AmountHT'),
408 $_SERVER[
"PHP_SELF"],
420 $langs->trans(
"AmountTTC"),
421 $_SERVER[
"PHP_SELF"],
430 $langs->trans(
"Percentage"),
431 $_SERVER[
"PHP_SELF"],
440 $langs->trans(
"OtherStatistics"),
441 $_SERVER[
"PHP_SELF"],
445 'align="center" width="20%"'
450 $arrayforsort = $name;
453 if ($sortfield ==
'name' && $sortorder ==
'asc') {
455 $arrayforsort = $name;
457 if ($sortfield ==
'name' && $sortorder ==
'desc') {
459 $arrayforsort = $name;
461 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
463 $arrayforsort = $amount_ht;
465 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
467 $arrayforsort = $amount_ht;
469 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
471 $arrayforsort = $amount;
473 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
475 $arrayforsort = $amount;
480 foreach ($arrayforsort as $key => $value) {
481 print
'<tr class="oddeven">';
484 $fullname = $name[$key];
486 $linkname =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$key.
'">'.img_object($langs->trans(
"ShowUser"),
'user').
' '.$fullname.
'</a>';
488 $linkname = $langs->trans(
"PaymentsNotLinkedToUser");
490 print
"<td>".$linkname.
"</td>\n";
493 print
'<td class="right">';
494 if ($modecompta ==
'RECETTES-DEPENSES') {
500 } elseif ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
502 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
506 print
price($amount_ht[$key]);
514 print
'<td class="right">';
515 if ($modecompta ==
'RECETTES-DEPENSES') {
521 } elseif ($modecompta ==
'CREANCES-DETTES') {
523 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
528 print
price($amount[$key]);
529 if ($modecompta ==
'RECETTES-DEPENSES') {
535 } elseif ($modecompta ==
'CREANCES-DETTES') {
543 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
546 print
'<td class="center">';
548 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?userid='.$key.
'">'.img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
551 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?userid='.$key.
'">'.img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
554 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?userid='.$key.
'">'.img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
562 print
'<tr class="liste_total">';
563 print
'<td>'.$langs->trans(
"Total").
'</td>';
564 if ($modecompta ==
'RECETTES-DEPENSES') {
567 print
'<td class="right">'.price($catotal_ht).
'</td>';
569 print
'<td class="right">'.price($catotal).
'</td>';
570 print
'<td> </td>';
571 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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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).
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.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
img_next($titlealt='default', $moreatt='')
Show next logo.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
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, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.