Refactor project structure
This commit is contained in:
57
core/src/TimeSheets/Common/Model/EmployeeTimeEntry.php
Normal file
57
core/src/TimeSheets/Common/Model/EmployeeTimeEntry.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/20/17
|
||||
* Time: 9:18 PM
|
||||
*/
|
||||
|
||||
namespace TimeSheets\Common\Model;
|
||||
|
||||
use Attendance\Common\Model\Attendance;
|
||||
use Classes\IceResponse;
|
||||
use Classes\SettingsManager;
|
||||
use Model\BaseModel;
|
||||
|
||||
class EmployeeTimeEntry extends BaseModel
|
||||
{
|
||||
public $table = 'EmployeeTimeEntry';
|
||||
|
||||
public function getAdminAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getManagerAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getUserAccess()
|
||||
{
|
||||
return array("get");
|
||||
}
|
||||
|
||||
public function getUserOnlyMeAccess()
|
||||
{
|
||||
return array("element","save","delete");
|
||||
}
|
||||
|
||||
public function validateSave($obj)
|
||||
{
|
||||
if (SettingsManager::getInstance()->getSetting("Attendance: Time-sheet Cross Check") == "1") {
|
||||
$attendance = new Attendance();
|
||||
$list = $attendance->Find(
|
||||
"employee = ? and in_time <= ? and out_time >= ?",
|
||||
array($obj->employee,$obj->date_start,$obj->date_end)
|
||||
);
|
||||
if (empty($list) || count($list) == 0) {
|
||||
return new IceResponse(
|
||||
IceResponse::ERROR,
|
||||
"The time entry can not be added since you have not marked attendance for selected period"
|
||||
);
|
||||
}
|
||||
}
|
||||
return new IceResponse(IceResponse::SUCCESS, "");
|
||||
}
|
||||
}
|
||||
91
core/src/TimeSheets/Common/Model/EmployeeTimeSheet.php
Normal file
91
core/src/TimeSheets/Common/Model/EmployeeTimeSheet.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/20/17
|
||||
* Time: 9:17 PM
|
||||
*/
|
||||
|
||||
namespace TimeSheets\Common\Model;
|
||||
|
||||
use Model\BaseModel;
|
||||
use Utils\CalendarTools;
|
||||
|
||||
class EmployeeTimeSheet extends BaseModel
|
||||
{
|
||||
public $table = 'EmployeeTimeSheets';
|
||||
|
||||
public function getAdminAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getManagerAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getUserAccess()
|
||||
{
|
||||
return array("get","element");
|
||||
}
|
||||
|
||||
public function getUserOnlyMeAccess()
|
||||
{
|
||||
return array("element","save","delete");
|
||||
}
|
||||
|
||||
public function getTotalTimeMinutes()
|
||||
{
|
||||
|
||||
$start = $this->date_start . " 00:00:00";
|
||||
$end = $this->date_end . " 23:59:59";
|
||||
|
||||
$timeEntry = new EmployeeTimeEntry();
|
||||
$list = $timeEntry->Find(
|
||||
"employee = ? and ((date_start >= ? and date_start <= ?) or (date_end >= ? and date_end <= ?))",
|
||||
array($this->employee, $start, $end, $start, $end)
|
||||
);
|
||||
|
||||
$seconds = 0;
|
||||
|
||||
foreach ($list as $entry) {
|
||||
$secondsTemp = (strtotime($entry->date_end) - strtotime($entry->date_start));
|
||||
if ($secondsTemp < 0) {
|
||||
$secondsTemp = 0;
|
||||
}
|
||||
|
||||
$seconds += $secondsTemp;
|
||||
}
|
||||
|
||||
$totMinutes = round($seconds / 60);
|
||||
|
||||
return $totMinutes;
|
||||
}
|
||||
|
||||
public function getTotalTime()
|
||||
{
|
||||
$totMinutes = $this->getTotalTimeMinutes();
|
||||
$minutes = $totMinutes % 60;
|
||||
$hours = ($totMinutes - $minutes) / 60;
|
||||
|
||||
return CalendarTools::addLeadingZero($hours)
|
||||
. ":" . CalendarTools::addLeadingZero($minutes);
|
||||
}
|
||||
|
||||
public function postProcessGetData($entry)
|
||||
{
|
||||
$entry->total_time = $this->getTotalTime();
|
||||
return $entry;
|
||||
}
|
||||
|
||||
public function postProcessGetElement($entry)
|
||||
{
|
||||
$entry->days = [];
|
||||
$days = CalendarTools::getDaysBetweenDates($entry->date_start, $entry->date_end);
|
||||
foreach ($days as $dayObj) {
|
||||
$entry->days[] = [$dayObj->format('Y-m-d'), $dayObj->format("(D) d M")];
|
||||
}
|
||||
return $entry;
|
||||
}
|
||||
}
|
||||
16
core/src/TimeSheets/Common/Model/QTDays.php
Normal file
16
core/src/TimeSheets/Common/Model/QTDays.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/20/17
|
||||
* Time: 9:19 PM
|
||||
*/
|
||||
|
||||
namespace TimeSheets\Common\Model;
|
||||
|
||||
use Model\BaseModel;
|
||||
|
||||
class QTDays extends BaseModel
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user