Nuovo modulo per gestire i "Settori merceologici"

This commit is contained in:
Luca 2022-06-10 19:07:12 +02:00
parent 4a85c8455b
commit b784c1bd1a
11 changed files with 273 additions and 9 deletions

View File

@ -80,7 +80,7 @@ switch (post('op')) {
$anagrafica->idiva_vendite = post('idiva_vendite');
$anagrafica->idbanca_acquisti = post('idbanca_acquisti');
$anagrafica->idbanca_vendite = post('idbanca_vendite');
$anagrafica->settore = post('settore');
$anagrafica->id_settore = post('id_settore');
$anagrafica->marche = post('marche');
$anagrafica->dipendenti = post('dipendenti');
$anagrafica->macchine = post('macchine');

View File

@ -42,7 +42,6 @@ $fields = [
'Sito web' => 'sitoweb',
'Note' => 'note',
'Codice REA' => 'codicerea',
'Settore' => 'settore',
'Marche' => 'marche',
'CCIAA' => 'cciaa',
'Numero di iscrizione albo artigiani' => 'n_alboartigiani',

View File

@ -386,6 +386,20 @@ switch ($resource) {
break;
case 'settori':
$query = 'SELECT id, descrizione FROM an_settori |where| ORDER BY descrizione';
foreach ($elements as $element) {
$filter[] = 'id='.prepare($element);
}
if (!empty($search)) {
$search_fields[] = 'descrizione LIKE '.prepare('%'.$search.'%');
}
break;
/*
* Opzioni utilizzate:
* - idanagrafica

View File

@ -675,9 +675,9 @@ if ($is_cliente or $is_fornitore or $is_tecnico) {
</div>
<div class="row">
<div class="col-md-3">
{[ "type": "text", "label": "<?php echo tr('Settore merceologico'); ?>", "name": "settore", "value": "$settore$" ]}
</div>
<div class="col-md-3">
{[ "type": "select", "label": "<?php echo tr('Settore merceologico'); ?>", "name": "id_settore", "ajax-source": "settori", "value": "$id_settore$", "icon-after": "add|<?php echo Modules::get('Settori')['id']; ?>" ]}
</div>
<div class="col-md-3">
{[ "type": "text", "label": "<?php echo tr('Marche trattate'); ?>", "name": "marche", "value": "$marche$" ]}

View File

@ -46,7 +46,7 @@ include_once __DIR__.'/../../core.php';
</form>
<?php
$righe = $dbo->fetchNum('SELECT idanagrafica FROM an_anagrafiche WHERE idrelazione='.prepare($id_record));
$righe = $dbo->fetchNum('SELECT idanagrafica FROM an_anagrafiche WHERE id_provenienza='.prepare($id_record));
if (!empty($righe)) {
echo '

View File

@ -0,0 +1,83 @@
<?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';
switch (filter('op')) {
case 'update':
$descrizione = filter('descrizione');
$colore = filter('colore');
if (isset($descrizione)) {
if ($dbo->fetchNum('SELECT * FROM `an_settori` WHERE `descrizione`='.prepare($descrizione).' AND `id`!='.prepare($id_record)) == 0) {
$dbo->query('UPDATE `an_settori` SET `descrizione`='.prepare($descrizione).' WHERE `id`='.prepare($id_record));
flash()->info(tr('Salvataggio completato.'));
} else {
flash()->error(tr("E' già presente il settore merceologico _NAME_.", [
'_TYPE_' => $descrizione,
]));
}
} else {
flash()->error(tr('Ci sono stati alcuni errori durante il salvataggio'));
}
break;
case 'add':
$descrizione = filter('descrizione');
$colore = filter('colore');
if (isset($descrizione)) {
if ($dbo->fetchNum('SELECT * FROM `an_settori` WHERE `descrizione`='.prepare($descrizione)) == 0) {
$dbo->query('INSERT INTO `an_settori` (`descrizione`) VALUES ('.prepare($descrizione).')');
$id_record = $dbo->lastInsertedID();
if (isAjaxRequest()) {
echo json_encode(['id' => $id_record, 'text' => $descrizione]);
}
flash()->info(tr('Aggiunto nuovo settore merceologico _NAME_', [
'_NAME_' => $descrizione,
]));
} else {
flash()->error(tr("E' già presente un settore merceologico _NAME_.", [
'_NAME_' => $descrizione,
]));
}
} else {
flash()->error(tr('Ci sono stati alcuni errori durante il salvataggio'));
}
break;
case 'delete':
$righe = $dbo->fetchNum('SELECT idanagrafica FROM an_anagrafiche WHERE id_settore='.prepare($id_record));
if (isset($id_record) && empty($righe)) {
$dbo->query('DELETE FROM `an_settori` WHERE `id`='.prepare($id_record));
flash()->info(tr('Settore merceologico _NAME_ eliminato con successo!', [
'_NAME_' => $descrizione,
]));
} else {
flash()->error(tr('Sono presenti '.count($righe).' anagrafiche collegate a questo settore merceologico.'));
}
break;
}

View File

@ -0,0 +1,47 @@
<?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';
?><form action="" method="post" id="add-form">
<input type="hidden" name="op" value="add">
<input type="hidden" name="backto" value="record-edit">
<div class="row">
<div class="col-md-12">
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "descrizione", "required": 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> <?php echo tr('Aggiungi'); ?></button>
</div>
</div>
</form>
<script>
$(document).ready( function() {
$('.colorpicker').colorpicker().on('changeColor', function() {
$('#colore').parent().find('.square').css( 'background', $('#colore').val() );
});
$('#colore').parent().find('.square').css( 'background', $('#colore').val() );
});
</script>

View File

@ -0,0 +1,72 @@
<?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';
?><form action="" method="post" id="edit-form">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="update">
<!-- DATI -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><?php echo tr('Dati'); ?></h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "descrizione", "required": 1, "value": "$descrizione$" ]}
</div>
</div>
</div>
</div>
</form>
<?php
$righe = $dbo->fetchNum('SELECT idanagrafica FROM an_anagrafiche WHERE id_settore='.prepare($id_record));
if (!empty($righe)) {
echo '
<div class="alert alert-danger">
'.tr('Ci sono _NUM_ anagrafiche collegate', [
'_NUM_' => $righe,
]).'.
</div>';
} else {
?>
<a class="btn btn-danger ask" data-backto="record-list">
<i class="fa fa-trash"></i> <?php echo tr('Elimina'); ?>
</a>
<?php
}
?>
<script>
$(document).ready( function() {
$('.colorpicker').colorpicker().on('changeColor', function() {
$('#colore').parent().find('.square').css( 'background', $('#colore').val() );
});
$('#colore').parent().find('.square').css( 'background', $('#colore').val() );
});
</script>

View File

@ -0,0 +1,24 @@
<?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';
if (isset($id_record)) {
$record = $dbo->fetchOne('SELECT * FROM `an_settori` WHERE id='.prepare($id_record));
}

View File

@ -77,10 +77,34 @@ INSERT INTO `an_provenienze` (`id`, `descrizione`, `colore`) VALUES
-- Aggiunto id_provenienza per scheda anagrafica Cliente
ALTER TABLE `an_anagrafiche` ADD `id_provenienza` AFTER `idrelazione`, INT DEFAULT NULL;
-- Nuovo modulo "Provenienze"
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`, `use_notes`, `use_checklists`) VALUES (NULL, 'Provenienze', 'Provenienze', 'provenienze', 'SELECT |select| FROM `an_provenienze` WHERE 1=1 HAVING 2=2', '', 'fa fa-angle-right', '2.4.34', '2.4.34', '1', (SELECT id FROM zz_modules t WHERE t.name = 'Anagrafiche'), '1', '1', '0', '0');
-- Nuovo modulo per gestire le "Provenienze"
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`, `use_notes`, `use_checklists`) VALUES (NULL, 'Provenienze', 'Provenienze clienti', 'provenienze', 'SELECT |select| FROM `an_provenienze` WHERE 1=1 HAVING 2=2', '', 'fa fa-angle-right', '2.4.34', '2.4.34', '3', (SELECT id FROM zz_modules t WHERE t.name = 'Anagrafiche'), '1', '1', '0', '0');
INSERT INTO `zz_views` (`id`, `id_module`, `name`, `query`, `order`, `visible`, `format`, `default`) VALUES
(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Provenienze'), 'id', 'an_provenienze.id', 1, 1, 0, 1),
(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Provenienze'), 'descrizione', 'an_provenienze.descrizione', 2, 1, 0, 1),
(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Provenienze'), 'colore', 'an_provenienze.colore', 3, 1, 0, 1);
(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Provenienze'), 'colore', 'an_provenienze.colore', 3, 1, 0, 1);
-- Aggiunta tabella settore merceologico
CREATE TABLE IF NOT EXISTS `an_settori` ( `id` INT NOT NULL AUTO_INCREMENT , `descrizione` VARCHAR(100) NOT NULL , PRIMARY KEY (`id`));
INSERT INTO `an_settori`(
`descrizione`
)(
SELECT DISTINCT `settore` FROM `an_anagrafiche`
);
ALTER TABLE `an_anagrafiche` ADD `id_settore` INT NOT NULL AFTER `settore`;
UPDATE `an_anagrafiche`, `an_settori` SET `id_settore`=`an_settori`.`id` WHERE `an_settori`.`descrizione`=`an_anagrafiche`.`settore`;
ALTER TABLE `an_anagrafiche` DROP `settore`;
-- Nuovo modulo per gestire i "Settori merceologici"
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`, `use_notes`, `use_checklists`) VALUES (NULL, 'Settori', 'Settori merceologici', 'settori_merceologici', 'SELECT |select| FROM `an_settori` WHERE 1=1 HAVING 2=2', '', 'fa fa-angle-right', '2.4.34', '2.4.34', '4', (SELECT id FROM zz_modules t WHERE t.name = 'Anagrafiche'), '1', '1', '0', '0');
INSERT INTO `zz_views` (`id`, `id_module`, `name`, `query`, `order`, `visible`, `format`, `default`) VALUES
(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Settori'), 'id', 'an_settori.id', 1, 1, 0, 1),
(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Settori'), 'descrizione', 'an_settori.descrizione', 2, 1, 0, 1);

View File

@ -9,6 +9,7 @@ return [
'an_regioni',
'an_relazioni',
'an_provenienze',
'an_settori',
'an_sedi',
'an_tipianagrafiche',
'an_tipianagrafiche_anagrafiche',