Start Point al 2026

This commit is contained in:
mirko.aletto committed 2026-05-06 11:04:41 +02:00
commit 8a76e1db3b
371 files changed
+160283

No files matched your search

View File
Whitespace-only changes.
+307
View File
@@ -0,0 +1,307 @@
<?php
namespace App\Models;
use CodeIgniter\Database\ConnectionInterface;
class AutoCRUD_Model {
protected $db;
public function __construct(ConnectionInterface &$db) { $this->db = &$db; }
public function schema($table) {
$query = "SHOW COLUMNS FROM $table";
$result = $this->db->query($query)->getResult();
return $result;
}//function schema
/**
* Ricava il nome del campo che fa da chiave primaria della tabella
* @param string $table nome della tabella nel DB
* @return string nome del campo che fa da chiave primaria della tabella
*/
function get_primary_key_field_name($table) {
$query = "SHOW KEYS FROM $table WHERE Key_name = 'PRIMARY'";
return $this->db->query($query)->getRow()->Column_name;
}//function get_primary_key_field_name
/**
* Calcola il numero di record in base al filtro
*/
public function countTotalRows($table, $where = null, $request, $schema, $fields) {
$count_query = "SELECT COUNT(*) as total FROM " . $table;
//get primary_key field name
$pk = $this->get_primary_key_field_name($table);
// Se ho dei filtri where, li decodifico e li inserisco nella query:
if ($where) {
$count_query .= " WHERE (";
$i = 0;
foreach ($where as $key => $value) {
if ($i > 0)
$count_query .= " AND ";
//Check if operator is different from = (equal sign)
$operator_arr = explode(" ", $key);
if (isset($operator_arr[1]))
$operator = $operator_arr[1];
else
$operator = "=";
$count_query .= " `$operator_arr[0]`$operator" . $this->db->escape($value) . " ";
$i++;
}
$count_query .= ")";
}
// Se ho indicato delle stringhe di ricerca nella tabella, le inserisco nella query come LIKE
if ($table_search = $request->getPost('table_search')) {
$allEmpty = true;
$tempQuery = '';
if ($where)
$tempQuery .= " AND ";
else
$tempQuery .= " WHERE ";
$tempQuery .= " ( ";
$i = 0;
// ciclo su tutti i campi della tabella per verificare se hanno delle stringhe di ricerca
foreach ($schema as $column) {
if (trim($request->getPost($column->Field)) == '')
continue;
if ($column->Extra == 'other_table')
continue;
$allEmpty = false;
if ($i > 0)
$tempQuery .= " OR ";
$tempQuery .= " " . $table_search
. "." . $column->Field
. " LIKE '%"
. trim($this->db->escapeLikeString($request->getPost($column->Field)))
. "%' ESCAPE '!'";
$i++;
}
$tempQuery .= ")";
if (!$allEmpty)
$count_query .= $tempQuery;
}
// MRK debug: echo $count_query;
return $this->db->query($count_query)->getRow()->total;
}//function countTotalRows
/**
* Select dei record in base alla query (clausole where principali e quelle di ricerca)
*/
public function getItems($table, $where = null, $request, $schema, $fields, $order, $offset, $per_page) {
$result_query = "SELECT * FROM " . $table;
//get primary_key field name
$pk = $this->get_primary_key_field_name($table);
// Ciclo fra le opzioni passate, per unire le tabelle che sono relazionate con questa tramite JOIN:
foreach ($fields as $key => $rel_field) {
if (isset($rel_field['relation']) && !isset($rel_field['relation']['save_table'])) {
$rfield = $rel_field['relation'];
$result_query .= " LEFT JOIN " . $rfield['table'] . " ON " . $table . '.' . $key . "=" . $rfield['table'] . "." . $rfield['primary_key'] . " ";
//$this->db->join($rfield['table'], $table.'.'.$key.'='.$rfield['table'].'.'.$rfield['primary_key'], 'left');
}
}
// Se ho dei filtri where, li decodifico e li inserisco nella query:
if ($where) {
$result_query .= " WHERE (";
$i = 0;
foreach ($where as $key => $value) {
if ($i > 0)
$result_query .= " AND ";
//Check if operator is different from = (equal sign)
$operator_arr = explode(" ", $key);
if (isset($operator_arr[1]))
$operator = $operator_arr[1];
else
$operator = "=";
$count_query .= " `$operator_arr[0]`$operator" . $this->db->escape($value) . " ";
$i++;
}
$result_query .= ")";
}
// Se ho indicato delle stringhe di ricerca nella tabella, le inserisco nella query come LIKE
if ($request->getPost('table_search')) {
$allEmpty = true;
$tempQuery = '';
$i = 0;
if ($where)
$tempQuery .= " AND ";
else
$tempQuery .= " WHERE ";
$tempQuery .= " ( ";
// ciclo su tutti i campi della tabella per verificare se hanno delle stringhe di ricerca
foreach ($schema as $column) {
if ($request->getPost($column->Field) == '')
continue;
$allEmpty = false;
$col_search = [];
$col_search[] = $column->Field;
if (isset($fields[$column->Field]['relation']) && isset($fields[$column->Field]['relation']['save_table'])) {
//Search relational table to get the ids of related ids
$relField = $fields[$column->Field]['relation'];
$parent_table = $relField['table'];
$relation_table = $relField['save_table'];
$joinString = $relation_table . '.' . $relField['child_field'] . '=' . $parent_table . '.' . $relField['primary_key'];
$likeColumns = $relField['display'];
$likeTerm = $request->getPost($column->Field);
//$relselect is optional. when used it will add DISTINCT to prevent dublicates
$relSelect = $relation_table . '.' . $relField['parent_field'];
$relatedItems = $this->searchRelatedItems($parent_table, $relation_table, $joinString, $likeColumns, $likeTerm, $relSelect);
$relatedItemsIdArr = [];
if (!$relatedItems)
$relatedItemsIdArr = '-1';
else {
//Create an array of ids for whereIn statement
foreach ($relatedItems as $relatedItem) {
$relatedItemsIdArr[] = $relatedItem->{$relField['parent_field']};
}
}
if ($i > 0)
$tempQuery .= " AND ";
if (is_array($relatedItemsIdArr))
$relTempQuery = '' . $table . '.' . $pk . ' IN (' . implode(',', $relatedItemsIdArr) . ')';
else
$relTempQuery = $table . '.' . $pk . ' = ' . $relatedItemsIdArr;
// echo $tempQuery.'<br>';
$tempQuery .= $relTempQuery;
// echo $tempQuery;
$i++;
//$allEmpty = false;
continue;
} else if (isset($fields[$column->Field]['relation'])) {
$col_search = $fields[$column->Field]['relation']['display'];
//check if display is an array of columns
if (!is_array($col_search))
$col_search[] = $col_search;
$table_search = $fields[$column->Field]['relation']['table'];
} else {
$table_search = $table;
//$col_search[] = $column->Field;
}
if ($i > 0)
$tempQuery .= " AND ";
//For loop is required when search must be performed in multiple relational columns from another table
$searchLikeTempQuery = '';
$searchLikeTempQueryArr = [];
foreach ($col_search as $colToSearch) {
$searchLikeTempQueryArr[] = $this->generateLikeClause($table_search, $colToSearch, $request->getPost($column->Field));
}
if (count($col_search) > 1) {
$searchLikeTempQuery = implode(' OR ', $searchLikeTempQueryArr);
$searchLikeTempQuery = "($searchLikeTempQuery)";
} else
$searchLikeTempQuery = $searchLikeTempQueryArr[0];
$tempQuery .= $searchLikeTempQuery;
//$this->db->like($table_search.'.'.$col_search, $request->getPost($column->Field), 'both');
$i++;
}
$tempQuery .= isset($searchLikeTempQuery) ? " " : "";
if (!$allEmpty)
$result_query .= $tempQuery;
}
if ($order) {
$result_query .= " ORDER BY ";
$i = 0;
foreach ($order as $ord) {
if ($i > 0)
$result_query .= ", ";
$result_query .= $ord[0] . " " . $ord[1];
//$this->db->order_by($ord[0], $ord[1]);
$i++;
}
} else {
$result_query .= " ORDER BY " . $pk . " DESC";
//$this->db->order_by($pk, 'DESC');
}
$result_query = rtrim($result_query, ',');
$result_query .= " LIMIT $offset, $per_page ";
//$this->db->limit($per_page, $offset);
$page_items = $this->db->query($result_query)->getResult();
return $page_items;
}
/**
* Estrae il singolo record in base all'id
*/
public function getItem($table, $field, $id) {
return $this->db->table($table)
->where([$field => $id])
->get()
->getRow();
}
public function generateLikeClause($table_search, $colToSearch, $searchTerm) {
return $table_search . "." . $colToSearch
. " LIKE '%"
. trim($this->db->escapeLikeString($searchTerm))
. "%' ESCAPE '!'";
}//function generateLikeClause
}//class AutoCRUD_Model
+82
View File
@@ -0,0 +1,82 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `CSiCoCarEvents` (
`ecaIDcarEvent` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco dell''evento',
`ecaIDcar` int(11) NOT NULL COMMENT 'Identificativo univoco del veicolo',
`ecaIDlavoratore` int(11) NOT NULL COMMENT 'Identificativo univoco del lavoratore che utilizza il veicolo',
`ecaDescrizione` text NOT NULL COMMENT 'Descrizione esplicativa del motivo per cui si utilizza il veicolo',
`ecaData` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Data in cui si è utilizzato il veicolo',
`ecaKm` float NOT NULL DEFAULT '0' COMMENT 'Kilometraggio totale alla data dell''evento',
`ecaTipologia` enum('Presa','Restituita','Dismessa') NOT NULL DEFAULT 'Presa' COMMENT 'Tipologia dell''evento',
`ecaStato` varchar(255) NOT NULL DEFAULT 'Tutto OK' COMMENT 'Annotazioni sullo stato del veicolo',
PRIMARY KEY (`ecaIDcarEvent`),
UNIQUE KEY `ecaIDcarEvent` (ecaIDcarEvent),
KEY `FK_CarEvents-CSiCoCars` (`ecaIDcar`),
KEY `FK_CarEvents-Lavoratori` (`ecaIDlavoratore`)
) ENGINE=InnoDB AUTO_INCREMENT=93 DEFAULT CHARSET=utf8 COMMENT='Tabella con tutti gli eventi riferiti alle macchina.';
Fields:
Tab: CSiCoCarEvents = ['ecaIDcarEvent', 'ecaIDcar', 'ecaIDlavoratore', 'ecaDescrizione', 'ecaData', 'ecaKm', 'ecaTipologia', 'ecaStato'];
*/
use CodeIgniter\Model;
class CSiCoCarEvents_Model extends Model {
//--------------------------------------------------------------------
// Property
protected $table = 'CSiCoCarEvents';
protected $primaryKey = 'ecaIDcarEvent';
protected $returnType = 'App\Entities\CSiCoCarEvnt';
//protected $returnType = 'array';
protected $allowedFields = ['ecaIDcar', 'ecaIDlavoratore', 'ecaDescrizione', 'ecaData', 'ecaKm', 'ecaTipologia', 'ecaStato'];
protected $useSoftDeletes = false;
protected $useTimestamps = false;
//protected $createdField = 'spCreatedAt';
//protected $updatedField = 'spUpdatedAt';
//protected $deletedField = 'spDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------
}//class CSiCoCarEvents_Model
+81
View File
@@ -0,0 +1,81 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `CSiCoCars` (
`caIDcar` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco del veicolo',
`caTarga` varchar(10) NOT NULL COMMENT 'Targa del veicolo',
`caDescrizione` text NOT NULL COMMENT 'Descrizione del veicolo',
`caDataAssicurazione` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Prossima data di scadenza dell''assicurazione del veicolo',
`caTipoGomme` enum('Invernali','Estive','4Stagioni') NOT NULL DEFAULT '4Stagioni' COMMENT 'Tipologia di pneumatici in dotazione al veicolo',
`caCreatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp di inserimento del record nel database',
`caUpdatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp in cui il record è stato aggiornato',
`caStato` enum('Disponibile','Occupata','Dismessa') NOT NULL DEFAULT 'Disponibile' COMMENT 'Stato della macchina, riassume gli eventi',
`caDeletedAt` timestamp NULL DEFAULT NULL COMMENT 'Timestamp in cui il record è stato virtualmente cancellato (senza delete reale)',
PRIMARY KEY (`caIDcar`),
UNIQUE KEY `caIDcar` (`caIDcar`),
UNIQUE KEY `caTarga` (`caTarga`, `smDeletedAt`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='Tabella con tutte le macchine della CSiCo.';
Fields:
Tab: CSiCoCars = ['caIDcar', 'caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caCreatedAt', 'caUpdatedAt', 'caStato', 'caDeletedAt'];
*/
use CodeIgniter\Model;
class CSiCoCars_Model extends Model {
//--------------------------------------------------------------------
// Property
protected $table = 'CSiCoCars';
protected $primaryKey = 'caIDcar';
protected $returnType = 'App\Entities\CSiCoCar';
//protected $returnType = 'array';
protected $allowedFields = ['caTarga', 'caDescrizione', 'caDataAssicurazione', 'caTipoGomme', 'caStato'];
protected $useSoftDeletes = true;
protected $useTimestamps = true;
protected $createdField = 'caCreatedAt';
protected $updatedField = 'caUpdatedAt';
protected $deletedField = 'caDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------
}//class CSiCoCars_Model
+79
View File
@@ -0,0 +1,79 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `Clienti` (
`clIDcliente` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco del cliente',
`clNome` varchar(32) NOT NULL COMMENT 'Nome, per riferimento interno, del cliente',
`clInfo` text NOT NULL COMMENT 'Informazioni sul cliente che vogliamo storicizzare',
`clCreatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp di inserimento del record nel database',
`clUpdatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp in cui il record è stato aggiornato',
`clDeletedAt` timestamp NULL DEFAULT NULL COMMENT 'Timestamp in cui il record è stato virtualmente cancellato (senza delete reale)',
PRIMARY KEY (`clIDcliente`),
UNIQUE KEY `clIDcliente` (`clIDcliente`),
UNIQUE KEY `clNome` (`clNome`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COMMENT='Elenco dei Clienti della CSiCo';
Fields:
Tab: Clienti = ['clIDcliente', 'clNome', 'clInfo', 'clCreatedAt', 'clUpdatedAt', 'clDeletedAt'];
*/
use CodeIgniter\Model;
class Clienti_Model extends Model{
//--------------------------------------------------------------------
// Property
protected $table = 'Clienti';
protected $primaryKey = 'clIDcliente';
//protected $returnType = 'App\Entities\Cliente';
protected $returnType = 'array';
protected $allowedFields = ['clNome', 'clInfo'];
protected $useSoftDeletes = true;
protected $useTimestamps = true;
protected $createdField = 'clCreatedAt';
protected $updatedField = 'clUpdatedAt';
protected $deletedField = 'clDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------
}//class Clienti_Model
+197
View File
@@ -0,0 +1,197 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `Commesse` (
`coIDcommessa` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco della commessa',
`coNome` varchar(32) NOT NULL COMMENT 'Nome univoco della commessa o codice identificativo della commessa',
`coIDcliente` int(11) NOT NULL COMMENT 'Codice identificativo del cliente a cui la commessa è associata',
`coDescrizione` text NOT NULL COMMENT 'Descrizione della commessa, cioè del lavoro che essa richiede',
`coIDstatoCommessa` varchar(16) NOT NULL COMMENT 'Stato a cui la commessa è associata, ne permette la filtrazione in modo conveniente',
`coCreatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp di inserimento del record nel database',
`coUpdatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp in cui il record è stato aggiornato',
`coDeletedAt` timestamp NULL DEFAULT NULL COMMENT 'Timestamp in cui il record è stato virtualmente cancellato (senza delete reale)',
PRIMARY KEY (`coIDcommessa`),
UNIQUE KEY `coIDcommessa` (`coIDcommessa`),
UNIQUE KEY `coNome` (`coNome`),
KEY `idx_Clienti_Used` (`coIDstatoCommessa`,`coModificatoIl`,`coNome`),
KEY `FK_Commesse-Clienti` (`coIDcliente`),
KEY `FK_Commesse-StatiCommessa` (`coIDstatoCommessa`)
) ENGINE=InnoDB AUTO_INCREMENT=197 DEFAULT CHARSET=utf8 COMMENT='Elenco delle Commesse';
Fields:
Tab: Commesse = ['coIDcommessa', 'coNome', 'coIDcliente', 'coDescrizione', 'coIDstatoCommessa', 'coCreatedAt', 'coUpdatedAt', 'coDeletedAt'];
*/
use CodeIgniter\Model;
class Commesse_Model extends Model{
//--------------------------------------------------------------------
// Property
protected $table = 'Commesse';
protected $primaryKey = 'coIDcommessa';
protected $returnType = 'App\Entities\Commessa';
//protected $returnType = 'array';
protected $allowedFields = ['coNome', 'coIDcliente', 'coDescrizione', 'coIDstatoCommessa'];
protected $useSoftDeletes = true;
protected $useTimestamps = true;
protected $createdField = 'coCreatedAt';
protected $updatedField = 'coUpdatedAt';
protected $deletedField = 'coDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
// Ritorna le coppie val,txt per compilare il select delle commesse in base al filtro attivo sugli orari
public function get_select_on_orari(){
// Tab: Commesse = ['coIDcommessa', 'coNome', 'coIDcliente', 'coDescrizione', 'coIDstatoCommessa', 'coModificatoIl', 'coCreatedAt', 'coUpdatedAt', 'coDeletedAt'];
// Creo la string SQL:
// - join fra le tabelle
$sql = 'SELECT Commesse.coIDcommessa AS val, Commesse.coNome AS txt FROM Commesse, Orari WHERE Commesse.coIDcommessa=Orari.orIDcommessa';
// - elimino le commesse chiuse:
$sql .= ' AND coIDstatoCommessa<>\'Chiusa\'';
// - Applico il filtro temporale:
$sql .= ' AND Orari.orData>=\'' . session()->get('filter_dal') . '\' AND Orari.orData<=\'' . session()->get('filter_al') . " 23:59:59" . '\'';
// - applico eventuale filtro per lavoratore
if ((null !== session()->get('filter_lavoratore')) && (session()->get('filter_lavoratore')!='-1')) {
$sql .= ' AND Orari.orIDlavoratore=\'' . session()->get('filter_lavoratore') . '\'';
}
// - Applico il filtro sulla tipologia di orario
if ((null !== session()->get('filter_tipo_ore')) && (session()->get('filter_tipo_ore')!='-1')) {
$sql .= ' AND Orari.orIDTipoOre=\'' . session()->get('filter_tipo_ore') . '\'';
}
// - Non applico il filtro sulla commessa:
if ((null !== session()->get('filter_commessa')) && (session()->get('filter_commessa')!='-1')) {
$sql .= ' AND Orari.orIDcommessa=\'' . session()->get('filter_commessa') . '\'';
}
// - Raggruppo i risultati:
$sql .= ' GROUP BY(txt)';
// - Ordino in modo decrescente sul numero di presenze e in modo alfabetico.
$sql .= ' ORDER BY COUNT(val) DESC, txt';
// Creo la query:
$query = $this->query($sql);
// Eseguo la query sul DB:
return $query->getResult();
} // function select_on_orari
//--------------------------------------------------------------------
// Ritorna le coppie val,txt per compilare il select delle commesse in base al filtro attivo sulle spese
public function get_select_on_spese(){
// Creo la string SQL:
// - join fra le tabelle\
$sql = 'SELECT Commesse.coIDcommessa AS val, CONCAT(Commesse.coNome, \' : \', Commesse.coDescrizione) AS txt FROM Commesse, Spese WHERE Commesse.coIDcommessa=Spese.spIDcommessa';
// - elimino le commesse chiuse:
$sql .= ' AND coIDstatoCommessa<>\'Chiusa\'';
// - Applico il filtro temporale:
$sql .= ' AND Spese.spData>=\'' . session()->get('filter_dal') . '\' AND Spese.spData<=\'' . session()->get('filter_al') . " 23:59:59" . '\'';
// - applico eventuale filtro per lavoratore
if ((null !== session()->get('filter_lavoratore')) && (session()->get('filter_lavoratore')!='-1')) {
$sql .= ' AND Spese.spIDlavoratore=\'' . session()->get('filter_lavoratore') . '\'';
}
// - Applico il filtro sulla tipologia di spesa
if ((null !== session()->get('filter_rimborso')) && (session()->get('filter_rimborso')!='-1')) {
$sql .= ' AND Spese.spDaRimborsare=\'' . session()->get('filter_rimborso') . '\'';
}
// - Non applico il filtro sulla commessa:
if ((null !== session()->get('filter_commessa')) && (session()->get('filter_commessa')!='-1')) {
$sql .= ' AND Spese.spIDcommessa=\'' . session()->get('filter_commessa') . '\'';
}
// - Raggruppo i risultati:
$sql .= ' GROUP BY(txt)';
// - Ordino in modo decrescente sul numero di presenze e in modo alfabetico.
$sql .= ' ORDER BY COUNT(val) DESC, txt';
// Creo la query:
$query = $this->query($sql);
// Eseguo la query sul DB:
return $query->getResult();
} // function select_on_orari
//--------------------------------------------------------------------
// Ritorna le coppie val,txt per compilare il select delle commesse
public function get_select(){
$query = $this->query('SELECT coIDcommessa AS val, CONCAT(coNome, \' : \', coDescrizione) AS txt FROM Commesse WHERE coIDstatoCommessa<>\'Chiusa\' ORDER BY coUpdatedAt DESC');
return $query->getResult();
}
//--------------------------------------------------------------------
// Ritorna i dati per il report della commessa indicata
public function get_ReportByCommessa($ID){
$query = $this->query("
SELECT
coIDcommessa AS ID,
coNome AS Nome,
(SELECT clNome FROM `Clienti` WHERE clIDcliente=coIDcliente) AS Cliente,
coDescrizione AS Descrizione,
(SELECT sum(stStima) FROM `Stime` WHERE stIDcommessa=coIDcommessa) AS Stima,
(SELECT sum(orOre) FROM `Orari` WHERE orIDcommessa=coIDcommessa) AS Usate,
coIDstatoCommessa AS Stato,
coCreatedAt AS CreatedAt,
coUpdatedAt AS UpdatedAt,
coDeletedAt AS DeletedAt
FROM `Commesse`
WHERE coIDcommessa='$ID'
");
return $query->getResult();
}
//--------------------------------------------------------------------
}//class Commesse_Model
+79
View File
@@ -0,0 +1,79 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `CreditCardEvents` (
`eccIDcreditEvent` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco dell''evento',
`eccIDcard` int(11) NOT NULL COMMENT 'Identificativo univoco della carta di credito aziendale',
`eccIDlavoratore` int(11) NOT NULL COMMENT 'Identificativo univoco del lavoratore che utilizza la carta',
`eccDescrizione` text NOT NULL COMMENT 'Descrizione esplicativa del motivo per cui si utilizza la carta',
`eccData` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Data in cui si è utilizzato la carta',
`eccCredito` float NOT NULL DEFAULT '0' COMMENT 'Stima del credito rimasto alla data dell''evento',
`eccTipologia` enum('Presa','Restituita') NOT NULL DEFAULT 'Presa' COMMENT 'Tipologia dell''evento',
PRIMARY KEY (`eccIDcreditEvent`),
KEY `FK_CreditEvents-CreditCards` (`eccIDcard`),
KEY `FK_CreditEvents-Lavoratori` (`eccIDlavoratore`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8 COMMENT='Tabella con tutti gli eventi riferiti alle carte di credito.';
Fields:
Tab: CreditCardEvents = ['eccIDcreditEvent', 'eccIDcard', 'eccIDlavoratore', 'eccDescrizione', 'eccData', 'eccCredito', 'eccTipologia'];
*/
use CodeIgniter\Model;
class CreditCardEvents_Model extends Model {
//--------------------------------------------------------------------
// Property
protected $table = 'CreditCardEvents';
protected $primaryKey = 'eccIDcreditEvent';
protected $returnType = 'App\Entities\CreditCardEvnt';
//protected $returnType = 'array';
protected $allowedFields = ['eccIDcard', 'eccIDlavoratore', 'eccDescrizione', 'eccData', 'eccCredito', 'eccTipologia'];
protected $useSoftDeletes = false;
protected $useTimestamps = false;
//protected $createdField = 'spCreatedAt';
//protected $updatedField = 'spUpdatedAt';
//protected $deletedField = 'spDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------
}//class CreditCardEvents_Model
+79
View File
@@ -0,0 +1,79 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `CreditCards` (
`ccIDcard` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco della carta di credito aziendale',
`ccNumero` varchar(20) NOT NULL COMMENT 'Numero nella carta',
`ccDescrizione` text NOT NULL COMMENT 'Descrizione della carta per riferimento interno CSiCo',
`ccScadeIl` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Data di scadenza della carta',
`ccPIN` varchar(6) NOT NULL COMMENT 'PIN della carta',
`ccCreatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp di inserimento del record nel database',
`ccUpdatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp in cui il record è stato aggiornato',
`ccStato` enum('Disponibile','Occupata','Scaduta') NOT NULL DEFAULT 'Disponibile' COMMENT 'Stato della carta di credito, riassume gli eventi',
`ccDeletedAt` timestamp NULL DEFAULT NULL COMMENT 'Timestamp in cui il record è stato virtualmente cancellato (senza delete reale)',
PRIMARY KEY (`ccIDcard`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COMMENT='Tabella con tutte le carte di credito della CSiCo.';
Fields:
Tab: CreditCards = ['ccIDcard', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', 'ccStato', 'ccDeletedAt'];
*/
use CodeIgniter\Model;
class CreditCards_Model extends Model {
//--------------------------------------------------------------------
// Property
protected $table = 'CreditCards';
protected $primaryKey = 'ccIDcard';
protected $returnType = 'App\Entities\CreditCard';
//protected $returnType = 'array';
protected $allowedFields = ['ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccStato'];
protected $useSoftDeletes = true;
protected $useTimestamps = true;
protected $createdField = 'ccCreatedAt';
protected $updatedField = 'ccUpdatedAt';
protected $deletedField = 'ccDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------
}//class CreditCards_Model
+379
View File
@@ -0,0 +1,379 @@
<?php
namespace App\Models;
use CodeIgniter\Database\ConnectionInterface;
class CrudModel
{
protected $db;
public function __construct(ConnectionInterface &$db)
{
$this->db = &$db;
}
public function schema($table)
{
$query = "SHOW COLUMNS FROM $table";
$result = $this->db->query($query)->getResult();
return $result;
}
public function insertItem($table, $data)
{
$this->db->table($table)->insert($data);
return $this->db->insertID();
}
public function getAnyItems($table, $where = false)
{
$builder = $this->db->table($table);
if ($where)
$builder->where($where);
return $builder->get()->getResult();
}
public function updateItem($table, $where, $data)
{
$this->db->table($table)->where($where)->update($data);
return $this->db->affectedRows();
}
function get_primary_key_field_name($table)
{
$query = "SHOW KEYS FROM $table WHERE Key_name = 'PRIMARY'";
return $this->db->query($query)->getRow()->Column_name;
}
//Get one item
public function getItem($table, $where)
{
return $this->db->table($table)
->where($where)
->get()
->getRow();
}
//Get total rows per request
public function countTotalRows($table, $where = null, $request, $schema, $fields)
{
$count_query = "SELECT COUNT(*) as total FROM " . $table;
//get primary_key field name
$pk = $this->get_primary_key_field_name($table);
if ($where) {
$count_query .= " WHERE (";
$i = 0;
foreach ($where as $key => $value) {
if ($i > 0)
$count_query .= " AND ";
//Check if operator is different from = (equal sign)
$operator_arr = explode(" ", $key);
if (isset($operator_arr[1]))
$operator = $operator_arr[1];
else
$operator = "=";
$count_query .= " `$operator_arr[0]`$operator" . $this->db->escape($value) . " ";
$i++;
}
$count_query .= ")";
}
if ($table_search = $request->getPost('table_search')) {
$allEmpty = true;
$tempQuery = '';
if ($where)
$tempQuery .= " AND ";
else
$tempQuery .= " WHERE ";
$tempQuery .= " ( ";
$i = 0;
// echo '<pre>';
// print_r($schema);
// echo '<pre>';
foreach ($schema as $column) {
if (trim($request->getPost($column->Field)) == '')
continue;
if ($column->Extra == 'other_table')
continue;
$allEmpty = false;
if ($i > 0)
$tempQuery .= " OR ";
$tempQuery .= " " . $table_search
. "." . $column->Field
. " LIKE '%"
. trim($this->db->escapeLikeString($request->getPost($column->Field)))
. "%' ESCAPE '!'";
$i++;
}
$tempQuery .= ")";
if (!$allEmpty)
$count_query .= $tempQuery;
}
return $this->db->query($count_query)->getRow()->total;
}
public function getItems($table, $where = null, $request, $schema, $fields, $order, $offset, $per_page)
{
$result_query = "SELECT * FROM " . $table;
//get primary_key field name
$pk = $this->get_primary_key_field_name($table);
//Check for relation fields
foreach ($fields as $key => $rel_field) {
if (isset($rel_field['relation']) && !isset($rel_field['relation']['save_table'])) {
$rfield = $rel_field['relation'];
$result_query .= " LEFT JOIN " . $rfield['table'] . " ON " . $table . '.' . $key . "=" . $rfield['table'] . "." . $rfield['primary_key'] . " ";
//$this->db->join($rfield['table'], $table.'.'.$key.'='.$rfield['table'].'.'.$rfield['primary_key'], 'left');
}
}
if ($where) {
$result_query .= " WHERE (";
$i = 0;
foreach ($where as $key => $value) {
if ($i > 0)
$result_query .= " AND ";
//Check if operator is different from = (equal sign)
$operator_arr = explode(" ", $key);
if (isset($operator_arr[1]))
$operator = $operator_arr[1];
else
$operator = "=";
$result_query .= " `$operator_arr[0]`$operator'$value' ";
//$this->db->where($key, $value);
$i++;
}
$result_query .= ")";
}
if ($request->getPost('table_search')) {
$allEmpty = true;
$tempQuery = '';
$i = 0;
if ($where)
$tempQuery .= " AND ";
else
$tempQuery .= " WHERE ";
//$tempQuery .= " ( ";
foreach ($schema as $column) {
if ($request->getPost($column->Field) == '')
continue;
$allEmpty = false;
$col_search = [];
$col_search[] = $column->Field;
if (isset($fields[$column->Field]['relation']) && isset($fields[$column->Field]['relation']['save_table'])) {
//Search relational table to get the ids of related ids
$relField = $fields[$column->Field]['relation'];
$parent_table = $relField['table'];
$relation_table = $relField['save_table'];
$joinString = $relation_table . '.' . $relField['child_field'] . '=' . $parent_table . '.' . $relField['primary_key'];
$likeColumns = $relField['display'];
$likeTerm = $request->getPost($column->Field);
//$relselect is optional. when used it will add DISTINCT to prevent dublicates
$relSelect = $relation_table . '.' . $relField['parent_field'];
$relatedItems = $this->searchRelatedItems($parent_table, $relation_table, $joinString, $likeColumns, $likeTerm, $relSelect);
$relatedItemsIdArr = [];
if (!$relatedItems)
$relatedItemsIdArr = '-1';
else {
//Create an array of ids for whereIn statement
foreach ($relatedItems as $relatedItem) {
$relatedItemsIdArr[] = $relatedItem->{$relField['parent_field']};
}
}
if ($i > 0)
$tempQuery .= " AND ";
if (is_array($relatedItemsIdArr))
$relTempQuery = '' . $table . '.' . $pk . ' IN (' . implode(',', $relatedItemsIdArr) . ')';
else
$relTempQuery = $table . '.' . $pk . ' = ' . $relatedItemsIdArr;
// echo $tempQuery.'<br>';
$tempQuery .= $relTempQuery;
// echo $tempQuery;
$i++;
//$allEmpty = false;
continue;
} else if (isset($fields[$column->Field]['relation'])) {
$col_search = $fields[$column->Field]['relation']['display'];
//check if display is an array of columns
if (!is_array($col_search))
$col_search[] = $col_search;
$table_search = $fields[$column->Field]['relation']['table'];
} else {
$table_search = $table;
//$col_search[] = $column->Field;
}
if ($i > 0)
$tempQuery .= " AND ";
//For loop is required when search must be performed in multiple relational columns from another table
$searchLikeTempQuery = '';
$searchLikeTempQueryArr = [];
foreach ($col_search as $colToSearch) {
$searchLikeTempQueryArr[] = $this->generateLikeClause($table_search, $colToSearch, $request->getPost($column->Field));
}
if (count($col_search) > 1) {
$searchLikeTempQuery = implode(' OR ', $searchLikeTempQueryArr);
$searchLikeTempQuery = "($searchLikeTempQuery)";
} else
$searchLikeTempQuery = $searchLikeTempQueryArr[0];
$tempQuery .= $searchLikeTempQuery;
//$this->db->like($table_search.'.'.$col_search, $request->getPost($column->Field), 'both');
$i++;
}
$tempQuery .= isset($searchLikeTempQuery) ? " " : "";
if (!$allEmpty)
$result_query .= $tempQuery;
}
if ($order) {
$result_query .= " ORDER BY ";
$i = 0;
foreach ($order as $ord) {
if ($i > 0)
$result_query .= ", ";
$result_query .= $ord[0] . " " . $ord[1];
//$this->db->order_by($ord[0], $ord[1]);
$i++;
}
} else {
$result_query .= " ORDER BY " . $pk . " DESC";
//$this->db->order_by($pk, 'DESC');
}
$result_query = rtrim($result_query, ',');
$result_query .= " LIMIT $offset, $per_page ";
//$this->db->limit($per_page, $offset);
$page_items = $this->db->query($result_query)->getResult();
return $page_items;
}
public function getRelationItems($table, $where = null, $orderField = null, $orderDirection = null)
{
$builder = $this->db->table($table);
if ($where)
$builder->where($where);
if ($orderField)
$builder->orderBy($orderField, $orderDirection);
$items = $builder->get()
->getResult();
return $items;
}
public function deleteItems($table, $where = null, $whereInField = null, $whereInValue = null)
{
$builder = $this->db->table($table);
if ($where)
$builder->where($where);
if ($whereInField && $whereInValue)
$builder->whereIn($whereInField, $whereInValue);
return $builder->delete();
}
public function batchInsert($table, $data)
{
$builder = $this->db->table($table);
return $builder->insertBatch($data);
}
public function getRelationItemsJoin($table, $where, $joinTable, $joinString)
{
$builder = $this->db->table($table);
$builder->where($where);
$builder->join($joinTable, $joinString);
return $builder->get()->getResult();
}
public function searchRelatedItems($parent_table, $relation_table, $joinString, $likeColumns, $likeTerm, $select = '*')
{
$builder = $this->db->table($relation_table);
$builder->select($select);
$builder->join($parent_table, $joinString);
for ($i = 0; $i < count($likeColumns); $i++) {
if ($i < 1) {
$builder->like($parent_table . '.' . $likeColumns[$i], $likeTerm);
} else {
$builder->orLike($parent_table . '.' . $likeColumns[$i], $likeTerm);
}
}
return $builder->distinct()->get()->getResult();
}
public function generateLikeClause($table_search, $colToSearch, $searchTerm)
{
return $table_search . "." . $colToSearch
. " LIKE '%"
. trim($this->db->escapeLikeString($searchTerm))
. "%' ESCAPE '!'";
}
//Get total rows per request
public function GetOreByCommessa($IDcommessa)
{
$cont_query = "SELECT SUM(orOre) as OreLavorate FROM Orari WHERE orIDcommessa='" . $IDcommessa . "'";
//return $query;
return $this->db->query($cont_query)->getRow()->OreLavorate;
}
public function GetStimaByCommessa($IDcommessa)
{
$cont_query = "SELECT SUM(stStima) AS Stima FROM `Stime` WHERE stIDcommessa='" . $IDcommessa . "'";
//return $query;
return $this->db->query($cont_query)->getRow()->Stima;
}
}
+81
View File
@@ -0,0 +1,81 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `Issues` (
`isIDissue` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco dell''issue',
`isTipologia` enum('BUG','IDEA','INFO','RICHIESTA') DEFAULT 'INFO' COMMENT 'Indica la tipologia dell''issue: -BUG indica un malfuzionamento della webapp o una mancanza; - IDEA indica una funzionalità da inserire o descrive un possibile miglioramento; INFO indica delle informazioni utili per tutti e che è utile tenere in evidenza.',
`isStato` enum('Da_Leggere','Da_Fare','In_Working','Sospesa','Abortita','Done') DEFAULT 'Da_Leggere' COMMENT 'Stato associabile all''issue.',
`isIDlavoratore` int(11) NOT NULL COMMENT 'Identificativo del lavoratore che ha inserito l''issue',
`isTesto` text NOT NULL COMMENT 'Testo o descrizione dell''issue.',
`isCreatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp di inserimento del record nel database',
`isUpdatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp in cui il record è stato aggiornato',
`isDeletedAt` timestamp NULL DEFAULT NULL COMMENT 'Timestamp in cui il record è stato virtualmente cancellato (senza delete reale)',
PRIMARY KEY (`isIDissue`),
KEY `FK_Issues-Lavoratori` (`isIDlavoratore`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Tabella con le issue relative alla webapplication. Utile per segnalare all''amministratore eventuali bug, migliorie o per evidenziare a tutti delle informazioni.';
Fields:
Tab: Issues = ['isIDissue', 'isTipologia', 'isStato', 'isIDlavoratore', 'isTesto', 'isCreatedAt', 'isUpdatedAt', 'isDeletedAt'];
*/
use CodeIgniter\Model;
class Issues_Model extends Model{
//--------------------------------------------------------------------
// Property
protected $table = 'Issues';
protected $primaryKey = 'isIDissue';
protected $returnType = 'App\Entities\Issue';
//protected $returnType = 'array';
protected $allowedFields = ['isIDissue', 'isTipologia', 'isStato', 'isIDlavoratore', 'isTesto'];
protected $useSoftDeletes = true;
protected $useTimestamps = true;
protected $createdField = 'isCreatedAt';
protected $updatedField = 'isUpdatedAt';
protected $deletedField = 'isDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------
}//class Issues_Model
+200
View File
@@ -0,0 +1,200 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `Lavoratori` (
`lvIDlavoratore` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco del lavoratore',
`lvNome` varchar(64) NOT NULL COMMENT 'Nome anagrafico del lavoratore',
`lvCognome` varchar(64) NOT NULL COMMENT 'Cognome anagrfico del lavoratore',
`lvMail` varchar(128) NOT NULL COMMENT 'Indirizzo mail assegnato al al lavoratore',
`lvLevel` int(1) NOT NULL DEFAULT '1' COMMENT 'Livello di accesso alla webapp. 0=Guest; 1=Oper; 2=Inven; 3=Admin; 4=Root.',
`lvRimborsoKm` float NOT NULL DEFAULT '0' COMMENT 'Valore del rimborso kilometrico corrisposto al lavoratore',
`lvNickname` varchar(8) NOT NULL COMMENT 'Nickname distindivo del lavoratore',
`lvPassword` varchar(255) NOT NULL COMMENT 'Codice Hash della password editata dal lavoratore',
`lvCreatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp di inserimento del record nel database',
`lvUpdatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp in cui il record è stato aggiornato',
`lvDeletedAt` timestamp NULL DEFAULT NULL COMMENT 'Timestamp in cui il record è stato virtualmente cancellato (senza delete reale)',
PRIMARY KEY (`lvIDlavoratore`),
UNIQUE KEY `lvIDlavoratore` (`lvIDlavoratore`),
UNIQUE KEY `lvNikname` (`lvNickname`,`lvDeletedAt`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8 COMMENT='Elenco dei Lavoratori della CSiCo (CSiCoBoys)';
Fields:
Tab: Lavoratori = ['lvIDlavoratore', 'lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'lvCreatedAt', 'lvUpdatedAt', 'lvDeletedAt'];
*/
use CodeIgniter\Model;
class Lavoratori_Model extends Model{
//--------------------------------------------------------------------
// Property
protected $table = 'Lavoratori';
protected $primaryKey = 'lvIDlavoratore';
protected $returnType = 'App\Entities\Lavoratore';
//protected $returnType = 'array';
protected $allowedFields = ['lvNome', 'lvCognome', 'lvMail', 'lvLevel', 'lvRimborsoKm', 'lvNickname', 'lvPassword', 'ccStato'];
protected $useSoftDeletes = true;
protected $useTimestamps = true;
protected $createdField = 'lvCreatedAt';
protected $updatedField = 'lvUpdatedAt';
protected $deletedField = 'lvDeletedAt';
//--------------------------------------------------------------------
// Events
protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
protected function beforeInsert(array $data){
$data = $this->passwordHash($data);
return $data;
}
protected function beforeUpdate(array $data){
$data = $this->passwordHash($data);
return $data;
}
protected function passwordHash(array $data){
if(isset($data['data']['lvPassword']))
$data['data']['lvPassword'] = password_hash($data['data']['lvPassword'], PASSWORD_DEFAULT);
return $data;
}
//--------------------------------------------------------------------
/**
* Ritorna le coppie val,txt per compilare il select dei lavoratori, in base al filtro attivo
*/
public function get_select_on_orari(){
// Creo la string SQL:
// - join fra le tabelle
$sql = 'SELECT Lavoratori.lvIDlavoratore AS val, Lavoratori.lvNickname AS txt FROM Lavoratori, Orari WHERE Lavoratori.lvIDlavoratore=Orari.orIDlavoratore';
// - Filtro fra i lavoratori Guest o i cancellati:
$sql .= " AND lvDeletedAt IS null AND lvLevel>0";
// - Applico il filtro temporale:
$sql .= ' AND Orari.orData>=\'' . session()->get('filter_dal') . '\' AND Orari.orData<=\'' . session()->get('filter_al') . " 23:59:59" . '\'';
// - applico eventuale filtro per lavoratore
if ((null !== session()->get('filter_lavoratore')) && (session()->get('filter_lavoratore')!='-1')) {
$sql .= ' AND Lavoratori.lvIDlavoratore=\'' . session()->get('filter_lavoratore') . '\'';
}
// - applico eventuale filtro per commessa
if ((null !== session()->get('filter_commessa')) && (session()->get('filter_commessa')!='-1')) {
$sql .= ' AND Orari.orIDcommessa=\'' . session()->get('filter_commessa') . '\'';
}
// - applico eventuale filtro per tipologia di ora:
if ((null !== session()->get('filter_tipo_ore')) && (session()->get('filter_tipo_ore')!='-1')) {
$sql .= ' AND Orari.orIDTipoOre=\'' . session()->get('filter_tipo_ore') . '\'';
}
// - Raggruppo i risultati:
$sql .= ' GROUP BY(txt)';
// - Ordino in modo decrescente sul numero di presenze e in modo alfabetico.
$sql .= ' ORDER BY COUNT(val) DESC, txt';
// Creo la query:
$query = $this->query($sql);
// Eseguo la query sul DB:
return $query->getResult();
} // function select_on_orari
//--------------------------------------------------------------------
// Ritorna le coppie val,txt per compilare il select dei lavoratori, in base al filtro attivo
public function get_select_on_spese(){
// Creo la string SQL:
// - join fra le tabelle
$sql = 'SELECT Lavoratori.lvIDlavoratore AS val, Lavoratori.lvNickname AS txt FROM Lavoratori, Spese WHERE Lavoratori.lvIDlavoratore=Spese.spIDlavoratore';
// - Filtro fra i lavoratori Guest o i cancellati:
$sql .= " AND lvDeletedAt IS null AND lvLevel>0";
// - Applico il filtro temporale:
$sql .= ' AND Spese.spData>=\'' . session()->get('filter_dal') . '\' AND Spese.spData<=\'' . session()->get('filter_al') . " 23:59:59" . '\'';
// - applico eventuale filtro per lavoratore
if ((null !== session()->get('filter_lavoratore')) && (session()->get('filter_lavoratore')!='-1')) {
$sql .= ' AND Lavoratori.lvIDlavoratore=\'' . session()->get('filter_lavoratore') . '\'';
}
// - applico eventuale filtro per commessa
if ((null !== session()->get('filter_commessa')) && (session()->get('filter_commessa')!='-1')) {
$sql .= ' AND Spese.spIDcommessa=\'' . session()->get('filter_commessa') . '\'';
}
// - applico eventuale filtro per tipologia di rimborso:
if ((null !== session()->get('filter_rimborso')) && (session()->get('filter_rimborso')!='-1')) {
$sql .= ' AND Spese.spDaRimborsare=\'' . session()->get('filter_rimborso') . '\'';
}
// - Raggruppo i risultati:
$sql .= ' GROUP BY(txt)';
// - Ordino in modo decrescente sul numero di presenze e in modo alfabetico.
$sql .= ' ORDER BY COUNT(val) DESC, txt';
// Creo la query:
$query = $this->query($sql);
// Eseguo la query sul DB:
return $query->getResult();
} // function select_on_spese
//--------------------------------------------------------------------
/**
* Ritorna le coppie val,txt per compilare il select dei lavoratori
*/
public function get_select() {
// Filtro fra i lavoratori cancellati e quelli solo guest:
$query = $this->query('SELECT lvIDlavoratore AS val, lvNickname AS txt FROM Lavoratori WHERE lvDeletedAt IS null AND lvLevel>0 ORDER BY lvNickname');
return $query->getResult();
}//function get_select
//--------------------------------------------------------------------
}//class Lavoratori_Model
+105
View File
@@ -0,0 +1,105 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `Orari` (
`orIDorario` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco dell''orario',
`orIDcommessa` int(11) NOT NULL COMMENT 'Identificativo univoco della commessa a cui si riferisce l''orario',
`orIDlavoratore` int(11) NOT NULL COMMENT 'Identificativo univoco del lavoratore a cui si riferisce l''orario',
`orData` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Data in cui si è avuto l''orario',
`orOre` float NOT NULL DEFAULT '0' COMMENT 'Durata espressa in ore con i decimali (0,5=30 minuti)',
`orIDTipoOre` varchar(2) NOT NULL COMMENT 'Tipologia dell''orario in base a quanto indicato sulle buste paga',
`orIDTipoWork` varchar(5) NOT NULL COMMENT 'Tipologia del lavoro svolto',
`orDescrizione` text NOT NULL COMMENT 'Descrizione esplicativa di quanto fatto nell''orario',
PRIMARY KEY (`orIDorario`),
KEY `FK_Orari-Commesse` (`orIDcommessa`),
KEY `FK_Orari-Lavoratori` (`orIDlavoratore`),
KEY `FK_Orari-TipoOre` (`orIDTipoOre`)
) ENGINE=InnoDB AUTO_INCREMENT=15429 DEFAULT CHARSET=utf8 COMMENT='Tabella con tutti i log delle ore lavorate.';
Fields:
Tab: Orari = ['orIDorario', 'orIDcommessa', 'orIDlavoratore', 'orData', 'orOre', 'orIDTipoOre', 'orIDTipoWork', 'orDescrizione'];
*/
use CodeIgniter\Model;
class Orari_Model extends Model{
//--------------------------------------------------------------------
// Property
protected $table = 'Orari';
protected $primaryKey = 'orIDorario';
protected $returnType = 'App\Entities\Orario';
//protected $returnType = 'array';
protected $allowedFields = ['orIDcommessa', 'orIDlavoratore', 'orData', 'orOre', 'orIDTipoOre', 'orIDTipoWork', 'orDescrizione'];
protected $useSoftDeletes = false;
protected $useTimestamps = false;
//protected $createdField = 'spCreatedAt';
//protected $updatedField = 'spUpdatedAt';
//protected $deletedField = 'spDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------
// Ritorna i dati per il report della commessa indicata
public function get_ReportByCommessa($ID){
$query = $this->query("
SELECT
(SELECT coNome FROM `Commesse` WHERE coIDcommessa=orIDCommessa) AS Commessa,
(SELECT lvNickname FROM `Lavoratori` WHERE lvIDlavoratore=orIDlavoratore) AS Lavoratore,
orIDlavoratore AS IDlavoratore,
orIDTipoOre AS IDTipoOre,
orIDTipoWork AS IDTipoWork,
sum(orOre) AS TotOre
FROM `Orari`
WHERE orIDcommessa='$ID'
GROUP BY orIDlavoratore, orIDTipoOre, orIDTipoWork
WITH ROLLUP
");
return $query->getResult();
}
//--------------------------------------------------------------------
}//class Orari_Model
+79
View File
@@ -0,0 +1,79 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `SIMEvents` (
`esmIDsimEvent` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco dell''evento',
`esmIDsim` int(11) NOT NULL COMMENT 'Identificativo univoco della SIM telefonica',
`esmIDlavoratore` int(11) NOT NULL COMMENT 'Identificativo univoco del lavoratore',
`esmDescrizione` text NOT NULL COMMENT 'Descrizione esplicativa del''evento',
`esmData` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Data dell''evento',
`esmTipologia` enum('Presa','Restituita','Dismessa') NOT NULL DEFAULT 'Restituita' COMMENT 'Tipologia dell''evento',
PRIMARY KEY (`esmIDsimEvent`),
UNIQUE KEY `esmIDsimEvent` (`esmIDsimEvent`),
KEY `FK_SIMEvents-SIMs` (`esmIDsim`),
KEY `FK_SIMEvents-Lavoratori` (`esmIDlavoratore`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='Tabella con tutti gli eventi riferiti alle SIM aziendali.';
Fields:
Tab: SIMEvents = ['esmIDsimEvent', 'esmIDsim', 'esmIDlavoratore', 'esmDescrizione', 'esmData', 'esmTipologia'];
*/
use CodeIgniter\Model;
class SIMEvents_Model extends Model {
//--------------------------------------------------------------------
// Property
protected $table = 'SIMEvents';
protected $primaryKey = 'esmIDsimEvent';
protected $returnType = 'App\Entities\SIMEvnt';
//protected $returnType = 'array';
protected $allowedFields = ['esmIDsim', 'esmIDlavoratore', 'esmDescrizione', 'esmData', 'esmTipologia'];
protected $useSoftDeletes = false;
protected $useTimestamps = false;
//protected $createdField = 'spCreatedAt';
//protected $updatedField = 'spUpdatedAt';
//protected $deletedField = 'spDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------
}//class SIMEvents_Model
+82
View File
@@ -0,0 +1,82 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `SIMs` (
`smIDsim` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco della SIM telefonica',
`smNumero` varchar(16) NOT NULL COMMENT 'Numero telefonico della SIM',
`smPIN` varchar(16) NOT NULL COMMENT 'Pin della SIM',
`smPUK` varchar(16) NOT NULL COMMENT 'Puk della SIM',
`smDescrizione` text NOT NULL COMMENT 'Descrizione dell''articolo',
`smCredito` float NOT NULL DEFAULT 0 COMMENT 'Valore stimato del credito nella SIM',
`smCreatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp di inserimento del record nel database',
`smUpdatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp in cui il record è stato aggiornato',
`smStato` enum('Disponibile','In uso','Scaduta') NOT NULL DEFAULT 'Disponibile' COMMENT 'Stato della SIM, riassume gli eventi',
`smDeletedAt` timestamp NULL DEFAULT NULL COMMENT 'Timestamp in cui il record è stato virtualmente cancellato (senza delete reale)',
PRIMARY KEY (`smIDsim`),
UNIQUE KEY `smIDsim` (`smIDsim`),
UNIQUE KEY `smNumero` (`smNumero`, `smDeletedAt`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Tabella con tutte le SIM aziendali.';
Fields:
Tab: SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smCreatedAt', 'smUpdatedAt', 'smStato', 'smDeletedAt'];
*/
use CodeIgniter\Model;
class SIMs_Model extends Model {
//--------------------------------------------------------------------
// Property
protected $table = 'SIMs';
protected $primaryKey = 'smIDsim';
protected $returnType = 'App\Entities\SIM';
//protected $returnType = 'array';
protected $allowedFields = ['smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smStato'];
protected $useSoftDeletes = true;
protected $useTimestamps = true;
protected $createdField = 'smCreatedAt';
protected $updatedField = 'smUpdatedAt';
protected $deletedField = 'smDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------
}//class SIMs_Model
+79
View File
@@ -0,0 +1,79 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `Spese` (
`spIDspesa` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco della spesa',
`spIDcommessa` int(11) NOT NULL COMMENT 'Identificativo univoco della commessa a cui riferire la spesa',
`spIDlavoratore` int(11) NOT NULL COMMENT 'Identificativo univoco del lavoratore a cui riferire la spesa',
`spImporto` float NOT NULL DEFAULT '0' COMMENT 'Valore in euro della spesa.',
`spDaRimborsare` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Indica se la spesa è da rimborsare perchè anticipata dal lavoratore o no',
`spDescrizione` text NOT NULL COMMENT 'Descrizione della spesa',
`spData` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Data in cui si è fatta la spesa',
PRIMARY KEY (`spIDspesa`),
KEY `FK_Spese-Commesse` (`spIDcommessa`),
KEY `FK_Spese-Lavoratori` (`spIDlavoratore`)
) ENGINE=InnoDB AUTO_INCREMENT=1615 DEFAULT CHARSET=utf8 COMMENT='Tabella con tutti i log delle Spese da rimborsare.';
Fields:
Tab: Spese = ['spIDspesa', 'spIDcommessa', 'spIDlavoratore', 'spImporto', 'spDaRimborsare', 'spDescrizione', 'spData'];
*/
use CodeIgniter\Model;
class Spese_Model extends Model{
//--------------------------------------------------------------------
// Property
protected $table = 'Spese';
protected $primaryKey = 'spIDspesa';
protected $returnType = 'App\Entities\Spesa';
//protected $returnType = 'array';
protected $allowedFields = ['spIDcommessa', 'spIDlavoratore', 'spImporto', 'spDaRimborsare', 'spDescrizione', 'spData'];
protected $useSoftDeletes = false;
protected $useTimestamps = false;
//protected $createdField = 'spCreatedAt';
//protected $updatedField = 'spUpdatedAt';
//protected $deletedField = 'spDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------
}//class Spese_Model
+102
View File
@@ -0,0 +1,102 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `Stime` (
`stIDcommessa` int NOT NULL AUTO_INCREMENT COMMENT 'Identificativo univoco della commessa a cui si riferisce la stima',
`stIDTipoWork` varchar(5) NOT NULL COMMENT 'Identificativo univoco della tipologia di lavoro a cui si riferisce la stima',
`stStima` int NOT NULL DEFAULT '0' COMMENT 'Stima (in ore) del tempo necessario allo svolgimento del lavoro per la commessa, fatta in fase di offerta.',
`stNota` text NOT NULL COMMENT 'Eventuale annotazione sulla stima',
PRIMARY KEY (`stIDcommessa`,`stIDTipoWork`),
KEY `FK_Stime-Commessa` (`stIDcommessa`),
KEY `FK_Stime-TipiWork` (`stIDTipoWork`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Elenco delle stime fatte per la commessa';
Fields:
Tab: Stime = ['stIDcommessa', 'stIDTipoWork', 'stStima', 'stNota'];
*/
use CodeIgniter\Model;
class Stime_Model extends Model{
//--------------------------------------------------------------------
// Property
protected $table = 'Stime';
//protected $primaryKey = 'stIDcommessa';
protected $returnType = 'App\Entities\Stima';
//protected $returnType = 'array';
protected $allowedFields = ['stIDcommessa', 'stIDTipoWork', 'stStima', 'stNota'];
protected $useSoftDeletes = false;
protected $useTimestamps = false;
//protected $createdField = 'spCreatedAt';
//protected $updatedField = 'spUpdatedAt';
//protected $deletedField = 'spDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------
// Ritorna i dati per il report della commessa indicata
public function get_ReportByCommessa($ID){
$query = $this->query("
SELECT
twIDTipoWork AS IDTipoWork,
twDescrizione AS Descrizione,
(SELECT sum(stStima) FROM `Stime` WHERE stIDcommessa='$ID' AND stIDTipoWork=twIDTipoWork) AS Stima,
(SELECT sum(orOre) FROM `Orari` WHERE orIDcommessa='$ID' AND orIDTipoWork=twIDTipoWork) AS TotOre,
(SELECT stNota FROM `Stime` WHERE stIDcommessa='$ID' AND stIDTipoWork=twIDTipoWork) AS Nota
FROM `TipiWork`
ORDER BY twOrdinamento
");
return $query->getResult();
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
}//class Stime_Model
+120
View File
@@ -0,0 +1,120 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `TipiWork` (
`twIDTipoWork` varchar(5) NOT NULL COMMENT 'Identificativo univoco della tipologia di lavoro',
`twDescrizione` text NOT NULL COMMENT 'Descrizione della tipologia di lavoro',
`twOrdinamento` int NOT NULL COMMENT 'Indice per l''ordinamento nella visualizzazione della tipologia',
PRIMARY KEY (`twIDTipoWork`),
UNIQUE KEY `twIDTipoWork` (`twIDTipoWork`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Elenco delle tipologie di lavoro';
Fields:
Tab: TipiWork = ['twIDTipoWork', 'twDescrizione', 'twOrdinamento'];
*/
use CodeIgniter\Model;
class TipiWork_Model extends Model{
//--------------------------------------------------------------------
// Property
protected $table = 'TipiWork';
protected $primaryKey = 'twIDTipoWork';
protected $returnType = 'App\Entities\TipoWork';
//protected $returnType = 'array';
protected $allowedFields = ['twDescrizione', 'twOrdinamento'];
protected $useSoftDeletes = false;
protected $useTimestamps = false;
//protected $createdField = 'spCreatedAt';
//protected $updatedField = 'spUpdatedAt';
//protected $deletedField = 'spDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
public function get_select_on_orari(){
// Creo la string SQL:
// - join fra le tabelle
//$sql = 'SELECT TipiWork.twIDTipoWork AS val, TipiWork.twDescrizione AS txt FROM TipiWork, Orari WHERE TipiWork.twIDTipoWork=Orari.orIDTipoWork';
$sql = "SELECT TipiWork.twIDTipoWork AS val, CONCAT(TipiWork.twIDTipoWork, ' - ', TipiWork.twDescrizione) AS txt FROM TipiWork, Orari WHERE TipiWork.twIDTipoWork=Orari.orIDTipoWork";
// - Applico il filtro temporale:
$sql .= ' AND Orari.orData>=\'' . session()->get('filter_dal') . '\' AND Orari.orData<=\'' . session()->get('filter_al') . " 23:59:59" . '\'';
// - applico eventuale filtro per lavoratore
if ((null !== session()->get('filter_lavoratore')) && (session()->get('filter_lavoratore')!='-1')) {
$sql .= ' AND Orari.orIDlavoratore=\'' . session()->get('filter_lavoratore') . '\'';
}
// - Applico il filtro sulla tipologia di orario
if ((null !== session()->get('filter_tipo_ore')) && (session()->get('filter_tipo_ore')!='-1')) {
$sql .= ' AND Orari.orIDTipiWork=\'' . session()->get('filter_tipo_ore') . '\'';
}
// - Non applico il filtro sulla commessa:
if ((null !== session()->get('filter_commessa')) && (session()->get('filter_commessa')!='-1')) {
$sql .= ' AND Orari.orIDcommessa=\'' . session()->get('filter_commessa') . '\'';
}
// - Raggruppo i risultati:
$sql .= ' GROUP BY(val)';
// - Ordino in modo decrescente sul numero di presenze e in modo alfabetico.
$sql .= ' ORDER BY COUNT(val) DESC, txt';
// Creo la query:
$query = $this->query($sql);
// Eseguo la query sul DB:
return $query->getResult();
}//function select_on_orari
//--------------------------------------------------------------------
public function get_select(){
//$query = $this->query("SELECT twIDTipoWork AS val, twDescrizione AS txt FROM TipiWork WHERE twIDTipoWork<>'XXX00' ORDER BY twOrdinamento");
//$query = $this->query("SELECT twIDTipoWork AS val, CONCAT(twIDTipoWork, ' - ', twDescrizione) AS txt FROM TipiWork WHERE twIDTipoWork<>'XXX00' ORDER BY twOrdinamento");
$query = $this->query("SELECT twIDTipoWork AS val, CONCAT(twIDTipoWork, ' - ', twDescrizione) AS txt FROM TipiWork WHERE twOrdinamento<9999 ORDER BY twOrdinamento");
return $query->getResult();
}//function get_select
//--------------------------------------------------------------------
}//class TipiWork_Model
+117
View File
@@ -0,0 +1,117 @@
<?php namespace App\Models;
/*
CREATE TABLE IF NOT EXISTS `TipoOre` (
`toIDTipoOre` varchar(2) NOT NULL COMMENT 'Identificativo univoco della tipologia',
`toDescrizione` text NOT NULL COMMENT 'Descrizione della tipologia',
`toOrdinamento` int(1) NOT NULL COMMENT 'Indice per l''ordinamento nella visualizzazione della tipologia',
PRIMARY KEY (`toIDTipoOre`),
UNIQUE KEY `toIDTipoOre` (`toIDTipoOre`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Elenco delle tipologie di Orario i cui valori sono standardizzati sulla busta paga.';
Fields:
Tab: TipoOre = ['toIDTipoOre', 'toDescrizione', 'toOrdinamento'];
*/
use CodeIgniter\Model;
class TipoOre_Model extends Model{
//--------------------------------------------------------------------
// Property
protected $table = 'TipoOre';
protected $primaryKey = 'toIDTipoOre';
protected $returnType = 'App\Entities\TipoOra';
//protected $returnType = 'array';
protected $allowedFields = ['toDescrizione', 'toOrdinamento'];
protected $useSoftDeletes = false;
protected $useTimestamps = false;
//protected $createdField = 'spCreatedAt';
//protected $updatedField = 'spUpdatedAt';
//protected $deletedField = 'spDeletedAt';
//--------------------------------------------------------------------
// Events
//protected $beforeInsert = ['beforeInsert'];
//protected $afterInsert = ['afterInsert'];
//protected $beforeUpdate = ['beforeUpdate'];
//protected $afterUpdate = ['afterUpdate'];
//protected $beforeDelete = ['beforeDelete'];
//protected $afterDelete = ['afterDelete'];
//protected $afterFind = ['afterFind'];
//--------------------------------------------------------------------
// Methods
public function get_select_on_orari(){
// Creo la string SQL:
// - join fra le tabelle
$sql = 'SELECT TipoOre.toIDTipoOre AS val, TipoOre.toDescrizione AS txt FROM TipoOre, Orari WHERE TipoOre.toIDTipoOre=Orari.orIDTipoOre';
// - Applico il filtro temporale:
$sql .= ' AND Orari.orData>=\'' . session()->get('filter_dal') . '\' AND Orari.orData<=\'' . session()->get('filter_al') . " 23:59:59" . '\'';
// - applico eventuale filtro per lavoratore
if ((null !== session()->get('filter_lavoratore')) && (session()->get('filter_lavoratore')!='-1')) {
$sql .= ' AND Orari.orIDlavoratore=\'' . session()->get('filter_lavoratore') . '\'';
}
// - Applico il filtro sulla tipologia di orario
if ((null !== session()->get('filter_tipo_ore')) && (session()->get('filter_tipo_ore')!='-1')) {
$sql .= ' AND Orari.orIDTipoOre=\'' . session()->get('filter_tipo_ore') . '\'';
}
// - Non applico il filtro sulla commessa:
if ((null !== session()->get('filter_commessa')) && (session()->get('filter_commessa')!='-1')) {
$sql .= ' AND Orari.orIDcommessa=\'' . session()->get('filter_commessa') . '\'';
}
// - Raggruppo i risultati:
$sql .= ' GROUP BY(val)';
// - Ordino in modo decrescente sul numero di presenze e in modo alfabetico.
$sql .= ' ORDER BY COUNT(val) DESC, txt';
// Creo la query:
$query = $this->query($sql);
// Eseguo la query sul DB:
return $query->getResult();
}//function select_on_orari
//--------------------------------------------------------------------
public function get_select(){
$query = $this->query('SELECT toIDTipoOre AS val, toDescrizione AS txt FROM TipoOre ORDER BY toOrdinamento');
return $query->getResult();
}//function get_select
//--------------------------------------------------------------------
}//class TipoOre_Model