541 lines
21 KiB
PHP
541 lines
21 KiB
PHP
<?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
|