Performance improvements for PDF rendering (#3556)

* Performance improvements for PDF generation

* CS Fixer

* Performance improvements for PDF generate

* Fixes for tests
This commit is contained in:
David Bomba 2020-03-28 14:45:11 +11:00 committed by GitHub
parent 669507f995
commit 9cb7996a2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 167 additions and 168 deletions

View File

@ -466,70 +466,70 @@ class CompanySettings extends BaseSettings
private static function getEntityVariableDefaults() private static function getEntityVariableDefaults()
{ {
$variables = [ $variables = [
'client_details' => (object)[ 'client_details' => [
'$client.name' => ctrans('texts.client_name'), '$client.name',
'$client.id_number' => ctrans('texts.id_number'), '$client.id_number',
'$client.vat_number' => ctrans('texts.vat_number'), '$client.vat_number',
'$client.address1' => ctrans('texts.address1'), '$client.address1',
'$client.address2' => ctrans('texts.address2'), '$client.address2',
'$client.city_state_postal' => ctrans('texts.city_state_postal'), '$client.city_state_postal',
'$client.country' => ctrans('texts.country'), '$client.country',
'$client.email' => ctrans('texts.email'), '$contact.email',
], ],
'company_details' => (object)[ 'company_details' => [
'$company.company_name' => ctrans('texts.company_name'), '$company.company_name',
'$company.id_number' => ctrans('texts.id_number'), '$company.id_number',
'$company.vat_number' => ctrans('texts.vat_number'), '$company.vat_number',
'$company.website' => ctrans('texts.website'), '$company.website',
'$company.email' => ctrans('texts.email'), '$company.email',
'$company.phone' => ctrans('texts.phone'), '$company.phone',
], ],
'company_address' => (object)[ 'company_address' => [
'$company.address1' => ctrans('texts.address1'), '$company.address1',
'$company.address2' => ctrans('texts.address2'), '$company.address2',
'$company.city_state_postal' => ctrans('texts.city_state_postal'), '$company.city_state_postal',
'$company.country' => ctrans('texts.country'), '$company.country',
], ],
'invoice_details' => (object)[ 'invoice_details' => [
'$invoice.invoice_number' => ctrans('texts.invoice_number'), '$invoice.invoice_number',
'$invoice.po_number' => ctrans('texts.po_number'), '$invoice.po_number',
'$invoice.invoice_date' => ctrans('texts.invoice_date'), '$invoice.invoice_date',
'$invoice.due_date' => ctrans('texts.due_date'), '$invoice.due_date',
'$invoice.balance_due' => ctrans('texts.balance_due'), '$invoice.balance_due',
'$invoice.invoice_total' => ctrans('texts.invoice_total'), '$invoice.invoice_total',
], ],
'quote_details' => (object)[ 'quote_details' => [
'$quote.quote_number' => ctrans('texts.quote_number'), '$quote.quote_number',
'$quote.po_number' => ctrans('texts.po_number'), '$quote.po_number',
'$quote.quote_date' => ctrans('texts.quote_date'), '$quote.quote_date',
'$quote.valid_until' => ctrans('texts.valid_until'), '$quote.valid_until',
'$quote.balance_due' => ctrans('texts.balance_due'), '$quote.balance_due',
'$quote.quote_total' => ctrans('texts.quote_total'), '$quote.quote_total',
], ],
'credit_details' => (object)[ 'credit_details' => [
'$credit.credit_number' => ctrans('texts.credit_number'), '$credit.credit_number',
'$credit.po_number' => ctrans('texts.po_number'), '$credit.po_number',
'$credit.credit_date' => ctrans('texts.credit_date'), '$credit.credit_date',
'$credit.credit_balance' => ctrans('texts.credit_balance'), '$credit.credit_balance',
'$credit.credit_amount' => ctrans('texts.credit_amount'), '$credit.credit_amount',
], ],
'product_columns' => (object)[ 'product_columns' => [
'$product.product_key' => ctrans('texts.product_key'), '$product.product_key',
'$product.notes' => ctrans('texts.notes'), '$product.notes',
'$product.cost' => ctrans('texts.cost'), '$product.cost',
'$product.quantity' => ctrans('texts.quantity'), '$product.quantity',
'$product.discount' => ctrans('texts.discount'), '$product.discount',
'$product.tax_name1' => ctrans('texts.tax_name1'), '$product.tax_name1',
'$product.line_total' => ctrans('texts.line_total'), '$product.line_total',
], ],
'task_columns' => (object)[ 'task_columns' =>[
'$task.product_key' => ctrans('texts.product_key'), '$task.product_key',
'$task.notes' => ctrans('texts.notes'), '$task.notes',
'$task.cost' => ctrans('texts.cost'), '$task.cost',
'$task.quantity' => ctrans('texts.quantity'), '$task.quantity',
'$task.discount' => ctrans('texts.discount'), '$task.discount',
'$task.tax_name1' => ctrans('texts.tax_name1'), '$task.tax_name1',
'$task.line_total' => ctrans('texts.line_total'), '$task.line_total',
], ],
]; ];

View File

@ -89,30 +89,22 @@ class Designer
public function getIncludes() public function getIncludes()
{ {
$this->setDesign($this->getSection('includes')); return $this->getSection('includes');
return $this;
} }
public function getHeader() public function getHeader()
{ {
$this->setDesign($this->getSection('header')); return $this->getSection('header');
return $this;
} }
public function getFooter() public function getFooter()
{ {
$this->setDesign($this->getSection('footer')); return $this->getSection('footer');
return $this;
} }
public function getBody() public function getBody()
{ {
$this->setDesign($this->getSection('body')); return $this->getSection('body');
return $this;
} }
public function getHtml():string public function getHtml():string
@ -148,6 +140,7 @@ class Designer
private function exportVariables() private function exportVariables()
{ {
//$s = microtime(true);
$company = $this->entity->company; $company = $this->entity->company;
$this->exported_variables['$app_url'] = $this->entity->generateAppUrl(); $this->exported_variables['$app_url'] = $this->entity->generateAppUrl();
@ -178,7 +171,7 @@ class Designer
if (strlen($this->exported_variables['$product_table_body']) == 0) { if (strlen($this->exported_variables['$product_table_body']) == 0) {
$this->exported_variables['$product_table_header'] = ''; $this->exported_variables['$product_table_header'] = '';
} }
//\Log::error("Exporting variables took = ".(microtime(true)-$s));
return $this; return $this;
} }
@ -186,8 +179,10 @@ class Designer
{ {
$output = ''; $output = '';
foreach (array_keys($input_variables) as $value) { foreach (array_values($input_variables) as $value) {
$output .= $variables[$value]; if (array_key_exists($value, $variables)) {
$output .= $variables[$value];
}
} }
return $output; return $output;
@ -198,9 +193,11 @@ class Designer
$output = ''; $output = '';
foreach (array_keys($input_variables) as $value) { foreach (array_keys($input_variables) as $value) {
$tmp = str_replace("</span>", "_label</span>", $variables[$value]); if (array_key_exists($value, $variables)) {
//$output .= $variables[$value]; $tmp = str_replace("</span>", "_label</span>", $variables[$value]);
$output .= $tmp;
$output .= $tmp;
}
} }
return $output; return $output;
@ -217,15 +214,15 @@ class Designer
'$client.city_state_postal' => '<p>$client.city_state_postal</p>', '$client.city_state_postal' => '<p>$client.city_state_postal</p>',
'$client.postal_city_state' => '<p>$client.postal_city_state</p>', '$client.postal_city_state' => '<p>$client.postal_city_state</p>',
'$client.country' => '<p>$client.country</p>', '$client.country' => '<p>$client.country</p>',
'$client.email' => '<p>$client.email</p>', '$contact.email' => '<p>$client.email</p>',
'$client.client1' => '<p>$client1</p>', '$client.custom1' => '<p>$client.custom1</p>',
'$client.client2' => '<p>$client2</p>', '$client.custom2' => '<p>$client.custom2</p>',
'$client.client3' => '<p>$client3</p>', '$client.custom3' => '<p>$client.custom3</p>',
'$client.client4' => '<p>$client4</p>', '$client.custom4' => '<p>$client.custom4</p>',
'$client.contact1' => '<p>$contact1</p>', '$contact.contact1' => '<p>$contact.custom1</p>',
'$client.contact2' => '<p>$contact2</p>', '$contact.contact2' => '<p>$contact.custom2</p>',
'$client.contact3' => '<p>$contact3</p>', '$contact.contact3' => '<p>$contact.custom3</p>',
'$client.contact4' => '<p>$contact4</p>', '$contact.contact4' => '<p>$contact.custom4</p>',
]; ];
return $this->processCustomFields($company, $data); return $this->processCustomFields($company, $data);
@ -269,21 +266,21 @@ class Designer
private function invoiceDetails(Company $company) private function invoiceDetails(Company $company)
{ {
$data = [ $data = [
'$invoice.invoice_number' => '<span>$invoice.number_label</span><span>$invoice.number</span>', '$invoice.number' => '<span>$invoice.number_label: $invoice.number</span>',
'$invoice.po_number' => '<span>$invoice.po_number_label</span><span>$invoice.po_number</span>', '$invoice.po_number' => '<span>$invoice.po_number_label: $invoice.po_number</span>',
'$invoice.invoice_date' => '<span>$invoice.date_label</span><span>$invoice.date</span>', '$invoice.date' => '<span>$invoice.date_label: $invoice.date</span>',
'$invoice.due_date' => '<span>$invoice.due_date_label</span><span>$invoice.due_date</span>', '$invoice.due_date' => '<span>$invoice.due_date_label: $invoice.due_date</span>',
'$invoice.balance_due' => '<span>$invoice.balance_due_label</span><span>$invoice.balance_due</span>', '$invoice.balance_due' => '<span>$invoice.balance_due_label: $invoice.balance_due</span>',
'$invoice.invoice_total' => '<span>$invoice.total_label</span><span>$invoice.total</span>', '$invoice.total' => '<span>$invoice.total_label: $invoice.total</span>',
'$invoice.partial_due' => '<span>$invoice.partial_due_label</span><span>$invoice.partial_due</span>', '$invoice.partial_due' => '<span>$invoice.partial_due_label: $invoice.partial_due</span>',
'$invoice.invoice1' => '<span>$invoice1_label</span><span>$invoice1</span>', '$invoice.custom1' => '<span>$invoice1_label: $invoice.custom1</span>',
'$invoice.invoice2' => '<span>$invoice2_label</span><span>$invoice2</span>', '$invoice.custom2' => '<span>$invoice2_label: $invoice.custom2</span>',
'$invoice.invoice3' => '<span>$invoice3_label</span><span>$invoice3</span>', '$invoice.custom3' => '<span>$invoice3_label: $invoice.custom3</span>',
'$invoice.invoice4' => '<span>$invoice4_label</span><span>$invoice4</span>', '$invoice.custom4' => '<span>$invoice4_label: $invoice.custom4</span>',
'$invoice.surcharge1' => '<span>$surcharge1_label</span><span>$surcharge1</span>', '$surcharge1' => '<span>$surcharge1_label: $surcharge1</span>',
'$invoice.surcharge2' => '<span>$surcharge2_label</span><span>$surcharge2</span>', '$surcharge2' => '<span>$surcharge2_label: $surcharge2</span>',
'$invoice.surcharge3' => '<span>$surcharge3_label</span><span>$surcharge3</span>', '$surcharge3' => '<span>$surcharge3_label: $surcharge3</span>',
'$invoice.surcharge4' => '<span>$surcharge4_label</span><span>$surcharge4</span>', '$surcharge4' => '<span>$surcharge4_label: $surcharge4</span>',
]; ];
return $this->processCustomFields($company, $data); return $this->processCustomFields($company, $data);

View File

@ -99,14 +99,15 @@ class SetupController extends Controller
*/ */
public function checkDB(): Response public function checkDB(): Response
{ {
if (Account::count() == 0) {} if (Account::count() == 0) {
}
// test db - > /setup/check_db (POST) please send array of DB variables - response 200/success or 400 [message] // test db - > /setup/check_db (POST) please send array of DB variables - response 200/success or 400 [message]
// test mail -> /setup/check_mail (POST) please send array of MAIL xvariables - response 200/success or 400 [message] // test mail -> /setup/check_mail (POST) please send array of MAIL xvariables - response 200/success or 400 [message]
$randomStatus = rand(0, 1); $randomStatus = rand(0, 1);
if($randomStatus) { if ($randomStatus) {
return response([], 200); return response([], 200);
} }
@ -120,14 +121,15 @@ class SetupController extends Controller
*/ */
public function checkMail(): Response public function checkMail(): Response
{ {
if (Account::count() == 0) {} if (Account::count() == 0) {
}
// test db - > /setup/check_db (POST) please send array of DB variables - response 200/success or 400 [message] // test db - > /setup/check_db (POST) please send array of DB variables - response 200/success or 400 [message]
// test mail -> /setup/check_mail (POST) please send array of MAIL variables - response 200/success or 400 [message] // test mail -> /setup/check_mail (POST) please send array of MAIL variables - response 200/success or 400 [message]
$randomStatus = rand(0, 1); $randomStatus = rand(0, 1);
if($randomStatus) { if ($randomStatus) {
return response([], 200); return response([], 200);
} }

View File

@ -46,7 +46,6 @@ class Kernel extends HttpKernel
\Illuminate\View\Middleware\ShareErrorsFromSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class, \App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class, \Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\StartupCheck::class,
\App\Http\Middleware\QueryLogging::class, \App\Http\Middleware\QueryLogging::class,
], ],

View File

@ -46,6 +46,5 @@ class ShowTemplateRequest extends Request
public function message() public function message()
{ {
} }
} }

View File

@ -74,47 +74,22 @@ class CreateQuotePdf implements ShouldQueue
App::setLocale($this->contact->preferredLocale()); App::setLocale($this->contact->preferredLocale());
$path = $this->quote->client->quote_filepath(); $path = $this->quote->client->quote_filepath();
$design = Design::find($this->decodePrimaryKey($this->quote->client->getSetting('quote_design_id'))); $design = Design::find($this->decodePrimaryKey($this->quote->client->getSetting('quote_design_id')));
$designer = new Designer($this->quote, $design, $this->quote->client->getSetting('pdf_variables'), 'quote'); $designer = new Designer($this->quote, $design, $this->quote->client->getSetting('pdf_variables'), 'quote');
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily //todo - move this to the client creation stage so we don't keep hitting this unnecessarily
Storage::makeDirectory($path, 0755); Storage::makeDirectory($path, 0755);
//\Log::error($html);
$all_pages_header = $settings->all_pages_header; $all_pages_header = $settings->all_pages_header;
$all_pages_footer = $settings->all_pages_footer; $all_pages_footer = $settings->all_pages_footer;
$quote_number = $this->quote->number; $quote_number = $this->quote->number;
// if($all_pages_header && $all_pages_footer){
// $all_pages_header = $designer->init()->getHeader()->getHtml();
// $all_pages_footer = $designer->init()->getFooter()->getHtml();
// $design_body = $designer->init()->getBody()->getHtml();
// $quote_number = "header_and_footer";
// }
// elseif($all_pages_header){
// $all_pages_header = $designer->init()->getHeader()->getHtml();
// $design_body = $designer->init()->getBody()->getFooter()->getHtml();
// $quote_number = "header_only";
// }
// elseif($all_pages_footer){
// $all_pages_footer = $designer->init()->getFooter()->getHtml();
// $design_body = $designer->init()->getHeader()->getBody()->getHtml();
// $quote_number = "footer_only";
// }
// else{
$design_body = $designer->build()->getHtml(); $design_body = $designer->build()->getHtml();
//get invoice design
// $html = $this->generateInvoiceHtml($design_body, $this->quote, $this->contact);
$html = $this->generateEntityHtml($designer, $this->quote, $this->contact); $html = $this->generateEntityHtml($designer, $this->quote, $this->contact);
$pdf = $this->makePdf($all_pages_header, $all_pages_footer, $html); $pdf = $this->makePdf($all_pages_header, $all_pages_footer, $html);
@ -122,8 +97,6 @@ class CreateQuotePdf implements ShouldQueue
$instance = Storage::disk($this->disk)->put($file_path, $pdf); $instance = Storage::disk($this->disk)->put($file_path, $pdf);
//$instance= Storage::disk($this->disk)->path($file_path);
//
return $file_path; return $file_path;
} }
} }

View File

@ -126,7 +126,6 @@ class TemplateEngine
]); ]);
$this->body = $converter->convertToHtml($this->body); $this->body = $converter->convertToHtml($this->body);
} }
private function entityValues() private function entityValues()
@ -145,7 +144,6 @@ class TemplateEngine
]); ]);
$this->body = $converter->convertToHtml($this->body); $this->body = $converter->convertToHtml($this->body);
} }
private function renderTemplate() private function renderTemplate()

View File

@ -45,13 +45,15 @@ trait MakesInvoiceHtml
$labels = $entity->makeLabels(); $labels = $entity->makeLabels();
$values = $entity->makeValues($contact); $values = $entity->makeValues($contact);
$designer->build();
$data = []; $data = [];
$data['entity'] = $entity; $data['entity'] = $entity;
$data['lang'] = $client->preferredLocale(); $data['lang'] = $client->preferredLocale();
$data['includes'] = $designer->init()->getIncludes()->getHtml(); $data['includes'] = $designer->getIncludes();
$data['header'] = $designer->init()->getHeader()->getHtml(); $data['header'] = $designer->getHeader();
$data['body'] = $designer->init()->getBody()->getHtml(); $data['body'] = $designer->getBody();
$data['footer'] = $designer->init()->getFooter()->getHtml(); $data['footer'] = $designer->getFooter();
$html = view('pdf.stub', $data)->render(); $html = view('pdf.stub', $data)->render();

View File

@ -125,6 +125,12 @@ trait MakesInvoiceValues
$settings = $this->client->getMergedSettings(); $settings = $this->client->getMergedSettings();
if (!$contact) {
$contact = $this->client->primary_contact()->first();
}
$calc = $this->calc();
$data = []; $data = [];
$data['$tax'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$tax'] = ['value' => '', 'label' => ctrans('texts.tax')];
$data['$app_url'] = ['value' => $this->generateAppUrl(), 'label' => '']; $data['$app_url'] = ['value' => $this->generateAppUrl(), 'label' => ''];
@ -170,26 +176,26 @@ trait MakesInvoiceValues
$data['$entity_number'] = &$data['$number']; $data['$entity_number'] = &$data['$number'];
//$data['$paid_to_date'] = ; //$data['$paid_to_date'] = ;
$data['$invoice.discount'] = ['value' => Number::formatMoney($this->calc()->getTotalDiscount(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.discount')]; $data['$invoice.discount'] = ['value' => Number::formatMoney($calc->getTotalDiscount(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.discount')];
$data['$discount'] = &$data['$invoice.discount']; $data['$discount'] = &$data['$invoice.discount'];
$data['$subtotal'] = ['value' => Number::formatMoney($this->calc()->getSubTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.subtotal')]; $data['$subtotal'] = ['value' => Number::formatMoney($calc->getSubTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.subtotal')];
$data['$invoice.subtotal'] = &$data['$subtotal']; $data['$invoice.subtotal'] = &$data['$subtotal'];
$data['$invoice.balance_due'] = ['value' => Number::formatMoney($this->balance, $this->client) ?: '&nbsp;', 'label' => ctrans('texts.balance_due')]; $data['$invoice.balance_due'] = ['value' => Number::formatMoney($this->balance, $this->client) ?: '&nbsp;', 'label' => ctrans('texts.balance_due')];
$data['$quote.balance_due'] = &$data['$invoice.balance_due']; $data['$quote.balance_due'] = &$data['$invoice.balance_due'];
$data['$balance_due'] = &$data['$invoice.balance_due']; $data['$balance_due'] = &$data['$invoice.balance_due'];
$data['$invoice.partial_due'] = ['value' => Number::formatMoney($this->partial, $this->client) ?: '&nbsp;', 'label' => ctrans('texts.partial_due')]; $data['$invoice.partial_due'] = ['value' => Number::formatMoney($this->partial, $this->client) ?: '&nbsp;', 'label' => ctrans('texts.partial_due')];
$data['$total'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.total')]; $data['$total'] = ['value' => Number::formatMoney($calc->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.total')];
$data['$quote.total'] = &$data['$total']; $data['$quote.total'] = &$data['$total'];
$data['$invoice.total'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.invoice_total')]; $data['$invoice.total'] = ['value' => Number::formatMoney($calc->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.invoice_total')];
$data['$invoice.amount'] = &$data['$total']; $data['$invoice.amount'] = &$data['$total'];
$data['$quote.amount'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.quote_total')]; $data['$quote.amount'] = ['value' => Number::formatMoney($calc->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.quote_total')];
$data['$credit.total'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.credit_total')]; $data['$credit.total'] = ['value' => Number::formatMoney($calc->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.credit_total')];
$data['$credit.number'] = ['value' => $this->number ?: '&nbsp;', 'label' => ctrans('texts.credit_number')]; $data['$credit.number'] = ['value' => $this->number ?: '&nbsp;', 'label' => ctrans('texts.credit_number')];
$data['$credit.amount'] = &$data['$credit.total']; $data['$credit.amount'] = &$data['$credit.total'];
$data['$balance'] = ['value' => Number::formatMoney($this->calc()->getBalance(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.balance')]; $data['$balance'] = ['value' => Number::formatMoney($calc->getBalance(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.balance')];
$data['$invoice.balance'] = &$data['$balance']; $data['$invoice.balance'] = &$data['$balance'];
$data['$taxes'] = ['value' => Number::formatMoney($this->calc()->getItemTotalTaxes(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.taxes')]; $data['$taxes'] = ['value' => Number::formatMoney($calc->getItemTotalTaxes(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.taxes')];
$data['$invoice.taxes'] = &$data['$taxes']; $data['$invoice.taxes'] = &$data['$taxes'];
$data['$invoice.custom1'] = ['value' => $this->custom_value1 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice1')]; $data['$invoice.custom1'] = ['value' => $this->custom_value1 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice1')];
@ -210,7 +216,7 @@ trait MakesInvoiceValues
$data['$quote_no'] = &$data['$quote.number']; $data['$quote_no'] = &$data['$quote.number'];
$data['$quote.quote_no'] = &$data['$quote.number']; $data['$quote.quote_no'] = &$data['$quote.number'];
$data['$quote.valid_until'] = ['value' => $this->due_date, 'label' => ctrans('texts.valid_until')]; $data['$quote.valid_until'] = ['value' => $this->due_date, 'label' => ctrans('texts.valid_until')];
$data['$credit_amount'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.credit_amount')]; $data['$credit_amount'] = ['value' => Number::formatMoney($calc->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.credit_amount')];
$data['$credit_balance'] = ['value' => Number::formatMoney($this->balance, $this->client) ?: '&nbsp;', 'label' => ctrans('texts.credit_balance')]; $data['$credit_balance'] = ['value' => Number::formatMoney($this->balance, $this->client) ?: '&nbsp;', 'label' => ctrans('texts.credit_balance')];
; ;
$data['$credit_number'] = &$data['$number']; $data['$credit_number'] = &$data['$number'];
@ -239,7 +245,7 @@ trait MakesInvoiceValues
$data['$website'] = ['value' => $this->client->present()->website() ?: '&nbsp;', 'label' => ctrans('texts.website')]; $data['$website'] = ['value' => $this->client->present()->website() ?: '&nbsp;', 'label' => ctrans('texts.website')];
$data['$phone'] = ['value' => $this->client->present()->phone() ?: '&nbsp;', 'label' => ctrans('texts.phone')]; $data['$phone'] = ['value' => $this->client->present()->phone() ?: '&nbsp;', 'label' => ctrans('texts.phone')];
$data['$country'] = ['value' => isset($this->client->country->name) ? $this->client->country->name : 'No Country Set', 'label' => ctrans('texts.country')]; $data['$country'] = ['value' => isset($this->client->country->name) ? $this->client->country->name : 'No Country Set', 'label' => ctrans('texts.country')];
$data['$email'] = ['value' => isset($this->client->primary_contact()->first()->email) ? $this->client->primary_contact()->first()->email : 'no contact email on record', 'label' => ctrans('texts.email')]; $data['$email'] = ['value' => isset($contact) ? $contact->email : 'no contact email on record', 'label' => ctrans('texts.email')];
$data['$client_name'] = ['value' => $this->present()->clientName() ?: '&nbsp;', 'label' => ctrans('texts.client_name')]; $data['$client_name'] = ['value' => $this->present()->clientName() ?: '&nbsp;', 'label' => ctrans('texts.client_name')];
$data['$client.name'] = &$data['$client_name']; $data['$client.name'] = &$data['$client_name'];
$data['$client.address1'] = &$data['$address1']; $data['$client.address1'] = &$data['$address1'];
@ -257,16 +263,17 @@ trait MakesInvoiceValues
$data['$client.country'] = &$data['$country']; $data['$client.country'] = &$data['$country'];
$data['$client.email'] = &$data['$email']; $data['$client.email'] = &$data['$email'];
if (!$contact) {
$contact = $this->client->primary_contact()->first(); $data['$contact.full_name'] = ['value' => $contact->present()->name(), 'label' => ctrans('texts.name')];
} $data['$contact.email'] = ['value' => $contact->email, 'label' => ctrans('texts.email')];
$data['$contact.phone'] = ['value' => $contact->phone, 'label' => ctrans('texts.phone')];
$data['$contact_name'] = $data['$contact_name'] =
$data['$contact.name'] = ['value' => isset($contact) ? $contact->present()->name() : 'no contact name on record', 'label' => ctrans('texts.contact_name')]; $data['$contact.name'] = ['value' => isset($contact) ? $contact->present()->name() : 'no contact name on record', 'label' => ctrans('texts.contact_name')];
$data['$contact1'] = ['value' => isset($contact) ? $contact->custom_value1 : '&nbsp;', 'label' => $this->makeCustomField('contact1')]; $data['$contact.custom1'] = ['value' => isset($contact) ? $contact->custom_value1 : '&nbsp;', 'label' => $this->makeCustomField('contact1')];
$data['$contact2'] = ['value' => isset($contact) ? $contact->custom_value2 : '&nbsp;', 'label' => $this->makeCustomField('contact1')]; $data['$contact.custom2'] = ['value' => isset($contact) ? $contact->custom_value2 : '&nbsp;', 'label' => $this->makeCustomField('contact1')];
$data['$contact3'] = ['value' => isset($contact) ? $contact->custom_value3 : '&nbsp;', 'label' => $this->makeCustomField('contact1')]; $data['$contact.custom3'] = ['value' => isset($contact) ? $contact->custom_value3 : '&nbsp;', 'label' => $this->makeCustomField('contact1')];
$data['$contact4'] = ['value' => isset($contact) ? $contact->custom_value4 : '&nbsp;', 'label' => $this->makeCustomField('contact1')]; $data['$contact.custom4'] = ['value' => isset($contact) ? $contact->custom_value4 : '&nbsp;', 'label' => $this->makeCustomField('contact1')];
$data['$company.city_state_postal'] = ['value' => $this->company->present()->cityStateZip($settings->city, $settings->state, $settings->postal_code, false) ?: '&nbsp;', 'label' => ctrans('texts.city_state_postal')]; $data['$company.city_state_postal'] = ['value' => $this->company->present()->cityStateZip($settings->city, $settings->state, $settings->postal_code, false) ?: '&nbsp;', 'label' => ctrans('texts.city_state_postal')];
$data['$company.postal_city_state'] = ['value' => $this->company->present()->cityStateZip($settings->city, $settings->state, $settings->postal_code, true) ?: '&nbsp;', 'label' => ctrans('texts.postal_city_state')]; $data['$company.postal_city_state'] = ['value' => $this->company->present()->cityStateZip($settings->city, $settings->state, $settings->postal_code, true) ?: '&nbsp;', 'label' => ctrans('texts.postal_city_state')];
@ -373,7 +380,7 @@ trait MakesInvoiceValues
$table_header = '<tr>'; $table_header = '<tr>';
foreach ($columns as $key => $column) { foreach ($columns as $key => $column) {
$table_header .= '<td class="table_header_td_class">' . $key . '_label</td>'; $table_header .= '<td class="table_header_td_class">' . $column . '_label</td>';
} }
$table_header .= '</tr>'; $table_header .= '</tr>';
@ -411,7 +418,7 @@ trait MakesInvoiceValues
$table_row = '<tr>'; $table_row = '<tr>';
foreach ($default_columns as $key => $column) { foreach ($default_columns as $key => $column) {
$table_row .= '<td class="table_header_td_class">' . $key . '</td>'; $table_row .= '<td class="table_header_td_class">' . $column . '</td>';
} }
$table_row .= '</tr>'; $table_row .= '</tr>';

View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Invoice Ninja</title>
<meta name="report_errors" content="{{ $report_errors }}">
</head>
<body style="background-color:#888888;">
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/flutter_service_worker.js');
});
}
</script>
<script src="main.dart.js" type="application/javascript"></script>
<center style="font-family:Tahoma,Geneva,sans-serif;font-size:28px;color:white;padding-top:100px">
Loading...
</center>
</body>
</html>

View File

@ -2,7 +2,6 @@
namespace Tests\Integration; namespace Tests\Integration;
use App\Jobs\Invoice\MarkInvoicePaid;
use App\Models\Account; use App\Models\Account;
use App\Models\Company; use App\Models\Company;
use App\Models\Invoice; use App\Models\Invoice;
@ -15,7 +14,6 @@ use Tests\TestCase;
/** /**
* @test * @test
* @covers App\Services\Invoice\MarkInvoicePaid
*/ */
class MarkInvoicePaidTest extends TestCase class MarkInvoicePaidTest extends TestCase
{ {

View File

@ -18,8 +18,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\MockAccountData; use Tests\MockAccountData;
use Tests\TestCase; use Tests\TestCase;
/** @test /** @test*/
/** @covers App\Services\Ledger\LedgerService */
class UpdateCompanyLedgerTest extends TestCase class UpdateCompanyLedgerTest extends TestCase
{ {
@ -35,7 +34,6 @@ class UpdateCompanyLedgerTest extends TestCase
/** /**
* @test * @test
* @covers App\Jobs\Company\UpdateCompanyLedgerWithPayment
*/ */
public function testPaymentIsPresentInLedger() public function testPaymentIsPresentInLedger()
{ {
@ -52,7 +50,6 @@ class UpdateCompanyLedgerTest extends TestCase
/** /**
* @test * @test
* @covers App\Jobs\Company\UpdateCompanyLedgerWithInvoice
*/ */
public function testInvoiceIsPresentInLedger() public function testInvoiceIsPresentInLedger()
{ {

View File

@ -18,7 +18,7 @@ class PdfVariablesTest extends TestCase
$this->settings = CompanySettings::defaults(); $this->settings = CompanySettings::defaults();
} }
/*
public function testPdfVariableDefaults() public function testPdfVariableDefaults()
{ {
$pdf_variables = $this->settings->pdf_variables; $pdf_variables = $this->settings->pdf_variables;
@ -35,7 +35,6 @@ class PdfVariablesTest extends TestCase
public function testReplaceSampleHeaderText() public function testReplaceSampleHeaderText()
{ {
/* this flattens the multi dimensional array so we can do a single str_replace */
$pdf_variables = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->settings->pdf_variables))); $pdf_variables = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->settings->pdf_variables)));
//\Log::error(print_r($pdf_variables,1)); //\Log::error(print_r($pdf_variables,1));
@ -46,4 +45,7 @@ class PdfVariablesTest extends TestCase
$this->assertEquals($replaced_header_text, '<tr><td>Client Name</td><td>Product</td><td>Line Total</td></tr>'); $this->assertEquals($replaced_header_text, '<tr><td>Client Name</td><td>Product</td><td>Line Total</td></tr>');
} }
*/
} }