Refactoring
This commit is contained in:
33
src/Reports/User/Api/ReportsModulesManager.php
Normal file
33
src/Reports/User/Api/ReportsModulesManager.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/19/17
|
||||
* Time: 10:26 PM
|
||||
*/
|
||||
|
||||
namespace Reports\User\Api;
|
||||
|
||||
use Classes\AbstractModuleManager;
|
||||
|
||||
class ReportsModulesManager extends AbstractModuleManager
|
||||
{
|
||||
|
||||
public function initializeUserClasses()
|
||||
{
|
||||
}
|
||||
|
||||
public function initializeFieldMappings()
|
||||
{
|
||||
}
|
||||
|
||||
public function initializeDatabaseErrorMappings()
|
||||
{
|
||||
}
|
||||
|
||||
public function setupModuleClassDefinitions()
|
||||
{
|
||||
|
||||
//This is a fixed module, store model classes in Models.inc.php
|
||||
}
|
||||
}
|
||||
182
src/Reports/User/Reports/ClientProjectTimeReport.php
Normal file
182
src/Reports/User/Reports/ClientProjectTimeReport.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
namespace Reports\User\Reports;
|
||||
|
||||
use Classes\BaseService;
|
||||
use Classes\SettingsManager;
|
||||
use Leaves\Common\Model\HoliDay;
|
||||
use Leaves\Common\Model\WorkDay;
|
||||
use Metadata\Common\Model\Country;
|
||||
use Reports\Admin\Api\PDFReportBuilder;
|
||||
use Reports\Admin\Api\PDFReportBuilderInterface;
|
||||
use Employees\Common\Model\Employee;
|
||||
use Projects\Common\Model\Client;
|
||||
use Projects\Common\Model\Project;
|
||||
use TimeSheets\Common\Model\EmployeeTimeEntry;
|
||||
use Utils\CalendarTools;
|
||||
|
||||
class ClientProjectTimeReport extends PDFReportBuilder implements PDFReportBuilderInterface
|
||||
{
|
||||
public function getData($report, $request)
|
||||
{
|
||||
$data = $this->getDefaultData();
|
||||
|
||||
$data['company'] = SettingsManager::getInstance()->getSetting('Company: Name');
|
||||
|
||||
$client = new Client();
|
||||
$client->Load("id = ?", array($request['client']));
|
||||
$data['client'] = $client->name;
|
||||
|
||||
$data['period'] = $request['date_start']." to ".$request['date_end'];
|
||||
|
||||
$project = new Project();
|
||||
$projects = $project->Find("client = ?", array($request['client']));
|
||||
|
||||
$projectsStr = "";
|
||||
$projectIds = '';
|
||||
$projectsMap = array();
|
||||
foreach ($projects as $pro) {
|
||||
$projectIds[] = $pro->id;
|
||||
$projectsMap[$pro->id] = $pro->name;
|
||||
}
|
||||
|
||||
$employeeId = BaseService::getInstance()->getCurrentProfileId();
|
||||
$employee = new Employee();
|
||||
$employee->Load("id = ?", array($employeeId));
|
||||
|
||||
$data['employee'] = $employee->first_name." ".$employee->last_name;
|
||||
|
||||
$employeeTimeEntry = new EmployeeTimeEntry();
|
||||
$timeEntryList = $employeeTimeEntry->Find(
|
||||
"employee = ? and date(date_start) >= ? and date(date_end) <= ? and project in (".implode(",", $projectIds).") order by date_start",
|
||||
array($employeeId, $request['date_start'], $request['date_end'])
|
||||
);
|
||||
|
||||
$totalHours = 0;
|
||||
$nonWorkingDayHours = 0;
|
||||
|
||||
$projectTimes = array();
|
||||
|
||||
$timeEntryListNew = array();
|
||||
|
||||
$country = new Country();
|
||||
$country->Load("code = ?", $employee->country);
|
||||
|
||||
$countryCode = null;
|
||||
if (!empty($country->id)) {
|
||||
$countryCode = $country->id;
|
||||
}
|
||||
|
||||
$projectsWorked = array();
|
||||
|
||||
foreach ($timeEntryList as $timeEntry) {
|
||||
if (!in_array($timeEntry->project, $projectsWorked)) {
|
||||
$projectsWorked[] = $timeEntry->project;
|
||||
}
|
||||
|
||||
$entry = new \stdClass();
|
||||
$entry->date = date("d.m.Y", strtotime($timeEntry->date_start));
|
||||
$entry->startTime = $timeEntry->time_start;
|
||||
$entry->endTime = $timeEntry->time_end;
|
||||
$entry->details = $timeEntry->details;
|
||||
$entry->project = $projectsMap[$timeEntry->project];
|
||||
$entry->duration = CalendarTools::getTimeDiffInHours(
|
||||
$timeEntry->date_start,
|
||||
$timeEntry->date_end
|
||||
);
|
||||
$timeEntryListNew[] = $entry;
|
||||
|
||||
$totalHours += $entry->duration;
|
||||
|
||||
$isWorkingDay = $this->isWorkingDay($timeEntry->date_start, $countryCode);
|
||||
|
||||
if (!$isWorkingDay) {
|
||||
$nonWorkingDayHours += $entry->duration;
|
||||
}
|
||||
|
||||
if (!isset($projectTimes[$projectsMap[$timeEntry->project]])) {
|
||||
$projectTimes[$projectsMap[$timeEntry->project]] = 0;
|
||||
}
|
||||
|
||||
$projectTimes[$projectsMap[$timeEntry->project]] += $entry->duration;
|
||||
}
|
||||
|
||||
foreach ($projects as $pro) {
|
||||
if (in_array($pro->id, $projectsWorked)) {
|
||||
if ($projectsStr != "") {
|
||||
$projectsStr .= " ,";
|
||||
}
|
||||
$projectsStr .= $pro->name;
|
||||
}
|
||||
}
|
||||
|
||||
$data['projects'] = $projectsStr;
|
||||
|
||||
$data['entries'] = $timeEntryListNew;
|
||||
$data['projectTimes'] = $projectTimes;
|
||||
$data['totalHours'] = $totalHours;
|
||||
$data['totalHoursWorking'] = $totalHours - $nonWorkingDayHours;
|
||||
$data['totalHoursNonWorking'] = $nonWorkingDayHours;
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function isHoliday($date, $countryId)
|
||||
{
|
||||
|
||||
$hd = new HoliDay();
|
||||
$allHolidays = $hd->Find(
|
||||
"dateh = ? and country IS NULL",
|
||||
array(date('Y-m-d', strtotime($date)))
|
||||
);
|
||||
|
||||
if (count($allHolidays) > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!empty($countryId)) {
|
||||
$countryHolidays = $hd->Find(
|
||||
"dateh = ? and country = ?",
|
||||
array(date('Y-m-d', strtotime($date)), $countryId)
|
||||
);
|
||||
|
||||
if (count($countryHolidays) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function isWorkingDay($date, $countryId)
|
||||
{
|
||||
$day = date("l", strtotime($date));
|
||||
|
||||
$isHoliday = $this->isHoliday($date, $countryId);
|
||||
|
||||
if ($isHoliday) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$wdCountry = new WorkDay();
|
||||
$wdCountry->Load("name = ? and country = ?", array($day, $countryId));
|
||||
if (!empty($wdCountry->id)) {
|
||||
if ($wdCountry->status == 'Full Day' || $wdCountry->status == 'Half Day') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$wdAll = new WorkDay();
|
||||
$wdAll->Load("name = ? and country IS NULL", array($day));
|
||||
if ($wdAll->status == 'Full Day' || $wdAll->status == 'Half Day') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getTemplate()
|
||||
{
|
||||
return "client_project_time_report.html";
|
||||
}
|
||||
}
|
||||
40
src/Reports/User/Reports/EmployeeAttendanceReport.php
Normal file
40
src/Reports/User/Reports/EmployeeAttendanceReport.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Reports\User\Reports;
|
||||
|
||||
use Classes\BaseService;
|
||||
use Reports\Admin\Api\CSVReportBuilder;
|
||||
use Reports\Admin\Api\CSVReportBuilderInterface;
|
||||
use Utils\LogManager;
|
||||
|
||||
class EmployeeAttendanceReport extends CSVReportBuilder implements CSVReportBuilderInterface
|
||||
{
|
||||
|
||||
public function getMainQuery()
|
||||
{
|
||||
$query = "SELECT
|
||||
(SELECT `employee_id` from Employees where id = at.employee) as 'Employee',
|
||||
(SELECT concat(`first_name`,' ',`middle_name`,' ', `last_name`) from Employees where id = at.employee) as 'Employee',
|
||||
in_time as 'Time In',
|
||||
out_time as 'Time Out',
|
||||
note as 'Note'
|
||||
FROM Attendance at";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getWhereQuery($request)
|
||||
{
|
||||
|
||||
$query = "where employee = ? and in_time >= ? and out_time <= ? order by in_time desc;";
|
||||
$params = array(
|
||||
BaseService::getInstance()->getCurrentProfileId(),
|
||||
$request['date_start']." 00:00:00",
|
||||
$request['date_end']." 23:59:59",
|
||||
);
|
||||
|
||||
LogManager::getInstance()->info("Query:".$query);
|
||||
LogManager::getInstance()->info("Params:".json_encode($params));
|
||||
|
||||
return array($query, $params);
|
||||
}
|
||||
}
|
||||
59
src/Reports/User/Reports/EmployeeLeavesReport.php
Normal file
59
src/Reports/User/Reports/EmployeeLeavesReport.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace Reports\User\Reports;
|
||||
|
||||
use Classes\BaseService;
|
||||
use Reports\Admin\Api\CSVReportBuilder;
|
||||
use Reports\Admin\Api\CSVReportBuilderInterface;
|
||||
use Utils\LogManager;
|
||||
|
||||
class EmployeeLeavesReport extends CSVReportBuilder implements CSVReportBuilderInterface
|
||||
{
|
||||
|
||||
public function getMainQuery()
|
||||
{
|
||||
$query = "SELECT
|
||||
(SELECT concat(`first_name`,' ',`middle_name`,' ', `last_name`) from Employees where id = employee) as 'Employee',
|
||||
(SELECT name from LeaveTypes where id = leave_type) as 'Leave Type',
|
||||
(SELECT name from LeavePeriods where id = leave_period) as 'Leave Period',
|
||||
date_start as 'Start Date',
|
||||
date_end as 'End Date',
|
||||
details as 'Reason',
|
||||
status as 'Leave Status',
|
||||
(select count(*) from EmployeeLeaveDays d where d.employee_leave = lv.id and leave_type = 'Full Day') as 'Full Day Count',
|
||||
(select count(*) from EmployeeLeaveDays d where d.employee_leave = lv.id and leave_type = 'Half Day - Morning') as 'Half Day (Morning) Count',
|
||||
(select count(*) from EmployeeLeaveDays d where d.employee_leave = lv.id and leave_type = 'Half Day - Afternoon') as 'Half Day (Afternoon) Count'
|
||||
from EmployeeLeaves lv";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getWhereQuery($request)
|
||||
{
|
||||
|
||||
if (($request['status'] != "NULL" && !empty($request['status']))) {
|
||||
$query = "where employee = ? and status = ? and ((date_start >= ? and date_start <= ?) or (date_end >= ? and date_end <= ?));";
|
||||
$params = array(
|
||||
BaseService::getInstance()->getCurrentProfileId(),
|
||||
$request['status'],
|
||||
$request['date_start'],
|
||||
$request['date_end'],
|
||||
$request['date_start'],
|
||||
$request['date_end']
|
||||
);
|
||||
} else {
|
||||
$query = "where employee = ? and ((date_start >= ? and date_start <= ?) or (date_end >= ? and date_end <= ?));";
|
||||
$params = array(
|
||||
BaseService::getInstance()->getCurrentProfileId(),
|
||||
$request['date_start'],
|
||||
$request['date_end'],
|
||||
$request['date_start'],
|
||||
$request['date_end']
|
||||
);
|
||||
}
|
||||
|
||||
LogManager::getInstance()->info("Query:".$query);
|
||||
LogManager::getInstance()->info("Params:".json_encode($params));
|
||||
|
||||
return array($query, $params);
|
||||
}
|
||||
}
|
||||
76
src/Reports/User/Reports/EmployeeTimeSheetData.php
Normal file
76
src/Reports/User/Reports/EmployeeTimeSheetData.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace Reports\User\Reports;
|
||||
|
||||
use Employees\Common\Model\Employee;
|
||||
use Reports\Admin\Api\ClassBasedReportBuilder;
|
||||
use Reports\Admin\Api\ReportBuilderInterface;
|
||||
use TimeSheets\Common\Model\EmployeeTimeSheet;
|
||||
use Utils\LogManager;
|
||||
|
||||
class EmployeeTimeSheetData extends ClassBasedReportBuilder implements ReportBuilderInterface
|
||||
{
|
||||
public function getData($report, $request)
|
||||
{
|
||||
|
||||
$employeeCache = array();
|
||||
|
||||
$employeeList = array();
|
||||
if (!empty($request['employee'])) {
|
||||
$employeeList = json_decode($request['employee'], true);
|
||||
}
|
||||
|
||||
if (in_array("NULL", $employeeList)) {
|
||||
$employeeList = array();
|
||||
}
|
||||
|
||||
$employee_query = "";
|
||||
if (!empty($employeeList)) {
|
||||
$employee_query = "employee in (".implode(",", $employeeList).") and ";
|
||||
}
|
||||
|
||||
$timeSheet = new EmployeeTimeSheet();
|
||||
if ($request['status'] != "NULL") {
|
||||
$timeSheets = $timeSheet->Find(
|
||||
$employee_query."status = ? and date_start >= ? and date_end <= ?",
|
||||
array($request['status'],$request['date_start'],$request['date_end'])
|
||||
);
|
||||
} else {
|
||||
$timeSheets = $timeSheet->Find(
|
||||
$employee_query."date_start >= ? and date_end <= ?",
|
||||
array($request['date_start'],$request['date_end'])
|
||||
);
|
||||
}
|
||||
|
||||
if (!$timeSheets) {
|
||||
LogManager::getInstance()->info($timeSheet->ErrorMsg());
|
||||
}
|
||||
|
||||
$reportData = array();
|
||||
$reportData[] = array("Employee ID","Employee","Name","Start","End","Total Time","Status");
|
||||
|
||||
foreach ($timeSheets as $ts) {
|
||||
$employee = $employeeCache[$ts->employee];
|
||||
if (empty($employee)) {
|
||||
$employee = new Employee();
|
||||
$employee->Load("id = ?", array($ts->employee));
|
||||
if (empty($employee->id)) {
|
||||
continue;
|
||||
}
|
||||
$employeeCache[$employee->id] = $employee;
|
||||
}
|
||||
$reportData[] = array(
|
||||
$employee->employee_id,
|
||||
$employee->first_name." ".$employee->last_name,
|
||||
date("F j, Y", strtotime($ts->date_start))
|
||||
." - "
|
||||
.date("F j, Y", strtotime($ts->date_end)),
|
||||
$ts->date_start,
|
||||
$ts->date_end,
|
||||
$ts->getTotalTime(),
|
||||
$ts->status
|
||||
);
|
||||
}
|
||||
|
||||
return $reportData;
|
||||
}
|
||||
}
|
||||
114
src/Reports/User/Reports/EmployeeTimeTrackReport.php
Normal file
114
src/Reports/User/Reports/EmployeeTimeTrackReport.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
namespace Reports\User\Reports;
|
||||
|
||||
use Attendance\Common\Model\Attendance;
|
||||
use Classes\BaseService;
|
||||
use Employees\Common\Model\Employee;
|
||||
use Reports\Admin\Api\ClassBasedReportBuilder;
|
||||
use Reports\Admin\Api\ReportBuilderInterface;
|
||||
use TimeSheets\Common\Model\EmployeeTimeEntry;
|
||||
|
||||
class EmployeeTimeTrackReport extends ClassBasedReportBuilder implements ReportBuilderInterface
|
||||
{
|
||||
public function getData($report, $req)
|
||||
{
|
||||
|
||||
$req['employee'] = BaseService::getInstance()->getCurrentProfileId();
|
||||
|
||||
$employeeTimeEntry = new EmployeeTimeEntry();
|
||||
|
||||
$timeEntryList = $employeeTimeEntry->Find(
|
||||
"employee = ? and date(date_start) >= ? and date(date_end) <= ?",
|
||||
array($req['employee'], $req['date_start'], $req['date_end'])
|
||||
);
|
||||
|
||||
|
||||
$seconds = 0;
|
||||
$graphTimeArray = array();
|
||||
foreach ($timeEntryList as $entry) {
|
||||
$seconds = (strtotime($entry->date_end) - strtotime($entry->date_start));
|
||||
$key = date("Y-m-d", strtotime($entry->date_end));
|
||||
if (isset($graphTimeArray[$key])) {
|
||||
$graphTimeArray[$key] += $seconds;
|
||||
} else {
|
||||
$graphTimeArray[$key] = $seconds;
|
||||
}
|
||||
}
|
||||
|
||||
//$minutes = (int)($seconds/60);
|
||||
|
||||
|
||||
//Find Attendance Entries
|
||||
|
||||
$attendance = new Attendance();
|
||||
$atteandanceList = $attendance->Find("employee = ? and date(in_time) >= ? and date(out_time) <= ? and in_time < out_time", array($req['employee'], $req['date_start'], $req['date_end']));
|
||||
|
||||
$seconds = 0;
|
||||
$graphAttendanceArray = array();
|
||||
$firstTimeInArray = array();
|
||||
$lastTimeOutArray = array();
|
||||
foreach ($atteandanceList as $entry) {
|
||||
$seconds = (strtotime($entry->out_time) - strtotime($entry->in_time));
|
||||
$key = date("Y-m-d", strtotime($entry->in_time));
|
||||
if (isset($graphAttendanceArray[$key])) {
|
||||
$graphAttendanceArray[$key] += $seconds;
|
||||
$lastTimeOutArray[$key] = $entry->out_time;
|
||||
} else {
|
||||
$graphAttendanceArray[$key] = $seconds;
|
||||
$firstTimeInArray[$key] = $entry->in_time;
|
||||
$lastTimeOutArray[$key] = $entry->out_time;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////
|
||||
|
||||
$employeeObject = new Employee();
|
||||
$employeeObject->Load("id = ?", array($req['employee']));
|
||||
|
||||
|
||||
$reportData = array();
|
||||
//$reportData[] = array($employeeObject->first_name." ".$employeeObject->last_name,"","","","");
|
||||
$reportData[] = array("Date","First Punch-In Time","Last Punch-Out Time","Time in Office","Time in Timesheets");
|
||||
|
||||
|
||||
//Iterate date range
|
||||
|
||||
$interval = \DateInterval::createFromDateString('1 day');
|
||||
$period = new \DatePeriod(new \DateTime($req['date_start']), $interval, new \DateTime($req['date_end']));
|
||||
|
||||
foreach ($period as $dt) {
|
||||
$dataRow = array();
|
||||
$key = $dt->format("Y-m-d");
|
||||
|
||||
$dataRow[] = $key;
|
||||
|
||||
if (isset($firstTimeInArray[$key])) {
|
||||
$dataRow[] = $firstTimeInArray[$key];
|
||||
} else {
|
||||
$dataRow[] = "Not Found";
|
||||
}
|
||||
|
||||
if (isset($lastTimeOutArray[$key])) {
|
||||
$dataRow[] = $lastTimeOutArray[$key];
|
||||
} else {
|
||||
$dataRow[] = "Not Found";
|
||||
}
|
||||
|
||||
if (isset($graphAttendanceArray[$key])) {
|
||||
$dataRow[] = round(($graphAttendanceArray[$key]/3600), 2);
|
||||
} else {
|
||||
$dataRow[] = 0;
|
||||
}
|
||||
|
||||
if (isset($graphTimeArray[$key])) {
|
||||
$dataRow[] = round(($graphTimeArray[$key]/3600), 2);
|
||||
} else {
|
||||
$dataRow[] = 0;
|
||||
}
|
||||
|
||||
$reportData[] = $dataRow;
|
||||
}
|
||||
return $reportData;
|
||||
}
|
||||
}
|
||||
78
src/Reports/User/Reports/EmployeeTimesheetReport.php
Normal file
78
src/Reports/User/Reports/EmployeeTimesheetReport.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
namespace Reports\User\Reports;
|
||||
|
||||
use Classes\BaseService;
|
||||
use Projects\Common\Model\Project;
|
||||
use Reports\Admin\Api\CSVReportBuilder;
|
||||
use Reports\Admin\Api\CSVReportBuilderInterface;
|
||||
use Utils\LogManager;
|
||||
|
||||
class EmployeeTimesheetReport extends CSVReportBuilder implements CSVReportBuilderInterface
|
||||
{
|
||||
|
||||
public function getMainQuery()
|
||||
{
|
||||
$query = "SELECT
|
||||
(SELECT concat(`first_name`,' ',`middle_name`,' ', `last_name`) from Employees where id = te.employee) as 'Employee',
|
||||
(SELECT name from Projects where id = te.project) as 'Project',
|
||||
details as 'Details',
|
||||
date_start as 'Start Time',
|
||||
date_end as 'End Time',
|
||||
SEC_TO_TIME(TIMESTAMPDIFF(SECOND,te.date_start,te.date_end)) as 'Duration'
|
||||
FROM EmployeeTimeEntry te";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getWhereQuery($request)
|
||||
{
|
||||
|
||||
if (($request['client'] != "NULL" && !empty($request['client']))) {
|
||||
if (($request['project'] != "NULL" && !empty($request['project']))) {
|
||||
$query = "where employee = ? and project = ? and date_start >= ? and date_end <= ?;";
|
||||
$params = array(
|
||||
BaseService::getInstance()->getCurrentProfileId(),
|
||||
$request['project'],
|
||||
$request['date_start'],
|
||||
$request['date_end']
|
||||
);
|
||||
} else {
|
||||
$project = new Project();
|
||||
$projects = $project->Find("client = ?", array($request['client']));
|
||||
$projectIds = array();
|
||||
foreach ($projects as $project) {
|
||||
$projectIds[] = $project->id;
|
||||
}
|
||||
|
||||
$query = "where project in (".implode(",", $projectIds).") and employee = ? and date_start >= ? and date_end <= ?;";
|
||||
$params = array(
|
||||
BaseService::getInstance()->getCurrentProfileId(),
|
||||
$request['date_start'],
|
||||
$request['date_end']
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (($request['project'] != "NULL" && !empty($request['project']))) {
|
||||
$query = "where employee = ? and project = ? and date_start >= ? and date_end <= ?;";
|
||||
$params = array(
|
||||
BaseService::getInstance()->getCurrentProfileId(),
|
||||
$request['project'],
|
||||
$request['date_start'],
|
||||
$request['date_end']
|
||||
);
|
||||
} else {
|
||||
$query = "where employee = ? and date_start >= ? and date_end <= ?;";
|
||||
$params = array(
|
||||
BaseService::getInstance()->getCurrentProfileId(),
|
||||
$request['date_start'],
|
||||
$request['date_end']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
LogManager::getInstance()->info("Query:".$query);
|
||||
LogManager::getInstance()->info("Params:".json_encode($params));
|
||||
|
||||
return array($query, $params);
|
||||
}
|
||||
}
|
||||
52
src/Reports/User/Reports/ExpenseReport.php
Normal file
52
src/Reports/User/Reports/ExpenseReport.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace Reports\User\Reports;
|
||||
|
||||
use Classes\BaseService;
|
||||
use Reports\Admin\Api\CSVReportBuilder;
|
||||
use Reports\Admin\Api\CSVReportBuilderInterface;
|
||||
|
||||
class ExpenseReport extends CSVReportBuilder implements CSVReportBuilderInterface
|
||||
{
|
||||
|
||||
public function getMainQuery()
|
||||
{
|
||||
$query = "SELECT
|
||||
(SELECT concat(`first_name`,' ',`middle_name`,' ', `last_name`) from Employees where id = employee) as 'Employee',
|
||||
expense_date as 'Date',
|
||||
(SELECT name from ExpensesPaymentMethods where id = payment_method) as 'Payment Method',
|
||||
transaction_no as 'Transaction Ref',
|
||||
payee as 'Payee',
|
||||
(SELECT name from ExpensesCategories where id = category) as 'Category',
|
||||
notes as 'Notes',
|
||||
concat(`amount`,' ',`currency`) as 'Amount',
|
||||
status as 'Status',
|
||||
created as 'Created',
|
||||
updated as 'Updated'
|
||||
from EmployeeExpenses";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getWhereQuery($request)
|
||||
{
|
||||
|
||||
if (($request['status'] != "NULL" && !empty($request['status']))) {
|
||||
$query = "where employee = ? and status = ? and date(expense_date) >= ? and date(expense_date) <= ?;";
|
||||
$params = array(
|
||||
BaseService::getInstance()->getCurrentProfileId(),
|
||||
$request['status'],
|
||||
$request['date_start'],
|
||||
$request['date_end']
|
||||
);
|
||||
} else {
|
||||
$query = "where employee = ? and date(expense_date) >= ? and date(expense_date) <= ?;";
|
||||
$params = array(
|
||||
BaseService::getInstance()->getCurrentProfileId(),
|
||||
$request['date_start'],
|
||||
$request['date_end']
|
||||
);
|
||||
}
|
||||
|
||||
return array($query, $params);
|
||||
}
|
||||
}
|
||||
86
src/Reports/User/Reports/OvertimeReport.php
Normal file
86
src/Reports/User/Reports/OvertimeReport.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
namespace Reports\User\Reports;
|
||||
|
||||
use Attendance\Common\Model\Attendance;
|
||||
use Classes\BaseService;
|
||||
use Classes\SettingsManager;
|
||||
use Employees\Common\Model\Employee;
|
||||
use Reports\Admin\Api\ClassBasedReportBuilder;
|
||||
use Reports\Admin\Api\ReportBuilderInterface;
|
||||
|
||||
class OvertimeReport extends ClassBasedReportBuilder implements ReportBuilderInterface
|
||||
{
|
||||
public function getData($report, $request)
|
||||
{
|
||||
|
||||
$employeeList = array();
|
||||
$employeeList[] = BaseService::getInstance()->getCurrentProfileId();
|
||||
|
||||
$sevenDateBefore = date('Y-m-d', strtotime('-7 days', strtotime($request['date_start'])));
|
||||
|
||||
$query = "employee in (".implode(",", $employeeList).") and in_time >= ? and out_time <= ? order by in_time;";
|
||||
$params = array(
|
||||
$sevenDateBefore." 00:00:00",
|
||||
$request['date_end']." 23:59:59",
|
||||
);
|
||||
|
||||
$at = new Attendance();
|
||||
$attendance = $at->Find($query, $params);
|
||||
|
||||
//Group records by employee
|
||||
$employeeAttendance = array();
|
||||
foreach ($attendance as $entry) {
|
||||
if (!isset($employeeAttendance[$entry->employee])) {
|
||||
$employeeAttendance[$entry->employee] = array();
|
||||
}
|
||||
|
||||
$employeeAttendance[$entry->employee][] = $entry;
|
||||
}
|
||||
|
||||
$atCalClassName = SettingsManager::getInstance()->getSetting('Attendance: Overtime Calculation Class');
|
||||
$atCalClassName = '\\Attendance\\Common\\Calculations\\'.$atCalClassName;
|
||||
$atCal = new $atCalClassName();
|
||||
|
||||
$reportData = array();
|
||||
if (!$this->isAggregated()) {
|
||||
$reportData[] = array("Date", "Employee ID", "Employee", "Time in Office", "Regular Time", "Overtime", "Double Time");
|
||||
} else {
|
||||
$reportData[] = array("Employee ID", "Employee", "Time in Office", "Regular Time", "Overtime", "Double Time");
|
||||
}
|
||||
|
||||
foreach ($employeeAttendance as $employeeId => $atData) {
|
||||
$employee = new Employee();
|
||||
$employee->Load("id = ?", array($employeeId));
|
||||
$atSum = $atCal->getData($atData, $request['date_start'], $this->isAggregated());
|
||||
if (!$this->isAggregated()) {
|
||||
foreach ($atSum as $date => $counts) {
|
||||
$reportData[] = array(
|
||||
$date,
|
||||
$employee->employee_id,
|
||||
$employee->first_name." ".$employee->last_name,
|
||||
$counts['t'],
|
||||
$counts['r'],
|
||||
$counts['o'],
|
||||
$counts['d']
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$reportData[] = array(
|
||||
$employee->employee_id,
|
||||
$employee->first_name." ".$employee->last_name,
|
||||
$atSum['t'],
|
||||
$atSum['r'],
|
||||
$atSum['o'],
|
||||
$atSum['d']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $reportData;
|
||||
}
|
||||
|
||||
protected function isAggregated()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
10
src/Reports/User/Reports/OvertimeSummaryReport.php
Normal file
10
src/Reports/User/Reports/OvertimeSummaryReport.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace Reports\User\Reports;
|
||||
|
||||
class OvertimeSummaryReport extends OvertimeReport
|
||||
{
|
||||
protected function isAggregated()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
74
src/Reports/User/Reports/PayslipReport.php
Normal file
74
src/Reports/User/Reports/PayslipReport.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace Reports\User\Reports;
|
||||
|
||||
use Classes\BaseService;
|
||||
use Payroll\Common\Model\Payroll;
|
||||
use Payroll\Common\Model\PayrollColumn;
|
||||
use Payroll\Common\Model\PayrollData;
|
||||
use Payroll\Common\Model\PayslipTemplate;
|
||||
use Reports\Admin\Api\PDFReportBuilder;
|
||||
use Reports\Admin\Api\PDFReportBuilderInterface;
|
||||
|
||||
class PayslipReport extends PDFReportBuilder implements PDFReportBuilderInterface
|
||||
{
|
||||
public function getData($report, $request)
|
||||
{
|
||||
$data = $this->getDefaultData();
|
||||
|
||||
$data['fields'] = array();
|
||||
|
||||
$payroll = new Payroll();
|
||||
$payroll->Load("id = ?", array($request['payroll']));
|
||||
|
||||
if (empty($payroll->payslipTemplate)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$payslipTemplate = new PayslipTemplate();
|
||||
$payslipTemplate->Load("id = ?", array($payroll->payslipTemplate));
|
||||
|
||||
if (empty($payslipTemplate->id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$fields = json_decode($payslipTemplate->data, true);
|
||||
|
||||
foreach ($fields as $field) {
|
||||
if ($field['type'] == 'Payroll Column') {
|
||||
$col = new PayrollColumn();
|
||||
$col->Load("id = ?", $field['payrollColumn']);
|
||||
if (empty($col->id)) {
|
||||
continue;
|
||||
}
|
||||
$payrollData = new PayrollData();
|
||||
$payrollData->Load(
|
||||
"payroll = ? and payroll_item = ? and employee = ?",
|
||||
array(
|
||||
$request['payroll'],
|
||||
$col->id, BaseService::getInstance()->getCurrentProfileId()
|
||||
)
|
||||
);
|
||||
|
||||
if (empty($payrollData->id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$field['value'] = $payrollData->amount;
|
||||
|
||||
if (empty($field['label'])) {
|
||||
$field['label'] = $col->name;
|
||||
}
|
||||
}
|
||||
|
||||
if ($field['status'] == 'Show') {
|
||||
$data['fields'][] = $field;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getTemplate()
|
||||
{
|
||||
return "payslip.html";
|
||||
}
|
||||
}
|
||||
53
src/Reports/User/Reports/TravelRequestReport.php
Normal file
53
src/Reports/User/Reports/TravelRequestReport.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace Reports\User\Reports;
|
||||
|
||||
use Classes\BaseService;
|
||||
use Reports\Admin\Api\CSVReportBuilder;
|
||||
use Reports\Admin\Api\CSVReportBuilderInterface;
|
||||
|
||||
class TravelRequestReport extends CSVReportBuilder implements CSVReportBuilderInterface
|
||||
{
|
||||
|
||||
public function getMainQuery()
|
||||
{
|
||||
$query = "SELECT
|
||||
(SELECT concat(`first_name`,' ',`middle_name`,' ', `last_name`) from Employees where id = employee) as 'Employee',
|
||||
type as 'Type',
|
||||
purpose as 'Purpose',
|
||||
travel_from as 'Travel From',
|
||||
travel_to as 'Travel To',
|
||||
travel_date as 'Travel Date',
|
||||
return_date as 'Return Date',
|
||||
details as 'Other Details',
|
||||
concat(`funding`,' ',`currency`) as 'Funding',
|
||||
status as 'Status',
|
||||
created as 'Created',
|
||||
updated as 'Updated'
|
||||
from EmployeeTravelRecords";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getWhereQuery($request)
|
||||
{
|
||||
|
||||
if (($request['status'] != "NULL" && !empty($request['status']))) {
|
||||
$query = "where employee = ? and status = ? and date(travel_date) >= ? and date(return_date) <= ?;";
|
||||
$params = array(
|
||||
BaseService::getInstance()->getCurrentProfileId(),
|
||||
$request['status'],
|
||||
$request['date_start'],
|
||||
$request['date_end']
|
||||
);
|
||||
} else {
|
||||
$query = "where employee = ? and date(travel_date) >= ? and date(return_date) <= ?;";
|
||||
$params = array(
|
||||
BaseService::getInstance()->getCurrentProfileId(),
|
||||
$request['date_start'],
|
||||
$request['date_end']
|
||||
);
|
||||
}
|
||||
|
||||
return array($query, $params);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user