mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Apply formatted numbers to design editor preview
If a custom Invoice Number Pattern is defined, this will update the mock invoice with a formatted entity number, rather than the EAN13 from faker in the invoice factory. This doesn't apply once a real invoice has been created, but it can still be useful for designing during initial setup.
This commit is contained in:
parent
9195addb37
commit
e1d08d34bf
@ -29,6 +29,7 @@ use App\Utils\HostedPDF\NinjaPdf;
|
|||||||
use App\Utils\HtmlEngine;
|
use App\Utils\HtmlEngine;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use App\Utils\PhantomJS\Phantom;
|
use App\Utils\PhantomJS\Phantom;
|
||||||
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Utils\Traits\MakesInvoiceHtml;
|
use App\Utils\Traits\MakesInvoiceHtml;
|
||||||
use App\Utils\Traits\Pdf\PageNumbering;
|
use App\Utils\Traits\Pdf\PageNumbering;
|
||||||
@ -40,6 +41,7 @@ use Twig\Error\SyntaxError;
|
|||||||
|
|
||||||
class PreviewController extends BaseController
|
class PreviewController extends BaseController
|
||||||
{
|
{
|
||||||
|
use GeneratesCounter;
|
||||||
use MakesHash;
|
use MakesHash;
|
||||||
use MakesInvoiceHtml;
|
use MakesInvoiceHtml;
|
||||||
use PageNumbering;
|
use PageNumbering;
|
||||||
@ -404,23 +406,24 @@ class PreviewController extends BaseController
|
|||||||
|
|
||||||
/** @var \App\Models\Client $client */
|
/** @var \App\Models\Client $client */
|
||||||
$client = Client::factory()->create([
|
$client = Client::factory()->create([
|
||||||
'user_id' => auth()->user()->id,
|
'user_id' => $user->id,
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/** @var \App\Models\ClientContact $contact */
|
/** @var \App\Models\ClientContact $contact */
|
||||||
$contact = ClientContact::factory()->create([
|
$contact = ClientContact::factory()->create([
|
||||||
'user_id' => auth()->user()->id,
|
'user_id' => $user->id,
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
'client_id' => $client->id,
|
'client_id' => $client->id,
|
||||||
'is_primary' => 1,
|
'is_primary' => 1,
|
||||||
'send_email' => true,
|
'send_email' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/** @var \App\Models\Invoice $invoice */
|
$settings = $company->settings;
|
||||||
|
|
||||||
|
/** @var \App\Models\Invoice $invoice */
|
||||||
$invoice = Invoice::factory()->create([
|
$invoice = Invoice::factory()->create([
|
||||||
'user_id' => auth()->user()->id,
|
'user_id' => $user->id,
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
'client_id' => $client->id,
|
'client_id' => $client->id,
|
||||||
'terms' => $company->settings->invoice_terms,
|
'terms' => $company->settings->invoice_terms,
|
||||||
@ -428,8 +431,18 @@ class PreviewController extends BaseController
|
|||||||
'public_notes' => 'Sample Public Notes',
|
'public_notes' => 'Sample Public Notes',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($settings->invoice_number_pattern) {
|
||||||
|
$invoice->number = $this->getFormattedEntityNumber(
|
||||||
|
$invoice,
|
||||||
|
rand(1, 9999),
|
||||||
|
$settings->counter_padding ?: 4,
|
||||||
|
$settings->invoice_number_pattern,
|
||||||
|
);
|
||||||
|
$invoice->save();
|
||||||
|
}
|
||||||
|
|
||||||
$invitation = InvoiceInvitation::factory()->create([
|
$invitation = InvoiceInvitation::factory()->create([
|
||||||
'user_id' => auth()->user()->id,
|
'user_id' => $user->id,
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
'invoice_id' => $invoice->id,
|
'invoice_id' => $invoice->id,
|
||||||
'client_contact_id' => $contact->id,
|
'client_contact_id' => $contact->id,
|
||||||
@ -454,7 +467,7 @@ class PreviewController extends BaseController
|
|||||||
'template' => $design->elements([
|
'template' => $design->elements([
|
||||||
'client' => $invoice->client,
|
'client' => $invoice->client,
|
||||||
'entity' => $invoice,
|
'entity' => $invoice,
|
||||||
'pdf_variables' => (array) $invoice->company->settings->pdf_variables,
|
'pdf_variables' => (array) $settings->pdf_variables,
|
||||||
'products' => request()->design['design']['product'],
|
'products' => request()->design['design']['product'],
|
||||||
]),
|
]),
|
||||||
'variables' => $html->generateLabelsAndValues(),
|
'variables' => $html->generateLabelsAndValues(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user