mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
Aggiunta relazione utente-sedi per filtro sede azienda + fix calcolo giancenze
This commit is contained in:
@@ -217,19 +217,23 @@ switch ($resource) {
|
|||||||
|
|
||||||
case 'sedi_azienda':
|
case 'sedi_azienda':
|
||||||
if (isset($superselect['idanagrafica'])) {
|
if (isset($superselect['idanagrafica'])) {
|
||||||
$query = "SELECT * FROM (SELECT '0' AS id, 'Sede legale' AS descrizione UNION SELECT id, CONCAT_WS(' - ', nomesede, citta) FROM an_sedi |where|) AS tab |filter| GROUP BY descrizione";
|
$user = Auth::user();
|
||||||
|
|
||||||
|
$query = "SELECT * FROM (SELECT '0' AS id, 'Sede legale' AS descrizione UNION SELECT id, CONCAT_WS(' - ', nomesede, citta) FROM an_sedi |where|) AS tab |filter| ORDER BY descrizione";
|
||||||
|
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
$filter[] = 'id='.prepare($element);
|
$filter[] = 'id='.prepare($element);
|
||||||
}
|
}
|
||||||
|
|
||||||
$where[] = 'idanagrafica='.prepare(setting('Azienda predefinita'));
|
$where[] = 'idanagrafica='.prepare($user->idanagrafica);
|
||||||
|
$where[] = 'id IN('.implode(',', $user->idsedi).')';
|
||||||
|
|
||||||
if (!empty($search)) {
|
if (!empty($search)) {
|
||||||
$search_fields[] = 'nomesede LIKE '.prepare('%'.$search.'%');
|
$search_fields[] = 'nomesede LIKE '.prepare('%'.$search.'%');
|
||||||
$search_fields[] = 'citta LIKE '.prepare('%'.$search.'%');
|
$search_fields[] = 'citta LIKE '.prepare('%'.$search.'%');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'referenti':
|
case 'referenti':
|
||||||
|
@@ -324,9 +324,17 @@ if (!empty($elementi)) {
|
|||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<a class="btn btn-danger ask" data-backto="record-list">
|
<?php
|
||||||
|
// Eliminazione ddt solo se ho accesso alla sede aziendale
|
||||||
|
$field_name = ( $dir == 'entrata' ) ? 'idsede_partenza' : 'idsede_destinazione';
|
||||||
|
if (in_array($record[$field_name], $user->idsedi)){
|
||||||
|
?>
|
||||||
|
<a class="btn btn-danger ask" data-backto="record-list">
|
||||||
<i class="fa fa-trash"></i> <?php echo tr('Elimina'); ?>
|
<i class="fa fa-trash"></i> <?php echo tr('Elimina'); ?>
|
||||||
</a>
|
</a>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
<?php
|
<?php
|
||||||
|
@@ -20,4 +20,10 @@ if (isset($id_record)) {
|
|||||||
$record['idcausalet'] = $record['idcausalet'] ?: $dbo->fetchOne('SELECT id FROM dt_causalet WHERE predefined = 1')['id'];
|
$record['idcausalet'] = $record['idcausalet'] ?: $dbo->fetchOne('SELECT id FROM dt_causalet WHERE predefined = 1')['id'];
|
||||||
$record['idspedizione'] = $record['idspedizione'] ?: $dbo->fetchOne('SELECT id FROM dt_spedizione WHERE predefined = 1')['id'];
|
$record['idspedizione'] = $record['idspedizione'] ?: $dbo->fetchOne('SELECT id FROM dt_spedizione WHERE predefined = 1')['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Se la sede del ddt non è di mia competenza, blocco il ddt in modifica
|
||||||
|
$field_name = ( $dir == 'entrata' ) ? 'idsede_partenza' : 'idsede_destinazione';
|
||||||
|
if (!in_array($record[$field_name], $user->idsedi)){
|
||||||
|
$record['flag_completato'] = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -161,7 +161,7 @@ if (empty($record['is_fiscale'])) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
{[ "type": "select", "label": "<?php echo tr('Destinazione merce'); ?>", "name": "idsede_destinazione", "ajax-source": "sedi_azienda", "value": "$idsede_destinazione$", "readonly": "<?php echo $record['flag_completato']; ?>" ]}
|
{[ "type": "select", "label": "<?php echo tr('Destinazione merce'); ?>", "name": "idsede_destinazione", "ajax-source": "sedi_azienda", "value": "$idsede_destinazione$", "readonly": "<?php echo (sizeof($articolo)) ? 1 : 0; ?>" ]}
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
} else {
|
} else {
|
||||||
@@ -171,11 +171,12 @@ if (empty($record['is_fiscale'])) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
{[ "type": "select", "label": "<?php echo tr('Destinazione merce'); ?>", "name": "idsede_destinazione", "ajax-source": "sedi", "value": "$idsede_destinazione$", "readonly": "<?php echo $record['flag_completato']; ?>" ]}
|
{[ "type": "select", "label": "<?php echo tr('Destinazione merce'); ?>", "name": "idsede_destinazione", "ajax-source": "sedi", "value": "$idsede_destinazione$", "readonly": "" ]}
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<!-- TODO: Rimuovere possibilità di selezionare lo stato pagato obbligando l'utente ad aggiungere il movimento in prima nota -->
|
<!-- TODO: Rimuovere possibilità di selezionare lo stato pagato obbligando l'utente ad aggiungere il movimento in prima nota -->
|
||||||
{[ "type": "select", "label": "<?php echo tr('Stato'); ?>", "name": "idstatodocumento", "required": 1, "values": "query=<?php echo $query; ?>", "value": "$idstatodocumento$", "class": "unblockable", "extra": " onchange = \"if ($('#idstatodocumento option:selected').text()=='Pagato' || $('#idstatodocumento option:selected').text()=='Parzialmente pagato' ){if( confirm('<?php echo tr('Sicuro di voler impostare manualmente la fattura come pagata senza aggiungere il movimento in prima nota?'); ?>') ){ return true; }else{ $('#idstatodocumento').selectSet(<?php echo $record['idstatodocumento']; ?>); }}\" " ]}
|
{[ "type": "select", "label": "<?php echo tr('Stato'); ?>", "name": "idstatodocumento", "required": 1, "values": "query=<?php echo $query; ?>", "value": "$idstatodocumento$", "class": "unblockable", "extra": " onchange = \"if ($('#idstatodocumento option:selected').text()=='Pagato' || $('#idstatodocumento option:selected').text()=='Parzialmente pagato' ){if( confirm('<?php echo tr('Sicuro di voler impostare manualmente la fattura come pagata senza aggiungere il movimento in prima nota?'); ?>') ){ return true; }else{ $('#idstatodocumento').selectSet(<?php echo $record['idstatodocumento']; ?>); }}\" " ]}
|
||||||
@@ -670,11 +671,17 @@ if (!empty($note_accredito)) {
|
|||||||
|
|
||||||
{( "name": "log_email", "id_module": "$id_module$", "id_record": "$id_record$" )}
|
{( "name": "log_email", "id_module": "$id_module$", "id_record": "$id_record$" )}
|
||||||
|
|
||||||
<a class="btn btn-danger ask" data-backto="record-list">
|
|
||||||
<i class="fa fa-trash"></i> <?php echo tr('Elimina'); ?>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
// Eliminazione ddt solo se ho accesso alla sede aziendale
|
||||||
|
$field_name = ( $dir == 'entrata' ) ? 'idsede_partenza' : 'idsede_uscita';
|
||||||
|
if (in_array($record[$field_name], $user->idsedi)){
|
||||||
|
?>
|
||||||
|
<a class="btn btn-danger ask" data-backto="record-list">
|
||||||
|
<i class="fa fa-trash"></i> <?php echo tr('Elimina'); ?>
|
||||||
|
</a>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@ switch (filter('op')) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Cambio di password e usernome dell'utente
|
// Cambio di password e username dell'utente
|
||||||
case 'change_pwd':
|
case 'change_pwd':
|
||||||
$id_utente = filter('id_utente');
|
$id_utente = filter('id_utente');
|
||||||
$min_length = filter('min_length');
|
$min_length = filter('min_length');
|
||||||
@@ -41,6 +41,11 @@ switch (filter('op')) {
|
|||||||
|
|
||||||
$dbo->query('UPDATE zz_users SET password='.prepare(Auth::hashPassword($password)).', idanagrafica='.prepare($idanagrafica).', email='.prepare($email).' WHERE id='.prepare($id_utente));
|
$dbo->query('UPDATE zz_users SET password='.prepare(Auth::hashPassword($password)).', idanagrafica='.prepare($idanagrafica).', email='.prepare($email).' WHERE id='.prepare($id_utente));
|
||||||
|
|
||||||
|
$dbo->query('DELETE FROM zz_user_sedi WHERE id_user='.prepare($id_utente));
|
||||||
|
foreach(post('idsede') as $i=>$idsede ){
|
||||||
|
$dbo->query('INSERT INTO `zz_user_sedi` (`id_user`,`idsede`) VALUES ('.prepare($id_utente).', '.prepare($idsede).')');
|
||||||
|
}
|
||||||
|
|
||||||
flash()->info(tr('Password aggiornata!'));
|
flash()->info(tr('Password aggiornata!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +98,13 @@ switch (filter('op')) {
|
|||||||
} else {
|
} else {
|
||||||
if ($dbo->query('INSERT INTO zz_users(idgruppo, username, password, idanagrafica, enabled, email) VALUES('.prepare($id_record).', '.prepare($username).', '.prepare(Auth::hashPassword($password)).', '.prepare($idanagrafica).', 1, '.prepare($email).')')) {
|
if ($dbo->query('INSERT INTO zz_users(idgruppo, username, password, idanagrafica, enabled, email) VALUES('.prepare($id_record).', '.prepare($username).', '.prepare(Auth::hashPassword($password)).', '.prepare($idanagrafica).', 1, '.prepare($email).')')) {
|
||||||
$dbo->query('INSERT INTO `zz_tokens` (`id_utente`, `token`) VALUES ('.prepare($dbo->lastInsertedID()).', '.prepare(secure_random_string()).')');
|
$dbo->query('INSERT INTO `zz_tokens` (`id_utente`, `token`) VALUES ('.prepare($dbo->lastInsertedID()).', '.prepare(secure_random_string()).')');
|
||||||
|
|
||||||
flash()->info(tr('Utente aggiunto!'));
|
flash()->info(tr('Utente aggiunto!'));
|
||||||
|
|
||||||
|
$id_utente = $dbo->lastInsertedID();
|
||||||
|
|
||||||
|
foreach(post('idsede') as $i=>$idsede ){
|
||||||
|
$dbo->query('INSERT INTO `zz_user_sedi` (`id_user`,`idsede`) VALUES ('.prepare($id_utente).', '.prepare($idsede).')');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@@ -21,6 +21,7 @@ if (!empty($utenti)) {
|
|||||||
<th>'.tr('Nome utente').'</th>
|
<th>'.tr('Nome utente').'</th>
|
||||||
<th>'.tr('Ragione sociale').'</th>
|
<th>'.tr('Ragione sociale').'</th>
|
||||||
<th>'.tr('Tipo di anagrafica').'</th>
|
<th>'.tr('Tipo di anagrafica').'</th>
|
||||||
|
<th>'.tr('Sedi').'</th>
|
||||||
<th width="120">'.tr('Opzioni').'</th>
|
<th width="120">'.tr('Opzioni').'</th>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
@@ -41,6 +42,12 @@ if (!empty($utenti)) {
|
|||||||
<td>-</td>
|
<td>-</td>
|
||||||
<td>-</td>';
|
<td>-</td>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sedi = $dbo->fetchOne('SELECT GROUP_CONCAT(nomesede SEPARATOR ", " ) as nomesede FROM zz_user_sedi INNER JOIN ((SELECT "0" AS id, "Sede legale" AS nomesede) UNION (SELECT id, nomesede FROM an_sedi)) sedi ON zz_user_sedi.idsede=sedi.id WHERE id_user='.prepare($utente['id']).' GROUP BY id_user ')['nomesede'];
|
||||||
|
|
||||||
|
echo '
|
||||||
|
<td>'.$sedi.'</td>';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Funzioni per gli utenti
|
* Funzioni per gli utenti
|
||||||
*/
|
*/
|
||||||
|
@@ -35,6 +35,10 @@ if (!empty($id_utente)) {
|
|||||||
$username = $rs[0]['username'];
|
$username = $rs[0]['username'];
|
||||||
$email = $rs[0]['email'];
|
$email = $rs[0]['email'];
|
||||||
$id_anagrafica = $rs[0]['idanagrafica'];
|
$id_anagrafica = $rs[0]['idanagrafica'];
|
||||||
|
|
||||||
|
// Lettura sedi dell'utente già impostate
|
||||||
|
$idsedi = $dbo->fetchOne('SELECT GROUP_CONCAT(idsede) as idsedi FROM zz_user_sedi WHERE id_user='.prepare($id_utente).' GROUP BY id_user')['idsedi'];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$op = 'adduser';
|
$op = 'adduser';
|
||||||
$message = tr('Aggiungi');
|
$message = tr('Aggiungi');
|
||||||
@@ -42,8 +46,11 @@ if (!empty($id_utente)) {
|
|||||||
$username = '';
|
$username = '';
|
||||||
$email = '';
|
$email = '';
|
||||||
$id_anagrafica = '';
|
$id_anagrafica = '';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$_SESSION['superselect']['idanagrafica'] = $id_anagrafica;
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<form action="" method="post" id="link_form">
|
<form action="" method="post" id="link_form">
|
||||||
<input type="hidden" name="op" value="'.$op.'">
|
<input type="hidden" name="op" value="'.$op.'">
|
||||||
@@ -100,13 +107,20 @@ if (!$self_edit) {
|
|||||||
{[ "type": "select", "label": "'.tr('Collega ad una anagrafica').'", "name": "idanag", "required": 1, "ajax-source": "anagrafiche_utenti", "value": "'.$id_anagrafica.'", "icon-after": "add|'.Modules::get('Anagrafiche')['id'].'|tipoanagrafica='.$nome_gruppo.'" ]}
|
{[ "type": "select", "label": "'.tr('Collega ad una anagrafica').'", "name": "idanag", "required": 1, "ajax-source": "anagrafiche_utenti", "value": "'.$id_anagrafica.'", "icon-after": "add|'.Modules::get('Anagrafiche')['id'].'|tipoanagrafica='.$nome_gruppo.'" ]}
|
||||||
</div>
|
</div>
|
||||||
</div>';
|
</div>';
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo '
|
echo '
|
||||||
<input type="hidden" id="idanag" name="idanag" value="'.$id_anagrafica.'">';
|
<input type="hidden" id="idanag" name="idanag" value="'.$id_anagrafica.'">';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
{[ "type": "select", "label": "'.tr('Sede').'", "name": "idsede[]", "ajax-source": "sedi", "multiple":"1", "value":"'.$idsedi.'" ]}
|
||||||
|
</div>
|
||||||
|
</div>';
|
||||||
|
|
||||||
|
echo '
|
||||||
<button type="button" onclick="do_submit()" class="btn btn-primary pull-right"><i class="fa fa-plus"></i> '.$message.'</button>
|
<button type="button" onclick="do_submit()" class="btn btn-primary pull-right"><i class="fa fa-plus"></i> '.$message.'</button>
|
||||||
<div class="clearfix"> </div>
|
<div class="clearfix"> </div>
|
||||||
</form>
|
</form>
|
||||||
@@ -144,7 +158,11 @@ echo '
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$("#bs-popup #idanag").val("'.$id_anagrafica.'").change();
|
$("#idanag").change(function(){
|
||||||
|
session_set("superselect,idanagrafica", $(this).val(), 0);
|
||||||
|
|
||||||
|
$("#idsede").selectReset();
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
10
src/Auth.php
10
src/Auth.php
@@ -464,6 +464,16 @@ class Auth extends \Util\Singleton
|
|||||||
|
|
||||||
if (!empty($results)) {
|
if (!empty($results)) {
|
||||||
$this->user = User::with('group')->find($user_id);
|
$this->user = User::with('group')->find($user_id);
|
||||||
|
|
||||||
|
// Estraggo le sedi dell'utente loggato
|
||||||
|
$idsedi = $database->fetchArray('SELECT idsede FROM zz_user_sedi WHERE id_user='.prepare($user_id));
|
||||||
|
|
||||||
|
// Se l'utente non ha sedi, è come se ce le avesse tutte disponibili per retrocompatibilità
|
||||||
|
if (empty($idsedi)){
|
||||||
|
$idsedi = $database->fetchArray('SELECT id AS idsede FROM an_sedi WHERE idanagrafica='.prepare($results[0]['idanagrafica']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->user['idsedi'] = array_column( $idsedi, 'idsede' );
|
||||||
}
|
}
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$this->destory();
|
$this->destory();
|
||||||
|
@@ -98,3 +98,8 @@ UPDATE `zz_views` SET `query` = 'IF(`email`.`name` IS NOT NULL, \'fa fa-envelope
|
|||||||
-- Sistemo vista per icon_title_Inviata modulo Fatture di vendita
|
-- Sistemo vista per icon_title_Inviata modulo Fatture di vendita
|
||||||
UPDATE `zz_views` SET `query` = '`email`.`name`' WHERE `zz_views`.`name` = 'icon_title_Inviata' AND `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Fatture di vendita') ;
|
UPDATE `zz_views` SET `query` = '`email`.`name`' WHERE `zz_views`.`name` = 'icon_title_Inviata' AND `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Fatture di vendita') ;
|
||||||
|
|
||||||
|
-- Relazione fra utente e una o più sedi
|
||||||
|
CREATE TABLE `zz_user_sedi` (
|
||||||
|
`id_user` int(11) NOT NULL,
|
||||||
|
`idsede` int(11) NOT NULL
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user