mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 07:34:34 -04: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,
|
'process_markdown' => $entity_obj->client->company->markdown_enabled,
|
||||||
'options' => [
|
'options' => [
|
||||||
'client' => $entity_obj->client,
|
'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,
|
'process_markdown' => $invitation->invoice->client->company->markdown_enabled,
|
||||||
'options' => [
|
'options' => [
|
||||||
'client' => $invitation->invoice->client,
|
'client' => $invitation->invoice->client,
|
||||||
'entity' => $invitation->invoice,
|
'invoices' => [$invitation->invoice],
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -485,79 +485,84 @@ class PreviewController extends BaseController
|
|||||||
/** @var \App\Models\Company $company */
|
/** @var \App\Models\Company $company */
|
||||||
$company = $user->company();
|
$company = $user->company();
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::connection($company->db)->beginTransaction();
|
||||||
|
|
||||||
DB::connection($company->db)->beginTransaction();
|
/** @var \App\Models\Client $client */
|
||||||
|
$client = Client::factory()->create([
|
||||||
|
'user_id' => auth()->user()->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
]);
|
||||||
|
|
||||||
/** @var \App\Models\Client $client */
|
/** @var \App\Models\ClientContact $contact */
|
||||||
$client = Client::factory()->create([
|
$contact = ClientContact::factory()->create([
|
||||||
'user_id' => auth()->user()->id,
|
'user_id' => auth()->user()->id,
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
]);
|
'client_id' => $client->id,
|
||||||
|
'is_primary' => 1,
|
||||||
|
'send_email' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
/** @var \App\Models\ClientContact $contact */
|
/** @var \App\Models\Invoice $invoice */
|
||||||
$contact = ClientContact::factory()->create([
|
|
||||||
'user_id' => auth()->user()->id,
|
|
||||||
'company_id' => $company->id,
|
|
||||||
'client_id' => $client->id,
|
|
||||||
'is_primary' => 1,
|
|
||||||
'send_email' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
/** @var \App\Models\Invoice $invoice */
|
$invoice = Invoice::factory()->create([
|
||||||
|
'user_id' => auth()->user()->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
'client_id' => $client->id,
|
||||||
|
'terms' => $company->settings->invoice_terms,
|
||||||
|
'footer' => $company->settings->invoice_footer,
|
||||||
|
'public_notes' => 'Sample Public Notes',
|
||||||
|
]);
|
||||||
|
|
||||||
$invoice = Invoice::factory()->create([
|
$invitation = InvoiceInvitation::factory()->create([
|
||||||
'user_id' => auth()->user()->id,
|
'user_id' => auth()->user()->id,
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
'client_id' => $client->id,
|
'invoice_id' => $invoice->id,
|
||||||
'terms' => $company->settings->invoice_terms,
|
'client_contact_id' => $contact->id,
|
||||||
'footer' => $company->settings->invoice_footer,
|
]);
|
||||||
'public_notes' => 'Sample Public Notes',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$invitation = InvoiceInvitation::factory()->create([
|
$invoice->setRelation('invitations', $invitation);
|
||||||
'user_id' => auth()->user()->id,
|
$invoice->setRelation('client', $client);
|
||||||
'company_id' => $company->id,
|
$invoice->setRelation('company', $company);
|
||||||
'invoice_id' => $invoice->id,
|
$invoice->load('client.company');
|
||||||
'client_contact_id' => $contact->id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$invoice->setRelation('invitations', $invitation);
|
$design_object = json_decode(json_encode(request()->input('design')));
|
||||||
$invoice->setRelation('client', $client);
|
|
||||||
$invoice->setRelation('company', $company);
|
|
||||||
$invoice->load('client.company');
|
|
||||||
|
|
||||||
$design_object = json_decode(json_encode(request()->input('design')));
|
if (! is_object($design_object)) {
|
||||||
|
return response()->json(['message' => 'Invalid custom design object'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
if (! is_object($design_object)) {
|
$html = new HtmlEngine($invoice->invitations()->first());
|
||||||
return response()->json(['message' => 'Invalid custom design object'], 400);
|
|
||||||
|
$design = new Design(Design::CUSTOM, ['custom_partials' => request()->design['design']]);
|
||||||
|
|
||||||
|
$state = [
|
||||||
|
'template' => $design->elements([
|
||||||
|
'client' => $invoice->client,
|
||||||
|
'entity' => $invoice,
|
||||||
|
'pdf_variables' => (array) $invoice->company->settings->pdf_variables,
|
||||||
|
'products' => request()->design['design']['product'],
|
||||||
|
]),
|
||||||
|
'variables' => $html->generateLabelsAndValues(),
|
||||||
|
'process_markdown' => $invoice->client->company->markdown_enabled,
|
||||||
|
'options' => [
|
||||||
|
'client' => $invoice->client,
|
||||||
|
'invoices' => [$invoice],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$maker = new PdfMaker($state);
|
||||||
|
|
||||||
|
$maker
|
||||||
|
->design($design)
|
||||||
|
->build();
|
||||||
|
|
||||||
|
DB::connection($company->db)->rollBack();
|
||||||
|
}
|
||||||
|
catch(\Exception $e){
|
||||||
|
DB::connection($company->db)->rollBack();
|
||||||
|
return response()->json(['message' => $e->getMessage()], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$html = new HtmlEngine($invoice->invitations()->first());
|
|
||||||
|
|
||||||
$design = new Design(Design::CUSTOM, ['custom_partials' => request()->design['design']]);
|
|
||||||
|
|
||||||
$state = [
|
|
||||||
'template' => $design->elements([
|
|
||||||
'client' => $invoice->client,
|
|
||||||
'entity' => $invoice,
|
|
||||||
'pdf_variables' => (array) $invoice->company->settings->pdf_variables,
|
|
||||||
'products' => request()->design['design']['product'],
|
|
||||||
]),
|
|
||||||
'variables' => $html->generateLabelsAndValues(),
|
|
||||||
'process_markdown' => $invoice->client->company->markdown_enabled,
|
|
||||||
'options' => [
|
|
||||||
'client' => $invoice->client,
|
|
||||||
'entity' => $invoice,
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
$maker = new PdfMaker($state);
|
|
||||||
|
|
||||||
$maker
|
|
||||||
->design($design)
|
|
||||||
->build();
|
|
||||||
|
|
||||||
DB::connection($company->db)->rollBack();
|
|
||||||
|
|
||||||
if (request()->query('html') == 'true') {
|
if (request()->query('html') == 'true') {
|
||||||
return $maker->getCompiledHTML();
|
return $maker->getCompiledHTML();
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Credit;
|
namespace App\Jobs\Credit;
|
||||||
|
|
||||||
use App\Jobs\Entity\CreateEntityPdf;
|
|
||||||
use App\Jobs\Mail\NinjaMailerJob;
|
use App\Jobs\Mail\NinjaMailerJob;
|
||||||
use App\Jobs\Mail\NinjaMailerObject;
|
use App\Jobs\Mail\NinjaMailerObject;
|
||||||
use App\Jobs\Util\UnlinkFile;
|
use App\Jobs\Util\UnlinkFile;
|
||||||
@ -31,8 +30,6 @@ class ZipCredits implements ShouldQueue
|
|||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
public $settings;
|
|
||||||
|
|
||||||
public $tries = 1;
|
public $tries = 1;
|
||||||
|
|
||||||
public function __construct(protected array $credit_ids, protected Company $company, protected User $user)
|
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);
|
MultiDB::setDb($this->company->db);
|
||||||
|
|
||||||
$this->settings = $this->company->settings;
|
$settings = $this->company->settings;
|
||||||
$zipFile = new \PhpZip\ZipFile();
|
$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';
|
$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 = new NinjaMailerObject;
|
||||||
$nmo->mailable = new DownloadCredits(Storage::url($path.$file_name), $this->company);
|
$nmo->mailable = new DownloadCredits(Storage::url($path.$file_name), $this->company);
|
||||||
$nmo->to_user = $this->user;
|
$nmo->to_user = $this->user;
|
||||||
$nmo->settings = $this->settings;
|
$nmo->settings = $settings;
|
||||||
$nmo->company = $this->company;
|
$nmo->company = $this->company;
|
||||||
|
|
||||||
NinjaMailerJob::dispatch($nmo);
|
NinjaMailerJob::dispatch($nmo);
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Invoice;
|
namespace App\Jobs\Invoice;
|
||||||
|
|
||||||
use App\Jobs\Entity\CreateEntityPdf;
|
|
||||||
use App\Jobs\Mail\NinjaMailerJob;
|
use App\Jobs\Mail\NinjaMailerJob;
|
||||||
use App\Jobs\Mail\NinjaMailerObject;
|
use App\Jobs\Mail\NinjaMailerObject;
|
||||||
use App\Jobs\Util\UnlinkFile;
|
use App\Jobs\Util\UnlinkFile;
|
||||||
@ -30,14 +29,6 @@ class ZipInvoices implements ShouldQueue
|
|||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
public $invoices;
|
|
||||||
|
|
||||||
private $company;
|
|
||||||
|
|
||||||
private $user;
|
|
||||||
|
|
||||||
public $settings;
|
|
||||||
|
|
||||||
public $tries = 1;
|
public $tries = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,15 +38,8 @@ class ZipInvoices implements ShouldQueue
|
|||||||
* @deprecated confirm to be deleted
|
* @deprecated confirm to be deleted
|
||||||
* Create a new job instance.
|
* 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
|
public function handle(): void
|
||||||
{
|
{
|
||||||
MultiDB::setDb($this->company->db);
|
MultiDB::setDb($this->company->db);
|
||||||
|
$settings = $this->company->settings;
|
||||||
|
|
||||||
// create new zip object
|
// create new zip object
|
||||||
$zipFile = new \PhpZip\ZipFile();
|
$zipFile = new \PhpZip\ZipFile();
|
||||||
@ -93,7 +78,7 @@ class ZipInvoices implements ShouldQueue
|
|||||||
$nmo = new NinjaMailerObject;
|
$nmo = new NinjaMailerObject;
|
||||||
$nmo->mailable = new DownloadInvoices(Storage::url($path.$file_name), $this->company);
|
$nmo->mailable = new DownloadInvoices(Storage::url($path.$file_name), $this->company);
|
||||||
$nmo->to_user = $this->user;
|
$nmo->to_user = $this->user;
|
||||||
$nmo->settings = $this->settings;
|
$nmo->settings = $settings;
|
||||||
$nmo->company = $this->company;
|
$nmo->company = $this->company;
|
||||||
|
|
||||||
NinjaMailerJob::dispatch($nmo);
|
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\DocumentWasDeleted;
|
||||||
use App\Events\Document\DocumentWasUpdated;
|
use App\Events\Document\DocumentWasUpdated;
|
||||||
use App\Events\Invoice\InvoiceWasCancelled;
|
use App\Events\Invoice\InvoiceWasCancelled;
|
||||||
use App\Listeners\Invoice\CreateInvoicePdf;
|
|
||||||
use App\Listeners\Quote\QuoteEmailActivity;
|
use App\Listeners\Quote\QuoteEmailActivity;
|
||||||
use App\Listeners\User\CreatedUserActivity;
|
use App\Listeners\User\CreatedUserActivity;
|
||||||
use App\Listeners\User\DeletedUserActivity;
|
use App\Listeners\User\DeletedUserActivity;
|
||||||
@ -378,7 +377,6 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
],
|
],
|
||||||
CreditWasUpdated::class => [
|
CreditWasUpdated::class => [
|
||||||
UpdatedCreditActivity::class,
|
UpdatedCreditActivity::class,
|
||||||
CreateInvoicePdf::class,
|
|
||||||
],
|
],
|
||||||
CreditWasEmailedAndFailed::class => [
|
CreditWasEmailedAndFailed::class => [
|
||||||
],
|
],
|
||||||
@ -459,7 +457,6 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
],
|
],
|
||||||
InvoiceWasReversed::class => [
|
InvoiceWasReversed::class => [
|
||||||
InvoiceReversedActivity::class,
|
InvoiceReversedActivity::class,
|
||||||
CreateInvoicePdf::class,
|
|
||||||
],
|
],
|
||||||
InvoiceWasCancelled::class => [
|
InvoiceWasCancelled::class => [
|
||||||
InvoiceCancelledActivity::class,
|
InvoiceCancelledActivity::class,
|
||||||
@ -515,7 +512,6 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
],
|
],
|
||||||
QuoteWasUpdated::class => [
|
QuoteWasUpdated::class => [
|
||||||
QuoteUpdatedActivity::class,
|
QuoteUpdatedActivity::class,
|
||||||
CreateInvoicePdf::class,
|
|
||||||
],
|
],
|
||||||
QuoteWasEmailed::class => [
|
QuoteWasEmailed::class => [
|
||||||
QuoteEmailActivity::class,
|
QuoteEmailActivity::class,
|
||||||
|
@ -80,14 +80,16 @@ class PdfMaker
|
|||||||
$replacements = [];
|
$replacements = [];
|
||||||
$contents = $this->document->getElementsByTagName('ninja');
|
$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) {
|
foreach ($contents as $content) {
|
||||||
|
|
||||||
$template = $content->ownerDocument->saveHTML($content);
|
$template = $content->ownerDocument->saveHTML($content);
|
||||||
|
|
||||||
$template = $twig->createTemplate(html_entity_decode($template));
|
$template = $twig->createTemplate(html_entity_decode($template));
|
||||||
$template = $template->render($this->options);
|
$template = $template->render($data);
|
||||||
|
|
||||||
$f = $this->document->createDocumentFragment();
|
$f = $this->document->createDocumentFragment();
|
||||||
$f->appendXML($template);
|
$f->appendXML($template);
|
||||||
|
@ -79,7 +79,7 @@ class TemplateService
|
|||||||
$this->twig = new Environment($loader, [
|
$this->twig = new Environment($loader, [
|
||||||
'debug' => true,
|
'debug' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$string_extension = new StringLoaderExtension();
|
$string_extension = new StringLoaderExtension();
|
||||||
$this->twig->addExtension($string_extension);
|
$this->twig->addExtension($string_extension);
|
||||||
$this->twig->addExtension(new IntlExtension());
|
$this->twig->addExtension(new IntlExtension());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user