276 lines
9.4 KiB
PHP
276 lines
9.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers;
|
||
|
|
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\WorkflowDocument;
|
||
|
|
use App\WorkflowType;
|
||
|
|
use App\WorkflowDocumentFile;
|
||
|
|
use App\WorkflowDocumentUser;
|
||
|
|
use App\WorkflowDocumentProcess;
|
||
|
|
use App\WorkflowDocumentSender;
|
||
|
|
use App\Department;
|
||
|
|
use App\User;
|
||
|
|
use App\Event;
|
||
|
|
use App\Setting;
|
||
|
|
use Session;
|
||
|
|
use DB;
|
||
|
|
use Auth;
|
||
|
|
use Carbon\Carbon;
|
||
|
|
use App\Exports\ListingExport;
|
||
|
|
use Excel;
|
||
|
|
|
||
|
|
|
||
|
|
class DashboardController extends Controller
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Create a new controller instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
$this->middleware('auth:web');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the application dashboard.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function basicDashboard()
|
||
|
|
{
|
||
|
|
return view('dashboard.basic');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function advancedDashboard(Request $request)
|
||
|
|
{
|
||
|
|
if(!in_array(14, auth()->user()->getPermissionList()))
|
||
|
|
{
|
||
|
|
\Session::flash('error_message', __('no permission'));
|
||
|
|
return redirect()->back();
|
||
|
|
}
|
||
|
|
|
||
|
|
$regdate = '';
|
||
|
|
if($request->has('reg_date'))
|
||
|
|
{
|
||
|
|
$regdates = preg_split("/\s+:\s+/", trim($request->input('reg_date')));
|
||
|
|
$date['f'] = Carbon::createFromFormat('d-m-Y', $regdates[0])->format('Y-m-d') . ' 00:00:00';
|
||
|
|
$date['t'] = Carbon::createFromFormat('d-m-Y', $regdates[1])->format('Y-m-d') . ' 23:59:59';
|
||
|
|
$regdate = trim($request->input('reg_date'));
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$date['f'] = Carbon::now()->startOfDay()->format('Y-m-d H:i:s');
|
||
|
|
$date['t'] = Carbon::now()->endOfDay()->format('Y-m-d H:i:s');
|
||
|
|
$regdate = Carbon::now()->startOfDay()->format('d-m-Y') . " : " . Carbon::now()->endOfDay()->format('d-m-Y');
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
$departments = Department::where('status', 1)->get();
|
||
|
|
$workfloworkflowtypes = WorkflowType::where('id', '!=', 4)->orderBy('id', 'asc')->get();
|
||
|
|
$setting = Setting::first();
|
||
|
|
|
||
|
|
$total_documents = DB::table('workflow_documents as w')
|
||
|
|
->join('workflow_types as wt', 'wt.id', '=', 'w.workflow_type_id')
|
||
|
|
->where('w.is_deleted', 0)
|
||
|
|
->groupBy('w.workflow_type_id')
|
||
|
|
->groupBy('w.status')
|
||
|
|
->selectRaw('w.workflow_type_id, wt.name, w.status, count(*) as count')
|
||
|
|
->whereBetween('w.registration_date', [$date['f'], $date['t']])
|
||
|
|
->get();
|
||
|
|
|
||
|
|
$sub_departments = DB::table('workflow_document_process')
|
||
|
|
->selectRaw('workflow_document_id, max(id) as maxid')
|
||
|
|
->groupBy('workflow_document_id')
|
||
|
|
->where('user_type', 'R');
|
||
|
|
|
||
|
|
$total_departments = DB::table('workflow_documents as w')
|
||
|
|
->join('workflow_types as wt', 'wt.id', '=', 'w.workflow_type_id')
|
||
|
|
->join('workflow_document_process as wp', 'wp.workflow_document_id', '=', 'w.id')
|
||
|
|
->joinSub($sub_departments, 'sb', function($join){
|
||
|
|
$join->on('sb.maxid', '=', 'wp.id');
|
||
|
|
})
|
||
|
|
->where('w.is_deleted', 0)
|
||
|
|
->whereBetween('w.registration_date', [$date['f'], $date['t']])
|
||
|
|
->selectRaw('wt.name as workflow_type_name, wt.id as workflow_type_id, w.status, wp.user_department as department, count(*) as count')
|
||
|
|
->groupBy('w.workflow_type_id')
|
||
|
|
->groupBy('w.status')
|
||
|
|
->groupBy('wp.user_department')
|
||
|
|
->orderBy('w.id')
|
||
|
|
->get();
|
||
|
|
|
||
|
|
|
||
|
|
// echo '<pre>';
|
||
|
|
// print_r($total_documents->toArray());
|
||
|
|
// echo '</pre>';
|
||
|
|
// die();
|
||
|
|
// dd($regdate);
|
||
|
|
|
||
|
|
return view('dashboard.advanced', compact('total_documents', 'setting', 'total_departments', 'departments', 'workfloworkflowtypes', 'regdate'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function filterDocuments($reg_date, $workflowtype, $status, $not, $department='', $type=null)
|
||
|
|
{
|
||
|
|
$workflowtypes = WorkflowType::where('status', $workflowtype)->get(['id', 'name']);
|
||
|
|
|
||
|
|
$input['reg_date'] = $reg_date;
|
||
|
|
$input['workflowtype'] = $workflowtype;
|
||
|
|
$input['status'] = $status;
|
||
|
|
$input['not'] = $not ?? 'N';
|
||
|
|
$input['department'] = $department;
|
||
|
|
$input['export'] = $type;
|
||
|
|
|
||
|
|
$regdates = preg_split("/\s+:\s+/", trim($input['reg_date']));
|
||
|
|
$f = Carbon::createFromFormat('d-m-Y', $regdates[0])->format('Y-m-d') . ' 00:00:00';
|
||
|
|
$t = Carbon::createFromFormat('d-m-Y', $regdates[1])->format('Y-m-d') . ' 23:59:59';
|
||
|
|
|
||
|
|
$documents = WorkflowDocument::where('workflow_type_id', $input['workflowtype'])->whereBetween('registration_date', [$f , $t]);
|
||
|
|
$input['compare'] = ($input['not'] == 'Y') ? '!=' : '=';
|
||
|
|
// if($input['status'] != 'x')
|
||
|
|
// $documents = $documents->where('status', $compare, $input['status']);
|
||
|
|
|
||
|
|
if($input['department'] != 'x')
|
||
|
|
{
|
||
|
|
// dd($input);
|
||
|
|
$ds = Department::all();
|
||
|
|
$did = 0;
|
||
|
|
foreach($ds as $d)
|
||
|
|
{
|
||
|
|
if(dataTranslation($d->name) == $input['department'])
|
||
|
|
{
|
||
|
|
$did = $d->id;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$user_ids = User::where('department_id', $did)->pluck('id')->toArray();
|
||
|
|
if($input['workflowtype'] == 3)
|
||
|
|
$documents = $documents->whereHas('workflowprocesses', function($q) use($user_ids, $input){
|
||
|
|
$q->whereIn('user_id', $user_ids);
|
||
|
|
});
|
||
|
|
else
|
||
|
|
$documents = $documents->whereHas('workflowprocesses', function($q) use($user_ids, $input){
|
||
|
|
$q->whereIn('user_id', $user_ids)
|
||
|
|
->where('status', $input['compare'], $input['status']);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
else if($input['status'] != 'x')
|
||
|
|
{
|
||
|
|
$documents = $documents->where('status', $input['compare'], $input['status']);
|
||
|
|
// $documents = $documents->whereHas('workflowprocesses', function($q) use($input){
|
||
|
|
// $q->where('status', $input['compare'], $input['status']);
|
||
|
|
// });
|
||
|
|
}
|
||
|
|
|
||
|
|
// dd($input);
|
||
|
|
|
||
|
|
if(isset($input['export']))
|
||
|
|
return [$workflowtypes, $input, $documents->get(), 'dashboard'];
|
||
|
|
|
||
|
|
$documents = $documents->orderBy('id', 'desc')->paginate(20)->appends([
|
||
|
|
'reg_date' => $reg_date ?? '',
|
||
|
|
'workflowtype' => $workflowtype ?? 1,
|
||
|
|
'status'=>$status ?? '',
|
||
|
|
'not' => $not ?? 'N',
|
||
|
|
'department' => $department ?? ''
|
||
|
|
]);
|
||
|
|
|
||
|
|
return view('dashboard.list', compact('input', 'documents', 'workflowtypes'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function export(Request $request, $type=null)
|
||
|
|
{
|
||
|
|
$type = (in_array($type, ['xlsx', 'csv', 'pdf'])) ? $type : 'xlsx';
|
||
|
|
$new_req = new \Illuminate\Http\Request;
|
||
|
|
$new_req->setMethod('GET');
|
||
|
|
$new_req = (clone request())->replace(json_decode($request->input('export-filterBy'), true));
|
||
|
|
$row = $this->filterDocuments($new_req->reg_date, $new_req->workflowtype, $new_req->status, $new_req->not, $new_req->department, 'export');
|
||
|
|
$name = 'documents' . '_' . now()->format('d-m-Y') . '.' . $type;
|
||
|
|
|
||
|
|
return Excel::download(new ListingExport($row), $name);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function calendar()
|
||
|
|
{
|
||
|
|
if(Auth::user()->department_id== 7)
|
||
|
|
{
|
||
|
|
$workflow_documents = DB::table('workflow_documents')->get();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$workflow_documents = DB::table('workflow_documents')
|
||
|
|
->join('workflow_document_users', 'workflow_documents.id', '=', 'workflow_document_users.workflow_document_id')
|
||
|
|
->select('workflow_documents.*')
|
||
|
|
->where('workflow_document_users.user_id', Auth::user()->id)
|
||
|
|
->get();
|
||
|
|
}
|
||
|
|
$custom_event = Event::where('user_id',Auth::user()->id)->get();
|
||
|
|
return view('calendar', compact('workflow_documents', 'custom_event'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function storeEvent(Request $request)
|
||
|
|
{
|
||
|
|
$input = $request->all();
|
||
|
|
if(isset($input['start_date_time']) && $input['start_date_time'] != "")
|
||
|
|
$input['start_date_time'] = Carbon\Carbon::createFromFormat('d/m/Y H:i', $input['start_date_time'])->format('Y-m-d H:i');
|
||
|
|
if(isset($input['end_date_time']) && $input['end_date_time'] != "")
|
||
|
|
$input['end_date_time'] = Carbon\Carbon::createFromFormat('d/m/Y H:i', $input['end_date_time'])->format('Y-m-d H:i');
|
||
|
|
$input['user_id'] = Auth::user()->id;
|
||
|
|
$saved_data=Event::create($input);
|
||
|
|
if($saved_data)
|
||
|
|
{
|
||
|
|
Session::flash('success_message', __('Event has been added successfully'));
|
||
|
|
}else{
|
||
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
||
|
|
}
|
||
|
|
return redirect()->back();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function deleteEvent($id)
|
||
|
|
{
|
||
|
|
$id=base64_decode($id);
|
||
|
|
$event = Event::findOrFail($id);
|
||
|
|
$delete_event = $event->delete();
|
||
|
|
if($delete_event):
|
||
|
|
Session::flash('success_message', __('Event has been deleted successfully'));
|
||
|
|
else:
|
||
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
||
|
|
endif;
|
||
|
|
return redirect()->back();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function edit($id)
|
||
|
|
{
|
||
|
|
$setting = Setting::first();
|
||
|
|
$id=base64_decode($id);
|
||
|
|
$event = Event::where('id', '=', $id)->first();
|
||
|
|
if($event):
|
||
|
|
return view('includes.event-update', compact('event', 'setting'));
|
||
|
|
else:
|
||
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
||
|
|
return redirect()->back();
|
||
|
|
endif;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function updateEvent (Request $request, $id)
|
||
|
|
{
|
||
|
|
$id=base64_decode($id);
|
||
|
|
$event = Event::findOrFail($id);
|
||
|
|
$input = $request->all();
|
||
|
|
if(isset($input['start_date_time']) && $input['start_date_time'] != "")
|
||
|
|
$input['start_date_time'] = Carbon\Carbon::createFromFormat('d/m/Y H:i', $input['start_date_time'])->format('Y-m-d H:i');
|
||
|
|
if(isset($input['end_date_time']) && $input['end_date_time'] != "")
|
||
|
|
$input['end_date_time'] = Carbon\Carbon::createFromFormat('d/m/Y H:i', $input['end_date_time'])->format('Y-m-d H:i');
|
||
|
|
$saved_data=$event->fill($input)->save();
|
||
|
|
if($saved_data):
|
||
|
|
Session::flash('success_message', __('Event has been updated successfully'));
|
||
|
|
return redirect()->route('calendar');
|
||
|
|
else:
|
||
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
||
|
|
return redirect()->back();
|
||
|
|
endif;
|
||
|
|
}
|
||
|
|
}
|