mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01: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\Ninja;
|
||||
use App\Utils\PhantomJS\Phantom;
|
||||
use App\Utils\Traits\GeneratesCounter;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\MakesInvoiceHtml;
|
||||
use App\Utils\Traits\Pdf\PageNumbering;
|
||||
@ -40,6 +41,7 @@ use Twig\Error\SyntaxError;
|
||||
|
||||
class PreviewController extends BaseController
|
||||
{
|
||||
use GeneratesCounter;
|
||||
use MakesHash;
|
||||
use MakesInvoiceHtml;
|
||||
use PageNumbering;
|
||||
@ -404,23 +406,24 @@ class PreviewController extends BaseController
|
||||
|
||||
/** @var \App\Models\Client $client */
|
||||
$client = Client::factory()->create([
|
||||
'user_id' => auth()->user()->id,
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
]);
|
||||
|
||||
/** @var \App\Models\ClientContact $contact */
|
||||
$contact = ClientContact::factory()->create([
|
||||
'user_id' => auth()->user()->id,
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
'client_id' => $client->id,
|
||||
'is_primary' => 1,
|
||||
'send_email' => true,
|
||||
]);
|
||||
|
||||
/** @var \App\Models\Invoice $invoice */
|
||||
$settings = $company->settings;
|
||||
|
||||
/** @var \App\Models\Invoice $invoice */
|
||||
$invoice = Invoice::factory()->create([
|
||||
'user_id' => auth()->user()->id,
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
'client_id' => $client->id,
|
||||
'terms' => $company->settings->invoice_terms,
|
||||
@ -428,8 +431,18 @@ class PreviewController extends BaseController
|
||||
'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([
|
||||
'user_id' => auth()->user()->id,
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
'invoice_id' => $invoice->id,
|
||||
'client_contact_id' => $contact->id,
|
||||
@ -454,7 +467,7 @@ class PreviewController extends BaseController
|
||||
'template' => $design->elements([
|
||||
'client' => $invoice->client,
|
||||
'entity' => $invoice,
|
||||
'pdf_variables' => (array) $invoice->company->settings->pdf_variables,
|
||||
'pdf_variables' => (array) $settings->pdf_variables,
|
||||
'products' => request()->design['design']['product'],
|
||||
]),
|
||||
'variables' => $html->generateLabelsAndValues(),
|
||||
|
Loading…
Reference in New Issue
Block a user