27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
33 $langs->load(
"accountancy");
35 $socid =
GETPOST(
'socid',
'int');
38 if ($user->socid > 0) $socid = $user->socid;
39 if (!empty($conf->comptabilite->enabled)) $result =
restrictedArea($user,
'compta',
'',
'',
'resultat');
40 if (!empty($conf->accounting->enabled)) $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
43 $modecompta = $conf->global->ACCOUNTING_MODE;
46 $sortorder = isset($_GET[
"sortorder"]) ? $_GET[
"sortorder"] : $_POST[
"sortorder"];
47 $sortfield = isset($_GET[
"sortfield"]) ? $_GET[
"sortfield"] : $_POST[
"sortfield"];
48 if (!$sortorder) $sortorder =
"asc";
49 if (!$sortfield) $sortfield =
"name";
54 $date_startyear =
GETPOST(
"date_startyear");
55 $date_startmonth =
GETPOST(
"date_startmonth");
56 $date_startday =
GETPOST(
"date_startday");
57 $date_endyear =
GETPOST(
"date_endyear");
58 $date_endmonth =
GETPOST(
"date_endmonth");
59 $date_endday =
GETPOST(
"date_endday");
62 $year_current = strftime(
"%Y",
dol_now());
63 $month_current = strftime(
"%m",
dol_now());
64 $year_start = $year_current;
66 $year_current = $year;
67 $month_current = strftime(
"%m",
dol_now());
70 $date_start =
dol_mktime(0, 0, 0, $_REQUEST[
"date_startmonth"], $_REQUEST[
"date_startday"], $_REQUEST[
"date_startyear"]);
71 $date_end =
dol_mktime(23, 59, 59, $_REQUEST[
"date_endmonth"], $_REQUEST[
"date_endday"], $_REQUEST[
"date_endyear"]);
73 if (empty($date_start) || empty($date_end))
79 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
80 $year_end = $year_start;
81 $month_end = $month_start;
84 if (!
GETPOST(
'year') && $month_start > $month_current)
89 $month_end = $month_start - 1;
90 if ($month_end < 1) $month_end = 12;
104 $year_start = $tmps[
'year'];
106 $year_end = $tmpe[
'year'];
107 $nbofyear = ($year_end - $year_start) + 1;
109 $commonparams = array();
110 $commonparams[
'modecompta'] = $modecompta;
111 $commonparams[
'sortorder'] = $sortorder;
112 $commonparams[
'sortfield'] = $sortfield;
114 $headerparams = array();
115 $headerparams[
'date_startyear'] = $date_startyear;
116 $headerparams[
'date_startmonth'] = $date_startmonth;
117 $headerparams[
'date_startday'] = $date_startday;
118 $headerparams[
'date_endyear'] = $date_endyear;
119 $headerparams[
'date_endmonth'] = $date_endmonth;
120 $headerparams[
'date_endday'] = $date_endday;
121 $headerparams[
'q'] = $q;
123 $tableparams = array();
124 $tableparams[
'search_categ'] = $selected_cat;
125 $tableparams[
'subcat'] = ($subcat ===
true) ?
'yes' :
'';
128 $allparams = array_merge($commonparams, $headerparams, $tableparams);
129 $headerparams = array_merge($commonparams, $headerparams);
130 $tableparams = array_merge($commonparams, $tableparams);
132 foreach ($allparams as $key => $value) {
133 $paramslink .=
'&'.$key.
'='.$value;
142 $form =
new Form($db);
145 if ($modecompta ==
"BOOKKEEPING") $modecompta =
"CREANCES-DETTES";
146 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") $modecompta =
"RECETTES-DEPENSES";
149 if ($modecompta ==
"CREANCES-DETTES") {
150 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
151 $calcmode = $langs->trans(
"CalcModeDebt");
153 $description = $langs->trans(
"RulesCADue");
154 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans(
"DepositsAreNotIncluded");
155 else $description .= $langs->trans(
"DepositsAreIncluded");
158 } elseif ($modecompta ==
"RECETTES-DEPENSES")
160 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByUserAuthorOfInvoice");
161 $calcmode = $langs->trans(
"CalcModeEngagement");
163 $description = $langs->trans(
"RulesCAIn");
164 $description .= $langs->trans(
"DepositsAreIncluded");
167 } elseif ($modecompta ==
"BOOKKEEPING")
170 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED")
174 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
175 if ($date_end ==
dol_time_plus_duree($date_start, 1,
'y') - 1) $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>';
176 else $periodlink =
'';
178 $moreparam = array();
179 if (!empty($modecompta)) $moreparam[
'modecompta'] = $modecompta;
181 report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
183 if (!empty($conf->accounting->enabled) && $modecompta !=
'BOOKKEEPING')
192 print '<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
193 print '<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
195 foreach ($headerparams as $key => $value)
197 print '<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
201 if ($modecompta ==
'CREANCES-DETTES') {
202 $sql =
"SELECT u.rowid as rowid, u.lastname as name, u.firstname as firstname, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc";
203 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
204 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.fk_user_author = u.rowid";
205 $sql .=
" WHERE f.fk_statut in (1,2)";
206 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
207 $sql .=
" AND f.type IN (0,1,2,5)";
209 $sql .=
" AND f.type IN (0,1,2,3,5)";
211 if ($date_start && $date_end) {
212 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
219 $sql =
"SELECT u.rowid as rowid, u.lastname as name, u.firstname as firstname, sum(pf.amount) as amount_ttc";
220 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
221 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.fk_user_author = u.rowid ";
222 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_facture = f.rowid";
223 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement as p ON p.rowid = pf.fk_paiement";
224 $sql .=
" WHERE 1=1";
225 if ($date_start && $date_end) {
226 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
229 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
230 if ($socid) $sql .=
" AND f.fk_soc = ".$socid;
231 $sql .=
" GROUP BY u.rowid, u.lastname, u.firstname";
232 $sql .=
" ORDER BY u.rowid";
237 $result = $db->query($sql);
239 $num = $db->num_rows($result);
242 $obj = $db->fetch_object($result);
243 $amount_ht[$obj->rowid] = $obj->amount;
244 $amount[$obj->rowid] = $obj->amount_ttc;
245 $name[$obj->rowid] = $obj->name.
' '.$obj->firstname;
246 $catotal_ht += $obj->amount;
247 $catotal += $obj->amount_ttc;
255 if ($modecompta !=
'CREANCES-DETTES') {
256 $sql =
"SELECT -1 as rowidx, '' as name, '' as firstname, sum(DISTINCT p.amount) as amount_ttc";
257 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
258 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
259 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
260 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
261 $sql .=
" WHERE pf.rowid IS NULL";
262 $sql .=
" AND p.fk_bank = b.rowid";
263 $sql .=
" AND b.fk_account = ba.rowid";
264 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
265 if ($date_start && $date_end) {
266 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
268 $sql .=
" GROUP BY rowidx, name, firstname";
269 $sql .=
" ORDER BY rowidx";
271 $result = $db->query($sql);
273 $num = $db->num_rows($result);
276 $obj = $db->fetch_object($result);
277 $amount[$obj->rowidx] = $obj->amount_ttc;
278 $name[$obj->rowidx] = $obj->name.
' '.$obj->firstname;
279 $catotal += $obj->amount_ttc;
289 print '<div class="div-table-responsive">';
290 print '<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
292 print "<tr class=\"liste_titre\">";
294 $langs->trans(
"User"),
303 if ($modecompta ==
'CREANCES-DETTES') {
305 $langs->trans(
'AmountHT'),
318 $langs->trans(
"AmountTTC"),
328 $langs->trans(
"Percentage"),
337 $langs->trans(
"OtherStatistics"),
342 'align="center" width="20%"'
346 if (count($amount)) {
347 $arrayforsort = $name;
350 if ($sortfield ==
'name' && $sortorder ==
'asc') {
352 $arrayforsort = $name;
354 if ($sortfield ==
'name' && $sortorder ==
'desc') {
356 $arrayforsort = $name;
358 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
360 $arrayforsort = $amount_ht;
362 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
364 $arrayforsort = $amount_ht;
366 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
368 $arrayforsort = $amount;
370 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
372 $arrayforsort = $amount;
377 foreach ($arrayforsort as $key => $value) {
378 print
'<tr class="oddeven">';
381 $fullname = $name[$key];
383 $linkname =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$fullname.
'</a>';
385 $linkname = $langs->trans(
"PaymentsNotLinkedToUser");
387 print
"<td>".$linkname.
"</td>\n";
390 print
'<td class="right">';
391 if ($modecompta ==
'RECETTES-DEPENSES') {
397 } elseif ($modecompta ==
'CREANCES-DETTES') {
399 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
403 print
price($amount_ht[$key]);
404 if ($key > 0) print
'</a>';
409 print
'<td class="right">';
410 if ($modecompta ==
'RECETTES-DEPENSES') {
416 } elseif ($modecompta ==
'CREANCES-DETTES') {
418 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?userid='.$key.
'">';
423 print
price($amount[$key]);
424 if ($modecompta ==
'RECETTES-DEPENSES') {
430 } elseif ($modecompta ==
'CREANCES-DETTES') {
438 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
441 print
'<td class="center">';
442 if (!empty($conf->propal->enabled) && $key > 0) {
443 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
445 if (!empty($conf->commande->enabled) && $key > 0) {
446 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
448 if (!empty($conf->facture->enabled) && $key > 0) {
449 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?userid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
457 print
'<tr class="liste_total">';
458 print
'<td>'.$langs->trans(
"Total").
'</td>';
459 if ($modecompta !=
'CREANCES-DETTES') {
462 print
'<td class="right">'.price($catotal_ht).
'</td>';
464 print
'<td class="right">'.price($catotal).
'</td>';
465 print
'<td> </td>';
466 print
'<td> </td>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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_now($mode= 'auto')
Return date for now.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
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...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
print
Draft customers invoices.
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.