| 1 | ############################################################################## | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Copyright (C) 2022 Res Binaria Di Paolo Capaldo (<https://www.resbinaria.com/>) | ||||||||||||||||||||||||||||
| 4 | # All Rights Reserved | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # This program is free software: you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 7 | # it under the terms of the GNU Affero General Public License as published | ||||||||||||||||||||||||||||
| 8 | # by the Free Software Foundation, either version 3 of the License, or | ||||||||||||||||||||||||||||
| 9 | # (at your option) any later version. | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||
| 14 | # GNU Affero General Public License for more details. | ||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | # You should have received a copy of the GNU Affero General Public License | ||||||||||||||||||||||||||||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||
| 19 | ############################################################################## | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | package CBI::Wrapper::RIBA; | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use CBI::Wrapper::Record; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use CBI::Wrapper::Disposal; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use CBI::Wrapper::Flow; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # Create a RIBA flow with header, disposals and footer. | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub create_RIBA { | ||||||||||||||||||||||||||
|
Subroutine
create_RIBA: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 0 | my $args = shift; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | my $header = $args->{header}; | |||||||||||||||||||||||||||
| 35 | 0 | my $disposals = $args->{disposals}; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | return unless (defined $header and defined $disposals); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $header and defined $disposals
MC/DC0%0/2
defined $header and defined $disposals
defined $header
defined $disposals
Truth table0%0/3
A and B
A= defined $headerB= defined $disposals
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | my $flow_type = 'RICEVUTE_BANCARIE'; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | my $flow_CBI = new CBI::Wrapper::Flow(); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | my $data_creazione = $header->{data_creazione}; | |||||||||||||||||||||||||||
| 44 | 0 | $data_creazione =~ /\d{2}(\d{2})-(\d{2})-(\d{2})/; | |||||||||||||||||||||||||||
| 45 | 0 | $data_creazione = $3 . $2 . $1; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | my $header_CBI = &_create_record_CBI({ | ||||||||||||||||||||||||||||
| 48 | fields => | ||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | tipo_record => 'IB', | ||||||||||||||||||||||||||||
| 51 | mittente => $header->{mittente}, | ||||||||||||||||||||||||||||
| 52 | ricevente => $header->{ricevente}, | ||||||||||||||||||||||||||||
| 53 | data_creazione => $data_creazione, | ||||||||||||||||||||||||||||
| 54 | nome_supporto => $header->{nome_supporto}, | ||||||||||||||||||||||||||||
| 55 | campo_a_disposizione => $header->{campo_a_disposizione}, | ||||||||||||||||||||||||||||
| 56 | tipo_flusso => $header->{tipo_flusso}, | ||||||||||||||||||||||||||||
| 57 | qualificatore_flusso => $header->{qualificatore_flusso}, | ||||||||||||||||||||||||||||
| 58 | soggetto_veicolatore => $header->{soggetto_veicolatore}, | ||||||||||||||||||||||||||||
| 59 | 0 | codice_divisa => 'E', | |||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||
| 61 | flow_type => $flow_type, | ||||||||||||||||||||||||||||
| 62 | }); | ||||||||||||||||||||||||||||
| 63 | 0 | $flow_CBI->set_header($header_CBI); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # Set disposals and calculate footer values. | ||||||||||||||||||||||||||||
| 66 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 67 | 0 | my $tot_importi_negativi = 0; | |||||||||||||||||||||||||||
| 68 | 0 | my $num_records = 2; # header + footer + num disposals. | |||||||||||||||||||||||||||
| 69 | 0 | for my $disposal (@{$disposals}) { | |||||||||||||||||||||||||||
| 70 | 0 | $i++; | |||||||||||||||||||||||||||
| 71 | 0 | my $disposal_CBI = &_create_disposal_CBI_RIBA( | |||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | header => $header, | ||||||||||||||||||||||||||||
| 74 | disposal => $disposal, | ||||||||||||||||||||||||||||
| 75 | numero_progressivo => $i, | ||||||||||||||||||||||||||||
| 76 | flow_type => $flow_type, | ||||||||||||||||||||||||||||
| 77 | }, | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | 0 | $flow_CBI->append_disposal($disposal_CBI); | |||||||||||||||||||||||||||
| 80 | 0 | $tot_importi_negativi += int((($disposal_CBI->get_record('14'))->get_field_content('importo'))); | |||||||||||||||||||||||||||
| 81 | 0 | $num_records += scalar @{$disposal_CBI->get_records()}; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | my $footer_CBI = &_create_record_CBI({ | ||||||||||||||||||||||||||||
| 85 | fields => | ||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||
| 87 | tipo_record => 'EF', | ||||||||||||||||||||||||||||
| 88 | mittente => $header->{mittente}, | ||||||||||||||||||||||||||||
| 89 | ricevente => $header->{ricevente}, | ||||||||||||||||||||||||||||
| 90 | data_creazione => $data_creazione, | ||||||||||||||||||||||||||||
| 91 | nome_supporto => $header->{nome_supporto}, | ||||||||||||||||||||||||||||
| 92 | numero_disposizioni => $i, | ||||||||||||||||||||||||||||
| 93 | tot_importi_negativi => $tot_importi_negativi, | ||||||||||||||||||||||||||||
| 94 | tot_importi_positivi => 0, | ||||||||||||||||||||||||||||
| 95 | numero_record => $num_records, | ||||||||||||||||||||||||||||
| 96 | codice_divisa => $header->{codice_divisa}, | ||||||||||||||||||||||||||||
| 97 | }, | ||||||||||||||||||||||||||||
| 98 | 0 | flow_type => $flow_type, | |||||||||||||||||||||||||||
| 99 | }); | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | $flow_CBI->set_footer($footer_CBI); | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | return $flow_CBI; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # Create a disposal with records 14, 20, 30, 40, 50, 51, 70. | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub _create_disposal_CBI_RIBA { | ||||||||||||||||||||||||||
|
Subroutine
_create_disposal_CBI_RIBA: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 108 | 0 | my $args = shift; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | my $header = $args->{header}; | |||||||||||||||||||||||||||
| 111 | 0 | my $disposal = $args->{disposal}; | |||||||||||||||||||||||||||
| 112 | 0 | my $num_progressivo = $args->{numero_progressivo}; | |||||||||||||||||||||||||||
| 113 | 0 | my $flow_type = $args->{flow_type}; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | my $disposal_CBI = new CBI::Wrapper::Disposal(); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # Values conversion: | ||||||||||||||||||||||||||||
| 118 | # -> Currency from 0000.00 to 000000 | ||||||||||||||||||||||||||||
| 119 | # -> Date from YYYY-MM-DD to DDMMYYYY | ||||||||||||||||||||||||||||
| 120 | 0 | my $importo = $disposal->{importo} * 100; | |||||||||||||||||||||||||||
| 121 | 0 | my $data = $disposal->{data}; | |||||||||||||||||||||||||||
| 122 | 0 | $data =~ /\d{2}(\d{2})-(\d{2})-(\d{2})/; | |||||||||||||||||||||||||||
| 123 | 0 | $data = $3 . $2 . $1; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | my $record_CBI = &_create_record_CBI({ | ||||||||||||||||||||||||||||
| 126 | fields => | ||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||
| 128 | tipo_record => '14', | ||||||||||||||||||||||||||||
| 129 | numero_progressivo => $num_progressivo, | ||||||||||||||||||||||||||||
| 130 | data_pagamento => $data, | ||||||||||||||||||||||||||||
| 131 | causale => '30000', | ||||||||||||||||||||||||||||
| 132 | importo => $importo, | ||||||||||||||||||||||||||||
| 133 | segno => '-', | ||||||||||||||||||||||||||||
| 134 | codice_abi_banca_assuntrice => $disposal->{cod_abi_banca_assuntrice}, | ||||||||||||||||||||||||||||
| 135 | cab_banca_assuntrice => $disposal->{cab_banca_assuntrice}, | ||||||||||||||||||||||||||||
| 136 | conto => $disposal->{conto}, | ||||||||||||||||||||||||||||
| 137 | codice_abi_banca_domiciliataria => $disposal->{cod_abi_banca_domiciliataria}, | ||||||||||||||||||||||||||||
| 138 | cab_banca_domiciliataria => $disposal->{cab_banca_domiciliataria}, | ||||||||||||||||||||||||||||
| 139 | codice_azienda => $disposal->{cod_azienda}, | ||||||||||||||||||||||||||||
| 140 | tipo_codice => '4', | ||||||||||||||||||||||||||||
| 141 | codice_cliente_debitore => $disposal->{cod_cliente_debitore}, | ||||||||||||||||||||||||||||
| 142 | flag_tipo_debitore => $disposal->{flag_tipo_debitore}, | ||||||||||||||||||||||||||||
| 143 | codice_divisa => $header->{codice_divisa} | ||||||||||||||||||||||||||||
| 144 | }, | ||||||||||||||||||||||||||||
| 145 | 0 | flow_type => $flow_type, | |||||||||||||||||||||||||||
| 146 | }); | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | $disposal_CBI->append_record($record_CBI); | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | $record_CBI = &_create_record_CBI({ | ||||||||||||||||||||||||||||
| 151 | fields => | ||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||
| 153 | tipo_record => '20', | ||||||||||||||||||||||||||||
| 154 | numero_progressivo => $num_progressivo, | ||||||||||||||||||||||||||||
| 155 | '1_segmento' => substr($disposal->{rag_soc_creditore},0,24), | ||||||||||||||||||||||||||||
| 156 | '2_segmento' => length($disposal->{rag_soc_creditore}) > 24 ? substr($disposal->{rag_soc_creditore},24,24) : '', | ||||||||||||||||||||||||||||
| 157 | '3_segmento' => length($disposal->{rag_soc_creditore}) > 48 ? substr($disposal->{rag_soc_creditore},48,24) : '', | ||||||||||||||||||||||||||||
| 158 | 0 | ▶ | '4_segmento' => length($disposal->{rag_soc_creditore}) > 72 ? substr($disposal->{rag_soc_creditore},72,24) : '', | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 159 | }, | ||||||||||||||||||||||||||||
| 160 | flow_type => $flow_type, | ||||||||||||||||||||||||||||
| 161 | }); | ||||||||||||||||||||||||||||
| 162 | 0 | $disposal_CBI->append_record($record_CBI); | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | $record_CBI = &_create_record_CBI({ | ||||||||||||||||||||||||||||
| 165 | fields => | ||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||
| 167 | tipo_record => '30', | ||||||||||||||||||||||||||||
| 168 | numero_progressivo => $num_progressivo, | ||||||||||||||||||||||||||||
| 169 | '1_segmento' => substr($disposal->{nome_debitore},0,30), # Vedi tipo_record 20. | ||||||||||||||||||||||||||||
| 170 | '2_segmento' => length($disposal->{nome_debitore}) > 30 ? substr($disposal->{nome_debitore},30,30) : '', | ||||||||||||||||||||||||||||
| 171 | codice_fiscale_cliente => $disposal->{CF_debitore} | ||||||||||||||||||||||||||||
| 172 | }, | ||||||||||||||||||||||||||||
| 173 | 0 | ▶ | flow_type => $flow_type, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | }); | ||||||||||||||||||||||||||||
| 175 | 0 | $disposal_CBI->append_record($record_CBI); | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | $disposal->{comune_sigla_pv_debitore} =~ s/'//; | |||||||||||||||||||||||||||
| 178 | $record_CBI = &_create_record_CBI({ | ||||||||||||||||||||||||||||
| 179 | fields => | ||||||||||||||||||||||||||||
| 180 | { | ||||||||||||||||||||||||||||
| 181 | tipo_record => '40', | ||||||||||||||||||||||||||||
| 182 | numero_progressivo => $num_progressivo, | ||||||||||||||||||||||||||||
| 183 | 'indirizzo' => $disposal->{indirizzo_debitore}, | ||||||||||||||||||||||||||||
| 184 | 'cap' => $disposal->{cap_debitore}, | ||||||||||||||||||||||||||||
| 185 | 'comune_e_sigla_provincia' => $disposal->{comune_sigla_pv_debitore}, | ||||||||||||||||||||||||||||
| 186 | 'completamento_indirizzo' => $disposal->{compl_indirizzo}, | ||||||||||||||||||||||||||||
| 187 | }, | ||||||||||||||||||||||||||||
| 188 | 0 | flow_type => $flow_type, | |||||||||||||||||||||||||||
| 189 | }); | ||||||||||||||||||||||||||||
| 190 | 0 | $disposal_CBI->append_record($record_CBI); | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | $record_CBI = &_create_record_CBI({ | ||||||||||||||||||||||||||||
| 193 | fields => | ||||||||||||||||||||||||||||
| 194 | { | ||||||||||||||||||||||||||||
| 195 | tipo_record => '50', | ||||||||||||||||||||||||||||
| 196 | numero_progressivo => $num_progressivo, | ||||||||||||||||||||||||||||
| 197 | '1_segmento' => substr($disposal->{descrizione}, 0, 40), # Vedi tipo_record 20. | ||||||||||||||||||||||||||||
| 198 | '2_segmento' => length($disposal->{descrizione}) > 40 ? substr($disposal->{descrizione}, 40, 40) : '', | ||||||||||||||||||||||||||||
| 199 | codifica_fiscale_creditore => $disposal->{PIVA_creditore} | ||||||||||||||||||||||||||||
| 200 | }, | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | flow_type => $flow_type, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | }); | ||||||||||||||||||||||||||||
| 203 | 0 | $disposal_CBI->append_record($record_CBI); | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | $record_CBI = &_create_record_CBI({ | ||||||||||||||||||||||||||||
| 206 | fields => | ||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||
| 208 | tipo_record => '51', | ||||||||||||||||||||||||||||
| 209 | numero_progressivo => $num_progressivo, | ||||||||||||||||||||||||||||
| 210 | numero_ricevuta => $disposal->{numero_ricevuta}, | ||||||||||||||||||||||||||||
| 211 | denominazione_creditore => $disposal->{denom_creditore}, | ||||||||||||||||||||||||||||
| 212 | provincia_bollo => $disposal->{provincia_bollo}, | ||||||||||||||||||||||||||||
| 213 | numero_autorizzazione => $disposal->{num_autorizzazione}, | ||||||||||||||||||||||||||||
| 214 | data_autorizzazione => $disposal->{data_autorizzazione} | ||||||||||||||||||||||||||||
| 215 | }, | ||||||||||||||||||||||||||||
| 216 | 0 | flow_type => $flow_type, | |||||||||||||||||||||||||||
| 217 | }); | ||||||||||||||||||||||||||||
| 218 | 0 | $disposal_CBI->append_record($record_CBI); | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | $record_CBI = &_create_record_CBI({ | ||||||||||||||||||||||||||||
| 221 | fields => | ||||||||||||||||||||||||||||
| 222 | { | ||||||||||||||||||||||||||||
| 223 | tipo_record => '70', | ||||||||||||||||||||||||||||
| 224 | numero_progressivo => $num_progressivo, | ||||||||||||||||||||||||||||
| 225 | indicatori_di_circuito => $disposal->{indicatori_di_circuito}, | ||||||||||||||||||||||||||||
| 226 | indicatore_richiesta_incasso => $disposal->{indicatore_richiesta_incasso}, | ||||||||||||||||||||||||||||
| 227 | chiavi_di_controllo => $disposal->{chiavi_di_controllo} | ||||||||||||||||||||||||||||
| 228 | }, | ||||||||||||||||||||||||||||
| 229 | 0 | flow_type => $flow_type, | |||||||||||||||||||||||||||
| 230 | }); | ||||||||||||||||||||||||||||
| 231 | 0 | $disposal_CBI->append_record($record_CBI); | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | return $disposal_CBI; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | # Single line in the cbi flow. | ||||||||||||||||||||||||||||
| 237 | 0 | ▶ | sub _create_record_CBI { | ||||||||||||||||||||||||||
|
Subroutine
_create_record_CBI: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 238 | 0 | my $args = shift; | |||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 0 | my $fields = $args->{fields}; | |||||||||||||||||||||||||||
| 241 | 0 | my $flow_type = $args->{flow_type}; | |||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | my $record_CBI = new CBI::Wrapper::Record($fields->{tipo_record}, $flow_type); | |||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | for my $key (keys %$fields) { | |||||||||||||||||||||||||||
| 246 | 0 | $record_CBI->set_field_content($key, $fields->{$key}); | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | return $record_CBI; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 1 | 1; | |||||||||||||||||||||||||||