2019-09-02 07:08:26 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-09-02 07:08:26 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-09-02 07:08:26 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Utils\Traits;
|
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
use App\Models\Country;
|
2020-02-26 05:11:17 +01:00
|
|
|
use App\Models\Credit;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Quote;
|
2019-09-02 07:08:26 +02:00
|
|
|
use App\Utils\Number;
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class MakesInvoiceValues.
|
2019-09-02 07:08:26 +02:00
|
|
|
*/
|
|
|
|
trait MakesInvoiceValues
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
/**
|
|
|
|
* Master list of columns used
|
2020-09-06 11:38:10 +02:00
|
|
|
* for invoice tables.
|
2019-12-30 22:59:12 +01:00
|
|
|
* @var array
|
|
|
|
*/
|
2019-09-04 01:16:23 +02:00
|
|
|
private static $master_columns = [
|
|
|
|
'date',
|
|
|
|
'discount',
|
|
|
|
'product_key',
|
|
|
|
'notes',
|
|
|
|
'cost',
|
|
|
|
'quantity',
|
|
|
|
'tax_name1',
|
|
|
|
'tax_name2',
|
2019-10-05 04:28:23 +02:00
|
|
|
'tax_name3',
|
2019-09-04 01:16:23 +02:00
|
|
|
'line_total',
|
|
|
|
'custom_label1',
|
|
|
|
'custom_label2',
|
|
|
|
'custom_label3',
|
|
|
|
'custom_label4',
|
|
|
|
];
|
|
|
|
|
2020-02-10 10:53:02 +01:00
|
|
|
private static $custom_label_fields = [
|
|
|
|
'invoice1',
|
|
|
|
'invoice2',
|
|
|
|
'invoice3',
|
|
|
|
'invoice4',
|
|
|
|
'surcharge1',
|
|
|
|
'surcharge2',
|
|
|
|
'surcharge3',
|
|
|
|
'surcharge4',
|
|
|
|
'client1',
|
|
|
|
'client2',
|
|
|
|
'client3',
|
|
|
|
'client4',
|
|
|
|
'contact1',
|
|
|
|
'contact2',
|
|
|
|
'contact3',
|
|
|
|
'contact4',
|
|
|
|
'company1',
|
|
|
|
'company2',
|
|
|
|
'company3',
|
|
|
|
'company4',
|
2019-09-04 03:45:53 +02:00
|
|
|
];
|
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
public function makeCustomField($field) :string
|
2019-09-03 01:00:52 +02:00
|
|
|
{
|
2020-02-06 10:35:51 +01:00
|
|
|
$custom_fields = $this->company->custom_fields;
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($custom_fields && property_exists($custom_fields, $field)) {
|
2020-03-16 11:12:10 +01:00
|
|
|
$custom_field = $custom_fields->{$field};
|
2020-09-06 11:38:10 +02:00
|
|
|
$custom_field_parts = explode('|', $custom_field);
|
2020-03-16 11:12:10 +01:00
|
|
|
|
|
|
|
return $custom_field_parts[0];
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-09-03 01:00:52 +02:00
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2020-04-11 03:41:43 +02:00
|
|
|
private function findCustomType($field)
|
|
|
|
{
|
|
|
|
$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-11 03:41:43 +02:00
|
|
|
|
|
|
|
return $custom_field_parts[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method produces the key /value pairs for
|
2020-09-06 11:38:10 +02:00
|
|
|
* custom fields.
|
2020-04-11 03:41:43 +02:00
|
|
|
*
|
|
|
|
* We need to explode the field name and search for the |
|
|
|
|
* we split on the pipe, the first value is the field name
|
|
|
|
* and the second is the field _type_
|
|
|
|
*
|
|
|
|
* We transform the $value depending the $field type
|
2020-04-15 02:30:52 +02:00
|
|
|
*
|
2020-04-11 03:41:43 +02:00
|
|
|
* @param string $field The full field name
|
|
|
|
* @param string $value The custom value
|
|
|
|
* @return array The key value pair
|
|
|
|
*/
|
|
|
|
private function makeCustomFieldKeyValuePair($field, $value)
|
|
|
|
{
|
2020-04-15 02:30:52 +02:00
|
|
|
if ($this->findCustomType($field) == 'date') {
|
2020-04-11 03:41:43 +02:00
|
|
|
$value = $this->formatDate($value, $this->client->date_format());
|
2020-04-15 02:30:52 +02:00
|
|
|
} elseif ($this->findCustomType($field) == 'switch') {
|
2020-04-11 03:41:43 +02:00
|
|
|
$value = ctrans('texts.'.$value);
|
2020-04-15 02:30:52 +02:00
|
|
|
}
|
2020-04-11 03:41:43 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $value) {
|
2020-04-11 03:41:43 +02:00
|
|
|
$value = '';
|
2020-04-15 02:30:52 +02:00
|
|
|
}
|
2020-04-11 03:41:43 +02:00
|
|
|
|
|
|
|
return ['value' => $value, 'field' => $this->makeCustomField($field)];
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
public function makeLabels($contact = null) :array
|
|
|
|
{
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
$values = $this->makeLabelsAndValues($contact);
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
foreach ($values as $key => $value) {
|
2020-03-16 11:12:10 +01:00
|
|
|
$data[$key.'_label'] = $value['label'];
|
|
|
|
}
|
2020-02-06 10:35:51 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return $data;
|
|
|
|
}
|
2019-09-03 01:00:52 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
/**
|
|
|
|
* Transforms all placeholders
|
2020-09-06 11:38:10 +02:00
|
|
|
* to invoice values.
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
|
|
|
* @return array returns an array
|
2019-09-04 23:50:16 +02:00
|
|
|
* of keyed labels (appended with _label)
|
2019-09-03 01:00:52 +02:00
|
|
|
*/
|
2019-12-24 22:55:29 +01:00
|
|
|
public function makeValues($contact = null) :array
|
2020-03-16 11:12:10 +01:00
|
|
|
{
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
$values = $this->makeLabelsAndValues($contact);
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
foreach ($values as $key => $value) {
|
2020-03-16 11:12:10 +01:00
|
|
|
$data[$key] = $value['value'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
public function buildLabelsAndValues($contact)
|
2020-04-16 10:41:25 +02:00
|
|
|
{
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
$values = $this->makeLabelsAndValues($contact);
|
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;
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
private function makeLabelsAndValues($contact = null) :array
|
2019-09-02 07:08:26 +02:00
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $this->client->currency() || ! $this->client) {
|
2020-02-17 19:05:11 +01:00
|
|
|
throw new \Exception(debug_backtrace()[1]['function'], 1);
|
2019-10-07 11:39:22 +02:00
|
|
|
exit;
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
$settings = $this->client->getMergedSettings();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $contact) {
|
2020-03-28 04:45:11 +01:00
|
|
|
$contact = $this->client->primary_contact()->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
$calc = $this->calc();
|
2020-07-29 04:13:12 +02:00
|
|
|
$invitation = $this->invitations->where('client_contact_id', $contact->id)->first();
|
2020-03-28 04:45:11 +01:00
|
|
|
|
2019-09-02 07:08:26 +02:00
|
|
|
$data = [];
|
2020-09-06 11:38:10 +02:00
|
|
|
$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->date ?: ' ', 'label' => ctrans('texts.date')];
|
2020-03-25 00:20:42 +01: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['$invoice.due_date'] = ['value' => $this->due_date ?: ' ', 'label' => ctrans('texts.due_date')];
|
|
|
|
$data['$due_date'] = &$data['$invoice.due_date'];
|
|
|
|
$data['$invoice.number'] = ['value' => $this->number ?: ' ', 'label' => ctrans('texts.invoice_number')];
|
|
|
|
$data['$invoice.po_number'] = ['value' => $this->po_number ?: ' ', 'label' => ctrans('texts.po_number')];
|
|
|
|
$data['$line_taxes'] = ['value' => $this->makeLineTaxes() ?: ' ', 'label' => ctrans('texts.taxes')];
|
|
|
|
$data['$invoice.line_taxes'] = &$data['$line_taxes'];
|
|
|
|
$data['$total_taxes'] = ['value' => $this->makeTotalTaxes() ?: ' ', 'label' => ctrans('texts.taxes')];
|
|
|
|
$data['$invoice.total_taxes'] = &$data['$total_taxes'];
|
2020-03-16 11:12:10 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($this instanceof Invoice) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$data['$entity_label'] = ['value' => '', 'label' => ctrans('texts.invoice')];
|
|
|
|
$data['$number'] = ['value' => $this->number ?: ' ', 'label' => ctrans('texts.invoice_number')];
|
|
|
|
$data['$entity.terms'] = ['value' => $this->terms ?: ' ', 'label' => ctrans('texts.invoice_terms')];
|
|
|
|
$data['$terms'] = &$data['$entity.terms'];
|
|
|
|
$data['$view_link'] = ['value' => '<a href="'.$invitation->getLink().'">'.ctrans('texts.view_invoice').'</a>', 'label' => ctrans('texts.view_invoice')];
|
2020-08-22 14:24:41 +02:00
|
|
|
// $data['$view_link'] = ['value' => $invitation->getLink(), 'label' => ctrans('texts.view_invoice')];
|
2020-03-16 11:12:10 +01:00
|
|
|
}
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($this instanceof Quote) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$data['$entity_label'] = ['value' => '', 'label' => ctrans('texts.quote')];
|
|
|
|
$data['$number'] = ['value' => $this->number ?: ' ', 'label' => ctrans('texts.quote_number')];
|
|
|
|
$data['$entity.terms'] = ['value' => $this->terms ?: ' ', 'label' => ctrans('texts.quote_terms')];
|
|
|
|
$data['$terms'] = &$data['$entity.terms'];
|
|
|
|
$data['$view_link'] = ['value' => '<a href="'.$invitation->getLink().'">'.ctrans('texts.view_quote').'</a>', 'label' => ctrans('texts.view_quote')];
|
2020-08-22 14:24:41 +02:00
|
|
|
// $data['$view_link'] = ['value' => $invitation->getLink(), 'label' => ctrans('texts.view_quote')];
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|
2019-09-02 07:08:26 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($this instanceof Credit) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$data['$entity_label'] = ['value' => '', 'label' => ctrans('texts.credit')];
|
|
|
|
$data['$number'] = ['value' => $this->number ?: ' ', 'label' => ctrans('texts.credit_number')];
|
|
|
|
$data['$entity.terms'] = ['value' => $this->terms ?: ' ', 'label' => ctrans('texts.credit_terms')];
|
|
|
|
$data['$terms'] = &$data['$entity.terms'];
|
|
|
|
$data['$view_link'] = ['value' => '<a href="'.$invitation->getLink().'">'.ctrans('texts.view_credit').'</a>', 'label' => ctrans('texts.view_credit')];
|
2020-08-22 14:24:41 +02:00
|
|
|
// $data['$view_link'] = ['value' => $invitation->getLink(), 'label' => ctrans('texts.view_credit')];
|
2020-03-16 11:12:10 +01:00
|
|
|
}
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$data['$entity_number'] = &$data['$number'];
|
2020-03-16 11:12:10 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$data['$invoice.discount'] = ['value' => Number::formatMoney($calc->getTotalDiscount(), $this->client) ?: ' ', 'label' => ctrans('texts.discount')];
|
|
|
|
$data['$discount'] = &$data['$invoice.discount'];
|
|
|
|
$data['$subtotal'] = ['value' => Number::formatMoney($calc->getSubTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.subtotal')];
|
|
|
|
$data['$invoice.subtotal'] = &$data['$subtotal'];
|
|
|
|
$data['$invoice.balance_due'] = ['value' => Number::formatMoney($this->balance, $this->client) ?: ' ', 'label' => ctrans('texts.balance_due')];
|
|
|
|
$data['$quote.balance_due'] = &$data['$invoice.balance_due'];
|
|
|
|
$data['$balance_due'] = &$data['$invoice.balance_due'];
|
|
|
|
$data['$invoice.partial_due'] = ['value' => Number::formatMoney($this->partial, $this->client) ?: ' ', 'label' => ctrans('texts.partial_due')];
|
|
|
|
$data['$total'] = ['value' => Number::formatMoney($calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.total')];
|
|
|
|
$data['$amount'] = &$data['$total'];
|
|
|
|
$data['$quote.total'] = &$data['$total'];
|
|
|
|
$data['$invoice.total'] = ['value' => Number::formatMoney($calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.invoice_total')];
|
|
|
|
$data['$invoice.amount'] = &$data['$total'];
|
|
|
|
$data['$quote.amount'] = ['value' => Number::formatMoney($calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.quote_total')];
|
|
|
|
$data['$credit.total'] = ['value' => Number::formatMoney($calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.credit_total')];
|
|
|
|
$data['$credit.number'] = ['value' => $this->number ?: ' ', 'label' => ctrans('texts.credit_number')];
|
|
|
|
$data['$credit.amount'] = &$data['$credit.total'];
|
|
|
|
$data['$credit.po_number'] = &$data['$invoice.po_number'];
|
|
|
|
$data['$credit.date'] = ['value' => $this->date, 'label' => ctrans('texts.credit_date')];
|
|
|
|
$data['$balance'] = ['value' => Number::formatMoney($calc->getBalance(), $this->client) ?: ' ', 'label' => ctrans('texts.balance')];
|
|
|
|
$data['$credit.balance'] = &$data['$balance'];
|
|
|
|
|
|
|
|
$data['$invoice.balance'] = &$data['$balance'];
|
|
|
|
$data['$taxes'] = ['value' => Number::formatMoney($calc->getItemTotalTaxes(), $this->client) ?: ' ', 'label' => ctrans('texts.taxes')];
|
|
|
|
$data['$invoice.taxes'] = &$data['$taxes'];
|
|
|
|
|
|
|
|
$data['$invoice.custom1'] = ['value' => $this->custom_value1 ?: ' ', 'label' => $this->makeCustomField('invoice1')];
|
|
|
|
$data['$invoice.custom2'] = ['value' => $this->custom_value2 ?: ' ', 'label' => $this->makeCustomField('invoice2')];
|
|
|
|
$data['$invoice.custom3'] = ['value' => $this->custom_value3 ?: ' ', 'label' => $this->makeCustomField('invoice3')];
|
|
|
|
$data['$invoice.custom4'] = ['value' => $this->custom_value4 ?: ' ', 'label' => $this->makeCustomField('invoice4')];
|
|
|
|
$data['$invoice.public_notes'] = ['value' => $this->public_notes ?: ' ', 'label' => ctrans('texts.public_notes')];
|
|
|
|
$data['$entity.public_notes'] = &$data['$invoice.public_notes'];
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
// $data['$your_invoice'] = ;
|
|
|
|
// $data['$quote'] = ;
|
|
|
|
// $data['$your_quote'] = ;
|
2020-03-21 06:37:30 +01:00
|
|
|
//
|
2020-09-06 11:38:10 +02:00
|
|
|
$data['$quote.date'] = ['value' => $this->date ?: ' ', 'label' => ctrans('texts.quote_date')];
|
|
|
|
$data['$quote.number'] = ['value' => $this->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->due_date, 'label' => ctrans('texts.valid_until')];
|
|
|
|
$data['$credit_amount'] = ['value' => Number::formatMoney($calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.credit_amount')];
|
|
|
|
$data['$credit_balance'] = ['value' => Number::formatMoney($this->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-02-19 21:44:12 +01:00
|
|
|
|
2019-12-30 22:59:12 +01: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')];
|
|
|
|
$data['$country'] = ['value' => isset($this->client->country->name) ? $this->client->country->name : 'No Country Set', 'label' => ctrans('texts.country')];
|
|
|
|
$data['$email'] = ['value' => isset($contact) ? $contact->email : 'no contact email on record', 'label' => ctrans('texts.email')];
|
|
|
|
$data['$client_name'] = ['value' => $this->present()->clientName() ?: ' ', 'label' => ctrans('texts.client_name')];
|
|
|
|
$data['$client.name'] = &$data['$client_name'];
|
2020-09-08 06:06:46 +02:00
|
|
|
$data['$client.balance'] = ['value' => $this->client->balance, 'label' => ctrans('texts.balance')];
|
|
|
|
|
|
|
|
$data['$paid_to_date'] = ['value' => $this->client->paid_to_date, 'label' => ctrans('texts.paid_to_date')];
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$data['$client.address1'] = &$data['$address1'];
|
|
|
|
$data['$client.address2'] = &$data['$address2'];
|
|
|
|
$data['$client_address'] = ['value' => $this->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->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->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'];
|
|
|
|
|
|
|
|
$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'] = ['value' => isset($contact) ? $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($contact) ? $contact->custom_value1 : ' ', 'label' => $this->makeCustomField('contact1')];
|
|
|
|
$data['$contact.custom2'] = ['value' => isset($contact) ? $contact->custom_value2 : ' ', 'label' => $this->makeCustomField('contact1')];
|
|
|
|
$data['$contact.custom3'] = ['value' => isset($contact) ? $contact->custom_value3 : ' ', 'label' => $this->makeCustomField('contact1')];
|
|
|
|
$data['$contact.custom4'] = ['value' => isset($contact) ? $contact->custom_value4 : ' ', 'label' => $this->makeCustomField('contact1')];
|
2020-03-16 11:12:10 +01:00
|
|
|
|
|
|
|
$data['$company.city_state_postal'] = ['value' => $this->company->present()->cityStateZip($settings->city, $settings->state, $settings->postal_code, false) ?: ' ', 'label' => ctrans('texts.city_state_postal')];
|
|
|
|
$data['$company.postal_city_state'] = ['value' => $this->company->present()->cityStateZip($settings->city, $settings->state, $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' => $settings->address1 ?: ' ', 'label' => ctrans('texts.address1')];
|
|
|
|
$data['$company.address2'] = ['value' => $settings->address2 ?: ' ', 'label' => ctrans('texts.address2')];
|
|
|
|
$data['$company.city'] = ['value' => $settings->city ?: ' ', 'label' => ctrans('texts.city')];
|
|
|
|
$data['$company.state'] = ['value' => $settings->state ?: ' ', 'label' => ctrans('texts.state')];
|
|
|
|
$data['$company.postal_code'] = ['value' => $settings->postal_code ?: ' ', 'label' => ctrans('texts.postal_code')];
|
|
|
|
$data['$company.country'] = ['value' => Country::find($settings->country_id)->first()->name ?: ' ', 'label' => ctrans('texts.country')];
|
|
|
|
$data['$company.phone'] = ['value' => $settings->phone ?: ' ', 'label' => ctrans('texts.phone')];
|
|
|
|
$data['$company.email'] = ['value' => $settings->email ?: ' ', 'label' => ctrans('texts.email')];
|
|
|
|
$data['$company.vat_number'] = ['value' => $settings->vat_number ?: ' ', 'label' => ctrans('texts.vat_number')];
|
|
|
|
$data['$company.id_number'] = ['value' => $settings->id_number ?: ' ', 'label' => ctrans('texts.id_number')];
|
|
|
|
$data['$company.website'] = ['value' => $settings->website ?: ' ', 'label' => ctrans('texts.website')];
|
|
|
|
$data['$company.address'] = ['value' => $this->company->present()->address($settings) ?: ' ', 'label' => ctrans('texts.address')];
|
|
|
|
|
2020-02-05 11:28:56 +01:00
|
|
|
$logo = $this->company->present()->logo($settings);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$data['$company.logo'] = ['value' => "<img src='{$logo}' class='h-32' alt='logo'>" ?: ' ', 'label' => ctrans('texts.logo')];
|
|
|
|
$data['$company_logo'] = &$data['$company.logo'];
|
|
|
|
$data['$company1'] = ['value' => $settings->custom_value1 ?: ' ', 'label' => $this->makeCustomField('company1')];
|
|
|
|
$data['$company2'] = ['value' => $settings->custom_value2 ?: ' ', 'label' => $this->makeCustomField('company2')];
|
|
|
|
$data['$company3'] = ['value' => $settings->custom_value3 ?: ' ', 'label' => $this->makeCustomField('company3')];
|
|
|
|
$data['$company4'] = ['value' => $settings->custom_value4 ?: ' ', 'label' => $this->makeCustomField('company4')];
|
|
|
|
|
2020-09-08 06:02:00 +02:00
|
|
|
$data['$custom_surcharge1'] = ['value' => $this->custom_surcharge1, 'label' => $this->makeCustomField('custom_surcharge1')];
|
|
|
|
$data['$custom_surcharge2'] = ['value' => $this->custom_surcharge2, 'label' => $this->makeCustomField('custom_surcharge2')];
|
|
|
|
$data['$custom_surcharge3'] = ['value' => $this->custom_surcharge3, 'label' => $this->makeCustomField('custom_surcharge3')];
|
|
|
|
$data['$custom_surcharge4'] = ['value' => $this->custom_surcharge4, 'label' => $this->makeCustomField('custom_surcharge4')];
|
|
|
|
|
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')];
|
2020-03-26 04:23:57 +01:00
|
|
|
//$data['$contact.signature']
|
2020-03-16 11:12:10 +01: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.')];
|
2019-12-30 22:59:12 +01:00
|
|
|
//$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'] = ;
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
$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'] =;
|
2019-09-02 07:08:26 +02:00
|
|
|
*/
|
2020-02-10 10:53:02 +01:00
|
|
|
|
|
|
|
$arrKeysLength = array_map('strlen', array_keys($data));
|
|
|
|
array_multisort($arrKeysLength, SORT_DESC, $data);
|
|
|
|
|
2019-09-02 07:08:26 +02:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2019-09-03 01:00:52 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* V2 of building a table header for PDFs.
|
2020-03-16 11:12:10 +01:00
|
|
|
* @param array $columns The array (or string of column headers)
|
|
|
|
* @return string injectable HTML string
|
2019-09-03 01:00:52 +02:00
|
|
|
*/
|
2020-03-16 11:12:10 +01:00
|
|
|
public function buildTableHeader($columns) :?string
|
2019-09-03 01:00:52 +02:00
|
|
|
{
|
2020-03-16 11:12:10 +01:00
|
|
|
$data = $this->makeLabels();
|
2019-09-03 01:00:52 +02:00
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
$table_header = '<tr>';
|
2019-09-03 01:00:52 +02:00
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
foreach ($columns as $key => $column) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$table_header .= '<td class="table_header_td_class">'.$column.'_label</td>';
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-09 21:07:46 +01:00
|
|
|
$table_header .= '</tr>';
|
2020-02-05 11:28:56 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$table_header = strtr($table_header, $data); // str_replace(array_keys($data), array_values($data), $table_header);
|
2020-03-16 11:12:10 +01:00
|
|
|
|
2020-02-05 11:28:56 +01:00
|
|
|
return $table_header;
|
|
|
|
}
|
|
|
|
|
2020-03-07 07:31:26 +01:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* V2 of building a table body for PDFs.
|
2020-03-16 11:12:10 +01:00
|
|
|
* @param array $columns The array (or string of column headers)
|
|
|
|
* @return string injectable HTML string
|
2020-03-07 07:31:26 +01:00
|
|
|
*/
|
2020-03-21 06:37:30 +01:00
|
|
|
public function buildTableBody(array $default_columns, $user_columns, string $table_prefix) :?string
|
2020-02-05 11:28:56 +01:00
|
|
|
{
|
2020-03-16 11:12:10 +01:00
|
|
|
$items = $this->transformLineItems($this->line_items, $table_prefix);
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if (count($items) == 0) {
|
2020-03-16 11:12:10 +01:00
|
|
|
return '';
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-02-05 11:28:56 +01:00
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
$data = $this->makeValues();
|
2020-02-05 11:28:56 +01:00
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
$output = '';
|
2020-02-05 11:28:56 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if (strlen($user_columns) > 1) {
|
|
|
|
foreach ($items as $key => $item) {
|
2020-04-15 02:30:52 +02:00
|
|
|
// $tmp = str_replace(array_keys($data), array_values($data), $user_columns);
|
|
|
|
// $tmp = str_replace(array_keys($item), array_values($item), $tmp);
|
|
|
|
$tmp = strtr($user_columns, $data);
|
|
|
|
$tmp = strtr($tmp, $item);
|
2020-02-05 11:28:56 +01:00
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
$output .= $tmp;
|
2020-02-05 11:28:56 +01:00
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
} else {
|
2020-03-16 11:12:10 +01:00
|
|
|
$table_row = '<tr>';
|
2020-02-05 11:28:56 +01:00
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
foreach ($default_columns as $key => $column) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$table_row .= '<td class="table_header_td_class">'.$column.'</td>';
|
2020-03-16 11:12:10 +01:00
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
$table_row .= '</tr>';
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
foreach ($items as $key => $item) {
|
2020-04-15 02:30:52 +02:00
|
|
|
// $tmp = str_replace(array_keys($item), array_values($item), $table_row);
|
|
|
|
// $tmp = str_replace(array_keys($data), array_values($data), $tmp);
|
|
|
|
$tmp = strtr($table_row, $item);
|
|
|
|
$tmp = strtr($tmp, $data);
|
2020-03-16 11:12:10 +01:00
|
|
|
|
|
|
|
$output .= $tmp;
|
|
|
|
}
|
2020-02-05 11:28:56 +01:00
|
|
|
}
|
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
return $output;
|
2020-02-05 11:28:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-03 08:01:40 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Transform the column headers into translated header values.
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-09-04 01:16:23 +02:00
|
|
|
* @param array $columns The column header values
|
|
|
|
* @return array The new column header variables
|
|
|
|
*/
|
|
|
|
private function transformColumnsForHeader(array $columns) :array
|
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
if (count($columns) == 0) {
|
2020-03-05 08:14:57 +01:00
|
|
|
return [];
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-05 08:14:57 +01:00
|
|
|
|
2019-09-04 07:10:10 +02:00
|
|
|
$pre_columns = $columns;
|
|
|
|
$columns = array_intersect($columns, self::$master_columns);
|
2019-09-04 01:16:23 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return str_replace(
|
|
|
|
[
|
2019-09-04 01:16:23 +02:00
|
|
|
'tax_name1',
|
2020-02-19 21:44:12 +01:00
|
|
|
'tax_name2',
|
2020-09-06 11:38:10 +02:00
|
|
|
'tax_name3',
|
2019-12-30 22:59:12 +01:00
|
|
|
],
|
2019-09-04 01:16:23 +02:00
|
|
|
[
|
|
|
|
'tax',
|
|
|
|
'tax',
|
2020-09-06 11:38:10 +02:00
|
|
|
'tax',
|
2019-12-30 22:59:12 +01:00
|
|
|
],
|
|
|
|
$columns
|
|
|
|
);
|
2019-09-04 01:16:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Transform the column headers into invoice variables.
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-09-03 08:01:40 +02:00
|
|
|
* @param array $columns The column header values
|
|
|
|
* @return array The invoice variables
|
|
|
|
*/
|
2019-09-04 01:16:23 +02:00
|
|
|
private function transformColumnsForLineItems(array $columns) :array
|
2019-09-03 08:01:40 +02:00
|
|
|
{
|
2019-09-04 01:16:23 +02:00
|
|
|
/* Removes any invalid columns the user has entered. */
|
2019-09-04 07:10:10 +02:00
|
|
|
$columns = array_intersect($columns, self::$master_columns);
|
2019-09-04 01:16:23 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return str_replace(
|
|
|
|
[
|
|
|
|
'custom_invoice_label1',
|
|
|
|
'custom_invoice_label2',
|
|
|
|
'custom_invoice_label3',
|
|
|
|
'custom_invoice_label4',
|
|
|
|
'tax_name1',
|
2020-02-19 21:44:12 +01:00
|
|
|
'tax_name2',
|
2020-09-06 11:38:10 +02:00
|
|
|
'tax_name3',
|
2019-12-30 22:59:12 +01:00
|
|
|
],
|
|
|
|
[
|
2019-09-04 00:16:53 +02:00
|
|
|
'custom_invoice_value1',
|
|
|
|
'custom_invoice_value2',
|
|
|
|
'custom_invoice_value3',
|
|
|
|
'custom_invoice_value4',
|
|
|
|
'tax_rate1',
|
2020-02-19 21:44:12 +01:00
|
|
|
'tax_rate2',
|
2020-09-06 11:38:10 +02:00
|
|
|
'tax_rate3',
|
2019-12-30 22:59:12 +01:00
|
|
|
],
|
|
|
|
$columns
|
|
|
|
);
|
2019-09-03 08:01:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Formats the line items for display.
|
2019-09-03 08:01:40 +02:00
|
|
|
* @param array $items The array of invoice items
|
|
|
|
* @return array The formatted array of invoice items
|
|
|
|
*/
|
2020-07-30 17:47:40 +02:00
|
|
|
public function transformLineItems($items, $table_type = '$product') :array
|
2019-09-03 08:01:40 +02:00
|
|
|
{
|
2020-03-16 11:12:10 +01:00
|
|
|
$data = [];
|
2020-09-06 11:38:10 +02:00
|
|
|
|
|
|
|
if (! is_array($items)) {
|
2020-03-16 11:12:10 +01:00
|
|
|
$data;
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-02-17 10:37:44 +01:00
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
foreach ($items as $key => $item) {
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($table_type == '$product' && $item->type_id != 1) {
|
2020-03-16 11:12:10 +01:00
|
|
|
continue;
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-16 11:12:10 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($table_type == '$task' && $item->type_id != 2) {
|
2020-03-16 11:12:10 +01:00
|
|
|
continue;
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-16 11:12:10 +01:00
|
|
|
|
|
|
|
$data[$key][$table_type.'.product_key'] = $item->product_key;
|
|
|
|
$data[$key][$table_type.'.notes'] = $item->notes;
|
|
|
|
$data[$key][$table_type.'.custom_value1'] = $item->custom_value1;
|
|
|
|
$data[$key][$table_type.'.custom_value2'] = $item->custom_value2;
|
|
|
|
$data[$key][$table_type.'.custom_value3'] = $item->custom_value3;
|
|
|
|
$data[$key][$table_type.'.custom_value4'] = $item->custom_value4;
|
|
|
|
$data[$key][$table_type.'.quantity'] = $item->quantity;
|
|
|
|
|
|
|
|
$data[$key][$table_type.'.cost'] = Number::formatMoney($item->cost, $this->client);
|
|
|
|
$data[$key][$table_type.'.line_total'] = Number::formatMoney($item->line_total, $this->client);
|
2019-09-04 00:16:53 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if (isset($item->discount) && $item->discount > 0) {
|
|
|
|
if ($item->is_amount_discount) {
|
2020-03-16 11:12:10 +01:00
|
|
|
$data[$key][$table_type.'.discount'] = Number::formatMoney($item->discount, $this->client);
|
2019-12-30 22:59:12 +01:00
|
|
|
} else {
|
2020-09-06 11:38:10 +02:00
|
|
|
$data[$key][$table_type.'.discount'] = $item->discount.'%';
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
} else {
|
2020-03-16 11:12:10 +01:00
|
|
|
$data[$key][$table_type.'.discount'] = '';
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if (isset($item->tax_rate1) && $item->tax_rate1 > 0) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$data[$key][$table_type.'.tax_rate1'] = round($item->tax_rate1, 2).'%';
|
2020-03-16 11:12:10 +01:00
|
|
|
$data[$key][$table_type.'.tax1'] = &$data[$key][$table_type.'.tax_rate1'];
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if (isset($item->tax_rate2) && $item->tax_rate2 > 0) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$data[$key][$table_type.'.tax_rate2'] = round($item->tax_rate2, 2).'%';
|
2020-03-16 11:12:10 +01:00
|
|
|
$data[$key][$table_type.'.tax2'] = &$data[$key][$table_type.'.tax_rate2'];
|
|
|
|
}
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if (isset($item->tax_rate3) && $item->tax_rate3 > 0) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$data[$key][$table_type.'.tax_rate3'] = round($item->tax_rate3, 2).'%';
|
2020-03-16 11:12:10 +01:00
|
|
|
$data[$key][$table_type.'.tax3'] = &$data[$key][$table_type.'.tax_rate3'];
|
|
|
|
}
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if (isset($item->tax_rate1) && $item->tax_rate1 == 0) {
|
2020-03-16 11:12:10 +01:00
|
|
|
$data[$key][$table_type.'.tax_rate1'] = '';
|
|
|
|
$data[$key][$table_type.'.tax1'] = &$data[$key][$table_type.'.tax_rate1'];
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if (isset($item->tax_rate2) && $item->tax_rate2 == 0) {
|
2020-03-16 11:12:10 +01:00
|
|
|
$data[$key][$table_type.'.tax_rate2'] = '';
|
|
|
|
$data[$key][$table_type.'.tax2'] = &$data[$key][$table_type.'.tax_rate2'];
|
|
|
|
}
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if (isset($item->tax_rate3) && $item->tax_rate3 == 0) {
|
2020-03-16 11:12:10 +01:00
|
|
|
$data[$key][$table_type.'.tax_rate3'] = '';
|
|
|
|
$data[$key][$table_type.'.tax3'] = &$data[$key][$table_type.'.tax_rate3'];
|
|
|
|
}
|
2019-09-04 00:16:53 +02:00
|
|
|
}
|
|
|
|
|
2020-03-16 11:12:10 +01:00
|
|
|
return $data;
|
2019-09-03 08:01:40 +02:00
|
|
|
}
|
2019-09-04 14:01:19 +02:00
|
|
|
|
|
|
|
/**
|
2019-12-30 22:59:12 +01:00
|
|
|
* Due to the way we are compiling the blade template we
|
2019-09-04 14:01:19 +02:00
|
|
|
* have no ability to iterate, so in the case
|
2019-12-30 22:59:12 +01:00
|
|
|
* 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.
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
|
|
|
* @return string a collection of <tr> rows with line item
|
2019-09-04 14:01:19 +02:00
|
|
|
* aggregate data
|
|
|
|
*/
|
|
|
|
private function makeLineTaxes() :string
|
|
|
|
{
|
|
|
|
$tax_map = $this->calc()->getTaxMap();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-09-04 14:01:19 +02:00
|
|
|
$data = '';
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
foreach ($tax_map as $tax) {
|
2019-09-04 14:01:19 +02:00
|
|
|
$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>';
|
2019-09-04 14:01:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2019-10-13 12:59:55 +02:00
|
|
|
|
|
|
|
/**
|
2019-12-30 22:59:12 +01:00
|
|
|
* @return string a collectino of <tr> with
|
2019-10-13 12:59:55 +02:00
|
|
|
* itemised total tax data
|
|
|
|
*/
|
|
|
|
private function makeTotalTaxes() :string
|
|
|
|
{
|
|
|
|
$data = '';
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $this->calc()->getTotalTaxMap()) {
|
2019-10-16 11:28:52 +02:00
|
|
|
return $data;
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-10-16 11:28:52 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
foreach ($this->calc()->getTotalTaxMap() as $tax) {
|
2019-10-13 12:59:55 +02:00
|
|
|
$data .= '<tr class="total_taxes">';
|
2020-09-06 11:38:10 +02:00
|
|
|
$data .= '<td>'.$tax['name'].'</td>';
|
|
|
|
$data .= '<td>'.Number::formatMoney($tax['total'], $this->client).'</td></tr>';
|
2019-10-13 12:59:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2020-02-06 10:35:51 +01:00
|
|
|
|
|
|
|
private function totalTaxLabels() :string
|
|
|
|
{
|
|
|
|
$data = '';
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $this->calc()->getTotalTaxMap()) {
|
2020-02-06 10:35:51 +01:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->calc()->getTotalTaxMap() as $tax) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$data .= '<span>'.$tax['name'].'</span>';
|
2020-02-06 10:35:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function totalTaxValues() :string
|
|
|
|
{
|
|
|
|
$data = '';
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $this->calc()->getTotalTaxMap()) {
|
2020-02-06 10:35:51 +01:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->calc()->getTotalTaxMap() as $tax) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$data .= '<span>'.Number::formatMoney($tax['total'], $this->client).'</span>';
|
2020-02-06 10:35:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function lineTaxLabels() :string
|
|
|
|
{
|
|
|
|
$tax_map = $this->calc()->getTaxMap();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-06 10:35:51 +01:00
|
|
|
$data = '';
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
foreach ($tax_map as $tax) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$data .= '<span>'.$tax['name'].'</span>';
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-06 10:35:51 +01:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function lineTaxValues() :string
|
|
|
|
{
|
|
|
|
$tax_map = $this->calc()->getTaxMap();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-06 10:35:51 +01:00
|
|
|
$data = '';
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
foreach ($tax_map as $tax) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$data .= '<span>'.Number::formatMoney($tax['total'], $this->client).'</span>';
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-06 10:35:51 +01:00
|
|
|
return $data;
|
|
|
|
}
|
2020-03-16 11:12:10 +01: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-03-16 11:12:10 +01:00
|
|
|
}
|
2020-04-12 13:51:27 +02:00
|
|
|
|
2020-04-13 03:49:58 +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-13 03:49:58 +02:00
|
|
|
* @return string The css string
|
|
|
|
*/
|
|
|
|
public function generateCustomCSS() :string
|
2020-04-12 13:51:27 +02:00
|
|
|
{
|
|
|
|
$settings = $this->client->getMergedSettings();
|
|
|
|
|
|
|
|
$header_and_footer = '
|
2020-04-13 02:24:02 +02:00
|
|
|
.header, .header-space {
|
|
|
|
height: 160px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.footer, .footer-space {
|
|
|
|
height: 160px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.footer {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 0;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.header {
|
|
|
|
position: fixed;
|
|
|
|
top: 0mm;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
2020-04-12 13:51:27 +02:00
|
|
|
@media print {
|
|
|
|
thead {display: table-header-group;}
|
|
|
|
tfoot {display: table-footer-group;}
|
|
|
|
button {display: none;}
|
|
|
|
body {margin: 0;}
|
2020-04-15 02:30:52 +02:00
|
|
|
}';
|
2020-04-12 13:51:27 +02:00
|
|
|
|
|
|
|
$header = '
|
2020-04-13 02:24:02 +02:00
|
|
|
.header, .header-space {
|
|
|
|
height: 160px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.header {
|
|
|
|
position: fixed;
|
|
|
|
top: 0mm;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
2020-04-12 13:51:27 +02:00
|
|
|
@media print {
|
|
|
|
thead {display: table-header-group;}
|
|
|
|
button {display: none;}
|
|
|
|
body {margin: 0;}
|
2020-04-15 02:30:52 +02:00
|
|
|
}';
|
2020-04-12 13:51:27 +02:00
|
|
|
|
|
|
|
$footer = '
|
2020-04-13 02:24:02 +02:00
|
|
|
|
|
|
|
.footer, .footer-space {
|
|
|
|
height: 160px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.footer {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 0;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
2020-04-12 13:51:27 +02:00
|
|
|
@media print {
|
|
|
|
tfoot {display: table-footer-group;}
|
|
|
|
button {display: none;}
|
|
|
|
body {margin: 0;}
|
2020-04-15 02:30:52 +02:00
|
|
|
}';
|
2020-04-12 13:51:27 +02:00
|
|
|
$css = '';
|
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
if ($settings->all_pages_header && $settings->all_pages_footer) {
|
2020-04-12 13:51:27 +02:00
|
|
|
$css .= $header_and_footer;
|
2020-09-06 11:38:10 +02:00
|
|
|
} elseif ($settings->all_pages_header && ! $settings->all_pages_footer) {
|
2020-04-12 13:51:27 +02:00
|
|
|
$css .= $header;
|
2020-09-06 11:38:10 +02:00
|
|
|
} elseif (! $settings->all_pages_header && $settings->all_pages_footer) {
|
2020-04-12 13:51:27 +02:00
|
|
|
$css .= $footer;
|
2020-04-15 02:30:52 +02:00
|
|
|
}
|
2020-04-12 13:51:27 +02:00
|
|
|
|
|
|
|
$css .= '
|
|
|
|
.page {
|
|
|
|
page-break-after: always;
|
|
|
|
}
|
|
|
|
|
|
|
|
@page {
|
|
|
|
margin: 0mm
|
|
|
|
}
|
|
|
|
|
|
|
|
html {
|
|
|
|
';
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$css .= 'font-size:'.$settings->font_size.'px;';
|
2020-04-13 03:49:58 +02:00
|
|
|
// $css .= 'font-size:14px;';
|
2020-04-12 13:51:27 +02:00
|
|
|
|
|
|
|
$css .= '}';
|
|
|
|
|
|
|
|
return $css;
|
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|