mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
"Real" entity numbers in Invoice Settings preview
This refactors the GeneratesCounter trait slightly, such that arbitrary entity numbers can be formatted according to the given padding/pattern. With that small abstraction we can use the trait in the PdfMock instance to show the exmple entity number using real patterns without actually incrementing it or checking the number is available in the database.
This commit is contained in:
parent
354cc3343b
commit
9195addb37
@ -27,11 +27,13 @@ use App\Models\PurchaseOrderInvitation;
|
|||||||
use App\Models\Quote;
|
use App\Models\Quote;
|
||||||
use App\Models\QuoteInvitation;
|
use App\Models\QuoteInvitation;
|
||||||
use App\Models\Vendor;
|
use App\Models\Vendor;
|
||||||
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
|
||||||
class PdfMock
|
class PdfMock
|
||||||
{
|
{
|
||||||
use MakesHash;
|
use MakesHash;
|
||||||
|
use GeneratesCounter;
|
||||||
|
|
||||||
private mixed $mock;
|
private mixed $mock;
|
||||||
|
|
||||||
@ -206,6 +208,14 @@ class PdfMock
|
|||||||
*/
|
*/
|
||||||
public function getStubVariables(): array
|
public function getStubVariables(): array
|
||||||
{
|
{
|
||||||
|
// Although $this->mock is the Invoice/etc entity, we need the invitation to get company details.
|
||||||
|
$entity_number = $this->getFormattedEntityNumber(
|
||||||
|
$this->mock->invitation,
|
||||||
|
29,
|
||||||
|
$this->settings->counter_padding,
|
||||||
|
$this->settings->invoice_number_pattern
|
||||||
|
);
|
||||||
|
|
||||||
return ['values' =>
|
return ['values' =>
|
||||||
[
|
[
|
||||||
'$client.shipping_postal_code' => '46420',
|
'$client.shipping_postal_code' => '46420',
|
||||||
@ -370,7 +380,7 @@ class PdfMock
|
|||||||
'$company.phone' => $this->settings->phone,
|
'$company.phone' => $this->settings->phone,
|
||||||
'$company.state' => $this->settings->state,
|
'$company.state' => $this->settings->state,
|
||||||
'$credit.number' => '0029',
|
'$credit.number' => '0029',
|
||||||
'$entity_number' => '0029',
|
'$entity_number' => $entity_number,
|
||||||
'$credit_number' => '0029',
|
'$credit_number' => '0029',
|
||||||
'$global_margin' => '6.35mm',
|
'$global_margin' => '6.35mm',
|
||||||
'$contact.phone' => '681-480-9828',
|
'$contact.phone' => '681-480-9828',
|
||||||
|
@ -288,7 +288,6 @@ trait GeneratesCounter
|
|||||||
*/
|
*/
|
||||||
public function getNextProjectNumber(Project $project): string
|
public function getNextProjectNumber(Project $project): string
|
||||||
{
|
{
|
||||||
|
|
||||||
$entity_number = $this->getNextEntityNumber(Project::class, $project->client, false);
|
$entity_number = $this->getNextEntityNumber(Project::class, $project->client, false);
|
||||||
|
|
||||||
return $this->replaceUserVars($project, $entity_number);
|
return $this->replaceUserVars($project, $entity_number);
|
||||||
@ -412,7 +411,7 @@ trait GeneratesCounter
|
|||||||
*
|
*
|
||||||
* @param string $pattern
|
* @param string $pattern
|
||||||
* @param string $prefix
|
* @param string $prefix
|
||||||
* @return string The padded and prefixed entity number
|
* @return string The padded, prefixed and unique entity number
|
||||||
*/
|
*/
|
||||||
private function checkEntityNumber($class, $entity, $counter, $padding, $pattern, $prefix = ''): string
|
private function checkEntityNumber($class, $entity, $counter, $padding, $pattern, $prefix = ''): string
|
||||||
{
|
{
|
||||||
@ -420,11 +419,7 @@ trait GeneratesCounter
|
|||||||
$check_counter = 1;
|
$check_counter = 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$number = $this->padCounter($counter, $padding);
|
$number = $this->getFormattedEntityNumber($entity, $counter, $padding, $pattern);
|
||||||
|
|
||||||
$number = $this->applyNumberPattern($entity, $number, $pattern);
|
|
||||||
|
|
||||||
$number = $this->prefixCounter($number, $prefix);
|
|
||||||
|
|
||||||
$check = $class::where('company_id', $entity->company_id)->where('number', $number)->withTrashed()->exists();
|
$check = $class::where('company_id', $entity->company_id)->where('number', $number)->withTrashed()->exists();
|
||||||
|
|
||||||
@ -443,6 +438,26 @@ trait GeneratesCounter
|
|||||||
return $number;
|
return $number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats the entity number according to pattern, prefix and padding.
|
||||||
|
*
|
||||||
|
* @param Collection $entity The entity ie App\Models\Client, Invoice, Quote etc
|
||||||
|
* @param int $counter The counter
|
||||||
|
* @param int $padding The padding
|
||||||
|
* @param string $pattern
|
||||||
|
* @param string $prefix
|
||||||
|
*
|
||||||
|
* @return string The padded and prefixed entity number
|
||||||
|
*/
|
||||||
|
public function getFormattedEntityNumber($entity, $counter, $padding, $pattern, $prefix = ''): string
|
||||||
|
{
|
||||||
|
$number = $this->padCounter($counter, $padding);
|
||||||
|
|
||||||
|
$number = $this->applyNumberPattern($entity, $number, $pattern);
|
||||||
|
|
||||||
|
return $this->prefixCounter($number, $prefix);
|
||||||
|
}
|
||||||
|
|
||||||
/*Check if a number is available for use. */
|
/*Check if a number is available for use. */
|
||||||
public function checkNumberAvailable($class, $entity, $number): bool
|
public function checkNumberAvailable($class, $entity, $number): bool
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user