Go to the documentation of this file.
28 require
'../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
34 $langs->load(
"accountancy");
36 $socid =
GETPOST(
'socid',
'int');
39 if ($user->socid > 0) {
40 $socid = $user->socid;
46 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
50 $modecompta = $conf->global->ACCOUNTING_MODE;
52 $modecompta =
GETPOST(
"modecompta");
55 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
56 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
66 $month =
GETPOST(
"month",
'int');
67 $date_startyear =
GETPOST(
"date_startyear",
'int');
68 $date_startmonth =
GETPOST(
"date_startmonth",
'int');
69 $date_startday =
GETPOST(
"date_startday",
'int');
70 $date_endyear =
GETPOST(
"date_endyear",
'int');
71 $date_endmonth =
GETPOST(
"date_endmonth",
'int');
72 $date_endday =
GETPOST(
"date_endday",
'int');
76 $year_start = $year_current;
78 $year_current = $year;
85 if (empty($date_start) || empty($date_end)) {
89 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
90 $year_end = $year_start;
91 $month_end = $month_start;
93 if (!
GETPOST(
'year') && $month_start > $month_current) {
97 $month_end = $month_start - 1;
128 $year_start = $tmps[
'year'];
130 $year_end = $tmpe[
'year'];
131 $nbofyear = ($year_end - $year_start) + 1;
133 $commonparams = array();
134 $commonparams[
'modecompta'] = $modecompta;
135 $commonparams[
'sortorder'] = $sortorder;
136 $commonparams[
'sortfield'] = $sortfield;
138 $headerparams = array();
139 if (!empty($date_startyear)) {
140 $headerparams[
'date_startyear'] = $date_startyear;
142 if (!empty($date_startmonth)) {
143 $headerparams[
'date_startmonth'] = $date_startmonth;
145 if (!empty($date_startday)) {
146 $headerparams[
'date_startday'] = $date_startday;
148 if (!empty($date_endyear)) {
149 $headerparams[
'date_endyear'] = $date_endyear;
151 if (!empty($date_endmonth)) {
152 $headerparams[
'date_endmonth'] = $date_endmonth;
154 if (!empty($date_endday)) {
155 $headerparams[
'date_endday'] = $date_endday;
158 $headerparams[
'q'] = $q;
161 $tableparams = array();
164 $allparams = array_merge($commonparams, $headerparams, $tableparams);
165 $headerparams = array_merge($commonparams, $headerparams);
166 $tableparams = array_merge($commonparams, $tableparams);
169 foreach ($allparams as $key => $value) {
170 $paramslink .=
'&'.$key.
'='.$value;
182 if ($modecompta ==
"BOOKKEEPING") {
183 $modecompta =
"CREANCES-DETTES";
185 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
186 $modecompta =
"RECETTES-DEPENSES";
193 if ($modecompta ==
"CREANCES-DETTES") {
194 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
195 $calcmode = $langs->trans(
"CalcModeDebt");
197 $description = $langs->trans(
"RulesCADue");
198 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
199 $description .= $langs->trans(
"DepositsAreNotIncluded");
201 $description .= $langs->trans(
"DepositsAreIncluded");
205 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
206 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
207 $calcmode = $langs->trans(
"CalcModeEngagement");
209 $description = $langs->trans(
"RulesCAIn");
210 $description .= $langs->trans(
"DepositsAreIncluded");
213 } elseif ($modecompta ==
"BOOKKEEPING") {
215 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
218 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
220 $period .=
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
222 $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>';
227 $moreparam = array();
228 if (!empty($modecompta)) {
229 $moreparam[
'modecompta'] = $modecompta;
232 report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
234 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
235 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
242 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
243 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
245 foreach ($headerparams as $key => $value) {
246 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
252 if ($modecompta ==
'CREANCES-DETTES') {
253 $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";
254 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
255 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.fk_user_author = u.rowid";
256 $sql .=
" WHERE f.fk_statut in (1,2)";
257 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
258 $sql .=
" AND f.type IN (0,1,2,5)";
260 $sql .=
" AND f.type IN (0,1,2,3,5)";
262 if ($date_start && $date_end) {
263 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
265 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
270 $sql =
"SELECT u.rowid as rowid, u.lastname as name, u.firstname as firstname, sum(pf.amount) as amount_ttc";
271 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
272 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.fk_user_author = u.rowid ";
273 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_facture = f.rowid";
274 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement as p ON p.rowid = pf.fk_paiement";
275 $sql .=
" WHERE 1=1";
276 if ($date_start && $date_end) {
277 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
279 } elseif ($modecompta ==
"BOOKKEEPING") {
280 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
282 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
284 $sql .=
" AND f.fk_soc = ".((int) $socid);
286 $sql .=
" GROUP BY u.rowid, u.lastname, u.firstname";
287 $sql .=
" ORDER BY u.rowid";
292 $result = $db->query($sql);
294 $num = $db->num_rows($result);
297 $obj = $db->fetch_object($result);
298 $amount_ht[$obj->rowid] = $obj->amount;
299 $amount[$obj->rowid] = $obj->amount_ttc;
300 $name[$obj->rowid] = $obj->name.
' '.$obj->firstname;
301 $catotal_ht += $obj->amount;
302 $catotal += $obj->amount_ttc;
310 if ($modecompta ==
'RECETTES-DEPENSES') {
311 $sql =
"SELECT -1 as rowidx, '' as name, '' as firstname, sum(DISTINCT p.amount) as amount_ttc";
312 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
313 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
314 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
315 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
316 $sql .=
" WHERE pf.rowid IS NULL";
317 $sql .=
" AND p.fk_bank = b.rowid";
318 $sql .=
" AND b.fk_account = ba.rowid";
319 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
320 if ($date_start && $date_end) {
321 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
323 $sql .=
" GROUP BY rowidx, name, firstname";
324 $sql .=
" ORDER BY rowidx";
326 $result = $db->query($sql);
328 $num = $db->num_rows($result);
331 $obj = $db->fetch_object($result);
332 $amount[$obj->rowidx] = $obj->amount_ttc;
333 $name[$obj->rowidx] = $obj->name.
' '.$obj->firstname;
334 $catotal += $obj->amount_ttc;
344 print
'<div class="div-table-responsive">';
345 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
347 print
"<tr class=\"liste_titre\">";
349 $langs->trans(
"User"),
350 $_SERVER[
"PHP_SELF"],
358 if ($modecompta ==
'CREANCES-DETTES') {
360 $langs->trans(
'AmountHT'),
361 $_SERVER[
"PHP_SELF"],
373 $langs->trans(
"AmountTTC"),
374 $_SERVER[
"PHP_SELF"],
383 $langs->trans(
"Percentage"),
384 $_SERVER[
"PHP_SELF"],
393 $langs->trans(
"OtherStatistics"),
394 $_SERVER[
"PHP_SELF"],
398 'align="center" width="20%"'
402 if (count($amount)) {
403 $arrayforsort = $name;
406 if ($sortfield ==
'name' && $sortorder ==
'asc') {
408 $arrayforsort = $name;
410 if ($sortfield ==
'name' && $sortorder ==
'desc') {
412 $arrayforsort = $name;
414 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
416 $arrayforsort = $amount_ht;
418 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
420 $arrayforsort = $amount_ht;
422 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
424 $arrayforsort = $amount;
426 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
428 $arrayforsort = $amount;
433 foreach ($arrayforsort as $key => $value) {
434 print
'<tr class="oddeven">';
437 $fullname = $name[$key];
439 $linkname =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$fullname.
'</a>';
441 $linkname = $langs->trans(
"PaymentsNotLinkedToUser");
443 print
"<td>".$linkname.
"</td>\n";
446 print
'<td class="right">';
447 if ($modecompta ==
'RECETTES-DEPENSES') {
453 } elseif ($modecompta ==
'CREANCES-DETTES') {
455 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
459 print
price($amount_ht[$key]);
467 print
'<td class="right">';
468 if ($modecompta ==
'RECETTES-DEPENSES') {
474 } elseif ($modecompta ==
'CREANCES-DETTES') {
476 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
481 print
price($amount[$key]);
482 if ($modecompta ==
'RECETTES-DEPENSES') {
488 } elseif ($modecompta ==
'CREANCES-DETTES') {
496 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
499 print
'<td class="center">';
501 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
504 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
507 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
515 print
'<tr class="liste_total">';
516 print
'<td>'.$langs->trans(
"Total").
'</td>';
517 if ($modecompta !=
'CREANCES-DETTES') {
520 print
'<td class="right">'.price($catotal_ht).
'</td>';
522 print
'<td class="right">'.price($catotal).
'</td>';
523 print
'<td> </td>';
524 print
'<td> </td>';
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
restrictedArea($user, $features, $objectid=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.
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='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
isModEnabled($module)
Is Dolibarr module enabled.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
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_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...
img_previous($titlealt='default', $moreatt='')
Show previous logo.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.