26require
'../../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
36require_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);
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;
118 $modecompta =
'BOOKKEEPING';
120if (
GETPOST(
"modecompta",
'alpha')) {
121 $modecompta =
GETPOST(
"modecompta",
'alpha');
125if ($user->socid > 0) {
126 $socid = $user->socid;
132 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
155if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
156 $modecompta =
"RECETTES-DEPENSES";
160if ($modecompta ==
"CREANCES-DETTES") {
161 $name = $langs->trans(
"PurchaseTurnover");
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(
"RulesPurchaseTurnoverDue");
165} elseif ($modecompta ==
"RECETTES-DEPENSES") {
166 $name = $langs->trans(
"PurchaseTurnoverCollected");
167 $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>" :
"");
168 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
170} elseif ($modecompta ==
"BOOKKEEPING") {
171 $name = $langs->trans(
"PurchaseTurnover");
172 $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>" :
"");
173 $description = $langs->trans(
"RulesPurchaseTurnoverOfExpenseAccounts");
175} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
176 $name = $langs->trans(
"PurchaseTurnoverCollected");
177 $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>" :
"");
178 $description = $langs->trans(
"RulesPurchaseTurnoverCollectedOfExpenseAccounts");
182$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
184$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
187if (!empty($modecompta)) {
188 $moreparam[
'modecompta'] = $modecompta;
193if ($modecompta ==
"RECETTES-DEPENSES" || $modecompta ==
"BOOKKEEPINGCOLLECTED") {
198 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModePayment");
200 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
202 $calcmode .=
'</label>';
205 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
206 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"DataMustHaveBeenTransferredInAccounting").
')</span>';
209 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
211 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
213 $calcmode .=
'</label>';
217report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
220 if ($modecompta !=
'BOOKKEEPING') {
221 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
226 if (empty($pcgvercode)) {
227 $pcgvercode = $pcgverid;
230 $sql =
"SELECT b.rowid ";
231 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
232 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
233 $sql .=
" WHERE b.entity = ".$conf->entity;
234 $sql .=
" AND b.numero_compte = aa.account_number";
235 $sql .=
" AND aa.entity = ".$conf->entity;
236 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
237 $sql .=
$db->plimit(1);
239 $resql =
$db->query($sql);
240 $nb =
$db->num_rows($resql);
242 $langs->load(
"errors");
243 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0,
'1');
251if ($modecompta ==
'CREANCES-DETTES') {
252 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
253 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
254 $sql .=
" WHERE f.fk_statut in (1,2)";
255 $sql .=
" AND f.type IN (0,2)";
256 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
258 $sql .=
" AND f.fk_soc = ".((int) $socid);
260} elseif ($modecompta ==
"RECETTES-DEPENSES") {
261 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
262 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
263 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
264 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
265 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
266 $sql .=
" AND pf.fk_facturefourn = f.rowid";
267 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
269 $sql .=
" AND f.fk_soc = ".((int) $socid);
271} elseif ($modecompta ==
"BOOKKEEPING") {
274 if (empty($pcgvercode)) {
275 $pcgvercode = $pcgverid;
278 $sql =
"SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.debit - b.credit) as amount_ttc";
279 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
280 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
281 $sql .=
" WHERE b.entity = ".$conf->entity;
282 $sql .=
" AND b.doc_type = 'supplier_invoice'";
283 $sql .=
" AND b.numero_compte = aa.account_number";
284 $sql .=
" AND aa.entity = ".$conf->entity;
285 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
286 $sql .=
" AND aa.pcg_type = 'EXPENSE'";
288$sql .=
" GROUP BY dm";
289$sql .=
" ORDER BY dm";
292$minyearmonth = $maxyearmonth = 0;
294$cumulative = array();
295$cumulative_ht = array();
299$result =
$db->query($sql);
301 $num =
$db->num_rows($result);
304 $obj =
$db->fetch_object($result);
305 $cumulative_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
306 $cumulative[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
307 if ($obj->amount_ttc) {
308 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
309 $maxyearmonth = max($maxyearmonth, $obj->dm);
320print
'<div class="div-table-responsive">';
321print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
323print
'<tr class="liste_titre"><td> </td>';
325for ($annee = $year_start; $annee <= $year_end; $annee++) {
326 if ($modecompta ==
'CREANCES-DETTES') {
327 print
'<td align="center" width="10%" colspan="3">';
329 print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
331 if ($modecompta !=
'BOOKKEEPING') {
332 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
336 print
'-'.($annee + 1);
338 if ($modecompta !=
'BOOKKEEPING') {
342 if ($annee != $year_end) {
343 print
'<td width="15"> </td>';
348print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
349for ($annee = $year_start; $annee <= $year_end; $annee++) {
350 if ($modecompta ==
'CREANCES-DETTES') {
351 print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
353 print
'<td class="liste_titre right">';
354 if ($modecompta ==
"BOOKKEEPING") {
355 print $langs->trans(
"Amount");
357 print $langs->trans(
"AmountTTC");
360 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
361 if ($annee != $year_end) {
362 print
'<td class="liste_titre" width="15"> </td>';
368$minyear = substr($minyearmonth, 0, 4);
369$maxyear = substr($maxyearmonth, 0, 4);
372$maxyearmonth = max($maxyearmonth, $nowyearmonth);
377$nb_mois_decalage = GETPOSTISSET(
'date_startmonth') ? (
GETPOSTINT(
'date_startmonth') - 1) : (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 0 : (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') - 1));
378for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
379 $mois_modulo = $mois;
381 $mois_modulo = $mois - 12;
384 if ($year_start == $year_end) {
385 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
390 print
'<tr class="oddeven">';
393 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
395 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) {
396 $annee_decalage = $annee;
398 $annee_decalage = $annee + 1;
403 if ($annee >= $year_start) {
404 if ($modecompta ==
'CREANCES-DETTES') {
406 print
'<td class="right">';
407 if (!empty($cumulative_ht[$case])) {
409 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price($cumulative_ht[$case], 1).
'</a>';
411 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
421 print
'<td class="right">';
422 if (!empty($cumulative[$case])) {
424 if ($modecompta !=
'BOOKKEEPING') {
425 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
427 print
price($cumulative[$case], 1);
428 if ($modecompta !=
'BOOKKEEPING') {
432 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
441 if ($annee_decalage > $minyear && $case <= $casenow) {
442 if (!empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
443 $percent = (round(($cumulative[$case] - $cumulative[$caseprev]) / $cumulative[$caseprev], 4) * 100);
445 print
'<td class="borderrightlight right">'.($percent >= 0 ?
"+$percent" :
"$percent").
'%</td>';
447 if (!empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
448 print
'<td class="borderrightlight right">-100%</td>';
450 if (empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
452 print
'<td class="borderrightlight right">-</td>';
454 if (isset($cumulative[$caseprev]) && empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
455 print
'<td class="borderrightlight right">+0%</td>';
457 if (!isset($cumulative[$caseprev]) && empty($cumulative[$case])) {
458 print
'<td class="borderrightlight right">-</td>';
461 print
'<td class="borderrightlight right">';
462 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
470 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
471 print
'<td width="15"> </td>';
475 if (empty($total_ht[$annee])) {
476 $total_ht[$annee] = ((!empty($cumulative_ht[$case])) ? $cumulative_ht[$case] : 0);
478 $total_ht[$annee] += ((!empty($cumulative_ht[$case])) ? $cumulative_ht[$case] : 0);
480 if (empty($total[$annee])) {
481 $total[$annee] = (empty($cumulative[$case]) ? 0 : $cumulative[$case]);
483 $total[$annee] += (empty($cumulative[$case]) ? 0 : $cumulative[$case]);
491print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
492for ($annee = $year_start; $annee <= $year_end; $annee++) {
493 if ($modecompta ==
'CREANCES-DETTES') {
495 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
496 print
'<td class="nowrap right">';
497 print($total_ht[$annee] ?
price($total_ht[$annee]) :
"0");
500 print
'<td> </td>';
505 if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
506 print
'<td class="nowrap right">'.($total[$annee] ?
price($total[$annee]) :
"0").
"</td>";
508 print
'<td> </td>';
512 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
513 if ($total[$annee - 1] && $total[$annee]) {
514 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
515 print
'<td class="nowrap borderrightlight right">';
516 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
519 if (!empty($total[$annee - 1]) && empty($total[$annee])) {
520 print
'<td class="borderrightlight right">-100%</td>';
522 if (empty($total[$annee - 1]) && !empty($total[$annee])) {
523 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
525 if (empty($total[$annee - 1]) && empty($total[$annee])) {
526 print
'<td class="borderrightlight right">+0%</td>';
529 print
'<td class="borderrightlight right">';
530 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
538 if ($annee != $year_end) {
539 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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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_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).
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.
isModEnabled($module)
Is Dolibarr module enabled.
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.