Files
2026-01-09 11:41:28 +01:00

61 lines
1.6 KiB
PHP

<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 21/12/2017
* Time: 18:05
*/
class Employeehour extends BaseModel {
protected $table = "employeehours";
public function user()
{
return $this->belongsTo( 'User', 'employee_id' );
}
public function hourtype()
{
return $this->belongsTo( 'Hourtype' );
}
public static function getEmployeehours( $month, $year )
{
$employeehours = Employeehour::whereRaw( "MONTH(hourdate) = " . ( $month + 1 ) . " AND YEAR(hourdate) = {$year}" )
->with( [
'user' => function ( $q ) {
$q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" );
}] )
->with( 'hourtype' );
$projecthours = Employeehour::whereRaw("MONTH(hourdate) = " . ( $month + 1 ) . " AND YEAR(hourdate) = {$year}" )->with( [
'user' => function ( $q ) {
$q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" );
}] )
->with( 'hourtype' );
$results = $employeehours->union($projecthours)->get();
return $results;
}
public static function saveEmployeehour( $data )
{
$record = Employeehour::whereUuid( $data['uuid'])->first();
if ( ! $record )
{
$employeehour = Employeehour::create( $data );
$employeehourID = $employeehour->id;
}
else
{
Employeehour::whereUuid( $data['uuid'] )->update( $data );
$employeehourID = FALSE;
}
return $employeehourID;
}
}