mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add in shipping details
This commit is contained in:
parent
dc95528d13
commit
010bcb8286
@ -14,7 +14,6 @@ namespace App\Services\Pdf;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Quote;
|
||||
use App\Utils\Helpers;
|
||||
use App\Utils\Number;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use DOMDocument;
|
||||
use Illuminate\Support\Carbon;
|
||||
@ -836,7 +835,7 @@ class PdfBuilder
|
||||
return [
|
||||
['element' => 'div', 'properties' => ['style' => 'display: flex; flex-direction: column;'], 'elements' => [
|
||||
['element' => 'div', 'properties' => ['style' => 'margin-top: 1.5rem; display: block; align-items: flex-start; page-break-inside: avoid; visible !important;'], 'elements' => [
|
||||
['element' => 'img', 'properties' => ['src' => '$invoiceninja.whitelabel', 'style' => 'height: 2.5rem;', 'hidden' => $this->service->account->isPaid() ? 'true' : 'false', 'id' => 'invoiceninja-whitelabel-logo']],
|
||||
['element' => 'img', 'properties' => ['src' => '$invoiceninja.whitelabel', 'style' => 'height: 2.5rem;', 'hidden' => 'false', 'id' => 'invoiceninja-whitelabel-logo']],
|
||||
]],
|
||||
]],
|
||||
];
|
||||
@ -908,7 +907,7 @@ class PdfBuilder
|
||||
]],
|
||||
['element' => 'img', 'properties' => ['style' => 'max-width: 50%; height: auto;', 'src' => '$contact.signature', 'id' => 'contact-signature']],
|
||||
['element' => 'div', 'properties' => ['style' => 'margin-top: 1.5rem; display: flex; align-items: flex-start; page-break-inside: auto;'], 'elements' => [
|
||||
['element' => 'img', 'properties' => ['src' => '$invoiceninja.whitelabel', 'style' => 'height: 2.5rem;', 'hidden' => $this->service->account->isPaid() ? 'true' : 'false', 'id' => 'invoiceninja-whitelabel-logo']],
|
||||
['element' => 'img', 'properties' => ['src' => '$invoiceninja.whitelabel', 'style' => 'height: 2.5rem;', 'hidden' => 'false', 'id' => 'invoiceninja-whitelabel-logo']],
|
||||
]],
|
||||
]],
|
||||
['element' => 'div', 'properties' => ['class' => 'totals-table-right-side', 'dir' => '$dir'], 'elements' => []],
|
||||
|
@ -11,29 +11,29 @@
|
||||
|
||||
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;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Country;
|
||||
use App\Models\Credit;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\Currency;
|
||||
use App\Models\Design;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\PurchaseOrderInvitation;
|
||||
use App\Models\Quote;
|
||||
use App\Models\QuoteInvitation;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
use App\Models\Vendor;
|
||||
use App\Models\VendorContact;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\AppSetup;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Models\PurchaseOrderInvitation;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class PdfConfiguration
|
||||
{
|
||||
@ -317,7 +317,6 @@ class PdfConfiguration
|
||||
} elseif ($this->settings->show_currency_code === false) {
|
||||
return "{$symbol}{$value}";
|
||||
} else {
|
||||
|
||||
$value = floatval($value);
|
||||
$thousand = $this->currency->thousand_separator;
|
||||
$decimal = $this->currency->decimal_separator;
|
||||
@ -325,7 +324,6 @@ class PdfConfiguration
|
||||
|
||||
return number_format($value, $precision, $decimal, $thousand);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -342,11 +340,9 @@ class PdfConfiguration
|
||||
}
|
||||
|
||||
$this->date_format = $date_formats->filter(function ($item) {
|
||||
return $item->id == $this->settings->date_format_id;
|
||||
})->first()->format;
|
||||
return $item->id == $this->settings->date_format_id;
|
||||
})->first()->format;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -11,22 +11,18 @@
|
||||
|
||||
namespace App\Services\Pdf;
|
||||
|
||||
use App\Models\Quote;
|
||||
use App\DataMapper\ClientSettings;
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Design;
|
||||
use App\Models\Vendor;
|
||||
use App\Models\Company;
|
||||
use App\Models\Country;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Currency;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Services\Pdf\PdfBuilder;
|
||||
use App\Services\Pdf\PdfService;
|
||||
use App\Models\Design;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Services\Pdf\PdfDesigner;
|
||||
use App\DataMapper\ClientSettings;
|
||||
use App\Services\Pdf\PdfConfiguration;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\Quote;
|
||||
use App\Models\Vendor;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class PdfMock
|
||||
@ -35,14 +31,14 @@ class PdfMock
|
||||
|
||||
private mixed $mock;
|
||||
|
||||
private object $settings;
|
||||
public object $settings;
|
||||
|
||||
public function __construct(public array $request, public Company $company)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
public function getPdf(): mixed
|
||||
{
|
||||
|
||||
$pdf_service = new PdfService($this->mock->invitation);
|
||||
|
||||
$pdf_config = (new PdfConfiguration($pdf_service));
|
||||
@ -50,14 +46,14 @@ class PdfMock
|
||||
$pdf_config->entity_string = $this->request['entity_type'];
|
||||
$pdf_config->setTaxMap($this->mock->tax_map);
|
||||
$pdf_config->setTotalTaxMap($this->mock->total_tax_map);
|
||||
$pdf_config->setCurrency(Currency::find(1));
|
||||
$pdf_config->setCountry(Country::find(840));
|
||||
$pdf_config->client = $this->mock->client;
|
||||
$pdf_config->settings_object = $this->mock->client;
|
||||
$pdf_config->settings = $this->getMergedSettings();
|
||||
$this->settings = $pdf_config->settings;
|
||||
$pdf_config->entity_design_id = $pdf_config->settings->{"{$pdf_config->entity_string}_design_id"};
|
||||
$pdf_config->setPdfVariables();
|
||||
$pdf_config->setCurrency(Currency::find($this->settings->currency_id));
|
||||
$pdf_config->setCountry(Country::find($this->settings->country_id));
|
||||
$pdf_config->design = Design::find($this->decodePrimaryKey($pdf_config->entity_design_id));
|
||||
$pdf_config->currency_entity = $this->mock->client;
|
||||
|
||||
@ -72,20 +68,18 @@ class PdfMock
|
||||
$pdf_service->builder = $pdf_builder;
|
||||
|
||||
$html = $pdf_service->getHtml();
|
||||
nlog($html);
|
||||
|
||||
return $pdf_service->resolvePdfEngine($html);
|
||||
}
|
||||
|
||||
public function build(): self
|
||||
{
|
||||
|
||||
$this->mock = $this->initEntity();
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
private function initEntity(): mixed
|
||||
public function initEntity(): mixed
|
||||
{
|
||||
match ($this->request['entity_type']) {
|
||||
'invoice' => $entity = Invoice::factory()->make(),
|
||||
@ -95,10 +89,9 @@ nlog($html);
|
||||
default => $entity = Invoice::factory()->make()
|
||||
};
|
||||
|
||||
if($this->request['entity_type'] == PurchaseOrder::class){
|
||||
if ($this->request['entity_type'] == PurchaseOrder::class) {
|
||||
$entity->vendor = Vendor::factory()->make();
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$entity->client = Client::factory()->make();
|
||||
}
|
||||
|
||||
@ -106,30 +99,26 @@ nlog($html);
|
||||
$entity->total_tax_map = $this->getTotalTaxMap();
|
||||
$entity->invitation = InvoiceInvitation::factory()->make();
|
||||
$entity->invitation->company = $this->company;
|
||||
// $entity->invitation->company->account = $this->company->account;
|
||||
|
||||
return $entity;
|
||||
|
||||
}
|
||||
|
||||
public function getMergedSettings() :object
|
||||
{
|
||||
match($this->request['settings_type']){
|
||||
match ($this->request['settings_type']) {
|
||||
'group' => $settings = ClientSettings::buildClientSettings($this->company->settings, $this->request['settings']),
|
||||
'client' => $settings = ClientSettings::buildClientSettings($this->company->settings, $this->request['settings']),
|
||||
'company' => $settings = (object)$this->request['settings'],
|
||||
default => $settings = $this->company->settings,
|
||||
};
|
||||
|
||||
nlog($settings);
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
|
||||
private function getTaxMap()
|
||||
{
|
||||
return collect( [['name' => 'GST', 'total' => 10]]);
|
||||
return collect([['name' => 'GST', 'total' => 10]]);
|
||||
}
|
||||
|
||||
private function getTotalTaxMap()
|
||||
@ -139,8 +128,8 @@ nlog($html);
|
||||
|
||||
public function getStubVariables()
|
||||
{
|
||||
return ['values' =>
|
||||
[
|
||||
return ['values' =>
|
||||
[
|
||||
'$client.shipping_postal_code' => '46420',
|
||||
'$client.billing_postal_code' => '11243',
|
||||
'$company.city_state_postal' => '90210',
|
||||
@ -222,10 +211,10 @@ nlog($html);
|
||||
'$company.address1' => $this->settings->address1,
|
||||
'$credit.credit_no' => '0029',
|
||||
'$invoice.datetime' => '25/Feb/2023 1:10 am',
|
||||
'$contact.custom1' => NULL,
|
||||
'$contact.custom2' => NULL,
|
||||
'$contact.custom3' => NULL,
|
||||
'$contact.custom4' => NULL,
|
||||
'$contact.custom1' => null,
|
||||
'$contact.custom2' => null,
|
||||
'$contact.custom3' => null,
|
||||
'$contact.custom4' => null,
|
||||
'$task.line_total' => '',
|
||||
'$line_tax_labels' => '',
|
||||
'$line_tax_values' => '',
|
||||
@ -324,7 +313,7 @@ nlog($html);
|
||||
'$contact.name' => 'Benedict Eichmann',
|
||||
'$entity.terms' => 'Default company invoice terms',
|
||||
'$client.state' => 'North Carolina',
|
||||
'$company.logo' => $this->settings->company_logo,
|
||||
'$company.logo' => $this->settings->company_logo,
|
||||
'$company_logo' => $this->settings->company_logo,
|
||||
'$payment_link' => 'http://ninja.test:8000/client/pay/UAUY8vIPuno72igmXbbpldwo5BDDKIqs',
|
||||
'$status_logo' => '',
|
||||
@ -465,7 +454,7 @@ EPD
|
||||
'$show_shipping_address_block' => $this->settings->show_shipping_address ? 'block' : 'none',
|
||||
'$show_shipping_address_visibility' => $this->settings->show_shipping_address ? 'visible' : 'hidden',
|
||||
],
|
||||
'labels' =>
|
||||
'labels' =>
|
||||
[
|
||||
'$client.shipping_postal_code_label' => 'Shipping Postal Code',
|
||||
'$client.billing_postal_code_label' => 'Postal Code',
|
||||
|
@ -13,18 +13,17 @@ namespace App\Services\Pdf;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Models\Company;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Models\QuoteInvitation;
|
||||
use App\Utils\VendorHtmlEngine;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Utils\PhantomJS\Phantom;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Services\Pdf\PdfDesigner;
|
||||
use App\Utils\HostedPDF\NinjaPdf;
|
||||
use App\Utils\Traits\Pdf\PdfMaker;
|
||||
use App\Models\PurchaseOrderInvitation;
|
||||
use App\Utils\Traits\Pdf\PageNumbering;
|
||||
use App\Models\QuoteInvitation;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
use App\Utils\HostedPDF\NinjaPdf;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\PhantomJS\Phantom;
|
||||
use App\Utils\Traits\Pdf\PageNumbering;
|
||||
use App\Utils\Traits\Pdf\PdfMaker;
|
||||
use App\Utils\VendorHtmlEngine;
|
||||
|
||||
class PdfService
|
||||
{
|
||||
@ -34,8 +33,6 @@ class PdfService
|
||||
|
||||
public Company $company;
|
||||
|
||||
public Account $account;
|
||||
|
||||
public PdfConfiguration $config;
|
||||
|
||||
public PdfBuilder $builder;
|
||||
@ -59,12 +56,9 @@ class PdfService
|
||||
|
||||
$this->company = $invitation->company;
|
||||
|
||||
$this->account = $this->company->account;
|
||||
|
||||
$this->document_type = $document_type;
|
||||
|
||||
$this->options = $options;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,7 +72,6 @@ class PdfService
|
||||
public function getPdf()
|
||||
{
|
||||
try {
|
||||
|
||||
$pdf = $this->resolvePdfEngine($this->getHtml());
|
||||
|
||||
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||
@ -86,7 +79,6 @@ class PdfService
|
||||
if ($numbered_pdf) {
|
||||
$pdf = $numbered_pdf;
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
nlog(print_r($e->getMessage(), 1));
|
||||
throw new \Exception($e->getMessage(), $e->getCode());
|
||||
@ -119,7 +111,6 @@ class PdfService
|
||||
*/
|
||||
public function init(): self
|
||||
{
|
||||
|
||||
$this->config = (new PdfConfiguration($this))->init();
|
||||
|
||||
|
||||
@ -132,7 +123,6 @@ class PdfService
|
||||
$this->builder = (new PdfBuilder($this))->build();
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,7 +132,6 @@ class PdfService
|
||||
*/
|
||||
public function resolvePdfEngine(string $html): mixed
|
||||
{
|
||||
|
||||
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
|
||||
$pdf = (new Phantom)->convertHtmlToPdf($html);
|
||||
} elseif (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
|
||||
@ -153,5 +142,4 @@ class PdfService
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,15 +12,17 @@
|
||||
|
||||
namespace Tests\Pdf;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use Tests\TestCase;
|
||||
use App\Models\Design;
|
||||
use App\Models\Company;
|
||||
use App\Models\Country;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Currency;
|
||||
use App\Services\Pdf\PdfBuilder;
|
||||
use Tests\MockAccountData;
|
||||
use App\Services\Pdf\PdfMock;
|
||||
use Beganovich\Snappdf\Snappdf;
|
||||
use App\Services\Pdf\PdfBuilder;
|
||||
use App\Services\Pdf\PdfService;
|
||||
use App\Services\Pdf\PdfConfiguration;
|
||||
|
||||
@ -39,13 +41,17 @@ class PdfmockTest extends TestCase
|
||||
|
||||
public function testPdfInstance ()
|
||||
{
|
||||
$data = [
|
||||
'settings' => CompanySettings::defaults(),
|
||||
'settings_type' => 'company',
|
||||
'entity_type' => 'invoice',
|
||||
];
|
||||
|
||||
$entity = (new \App\Services\Pdf\PdfMock(Invoice::class))->build();
|
||||
$entity = (new \App\Services\Pdf\PdfMock($data, Company::factory()->make()))->build()->initEntity();
|
||||
|
||||
$this->assertInstanceOf(Invoice::class, $entity);
|
||||
$this->assertNotNull($entity->client);
|
||||
|
||||
|
||||
$pdf_service = new PdfService($entity->invitation);
|
||||
|
||||
$this->assertNotNull($pdf_service);
|
||||
@ -59,8 +65,14 @@ class PdfmockTest extends TestCase
|
||||
|
||||
public function testHtmlGeneration()
|
||||
{
|
||||
$pdf_mock = (new PdfMock(Invoice::class));
|
||||
$mock = $pdf_mock->build();
|
||||
$data = [
|
||||
'settings' => CompanySettings::defaults(),
|
||||
'settings_type' => 'company',
|
||||
'entity_type' => 'invoice',
|
||||
];
|
||||
|
||||
$pdf_mock = (new PdfMock($data, Company::factory()->make()))->build();
|
||||
$mock = $pdf_mock->initEntity();
|
||||
|
||||
$pdf_service = new PdfService($mock->invitation);
|
||||
|
||||
@ -74,7 +86,8 @@ class PdfmockTest extends TestCase
|
||||
$pdf_config->entity_design_id = 'invoice_design_id';
|
||||
$pdf_config->settings_object = $mock->client;
|
||||
$pdf_config->entity_string = 'invoice';
|
||||
$pdf_config->settings = (object)$pdf_config->service->company->settings;
|
||||
$pdf_config->settings = $pdf_mock->getMergedSettings();
|
||||
$pdf_mock->settings = $pdf_config->settings;
|
||||
$pdf_config->setPdfVariables();
|
||||
$pdf_config->design = Design::find(2);
|
||||
$pdf_config->currency_entity = $mock->client;
|
||||
|
Loading…
x
Reference in New Issue
Block a user