Skip to content

Commit 6b56505

Browse files
committed
feat: assegnazione numero progressivo ai ddt in uscita al momento della loro evasione
1 parent a849a2a commit 6b56505

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

modules/ddt/actions.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@
5656
$ddt->idcausalet = post('idcausalet');
5757
$ddt->save();
5858

59-
flash()->info(tr('Aggiunto ddt in _TYPE_ numero _NUM_!', [
59+
flash()->info(tr('Aggiunto ddt in _TYPE_!', [
6060
'_TYPE_' => ($dir == 'entrata' ? 'uscita' : 'entrata'),
61-
'_NUM_' => ($dir == 'entrata' ? $ddt->numero_esterno : $ddt->numero),
6261
]));
6362

6463
break;
@@ -123,18 +122,21 @@
123122

124123
$ddt->setScontoFinale(post('sconto_finale'), post('tipo_sconto_finale'));
125124

126-
$ddt->save();
125+
// Assegna il numero progressivo se il DDT viene evaso
126+
$stato = Stato::find($idstatoddt);
127127

128-
$query = 'SELECT `title` FROM `dt_statiddt` LEFT JOIN `dt_statiddt_lang` ON (`dt_statiddt`.`id` = `dt_statiddt_lang`.`id_record` AND `dt_statiddt_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') WHERE `dt_statiddt`.`id`='.prepare($idstatoddt);
129-
$rs = $dbo->fetchArray($query);
128+
if ($stato->name == 'Evaso' && $dir == 'entrata' && empty($ddt->numero_esterno)) {
129+
$ddt->numero_esterno = DDT::getNextNumeroSecondario($ddt->data, $dir, $ddt->id_segment);
130+
}
131+
$ddt->save();
130132

131-
// Ricalcolo inps, ritenuta e bollo (se l'ddt non è stato evaso)
133+
// Ricalcolo inps, ritenuta e bollo (se il ddt non è stato evaso)
132134
if ($dir == 'entrata') {
133-
if ($rs[0]['descrizione'] != 'Pagato') {
135+
if ($stato->name != 'Pagato') {
134136
ricalcola_costiagg_ddt($id_record);
135137
}
136138
} else {
137-
if ($rs[0]['descrizione'] != 'Pagato') {
139+
if ($stato->name != 'Pagato') {
138140
ricalcola_costiagg_ddt($id_record, $idrivalsainps, $idritenutaacconto, $bollo);
139141
}
140142
}
@@ -578,6 +580,9 @@
578580
$copia->idsede_partenza = $ddt->idsede_partenza;
579581
$copia->idsede_destinazione = $ddt->idsede_destinazione;
580582

583+
// Assegna il numero progressivo poiché il DDT viene creato già evaso
584+
$copia->numero_esterno = DDT::getNextNumeroSecondario($copia->data, $dir, $copia->id_segment);
585+
581586
$copia->save();
582587

583588
// Copia righe
@@ -612,8 +617,9 @@
612617
case 'copy':
613618
$new = $ddt->replicate();
614619

615-
$new->numero = DDT::getNextNumero($new->data, $dir, $ddt->id_segment);
616-
$new->numero_esterno = DDT::getNextNumeroSecondario($new->data, $dir, $new->id_segment);
620+
// Il numero progressivo viene assegnato solo al momento dell'evasione
621+
$new->numero = '';
622+
$new->numero_esterno = '';
617623

618624
$stato = Stato::where('name', 'Bozza')->first()->id;
619625
$new->stato()->associate($stato);

modules/ddt/src/DDT.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,13 @@ public static function build(Anagrafica $anagrafica, Tipo $tipo_documento, $data
139139
$model->idpagamento = $id_pagamento;
140140
}
141141

142-
$model->numero = static::getNextNumero($data, $direzione, $id_segment);
143-
$model->numero_esterno = static::getNextNumeroSecondario($data, $direzione, $id_segment);
144-
142+
if ($direzione == 'entrata') {
143+
$model->numero_esterno = '';
144+
} else {
145+
$model->numero = static::getNextNumero($data, $direzione, $id_segment);
146+
$model->numero_esterno = static::getNextNumeroSecondario($data, $direzione, $id_segment);
147+
}
148+
145149
// Imposto la sede in base alla direzione
146150
$id_sede = self::getSedeUtente($direzione);
147151
if ($direzione == 'entrata') {

0 commit comments

Comments
 (0)