Phase 113 complete (v3.7 Invoices): - DB: invoices, invoice_configs, invoice_number_counters, fakturownia_integration_settings + orders.invoice_requested - FakturowniaIntegrationRepository (multi-account via integrations.type='fakturownia') - FakturowniaApiClient (testConnection; createInvoice/downloadPdf STUBs) - IntegrationsRepository::updateTestResult() (reusable test-result writer) - /settings/integrations/fakturownia (list + edit + test + delete) - Karta Fakturownia w hubie /settings/integrations Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
121 lines
5.6 KiB
PHP
121 lines
5.6 KiB
PHP
<?php
|
|
/** @var array<string, mixed>|null $row */
|
|
$row = is_array($row ?? null) ? $row : null;
|
|
$isNew = $row === null;
|
|
$integrationId = (int) ($row['integration_id'] ?? 0);
|
|
$name = (string) ($row['name'] ?? '');
|
|
$prefix = (string) ($row['account_prefix'] ?? '');
|
|
$departmentId = (string) ($row['department_id'] ?? '');
|
|
$defaultKind = (string) ($row['default_kind'] ?? 'vat');
|
|
$defaultPaymentDays = (int) ($row['default_payment_to_days'] ?? 7);
|
|
$isActive = $isNew ? true : (bool) ($row['is_active'] ?? false);
|
|
$hasToken = (bool) ($row['has_api_token'] ?? false);
|
|
$lastTestAt = (string) ($row['last_test_at'] ?? '');
|
|
$lastTestStatus = (string) ($row['last_test_status'] ?? '');
|
|
$lastTestMessage = (string) ($row['last_test_message'] ?? '');
|
|
|
|
$flashSave = trim((string) ($flashSave ?? ''));
|
|
$flashTest = trim((string) ($flashTest ?? ''));
|
|
$flashError = trim((string) ($flashError ?? ''));
|
|
?>
|
|
|
|
<section class="card">
|
|
<h2 class="section-title"><?= $isNew ? 'Nowa integracja Fakturownia' : 'Edycja integracji Fakturownia' ?></h2>
|
|
<p class="muted mt-12">Wystawianie faktur w aplikacji Fakturownia (app.fakturownia.pl).</p>
|
|
|
|
<?php if ($flashError !== ''): ?>
|
|
<div class="alert alert--danger mt-12" role="alert"><?= $e($flashError) ?></div>
|
|
<?php endif; ?>
|
|
<?php if ($flashSave !== ''): ?>
|
|
<div class="alert alert--success mt-12" role="status"><?= $e($flashSave) ?></div>
|
|
<?php endif; ?>
|
|
<?php if ($flashTest !== ''): ?>
|
|
<div class="alert alert--info mt-12" role="status"><?= $e($flashTest) ?></div>
|
|
<?php endif; ?>
|
|
</section>
|
|
|
|
<section class="card mt-16">
|
|
<form class="statuses-form" action="/settings/integrations/fakturownia/save" method="post" novalidate>
|
|
<input type="hidden" name="_token" value="<?= $e($csrfToken ?? '') ?>">
|
|
<?php if (!$isNew): ?>
|
|
<input type="hidden" name="id" value="<?= $integrationId ?>">
|
|
<?php endif; ?>
|
|
|
|
<label class="form-field">
|
|
<span class="field-label">Nazwa integracji *</span>
|
|
<input class="form-control" type="text" name="name" maxlength="128" value="<?= $e($name) ?>" required>
|
|
<span class="muted">Dowolna etykieta pomocnicza (np. "Fakturownia - moja firma").</span>
|
|
</label>
|
|
|
|
<label class="form-field">
|
|
<span class="field-label">Prefix konta (subdomena) *</span>
|
|
<div style="display:flex;align-items:center;gap:8px;">
|
|
<input class="form-control" type="text" name="account_prefix" maxlength="63" value="<?= $e($prefix) ?>" pattern="[a-z0-9][a-z0-9-]{1,62}" required style="flex:0 0 220px;">
|
|
<span class="muted">.fakturownia.pl</span>
|
|
</div>
|
|
<span class="muted">Maly litery, cyfry, mysliniki. Tak jak w adresie panelu Fakturowni.</span>
|
|
</label>
|
|
|
|
<label class="form-field">
|
|
<span class="field-label">Token API <?= $isNew ? '*' : '' ?></span>
|
|
<input class="form-control" type="password" name="api_token" autocomplete="new-password" placeholder="<?= $hasToken ? '********' : '' ?>" <?= $isNew ? 'required' : '' ?>>
|
|
<span class="muted"><?= $hasToken ? 'Token jest zapisany. Wpisz nowy aby nadpisac.' : 'Token API z Fakturowni (Ustawienia > Konta uzytkownikow > API).' ?></span>
|
|
</label>
|
|
|
|
<label class="form-field">
|
|
<span class="field-label">ID departamentu (opcjonalnie)</span>
|
|
<input class="form-control" type="text" name="department_id" maxlength="64" value="<?= $e($departmentId) ?>">
|
|
</label>
|
|
|
|
<label class="form-field">
|
|
<span class="field-label">Domyslny typ dokumentu</span>
|
|
<select class="form-control" name="default_kind">
|
|
<option value="vat" <?= $defaultKind === 'vat' ? 'selected' : '' ?>>Faktura VAT</option>
|
|
<option value="proforma" <?= $defaultKind === 'proforma' ? 'selected' : '' ?>>Proforma</option>
|
|
<option value="invoice_other" <?= $defaultKind === 'invoice_other' ? 'selected' : '' ?>>Inna</option>
|
|
</select>
|
|
</label>
|
|
|
|
<label class="form-field">
|
|
<span class="field-label">Domyslny termin platnosci (dni)</span>
|
|
<input class="form-control" type="number" name="default_payment_to_days" min="0" max="120" value="<?= $defaultPaymentDays ?>" style="max-width:120px;">
|
|
</label>
|
|
|
|
<label class="form-field">
|
|
<span class="field-label">Status</span>
|
|
<label style="display:inline-flex;align-items:center;gap:8px;">
|
|
<input type="checkbox" name="is_active" value="1" <?= $isActive ? 'checked' : '' ?>>
|
|
Integracja aktywna
|
|
</label>
|
|
</label>
|
|
|
|
<div class="form-actions" style="display:flex;gap:8px;">
|
|
<button type="submit" class="btn btn--primary">Zapisz</button>
|
|
<a class="btn btn--secondary" href="/settings/integrations/fakturownia">Anuluj</a>
|
|
</div>
|
|
</form>
|
|
|
|
<?php if (!$isNew): ?>
|
|
<hr class="mt-16">
|
|
<h3 class="section-title">Test polaczenia</h3>
|
|
<p class="muted">Wykonuje GET <code><?= $e('https://' . ($prefix !== '' ? $prefix : '{prefix}') . '.fakturownia.pl/account.json') ?></code> z zapisanym tokenem.</p>
|
|
<form action="/settings/integrations/fakturownia/test" method="post" style="margin-top:12px;">
|
|
<input type="hidden" name="_token" value="<?= $e($csrfToken ?? '') ?>">
|
|
<input type="hidden" name="id" value="<?= $integrationId ?>">
|
|
<button type="submit" class="btn btn--secondary">Testuj polaczenie</button>
|
|
</form>
|
|
|
|
<?php if ($lastTestAt !== ''): ?>
|
|
<div class="muted mt-12">
|
|
Ostatni test: <strong><?= $e($lastTestAt) ?></strong>
|
|
<?php if ($lastTestStatus !== ''): ?>
|
|
— <strong><?= $e($lastTestStatus) ?></strong>
|
|
<?php endif; ?>
|
|
<?php if ($lastTestMessage !== ''): ?>
|
|
<div><?= $e($lastTestMessage) ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</section>
|