company->custom_fields; //todo we might want to translate like this //trans('texts.labe', [], null, $this->client->locale()); $data = []; foreach (self::$labels as $label) { $data['$'.$label . '_label'] = ctrans('texts.'.$label); } if($custom_fields) { foreach($custom_fields as $key => $value) { if(strpos($value, '|') !== false) { $value = explode("|", $value); $value = $value[0]; } $data['$'.$key.'_label'] = $value; } } /* Don't forget pipe | strings for dropdowns needs to be filtered */ /* invoice1 invoice2 invoice3 invoice4 surcharge1 surcharge2 surcharge3 surcharge4 client1 client2 client3 client4 contact1 contact2 contact3 contact4 */ $arrKeysLength = array_map('strlen', array_keys($data)); array_multisort($arrKeysLength, SORT_DESC, $data); return $data; } /** * Transforms all placeholders * to invoice values * * @return array returns an array * of keyed labels (appended with _label) */ public function makeValues($contact = null) :array { if (!$this->client->currency() || !$this->client) { throw new Exception(debug_backtrace()[1]['function'], 1); exit; } $settings = $this->client->getMergedSettings(); $data = []; $data['$total_tax_labels'] = $this->totalTaxLabels(); $data['$total_tax_values'] = $this->totalTaxValues(); $data['$line_tax_labels'] = $this->lineTaxLabels(); $data['$line_tax_values'] = $this->lineTaxValues(); $data['$date'] = $this->date ?: ' '; $data['$invoice.date'] = &$data['$date']; $data['$due_date'] = $this->due_date ?: ' '; $data['$invoice.due_date'] = &$data['$due_date']; $data['$number'] = $this->number ?: ' '; $data['$invoice.number'] = &$data['$number']; $data['$invoice_number'] = &$data['$number']; $data['$po_number'] = $this->po_number ?: ' '; $data['$invoice.po_number'] = &$data['$po_number']; $data['$line_taxes'] = $this->makeLineTaxes() ?: ' '; $data['$invoice.line_taxes'] = &$data['$line_taxes']; $data['$total_taxes'] = $this->makeTotalTaxes() ?: ' '; $data['$invoice.total_taxes'] = &$data['$total_taxes']; // $data['$tax'] = ; // $data['$item'] = ; // $data['$description'] = ; // $data['$unit_cost'] = ; // $data['$quantity'] = ; // $data['$line_total'] = ; // $data['$paid_to_date'] = ; $data['$discount'] = Number::formatMoney($this->calc()->getTotalDiscount(), $this->client) ?: ' '; $data['$invoice.discount'] = &$data['$discount']; $data['$subtotal'] = Number::formatMoney($this->calc()->getSubTotal(), $this->client) ?: ' '; $data['$invoice.subtotal'] = &$data['$subtotal']; $data['$balance_due'] = Number::formatMoney($this->balance, $this->client) ?: ' '; $data['$invoice.balance_due'] = &$data['$balance_due']; $data['$partial_due'] = Number::formatMoney($this->partial, $this->client) ?: ' '; $data['$invoice.partial_due'] = &$data['$partial_due']; $data['$total'] = Number::formatMoney($this->calc()->getTotal(), $this->client) ?: ' '; $data['$invoice.total'] = &$data['$total']; $data['$amount'] = &$data['$total']; $data['$invoice_total'] = &$data['$total']; $data['$invoice.amount'] = &$data['$total']; $data['$balance'] = Number::formatMoney($this->calc()->getBalance(), $this->client) ?: ' '; $data['$invoice.balance'] = &$data['$balance']; $data['$taxes'] = Number::formatMoney($this->calc()->getItemTotalTaxes(), $this->client) ?: ' '; $data['$invoice.taxes'] = &$data['$taxes']; $data['$terms'] = $this->terms ?: ' '; $data['$invoice.terms'] = &$data['$terms']; $data['$invoice1'] = $this->custom_value1 ?: ' '; $data['$invoice2'] = $this->custom_value2 ?: ' '; $data['$invoice3'] = $this->custom_value3 ?: ' '; $data['$invoice4'] = $this->custom_value4 ?: ' '; $data['$invoice.public_notes'] = $this->public_notes ?: ' '; // $data['$your_invoice'] = ; // $data['$quote'] = ; // $data['$your_quote'] = ; // $data['$quote_date'] = ; // $data['$quote_number'] = ; // $data['$invoice_issued_to'] = ; // $data['$quote_issued_to'] = ; // $data['$rate'] = ; // $data['$hours'] = ; // $data['$from'] = ; // $data['$to'] = ; // $data['$invoice_to'] = ; // $data['$quote_to'] = ; // $data['$details'] = ; $data['$invoice_no'] = $this->number ?: ' '; $data['$invoice.invoice_no'] = &$data['$invoice_no']; // $data['$quote_no'] = ; // $data['$valid_until'] = ; $data['$client1'] = $this->client->custom_value1 ?: ' '; $data['$client2'] = $this->client->custom_value2 ?: ' '; $data['$client3'] = $this->client->custom_value3 ?: ' '; $data['$client4'] = $this->client->custom_value4 ?: ' '; $data['$client_name'] = $this->present()->clientName() ?: ' '; $data['$client.name'] = &$data['$client_name']; $data['$address1'] = $this->client->address1 ?: ' '; $data['$address2'] = $this->client->address2 ?: ' '; $data['$client.address2'] = &$data['$address2']; $data['$client.address1'] = &$data['$address1']; $data['$client.address'] = &$data['$client_address']; $data['$client_address'] = $this->present()->address() ?: ' '; $data['$id_number'] = $this->client->id_number ?: ' '; $data['$client.id_number'] = &$data['$id_number']; $data['$vat_number'] = $this->client->vat_number ?: ' '; $data['$client.vat_number'] = &$data['$vat_number']; $data['$website'] = $this->client->present()->website() ?: ' '; $data['$client.website'] = &$data['$website']; $data['$phone'] = $this->client->present()->phone() ?: ' '; $data['$client.phone'] = &$data['$phone']; $data['$city_state_postal'] = $this->present()->cityStateZip($this->client->city, $this->client->state, $this->client->postal_code, false) ?: ' '; $data['$client.city_state_postal'] = &$data['$city_state_postal']; $data['$postal_city_state'] = $this->present()->cityStateZip($this->client->city, $this->client->state, $this->client->postal_code, true) ?: ' '; $data['$client.postal_city_state'] = &$data['$postal_city_state']; $data['$country'] = isset($this->client->country->name) ? $this->client->country->name : 'No Country Set'; $data['$client.country'] = &$data['$country']; $data['$email'] = isset($this->client->primary_contact()->first()->email) ? $this->client->primary_contact()->first()->email : 'no contact email on record'; $data['$client.email'] = &$data['$email']; if(!$contact) $contact = $this->client->primary_contact()->first(); $data['$contact_name'] = isset($contact) ? $contact->present()->name() : 'no contact name on record'; $data['$contact.name'] = &$data['$contact_name']; $data['$contact1'] = isset($contact) ? $contact->custom_value1 : ' '; $data['$contact2'] = isset($contact) ? $contact->custom_value2 : ' '; $data['$contact3'] = isset($contact) ? $contact->custom_value3 : ' '; $data['$contact4'] = isset($contact) ? $contact->custom_value4 : ' '; $data['$company.city_state_postal'] = $this->company->present()->cityStateZip($settings->city, $settings->state, $settings->postal_code, false) ?: ' '; $data['$company.postal_city_state'] = $this->company->present()->cityStateZip($settings->city, $settings->state, $settings->postal_code, true) ?: ' '; $data['$company.name'] = $this->company->present()->name() ?: ' '; $data['$company.company_name'] = &$data['$company.name']; $data['$company.address1'] = $settings->address1 ?: ' '; $data['$company.address2'] = $settings->address2 ?: ' '; $data['$company.city'] = $settings->city ?: ' '; $data['$company.state'] = $settings->state ?: ' '; $data['$company.postal_code'] = $settings->postal_code ?: ' '; $data['$company.country'] = Country::find($settings->country_id)->first()->name ?: ' '; $data['$company.phone'] = $settings->phone ?: ' '; $data['$company.email'] = $settings->email ?: ' '; $data['$company.vat_number'] = $settings->vat_number ?: ' '; $data['$company.id_number'] = $settings->id_number ?: ' '; $data['$company.website'] = $settings->website ?: ' '; $data['$company.address'] = $this->company->present()->address($settings) ?: ' '; $logo = $this->company->present()->logo($settings); $data['$company.logo'] = "" ?: ' '; $data['$company_logo'] = &$data['$company.logo']; $data['$company1'] = $settings->custom_value1 ?: ' '; $data['$company2'] = $settings->custom_value2 ?: ' '; $data['$company3'] = $settings->custom_value3 ?: ' '; $data['$company4'] = $settings->custom_value4 ?: ' '; //$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_number'] = ; $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); // \Log::error('woop'); //\Log::error(print_r($data,1)); return $data; } /** * Returns a formatted HTML table of invoice line items * * @param array $columns The columns to be displayed * * @return string[HTML string */ public function table(array $columns) :?string { $data = '
' . ctrans('texts.'.$column.'') . ' | '; } $data .= '
'. $item->{$column} . ' | '; } $data .= '