Skip to content

Commit 2152643

Browse files
committed
fix: generazione presentazione bancaria raggruppata per scadenza
1 parent c0f11ff commit 2152643

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

plugins/presentazioni_bancarie/src/Gestore.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class Gestore
4343

4444
protected $totale_debito_diretto = 0;
4545

46+
protected $payment_info_by_date_customer = [];
47+
4648
public function __construct(private Anagrafica $azienda, private Banca $banca_azienda)
4749
{
4850
$this->id_riba = random_string();
@@ -369,17 +371,28 @@ public function aggiungiDebitoDirettoSEPA(int $identifier, Anagrafica $contropar
369371

370372
public function aggiungiDebitoDiretto(int $identifier, Anagrafica $controparte, Banca $banca_controparte, string $descrizione, $totale, \DateTime $data_prevista, $method, $codice_sequenza)
371373
{
372-
$paymentInformation = new PaymentInformationCBI();
373-
$paymentInformation
374-
->setCreditorName($this->azienda->ragione_sociale)
375-
->setCreditorIBAN($this->banca_azienda->iban)
376-
->setCreditorId($this->banca_azienda->creditor_id)
377-
->setPaymentInformationIdentification($identifier)
378-
->setRequestedExecutionDate($data_prevista->format('Y-m-d'))
379-
->setLocalMethod($method)
380-
->setServiceLevel('SEPA')
381-
->setSeqType($codice_sequenza != '' ? $codice_sequenza : 'RCUR');
374+
$date_key = $data_prevista->format('Y-m-d');
375+
$customer_key = $controparte->id;
376+
$group_key = $date_key . '_' . $customer_key;
377+
378+
if (!isset($this->payment_info_by_date_customer[$group_key])) {
379+
$paymentInformation = new PaymentInformationCBI();
380+
$paymentInformation
381+
->setCreditorName($this->azienda->ragione_sociale)
382+
->setCreditorIBAN($this->banca_azienda->iban)
383+
->setCreditorId($this->banca_azienda->creditor_id)
384+
->setPaymentInformationIdentification($group_key)
385+
->setRequestedExecutionDate($date_key)
386+
->setLocalMethod($method)
387+
->setServiceLevel('SEPA')
388+
->setSeqType($codice_sequenza != '' ? $codice_sequenza : 'RCUR');
389+
390+
$this->payment_info_by_date_customer[$group_key] = $paymentInformation;
391+
392+
$this->debito_diretto->addPaymentInformation($paymentInformation);
393+
}
382394

395+
$paymentInformation = $this->payment_info_by_date_customer[$group_key];
383396
$mandato = $this->getMandato($banca_controparte);
384397
$payment = new PaymentCBI();
385398
$payment
@@ -394,9 +407,7 @@ public function aggiungiDebitoDiretto(int $identifier, Anagrafica $controparte,
394407

395408
$paymentInformation->addPayments([$payment]);
396409

397-
$this->debito_diretto->addPaymentInformation($paymentInformation);
398410
++$this->numero_transazioni_debito_diretto;
399-
400411
$this->totale_debito_diretto += $totale;
401412

402413
return true;

0 commit comments

Comments
 (0)