mock->invitation);
$pdf_config = (new PdfConfiguration($pdf_service));
$pdf_config->entity = $this->mock;
$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->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;
$pdf_service->config = $pdf_config;
$pdf_designer = (new PdfDesigner($pdf_service))->build();
$pdf_service->designer = $pdf_designer;
$pdf_service->html_variables = $this->getStubVariables();
$pdf_builder = (new PdfBuilder($pdf_service))->build();
$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;
}
public function initEntity(): mixed
{
match ($this->request['entity_type']) {
'invoice' => $entity = Invoice::factory()->make(),
'quote' => $entity = Quote::factory()->make(),
'credit' => $entity = Credit::factory()->make(),
'purchase_order' => $entity = PurchaseOrder::factory()->make(),
default => $entity = Invoice::factory()->make()
};
if ($this->request['entity_type'] == PurchaseOrder::class) {
$entity->vendor = Vendor::factory()->make();
} else {
$entity->client = Client::factory()->make();
}
$entity->tax_map = $this->getTaxMap();
$entity->total_tax_map = $this->getTotalTaxMap();
$entity->invitation = InvoiceInvitation::factory()->make();
$entity->invitation->company = $this->company;
return $entity;
}
public function getMergedSettings() :object
{
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,
};
return $settings;
}
private function getTaxMap()
{
return collect([['name' => 'GST', 'total' => 10]]);
}
private function getTotalTaxMap()
{
return [['name' => 'GST', 'total' => 10]];
}
public function getStubVariables()
{
return ['values' =>
[
'$client.shipping_postal_code' => '46420',
'$client.billing_postal_code' => '11243',
'$company.city_state_postal' => '90210',
'$company.postal_city_state' => 'CA',
'$product.gross_line_total' => '100',
'$client.postal_city_state' => '11243 Aufderharchester, North Carolina',
'$client.postal_city' => '11243 Aufderharchester, North Carolina',
'$client.shipping_address1' => '453',
'$client.shipping_address2' => '66327 Waters Trail',
'$client.city_state_postal' => 'Aufderharchester, North Carolina 11243',
'$client.shipping_address' => '453
66327 Waters Trail
Aufderharchester, North Carolina 11243
Afghanistan
',
'$client.billing_address2' => '63993 Aiyana View',
'$client.billing_address1' => '8447',
'$client.shipping_country' => 'USA',
'$invoiceninja.whitelabel' => 'https://raw.githubusercontent.com/invoiceninja/invoiceninja/v5-develop/public/images/new_logo.png',
'$client.billing_address' => '8447
63993 Aiyana View
Aufderharchester, North Carolina 11243
Afghanistan
',
'$client.billing_country' => 'USA',
'$task.gross_line_total' => '100',
'$contact.portal_button' => 'View client portal',
'$client.shipping_state' => 'Delaware',
'$invoice.public_notes' => 'These are some public notes for your document',
'$client.shipping_city' => 'Kesslerport',
'$client.billing_state' => 'North Carolina',
'$product.description' => 'A Product Description',
'$product.product_key' => 'A Product Key',
'$entity.public_notes' => 'Entity Public notes',
'$invoice.balance_due' => '$0.00',
'$client.public_notes' => ' ',
'$company.postal_code' => $this->settings->postal_code,
'$client.billing_city' => 'Aufderharchester',
'$secondary_font_name' => 'Roboto',
'$product.line_total' => '',
'$product.tax_amount' => '',
'$company.vat_number' => $this->settings->vat_number,
'$invoice.invoice_no' => '0029',
'$quote.quote_number' => '0029',
'$client.postal_code' => '11243',
'$contact.first_name' => 'Benedict',
'$secondary_font_url' => 'https://fonts.googleapis.com/css2?family=Roboto&display=swap',
'$contact.signature' => '',
'$company_logo_size' => $this->settings->company_logo_size ?: 55,
'$product.tax_name1' => '',
'$product.tax_name2' => '',
'$product.tax_name3' => '',
'$product.unit_cost' => '',
'$quote.valid_until' => '2023-10-24',
'$custom_surcharge1' => '$0.00',
'$custom_surcharge2' => '$0.00',
'$custom_surcharge3' => '$0.00',
'$custom_surcharge4' => '$0.00',
'$quote.balance_due' => '$0.00',
'$company.id_number' => $this->settings->id_number,
'$invoice.po_number' => ' ',
'$invoice_total_raw' => 0.0,
'$postal_city_state' => '11243 Aufderharchester, North Carolina',
'$client.vat_number' => '975977515',
'$city_state_postal' => 'Aufderharchester, North Carolina 11243',
'$contact.full_name' => 'Benedict Eichmann',
'$contact.last_name' => 'Eichmann',
'$company.country_2' => 'US',
'$product.product1' => '',
'$product.product2' => '',
'$product.product3' => '',
'$product.product4' => '',
'$statement_amount' => '',
'$task.description' => '',
'$product.discount' => '',
'$entity_issued_to' => '',
'$assigned_to_user' => '',
'$product.quantity' => '',
'$total_tax_labels' => '',
'$total_tax_values' => '',
'$invoice.discount' => '$0.00',
'$invoice.subtotal' => '$0.00',
'$company.address2' => $this->settings->address2,
'$partial_due_date' => ' ',
'$invoice.due_date' => ' ',
'$client.id_number' => ' ',
'$credit.po_number' => ' ',
'$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,
'$task.line_total' => '',
'$line_tax_labels' => '',
'$line_tax_values' => '',
'$secondary_color' => '#7081e0',
'$invoice.balance' => '$0.00',
'$invoice.custom1' => ' ',
'$invoice.custom2' => ' ',
'$invoice.custom3' => ' ',
'$invoice.custom4' => ' ',
'$company.custom1' => ' ',
'$company.custom2' => ' ',
'$company.custom3' => ' ',
'$company.custom4' => ' ',
'$quote.po_number' => ' ',
'$company.website' => $this->settings->website,
'$balance_due_raw' => '0.00',
'$entity.datetime' => '25/Feb/2023 1:10 am',
'$credit.datetime' => '25/Feb/2023 1:10 am',
'$client.address2' => '63993 Aiyana View',
'$client.address1' => '8447',
'$user.first_name' => 'Derrick Monahan DDS',
'$created_by_user' => 'Derrick Monahan DDS Erna Wunsch',
'$client.currency' => 'USD',
'$company.country' => 'United States',
'$company.address' => 'United States
',
'$tech_hero_image' => 'http://ninja.test:8000/images/pdf-designs/tech-hero-image.jpg',
'$task.tax_name1' => '',
'$task.tax_name2' => '',
'$task.tax_name3' => '',
'$client.balance' => '$0.00',
'$client_balance' => '$0.00',
'$credit.balance' => '$0.00',
'$credit_balance' => '$0.00',
'$gross_subtotal' => '$0.00',
'$invoice.amount' => '$0.00',
'$client.custom1' => ' ',
'$client.custom2' => ' ',
'$client.custom3' => ' ',
'$client.custom4' => ' ',
'$emailSignature' => ' ',
'$invoice.number' => '0029',
'$quote.quote_no' => '0029',
'$quote.datetime' => '25/Feb/2023 1:10 am',
'$client_address' => '8447
63993 Aiyana View
Aufderharchester, North Carolina 11243
Afghanistan
',
'$client.address' => '8447
63993 Aiyana View
Aufderharchester, North Carolina 11243
Afghanistan
',
'$payment_button' => 'Pay Now',
'$payment_qrcode' => '',
'$client.country' => 'Afghanistan',
'$user.last_name' => 'Erna Wunsch',
'$client.website' => 'http://www.parisian.org/',
'$dir_text_align' => 'left',
'$entity_images' => '',
'$task.discount' => '',
'$contact.email' => '',
'$primary_color' => '#298AAB',
'$credit_amount' => '$0.00',
'$invoice.total' => '$0.00',
'$invoice.taxes' => '$0.00',
'$quote.custom1' => ' ',
'$quote.custom2' => ' ',
'$quote.custom3' => ' ',
'$quote.custom4' => ' ',
'$company.email' => $this->settings->email,
'$client.number' => ' ',
'$company.phone' => $this->settings->phone,
'$company.state' => $this->settings->state,
'$credit.number' => '0029',
'$entity_number' => '0029',
'$credit_number' => '0029',
'$global_margin' => '6.35mm',
'$contact.phone' => '681-480-9828',
'$portal_button' => 'View client portal',
'$paymentButton' => 'Pay Now',
'$entity_footer' => 'Default invoice footer',
'$client.lang_2' => 'en',
'$product.date' => '',
'$client.email' => '',
'$product.item' => '',
'$public_notes' => '',
'$task.service' => '',
'$credit.total' => '$0.00',
'$net_subtotal' => '$0.00',
'$paid_to_date' => '$0.00',
'$quote.amount' => '$0.00',
'$company.city' => $this->settings->city,
'$payment.date' => ' ',
'$client.phone' => ' ',
'$number_short' => '0029',
'$quote.number' => '0029',
'$invoice.date' => '25/Feb/2023',
'$company.name' => $this->settings->name,
'$portalButton' => 'View client portal',
'$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,
'$payment_link' => 'http://ninja.test:8000/client/pay/UAUY8vIPuno72igmXbbpldwo5BDDKIqs',
'$status_logo' => '',
'$description' => '',
'$product.tax' => '',
'$valid_until' => '',
'$your_entity' => '',
'$shipping' => '',
'$balance_due' => '$0.00',
'$outstanding' => '$0.00',
'$partial_due' => '$0.00',
'$quote.total' => '$0.00',
'$payment_due' => ' ',
'$credit.date' => '25/Feb/2023',
'$invoiceDate' => '25/Feb/2023',
'$view_button' => 'View Invoice',
'$client.city' => 'Aufderharchester',
'$spc_qr_code' => 'SPC
0200
1
K
434343
CH
0.000000
USD
NON
0029
EPD
',
'$client_name' => 'A Client Called Bob',
'$client.name' => 'A Client Called Bob',
'$paymentLink' => 'http://ninja.test:8000/client/pay/UAUY8vIPuno72igmXbbpldwo5BDDKIqs',
'$payment_url' => 'http://ninja.test:8000/client/pay/UAUY8vIPuno72igmXbbpldwo5BDDKIqs',
'$page_layout' => $this->settings->page_layout,
'$task.task1' => '',
'$task.task2' => '',
'$task.task3' => '',
'$task.task4' => '',
'$task.hours' => '',
'$amount_due' => '$0.00',
'$amount_raw' => '0.00',
'$invoice_no' => '0029',
'$quote.date' => '25/Feb/2023',
'$vat_number' => '975977515',
'$viewButton' => 'View Invoice',
'$portal_url' => 'http://ninja.test:8000/client/',
'$task.date' => '',
'$task.rate' => '',
'$task.cost' => '',
'$statement' => '',
'$user_iban' => ' ',
'$signature' => ' ',
'$id_number' => ' ',
'$credit_no' => '0029',
'$font_size' => $this->settings->font_size,
'$view_link' => 'View Invoice',
'$page_size' => $this->settings->page_size,
'$country_2' => 'AF',
'$firstName' => 'Benedict',
'$user.name' => 'Derrick Monahan DDS Erna Wunsch',
'$font_name' => 'Roboto',
'$auto_bill' => 'This invoice will automatically be billed to your credit card on file on the due date.',
'$payments' => '',
'$task.tax' => '',
'$discount' => '$0.00',
'$subtotal' => '$0.00',
'$company1' => ' ',
'$company2' => ' ',
'$company3' => ' ',
'$company4' => ' ',
'$due_date' => ' ',
'$poNumber' => ' ',
'$quote_no' => '0029',
'$address2' => '63993 Aiyana View',
'$address1' => '8447',
'$viewLink' => 'View Invoice',
'$autoBill' => 'This invoice will automatically be billed to your credit card on file on the due date.',
'$view_url' => 'http://ninja.test:8000/client/invoice/UAUY8vIPuno72igmXbbpldwo5BDDKIqs',
'$font_url' => 'https://fonts.googleapis.com/css2?family=Roboto&display=swap',
'$details' => '',
'$balance' => '$0.00',
'$partial' => '$0.00',
'$client1' => ' ',
'$client2' => ' ',
'$client3' => ' ',
'$client4' => ' ',
'$dueDate' => ' ',
'$invoice' => '0029',
'$account' => '434343',
'$country' => 'Afghanistan',
'$contact' => 'Benedict Eichmann',
'$app_url' => 'http://ninja.test:8000',
'$website' => 'http://www.parisian.org/',
'$entity' => '',
'$thanks' => '',
'$amount' => '$0.00',
'$method' => ' ',
'$number' => '0029',
'$footer' => 'Default invoice footer',
'$client' => 'cypress',
'$email' => '',
'$notes' => '',
'_rate1' => '',
'_rate2' => '',
'_rate3' => '',
'$taxes' => '$0.00',
'$total' => '$0.00',
'$phone' => ' ',
'$terms' => 'Default company invoice terms',
'$from' => '',
'$item' => '',
'$date' => '25/Feb/2023',
'$tax' => '',
'$dir' => 'ltr',
'$to' => '',
'$show_paid_stamp' => $this->settings->show_paid_stamp ? 'flex' : 'none',
'$status_logo' => '