diff --git a/app/Http/Controllers/Admin/InvoiceController.php b/app/Http/Controllers/Admin/InvoiceController.php new file mode 100644 index 00000000..bc20ef4c --- /dev/null +++ b/app/Http/Controllers/Admin/InvoiceController.php @@ -0,0 +1,70 @@ +open($zip_safe_path, ZipArchive::CREATE | ZipArchive::OVERWRITE); + $result = $this::rglob(storage_path('app/invoice/*')); + if ($res === TRUE) { + $zip->addFromString("1. Info.txt", __("Created at") . " " . now()->format("d.m.Y")); + foreach ($result as $file) { + if (file_exists($file) && is_file($file)) { + $zip->addFile($file, basename($file)); + } + } + $zip->close(); + } + return response()->download($zip_safe_path); + } + + /** + * @param $pattern + * @param $flags + * @return array|false + */ + 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; + } + + /** + * @param $paymentID + * @param $date + */ + public function downloadSingleInvoice(Request $request) + { + $id = $request->id; + try { + $query = Invoice::where('payment_id', '=', $id)->firstOrFail(); + } catch (Throwable $e) { + return redirect()->back()->with("error", __("Error!")); + } + + $invoice_path = storage_path('app/invoice/' . $query->invoice_user . '/' . $query->created_at->format("Y") . '/' . $query->invoice_name . '.pdf'); + + if (!file_exists($invoice_path)) { + return redirect()->back()->with("error", __("Error!")); + } + + + return response()->download($invoice_path); + + } + +} diff --git a/app/Http/Controllers/Admin/PaymentController.php b/app/Http/Controllers/Admin/PaymentController.php index ea7d3dd0..ff882da6 100644 --- a/app/Http/Controllers/Admin/PaymentController.php +++ b/app/Http/Controllers/Admin/PaymentController.php @@ -591,6 +591,11 @@ class PaymentController extends Controller ->editColumn('created_at', function (Payment $payment) { return $payment->created_at ? $payment->created_at->diffForHumans() : ''; }) - ->make(); + ->addColumn('actions', function (Payment $payment) { + return ' +'; + }) + ->rawColumns(['actions']) + ->make(true); } } diff --git a/app/Http/Controllers/Admin/SettingsControllers/SettingsController.php b/app/Http/Controllers/Admin/SettingsControllers/SettingsController.php index 0e0da944..cfc7a531 100644 --- a/app/Http/Controllers/Admin/SettingsControllers/SettingsController.php +++ b/app/Http/Controllers/Admin/SettingsControllers/SettingsController.php @@ -9,7 +9,6 @@ use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\View; use Illuminate\Http\Request; use Illuminate\Http\Response; -use ZipArchive; class SettingsController extends Controller { @@ -86,30 +85,4 @@ class SettingsController extends Controller return redirect()->route('admin.settings.index')->with('success', 'Invoice settings updated!'); } - public function downloadAllInvoices() - { - $zip = new ZipArchive; - $zip_safe_path = storage_path('invoices.zip'); - $res = $zip->open($zip_safe_path, ZipArchive::CREATE | ZipArchive::OVERWRITE); - $result = $this::rglob(storage_path('app/invoice/*')); - if ($res === TRUE) { - $zip->addFromString("1. Info.txt", "This Archive contains all Invoices from all Users!\nIf there are no Invoices here, no Invoices have ever been created!"); - foreach ($result as $file) { - if (file_exists($file) && is_file($file)) { - $zip->addFile($file, basename($file)); - } - } - $zip->close(); - } - return response()->download($zip_safe_path); - } - - 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; - } } diff --git a/resources/views/admin/payments/index.blade.php b/resources/views/admin/payments/index.blade.php index f37485ea..de1fc9c1 100644 --- a/resources/views/admin/payments/index.blade.php +++ b/resources/views/admin/payments/index.blade.php @@ -27,6 +27,10 @@