feat(115): wystawianie faktury z zamowienia (lokalne + delegowane Fakturownia)
Phase 115 complete (vertical slice "zamowienie z NIP -> faktura PDF"):
- Task 1: InvoiceRepository + InvoiceService (dual-flow orchestrator) +
InvoiceIssueException + FakturowniaApiClient::createInvoice + buildPdfUrl
- Task 2: InvoiceController + OrdersController::toggleInvoiceRequested +
OrdersRepository::setInvoiceRequested + auto-import invoice_requested z
Allegro (invoice.required) i shopPRO (5-key flexible parser) + show.php
(toggle w zakladce Platnosci + warunkowy przycisk Wystaw fakture)
- Task 3: Lista wystawionych /settings/accounting/invoices/issued z filtrami
+ invoice_preview + invoice_pdf Dompdf template + hub link
- Task 3b (dodany): NIP lookup przez MF Biala Lista (publiczne API, bez
rejestracji) — MfWhitelistApiClient w src/Core/Http/ + /api/nip/lookup +
przycisk "Pobierz z GUS" w formularzu
Auto-fixes podczas smoke testu (5):
- GUS endpoint Fakturowni nie istnial (HTML 404 -> "json is not valid");
switch na MF Biala Liste
- PHP 8.5 curl_close() deprecation wycieka HTML przed JSON; usuniete z
MfWhitelistApiClient i FakturowniaApiClient (3 miejsca)
- Fakturownia 422 payment_to_kind_days (nieistniejace pole) -> usuniete
- Generic "error" w 422 -> parser plaskuje errors: {pole: [...]} +
error_log z 1000 znakow raw body
- Fakturownia security odrzuca seller_*/department_id jako "create new
department"; usuniete z payloadu (Fakturownia uzywa danych konta)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -270,6 +270,12 @@ final class ShopproOrdersSyncService
|
||||
);
|
||||
}
|
||||
|
||||
if ($savedOrderId > 0 && $wasCreated) {
|
||||
if ($this->shouldRequestInvoice($rawOrder)) {
|
||||
$this->orders->setInvoiceRequested($savedOrderId, true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($savedOrderId > 0 && $wasCreated && !$wasPaymentTransition && $this->automationService !== null) {
|
||||
$this->automationService->trigger('order.imported', $savedOrderId, [
|
||||
'source' => 'shoppro',
|
||||
@@ -301,6 +307,36 @@ final class ShopproOrdersSyncService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect "klient prosi o fakture" flag from shopPRO raw payload.
|
||||
* Tries common keys; returns false when none present (manual toggle still possible).
|
||||
*
|
||||
* @param array<string, mixed> $rawOrder
|
||||
*/
|
||||
private function shouldRequestInvoice(array $rawOrder): bool
|
||||
{
|
||||
foreach ([['wants_invoice'], ['invoice_required'], ['invoice', 'required'], ['buyer', 'wants_invoice'], ['buyer', 'invoice']] as $path) {
|
||||
$value = $rawOrder;
|
||||
$found = true;
|
||||
foreach ($path as $key) {
|
||||
if (!is_array($value) || !array_key_exists($key, $value)) {
|
||||
$found = false;
|
||||
break;
|
||||
}
|
||||
$value = $value[$key];
|
||||
}
|
||||
if ($found && (
|
||||
$value === true
|
||||
|| $value === 1
|
||||
|| $value === '1'
|
||||
|| (is_string($value) && in_array(strtolower($value), ['true', 'yes', 'tak'], true))
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $rawIds
|
||||
* @return array<int, true>
|
||||
|
||||
Reference in New Issue
Block a user