24require
'../../main.inc.php';
25require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
26require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
29$langs->loadLangs(array(
'compta',
'bills'));
31$date_startday =
GETPOST(
'date_startday',
'int');
32$date_startmonth =
GETPOST(
'date_startmonth',
'int');
33$date_startyear =
GETPOST(
'date_startyear',
'int');
34$date_endday =
GETPOST(
'date_endday',
'int');
35$date_endmonth =
GETPOST(
'date_endmonth',
'int');
36$date_endyear =
GETPOST(
'date_endyear',
'int');
45 $year_start = $year_current - ($nbofyear - 1);
47 $year_current = $year;
49 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
51$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
52$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
55if (empty($date_start) || empty($date_end)) {
59 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
60 $month_start = GETPOSTISSET(
"month") ?
GETPOST(
"month",
'int') :
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1);
62 if (!$year && $month_start > $month_current) {
66 $month_end = $month_start - 1;
71 $month_end = $month_start;
94$userid =
GETPOST(
'userid',
'int');
95$socid =
GETPOST(
'socid',
'int');
98$year_start = $tmps[
'year'];
100$year_end = $tmpe[
'year'];
101$nbofyear = ($year_end - $year_start) + 1;
104$modecompta = $conf->global->ACCOUNTING_MODE;
105if (isModEnabled(
'accounting')) {
106 $modecompta =
'BOOKKEEPING';
108if (
GETPOST(
"modecompta",
'alpha')) {
109 $modecompta =
GETPOST(
"modecompta",
'alpha');
113if ($user->socid > 0) {
114 $socid = $user->socid;
116if (isModEnabled(
'comptabilite')) {
119if (isModEnabled(
'accounting')) {
120 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
130$form =
new Form($db);
140if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
141 $modecompta =
"RECETTES-DEPENSES";
145if ($modecompta ==
"CREANCES-DETTES") {
146 $name = $langs->trans(
"PurchaseTurnover");
147 $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>" :
"");
148 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
150} elseif ($modecompta ==
"RECETTES-DEPENSES") {
151 $name = $langs->trans(
"PurchaseTurnoverCollected");
152 $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>" :
"");
153 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
155} elseif ($modecompta ==
"BOOKKEEPING") {
156 $name = $langs->trans(
"PurchaseTurnover");
157 $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>" :
"");
158 $description = $langs->trans(
"RulesPurchaseTurnoverOfExpenseAccounts");
160} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
161 $name = $langs->trans(
"PurchaseTurnoverCollected");
162 $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>" :
"");
163 $description = $langs->trans(
"RulesPurchaseTurnoverCollectedOfExpenseAccounts");
167$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
169$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
172if (!empty($modecompta)) {
173 $moreparam[
'modecompta'] = $modecompta;
178if ($modecompta ==
"RECETTES-DEPENSES" || $modecompta ==
"BOOKKEEPINGCOLLECTED") {
183 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeEngagement");
184 if (isModEnabled(
'accounting')) {
185 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
187 $calcmode .=
'</label>';
189 if (isModEnabled(
'accounting')) {
190 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
193 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeEngagement");
194 if (isModEnabled(
'accounting')) {
195 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
197 $calcmode .=
'</label>';
201report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
203if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
204 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
208if ($modecompta ==
'CREANCES-DETTES') {
209 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
210 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
211 $sql .=
" WHERE f.fk_statut in (1,2)";
212 $sql .=
" AND f.type IN (0,2)";
213 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
215 $sql .=
" AND f.fk_soc = ".((int) $socid);
217} elseif ($modecompta ==
"RECETTES-DEPENSES") {
218 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
219 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
220 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
221 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
222 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
223 $sql .=
" AND pf.fk_facturefourn = f.rowid";
224 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
226 $sql .=
" AND f.fk_soc = ".((int) $socid);
228} elseif ($modecompta ==
"BOOKKEEPING") {
230 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
231 if (empty($pcgvercode)) {
232 $pcgvercode = $pcgverid;
235 $sql =
"SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.debit - b.credit) as amount_ttc";
236 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
237 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
238 $sql .=
" WHERE b.entity = ".$conf->entity;
239 $sql .=
" AND b.doc_type = 'supplier_invoice'";
240 $sql .=
" AND b.numero_compte = aa.account_number";
241 $sql .=
" AND aa.entity = ".$conf->entity;
242 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
243 $sql .=
" AND aa.pcg_type = 'EXPENSE'";
247$sql .=
" GROUP BY dm";
248$sql .=
" ORDER BY dm";
252$minyearmonth = $maxyearmonth = 0;
259$result = $db->query($sql);
261 $num = $db->num_rows($result);
264 $obj = $db->fetch_object($result);
265 $cum_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
266 $cum[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
267 if ($obj->amount_ttc) {
268 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
269 $maxyearmonth = max($maxyearmonth, $obj->dm);
280print
'<div class="div-table-responsive">';
281print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
283print
'<tr class="liste_titre"><td> </td>';
285for ($annee = $year_start; $annee <= $year_end; $annee++) {
286 if ($modecompta ==
'CREANCES-DETTES') {
287 print
'<td align="center" width="10%" colspan="3">';
289 print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
291 if ($modecompta !=
'BOOKKEEPING') {
292 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
295 if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) {
296 print
'-'.($annee + 1);
298 if ($modecompta !=
'BOOKKEEPING') {
302 if ($annee != $year_end) {
303 print
'<td width="15"> </td>';
308print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
309for ($annee = $year_start; $annee <= $year_end; $annee++) {
310 if ($modecompta ==
'CREANCES-DETTES') {
311 print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
313 print
'<td class="liste_titre right">';
314 if ($modecompta ==
"BOOKKEEPING") {
315 print $langs->trans(
"Amount");
317 print $langs->trans(
"AmountTTC");
320 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
321 if ($annee != $year_end) {
322 print
'<td class="liste_titre" width="15"> </td>';
328$minyear = substr($minyearmonth, 0, 4);
329$maxyear = substr($maxyearmonth, 0, 4);
331$nowyearmonth = strftime(
"%Y-%m",
dol_now());
332$maxyearmonth = max($maxyearmonth, $nowyearmonth);
337$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0;
338for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
339 $mois_modulo = $mois;
341 $mois_modulo = $mois - 12;
344 if ($year_start == $year_end) {
345 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
350 print
'<tr class="oddeven">';
353 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
355 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) {
356 $annee_decalage = $annee;
358 $annee_decalage = $annee + 1;
363 if ($annee >= $year_start) {
364 if ($modecompta ==
'CREANCES-DETTES') {
366 print
'<td class="right">';
367 if (!empty($cum_ht[$case])) {
369 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price($cum_ht[$case], 1).
'</a>';
371 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
381 print
'<td class="right">';
382 if (!empty($cum[$case])) {
384 if ($modecompta !=
'BOOKKEEPING') {
385 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
387 print
price($cum[$case], 1);
388 if ($modecompta !=
'BOOKKEEPING') {
392 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
401 if ($annee_decalage > $minyear && $case <= $casenow) {
402 if (!empty($cum[$caseprev]) && !empty($cum[$case])) {
403 $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100);
405 print
'<td class="borderrightlight right">'.($percent >= 0 ?
"+$percent" :
"$percent").
'%</td>';
407 if (!empty($cum[$caseprev]) && empty($cum[$case])) {
408 print
'<td class="borderrightlight right">-100%</td>';
410 if (empty($cum[$caseprev]) && !empty($cum[$case])) {
412 print
'<td class="borderrightlight right">-</td>';
414 if (isset($cum[$caseprev]) && empty($cum[$caseprev]) && empty($cum[$case])) {
415 print
'<td class="borderrightlight right">+0%</td>';
417 if (!isset($cum[$caseprev]) && empty($cum[$case])) {
418 print
'<td class="borderrightlight right">-</td>';
421 print
'<td class="borderrightlight right">';
422 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
430 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
431 print
'<td width="15"> </td>';
435 if (empty($total_ht[$annee])) {
436 $total_ht[$annee] = ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0);
438 $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0);
440 if (empty($total[$annee])) {
441 $total[$annee] = (empty($cum[$case]) ? 0 : $cum[$case]);
443 $total[$annee] += (empty($cum[$case]) ? 0 : $cum[$case]);
451print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
452for ($annee = $year_start; $annee <= $year_end; $annee++) {
453 if ($modecompta ==
'CREANCES-DETTES') {
455 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
456 print
'<td class="nowrap right">';
457 print ($total_ht[$annee] ?
price($total_ht[$annee]) :
"0");
460 print
'<td> </td>';
465 if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
466 print
'<td class="nowrap right">'.($total[$annee] ?
price($total[$annee]) :
"0").
"</td>";
468 print
'<td> </td>';
472 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
473 if ($total[$annee - 1] && $total[$annee]) {
474 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
475 print
'<td class="nowrap borderrightlight right">';
476 print ($percent >= 0 ?
"+$percent" :
"$percent").
'%';
479 if (!empty($total[$annee - 1]) && empty($total[$annee])) {
480 print
'<td class="borderrightlight right">-100%</td>';
482 if (empty($total[$annee - 1]) && !empty($total[$annee])) {
483 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
485 if (empty($total[$annee - 1]) && empty($total[$annee])) {
486 print
'<td class="borderrightlight right">+0%</td>';
489 print
'<td class="borderrightlight right">';
490 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
498 if ($annee != $year_end) {
499 print
'<td width="15"> </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_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...
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.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
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_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.