2020-04-16 10:41:25 +02:00
< ? php
2020-09-11 10:07:59 +02:00
2020-04-16 10:41:25 +02:00
/**
2020-09-06 11:38:10 +02:00
* Invoice Ninja ( https :// invoiceninja . com ) .
2020-04-16 10:41:25 +02:00
*
* @ link https :// github . com / invoiceninja / invoiceninja source repository
*
* @ copyright Copyright ( c ) 2020. Invoice Ninja LLC ( https :// invoiceninja . com )
*
* @ license https :// opensource . org / licenses / AAL
*/
namespace App\Utils ;
use App\Designs\Designer ;
use App\Models\Country ;
use App\Utils\Number ;
use Illuminate\Support\Facades\App ;
class HtmlEngine
{
public $entity ;
public $invitation ;
public $client ;
public $contact ;
public $company ;
public $settings ;
public $entity_calc ;
public $entity_string ;
2020-08-06 05:04:09 +02:00
public $designer ;
2020-09-06 11:38:10 +02:00
2020-08-06 05:04:09 +02:00
public function __construct ( $designer , $invitation , $entity_string )
2020-04-16 10:41:25 +02:00
{
2020-08-06 05:04:09 +02:00
$this -> designer = $designer ;
2020-04-16 10:41:25 +02:00
$this -> invitation = $invitation ;
$this -> entity = $invitation -> { $entity_string };
$this -> company = $invitation -> company ;
$this -> contact = $invitation -> contact ;
$this -> client = $this -> entity -> client ;
$this -> settings = $this -> client -> getMergedSettings ();
$this -> entity_calc = $this -> entity -> calc ();
$this -> entity_string = $entity_string ;
}
public function build () : string
2020-09-06 11:38:10 +02:00
{
2020-04-16 10:41:25 +02:00
App :: setLocale ( $this -> client -> preferredLocale ());
$values_and_labels = $this -> generateLabelsAndValues ();
2020-09-06 11:38:10 +02:00
2020-04-16 10:41:25 +02:00
$this -> designer -> build ();
$data = [];
$data [ 'entity' ] = $this -> entity ;
$data [ 'lang' ] = $this -> client -> preferredLocale ();
$data [ 'includes' ] = $this -> designer -> getIncludes ();
$data [ 'header' ] = $this -> designer -> getHeader ();
$data [ 'body' ] = $this -> designer -> getBody ();
$data [ 'footer' ] = $this -> designer -> getFooter ();
$html = view ( 'pdf.stub' , $data ) -> render ();
2020-09-06 11:38:10 +02:00
2020-04-16 10:41:25 +02:00
$html = $this -> parseLabelsAndValues ( $values_and_labels [ 'labels' ], $values_and_labels [ 'values' ], $html );
2020-09-06 11:38:10 +02:00
return $html ;
2020-04-16 10:41:25 +02:00
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2020-07-29 04:13:12 +02:00
public function buildEntityDataArray () : array
2020-04-16 10:41:25 +02:00
{
2020-09-06 11:38:10 +02:00
if ( ! $this -> client -> currency ()) {
2020-04-16 10:41:25 +02:00
throw new \Exception ( debug_backtrace ()[ 1 ][ 'function' ], 1 );
exit ;
}
$data = [];
2020-09-06 11:38:10 +02:00
$data [ '$global-margin' ] = [ 'value' => 'm-8' , 'label' => '' ];
$data [ '$global-padding' ] = [ 'value' => 'p-8' , 'label' => '' ];
$data [ '$tax' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.tax' )];
$data [ '$app_url' ] = [ 'value' => $this -> generateAppUrl (), 'label' => '' ];
$data [ '$from' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.from' )];
$data [ '$to' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.to' )];
$data [ '$total_tax_labels' ] = [ 'value' => $this -> totalTaxLabels (), 'label' => ctrans ( 'texts.taxes' )];
$data [ '$total_tax_values' ] = [ 'value' => $this -> totalTaxValues (), 'label' => ctrans ( 'texts.taxes' )];
$data [ '$line_tax_labels' ] = [ 'value' => $this -> lineTaxLabels (), 'label' => ctrans ( 'texts.taxes' )];
$data [ '$line_tax_values' ] = [ 'value' => $this -> lineTaxValues (), 'label' => ctrans ( 'texts.taxes' )];
$data [ '$date' ] = [ 'value' => $this -> entity -> date ? : ' ' , 'label' => ctrans ( 'texts.date' )];
2020-04-16 10:41:25 +02:00
//$data['$invoice_date'] = ['value' => $this->date ?: ' ', 'label' => ctrans('texts.invoice_date')];
2020-09-06 11:38:10 +02:00
$data [ '$invoice.date' ] = & $data [ '$date' ];
$data [ '$due_date' ] = [ 'value' => $this -> entity -> due_date ? : ' ' , 'label' => ctrans ( 'texts.' . $this -> entity_string . '_due_date' )];
2020-09-09 14:47:26 +02:00
$data [ '$payment_due' ] = [ 'value' => $this -> entity -> due_date ? : ' ' , 'label' => ctrans ( 'texts.payment_due' )];
2020-09-06 11:38:10 +02:00
$data [ '$invoice.due_date' ] = & $data [ '$due_date' ];
$data [ '$invoice.number' ] = [ 'value' => $this -> entity -> number ? : ' ' , 'label' => ctrans ( 'texts.invoice_number' )];
$data [ '$invoice.po_number' ] = [ 'value' => $this -> entity -> po_number ? : ' ' , 'label' => ctrans ( 'texts.po_number' )];
2020-09-11 10:07:59 +02:00
// $data['$line_taxes'] = ['value' => $this->makeLineTaxes() ?: ' ', 'label' => ctrans('texts.taxes')];
// $data['$invoice.line_taxes'] = &$data['$line_taxes'];
2020-10-09 16:03:27 +02:00
2020-09-11 10:07:59 +02:00
// $data['$total_taxes'] = ['value' => $this->makeTotalTaxes() ?: ' ', 'label' => ctrans('texts.taxes')];
// $data['$invoice.total_taxes'] = &$data['$total_taxes'];
2020-04-16 10:41:25 +02:00
if ( $this -> entity_string == 'invoice' ) {
2020-09-06 11:38:10 +02:00
$data [ '$entity' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.invoice' )];
$data [ '$number' ] = [ 'value' => $this -> entity -> number ? : ' ' , 'label' => ctrans ( 'texts.invoice_number' )];
$data [ '$entity.terms' ] = [ 'value' => $this -> entity -> terms ? : ' ' , 'label' => ctrans ( 'texts.invoice_terms' )];
$data [ '$terms' ] = & $data [ '$entity.terms' ];
$data [ '$view_link' ] = [ 'value' => '<a href="' . $this -> invitation -> getLink () . '">' . ctrans ( 'texts.view_invoice' ) . '</a>' , 'label' => ctrans ( 'texts.view_invoice' )];
2020-10-09 13:13:33 +02:00
$data [ '$view_url' ] = [ 'value' => $this -> invitation -> getLink (), 'label' => ctrans ( 'texts.view_invoice' )];
2020-09-06 11:38:10 +02:00
}
2020-04-16 10:41:25 +02:00
if ( $this -> entity_string == 'quote' ) {
2020-09-06 11:38:10 +02:00
$data [ '$entity' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.quote' )];
$data [ '$number' ] = [ 'value' => $this -> entity -> number ? : ' ' , 'label' => ctrans ( 'texts.quote_number' )];
$data [ '$entity.terms' ] = [ 'value' => $this -> entity -> terms ? : ' ' , 'label' => ctrans ( 'texts.quote_terms' )];
$data [ '$terms' ] = & $data [ '$entity.terms' ];
$data [ '$view_link' ] = [ 'value' => '<a href="' . $this -> invitation -> getLink () . '">' . ctrans ( 'texts.view_quote' ) . '</a>' , 'label' => ctrans ( 'texts.view_quote' )];
2020-08-22 00:16:40 +02:00
// $data['$view_link'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_quote')];
2020-09-06 11:38:10 +02:00
}
2020-04-16 10:41:25 +02:00
if ( $this -> entity_string == 'credit' ) {
2020-09-06 11:38:10 +02:00
$data [ '$entity' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.credit' )];
$data [ '$number' ] = [ 'value' => $this -> entity -> number ? : ' ' , 'label' => ctrans ( 'texts.credit_number' )];
$data [ '$entity.terms' ] = [ 'value' => $this -> entity -> terms ? : ' ' , 'label' => ctrans ( 'texts.credit_terms' )];
$data [ '$terms' ] = & $data [ '$entity.terms' ];
$data [ '$view_link' ] = [ 'value' => '<a href="' . $this -> invitation -> getLink () . '">' . ctrans ( 'texts.view_credit' ) . '</a>' , 'label' => ctrans ( 'texts.view_credit' )];
2020-08-22 00:16:40 +02:00
// $data['$view_link'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_credit')];
2020-09-06 11:38:10 +02:00
}
2020-04-16 10:41:25 +02:00
2020-09-06 11:38:10 +02:00
$data [ '$entity_number' ] = & $data [ '$number' ];
$data [ '$invoice.discount' ] = [ 'value' => Number :: formatMoney ( $this -> entity_calc -> getTotalDiscount (), $this -> client ) ? : ' ' , 'label' => ctrans ( 'texts.discount' )];
$data [ '$discount' ] = & $data [ '$invoice.discount' ];
$data [ '$subtotal' ] = [ 'value' => Number :: formatMoney ( $this -> entity_calc -> getSubTotal (), $this -> client ) ? : ' ' , 'label' => ctrans ( 'texts.subtotal' )];
$data [ '$invoice.subtotal' ] = & $data [ '$subtotal' ];
$data [ '$balance_due' ] = [ 'value' => Number :: formatMoney ( $this -> entity -> balance , $this -> client ) ? : ' ' , 'label' => ctrans ( 'texts.balance_due' )];
$data [ '$quote.balance_due' ] = & $data [ '$balance_due' ];
$data [ '$invoice.balance_due' ] = & $data [ '$balance_due' ];
$data [ '$balance_due' ] = & $data [ '$balance_due' ];
$data [ '$outstanding' ] = & $data [ '$balance_due' ];
$data [ '$partial_due' ] = [ 'value' => Number :: formatMoney ( $this -> entity -> partial , $this -> client ) ? : ' ' , 'label' => ctrans ( 'texts.partial_due' )];
$data [ '$total' ] = [ 'value' => Number :: formatMoney ( $this -> entity_calc -> getTotal (), $this -> client ) ? : ' ' , 'label' => ctrans ( 'texts.total' )];
$data [ '$amount' ] = & $data [ '$total' ];
2020-09-09 14:47:26 +02:00
$data [ '$amount_due' ] = [ 'value' => & $data [ '$total' ][ 'value' ], 'label' => ctrans ( 'texts.amount_due' )];
2020-09-06 11:38:10 +02:00
$data [ '$quote.total' ] = & $data [ '$total' ];
$data [ '$invoice.total' ] = [ 'value' => Number :: formatMoney ( $this -> entity_calc -> getTotal (), $this -> client ) ? : ' ' , 'label' => ctrans ( 'texts.invoice_total' )];
$data [ '$invoice.amount' ] = & $data [ '$total' ];
$data [ '$quote.amount' ] = [ 'value' => Number :: formatMoney ( $this -> entity_calc -> getTotal (), $this -> client ) ? : ' ' , 'label' => ctrans ( 'texts.quote_total' )];
$data [ '$credit.total' ] = [ 'value' => Number :: formatMoney ( $this -> entity_calc -> getTotal (), $this -> client ) ? : ' ' , 'label' => ctrans ( 'texts.credit_total' )];
$data [ '$credit.number' ] = [ 'value' => $this -> entity -> number ? : ' ' , 'label' => ctrans ( 'texts.credit_number' )];
2020-09-30 00:42:55 +02:00
$data [ '$credit.total' ] = & $data [ '$credit.total' ];
2020-09-06 11:38:10 +02:00
$data [ '$credit.po_number' ] = & $data [ '$invoice.po_number' ];
$data [ '$credit.date' ] = [ 'value' => $this -> entity -> date , 'label' => ctrans ( 'texts.credit_date' )];
$data [ '$balance' ] = [ 'value' => Number :: formatMoney ( $this -> entity_calc -> getBalance (), $this -> client ) ? : ' ' , 'label' => ctrans ( 'texts.balance' )];
$data [ '$credit.balance' ] = & $data [ '$balance' ];
$data [ '$invoice.balance' ] = & $data [ '$balance' ];
$data [ '$taxes' ] = [ 'value' => Number :: formatMoney ( $this -> entity_calc -> getItemTotalTaxes (), $this -> client ) ? : ' ' , 'label' => ctrans ( 'texts.taxes' )];
$data [ '$invoice.taxes' ] = & $data [ '$taxes' ];
$data [ '$invoice.custom1' ] = [ 'value' => $this -> entity -> custom_value1 ? : ' ' , 'label' => $this -> makeCustomField ( 'invoice1' )];
$data [ '$invoice.custom2' ] = [ 'value' => $this -> entity -> custom_value2 ? : ' ' , 'label' => $this -> makeCustomField ( 'invoice2' )];
$data [ '$invoice.custom3' ] = [ 'value' => $this -> entity -> custom_value3 ? : ' ' , 'label' => $this -> makeCustomField ( 'invoice3' )];
$data [ '$invoice.custom4' ] = [ 'value' => $this -> entity -> custom_value4 ? : ' ' , 'label' => $this -> makeCustomField ( 'invoice4' )];
$data [ '$invoice.public_notes' ] = [ 'value' => $this -> entity -> public_notes ? : ' ' , 'label' => ctrans ( 'texts.public_notes' )];
$data [ '$entity.public_notes' ] = & $data [ '$invoice.public_notes' ];
$data [ '$entity_issued_to' ] = [ 'value' => '' , 'label' => ctrans ( " texts. { $this -> entity_string } _issued_to " )];
$data [ '$your_entity' ] = [ 'value' => '' , 'label' => ctrans ( " texts.your_ { $this -> entity_string } " )];
$data [ '$quote.date' ] = [ 'value' => $this -> entity -> date ? : ' ' , 'label' => ctrans ( 'texts.quote_date' )];
$data [ '$quote.number' ] = [ 'value' => $this -> entity -> number ? : ' ' , 'label' => ctrans ( 'texts.quote_number' )];
$data [ '$quote.po_number' ] = & $data [ '$invoice.po_number' ];
$data [ '$quote.quote_number' ] = & $data [ '$quote.number' ];
$data [ '$quote_no' ] = & $data [ '$quote.number' ];
$data [ '$quote.quote_no' ] = & $data [ '$quote.number' ];
$data [ '$quote.valid_until' ] = [ 'value' => $this -> entity -> due_date , 'label' => ctrans ( 'texts.valid_until' )];
$data [ '$credit_amount' ] = [ 'value' => Number :: formatMoney ( $this -> entity_calc -> getTotal (), $this -> client ) ? : ' ' , 'label' => ctrans ( 'texts.credit_amount' )];
$data [ '$credit_balance' ] = [ 'value' => Number :: formatMoney ( $this -> entity -> balance , $this -> client ) ? : ' ' , 'label' => ctrans ( 'texts.credit_balance' )];
$data [ '$credit_number' ] = & $data [ '$number' ];
$data [ '$credit_no' ] = & $data [ '$number' ];
$data [ '$credit.credit_no' ] = & $data [ '$number' ];
2020-04-16 10:41:25 +02:00
// $data['$invoice_issued_to'] = ;
// $data['$quote_issued_to'] = ;
// $data['$rate'] = ;
// $data['$hours'] = ;
// $data['$from'] = ;
// $data['$to'] = ;
// $data['$invoice_to'] = ;
// $data['$quote_to'] = ;
// $data['$details'] = ;
2020-09-06 11:38:10 +02:00
$data [ '$invoice_no' ] = & $data [ '$number' ];
$data [ '$invoice.invoice_no' ] = & $data [ '$number' ];
$data [ '$client1' ] = [ 'value' => $this -> client -> custom_value1 ? : ' ' , 'label' => $this -> makeCustomField ( 'client1' )];
$data [ '$client2' ] = [ 'value' => $this -> client -> custom_value2 ? : ' ' , 'label' => $this -> makeCustomField ( 'client2' )];
$data [ '$client3' ] = [ 'value' => $this -> client -> custom_value3 ? : ' ' , 'label' => $this -> makeCustomField ( 'client3' )];
$data [ '$client4' ] = [ 'value' => $this -> client -> custom_value4 ? : ' ' , 'label' => $this -> makeCustomField ( 'client4' )];
$data [ '$address1' ] = [ 'value' => $this -> client -> address1 ? : ' ' , 'label' => ctrans ( 'texts.address1' )];
$data [ '$address2' ] = [ 'value' => $this -> client -> address2 ? : ' ' , 'label' => ctrans ( 'texts.address2' )];
$data [ '$id_number' ] = [ 'value' => $this -> client -> id_number ? : ' ' , 'label' => ctrans ( 'texts.id_number' )];
$data [ '$vat_number' ] = [ 'value' => $this -> client -> vat_number ? : ' ' , 'label' => ctrans ( 'texts.vat_number' )];
$data [ '$website' ] = [ 'value' => $this -> client -> present () -> website () ? : ' ' , 'label' => ctrans ( 'texts.website' )];
$data [ '$phone' ] = [ 'value' => $this -> client -> present () -> phone () ? : ' ' , 'label' => ctrans ( 'texts.phone' )];
2020-10-09 16:03:27 +02:00
$data [ '$country' ] = [ 'value' => isset ( $this -> client -> country -> name ) ? $this -> client -> country -> name : '' , 'label' => ctrans ( 'texts.country' )];
2020-09-06 11:38:10 +02:00
$data [ '$email' ] = [ 'value' => isset ( $this -> contact ) ? $this -> contact -> email : 'no contact email on record' , 'label' => ctrans ( 'texts.email' )];
$data [ '$client_name' ] = [ 'value' => $this -> entity -> present () -> clientName () ? : ' ' , 'label' => ctrans ( 'texts.client_name' )];
$data [ '$client.name' ] = & $data [ '$client_name' ];
$data [ '$client.address1' ] = & $data [ '$address1' ];
$data [ '$client.address2' ] = & $data [ '$address2' ];
$data [ '$client_address' ] = [ 'value' => $this -> entity -> present () -> address () ? : ' ' , 'label' => ctrans ( 'texts.address' )];
$data [ '$client.address' ] = & $data [ '$client_address' ];
$data [ '$client.id_number' ] = & $data [ '$id_number' ];
$data [ '$client.vat_number' ] = & $data [ '$vat_number' ];
$data [ '$client.website' ] = & $data [ '$website' ];
$data [ '$client.phone' ] = & $data [ '$phone' ];
$data [ '$city_state_postal' ] = [ 'value' => $this -> entity -> present () -> cityStateZip ( $this -> client -> city , $this -> client -> state , $this -> client -> postal_code , false ) ? : ' ' , 'label' => ctrans ( 'texts.city_state_postal' )];
$data [ '$client.city_state_postal' ] = & $data [ '$city_state_postal' ];
$data [ '$postal_city_state' ] = [ 'value' => $this -> entity -> present () -> cityStateZip ( $this -> client -> city , $this -> client -> state , $this -> client -> postal_code , true ) ? : ' ' , 'label' => ctrans ( 'texts.postal_city_state' )];
$data [ '$client.postal_city_state' ] = & $data [ '$postal_city_state' ];
$data [ '$client.country' ] = & $data [ '$country' ];
$data [ '$client.email' ] = & $data [ '$email' ];
2020-09-11 00:30:12 +02:00
$data [ '$client.balance' ] = [ 'value' => Number :: formatMoney ( $this -> client -> balance , $this -> client ), 'label' => ctrans ( 'texts.account_balance' )];
2020-09-27 12:39:13 +02:00
$data [ '$outstanding' ] = [ 'value' => Number :: formatMoney ( $this -> client -> balance , $this -> client ), 'label' => ctrans ( 'texts.account_balance' )];
2020-09-17 00:22:23 +02:00
$data [ '$client_balance' ] = [ 'value' => Number :: formatMoney ( $this -> client -> balance , $this -> client ), 'label' => ctrans ( 'texts.account_balance' )];
2020-09-11 00:30:12 +02:00
$data [ '$paid_to_date' ] = [ 'value' => Number :: formatMoney ( $this -> client -> paid_to_date , $this -> client ), 'label' => ctrans ( 'texts.paid_to_date' )];
2020-09-08 06:06:46 +02:00
2020-09-06 11:38:10 +02:00
$data [ '$contact.full_name' ] = [ 'value' => $this -> contact -> present () -> name (), 'label' => ctrans ( 'texts.name' )];
$data [ '$contact.email' ] = [ 'value' => $this -> contact -> email , 'label' => ctrans ( 'texts.email' )];
$data [ '$contact.phone' ] = [ 'value' => $this -> contact -> phone , 'label' => ctrans ( 'texts.phone' )];
$data [ '$contact.name' ] = [ 'value' => isset ( $this -> contact ) ? $this -> contact -> present () -> name () : 'no contact name on record' , 'label' => ctrans ( 'texts.contact_name' )];
$data [ '$contact.first_name' ] = [ 'value' => isset ( $contact ) ? $contact -> first_name : '' , 'label' => ctrans ( 'texts.first_name' )];
$data [ '$contact.last_name' ] = [ 'value' => isset ( $contact ) ? $contact -> last_name : '' , 'label' => ctrans ( 'texts.last_name' )];
$data [ '$contact.custom1' ] = [ 'value' => isset ( $this -> contact ) ? $this -> contact -> custom_value1 : ' ' , 'label' => $this -> makeCustomField ( 'contact1' )];
$data [ '$contact.custom2' ] = [ 'value' => isset ( $this -> contact ) ? $this -> contact -> custom_value2 : ' ' , 'label' => $this -> makeCustomField ( 'contact1' )];
$data [ '$contact.custom3' ] = [ 'value' => isset ( $this -> contact ) ? $this -> contact -> custom_value3 : ' ' , 'label' => $this -> makeCustomField ( 'contact1' )];
$data [ '$contact.custom4' ] = [ 'value' => isset ( $this -> contact ) ? $this -> contact -> custom_value4 : ' ' , 'label' => $this -> makeCustomField ( 'contact1' )];
2020-04-16 10:41:25 +02:00
$data [ '$company.city_state_postal' ] = [ 'value' => $this -> company -> present () -> cityStateZip ( $this -> settings -> city , $this -> settings -> state , $this -> settings -> postal_code , false ) ? : ' ' , 'label' => ctrans ( 'texts.city_state_postal' )];
$data [ '$company.postal_city_state' ] = [ 'value' => $this -> company -> present () -> cityStateZip ( $this -> settings -> city , $this -> settings -> state , $this -> settings -> postal_code , true ) ? : ' ' , 'label' => ctrans ( 'texts.postal_city_state' )];
2020-09-06 11:38:10 +02:00
$data [ '$company.name' ] = [ 'value' => $this -> company -> present () -> name () ? : ' ' , 'label' => ctrans ( 'texts.company_name' )];
$data [ '$company.address1' ] = [ 'value' => $this -> settings -> address1 ? : ' ' , 'label' => ctrans ( 'texts.address1' )];
$data [ '$company.address2' ] = [ 'value' => $this -> settings -> address2 ? : ' ' , 'label' => ctrans ( 'texts.address2' )];
$data [ '$company.city' ] = [ 'value' => $this -> settings -> city ? : ' ' , 'label' => ctrans ( 'texts.city' )];
$data [ '$company.state' ] = [ 'value' => $this -> settings -> state ? : ' ' , 'label' => ctrans ( 'texts.state' )];
$data [ '$company.postal_code' ] = [ 'value' => $this -> settings -> postal_code ? : ' ' , 'label' => ctrans ( 'texts.postal_code' )];
$data [ '$company.country' ] = [ 'value' => $this -> getCountryName (), 'label' => ctrans ( 'texts.country' )];
$data [ '$company.phone' ] = [ 'value' => $this -> settings -> phone ? : ' ' , 'label' => ctrans ( 'texts.phone' )];
$data [ '$company.email' ] = [ 'value' => $this -> settings -> email ? : ' ' , 'label' => ctrans ( 'texts.email' )];
$data [ '$company.vat_number' ] = [ 'value' => $this -> settings -> vat_number ? : ' ' , 'label' => ctrans ( 'texts.vat_number' )];
$data [ '$company.id_number' ] = [ 'value' => $this -> settings -> id_number ? : ' ' , 'label' => ctrans ( 'texts.id_number' )];
$data [ '$company.website' ] = [ 'value' => $this -> settings -> website ? : ' ' , 'label' => ctrans ( 'texts.website' )];
$data [ '$company.address' ] = [ 'value' => $this -> company -> present () -> address ( $this -> settings ) ? : ' ' , 'label' => ctrans ( 'texts.address' )];
2020-04-16 10:41:25 +02:00
$logo = $this -> company -> present () -> logo ( $this -> settings );
2020-09-06 11:38:10 +02:00
$data [ '$company.logo' ] = [ 'value' => $logo ? : ' ' , 'label' => ctrans ( 'texts.logo' )];
$data [ '$company_logo' ] = & $data [ '$company.logo' ];
$data [ '$company1' ] = [ 'value' => $this -> settings -> custom_value1 ? : ' ' , 'label' => $this -> makeCustomField ( 'company1' )];
$data [ '$company2' ] = [ 'value' => $this -> settings -> custom_value2 ? : ' ' , 'label' => $this -> makeCustomField ( 'company2' )];
$data [ '$company3' ] = [ 'value' => $this -> settings -> custom_value3 ? : ' ' , 'label' => $this -> makeCustomField ( 'company3' )];
$data [ '$company4' ] = [ 'value' => $this -> settings -> custom_value4 ? : ' ' , 'label' => $this -> makeCustomField ( 'company4' )];
2020-09-09 14:47:26 +02:00
$data [ '$custom_surcharge1' ] = [ 'value' => $this -> entity -> custom_surcharge1 ? : ' ' , 'label' => $this -> makeCustomField ( 'custom_surcharge1' )];
$data [ '$custom_surcharge2' ] = [ 'value' => $this -> entity -> custom_surcharge2 ? : ' ' , 'label' => $this -> makeCustomField ( 'custom_surcharge2' )];
$data [ '$custom_surcharge3' ] = [ 'value' => $this -> entity -> custom_surcharge3 ? : ' ' , 'label' => $this -> makeCustomField ( 'custom_surcharge3' )];
$data [ '$custom_surcharge4' ] = [ 'value' => $this -> entity -> custom_surcharge4 ? : ' ' , 'label' => $this -> makeCustomField ( 'custom_surcharge4' )];
2020-09-08 06:02:00 +02:00
2020-09-06 11:38:10 +02:00
$data [ '$product.date' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.date' )];
$data [ '$product.discount' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.discount' )];
$data [ '$product.product_key' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.product_key' )];
$data [ '$product.notes' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.notes' )];
$data [ '$product.cost' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.cost' )];
$data [ '$product.quantity' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.quantity' )];
$data [ '$product.tax_name1' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.tax' )];
$data [ '$product.tax' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.tax' )];
$data [ '$product.tax_name2' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.tax' )];
$data [ '$product.tax_name3' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.tax' )];
$data [ '$product.line_total' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.line_total' )];
$data [ '$task.date' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.date' )];
$data [ '$task.discount' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.discount' )];
$data [ '$task.product_key' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.product_key' )];
$data [ '$task.notes' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.notes' )];
$data [ '$task.cost' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.cost' )];
$data [ '$task.quantity' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.quantity' )];
$data [ '$task.tax' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.tax' )];
$data [ '$task.tax_name1' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.tax' )];
$data [ '$task.tax_name2' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.tax' )];
$data [ '$task.tax_name3' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.tax' )];
$data [ '$task.line_total' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.line_total' )];
$data [ '$contact.signature' ] = [ 'value' => $this -> invitation -> signature_base64 , 'label' => ctrans ( 'texts.signature' )];
$data [ '$thanks' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.thanks' )];
$data [ '$from' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.from' )];
$data [ '$to' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.to' )];
2020-09-16 12:16:56 +02:00
$data [ '$details' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.details' )];
2020-09-06 11:38:10 +02:00
$data [ '_rate1' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.tax' )];
$data [ '_rate2' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.tax' )];
$data [ '_rate3' ] = [ 'value' => '' , 'label' => ctrans ( 'texts.tax' )];
2020-08-13 13:46:53 +02:00
2020-10-01 13:37:34 +02:00
$data [ '$font_size' ] = [ 'value' => $this -> settings -> font_size . 'px' , 'label' => '' ];
2020-09-09 17:14:55 +02:00
2020-09-17 14:28:55 +02:00
$data [ '$invoiceninja.whitelabel' ] = [ 'value' => asset ( 'images/created-by-invoiceninja-new.png' ), 'label' => '' ];
2020-10-01 13:20:32 +02:00
$data [ '$primary_color' ] = [ 'value' => $this -> settings -> primary_color , 'label' => '' ];
$data [ '$secondary_color' ] = [ 'value' => $this -> settings -> secondary_color , 'label' => '' ];
2020-04-16 10:41:25 +02:00
// $data['custom_label1'] = ['value' => '', 'label' => ctrans('texts.')];
// $data['custom_label2'] = ['value' => '', 'label' => ctrans('texts.')];
// $data['custom_label3'] = ['value' => '', 'label' => ctrans('texts.')];
// $data['custom_label4'] = ['value' => '', 'label' => ctrans('texts.')];
//$data['$blank'] = ;
//$data['$surcharge'] = ;
/*
$data [ '$tax_invoice' ] =
$data [ '$tax_quote' ] =
$data [ '$statement' ] = ;
$data [ '$statement_date' ] = ;
$data [ '$your_statement' ] = ;
$data [ '$statement_issued_to' ] = ;
$data [ '$statement_to' ] = ;
$data [ '$credit_note' ] = ;
$data [ '$credit_date' ] = ;
$data [ '$credit_issued_to' ] = ;
$data [ '$credit_to' ] = ;
$data [ '$your_credit' ] = ;
$data [ '$phone' ] = ;
$data [ '$outstanding' ] = ;
$data [ '$invoice_due_date' ] = ;
$data [ '$quote_due_date' ] = ;
$data [ '$service' ] = ;
$data [ '$product_key' ] = ;
$data [ '$unit_cost' ] = ;
$data [ '$custom_value1' ] = ;
$data [ '$custom_value2' ] = ;
$data [ '$delivery_note' ] = ;
$data [ '$date' ] = ;
$data [ '$method' ] = ;
$data [ '$payment_date' ] = ;
$data [ '$reference' ] = ;
$data [ '$amount' ] = ;
$data [ '$amount_paid' ] = ;
*/
$arrKeysLength = array_map ( 'strlen' , array_keys ( $data ));
array_multisort ( $arrKeysLength , SORT_DESC , $data );
return $data ;
}
2020-09-06 11:38:10 +02:00
public function generateLabelsAndValues ()
2020-04-16 10:41:25 +02:00
{
$data = [];
$values = $this -> buildEntityDataArray ();
2020-09-06 11:38:10 +02:00
2020-04-16 10:41:25 +02:00
foreach ( $values as $key => $value ) {
$data [ 'values' ][ $key ] = $value [ 'value' ];
$data [ 'labels' ][ $key . '_label' ] = $value [ 'label' ];
}
return $data ;
}
private function totalTaxLabels () : string
{
$data = '' ;
2020-09-06 11:38:10 +02:00
if ( ! $this -> entity_calc -> getTotalTaxMap ()) {
2020-04-16 10:41:25 +02:00
return $data ;
}
foreach ( $this -> entity_calc -> getTotalTaxMap () as $tax ) {
2020-09-06 11:38:10 +02:00
$data .= '<span>' . $tax [ 'name' ] . '</span>' ;
2020-04-16 10:41:25 +02:00
}
return $data ;
}
private function totalTaxValues () : string
{
$data = '' ;
2020-09-06 11:38:10 +02:00
if ( ! $this -> entity_calc -> getTotalTaxMap ()) {
2020-04-16 10:41:25 +02:00
return $data ;
}
foreach ( $this -> entity_calc -> getTotalTaxMap () as $tax ) {
2020-09-06 11:38:10 +02:00
$data .= '<span>' . Number :: formatMoney ( $tax [ 'total' ], $this -> client ) . '</span>' ;
2020-04-16 10:41:25 +02:00
}
return $data ;
}
private function lineTaxLabels () : string
{
$tax_map = $this -> entity_calc -> getTaxMap ();
2020-09-06 11:38:10 +02:00
2020-04-16 10:41:25 +02:00
$data = '' ;
foreach ( $tax_map as $tax ) {
2020-09-06 11:38:10 +02:00
$data .= '<span>' . $tax [ 'name' ] . '</span>' ;
2020-04-16 10:41:25 +02:00
}
2020-09-06 11:38:10 +02:00
2020-04-16 10:41:25 +02:00
return $data ;
}
private function getCountryName () : string
{
$country = Country :: find ( $this -> settings -> country_id ) -> first ();
2020-09-06 11:38:10 +02:00
if ( $country ) {
2020-04-16 10:41:25 +02:00
return $country -> name ;
2020-09-06 11:38:10 +02:00
}
2020-04-16 10:41:25 +02:00
return ' ' ;
}
2020-09-06 11:38:10 +02:00
2020-04-16 10:41:25 +02:00
/**
* Due to the way we are compiling the blade template we
* have no ability to iterate , so in the case
* of line taxes where there are multiple rows ,
2020-09-06 11:38:10 +02:00
* we use this function to format a section of rows .
2020-04-16 10:41:25 +02:00
*
* @ return string a collection of < tr > rows with line item
* aggregate data
*/
private function makeLineTaxes () : string
{
$tax_map = $this -> entity_calc -> getTaxMap ();
2020-09-06 11:38:10 +02:00
2020-04-16 10:41:25 +02:00
$data = '' ;
foreach ( $tax_map as $tax ) {
$data .= '<tr class="line_taxes">' ;
2020-09-06 11:38:10 +02:00
$data .= '<td>' . $tax [ 'name' ] . '</td>' ;
$data .= '<td>' . Number :: formatMoney ( $tax [ 'total' ], $this -> client ) . '</td></tr>' ;
2020-04-16 10:41:25 +02:00
}
return $data ;
}
private function lineTaxValues () : string
{
$tax_map = $this -> entity_calc -> getTaxMap ();
2020-09-06 11:38:10 +02:00
2020-04-16 10:41:25 +02:00
$data = '' ;
foreach ( $tax_map as $tax ) {
2020-09-06 11:38:10 +02:00
$data .= '<span>' . Number :: formatMoney ( $tax [ 'total' ], $this -> client ) . '</span>' ;
2020-04-16 10:41:25 +02:00
}
2020-09-06 11:38:10 +02:00
2020-04-16 10:41:25 +02:00
return $data ;
}
private function makeCustomField ( $field ) : string
{
$custom_fields = $this -> company -> custom_fields ;
if ( $custom_fields && property_exists ( $custom_fields , $field )) {
$custom_field = $custom_fields -> { $field };
2020-09-06 11:38:10 +02:00
$custom_field_parts = explode ( '|' , $custom_field );
2020-04-16 10:41:25 +02:00
return $custom_field_parts [ 0 ];
}
return '' ;
}
private function makeTotalTaxes () : string
{
$data = '' ;
2020-09-06 11:38:10 +02:00
if ( ! $this -> entity_calc -> getTotalTaxMap ()) {
2020-04-16 10:41:25 +02:00
return $data ;
}
foreach ( $this -> entity_calc -> getTotalTaxMap () as $tax ) {
2020-09-04 13:17:30 +02:00
$data .= '<tr>' ;
$data .= '<td colspan="{ count($this->entity->company->settings->pdf_variables->total_columns) - 2 }"></td>' ;
2020-09-06 11:38:10 +02:00
$data .= '<td>' . $tax [ 'name' ] . '</td>' ;
$data .= '<td>' . Number :: formatMoney ( $tax [ 'total' ], $this -> client ) . '</td></tr>' ;
2020-04-16 10:41:25 +02:00
}
return $data ;
}
private function parseLabelsAndValues ( $labels , $values , $section ) : string
{
$section = strtr ( $section , $labels );
2020-09-06 11:38:10 +02:00
return strtr ( $section , $values );
2020-04-16 10:41:25 +02:00
}
/*
| Ensures the URL doesn ' t have duplicated trailing slash
*/
public function generateAppUrl ()
{
2020-07-14 11:55:28 +02:00
//return rtrim(config('ninja.app_url'), "/");
return config ( 'ninja.app_url' );
2020-04-16 10:41:25 +02:00
}
/**
* Builds CSS to assist with the generation
2020-09-06 11:38:10 +02:00
* of Repeating headers and footers on the PDF .
2020-04-16 10:41:25 +02:00
* @ return string The css string
*/
private function generateCustomCSS () : string
{
$header_and_footer = '
. header , . header - space {
height : 160 px ;
}
. footer , . footer - space {
height : 160 px ;
}
. footer {
position : fixed ;
bottom : 0 ;
width : 100 % ;
}
. header {
position : fixed ;
top : 0 mm ;
width : 100 % ;
}
@ media print {
2020-10-09 16:03:27 +02:00
thead { display : table - header - group ;}
2020-04-16 10:41:25 +02:00
tfoot { display : table - footer - group ;}
button { display : none ;}
body { margin : 0 ;}
} ' ;
$header = '
. header , . header - space {
height : 160 px ;
}
. header {
position : fixed ;
top : 0 mm ;
width : 100 % ;
}
@ media print {
2020-10-09 16:03:27 +02:00
thead { display : table - header - group ;}
2020-04-16 10:41:25 +02:00
button { display : none ;}
body { margin : 0 ;}
} ' ;
$footer = '
. footer , . footer - space {
height : 160 px ;
}
. footer {
position : fixed ;
bottom : 0 ;
width : 100 % ;
}
@ media print {
tfoot { display : table - footer - group ;}
button { display : none ;}
body { margin : 0 ;}
} ' ;
$css = '' ;
if ( $this -> settings -> all_pages_header && $this -> settings -> all_pages_footer ) {
$css .= $header_and_footer ;
2020-09-06 11:38:10 +02:00
} elseif ( $this -> settings -> all_pages_header && ! $this -> settings -> all_pages_footer ) {
2020-04-16 10:41:25 +02:00
$css .= $header ;
2020-09-06 11:38:10 +02:00
} elseif ( ! $this -> settings -> all_pages_header && $this -> settings -> all_pages_footer ) {
2020-04-16 10:41:25 +02:00
$css .= $footer ;
}
$css .= '
. page {
page - break - after : always ;
}
@ page {
margin : 0 mm
}
html {
' ;
2020-09-06 11:38:10 +02:00
$css .= 'font-size:' . $this -> settings -> font_size . 'px;' ;
2020-04-16 10:41:25 +02:00
// $css .= 'font-size:14px;';
$css .= '}' ;
return $css ;
}
2020-09-06 11:38:10 +02:00
}