31require
'../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
44$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries'));
47$date_startmonth =
GETPOSTINT(
'date_startmonth');
60 $year_start = $year_current - ($nbofyear - 1);
62 $year_current = $year;
64 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
67$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
74 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
77 if (!$year && $month_start > $month_current) {
81 $month_end = $month_start - 1;
86 $month_end = $month_start;
113$month_start = $tmps[
'mon'];
114$year_start = $tmps[
'year'];
116$month_end = $tmpe[
'mon'];
117$year_end = $tmpe[
'year'];
118$nbofyear = ($year_end - $year_start) + 1;
123 $modecompta =
'BOOKKEEPING';
125if (
GETPOST(
"modecompta",
'alpha')) {
126 $modecompta =
GETPOST(
"modecompta",
'alpha');
130if ($user->socid > 0) {
131 $socid = $user->socid;
137 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
148if ($date_startday && $date_startmonth && $date_startyear) {
149 $param .=
'&date_startday='.$date_startday.
'&date_startmonth='.$date_startmonth.
'&date_startyear='.$date_startyear;
151if ($date_endday && $date_endmonth && $date_endyear) {
152 $param .=
'&date_endday='.$date_endday.
'&date_endmonth='.$date_endmonth.
'&date_endyear='.$date_endyear;
157$form =
new Form($db);
167if ($modecompta ==
"CREANCES-DETTES") {
168 $name = $langs->trans(
"Turnover");
169 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear - 2).
"&modecompta=".$modecompta.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear).
"&modecompta=".$modecompta.
"'>".
img_next().
"</a>" :
"");
170 $description = $langs->trans(
"RulesCADue");
172 $description .= $langs->trans(
"DepositsAreNotIncluded");
174 $description .= $langs->trans(
"DepositsAreIncluded");
177} elseif ($modecompta ==
"RECETTES-DEPENSES") {
178 $name = $langs->trans(
"TurnoverCollected");
179 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear - 2).
"&modecompta=".$modecompta.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear).
"&modecompta=".$modecompta.
"'>".
img_next().
"</a>" :
"");
180 $description = $langs->trans(
"RulesCAIn");
181 $description .= $langs->trans(
"DepositsAreIncluded");
183} elseif ($modecompta ==
"BOOKKEEPING") {
184 $name = $langs->trans(
"Turnover");
185 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear - 2).
"&modecompta=".$modecompta.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear).
"&modecompta=".$modecompta.
"'>".
img_next().
"</a>" :
"");
186 $description = $langs->trans(
"RulesSalesTurnoverOfIncomeAccounts");
189$period = $form->selectDate(
$date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
191$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
194if (!empty($modecompta)) {
195 $moreparam[
'modecompta'] = $modecompta;
200if ($modecompta ==
"RECETTES-DEPENSES" || $modecompta ==
"BOOKKEEPINGCOLLECTED") {
205 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModePayment");
207 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
209 $calcmode .=
'</label>';
212 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
213 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"DataMustHaveBeenTransferredInAccounting").
')</span>';
216 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
218 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
220 $calcmode .=
'</label>';
223report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
227 if ($modecompta !=
'BOOKKEEPING') {
228 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
232 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
233 if (empty($pcgvercode)) {
234 $pcgvercode = $pcgverid;
237 $sql =
"SELECT b.rowid ";
238 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
239 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
240 $sql .=
" WHERE b.entity = ".((int)
$conf->entity);
241 $sql .=
" AND b.numero_compte = aa.account_number";
242 $sql .=
" AND aa.entity = ".((int)
$conf->entity);
243 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
244 $sql .= $db->plimit(1);
246 $resql = $db->query($sql);
247 $nb = $db->num_rows($resql);
249 $langs->load(
"errors");
250 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0,
'1');
256if ($modecompta ==
'CREANCES-DETTES') {
257 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
258 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
259 $sql .=
" WHERE f.fk_statut in (1,2)";
261 $sql .=
" AND f.type IN (0,1,2,5)";
263 $sql .=
" AND f.type IN (0,1,2,3,5)";
266 $hookmanager->initHooks(array(
'turnoverreport'));
267 $parameters = array(
'invoicealias' =>
'f',
'issupplier' => 0,
'datefield' =>
'datef');
268 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
269 $sql .= $hookmanager->resPrint;
270 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
272 $sql .=
" AND f.fk_soc = ".((int) $socid);
274} elseif ($modecompta ==
"RECETTES-DEPENSES") {
279 $sql =
"SELECT date_format(p.datep, '%Y-%m') as dm, sum(pf.amount) as amount_ttc";
280 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
281 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
282 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
283 $sql .=
" WHERE p.rowid = pf.fk_paiement";
284 $sql .=
" AND pf.fk_facture = f.rowid";
285 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
287 $sql .=
" AND f.fk_soc = ".((int) $socid);
289} elseif ($modecompta ==
"BOOKKEEPING") {
291 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
292 if (empty($pcgvercode)) {
293 $pcgvercode = $pcgverid;
296 $sql =
"SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.credit - b.debit) as amount_ttc";
297 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
298 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
299 $sql .=
" WHERE b.entity = ".((int)
$conf->entity);
300 $sql .=
" AND b.numero_compte = aa.account_number";
301 $sql .=
" AND b.doc_type = 'customer_invoice'";
302 $sql .=
" AND aa.entity = ".((int)
$conf->entity);
303 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
304 $sql .=
" AND aa.pcg_type = 'INCOME'";
306$sql .=
" GROUP BY dm";
307$sql .=
" ORDER BY dm";
311$minyearmonth = $maxyearmonth = 0;
313$cumulative = array();
314$cumulative_ht = array();
318$result = $db->query($sql);
320 $num = $db->num_rows($result);
323 $obj = $db->fetch_object($result);
324 $cumulative_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
325 $cumulative[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
326 if ($obj->amount_ttc) {
327 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
328 $maxyearmonth = max($maxyearmonth, $obj->dm);
334 dol_print_error($db);
338if ($modecompta ==
'RECETTES-DEPENSES') {
339 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
340 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
341 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
342 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
343 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
344 $sql .=
" WHERE pf.rowid IS NULL";
345 $sql .=
" AND p.fk_bank = b.rowid";
346 $sql .=
" AND b.fk_account = ba.rowid";
347 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
348 $sql .=
" GROUP BY dm";
349 $sql .=
" ORDER BY dm";
351 $result = $db->query($sql);
353 $num = $db->num_rows($result);
356 $obj = $db->fetch_object($result);
357 if (empty($cumulative[$obj->dm])) {
358 $cumulative[$obj->dm] = $obj->amount_ttc;
360 $cumulative[$obj->dm] += $obj->amount_ttc;
362 if ($obj->amount_ttc) {
363 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
364 $maxyearmonth = max($maxyearmonth, $obj->dm);
369 dol_print_error($db);
375print
'<div class="div-table-responsive">';
376print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
378print
'<tr class="liste_titre"><td> </td>';
380for ($annee = $year_start; $annee <= $year_end; $annee++) {
381 if ($modecompta ==
'CREANCES-DETTES') {
382 print
'<td align="center" width="10%" colspan="3">';
384 print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
386 if ($modecompta !=
'BOOKKEEPING') {
387 print
'<a href="casoc.php?year='.$annee.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
391 print
'-'.($annee + 1);
393 if ($modecompta !=
'BOOKKEEPING') {
397 if ($annee != $year_end) {
398 print
'<td width="15"> </td>';
403print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
404for ($annee = $year_start; $annee <= $year_end; $annee++) {
405 if ($modecompta ==
'CREANCES-DETTES') {
406 print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
408 print
'<td class="liste_titre right">';
409 if ($modecompta ==
"BOOKKEEPING") {
410 print $langs->trans(
"Amount");
412 print $langs->trans(
"AmountTTC");
415 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
416 if ($annee != $year_end) {
417 print
'<td class="liste_titre" width="15"> </td>';
423$minyear = substr($minyearmonth, 0, 4);
424$maxyear = substr($maxyearmonth, 0, 4);
427$maxyearmonth = max($maxyearmonth, $nowyearmonth);
433for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
434 $mois_modulo = $mois;
436 $mois_modulo = $mois - 12;
439 if ($year_start == $year_end) {
441 if ($mois < $date_startmonth && $year_start <= $date_startyear) {
445 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
450 print
'<tr class="oddeven">';
453 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
455 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) {
456 $annee_decalage = $annee;
458 $annee_decalage = $annee + 1;
463 if ($annee >= $year_start) {
464 if ($modecompta ==
'CREANCES-DETTES') {
466 print
'<td class="right">';
467 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
468 if (!empty($cumulative_ht[$case])) {
470 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.
'&modecompta='.$modecompta.
'">'.
price($cumulative_ht[$case], 1).
'</a>';
472 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
483 print
'<td class="right">';
484 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
485 if (!empty($cumulative[$case])) {
487 if ($modecompta !=
'BOOKKEEPING') {
488 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
490 print
price($cumulative[$case], 1);
491 if ($modecompta !=
'BOOKKEEPING') {
495 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
505 print
'<td class="borderrightlight right"><span class="opacitymedium">';
507 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
508 if ($annee_decalage > $minyear && $case <= $casenow) {
509 if ($modecompta==
'CREANCES-DETTES') {
510 $cumulative_previous_year = (!empty($cumulative_ht[$caseprev]) ? (float) $cumulative_ht[$caseprev] : 0);
511 $cumulative_year = (!empty($cumulative_ht[$case]) ? (float) $cumulative_ht[$case] : 0);
512 $isset_cumulative_previous_year = isset($cumulative_ht[$caseprev]);
514 $cumulative_previous_year = (!empty($cumulative[$caseprev]) ? (float) $cumulative[$caseprev] : 0);
515 $cumulative_year = (!empty($cumulative[$case]) ? (float) $cumulative[$case] : 0);
516 $isset_cumulative_previous_year = isset($cumulative_ht[$caseprev]);
518 if (!empty($cumulative_previous_year) && !empty($cumulative_year)) {
519 $percent = (round(($cumulative_year - $cumulative_previous_year) / $cumulative_previous_year, 4) * 100);
521 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
523 if (!empty($cumulative_previous_year) && empty($cumulative_year)) {
526 if (empty($cumulative_previous_year) && !empty($cumulative_year)) {
530 if ($isset_cumulative_previous_year && empty($cumulative_previous_year) && empty($cumulative_year)) {
533 if (!$isset_cumulative_previous_year && empty($cumulative_year)) {
537 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
544 print
'</span></td>';
546 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
547 print
'<td width="15"> </td>';
551 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
552 if (empty($total_ht[$annee])) {
553 $total_ht[$annee] = (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
555 $total_ht[$annee] += (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
557 if (empty($total[$annee])) {
558 $total[$annee] = empty($cumulative[$case]) ? 0 : $cumulative[$case];
560 $total[$annee] += empty($cumulative[$case]) ? 0 : $cumulative[$case];
633print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
634for ($annee = $year_start; $annee <= $year_end; $annee++) {
635 if ($modecompta ==
'CREANCES-DETTES') {
637 if (isset($total_ht[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
638 print
'<td class="nowrap right">';
639 print(empty($total_ht[$annee]) ?
'0' :
price($total_ht[$annee]));
642 print
'<td> </td>';
647 if (!empty($total[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
648 print
'<td class="nowrap right">';
649 print(empty($total[$annee]) ?
'0' :
price($total[$annee]));
652 print
'<td> </td>';
656 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
657 if ($modecompta ==
'CREANCES-DETTES') {
658 $total_previous_year = (!empty($total_ht[$annee - 1]) ? (float) $total_ht[$annee - 1] : 0);
659 $total_year = (!empty($total_ht[$annee]) ? (float) $total_ht[$annee] : 0);
661 $total_previous_year = (!empty($total[$annee - 1]) ? (float) $total[$annee - 1] : 0);
662 $total_year = (!empty($total[$annee]) ? (float) $total[$annee] : 0);
664 if (!empty($total_previous_year) && !empty($total_year)) {
665 $percent = (round(($total_year - $total_previous_year) / $total_previous_year, 4) * 100);
666 print
'<td class="nowrap borderrightlight right">';
667 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
670 if (!empty($total_previous_year) && empty($total_year)) {
671 print
'<td class="borderrightlight right">-100%</td>';
673 if (empty($total_previous_year) && !empty($total_year)) {
674 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
676 if (empty($total_previous_year) && empty($total_year)) {
677 print
'<td class="borderrightlight right">+0%</td>';
680 print
'<td class="borderrightlight right">';
681 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
689 if ($annee != $year_end) {
690 print
'<td width="15"> </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_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).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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.