Attributi avanzati FE per documenti

This commit is contained in:
Thomas Zilio 2019-07-15 18:34:59 +02:00
parent 19d87a134b
commit 1556292474
14 changed files with 505 additions and 130 deletions

View File

@ -30,4 +30,4 @@ echo '
</form>';
echo '
<script src="'.ROOTDIR.'/lib/init.js"></script>';
<script src="'.ROOTDIR.'/lib/init.js"></script>';

View File

@ -940,6 +940,73 @@ function openLink(event, link) {
}
}
function start_datepickers() {
var icons = {
time: 'fa fa-clock-o',
date: 'fa fa-calendar',
up: 'fa fa-chevron-up',
down: 'fa fa-chevron-down',
previous: 'fa fa-chevron-left',
next: 'fa fa-chevron-right',
today: 'fa fa-street-view',
clear: 'fa fa-trash',
close: 'fa fa-times'
};
$('.timestamp-picker').each(function () {
$this = $(this);
$this.datetimepicker({
locale: globals.locale,
icons: icons,
collapse: false,
sideBySide: true,
useCurrent: false,
stepping: 5,
widgetPositioning: {
horizontal: 'left',
vertical: 'bottom'
},
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
});
});
//fix per timestamp-picker non visibile con la classe table-responsive
$('.timestamp-picker').each(function () {
$this = $(this);
$this.on("dp.show", function (e) {
$('#tecnici > div').removeClass('table-responsive');
});
$this.on("dp.hide", function (e) {
$('#tecnici > div').addClass('table-responsive');
})
});
$('.datepicker').each(function () {
$this = $(this);
$this.datetimepicker({
locale: globals.locale,
icons: icons,
useCurrent: false,
format: 'L',
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
});
});
$('.timepicker').each(function () {
$this = $(this);
$this.datetimepicker({
locale: globals.locale,
icons: icons,
useCurrent: false,
format: 'LT',
stepping: 5,
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
});
});
}
// Select
function start_superselect() {
// Statico

View File

@ -34,71 +34,7 @@ $(document).ready(function () {
this.$element.removeClass('parsley-success');
});
var icons = {
time: 'fa fa-clock-o',
date: 'fa fa-calendar',
up: 'fa fa-chevron-up',
down: 'fa fa-chevron-down',
previous: 'fa fa-chevron-left',
next: 'fa fa-chevron-right',
today: 'fa fa-street-view',
clear: 'fa fa-trash',
close: 'fa fa-times'
};
$('.timestamp-picker').each(function () {
$this = $(this);
$this.datetimepicker({
locale: globals.locale,
icons: icons,
collapse: false,
sideBySide: true,
useCurrent: false,
stepping: 5,
widgetPositioning: {
horizontal: 'left',
vertical: 'bottom'
},
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
});
});
//fix per timestamp-picker non visibile con la classe table-responsive
$('.timestamp-picker').each(function () {
$this = $(this);
$this.on("dp.show", function (e) {
$('#tecnici > div').removeClass('table-responsive');
});
$this.on("dp.hide", function (e) {
$('#tecnici > div').addClass('table-responsive');
})
});
$('.datepicker').each(function () {
$this = $(this);
$this.datetimepicker({
locale: globals.locale,
icons: icons,
useCurrent: false,
format: 'L',
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
});
});
$('.timepicker').each(function () {
$this = $(this);
$this.datetimepicker({
locale: globals.locale,
icons: icons,
useCurrent: false,
format: 'LT',
stepping: 5,
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
});
});
start_datepickers();
// Aggiunta nell'URL del nome tab su cui tornare dopo il submit
// Blocco del pulsante di submit dopo il primo submit

View File

@ -270,6 +270,61 @@ switch (post('op')) {
}
break;
case 'manage_documento_fe':
$data = Filter::getPOST();
$ignore = [
'id_plugin',
'id_module',
'id_record',
'backto',
'hash',
'op',
'idriga',
'dir',
];
foreach ($ignore as $name) {
unset($data[$name]);
}
$fattura->dati_aggiuntivi_fe = $data;
$fattura->save();
flash()->info(tr('Dati FE aggiornati correttamente!'));
break;
case 'manage_riga_fe':
$id_riga = post('idriga');
if ($id_riga != null) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Descrizione::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
$data = Filter::getPOST();
$ignore = [
'id_plugin',
'id_module',
'id_record',
'backto',
'hash',
'op',
'idriga',
'dir',
];
foreach ($ignore as $name) {
unset($data[$name]);
}
$riga->dati_aggiuntivi_fe = $data;
$riga->save();
flash()->info(tr('Dati FE aggiornati correttamente!'));
}
break;
case 'manage_articolo':
if (post('idriga') != null) {
$articolo = Articolo::find(post('idriga'));
@ -323,36 +378,6 @@ switch (post('op')) {
// Ricalcolo inps, ritenuta e bollo
ricalcola_costiagg_fattura($id_record);
break;
case 'manage_dati_fe':
$id_riga = post('idriga');
if ($id_riga != null) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Descrizione::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
$data = Filter::getPOST();
$ignore = [
'id_plugin',
'id_module',
'id_record',
'backto',
'hash',
'op',
'idriga',
'dir',
];
foreach ($ignore as $name) {
unset($data[$name]);
}
$riga->dati_aggiuntivi_fe = $data;
$riga->save();
flash()->info(tr('Dati FE aggiornati correttamente!'));
}
break;
case 'manage_sconto':

View File

@ -13,6 +13,13 @@ echo '
<i class="fa fa-copy"></i> '.tr('Duplica fattura').'
</button>';
if ($record['stato'] != 'Emessa' && $record['stato'] != 'Parzialmente pagato' && $record['stato'] != 'Pagato') {
echo '
<a class="btn btn-info" data-toggle="modal" data-title="'.tr('Dati Fattura Elettronica').'" data-href="'.$structure->fileurl('fe/document-fe.php').'?id_module='.$id_module.'&id_record='.$id_record.'">
<i class="fa fa-file-code-o"></i> '.tr('Attributi avanzati').'
</a>';
}
if ($dir == 'entrata') {
echo '
<div class="btn-group">
@ -73,4 +80,4 @@ if (!empty($record['is_fiscale'])) {
<?php
}
}
?>
?>

View File

@ -3,7 +3,7 @@
// Altri dati gestionali
echo '
<tr>
<td colspan="2">
<th colspan="2">
'.str_repeat($space, 3).'2.2.1.16 AltriDatiGestionali - '.tr('Riga _NUM_', [
'_NUM_' => $key,
]);
@ -16,7 +16,7 @@ if ($key == 1) {
}
echo '
</td>
</th>
</tr>';
// Tipo Dato
@ -24,7 +24,7 @@ echo '
<tr>
<td style="vertical-align: middle;">'.str_repeat($space, 4).'2.2.1.16.1 TipoDato</td>
<td>
{[ "type": "text", "name": "altri_dati['.$key.'][tipo_dato]", "value": "'.$dato['tipo_dato'].'", "maxlength": 20 ]}
{[ "type": "text", "name": "altri_dati['.$key.'][tipo_dato]", "value": "'.$dato['tipo_dato'].'", "maxlength": 10 ]}
</td>
</tr>';
@ -33,7 +33,7 @@ echo '
<tr>
<td style="vertical-align: middle;">'.str_repeat($space, 4).'2.2.1.16.2 RiferimentoTesto</td>
<td>
{[ "type": "text", "name": "altri_dati['.$key.'][riferimento_testo]", "value": "'.$dato['riferimento_testo'].'", "maxlength": 20 ]}
{[ "type": "text", "name": "altri_dati['.$key.'][riferimento_testo]", "value": "'.$dato['riferimento_testo'].'", "maxlength": 60 ]}
</td>
</tr>';
@ -42,7 +42,7 @@ echo '
<tr>
<td style="vertical-align: middle;">'.str_repeat($space, 4).'2.2.1.16.3 RiferimentoNumero</td>
<td>
{[ "type": "number", "name": "altri_dati['.$key.'][riferimento_numero]", "value": "'.$dato['tipo_dato'].'", "maxlength": 20 ]}
{[ "type": "number", "name": "altri_dati['.$key.'][riferimento_numero]", "value": "'.$dato['tipo_dato'].'" ]}
</td>
</tr>';
@ -51,6 +51,6 @@ echo '
<tr id="last-altri_dati-'.$key.'">
<td style="vertical-align: middle;">'.str_repeat($space, 4).'2.2.1.16.4 RiferimentoData</td>
<td>
{[ "type": "date", "name": "altri_dati['.$key.'][riferimento_data]", "value": "'.$dato['tipo_dato'].'", "maxlength": 20 ]}
{[ "type": "date", "name": "altri_dati['.$key.'][riferimento_data]", "value": "'.$dato['tipo_dato'].'"]}
</td>
</tr>';

View File

@ -0,0 +1,105 @@
<?php
// Altri dati gestionali
echo '
<tr>
<th colspan="2">
'.str_repeat($space, 3).$info['code'].' '.$info['name'].' - '.tr('Riga _NUM_', [
'_NUM_' => $key,
]);
if ($key == 1) {
echo '
<button type="button" class="btn btn-xs btn-info pull-right" onclick="add_blocco(this, \''.$nome.'\')">
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
</button>';
}
echo '
</th>
</tr>';
// RiferimentoNumeroLinea
if (empty($dato['riferimento_linea'])) {
$dato['riferimento_linea'][] = 0;
}
$index = 1;
foreach ($dato['riferimento_linea'] as $linea) {
echo '
<tr title="RiferimentoNumeroLinea-'.$nome.'-'.$key.'">
<td style="vertical-align: middle;">
'.str_repeat($space, 4).$info['code'].'.1 RiferimentoNumeroLinea - '.tr('Riga _NUM_', [
'_NUM_' => $index,
]);
if ($index == 1) {
echo '
<button type="button" class="btn btn-xs btn-info pull-right" onclick="add_riferimento(this, \''.$nome.'\', \''.$key.'\')">
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
</button>';
}
echo '
</td>
<td>
{[ "type": "number", "name": "'.$nome.'['.$key.'][riferimento_linea][]", "value": "'.$linea.'", "maxlength": 4, "decimals": 0 ]}
</td>
</tr>';
++$index;
}
// IdDocumento
echo '
<tr>
<td style="vertical-align: middle;">'.str_repeat($space, 4).$info['code'].'.2 IdDocumento</td>
<td>
{[ "type": "text", "name": "'.$nome.'['.$key.'][id_documento]", "value": "'.$dato['id_documento'].'", "maxlength": 20 ]}
</td>
</tr>';
// Data
echo '
<tr>
<td style="vertical-align: middle;">'.str_repeat($space, 4).$info['code'].'.3 Data</td>
<td>
{[ "type": "date", "name": "'.$nome.'['.$key.'][data]", "value": "'.$dato['data'].'" ]}
</td>
</tr>';
// NumItem
echo '
<tr>
<td style="vertical-align: middle;">'.str_repeat($space, 4).$info['code'].'.4 NumItem</td>
<td>
{[ "type": "text", "name": "'.$nome.'['.$key.'][num_item]", "value": "'.$dato['num_item'].'", "maxlength": 20 ]}
</td>
</tr>';
// CodiceCommessaConvenzione
echo '
<tr>
<td style="vertical-align: middle;">'.str_repeat($space, 4).$info['code'].'.5 CodiceCommessaConvenzione</td>
<td>
{[ "type": "text", "name": "'.$nome.'['.$key.'][codice_commessa]", "value": "'.$dato['codice_commessa'].'", "maxlength": 100 ]}
</td>
</tr>';
// CodiceCUP
echo '
<tr>
<td style="vertical-align: middle;">'.str_repeat($space, 4).$info['code'].'.6 CodiceCUP</td>
<td>
{[ "type": "text", "name": "'.$nome.'['.$key.'][codice_cup]", "value": "'.$dato['codice_cup'].'", "maxlength": 15 ]}
</td>
</tr>';
// CodiceCIG
echo '
<tr id="last-'.$nome.'-'.$key.'">
<td style="vertical-align: middle;">'.str_repeat($space, 4).$info['code'].'.7 CodiceCIG</td>
<td>
{[ "type": "text", "name": "'.$nome.'['.$key.'][codice_cig]", "value": "'.$dato['codice_cig'].'", "maxlength": 15 ]}
</td>
</tr>';

View File

@ -0,0 +1,188 @@
<?php
include_once __DIR__.'/../../../core.php';
use Modules\Fatture\Fattura;
$space = str_repeat('&nbsp;', 6);
$documento = Fattura::find($id_record);
$result = $documento->toArray();
$result = array_merge($result, $documento->dati_aggiuntivi_fe);
echo '
<form action="" method="post">
<input type="hidden" name="op" value="manage_documento_fe">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="id_module" value="'.$id_module.'">
<input type="hidden" name="id_record" value="'.$id_record.'">';
echo '
<table class="table">
<tbody>
<tr>
<th colspan="2">
2 FatturaElettronicaBody
<button type="submit" class="btn btn-primary pull-right">
<i class="fa fa-edit"></i> '.tr('Salva').'
</button>
</th>
</tr>
<tr>
<th colspan="2">'.str_repeat($space, 1).'2.1 DatiGenerali</th>
</tr>
<tr>
<th colspan="2">'.str_repeat($space, 2).'2.1.1 DatiGeneraliDocumento</th>
</tr>';
// Art73
echo '
<tr>
<td style="vertical-align: middle;">'.str_repeat($space, 3).'2.1.1.12 Art73</td>
<td>
{[ "type": "checkbox", "name": "art73", "value": "'.$result['art73'].'", "placeholder": "'.tr("Emesso ai sensi dell'articolo 73 del DPR 633/72").'" ]}
</td>
</tr>';
$documenti = [
'dati_ordine' => [
'code' => '2.1.2',
'name' => 'DatiOrdineAcquisto',
],
'dati_contratto' => [
'code' => '2.1.3',
'name' => 'DatiContratto',
],
'dati_convenzione' => [
'code' => '2.1.4',
'name' => 'DatiConvenzione',
],
'dati_ricezione' => [
'code' => '2.1.5',
'name' => 'DatiRicezione',
],
'dati_fatture' => [
'code' => '2.1.6',
'name' => 'DatiFattureCollegate',
],
];
foreach ($documenti as $nome => $info) {
if (empty($result[$nome])) {
$result[$nome][] = [];
}
$key = 1;
foreach ($result[$nome] as $dato) {
include __DIR__.'/components/dati_documento.php';
++$key;
}
$documenti[$nome]['key'] = $key;
$documenti[$nome]['index'] = $index;
}
echo '
</tbody>
</table>';
echo '
<script>
var keys = {';
foreach ($documenti as $nome => $info) {
echo '
'.$nome.': '.($info['key'] - 1).',';
}
echo '
};
var ref = {';
foreach ($documenti as $nome => $info) {
echo '
'.$nome.($info['key'] - 1).': '.($info['index'] - 1).',';
}
echo '
};
</script>';
foreach ($documenti as $nome => $info) {
echo '
<table class="hide">
<tbody id="'.$nome.'-templace">';
$dato = [];
$key = '-id-';
include __DIR__.'/components/dati_documento.php';
echo '
</tbody>
<tbody id="riferimento_'.$nome.'-templace">
<tr title="RiferimentoNumeroLinea-'.$nome.'--id-">
<td style="vertical-align: middle;">
'.str_repeat($space, 4).$info['code'].'.1 RiferimentoNumeroLinea - '.tr('Riga _NUM_', [
'_NUM_' => '-num-',
]).'
</td>
<td>
{[ "type": "number", "name": "'.$nome.'[-id-][riferimento_linea][]", "value": "", "maxlength": 4, "decimals": 0 ]}
</td>
</tr>
</tbody>
</table>';
}
echo '
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-primary">
<i class="fa fa-edit"></i> '.tr('Salva').'
</button>
</div>
</div>';
echo '
</form>';
echo '
<script>
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, "g"), replace);
}
function add_blocco(btn, nome){
$("#template .superselect, #template .superselectajax").select2().select2("destroy");
var last = $(btn).closest("table").find("tr[id^=last-" + nome + "]").last();
keys[nome]++;
var text = replaceAll($("#" + nome + "-templace").html(), "-id-", "" + keys[nome]);
ref[nome + keys[nome]] = 1;
last.after(text);
start_superselect();
start_datepickers();
}
function add_riferimento(btn, nome, key) {
$("#template .superselect, #template .superselectajax").select2().select2("destroy");
var last = $(btn).closest("table").find("tr[title=RiferimentoNumeroLinea-" + nome + "-" + key + "]").last();
ref[nome + key]++;
var text = replaceAll($("#riferimento_" + nome + "-templace").html(), "-id-", "" + key);
text = replaceAll(text, "-num-", "" + ref[nome + key]);
last.after(text);
start_superselect();
start_datepickers();
}
</script>
<script src="'.ROOTDIR.'/lib/init.js"></script>';

View File

@ -1,5 +1,9 @@
<?php
include_once __DIR__.'/../../../core.php';
use Modules\Fatture\Fattura;
$tipi_cessione_prestazione = [
[
'id' => 'SC',
@ -21,11 +25,32 @@ $tipi_cessione_prestazione = [
$space = str_repeat('&nbsp;', 6);
$documento = Fattura::find($id_record);
// Dati della riga
$id_riga = get('idriga');
$riga = $documento->getRighe()->find($id_riga);
$result = $riga->toArray();
$result = array_merge($result, $riga->dati_aggiuntivi_fe);
echo '
<form action="" method="post">
<input type="hidden" name="op" value="manage_riga_fe">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="id_module" value="'.$id_module.'">
<input type="hidden" name="id_record" value="'.$id_record.'">';
echo '
<table class="table">
<tbody>
<tr>
<th colspan="2">2 FatturaElettronicaBody</th>
<th colspan="2">
2 FatturaElettronicaBody
<button type="submit" class="btn btn-primary pull-right">
<i class="fa fa-edit"></i> '.tr('Salva').'
</button>
</th>
</tr>
<tr>
<th colspan="2">'.str_repeat($space, 1).'2.2 DatiBeniServizi</th>
@ -76,7 +101,7 @@ if (empty($result['altri_dati'])) {
$key = 1;
foreach ($result['altri_dati'] as $dato) {
include __DIR__.'/fe_components/altri_dati.php';
include __DIR__.'/components/altri_dati.php';
++$key;
}
@ -111,8 +136,24 @@ function add_altri_dati(btn){
$dato = [];
$key = '-id-';
include __DIR__.'/fe_components/altri_dati.php';
include __DIR__.'/components/altri_dati.php';
echo '
</tbody>
</table>';
echo '
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-primary">
<i class="fa fa-edit"></i> '.tr('Salva').'
</button>
</div>
</div>';
echo '
</form>';
echo '
<script src="'.ROOTDIR.'/lib/init.js"></script>';

View File

@ -1,23 +0,0 @@
<?php
use Modules\Fatture\Fattura;
include_once __DIR__.'/../../core.php';
$documento = Fattura::find($id_record);
// Impostazioni per la gestione
$options = [
'op' => 'manage_dati_fe',
'action' => 'edit',
'dir' => $documento->direzione,
];
// Dati della riga
$id_riga = get('idriga');
$riga = $documento->getRighe()->find($id_riga);
$result = $riga->toArray();
$result = array_merge($result, $riga->dati_aggiuntivi_fe);
echo App::load('riga_fe.php', $result, $options);

View File

@ -262,7 +262,7 @@ foreach ($righe as $row) {
}
echo "
<a class='btn btn-xs btn-info' data-toggle='modal' data-title='".tr('Dati Fattura Elettronica')."' data-href='".$structure->fileurl('row-fe.php').'?id_module='.$id_module.'&id_record='.$id_record.'&idriga='.$riga['id']."'>
<a class='btn btn-xs btn-info' data-toggle='modal' data-title='".tr('Dati Fattura Elettronica')."' data-href='".$structure->fileurl('fe/row-fe.php').'?id_module='.$id_module.'&id_record='.$id_record.'&idriga='.$riga['id']."'>
<i class='fa fa-file-code-o '></i>
</a>

View File

@ -210,6 +210,29 @@ class Fattura extends Document
return $this->calcola('ritenuta_contributi');
}
/**
* Restituisce i dati aggiuntivi per la fattura elettronica dell'elemento.
*
* @return array
*/
public function getDatiAggiuntiviFEAttribute()
{
$result = json_decode($this->attributes['dati_aggiuntivi_fe'], true);
return (array) $result;
}
/**
* Imposta i dati aggiuntivi per la fattura elettronica dell'elemento.
*/
public function setDatiAggiuntiviFEAttribute($values)
{
$values = (array) $values;
$dati = array_deep_clean($values);
$this->attributes['dati_aggiuntivi_fe'] = json_encode($dati);
}
// Relazioni Eloquent
public function anagrafica()

View File

@ -703,6 +703,10 @@ class FatturaElettronica
}
// Art73 - Ciò consente al cedente/prestatore l'emissione nello stesso anno di più documenti aventi stesso numero (2.1.1.12)
$dati_aggiuntivi = $documento->dati_aggiuntivi_fe;
if (!empty($dati_aggiuntivi['art73'])) {
$result['Art73'] = 'SI';
}
return $result;
}

View File

@ -6,3 +6,5 @@ DELETE FROM `zz_plugins` WHERE `name` = 'Pianificazione ordini di servizio';
ALTER TABLE `co_righe_documenti` ADD `dati_aggiuntivi_fe` TEXT;
UPDATE `co_righe_documenti` SET `dati_aggiuntivi_fe` = CONCAT('{"tipo_cessione_prestazione":"', IFNULL(tipo_cessione_prestazione, ""), '","riferimento_amministrazione":"', IFNULL(riferimento_amministrazione, ""), '","data_inizio_periodo":"', IFNULL(data_inizio_periodo, ""), '","data_fine_periodo":"', IFNULL(data_fine_periodo, ""), '"}');
ALTER TABLE `co_righe_documenti` DROP `tipo_cessione_prestazione`, DROP `riferimento_amministrazione`, DROP `data_inizio_periodo`, DROP `data_fine_periodo`;
ALTER TABLE `co_documenti` ADD `dati_aggiuntivi_fe` TEXT;