dolibarr/htdocs/compta/paiement/rapport.php

146 lines
4.6 KiB
PHP
Raw Normal View History

<?php
2006-12-23 11:48:26 +01:00
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2014-01-30 11:44:31 +01:00
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
2004-04-19 11:16:32 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2004-04-19 11:16:32 +02:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2004-04-19 11:16:32 +02:00
*/
2008-10-28 21:05:23 +01:00
2006-12-23 11:48:26 +01:00
/**
* \file htdocs/compta/paiement/rapport.php
* \ingroup facture
* \brief Payment reports page
2008-10-28 21:05:23 +01:00
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
$action = GETPOST('action', 'aZ09');
$socid = 0;
2021-02-23 21:09:01 +01:00
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
2005-10-08 21:13:58 +02:00
}
2014-01-30 11:44:31 +01:00
$dir = $conf->facture->dir_output.'/payments';
2021-10-22 22:15:59 +02:00
if (empty($user->rights->societe->client->voir) || $socid) {
2021-02-23 21:09:01 +01:00
$dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
}
2014-01-30 11:44:31 +01:00
2016-12-18 13:27:14 +01:00
$year = GETPOST('year', 'int');
2021-02-23 21:09:01 +01:00
if (!$year) {
$year = date("Y");
}
2004-07-26 16:17:42 +02:00
// Security check
2021-02-23 21:09:01 +01:00
if (empty($user->rights->facture->lire)) {
accessforbidden();
}
/*
* Actions
*/
2021-02-23 21:09:01 +01:00
if ($action == 'builddoc') {
$rap = new pdf_paiement($db);
$outputlangs = $langs;
2021-02-23 21:09:01 +01:00
if (GETPOST('lang_id', 'aZ09')) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
}
// We save charset_output to restore it because write_file can change it if needed for
// output format that does not support UTF8.
$sav_charset_output = $outputlangs->charset_output;
2021-03-25 16:59:47 +01:00
if ($rap->write_file($dir, GETPOST("remonth", "int"), GETPOST("reyear", "int"), $outputlangs) > 0) {
$outputlangs->charset_output = $sav_charset_output;
} else {
$outputlangs->charset_output = $sav_charset_output;
dol_print_error($db, $obj->error);
}
2021-03-25 16:59:47 +01:00
$year = GETPOST("reyear", "int");
2004-04-19 11:16:32 +02:00
}
2008-10-28 21:05:23 +01:00
/*
* View
*/
2008-10-28 21:05:23 +01:00
$formother = new FormOther($db);
$formfile = new FormFile($db);
2011-12-13 01:10:07 +01:00
llxHeader();
$titre = ($year ? $langs->trans("PaymentsReportsForYear", $year) : $langs->trans("PaymentsReports"));
2020-04-25 13:49:44 +02:00
print load_fiche_titre($titre, '', 'bill');
2004-04-19 11:16:32 +02:00
// Formulaire de generation
2009-01-09 23:52:45 +01:00
print '<form method="post" action="rapport.php?year='.$year.'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="builddoc">';
$cmonth = GETPOST("remonth") ?GETPOST("remonth") : date("n", time());
$syear = GETPOST("reyear") ?GETPOST("reyear") : date("Y", time());
2008-10-28 21:05:23 +01:00
print $formother->select_month($cmonth, 'remonth');
2011-12-13 01:10:07 +01:00
2022-05-18 11:38:56 +02:00
print $formother->selectyear($syear, 'reyear');
2004-04-19 11:16:32 +02:00
print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
2004-04-19 11:16:32 +02:00
print '</form>';
print '<br>';
2004-04-19 11:16:32 +02:00
clearstatcache();
2011-03-07 03:11:38 +01:00
// Show link on other years
2021-05-03 17:17:44 +02:00
$year_dirs = dol_dir_list($dir, 'directories', 0, '^[0-9]{4}$', '', 'DESC');
2021-05-03 20:22:36 +02:00
foreach ($year_dirs as $d) {
2021-05-03 17:17:44 +02:00
print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$d['name'].'">'.$d['name'].'</a> &nbsp;';
2009-01-09 23:50:58 +01:00
}
2004-04-19 11:16:32 +02:00
2021-05-03 20:22:36 +02:00
if ($year) {
if (is_dir($dir.'/'.$year)) {
2021-05-03 17:17:44 +02:00
if (!empty($year_dirs)) print '<br>';
print '<br>';
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Reporting").'</td>';
print '<td class="right">'.$langs->trans("Size").'</td>';
print '<td class="right">'.$langs->trans("Date").'</td>';
print '</tr>';
2021-05-03 17:17:44 +02:00
$files = (dol_dir_list($dir.'/'.$year, 'files', 0, '^payments-[0-9]{4}-[0-9]{2}\.pdf$', '', 'name', 'DESC', 1));
foreach ($files as $f) {
2021-05-03 17:17:44 +02:00
$relativepath = $f['level1name'].'/'.$f['name'];
print '<tr class="oddeven">';
print '<td><a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart=facture_paiement&amp;file='.urlencode($relativepath).'">'.img_pdf().' '.$f['name'].'</a>'.$formfile->showPreview($f['name'], 'facture_paiement', $relativepath, 0).'</td>';
print '<td class="right">'.dol_print_size($f['size']).'</td>';
print '<td class="right">'.dol_print_date($f['date'], "dayhour").'</td>';
print '</tr>';
}
print '</table>';
}
2004-04-19 11:16:32 +02:00
}
2006-12-23 11:48:26 +01:00
2018-08-08 12:29:36 +02:00
// End of page
llxFooter();
2011-12-13 01:10:07 +01:00
$db->close();