freescout2ant/Resources/views/partials/contracts.blade.php
Claude 6eb4e8dfc2
Add API selection between MitarbeiterWebservice and Customer Archives/Stocks
Introduces an "Archive API" setting that switches both reads and writes
between the legacy MitarbeiterWebservice API and the new Customer Archives
(write) + Stocks (read) APIs.

- New write strategy (ArchiveWriterInterface + factory): legacy header-based
  writer and a Customer Archives JSON writer (CreateArchiveRequestDto, files as
  base64 data URIs, one entry per attachment), backed by CustomerArchivesApiClient.
- New read strategy (CrmReadClientInterface + factory): legacy delegate and a
  StocksReadClient that normalizes Stocks responses (customers/names,
  communications, contracts, contract lines/states) to the legacy shape so the
  controller/frontend stay unchanged.
- Hybrid: customer lookup by e-mail stays on MitarbeiterWebservice because the
  Stocks API cannot search by e-mail.
- Settings: ameise_api + ameise_archive_is_public dropdowns, env-backed base
  URLs for both new APIs (test/live), German translations.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KfJdbw4dRvJdcihTkKt69T
2026-06-25 13:23:16 +00:00

78 lines
4.5 KiB
PHP

@if($archives->isNotEmpty())
<div class="panel-group accordion accordion-empty">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" href=".collapse-conv-ameise">{{ __('Ameise Archivierungen') }}
<b class="caret"></b>
</a>
</h4>
</div>
<div class="collapse-conv-ameise panel-collapse collapse in">
<div class="conversation-contracts panel-body" id="contracts-list">
@if ($archives->isNotEmpty() && file_exists(storage_path('user_' . auth()->user()->id . '_ant.txt')))
<div class="conversation-archives-data">
@foreach ($archives as $archive)
@php
// Sicherstellen, dass crm_user decodiert werden kann
$user = [];
$malformed = false;
if ($archive->crm_user) {
$decoded = json_decode($archive->crm_user, true);
if (json_last_error() !== JSON_ERROR_NONE) {
$decoded = json_decode(urldecode($archive->crm_user), true);
$malformed = true;
}
if (!$decoded && preg_match('/"text"\s*:\s*"([^"]*)/', $archive->crm_user, $m)) {
$decoded = ['id' => $archive->crm_user_id, 'text' => $m[1]];
$malformed = true;
}
$user = is_array($decoded) ? $decoded : [];
}
if (empty($user) || $malformed) {
$tokenService = new \Modules\AmeiseModule\Services\TokenService('', auth()->user()->id);
$apiClient = new \Modules\AmeiseModule\Services\CrmApiClient($tokenService);
$client = \Modules\AmeiseModule\Services\Read\ReadClientFactory::make($apiClient, $tokenService);
$resp = $client->fetchUserByIdOrName($archive->crm_user_id);
if (is_array($resp) && count($resp) > 0) {
$user = ['id' => $resp[0]['Id'], 'text' => $resp[0]['Text']];
}
}
@endphp
<div class="conversation-archives">
<a style="font-size:14px;" target="_blank"
href="{{ (config('ameisemodule.ameise_mode') == 'test' ? 'https://maklerinfo.inte.dionera.dev' : 'https://ameise.app') }}/maklerportal/?show=kunde&kunde={{ $user['id'] ?? '' }}">
<p>{{ $user['text'] ?? '' }}</p>
</a>
@php
$contracts = $archive->contracts ? json_decode($archive->contracts, true) : [];
@endphp
@if (!empty($contracts))
@foreach ($contracts as $contract)
<div class="contract-tag">
<span class="tag-text glyphicon glyphicon-file"></span>{{ $contract['text'] ?? '' }}
</div>
@endforeach
@endif
@php
$divisions = $archive->divisions ? json_decode($archive->divisions, true) : [];
@endphp
@if (!empty($divisions))
@foreach ($divisions as $division)
<div class="division-tag">
<span class="tag-text glyphicon glyphicon-circle"></span>{{ $division['text'] ?? '' }}
</div>
@endforeach
@endif
</div>
@endforeach
</div>
@endif
</div>
</div>
</div>
</div>
@endif