Merge branch 'master' into Development
This commit is contained in:
@@ -399,6 +399,21 @@ public function updateContractSegment(ClientCase $clientCase, string $uuid, Requ
|
||||
return back()->with('success', 'Contract segment updated.')->with('flash_method', 'PATCH');
|
||||
}
|
||||
|
||||
public function patchContractMeta(ClientCase $clientCase, string $uuid, Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'meta' => ['required', 'array'],
|
||||
]);
|
||||
|
||||
$contract = $clientCase->contracts()->where('uuid', $uuid)->firstOrFail();
|
||||
|
||||
$contract->update([
|
||||
'meta' => $validated['meta'],
|
||||
]);
|
||||
|
||||
return back()->with('success', __('Meta podatki so bili posodobljeni.'));
|
||||
}
|
||||
|
||||
public function attachSegment(ClientCase $clientCase, Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
@@ -1224,7 +1239,7 @@ public function listContracts(ClientCase $clientCase)
|
||||
{
|
||||
$contracts = $clientCase->contracts()
|
||||
->with('account.type')
|
||||
->select('id', 'uuid', 'reference', 'active', 'start_date', 'end_date')
|
||||
->select('id', 'uuid', 'reference', 'active', 'start_date', 'end_date', 'meta')
|
||||
->latest('id')
|
||||
->get()
|
||||
->map(function ($c) {
|
||||
@@ -1240,6 +1255,7 @@ public function listContracts(ClientCase $clientCase)
|
||||
'active' => (bool) $c->active,
|
||||
'start_date' => (string) ($c->start_date ?? ''),
|
||||
'end_date' => (string) ($c->end_date ?? ''),
|
||||
'meta' => is_array($c->meta) && ! empty($c->meta) ? $this->flattenMeta($c->meta) : null,
|
||||
'account' => $acc ? [
|
||||
'reference' => $acc->reference,
|
||||
'type' => $acc->type?->name,
|
||||
@@ -1282,6 +1298,10 @@ public function previewSms(ClientCase $clientCase, Request $request, SmsService
|
||||
'start_date' => (string) ($contract->start_date ?? ''),
|
||||
'end_date' => (string) ($contract->end_date ?? ''),
|
||||
];
|
||||
// Include contract.meta as flattened key-value pairs
|
||||
if (is_array($contract->meta) && ! empty($contract->meta)) {
|
||||
$vars['contract']['meta'] = $this->flattenMeta($contract->meta);
|
||||
}
|
||||
if ($contract->account) {
|
||||
$initialRaw = (string) $contract->account->initial_amount;
|
||||
$balanceRaw = (string) $contract->account->balance_amount;
|
||||
@@ -1305,4 +1325,47 @@ public function previewSms(ClientCase $clientCase, Request $request, SmsService
|
||||
'variables' => $vars,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten nested meta structure into dot-notation key-value pairs.
|
||||
* Extracts 'value' from objects with {title, value, type} structure.
|
||||
* Also creates direct access aliases for nested fields (skipping numeric keys).
|
||||
*/
|
||||
private function flattenMeta(array $meta, string $prefix = ''): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($meta as $key => $value) {
|
||||
$newKey = $prefix === '' ? $key : "{$prefix}.{$key}";
|
||||
|
||||
if (is_array($value)) {
|
||||
// Check if it's a structured meta entry with 'value' field
|
||||
if (isset($value['value'])) {
|
||||
$result[$newKey] = $value['value'];
|
||||
// If parent key is numeric, also create direct alias without the number
|
||||
if ($prefix !== '' && is_numeric($key)) {
|
||||
$result[$key] = $value['value'];
|
||||
}
|
||||
} else {
|
||||
// Recursively flatten nested arrays
|
||||
$nested = $this->flattenMeta($value, $newKey);
|
||||
$result = array_merge($result, $nested);
|
||||
|
||||
// If current key is numeric, also flatten without it for easier access
|
||||
if (is_numeric($key)) {
|
||||
$directNested = $this->flattenMeta($value, $prefix);
|
||||
foreach ($directNested as $dk => $dv) {
|
||||
// Only add if not already set (prefer first occurrence)
|
||||
if (! isset($result[$dk])) {
|
||||
$result[$dk] = $dv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result[$newKey] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user