Start Point al 2026
This commit is contained in:
commit
8a76e1db3b
371 files changed
+160283
No files matched your search
@@ -0,0 +1,93 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
|
||||
use App\Models\Lavoratori_Model;
|
||||
use App\Models\Clienti_Model;
|
||||
|
||||
|
||||
class Admin extends BaseController{
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// visualizza e permette il CRUD della tabella indicata:
|
||||
public function crud($tab = 'Clienti'){
|
||||
$data['title'] = "CRUD della tabella: $tab";
|
||||
helper(['tools','form']);
|
||||
|
||||
return view('test', $data);
|
||||
}//function clienti()
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// visualizza e permette il CRUD della tabella Clienti:
|
||||
public function clienti($order_field = null, $order_direction = null) {
|
||||
// Tab: Clienti = ['clIDcliente', 'clNome', 'clInfo', 'clCreatedAt', 'clUpdatedAt', 'clDeletedAt'];
|
||||
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'admin';
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(3)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
// gestisco ordinamento:
|
||||
if (null==$order_field){ $order_field = 'clIDcliente'; }
|
||||
if (null==$order_direction){ $order_direction = 'DESC'; }
|
||||
|
||||
// Imposto i parametri per la pagina parametrica:
|
||||
$data['title'] = 'Elenco clienti della CSiCo:'; // titolo della pagina
|
||||
$data['cmd_tab'] = [ // Elenco dei comandi per l'intera tabella
|
||||
'add' => 'clienti/add', // - inserimento nuovo record
|
||||
'exp_csv' => 'clienti/export_csv', // - esportazione in csv dei records
|
||||
];
|
||||
$data['cmd_rec'] = [ // Elenco dei comandi per ciascun records
|
||||
'edit' => 'clienti/edit', // - editazione del record
|
||||
'delete' => 'clienti/delete', // - cancellazione del record
|
||||
//'select' => 'clienti/select', // - selezione del record
|
||||
];
|
||||
$data['fields'] = [ // campi che voglio riportare sulla tabella (nell'ordine voluto)
|
||||
'clIDcliente' => 'ID', // - coppia Key -> Label dove key è l'identificativo del campo sul database, e label è il testo che vogliamo visualizzare.
|
||||
'clNome' => 'Nome', // - coppia Key -> Label
|
||||
'clInfo' => 'Info', // - coppia Key -> Label
|
||||
'clCreatedAt' => 'CreatedAt', // - coppia Key -> Label
|
||||
'clUpdatedAt' => 'UpdatedAt', // - coppia Key -> Label
|
||||
'clDeletedAt' => 'DeletedAt' // - coppia Key -> Label
|
||||
];
|
||||
$data['id'] = 'clIDcliente'; // identificativo del campo che fa ta ID della tabella
|
||||
$data['sort'] = [ // ordinamento della tabella
|
||||
'calbck' => 'admin/clienti', // funzione di call back per il riordino
|
||||
'field' => $order_field, // Colonna utilizzata per l'ordinamento
|
||||
'val' => $order_direction, // Tipo di ordinamento (ascendente o discendente)
|
||||
];
|
||||
|
||||
// Ricavo i dati da visualizzare:
|
||||
$model = new Clienti_Model();
|
||||
// imposto l'ordinamento selezionato
|
||||
if (isset($data['sort'])){
|
||||
$order_field = $data['sort']['field'];
|
||||
$order_direction =$data['sort']['val'];
|
||||
$model->orderBy($order_field, $order_direction);
|
||||
}
|
||||
// eseguo la query con paginazione:
|
||||
$data['dataset'] = $model->paginate(session()->get('pager_num'));
|
||||
$data['pager'] = $model->pager;
|
||||
|
||||
return view('pages/crud', $data);
|
||||
}//function clienti()
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}//class Admin
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
|
||||
|
||||
class Articoli extends CRUDController {
|
||||
|
||||
// Tab: Articoli = ['arIDarticolo', 'arCode', 'arIDcategoria', 'arIDplace', 'arNome', 'arDescrizione', 'arDataAcquisto', 'arEuro', 'arCreatedAt', 'arUpdatedAt', 'arDeletedAt'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'Articoli',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Articolo',
|
||||
'form_title_update' => 'Edit Articolo',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella Articoli',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => 'arUpdatedAt',
|
||||
'DeletedAt' => 'arDeletedAt',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['arIDarticolo'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['arCode'] = ['label' => 'Codice', 'helper' => 'Codice identificativo dell\'articolo (5 caratteri)', 'required' => true, 'unique' => [true, 'arCode']];
|
||||
$fields['arIDcategoria'] = [
|
||||
'label' => 'Categoria',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'relation' => [
|
||||
'table'=> 'Categorie',
|
||||
'primary_key' => 'caIDcategoria',
|
||||
'display' => ['caCode', 'caNome'],
|
||||
'order_by' => 'caCode',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['arIDplace'] = [
|
||||
'label' => 'Posizione',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'relation' => [
|
||||
'table'=> 'Posizioni',
|
||||
'primary_key' => 'psIDplace',
|
||||
'display' => ['psCode', 'psDescrizione'],
|
||||
'order_by' => 'psCode',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['arNome'] = ['label' => 'Nome', 'helper' => 'Nome dell\'articolo (max 32 caratteri)', 'required' => true];
|
||||
$fields['arDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva dell\'articolo', 'required' => true];
|
||||
$fields['arDataAcquisto'] = ['label' => 'Data Acquisto', 'helper' => 'Data di acquisto dell\'articolo', 'required' => true, 'type' => 'date'];
|
||||
$fields['arEuro'] = ['label' => 'Valore', 'helper' => 'Valore stimato dell\'articolo in €', 'required' => true];
|
||||
$fields['arCreatedAt'] = ['label' => 'Created At', 'helper' => 'Data di creazione del record relativo nel database', 'only_edit'=> true];
|
||||
$fields['arUpdatedAt'] = ['label' => 'Updated At', 'helper' => 'Timestamp dell\'ultimo aggiornamento del record nel database', 'type' => 'unset'];
|
||||
$fields['arDeletedAt'] = ['label' => 'Deleted At', 'helper' => 'Data di cancellazione del record relativo nel database', 'type' => 'unset'];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['arIDarticolo', 'arCode', 'arIDcategoria', 'arIDplace', 'arNome', 'arDescrizione', 'arDataAcquisto', 'arEuro', 'arCreatedAt', 'arUpdatedAt', 'arDeletedAt']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
|
||||
|
||||
class ArticoloEvents extends CRUDController {
|
||||
|
||||
// Tab: ArticoloEvents = ['earIDarticoloEvent', 'earIDarticolo', 'earIDlavoratore', 'earDescrizione', 'earData', 'earTipologia'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'ArticoloEvents',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Evento',
|
||||
'form_title_update' => 'Edit Evento',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella ArticoloEvents',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => '',
|
||||
'DeletedAt' => '',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['earIDarticoloEvent'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['earIDarticolo'] = [
|
||||
'label' => 'Articolo',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Articolo a cui si riferisce l\'evento',
|
||||
'relation' => [
|
||||
'table'=> 'Articoli',
|
||||
'primary_key' => 'arIDarticolo',
|
||||
'display' => ['arCode', 'arNome'],
|
||||
'order_by' => 'arCode',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['earIDlavoratore'] = [
|
||||
'label' => 'Lavoratore',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Lavoratore a cui si riferisce l\'evento',
|
||||
'relation' => [
|
||||
'table'=> 'Lavoratori',
|
||||
'primary_key' => 'lvIDlavoratore',
|
||||
'display' => ['lvNickname', 'lvNome', 'lvCognome'], //'display' => ['lvNickname'],
|
||||
'order_by' => 'lvNickname',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['earDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva dell\'evento', 'required' => true];
|
||||
$fields['earData'] = ['label' => 'Timestamp', 'helper' => 'Timestamp dell\'evento', 'required' => true, 'type' => 'date'];
|
||||
$fields['earTipologia'] = ['label' => 'Tipo', 'helper' => 'Tipologia di evento', 'required' => true];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['earIDarticoloEvent', 'earIDarticolo', 'earIDlavoratore', 'earDescrizione', 'earData', 'earTipologia']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
/**
|
||||
* Class BaseController
|
||||
*
|
||||
* BaseController provides a convenient place for loading components
|
||||
* and performing functions that are needed by all your controllers.
|
||||
* Extend this class in any new controllers:
|
||||
* class Home extends BaseController
|
||||
*
|
||||
* For security be sure to declare any new methods as protected or private.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
*/
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
class BaseController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* An array of helpers to be loaded automatically upon
|
||||
* class instantiation. These helpers will be available
|
||||
* to all other controllers that extend BaseController.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $helpers = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
// Do Not Edit This Line
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Preload any models, libraries, etc, here.
|
||||
//--------------------------------------------------------------------
|
||||
// E.g.:
|
||||
// $this->session = \Config\Services::session();
|
||||
|
||||
date_default_timezone_set('Europe/Rome'); // Imposto il timestamp voluto e sono a posto.
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
|
||||
|
||||
class CRUDController extends BaseController {
|
||||
|
||||
|
||||
protected $crud;
|
||||
|
||||
public function CRUD_view($cols) {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'admin';
|
||||
|
||||
$page = 1;
|
||||
if (isset($_GET['page'])) {
|
||||
$page = (int) $_GET['page'];
|
||||
$page = max(1, $page);
|
||||
}
|
||||
|
||||
$data['title'] = $this->crud->getTableTitle();
|
||||
|
||||
$per_page = session()->get('pager_num');
|
||||
$columns = $cols;
|
||||
$where = null;//['DeletedAt =' => 'null'];
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort( $this->crud->getTable(), true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$order = [
|
||||
[$data['sortCol'], $data['sortDir']]
|
||||
];
|
||||
$data['order']=$order;
|
||||
$data['table'] = $this->crud->MRK_view($page, $per_page, $columns, $where, $order);
|
||||
return view('pages/crud_table', $data);
|
||||
}//function CRUD_view
|
||||
|
||||
public function CRUD_viewSelect($cols) {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'admin';
|
||||
|
||||
$page = 1;
|
||||
if (isset($_GET['page'])) {
|
||||
$page = (int) $_GET['page'];
|
||||
$page = max(1, $page);
|
||||
}
|
||||
|
||||
$data['title'] = $this->crud->getTableTitle();
|
||||
|
||||
$per_page = session()->get('pager_num');
|
||||
$columns = $cols;
|
||||
$where = null;//['DeletedAt =' => 'null'];
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort( $this->crud->getTable(), true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$order = [
|
||||
[$data['sortCol'], $data['sortDir']]
|
||||
];
|
||||
$data['order']=$order;
|
||||
$data['table'] = $this->crud->mrk_viewSelectCommessa($page, $per_page, $columns, $where, $order);
|
||||
return view('pages/crud_table', $data);
|
||||
}//function CRUD_view
|
||||
|
||||
|
||||
public function CRUD_add() {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(3)) {
|
||||
session()->setFlashdata('warning', 'L\'utente non ha i permessi per inserire un nuovo record');
|
||||
$pg = $this->crud->getTable();
|
||||
return redirect()->to("/$pg");
|
||||
}
|
||||
|
||||
$data['tab'] = 'admin';
|
||||
$data['form'] = $form = $this->crud->form();
|
||||
$data['title'] = $this->crud->getAddTitle();
|
||||
|
||||
if(is_array($form) && isset($form['redirect']))
|
||||
return redirect()->to($form['redirect']);
|
||||
|
||||
return view('pages/crud_form', $data);
|
||||
}//function CRUD_add
|
||||
|
||||
|
||||
public function CRUD_edit($id) {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(3)) {
|
||||
session()->setFlashdata('warning', 'L\'utente non ha i permessi per editare un record');
|
||||
$pg = $this->crud->getTable();
|
||||
return redirect()->to("/$pg");
|
||||
}
|
||||
|
||||
$data['tab'] = 'admin';
|
||||
|
||||
if(!$this->crud->current_values($id))
|
||||
return redirect()->to($this->crud->getBase() . '/' . $this->crud->getTable());
|
||||
|
||||
$data['item_id'] = $id;
|
||||
$data['form'] = $form = $this->crud->form();
|
||||
$data['title'] = $this->crud->getEditTitle();
|
||||
|
||||
if (is_array($form) && isset($form['redirect']))
|
||||
return redirect()->to($form['redirect']);
|
||||
|
||||
return view('pages/crud_form', $data);
|
||||
}//function CRUD_edit
|
||||
|
||||
|
||||
function CRUD_delete($id) {
|
||||
$data = [];
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(3)) {
|
||||
session()->setFlashdata('warning', 'L\'utente non ha i permessi per eliminare un record');
|
||||
} else {
|
||||
// Debug
|
||||
//$data['form'] = $this->crud->MRK_deleteItem($id);
|
||||
//return view('test', $data);
|
||||
// Elimino il record:
|
||||
if ($this->crud->MRK_deleteItem($id)) {
|
||||
session()->setFlashdata('success', 'Recors cancellato correttamente.');
|
||||
|
||||
} else {
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
}
|
||||
$pg = $this->crud->getTable();
|
||||
return redirect()->to("/$pg");
|
||||
|
||||
}//function CRUD_delete
|
||||
|
||||
|
||||
function CRUD_sort($col, $dir){
|
||||
helper(['tools']);
|
||||
SetSort($this->crud->getTable(), $col, $dir);
|
||||
|
||||
//return $this->CRUD_view();
|
||||
$pg = $this->crud->getTable();
|
||||
return redirect()->to("/$pg");
|
||||
}//function CRUD_sort
|
||||
|
||||
|
||||
function CRUD_exp(){
|
||||
helper(['tools']);
|
||||
|
||||
session()->setFlashdata('warning', 'Esportazione dei record, per ora non abilitata.');
|
||||
|
||||
$pg = $this->crud->getTable();
|
||||
return redirect()->to("/$pg");
|
||||
}//function CRUD_exp
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,545 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\Lavoratori_Model;
|
||||
use App\Models\CSiCoCars_Model;
|
||||
use App\Models\CSiCoCarEvents_Model;
|
||||
|
||||
|
||||
class CSiCoCarEvents extends CRUDController {
|
||||
|
||||
// Tab: CSiCoCarEvents = ['ecaIDcarEvent', 'ecaIDcar', 'ecaIDlavoratore', 'ecaDescrizione', 'ecaStato', 'ecaData', 'ecaKm', 'ecaTipologia'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'CSiCoCarEvents',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Evento',
|
||||
'form_title_update' => 'Edit Evento',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella CSiCoCarEvents',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => '',
|
||||
'DeletedAt' => '',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['ecaIDcarEvent'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['ecaIDcar'] = [
|
||||
'label' => 'CSiCoCar',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'CSiCoCar a cui si riferisce l\'evento',
|
||||
'relation' => [
|
||||
'table'=> 'CSiCoCars',
|
||||
'primary_key' => 'caIDcar',
|
||||
'display' => ['caTarga', 'caDescrizione'],
|
||||
'order_by' => 'caTarga',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['ecaIDlavoratore'] = [
|
||||
'label' => 'Lavoratore',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Lavoratore a cui si riferisce l\'evento',
|
||||
'relation' => [
|
||||
'table'=> 'Lavoratori',
|
||||
'primary_key' => 'lvIDlavoratore',
|
||||
'display' => ['lvNickname', 'lvNome', 'lvCognome'], //'display' => ['lvNickname'],
|
||||
'order_by' => 'lvNickname',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['ecaDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva dell\'evento', 'required' => true];
|
||||
$fields['ecaStato'] = ['label' => 'Stato', 'helper' => 'Descrizione esaustiva dello stato attuale della macchina', 'required' => true];
|
||||
$fields['ecaKm'] = ['label' => 'Km', 'helper' => 'Totale Km percorsi (valore del totalizzatore dell\'auto)', 'required' => true];
|
||||
$fields['ecaData'] = ['label' => 'Timestamp', 'helper' => 'Timestamp dell\'evento', 'required' => true, 'type' => 'date'];
|
||||
$fields['ecaTipologia'] = ['label' => 'Tipo', 'helper' => 'Tipologia di evento', 'required' => true];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['ecaIDcarEvent', 'ecaIDcar', 'ecaIDlavoratore', 'ecaDescrizione', 'ecaStato', 'ecaData', 'ecaKm', 'ecaTipologia']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function show() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'cars';
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCarEvents/show -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo la macchina selezionata (se vi è una selezione):
|
||||
$IDcar = session()->get('filter_car');
|
||||
if ((null !== $IDcar) && ($IDcar!=-1)) {
|
||||
$mcc = new CSiCoCars_Model();
|
||||
$data['car'] = $mcc->where('caIDcar', $IDcar)->first();
|
||||
}
|
||||
|
||||
// Ricavo i relativi eventi:
|
||||
$mev = new CSiCoCarEvents_Model();
|
||||
$mev->join('Lavoratori', 'CSiCoCarEvents.ecaIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$mev->join('CSiCoCars', 'CSiCoCarEvents.ecaIDcar = CSiCoCars.caIDcar');
|
||||
|
||||
// Per ora niente filtro, poi in futuro forse
|
||||
$mev->where('ecaIDcar', $IDcar);
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('evncar',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$mev->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query con paginazione:
|
||||
$data['dataset'] = $mev->paginate(session()->get('pager_num'));
|
||||
$data['pager'] = $mev->pager;
|
||||
|
||||
return view('/pages/events/CSiCoCarEvents', $data);
|
||||
}//function select
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function add() {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCarEvents/add -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Ricavo la macchina selezionata (se vi è una selezione):
|
||||
$IDcar = session()->get('filter_car');
|
||||
if ((null == $IDcar) || ($IDcar==-1)) {
|
||||
return redirect()->to('/dashboard/cars');
|
||||
}
|
||||
|
||||
$mcc = new CSiCoCars_Model();
|
||||
$data['car'] = $mcc->where('caIDcar', $IDcar)->first();
|
||||
if ($data['car']==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCarEvents/add -> Error code 002'); }
|
||||
return redirect()->to('/dashboard/cars');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'credit';
|
||||
$data['add'] = true;
|
||||
$data['title'] = 'Dettagli nuova evento della macchina: ' . $data['car']->ccNumero;
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Data' => 'trim|required',
|
||||
'Km' => 'trim|required',
|
||||
'Tipologia' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
'Stato' => 'trim|required|min_length[8]',
|
||||
];
|
||||
if ($enable){
|
||||
$rules['IDlavoratore'] = 'trim|required';
|
||||
}
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
} else {
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
// Tab: CSiCoCarEvents = ['ecaIDcarEvent', 'ecaIDcar', 'ecaIDlavoratore', 'ecaDescrizione', 'ecaStato', 'ecaData', 'ecaKm', 'ecaTipologia'];
|
||||
// Tab: CSiCoCars = ['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'caStato', 'caDeletedAt'];
|
||||
$newData = [
|
||||
'ecaIDcar' => $data['car']->caIDcar,
|
||||
'ecaDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'ecaStato' => $this->request->getVar('Stato'),
|
||||
'ecaData' => $this->request->getVar('Data'),
|
||||
'ecaKm' => $this->request->getVar('Km'),
|
||||
'ecaTipologia' => $this->request->getVar('Tipologia'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['ecaIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
} else {
|
||||
$newData['ecaIDlavoratore'] = session()->get('lavoratore')->lvIDlavoratore;
|
||||
}
|
||||
|
||||
$model = new CSiCoCarEvents_Model();
|
||||
if ($model->save($newData)) {
|
||||
// evento inserito con successo, aggiorno lo stato della carta
|
||||
if ($this->updateCarStato($data['car']->caIDcar)) {
|
||||
// update dello stato nella carta di credito riuscito
|
||||
session()->setFlashdata('success', 'Evento inserito con successo');
|
||||
} else {
|
||||
// update dello stato nella carta di credito fallito
|
||||
session()->setFlashdata('danger', 'Evento inserito ma stato della carta non aggiornato correttamente');
|
||||
}
|
||||
// apro la pagina desiderata in base al pulsante utilizzato:
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/CSiCoCarEvents/show');
|
||||
}
|
||||
} else {
|
||||
// errore durante l'inserimento dell'evento
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/CSiCoCarEvents_form_add_edit', $data);
|
||||
}//function add
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function edit($IDevent = null) {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDevent==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCarEvents/edit -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCarEvents/edit -> Error code 002'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Ricavo l'evento selezionato, completo di tutti i particolari:
|
||||
// Tab: CSiCoCarEvents = ['ecaIDcarEvent', 'ecaIDcar', 'ecaIDlavoratore', 'ecaDescrizione', 'ecaStato', 'ecaData', 'ecaKm', 'ecaTipologia'];
|
||||
// Tab: CSiCoCars = ['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'caStato', 'caDeletedAt'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'caStato', 'lvDeletedAt'];
|
||||
$model = new CSiCoCarEvents_Model();
|
||||
$model->join('CSiCoCars', 'CSiCoCarEvents.ecaIDcar = CSiCoCars.caIDcar');
|
||||
$model->join('Lavoratori', 'CSiCoCarEvents.ecaIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$data['evnt'] = $model->where('ecaIDcarEvent', $IDevent)
|
||||
->first();
|
||||
// Verifico che esista il record:
|
||||
if (null==$data['evnt']) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCarEvents/edit -> Error code 003'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// ricavo la macchina a cui l'evento si riferisce
|
||||
$mcc = new CSiCoCars_Model();
|
||||
$data['car'] = $mcc->where('caIDcar', $data['evnt']->ecaIDcar)->first();
|
||||
// Verifico che esista il record:
|
||||
if ($data['car']==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCarEvents/edit -> Error code 004'); }
|
||||
return redirect()->to('/dashboard/cars');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'credit';
|
||||
$data['add'] = false;
|
||||
$data['title'] = 'Dettagli evento: ' . $data['evnt']->caTarga;
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Data' => 'trim|required',
|
||||
'Km' => 'trim|required',
|
||||
'Tipologia' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
'Stato' => 'trim|required|min_length[8]',
|
||||
];
|
||||
if ($enable){
|
||||
$rules['IDlavoratore'] = 'trim|required';
|
||||
}
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
$newData = [
|
||||
'ecaIDcarEvent' => $IDevent,
|
||||
'ecaDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'ecaStato' => $this->request->getVar('Stato'),
|
||||
'ecaData' => $this->request->getVar('Data'),
|
||||
'ecaKm' => $this->request->getVar('Km'),
|
||||
'ecaTipologia' => $this->request->getVar('Tipologia'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['ecaIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
}
|
||||
|
||||
if ($model->save($newData)) {
|
||||
// evento inserito con successo, aggiorno lo stato della carta
|
||||
if ($this->updateCarStato($data['car']->caIDcar)) {
|
||||
// update dello stato nella carta di credito riuscito
|
||||
session()->setFlashdata('success', 'Evento aggiornato con successo');
|
||||
} else {
|
||||
// update dello stato nella carta di credito fallito
|
||||
session()->setFlashdata('danger', 'Evento inserito ma stato della carta non aggiornato correttamente');
|
||||
}
|
||||
// apro la pagina desiderata in base al pulsante utilizzato:
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/CSiCoCarEvents/show');
|
||||
}
|
||||
} else {
|
||||
// errore durante l'inserimento dell'evento
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/CSiCoCarEvents_form_add_edit', $data);
|
||||
}//function edit
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function delete($IDevent = null){
|
||||
helper(['tools']);
|
||||
$data = [];
|
||||
|
||||
// Ricavo l'evento selezionato, completo di tutti i particolari:
|
||||
// Tab: CSiCoCarEvents = ['ecaIDcarEvent', 'ecaIDcar', 'ecaIDlavoratore', 'ecaDescrizione', 'ecaStato', 'ecaData', 'ecaKm', 'ecaTipologia'];
|
||||
// Tab: CSiCoCars = ['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'caStato', 'caDeletedAt'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt'];
|
||||
$model = new CSiCoCarEvents_Model();
|
||||
$model->join('CSiCoCars', 'CSiCoCarEvents.ecaIDcar = CSiCoCars.caIDcar');
|
||||
$model->join('Lavoratori', 'CSiCoCarEvents.ecaIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$evnt = $model->where('ecaIDcarEvent', $IDevent)
|
||||
->first();
|
||||
// Verifico che esista il record:
|
||||
if (null==$evnt) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCarEvents/delete -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!(CheckLevel(3) || session()->get('lavoratore')->lvIDlavoratore==$evnt->ecaIDlavoratore)) {
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per cancellare un evento inserito da altri lavoratori.');
|
||||
return redirect()->to('/CSiCoCarEvents/show');
|
||||
}
|
||||
|
||||
// Elimino il record:
|
||||
if ($model->delete($IDevent)) {
|
||||
// Evento cancellato, aggiorno stato della macchina relativa
|
||||
if ($this->updateCarStato($evnt->ecaIDcar)) {
|
||||
// update dello stato nella macchina riuscito
|
||||
session()->setFlashdata('success', 'Recors cancellato correttamente.');
|
||||
} else {
|
||||
// update dello stato nella macchina fallito
|
||||
session()->setFlashdata('danger', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
} else {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
|
||||
// Show profile
|
||||
return redirect()->to('/CSiCoCarEvents/show');
|
||||
} // function delete($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function export_csv(){
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCars/export_csv -> Error code 001'); }
|
||||
return redirect()->to('/CSiCoCarEvents/show');
|
||||
}
|
||||
|
||||
// Ricavo gli eventi della carta di credito:
|
||||
// Tab: CSiCoCarEvents = ['ecaIDcarEvent', 'ecaIDcar', 'ecaIDlavoratore', 'ecaDescrizione', 'ecaStato', 'ecaData', 'ecaKm', 'ecaTipologia'];
|
||||
// Tab: CSiCoCars = ['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'caStato', 'caDeletedAt'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt'];
|
||||
$mev = new CSiCoCarEvents_Model();
|
||||
$mev->join('Lavoratori', 'CSiCoCarEvents.ecaIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$mev->join('CSiCoCars', 'CSiCoCarEvents.ecaIDcar = CSiCoCars.caIDcar');
|
||||
|
||||
// Per ora niente filtro, poi in futuro forse
|
||||
$mev->where('ecaIDcar', session()->get('filter_car'));
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('evncar',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$mev->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query:
|
||||
$data['dataset'] = $mev->asArray()
|
||||
->findAll();
|
||||
|
||||
// Imposto il nome del file da downloadare:
|
||||
$filepath = $_SERVER['MRK_FILE_PATH'];
|
||||
$filename = 'CSiCoDB_Eventi_CSiCoCar_il_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
// file creation
|
||||
$file = fopen($filepath . $filename,"w");
|
||||
// Esport header
|
||||
fputcsv($file,['Auto aziendale selezionata:']);
|
||||
|
||||
fputcsv($file,['ID car', 'Targa', 'Descrizione', 'Scadenza Assicurazione', 'Tipo Gomme', 'Created At', 'Updated At', 'Stato']);
|
||||
$head = [];
|
||||
$head['caIDcar'] = $data['dataset'][0]['caIDcar'];
|
||||
$head['caTarga'] = $data['dataset'][0]['caTarga'];
|
||||
$head['caDescrizione'] = $data['dataset'][0]['caDescrizione'];
|
||||
$head['caDataAssicurazione'] = $data['dataset'][0]['caDataAssicurazione'];
|
||||
$head['caTipoGomme'] = $data['dataset'][0]['caTipoGomme'];
|
||||
$head['caCreatedAt'] = $data['dataset'][0]['caCreatedAt'];
|
||||
$head['caUpdatedAt'] = $data['dataset'][0]['caUpdatedAt'];
|
||||
$head['caStato'] = $data['dataset'][0]['caStato'];
|
||||
fputcsv($file,$head);
|
||||
fputcsv($file,[' ']);
|
||||
fputcsv($file,[' ']);
|
||||
fputcsv($file,[' ']);
|
||||
fputcsv($file,['Eventi dell\'auto aziendale:']);
|
||||
fputcsv($file,['ID evento', 'ID Lavoratore', 'Nickname', 'Descrizione Evento', 'Stato Auto', 'Data', 'Totale Km', 'Tipologia']);
|
||||
foreach ($data['dataset'] as $line){
|
||||
//fputcsv($file,$line);
|
||||
// Seleziono le colonne da esportare:
|
||||
$record = [];
|
||||
$record['ecaIDcarEvent'] = $line['ecaIDcarEvent'];
|
||||
$record['ecaIDlavoratore'] = $line['ecaIDlavoratore'];
|
||||
$record['lvNickname'] = $line['lvNickname'];
|
||||
$record['ecaDescrizione'] = $line['ecaDescrizione'];
|
||||
$record['ecaStato'] = $line['ecaStato'];
|
||||
$record['ecaData'] = $line['ecaData'];
|
||||
$record['ecaKm'] = $line['ecaKm'];
|
||||
$record['ecaTipologia'] = $line['ecaTipologia'];
|
||||
fputcsv($file,$record);
|
||||
}
|
||||
// Chiudo il file
|
||||
fclose($file);
|
||||
// download
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Disposition: attachment; filename=".$filename);
|
||||
header("Content-Type: application/csv; ");
|
||||
readfile($filepath . $filename);
|
||||
// deleting file
|
||||
unlink($filepath . $filename);
|
||||
exit();
|
||||
} // function export_csv
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Eseguo l'aggiornamento dello stato della macchina indicata, in base alla cronologia degli eventi
|
||||
*/
|
||||
private function updateCarStato($IDcar){
|
||||
try {
|
||||
// verifico la tipologia dell'ultimo evento inserito:
|
||||
// Tab: CSiCoCarEvents = ['ecaIDcarEvent', 'ecaIDcar', 'ecaIDlavoratore', 'ecaDescrizione', 'ecaStato', 'ecaData', 'ecaKm', 'ecaTipologia'];
|
||||
// Tab: CSiCoCars = ['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'caStato', 'caDeletedAt'];
|
||||
$mev = new CSiCoCarEvents_Model();
|
||||
$evnt = $mev->where('ecaIDcar', $IDcar)
|
||||
->orderBy('ecaData', 'DESC')->orderBy('ecaIDcarEvent', 'DESC')->first();
|
||||
|
||||
// Preparo i dati per aggiornare la carta:
|
||||
$updCar['caIDcar'] = $IDcar;
|
||||
// determino lo stato attuale della carta dalla tipologia dell'evento:
|
||||
switch ($evnt->ecaTipologia) {
|
||||
case 'Dismessa':
|
||||
$updCar['caStato'] = 'Dismessa';
|
||||
break;
|
||||
case 'Presa':
|
||||
$updCar['caStato'] = 'Occupata';
|
||||
break;
|
||||
case 'Restituita':
|
||||
default:
|
||||
$updCar['caStato'] = 'Disponibile';
|
||||
break;
|
||||
}
|
||||
|
||||
// Aggiorno la carta:
|
||||
$model_car = new CSiCoCars_Model();
|
||||
if ($model_car->save($updCar)) {
|
||||
// carta aggiornata con successo
|
||||
return true;
|
||||
} else {
|
||||
// aggiornamento fallito
|
||||
return false;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
//throw $th;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,351 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\CSiCoCars_Model;
|
||||
use App\Models\CSiCoCarEvents_Model;
|
||||
|
||||
|
||||
class CSiCoCars extends CRUDController {
|
||||
|
||||
// Tab: CSiCoCars = ['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'caStato', 'caDeletedAt'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'CSiCoCars',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add CSiCoCar',
|
||||
'form_title_update' => 'Edit CSiCoCar',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella CSiCoCars',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => 'caUpdatedAt',
|
||||
'DeletedAt' => 'caDeletedAt',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['caIDcar'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['caTarga'] = ['label' => 'Targa', 'helper' => 'Targa dell\'auto (max 10 caratteri)', 'required' => true];
|
||||
$fields['caDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva della CSiCoCar', 'required' => true];
|
||||
$fields['caDataAssicurazione'] = ['label' => 'Scadenza Assicurazione', 'helper' => 'Data di scadenza dell\'assicurazione', 'required' => true];
|
||||
$fields['caTipoGomme'] = ['label' => 'Tipo Gomme', 'helper' => 'Tipologia delle gomme in uso', 'required' => true];
|
||||
$fields['caStato'] = ['label' => 'Stato', 'helper' => 'Stato di disponibilità della CSiCoCar', 'required' => true];
|
||||
$fields['caCreatedAt'] = ['label' => 'Created At', 'helper' => 'Data di creazione del record relativo nel database', 'only_edit'=> true];
|
||||
$fields['caUpdatedAt'] = ['label' => 'Updated At', 'helper' => 'Timestamp dell\'ultimo aggiornamento del record nel database', 'type' => 'unset'];
|
||||
$fields['caDeletedAt'] = ['label' => 'Deleted At', 'helper' => 'Data di cancellazione del record relativo nel database', 'type' => 'unset'];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caStato', 'caCreatedAt', 'caUpdatedAt', 'caDeletedAt']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function select($IDcar = null) {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'cars';
|
||||
$model = new CSiCoCars_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCars/select -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// memorizzo la selezione
|
||||
session()->set('filter_car', $IDcar);
|
||||
|
||||
// visualizzo gli eventi della carta selezionata:
|
||||
return redirect()->to('/CSiCoCarEvents/show');
|
||||
}//function select
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function add() {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCars/add -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Solo amministratori possono inserire una nuova sim:
|
||||
if (!$enable){
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per inserire una nuova auto aziendale.');
|
||||
return redirect()->to('/dashboard/cars');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'cars';
|
||||
$data['add'] = true;
|
||||
$data['title'] = 'Dettagli nuova Auto';
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Targa' => 'trim|required|min_length[7]|max_length[9]',
|
||||
'DataAssicurazione' => 'trim|required',
|
||||
'TipoGomme' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
//'Stato' => 'trim|required',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
// Tab: CSiCoCars = ['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'caStato', 'caDeletedAt'];
|
||||
$newData = [
|
||||
'caTarga' => $this->request->getVar('Targa'),
|
||||
'caDataAssicurazione' => $this->request->getVar('DataAssicurazione'),
|
||||
'caTipoGomme' => $this->request->getVar('TipoGomme'),
|
||||
'caDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'caStato' => 'Disponibile',
|
||||
];
|
||||
|
||||
$model = new CSiCoCars_Model();
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Record inserito con successo sul DB');
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/dashboard/cars');
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/CSiCoCars_form_add_edit', $data);
|
||||
}//function add
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function edit($IDcar = null) {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDcar==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCars/edit -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCars/edit -> Error code 002'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Solo amministratori possono editare una carta:
|
||||
if (!$enable){
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per editare i dati di una carta di credito aziendale.');
|
||||
return redirect()->to('/dashboard/cars');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'cars';
|
||||
$data['add'] = false;
|
||||
$data['title'] = 'Dettagli dell\'auto aziendale';
|
||||
|
||||
// Ricavo il profilo dell'orario da editare
|
||||
// Tab: CSiCoCars = ['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'caStato', 'caDeletedAt'];
|
||||
$model = new CSiCoCars_Model();
|
||||
$data['car'] = $model->where('caIDcar', $IDcar)
|
||||
->first();
|
||||
|
||||
// Verifico che esista il record dell'orario:
|
||||
if (null==$data['car']) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCars/edit -> Error code 003'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Targa' => 'trim|required|min_length[7]|max_length[9]',
|
||||
'DataAssicurazione' => 'trim|required',
|
||||
'TipoGomme' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
'Stato' => 'trim|required',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'aggiornamento
|
||||
// Tab: CSiCoCars = ['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'caStato', 'caDeletedAt'];
|
||||
$newData = [
|
||||
'caIDcar' => $this->request->getVar('IDcar'),
|
||||
'caTarga' => $this->request->getVar('Targa'),
|
||||
'caDataAssicurazione' => $this->request->getVar('DataAssicurazione'),
|
||||
'caTipoGomme' => $this->request->getVar('TipoGomme'),
|
||||
'caDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'caStato' => $this->request->getVar('Stato'),
|
||||
];
|
||||
|
||||
|
||||
|
||||
$model = new CSiCoCars_Model();
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Successfuly Updated');
|
||||
return redirect()->to('/dashboard/cars');
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'update del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/CSiCoCars_form_add_edit', $data);
|
||||
}//function select
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function delete($IDcar = null){
|
||||
helper(['tools']);
|
||||
$data = [];
|
||||
$model = new CSiCoCars_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(3)) {
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per cancellare un\'auto aziendale.');
|
||||
return redirect()->to('/dashboard/cars');
|
||||
}
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDcar==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCars/delete -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Elimino il record:
|
||||
if ($model->delete($IDcar)) {
|
||||
session()->setFlashdata('success', 'Recors cancellato correttamente.');
|
||||
|
||||
} else {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
|
||||
// Show profile
|
||||
return redirect()->to('/dashboard/cars');
|
||||
} // function delete($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function export_csv(){
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CSiCoCars/export_csv -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Ricavo le ore dell'utente:
|
||||
// Tab: CSiCoCars = ['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'caStato', 'caDeletedAt'];
|
||||
$model = new CSiCoCars_Model();
|
||||
|
||||
// Costruisco la query per selezionare le ore da esportare:
|
||||
// - applico eventuale filtro per lo stato:
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('csicocars',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query:
|
||||
$data['dataset'] = $model->asArray()
|
||||
->findAll();
|
||||
|
||||
// Imposto il nome del file da downloadare:
|
||||
$filepath = $_SERVER['MRK_FILE_PATH'];
|
||||
$filename = 'CSiCoDB_CSiCoCars_il_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
// file creation
|
||||
$file = fopen($filepath . $filename,"w");
|
||||
// Esport header
|
||||
fputcsv($file,['ID Car', 'Targa', 'Descrizione', 'Data Assicurazione', 'Tipo Gomme', 'CreatedAt', 'UpdatedAt', 'Stato']);
|
||||
|
||||
foreach ($data['dataset'] as $line){
|
||||
fputcsv($file,$line);
|
||||
}
|
||||
// Chiudo il file
|
||||
fclose($file);
|
||||
// download
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Disposition: attachment; filename=".$filename);
|
||||
header("Content-Type: application/csv; ");
|
||||
readfile($filepath . $filename);
|
||||
// deleting file
|
||||
unlink($filepath . $filename);
|
||||
exit();
|
||||
} // function export_csv
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}//class CSiCoCars
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
|
||||
|
||||
class Categorie extends CRUDController {
|
||||
|
||||
// Tab: Categorie = ['caIDcategoria', 'caCode', 'caNome', 'caDescrizione'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'Categorie',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Categoria',
|
||||
'form_title_update' => 'Edit Categoria',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella Categorie',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => '',
|
||||
'DeletedAt' => '',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['caIDcategoria'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['caCode'] = ['label' => 'Code', 'helper' => 'Codice della categoria (2 caratteri)', 'required' => true];
|
||||
$fields['caNome'] = ['label' => 'Nome', 'helper' => 'Nome della categoria (max 32 caratteri)', 'required' => true];
|
||||
$fields['caDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva della categoria','required' => true];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['caIDcategoria', 'caCode', 'caNome', 'caDescrizione']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
|
||||
|
||||
class Clienti extends CRUDController {
|
||||
|
||||
// Tab: Clienti = ['clIDcliente', 'clNome', 'clInfo', 'clCreatedAt', 'clUpdatedAt', 'clDeletedAt'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'Clienti',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Cliente',
|
||||
'form_title_update' => 'Edit Cliente',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella Clienti',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => 'clUpdatedAt',
|
||||
'DeletedAt' => 'clDeletedAt',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['clIDcliente'] = ['label' => 'ID Cliente', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['clNome'] = ['label' => 'Nome', 'helper' => 'Nome identificativo del cliente (max 32 caratteri)', 'required' => true, 'unique' => [true, 'clNome']];
|
||||
$fields['clInfo'] = ['label' => 'Info relative', 'helper' => 'Descrizione del cliente o altre informazioni utili ad esso relative', 'required' => true];
|
||||
$fields['clCreatedAt'] = ['label' => 'Created at', 'helper' => 'Data di creazione del record relativo nel database', 'only_edit'=> true];
|
||||
$fields['clUpdatedAt'] = ['label' => 'Updated at', 'helper' => 'Timestamp dell\'ultimo aggiornamento del record nel database', 'type' => 'unset'];
|
||||
$fields['clDeletedAt'] = ['label' => 'Deleted at', 'helper' => 'Data di cancellazione del record relativo nel database', 'type' => 'unset'];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['clIDcliente', 'clNome', 'clInfo', 'clCreatedAt', 'clUpdatedAt', 'clDeletedAt']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\Commesse_Model;
|
||||
use App\Models\Stime_Model;
|
||||
use App\Models\Orari_Model;
|
||||
|
||||
class Commesse extends CRUDController {
|
||||
|
||||
// Tab: Commesse = ['coIDcommessa', 'coNome', 'coIDcliente', 'coDescrizione', 'coIDstatoCommessa', 'coCreatedAt', 'coUpdatedAt', 'coDeletedAt'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'Commesse',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Commessa',
|
||||
'form_title_update' => 'Edit Commessa',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella Commesse',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => 'coUpdatedAt',
|
||||
'DeletedAt' => 'coDeletedAt',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['coIDcommessa'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['coNome'] = ['label' => 'Nome', 'helper' => 'Nome della commessa (max 32 caratteri)', 'required' => true];
|
||||
$fields['coIDcliente'] = [
|
||||
'label' => 'Cliente',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Cliente a cui si riferisce la commessa',
|
||||
'relation' => [
|
||||
'table'=> 'Clienti',
|
||||
'primary_key' => 'clIDcliente',
|
||||
'display' => ['clNome'],
|
||||
'order_by' => 'clNome',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['coDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva della commessa','required' => true];
|
||||
$fields['coIDstatoCommessa'] = [
|
||||
'label' => 'Stato',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Stato della commessa',
|
||||
'relation' => [
|
||||
'table'=> 'StatiCommessa',
|
||||
'primary_key' => 'stIDstatoCommessa',
|
||||
'display' => ['stIDstatoCommessa'],
|
||||
'order_by' => 'stIDstatoCommessa',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['coCreatedAt'] = ['label' => 'Created At', 'helper' => 'Data di creazione del record relativo nel database', 'only_edit'=> true];
|
||||
$fields['coUpdatedAt'] = ['label' => 'Updated At', 'helper' => 'Timestamp dell\'ultimo aggiornamento del record nel database', 'type' => 'unset'];
|
||||
$fields['coDeletedAt'] = ['label' => 'Deleted At', 'helper' => 'Data di cancellazione del record relativo nel database', 'type' => 'unset'];
|
||||
|
||||
$fields['coMRK'] = ['label' => 'Usate', 'helper' => 'Ore lavorate per lo svolgimento della commessa','required' => false];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
//public function index() { return $this->CRUD_view(['coIDcommessa', 'coNome', 'coIDcliente', 'coDescrizione', 'coIDstatoCommessa', 'coCreatedAt', 'coUpdatedAt', 'coDeletedAt']); }
|
||||
public function index() {
|
||||
$colums = [
|
||||
'coIDcommessa',
|
||||
'coNome',
|
||||
'coIDcliente',
|
||||
'coDescrizione',
|
||||
[
|
||||
'label' => 'Stima',
|
||||
'callback' => 'callback_OreStimate',
|
||||
],
|
||||
[
|
||||
'label' => 'Usate',
|
||||
'callback' => 'callback_OreLavorate',
|
||||
],
|
||||
'coIDstatoCommessa',
|
||||
'coCreatedAt',
|
||||
'coUpdatedAt',
|
||||
'coDeletedAt'];
|
||||
//return $this->CRUD_view($colums);
|
||||
return $this->CRUD_viewSelect($colums);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Visualizzo il report della commessa:
|
||||
public function CRUD_select($id) {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'admin'; //$data['tab'] = 'amministrazione';
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
// // imposto l'ordinamento richiesto:
|
||||
// CheckSort('ReportCommessa',true);
|
||||
// $data['sortCol'] = session()->get('sort')['col'];
|
||||
// $data['sortDir'] = session()->get('sort')['dir'];
|
||||
// $model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// Ricavo il dataset per il riepilogo della Commessa:
|
||||
$model = new Commesse_Model();
|
||||
$data['datasetCommessa'] = $model->get_ReportByCommessa($id);
|
||||
|
||||
// Ricavo il dataset per il riepilogo delle Stime:
|
||||
$model = new Stime_Model();
|
||||
$data['datasetStime'] = $model->get_ReportByCommessa($id);
|
||||
|
||||
// Ricavo il dataset per il riepilogo delle Ore:
|
||||
$model = new Orari_Model();
|
||||
$data['datasetOre'] = $model->get_ReportByCommessa($id);
|
||||
|
||||
$data['title'] = "Analisi della commessa selezionata: " . $id;
|
||||
$data['id'] = $id;
|
||||
|
||||
//return view('test_ReportCommessa', $data);
|
||||
return view('pages/reportCommessa', $data);
|
||||
|
||||
}//function CRUD_edit
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Methods
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function export_report_csv($id){
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'admin'; //$data['tab'] = 'amministrazione';
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Commesse/export_report_csv -> Error code 001'); }
|
||||
return redirect()->to('/Commesse/CRUD_select');
|
||||
}
|
||||
|
||||
// Ricavo il dataset per il riepilogo della Commessa:
|
||||
$model = new Commesse_Model();
|
||||
$data['datasetCommessa'] = $model->get_ReportByCommessa($id);
|
||||
|
||||
// Ricavo il dataset per il riepilogo delle Stime:
|
||||
$model = new Stime_Model();
|
||||
$data['datasetStime'] = $model->get_ReportByCommessa($id);
|
||||
|
||||
// Ricavo il dataset per il riepilogo delle Ore:
|
||||
$model = new Orari_Model();
|
||||
$data['datasetOre'] = $model->get_ReportByCommessa($id);
|
||||
|
||||
|
||||
$data['title'] = "Analisi della commessa selezionata: " . $id;
|
||||
|
||||
|
||||
// Imposto il nome del file da downloadare:
|
||||
$filepath = $_SERVER['MRK_FILE_PATH'];
|
||||
$filename = 'CSiCoDB_Report_Commessa_' . $id . '_il_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
// file creation
|
||||
$file = fopen($filepath . $filename,"w");
|
||||
// Esport header
|
||||
fputcsv($file,['Analisi della commessa selezionata: ', $id]);
|
||||
fputcsv($file,['', '']);
|
||||
|
||||
// Export report commessa:
|
||||
// fputcsv($file,['','','ID','Nome','Cliente','Descrizione','Stima','Usate','Delta','Stato','Created At','Updated At','Deleted At']);
|
||||
// foreach ($data['datasetCommessa'] as $line){
|
||||
// //fputcsv($file,$line);
|
||||
// // Seleziono le colonne da esportare:
|
||||
// $record = [];
|
||||
// $record['A'] = '';
|
||||
// $record['B'] = '';
|
||||
// $record['ID'] = $line['ID'];
|
||||
// $record['Nome'] = $line['Nome'];
|
||||
// $record['Cliente'] = $line['Cliente'];
|
||||
// $record['Descrizione'] = $line['Descrizione'];
|
||||
// $record['Stima'] = $line['Stima'];
|
||||
// $record['Usate'] = $line['Usate'];
|
||||
// $record['Delta'] = $line['Stima']-$line['Usate'];
|
||||
// $record['Stato'] = $line['Stato'];
|
||||
// $record['CreatedAt'] = $line['CreatedAt'];
|
||||
// $record['UpdatedAt'] = $line['UpdatedAt'];
|
||||
// $record['DeletedAt'] = $line['DeletedAt'];
|
||||
// fputcsv($file,$record);
|
||||
// }
|
||||
// fputcsv($file,['', '']);
|
||||
|
||||
// Export report stime:
|
||||
|
||||
// Export report ore:
|
||||
|
||||
|
||||
// Chiudo il file
|
||||
fclose($file);
|
||||
// download
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Disposition: attachment; filename=".$filename);
|
||||
header("Content-Type: application/csv; ");
|
||||
readfile($filepath . $filename);
|
||||
// deleting file
|
||||
unlink($filepath . $filename);
|
||||
exit();
|
||||
|
||||
} // function export_report_csv
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,541 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\Lavoratori_Model;
|
||||
use App\Models\CreditCards_Model;
|
||||
use App\Models\CreditCardEvents_Model;
|
||||
|
||||
|
||||
class CreditCardEvents extends CRUDController {
|
||||
|
||||
// Tab: CreditCardEvents = ['eccIDcreditEvent', 'eccIDcard', 'eccIDlavoratore', 'eccDescrizione', 'eccData', 'eccCredito', 'eccTipologia'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'CreditCardEvents',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Evento',
|
||||
'form_title_update' => 'Edit Evento',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella CreditCardEvents',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => '',
|
||||
'DeletedAt' => '',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['eccIDcreditEvent'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['eccIDcard'] = [
|
||||
'label' => 'CSiCoCard',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Carta di credito a cui si riferisce l\'evento',
|
||||
'relation' => [
|
||||
'table'=> 'CreditCards',
|
||||
'primary_key' => 'ccIDcard',
|
||||
'display' => ['ccNumero'],
|
||||
'order_by' => 'ccNumero',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['eccIDlavoratore'] = [
|
||||
'label' => 'Lavoratore',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Lavoratore a cui si riferisce l\'evento',
|
||||
'relation' => [
|
||||
'table'=> 'Lavoratori',
|
||||
'primary_key' => 'lvIDlavoratore',
|
||||
'display' => ['lvNickname', 'lvNome', 'lvCognome'], //'display' => ['lvNickname'],
|
||||
'order_by' => 'lvNickname',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['eccDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva dell\'evento', 'required' => true];
|
||||
$fields['eccData'] = ['label' => 'Timestamp', 'helper' => 'Timestamp dell\'evento', 'required' => true, 'type' => 'date'];
|
||||
$fields['eccCredito'] = ['label' => 'Credito Residuo', 'helper' => 'Stima del credito residuo sulla carta', 'required' => true];
|
||||
$fields['eccTipologia'] = ['label' => 'Tipo', 'helper' => 'Tipologia di evento', 'required' => true];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['eccIDcreditEvent', 'eccIDcard', 'eccIDlavoratore', 'eccDescrizione', 'eccData', 'eccCredito', 'eccTipologia']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function show() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'credit';
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCardEvents/show -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo la carta di credito selezionata (se vi è una selezione):
|
||||
// Tab: CreditCards = ['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', 'ccDeletedAt'];
|
||||
$IDcard = session()->get('filter_cc');
|
||||
if ((null !== $IDcard) && ($IDcard!=-1)) {
|
||||
$mcc = new CreditCards_Model();
|
||||
$data['card'] = $mcc->where('ccIDcard', $IDcard)->first();
|
||||
}
|
||||
|
||||
// Ricavo i relativi eventi:
|
||||
// Tab: CreditCardEvents = ['eccIDcreditEvent', 'eccIDcard', 'eccIDlavoratore', 'eccDescrizione', 'eccData', 'eccCredito', 'eccTipologia'];
|
||||
$mev = new CreditCardEvents_Model();
|
||||
$mev->join('Lavoratori', 'CreditCardEvents.eccIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$mev->join('CreditCards', 'CreditCardEvents.eccIDcard = CreditCards.ccIDcard');
|
||||
|
||||
// Per ora niente filtro, poi in futuro forse
|
||||
$mev->where('eccIDcard', $IDcard);
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('evncredit',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$mev->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query con paginazione:
|
||||
$data['dataset'] = $mev->paginate(session()->get('pager_num'));
|
||||
$data['pager'] = $mev->pager;
|
||||
|
||||
return view('/pages/events/CreditCardEvents', $data);
|
||||
}//function select
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function add() {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCardEvents/add -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Ricavo la carta di credito selezionata (se vi è una selezione):
|
||||
// Tab: CreditCards = ['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', 'ccDeletedAt'];
|
||||
$IDcard = session()->get('filter_cc');
|
||||
if ((null == $IDcard) || ($IDcard==-1)) {
|
||||
return redirect()->to('/dashboard/credit');
|
||||
}
|
||||
$mcc = new CreditCards_Model();
|
||||
$data['card'] = $mcc->where('ccIDcard', $IDcard)->first();
|
||||
if ($data['card']==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCardEvents/add -> Error code 002'); }
|
||||
return redirect()->to('/dashboard/credit');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'credit';
|
||||
$data['add'] = true;
|
||||
$data['title'] = 'Dettagli nuova evento della carta: ' . $data['card']->ccNumero;
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Data' => 'trim|required',
|
||||
'Credito' => 'trim|required',
|
||||
'Tipologia' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
];
|
||||
if ($enable){
|
||||
$rules['IDlavoratore'] = 'trim|required';
|
||||
}
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
// Tab: CreditCardEvents = ['eccIDcreditEvent', 'eccIDcard', 'eccIDlavoratore', 'eccDescrizione', 'eccData', 'eccCredito', 'eccTipologia'];
|
||||
$newData = [
|
||||
'eccIDcard' => $data['card']->ccIDcard,
|
||||
'eccDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'eccData' => $this->request->getVar('Data'),
|
||||
'eccCredito' => $this->request->getVar('Credito'),
|
||||
'eccTipologia' => $this->request->getVar('Tipologia'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['eccIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
} else {
|
||||
$newData['eccIDlavoratore'] = session()->get('lavoratore')->lvIDlavoratore;
|
||||
}
|
||||
|
||||
$model = new CreditCardEvents_Model();
|
||||
if ($model->save($newData)) {
|
||||
// evento inserito con successo, aggiorno lo stato della carta
|
||||
if ($this->updateCardStato($data['card']->ccIDcard)) {
|
||||
// update dello stato nella carta di credito riuscito
|
||||
session()->setFlashdata('success', 'Evento inserito con successo');
|
||||
} else {
|
||||
// update dello stato nella carta di credito fallito
|
||||
session()->setFlashdata('danger', 'Evento inserito ma stato della carta non aggiornato correttamente');
|
||||
}
|
||||
// apro la pagina desiderata in base al pulsante utilizzato:
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/CreditCardEvents/show');
|
||||
}
|
||||
} else {
|
||||
// errore durante l'inserimento dell'evento
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/creditcardevents_form_add_edit', $data);
|
||||
}//function add
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function edit($IDevent = null) {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDevent==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCardEvents/edit -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCardEvents/edit -> Error code 002'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Ricavo l'evento selezionato, completo di tutti i particolari:
|
||||
// Tab: CreditCardEvents = ['eccIDcreditEvent', 'eccIDcard', 'eccIDlavoratore', 'eccDescrizione', 'eccData', 'eccCredito', 'eccTipologia'];
|
||||
// Tab: CreditCards = ['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', 'ccDeletedAt'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'ccStato', 'lvDeletedAt'];
|
||||
$model = new CreditCardEvents_Model();
|
||||
$model->join('CreditCards', 'CreditCardEvents.eccIDcard = CreditCards.ccIDcard');
|
||||
$model->join('Lavoratori', 'CreditCardEvents.eccIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$data['evnt'] = $model->where('eccIDcreditEvent', $IDevent)
|
||||
->first();
|
||||
// Verifico che esista il record:
|
||||
if (null==$data['evnt']) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCardEvents/edit -> Error code 003'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// ricavo la carta a cui l'evento si riferisce
|
||||
$mcc = new CreditCards_Model();
|
||||
$data['card'] = $mcc->where('ccIDcard', $data['evnt']->eccIDcard)->first();
|
||||
// Verifico che esista il record:
|
||||
if ($data['card']==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCardEvents/edit -> Error code 004'); }
|
||||
return redirect()->to('/dashboard/credit');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'credit';
|
||||
$data['add'] = false;
|
||||
$data['title'] = 'Dettagli evento: ' . $data['evnt']->ccNumero;
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Data' => 'trim|required',
|
||||
'Credito' => 'trim|required',
|
||||
'Tipologia' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
];
|
||||
if ($enable){
|
||||
$rules['IDlavoratore'] = 'trim|required';
|
||||
}
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
$newData = [
|
||||
'eccIDcreditEvent' => $IDevent,
|
||||
'eccDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'eccData' => $this->request->getVar('Data'),
|
||||
'eccCredito' => $this->request->getVar('Credito'),
|
||||
'eccTipologia' => $this->request->getVar('Tipologia'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['eccIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
}
|
||||
|
||||
if ($model->save($newData)) {
|
||||
// evento inserito con successo, aggiorno lo stato della carta
|
||||
if ($this->updateCardStato($data['card']->ccIDcard)) {
|
||||
// update dello stato nella carta di credito riuscito
|
||||
session()->setFlashdata('success', 'Evento aggiornato con successo');
|
||||
} else {
|
||||
// update dello stato nella carta di credito fallito
|
||||
session()->setFlashdata('danger', 'Evento inserito ma stato della carta non aggiornato correttamente');
|
||||
}
|
||||
// apro la pagina desiderata in base al pulsante utilizzato:
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/CreditCardEvents/show');
|
||||
}
|
||||
} else {
|
||||
// errore durante l'inserimento dell'evento
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/creditcardevents_form_add_edit', $data);
|
||||
}//function edit
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function delete($IDevent = null){
|
||||
helper(['tools']);
|
||||
$data = [];
|
||||
|
||||
// Ricavo l'evento selezionato, completo di tutti i particolari:
|
||||
// Tab: CreditCardEvents = ['eccIDcreditEvent', 'eccIDcard', 'eccIDlavoratore', 'eccDescrizione', 'eccData', 'eccCredito', 'eccTipologia'];
|
||||
// Tab: CreditCards = ['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', 'ccDeletedAt'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'ccStato', 'lvDeletedAt'];
|
||||
$model = new CreditCardEvents_Model();
|
||||
$model->join('CreditCards', 'CreditCardEvents.eccIDcard = CreditCards.ccIDcard');
|
||||
$model->join('Lavoratori', 'CreditCardEvents.eccIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$evnt = $model->where('eccIDcreditEvent', $IDevent)
|
||||
->first();
|
||||
// Verifico che esista il record:
|
||||
if (null==$evnt) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCardEvents/delete -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!(CheckLevel(3) || session()->get('lavoratore')->lvIDlavoratore==$evnt->eccIDlavoratore)) {
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per cancellare un evento inserito da altri lavoratori.');
|
||||
return redirect()->to('/CreditCardEvents/show');
|
||||
}
|
||||
|
||||
// Elimino il record:
|
||||
if ($model->delete($IDevent)) {
|
||||
// Evento cancellato, aggiorno stato della carta di credito relativa
|
||||
if ($this->updateCardStato($evnt->eccIDcard)) {
|
||||
// update dello stato nella carta di credito riuscito
|
||||
session()->setFlashdata('success', 'Recors cancellato correttamente.');
|
||||
} else {
|
||||
// update dello stato nella carta di credito fallito
|
||||
session()->setFlashdata('danger', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
} else {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
|
||||
// Show profile
|
||||
return redirect()->to('/CreditCardEvents/show');
|
||||
} // function delete($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function export_csv(){
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCards/export_csv -> Error code 001'); }
|
||||
return redirect()->to('/CreditCardEvents/show');
|
||||
}
|
||||
|
||||
// Ricavo gli eventi della carta di credito:
|
||||
// Tab: CreditCardEvents = ['eccIDcreditEvent', 'eccIDcard', 'eccIDlavoratore', 'eccDescrizione', 'eccData', 'eccCredito', 'eccTipologia'];
|
||||
// Tab: CreditCards = ['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', 'ccDeletedAt', 'ccStato'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt'];
|
||||
$mev = new CreditCardEvents_Model();
|
||||
$mev->join('Lavoratori', 'CreditCardEvents.eccIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$mev->join('CreditCards', 'CreditCardEvents.eccIDcard = CreditCards.ccIDcard');
|
||||
|
||||
// Per ora niente filtro, poi in futuro forse
|
||||
$mev->where('eccIDcard', session()->get('filter_cc'));
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('evncredit',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$mev->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query:
|
||||
$data['dataset'] = $mev->asArray()
|
||||
->findAll();
|
||||
|
||||
// Imposto il nome del file da downloadare:
|
||||
$filepath = $_SERVER['MRK_FILE_PATH'];
|
||||
$filename = 'CSiCoDB_Eventi_Credit_Card_il_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
// file creation
|
||||
$file = fopen($filepath . $filename,"w");
|
||||
// Esport header
|
||||
fputcsv($file,['Carta di credito selezionata:']);
|
||||
|
||||
fputcsv($file,['ID card', 'Numero', 'Descrizione', 'ScadeIl', 'PIN', 'CreatedAt', 'UpdatedAt', 'Stato']);
|
||||
$head = [];
|
||||
$head['eccIDcard'] = $data['dataset'][0]['eccIDcard'];
|
||||
$head['ccNumero'] = $data['dataset'][0]['ccNumero'];
|
||||
$head['ccDescrizione'] = $data['dataset'][0]['ccDescrizione'];
|
||||
$head['ccScadeIl'] = $data['dataset'][0]['ccScadeIl'];
|
||||
$head['ccPIN'] = $data['dataset'][0]['ccPIN'];
|
||||
$head['ccCreatedAt'] = $data['dataset'][0]['ccCreatedAt'];
|
||||
$head['ccUpdatedAt'] = $data['dataset'][0]['ccUpdatedAt'];
|
||||
$head['ccStato'] = $data['dataset'][0]['ccStato'];
|
||||
fputcsv($file,$head);
|
||||
fputcsv($file,[' ']);
|
||||
fputcsv($file,[' ']);
|
||||
fputcsv($file,[' ']);
|
||||
fputcsv($file,['Eventi della carta di credito:']);
|
||||
fputcsv($file,['ID evento', 'ID Lavoratore', 'Nickname', 'Descrizione Evento', 'Data', 'Credito', 'Tipologia']);
|
||||
|
||||
foreach ($data['dataset'] as $line){
|
||||
//fputcsv($file,$line);
|
||||
// Seleziono le colonne da esportare:
|
||||
$record = [];
|
||||
$record['eccIDcreditEvent'] = $line['eccIDcreditEvent'];
|
||||
$record['eccIDlavoratore'] = $line['eccIDlavoratore'];
|
||||
$record['lvNickname'] = $line['lvNickname'];
|
||||
$record['eccDescrizione'] = $line['eccDescrizione'];
|
||||
$record['eccData'] = $line['eccData'];
|
||||
$record['eccCredito'] = $line['eccCredito'];
|
||||
$record['eccTipologia'] = $line['eccTipologia'];
|
||||
fputcsv($file,$record);
|
||||
}
|
||||
// Chiudo il file
|
||||
fclose($file);
|
||||
// download
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Disposition: attachment; filename=".$filename);
|
||||
header("Content-Type: application/csv; ");
|
||||
readfile($filepath . $filename);
|
||||
// deleting file
|
||||
unlink($filepath . $filename);
|
||||
exit();
|
||||
} // function export_csv
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Eseguo l'aggiornamento dello stato della carta di credito indicata, in base alla cronologia degli eventi
|
||||
*/
|
||||
private function updateCardStato($IDcard){
|
||||
try {
|
||||
// verifico la tipologia dell'ultimo evento inserito:
|
||||
// Tab: CreditCards = ['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', 'ccDeletedAt'];
|
||||
// Tab: CreditCardEvents = ['eccIDcreditEvent', 'eccIDcard', 'eccIDlavoratore', 'eccDescrizione', 'eccData', 'eccCredito', 'eccTipologia'];
|
||||
$mev = new CreditCardEvents_Model();
|
||||
$evnt = $mev->where('eccIDcard', $IDcard)
|
||||
->orderBy('eccData', 'DESC')->orderBy('eccIDcreditEvent', 'DESC')->first();
|
||||
|
||||
// Preparo i dati per aggiornare la carta:
|
||||
$updCard['ccIDcard'] = $IDcard;
|
||||
// determino lo stato attuale della carta dalla tipologia dell'evento:
|
||||
switch ($evnt->eccTipologia) {
|
||||
case 'Dismessa':
|
||||
$updCard['ccStato'] = 'Dismessa';
|
||||
break;
|
||||
case 'Presa':
|
||||
$updCard['ccStato'] = 'Occupata';
|
||||
break;
|
||||
case 'Restituita':
|
||||
default:
|
||||
$updCard['ccStato'] = 'Disponibile';
|
||||
break;
|
||||
}
|
||||
|
||||
// Aggiorno la carta:
|
||||
$model_card = new CreditCards_Model();
|
||||
if ($model_card->save($updCard)) {
|
||||
// carta aggiornata con successo
|
||||
return true;
|
||||
} else {
|
||||
// aggiornamento fallito
|
||||
return false;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
//throw $th;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}//class CreditCardEvents
|
||||
@@ -0,0 +1,350 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\Lavoratori_Model;
|
||||
use App\Models\CreditCards_Model;
|
||||
use App\Models\CreditCardEvents_Model;
|
||||
|
||||
|
||||
class CreditCards extends CRUDController {
|
||||
|
||||
// Tab: CreditCards = ['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccStato', 'ccCreatedAt', 'ccUpdatedAt', 'ccDeletedAt'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'CreditCards',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add CreditCard',
|
||||
'form_title_update' => 'Edit CreditCard',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella CreditCards',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => 'ccUpdatedAt',
|
||||
'DeletedAt' => 'ccDeletedAt',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['ccIDcard'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['ccNumero'] = ['label' => 'Numero', 'helper' => 'Numero della carta di credito (max 20 caratteri)', 'required' => true];
|
||||
$fields['ccDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva carta di credito', 'required' => true];
|
||||
$fields['ccScadeIl'] = ['label' => 'Data Scadenza', 'helper' => 'Data di scadenza della carta di credito', 'required' => true];
|
||||
$fields['ccPIN'] = ['label' => 'PIN', 'helper' => 'PIN della carta di credito (max 6 caratteri)', 'required' => true];
|
||||
$fields['ccStato'] = ['label' => 'Stato', 'helper' => 'Stato di disponmibilità della carta di credito', 'required' => true];
|
||||
$fields['ccCreatedAt'] = ['label' => 'Created At', 'helper' => 'Data di creazione del record relativo nel database', 'only_edit'=> true];
|
||||
$fields['ccUpdatedAt'] = ['label' => 'Updated At', 'helper' => 'Timestamp dell\'ultimo aggiornamento del record nel database', 'type' => 'unset'];
|
||||
$fields['ccDeletedAt'] = ['label' => 'Deleted At', 'helper' => 'Data di cancellazione del record relativo nel database', 'type' => 'unset'];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccStato', 'ccCreatedAt', 'ccUpdatedAt', 'ccDeletedAt']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function select($IDcard = null) {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'credit';
|
||||
$model = new CreditCards_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCards/select -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// memorizzo la selezione
|
||||
session()->set('filter_cc', $IDcard);
|
||||
|
||||
// visualizzo gli eventi della carta selezionata:
|
||||
return redirect()->to('/CreditCardEvents/show');
|
||||
}//function select
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function add() {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCards/add -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Solo amministratori possono inserire una nuova carta:
|
||||
if (!$enable){
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per inserire una nuova carta di credito aziendale.');
|
||||
return redirect()->to('/dashboard/credit');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'credit';
|
||||
$data['add'] = true;
|
||||
$data['title'] = 'Dettagli nuova carta di credito';
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
//
|
||||
$rules = [
|
||||
'Numero' => 'trim|required|min_length[8]|max_length[20]',
|
||||
'ScadeIl' => 'trim|required',
|
||||
'PIN' => 'trim|required|min_length[3]|max_length[6]',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
//'Stato' => 'trim|required',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
// Tab: CreditCards = ['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', 'ccStato', 'ccDeletedAt'];
|
||||
$newData = [
|
||||
'ccNumero' => $this->request->getVar('Numero'),
|
||||
'ccScadeIl' => $this->request->getVar('ScadeIl'),
|
||||
'ccPIN' => $this->request->getVar('PIN'),
|
||||
'ccDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'ccStato' => 'Disponibile',
|
||||
];
|
||||
|
||||
$model = new CreditCards_Model();
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Record inserito con successo sul DB');
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/dashboard/credit');
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/creditcards_form_add_edit', $data);
|
||||
}//function select
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function edit($IDcard = null) {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDcard==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCards/edit -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCards/add -> Error code 002'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Solo amministratori possono editare una carta:
|
||||
if (!$enable){
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per editare i dati di una carta di credito aziendale.');
|
||||
return redirect()->to('/dashboard/credit');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'credit';
|
||||
$data['add'] = false;
|
||||
$data['title'] = 'Dettagli della carta di credito';
|
||||
|
||||
// Ricavo il profilo dell'orario da editare
|
||||
$model = new CreditCards_Model();
|
||||
$data['card'] = $model->where('ccIDcard', $IDcard)
|
||||
->first();
|
||||
|
||||
// Verifico che esista il record dell'orario:
|
||||
if (null==$data['card']) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCards/edit -> Error code 003'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Numero' => 'trim|required|min_length[8]|max_length[20]',
|
||||
'ScadeIl' => 'trim|required',
|
||||
'PIN' => 'trim|required|min_length[3]|max_length[6]',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
'Stato' => 'trim|required',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'aggiornamento
|
||||
// Tab: CreditCards = ['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', 'ccStato', 'ccDeletedAt'];
|
||||
$newData = [
|
||||
'ccIDcard' => $this->request->getVar('IDcard'),
|
||||
'ccNumero' => $this->request->getVar('Numero'),
|
||||
'ccScadeIl' => $this->request->getVar('ScadeIl'),
|
||||
'ccPIN' => $this->request->getVar('PIN'),
|
||||
'ccDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'ccStato' => $this->request->getVar('Stato'),
|
||||
];
|
||||
|
||||
$model = new CreditCards_Model();
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Successfuly Updated');
|
||||
return redirect()->to('/dashboard/credit');
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'update del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/creditcards_form_add_edit', $data);
|
||||
}//function select
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function delete($IDcard = null){
|
||||
helper(['tools']);
|
||||
$data = [];
|
||||
$model = new CreditCards_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(3)) {
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per cancellare una carta di credito aziendale.');
|
||||
return redirect()->to('/dashboard/credit');
|
||||
}
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDcard==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCards/delete -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Elimino il record:
|
||||
if ($model->delete($IDcard)) {
|
||||
session()->setFlashdata('success', 'Recors cancellato correttamente.');
|
||||
|
||||
} else {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
|
||||
// Show profile
|
||||
return redirect()->to('/dashboard/credit');
|
||||
} // function delete($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function export_csv(){
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/CreditCards/export_csv -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Ricavo le ore dell'utente:
|
||||
// Tab: CreditCards = ['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', 'ccStato', 'ccDeletedAt'];
|
||||
$model = new CreditCards_Model();
|
||||
|
||||
// Costruisco la query per selezionare le ore da esportare:
|
||||
// - applico eventuale filtro per lo stato:
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('credit',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query:
|
||||
$data['dataset'] = $model->asArray()
|
||||
->findAll();
|
||||
|
||||
// Imposto il nome del file da downloadare:
|
||||
$filepath = $_SERVER['MRK_FILE_PATH'];
|
||||
$filename = 'CSiCoDB_CarteDiCredito_il_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
// file creation
|
||||
$file = fopen($filepath . $filename,"w");
|
||||
// Esport header
|
||||
fputcsv($file,['ID card', 'Numero', 'Descrizione', 'ScadeIl', 'PIN', 'CreatedAt', 'UpdatedAt', 'Stato']);
|
||||
|
||||
foreach ($data['dataset'] as $line){
|
||||
fputcsv($file,$line);
|
||||
}
|
||||
// Chiudo il file
|
||||
fclose($file);
|
||||
// download
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Disposition: attachment; filename=".$filename);
|
||||
header("Content-Type: application/csv; ");
|
||||
readfile($filepath . $filename);
|
||||
// deleting file
|
||||
unlink($filepath . $filename);
|
||||
exit();
|
||||
} // function export_csv
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}//class CreditCards
|
||||
@@ -0,0 +1,556 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
|
||||
use App\Models\Lavoratori_Model;
|
||||
use App\Models\TipoOre_Model;
|
||||
use App\Models\TipiWork_Model;
|
||||
use App\Models\Orari_Model;
|
||||
use App\Models\Spese_Model;
|
||||
use App\Models\Commesse_Model;
|
||||
use App\Models\CreditCardEvents_Model;
|
||||
use App\Models\CreditCards_Model;
|
||||
use App\Models\CSiCoCars_Model;
|
||||
use App\Models\CSiCoCarEvents_Model;
|
||||
use App\Models\SIMs_Model;
|
||||
use App\Models\SIMEvents_Model;
|
||||
|
||||
|
||||
class Dashboard extends BaseController {
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function index() {
|
||||
return $this->home();
|
||||
}//function index
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function home() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'home';
|
||||
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(0)) { return redirect()->to('/Lavoratori/login'); }
|
||||
|
||||
$lav = session()->get('lavoratore');
|
||||
// // Gli utenti Guest non possono inserire valori e per sicurezza visualizzo una pagina apposta.
|
||||
// if ($lav->lvLevel==1){ return redirect()->to('/dashboard/home'); }
|
||||
|
||||
// Gli utenti guest non possono inserire ore, quindi per loro non gestisco le
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// verifico chi ha fatto il POST (ore o spese):
|
||||
if(isset($_POST['PBinsetrOraPOST'])) {
|
||||
// POST di aggiunta dell'orario e quindi verifico i dati dell'orario e se validi lo inserisco.
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'o_IDcommessa' => 'trim|required',
|
||||
'o_Data' => 'trim|required',
|
||||
'o_Ore' => 'trim|required',
|
||||
'o_IDTipoOre' => 'trim|required',
|
||||
'o_Descrizione' => 'trim|required|min_length[8]',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
$newData = [
|
||||
'orIDcommessa' => $this->request->getVar('o_IDcommessa'),
|
||||
'orIDlavoratore' => $lav->lvIDlavoratore,
|
||||
'orData' => $this->request->getVar('o_Data'),
|
||||
'orOre' => $this->request->getVar('o_Ore'),
|
||||
'orIDTipoOre' => $this->request->getVar('o_IDTipoOre'),
|
||||
'orDescrizione' => $this->request->getVar('o_Descrizione'),
|
||||
];
|
||||
$modelOrari = new Orari_Model();
|
||||
if ($modelOrari->save($newData)) {
|
||||
session()->setFlashdata('success', 'Record inserito con successo sul DB');
|
||||
UpdateCommessa($newData['orIDcommessa']);
|
||||
//return redirect()->to('/dashboard/home');
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
}// analisi validazione
|
||||
} // if PBinsetrOraPOST
|
||||
|
||||
if(isset($_POST['PBinsetrSpesaPOST'])) {
|
||||
// POST di aggiunta della spesa e quindi verifico i dati della spesa e se validi lo inserisco.
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
's_IDcommessa' => 'trim|required',
|
||||
's_Data' => 'trim|required',
|
||||
's_Importo' => 'trim|required',
|
||||
's_DaRimborsare' => 'trim|required',
|
||||
's_Descrizione' => 'trim|required|min_length[8]',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
$newData = [
|
||||
'spIDcommessa' => $this->request->getVar('s_IDcommessa'),
|
||||
'spIDlavoratore' => $lav->lvIDlavoratore,
|
||||
'spData' => $this->request->getVar('s_Data'),
|
||||
'spImporto' => $this->request->getVar('s_Importo'),
|
||||
'spDaRimborsare' => $this->request->getVar('s_DaRimborsare'),
|
||||
'spDescrizione' => $this->request->getVar('s_Descrizione'),
|
||||
];
|
||||
$modelOrari = new Spese_Model();
|
||||
if ($modelOrari->save($newData)) {
|
||||
session()->setFlashdata('success', 'Record inserito con successo sul DB');
|
||||
UpdateCommessa($newData['spIDcommessa']);
|
||||
//return redirect()->to('/dashboard/home');
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
}// analisi validazione
|
||||
} // if PBinsetrSpesaPOST
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Ricavo riepilogo ultimi orari inseriti
|
||||
$modelCommesse = new Commesse_Model();
|
||||
$data['orari'] = $modelCommesse->join('Orari', 'Commesse.coIDcommessa = Orari.orIDcommessa')
|
||||
->where('orIDlavoratore', $lav->lvIDlavoratore)
|
||||
->orderBy('orIDorario', 'DESC')
|
||||
->findAll(3);
|
||||
|
||||
// Ricavo ultime spese inserite
|
||||
$data['spese'] = $modelCommesse->join('Spese', 'Commesse.coIDcommessa = Spese.spIDcommessa')
|
||||
->where('spIDlavoratore', $lav->lvIDlavoratore)
|
||||
->orderBy('spIDspesa', 'DESC')
|
||||
->findAll(3);
|
||||
|
||||
// Ricavo i dati per il select delle tipologie di orario:
|
||||
$modelTipoOre = new TipoOre_Model();
|
||||
$data['select_tipo_ore'] = $modelTipoOre->get_select();
|
||||
|
||||
// Ricavo i dati per il select delle commesse:
|
||||
$data['select_commesse'] = $modelCommesse->get_select();
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
return view('pages/home', $data);
|
||||
|
||||
|
||||
}//function home
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function orari() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'orari';
|
||||
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
|
||||
// Ricavo le ore dell'utente:
|
||||
// Tab: Orari = ['orIDorario', 'orIDcommessa', 'orIDlavoratore', 'orData', 'orOre', 'orIDTipoOre', 'orIDTipoWork', 'orDescrizione'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt'];
|
||||
// Tab: Commesse = ['coIDcommessa', 'coNome', 'coIDcliente', 'coDescrizione', 'coIDstatoCommessa', 'coModificatoIl', 'coCreatedAt', 'coUpdatedAt', 'coDeletedAt'];
|
||||
$model = new Orari_Model();
|
||||
$model->join('Lavoratori', 'Lavoratori.lvIDlavoratore = Orari.orIDlavoratore');
|
||||
$model->join('Commesse', 'Commesse.coIDcommessa = Orari.orIDcommessa');
|
||||
|
||||
// Costruisco la query per selezionare le ore da mostrare:
|
||||
// - applico il filtro sull'intervallo temporale:
|
||||
$model->where('orData >=', session()->get('filter_dal'))
|
||||
->where('orData <=', session()->get('filter_al') . " 23:59:59");
|
||||
// - applico eventuale filtro per lavoratore
|
||||
if (session()->filter_lavoratore!='-1') { $model->where('orIDlavoratore', session()->get('filter_lavoratore')); }
|
||||
// - applico eventuale filtro per commessa
|
||||
if (session()->filter_commessa!='-1') { $model->where('orIDcommessa', session()->get('filter_commessa')); }
|
||||
// - applico eventuale filtro per tipologia di ora:
|
||||
if (session()->filter_tipo_ore!='-1') { $model->where('orIDTipoOre', session()->get('filter_tipo_ore')); }
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('orari',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query con paginazione:
|
||||
$data['dataset'] = $model->paginate(session()->get('pager_num'));
|
||||
$data['pager'] = $model->pager;
|
||||
|
||||
// Ricavo i dati per il select delle commesse:
|
||||
$modelCommesse = new Commesse_Model();
|
||||
$data['select_commesse'] = $modelCommesse->get_select_on_orari();
|
||||
|
||||
// Ricavo i dati per il select delle tipologie di orario:
|
||||
$modelTipoOre = new TipoOre_Model();
|
||||
$data['select_tipo_ore'] = $modelTipoOre->get_select_on_orari();
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select_on_orari();
|
||||
|
||||
// Ricavo i dati per il select delle tipologie di lavoro:
|
||||
$modelTipoWork = new TipiWork_Model();
|
||||
$data['select_tipo_work'] = $modelTipoWork->get_select_on_orari();
|
||||
|
||||
return view('pages/orari', $data);
|
||||
}//function orari
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function spese() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'spese';
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
// Ricavo le ore dell'utente:
|
||||
// Tab: Spese = ['spIDspesa', 'spIDcommessa', 'spIDlavoratore', 'spImporto', 'spDaRimborsare', 'spDescrizione', 'spData'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt'];
|
||||
// Tab: Commesse = ['coIDcommessa', 'coNome', 'coIDcliente', 'coDescrizione', 'coIDstatoCommessa', 'coModificatoIl', 'coCreatedAt', 'coUpdatedAt', 'coDeletedAt'];
|
||||
$model = new Spese_Model();
|
||||
$model->join('Lavoratori', 'Lavoratori.lvIDlavoratore = Spese.spIDlavoratore');
|
||||
$model->join('Commesse', 'Commesse.coIDcommessa = Spese.spIDcommessa');
|
||||
|
||||
// Costruisco la query per selezionare le ore da mostrare:
|
||||
// - applico il filtro sull'intervallo temporale:
|
||||
$model->where('spData >=', session()->get('filter_dal'))
|
||||
->where('spData <=', session()->get('filter_al') . " 23:59:59");
|
||||
// - applico eventuale filtro per lavoratore
|
||||
if (session()->filter_lavoratore!='-1') { $model->where('spIDlavoratore', session()->get('filter_lavoratore')); }
|
||||
// - applico eventuale filtro per commessa
|
||||
if (session()->filter_commessa!='-1') { $model->where('coIDcommessa', session()->get('filter_commessa')); }
|
||||
// - applico eventuale filtro per rimborso:
|
||||
if (session()->filter_rimborso!='-1') { $model->where('spDaRimborsare', session()->get('filter_rimborso')); }
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('spese',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query con paginazione:
|
||||
$data['dataset'] = $model->paginate(session()->get('pager_num'));
|
||||
$data['pager'] = $model->pager;
|
||||
|
||||
// Ricavo i dati per il select delle commesse:
|
||||
$modelCommesse = new Commesse_Model();
|
||||
$data['select_commesse'] = $modelCommesse->get_select_on_spese();
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select_on_spese();
|
||||
|
||||
return view('pages/spese', $data);
|
||||
}//function spese
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function archivio() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'archivio';
|
||||
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
|
||||
return view('pages/archivio', $data);
|
||||
|
||||
}//function archivio
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function cars() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'cars';
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
// Ricavo le car:
|
||||
// Tab: CSiCoCars = ['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'caStato', 'caDeletedAt'];
|
||||
$model = new CSiCoCars_Model();
|
||||
|
||||
// Costruisco la query per selezionare le macchine da mostrare:
|
||||
// - applico il filtro sullo stato:
|
||||
if (session()->filter_caStato!='-1') { $model->where('caStato', session()->get('filter_caStato')); }
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('cars',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query con paginazione:
|
||||
$data['dataset'] = $model->paginate(session()->get('pager_num'));
|
||||
$data['pager'] = $model->pager;
|
||||
|
||||
return view('pages/cars', $data);
|
||||
|
||||
}//function cars
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function credit() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'credit';
|
||||
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
// Ricavo le carte:
|
||||
// Tab: CreditCards = ['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', ', 'ccStato', 'ccDeletedAt'];
|
||||
$model = new CreditCards_Model();
|
||||
|
||||
// Costruisco la query per selezionare le ore da mostrare:
|
||||
// - applico il filtro sullo stato:
|
||||
if (session()->filter_ccStato!='-1') { $model->where('ccStato', session()->get('filter_ccStato')); }
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('credit',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query con paginazione:
|
||||
$data['dataset'] = $model->paginate(session()->get('pager_num'));
|
||||
$data['pager'] = $model->pager;
|
||||
|
||||
return view('pages/credit', $data);
|
||||
|
||||
}//function credit
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function sims() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'sims';
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
// Ricavo le sim:
|
||||
// SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smCreatedAt', 'smUpdatedAt', 'smStato', 'smDeletedAt'];
|
||||
$model = new SIMs_Model();
|
||||
|
||||
// Costruisco la query per selezionare le macchine da mostrare:
|
||||
// - applico il filtro sullo stato:
|
||||
if (session()->filter_smStato!='-1') { $model->where('smStato', session()->get('filter_smStato')); }
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('sims',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query con paginazione:
|
||||
$data['dataset'] = $model->paginate(session()->get('pager_num'));
|
||||
$data['pager'] = $model->pager;
|
||||
|
||||
return view('pages/sims', $data);
|
||||
|
||||
}//function sims
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function admin() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'admin';
|
||||
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
|
||||
return view('pages/admin', $data);
|
||||
|
||||
}//function admin
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
public function set_order($tab, $col, $dir){
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(0)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
if (SetSort($tab, $col, $dir)) {
|
||||
if ($tab=='anagrafica') return redirect()->to('/Lavoratori/anagrafica');
|
||||
if ($tab=='evncredit') return redirect()->to('/CreditCardEvents/show');
|
||||
if ($tab=='evncar') return redirect()->to('/CSiCoCarEvents/show');
|
||||
if ($tab=='Issues') return redirect()->to('/Issues/View');
|
||||
|
||||
|
||||
return redirect()->to('/dashboard/' . $tab);
|
||||
} else {
|
||||
// ordinamento non riuscito, avviso l'utente e torno alla home
|
||||
session()->setFlashdata('warning', 'Errore durante il riordino dei records');
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function set_filter($page, $new_filter_dal, $new_filter_al, $new_option, $new_filter_commessa, $new_filter_lavoratore) {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(0)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
// Questi filtri sono indipendenti dalla tabella
|
||||
session()->set('filter_dal', $new_filter_dal);
|
||||
session()->set('filter_al', $new_filter_al);
|
||||
session()->set('filter_commessa', $new_filter_commessa);
|
||||
// Questo filtro dipende dal tipo di tabella:
|
||||
if ($page=='orari'){
|
||||
session()->set('filter_tipo_ore', $new_option);
|
||||
}
|
||||
if ($page=='spese'){
|
||||
session()->set('filter_rimborso', $new_option);
|
||||
}
|
||||
// solo gli amministratori possono vedere tutto e quindi cambiare il filtro del lavoratore:
|
||||
if (CheckLevel(3, false)) {
|
||||
session()->set('filter_lavoratore', $new_filter_lavoratore);
|
||||
} else {
|
||||
session()->set('filter_lavoratore', session()->get('lavoratore')->lvIDlavoratore);
|
||||
}
|
||||
return redirect()->to("/dashboard/$page");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function set_filter1($page, $new_option) {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(0)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
// Questo filtro dipende dal tipo di tabella:
|
||||
if ($page=='cars'){
|
||||
session()->set('filter_caStato', $new_option);
|
||||
return redirect()->to("/dashboard/$page");
|
||||
}
|
||||
if ($page=='credit'){
|
||||
session()->set('filter_ccStato', $new_option);
|
||||
return redirect()->to("/dashboard/$page");
|
||||
}
|
||||
if ($page=='sims'){
|
||||
session()->set('filter_smStato', $new_option);
|
||||
return redirect()->to("/dashboard/$page");
|
||||
}
|
||||
if ($page=='Stime'){
|
||||
session()->set('filter_commessa', $new_option);
|
||||
return redirect()->to("/Stime");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function reset_filter($page) {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(0)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
// Questi filtri sono indipendenti dalla tabella
|
||||
session()->set('filter_dal', date("Y-m-d", strtotime("first day of this month")));
|
||||
session()->set('filter_al', date("Y-m-d", strtotime("last day of this month")));
|
||||
session()->set('filter_commessa', '-1');
|
||||
|
||||
// Questo filtro dipende dal tipo di tabella:
|
||||
if ($page=='orari'){
|
||||
session()->set('filter_tipo_ore', '-1');
|
||||
}
|
||||
if ($page=='spese'){
|
||||
session()->set('filter_rimborso', '-1');
|
||||
}
|
||||
if ($page=='cars'){
|
||||
session()->set('filter_caStato', '-1');
|
||||
}
|
||||
if ($page=='credit'){
|
||||
session()->set('filter_ccStato', '-1');
|
||||
}
|
||||
if ($page=='sims'){
|
||||
session()->set('filter_smStato', '-1');
|
||||
}
|
||||
// solo gli amministratori possono vedere tutto e quindi cambiare il filtro del lavoratore:
|
||||
if (CheckLevel(3, false)) {
|
||||
session()->set('filter_lavoratore', '-1');
|
||||
} else {
|
||||
session()->set('filter_lavoratore', session()->get('lavoratore')->lvIDlavoratore);
|
||||
}
|
||||
if ($page=='Stime'){
|
||||
return redirect()->to("/Stime");
|
||||
}
|
||||
return redirect()->to("/dashboard/$page");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}//class Dashboard
|
||||
@@ -0,0 +1,388 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\Issues_Model;
|
||||
use App\Models\Lavoratori_Model;
|
||||
|
||||
class Issues extends CRUDController {
|
||||
|
||||
// Tab: Issues = ['isIDissue', 'isTipologia', 'isStato', 'isIDlavoratore', 'isTesto', 'isCreatedAt', 'isUpdatedAt', 'isDeletedAt'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'Issues',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Issue',
|
||||
'form_title_update' => 'Edit Issue',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella Issues',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => 'isUpdatedAt',
|
||||
'DeletedAt' => 'isDeletedAt',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['isIDissue'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['isTipologia'] = ['label' => 'Tipologia', 'helper' => 'Tipologia dell\'issue', 'required' => true];
|
||||
$fields['isStato'] = ['label' => 'Stato', 'helper' => 'Stato dell\'issue', 'required' => true];
|
||||
$fields['isIDlavoratore'] = [
|
||||
'label' => 'Lavoratore',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Lavoratore che inserisce l\'issue',
|
||||
'relation' => [
|
||||
'table'=> 'Lavoratori',
|
||||
'primary_key' => 'lvIDlavoratore',
|
||||
'display' => ['lvNickname', 'lvNome', 'lvCognome'], //'display' => ['lvNickname'],
|
||||
'order_by' => 'lvNickname',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['isTesto'] = ['label' => 'Testo', 'helper' => 'Testo descrittivo della issue','required' => true];
|
||||
$fields['isCreatedAt'] = ['label' => 'Created At', 'helper' => 'Data di creazione del record relativo nel database', 'only_edit'=> true];
|
||||
$fields['isUpdatedAt'] = ['label' => 'Updated At', 'helper' => 'Timestamp dell\'ultimo aggiornamento del record nel database', 'type' => 'unset'];
|
||||
$fields['isDeletedAt'] = ['label' => 'Deleted At', 'helper' => 'Data di cancellazione del record relativo nel database', 'type' => 'unset'];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['isIDissue', 'isTipologia', 'isStato', 'isIDlavoratore', 'isTesto', 'isCreatedAt', 'isUpdatedAt', 'isDeletedAt']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function View() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'admin';
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Issues/show -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo i relativi eventi:
|
||||
$mev = new Issues_Model();
|
||||
$mev->join('Lavoratori', 'Lavoratori.lvIDlavoratore = Issues.isIDlavoratore');
|
||||
|
||||
// Per ora niente filtro, poi in futuro forse
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('Issues',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$mev->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query con paginazione:
|
||||
$data['dataset'] = $mev->paginate(session()->get('pager_num'));
|
||||
$data['pager'] = $mev->pager;
|
||||
|
||||
return view('/pages/issues', $data);
|
||||
}//function select
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function add() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'admin';
|
||||
$data['add'] = true;
|
||||
$data['title'] = 'Dettagli dell\'Issue:';
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Issues/add -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Tipologia' => 'trim|required',
|
||||
'Stato' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
];
|
||||
if ($enable){
|
||||
$rules['IDlavoratore'] = 'trim|required';
|
||||
}
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
} else {
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
$newData = [
|
||||
//isIDissue' => $this->request->getVar('IDlavoratore'),
|
||||
'isTipologia' => $this->request->getVar('Tipologia'),
|
||||
'isStato' => $this->request->getVar('Stato'),
|
||||
'isTesto' => $this->request->getVar('Descrizione'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['isIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
} else {
|
||||
$newData['isIDlavoratore'] = session()->get('lavoratore')->lvIDlavoratore;
|
||||
}
|
||||
|
||||
$model = new Issues_Model();
|
||||
if ($model->save($newData)) {
|
||||
// issue inserito con successo, aggiorno lo stato della SIM
|
||||
session()->setFlashdata('success', 'issue inserito con successo');
|
||||
|
||||
// apro la pagina desiderata in base al pulsante utilizzato:
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/Issues/View');
|
||||
}
|
||||
} else {
|
||||
// errore durante l'inserimento dell'issue
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/Issues_form_add_edit', $data);
|
||||
}//function add
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function edit($IDissue = null) {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'admin';
|
||||
$data['add'] = false;
|
||||
$data['title'] = 'Dettagli dell\'Issue:';
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDissue==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Issues/edit -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Ricavo l'issue selezionato, completo di tutti i particolari:
|
||||
$model = new Issues_Model();
|
||||
$model->join('Lavoratori', 'Issues.isIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$data['issue'] = $model->where('isIDissue', $IDissue)
|
||||
->first();
|
||||
// Verifico che esista il record:
|
||||
if (null==$data['issue']) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Issues/edit -> Error code 003'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Tipologia' => 'trim|required',
|
||||
'Stato' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
];
|
||||
if ($enable){
|
||||
$rules['IDlavoratore'] = 'trim|required';
|
||||
}
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
$newData = [
|
||||
'isIDissue' => $IDissue,
|
||||
'isTipologia' => $this->request->getVar('Tipologia'),
|
||||
'isStato' => $this->request->getVar('Stato'),
|
||||
'isTesto' => $this->request->getVar('Descrizione'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['isIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
}
|
||||
|
||||
if ($model->save($newData)) {
|
||||
// issue inserito con successo, aggiorno lo stato della carta
|
||||
session()->setFlashdata('success', 'issue aggiornato con successo');
|
||||
|
||||
// apro la pagina desiderata in base al pulsante utilizzato:
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/Issues/View');
|
||||
}
|
||||
} else {
|
||||
// errore durante l'inserimento dell'issue
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/Issues_form_add_edit', $data);
|
||||
}//function edit
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function delete($IDissue = null){
|
||||
helper(['tools']);
|
||||
$data = [];
|
||||
|
||||
// Ricavo l'issue selezionato, completo di tutti i particolari:
|
||||
$model = new Issues_Model();
|
||||
$model->join('Lavoratori', 'Issues.isIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$issue = $model->where('isIDissue', $IDissue)
|
||||
->first();
|
||||
// Verifico che esista il record:
|
||||
if (null==$issue) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Issues/delete -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!(CheckLevel(3) || session()->get('lavoratore')->lvIDlavoratore==$issue->isIDlavoratore)) {
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per cancellare un issue inserito da altri lavoratori.');
|
||||
return redirect()->to('/Issues/show');
|
||||
}
|
||||
|
||||
// Elimino il record:
|
||||
if ($model->delete($IDissue)) {
|
||||
// issue cancellato, aggiorno stato della macchina relativa
|
||||
session()->setFlashdata('success', 'Record cancellato correttamente.');
|
||||
|
||||
} else {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
|
||||
// Show profile
|
||||
return redirect()->to('/Issues/View');
|
||||
} // function delete($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function export_csv(){
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/export_csv -> Error code 001'); }
|
||||
return redirect()->to('/Issues/show');
|
||||
}
|
||||
|
||||
// Ricavo gli eventi della sim:
|
||||
// Tab: Issues = ['isIDissue', 'isTipologia', 'isStato', 'isIDlavoratore', 'isTesto', 'isCreatedAt', 'isUpdatedAt', 'isDeletedAt'];
|
||||
$mev = new Issues_Model();
|
||||
$mev->join('Lavoratori', 'Issues.isIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
|
||||
// Per ora niente filtro, poi in futuro forse
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('Issues',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$mev->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query:
|
||||
$data['dataset'] = $mev->asArray()
|
||||
->findAll();
|
||||
|
||||
// Imposto il nome del file da downloadare:
|
||||
$filepath = $_SERVER['MRK_FILE_PATH'];
|
||||
$filename = 'CSiCoDB_Issues_il_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
// file creation
|
||||
$file = fopen($filepath . $filename,"w");
|
||||
// Esport header
|
||||
fputcsv($file,['Issue della web app:']);
|
||||
fputcsv($file,['ID issue', 'Tipologia', 'Stato', 'Descrizione issue', 'ID Lavoratore', 'Nickname', 'Created At', 'Updated At']);
|
||||
foreach ($data['dataset'] as $line){
|
||||
//fputcsv($file,$line);
|
||||
// Seleziono le colonne da esportare:
|
||||
$record = [];
|
||||
$record['isIDissue'] = $line['isIDissue'];
|
||||
$record['isTipologia'] = $line['isTipologia'];
|
||||
$record['isStato'] = $line['isStato'];
|
||||
$record['isTesto'] = $line['isTesto'];
|
||||
$record['isIDlavoratore'] = $line['isIDlavoratore'];
|
||||
$record['lvNickname'] = $line['lvNickname'];
|
||||
$record['isCreatedAt'] = $line['isCreatedAt'];
|
||||
$record['isUpdatedAt'] = $line['isUpdatedAt'];
|
||||
fputcsv($file,$record);
|
||||
}
|
||||
// Chiudo il file
|
||||
fclose($file);
|
||||
// download
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Disposition: attachment; filename=".$filename);
|
||||
header("Content-Type: application/csv; ");
|
||||
readfile($filepath . $filename);
|
||||
// deleting file
|
||||
unlink($filepath . $filename);
|
||||
exit();
|
||||
} // function export_csv
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,493 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\Lavoratori_Model;
|
||||
|
||||
|
||||
class Lavoratori extends CRUDController {
|
||||
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'Lavoratori',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Issue',
|
||||
'form_title_update' => 'Edit Issue',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella Lavoratori',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => 'lvUpdatedAt',
|
||||
'DeletedAt' => 'lvDeletedAt',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
|
||||
$fields['lvIDlavoratore'] = ['label' => 'ID Lavoratore'];
|
||||
$fields['lvNome'] = ['label' => 'Nome', 'helper' => 'Nome del lavoratore (max 64 caratteri)', 'required' => true];
|
||||
$fields['lvCognome'] = ['label' => 'Cognome', 'helper' => 'Cognome del lavoratore (max 64 caratteri)', 'required' => true];
|
||||
$fields['lvMail'] = ['label' => 'email', 'helper' => 'Indirizzo mail del lavoratore (max 128 caratteri)', 'required' => true, 'unique' => [true, 'lvMail']];
|
||||
$fields['lvLevel'] = ['label' => 'Livello', 'helper' => 'Livello di accesso alla webapp: 0=Guest; 1=Oper; 2=Inven; 3=Admin; 4=Root', 'required' => true];
|
||||
$fields['lvRimborsoKm'] = ['label' => '€/Km', 'helper' => 'Rimborso chilometrico riconosciuto al lavoratore', 'required' => true];
|
||||
$fields['lvNickname'] = ['label' => 'Nickname', 'helper' => 'Nickname del lavoratore nella forma CSiCoCCN', 'required' => true, 'unique' => [true, 'lvNickname']];
|
||||
$fields['lvPassword'] = [
|
||||
'label' => 'Password',
|
||||
'required' => true,
|
||||
'only_add' => true,
|
||||
'type' => 'password',
|
||||
'confirm' => true,
|
||||
'password_hash' => true,
|
||||
'helper' => 'Password per il riconoscimento del lavoratore (min 8 caratteri)'
|
||||
];
|
||||
$fields['lvCreatedAt'] = ['label' => 'Created at', 'helper' => 'Data di creazione del record relativo nel database', 'only_edit'=> true];
|
||||
$fields['lvUpdatedAt'] = ['label' => 'Updated at', 'helper' => 'Timestamp dell\'ultimo aggiornamento del record nel database', 'type' => 'unset'];
|
||||
$fields['lvDeletedAt'] = ['label' => 'Deleted at', 'helper' => 'Data di cancellazione del record relativo nel database', 'type' => 'unset'];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['lvIDlavoratore', 'lvNickname', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// funzione per reinizializzare un utente senza loggarsi, utile in caso di problemi per avere un nuovo amministratore e potersi collegare.
|
||||
// http://localhost/Lavoratori/reinizzializza/CSiCoAlm/4/password/127
|
||||
public function Reinizzializza($Nickname = 'CSiCoZZZ', $Level = '0', $Password = 'password', $CheckId = 0){
|
||||
if ($CheckId<>127) {
|
||||
// Se non siamo loggati
|
||||
session()->setFlashdata('danger', 'Reinizzializzazione del lavoratore non autorizzata.');
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo l'ID del lavoratore indicato:
|
||||
$model = new Lavoratori_Model();
|
||||
$lav = $model->where('lvNickname', $Nickname)
|
||||
->first();
|
||||
if (!isset($lav)) {
|
||||
// Lavoratore non trovato
|
||||
session()->setFlashdata('danger', 'Lavoratore da reinizzializzare non trovato.');
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Preparo i dati per l'aggiornamento
|
||||
$newData = [
|
||||
'lvIDlavoratore' => $lav->lvIDlavoratore,
|
||||
'lvLevel' => $Level,
|
||||
'lvPassword' => $Password,
|
||||
];
|
||||
|
||||
// Eseguo update del record
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Lavoratore reinizzializzato correttamente.');
|
||||
return redirect()->to('/dashboard');
|
||||
} else {
|
||||
session()->setFlashdata('warning', 'Reinizzializzazione non riuscita.');
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
} // function Reinizzializza
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function logout(){
|
||||
session()->destroy();
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}//function logout
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function login (){
|
||||
$data = [];
|
||||
helper(['tools','form']);
|
||||
|
||||
// Gestione POST data dal form
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Nickname' => 'required|min_length[8]|max_length[8]',
|
||||
'Password' => 'required|min_length[8]|max_length[255]',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
// Validazione non passata, mostro errori sulla flash di warning
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
} else {
|
||||
// validazione passata
|
||||
// ricavo il lavoratore dai dati inseriti
|
||||
$model = new Lavoratori_Model();
|
||||
$lav = $model->where('lvNickname', $this->request->getVar('Nickname'))
|
||||
->first();
|
||||
if (isset($lav) && (password_verify($this->request->getVar('Password'), $lav->lvPassword))) {
|
||||
// Verifico se lavoratore abilitato:
|
||||
if (password_verify($this->request->getVar('Password'), $lav->lvPassword)){
|
||||
// Utente riconosciuto, inizio la sessione di lavoro
|
||||
if (setUserSession($lav)){
|
||||
session()->setFlashdata('success', 'Utente abilitato correttamente');
|
||||
return redirect()->to('/dashboard');
|
||||
} else {
|
||||
session()->setFlashdata('warning', 'Errore durante la creazione della sessione di lavoro.<br> Riprovare e se l\'errore si ripete, contattare l\'amministratore.');
|
||||
}
|
||||
|
||||
} else {
|
||||
// utente non riconosciuto, ritorno al login
|
||||
session()->setFlashdata('warning', 'Errore, lavoratore non riconosciuto.<br> Riprovare e se l\'errore si ripete, contattare l\'amministratore.');
|
||||
}
|
||||
|
||||
} else {
|
||||
// Coppia nickname/password non corretta.
|
||||
session()->setFlashdata('warning', 'Errore, lavoratore non riconosciuto.<br> Riprovare e se l\'errore si ripete, contattare l\'amministratore.');
|
||||
}
|
||||
|
||||
}// analisi della validazione
|
||||
|
||||
}// Gestione POST data dal form
|
||||
|
||||
// Show login page
|
||||
echo view('pages/lavoratori/lavoratori_form_login', $data);
|
||||
}//function login
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function profile($id = null){
|
||||
$data = [];
|
||||
helper(['tools','form']);
|
||||
$model = new Lavoratori_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(0)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutte del lavoratore)
|
||||
$enable = CheckLevel(3,false);
|
||||
|
||||
// Ricavo l'ID del lavoratore di cui editare il profilo:
|
||||
if (!isset($id)) {
|
||||
$id = session()->get('lavoratore')->lvIDlavoratore;
|
||||
}
|
||||
|
||||
// Ricavo il profilo del lavoratore da editare
|
||||
$lav = $model->where('lvIDlavoratore', $id)
|
||||
->first();
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
//
|
||||
// L'utente normale può editare solo nome, cognome e quando vuole anche la password.
|
||||
// L'utente amministratore o superiore, può editare tutto dell'utente.
|
||||
$rules = [
|
||||
//'IDlavoratore' => '',
|
||||
'Nome' => 'trim|required|min_length[3]|max_length[64]',
|
||||
'Cognome' => 'trim|required|min_length[3]|max_length[64]',
|
||||
];
|
||||
if ($enable){
|
||||
$rules['Mail'] = 'required|min_length[6]|max_length[50]|valid_email';
|
||||
$rules['Nickname'] = 'trim|required|min_length[8]|max_length[8]';
|
||||
$rules['RimborsoKm'] = 'required';
|
||||
}
|
||||
if($this->request->getPost('NewPassword') != ''){
|
||||
$rules['NewPassword'] = 'required|min_length[8]|max_length[255]';
|
||||
$rules['ConfirmNewPassword'] = 'matches[NewPassword]';
|
||||
}
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'aggiornamento
|
||||
$newData = [
|
||||
'lvIDlavoratore' => $lav->lvIDlavoratore,
|
||||
'lvNome' => $this->request->getVar('Nome'),
|
||||
'lvCognome' => $this->request->getVar('Cognome'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['lvLevel'] = $this->request->getVar('Livello');
|
||||
$newData['lvMail'] = $this->request->getVar('Mail');
|
||||
$newData['lvNickname'] = $this->request->getVar('Nickname');
|
||||
$newData['lvRimborsoKm'] = $this->request->getVar('RimborsoKm');
|
||||
}
|
||||
if($this->request->getPost('NewPassword') != ''){
|
||||
$newData['lvPassword'] = $this->request->getPost('NewPassword');
|
||||
}
|
||||
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Successfuly Updated');
|
||||
return redirect()->to('/dashboard');
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'update del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Rileggo i dati dal DB
|
||||
$data['lavoratore'] = $lav;
|
||||
$data['enable'] = $enable;
|
||||
// Show profile
|
||||
echo view('pages/lavoratori/lavoratori_form_profile', $data);
|
||||
} // function profile
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function delete($id = null){
|
||||
$data = [];
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(3,false)) { return redirect()->to('/Lavoratori/anagrafica'); }
|
||||
|
||||
// Verifico di non cancellare me stesso:
|
||||
if (session()->get('lavoratore')->lvIDlavoratore==$id) {
|
||||
session()->setFlashdata('warning', 'L\'utente non può cancellare se stesso.');
|
||||
return redirect()->to('/Lavoratori/anagrafica');
|
||||
}
|
||||
|
||||
// Elimino il record:
|
||||
$model = new Lavoratori_Model();
|
||||
if ($model->delete($id)) {
|
||||
session()->setFlashdata('success', 'Recors cancellato correttamente.');
|
||||
|
||||
} else {
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
|
||||
return redirect()->to('/Lavoratori/anagrafica');
|
||||
} // function delete
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function register(){
|
||||
$data = [];
|
||||
helper(['tools','form']);
|
||||
|
||||
// // Verifico sessione e livello:
|
||||
// if (CheckLevel(0,false)) { return redirect()->to('/dashboard'); } // non faccio il test così lo uso anche per creare nuovo utente dalla pagina anagrafica
|
||||
|
||||
// Gestione POST data dal form
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Nome' => 'required|min_length[3]|max_length[64]',
|
||||
'Cognome' => 'required|min_length[3]|max_length[64]',
|
||||
'Password' => 'required|min_length[8]|max_length[255]',
|
||||
'PasswordConfirm' => 'matches[Password]',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
// Validazione non passata, mostro errori sulla flash di warning
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
$model = new Lavoratori_Model();
|
||||
$nom = $this->request->getVar('Nome');
|
||||
$cogn = $this->request->getVar('Cognome');
|
||||
|
||||
// Preparo i dati del nuovo record
|
||||
$newData = [
|
||||
'lvNome' => $nom,
|
||||
'lvCognome' => $cogn,
|
||||
'lvMail' => strtolower($nom) . "." . strtolower($cogn) . "@csico.it",
|
||||
'lvLevel' => 0,
|
||||
'lvRimborsoKm' => 0.0,
|
||||
'lvNickname' => 'CSiCo'.(substr(strtoupper($cogn), 0, 1)).(substr(strtolower($cogn), 1, 1)).(substr(strtolower($nom), 0, 1)),
|
||||
'lvPassword' => $this->request->getVar('Password'),
|
||||
];
|
||||
// Inserisco il nuovo record
|
||||
if ($model->save($newData)){
|
||||
session()->setFlashdata('success', 'Dati acquisiti, attendere la mail di conferma per l\'abilitazione completa');
|
||||
//return redirect()->to('/dashboard');
|
||||
return redirect()->to('/Lavoratori/anagrafica'); // uso register anche nell'anagrafica
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
echo view('pages/lavoratori/lavoratori_form_register', $data);
|
||||
} // function register
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function anagrafica(){
|
||||
$data['tab'] = 'amministrazione';
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
$model = new Lavoratori_Model();
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('anagrafica',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// // imposto l'ordinamento richiesto:
|
||||
// $order_field = session()->get('sort_lavoratori_field');
|
||||
// $order_direction = session()->get('sort_lavoratori_val');
|
||||
// $model->orderBy($order_field, $order_direction);
|
||||
|
||||
$data['dataset'] = $model->paginate(session()->get('pager_num'));
|
||||
$data['pager'] = $model->pager;
|
||||
|
||||
// Show anagrafica
|
||||
echo view('pages/lavoratori/lavoratori_anagrafica', $data);
|
||||
} // function anagrafica
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// Funzione per resettare la password dell'utente indicato con la standard password.
|
||||
// TODO Deve inviare mail di conferma all'utente.
|
||||
public function reset($id){
|
||||
$data = [];
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(0)) { return redirect()->to('/Lavoratori/login'); }
|
||||
|
||||
|
||||
// Se non abbiamo il livello amministrativo non posso resettare la password a meno che non sia la mia.
|
||||
$lav = session()->get('lavoratore');
|
||||
if ((CheckLevel(3, false)) || ($lav->lvIDlavoratore==$id)){
|
||||
//Resetto password con quella standard: password
|
||||
|
||||
// Preparo i dati per l'aggiornamento
|
||||
$newData = [
|
||||
'lvIDlavoratore' => $id,
|
||||
'lvPassword' => 'password',
|
||||
];
|
||||
|
||||
// Eseguo update del record
|
||||
$model = new Lavoratori_Model();
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Password resettata correttamente.');
|
||||
} else {
|
||||
session()->setFlashdata('warning', 'Reset password non riuscito.');
|
||||
}
|
||||
} else{
|
||||
// non resetto la password
|
||||
session()->setFlashdata('warning', 'Reset password non consentito.');
|
||||
}
|
||||
|
||||
return redirect()->to('/Lavoratori/anagrafica');
|
||||
} // function reset
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function export_csv(){
|
||||
helper(['tools']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Lavoratori/export_csv -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo le ore dell'utente:
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt'];
|
||||
$model = new Lavoratori_Model();
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('anagrafica',true);
|
||||
$sortCol = session()->get('sort')['col'];
|
||||
$sortDir = session()->get('sort')['dir'];
|
||||
$model->orderBy($sortCol, $sortDir);
|
||||
|
||||
// eseguo la query:
|
||||
$data['dataset'] = $model->asArray()
|
||||
->findAll();
|
||||
|
||||
// Imposto il nome del file da downloadare:
|
||||
$filepath = $_SERVER['MRK_FILE_PATH'];
|
||||
$filename = 'CSiCoDB_Lavoratori_il_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
// file creation
|
||||
$file = fopen($filepath . $filename,"w");
|
||||
// Esport header
|
||||
fputcsv($file,['ID','Nome','Cognome','Mail','Level','RimborsoKm','Nickname','Hash Password','CreatedAt','UpdatedAt','DeletedAt']);
|
||||
foreach ($data['dataset'] as $line){
|
||||
fputcsv($file,$line);
|
||||
}
|
||||
// Chiudo il file
|
||||
// download
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Disposition: attachment; filename=".$filename);
|
||||
header("Content-Type: application/csv; ");
|
||||
readfile($filepath . $filename);
|
||||
// deleting file
|
||||
unlink($filepath . $filename);
|
||||
exit();
|
||||
}//function export_csv
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}//class Lavoratori
|
||||
@@ -0,0 +1,471 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\Lavoratori_Model;
|
||||
use App\Models\Commesse_Model;
|
||||
use App\Models\TipoOre_Model;
|
||||
use App\Models\TipiWork_Model;
|
||||
use App\Models\Orari_Model;
|
||||
use App\Models\Spese_Model;
|
||||
|
||||
|
||||
class Orari extends CRUDController {
|
||||
|
||||
// Tab: Orari = ['orIDorario', 'orIDcommessa', 'orIDlavoratore', 'orData', 'orOre', 'orIDTipoOre', 'orIDTipoWork', 'orDescrizione'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'Orari',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Orario',
|
||||
'form_title_update' => 'Edit Orario',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella Orari',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => '',
|
||||
'DeletedAt' => '',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['orIDorario'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['orIDcommessa'] = [
|
||||
'label' => 'Commessa',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Commessa a cui si riferisce l\'orario',
|
||||
'relation' => [
|
||||
'table'=> 'Commesse',
|
||||
'primary_key' => 'coIDcommessa',
|
||||
'display' => ['coNome'],
|
||||
'order_by' => 'coUpdatedAt',
|
||||
'order' => 'DESC'
|
||||
]
|
||||
];
|
||||
$fields['orIDlavoratore'] = [
|
||||
'label' => 'Lavoratore',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Lavoratore a cui si riferisce l\'orario',
|
||||
'relation' => [
|
||||
'table'=> 'Lavoratori',
|
||||
'primary_key' => 'lvIDlavoratore',
|
||||
'display' => ['lvNickname', 'lvNome', 'lvCognome'], //'display' => ['lvNickname'],
|
||||
'order_by' => 'lvNickname',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['orData'] = ['label' => 'Data', 'helper' => 'Data dell\'orario','required' => true];
|
||||
$fields['orOre'] = ['label' => 'Durata', 'helper' => 'Durata dell\'orario di lavoro. Approssimare al quarto d\'ora (0.25)', 'required' => true];
|
||||
$fields['orIDTipoOre'] = [
|
||||
'label' => 'Tipologia',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Tipologia dell\'orario',
|
||||
'relation' => [
|
||||
'table'=> 'TipoOre',
|
||||
'primary_key' => 'toIDTipoOre',
|
||||
'display' => ['toDescrizione'],
|
||||
'order_by' => 'toOrdinamento',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['orDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva di quanto fatto durante l\'orario inserito','required' => true];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['orIDorario', 'orIDcommessa', 'orIDlavoratore', 'orData', 'orOre', 'orIDTipoOre', 'orIDTipoWork', 'orDescrizione']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function add(){
|
||||
helper(['tools','form']);
|
||||
$data['Data'] = date('Y-m-d');
|
||||
$model = new Orari_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Orari/add -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$enable = CheckLevel(3, false);
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
//
|
||||
$rules = [
|
||||
'IDcommessa' => 'trim|required',
|
||||
'Data' => 'trim|required',
|
||||
'Durata' => 'trim|required',
|
||||
'IDTipoOre' => 'trim|required',
|
||||
'IDTipoWork' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
];
|
||||
if ($enable){
|
||||
$rules['IDlavoratore'] = 'trim|required';
|
||||
}
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
// Tab: Orari = ['orIDorario', 'orIDcommessa', 'orIDlavoratore', 'orData', 'orOre', 'orIDTipoOre', 'orIDTipoWork', 'orDescrizione'];
|
||||
$newData = [
|
||||
'orIDcommessa' => $this->request->getVar('IDcommessa'),
|
||||
'orData' => $this->request->getVar('Data'),
|
||||
'orOre' => $this->request->getVar('Durata'),
|
||||
'orIDTipoOre' => $this->request->getVar('IDTipoOre'),
|
||||
'orIDTipoWork' => $this->request->getVar('IDTipoWork'),
|
||||
'orDescrizione' => $this->request->getVar('Descrizione'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['orIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
} else {
|
||||
$newData['orIDlavoratore'] = session()->get('lavoratore')->lvIDlavoratore;
|
||||
}
|
||||
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Record inserito con successo sul DB');
|
||||
UpdateCommessa($newData['orIDcommessa']);
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/dashboard/orari');
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Rileggo i dati dal DB
|
||||
$data['enable'] = $enable;
|
||||
|
||||
// Ricavo i dati per il select delle commesse:
|
||||
$modelCommesse = new Commesse_Model();
|
||||
$data['select_commesse'] = $modelCommesse->get_select();
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
// Ricavo i dati per il select deila tipologia di ore:
|
||||
$modelTipoOre = new TipoOre_Model();
|
||||
$data['select_tipo_ore'] = $modelTipoOre->get_select();
|
||||
|
||||
// Ricavo i dati per il select deila tipologia di lavoro:
|
||||
$modelTipiWork = new TipiWork_Model();
|
||||
$data['select_tipi_work'] = $modelTipiWork->get_select();
|
||||
|
||||
// Show profile
|
||||
echo view('pages/orari/orari_form_add', $data);
|
||||
} // function add($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function edit($IDorario = null){
|
||||
helper(['tools','form']);
|
||||
$data = [];
|
||||
$model = new Orari_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Orari/edit -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$enable = CheckLevel(3, false);
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDorario==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Orari/edit -> Error code 002'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo il profilo dell'orario da editare
|
||||
$orario = $model->where('orIDorario', $IDorario)
|
||||
->first();
|
||||
|
||||
// Verifico che esista il record dell'orario:
|
||||
if (null==$orario) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Orari/edit -> Error code 003'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico se posso editare il campo:
|
||||
// - utente amministratore o superiore, può editare tutti i campi
|
||||
// - utente normale può editare solo i propi orari
|
||||
$lav = session()->get('lavoratore');
|
||||
if ((!$enable) && ($lav->lvIDlavoratore<>$orario->orIDlavoratore)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Orari/edit -> Error code 004'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
//
|
||||
$rules = [
|
||||
'IDorario' => 'trim|required',
|
||||
'IDcommessa' => 'trim|required',
|
||||
'Data' => 'trim|required',
|
||||
'Durata' => 'trim|required',
|
||||
'IDTipoOre' => 'trim|required',
|
||||
'IDTipoWork' => 'trim|required',
|
||||
'Descrizione' => 'trim|required',
|
||||
];
|
||||
if ($enable){
|
||||
//$rules['Level'] = 'trim|required|min_length[8]|max_length[255]';
|
||||
$rules['IDlavoratore'] = 'trim|required';
|
||||
}
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'aggiornamento
|
||||
$newData = [
|
||||
'orIDorario' => $orario->orIDorario,
|
||||
'orIDcommessa' => $this->request->getVar('IDcommessa'),
|
||||
'orData' => $this->request->getVar('Data'),
|
||||
'orOre' => $this->request->getVar('Durata'),
|
||||
'orIDTipoOre' => $this->request->getVar('IDTipoOre'),
|
||||
'orIDTipoWork' => $this->request->getVar('IDTipoWork'),
|
||||
'orDescrizione' => $this->request->getVar('Descrizione'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['orIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
}
|
||||
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Successfuly Updated');
|
||||
UpdateCommessa($newData['orIDcommessa']);
|
||||
return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'update del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Rileggo i dati dal DB
|
||||
$data['orario'] = $orario;
|
||||
$data['enable'] = $enable;
|
||||
|
||||
// Ricavo i dati per il select delle commesse:
|
||||
$modelCommesse = new Commesse_Model();
|
||||
$data['select_commesse'] = $modelCommesse->get_select();
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
// Ricavo i dati per il select deila tipologia di ore:
|
||||
$modelTipoOre = new TipoOre_Model();
|
||||
$data['select_tipo_ore'] = $modelTipoOre->get_select();
|
||||
|
||||
// Ricavo i dati per il select deila tipologia di lavoro:
|
||||
$modelTipiWork = new TipiWork_Model();
|
||||
$data['select_tipi_work'] = $modelTipiWork->get_select();
|
||||
|
||||
|
||||
// Show profile
|
||||
echo view('pages/orari/orari_form_edit', $data);
|
||||
} // function edit($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function delete($IDorario = null){
|
||||
helper(['tools']);
|
||||
$data = [];
|
||||
$model = new Orari_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Orari/delete -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$enable = CheckLevel(3, false);
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDorario==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Orari/delete -> Error code 002'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo il record dell'orario da editare
|
||||
$orario = $model->where('orIDorario', $IDorario)
|
||||
->first();
|
||||
|
||||
// Verifico che esista il record dell'orario:
|
||||
//if (null==$orario) { return redirect()->to('/dashboard'); }
|
||||
if (!isset($orario)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Orari/delete -> Error code 003'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico se posso editare il record:
|
||||
// - utente amministratore o superiore, cancellare qualunque orario
|
||||
// - utente normale può cancellare solo i propi orari
|
||||
$lav = session()->get('lavoratore');
|
||||
if ((!$enable) && ($lav->IDlavoratore<>$orario->IDlavoratore)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Orari/delete -> Error code 004'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Elimino il record:
|
||||
if ($model->delete($IDorario)) {
|
||||
session()->setFlashdata('success', 'Recors cancellato correttamente.');
|
||||
|
||||
} else {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
|
||||
// Show profile
|
||||
return redirect()->to('/dashboard/orari');
|
||||
} // function delete($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function export_csv(){
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Orari/export_csv -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Ricavo le ore dell'utente:
|
||||
// Tab: Orari = ['orIDorario', 'orIDcommessa', 'orIDlavoratore', 'orData', 'orOre', 'orIDTipoOre', 'orDescrizione'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt'];
|
||||
// Tab: Commesse = ['coIDcommessa', 'coNome', 'coIDcliente', 'coDescrizione', 'coIDstatoCommessa', 'coModificatoIl', 'coCreatedAt', 'coUpdatedAt', 'coDeletedAt'];
|
||||
$model = new Orari_Model();
|
||||
$model->join('Lavoratori', 'Lavoratori.lvIDlavoratore = Orari.orIDlavoratore');
|
||||
$model->join('Commesse', 'Commesse.coIDcommessa = Orari.orIDcommessa');
|
||||
$model->join('TipoOre', 'TipoOre.toIDTipoOre = Orari.orIDTipoOre');
|
||||
|
||||
// Costruisco la query per selezionare le ore da esportare:
|
||||
// - applico il filtro sull'intervallo temporale:
|
||||
$model->where('orData >=', session()->get('filter_dal'))
|
||||
->where('orData <=', session()->get('filter_al') . " 23:59:59");
|
||||
// - applico eventuale filtro per lavoratore
|
||||
if (session()->filter_lavoratore!='-1') { $model->where('orIDlavoratore', session()->get('filter_lavoratore')); }
|
||||
// - applico eventuale filtro per commessa
|
||||
if (session()->filter_commessa!='-1') { $model->where('orIDcommessa', session()->get('filter_commessa')); }
|
||||
// - applico eventuale filtro per tipologia di ora:
|
||||
if (session()->filter_tipo_ore!='-1') { $model->where('orIDTipoOre', session()->get('filter_tipo_ore')); }
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('orari',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query:
|
||||
$data['dataset'] = $model->asArray()
|
||||
->findAll();
|
||||
|
||||
// Imposto il nome del file da downloadare:
|
||||
$filepath = $_SERVER['MRK_FILE_PATH'];
|
||||
$filename = 'CSiCoDB_Orari_il_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
// file creation
|
||||
$file = fopen($filepath . $filename,"w");
|
||||
// Esport header
|
||||
fputcsv($file,['IDorario','IDcommessa','Commessa','IDlavoratore','Lavoratore','Il','Durata','IDTipoOre','Tipologia','IDTipoWork','Descrizione']);
|
||||
|
||||
foreach ($data['dataset'] as $line){
|
||||
//fputcsv($file,$line);
|
||||
// Seleziono le colonne da esportare:
|
||||
$record = [];
|
||||
$record['orIDorario'] = $line['orIDorario'];
|
||||
$record['orIDcommessa'] = $line['orIDcommessa'];
|
||||
$record['coNome'] = $line['coNome'];
|
||||
$record['orIDlavoratore'] = $line['orIDlavoratore'];
|
||||
$record['lvNickname'] = $line['lvNickname'];
|
||||
$record['orData'] = $line['orData'];
|
||||
$record['orOre'] = $line['orOre'];
|
||||
$record['orIDTipoOre'] = $line['orIDTipoOre'];
|
||||
$record['toDescrizione'] = $line['toDescrizione'];
|
||||
$record['orIDTipoWork'] = $line['orIDTipoWork'];
|
||||
$record['orDescrizione'] = $line['orDescrizione'];
|
||||
fputcsv($file,$record);
|
||||
}
|
||||
// Chiudo il file
|
||||
fclose($file);
|
||||
// download
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Disposition: attachment; filename=".$filename);
|
||||
header("Content-Type: application/csv; ");
|
||||
readfile($filepath . $filename);
|
||||
// deleting file
|
||||
unlink($filepath . $filename);
|
||||
exit();
|
||||
} // function export_csv
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}//class Orari
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
|
||||
|
||||
class Posizioni extends CRUDController {
|
||||
|
||||
// Tab: Posizioni = ['psIDplace', 'psCode', 'psDescrizione'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'Posizioni',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Posizione',
|
||||
'form_title_update' => 'Edit Posizione',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella Posizioni',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => '',
|
||||
'DeletedAt' => '',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['psIDplace'] = ['label' => 'ID', 'helper' => 'Identificativo univoco della posizione'];
|
||||
$fields['psCode'] = ['label' => 'Code', 'helper' => 'Codice della posizione (max 16 caratteri)', 'required' => true, 'unique' => [true, 'psCode']];
|
||||
$fields['psDescrizione'] = ['label' =>'Descrizione', 'helper' => 'Descrizione della posizione', 'required' => true];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['psIDplace', 'psCode', 'psDescrizione']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,534 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\SIMs_Model;
|
||||
use App\Models\SIMEvents_Model;
|
||||
use App\Models\Lavoratori_Model;
|
||||
|
||||
|
||||
class SIMEvents extends CRUDController {
|
||||
|
||||
// Tab: SIMEvents = ['esmIDsimEvent', 'esmIDsim', 'esmIDlavoratore', 'esmDescrizione', 'esmData', 'esmTipologia'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'SIMEvents',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Evento',
|
||||
'form_title_update' => 'Edit Evento',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella SIMEvents',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => '',
|
||||
'DeletedAt' => '',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['esmIDsimEvent'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['esmIDsim'] = [
|
||||
'label' => 'SIM',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'SIM a cui si riferisce l\'evento',
|
||||
'relation' => [
|
||||
'table'=> 'SIMs',
|
||||
'primary_key' => 'smIDsim',
|
||||
'display' => ['smIDsim', 'smNumero'],
|
||||
'order_by' => 'smNumero',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['esmIDlavoratore'] = [
|
||||
'label' => 'Lavoratore',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Lavoratore a cui si riferisce l\'evento',
|
||||
'relation' => [
|
||||
'table'=> 'Lavoratori',
|
||||
'primary_key' => 'lvIDlavoratore',
|
||||
'display' => ['lvNickname', 'lvNome', 'lvCognome'], //'display' => ['lvNickname'],
|
||||
'order_by' => 'lvNickname',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['esmDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva dell\'evento', 'required' => true];
|
||||
$fields['esmData'] = ['label' => 'Timestamp', 'helper' => 'Timestamp dell\'evento', 'required' => true, 'type' => 'date'];
|
||||
$fields['esmTipologia'] = ['label' => 'Tipo', 'helper' => 'Tipologia di evento', 'required' => true];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['esmIDsimEvent', 'esmIDsim', 'esmIDlavoratore', 'esmDescrizione', 'esmData', 'esmTipologia']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function show() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'sims';
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMEvents/show -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo la macchina selezionata (se vi è una selezione):
|
||||
$IDsim = session()->get('filter_sim');
|
||||
if ((null !== $IDsim) && ($IDsim!=-1)) {
|
||||
$mcc = new SIMs_Model();
|
||||
$data['sim'] = $mcc->where('smIDsim', $IDsim)->first();
|
||||
}
|
||||
|
||||
// Ricavo i relativi eventi:
|
||||
$mev = new SIMEvents_Model();
|
||||
$mev->join('Lavoratori', 'SIMEvents.esmIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$mev->join('SIMs', 'SIMEvents.esmIDsim = SIMs.smIDsim');
|
||||
|
||||
// Per ora niente filtro, poi in futuro forse
|
||||
$mev->where('esmIDsim', $IDsim);
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('evnsim',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$mev->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query con paginazione:
|
||||
$data['dataset'] = $mev->paginate(session()->get('pager_num'));
|
||||
$data['pager'] = $mev->pager;
|
||||
|
||||
return view('/pages/events/SIMEvents', $data);
|
||||
}//function select
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function add() {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMEvents/add -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Ricavo la macchina selezionata (se vi è una selezione):
|
||||
$IDsim = session()->get('filter_sim');
|
||||
if ((null == $IDsim) || ($IDsim==-1)) {
|
||||
return redirect()->to('/dashboard/sim');
|
||||
}
|
||||
|
||||
$mcc = new SIMs_Model();
|
||||
$data['sim'] = $mcc->where('smIDsim', $IDsim)->first();
|
||||
if ($data['sim']==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMEvents/add -> Error code 002'); }
|
||||
return redirect()->to('/dashboard/sim');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'sims';
|
||||
$data['add'] = true;
|
||||
$data['title'] = 'Dettagli nuova evento della SIM: ' . $data['sim']->ccNumero;
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Data' => 'trim|required',
|
||||
'Tipologia' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
];
|
||||
if ($enable){
|
||||
$newData['ecaIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
}
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
} else {
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
// Tab: SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smStato', 'smCreatedAt', 'smUpdatedAt', 'smDeletedAt'];
|
||||
// Tab: SIMEvents = ['esmIDsimEvent', 'esmIDsim', 'esmIDlavoratore', 'esmDescrizione', 'esmData', 'esmTipologia'];
|
||||
$newData = [
|
||||
'esmIDsim' => $data['sim']->smIDsim,
|
||||
'esmDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'esmData' => $this->request->getVar('Data'),
|
||||
'esmTipologia' => $this->request->getVar('Tipologia'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['esmIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
} else {
|
||||
$newData['esmIDlavoratore'] = session()->get('lavoratore')->lvIDlavoratore;
|
||||
}
|
||||
|
||||
$model = new SIMEvents_Model();
|
||||
if ($model->save($newData)) {
|
||||
// evento inserito con successo, aggiorno lo stato della SIM
|
||||
if ($this->updateSimStato($data['sim']->smIDsim)) {
|
||||
// update dello stato nella SIM riuscito
|
||||
session()->setFlashdata('success', 'Evento inserito con successo');
|
||||
} else {
|
||||
// update dello stato nella SIM fallito
|
||||
session()->setFlashdata('danger', 'Evento inserito ma stato della SIM non aggiornato correttamente');
|
||||
}
|
||||
// apro la pagina desiderata in base al pulsante utilizzato:
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/SIMEvents/show');
|
||||
}
|
||||
} else {
|
||||
// errore durante l'inserimento dell'evento
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/SIMEvents_form_add_edit', $data);
|
||||
}//function add
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function edit($IDevent = null) {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDevent==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMEvents/edit -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMEvents/edit -> Error code 002'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Ricavo l'evento selezionato, completo di tutti i particolari:
|
||||
// Tab: SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smStato', 'smCreatedAt', 'smUpdatedAt', 'smDeletedAt'];
|
||||
// Tab: SIMEvents = ['esmIDsimEvent', 'esmIDsim', 'esmIDlavoratore', 'esmDescrizione', 'esmData', 'esmTipologia'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'smStato', 'lvDeletedAt'];
|
||||
$model = new SIMEvents_Model();
|
||||
$model->join('SIMs', 'SIMEvents.esmIDsim = SIMs.smIDsim');
|
||||
$model->join('Lavoratori', 'SIMEvents.esmIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$data['evnt'] = $model->where('esmIDsimEvent', $IDevent)
|
||||
->first();
|
||||
// Verifico che esista il record:
|
||||
if (null==$data['evnt']) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMEvents/edit -> Error code 003'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// ricavo la macchina a cui l'evento si riferisce
|
||||
$mcc = new SIMs_Model();
|
||||
$data['sim'] = $mcc->where('smIDsim', $data['evnt']->esmIDsim)->first();
|
||||
// Verifico che esista il record:
|
||||
if ($data['sim']==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMEvents/edit -> Error code 004'); }
|
||||
return redirect()->to('/dashboard/cars');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'sims';
|
||||
$data['add'] = false;
|
||||
$data['title'] = 'Dettagli evento: ' . $data['evnt']->smNumero;
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Data' => 'trim|required',
|
||||
'Tipologia' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
];
|
||||
if ($enable){
|
||||
$newData['ecaIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
}
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
$newData = [
|
||||
'esmIDsimEvent' => $IDevent,
|
||||
'esmDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'esmData' => $this->request->getVar('Data'),
|
||||
'esmTipologia' => $this->request->getVar('Tipologia'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['esmIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
}
|
||||
|
||||
if ($model->save($newData)) {
|
||||
// evento inserito con successo, aggiorno lo stato della carta
|
||||
if ($this->updateSimStato($data['sim']->smIDsim)) {
|
||||
// update dello stato nella sim riuscito
|
||||
session()->setFlashdata('success', 'Evento aggiornato con successo');
|
||||
} else {
|
||||
// update dello stato nella sim fallito
|
||||
session()->setFlashdata('danger', 'Evento inserito ma stato della SIM non aggiornato correttamente');
|
||||
}
|
||||
// apro la pagina desiderata in base al pulsante utilizzato:
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/SIMEvents/show');
|
||||
}
|
||||
} else {
|
||||
// errore durante l'inserimento dell'evento
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/SIMEvents_form_add_edit', $data);
|
||||
}//function edit
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function delete($IDevent = null){
|
||||
helper(['tools']);
|
||||
$data = [];
|
||||
|
||||
// Ricavo l'evento selezionato, completo di tutti i particolari:
|
||||
// Tab: SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smStato', 'smCreatedAt', 'smUpdatedAt', 'smDeletedAt'];
|
||||
// Tab: SIMEvents = ['esmIDsimEvent', 'esmIDsim', 'esmIDlavoratore', 'esmDescrizione', 'esmData', 'esmTipologia'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt'];
|
||||
$model = new SIMEvents_Model();
|
||||
$model->join('SIMs', 'SIMEvents.esmIDsim = SIMs.smIDsim');
|
||||
$model->join('Lavoratori', 'SIMEvents.esmIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$evnt = $model->where('esmIDsimEvent', $IDevent)
|
||||
->first();
|
||||
// Verifico che esista il record:
|
||||
if (null==$evnt) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMEvents/delete -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!(CheckLevel(3) || session()->get('lavoratore')->lvIDlavoratore==$evnt->esmIDlavoratore)) {
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per cancellare un evento inserito da altri lavoratori.');
|
||||
return redirect()->to('/SIMEvents/show');
|
||||
}
|
||||
|
||||
// Elimino il record:
|
||||
if ($model->delete($IDevent)) {
|
||||
// Evento cancellato, aggiorno stato della macchina relativa
|
||||
if ($this->updateSimStato($evnt->esmIDsim)) {
|
||||
// update dello stato nella macchina riuscito
|
||||
session()->setFlashdata('success', 'Recors cancellato correttamente.');
|
||||
} else {
|
||||
// update dello stato nella macchina fallito
|
||||
session()->setFlashdata('danger', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
} else {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
|
||||
// Show profile
|
||||
return redirect()->to('/SIMEvents/show');
|
||||
} // function delete($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function export_csv(){
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/export_csv -> Error code 001'); }
|
||||
return redirect()->to('/SIMEvents/show');
|
||||
}
|
||||
|
||||
// Ricavo gli eventi della sim:
|
||||
// Tab: SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smStato', 'smCreatedAt', 'smUpdatedAt', 'smDeletedAt'];
|
||||
// Tab: SIMEvents = ['esmIDsimEvent', 'esmIDsim', 'esmIDlavoratore', 'esmDescrizione', 'esmData', 'esmTipologia'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt'];
|
||||
$mev = new SIMEvents_Model();
|
||||
$mev->join('Lavoratori', 'SIMEvents.esmIDlavoratore = Lavoratori.lvIDlavoratore');
|
||||
$mev->join('SIMs', 'SIMEvents.esmIDsim = SIMs.smIDsim');
|
||||
|
||||
// Per ora niente filtro, poi in futuro forse
|
||||
$mev->where('esmIDsim', session()->get('filter_sim'));
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('evnsim',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$mev->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query:
|
||||
$data['dataset'] = $mev->asArray()
|
||||
->findAll();
|
||||
|
||||
// Imposto il nome del file da downloadare:
|
||||
$filepath = $_SERVER['MRK_FILE_PATH'];
|
||||
$filename = 'CSiCoDB_Eventi_CSiCoSIMs_il_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
// file creation
|
||||
$file = fopen($filepath . $filename,"w");
|
||||
// Esport header
|
||||
fputcsv($file,['SIM aziendale selezionata:']);
|
||||
|
||||
fputcsv($file,['ID sim', 'Numero', 'PIN', 'PUK', 'Descrizione', 'Credito Residuo', 'Stato', 'Created At', 'Updated At']);
|
||||
$head = [];
|
||||
$head['smIDsim'] = $data['dataset'][0]['smIDsim'];
|
||||
$head['smNumero'] = $data['dataset'][0]['smNumero'];
|
||||
$head['smPIN'] = $data['dataset'][0]['smPIN'];
|
||||
$head['smPUK'] = $data['dataset'][0]['smPUK'];
|
||||
$head['smDescrizione'] = $data['dataset'][0]['smDescrizione'];
|
||||
$head['smCredito'] = $data['dataset'][0]['smCredito'];
|
||||
$head['smStato'] = $data['dataset'][0]['smStato'];
|
||||
$head['smCreatedAt'] = $data['dataset'][0]['smCreatedAt'];
|
||||
$head['smUpdatedAt'] = $data['dataset'][0]['smUpdatedAt'];
|
||||
fputcsv($file,$head);
|
||||
fputcsv($file,[' ']);
|
||||
fputcsv($file,[' ']);
|
||||
fputcsv($file,[' ']);
|
||||
fputcsv($file,['Eventi della SIM aziendale:']);
|
||||
fputcsv($file,['ID evento', 'ID Lavoratore', 'Nickname', 'Descrizione Evento', 'Data', 'Tipologia']);
|
||||
foreach ($data['dataset'] as $line){
|
||||
//fputcsv($file,$line);
|
||||
// Seleziono le colonne da esportare:
|
||||
$record = [];
|
||||
$record['esmIDsimEvent'] = $line['esmIDsimEvent'];
|
||||
$record['esmIDlavoratore'] = $line['esmIDlavoratore'];
|
||||
$record['lvNickname'] = $line['lvNickname'];
|
||||
$record['esmDescrizione'] = $line['esmDescrizione'];
|
||||
$record['esmData'] = $line['esmData'];
|
||||
$record['esmTipologia'] = $line['esmTipologia'];
|
||||
fputcsv($file,$record);
|
||||
}
|
||||
// Chiudo il file
|
||||
fclose($file);
|
||||
// download
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Disposition: attachment; filename=".$filename);
|
||||
header("Content-Type: application/csv; ");
|
||||
readfile($filepath . $filename);
|
||||
// deleting file
|
||||
unlink($filepath . $filename);
|
||||
exit();
|
||||
} // function export_csv
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Eseguo l'aggiornamento dello stato della macchina indicata, in base alla cronologia degli eventi
|
||||
*/
|
||||
private function updateSimStato($IDsim){
|
||||
try {
|
||||
// verifico la tipologia dell'ultimo evento inserito:
|
||||
// Tab: SIMEvents = ['esmIDsimEvent', 'esmIDsim', 'esmIDlavoratore', 'esmDescrizione', 'esmStato', 'esmData', 'ecaKm', 'esmTipologia'];
|
||||
// Tab: SIMs = ['smIDsim', 'smNumero', 'smDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'smStato', 'caDeletedAt'];
|
||||
$mev = new SIMEvents_Model();
|
||||
$evnt = $mev->where('esmIDsim', $IDsim)
|
||||
->orderBy('esmData', 'DESC')->orderBy('esmIDsimEvent', 'DESC')->first();
|
||||
|
||||
// Preparo i dati per aggiornare la carta:
|
||||
$updCar['smIDsim'] = $IDsim;
|
||||
// determino lo stato attuale della carta dalla tipologia dell'evento:
|
||||
switch ($evnt->esmTipologia) {
|
||||
case 'Dismessa':
|
||||
$updCar['smStato'] = 'Dismessa';
|
||||
break;
|
||||
case 'Presa':
|
||||
$updCar['smStato'] = 'Occupata';
|
||||
break;
|
||||
case 'Restituita':
|
||||
default:
|
||||
$updCar['smStato'] = 'Disponibile';
|
||||
break;
|
||||
}
|
||||
|
||||
// Aggiorno la carta:
|
||||
$model_car = new SIMs_Model();
|
||||
if ($model_car->save($updCar)) {
|
||||
// carta aggiornata con successo
|
||||
return true;
|
||||
} else {
|
||||
// aggiornamento fallito
|
||||
return false;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
//throw $th;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\SIMs_Model;
|
||||
use App\Models\SIMEvents_Model;
|
||||
|
||||
|
||||
class Sims extends CRUDController {
|
||||
|
||||
// Tab: SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smStato', 'smCreatedAt', 'smUpdatedAt', 'smDeletedAt'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'SIMs',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add SIM',
|
||||
'form_title_update' => 'Edit SIM',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella SIMs',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => 'smUpdatedAt',
|
||||
'DeletedAt' => 'smDeletedAt',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['smIDsim'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['smNumero'] = ['label' => 'Numero', 'helper' => 'Numero telefonico (max 16 caratteri)', 'required' => true];
|
||||
$fields['smPIN'] = ['label' => 'PIN', 'helper' => 'PIN della SIM (max 16 caratteri)', 'required' => true];
|
||||
$fields['smPUK'] = ['label' => 'PUK', 'helper' => 'PUK della SIM (max 16 caratteri)', 'required' => true];
|
||||
$fields['smDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva della SIM', 'required' => true];
|
||||
$fields['smCredito'] = ['label' => 'Credito', 'helper' => 'Credito stimato sulla SIM', 'required' => true];
|
||||
$fields['smStato'] = ['label' => 'Stato', 'helper' => 'Stato di disponmibilità della SIM', 'required' => true];
|
||||
$fields['smCreatedAt'] = ['label' => 'Created At', 'helper' => 'Data di creazione del record relativo nel database', 'only_edit'=> true];
|
||||
$fields['smUpdatedAt'] = ['label' => 'Updated At', 'helper' => 'Timestamp dell\'ultimo aggiornamento del record nel database', 'type' => 'unset'];
|
||||
$fields['smDeletedAt'] = ['label' => 'Deleted At', 'helper' => 'Data di cancellazione del record relativo nel database', 'type' => 'unset'];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smStato', 'smCreatedAt', 'smUpdatedAt', 'smDeletedAt']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function select($IDsim = null) {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'sims';
|
||||
$model = new SIMs_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/select -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// memorizzo la selezione
|
||||
session()->set('filter_sim', $IDsim);
|
||||
|
||||
// visualizzo gli eventi della carta selezionata:
|
||||
return redirect()->to('/SIMEvents/show');
|
||||
}//function select
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function add() {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/add -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Solo amministratori possono inserire una nuova sim:
|
||||
if (!$enable){
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per inserire una nuova SIM aziendale.');
|
||||
return redirect()->to('/dashboard/sims');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'sims';
|
||||
$data['add'] = true;
|
||||
$data['title'] = 'Dettagli nuova SIM';
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
//
|
||||
$rules = [
|
||||
'Numero' => 'trim|required|min_length[8]|max_length[20]',
|
||||
'PIN' => 'trim|required|min_length[4]|max_length[16]',
|
||||
'PUK' => 'trim|required|min_length[4]|max_length[16]',
|
||||
'Credito' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
//'Stato' => 'trim|required',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
// SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smCreatedAt', 'smUpdatedAt', 'smStato', 'smDeletedAt'];
|
||||
$newData = [
|
||||
'smNumero' => $this->request->getVar('Numero'),
|
||||
'smPIN' => $this->request->getVar('PIN'),
|
||||
'smPUK' => $this->request->getVar('PUK'),
|
||||
'smCredito' => $this->request->getVar('Credito'),
|
||||
'smDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'smStato' => 'Disponibile',
|
||||
];
|
||||
|
||||
$model = new Sims_Model();
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Record inserito con successo sul DB');
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/dashboard/sims');
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/sims_form_add_edit', $data);
|
||||
}//function add
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function edit($IDsim = null) {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDsim==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/edit -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/add -> Error code 002'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Solo amministratori possono editare una carta:
|
||||
if (!$enable){
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per editare i dati di una carta di credito aziendale.');
|
||||
return redirect()->to('/dashboard/sims');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'sims';
|
||||
$data['add'] = false;
|
||||
$data['title'] = 'Dettagli della SIM telefonica';
|
||||
|
||||
// Ricavo il profilo dell'orario da editare
|
||||
// SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smCreatedAt', 'smUpdatedAt', 'smStato', 'smDeletedAt'];
|
||||
$model = new Sims_Model();
|
||||
$data['sim'] = $model->where('smIDsim', $IDsim)
|
||||
->first();
|
||||
|
||||
// Verifico che esista il record dell'orario:
|
||||
if (null==$data['sim']) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/edit -> Error code 003'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Numero' => 'trim|required|min_length[8]|max_length[20]',
|
||||
'PIN' => 'trim|required|min_length[4]|max_length[16]',
|
||||
'PUK' => 'trim|required|min_length[4]|max_length[16]',
|
||||
'Credito' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
'Stato' => 'trim|required',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'aggiornamento
|
||||
// Tab: sims = ['smIDsim', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', 'ccStato', 'ccDeletedAt'];
|
||||
$newData = [
|
||||
'smIDsim' => $this->request->getVar('IDsim'),
|
||||
'smNumero' => $this->request->getVar('Numero'),
|
||||
'smPIN' => $this->request->getVar('PIN'),
|
||||
'smPUK' => $this->request->getVar('PUK'),
|
||||
'smCredito' => $this->request->getVar('Credito'),
|
||||
'smDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'smStato' => $this->request->getVar('Stato'),
|
||||
];
|
||||
|
||||
$model = new Sims_Model();
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Successfuly Updated');
|
||||
return redirect()->to('/dashboard/sims');
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'update del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/sims_form_add_edit', $data);
|
||||
}//function edit
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function delete($IDsim = null){
|
||||
helper(['tools']);
|
||||
$data = [];
|
||||
$model = new Sims_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(3)) {
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per cancellare una SIM aziendale.');
|
||||
return redirect()->to('/dashboard/sims');
|
||||
}
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDsim==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/delete -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Elimino il record:
|
||||
if ($model->delete($IDsim)) {
|
||||
session()->setFlashdata('success', 'Recors cancellato correttamente.');
|
||||
|
||||
} else {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
|
||||
// Show profile
|
||||
return redirect()->to('/dashboard/sims');
|
||||
} // function delete($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function export_csv(){
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/export_csv -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Ricavo le ore dell'utente:
|
||||
// SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smCreatedAt', 'smUpdatedAt', 'smStato', 'smDeletedAt'];
|
||||
$model = new Sims_Model();
|
||||
|
||||
// Costruisco la query per selezionare le ore da esportare:
|
||||
// - applico eventuale filtro per lo stato:
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('sims',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query:
|
||||
$data['dataset'] = $model->asArray()
|
||||
->findAll();
|
||||
|
||||
// Imposto il nome del file da downloadare:
|
||||
$filepath = $_SERVER['MRK_FILE_PATH'];
|
||||
$filename = 'CSiCoDB_SIMs_il_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
// file creation
|
||||
$file = fopen($filepath . $filename,"w");
|
||||
// Esport header
|
||||
fputcsv($file,['ID SIM', 'Numero', 'PIN', 'PUK', 'Descrizione', 'Credito', 'CreatedAt', 'UpdatedAt', 'Stato']);
|
||||
|
||||
foreach ($data['dataset'] as $line){
|
||||
fputcsv($file,$line);
|
||||
}
|
||||
// Chiudo il file
|
||||
fclose($file);
|
||||
// download
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Disposition: attachment; filename=".$filename);
|
||||
header("Content-Type: application/csv; ");
|
||||
readfile($filepath . $filename);
|
||||
// deleting file
|
||||
unlink($filepath . $filename);
|
||||
exit();
|
||||
} // function export_csv
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}//class Sims
|
||||
@@ -0,0 +1,428 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\Lavoratori_Model;
|
||||
use App\Models\Commesse_Model;
|
||||
use App\Models\TipoOre_Model;
|
||||
use App\Models\Orari_Model;
|
||||
use App\Models\Spese_Model;
|
||||
|
||||
|
||||
class Spese extends CRUDController {
|
||||
|
||||
// Tab: Spese = ['spIDspesa', 'spIDcommessa', 'spIDlavoratore', 'spImporto', 'spDaRimborsare', 'spDescrizione', 'spData'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'Spese',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add Spesa',
|
||||
'form_title_update' => 'Edit Spesa',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella Spese',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => '',
|
||||
'DeletedAt' => '',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['spIDspesa'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['spIDcommessa'] = [
|
||||
'label' => 'Commessa',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Commessa a cui si riferisce la spesa',
|
||||
'relation' => [
|
||||
'table'=> 'Commesse',
|
||||
'primary_key' => 'coIDcommessa',
|
||||
'display' => ['coNome'],
|
||||
'order_by' => 'coUpdatedAt',
|
||||
'order' => 'DESC'
|
||||
]
|
||||
];
|
||||
$fields['spIDlavoratore'] = [
|
||||
'label' => 'Lavoratore',
|
||||
'required' => true,
|
||||
'type' => 'dropdown',
|
||||
'helper' => 'Lavoratore a cui si riferisce la spesa',
|
||||
'relation' => [
|
||||
'table'=> 'Lavoratori',
|
||||
'primary_key' => 'lvIDlavoratore',
|
||||
'display' => ['lvNickname', 'lvNome', 'lvCognome'], //'display' => ['lvNickname'],
|
||||
'order_by' => 'lvNickname',
|
||||
'order' => 'ASC'
|
||||
]
|
||||
];
|
||||
$fields['spImporto'] = ['label' => 'Importo', 'helper' => 'Importo della spesa. Se non in € specificare nella descrizione il cambio attuale relativo', 'required' => true];
|
||||
$fields['spDaRimborsare'] = ['label' => 'Rimborsare', 'helper' => 'Indiva se la spesa è da rimborsare al lavoratore', 'required' => true];
|
||||
$fields['spDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva della spesa effettuata.','required' => true];
|
||||
$fields['spData'] = ['label' => 'Data', 'helper' => 'Data in cui si è avvenuta la spesa','required' => true];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['spIDspesa', 'spIDcommessa', 'spIDlavoratore', 'spImporto', 'spDaRimborsare', 'spDescrizione', 'spData']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function add(){
|
||||
helper(['form','tools']);
|
||||
$data['Data'] = date('Y-m-d');
|
||||
$model = new Spese_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Spese/add -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$enable = CheckLevel(3, false);
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
// Tab: Spese = ['spIDspesa', 'spIDcommessa', 'spIDlavoratore', 'spImporto', 'spDaRimborsare', 'spDescrizione', 'spData'];
|
||||
$rules = [
|
||||
'IDcommessa' => 'trim|required',
|
||||
'Data' => 'trim|required',
|
||||
'Importo' => 'trim|required',
|
||||
'DaRimborsare' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
];
|
||||
if ($enable){
|
||||
//$rules['Level'] = 'trim|required|min_length[8]|max_length[255]';
|
||||
$rules['IDlavoratore'] = 'trim|required';
|
||||
}
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
$newData = [
|
||||
'spIDcommessa' => $this->request->getVar('IDcommessa'),
|
||||
'spData' => $this->request->getVar('Data'),
|
||||
'spImporto' => $this->request->getVar('Importo'),
|
||||
'spDaRimborsare' => $this->request->getVar('DaRimborsare'),
|
||||
'spDescrizione' => $this->request->getVar('Descrizione'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['spIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
} else {
|
||||
$newData['spIDlavoratore'] = session()->get('lavoratore')->lvIDlavoratore;
|
||||
}
|
||||
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Record inserito con successo sul DB');
|
||||
UpdateCommessa($newData['spIDcommessa']);
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/spese');
|
||||
} else {
|
||||
return redirect()->to('/dashboard/spese');
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Rileggo i dati dal DB
|
||||
$data['enable'] = $enable;
|
||||
|
||||
// Ricavo i dati per il select delle commesse:
|
||||
$modelCommesse = new Commesse_Model();
|
||||
$data['select_commesse'] = $modelCommesse->get_select();
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
|
||||
// Show profile
|
||||
echo view('pages/spese/spese_form_add', $data);
|
||||
|
||||
} // function add($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function edit($IDspesa = null){
|
||||
helper(['form','tools']);
|
||||
$data = [];
|
||||
$model = new Spese_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Spese/edit -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$enable = CheckLevel(3, false);
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDspesa==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Spese/edit -> Error code 002'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo il profilo della spesa da editare
|
||||
$spesa = $model->where('spIDspesa', $IDspesa)
|
||||
->first();
|
||||
|
||||
// Verifico che esista il record della spesa:
|
||||
if (null==$spesa) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Spese/edit -> Error code 003'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico se posso editare il campo:
|
||||
// - utente amministratore o superiore, può editare tutti i campi
|
||||
// - utente normale può editare solo i propi spese
|
||||
$lav = session()->get('lavoratore');
|
||||
if ((!$enable) && ($lav->IDlavoratore<>$spesa->IDlavoratore)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Spese/edit -> Error code 004'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
//
|
||||
$rules = [
|
||||
'IDspesa' => 'trim|required',
|
||||
'IDcommessa' => 'trim|required',
|
||||
'Data' => 'trim|required',
|
||||
'Importo' => 'trim|required',
|
||||
'DaRimborsare' => 'trim|required',
|
||||
'Descrizione' => 'trim|required',
|
||||
];
|
||||
if ($enable){
|
||||
//$rules['Level'] = 'trim|required|min_length[8]|max_length[255]';
|
||||
$rules['IDlavoratore'] = 'trim|required';
|
||||
}
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'aggiornamento
|
||||
$newData = [
|
||||
'spIDspesa' => $spesa->spIDspesa,
|
||||
'spIDcommessa' => $this->request->getVar('IDcommessa'),
|
||||
'spData' => $this->request->getVar('Data'),
|
||||
'spImporto' => $this->request->getVar('Importo'),
|
||||
'spDaRimborsare' => $this->request->getVar('DaRimborsare'),
|
||||
'spDescrizione' => $this->request->getVar('Descrizione'),
|
||||
];
|
||||
if ($enable){
|
||||
$newData['spIDlavoratore'] = $this->request->getVar('IDlavoratore');
|
||||
} else {
|
||||
$newData['spIDlavoratore'] = session()->get('lavoratore')->lvIDlavoratore;
|
||||
}
|
||||
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'successfuly Updated');
|
||||
UpdateCommessa($newData['spIDcommessa']);
|
||||
return redirect()->to('/dashboard/spese');
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'update del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Rileggo i dati dal DB
|
||||
$data['spesa'] = $spesa;
|
||||
$data['enable'] = $enable;
|
||||
|
||||
// Ricavo i dati per il select delle commesse:
|
||||
$modelCommesse = new Commesse_Model();
|
||||
$data['select_commesse'] = $modelCommesse->get_select();
|
||||
|
||||
// Ricavo i dati per il select dei lavoratori:
|
||||
$modelLavoratori = new Lavoratori_Model();
|
||||
$data['select_lavoratori'] = $modelLavoratori->get_select();
|
||||
|
||||
// Show profile
|
||||
echo view('pages/spese/spese_form_edit', $data);
|
||||
} // function edit($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function delete($IDSpesa = null){
|
||||
helper(['tools']);
|
||||
$data = [];
|
||||
$model = new Spese_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Spese/delete -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$enable = CheckLevel(3, false);
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDSpesa==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Spese/delete -> Error code 002'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo il record della spesa da editare
|
||||
$Spesa = $model->where('spIDSpesa', $IDSpesa)
|
||||
->first();
|
||||
|
||||
// Verifico che esista il record della spesa:
|
||||
//if (null==$Spesa) { return redirect()->to('/dashboard'); }
|
||||
if (!isset($Spesa)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Spese/delete -> Error code 003'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico se posso editare il record:
|
||||
// - utente amministratore o superiore, cancellare qualunque Spesa
|
||||
// - utente normale può cancellare solo i propi spese
|
||||
$lav = session()->get('lavoratore');
|
||||
if ((!$enable) && ($lav->IDlavoratore<>$Spesa->IDlavoratore)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Spese/delete -> Error code 004'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Elimino il record:
|
||||
if ($model->delete($IDSpesa)) {
|
||||
session()->setFlashdata('success', 'Recors cancellato correttamente.');
|
||||
|
||||
} else {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
|
||||
// Show profile
|
||||
return redirect()->to('/dashboard/spese');
|
||||
} // function delete($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function export_csv(){
|
||||
helper(['tools']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Spese/export_csv -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Ricavo le ore dell'utente:
|
||||
// Tab: Spese = ['spIDspesa', 'spIDcommessa', 'spIDlavoratore', 'spImporto', 'spDaRimborsare', 'spDescrizione', 'spData'];
|
||||
// Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt'];
|
||||
// Tab: Commesse = ['coIDcommessa', 'coNome', 'coIDcliente', 'coDescrizione', 'coIDstatoCommessa', 'coModificatoIl', 'coCreatedAt', 'coUpdatedAt', 'coDeletedAt'];
|
||||
$model = new Spese_Model();
|
||||
$model->join('Lavoratori', 'Lavoratori.lvIDlavoratore = Spese.spIDlavoratore');
|
||||
$model->join('Commesse', 'Commesse.coIDcommessa = Spese.spIDcommessa');
|
||||
|
||||
// Costruisco la query per selezionare le ore, in base al filtro attivo:
|
||||
// - applico il filtro sull'intervallo temporale:
|
||||
$model->where('spData >', session()->get('filter_dal'))
|
||||
->where('spData <', session()->get('filter_al') . " 23:59:59");
|
||||
// - applico eventuale filtro per lavoratore
|
||||
if (session()->filter_lavoratore!='-1') { $model->where('spIDlavoratore', session()->get('filter_lavoratore')); }
|
||||
// - applico eventuale filtro per commessa
|
||||
if (session()->filter_commessa!='-1') { $model->where('spIDcommessa', session()->get('filter_commessa')); }
|
||||
// - applico eventuale filtro per tipologia di ora:
|
||||
if (session()->filter_rimborso!='-1') { $model->where('spDaRimborsare', session()->get('filter_rimborso')); }
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('spese',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query:
|
||||
$data['dataset'] = $model->asArray()
|
||||
->findAll();
|
||||
|
||||
// Imposto il nome del file da downloadare:
|
||||
$filepath = $_SERVER['MRK_FILE_PATH'];
|
||||
$filename = 'CSiCoDB_Spese_il_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
// file creation
|
||||
$file = fopen($filepath . $filename,"w");
|
||||
// Esport header
|
||||
fputcsv($file,['ID-Spesa','ID-Commessa','Commessa','ID-Lavoratore','Lavoratore','Importo','Data','Rimborso','Descrizione']);
|
||||
foreach ($data['dataset'] as $line){
|
||||
//fputcsv($file,$line);
|
||||
$record = [];
|
||||
$record['spIDspesa'] = $line['spIDspesa'];
|
||||
$record['spIDcommessa'] = $line['spIDcommessa'];
|
||||
$record['coNome'] = $line['coNome'];
|
||||
$record['spIDlavoratore'] = $line['spIDlavoratore'];
|
||||
$record['lvNickname'] = $line['lvNickname'];
|
||||
$record['spImporto'] = number_format( $line['spImporto'], 4);
|
||||
$record['spData'] = $line['spData'];
|
||||
$record['spDaRimborsare'] = ($line['spDaRimborsare'] ? 'Da Rimborsare' : 'No Rimborso');
|
||||
$record['spDescrizione'] = $line['spDescrizione'];
|
||||
fputcsv($file,$record);
|
||||
}
|
||||
// Chiudo il file
|
||||
fclose($file);
|
||||
// download
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Disposition: attachment; filename=".$filename);
|
||||
header("Content-Type: application/csv; ");
|
||||
readfile($filepath . $filename);
|
||||
// deleting file
|
||||
unlink($filepath . $filename);
|
||||
exit();
|
||||
|
||||
} // function export_csv
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
|
||||
|
||||
class StatiCommessa extends CRUDController {
|
||||
|
||||
// Tab: StatiCommessa = ['stIDstatoCommessa', 'stDescrizione'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'StatiCommessa',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Nuovo Stato Commessa',
|
||||
'form_title_update' => 'Edit Stato Commessa',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella StatiCommessa',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => '',
|
||||
'DeletedAt' => '',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['stIDstatoCommessa'] = ['label' => 'ID Stato', 'helper' => 'Identificativo univoco dello stato commessa (max 16 carateri)', 'required' => true, 'unique' => [true, 'stIDstatoCommessa']];
|
||||
$fields['stDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva dello stato', 'required' => true];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['stIDstatoCommessa', 'stDescrizione']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,320 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\Stime_Model;
|
||||
use App\Models\TipiWork_Model;
|
||||
use App\Models\Commesse_Model;
|
||||
|
||||
|
||||
class Stime extends CRUDController {
|
||||
|
||||
// Tab: Stime = ['stIDcommessa', 'stIDTipoWork', 'stStima', 'stNota'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'Stime',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Nuova stima',
|
||||
'form_title_update' => 'Edit stima',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella Stime',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => '',
|
||||
'DeletedAt' => '',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['stIDcommessa'] = ['label' => 'ID Commessa', 'helper' => 'Identificativo univoco della commessa a cui si riferisce la stima', 'required' => true];
|
||||
$fields['stIDTipoWork'] = ['label' => 'ID Tipo Work', 'helper' => 'Identificativo univoco della tipologia di lavoro a cui si riferisce la stima', 'required' => true];
|
||||
$fields['stStima'] = ['label' => 'Stima', 'helper' => 'Stima oraria', 'required' => true];
|
||||
$fields['stNota'] = ['label' => 'Nota', 'helper' => 'Eventuale nota associata alla stima', 'required' => true];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
// public function index() {
|
||||
// return $this->CRUD_view(['stIDcommessa', 'stIDTipoWork', 'stStima', 'stNota']);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function index() {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'admin';
|
||||
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) { return redirect()->to('/dashboard'); }
|
||||
|
||||
|
||||
// Ricavo le stime in base al filtro:
|
||||
// Tab: Stime = ['stIDcommessa', 'stIDTipoWork', 'stStima', 'stNota'];
|
||||
// Tab: TipiWork = ['twIDTipoWork', 'twDescrizione', 'twOrdinamento'];
|
||||
// Tab: Commesse = ['coIDcommessa', 'coNome', 'coIDcliente', 'coDescrizione', 'coIDstatoCommessa', 'coCreatedAt', 'coUpdatedAt', 'coDeletedAt'];
|
||||
$model = new Stime_Model();
|
||||
$model->join('TipiWork', 'stIDTipoWork = twIDTipoWork');
|
||||
$model->join('Commesse', 'stIDcommessa = coIDcommessa');
|
||||
|
||||
// Costruisco la query per selezionare le ore da mostrare:
|
||||
if (session()->filter_commessa!='-1') { $model->where('stIDcommessa', session()->get('filter_commessa')); }
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
$model->orderBy('twOrdinamento', 'ASC');
|
||||
|
||||
// eseguo la query con paginazione:
|
||||
$data['dataset'] = $model->paginate(session()->get('pager_num'));
|
||||
$data['pager'] = $model->pager;
|
||||
|
||||
// Ricavo i dati per il select delle commesse:
|
||||
$modelCommesse = new Commesse_Model();
|
||||
$data['select_commesse'] = $modelCommesse->get_select();
|
||||
|
||||
//return view('test', $data);
|
||||
return view('pages/stime', $data);
|
||||
|
||||
}//function index
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function add(){
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'admin';
|
||||
$data['add'] = true;
|
||||
$data['title'] = 'Dettagli nuova stima';
|
||||
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Stime/add -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Gestione POST
|
||||
// Tab: Stime = ['stIDcommessa', 'stIDTipoWork', 'stStima', 'stNota'];
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
//
|
||||
$rules = [
|
||||
'IDcommessa' => 'trim|required',
|
||||
'IDTipoWork' => 'trim|required',
|
||||
'Stima' => 'trim|required',
|
||||
'Nota' => 'trim|required',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
$newData = [
|
||||
'stIDcommessa' => $this->request->getVar('IDcommessa'),
|
||||
'stIDTipoWork' => $this->request->getVar('IDTipoWork'),
|
||||
'stStima' => $this->request->getVar('Stima'),
|
||||
'stNota' => $this->request->getVar('Nota'),
|
||||
];
|
||||
|
||||
$model = new Stime_Model();
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Record inserito con successo sul DB');
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/Stime');
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Ricavo i dati per il select delle commesse:
|
||||
$modelCommesse = new Commesse_Model();
|
||||
$data['select_commesse'] = $modelCommesse->get_select();
|
||||
|
||||
// Ricavo i dati per il select delle tipologie:
|
||||
$modelTipi = new TipiWork_Model();
|
||||
$data['select_tipologie'] = $modelTipi->get_select();
|
||||
|
||||
// Show profile
|
||||
echo view('pages/form/stime_form_add_edit', $data);
|
||||
} // function add()
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function edit($IDcm, $IDtw){
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'admin';
|
||||
$data['add'] = false;
|
||||
$data['title'] = 'Dettagli stima';
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Stime/add -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Ricavo il profilo della stima da editare
|
||||
// Tab: Stime = ['stIDcommessa', 'stIDTipoWork', 'stStima', 'stNota'];
|
||||
$model = new Stime_Model();
|
||||
$data['stima'] = $model->where('stIDcommessa', $IDcm)->where('stIDTipoWork', $IDtw)->first();
|
||||
|
||||
// Gestione POST
|
||||
// Tab: Stime = ['stIDcommessa', 'stIDTipoWork', 'stStima', 'stNota'];
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
//
|
||||
$rules = [
|
||||
'IDcommessa' => 'trim|required',
|
||||
'IDTipoWork' => 'trim|required',
|
||||
'Stima' => 'trim|required',
|
||||
'Nota' => 'trim|required',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
$newData = [
|
||||
'stIDcommessa' => $this->request->getVar('IDcommessa'),
|
||||
'stIDTipoWork' => $this->request->getVar('IDTipoWork'),
|
||||
'stStima' => $this->request->getVar('Stima'),
|
||||
'stNota' => $this->request->getVar('Nota'),
|
||||
];
|
||||
|
||||
// Cancello i record che devo andare a sostituire o aggiornare:
|
||||
$model->where('stIDcommessa',$IDcm)->where('stIDTipoWork',$IDtw)->delete(); // Record di partenza
|
||||
$model->where('stIDcommessa',$newData['stIDcommessa'])->where('stIDTipoWork',$newData['stIDTipoWork'])->delete(); // Nuovo record
|
||||
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Record editato con successo sul DB');
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/Stime');
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Ricavo i dati per il select delle commesse:
|
||||
$modelCommesse = new Commesse_Model();
|
||||
$data['select_commesse'] = $modelCommesse->get_select();
|
||||
|
||||
// Ricavo i dati per il select delle tipologie:
|
||||
$modelTipi = new TipiWork_Model();
|
||||
$data['select_tipologie'] = $modelTipi->get_select();
|
||||
|
||||
|
||||
// Show profile
|
||||
echo view('pages/form/stime_form_add_edit', $data);
|
||||
} // function edit($id)
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function Delete($IDcm = null, $IDtw = null){
|
||||
helper(['tools','form']);
|
||||
$data = [];
|
||||
// Tab: Stime = ['stIDcommessa', 'stIDTipoWork', 'stStima', 'stNota'];
|
||||
$model = new Stime_Model();
|
||||
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(3)) {
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per cancellare una stima.');
|
||||
return redirect()->to('/Stime');
|
||||
}
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if (($IDcm==null) OR ($IDtw==null)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/Stime/delete -> Error code 001'); }
|
||||
return redirect()->to('/Stime');
|
||||
}
|
||||
|
||||
// Elimino il record:
|
||||
if ($model->where('stIDcommessa',$IDcm)->where('stIDTipoWork',$IDtw)->delete()) {
|
||||
session()->setFlashdata('success', 'Records cancellato correttamente.');
|
||||
|
||||
} else {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
|
||||
// Show profile
|
||||
return redirect()->to('/Stime');
|
||||
|
||||
} // function edit($id)
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
|
||||
|
||||
class Test extends BaseController {
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// Test CRUD automatico:
|
||||
public function layout($lay='main') {
|
||||
$data = [];
|
||||
helper(['tools','form']);
|
||||
|
||||
$data = [];
|
||||
|
||||
if($lay=='main'){
|
||||
$data['title'] = 'Test main';
|
||||
echo view('pages/test_main', $data);
|
||||
} else {
|
||||
$data['title'] = 'Test form';
|
||||
echo view('pages/test_form', $data);
|
||||
}
|
||||
//echo view('test', $data);
|
||||
}//function t1()
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function index() {
|
||||
$data = [];
|
||||
helper(['tools']);
|
||||
|
||||
|
||||
return view('test', $data);
|
||||
}//function index()
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function timestamp() {
|
||||
$data = [];
|
||||
helper(['tools','form']);
|
||||
|
||||
$data['dt1'] = date("Y-m-d H:i:s");
|
||||
$data['tz1'] = date_default_timezone_get();
|
||||
|
||||
date_default_timezone_set('Europe/Rome');
|
||||
|
||||
$data['dt2'] = date("Y-m-d H:i:s");
|
||||
$data['tz2'] = date_default_timezone_get();
|
||||
|
||||
|
||||
return view('Test', $data);
|
||||
}//function timestamp()
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function env() {
|
||||
$data = [];
|
||||
helper(['tools']);
|
||||
|
||||
$data['pippo'] = $_SERVER['CI_ENVIRONMENT'];
|
||||
$data['test'] = $_SERVER['MRK_FILE_PATH'];
|
||||
$data['test2'] = $_SERVER['MRK_FILE_PATH2'];
|
||||
|
||||
return view('test', $data);
|
||||
}//function index()
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}//class Test
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
|
||||
|
||||
class TipiWork extends CRUDController {
|
||||
|
||||
// Tab: TipiWork = ['twIDTipoWork', 'twDescrizione', 'twOrdinamento'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'TipiWork',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Nuova tipologia lavoro',
|
||||
'form_title_update' => 'Edit tipologia',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella TipiWork',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => '',
|
||||
'DeletedAt' => '',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['twIDTipoWork'] = ['label' => 'ID Tipologia', 'helper' => 'Identificativo univoco della tipologia di lavoro (5 caratteri)', 'required' => true, 'unique' => [true, 'twIDTipoWork']];
|
||||
$fields['twDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione della tipologia di lavoro', 'required' => true];
|
||||
$fields['twOrdinamento'] = ['label' => 'Ordinamento', 'helper' => 'Ordinamento per la visualizzazione (numero intero)', 'required' => true];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() {
|
||||
return $this->CRUD_view(['twIDTipoWork', 'twDescrizione', 'twOrdinamento']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
|
||||
|
||||
class TipoOre extends CRUDController {
|
||||
|
||||
// Tab: TipoOre = ['toIDTipoOre', 'toDescrizione', 'toOrdinamento'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'TipoOre',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Nuova tipologia orario',
|
||||
'form_title_update' => 'Edit tipologia',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella TipoOre',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => '',
|
||||
'DeletedAt' => '',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['toIDTipoOre'] = ['label' => 'ID Tipologia', 'helper' => 'Identificativo univoco della tipologia di orario (2 caratteri)', 'required' => true, 'unique' => [true, 'toIDTipoOre']];
|
||||
$fields['toDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descriziona tipologia di orario', 'required' => true];
|
||||
$fields['toOrdinamento'] = ['label' => 'Ordinamento', 'helper' => 'Ordinamento per la visualizzazione (numero intero)', 'required' => true];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['toIDTipoOre', 'toDescrizione', 'toOrdinamento']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user