mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Merge pull request #4553 from beganovich/v5-support-for-custom-columns-on-invoice
(v5) Support for custom columns on invoice
This commit is contained in:
commit
3251efeb40
@ -32,7 +32,6 @@ use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Spatie\Browsershot\Browsershot;
|
||||
|
||||
/**
|
||||
* Class SetupController.
|
||||
|
@ -113,7 +113,6 @@ class CSVImport implements ShouldQueue
|
||||
info(print_r($data, 1));
|
||||
|
||||
MailRouter::dispatch(new ImportCompleted($data), $this->company, auth()->user());
|
||||
|
||||
}
|
||||
|
||||
public function failed($exception)
|
||||
@ -184,7 +183,6 @@ info(print_r($data,1));
|
||||
if ($validator->fails()) {
|
||||
$this->error_array['invoices'] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())];
|
||||
} else {
|
||||
|
||||
if ($validator->fails()) {
|
||||
$this->error_array[] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())];
|
||||
} else {
|
||||
@ -195,6 +193,7 @@ info(print_r($data,1));
|
||||
$this->performInvoiceActions($invoice, $record, $invoice_repository);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function performInvoiceActions($invoice, $record, $invoice_repository)
|
||||
{
|
||||
|
@ -96,7 +96,6 @@ class BaseMailerJob implements ShouldQueue
|
||||
|
||||
public function failed($exception = null)
|
||||
{
|
||||
|
||||
info('the job failed');
|
||||
info($exception->getMessage());
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace App\Jobs\Mail;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
@ -76,8 +75,9 @@ class MailRouter extends BaseMailerJob implements ShouldQueue
|
||||
} catch (\Exception $e) {
|
||||
$this->failed($e);
|
||||
|
||||
if($this->to_user instanceof ClientContact)
|
||||
if ($this->to_user instanceof ClientContact) {
|
||||
$this->logMailError($e->getMessage(), $this->to_user->client);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -298,6 +298,7 @@ class Design extends BaseDesign
|
||||
public function buildTableHeader(string $type): array
|
||||
{
|
||||
$this->processTaxColumns($type);
|
||||
$this->processCustomColumns($type);
|
||||
|
||||
$elements = [];
|
||||
|
||||
|
@ -266,4 +266,23 @@ trait DesignHelpers
|
||||
|
||||
return $logs;
|
||||
}
|
||||
|
||||
public function processCustomColumns(string $type): void
|
||||
{
|
||||
$custom_columns = [];
|
||||
|
||||
foreach ((array) $this->client->company->custom_fields as $field => $value) {
|
||||
info($field);
|
||||
|
||||
if (\Illuminate\Support\Str::startsWith($field, $type)) {
|
||||
$custom_columns[] = '$' . $type . '.' . $field;
|
||||
}
|
||||
}
|
||||
|
||||
$key = array_search(sprintf('%s%s.description', '$', $type), $this->context['pdf_variables']["{$type}_columns"], true);
|
||||
|
||||
if ($key) {
|
||||
array_splice($this->context['pdf_variables']["{$type}_columns"], $key + 1, 0, $custom_columns);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,10 +13,13 @@
|
||||
namespace App\Utils;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use stdClass;
|
||||
|
||||
class Helpers
|
||||
{
|
||||
use MakesDates;
|
||||
|
||||
public static function sharedEmailVariables(?Client $client, array $settings = null): array
|
||||
{
|
||||
if (!$client) {
|
||||
@ -35,4 +38,42 @@ class Helpers
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* A centralised way to format the custom fields content.
|
||||
*
|
||||
* @param mixed $custom_fields
|
||||
* @param mixed $field
|
||||
* @param mixed $value
|
||||
* @param null|\App\Models\Client $client
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function formatCustomFieldValue($custom_fields, $field, $value, ?Client $client): ?string
|
||||
{
|
||||
$custom_field = '';
|
||||
|
||||
if ($custom_fields && property_exists($custom_fields, $field)) {
|
||||
$custom_field = $custom_fields->{$field};
|
||||
$custom_field_parts = explode('|', $custom_field);
|
||||
|
||||
if (count($custom_field_parts) >= 2) {
|
||||
$custom_field = $custom_field_parts[1];
|
||||
}
|
||||
}
|
||||
|
||||
switch ($custom_field) {
|
||||
case 'date':
|
||||
return $this->formatDate($value, $client->date_format());
|
||||
break;
|
||||
|
||||
case 'switch':
|
||||
return trim($value) == 'yes' ? ctrans('texts.yes') : ctrans('texts.no');
|
||||
break;
|
||||
|
||||
default:
|
||||
return is_null($value) ? '' : $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -307,6 +307,10 @@ class HtmlEngine
|
||||
$data['$product.line_total'] = ['value' => '', 'label' => ctrans('texts.line_total')];
|
||||
$data['$product.description'] = ['value' => '', 'label' => ctrans('texts.description')];
|
||||
$data['$product.unit_cost'] = ['value' => '', 'label' => ctrans('texts.unit_cost')];
|
||||
$data['$product.product1'] = ['value' => '', 'label' => $this->makeCustomField('product1')];
|
||||
$data['$product.product2'] = ['value' => '', 'label' => $this->makeCustomField('product2')];
|
||||
$data['$product.product3'] = ['value' => '', 'label' => $this->makeCustomField('product3')];
|
||||
$data['$product.product4'] = ['value' => '', 'label' => $this->makeCustomField('product4')];
|
||||
|
||||
$data['$task.date'] = ['value' => '', 'label' => ctrans('texts.date')];
|
||||
$data['$task.discount'] = ['value' => '', 'label' => ctrans('texts.discount')];
|
||||
|
@ -15,6 +15,7 @@ use App\Models\Country;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Quote;
|
||||
use App\Utils\Helpers;
|
||||
use App\Utils\Number;
|
||||
|
||||
/**
|
||||
@ -591,9 +592,12 @@ trait MakesInvoiceValues
|
||||
|
||||
/**
|
||||
* Formats the line items for display.
|
||||
* @param array $items The array of invoice items
|
||||
*
|
||||
* @param mixed $items
|
||||
* @param string $table_type
|
||||
* @return array The formatted array of invoice items
|
||||
* @param mixed|null $custom_fields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transformLineItems($items, $table_type = '$product') :array
|
||||
{
|
||||
@ -616,14 +620,24 @@ trait MakesInvoiceValues
|
||||
}
|
||||
}
|
||||
|
||||
$helpers = new Helpers();
|
||||
$_table_type = ltrim($table_type, '$'); // From $product -> product.
|
||||
|
||||
|
||||
$data[$key][$table_type.'.product_key'] = $item->product_key;
|
||||
$data[$key][$table_type.'.service'] = is_null(optional($item)->service) ? $item->product_key : $item->service;
|
||||
$data[$key][$table_type.'.notes'] = $item->notes;
|
||||
$data[$key][$table_type.'.description'] = $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 . ".{$_table_type}1"] = $helpers->formatCustomFieldValue($this->client->company->custom_fields, "{$_table_type}1", $item->custom_value1, $this->client);
|
||||
$data[$key][$table_type . ".{$_table_type}2"] = $helpers->formatCustomFieldValue($this->client->company->custom_fields, "{$_table_type}2", $item->custom_value2, $this->client);
|
||||
;
|
||||
$data[$key][$table_type . ".{$_table_type}3"] = $helpers->formatCustomFieldValue($this->client->company->custom_fields, "{$_table_type}3", $item->custom_value3, $this->client);
|
||||
;
|
||||
$data[$key][$table_type . ".{$_table_type}4"] = $helpers->formatCustomFieldValue($this->client->company->custom_fields, "{$_table_type}4", $item->custom_value4, $this->client);
|
||||
;
|
||||
|
||||
$data[$key][$table_type.'.quantity'] = $item->quantity;
|
||||
|
||||
$data[$key][$table_type.'.unit_cost'] = Number::formatMoney($item->cost, $this->client);
|
||||
|
Loading…
Reference in New Issue
Block a user