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'));
32$date_startmonth =
GETPOSTINT(
'date_startmonth');
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);
62 if (!$year && $month_start > $month_current) {
66 $month_end = $month_start - 1;
71 $month_end = $month_start;
98$month_start = $tmps[
'mon'];
99$year_start = $tmps[
'year'];
101$month_end = $tmpe[
'mon'];
102$year_end = $tmpe[
'year'];
103$nbofyear = ($year_end - $year_start) + 1;
107if (isModEnabled(
'accounting')) {
108 $modecompta =
'BOOKKEEPING';
110if (
GETPOST(
"modecompta",
'alpha')) {
111 $modecompta =
GETPOST(
"modecompta",
'alpha');
115if ($user->socid > 0) {
116 $socid = $user->socid;
118if (isModEnabled(
'comptabilite')) {
121if (isModEnabled(
'accounting')) {
122 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
132$form =
new Form($db);
142if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
143 $modecompta =
"RECETTES-DEPENSES";
147if ($modecompta ==
"CREANCES-DETTES") {
148 $name = $langs->trans(
"PurchaseTurnover");
149 $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>" :
"");
150 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
152} elseif ($modecompta ==
"RECETTES-DEPENSES") {
153 $name = $langs->trans(
"PurchaseTurnoverCollected");
154 $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>" :
"");
155 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
157} elseif ($modecompta ==
"BOOKKEEPING") {
158 $name = $langs->trans(
"PurchaseTurnover");
159 $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>" :
"");
160 $description = $langs->trans(
"RulesPurchaseTurnoverOfExpenseAccounts");
162} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
163 $name = $langs->trans(
"PurchaseTurnoverCollected");
164 $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>" :
"");
165 $description = $langs->trans(
"RulesPurchaseTurnoverCollectedOfExpenseAccounts");
169$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
171$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
174if (!empty($modecompta)) {
175 $moreparam[
'modecompta'] = $modecompta;
180if ($modecompta ==
"RECETTES-DEPENSES" || $modecompta ==
"BOOKKEEPINGCOLLECTED") {
185 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModePayment");
186 if (isModEnabled(
'accounting')) {
187 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
189 $calcmode .=
'</label>';
191 if (isModEnabled(
'accounting')) {
192 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
193 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"DataMustHaveBeenTransferredInAccounting").
')</span>';
196 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
197 if (isModEnabled(
'accounting')) {
198 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
200 $calcmode .=
'</label>';
204report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
206if (isModEnabled(
'accounting')) {
207 if ($modecompta !=
'BOOKKEEPING') {
208 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
212 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
213 if (empty($pcgvercode)) {
214 $pcgvercode = $pcgverid;
217 $sql =
"SELECT b.rowid ";
218 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
219 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
220 $sql .=
" WHERE b.entity = ".$conf->entity;
221 $sql .=
" AND b.numero_compte = aa.account_number";
222 $sql .=
" AND aa.entity = ".$conf->entity;
223 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
224 $sql .= $db->plimit(1);
226 $resql = $db->query($sql);
227 $nb = $db->num_rows($resql);
229 $langs->load(
"errors");
230 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0, 1);
236if ($modecompta ==
'CREANCES-DETTES') {
237 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
238 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
239 $sql .=
" WHERE f.fk_statut in (1,2)";
240 $sql .=
" AND f.type IN (0,2)";
241 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
243 $sql .=
" AND f.fk_soc = ".((int) $socid);
245} elseif ($modecompta ==
"RECETTES-DEPENSES") {
246 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
247 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
248 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
249 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
250 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
251 $sql .=
" AND pf.fk_facturefourn = f.rowid";
252 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
254 $sql .=
" AND f.fk_soc = ".((int) $socid);
256} elseif ($modecompta ==
"BOOKKEEPING") {
258 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
259 if (empty($pcgvercode)) {
260 $pcgvercode = $pcgverid;
263 $sql =
"SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.debit - b.credit) as amount_ttc";
264 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
265 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
266 $sql .=
" WHERE b.entity = ".$conf->entity;
267 $sql .=
" AND b.doc_type = 'supplier_invoice'";
268 $sql .=
" AND b.numero_compte = aa.account_number";
269 $sql .=
" AND aa.entity = ".$conf->entity;
270 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
271 $sql .=
" AND aa.pcg_type = 'EXPENSE'";
273$sql .=
" GROUP BY dm";
274$sql .=
" ORDER BY dm";
278$minyearmonth = $maxyearmonth = 0;
280$cumulative = array();
281$cumulative_ht = array();
285$result = $db->query($sql);
287 $num = $db->num_rows($result);
290 $obj = $db->fetch_object($result);
291 $cumulative_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
292 $cumulative[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
293 if ($obj->amount_ttc) {
294 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
295 $maxyearmonth = max($maxyearmonth, $obj->dm);
306print
'<div class="div-table-responsive">';
307print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
309print
'<tr class="liste_titre"><td> </td>';
311for ($annee = $year_start; $annee <= $year_end; $annee++) {
312 if ($modecompta ==
'CREANCES-DETTES') {
313 print
'<td align="center" width="10%" colspan="3">';
315 print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
317 if ($modecompta !=
'BOOKKEEPING') {
318 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
322 print
'-'.($annee + 1);
324 if ($modecompta !=
'BOOKKEEPING') {
328 if ($annee != $year_end) {
329 print
'<td width="15"> </td>';
334print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
335for ($annee = $year_start; $annee <= $year_end; $annee++) {
336 if ($modecompta ==
'CREANCES-DETTES') {
337 print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
339 print
'<td class="liste_titre right">';
340 if ($modecompta ==
"BOOKKEEPING") {
341 print $langs->trans(
"Amount");
343 print $langs->trans(
"AmountTTC");
346 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
347 if ($annee != $year_end) {
348 print
'<td class="liste_titre" width="15"> </td>';
354$minyear = substr($minyearmonth, 0, 4);
355$maxyear = substr($maxyearmonth, 0, 4);
358$maxyearmonth = max($maxyearmonth, $nowyearmonth);
363$nb_mois_decalage = GETPOSTISSET(
'date_startmonth') ? (
GETPOSTINT(
'date_startmonth') - 1) : (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 0 : (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') - 1));
364for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
365 $mois_modulo = $mois;
367 $mois_modulo = $mois - 12;
370 if ($year_start == $year_end) {
371 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
376 print
'<tr class="oddeven">';
379 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
381 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) {
382 $annee_decalage = $annee;
384 $annee_decalage = $annee + 1;
389 if ($annee >= $year_start) {
390 if ($modecompta ==
'CREANCES-DETTES') {
392 print
'<td class="right">';
393 if (!empty($cumulative_ht[$case])) {
395 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price($cumulative_ht[$case], 1).
'</a>';
397 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
407 print
'<td class="right">';
408 if (!empty($cumulative[$case])) {
410 if ($modecompta !=
'BOOKKEEPING') {
411 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
413 print
price($cumulative[$case], 1);
414 if ($modecompta !=
'BOOKKEEPING') {
418 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
427 if ($annee_decalage > $minyear && $case <= $casenow) {
428 if (!empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
429 $percent = (round(($cumulative[$case] - $cumulative[$caseprev]) / $cumulative[$caseprev], 4) * 100);
431 print
'<td class="borderrightlight right">'.($percent >= 0 ?
"+$percent" :
"$percent").
'%</td>';
433 if (!empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
434 print
'<td class="borderrightlight right">-100%</td>';
436 if (empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
438 print
'<td class="borderrightlight right">-</td>';
440 if (isset($cumulative[$caseprev]) && empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
441 print
'<td class="borderrightlight right">+0%</td>';
443 if (!isset($cumulative[$caseprev]) && empty($cumulative[$case])) {
444 print
'<td class="borderrightlight right">-</td>';
447 print
'<td class="borderrightlight right">';
448 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
456 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
457 print
'<td width="15"> </td>';
461 if (empty($total_ht[$annee])) {
462 $total_ht[$annee] = ((!empty($cumulative_ht[$case])) ? $cumulative_ht[$case] : 0);
464 $total_ht[$annee] += ((!empty($cumulative_ht[$case])) ? $cumulative_ht[$case] : 0);
466 if (empty($total[$annee])) {
467 $total[$annee] = (empty($cumulative[$case]) ? 0 : $cumulative[$case]);
469 $total[$annee] += (empty($cumulative[$case]) ? 0 : $cumulative[$case]);
477print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
478for ($annee = $year_start; $annee <= $year_end; $annee++) {
479 if ($modecompta ==
'CREANCES-DETTES') {
481 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
482 print
'<td class="nowrap right">';
483 print($total_ht[$annee] ?
price($total_ht[$annee]) :
"0");
486 print
'<td> </td>';
491 if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
492 print
'<td class="nowrap right">'.($total[$annee] ?
price($total[$annee]) :
"0").
"</td>";
494 print
'<td> </td>';
498 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
499 if ($total[$annee - 1] && $total[$annee]) {
500 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
501 print
'<td class="nowrap borderrightlight right">';
502 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
505 if (!empty($total[$annee - 1]) && empty($total[$annee])) {
506 print
'<td class="borderrightlight right">-100%</td>';
508 if (empty($total[$annee - 1]) && !empty($total[$annee])) {
509 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
511 if (empty($total[$annee - 1]) && empty($total[$annee])) {
512 print
'<td class="borderrightlight right">+0%</td>';
515 print
'<td class="borderrightlight right">';
516 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
524 if ($annee != $year_end) {
525 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 information (by default a local PHP server timestamp) Rep...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a 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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
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.