NEW Add Button to Remove Payment Reports (#31822)

* button to remove rapport

* Update user.class.php

* Update rapport.php

* Update user.class.php
This commit is contained in:
Mohamed DAOUD 2024-11-14 23:29:35 +01:00 committed by GitHub
parent 3cfda29d0d
commit 239c0bdd2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 1 deletions

View file

@ -42,6 +42,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
*/
$action = GETPOST('action', 'aZ09');
$fileToRemove = GETPOST('removefile', 'alpha');
$socid = 0;
if ($user->socid > 0) {
@ -93,6 +94,21 @@ if ($action == 'builddoc' && $permissiontoread) {
$year = GETPOSTINT("reyear");
}
// Delete file from disk
if ($action == 'removedoc' && $permissiontoread && $fileToRemove) {
$fullpathfile = dol_sanitizePathName($dir.'/'.$fileToRemove);
$fileDirectory = dirname($fullpathfile);
if (dol_delete_file($fullpathfile)) {
// Delete empty directory after file deletion
if (empty(dol_dir_list($fileDirectory))) {
dol_delete_dir($fileDirectory);
}
setEventMessages($langs->trans("FileWasRemoved", $fileToRemove), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorFailToDeleteFile", $fileToRemove), null, 'errors');
}
}
/*
* View
@ -140,6 +156,7 @@ if ($year) {
print '<td>'.$langs->trans("Reporting").'</td>';
print '<td class="right">'.$langs->trans("Size").'</td>';
print '<td class="right">'.$langs->trans("Date").'</td>';
print '<td class="right"></td>';
print '</tr>';
$files = (dol_dir_list($dir.'/'.$year, 'files', 0, '^payments-[0-9]{4}-[0-9]{2}\.pdf$', '', 'name', SORT_DESC, 1));
@ -149,6 +166,7 @@ if ($year) {
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 '<td class="right"><a href="rapport.php?removefile='.urlencode($relativepath).'&action=removedoc&token='.newToken().'">'.img_delete().'</a></td>';
print '</tr>';
}
print '</table>';

View file

@ -48,6 +48,7 @@ if (!empty($user->socid)) {
$result = restrictedArea($user, 'fournisseur', 0, 'facture_fourn', 'facture');
$action = GETPOST('action', 'aZ09');
$fileToRemove = GETPOST('removefile', 'alpha');
$socid = 0;
if ($user->socid > 0) {
@ -95,6 +96,20 @@ if ($action == 'builddoc' && $permissiontoread) {
$year = GETPOSTINT("reyear");
}
// Delete file from disk
if ($action == 'removedoc' && $permissiontoread && $fileToRemove) {
$fileDirectory = dirname($dir.'/'.$fileToRemove);
if (dol_delete_file($dir.'/'.$fileToRemove)) {
// Delete empty directory after file deletion
if (empty(dol_dir_list($fileDirectory))) {
dol_delete_dir($fileDirectory);
}
setEventMessages($langs->trans("FileWasRemoved", $fileToRemove), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorFailToDeleteFile", $fileToRemove), null, 'errors');
}
}
/*
* View
@ -158,6 +173,7 @@ if ($year) {
print '<td>'.$langs->trans("Reporting").'</td>';
print '<td class="right">'.$langs->trans("Size").'</td>';
print '<td class="right">'.$langs->trans("Date").'</td>';
print '<td class="right"></td>';
print '</tr>';
if (is_resource($handle)) {
@ -167,7 +183,9 @@ if ($year) {
$relativepath = $year.'/'.$file;
print '<tr class="oddeven"><td><a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart=facture_fournisseur&amp;file=payments/'.urlencode($relativepath).'">'.img_pdf().' '.$file.'</a>'.$formfile->showPreview($file, 'facture_fournisseur', 'payments/'.$relativepath, 0).'</td>';
print '<td class="right">'.dol_print_size(dol_filesize($tfile)).'</td>';
print '<td class="right">'.dol_print_date(dol_filemtime($tfile), "dayhour").'</td></tr>';
print '<td class="right">'.dol_print_date(dol_filemtime($tfile), "dayhour").'</td>';
print '<td class="right"><a href="rapport.php?removefile='.urlencode($relativepath).'&action=removedoc&token='.newToken().'">'.img_delete().'</a></td>';
print '</tr>';
}
}
closedir($handle);