Files

105 lines
3.7 KiB
PHP
Raw Permalink Normal View History

2026-05-06 11:04:41 +02:00
<?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