237 lines
7.4 KiB
PHP
237 lines
7.4 KiB
PHP
<?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
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//--------------------------------------------------------------------
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|