Commit 5d27cac0 by hannan

export to excel -> report by department

parent 41c9baba
<?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 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;
// class UsersExport implements FromCollection, Responsable
class DepartmentExport implements FromView, ShouldAutoSize
{
use Exportable;
// private $fileName = "Ringkasan Laporan.xlsx";
protected $request;
function __construct($request) {
$this->request = $request;
}
/**
* @return \Illuminate\Support\Collection
*/
public function view(): View
{
// dd($this->request);
$month = $this->request['month'];
$year = $this->request['year'];
$dept = $this->request['dept'];
return view('timesheet::exports.exportDepartment', [
'dept' => Department::where('id', $dept)->first(),
'month'=> $month,
'year' => $year,
'staffs' => VwStaff::where('deptID', $dept)->get(),
'project' => VwProject::where('deptid', $dept)
->where('month', $month)
->where('year', $year)
->get(),
'overhead' => VwOverhead::where('deptid', $dept)
->where('month', $month)
->where('year', $year)
->get(),
]);
}
}
<table>
<thead>
<tr>
<th>Department </th>
<th>:</th>
<th colspan="3"> {{data_get($dept,'description')}} </th>
</tr>
<tr>
<th> Month/Year</th>
<th>:</th>
<th colspan="3"> {{$month}} {{$year}}</th>
</tr>
</thead>
</table>
<table>
<thead>
<tr>
<th>staff</th>
<th>project type</th>
<th>project code / task</th>
<th>description</th>
<th>total hours</th>
<th>total days</th>
</tr>
</thead>
<?php $totalhours = $totaldays = $staffhours = $staffdays = 0; ?>
@foreach($staffs as $key => $staff)
<tbody>
<tr>
<td colspan="6">{{data_get($staff,'name')}}</td>
</tr>
<?php
$chargeproject = $project->where('ptype', 1);
$chargehours = $chargedays = 0;
?>
@foreach($chargeproject as $key => $chargeable)
@if(data_get($chargeable,'staffid') == data_get($staff,'staffid'))
<tr>
<td></td>
<td>C</td>
<td>{{data_get($chargeable,'pcode')}}</td>
<td>{{data_get($chargeable,'pname')}}</td>
<td>{{data_get($chargeable,'hours')}}</td>
<td>{{number_format(data_get($chargeable,'hours')/8, '1', '.', '')}}</td>
</tr>
<?php
$chargehours += data_get($chargeable,'hours');
$chargedays += number_format(data_get($chargeable,'hours')/8, '1', '.', '');
?>
@endif
@endforeach
<?php
$nonchargeproject = $project->where('ptype', 2);
$nonchargehours = $nonchargedays = 0;
?>
@foreach($nonchargeproject as $key => $nonchargeable)
@if(data_get($nonchargeable,'staffid') == data_get($staff,'staffid'))
<tr>
<td></td>
<td>NC</td>
<td>{{data_get($nonchargeable,'pcode')}}</td>
<td>{{data_get($nonchargeable,'pname')}}</td>
<td>{{data_get($nonchargeable,'hours')}}</td>
<td>{{number_format(data_get($nonchargeable,'hours')/8, '1', '.', '')}}</td>
</tr>
<?php
$nonchargehours += data_get($nonchargeable,'hours');
$nonchargedays += number_format(data_get($nonchargeable,'hours')/8, '1', '.', '');
?>
@endif
@endforeach
<?php
$overheadhours = $overheaddays = 0;
?>
@foreach($overhead as $key => $value)
@if(data_get($value,'staffid') == data_get($staff,'staffid'))
<tr>
<td></td>
<td>NC</td>
<td></td>
<td>{{data_get($value,'pname')}}</td>
<td>{{data_get($value,'hours')}}</td>
<td>{{number_format(data_get($value,'hours')/8, '1', '.', '')}}</td>
</tr>
<?php
$overheadhours += data_get($value,'hours');
$overheaddays += number_format(data_get($value,'hours')/8, '1', '.', '');
?>
@endif
@endforeach
<?php
$staffhours = $chargehours+$nonchargehours+$overheadhours;
$staffdays = $chargedays+$nonchargedays+$overheaddays;
?>
<tr>
<td colspan="3"></td>
<td>Total</td>
<td>{{$staffhours}}</td>
<td>{{$staffdays}}</td>
</tr>
</tbody>
<?php
$totalhours += $staffhours;
$totaldays += $staffdays;
?>
@endforeach
<tfoot>
<tr>
<th colspan="3"><strong>Total</strong></th>
<th></th>
<th><strong>{{$totalhours}}</strong></th>
<th><strong>{{$totaldays}}</strong></th>
</tr>
</tfoot>
</table>
\ No newline at end of file
<table class="ui unstackable celled table"> <table>
<thead> <thead>
<tr> <tr>
<th style="width: 10%">Project </th> <th>Project </th>
<th style="width: 1%">:</th> <th>:</th>
<th colspan="3"> {{data_get($pdetail,'pcode')}} - {{data_get($pdetail,'pname')}}</th> <th colspan="3"> {{data_get($pdetail,'pcode')}} - {{data_get($pdetail,'pname')}}</th>
</tr> </tr>
<tr> <tr>
<th style="width: 10%"> Month/Year</th> <th> Month/Year</th>
<th style="width: 1%">:</th> <th>:</th>
<th colspan="3"> {{$month}} {{$year}}</th> <th colspan="3"> {{$month}} {{$year}}</th>
</tr> </tr>
</thead> </thead>
</table> </table>
<table class="ui unstackable celled table"> <table>
<thead> <thead>
<tr> <tr>
<th style="width: 45%">Staff Name</th> <th>Staff Name</th>
<th style="width: 25%" class="center aligned">Role</th> <th>Role</th>
<th style="width: 15%" class="center aligned">Total Hours</th> <th>Total Hours</th>
<th style="width: 15%" class="center aligned">Total Days</th> <th>Total Days</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php $totalhours = $totaldays = 0; ?> <?php $totalhours = $totaldays = 0; ?>
@foreach($pteam as $key => $team) @foreach($pteam as $key => $team)
<tr> <tr>
<td style="width: 40%">{{data_get($team,'name')}}</td> <td>{{data_get($team,'name')}}</td>
<td style="width: 30%" class="center aligned">{{data_get($team,'role')}}</td> <td>{{data_get($team,'role')}}</td>
<td style="width: 15%" class="center aligned"> <td>
@foreach($ptdetail as $key => $hours) @foreach($ptdetail as $key => $hours)
@if(data_get($hours,'staffid') == data_get($team,'staffid')) @if(data_get($hours,'staffid') == data_get($team,'staffid'))
{{data_get($hours,'hours')}} {{data_get($hours,'hours')}}
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
@endif @endif
@endforeach @endforeach
</td> </td>
<td style="width: 15%" class="center aligned"> <td>
@foreach($ptdetail as $key => $hours) @foreach($ptdetail as $key => $hours)
@if(data_get($hours,'staffid') == data_get($team,'staffid')) @if(data_get($hours,'staffid') == data_get($team,'staffid'))
{{number_format(data_get($hours,'hours')/8, 1, '.', '')}} {{number_format(data_get($hours,'hours')/8, 1, '.', '')}}
...@@ -46,12 +46,12 @@ ...@@ -46,12 +46,12 @@
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>
<tfoot class="full-width"> <tfoot>
<tr> <tr>
<th style="width: 40%"><strong>Total</strong></th> <th><strong>Total</strong></th>
<th style="width: 30%"></th> <th></th>
<th style="width: 15%" class="center aligned"><strong>{{$totalhours}}</strong></th> <th><strong>{{$totalhours}}</strong></th>
<th style="width: 15%" class="center aligned"><strong>{{$totaldays}}</strong></th> <th><strong>{{$totaldays}}</strong></th>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
\ No newline at end of file
...@@ -6,8 +6,13 @@ ...@@ -6,8 +6,13 @@
<div class="ui purple left ribbon label"> <div class="ui purple left ribbon label">
Report by Department Report by Department
</div> </div>
<br>
<br> <button class="right floated center aligned ui violet compact labeled icon button" onclick="window.location.href='{{ route('timesheet::export.exportdepartment', ['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="ui styled fluid">
<div class="title"> <div class="title">
......
...@@ -12,6 +12,7 @@ Route::group( ...@@ -12,6 +12,7 @@ Route::group(
//export //export
Route::get('ringkasan/export/', ['uses' => 'ExportController@export', 'as' => 'export.exportsummary']); Route::get('ringkasan/export/', ['uses' => 'ExportController@export', 'as' => 'export.exportsummary']);
Route::get('project/export/', ['uses' => 'ExportController@exportproject', 'as' => 'export.exportproject']); Route::get('project/export/', ['uses' => 'ExportController@exportproject', 'as' => 'export.exportproject']);
Route::get('department/export/', ['uses' => 'ExportController@exportdepartment', 'as' => 'export.exportdepartment']);
//dashboard //dashboard
Route::get('home',['uses' => 'DashboardController@index', 'as' => 'dashboard.index']); Route::get('home',['uses' => 'DashboardController@index', 'as' => 'dashboard.index']);
......
...@@ -37,6 +37,7 @@ use Curl; ...@@ -37,6 +37,7 @@ use Curl;
use Auth; use Auth;
use App\Exports\RingkasanExport; use App\Exports\RingkasanExport;
use App\Exports\ProjectExport; use App\Exports\ProjectExport;
use App\Exports\DepartmentExport;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
class ExportController extends Controller class ExportController extends Controller
...@@ -64,6 +65,9 @@ class ExportController extends Controller ...@@ -64,6 +65,9 @@ class ExportController extends Controller
$month = date('F', mktime(0,0,0,$request->month, 1, date('Y'))); $month = date('F', mktime(0,0,0,$request->month, 1, date('Y')));
$year = strval($request->year); $year = strval($request->year);
$pdetail = VwProject::where('pid', $request->pid)
->first();
return (new ProjectExport( return (new ProjectExport(
[ [
...@@ -72,7 +76,27 @@ class ExportController extends Controller ...@@ -72,7 +76,27 @@ class ExportController extends Controller
'year' => $request->year, 'year' => $request->year,
'pid' => $request->pid 'pid' => $request->pid
]))->download('Report by Project '.$month.' '.$year.'.xlsx'); ]))->download(data_get($pdetail,'pname').' Report '.$month.' '.$year.'.xlsx');
}
public function exportdepartment(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 DepartmentExport(
[
'dept' => $request->dept,
'month' => $request->month,
'year' => $request->year
]))->download(data_get($dept,'code').' Report '.$month.' '.$year.'.xlsx');
} }
} }
\ No newline at end of file
...@@ -165,6 +165,7 @@ class ReportController extends Controller ...@@ -165,6 +165,7 @@ class ReportController extends Controller
public function generatedeptreport(Request $request) public function generatedeptreport(Request $request)
{ {
$dept = Department::where('id', $request->dept)->first(); $dept = Department::where('id', $request->dept)->first();
// dd($dept);
$staffs = VwStaff::where('deptID', $request->dept)->get(); $staffs = VwStaff::where('deptID', $request->dept)->get();
$project = VwProject::where('deptid', $request->dept) $project = VwProject::where('deptid', $request->dept)
->where('month', $request->month) ->where('month', $request->month)
...@@ -181,9 +182,11 @@ class ReportController extends Controller ...@@ -181,9 +182,11 @@ class ReportController extends Controller
if ($request->year) { if ($request->year) {
$year = $request->year; $year = $request->year;
} }
$intmonth = $request->month;
$month = date('F', mktime(0,0,0,$request->month, 1, date('Y'))); $month = date('F', mktime(0,0,0,$request->month, 1, date('Y')));
return view('timesheet::report.department', compact('year', 'month', 'dept', 'staffs', 'project', 'overhead')); return view('timesheet::report.department', compact('intmonth','year', 'month', 'dept', 'staffs', 'project', 'overhead'));
} }
} }
\ No newline at end of file
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