mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
Refactor and removal of deprecated code paths
This commit is contained in:
parent
952f96de3b
commit
4fe9e1cef4
@ -280,7 +280,7 @@ class PreviewController extends BaseController
|
||||
'process_markdown' => $entity_obj->client->company->markdown_enabled,
|
||||
'options' => [
|
||||
'client' => $entity_obj->client,
|
||||
'entity' => $entity_obj,
|
||||
request()->input('entity_type', 'invoice')."s" => [$entity_obj],
|
||||
]
|
||||
];
|
||||
|
||||
@ -433,7 +433,7 @@ class PreviewController extends BaseController
|
||||
'process_markdown' => $invitation->invoice->client->company->markdown_enabled,
|
||||
'options' => [
|
||||
'client' => $invitation->invoice->client,
|
||||
'entity' => $invitation->invoice,
|
||||
'invoices' => [$invitation->invoice],
|
||||
]
|
||||
];
|
||||
|
||||
@ -485,7 +485,7 @@ class PreviewController extends BaseController
|
||||
/** @var \App\Models\Company $company */
|
||||
$company = $user->company();
|
||||
|
||||
|
||||
try {
|
||||
DB::connection($company->db)->beginTransaction();
|
||||
|
||||
/** @var \App\Models\Client $client */
|
||||
@ -547,7 +547,7 @@ class PreviewController extends BaseController
|
||||
'process_markdown' => $invoice->client->company->markdown_enabled,
|
||||
'options' => [
|
||||
'client' => $invoice->client,
|
||||
'entity' => $invoice,
|
||||
'invoices' => [$invoice],
|
||||
]
|
||||
];
|
||||
|
||||
@ -558,6 +558,11 @@ class PreviewController extends BaseController
|
||||
->build();
|
||||
|
||||
DB::connection($company->db)->rollBack();
|
||||
}
|
||||
catch(\Exception $e){
|
||||
DB::connection($company->db)->rollBack();
|
||||
return response()->json(['message' => $e->getMessage()], 400);
|
||||
}
|
||||
|
||||
if (request()->query('html') == 'true') {
|
||||
return $maker->getCompiledHTML();
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace App\Jobs\Credit;
|
||||
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Jobs\Util\UnlinkFile;
|
||||
@ -31,8 +30,6 @@ class ZipCredits implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $settings;
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
public function __construct(protected array $credit_ids, protected Company $company, protected User $user)
|
||||
@ -48,7 +45,7 @@ class ZipCredits implements ShouldQueue
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
$this->settings = $this->company->settings;
|
||||
$settings = $this->company->settings;
|
||||
$zipFile = new \PhpZip\ZipFile();
|
||||
$file_name = now()->addSeconds($this->company->timezone_offset())->format('Y-m-d-h-m-s').'_'.str_replace(' ', '_', trans('texts.credits')).'.zip';
|
||||
|
||||
@ -67,7 +64,7 @@ class ZipCredits implements ShouldQueue
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new DownloadCredits(Storage::url($path.$file_name), $this->company);
|
||||
$nmo->to_user = $this->user;
|
||||
$nmo->settings = $this->settings;
|
||||
$nmo->settings = $settings;
|
||||
$nmo->company = $this->company;
|
||||
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace App\Jobs\Invoice;
|
||||
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Jobs\Util\UnlinkFile;
|
||||
@ -30,14 +29,6 @@ class ZipInvoices implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $invoices;
|
||||
|
||||
private $company;
|
||||
|
||||
private $user;
|
||||
|
||||
public $settings;
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
/**
|
||||
@ -47,15 +38,8 @@ class ZipInvoices implements ShouldQueue
|
||||
* @deprecated confirm to be deleted
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct($invoices, Company $company, User $user)
|
||||
public function __construct(public mixed $invoices, public Company $company, public User $user)
|
||||
{
|
||||
$this->invoices = $invoices;
|
||||
|
||||
$this->company = $company;
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
$this->settings = $company->settings;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,6 +50,7 @@ class ZipInvoices implements ShouldQueue
|
||||
public function handle(): void
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
$settings = $this->company->settings;
|
||||
|
||||
// create new zip object
|
||||
$zipFile = new \PhpZip\ZipFile();
|
||||
@ -93,7 +78,7 @@ class ZipInvoices implements ShouldQueue
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new DownloadInvoices(Storage::url($path.$file_name), $this->company);
|
||||
$nmo->to_user = $this->user;
|
||||
$nmo->settings = $this->settings;
|
||||
$nmo->settings = $settings;
|
||||
$nmo->company = $this->company;
|
||||
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
|
@ -1,61 +0,0 @@
|
||||
<?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\Util;
|
||||
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Company;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\QuoteInvitation;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class RefreshPdfs implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $company;
|
||||
|
||||
public function __construct(Company $company)
|
||||
{
|
||||
$this->company = $company;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
InvoiceInvitation::where('company_id', $this->company->id)->cursor()->each(function ($invitation) {
|
||||
nlog("generating invoice pdf for {$invitation->invoice_id}");
|
||||
CreateEntityPdf::dispatch($invitation);
|
||||
});
|
||||
|
||||
QuoteInvitation::where('company_id', $this->company->id)->cursor()->each(function ($invitation) {
|
||||
nlog("generating quote pdf for {$invitation->quote_id}");
|
||||
CreateEntityPdf::dispatch($invitation);
|
||||
});
|
||||
|
||||
CreditInvitation::where('company_id', $this->company->id)->cursor()->each(function ($invitation) {
|
||||
nlog("generating credit pdf for {$invitation->credit_id}");
|
||||
CreateEntityPdf::dispatch($invitation);
|
||||
});
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
<?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\Listeners\Invoice;
|
||||
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Libraries\MultiDB;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class CreateInvoicePdf implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
MultiDB::setDb($event->company->db);
|
||||
|
||||
if (isset($event->invoice)) {
|
||||
$event->invoice->invitations->each(function ($invitation) {
|
||||
(new CreateEntityPdf($invitation->load('invoice', 'contact.client.company')))->handle();
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($event->quote)) {
|
||||
$event->quote->invitations->each(function ($invitation) {
|
||||
(new CreateEntityPdf($invitation->load('quote', 'contact.client.company')))->handle();
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($event->credit)) {
|
||||
$event->credit->invitations->each(function ($invitation) {
|
||||
(new CreateEntityPdf($invitation->load('credit', 'contact.client.company')))->handle();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -125,7 +125,6 @@ use App\Events\Document\DocumentWasCreated;
|
||||
use App\Events\Document\DocumentWasDeleted;
|
||||
use App\Events\Document\DocumentWasUpdated;
|
||||
use App\Events\Invoice\InvoiceWasCancelled;
|
||||
use App\Listeners\Invoice\CreateInvoicePdf;
|
||||
use App\Listeners\Quote\QuoteEmailActivity;
|
||||
use App\Listeners\User\CreatedUserActivity;
|
||||
use App\Listeners\User\DeletedUserActivity;
|
||||
@ -378,7 +377,6 @@ class EventServiceProvider extends ServiceProvider
|
||||
],
|
||||
CreditWasUpdated::class => [
|
||||
UpdatedCreditActivity::class,
|
||||
CreateInvoicePdf::class,
|
||||
],
|
||||
CreditWasEmailedAndFailed::class => [
|
||||
],
|
||||
@ -459,7 +457,6 @@ class EventServiceProvider extends ServiceProvider
|
||||
],
|
||||
InvoiceWasReversed::class => [
|
||||
InvoiceReversedActivity::class,
|
||||
CreateInvoicePdf::class,
|
||||
],
|
||||
InvoiceWasCancelled::class => [
|
||||
InvoiceCancelledActivity::class,
|
||||
@ -515,7 +512,6 @@ class EventServiceProvider extends ServiceProvider
|
||||
],
|
||||
QuoteWasUpdated::class => [
|
||||
QuoteUpdatedActivity::class,
|
||||
CreateInvoicePdf::class,
|
||||
],
|
||||
QuoteWasEmailed::class => [
|
||||
QuoteEmailActivity::class,
|
||||
|
@ -80,14 +80,16 @@ class PdfMaker
|
||||
$replacements = [];
|
||||
$contents = $this->document->getElementsByTagName('ninja');
|
||||
|
||||
$twig = (new TemplateService())->twig;
|
||||
$ts = new TemplateService();
|
||||
$data = $ts->processData($this->options)->getData();
|
||||
$twig = $ts->twig;
|
||||
|
||||
foreach ($contents as $content) {
|
||||
|
||||
$template = $content->ownerDocument->saveHTML($content);
|
||||
|
||||
$template = $twig->createTemplate(html_entity_decode($template));
|
||||
$template = $template->render($this->options);
|
||||
$template = $template->render($data);
|
||||
|
||||
$f = $this->document->createDocumentFragment();
|
||||
$f->appendXML($template);
|
||||
|
Loading…
Reference in New Issue
Block a user