From ada4f3065c76acdb2144d8b390b2259a72dbd469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 23 Dec 2020 11:41:57 +0100 Subject: [PATCH] fixes for tests --- app/Http/Controllers/SetupController.php | 1 - app/Jobs/Import/CSVImport.php | 21 ++++++++++----------- app/Jobs/Mail/BaseMailerJob.php | 1 - app/Jobs/Mail/MailRouter.php | 4 ++-- app/Utils/Helpers.php | 14 +++++++------- app/Utils/Traits/MakesInvoiceValues.php | 21 ++++++++++++--------- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index 4e2473bd2054..eb6e5aa7c9bb 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -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. diff --git a/app/Jobs/Import/CSVImport.php b/app/Jobs/Import/CSVImport.php index f54016ac8532..391d160549ab 100644 --- a/app/Jobs/Import/CSVImport.php +++ b/app/Jobs/Import/CSVImport.php @@ -110,10 +110,9 @@ class CSVImport implements ShouldQueue 'settings' => $this->company->settings ]; -info(print_r($data,1)); + info(print_r($data, 1)); MailRouter::dispatch(new ImportCompleted($data), $this->company, auth()->user()); - } public function failed($exception) @@ -179,20 +178,20 @@ info(print_r($data,1)); $invoice['line_items'] = $this->cleanItems($items); - $validator = Validator::make($invoice, (new StoreInvoiceRequest())->rules()); - - if ($validator->fails()) { - $this->error_array['invoices'] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())]; - } else { + $validator = Validator::make($invoice, (new StoreInvoiceRequest())->rules()); if ($validator->fails()) { - $this->error_array[] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())]; + $this->error_array['invoices'] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())]; } else { - $invoice = $invoice_repository->save($invoice, InvoiceFactory::create($this->company->id, $this->setUser($record))); + if ($validator->fails()) { + $this->error_array[] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())]; + } else { + $invoice = $invoice_repository->save($invoice, InvoiceFactory::create($this->company->id, $this->setUser($record))); - $this->maps['invoices'][] = $invoice->id; + $this->maps['invoices'][] = $invoice->id; - $this->performInvoiceActions($invoice, $record, $invoice_repository); + $this->performInvoiceActions($invoice, $record, $invoice_repository); + } } } diff --git a/app/Jobs/Mail/BaseMailerJob.php b/app/Jobs/Mail/BaseMailerJob.php index c337e939ce90..ae3fb9711c73 100644 --- a/app/Jobs/Mail/BaseMailerJob.php +++ b/app/Jobs/Mail/BaseMailerJob.php @@ -96,7 +96,6 @@ class BaseMailerJob implements ShouldQueue public function failed($exception = null) { - info('the job failed'); info($exception->getMessage()); diff --git a/app/Jobs/Mail/MailRouter.php b/app/Jobs/Mail/MailRouter.php index dabb8a456f28..14510e0d8b82 100644 --- a/app/Jobs/Mail/MailRouter.php +++ b/app/Jobs/Mail/MailRouter.php @@ -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); + } } } } diff --git a/app/Utils/Helpers.php b/app/Utils/Helpers.php index 5b026787a44e..889d75e29f3f 100644 --- a/app/Utils/Helpers.php +++ b/app/Utils/Helpers.php @@ -41,13 +41,13 @@ class Helpers /** * 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 + * + * @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 { diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index 1273db1089a8..5ad73c662210 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -592,12 +592,12 @@ trait MakesInvoiceValues /** * Formats the line items for display. - * - * @param mixed $items - * @param string $table_type - * @param mixed|null $custom_fields - * - * @return array + * + * @param mixed $items + * @param string $table_type + * @param mixed|null $custom_fields + * + * @return array */ public function transformLineItems($items, $table_type = '$product') :array { @@ -631,9 +631,12 @@ trait MakesInvoiceValues $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 . ".{$_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;