Skip to content

Commit 9cf2e19

Browse files
committed
feat: aggiunto campo stato su impianti e relativo modulo di gestione
1 parent 583310f commit 9cf2e19

9 files changed

Lines changed: 386 additions & 9 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"Modules\\CategorieDocumentali\\": ["modules/categorie_documenti/custom/src/", "modules/categorie_documenti/src/"],
126126
"Modules\\PianiSconto\\": ["modules/piano_sconto/custom/src/", "modules/piano_sconto/src/"],
127127
"Modules\\Impianti\\": ["modules/impianti/custom/src/", "modules/impianti/src/"],
128+
"Modules\\StatiImpianti\\": ["modules/stati_impianti/custom/src/", "modules/stati_impianti/src/"],
128129
"Modules\\Importazione\\": ["modules/import/custom/src/", "modules/import/src/"],
129130
"Modules\\Impostazioni\\": ["modules/impostazioni/custom/src/", "modules/impostazioni/src/"],
130131
"Modules\\Partitario\\": ["modules/partitario/custom/src/", "modules/partitario/src/"],

modules/impianti/actions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
'piano' => post('piano'),
5656
'interno' => post('interno'),
5757
'occupante' => post('occupante'),
58+
'id_stato' => post('id_stato') ?: null,
5859
], ['id' => $id_record]);
5960

6061
flash()->info(tr('Informazioni salvate correttamente!'));

modules/impianti/edit.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
$id_modulo_categorie_impianti = Module::where('name', 'Categorie')->first()->id;
2525
$id_modulo_marca_impianti = Module::where('name', 'Marche')->first()->id;
26+
$id_modulo_stati_impianti = Module::where('name', 'Stati impianti')->first()->id;
2627

2728
$impianto = Impianto::find($id_record);
2829
$img = !empty($impianto) ? $impianto->image : null;
@@ -73,16 +74,21 @@
7374
</div>
7475
</div>
7576
<div class ="row">
76-
<div class="col-md-4">
77-
{[ "type": "select", "label": "<?php echo tr('Marca'); ?>", "name": "id_marca", "value": "$id_marca$", "ajax-source": "marche", "select-options": <?php echo json_encode(['is_impianto' => true]); ?>, "icon-after": "add|<?php echo $id_modulo_marca_impianti; ?>" ]}
78-
</div>
79-
<div class="col-md-4">
80-
{[ "type": "select", "label": "<?php echo tr('Modello'); ?>", "name": "id_modello", "value": "$id_modello$","ajax-source": "modelli", "select-options": <?php echo json_encode(['id_marca' => $record['id_marca'], 'is_impianto' => true]); ?>, "icon-after": "add|<?php echo $id_modulo_marca_impianti; ?>|id_original=<?php echo $record['id_marca']; ?>" ]}
81-
</div>
82-
<div class="col-md-4">
83-
{[ "type": "text", "label": "<?php echo tr('Proprietario'); ?>", "name": "proprietario", "value": "$proprietario$" ]}
84-
</div>
77+
<div class="col-md-3">
78+
{[ "type": "select", "label": "<?php echo tr('Marca'); ?>", "name": "id_marca", "value": "$id_marca$", "ajax-source": "marche", "select-options": <?php echo json_encode(['is_impianto' => true]); ?>, "icon-after": "add|<?php echo $id_modulo_marca_impianti; ?>" ]}
8579
</div>
80+
<div class="col-md-3">
81+
{[ "type": "select", "label": "<?php echo tr('Modello'); ?>", "name": "id_modello", "value": "$id_modello$","ajax-source": "modelli", "select-options": <?php echo json_encode(['id_marca' => $record['id_marca'], 'is_impianto' => true]); ?>, "icon-after": "add|<?php echo $id_modulo_marca_impianti; ?>|id_original=<?php echo $record['id_marca']; ?>" ]}
82+
</div>
83+
<div class="col-md-3">
84+
{[ "type": "text", "label": "<?php echo tr('Proprietario'); ?>", "name": "proprietario", "value": "$proprietario$" ]}
85+
</div>
86+
<div class="col-md-3">
87+
<?php echo Modules::link('Stati impianti', $record['id_stato'], null, null, 'class="pull-right"'); ?>
88+
{[ "type": "select", "label": "<?php echo tr('Stato'); ?>", "name": "id_stato", "value": "$id_stato$", "values": "query=SELECT `my_statiimpianti`.`id`, `my_statiimpianti_lang`.`title` AS descrizione, `my_statiimpianti`.`colore` AS _bgcolor_ FROM `my_statiimpianti` LEFT JOIN `my_statiimpianti_lang` ON (`my_statiimpianti`.`id` = `my_statiimpianti_lang`.`id_record` AND `my_statiimpianti_lang`.`id_lang` = <?php echo prepare(Models\Locale::getDefault()->id); ?>) WHERE `my_statiimpianti`.`deleted_at` IS NULL ORDER BY `my_statiimpianti_lang`.`title`", "icon-after": "add|<?php echo $id_modulo_stati_impianti; ?>" ]}
89+
</div>
90+
</div>
91+
8692
<div class="row">
8793
<div class="col-md-6">
8894
<?php echo (!empty($record['id_categoria'])) ?

modules/stati_impianti/actions.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
/*
4+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
5+
* Copyright (C) DevCode s.r.l.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
include_once __DIR__.'/../../core.php';
22+
23+
use Modules\StatiImpianti\Stato;
24+
25+
switch (post('op')) {
26+
case 'update':
27+
$descrizione = post('descrizione');
28+
$stato_new = Stato::where('name', $descrizione)->where('id', '!=', $id_record)->first();
29+
30+
if ($stato_new) {
31+
flash()->error(tr('Questo nome è già stato utilizzato per un altro stato impianto.'));
32+
} else {
33+
if (Models\Locale::getDefault()->id == Models\Locale::getPredefined()->id) {
34+
$stato->name = $descrizione;
35+
}
36+
$stato->icona = post('icona');
37+
$stato->colore = post('colore');
38+
$stato->save();
39+
40+
$stato->setTranslation('title', $descrizione);
41+
flash()->info(tr('Informazioni salvate correttamente.'));
42+
}
43+
44+
break;
45+
46+
case 'add':
47+
$descrizione = post('descrizione');
48+
$icona = post('icona');
49+
$colore = post('colore');
50+
51+
$stato_new = Stato::where('name', $descrizione)->first();
52+
53+
if ($stato_new) {
54+
flash()->error(tr('Questo nome è già stato utilizzato per un altro stato impianto.'));
55+
} else {
56+
$stato = Stato::build($icona, $colore);
57+
$stato->name = $descrizione;
58+
$id_record = $dbo->lastInsertedID();
59+
$stato->save();
60+
61+
flash()->info(tr('Nuovo stato impianto aggiunto.'));
62+
}
63+
64+
break;
65+
66+
case 'delete':
67+
$stato->delete('my_statiimpianti');
68+
flash()->info(tr('Stato impianto eliminato.'));
69+
70+
break;
71+
}

modules/stati_impianti/add.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/*
3+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
4+
* Copyright (C) DevCode s.r.l.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
include_once __DIR__.'/../../core.php';
21+
22+
?><form action="" method="post" id="add-form">
23+
<input type="hidden" name="op" value="add">
24+
<input type="hidden" name="backto" value="record-edit">
25+
26+
<div class="row">
27+
<div class="col-md-6">
28+
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "descrizione", "required": 1 ]}
29+
</div>
30+
31+
<div class="col-md-4">
32+
{[ "type": "text", "label": "<?php echo tr('Icona'); ?>", "name": "icona", "required": 1, "class": "text-center", "value": "fa fa-circle", "extra": "" ]}
33+
</div>
34+
35+
<div class="col-md-2">
36+
{[ "type": "text", "label": "<?php echo tr('Colore'); ?>", "name": "colore", "required": 1, "class": "colorpicker text-center", "value": "#ffffff", "extra": "maxlength='7'", "icon-after": "<div class='img-circle square'></div>" ]}
37+
</div>
38+
</div>
39+
40+
<!-- PULSANTI -->
41+
<div class="modal-footer">
42+
<div class="col-md-12 text-right">
43+
<button type="submit" class="btn btn-primary"><i class="fa fa-plus"></i> <?php echo tr('Aggiungi'); ?></button>
44+
</div>
45+
</div>
46+
</form>
47+
48+
<script>
49+
$(document).ready(function() {
50+
$('.colorpicker').colorpicker({ format: 'hex' }).on('changeColor', function() {
51+
$(this).parent().find('.square').css('background', $(this).val());
52+
});
53+
$('.colorpicker').parent().find('.square').css('background', $('.colorpicker').val());
54+
});
55+
</script>

modules/stati_impianti/edit.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/*
3+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
4+
* Copyright (C) DevCode s.r.l.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
include_once __DIR__.'/../../core.php';
21+
22+
if ($record['can_delete']) {
23+
$attr = '';
24+
} else {
25+
$attr = 'readonly';
26+
echo '<div class="alert alert-warning">'.tr('Alcune impostazioni non possono essere modificate per questo stato.').('</div>');
27+
}
28+
29+
?>
30+
<form action="" method="post" id="edit-form">
31+
<input type="hidden" name="op" value="update">
32+
<input type="hidden" name="backto" value="record-edit">
33+
<input type="hidden" name="id_record" value="<?php echo $id_record; ?>">
34+
35+
<div class="row">
36+
<div class="col-md-5">
37+
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "descrizione", "required": 1, "value": "$title$", "extra": "<?php echo $attr; ?>" ]}
38+
</div>
39+
40+
<div class="col-md-4">
41+
{[ "type": "text", "label": "<?php echo tr('Icona'); ?>", "name": "icona", "required": 1, "class": "text-center", "value": "$icona$", "extra": "", "icon-after": "<?php echo (!empty($record['icona'])) ? '<i class=\"'.$record['icona'].'\"></i>' : ''; ?>" ]}
42+
</div>
43+
44+
<div class="col-md-3">
45+
{[ "type": "text", "label": "<?php echo tr('Colore'); ?>", "name": "colore", "required": 1, "class": "colorpicker text-center", "value": "$colore$", "extra": "maxlength='7'", "icon-after": "<div class='img-circle square'></div>" ]}
46+
</div>
47+
</div>
48+
</form>
49+
50+
<?php
51+
$impianti = $dbo->fetchNum('SELECT id FROM my_impianti WHERE id_stato='.prepare($id_record));
52+
53+
if (!empty($impianti)) {
54+
echo '
55+
<div class="alert alert-danger">
56+
'.tr('Ci sono _NUM_ impianti collegati', [
57+
'_NUM_' => $impianti,
58+
]).'.
59+
</div>';
60+
}
61+
62+
if (!empty($record['can_delete'])) {
63+
echo '
64+
<a class="btn btn-danger ask" data-backto="record-list">
65+
<i class="fa fa-trash"></i>'.tr('Elimina').'
66+
</a>';
67+
}
68+
69+
?>
70+
71+
<script>
72+
$(document).ready(function() {
73+
$('.colorpicker').colorpicker({ format: 'hex' }).on('changeColor', function() {
74+
$(this).parent().find('.square').css('background', $(this).val());
75+
});
76+
$('.colorpicker').parent().find('.square').css('background', $('.colorpicker').val());
77+
});
78+
</script>

modules/stati_impianti/init.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
5+
* Copyright (C) DevCode s.r.l.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
include_once __DIR__.'/../../core.php';
22+
use Modules\StatiImpianti\Stato;
23+
24+
if (!empty($id_record)) {
25+
$record = $dbo->fetchOne('SELECT * FROM `my_statiimpianti` LEFT JOIN `my_statiimpianti_lang` ON (`my_statiimpianti`.`id` = `my_statiimpianti_lang`.`id_record` AND `my_statiimpianti_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') WHERE `my_statiimpianti`.`id`='.prepare($id_record));
26+
27+
$stato = Stato::find($id_record);
28+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/*
4+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
5+
* Copyright (C) DevCode s.r.l.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
namespace Modules\StatiImpianti;
22+
23+
use Common\SimpleModelTrait;
24+
use Illuminate\Database\Eloquent\Model;
25+
use Traits\RecordTrait;
26+
use Illuminate\Database\Eloquent\SoftDeletes;
27+
28+
class Stato extends Model
29+
{
30+
use SimpleModelTrait;
31+
use RecordTrait;
32+
use SoftDeletes;
33+
34+
protected $table = 'my_statiimpianti';
35+
36+
protected static $translated_fields = [
37+
'title',
38+
];
39+
40+
public static function build($icona = null, $colore = null)
41+
{
42+
$model = new static();
43+
$model->icona = $icona;
44+
$model->colore = $colore;
45+
$model->save();
46+
47+
return $model;
48+
}
49+
50+
public function getModuleAttribute()
51+
{
52+
return 'Stati impianti';
53+
}
54+
55+
public static function getTranslatedFields()
56+
{
57+
return self::$translated_fields;
58+
}
59+
}

0 commit comments

Comments
 (0)