diff --git a/app/Models/Person/Person.php b/app/Models/Person/Person.php index ba4ea8a..06692d7 100644 --- a/app/Models/Person/Person.php +++ b/app/Models/Person/Person.php @@ -46,6 +46,7 @@ class Person extends Model 'group_id', 'type_id', 'user_id', + 'employer' ]; protected $hidden = [ diff --git a/app/Services/ImportProcessor.php b/app/Services/ImportProcessor.php index dac06bf..1c5bbd1 100644 --- a/app/Services/ImportProcessor.php +++ b/app/Services/ImportProcessor.php @@ -2974,7 +2974,7 @@ private function findOrCreatePersonId(array $p): ?int // Create person if any fields present; ensure required foreign keys if (! empty($p)) { $data = []; - foreach (['first_name', 'last_name', 'full_name', 'tax_number', 'social_security_number', 'birthday', 'gender', 'description', 'group_id', 'type_id'] as $k) { + foreach (['first_name', 'last_name', 'full_name', 'tax_number', 'social_security_number', 'birthday', 'gender', 'description', 'group_id', 'type_id', 'employer'] as $k) { if (array_key_exists($k, $p)) { $data[$k] = $p[$k]; } @@ -3163,10 +3163,38 @@ private function upsertAddress(int $personId, array $addrData, $mappings): array if (! isset($addrData['country']) || $addrData['country'] === null || $addrData['country'] === '') { $addrData['country'] = 'SLO'; } + + if (!empty($addrData['city']) && empty($addrData['post_code'])) { + if (preg_match('/^\d{3,}\s+/',trim($addrData['city']))) { + $cleanStrCity = str($addrData['city'])->squish()->value(); + $splitCity = preg_split('/\s/', $cleanStrCity, 2); + if (count($splitCity) >= 2) { + $addrData['post_code'] = $splitCity[0]; + $addrData['city'] = $splitCity[1]; + } + } + } // Compare addresses with all spaces removed to handle whitespace variations - $addressLineNoSpaces = preg_replace('/\s+/', '', $addressLine); + /*$addressLineNoSpaces = preg_replace('/\s+/', '', $addressLine); + + $existing = PersonAddress::where('person_id', $personId) ->whereRaw("REPLACE(address, ' ', '') = ?", [$addressLineNoSpaces]) + ->first();*/ + + // Build search query combining address, post_code and city + $searchParts = [$addrData['post_code']]; + if (!empty($addrData['post_code'])) { + $searchParts[] = $addrData['post_code']; + } + if (!empty($addrData['city'])) { + $searchParts[] = $addrData['city']; + } + + $searchQuery = implode(' ', $searchParts); + // Use fulltext search (GIN index optimized) + $existing = PersonAddress::where('person_id', $personId) + ->whereRaw("search_vector @@ plainto_tsquery('simple', ?)", [$searchQuery]) ->first(); $applyInsert = []; @@ -3211,6 +3239,11 @@ private function upsertAddress(int $personId, array $addrData, $mappings): array $data['person_id'] = $personId; $data['country'] = $data['country'] ?? 'SLO'; $data['type_id'] = $data['type_id'] ?? $this->getDefaultAddressTypeId(); + + if (!empty($addrData['post_code']) && $addrData['post_code'] !== '0' && !isset($applyUpdate['post_code'])) { + $data['post_code'] = $addrData['post_code']; + } + try { $created = PersonAddress::create($data); diff --git a/database/migrations/2026_01_14_183008_alter_table_person_add_column_employer.php b/database/migrations/2026_01_14_183008_alter_table_person_add_column_employer.php new file mode 100644 index 0000000..bfb1f8b --- /dev/null +++ b/database/migrations/2026_01_14_183008_alter_table_person_add_column_employer.php @@ -0,0 +1,28 @@ +string('employer', 125)->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('person', function (Blueprint $table){ + $table->dropColumn('employer'); + }); + } +}; diff --git a/database/migrations/2026_01_14_191129_alter_table_person_addresses_add_fulltext.php b/database/migrations/2026_01_14_191129_alter_table_person_addresses_add_fulltext.php new file mode 100644 index 0000000..ef535d0 --- /dev/null +++ b/database/migrations/2026_01_14_191129_alter_table_person_addresses_add_fulltext.php @@ -0,0 +1,37 @@ +dropIndex('person_addresses_search_vector_idx'); + $table->dropColumn('search_vector'); + }); + } +}; \ No newline at end of file diff --git a/database/seeders/ImportEntitySeeder.php b/database/seeders/ImportEntitySeeder.php index 2ec1be7..87f7db7 100644 --- a/database/seeders/ImportEntitySeeder.php +++ b/database/seeders/ImportEntitySeeder.php @@ -14,7 +14,7 @@ public function run(): void 'key' => 'person', 'canonical_root' => 'person', 'label' => 'Person', - 'fields' => ['first_name', 'last_name', 'full_name', 'gender', 'birthday', 'tax_number', 'social_security_number', 'description'], + 'fields' => ['first_name', 'last_name', 'full_name', 'gender', 'birthday', 'tax_number', 'social_security_number', 'description', 'employer'], 'field_aliases' => [ 'dob' => 'birthday', 'date_of_birth' => 'birthday', @@ -30,6 +30,7 @@ public function run(): void ['pattern' => '/^(spol|gender)\b/i', 'field' => 'gender'], ['pattern' => '/^(rojstvo|datum\s*rojstva|dob|birth|birthday|date\s*of\s*birth)\b/i', 'field' => 'birthday'], ['pattern' => '/^(komentar|opis|opomba|comment|description|note)\b/i', 'field' => 'description'], + ['pattern' => '/^(delodajalec|služba)\b/i', 'field' => 'employer'] ], 'ui' => ['order' => 1], ], diff --git a/resources/js/Components/PersonInfoGrid.vue b/resources/js/Components/PersonInfoGrid.vue index f36e8aa..647f88b 100644 --- a/resources/js/Components/PersonInfoGrid.vue +++ b/resources/js/Components/PersonInfoGrid.vue @@ -390,7 +390,7 @@ const buildVarsFromSelectedContract = () => { if (!uuid) return {}; const c = (contractsForCase.value || []).find((x) => x.uuid === uuid); if (!c) return {}; - + const vars = { contract: { uuid: c.uuid, @@ -407,7 +407,7 @@ const buildVarsFromSelectedContract = () => { ); vars.contract.meta = hasStructuredMeta ? flattenMeta(c.meta) : c.meta; } - + if (c.account) { vars.account = { reference: c.account.reference, @@ -580,6 +580,19 @@ const openSmsDialog = (phone) => { // Load contracts for this case (for contract/account placeholders) loadContractsForCase(); }; +// Format YYYY-MM-DD (or ISO date) to dd.mm.yyyy +function formatDate(value) { + if (!value) return "-"; + try { + const iso = String(value).split("T")[0]; + const parts = iso.split("-"); + if (parts.length !== 3) return value; + const [y, m, d] = parts; + return `${d.padStart(2, "0")}.${m.padStart(2, "0")}.${y}`; + } catch (e) { + return value; + } +} const loadContractsForCase = async () => { try { const url = route("clientCase.contracts.list", { client_case: props.clientCaseUuid }); @@ -640,43 +653,86 @@ const submitSms = () => {
-

Nu.

+

Primer ref.

{{ person.nu }}

-

Name.

+

Naziv

{{ person.full_name }}

-

Tax NU.

+

Davčna

{{ person.tax_number }}

-

Social security NU.

+

Emšo

{{ person.social_security_number }}

-
-
-

Address

+
+
+

Naslov

{{ getMainAddress(person.addresses) }}

-

Phone

+

Telefon

{{ getMainPhone(person.phones) }}

-
-

Description

+
+

Datum rojstva

+

+ {{ formatDate(person.birthday) }} +

+
+
+ +
+
+

Naslov

+

+ {{ getMainAddress(person.addresses) }} +

+
+
+

Telefon

+

+ {{ getMainPhone(person.phones) }} +

+
+
+
+
+

Delodajalec

+

+ {{ person.employer }} +

+
+
+

Opis

+

+ {{ person.description }} +

+
+
+
+
+

Opis

{{ person.description }}