73 lines
3.1 KiB
PHP
73 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\WorkflowDocument;
|
|
use App\WorkflowType;
|
|
use App\Exports\ListingExport;
|
|
use Carbon\Carbon;
|
|
use Excel;
|
|
|
|
class ListingController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$input = $request->all();
|
|
// dd($input);
|
|
$workflowtypes = WorkflowType::where('status', 1)->where('id', '!=', 4)->get(['id', 'name']);
|
|
$input['status'] = isset($input['status']) ? $input['status'] : 0;
|
|
if(!$request->has('reg_date'))
|
|
return view('listings.index', compact('workflowtypes', 'input'));
|
|
|
|
$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'])->where('is_deleted', 0)->whereBetween('registration_date', [$f , $t]);
|
|
if(isset($input['registration_number']) && strlen($input['registration_number'])>0)
|
|
$documents = $documents->where(function($q) use($input){
|
|
$q->orWhere('registration_number', 'LIKE', '%' . $input['registration_number'] . '%')
|
|
->orWhere('temporary_registration_number', 'LIKE', '%' . $input['registration_number'] . '%');
|
|
});
|
|
|
|
if(isset($input['status']) && in_array($input['status'], [1, 2]))
|
|
{
|
|
$st = 'Approved';
|
|
$st = ($input['workflowtype'] == 1) ? 'Complete' : $st;
|
|
$not = ($input['status'] == 1) ? '=' : '!=';
|
|
$documents = $documents->where('status', $not, $st);
|
|
}
|
|
|
|
if(isset($input['contact_id']) && count($input['contact_id'])>0)
|
|
$documents = $documents->whereHas('senders', function($q) use($input){
|
|
$q->whereIn('contact_id', $input['contact_id']);
|
|
});
|
|
|
|
// $workflowtypename = dataTranslation(WorkflowType::find($input['workflowtype'])->name);
|
|
if(isset($input['export']))
|
|
return [$workflowtypes, $input, $documents->get()];
|
|
|
|
$documents = $documents->orderBy('id', 'desc')->paginate(100)->appends([
|
|
'reg_date' => $input['reg_date'] ?? '',
|
|
'registration_number' => $input['registration_number'] ?? '',
|
|
'contact_id'=>$input['contact_id'] ?? [],
|
|
'workflowtype' => $input['workflowtype'] ?? 1
|
|
]);
|
|
|
|
return view('listings.index', compact('workflowtypes', 'input', 'documents'));
|
|
}
|
|
|
|
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->index($new_req);
|
|
$name = 'documents' . '_' . now()->format('d-m-Y') . '.' . $type;
|
|
|
|
return Excel::download(new ListingExport($row), $name);
|
|
}
|
|
}
|