Fix Verifactu QR amount

This commit is contained in:
Jonay Marrero 2025-11-25 14:34:12 +00:00
parent 3b4d108160
commit 3484effbab
1 changed files with 18 additions and 1 deletions

View File

@ -196,7 +196,24 @@ class Verifactu extends AbstractService
$nif = $log->nif;
$invoiceNumber = $log->invoice_number;
$date = $log->date->format('d-m-Y');
$total = (string)round($log->invoice->amount, 2);
$totalAmount = $log->invoice->amount;
// Intentar usar el importe que realmente se envió a la AEAT (sin retenciones)
try {
$state = @unserialize($log->state);
if ($state instanceof VerifactuInvoice) {
$stateTotal = $state->getImporteTotal();
if (is_numeric($stateTotal)) {
$totalAmount = (float)$stateTotal;
}
}
} catch (\Throwable $e) {
nlog('VERIFACTU WARNING: [qr-state]' . $e->getMessage());
}
$total = (string)round($totalAmount, 2);
$url = sprintf(
$this->aeat_client->base_qr_url,