diff --git a/.gitignore b/.gitignore index 74015e4f..02dee0df 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ npm-debug.log yarn-error.log .gitignore .env.dev -.env.testing \ No newline at end of file +.env.testing +storage/invoices.zip diff --git a/app/Http/Controllers/Admin/SettingsController.php b/app/Http/Controllers/Admin/SettingsController.php index b0a6aada..83297040 100644 --- a/app/Http/Controllers/Admin/SettingsController.php +++ b/app/Http/Controllers/Admin/SettingsController.php @@ -9,6 +9,7 @@ use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\View; use Illuminate\Http\Request; use Illuminate\Http\Response; +use ZipArchive; class SettingsController extends Controller { @@ -69,4 +70,28 @@ class SettingsController extends Controller return redirect()->route('admin.settings.index')->with('success', 'Invoice settings updated!'); } + public function rglob($pattern, $flags = 0) { + $files = glob($pattern, $flags); + foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { + $files = array_merge($files, $this::rglob($dir.'/'.basename($pattern), $flags)); + } + return $files; + } + + public function downloadAllInvoices(){ + $zip = new ZipArchive; + $zip_safe_path = storage_path('invoices.zip'); + $res = $zip->open($zip_safe_path, ZipArchive::CREATE); + $result = $this::rglob(storage_path('app/invoice/*')); + if ($res === TRUE) { + foreach($result as $file){ + if (file_exists($file) && is_file($file)) { + $zip->addFile($file,basename($file)); + } + } + $zip->close(); + } + return response()->download($zip_safe_path); + } + } diff --git a/resources/views/admin/settings/index.blade.php b/resources/views/admin/settings/index.blade.php index c2414bb3..c8e6ee29 100644 --- a/resources/views/admin/settings/index.blade.php +++ b/resources/views/admin/settings/index.blade.php @@ -93,6 +93,10 @@
+
+ +
+
@csrf @@ -186,7 +190,6 @@
-
diff --git a/routes/web.php b/routes/web.php index 6def19e0..ffbadb29 100644 --- a/routes/web.php +++ b/routes/web.php @@ -124,6 +124,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () { Route::patch('settings/update/icons', [SettingsController::class, 'updateIcons'])->name('settings.update.icons'); Route::patch('settings/update/invoice-settings', [SettingsController::class, 'updateInvoiceSettings'])->name('settings.update.invoicesettings'); + Route::get('settings/download-invoices', [SettingsController::class, 'downloadAllInvoices'])->name('settings.downloadAllInvoices');; Route::resource('settings', SettingsController::class)->only('index'); Route::get('usefullinks/datatable', [UsefulLinkController::class, 'datatable'])->name('usefullinks.datatable');