mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactor for zips
This commit is contained in:
parent
c7482c9615
commit
91e0e22298
@ -529,13 +529,11 @@ class CreditController extends BaseController
|
||||
if ($action == 'bulk_download' && $credits->count() > 1) {
|
||||
$credits->each(function ($credit) use($user){
|
||||
if ($user->cannot('view', $credit)) {
|
||||
nlog('access denied');
|
||||
|
||||
return response()->json(['message' => ctrans('text.access_denied')]);
|
||||
}
|
||||
});
|
||||
|
||||
ZipCredits::dispatch($credits, $credits->first()->company, $user);
|
||||
ZipCredits::dispatch($credits->pluck('id')->toArray(), $credits->first()->company, $user);
|
||||
|
||||
return response()->json(['message' => ctrans('texts.sent_message')], 200);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ use App\Jobs\Util\UnlinkFile;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\DownloadCredits;
|
||||
use App\Models\Company;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -30,32 +31,12 @@ class ZipCredits implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $credits;
|
||||
|
||||
private $company;
|
||||
|
||||
private $user;
|
||||
|
||||
public $settings;
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
/**
|
||||
* @param $invoices
|
||||
* @param Company $company
|
||||
* @param $email
|
||||
* @deprecated confirm to be deleted
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct($credits, Company $company, User $user)
|
||||
public function __construct(protected array $credit_ids, protected Company $company, protected User $user)
|
||||
{
|
||||
$this->credits = $credits;
|
||||
|
||||
$this->company = $company;
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
$this->settings = $company->settings;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,21 +48,18 @@ class ZipCredits implements ShouldQueue
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
// create new zip object
|
||||
$this->settings = $this->company->settings;
|
||||
$zipFile = new \PhpZip\ZipFile();
|
||||
$file_name = date('Y-m-d').'_'.str_replace(' ', '_', trans('texts.credits')).'.zip';
|
||||
$invitation = $this->credits->first()->invitations->first();
|
||||
$path = $this->credits->first()->client->quote_filepath($invitation);
|
||||
$file_name = now()->addSeconds($this->company->timezone_offset())->format('Y-m-d-h-m-s').'_'.str_replace(' ', '_', trans('texts.credits')).'.zip';
|
||||
|
||||
$this->credits->each(function ($credit) {
|
||||
(new CreateEntityPdf($credit->invitations()->first()))->handle();
|
||||
});
|
||||
$invitations = CreditInvitation::query()->with('credit')->whereIn('credit_id', $this->credit_ids)->get();
|
||||
$invitation = $invitations->first();
|
||||
$path = $invitation->contact->client->credit_filepath($invitation);
|
||||
|
||||
try {
|
||||
foreach ($this->credits as $credit) {
|
||||
$file = $credit->service()->getCreditPdf($credit->invitations()->first());
|
||||
$zip_file_name = basename($file);
|
||||
$zipFile->addFromString($zip_file_name, Storage::get($file));
|
||||
foreach ($invitations as $invitation) {
|
||||
$file = (new \App\Jobs\Entity\CreateRawPdf($invitation, $this->company->db))->handle();
|
||||
$zipFile->addFromString($invitation->credit->numberFormatter() . '.pdf', $file);
|
||||
}
|
||||
|
||||
Storage::put($path.$file_name, $zipFile->outputAsString());
|
||||
|
Loading…
x
Reference in New Issue
Block a user