Compilazione IBAN automatica per modulo Banche

This commit is contained in:
Dasc3er 2021-04-26 08:45:52 +02:00
parent aa10ccef1f
commit 364580bc33
7 changed files with 213 additions and 9 deletions

View File

@ -136,7 +136,7 @@ Input.prototype.getElement = function () {
/**
* Gestisce l'abilitazione e la disibilitazione dell'input sulla base del valore indicato.
*
* @param {bool} value
* @param {boolean} value
* @returns {Input}
*/
Input.prototype.setDisabled = function (value) {
@ -215,6 +215,15 @@ Input.prototype.enable = function () {
return this;
}
/**
* Controlla se l'input è disabilitato.
*
* @returns {boolean}
*/
Input.prototype.isDisabled = function () {
return this.element.hasClass("disabled")
}
/**
* Restituisce un oggetto cotentente le caratteristiche dell'input.
*

View File

@ -18,7 +18,9 @@
*/
use Modules\Anagrafiche\Anagrafica;
use Modules\Anagrafiche\Nazione;
use Modules\Banche\Banca;
use Modules\Banche\IBAN;
include_once __DIR__.'/../../core.php';
@ -52,7 +54,6 @@ switch (filter('op')) {
$banca->nome = post('nome');
$banca->iban = post('iban');
$banca->bic = post('bic');
$banca->note = post('note');
$banca->id_pianodeiconti3 = post('id_pianodeiconti3');
@ -75,5 +76,41 @@ switch (filter('op')) {
'_TYPE_' => 'Banca',
]));
break;
case 'compose':
$nazione = Nazione::find(filter('id_nazione'));
$iban = IBAN::generate([
'nation' => $nazione->iso2,
'bank_code' => filter('bank_code'),
'branch_code' => filter('branch_code'),
'account_number' => filter('account_number'),
'check_digits' => filter('check_digits'),
'national_check_digits' => filter('national_check_digits'),
]);
echo json_encode([
'iban' => $iban->getIban(),
]);
break;
case 'decompose':
$iban = new IBAN(filter('iban'));
$nazione = Nazione::where('iso2', '=', $iban->getNation())->first();
echo json_encode([
'id_nazione' => [
'id' => $nazione->id,
'text' => $nazione->nome,
],
'bank_code' => $iban->getBankCode(),
'branch_code' => $iban->getBranchCode(),
'account_number' => $iban->getAccountNumber(),
'check_digits' => $iban->getCheckDigits(),
'national_check_digits' => $iban->getNationalCheckDigits(),
]);
break;
}

View File

@ -58,11 +58,9 @@ include_once __DIR__.'/../../core.php';
<div class="col-md-8">
{[ "type": "text", "label": "<?php echo tr('IBAN'); ?>", "name": "iban", "required": "1", "class": "alphanumeric-mask", "maxlength": 32, "value": "$iban$" ]}
</div>
</div>
<div class="col-md-4">
{[ "type": "text", "label": "<?php echo tr('BIC'); ?>", "name": "bic", "required": "1", "class": "alphanumeric-mask", "maxlength": 11, "value": "$bic$" ]}
</div>
<div class="row">
<div class="col-md-6">
{[ "type": "text", "label": "<?php echo tr('ID Creditore SEPA'); ?>", "name": "creditor_id", "class": "alphanumeric-mask", "value": "$creditor_id$", "help": "<?php echo tr("Codice identificativo per l'azienda nell'area SEPA. Nel caso di aziende aderenti alla procedura Allineamento Elettronico Archivio per le quali non risulta reperibile in CF/PIVA viene generato un codice identificativo non significativo (NOTPROVIDEDXXXXXXXXXXXX)."); ?>" ]}
</div>
@ -79,9 +77,45 @@ include_once __DIR__.'/../../core.php';
</div>
</div>
</div>
</form>
<!-- Composizione IBAN -->
<div class="box box-info">
<div class="box-header">
<h3 class="box-title"><?php echo tr('Composizione IBAN'); ?></h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-md-4">
{[ "type": "select", "label": "<?php echo tr('Nazione'); ?>", "name": "id_nazione", "value": "$id_nazione$", "ajax-source": "nazioni" ]}
</div>
<div class="col-md-4">
{[ "type": "text", "label": "<?php echo tr('Codice banca nazionale (ABI e BIC)'); ?>", "name": "branch_code", "class": "alphanumeric-mask", "value": "$branch_code$" ]}
</div>
<div class="col-md-4">
{[ "type": "text", "label": "<?php echo tr('Codice filiale (CAB)'); ?>", "name": "bank_code", "class": "alphanumeric-mask", "value": "$bank_code$" ]}
</div>
</div>
<div class="row">
<div class="col-md-4">
{[ "type": "text", "label": "<?php echo tr('Numero account'); ?>", "name": "account_number", "class": "alphanumeric-mask", "value": "$account_number$"]}
</div>
<div class="col-md-4">
{[ "type": "text", "label": "<?php echo tr('Cifre di controllo'); ?>", "name": "check_digits", "class": "alphanumeric-mask", "value": "$check_digits$" ]}
</div>
<div class="col-md-4">
{[ "type": "text", "label": "<?php echo tr('Cifre di verifica nazionale'); ?>", "name": "national_check_digits", "class": "alphanumeric-mask", "value": "$national_check_digits$" ]}
</div>
</div>
</div>
</div>
<?php
// Collegamenti diretti (numerici)
$numero_documenti = $dbo->fetchNum('SELECT idanagrafica FROM an_anagrafiche WHERE idbanca_vendite='.prepare($id_record).'
@ -101,3 +135,99 @@ if (!empty($numero_documenti)) {
<a class="btn btn-danger ask" data-backto="record-list">
<i class="fa fa-trash"></i> <?php echo tr('Elimina'); ?>
</a>
<script>
var iban = input("iban");
var branch_code = input("branch_code");
var bank_code = input("bank_code");
var account_number = input("account_number");
var check_digits = input("check_digits");
var national_check_digits = input("national_check_digits");
var id_nazione = input("id_nazione");
var components = [branch_code, bank_code, account_number, check_digits, national_check_digits, id_nazione];
$(document).ready(function (){
iban.trigger("change");
});
iban.change(function () {
if (!iban.isDisabled()){
let value = iban.get();
for (const component of components){
component.setDisabled(value !== "")
}
scomponiIban();
}
});
for (const component of components){
component.change(function () {
let i = input(this);
if (!i.isDisabled()) {
iban.setDisabled(i.get() !== "")
componiIban();
}
});
}
function scomponiIban() {
$.ajax({
url: globals.rootdir + '/actions.php',
data: {
id_module: globals.id_module,
op: "decompose",
iban: iban.get(),
},
type: 'GET',
dataType: "json",
success: function (response) {
compilaCampi(response);
}
});
}
function componiIban() {
// Controllo su campi con valore impostato
let continua = false;
for (const component of components){
continua |= !([undefined, null, ""].includes(component.get()));
}
if (!continua){
return;
}
$.ajax({
url: globals.rootdir + '/actions.php',
data: {
id_module: globals.id_module,
op: "compose",
branch_code: branch_code.get(),
bank_code: bank_code.get(),
account_number: account_number.get(),
check_digits: check_digits.get(),
national_check_digits: national_check_digits.get(),
id_nazione: id_nazione.get(),
},
type: 'GET',
dataType: "json",
success: function (response) {
compilaCampi(response);
}
});
}
function compilaCampi(values) {
for([key, value] of Object.entries(values)) {
if (typeof value === 'object' && value !== null) {
input(key).getElement().selectSetNew(value.id, value.text, value);
} else {
input(key).set(value);
}
}
}
</script>

View File

@ -23,6 +23,7 @@ use Common\SimpleModelTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\Anagrafiche\Anagrafica;
use Modules\Anagrafiche\Nazione;
class Banca extends Model
{
@ -65,6 +66,17 @@ class Banca extends Model
{
$this->fixPredefined();
// Camponenti IBAN
$iban = new IBAN($this->iban);
$nazione = Nazione::where('iso2', '=', $iban->getNation())->first();
$this->id_nazione = $nazione->id;
$this->iban = $iban->getIban();
$this->bank_code = $iban->getBankCode();
$this->branch_code = $iban->getBranchCode();
$this->account_number = $iban->getAccountNumber();
$this->check_digits = $iban->getCheckDigits();
$this->national_check_digits = $iban->getNationalCheckDigits();
return parent::save($options);
}

View File

@ -6,7 +6,7 @@ use UnexpectedValueException;
/**
* Format:
* b = National bank code (Codice ABI)
* b = National bank code (Codice ABI e BIC)
* s = Bank/branch code (sort code, or CAB Codice d'Avviamento Bancario)
* c = Account number
* d = Account type

View File

@ -1,5 +1,6 @@
<?php
use Modules\Banche\Banca;
use Modules\Fatture\Fattura;
use Modules\Fatture\Gestori\Movimenti as GestoreMovimenti;
@ -14,3 +15,9 @@ foreach ($fatture as $fattura) {
$gestore = new GestoreMovimenti($fattura);
$gestore->registra();
}
// Completamento automatico informazioni IBAN per banche
$banche = Banca::all();
foreach ($banche as $banca) {
$banca->save();
}

View File

@ -167,4 +167,13 @@ ALTER TABLE `co_pagamenti` DROP `riba`;
INSERT INTO `zz_group_module` (`idgruppo`, `idmodule`, `name`, `clause`, `position`, `enabled`, `default`) VALUES(4, 31, 'Mostra i contratti ai clienti coivolti', 'co_contratti.idanagrafica=|id_anagrafica|', 'WHR', 1, 1);
-- Fix widget crediti clienti
UPDATE `zz_widgets` SET `query` = 'SELECT \n CONCAT_WS(\' \', REPLACE(REPLACE(REPLACE(FORMAT((\n SELECT SUM(da_pagare-pagato)), 2), \',\', \'#\'), \'.\', \',\'),\'#\', \'.\'), \'&euro;\') AS dato FROM (co_scadenziario INNER JOIN co_documenti ON co_scadenziario.iddocumento=co_documenti.id) INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE co_tipidocumento.dir=\'entrata\' AND co_documenti.idstatodocumento!=1 |segment| AND 1=1' WHERE `zz_widgets`.`name` = 'Crediti da clienti';
UPDATE `zz_widgets` SET `query` = 'SELECT \n CONCAT_WS(\' \', REPLACE(REPLACE(REPLACE(FORMAT((\n SELECT SUM(da_pagare-pagato)), 2), \',\', \'#\'), \'.\', \',\'),\'#\', \'.\'), \'&euro;\') AS dato FROM (co_scadenziario INNER JOIN co_documenti ON co_scadenziario.iddocumento=co_documenti.id) INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE co_tipidocumento.dir=\'entrata\' AND co_documenti.idstatodocumento!=1 |segment| AND 1=1' WHERE `zz_widgets`.`name` = 'Crediti da clienti';
-- Aggiunti campi per componenti IBAN
ALTER TABLE `co_banche` CHANGE `bic` `branch_code` VARCHAR(20) NULL,
ADD `bank_code` VARCHAR(20) NULL,
ADD `account_number` VARCHAR(20) NULL,
ADD `check_digits` VARCHAR(20) NULL,
ADD `national_check_digits` VARCHAR(20) NULL,
ADD `id_nazione` INT(11) NULL,
ADD FOREIGN KEY (`id_nazione`) REFERENCES `an_nazioni`(`id`);