From ed0dec0667f9f461eee587ebf24fd37e0046d2c9 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Thu, 13 Oct 2022 19:53:03 -0700 Subject: [PATCH] Continued to work on it --- src/bb-modules/Invoice/Service.php | 117 +++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 24 deletions(-) diff --git a/src/bb-modules/Invoice/Service.php b/src/bb-modules/Invoice/Service.php index b83cbf30f..d9ec68988 100644 --- a/src/bb-modules/Invoice/Service.php +++ b/src/bb-modules/Invoice/Service.php @@ -1217,7 +1217,66 @@ class Service implements InjectionAwareInterface $systemService = $this->di['mod_service']('System'); $company = $systemService->getCompany(); - $pdf = = new Dompdf(); + $pdf = new Dompdf(); + $options = $pdf->getOptions(); + $options->setChroot($_SERVER['DOCUMENT_ROOT']); + + $leftMargin = 12; + + $html = ' + + '; + $html .= "" . $invoice['serie_nr'] . ""; + $html .= ' + + '; if (isset($company['logo_url']) && !empty($company['logo_url'])) { $url = parse_url($company['logo_url'], PHP_URL_PATH); @@ -1226,38 +1285,48 @@ class Service implements InjectionAwareInterface if(!file_exists($url)){ // Assume the URL points to an image not hosted on this server $url = $company['logo_url']; + $options->set('isRemoteEnabled',true); } } - $pdf->Image($url, 15, 15, 50, 50); + $html .= ""; + $html .= '
'; } - - $invoiceDate = strftime($localeDateFormat, strtotime($this->di['array_get']($invoice, 'due_at', $invoice['created_at']))); - $invoiceInfo = sprintf("%s: %s\n", __('Invoice number'), $invoice['serie_nr']); - $invoiceInfo .= sprintf("%s: %s\n", __('Invoice date'), $invoiceDate); - $invoiceInfo .= sprintf("%s: %s\n", __('Due date'), strftime($localeDateFormat, strtotime($invoice['due_at']))); - $invoiceInfo .= sprintf("%s: %s\n", __('Invoice status'), ucfirst($invoice['status'])); + $html .= '
'; + $html .= '

Invoice number: ' . $invoice['serie_nr'] . '

'; + $html .= '

Invoice date: ' . $invoiceDate . '

'; + $html .= '

Due date: ' . strftime($localeDateFormat, strtotime($invoice['due_at'])) . '

'; + $html .= '

Invoice status: ' . ucfirst($invoice['status']) . '

'; + $html .= '
'; - $companyInfo = sprintf("%s: %s\n", __('Name'), $invoice['seller']['company']); - $companyInfo .= sprintf("%s: %s\n", __('Address'), $invoice['seller']['address']); - $companyInfo .= sprintf("%s: %s\n", __('Company VAT'), $invoice['seller']['company_vat']); - $companyInfo .= sprintf("%s: %s\n", __('Company number'), $invoice['seller']['company_number']); - $companyInfo .= sprintf("%s: %s\n", __('Account'), $invoice['seller']['account_number']); - $companyInfo .= sprintf("%s: %s\n", __('Phone'), $invoice['seller']['phone']); - $companyInfo .= sprintf("%s: %s\n", __('Email'), $invoice['seller']['email']); + $html .= '

Company

'; + $html .= '
'; + $html .= '

Name: ' . $invoice['seller']['company'] . '

'; + $html .= '

Address: ' . $invoice['seller']['address'] . '

'; + $html .= '

Company VAT: ' . $invoice['seller']['company_vat'] . '

'; + $html .= '

Company number: ' . $invoice['seller']['company_number'] . '

'; + $html .= '

Account: ' . $invoice['seller']['account_number'] . '

'; + $html .= '

Phone: ' . $invoice['seller']['phone'] . '

'; + $html .= '

Email: ' . $invoice['seller']['email'] . '

'; + $html .= '
'; - $buyerInfo = sprintf("%s: %s %s\n", __('Name'), $invoice['buyer']['first_name'], $invoice['buyer']['last_name']); - $buyerInfo .= sprintf("%s: %s\n", __('Company'), $invoice['buyer']['company']); - $buyerInfo .= sprintf("%s: %s\n", __('Address'), $invoice['buyer']['address']); - $buyerInfo .= sprintf("%s: %s\n", __('Company VAT'), $invoice['seller']['company_vat']); - $buyerInfo .= sprintf("%s: %s\n", __('Company number'), $invoice['seller']['company_number']); - $buyerInfo .= sprintf("%s: %s\n", __('Phone'), $invoice['buyer']['phone']); + $html .= '

Client

'; + $html .= '
'; + $html .= '

Name: ' . $invoice['buyer']['first_name'] . $invoice['buyer']['last_name'] . '

'; + $html .= '

Company: ' . $invoice['buyer']['company'] . '

'; + $html .= '

Address: ' . $invoice['buyer']['address'] . '

'; + $html .= '

Phone: ' . $invoice['buyer']['phone'] . '

'; + $html .= '
'; - $pdf->loadHtml('

Test PDF!

'); - $pdf->loadHtml("

$buyerInfo

"); + $html .= ' + '; + + $pdf->setOptions($options); + $pdf->loadHtml($html); $pdf->render(); - $pdf->stream(); + $pdf->stream($invoice['serie_nr'], array("Attachment" => false)); + exit(0); } private function money($price, $currencyCode)