From 4fa57dfc59bb43bb35f6cb357f2a27c0178eed4c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 29 Aug 2024 08:32:28 +1000 Subject: [PATCH] Fixes for import hints --- app/Http/Controllers/ImportController.php | 32 ++++++++++++++++++++--- app/Repositories/CompanyRepository.php | 3 +-- app/Services/Template/TemplateService.php | 1 + app/Utils/HtmlEngine.php | 2 ++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index f0b26ad7d7..ebaa8cb8b0 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -118,9 +118,36 @@ class ImportController extends Controller })->toArray(); - + //Exact string match foreach($headers as $key => $value) { + foreach($translated_keys as $tkey => $tvalue) { + + $concat_needle = str_ireplace(" ", "", $tvalue['index'].$tvalue['label']); + $concat_value = str_ireplace(" ", "", $value); + + if($this->testMatch($concat_value, $concat_needle)) { + + $hit = $tvalue['key']; + $hints[$key] = $hit; + unset($translated_keys[$tkey]); + break; + + } else { + $hints[$key] = null; + } + + } + + } + + //Label Match + foreach($headers as $key => $value) { + + if(isset($hints[$key])) { + continue; + } + foreach($translated_keys as $tkey => $tvalue) { if($this->testMatch($value, $tvalue['label'])) { @@ -134,10 +161,9 @@ class ImportController extends Controller } - } - //second pass using the index of the translation here + //Index matching pass using the index of the translation here foreach($headers as $key => $value) { if(isset($hints[$key])) { continue; diff --git a/app/Repositories/CompanyRepository.php b/app/Repositories/CompanyRepository.php index d292bed027..a2a2195d3b 100644 --- a/app/Repositories/CompanyRepository.php +++ b/app/Repositories/CompanyRepository.php @@ -58,9 +58,8 @@ class CompanyRepository extends BaseRepository $company->smtp_password = $data['smtp_password']; } - if(isset($data['e_invoice'])){ + if(isset($data['e_invoice']) && is_array($data['e_invoice'])){ //ensure it is normalized first! - $data['e_invoice'] = $this->arrayFilterRecursive($data['e_invoice']); $company->e_invoice = $data['e_invoice']; diff --git a/app/Services/Template/TemplateService.php b/app/Services/Template/TemplateService.php index 39e660f41d..c4894b674d 100644 --- a/app/Services/Template/TemplateService.php +++ b/app/Services/Template/TemplateService.php @@ -980,6 +980,7 @@ class TemplateService return [ 'name' => $user->present()->name(), 'email' => $user->email, + 'signature' => $user->signature ?? '', ]; } diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index aadea2190f..89b7d470e5 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -399,7 +399,9 @@ class HtmlEngine $data['$taxes'] = ['value' => Number::formatMoney($this->entity_calc->getItemTotalTaxes(), $this->client) ?: ' ', 'label' => ctrans('texts.taxes')]; $data['$invoice.taxes'] = &$data['$taxes']; + $data['$user.name'] = ['value' => $this->entity->user->present()->name(), 'label' => ctrans('texts.name')]; + $data['$user.signature'] = ['value' => $this->entity->user->signature ?? '', 'label' => ctrans('texts.signature')]; $data['$user.first_name'] = ['value' => $this->entity->user->first_name, 'label' => ctrans('texts.first_name')]; $data['$user.last_name'] = ['value' => $this->entity->user->last_name, 'label' => ctrans('texts.last_name')]; $data['$created_by_user'] = &$data['$user.name'];