mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 17:34:29 -04:00
PdfMockEntity
This commit is contained in:
parent
ce5dbf702e
commit
620f3a32e1
@ -955,7 +955,7 @@ class PdfBuilder
|
||||
|
||||
foreach ($variables as $variable) {
|
||||
if ($variable == '$total_taxes') {
|
||||
$taxes = $this->service->config->entity->calc()->getTotalTaxMap();
|
||||
$taxes = $this->service->config->entity->total_tax_map;
|
||||
|
||||
if (!$taxes) {
|
||||
continue;
|
||||
@ -968,7 +968,7 @@ class PdfBuilder
|
||||
]];
|
||||
}
|
||||
} elseif ($variable == '$line_taxes') {
|
||||
$taxes = $this->service->config->entity->calc()->getTaxMap();
|
||||
$taxes = $this->service->config->entity->tax_map;
|
||||
|
||||
if (!$taxes) {
|
||||
continue;
|
||||
|
@ -12,13 +12,18 @@
|
||||
namespace App\Services\Pdf;
|
||||
|
||||
use App\Utils\Ninja;
|
||||
use App\Models\Quote;
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Design;
|
||||
use App\Models\Vendor;
|
||||
use App\Models\Country;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Currency;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\VendorContact;
|
||||
use App\Utils\Traits\AppSetup;
|
||||
use App\Models\QuoteInvitation;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Models\CreditInvitation;
|
||||
@ -28,7 +33,7 @@ use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Models\PurchaseOrderInvitation;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
use App\Utils\Traits\AppSetup;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class PdfConfiguration
|
||||
{
|
||||
@ -46,7 +51,7 @@ class PdfConfiguration
|
||||
|
||||
public Design $design;
|
||||
|
||||
public $entity;
|
||||
public Invoice | Credit | Quote | PurchaseOrder $entity;
|
||||
|
||||
public string $entity_design_id;
|
||||
|
||||
@ -68,6 +73,9 @@ class PdfConfiguration
|
||||
|
||||
public string $locale;
|
||||
|
||||
public Collection $tax_map;
|
||||
|
||||
public ?array $total_tax_map;
|
||||
/**
|
||||
* __construct
|
||||
*
|
||||
@ -219,11 +227,28 @@ class PdfConfiguration
|
||||
throw new \Exception('Unable to resolve entity', 500);
|
||||
}
|
||||
|
||||
$this->setTaxMap($this->entity->calc()->getTaxMap());
|
||||
$this->setTotalTaxMap($this->entity->calc()->getTotalTaxMap());
|
||||
|
||||
$this->path = $this->path.$this->entity->numberFormatter().'.pdf';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTaxMap($map): self
|
||||
{
|
||||
$this->tax_map = $map;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTotalTaxMap($map): self
|
||||
{
|
||||
$this->total_tax_map = $map;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCurrency(Currency $currency): self
|
||||
{
|
||||
$this->currency = $currency;
|
||||
|
36
app/Services/Pdf/PdfMock.php
Normal file
36
app/Services/Pdf/PdfMock.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Services\Pdf;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Invoice;
|
||||
|
||||
class PdfMock
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
$mock = Invoice::factory()->make();
|
||||
$mock->client = Client::factory()->make();
|
||||
|
||||
nlog($mock);
|
||||
return $mock;
|
||||
|
||||
}
|
||||
|
||||
}
|
44
tests/Pdf/PdfmockTest.php
Normal file
44
tests/Pdf/PdfmockTest.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace Tests\Pdf;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Invoice;
|
||||
use Tests\MockAccountData;
|
||||
use Beganovich\Snappdf\Snappdf;
|
||||
use App\Services\Pdf\PdfService;
|
||||
use App\Services\Pdf\PdfConfiguration;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers App\Services\Pdf\PdfService
|
||||
*/
|
||||
class PdfmockTest extends TestCase
|
||||
{
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
}
|
||||
|
||||
public function testPdfInstance ()
|
||||
{
|
||||
|
||||
$entity = (new \App\Services\Pdf\PdfMock())->build();
|
||||
|
||||
$this->assertInstanceOf(Invoice::class, $entity);
|
||||
$this->assertNotNull($entity->client);
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user