2023-08-18 15:36:54 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Jobs\Report;
|
|
|
|
|
|
|
|
use App\Libraries\MultiDB;
|
2023-10-26 04:57:44 +02:00
|
|
|
use App\Models\Company;
|
2023-08-18 15:36:54 +02:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
2023-10-26 04:57:44 +02:00
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
2023-08-18 15:36:54 +02:00
|
|
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
2023-10-26 04:57:44 +02:00
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
2023-08-18 15:36:54 +02:00
|
|
|
|
|
|
|
class PreviewReport implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance
|
|
|
|
*/
|
|
|
|
public function __construct(protected Company $company, protected array $request, private string $report_class, protected string $hash)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
MultiDB::setDb($this->company->db);
|
|
|
|
|
|
|
|
/** @var \App\Export\CSV\CreditExport $export */
|
|
|
|
$export = new $this->report_class($this->company, $this->request);
|
2023-10-06 12:07:31 +02:00
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
if(isset($this->request['output']) && $this->request['output'] == 'json') {
|
2023-10-26 05:54:32 +02:00
|
|
|
$report = $export->returnJson();
|
2023-11-26 08:41:42 +01:00
|
|
|
} else {
|
2023-10-26 05:54:32 +02:00
|
|
|
$report = $export->run();
|
2023-11-26 08:41:42 +01:00
|
|
|
}
|
2023-10-26 05:54:32 +02:00
|
|
|
|
2023-11-12 11:26:28 +01:00
|
|
|
// nlog($report);
|
2023-11-01 02:14:58 +01:00
|
|
|
|
2023-08-18 15:36:54 +02:00
|
|
|
Cache::put($this->hash, $report, 60 * 60);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function middleware()
|
|
|
|
{
|
|
|
|
return [new WithoutOverlapping("report-{$this->company->company_key}")];
|
|
|
|
}
|
|
|
|
}
|