Skip to content

Commit c234d53

Browse files
committed
fix: verifica esigibilità
1 parent a304fa0 commit c234d53

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

plugins/importFE/src/FatturaElettronica.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ public function saveAnagrafica($type = null)
283283
}
284284
}
285285

286+
// Se è un fornitore e la fattura ha EsigibilitaIVA = 'S', abilita lo split payment sull'anagrafica
287+
if ($type === 'Fornitore' && $this->hasSplitPaymentEsigibilita()) {
288+
$anagrafica->split_payment = true;
289+
}
290+
286291
$anagrafica->save();
287292

288293
// Informazioni sulla sede
@@ -343,6 +348,11 @@ public function saveFattura($id_pagamento, $id_sezionale, $id_tipo, $data_regist
343348
$fattura->idpagamento = $id_pagamento;
344349
$fattura->is_ritenuta_pagata = $is_ritenuta_pagata;
345350

351+
// Verifica se è presente EsigibilitaIVA = 'S' nei riepiloghi IVA per abilitare lo split payment
352+
if ($this->hasSplitPaymentEsigibilita()) {
353+
$fattura->split_payment = true;
354+
}
355+
346356
// Salvataggio banca fornitore se specificata nel file XML
347357
$info_pagamento = $this->getBody()['DatiPagamento']['DettaglioPagamento'];
348358
if ($info_pagamento['IBAN']) {
@@ -441,4 +451,31 @@ protected function forceArray($result)
441451

442452
return $result;
443453
}
454+
455+
/**
456+
* Verifica se almeno un riepilogo IVA ha EsigibilitaIVA = 'S' (split payment).
457+
*
458+
* @return bool
459+
*/
460+
protected function hasSplitPaymentEsigibilita()
461+
{
462+
// Estraggo i riepiloghi IVA dal body della fattura
463+
$body = $this->getBody();
464+
465+
if (!isset($body['DatiBeniServizi']['DatiRiepilogo'])) {
466+
return false;
467+
}
468+
469+
$riepiloghi = $body['DatiBeniServizi']['DatiRiepilogo'];
470+
$riepiloghi = $this->forceArray($riepiloghi);
471+
472+
// Verifico se almeno un riepilogo ha EsigibilitaIVA = 'S'
473+
foreach ($riepiloghi as $riepilogo) {
474+
if (isset($riepilogo['EsigibilitaIVA']) && $riepilogo['EsigibilitaIVA'] === 'S') {
475+
return true;
476+
}
477+
}
478+
479+
return false;
480+
}
444481
}

0 commit comments

Comments
 (0)