mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-16 11:30:55 +01:00
Aggiunta relazione utente-sedi per filtro sede azienda + fix calcolo giancenze
This commit is contained in:
parent
4303bd8bf8
commit
9d1d40e385
@ -14,7 +14,7 @@ if (!isset($resource)) {
|
||||
$elements = (!is_array($elements)) ? explode(',', $elements) : $elements;
|
||||
|
||||
$results = AJAX::select($op, $elements, $search, $page, $length);
|
||||
|
||||
|
||||
echo json_encode($results);
|
||||
}
|
||||
|
||||
|
@ -217,19 +217,23 @@ switch ($resource) {
|
||||
|
||||
case 'sedi_azienda':
|
||||
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) {
|
||||
$filter[] = 'id='.prepare($element);
|
||||
}
|
||||
|
||||
$where[] = 'idanagrafica='.prepare(setting('Azienda predefinita'));
|
||||
$where[] = 'idanagrafica='.prepare($user->idanagrafica);
|
||||
$where[] = 'id IN('.implode(',', $user->idsedi).')';
|
||||
|
||||
if (!empty($search)) {
|
||||
$search_fields[] = 'nomesede LIKE '.prepare('%'.$search.'%');
|
||||
$search_fields[] = 'citta LIKE '.prepare('%'.$search.'%');
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'referenti':
|
||||
|
@ -324,9 +324,17 @@ if (!empty($elementi)) {
|
||||
|
||||
?>
|
||||
|
||||
<a class="btn btn-danger ask" data-backto="record-list">
|
||||
<i class="fa fa-trash"></i> <?php echo tr('Elimina'); ?>
|
||||
</a>
|
||||
<?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'); ?>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<script>
|
||||
<?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['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;
|
||||
}
|
||||
}
|
||||
|
@ -151,31 +151,32 @@ if (empty($record['is_fiscale'])) {
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// Conteggio numero articoli fatture
|
||||
$articolo = $dbo->fetchArray('SELECT mg_articoli.id FROM ((mg_articoli INNER JOIN co_righe_documenti ON mg_articoli.id=co_righe_documenti.idarticolo) INNER JOIN co_documenti ON co_documenti.id=co_righe_documenti.iddocumento) WHERE co_documenti.id='.prepare($id_record));
|
||||
if ($dir == 'uscita') {
|
||||
?>
|
||||
<div class="col-md-3">
|
||||
{[ "type": "select", "label": "<?php echo tr('Partenza merce'); ?>", "name": "idsede_partenza", "ajax-source": "sedi", "placeholder": "Sede legale", "value": "$idsede_partenza$"]}
|
||||
</div>
|
||||
|
||||
<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']; ?>" ]}
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div class="col-md-3">
|
||||
{[ "type": "select", "label": "<?php echo tr('Partenza merce'); ?>", "name": "idsede_partenza", "ajax-source": "sedi_azienda", "placeholder": "Sede legale", "value": "$idsede_partenza$", "readonly": "<?php echo (sizeof($articolo)) ? 1 : 0; ?>" ]}
|
||||
</div>
|
||||
|
||||
<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']; ?>" ]}
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
<?php
|
||||
// Conteggio numero articoli fatture
|
||||
$articolo = $dbo->fetchArray('SELECT mg_articoli.id FROM ((mg_articoli INNER JOIN co_righe_documenti ON mg_articoli.id=co_righe_documenti.idarticolo) INNER JOIN co_documenti ON co_documenti.id=co_righe_documenti.iddocumento) WHERE co_documenti.id='.prepare($id_record));
|
||||
if ($dir == 'uscita') {
|
||||
?>
|
||||
<div class="col-md-3">
|
||||
{[ "type": "select", "label": "<?php echo tr('Partenza merce'); ?>", "name": "idsede_partenza", "ajax-source": "sedi", "placeholder": "Sede legale", "value": "$idsede_partenza$"]}
|
||||
</div>
|
||||
|
||||
<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 (sizeof($articolo)) ? 1 : 0; ?>" ]}
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div class="col-md-3">
|
||||
{[ "type": "select", "label": "<?php echo tr('Partenza merce'); ?>", "name": "idsede_partenza", "ajax-source": "sedi_azienda", "placeholder": "Sede legale", "value": "$idsede_partenza$", "readonly": "<?php echo (sizeof($articolo)) ? 1 : 0; ?>" ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
{[ "type": "select", "label": "<?php echo tr('Destinazione merce'); ?>", "name": "idsede_destinazione", "ajax-source": "sedi", "value": "$idsede_destinazione$", "readonly": "" ]}
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="col-md-3">
|
||||
<!-- 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']; ?>); }}\" " ]}
|
||||
@ -670,11 +671,17 @@ if (!empty($note_accredito)) {
|
||||
|
||||
{( "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
|
||||
// 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 '
|
||||
<script>
|
||||
|
||||
|
@ -19,7 +19,7 @@ switch (filter('op')) {
|
||||
}
|
||||
break;
|
||||
|
||||
// Cambio di password e usernome dell'utente
|
||||
// Cambio di password e username dell'utente
|
||||
case 'change_pwd':
|
||||
$id_utente = filter('id_utente');
|
||||
$min_length = filter('min_length');
|
||||
@ -40,6 +40,11 @@ switch (filter('op')) {
|
||||
$idanagrafica = filter('idanag');
|
||||
|
||||
$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!'));
|
||||
}
|
||||
@ -93,8 +98,13 @@ switch (filter('op')) {
|
||||
} 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).')')) {
|
||||
$dbo->query('INSERT INTO `zz_tokens` (`id_utente`, `token`) VALUES ('.prepare($dbo->lastInsertedID()).', '.prepare(secure_random_string()).')');
|
||||
|
||||
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 {
|
||||
|
@ -20,7 +20,8 @@ if (!empty($utenti)) {
|
||||
<tr>
|
||||
<th>'.tr('Nome utente').'</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>
|
||||
</tr>';
|
||||
|
||||
@ -41,11 +42,17 @@ if (!empty($utenti)) {
|
||||
<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
|
||||
*/
|
||||
echo '
|
||||
<td>';
|
||||
<td>';
|
||||
// Disabilitazione utente, se diverso da id_utente #1 (admin)
|
||||
if ($utente['id'] != '1') {
|
||||
if ($utente['enabled'] == 1) {
|
||||
|
@ -34,16 +34,23 @@ if (!empty($id_utente)) {
|
||||
$rs = $dbo->fetchArray('SELECT idanagrafica, username, email FROM zz_users WHERE id='.prepare($id_utente));
|
||||
$username = $rs[0]['username'];
|
||||
$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 {
|
||||
$op = 'adduser';
|
||||
$message = tr('Aggiungi');
|
||||
|
||||
$username = '';
|
||||
$email = '';
|
||||
$id_anagrafica = '';
|
||||
$id_anagrafica = '';
|
||||
|
||||
}
|
||||
|
||||
$_SESSION['superselect']['idanagrafica'] = $id_anagrafica;
|
||||
|
||||
echo '
|
||||
<form action="" method="post" id="link_form">
|
||||
<input type="hidden" name="op" value="'.$op.'">
|
||||
@ -99,14 +106,21 @@ if (!$self_edit) {
|
||||
<div class="col-md-12">
|
||||
{[ "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>';
|
||||
|
||||
} else {
|
||||
echo '
|
||||
<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>
|
||||
<div class="clearfix"> </div>
|
||||
</form>
|
||||
@ -142,11 +156,15 @@ echo '
|
||||
else
|
||||
$("#link_form").submit();
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#bs-popup #idanag").val("'.$id_anagrafica.'").change();
|
||||
$("#idanag").change(function(){
|
||||
session_set("superselect,idanagrafica", $(this).val(), 0);
|
||||
|
||||
$("#idsede").selectReset();
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<script src="'.$rootdir.'/lib/init.js"></script>';
|
||||
|
10
src/Auth.php
10
src/Auth.php
@ -464,6 +464,16 @@ class Auth extends \Util\Singleton
|
||||
|
||||
if (!empty($results)) {
|
||||
$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) {
|
||||
$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
|
||||
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
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user