diff --git a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php index 6c51342d..f32e786f 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php @@ -74,11 +74,7 @@ class BulkDownloadCustomerInvoicesLogic ob_end_clean(); } - $response = response()->download($zip_file); - - File::delete($zip_file); - - return $response; + return response()->download($zip_file); } else { return response()->json([ 'status' => 'Failed', diff --git a/app/Console/Commands/DeleteBulkInvoiceFiles.php b/app/Console/Commands/DeleteBulkInvoiceFiles.php new file mode 100644 index 00000000..52ebf121 --- /dev/null +++ b/app/Console/Commands/DeleteBulkInvoiceFiles.php @@ -0,0 +1,52 @@ +logOutput('Process started'); + + $directory = storage_path('app/bulk_invoice'); + + if (File::isDirectory($directory)) { + File::cleanDirectory($directory); + $this->info('All files in the bulk_invoice directory have been deleted.'); + } else { + $this->error('The bulk_invoice directory does not exist.'); + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + + $this->logOutput('Process ended. ElapsedTime: ' . $elapsedTime); + } + + public function logOutput($text) + { + if (is_array($text)) { + $text = implode(', ', $text); + } + + $this->info(Carbon::now() . ' : ' . $text); + + $filePath = storage_path('logs/delete-orders.log'); + $textToAppend = Carbon::now()->format('[Y-m-d H:i:s]') . ' ' . $text . PHP_EOL; + file_put_contents($filePath, $textToAppend, FILE_APPEND); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 7ad5e7db..d8b5d9f1 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -38,6 +38,16 @@ class Kernel extends ConsoleKernel ->hourly() ->appendOutputTo(storage_path().'/logs/soft-delete-seasonal-segmant-company.log') ->withoutOverlapping(); + + $schedule->command('regenerateInvoice') + ->everyMinute() + ->appendOutputTo(storage_path().'/logs/regenerateInvoice.log') + ->withoutOverlapping(); + + $schedule->command('delete:bulk-invoice-files') + ->dailyAt('00:00') + ->appendOutputTo(storage_path().'/logs/delete-bulk-invoice-files.log') + ->withoutOverlapping(); } /**