25require
'../../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
30$langs->loadLangs(array(
'compta',
'bills'));
33$date_startmonth =
GETPOSTINT(
'date_startmonth');
46 $year_start = $year_current - ($nbofyear - 1);
48 $year_current = $year;
50 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
52$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
53$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
56if (empty($date_start) || empty($date_end)) {
60 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
63 if (!$year && $month_start > $month_current) {
67 $month_end = $month_start - 1;
72 $month_end = $month_start;
99$month_start = $tmps[
'mon'];
100$year_start = $tmps[
'year'];
102$month_end = $tmpe[
'mon'];
103$year_end = $tmpe[
'year'];
104$nbofyear = ($year_end - $year_start) + 1;
108if (isModEnabled(
'accounting')) {
109 $modecompta =
'BOOKKEEPING';
111if (
GETPOST(
"modecompta",
'alpha')) {
112 $modecompta =
GETPOST(
"modecompta",
'alpha');
116if ($user->socid > 0) {
117 $socid = $user->socid;
119if (isModEnabled(
'comptabilite')) {
122if (isModEnabled(
'accounting')) {
123 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
133$form =
new Form($db);
143if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
144 $modecompta =
"RECETTES-DEPENSES";
148if ($modecompta ==
"CREANCES-DETTES") {
149 $name = $langs->trans(
"PurchaseTurnover");
150 $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>" :
"");
151 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
153} elseif ($modecompta ==
"RECETTES-DEPENSES") {
154 $name = $langs->trans(
"PurchaseTurnoverCollected");
155 $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>" :
"");
156 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
158} elseif ($modecompta ==
"BOOKKEEPING") {
159 $name = $langs->trans(
"PurchaseTurnover");
160 $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>" :
"");
161 $description = $langs->trans(
"RulesPurchaseTurnoverOfExpenseAccounts");
163} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
164 $name = $langs->trans(
"PurchaseTurnoverCollected");
165 $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>" :
"");
166 $description = $langs->trans(
"RulesPurchaseTurnoverCollectedOfExpenseAccounts");
170$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
172$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
175if (!empty($modecompta)) {
176 $moreparam[
'modecompta'] = $modecompta;
181if ($modecompta ==
"RECETTES-DEPENSES" || $modecompta ==
"BOOKKEEPINGCOLLECTED") {
186 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModePayment");
187 if (isModEnabled(
'accounting')) {
188 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
190 $calcmode .=
'</label>';
192 if (isModEnabled(
'accounting')) {
193 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
194 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"DataMustHaveBeenTransferredInAccounting").
')</span>';
197 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
198 if (isModEnabled(
'accounting')) {
199 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
201 $calcmode .=
'</label>';
205report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
207if (isModEnabled(
'accounting')) {
208 if ($modecompta !=
'BOOKKEEPING') {
209 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
213 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
214 if (empty($pcgvercode)) {
215 $pcgvercode = $pcgverid;
218 $sql =
"SELECT b.rowid ";
219 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
220 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
221 $sql .=
" WHERE b.entity = ".$conf->entity;
222 $sql .=
" AND b.numero_compte = aa.account_number";
223 $sql .=
" AND aa.entity = ".$conf->entity;
224 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
225 $sql .= $db->plimit(1);
227 $resql = $db->query($sql);
228 $nb = $db->num_rows($resql);
230 $langs->load(
"errors");
231 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0,
'1');
237if ($modecompta ==
'CREANCES-DETTES') {
238 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
239 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
240 $sql .=
" WHERE f.fk_statut in (1,2)";
241 $sql .=
" AND f.type IN (0,2)";
242 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
244 $sql .=
" AND f.fk_soc = ".((int) $socid);
246} elseif ($modecompta ==
"RECETTES-DEPENSES") {
247 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
248 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
249 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
250 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
251 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
252 $sql .=
" AND pf.fk_facturefourn = f.rowid";
253 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
255 $sql .=
" AND f.fk_soc = ".((int) $socid);
257} elseif ($modecompta ==
"BOOKKEEPING") {
259 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
260 if (empty($pcgvercode)) {
261 $pcgvercode = $pcgverid;
264 $sql =
"SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.debit - b.credit) as amount_ttc";
265 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
266 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
267 $sql .=
" WHERE b.entity = ".$conf->entity;
268 $sql .=
" AND b.doc_type = 'supplier_invoice'";
269 $sql .=
" AND b.numero_compte = aa.account_number";
270 $sql .=
" AND aa.entity = ".$conf->entity;
271 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
272 $sql .=
" AND aa.pcg_type = 'EXPENSE'";
274$sql .=
" GROUP BY dm";
275$sql .=
" ORDER BY dm";
279$minyearmonth = $maxyearmonth = 0;
281$cumulative = array();
282$cumulative_ht = array();
286$result = $db->query($sql);
288 $num = $db->num_rows($result);
291 $obj = $db->fetch_object($result);
292 $cumulative_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
293 $cumulative[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
294 if ($obj->amount_ttc) {
295 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
296 $maxyearmonth = max($maxyearmonth, $obj->dm);
307print
'<div class="div-table-responsive">';
308print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
310print
'<tr class="liste_titre"><td> </td>';
312for ($annee = $year_start; $annee <= $year_end; $annee++) {
313 if ($modecompta ==
'CREANCES-DETTES') {
314 print
'<td align="center" width="10%" colspan="3">';
316 print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
318 if ($modecompta !=
'BOOKKEEPING') {
319 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
323 print
'-'.($annee + 1);
325 if ($modecompta !=
'BOOKKEEPING') {
329 if ($annee != $year_end) {
330 print
'<td width="15"> </td>';
335print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
336for ($annee = $year_start; $annee <= $year_end; $annee++) {
337 if ($modecompta ==
'CREANCES-DETTES') {
338 print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
340 print
'<td class="liste_titre right">';
341 if ($modecompta ==
"BOOKKEEPING") {
342 print $langs->trans(
"Amount");
344 print $langs->trans(
"AmountTTC");
347 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
348 if ($annee != $year_end) {
349 print
'<td class="liste_titre" width="15"> </td>';
355$minyear = substr($minyearmonth, 0, 4);
356$maxyear = substr($maxyearmonth, 0, 4);
359$maxyearmonth = max($maxyearmonth, $nowyearmonth);
364$nb_mois_decalage = GETPOSTISSET(
'date_startmonth') ? (
GETPOSTINT(
'date_startmonth') - 1) : (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 0 : (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') - 1));
365for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
366 $mois_modulo = $mois;
368 $mois_modulo = $mois - 12;
371 if ($year_start == $year_end) {
372 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
377 print
'<tr class="oddeven">';
380 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
382 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) {
383 $annee_decalage = $annee;
385 $annee_decalage = $annee + 1;
390 if ($annee >= $year_start) {
391 if ($modecompta ==
'CREANCES-DETTES') {
393 print
'<td class="right">';
394 if (!empty($cumulative_ht[$case])) {
396 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price($cumulative_ht[$case], 1).
'</a>';
398 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
408 print
'<td class="right">';
409 if (!empty($cumulative[$case])) {
411 if ($modecompta !=
'BOOKKEEPING') {
412 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
414 print
price($cumulative[$case], 1);
415 if ($modecompta !=
'BOOKKEEPING') {
419 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
428 if ($annee_decalage > $minyear && $case <= $casenow) {
429 if (!empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
430 $percent = (round(($cumulative[$case] - $cumulative[$caseprev]) / $cumulative[$caseprev], 4) * 100);
432 print
'<td class="borderrightlight right">'.($percent >= 0 ?
"+$percent" :
"$percent").
'%</td>';
434 if (!empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
435 print
'<td class="borderrightlight right">-100%</td>';
437 if (empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
439 print
'<td class="borderrightlight right">-</td>';
441 if (isset($cumulative[$caseprev]) && empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
442 print
'<td class="borderrightlight right">+0%</td>';
444 if (!isset($cumulative[$caseprev]) && empty($cumulative[$case])) {
445 print
'<td class="borderrightlight right">-</td>';
448 print
'<td class="borderrightlight right">';
449 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
457 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
458 print
'<td width="15"> </td>';
462 if (empty($total_ht[$annee])) {
463 $total_ht[$annee] = ((!empty($cumulative_ht[$case])) ? $cumulative_ht[$case] : 0);
465 $total_ht[$annee] += ((!empty($cumulative_ht[$case])) ? $cumulative_ht[$case] : 0);
467 if (empty($total[$annee])) {
468 $total[$annee] = (empty($cumulative[$case]) ? 0 : $cumulative[$case]);
470 $total[$annee] += (empty($cumulative[$case]) ? 0 : $cumulative[$case]);
478print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
479for ($annee = $year_start; $annee <= $year_end; $annee++) {
480 if ($modecompta ==
'CREANCES-DETTES') {
482 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
483 print
'<td class="nowrap right">';
484 print($total_ht[$annee] ?
price($total_ht[$annee]) :
"0");
487 print
'<td> </td>';
492 if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
493 print
'<td class="nowrap right">'.($total[$annee] ?
price($total[$annee]) :
"0").
"</td>";
495 print
'<td> </td>';
499 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
500 if ($total[$annee - 1] && $total[$annee]) {
501 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
502 print
'<td class="nowrap borderrightlight right">';
503 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
506 if (!empty($total[$annee - 1]) && empty($total[$annee])) {
507 print
'<td class="borderrightlight right">-100%</td>';
509 if (empty($total[$annee - 1]) && !empty($total[$annee])) {
510 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
512 if (empty($total[$annee - 1]) && empty($total[$annee])) {
513 print
'<td class="borderrightlight right">+0%</td>';
516 print
'<td class="borderrightlight right">';
517 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
525 if ($annee != $year_end) {
526 print
'<td width="15"> </td>';
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.
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 a 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.