Aggiunto nuovo plugin Componenti in Impianti

This commit is contained in:
MatteoPistorello 2021-06-17 18:33:00 +02:00
parent 7fde2b1a82
commit 643c1f2f81
6 changed files with 392 additions and 1 deletions

View File

@ -41,6 +41,7 @@ Il formato utilizzato è basato sulle linee guida di [Keep a Changelog](http://k
- Aggiunta nel calendario della Dashboard visualizzazione dei preventivi pianificabili in corrispondenza alla data di accettazione e conclusione.
- Aggiunta impostazione per la visualizzazione delle ore nella stampa intervento (Decimale, Sessantesimi).
- Aggiunta possibilità di selezionare la sede di partenza della merce in fase di aggiunta articolo da un'attività
- Sostituito plugin **Componenti** nel modulo Impianti con la possibilità di inserire gli articoli di magazzino
### Fixed
-

View File

@ -0,0 +1,125 @@
<?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/>.
*/
include_once __DIR__.'/../../core.php';
use Carbon\Carbon;
$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');
$key = key($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]);
flash()->info(tr('Salvataggio completato!'));
$dbo->commitTransaction();
header('Location: '.$rootdir.'/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'),
]);
flash()->info(tr('Salvataggio completato!'));
break;
case 'sostituisci':
$old_id = get('id_old');
$old = $dbo->selectOne('my_componenti_articoli', '*', ['id' => $old_id]);
if(!empty($old['id_articolo'])){
if(empty($old['data_disinstallazione'])){
$data = Carbon::now();
} else{
$data = $old['data_disinstallazione'];
}
$dbo->update('my_componenti_articoli', [
'pre_id_articolo' => $old['id_articolo'],
'id_articolo' => 0,
'data_disinstallazione' => $data,
],[
'id' => $old_id,
]);
$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: '.$rootdir.'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'#tab_'.$id_plugin);
exit;
break;
case 'delete':
$dbo->query('DELETE FROM my_componenti_articoli WHERE id='.prepare(get('id')));
flash()->info(tr('Componente eliminato!'));
$dbo->commitTransaction();
header('Location: '.$rootdir.'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'#tab_'.$id_plugin);
exit;
break;
}

View File

@ -0,0 +1,40 @@
<?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/>.
*/
include_once __DIR__.'/../../core.php';
echo '
<form action="" method="post" role="form">
<input type="hidden" name="id_parent" value="'.$id_parent.'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="add">
<div class="row">
<div class="col-md-6">
{["type": "select", "label": "'.tr('Articolo').'", "name": "id_articolo", "ajax-source": "articoli", "value": "", "required": 1, "select-options": {"permetti_movimento_a_zero": 1} ]}
</div>
</div>
<!-- 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>
</div>
</div>
</form>';

View File

@ -0,0 +1,22 @@
<?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/>.
*/
include_once __DIR__.'/../../core.php';
echo '{( "name": "filelist_and_upload", "id":"'.rand(1,999).'", "id_record": "'.get('id').'", "id_module": "'.$id_module.'", "id_plugin": "'.$id_plugin.'" )}';

194
plugins/componenti/edit.php Normal file
View File

@ -0,0 +1,194 @@
<?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/>.
*/
include_once __DIR__.'/../../core.php';
echo '<hr>';
$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');
$installati = 0;
$disinstallati = 0;
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++;
}
}
$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'];
if($allegati){
$icon = 'fa fa-check text-success';
} else{
$icon = 'fa fa-times text-danger';
}
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="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>
<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>
<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>
<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>
</div>
</div>
</div>
</div>
</div>
</div>
</form>';
}
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 elimina(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);
}
}
</script>';

View File

@ -30,4 +30,13 @@ INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`
INSERT INTO `zz_plugins` (`name`, `title`, `idmodule_from`, `idmodule_to`, `position`, `script`, `enabled`, `default`, `order`, `compatibility`, `version`, `options2`, `options`, `directory`, `help`) VALUES ('Allegati', 'Allegati', (SELECT `zz_modules`.`id` FROM `zz_modules` WHERE `zz_modules`.`name`='Anagrafiche'), (SELECT `zz_modules`.`id` FROM `zz_modules` WHERE `zz_modules`.`name`='Anagrafiche'), 'tab', 'allegati.php', '1', '0', '0', '', '', NULL, NULL, '', '');
-- Aggiunta idsede nelle righe dell'intervento
ALTER TABLE `in_righe_interventi` ADD `idsede_partenza` INT NOT NULL AFTER `id_dettaglio_fornitore`;
ALTER TABLE `in_righe_interventi` ADD `idsede_partenza` INT NOT NULL AFTER `id_dettaglio_fornitore`;
-- Aggiunto nuovo plugin Componenti e disabilitato quello precedente
UPDATE `zz_plugins` SET `name`='Componenti ini', `title`='Componenti ini' WHERE `name`='Componenti';
UPDATE `zz_plugins` SET `enabled`=0 WHERE `name`='Componenti ini';
INSERT INTO `zz_plugins` ( `name`, `title`, `idmodule_from`, `idmodule_to`, `position`, `script`, `enabled`, `default`, `order`, `compatibility`, `version`, `options2`, `options`, `directory`, `help`, `created_at`, `updated_at`) VALUES ('Componenti', 'Componenti', (SELECT `id` FROM `zz_modules` WHERE name='Impianti'), (SELECT `id` FROM `zz_modules` WHERE name='Impianti'), 'tab', '', '1', '0', '0', '', '', NULL, 'custom', 'componenti', '', NOW(), NOW());
CREATE TABLE `my_componenti_articoli` ( `id` INT NOT NULL AUTO_INCREMENT, `id_impianto` INT NOT NULL , `id_articolo` INT NOT NULL , `pre_id_articolo` INT NOT NULL, `note` TEXT NOT NULL , `data_registrazione` DATE NULL , `data_installazione` DATE NULL , `data_disinstallazione` DATE NULL , `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , `updated_at` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`));