mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
refactor invoice to entity
This commit is contained in:
parent
17858dae45
commit
438054744e
@ -26,12 +26,15 @@ class Plain extends BaseDesign
|
||||
/** @var App\Models\Client */
|
||||
public $client;
|
||||
|
||||
/** @var App\Models\Invoice */
|
||||
public $invoice;
|
||||
/** @var App\Models\Invoice || @var App\Models\Quote */
|
||||
public $entity;
|
||||
|
||||
/** Global state of the design, @var string */
|
||||
/** Global state of the design, @var array */
|
||||
public $context;
|
||||
|
||||
/** Type of entity => invoice||quote */
|
||||
public $type;
|
||||
|
||||
public function html(): ?string
|
||||
{
|
||||
return file_get_contents(
|
||||
@ -39,9 +42,11 @@ class Plain extends BaseDesign
|
||||
);
|
||||
}
|
||||
|
||||
public function elements(array $context): array
|
||||
public function elements(array $context, string $type = 'invoice'): array
|
||||
{
|
||||
$this->context = $context;
|
||||
$this->type = $type;
|
||||
|
||||
$this->setup();
|
||||
|
||||
return [
|
||||
@ -66,7 +71,7 @@ class Plain extends BaseDesign
|
||||
|
||||
public function companyAddress(): array
|
||||
{
|
||||
$variables = $this->invoice->company->settings->pdf_variables->company_address;
|
||||
$variables = $this->entity->company->settings->pdf_variables->company_address;
|
||||
|
||||
$elements = [];
|
||||
|
||||
@ -79,7 +84,7 @@ class Plain extends BaseDesign
|
||||
|
||||
public function entityDetails(): array
|
||||
{
|
||||
$variables = $this->invoice->company->settings->pdf_variables->invoice_details;
|
||||
$variables = $this->entity->company->settings->pdf_variables->invoice_details;
|
||||
|
||||
$elements = [];
|
||||
|
||||
@ -95,7 +100,7 @@ class Plain extends BaseDesign
|
||||
|
||||
public function clientDetails(): array
|
||||
{
|
||||
$variables = $this->invoice->company->settings->pdf_variables->client_details;
|
||||
$variables = $this->entity->company->settings->pdf_variables->client_details;
|
||||
|
||||
$elements = [];
|
||||
|
||||
@ -146,7 +151,7 @@ class Plain extends BaseDesign
|
||||
{
|
||||
$elements = [];
|
||||
|
||||
$items = $this->transformLineItems($this->invoice->line_items);
|
||||
$items = $this->transformLineItems($this->entity->line_items);
|
||||
|
||||
if (count($items) == 0) {
|
||||
return [];
|
||||
|
@ -20,8 +20,8 @@ class BaseDesign
|
||||
$this->client = $this->context['client'];
|
||||
}
|
||||
|
||||
if (isset($this->context['invoice'])) {
|
||||
$this->invoice = $this->context['invoice'];
|
||||
if (isset($this->context['entity'])) {
|
||||
$this->entity = $this->context['entity'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ trait BuildTableHeader
|
||||
public function processTaxColumns(): void
|
||||
{
|
||||
if (in_array('$product.tax', $this->context['product-table-columns'])) {
|
||||
$line_items = collect($this->invoice->line_items);
|
||||
$line_items = collect($this->entity->line_items);
|
||||
|
||||
$tax1 = $line_items->where('tax_name1', '<>', '')->where('type_id', 1)->count();
|
||||
$tax2 = $line_items->where('tax_name2', '<>', '')->where('type_id', 1)->count();
|
||||
|
@ -30,13 +30,13 @@ class ExampleIntegrationTest extends TestCase
|
||||
$state = [
|
||||
'template' => $design->elements([
|
||||
'client' => $invoice->client,
|
||||
'invoice' => $invoice,
|
||||
'entity' => $invoice,
|
||||
'product-table-columns' => $product_table_columns,
|
||||
]),
|
||||
'variables' => $engine->generateLabelsAndValues(),
|
||||
];
|
||||
|
||||
$maker = new PdfMaker($state);
|
||||
$maker = new PdfMaker($state, 'invoice');
|
||||
|
||||
$maker
|
||||
->design(Plain::class)
|
||||
|
Loading…
x
Reference in New Issue
Block a user