Nuovo modulo "Mappa" per geolocalizzare le attività.

This commit is contained in:
Matteo 2022-10-13 16:10:43 +02:00
parent 66dfdf2db5
commit a871dcf66e
5 changed files with 464 additions and 0 deletions

128
modules/mappa/actions.php Normal file
View File

@ -0,0 +1,128 @@
<?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 Util\Query;
switch( get('op') ){
case "get_markers":
$idanagrafica = get('idanagrafica');
$checks = get('check');
$where = [];
//Filtro per anagrafica
if(!empty($idanagrafica) && $idanagrafica!='null'){
$where[] = "in_interventi.idanagrafica=".prepare($idanagrafica);
}
//Filtri per stato
$checks = explode(',', $checks);
$where[] = "in_statiintervento.descrizione IN ('".implode("','", $checks)."')";
$add_query = "WHERE 1=1 AND ".implode(' AND ', $where);
//Filtri per data
$add_query .= " |date_period(`orario_inizio`,`data_richiesta`)|";
$query = "SELECT *, in_interventi.id AS idintervento, an_anagrafiche.lat AS lat_anagrafica, an_anagrafiche.lng AS lng_anagrafica, an_anagrafiche.indirizzo AS indirizzo_anagrafica, an_anagrafiche.cap AS cap_anagrafica, an_anagrafiche.citta AS citta_anagrafica, an_anagrafiche.provincia AS provincia_anagrafica, an_sedi.lat AS lat_sede, an_sedi.lng AS lng_sede, an_sedi.indirizzo AS indirizzo_sede, an_sedi.cap AS cap_sede, an_sedi.citta AS citta_sede, an_sedi.provincia AS provincia_sede, in_statiintervento.descrizione AS stato FROM in_interventi INNER JOIN an_anagrafiche ON in_interventi.idanagrafica=an_anagrafiche.idanagrafica LEFT JOIN an_sedi ON in_interventi.idsede_destinazione=an_sedi.id INNER JOIN in_statiintervento ON in_interventi.idstatointervento=in_statiintervento.idstatointervento LEFT JOIN in_interventi_tecnici ON in_interventi_tecnici.idintervento = in_interventi.id ".$add_query;
$query = Query::replacePlaceholder($query);
$query = Modules::replaceAdditionals(Modules::get('Interventi')['id'], $query);
$records = $dbo->fetchArray($query);
$rs = [];
if(sizeof($records)>0){
for( $i=0; $i<sizeof($records); $i++ ){
if(!empty($records[$i]['idsede_destinazione'])){
$lat = $records[$i]['lat_sede'];
$lng = $records[$i]['lng_sede'];
$indirizzo = $records[$i]['indirizzo_sede'];
$cap = $records[$i]['cap_anagrafica_sede'];
$citta = $records[$i]['citta_anagrafica_sede'];
$provincia = $records[$i]['provincia_anagrafica_sede'];
}else{
$lat = $records[$i]['lat_anagrafica'];
$lng = $records[$i]['lng_anagrafica'];
$indirizzo = $records[$i]['indirizzo_anagrafica'];
$cap = $records[$i]['cap_anagrafica'];
$citta = $records[$i]['citta_anagrafica'];
$provincia = $records[$i]['provincia_anagrafica'];
}
if ( ( $lat != '0.00000000' && $lng != '0.00000000' ) ){
$descrizione = '';
$descrizione .= '<i class="fa fa-user"></i> <b>Ragione sociale</b>: <a href="'.$rootdir.'/editor.php?id_module='.Modules::get('Anagrafiche')['id'].'&id_record='.$records[$i]['id'].'" target="_blank" > '.$records[$i]['ragione_sociale'].' <i class="fa fa-external-link"></i> </a>'."\n<br>";
if(!empty($indirizzo)){
$descrizione .= '<i class="fa fa-map-signs"></i> <b>Indirizzo</b>: '.$indirizzo."\n<br>";
}
if(!empty($cap)){
$descrizione .= ' '.$cap;
}
if(!empty($citta)){
$descrizione .= ', '.$citta;
}
if(!empty($provincia)){
$descrizione .= ' '.$provincia;
}
$descrizione .= '<hr>';
$descrizione .= '<a class="btn btn-info btn-block btn-xs" onclick="calcolaPercorso(\''.$indirizzo.' '.$cap.' '.$citta.' '.$provincia.'\')">
<i class="fa fa-map-signs"></i> Calcola percorso
</a>';
//dettagli intervento
$rs_sessioni = $dbo->fetchOne("SELECT MIN(orario_inizio) AS data, GROUP_CONCAT(DISTINCT ragione_sociale SEPARATOR ', ') AS tecnici FROM in_interventi_tecnici INNER JOIN an_anagrafiche ON in_interventi_tecnici.idtecnico=an_anagrafiche.idanagrafica WHERE idintervento=".prepare($records[$i]['idintervento'])." GROUP BY idintervento");
$descrizione .= '<hr>';
$descrizione .= '<b>Data</b>: '.(!empty($rs_sessioni['data'])?Translator::dateToLocale($rs_sessioni['data']):Translator::dateToLocale($records[$i]['data_richiesta'])).'<br>';
$descrizione .= '<b>Stato</b>: '.$records[$i]['stato']."<br>";
$descrizione .= '<b>Richiesta</b>: '.substr(strip_tags($records[$i]['richiesta']), 0, 200)."<br>";
if(!empty($rs_sessioni['tecnici'])){
$descrizione .= '<b>Tecnici</b>: '.$rs_sessioni['tecnici'];
}
$descrizione .= '<hr>';
$descrizione .= '<a class="btn btn-info btn-block btn-xs" onclick="window.open(\''.$rootdir.'/editor.php?id_module='.Modules::get('Interventi')['id'].'&id_record='.$records[$i]['idintervento'].'\');">
<i class="fa fa-external-link"></i> Apri attività
</a>';
$descrizione .= '<hr>';
$rs[] = ['descrizione'=>$descrizione, 'lat'=>$lat, 'lng'=>$lng];
}
}
}
echo json_encode($rs);
break;
}
?>

104
modules/mappa/css/app.css Normal file
View File

@ -0,0 +1,104 @@
#mappa {
width: 100%;
height: 835px;
}
#menu-filtri {
width:600px;
height:700px;
position:fixed;
top:100px;
}
.open-menu{
right:0px;
background-color:#FFFFFFEB;
}
.closed-menu{
right:-560px;
background-color:#FFFFFF00;
}
.row{
margin-bottom: 5px;
}
hr {
margin-top: 5px;
margin-bottom: 5px;
}
.material-switch > input[type="checkbox"] {
display: none;
}
.material-switch > label {
cursor: pointer;
height: 0px;
position: relative;
width: 40px;
}
.material-switch > label::before {
background: rgb(0, 0, 0);
box-shadow: inset 0px 0px 10px rgba(0, 0, 0, 0.5);
border-radius: 8px;
content: '';
height: 16px;
margin-top: -8px;
position:absolute;
opacity: 0.3;
transition: all 0.4s ease-in-out;
width: 40px;
}
.material-switch > label::after {
background: rgb(255, 255, 255);
border-radius: 16px;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
content: '';
height: 24px;
left: -4px;
margin-top: -8px;
position: absolute;
top: -4px;
transition: all 0.3s ease-in-out;
width: 24px;
}
.material-switch > input[type="checkbox"]:checked + label::before {
background: inherit;
opacity: 0.5;
}
.material-switch > input[type="checkbox"]:checked + label::after {
background: inherit;
left: 20px;
}
.material-switch {
margin-bottom:10px;
}
.btn-black{
background-color: #505050;
color: #fff;
border-color: #353535;
border-bottom-color: #353535;
}
.btn-black:hover{
background-color: #414141;
color: #fff;
border-color: #353535;
border-bottom-color: #353535;
}
.btn-black:focus{
color: #fff;
}
a:active, a:hover, a:focus {
outline: 0;
text-decoration: none;
outline: 0 !important;
}

100
modules/mappa/edit.php Normal file
View File

@ -0,0 +1,100 @@
<?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';
?>
<link rel="stylesheet" href="<?=$rootdir?>/modules/mappa/css/app.css">
<?php
if(!empty(setting('Google Maps API key'))){
?>
<!-- Mappa -->
<div id="mappa"></div>
<!-- Menu laterale -->
<div id="menu-filtri" class="open-menu">
<div style='width:100%;height:50px;background-color:#4d4d4d;padding:8px;font-size:25px;color:white;' class='text-center'>
<div class="pull-left"><i class='fa fa-forward clickable' id="menu-filtri-toggle"></i></div>
<b>Filtri</b>
</div>
<div id="lista-filtri" style="padding:20px 40px;height:637px;overflow:auto;">
<div class="row">
<div class="col-md-12">
<label style='font-size:12pt;'>Geolocalizzazione attività per anagrafica</label>
<hr>
</div>
</div>
<div class="row">
<div class="col-md-12">
{[ "type": "select", "name": "idanagrafica", "id": "idanagrafica", "required": 1, "ajax-source": "clienti_fornitori" ]}
</div>
</div>
<div class="row">
<div class="col-md-12">
<label style='font-size:12pt;'>Geolocalizzazione attività per stato</label>
<hr>
</div>
</div>
<div class="row">
<?php
$rs_stati = $dbo->fetchArray("SELECT * FROM in_statiintervento");
foreach($rs_stati AS $stato){
?>
<div class="col-md-4">
<label><?=$stato['descrizione']?></label>
<div class="material-switch">
<input id="<?=$stato['descrizione']?>" name="<?=$stato['descrizione']?>" type="checkbox" checked/>
<label for="<?=$stato['descrizione']?>" class="label-success"></label>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>
<script>
var ROOTDIR = '<?=$rootdir?>';
function calcolaPercorso(indirizzo) {
window.open("https://www.google.com/maps/dir/?api=1&destination=" + indirizzo);
}
</script>
<script type="text/javascript" src="<?=$rootdir?>/modules/mappa/js/app.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?callback=initialize&key=<?=setting('Google Maps API key')?>&libraries=&v=weekly" async></script>
<?php
}else{
echo '
<div class="alert alert-info">
'.Modules::link('Impostazioni', null, tr('Per abilitare la visualizzazione della mappa, inserire la Google Maps API Key nella scheda Impostazioni'), true, null, true, null, '&search=Google Maps API key').'.
</div>';
}
?>

131
modules/mappa/js/app.js Normal file
View File

@ -0,0 +1,131 @@
$(document).ready(function(){
if(!$('body').hasClass('sidebar-collapse')){
$('.sidebar-toggle').trigger('click');
$('.nav').hide();
}
reload_pointers();
});
let map;
var markers = [];
function initialize(startLat, startLon) {
if (startLat==undefined){
startLat = 43.45291889;
}
if (startLon==undefined){
startLon = 11.96411133;
}
var myLatlng = new google.maps.LatLng(startLat, startLon);
var mapOptions = {
zoom: 7,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false,
panControl: false,
scaleControl: false,
rotateControl: false
}
map = new google.maps.Map(document.getElementById('mappa'), mapOptions);
}
$('#menu-filtri-toggle').click(function(){
if($(this).parent().parent().parent().hasClass("open-menu")){
$(this).parent().parent().parent().removeClass("open-menu");
$(this).parent().parent().parent().addClass("closed-menu");
$(this).removeClass('fa-forward');
$(this).addClass('fa-backward');
$('#lista-filtri').hide();
}else{
$(this).parent().parent().parent().removeClass("closed-menu");
$(this).parent().parent().parent().addClass("open-menu");
$(this).removeClass('fa-backward');
$(this).addClass('fa-forward');
$('#lista-filtri').show();
}
});
function reload_pointers(){
clearMarkers();
var check = [];
$("input[type='checkbox']").each(function(){
if($(this).is(':checked')){
id = $(this).attr('id');
check.push(id);
}
});
$.get(ROOTDIR+'/modules/mappa/actions.php?op=get_markers&idanagrafica='+$('#idanagrafica').val()+'&check='+check, function(data){
var infowindow = new google.maps.InfoWindow();
var bounds = new google.maps.LatLngBounds ();
var dettagli = JSON.parse(data);
var marker, i;
var counter = 0;
dettagli.forEach(function(dettaglio) {
const posizione = new google.maps.LatLng(dettaglio.lat, dettaglio.lng);
marker = new google.maps.Marker({
position: posizione,
map: map,
});
markers.push(marker);
bounds.extend(posizione);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(dettaglio.descrizione);
infowindow.open(map, marker);
}
})(marker, i));
counter++;
});
if(counter>0){
map.setCenter(bounds.getCenter()); // this will set the center of map to center of all markers
map.fitBounds(bounds); // this will fit all the markers to screen
}
});
}
function setMapOnAll(map) {
for (let i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
function clearMarkers() {
setMapOnAll(null);
}
$("input[type='checkbox']").change(function(){
reload_pointers();
});
$('#idanagrafica').change(function(){
reload_pointers();
});

1
update/2_4_37.sql Normal file
View File

@ -0,0 +1 @@
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`, `created_at`, `updated_at`, `use_notes`, `use_checklists`) VALUES (NULL, 'Mappa', 'Mappa', 'mappa', 'custom', '', 'fa fa-map', '2.4.36', '2.4.36', '10', NULL, '1', '1', '2022-10-12 17:22:11', '2022-10-12 17:23:52', '0', '0');