mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01: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) {
|
if ($action == 'bulk_download' && $credits->count() > 1) {
|
||||||
$credits->each(function ($credit) use($user){
|
$credits->each(function ($credit) use($user){
|
||||||
if ($user->cannot('view', $credit)) {
|
if ($user->cannot('view', $credit)) {
|
||||||
nlog('access denied');
|
|
||||||
|
|
||||||
return response()->json(['message' => ctrans('text.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);
|
return response()->json(['message' => ctrans('texts.sent_message')], 200);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ use App\Jobs\Util\UnlinkFile;
|
|||||||
use App\Libraries\MultiDB;
|
use App\Libraries\MultiDB;
|
||||||
use App\Mail\DownloadCredits;
|
use App\Mail\DownloadCredits;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Models\CreditInvitation;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
@ -30,32 +31,12 @@ class ZipCredits implements ShouldQueue
|
|||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
public $credits;
|
|
||||||
|
|
||||||
private $company;
|
|
||||||
|
|
||||||
private $user;
|
|
||||||
|
|
||||||
public $settings;
|
public $settings;
|
||||||
|
|
||||||
public $tries = 1;
|
public $tries = 1;
|
||||||
|
|
||||||
/**
|
public function __construct(protected array $credit_ids, protected Company $company, protected User $user)
|
||||||
* @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)
|
|
||||||
{
|
{
|
||||||
$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);
|
MultiDB::setDb($this->company->db);
|
||||||
|
|
||||||
// create new zip object
|
$this->settings = $this->company->settings;
|
||||||
$zipFile = new \PhpZip\ZipFile();
|
$zipFile = new \PhpZip\ZipFile();
|
||||||
$file_name = date('Y-m-d').'_'.str_replace(' ', '_', trans('texts.credits')).'.zip';
|
$file_name = now()->addSeconds($this->company->timezone_offset())->format('Y-m-d-h-m-s').'_'.str_replace(' ', '_', trans('texts.credits')).'.zip';
|
||||||
$invitation = $this->credits->first()->invitations->first();
|
|
||||||
$path = $this->credits->first()->client->quote_filepath($invitation);
|
|
||||||
|
|
||||||
$this->credits->each(function ($credit) {
|
$invitations = CreditInvitation::query()->with('credit')->whereIn('credit_id', $this->credit_ids)->get();
|
||||||
(new CreateEntityPdf($credit->invitations()->first()))->handle();
|
$invitation = $invitations->first();
|
||||||
});
|
$path = $invitation->contact->client->credit_filepath($invitation);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
foreach ($this->credits as $credit) {
|
foreach ($invitations as $invitation) {
|
||||||
$file = $credit->service()->getCreditPdf($credit->invitations()->first());
|
$file = (new \App\Jobs\Entity\CreateRawPdf($invitation, $this->company->db))->handle();
|
||||||
$zip_file_name = basename($file);
|
$zipFile->addFromString($invitation->credit->numberFormatter() . '.pdf', $file);
|
||||||
$zipFile->addFromString($zip_file_name, Storage::get($file));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Storage::put($path.$file_name, $zipFile->outputAsString());
|
Storage::put($path.$file_name, $zipFile->outputAsString());
|
||||||
|
Loading…
Reference in New Issue
Block a user