26require
'../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
39$langs->loadLangs(array(
'compta',
'bills'));
42$date_startmonth =
GETPOSTINT(
'date_startmonth');
55 $year_start = $year_current - ($nbofyear - 1);
57 $year_current = $year;
59 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
61$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
62$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
65if (empty($date_start) || empty($date_end)) {
69 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
72 if (!$year && $month_start > $month_current) {
76 $month_end = $month_start - 1;
81 $month_end = $month_start;
108$month_start = $tmps[
'mon'];
109$year_start = $tmps[
'year'];
111$month_end = $tmpe[
'mon'];
112$year_end = $tmpe[
'year'];
113$nbofyear = ($year_end - $year_start) + 1;
117if (isModEnabled(
'accounting')) {
118 $modecompta =
'BOOKKEEPING';
120if (
GETPOST(
"modecompta",
'alpha')) {
121 $modecompta =
GETPOST(
"modecompta",
'alpha');
125if ($user->socid > 0) {
126 $socid = $user->socid;
128if (isModEnabled(
'comptabilite')) {
131if (isModEnabled(
'accounting')) {
132 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
142$form =
new Form($db);
154if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
155 $modecompta =
"RECETTES-DEPENSES";
159if ($modecompta ==
"CREANCES-DETTES") {
160 $name = $langs->trans(
"PurchaseTurnover");
161 $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>" :
"");
162 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
164} elseif ($modecompta ==
"RECETTES-DEPENSES") {
165 $name = $langs->trans(
"PurchaseTurnoverCollected");
166 $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>" :
"");
167 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
169} elseif ($modecompta ==
"BOOKKEEPING") {
170 $name = $langs->trans(
"PurchaseTurnover");
171 $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>" :
"");
172 $description = $langs->trans(
"RulesPurchaseTurnoverOfExpenseAccounts");
174} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
175 $name = $langs->trans(
"PurchaseTurnoverCollected");
176 $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>" :
"");
177 $description = $langs->trans(
"RulesPurchaseTurnoverCollectedOfExpenseAccounts");
181$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
183$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
186if (!empty($modecompta)) {
187 $moreparam[
'modecompta'] = $modecompta;
192if ($modecompta ==
"RECETTES-DEPENSES" || $modecompta ==
"BOOKKEEPINGCOLLECTED") {
197 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModePayment");
198 if (isModEnabled(
'accounting')) {
199 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
201 $calcmode .=
'</label>';
203 if (isModEnabled(
'accounting')) {
204 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
205 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"DataMustHaveBeenTransferredInAccounting").
')</span>';
208 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
209 if (isModEnabled(
'accounting')) {
210 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
212 $calcmode .=
'</label>';
216report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
218if (isModEnabled(
'accounting')) {
219 if ($modecompta !=
'BOOKKEEPING') {
220 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
224 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
225 if (empty($pcgvercode)) {
226 $pcgvercode = $pcgverid;
229 $sql =
"SELECT b.rowid ";
230 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
231 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
232 $sql .=
" WHERE b.entity = ".$conf->entity;
233 $sql .=
" AND b.numero_compte = aa.account_number";
234 $sql .=
" AND aa.entity = ".$conf->entity;
235 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
236 $sql .= $db->plimit(1);
238 $resql = $db->query($sql);
239 $nb = $db->num_rows($resql);
241 $langs->load(
"errors");
242 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0,
'1');
248if ($modecompta ==
'CREANCES-DETTES') {
249 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
250 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
251 $sql .=
" WHERE f.fk_statut in (1,2)";
252 $sql .=
" AND f.type IN (0,2)";
253 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
255 $sql .=
" AND f.fk_soc = ".((int) $socid);
257} elseif ($modecompta ==
"RECETTES-DEPENSES") {
258 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
259 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
260 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
261 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
262 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
263 $sql .=
" AND pf.fk_facturefourn = f.rowid";
264 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
266 $sql .=
" AND f.fk_soc = ".((int) $socid);
268} elseif ($modecompta ==
"BOOKKEEPING") {
270 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
271 if (empty($pcgvercode)) {
272 $pcgvercode = $pcgverid;
275 $sql =
"SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.debit - b.credit) as amount_ttc";
276 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
277 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
278 $sql .=
" WHERE b.entity = ".$conf->entity;
279 $sql .=
" AND b.doc_type = 'supplier_invoice'";
280 $sql .=
" AND b.numero_compte = aa.account_number";
281 $sql .=
" AND aa.entity = ".$conf->entity;
282 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
283 $sql .=
" AND aa.pcg_type = 'EXPENSE'";
285$sql .=
" GROUP BY dm";
286$sql .=
" ORDER BY dm";
290$minyearmonth = $maxyearmonth = 0;
292$cumulative = array();
293$cumulative_ht = array();
297$result = $db->query($sql);
299 $num = $db->num_rows($result);
302 $obj = $db->fetch_object($result);
303 $cumulative_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
304 $cumulative[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
305 if ($obj->amount_ttc) {
306 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
307 $maxyearmonth = max($maxyearmonth, $obj->dm);
318print
'<div class="div-table-responsive">';
319print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
321print
'<tr class="liste_titre"><td> </td>';
323for ($annee = $year_start; $annee <= $year_end; $annee++) {
324 if ($modecompta ==
'CREANCES-DETTES') {
325 print
'<td align="center" width="10%" colspan="3">';
327 print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
329 if ($modecompta !=
'BOOKKEEPING') {
330 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
334 print
'-'.($annee + 1);
336 if ($modecompta !=
'BOOKKEEPING') {
340 if ($annee != $year_end) {
341 print
'<td width="15"> </td>';
346print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
347for ($annee = $year_start; $annee <= $year_end; $annee++) {
348 if ($modecompta ==
'CREANCES-DETTES') {
349 print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
351 print
'<td class="liste_titre right">';
352 if ($modecompta ==
"BOOKKEEPING") {
353 print $langs->trans(
"Amount");
355 print $langs->trans(
"AmountTTC");
358 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
359 if ($annee != $year_end) {
360 print
'<td class="liste_titre" width="15"> </td>';
366$minyear = substr($minyearmonth, 0, 4);
367$maxyear = substr($maxyearmonth, 0, 4);
370$maxyearmonth = max($maxyearmonth, $nowyearmonth);
375$nb_mois_decalage = GETPOSTISSET(
'date_startmonth') ? (
GETPOSTINT(
'date_startmonth') - 1) : (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 0 : (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') - 1));
376for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
377 $mois_modulo = $mois;
379 $mois_modulo = $mois - 12;
382 if ($year_start == $year_end) {
383 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
388 print
'<tr class="oddeven">';
391 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
393 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) {
394 $annee_decalage = $annee;
396 $annee_decalage = $annee + 1;
401 if ($annee >= $year_start) {
402 if ($modecompta ==
'CREANCES-DETTES') {
404 print
'<td class="right">';
405 if (!empty($cumulative_ht[$case])) {
407 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price($cumulative_ht[$case], 1).
'</a>';
409 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
419 print
'<td class="right">';
420 if (!empty($cumulative[$case])) {
422 if ($modecompta !=
'BOOKKEEPING') {
423 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
425 print
price($cumulative[$case], 1);
426 if ($modecompta !=
'BOOKKEEPING') {
430 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
439 if ($annee_decalage > $minyear && $case <= $casenow) {
440 if (!empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
441 $percent = (round(($cumulative[$case] - $cumulative[$caseprev]) / $cumulative[$caseprev], 4) * 100);
443 print
'<td class="borderrightlight right">'.($percent >= 0 ?
"+$percent" :
"$percent").
'%</td>';
445 if (!empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
446 print
'<td class="borderrightlight right">-100%</td>';
448 if (empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
450 print
'<td class="borderrightlight right">-</td>';
452 if (isset($cumulative[$caseprev]) && empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
453 print
'<td class="borderrightlight right">+0%</td>';
455 if (!isset($cumulative[$caseprev]) && empty($cumulative[$case])) {
456 print
'<td class="borderrightlight right">-</td>';
459 print
'<td class="borderrightlight right">';
460 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
468 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
469 print
'<td width="15"> </td>';
473 if (empty($total_ht[$annee])) {
474 $total_ht[$annee] = ((!empty($cumulative_ht[$case])) ? $cumulative_ht[$case] : 0);
476 $total_ht[$annee] += ((!empty($cumulative_ht[$case])) ? $cumulative_ht[$case] : 0);
478 if (empty($total[$annee])) {
479 $total[$annee] = (empty($cumulative[$case]) ? 0 : $cumulative[$case]);
481 $total[$annee] += (empty($cumulative[$case]) ? 0 : $cumulative[$case]);
489print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
490for ($annee = $year_start; $annee <= $year_end; $annee++) {
491 if ($modecompta ==
'CREANCES-DETTES') {
493 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
494 print
'<td class="nowrap right">';
495 print($total_ht[$annee] ?
price($total_ht[$annee]) :
"0");
498 print
'<td> </td>';
503 if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
504 print
'<td class="nowrap right">'.($total[$annee] ?
price($total[$annee]) :
"0").
"</td>";
506 print
'<td> </td>';
510 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
511 if ($total[$annee - 1] && $total[$annee]) {
512 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
513 print
'<td class="nowrap borderrightlight right">';
514 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
517 if (!empty($total[$annee - 1]) && empty($total[$annee])) {
518 print
'<td class="borderrightlight right">-100%</td>';
520 if (empty($total[$annee - 1]) && !empty($total[$annee])) {
521 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
523 if (empty($total[$annee - 1]) && empty($total[$annee])) {
524 print
'<td class="borderrightlight right">+0%</td>';
527 print
'<td class="borderrightlight right">';
528 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
536 if ($annee != $year_end) {
537 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.