546 lines
20 KiB
PHP
546 lines
20 KiB
PHP
<?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;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
|
|
|
}
|