Commit 711525f0 by Azhan Hannan

Report Overtime

parent 27db5a1f
<?php
namespace App\Exports;
use App\User;
use Portal\Timesheet\Model\Department;
use Portal\Timesheet\Model\VwStaff;
use Portal\Timesheet\Model\VwProject;
use Portal\Timesheet\Model\VwOverhead;
use Portal\Timesheet\Model\Ts_master;
// use Illuminate\Contracts\Support\Responsable;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
// class UsersExport implements FromCollection, Responsable
class OvertimeExport implements FromView, ShouldAutoSize, WithColumnWidths, WithStyles
{
use Exportable;
// private $fileName = "Ringkasan Laporan.xlsx";
protected $request;
function __construct($request) {
$this->request = $request;
}
/**
* @return \Illuminate\Support\Collection
*/
public function styles(Worksheet $sheet)
{
$sheet->getStyle('1')->getFont()->setBold(true);
$sheet->getStyle('2')->getFont()->setBold(true);
$sheet->getStyle('4')->getFont()->setBold(true);
}
public function columnWidths(): array
{
return [
'A' => 10,
'B' => 20,
'C' => 20,
'D' => 20,
'E' => 20,
'F' => 20
];
}
public function view(): View
{
// dd($this->request);
$month = $this->request['month'];
$year = $this->request['year'];
$dept = $this->request['dept'];
$staffs = VwStaff::where('deptID', $dept)->get();
$staffsid = [];
foreach ($staffs as $key => $staff) {
$staffsid[] = data_get($staff,'staffid');
}
return view('timesheet::exports.exportOvertime', [
'dept' => Department::where('id', $dept)->first(),
'month'=> $month,
'year' => $year,
'staffs' => VwStaff::where('deptID', $dept)->get(),
'tmaster' => Ts_master::where('tm_year',$year)
->where('tm_month',$month)
->whereIn('tm_staff_id', $staffsid)
->where('tm_timesheet_master_sts',4)
->get(),
]);
}
}
<table class="ui unstackable celled table">
<thead>
<tr><th></th>
<th style="width: 10%">Department</th>
<th style="width: 1%">:</th>
<th colspan="2">{{ data_get($dept,'description') }}</th>
</tr>
<tr>
<th></th>
<th style="width: 10%"> Month/Year</th>
<th style="width: 1%">:</th>
<th colspan="2"> {{ date('F', mktime(0, 0, 0, $month, 10)) }} {{$year}}</th>
</tr>
</thead>
</table>
<table class="ui unstackable celled table">
<thead>
<th class="center aligned">No</th>
<th>Name</th>
<th class="center aligned">Staff No</th>
<th class="center aligned">Total Hours</th>
<th class="center aligned">Total Days</th>
<th class="center aligned">Total Overtime Hours</th>
<th class="center aligned">Total Overtime Days</th>
</thead>
<tbody>
@foreach($staffs as $key => $staff)
<?php
$sum = 0;
$overtime = 0;
?>
<tr>
<td class="center aligned">{{$key+1}}</td>
<td>{{ data_get($staff,'name') }}</td>
<td class="center aligned">{{ data_get($staff,'staffid') }}</td>
<td class="center aligned">
<?php
$timesheet = $tmaster->where('tm_staff_id', data_get($staff,'staffid'));
foreach ($timesheet as $key => $value) {
$sum += data_get($value,'tm_total_hours');
}
?>
@if($sum == 0)
@else
{{ number_format($sum, 1, '.', '') }}
@endif
</td>
<td class="center aligned">
@if($sum/8 == 0)
@else
{{ number_format($sum/8, 1, '.', '') }}
@endif
</td>
<td class="center aligned">
<?php
$timesheet = $tmaster->where('tm_staff_id', data_get($staff,'staffid'));
foreach ($timesheet as $key => $value) {
$overtime += data_get($value,'tm_overtime_hrs');
}
?>
@if($overtime == 0)
@else
{{ number_format($overtime, 1, '.', '') }}
@endif
</td>
<td class="center aligned">
@if($overtime/8 == 0)
@else
{{ number_format($overtime/8, 1, '.', '') }}
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
\ No newline at end of file
@extends('ui::layouts.app')
@section('content')
<div class="ui segment">
<a class="ui green left ribbon label">Overtime Report</a>
<br><br>
<form class="ui form" action="{{ route('timesheet::report.generateOvertimeReport') }}" method="POST">
{{csrf_field()}}
<div class="one fields">
<div class="six wide field">
<label>Department</label>
<select name="dept" class="ui fluid dropdown" required="required">
@foreach($dept as $key => $value)
<option value="{{data_get($value,'id')}}">{{data_get($value,'code')}} | {{data_get($value,'description')}}</option>
@endforeach
</select>
</div>
</div>
<div class="two fields">
<div class="three wide field">
<label>Year</label>
<select name="year" class="ui fluid dropdown" required="required">
@foreach($year as $key => $value)
<option value="{{ data_get($value,'tm_year') }}">{{ data_get($value,'tm_year') }}</option>
@endforeach
</select>
</div>
<div class="three wide field">
<label>Month</label>
<select name="month" class="ui fluid dropdown" required="required">
@foreach($month as $key => $value)
<option value="{{ $key+1 }}">{{ $value }}</option>
@endforeach
</select>
</div>
</div>
<button class="ui olive button" type="submit">Generate Report</button>
</form>
</div>
@endsection
\ No newline at end of file
@extends('ui::layouts.app')
@section('content')
<div class="ui segment">
<div class="ui purple left ribbon label">
Report by Project
</div>
<button class="right floated center aligned ui violet compact labeled icon button" onclick="window.location.href='{{ route('timesheet::export.exportovertime', ['month'=> $intmonth, 'year'=> $year, 'dept'=>$dept->id]) }}';">
<i class="file excel outline icon"></i>
Export to Excel
</button>
<br><br>
<div class="ui styled fluid">
<div class="title">
<table class="ui unstackable celled table">
<thead>
<tr>
<th style="width: 10%">Department</th>
<th style="width: 1%">:</th>
<th colspan="2">{{ data_get($dept,'description') }}</th>
</tr>
<tr>
<th style="width: 10%"> Month/Year</th>
<th style="width: 1%">:</th>
<th colspan="2"> {{$month}} {{$year}}</th>
</tr>
</thead>
</table>
<table class="ui unstackable celled table">
<thead>
<th class="center aligned">No</th>
<th>Name</th>
<th class="center aligned">Staff No</th>
<th class="center aligned">Total Hours</th>
<th class="center aligned">Total Days</th>
<th class="center aligned">Total Overtime Hours</th>
<th class="center aligned">Total Overtime Days</th>
</thead>
<tbody>
<?php
// dd($tmaster);
?>
@foreach($staffs as $key => $staff)
<?php
$sum = 0;
$overtime = 0;
?>
<tr>
<td class="center aligned">{{$key+1}}</td>
<td>{{ data_get($staff,'name') }}</td>
<td class="center aligned">{{ data_get($staff,'staffid') }}</td>
<td class="center aligned">
<?php
$timesheet = $tmaster->where('tm_staff_id', data_get($staff,'staffid'));
foreach ($timesheet as $key => $value) {
$sum += data_get($value,'tm_total_hours');
}
?>
@if($sum == 0)
@else
{{ number_format($sum, 1, '.', '') }}
@endif
</td>
<td class="center aligned">
@if($sum/8 == 0)
@else
{{ number_format($sum/8, 1, '.', '') }}
@endif
</td>
<td class="center aligned">
<?php
$timesheet = $tmaster->where('tm_staff_id', data_get($staff,'staffid'));
foreach ($timesheet as $key => $value) {
$overtime += data_get($value,'tm_overtime_hrs');
}
?>
@if($overtime == 0)
@else
{{ number_format($overtime, 1, '.', '') }}
@endif
</td>
<td class="center aligned">
@if($overtime/8 == 0)
@else
{{ number_format($overtime/8, 1, '.', '') }}
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
@endsection
@push('script')
@endpush
\ No newline at end of file
......@@ -13,6 +13,7 @@ Route::group(
Route::get('ringkasan/export/', ['uses' => 'ExportController@export', 'as' => 'export.exportsummary']);
Route::get('project/export/', ['uses' => 'ExportController@exportproject', 'as' => 'export.exportproject']);
Route::get('department/export/', ['uses' => 'ExportController@exportdepartment', 'as' => 'export.exportdepartment']);
Route::get('overtime/export/', ['uses' => 'ExportController@exportovertime', 'as' => 'export.exportovertime']);
//dashboard
Route::get('home',['uses' => 'DashboardController@index', 'as' => 'dashboard.index']);
......@@ -54,6 +55,8 @@ Route::group(
Route::post('generateprojectreport', ['uses' => 'ReportController@generateprojectreport', 'as' => 'report.generateprojectreport']);
Route::get('deptreport', ['uses' => 'ReportController@deptreport', 'as' => 'report.deptreport']);
Route::post('generatedeptreport', ['uses' => 'ReportController@generatedeptreport', 'as' => 'report.generatedeptreport']);
Route::get('filterOvertime', ['uses' => 'ReportController@filterOvertime', 'as' => 'report.filterOvertime']);
Route::post('generateOvertimeReport', ['uses' => 'ReportController@generateOvertimeReport', 'as' => 'report.generateOvertimeReport']);
//maintenance
Route::get('senaraiProject',['uses' => 'MaintenanceController@senaraiProject', 'as' => 'maintenance.senaraiProject']);
......@@ -115,7 +118,6 @@ Route::group(
Route::get('deletedraft',['uses' => 'FormController@deletedraft', 'as' => 'form.deletedraft']);
Route::get('draftdeleted',['uses' => 'FormController@draftdeleted', 'as' => 'form.draftdeleted']);
// nonChargeableForm
// Route::get('nonChargeableForm',['uses' => 'FormController@nonChargeableForm', 'as' => 'form.nonChargeableForm']);
// Route::post('savenonchargeablehours',['uses' => 'FormController@savenonchargeablehours', 'as' => 'form.savenonchargeablehours']);
......
......@@ -1490,7 +1490,6 @@ class DashboardController extends Controller
];
}
}
}
}
......
......@@ -38,6 +38,7 @@ use Auth;
use App\Exports\RingkasanExport;
use App\Exports\ProjectExport;
use App\Exports\DepartmentExport;
use App\Exports\OvertimeExport;
use Maatwebsite\Excel\Facades\Excel;
class ExportController extends Controller
......@@ -100,4 +101,23 @@ class ExportController extends Controller
]))->download(data_get($dept,'code').' Report '.$month.' '.$year.'.xlsx');
}
public function exportovertime(Request $request)
{
$month = date('F', mktime(0,0,0,$request->month, 1, date('Y')));
$year = strval($request->year);
$dept = Department::where('id', $request->dept)->first();
// dd($dept);
return (new OvertimeExport(
[
'dept' => $request->dept,
'month' => $request->month,
'year' => $request->year
]))->download(data_get($dept,'code').' Overtime Report '.$month.' '.$year.'.xlsx');
}
}
\ No newline at end of file
......@@ -271,4 +271,53 @@ class ReportController extends Controller
return view('timesheet::report.department', compact('intmonth','year', 'month', 'dept', 'staffs', 'project', 'overhead'));
}
public function filterOvertime()
{
$dept = Department::all()
->except([8]);
$month = [];
for ($m=1; $m<=12; $m++) {
$month[] = date('F', mktime(0,0,0,$m, 1, date('Y')));
}
$year = Ts_master::select('tm_year')
->where('tm_timesheet_master_sts', 4)
->distinct('tm_year')
->orderby('tm_year','DESC')
->get();
return view('timesheet::report.filterOvertime', compact('month', 'year', 'dept'));
}
public function generateOvertimeReport(Request $request)
{
$dept = Department::where('id', $request->dept)->first();
$staffs = VwStaff::where('deptID', $request->dept)->get();
$staffsid = [];
foreach ($staffs as $key => $staff) {
$staffsid[] = data_get($staff,'staffid');
}
$year = date('Y');
if ($request->year) {
$year = $request->year;
}
$intmonth = $request->month;
$month = date('F', mktime(0,0,0,$request->month, 1, date('Y')));
$tmaster = Ts_master::where('tm_year',$year)
->where('tm_month',data_get($request,'month'))
->whereIn('tm_staff_id', $staffsid)
->where('tm_timesheet_master_sts',4)
->get();
return view('timesheet::report.overtime', compact('intmonth','year', 'month', 'dept', 'staffs', 'tmaster'));
}
}
\ No newline at end of file
......@@ -116,6 +116,10 @@ class ServiceProvider extends BaseServiceProvider
->data('icon', 'file alternate outline icon')
->active('laporan/*')
->data('permission', Permission::laporan);
$laporan->add(__('Overtime Report'), route('timesheet::report.filterOvertime'))
->data('icon', 'file alternate outline icon')
->active('laporan/*')
->data('permission', Permission::laporan);
$laporan->add(__('Staff Timesheets'), route('timesheet::dashboard.filterHrStaffsTimesheet'))
->data('icon', 'file alternate outline icon')
->active('laporan/*')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment