1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/app/Http/Controllers/Reports/RecurringInvoiceReportController.php

68 lines
1.9 KiB
PHP
Raw Normal View History

2022-04-27 09:21:55 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2022-04-27 09:21:55 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Controllers\Reports;
2023-09-12 03:22:59 +02:00
use Illuminate\Http\Response;
use App\Utils\Traits\MakesHash;
use App\Jobs\Report\SendToAdmin;
use App\Jobs\Report\PreviewReport;
2022-04-27 09:21:55 +02:00
use App\Http\Controllers\BaseController;
2023-09-12 03:22:59 +02:00
use App\Export\CSV\RecurringInvoiceExport;
2022-04-27 09:21:55 +02:00
use App\Http\Requests\Report\GenericReportRequest;
class RecurringInvoiceReportController extends BaseController
{
use MakesHash;
private string $filename = 'recurring_invoices.csv';
public function __construct()
{
parent::__construct();
}
public function __invoke(GenericReportRequest $request)
{
2023-09-12 03:22:59 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
if ($request->has('send_email') && $request->get('send_email')) {
2023-09-12 03:22:59 +02:00
SendToAdmin::dispatch($user->company(), $request->all(), RecurringInvoiceExport::class, $this->filename);
return response()->json(['message' => 'working...'], 200);
}
2022-04-27 09:21:55 +02:00
// expect a list of visible fields, or use the default
2023-09-12 03:22:59 +02:00
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), RecurringInvoiceExport::class, $hash);
return response()->json(['message' => $hash], 200);
}
$export = new RecurringInvoiceExport($user->company(), $request->all());
2022-04-27 09:21:55 +02:00
$csv = $export->run();
$headers = [
2022-04-27 09:21:55 +02:00
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
2022-04-27 09:21:55 +02:00
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}