Commit 41c9baba by hannan

export to excel -> project report

parent 14164bfe
<?php
namespace App\Exports;
use App\User;
use Portal\Timesheet\Model\VwProject;
// 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 ProjectExport 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'];
$project = $this->request['pid'];
return view('timesheet::exports.exportProject', [
'month' => $month,
'year' => $year,
'pdetail' => VwProject::where('pid', $project)
->first(),
'pteam' => VwProject::where('pid', $project)
->orderby('roleid')
->get(),
'ptdetail' => VwProject::where('pid', $project)
->where('MONTH', $month)
->where('year', $year)
->orderby('roleid')
->get()
]);
}
}
<table class="ui unstackable celled table">
<thead>
<tr>
<th style="width: 10%">Project </th>
<th style="width: 1%">:</th>
<th colspan="3"> {{data_get($pdetail,'pcode')}} - {{data_get($pdetail,'pname')}}</th>
</tr>
<tr>
<th style="width: 10%"> Month/Year</th>
<th style="width: 1%">:</th>
<th colspan="3"> {{$month}} {{$year}}</th>
</tr>
</thead>
</table>
<table class="ui unstackable celled table">
<thead>
<tr>
<th style="width: 45%">Staff Name</th>
<th style="width: 25%" class="center aligned">Role</th>
<th style="width: 15%" class="center aligned">Total Hours</th>
<th style="width: 15%" class="center aligned">Total Days</th>
</tr>
</thead>
<tbody>
<?php $totalhours = $totaldays = 0; ?>
@foreach($pteam as $key => $team)
<tr>
<td style="width: 40%">{{data_get($team,'name')}}</td>
<td style="width: 30%" class="center aligned">{{data_get($team,'role')}}</td>
<td style="width: 15%" class="center aligned">
@foreach($ptdetail as $key => $hours)
@if(data_get($hours,'staffid') == data_get($team,'staffid'))
{{data_get($hours,'hours')}}
<?php $totalhours += data_get($hours,'hours'); ?>
@endif
@endforeach
</td>
<td style="width: 15%" class="center aligned">
@foreach($ptdetail as $key => $hours)
@if(data_get($hours,'staffid') == data_get($team,'staffid'))
{{number_format(data_get($hours,'hours')/8, 1, '.', '')}}
<?php $totaldays += number_format(data_get($hours,'hours')/8, 1, '.', ''); ?>
@endif
@endforeach
</td>
</tr>
@endforeach
</tbody>
<tfoot class="full-width">
<tr>
<th style="width: 40%"><strong>Total</strong></th>
<th style="width: 30%"></th>
<th style="width: 15%" class="center aligned"><strong>{{$totalhours}}</strong></th>
<th style="width: 15%" class="center aligned"><strong>{{$totaldays}}</strong></th>
</tr>
</tfoot>
</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 Project Report by Project
</div> </div>
<br>
<br> <button class="right floated center aligned ui violet compact labeled icon button" onclick="window.location.href='{{ route('timesheet::export.exportproject', ['month'=> $intmonth, 'year'=> $year, 'pid'=> $pid ]) }}';">
<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">
......
...@@ -11,6 +11,7 @@ Route::group( ...@@ -11,6 +11,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']);
//dashboard //dashboard
Route::get('home',['uses' => 'DashboardController@index', 'as' => 'dashboard.index']); Route::get('home',['uses' => 'DashboardController@index', 'as' => 'dashboard.index']);
......
...@@ -36,6 +36,7 @@ use Mail; ...@@ -36,6 +36,7 @@ use Mail;
use Curl; use Curl;
use Auth; use Auth;
use App\Exports\RingkasanExport; use App\Exports\RingkasanExport;
use App\Exports\ProjectExport;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
class ExportController extends Controller class ExportController extends Controller
...@@ -53,7 +54,25 @@ class ExportController extends Controller ...@@ -53,7 +54,25 @@ class ExportController extends Controller
'month' => $request->month, 'month' => $request->month,
'year' => $request->year 'year' => $request->year
]))->download('Ringkasan Laporan '.$month.' '.$year.'.xlsx'); ]))->download('Report Summary '.$month.' '.$year.'.xlsx');
}
public function exportproject(Request $request)
{
// dd($request);
$month = date('F', mktime(0,0,0,$request->month, 1, date('Y')));
$year = strval($request->year);
return (new ProjectExport(
[
'month' => $request->month,
'year' => $request->year,
'pid' => $request->pid
]))->download('Report by Project '.$month.' '.$year.'.xlsx');
} }
} }
\ No newline at end of file
...@@ -115,6 +115,9 @@ class ReportController extends Controller ...@@ -115,6 +115,9 @@ class ReportController extends Controller
public function generateprojectreport(Request $request) public function generateprojectreport(Request $request)
{ {
// dd($request);
$pid = $request->project;
$pdetail = VwProject::where('pid', $request->project) $pdetail = VwProject::where('pid', $request->project)
->first(); ->first();
...@@ -133,9 +136,11 @@ class ReportController extends Controller ...@@ -133,9 +136,11 @@ class ReportController extends Controller
$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.project', compact('month', 'year', 'pteam', 'pdetail', 'ptdetail')); return view('timesheet::report.project', compact('month', 'intmonth', 'year', 'pteam', 'pdetail', 'ptdetail', 'pid'));
} }
public function deptreport() public function deptreport()
......
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