mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-26 16:27:47 +01:00
Conversione Componenti Impianti al nuovo formato
Revisione Plugin Componenti precedentemente aggiornato
This commit is contained in:
parent
06eb5f916a
commit
7d21789e85
@ -109,7 +109,8 @@
|
||||
"Plugins\\PianificazioneFatturazione\\": ["plugins/pianificazione_fatturazione/custom/src/", "plugins/pianificazione_fatturazione/src/"],
|
||||
"Plugins\\StatisticheArticoli\\": ["plugins/statistiche_articoli/custom/src/", "plugins/statistiche_articoli/src/"],
|
||||
"Plugins\\ListinoClienti\\": ["plugins/listino_clienti/custom/src/", "plugins/listino_clienti/src/"],
|
||||
"Plugins\\ListinoFornitori\\": ["plugins/listino_fornitori/custom/src/", "plugins/listino_fornitori/src/"]
|
||||
"Plugins\\ListinoFornitori\\": ["plugins/listino_fornitori/custom/src/", "plugins/listino_fornitori/src/"],
|
||||
"Plugins\\ComponentiImpianti\\": ["plugins/componenti/custom/src/", "plugins/componenti/src/"]
|
||||
},
|
||||
"files": [
|
||||
"lib/functions.php",
|
||||
|
@ -74,7 +74,7 @@ if ($module['name'] == 'Interventi') {
|
||||
echo '
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{[ "type": "select", "label": "'.tr('Impianto su cui installare').'", "name": "idimpianto", "value": "'.$idimpianto.'", "ajax-source": "impianti-intervento", "select-options": '.json_encode($options['select-options']['impianti']).' ]}
|
||||
{[ "type": "select", "label": "'.tr('Impianto su cui installare').'", "name": "id_impianto", "value": "", "ajax-source": "impianti-intervento", "select-options": '.json_encode($options['select-options']['impianti']).', "help": "'.tr("La selezione di un Impianto in questo campo provocherà l'installazione di un nuovo Componente basato sull'Articolo corrente").'" ]}
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
||||
* Copyright (C) DevCode s.r.l.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use Util\Ini;
|
||||
|
||||
include_once __DIR__.'/../../../core.php';
|
||||
|
||||
switch ($resource) {
|
||||
/*
|
||||
* Opzioni utilizzate:
|
||||
* - matricola
|
||||
*/
|
||||
case 'componenti':
|
||||
if (isset($superselect['matricola'])) {
|
||||
$query = 'SELECT id, nome AS descrizione, contenuto FROM my_impianto_componenti |where| ORDER BY id';
|
||||
|
||||
foreach ($elements as $element) {
|
||||
$filter[] = 'id='.prepare($element);
|
||||
}
|
||||
|
||||
$temp = [];
|
||||
$impianti = explode(',', $superselect['matricola']);
|
||||
foreach ($impianti as $key => $idimpianto) {
|
||||
$temp[] = 'idimpianto='.prepare($idimpianto);
|
||||
}
|
||||
$where[] = '('.implode(' OR ', $temp).')';
|
||||
|
||||
if (!empty($search)) {
|
||||
$search_fields[] = 'nome LIKE '.prepare('%'.$search.'%');
|
||||
}
|
||||
|
||||
$results = AJAX::selectResults($query, $where, $filter, $search, $limit, $custom);
|
||||
$data = $results['results'];
|
||||
foreach ($data as $key => $value) {
|
||||
$matricola = Ini::getValue($value['contenuto'], 'Matricola');
|
||||
|
||||
$data[$key]['text'] = (empty($matricola) ? '' : $matricola.' - ').$data[$key]['text'];
|
||||
|
||||
unset($data[$key]['contenuto']);
|
||||
}
|
||||
|
||||
$results['results'] = $data;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
@ -77,4 +77,36 @@ switch ($resource) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* Opzioni utilizzate:
|
||||
* - matricola
|
||||
*/
|
||||
case 'componenti':
|
||||
if (isset($superselect['matricola'])) {
|
||||
$query = 'SELECT my_componenti.id, CONCAT("#", my_componenti.id, ": ", mg_articoli.codice, " - ", mg_articoli.descrizione) AS descrizione
|
||||
FROM my_componenti
|
||||
INNER JOIN mg_articoli ON mg_articoli.id = my_componenti.id_articolo
|
||||
|where| ORDER BY my_componenti.id';
|
||||
|
||||
foreach ($elements as $element) {
|
||||
$filter[] = 'my_componenti.id = '.prepare($element);
|
||||
}
|
||||
|
||||
$where = [
|
||||
'my_componenti.data_sostituzione IS NULL',
|
||||
'my_componenti.data_rimozione IS NULL',
|
||||
];
|
||||
|
||||
$impianti = $superselect['matricola'];
|
||||
if (!empty($impianti)){
|
||||
$where[] = 'my_componenti.id_impianto IN ('.$impianti.')';
|
||||
}
|
||||
|
||||
if (!empty($search)) {
|
||||
$search[] = 'my_componenti.note LIKE '.prepare('%'.$search.'%');
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -1,340 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
||||
* Copyright (C) DevCode s.r.l.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use Modules\Interventi\Intervento;
|
||||
use Util\Ini;
|
||||
|
||||
include_once __DIR__.'/../../../core.php';
|
||||
|
||||
switch (filter('op')) {
|
||||
case 'modifica_componente':
|
||||
$idcomponente = get('id');
|
||||
$data = post('data_componente');
|
||||
|
||||
// Ricavo il valore di contenuto leggendolo dal db
|
||||
$query = 'SELECT * FROM my_impianto_componenti WHERE idimpianto='.prepare($id_record).' AND id='.prepare($idcomponente);
|
||||
$rs = $dbo->fetchArray($query);
|
||||
$contenuto = $rs[0]['contenuto'];
|
||||
|
||||
$contenuto = Ini::write($contenuto, $post);
|
||||
|
||||
$query = 'UPDATE my_impianto_componenti SET data='.prepare($data).', contenuto='.prepare($contenuto).' WHERE idimpianto='.prepare($id_record).' AND id='.prepare($idcomponente);
|
||||
$dbo->query($query);
|
||||
|
||||
flash()->info(tr('Informazioni componente aggiornate correttamente!'));
|
||||
|
||||
$_SESSION['idcomponente'] = $idcomponente;
|
||||
break;
|
||||
|
||||
case 'aggiunta_componente':
|
||||
$filename = get('filename');
|
||||
|
||||
if (!empty($filename)) {
|
||||
$contenuto = file_get_contents(base_dir().'/files/impianti/'.$filename);
|
||||
$nome = Ini::getValue(Ini::readFile(base_dir().'/files/impianti/'.$filename), 'Nome');
|
||||
|
||||
$query = 'INSERT INTO my_impianto_componenti(filename, idimpianto, contenuto, nome, data) VALUES('.prepare($filename).', '.prepare($id_record).', '.prepare($contenuto).', '.prepare($nome).', NOW())';
|
||||
$dbo->query($query);
|
||||
|
||||
$idcomponente = $dbo->lastInsertedID();
|
||||
$_SESSION['idcomponente'] = $idcomponente;
|
||||
|
||||
flash()->info(tr("Aggiunto un nuovo componente all'impianto!"));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'sostituzione_componente':
|
||||
$filename = get('filename');
|
||||
$id = get('id');
|
||||
|
||||
$nome = Ini::getValue(Ini::readFile(base_dir().'/files/impianti/'.$filename), 'Nome');
|
||||
$contenuto = file_get_contents(base_dir().'/files/impianti/'.$filename);
|
||||
|
||||
// Verifico che questo componente non sia già stato sostituito
|
||||
$query = 'SELECT * FROM my_impianto_componenti WHERE idsostituto = '.prepare($id);
|
||||
$rs = $dbo->fetchArray($query);
|
||||
|
||||
if (empty($rs)) {
|
||||
// Inserisco il nuovo componente in sostituzione
|
||||
$query = 'INSERT INTO my_impianto_componenti(idsostituto, filename, idimpianto, contenuto, nome, data) VALUES('.prepare($id).', '.prepare($filename).', '.prepare($id_record).', '.prepare($contenuto).', '.prepare($nome).', NOW())';
|
||||
$dbo->query($query);
|
||||
|
||||
$idcomponente = $dbo->lastInsertedID();
|
||||
$_SESSION['idcomponente'] = $idcomponente;
|
||||
|
||||
// Aggiorno la data di sostituzione del componente precedente
|
||||
$query = 'UPDATE my_impianto_componenti SET data_sostituzione = NOW() WHERE idimpianto = '.prepare($id_record).' AND id = '.prepare($id);
|
||||
$dbo->query($query);
|
||||
|
||||
flash()->info(tr('Aggiunto un nuovo componente in sostituzione al precedente!'));
|
||||
} else {
|
||||
flash()->error(tr('Questo componente è già stato sostituito!').' '.('Nessuna modifica applicata'));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'unaggiunta_componente':
|
||||
$idcomponente = filter('id');
|
||||
|
||||
$query = 'DELETE FROM my_impianto_componenti WHERE id='.prepare($idcomponente).' AND idimpianto='.prepare($id_record);
|
||||
$dbo->query($query);
|
||||
|
||||
flash()->info(tr("Rimosso componente dall'impianto!"));
|
||||
break;
|
||||
}
|
||||
|
||||
// Componenti non ancora collegati
|
||||
if (empty($id_list)) {
|
||||
$id_list = '0';
|
||||
}
|
||||
|
||||
echo '
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">'.tr('Componenti installati').'</h3>
|
||||
</div>
|
||||
<div class="box-body">';
|
||||
|
||||
// Elenca i componenti disponibili
|
||||
$componenti_disponibili = Ini::getList(base_dir().'/files/impianti/', $id_list);
|
||||
echo '
|
||||
<div class="row">
|
||||
<div class="col-md-9">
|
||||
<select class="superselect" id="filename" name="filename">';
|
||||
|
||||
if (!empty($componenti_disponibili)) {
|
||||
echo '
|
||||
<option value="0">- '.tr('Aggiungi un componente').' -</option>';
|
||||
foreach ($componenti_disponibili as $componente) {
|
||||
echo '
|
||||
<option value="'.$componente[0].'">'.$componente[1].'</option>';
|
||||
}
|
||||
} else {
|
||||
echo '
|
||||
<option value="0">- '.tr('Hai già aggiunto tutti i componenti').' -</option>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<button type="button" class="btn btn-primary btn-block" onclick="aggiungiComponente()">
|
||||
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix"></div>
|
||||
<br>';
|
||||
|
||||
// Mostro tutti i componenti utilizzati elencando quelli attualmente installati per primi.
|
||||
$q2 = 'SELECT * FROM my_impianto_componenti WHERE idimpianto = '.prepare($id_record).' ORDER by nome ASC, idsostituto DESC';
|
||||
$componenti_installati = $dbo->fetchArray($q2);
|
||||
|
||||
if (!empty($componenti_installati)) {
|
||||
$prev_componente = '';
|
||||
|
||||
echo '
|
||||
<div class="panel-group" id="accordion">';
|
||||
|
||||
// Ciclo tra tutti i componenti
|
||||
foreach ($componenti_installati as $componente) {
|
||||
$contenuto = $componente['contenuto'];
|
||||
|
||||
$nome_componente = $componente['nome'];
|
||||
$filename = $componente['filename'];
|
||||
|
||||
if (empty($componente['data_sostituzione'])) {
|
||||
$stato_componente = tr('INSTALLATO in data _DATE_', [
|
||||
'_DATE_' => dateFormat($componente['data']),
|
||||
]);
|
||||
} else {
|
||||
$stato_componente = tr('SOSTITUITO in data _DATE_', [
|
||||
'_DATE_' => dateFormat($componente['data_sostituzione']),
|
||||
]);
|
||||
}
|
||||
|
||||
// Per più "versioni" dello stesso componente mostro un riga meno evidente
|
||||
// per non confonderlo come componente in uso in questo momento
|
||||
$same = ($prev_componente == $nome_componente);
|
||||
|
||||
if (get('id') == $componente['id']) {
|
||||
$collapsed = '';
|
||||
$icon = 'minus';
|
||||
} elseif ($_SESSION['idcomponente'] == $componente['id']) {
|
||||
unset($_SESSION['idcomponente']);
|
||||
$collapsed = '';
|
||||
$icon = 'minus';
|
||||
} else {
|
||||
$collapsed = 'collapsed-box';
|
||||
$icon = 'plus';
|
||||
}
|
||||
|
||||
echo '
|
||||
<div class="box '.$collapsed.' box-'.($same ? 'default' : 'primary').'">
|
||||
<div class="box-header with-border'.($same ? ' mini' : '').'">
|
||||
<h3 class="box-title'.($same ? ' mini' : '').'">'.
|
||||
($same ? '<small>' : '').$nome_componente.' ('.$stato_componente.')'.($same ? '</small>' : '').'
|
||||
</h3>
|
||||
|
||||
<div class="box-tools pull-right">
|
||||
<button type="button" class="btn btn-box-tool" data-widget="collapse">
|
||||
<i class="fa fa-'.$icon.'"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
echo '
|
||||
<div id="collapse_'.$j.'" class="box-body">
|
||||
<div class="row">
|
||||
<form method="post" action="'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'&op=modifica_componente&id='.$componente['id'].'">
|
||||
<input type="hidden" name="backto" value="record-edit">';
|
||||
|
||||
// Nome
|
||||
echo '
|
||||
<div class="col-md-6">
|
||||
{[ "type": "span", "label": "'.tr('Nome').':", "name": "nome", "value": "'.$componente['nome'].'" ]}
|
||||
</div>';
|
||||
|
||||
// Data
|
||||
echo '
|
||||
<div class="col-md-6">
|
||||
{[ "type": "date", "label": "'.tr('Data').':", "name": "data_componente", "id": "data_componente'.$j.'", "value": "'.$componente['data'].'" ]}
|
||||
</div>';
|
||||
|
||||
// Campi previsti dal componente
|
||||
$fields = Ini::getFields($contenuto);
|
||||
array_shift($fields);
|
||||
foreach ($fields as $field) {
|
||||
echo '
|
||||
<div class="col-md-6">
|
||||
'.$field.'
|
||||
</div>';
|
||||
}
|
||||
|
||||
// Interventi collegati al componente
|
||||
$interventi_collegati = Intervento::join('my_componenti_interventi', 'my_componenti_interventi.id_intervento', '=', 'in_interventi.id')
|
||||
->where('id_componente', $componente['id'])
|
||||
->get();
|
||||
if (!$interventi_collegati->isEmpty()) {
|
||||
echo '
|
||||
<div class="col-md-12">
|
||||
<b>'.tr('Interventi collegati').':</b>
|
||||
<table class="table table-condensed">
|
||||
<tr>
|
||||
<th>'.tr('Codice').'</th>
|
||||
<th>'.tr('Tipo').'</th>
|
||||
<th>'.tr('Stato').'</th>
|
||||
<th>'.tr('Data richiesta').'</th>
|
||||
<th>'.tr('Dettagli').'</th>
|
||||
</tr>';
|
||||
|
||||
foreach ($interventi_collegati as $intervento) {
|
||||
echo '
|
||||
<tr bgcolor="'.$intervento->stato->colore.'">
|
||||
<td>'.$intervento->codice.'</td>
|
||||
<td>'.$intervento->tipo->descrizione.'</td>
|
||||
<td>'.$intervento->stato->descrizione.'</td>
|
||||
<td>'.dateFormat($intervento->data_richiesta).'</td>
|
||||
<td>'.Modules::link('Interventi', $intervento->id, null, '-').'</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</table>
|
||||
</div>';
|
||||
} else {
|
||||
echo '
|
||||
<div class="clearfix"></div>
|
||||
<div class="col-md-12">
|
||||
<div class="alert alert-info">
|
||||
<i class="fa fa-info-circle"></i> '.tr('Nessuna attività collegato a questo componente!').'
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
// Intervento di installazione del componente
|
||||
if (!empty($componente['idintervento'])) {
|
||||
$intervento_origine = Intervento::find($componente['idintervento']);
|
||||
|
||||
echo '
|
||||
'.Modules::link('Interventi', $componente['idintervento'], $intervento_origine->getReference()).'<br>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<div class="clearfix"></div>
|
||||
<br>';
|
||||
|
||||
// Pulsante Salva/Elimina
|
||||
echo '
|
||||
<div class="col-md-12">
|
||||
<a class="btn btn-danger ask" data-backto="record-edit" data-op="unaggiunta_componente" data-id="'.$componente['id'].'"><i class="fa fa-trash"></i> '.tr('Elimina').'</a>';
|
||||
|
||||
// Sostituisci componente con un altro dello stesso tipo, posso sostituire solo i componenti installati
|
||||
if (empty($componente['data_sostituzione'])) {
|
||||
echo '
|
||||
<button type="button" class="btn btn-warning" onclick="sostituisciComponente()">
|
||||
<i class="fa fa-refresh"></i> '.tr('Sostituisci questo componente').'
|
||||
</button>';
|
||||
} else {
|
||||
echo '
|
||||
<button type="button" class="btn btn-warning disabled">
|
||||
'.tr('Componente già sostituito').'
|
||||
</button>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<button type="submit" class="btn btn-success pull-right"><i class="fa fa-check"></i> '.tr('Salva modifiche').'</button>';
|
||||
|
||||
echo '
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
$prev_componente = $nome_componente;
|
||||
}
|
||||
echo '
|
||||
</div>';
|
||||
} else {
|
||||
echo '
|
||||
<div class=\'alert alert-info\' ><i class=\'fa fa-info-circle\'></i> '.tr('Nessun componente inserito').'.</div>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function aggiungiComponente() {
|
||||
if ($("#filename").val() != "0") {
|
||||
redirect("'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'&op=aggiunta_componente&backto=record-edit&filename=" + $("#filename").val() + "&hash=tab_'.$id_plugin.'");
|
||||
} else {
|
||||
alert("'.tr('Seleziona prima un componente').'");
|
||||
$("#filename").focus();
|
||||
}
|
||||
}
|
||||
|
||||
function sostituisciComponente() {
|
||||
if(confirm("'.tr('Vuoi sostituire questo componente con un altro dello stesso tipo?').'")){
|
||||
redirect("'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'&op=sostituzione_componente&backto=record-edit&filename='.$filename.'&id='.$componente['id'].'");
|
||||
}
|
||||
}
|
||||
|
||||
</script>';
|
@ -23,7 +23,7 @@ $matricole = (array) post('matricole');
|
||||
|
||||
// Salvo gli impianti selezionati
|
||||
if (filter('op') == 'link_impianti') {
|
||||
$matricole_old = $dbo->fetchArray('SELECT * FROM my_impianti_interventi WHERE idintervento='.prepare($id_record));
|
||||
$matricole_old = $dbo->fetchArray('SELECT * FROM my_impianti_interventi WHERE idintervento = '.prepare($id_record));
|
||||
$matricole_old = array_column($matricole_old, 'idimpianto');
|
||||
|
||||
// Individuazione delle matricole mancanti
|
||||
@ -31,7 +31,7 @@ if (filter('op') == 'link_impianti') {
|
||||
if (!in_array($matricola, $matricole)) {
|
||||
$dbo->query('DELETE FROM my_impianti_interventi WHERE idintervento='.prepare($id_record).' AND idimpianto = '.prepare($matricola));
|
||||
|
||||
$components = $dbo->fetchArray('SELECT * FROM my_impianto_componenti WHERE idimpianto = '.prepare($matricola));
|
||||
$components = $dbo->fetchArray('SELECT * FROM my_componenti WHERE id_impianto = '.prepare($matricola));
|
||||
if (!empty($components)) {
|
||||
foreach ($components as $component) {
|
||||
$dbo->query('DELETE FROM my_componenti_interventi WHERE id_componente = '.prepare($component['id']).' AND id_intervento = '.prepare($id_record));
|
||||
@ -51,7 +51,7 @@ if (filter('op') == 'link_impianti') {
|
||||
$components = (array) post('componenti');
|
||||
$id_impianto = post('id_impianto');
|
||||
|
||||
$dbo->query('DELETE FROM my_componenti_interventi WHERE id_componente IN (SELECT id FROM my_impianto_componenti WHERE idimpianto = '.prepare($id_impianto).') AND id_intervento = '.prepare($id_record));
|
||||
$dbo->query('DELETE FROM my_componenti_interventi WHERE id_componente IN (SELECT id FROM my_componenti WHERE id_impianto = '.prepare($id_impianto).') AND id_intervento = '.prepare($id_record));
|
||||
|
||||
foreach ($components as $component) {
|
||||
$dbo->query('INSERT INTO my_componenti_interventi(id_componente, id_intervento) VALUES ('.prepare($component).', '.prepare($id_record).')');
|
||||
@ -87,13 +87,13 @@ echo '
|
||||
<div class="row">';
|
||||
foreach ($impianti_collegati as $impianto) {
|
||||
echo '
|
||||
<div class="col-md-3">
|
||||
<div class="col-md-4">
|
||||
<table class="table table-hover table-condensed table-striped">';
|
||||
|
||||
// MATRICOLA
|
||||
echo '
|
||||
<tr>
|
||||
<td class="text-right">'.tr('Matricola').':</td>
|
||||
<td class="text-right" width="25%">'.tr('Matricola').':</td>
|
||||
<td valign="top">'.$impianto['matricola'].'</td>
|
||||
</tr>';
|
||||
|
||||
@ -135,7 +135,9 @@ foreach ($impianti_collegati as $impianto) {
|
||||
|
||||
{[ "type": "select", "label": "'.tr('Componenti').'", "multiple": 1, "name": "componenti[]", "id": "componenti_'.$impianto['id'].'", "ajax-source": "componenti", "select-options": {"matricola": '.$impianto['id'].'}, "value": "'.implode(',', $ids).'", "readonly": "'.!empty($readonly).'", "disabled": "'.!empty($disabled).'" ]}
|
||||
|
||||
<button type="submit" class="btn btn-success" '.$disabled.'><i class="fa fa-check"></i> '.tr('Salva componenti').'</button>
|
||||
<button type="submit" class="btn btn-success" '.$disabled.'>
|
||||
<i class="fa fa-check"></i> '.tr('Salva componenti').'
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -23,6 +23,7 @@ use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Articoli\Articolo as ArticoloOriginale;
|
||||
use Modules\Emails\Mail;
|
||||
use Modules\Emails\Template;
|
||||
use Modules\Impianti\Impianto;
|
||||
use Modules\Interventi\Components\Articolo;
|
||||
use Modules\Interventi\Components\Riga;
|
||||
use Modules\Interventi\Components\Sconto;
|
||||
@ -30,6 +31,7 @@ use Modules\Interventi\Components\Sessione;
|
||||
use Modules\Interventi\Intervento;
|
||||
use Modules\Interventi\Stato;
|
||||
use Modules\TipiIntervento\Tipo as TipoSessione;
|
||||
use Plugins\ComponentiImpianti\Componente;
|
||||
use Plugins\PianificazioneInterventi\Promemoria;
|
||||
|
||||
switch (post('op')) {
|
||||
@ -228,7 +230,7 @@ switch (post('op')) {
|
||||
$intervento->delete();
|
||||
|
||||
// Elimino il collegamento al componente
|
||||
$dbo->query('DELETE FROM my_impianto_componenti WHERE idintervento='.prepare($id_record));
|
||||
$dbo->query('DELETE FROM my_componenti WHERE idintervento='.prepare($id_record));
|
||||
|
||||
// Eliminazione associazione tecnici collegati all'intervento
|
||||
$dbo->query('DELETE FROM in_interventi_tecnici WHERE idintervento='.prepare($id_record));
|
||||
@ -331,8 +333,18 @@ switch (post('op')) {
|
||||
flash()->info(tr('Articolo aggiunto!'));
|
||||
}
|
||||
|
||||
// Collegamento all'impianto
|
||||
link_componente_to_articolo($id_record, post('idimpianto'), $articolo->idarticolo, $qta);
|
||||
// Collegamento all'Impianto tramite generazione Componente
|
||||
$id_impianto = post('id_impianto');
|
||||
$impianto = Impianto::find($id_impianto);
|
||||
if (!empty($impianto)){
|
||||
// Data di inizio dell'intervento (data_richiesta in caso di assenza di sessioni)
|
||||
$data_registrazione = $intervento->inizio ?: $intervento->data_richiesta;
|
||||
|
||||
// Creazione in base alla quantità
|
||||
for ($q = 0; $q < $articolo->qta; ++$q) {
|
||||
$componente = Componente::build($impianto, $articolo->articolo, $data_registrazione);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
@ -52,6 +52,8 @@ function get_ore_intervento($id_intervento)
|
||||
* @param int $id_impianto
|
||||
* @param int $id_articolo
|
||||
* @param int $qta
|
||||
*
|
||||
* @deprecated 2.4.25
|
||||
*/
|
||||
function link_componente_to_articolo($id_intervento, $id_impianto, $id_articolo, $qta)
|
||||
{
|
||||
|
@ -68,7 +68,9 @@ if (!empty($results)) {
|
||||
</table>';
|
||||
} else {
|
||||
echo '
|
||||
<div class=\'alert alert-info\' ><i class=\'fa fa-info-circle\'></i> '.tr('Nessun intervento su questo impianto').'.</div>';
|
||||
<div class="alert alert-info">
|
||||
<i class="fa fa-info-circle"></i> '.tr('Nessun intervento su questo impianto').'.
|
||||
</div>';
|
||||
}
|
||||
|
||||
echo '
|
||||
|
@ -66,7 +66,7 @@ switch (filter('op')) {
|
||||
|
||||
$destinatari = $newsletter->destinatari();
|
||||
$count = $destinatari->count();
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$destinatario = $destinatari->skip($i)->first();
|
||||
$origine = $destinatario->getOrigine();
|
||||
|
||||
|
@ -20,105 +20,69 @@
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Modules\Articoli\Articolo;
|
||||
use Modules\Impianti\Impianto;
|
||||
use Plugins\ComponentiImpianti\Componente;
|
||||
|
||||
$operazione = filter('op');
|
||||
|
||||
switch ($operazione) {
|
||||
case 'update':
|
||||
$articolo = (array) post('id_articolo');
|
||||
$data_installazione = (array) post('data_installazione');
|
||||
$data_disinstallazione = (array) post('data_disinstallazione');
|
||||
$data_registrazione = (array) post('data_registrazione');
|
||||
$note = (array) post('note');
|
||||
case 'add':
|
||||
$impianto = Impianto::find($id_record);
|
||||
|
||||
$key = key($articolo);
|
||||
$id_articolo = filter('id_articolo');
|
||||
$articolo = Articolo::find($id_articolo);
|
||||
|
||||
if (post('sostituito')) {
|
||||
$field_articolo = 'pre_id_articolo';
|
||||
} else {
|
||||
$field_articolo = 'id_articolo';
|
||||
}
|
||||
|
||||
$dbo->update('my_componenti_articoli', [
|
||||
$field_articolo => $articolo[$key],
|
||||
'data_installazione' => $data_installazione[$key] ?: null,
|
||||
'data_disinstallazione' => $data_disinstallazione[$key] ?: null,
|
||||
'data_registrazione' => $data_registrazione[$key] ?: null,
|
||||
'note' => $note[$key],
|
||||
], ['id' => $key]);
|
||||
$componente = Componente::build($impianto, $articolo, new Carbon());
|
||||
|
||||
flash()->info(tr('Salvataggio completato!'));
|
||||
$dbo->commitTransaction();
|
||||
header('Location: '.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'#tab_'.$id_plugin);
|
||||
exit;
|
||||
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
$dbo->insert('my_componenti_articoli', [
|
||||
'id_impianto' => $id_record,
|
||||
'data_registrazione' => Carbon::now(),
|
||||
'id_articolo' => post('id_articolo'),
|
||||
]);
|
||||
case 'update':
|
||||
$id_componente = filter('id_componente');
|
||||
$componente = Componente::find($id_componente);
|
||||
|
||||
$componente->data_registrazione = filter('data_registrazione') ?: null;
|
||||
$componente->data_installazione = filter('data_installazione') ?: null;
|
||||
$componente->data_rimozione = filter('data_rimozione') ?: null;
|
||||
$componente->note = filter('note') ?: null;
|
||||
|
||||
$componente->save();
|
||||
|
||||
flash()->info(tr('Salvataggio completato!'));
|
||||
|
||||
break;
|
||||
|
||||
case 'sostituisci':
|
||||
$old_id = get('id_old');
|
||||
$old = $dbo->selectOne('my_componenti_articoli', '*', ['id' => $old_id]);
|
||||
$id_componente = filter('id_componente');
|
||||
$componente = Componente::find($id_componente);
|
||||
|
||||
if (!empty($old['id_articolo'])) {
|
||||
if (empty($old['data_disinstallazione'])) {
|
||||
$data = Carbon::now();
|
||||
} else {
|
||||
$data = $old['data_disinstallazione'];
|
||||
}
|
||||
// Creazione copia del componenten
|
||||
$copia = $componente->replicate();
|
||||
$copia->data_registrazione = new Carbon();
|
||||
$copia->data_installazione = new Carbon();
|
||||
$copia->data_sostituzione = null;
|
||||
$copia->data_rimozione = null;
|
||||
// Rimozione riferimento intervento di installazione
|
||||
$copia->id_intervento = null;
|
||||
$copia->save();
|
||||
|
||||
$dbo->update('my_componenti_articoli', [
|
||||
'pre_id_articolo' => $old['id_articolo'],
|
||||
'id_articolo' => 0,
|
||||
'data_disinstallazione' => $data,
|
||||
], [
|
||||
'id' => $old_id,
|
||||
]);
|
||||
// Sostituzione del componente indicato
|
||||
$componente->data_sostituzione = new Carbon();
|
||||
$componente->id_sostituzione = $copia->id;
|
||||
$componente->save();
|
||||
|
||||
$dbo->query('CREATE TEMPORARY TABLE tmp SELECT * FROM my_componenti_articoli WHERE id= '.prepare($old_id));
|
||||
$dbo->query('ALTER TABLE tmp DROP id');
|
||||
$dbo->query('INSERT INTO my_componenti_articoli SELECT NULL,tmp. * FROM tmp');
|
||||
$new_id = $dbo->lastInsertedID();
|
||||
$dbo->query('DROP TEMPORARY TABLE tmp');
|
||||
|
||||
$dbo->update('my_componenti_articoli', [
|
||||
'id_articolo' => $old['id_articolo'],
|
||||
'pre_id_articolo' => 0,
|
||||
'data_registrazione' => Carbon::now(),
|
||||
'data_installazione' => $data,
|
||||
'data_disinstallazione' => null,
|
||||
], [
|
||||
'id' => $new_id,
|
||||
]);
|
||||
|
||||
flash()->info(tr('Informazioni salvate correttamente!'));
|
||||
} else {
|
||||
flash()->warning(tr('Inserire un articolo prima di effettuare la sostituzione!'));
|
||||
}
|
||||
|
||||
$dbo->commitTransaction();
|
||||
header('Location: '.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'#tab_'.$id_plugin);
|
||||
exit;
|
||||
flash()->info(tr('Informazioni salvate correttamente!'));
|
||||
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$dbo->query('DELETE FROM my_componenti_articoli WHERE id='.prepare(get('id')));
|
||||
case 'rimuovi':
|
||||
$id_componente = filter('id_componente');
|
||||
$componente = Componente::find($id_componente);
|
||||
|
||||
flash()->info(tr('Componente eliminato!'));
|
||||
|
||||
$dbo->commitTransaction();
|
||||
header('Location: '.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'#tab_'.$id_plugin);
|
||||
exit;
|
||||
$componente->data_rimozione = new Carbon();
|
||||
$componente->save();
|
||||
|
||||
flash()->info(tr('Componente rimosso!'));
|
||||
break;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ echo '
|
||||
<input type="hidden" name="op" value="add">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-12">
|
||||
{["type": "select", "label": "'.tr('Articolo').'", "name": "id_articolo", "ajax-source": "articoli", "value": "", "required": 1, "select-options": {"permetti_movimento_a_zero": 1} ]}
|
||||
</div>
|
||||
</div>
|
||||
@ -34,7 +34,9 @@ echo '
|
||||
<!-- PULSANTI -->
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right">
|
||||
<button type="submit" class="btn btn-primary"><i class="fa fa-plus"></i> '.tr('Aggiungi').'</button>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>';
|
||||
|
@ -17,177 +17,235 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use Models\Plugin;
|
||||
use Plugins\ComponentiImpianti\Componente;
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
echo '<hr>';
|
||||
$compontenti_impianto = Componente::where('id_impianto', '=', $id_record);
|
||||
|
||||
$componenti = $dbo->fetchArray('SELECT my_componenti_articoli.*, my_impianti.idanagrafica, CONCAT(a.codice, " - ", a.descrizione) AS art_sostituito, CONCAT(b.codice, " - ", b.descrizione) AS art_installato, a.codice FROM my_componenti_articoli LEFT JOIN my_impianti ON my_componenti_articoli.id_impianto=my_impianti.id LEFT JOIN mg_articoli AS a ON my_componenti_articoli.pre_id_articolo=a.id LEFT JOIN mg_articoli AS b ON my_componenti_articoli.id_articolo=b.id WHERE id_impianto='.prepare($id_record).' ORDER BY data_registrazione, id_articolo DESC');
|
||||
$componenti_installati = (clone $compontenti_impianto)
|
||||
->whereNull('data_sostituzione')
|
||||
->whereNull('data_rimozione')
|
||||
->get();
|
||||
$componenti_sostituiti = (clone $compontenti_impianto)
|
||||
->whereNotNull('data_sostituzione')
|
||||
->get();
|
||||
$componenti_rimossi = (clone $compontenti_impianto)
|
||||
->whereNotNull('data_rimozione')
|
||||
->get();
|
||||
|
||||
$installati = 0;
|
||||
$disinstallati = 0;
|
||||
echo generaListaComponenti($componenti_installati, [
|
||||
'type' => 'primary',
|
||||
'title' => tr('Componenti installati'),
|
||||
'date' => 'data_installazione',
|
||||
'date_name' => tr('Installato'),
|
||||
]);
|
||||
|
||||
foreach ($componenti as $componente) {
|
||||
if (!empty($componente['pre_id_articolo'])) {
|
||||
$id_articolo = $componente['pre_id_articolo'];
|
||||
$check_value = 1;
|
||||
$box = 'danger';
|
||||
$articolo = $componente['art_sostituito'];
|
||||
$data = dateFormat($componente['data_disinstallazione']);
|
||||
$text = 'DISINSTALLATO';
|
||||
$class = 'danger';
|
||||
$title = ''.tr('Storico').'';
|
||||
$table = 'default';
|
||||
if ($disinstallati == 0) {
|
||||
echo '
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-center">
|
||||
<h4 class="text-danger">ARTICOLI DISINSTALLATI</h4>
|
||||
</div>
|
||||
</div>
|
||||
<hr>';
|
||||
++$disinstallati;
|
||||
}
|
||||
} else {
|
||||
$id_articolo = $componente['id_articolo'];
|
||||
$check_value = 0;
|
||||
$box = 'primary';
|
||||
$articolo = $componente['art_installato'];
|
||||
$data = dateFormat($componente['data_installazione']);
|
||||
$text = 'INSTALLATO';
|
||||
$class = 'primary';
|
||||
$title = ''.tr('Dati').'';
|
||||
$table = 'primary';
|
||||
if ($installati == 0) {
|
||||
echo '
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-center">
|
||||
<h4 class="text-blue">ARTICOLI INSTALLATI</h4>
|
||||
</div>
|
||||
</div>
|
||||
<hr>';
|
||||
++$installati;
|
||||
}
|
||||
}
|
||||
echo generaListaComponenti($componenti_sostituiti, [
|
||||
'type' => 'warning',
|
||||
'title' => tr('Componenti sostituiti'),
|
||||
'date' => 'data_sostituzione',
|
||||
'date_name' => tr('Sostituzione'),
|
||||
]);
|
||||
|
||||
$allegati = $dbo->fetchOne('SELECT COUNT(id) AS num FROM zz_files WHERE id_plugin='.prepare($id_plugin).' AND id_record='.$componente['id'].' GROUP BY id_record')['num'];
|
||||
echo generaListaComponenti($componenti_rimossi, [
|
||||
'type' => 'danger',
|
||||
'title' => tr('Componenti rimossi'),
|
||||
'date' => 'data_rimozione',
|
||||
'date_name' => tr('Rimosso'),
|
||||
]);
|
||||
|
||||
if ($allegati) {
|
||||
$icon = 'fa fa-check text-success';
|
||||
} else {
|
||||
$icon = 'fa fa-times text-danger';
|
||||
function generaListaComponenti($componenti, $options)
|
||||
{
|
||||
$type = $options['type'];
|
||||
$title = $options['title'];
|
||||
$date = $options['date'];
|
||||
$date_name = $options['date_name'];
|
||||
|
||||
$database = database();
|
||||
$plugin = Plugin::pool('Componenti');
|
||||
$module = $plugin->module;
|
||||
|
||||
if (empty($componenti) || $componenti->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '
|
||||
<form action="'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'" method="post" role="form">
|
||||
<input type="hidden" name="id_plugin" value="'.$id_plugin.'">
|
||||
<input type="hidden" name="id_record" value="'.$id_record.'">
|
||||
<input type="hidden" name="sostituito" value="'.$check_value.'">
|
||||
<input type="hidden" name="backto" value="record-edit">
|
||||
<input type="hidden" name="op" value="update">
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-center">
|
||||
<h4 class="text-'.$type.'">'.$title.'</h4>
|
||||
</div>
|
||||
</div>
|
||||
<hr>';
|
||||
|
||||
echo '
|
||||
<div class="box collapsed-box box-'.$type.'">
|
||||
<div class="box-header with-border mini">
|
||||
<table class="table" style="margin:0; padding:0;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">'.tr('ID', [], ['upper' => true]).'</td>
|
||||
<th class="text-center">'.tr('Articolo', [], ['upper' => true]).'</td>
|
||||
<th class="text-center" width="20%">'.tr($date_name, [], ['upper' => true]).'</th>
|
||||
<th class="text-center" width="20%">'.tr('Registrazione', [], ['upper' => true]).'</th>
|
||||
<th class="text-center" width="10%">'.tr('Allegati', [], ['upper' => true]).'</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<div class="panel-group" id="accordion">
|
||||
<div class="box collapsed-box box-'.$box.'">
|
||||
<div class="box-header with-border mini">
|
||||
<small class="text-'.$class.'">
|
||||
<table class="table" style="margin:0; padding:0;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">'.tr('ARTICOLO').'</td>
|
||||
<th class="text-center" width="20%">'.$text.'</th>
|
||||
<th class="text-center" width="20%">'.tr('REGISTRAZIONE').'</th>
|
||||
<th class="text-center" width="10%">'.tr('ALLEGATI').'</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-center">'.$articolo.'</td>
|
||||
<td class="text-center">'.$data.'</td>
|
||||
<td class="text-center">'.dateFormat($componente['data_registrazione']).'</td>
|
||||
<td class="text-center"><i class="'.$icon.' fa-lg"></i></td>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</small>
|
||||
<tbody>';
|
||||
|
||||
<div class="box-tools pull-right">
|
||||
<button type="button" class="btn btn-box-tool" data-widget="collapse">
|
||||
<i class="fa fa-plus"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="collapse_'.$j.'" class="box-body">
|
||||
<div class="panel panel-'.$table.'">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">'.$title.'</h3>
|
||||
</div>
|
||||
|
||||
foreach ($componenti as $componente) {
|
||||
$articolo = $componente->articolo;
|
||||
$numero_allegati = $database->fetchNum('SELECT id FROM zz_files WHERE id_plugin='.prepare($id_plugin).' AND id_record='.$componente['id'].' GROUP BY id_record');
|
||||
|
||||
<div class="panel-body">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
{[ "type":"select","label":"'.tr('Articolo').'","name":"id_articolo['.$componente['id'].']", "required":"1","value":"'.$id_articolo.'", "ajax-source": "articoli", "select-options": {"permetti_movimento_a_zero": 1} ]}
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
{[ "type":"date","label":"'.tr('Data registrazione').'","name":"data_registrazione['.$componente['id'].']", "value":"'.$componente['data_registrazione'].'" ]}
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
{[ "type":"date","label":"'.tr('Data installazione').'","name":"data_installazione['.$componente['id'].']", "value":"'.$componente['data_installazione'].'" ]}
|
||||
</div>
|
||||
$data = dateFormat($componente[$date]);
|
||||
$icona_allegati = $numero_allegati == 0 ? 'fa fa-times text-danger' : 'fa fa-check text-success';
|
||||
|
||||
<div class="col-md-2">
|
||||
{[ "type":"date","label":"'.tr('Data disinstallazione').'","name":"data_disinstallazione['.$componente['id'].']", "value":"'.$componente['data_disinstallazione'].'" ]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{[ "type":"textarea","label":"'.tr('Note').'","name":"note['.$componente['id'].']", "value":"'.$componente['note'].'" ]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PULSANTI -->
|
||||
<div class="row">
|
||||
<div class="col-md-1">
|
||||
<button type="button" class="btn btn-danger" onclick="elimina('.$componente['id'].')"><i class="fa fa-trash"></i> '.tr('Elimina').'</button>
|
||||
</div>
|
||||
<div class="col-md-1">
|
||||
<a onclick="openModal(\'Aggiungi file\', \''.$structure->fileurl('allegati.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'id_record='.$id_record.'&id='.$componente['id'].'\');" class="btn btn-default">
|
||||
<i class="fa fa-file-text-o"></i> '.tr('Allegati _NUM_', [
|
||||
'_NUM_' => $allegati,
|
||||
]).'
|
||||
</a>
|
||||
</div>';
|
||||
|
||||
if (!empty($componente['id_articolo'])) {
|
||||
echo '
|
||||
<div class="col-md-9">
|
||||
<button type="button" class="btn btn-warning pull-right" onclick="sostituisci('.$componente['id'].')"><i class="fa fa-cog"></i> '.tr('Sostituisci').'</button>
|
||||
</div>';
|
||||
}
|
||||
echo '
|
||||
<div class="col-md-1 pull-right">
|
||||
<button type="submit" class="btn btn-success pull-right"><i class="fa fa-check"></i> '.tr('Salva').'</button>
|
||||
</div>
|
||||
<tr class="riga-componente" data-id="'.$componente->id.'">
|
||||
<td class="text-center">#'.$componente->id.'</td>
|
||||
<td class="text-center">'.$articolo->codice.' - '.$articolo->descrizione.'</td>
|
||||
<td class="text-center">'.$data.'</td>
|
||||
<td class="text-center">'.dateFormat($componente->data_registrazione).'</td>
|
||||
<td class="text-center">
|
||||
<i class="'.$icona_allegati.' fa-lg"></i>
|
||||
|
||||
<div class="box-tools pull-right">
|
||||
<button type="button" class="btn btn-box-tool" onclick="toggleDettagli(this)">
|
||||
<i class="fa fa-plus"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="dettagli-componente" data-id="'.$componente->id.'" style="display: none">
|
||||
<td colspan="4">
|
||||
<div class="panel panel-'.$type.'">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">'.tr('Dati').'</h3>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
<form action="'.base_path().'/editor.php" method="post" role="form">
|
||||
<input type="hidden" name="id_module" value="'.$module->id.'">
|
||||
<input type="hidden" name="id_record" value="'.$componente->id_impianto.'">
|
||||
<input type="hidden" name="id_plugin" value="'.$plugin->id.'">
|
||||
|
||||
<input type="hidden" name="id_componente" value="'.$componente->id.'">
|
||||
<input type="hidden" name="backto" value="record-edit">
|
||||
<input type="hidden" name="op" value="update">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
{[ "type": "select", "label": "'.tr('Articolo').'", "name": "id_articolo", "id": "id_articolo_'.$componente->id.'", "disabled": "1", "value": "'.$componente->id_articolo.'", "ajax-source": "articoli", "select-options": {"permetti_movimento_a_zero": 1} ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
{[ "type": "date", "label": "'.tr('Data registrazione').'", "name": "data_registrazione", "id": "data_registrazione_'.$componente->id.'", "value": "'.$componente['data_registrazione'].'" ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
{[ "type": "date", "label": "'.tr('Data installazione').'", "name": "data_installazione", "id": "data_installazione_'.$componente->id.'", "value": "'.$componente['data_installazione'].'" ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
{[ "type": "date", "label": "'.tr('Data rimozione').'", "name": "data_rimozione", "id": "data_rimozione_'.$componente->id.'", "value": "'.$componente['data_rimozione'].'" ]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{[ "type": "ckeditor", "label": "'.tr('Note').'", "name": "note", "id": "note_'.$componente->id.'", "value": "'.$componente['note'].'" ]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PULSANTI -->
|
||||
<div class="row">';
|
||||
if (empty($componente->id_sostituzione)) {
|
||||
echo '
|
||||
<div class="col-md-1">
|
||||
<button type="button" class="btn btn-danger" onclick="rimuoviComponente(this)">
|
||||
<i class="fa fa-trash"></i> '.tr('Rimuovi').'
|
||||
</button>
|
||||
</div>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<div class="col-md-1">
|
||||
<button type="button" class="btn btn-default" onclick="gestisciAllegati(this)">
|
||||
<i class="fa fa-file-text-o"></i> '.tr('Allegati (_NUM_)', [
|
||||
'_NUM_' => $numero_allegati,
|
||||
]).'
|
||||
</button>
|
||||
</div>';
|
||||
|
||||
if (empty($componente->id_sostituzione)) {
|
||||
echo '
|
||||
<div class="col-md-9">
|
||||
<button type="button" class="btn btn-warning pull-right" onclick="sostituisciComponente(this)">
|
||||
<i class="fa fa-cog"></i> '.tr('Sostituisci').'
|
||||
</button>
|
||||
</div>';
|
||||
}
|
||||
echo '
|
||||
<div class="col-md-1 pull-right">
|
||||
<button type="submit" class="btn btn-success pull-right">
|
||||
<i class="fa fa-check"></i> '.tr('Salva').'
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>';
|
||||
</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<script>
|
||||
function sostituisci(id) {
|
||||
if(confirm("'.tr('Vuoi sostituire questo componente?').'")){
|
||||
redirect("'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'&op=sostituisci&backto=record-edit&id_plugin='.$id_plugin.'&id_old="+id);
|
||||
function toggleDettagli(trigger) {
|
||||
const tr = $(trigger).closest("tr");
|
||||
const dettagli = tr.next();
|
||||
|
||||
if (dettagli.css("display") === "none"){
|
||||
dettagli.show(500);
|
||||
} else {
|
||||
dettagli.hide(500);
|
||||
}
|
||||
}
|
||||
|
||||
function elimina(id) {
|
||||
function gestisciAllegati(trigger) {
|
||||
const tr = $(trigger).closest("tr");
|
||||
const id_componente = tr.data("id");
|
||||
|
||||
openModal(\'Aggiungi file\', \''.$structure->fileurl('allegati.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'id_record='.$id_record.'&id=\' + id_componente);
|
||||
}
|
||||
|
||||
function sostituisciComponente(trigger) {
|
||||
const tr = $(trigger).closest("tr");
|
||||
const id_componente = tr.data("id");
|
||||
|
||||
if(confirm("'.tr('Vuoi sostituire questo componente?').'")) {
|
||||
redirect("'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'&op=sostituisci&backto=record-edit&id_plugin='.$id_plugin.'&id_componente=" + id_componente + "&hash=tab_'.$structure->id.'");
|
||||
}
|
||||
}
|
||||
|
||||
function rimuoviComponente(trigger) {
|
||||
const tr = $(trigger).closest("tr");
|
||||
const id_componente = tr.data("id");
|
||||
|
||||
if(confirm("'.tr('Vuoi eliminare questo componente?').'")){
|
||||
redirect("'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'&op=delete&backto=record-edit&id_plugin='.$id_plugin.'&id="+id);
|
||||
redirect("'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'&op=delete&backto=record-edit&id_plugin='.$id_plugin.'&id=" + id_componente + "&hash=tab_'.$structure->id.'");
|
||||
}
|
||||
}
|
||||
|
||||
|
87
plugins/componenti/src/Componente.php
Normal file
87
plugins/componenti/src/Componente.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/*
|
||||
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
||||
* Copyright (C) DevCode s.r.l.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Plugins\ComponentiImpianti;
|
||||
|
||||
use Common\SimpleModelTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Modules\Articoli\Articolo;
|
||||
use Modules\Impianti\Impianto;
|
||||
use Modules\Interventi\Intervento;
|
||||
|
||||
/*
|
||||
* Classe per la gestione dei Componenti degli Impianti.
|
||||
*
|
||||
* @since 2.4.25
|
||||
*/
|
||||
class Componente extends Model
|
||||
{
|
||||
use SimpleModelTrait;
|
||||
|
||||
protected $table = 'my_componenti';
|
||||
|
||||
protected $dates = [
|
||||
'data_registrazione',
|
||||
'data_sostituzione',
|
||||
'data_installazione',
|
||||
'data_rimozione',
|
||||
];
|
||||
|
||||
/**
|
||||
* Crea un nuovo Componente per Impianti.
|
||||
*
|
||||
* @param $data_registrazione
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function build(Impianto $impianto, Articolo $articolo, $data_registrazione)
|
||||
{
|
||||
$model = new static();
|
||||
|
||||
$model->impianto()->associate($impianto);
|
||||
$model->articolo()->associate($articolo);
|
||||
|
||||
$model->data_registrazione = $data_registrazione;
|
||||
$model->save();
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
// Relazioni Eloquent
|
||||
|
||||
public function articolo()
|
||||
{
|
||||
return $this->belongsTo(Articolo::class, 'id_articolo');
|
||||
}
|
||||
|
||||
public function impianto()
|
||||
{
|
||||
return $this->belongsTo(Impianto::class, 'id_impianto');
|
||||
}
|
||||
|
||||
public function sostituzione()
|
||||
{
|
||||
return $this->hasMany(self::class, 'id_sostituzione');
|
||||
}
|
||||
|
||||
public function intervento()
|
||||
{
|
||||
return $this->hasMany(Intervento::class, 'id_intervento');
|
||||
}
|
||||
}
|
27
update/2_4_25.php
Normal file
27
update/2_4_25.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Util\Ini;
|
||||
|
||||
// Trasposizione contenuto Componenti precedenti al nuovo formato
|
||||
$componenti_interessati = $database->fetchArray('SELECT `my_componenti`.`id`, `my_componenti`.`id_componente_vecchio`, `my_impianto_componenti`.`contenuto` FROM `my_componenti`
|
||||
INNER JOIN `my_impianto_componenti` ON `my_impianto_componenti`.`id` = `my_componenti`.`id_componente_vecchio`
|
||||
WHERE `id_componente_vecchio` IS NOT NULL');
|
||||
foreach ($componenti_interessati as $componente) {
|
||||
$note = '';
|
||||
|
||||
// Lettura da impostazioni INI
|
||||
$array = Ini::read($componente['contenuto']);
|
||||
foreach ($array as $nome => $c) {
|
||||
$note .= $nome.': '.$array[$nome]['valore'].'\\n';
|
||||
}
|
||||
|
||||
// Aggiornmaneto note
|
||||
$database->update('my_componenti_articoli', [
|
||||
'note' => $note,
|
||||
], ['id' => $componente['id']]);
|
||||
}
|
||||
|
||||
// Rimozione dati deprecati
|
||||
$database->query('ALTER TABLE `my_componenti` DROP `pre_id_articolo`, DROP `id_componente_vecchio`');
|
||||
$database->query('DROP TABLE `my_impianto_componenti`');
|
||||
|
@ -25,3 +25,35 @@ UPDATE `zz_views` SET `query` = '(SELECT COUNT(*) FROM `em_newsletter_receiver`
|
||||
|
||||
ALTER TABLE `em_newsletter_receiver` ADD `id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT;
|
||||
ALTER TABLE `em_list_receiver` ADD `id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT;
|
||||
|
||||
--
|
||||
-- Passaggio Componenti Impianti esistenti al nuovo formato come Articoli
|
||||
--
|
||||
|
||||
-- Correzioni tabella Componenti
|
||||
ALTER TABLE `my_componenti_articoli` RENAME TO `my_componenti`;
|
||||
ALTER TABLE `my_componenti` ADD `id_componente_vecchio` INT(11), ADD `id_intervento` INT(11), ADD `id_sostituzione` INT(11), CHANGE `note` `note` TEXT, CHANGE `data_disinstallazione` `data_rimozione` DATE NULL, ADD `data_sostituzione` DATE NULL;
|
||||
|
||||
-- Introduzione categoria dedicata ai Componenti
|
||||
INSERT INTO `mg_categorie` (`nome`, `colore`, `nota`) VALUES ('Componenti', '#ffffff', '');
|
||||
INSERT INTO `mg_articoli` (`codice`, `descrizione`, `id_categoria`) SELECT DISTINCT(`filename`), `nome`, (SELECT `id` FROM `mg_categorie` WHERE `nome` = 'Componenti' LIMIT 1) FROM `my_impianto_componenti`;
|
||||
|
||||
-- Trasposizione componenti esistenti
|
||||
INSERT INTO `my_componenti` (`id_componente_vecchio`, `id_impianto`, `id_intervento`, `id_articolo`, `data_registrazione`, `data_sostituzione`) SELECT `id`, `idimpianto`, `idintervento`, (SELECT `id` FROM `mg_articoli` WHERE `codice` = `my_impianto_componenti`.`filename` LIMIT 1), `data`, `data_sostituzione` FROM `my_impianto_componenti`;
|
||||
|
||||
UPDATE `my_componenti`
|
||||
INNER JOIN `my_componenti` t ON `t`.`id_componente_vecchio` = `my_componenti`.`id_sostituzione`
|
||||
SET `my_componenti`.`id_sostituzione` = `t`.`id` WHERE `my_componenti`.`id_componente_vecchio` IS NOT NULL;
|
||||
|
||||
-- Aggiornamento collegamenti dinamico Componenti-Interventi
|
||||
ALTER TABLE `my_componenti_interventi` DROP FOREIGN KEY `my_componenti_interventi_ibfk_2`;
|
||||
DELETE FROM `my_componenti_interventi` WHERE `id_componente` NOT IN (SELECT `id_componente_vecchio` FROM `my_componenti`);
|
||||
UPDATE `my_componenti_interventi` SET `id_componente` = (SELECT `id` FROM `my_componenti` WHERE `id_componente_vecchio` = `my_componenti_interventi`.`id_componente`);
|
||||
ALTER TABLE `my_componenti_interventi` ADD FOREIGN KEY (`id_componente`) REFERENCES `my_componenti`(`id`) ON DELETE CASCADE;
|
||||
|
||||
-- Aggiornamento foreign keys
|
||||
ALTER TABLE `my_componenti` ADD FOREIGN KEY (`id_intervento`) REFERENCES `in_interventi`(`id`) ON DELETE SET NULL,
|
||||
ADD FOREIGN KEY (`id_sostituzione`) REFERENCES `my_componenti`(`id`) ON DELETE SET NULL,
|
||||
ADD FOREIGN KEY (`id_impianto`) REFERENCES `my_impianti`(`id`) ON DELETE CASCADE,
|
||||
ADD FOREIGN KEY (`id_articolo`) REFERENCES `mg_articoli`(`id`) ON DELETE CASCADE;
|
||||
|
||||
|
@ -92,7 +92,7 @@ return [
|
||||
'my_impianti_categorie',
|
||||
'my_impianti_contratti',
|
||||
'my_impianti_interventi',
|
||||
'my_impianto_componenti',
|
||||
'my_componenti',
|
||||
'or_ordini',
|
||||
'or_righe_ordini',
|
||||
'or_statiordine',
|
||||
|
Loading…
x
Reference in New Issue
Block a user