2143 lines
95 KiB
PHP
2143 lines
95 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\UploadedFile;
|
|
use App\Http\Controllers\Controller;
|
|
use App\WorkflowDocument;
|
|
use App\WorkflowType;
|
|
use App\Priority;
|
|
use App\DeliveryType;
|
|
use App\DocumentType;
|
|
use App\Contact;
|
|
use App\Department;
|
|
use App\Setting;
|
|
use App\User;
|
|
use App\WorkflowDocumentUser;
|
|
use App\WorkflowDocumentFile;
|
|
use App\WorkflowDocumentSender;
|
|
use App\WorkflowDocumentProcess;
|
|
use App\RegNumber;
|
|
use App\Comment;
|
|
use App\Notifications\DocumentNotification;
|
|
use Notification;
|
|
use Session;
|
|
use DB;
|
|
use Auth;
|
|
use Carbon;
|
|
use Log;
|
|
|
|
|
|
class WorkflowDocumentsController extends Controller
|
|
{
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth:web');
|
|
}
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
|
|
public function details(Request $request, $id, $not_id = null)
|
|
{
|
|
$id=base64_decode($id);
|
|
$notifications_update = Auth::user()->unreadNotifications()->where('workflow_document_id', $id)->update(['read_at'=>now()->format('Y-m-d H:i:s')]);
|
|
if($notifications_update){
|
|
if(Session::has('unread_notification_number')){
|
|
$notification_number = Session::get('unread_notification_number');
|
|
$request->session()->put('unread_notification_number', $notification_number-1);
|
|
}
|
|
}
|
|
$workflow_document = WorkflowDocument::where('id', $id)->first();
|
|
$setting = Setting::first();
|
|
$workflow_types = WorkflowType::orderBy('id', 'asc')->get();
|
|
$priorities = Priority::orderBy('id', 'asc')->get();
|
|
$delivery_types = DeliveryType::orderBy('id', 'asc')->get();
|
|
$document_types = DocumentType::orderBy('id', 'asc')->get();
|
|
$senders = Contact::where('status', 1)->where('is_approved', 1)->orderBy('id', 'asc')->get();
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
$users = User::getUserRole()->get();
|
|
|
|
$documents = WorkflowDocument::orderBy('id', 'desc')->get();
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
if($workflow_document){
|
|
$unread_user = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)
|
|
->where('user_id', Auth::user()->id)
|
|
->where('is_read', '0')
|
|
->where('status', 'Y')
|
|
->first();
|
|
if($unread_user){
|
|
$unreadUpdate = WorkflowDocumentUser::where('id', '=', $unread_user->id)->update(['is_read'=>1]);
|
|
}
|
|
return view('document-workflows.details', compact('setting', 'workflow_types', 'priorities', 'delivery_types', 'document_types', 'senders', 'departments', 'users', 'documents', 'workflow_document', 'document_user'));
|
|
}else{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->back();
|
|
}
|
|
}
|
|
|
|
public function delegate(Request $request, $id)
|
|
{
|
|
$type='Incoming';
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::findOrFail($id);
|
|
$setting = Setting::first();
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
$input = $request->all();
|
|
if(isset($input['related_documents'])) {
|
|
$input['related_documents'] = json_encode($input['related_documents']);
|
|
}
|
|
$input['registration_number'] = $workflow_document->registration_number;
|
|
$input['registration_date'] = $workflow_document->registration_date;
|
|
$input['workflow_type_id'] = $workflow_document->workflow_type_id;
|
|
$input['workflow_type_name'] = $workflow_document->workflow_type_name;
|
|
$input['delivery_type_id'] = $workflow_document->delivery_type_id;
|
|
$input['delivery_type_name'] = $workflow_document->delivery_type_name;
|
|
$input['topic'] = $workflow_document->topic;
|
|
$input['additional_notes'] = $workflow_document->additional_notes;
|
|
$input['priority_id'] = $workflow_document->priority_id;
|
|
$input['priority_name'] = $workflow_document->priority_name;
|
|
$input['max_completion_days'] = $workflow_document->max_completion_days;
|
|
$input['document_type_id'] = $workflow_document->document_type_id;
|
|
$input['document_type_name'] = $workflow_document->document_type_name;
|
|
$input['status']='Delegate';
|
|
$parent_process_comment = $input['comment'];
|
|
$input['comment'] = $workflow_document->comment;
|
|
$saved_data=$workflow_document->fill($input)->save();
|
|
if($saved_data)
|
|
{
|
|
$parent_process = WorkflowDocumentProcess::where('user_id', Auth::user()->id)->where('workflow_document_id', $workflow_document->id)->orderBy('id', 'desc')->first();
|
|
$process_input['parent_id']=$parent_process->id;
|
|
$process_input['workflow_document_id']=$workflow_document->id;
|
|
$process_input['start_date']=date('Y-m-d');
|
|
if(isset($input['reviewers']) && $input['reviewers']!=''){
|
|
$reviewers=explode('-',$input['reviewers']);
|
|
if($reviewers[0] == 'uid')
|
|
{
|
|
$document_user_for_work = User::getUserDocument()->where('users.id', '=', $reviewers[1])->first();
|
|
}
|
|
elseif($reviewers[0] == 'did')
|
|
{
|
|
if($workflow_document->workflow_type_id !=2)
|
|
{
|
|
$department = Department::where('id',$reviewers[1])->first();
|
|
$document_user_for_work = User::getUserDocument()
|
|
->where('users.department_id', '=', $department->id)
|
|
->where('role_user.role_id', '>', $document_user->role_id)
|
|
->orderBy('role_user.role_id', 'asc')
|
|
->first();
|
|
}
|
|
else
|
|
{
|
|
$department = Department::where('id',$reviewers[1])->first();
|
|
$document_user_for_work = User::getUserDocument()
|
|
->where('users.department_id', '=', $department->id)
|
|
->where('role_user.role_id', '<', $document_user->role_id)
|
|
->orderBy('role_user.role_id', 'desc')
|
|
->first();
|
|
}
|
|
}
|
|
}
|
|
$process_input['status']='P';
|
|
$process_input['user_id']=$document_user_for_work->id;
|
|
$process_input['user_name']=$document_user_for_work->first_name.' '.$document_user_for_work->last_name;
|
|
$process_input['user_email']=$document_user_for_work->email;
|
|
$process_input['user_role']=$document_user_for_work->role_name;
|
|
$document_user_for_work_department = Department::where('id',$document_user_for_work->department_id)->first();
|
|
if($document_user_for_work_department)
|
|
{
|
|
$process_input['user_department']=$document_user_for_work_department->name;
|
|
}
|
|
|
|
$process_input['assign_by']=Auth::user()->id;
|
|
$process_input['assigner_name']=$document_user->first_name.' '.$document_user->last_name;
|
|
$process_input['assigner_email']=$document_user->email;
|
|
$process_input['assign_date']=date('Y-m-d H:i:s');
|
|
$process_input['assigner_role']=$document_user->role_name;
|
|
$document_user_department = Department::where('id',$document_user->department_id)->first();
|
|
if($document_user_department)
|
|
{
|
|
$process_input['assigner_department'] = $document_user_department->name;
|
|
}
|
|
$process_save=WorkflowDocumentProcess::create($process_input);
|
|
if($process_save){
|
|
if(isset($parent_process)){
|
|
$update_parent_process = WorkflowDocumentProcess::where('id', $parent_process->id)->update(['end_date' => date('Y-m-d'), 'status'=>'D', 'comment' =>$parent_process_comment]);
|
|
}
|
|
}
|
|
|
|
$reviewer_input['_token']=$input['_token'];
|
|
$reviewer_input['workflow_document_id']=$workflow_document->id;
|
|
$reviewer_input['user_id']=$document_user_for_work->id;
|
|
$reviewer_input['user_type']='R';
|
|
$reviewer_input['user_name']=$document_user_for_work->first_name.' '.$document_user_for_work->last_name;
|
|
$reviewer_input['user_email']=$document_user_for_work->email;
|
|
$reviewer_input['user_role']=$document_user_for_work->role_name;
|
|
$reviewer_input['added_by']=Auth::user()->id;
|
|
$reviewer_department = Department::where('id',$document_user_for_work->department_id)->first();
|
|
if($reviewer_department)
|
|
{
|
|
$reviewer_input['user_department']=$reviewer_department->name;
|
|
}
|
|
$reviewer_save=WorkflowDocumentUser::create($reviewer_input);
|
|
if($reviewer_save){
|
|
$link = route('details', base64_encode($workflow_document->id));
|
|
Notification::send(User::findOrFail($reviewer_save->user_id), new DocumentNotification($workflow_document->id, "reveiwer", "delegated", $link));
|
|
}
|
|
|
|
$prev_supporters = WorkflowDocumentUser::where('workflow_document_id', $workflow_document->id)->where('user_type', 'S')->update(['status'=>'N']);
|
|
|
|
if(isset($input['supporters']) && is_array($input['supporters'])){
|
|
foreach($input['supporters'] as $supporter){
|
|
$supp_array=explode('-',$supporter);
|
|
if($supp_array[0] == 'uid')
|
|
{
|
|
$supporter_user = User::getUserDocument()->where('users.id', '=', $supp_array[1])->first();
|
|
}
|
|
elseif($supp_array[0] == 'did')
|
|
{
|
|
$department = Department::where('id',$supp_array[1])->first();
|
|
$supporter_user = User::getUserDocument()
|
|
->where('users.department_id', '=', $department->id)
|
|
->orderBy('role_user.role_id', 'asc')
|
|
->first();
|
|
}
|
|
if(isset($supporter_user)){
|
|
$is_exist=WorkflowDocumentUser::where('workflow_document_id', $workflow_document->id)->where('user_id', $supporter_user->id)->first();
|
|
if(!isset($is_exist) || empty($is_exist))
|
|
{
|
|
$supporter_input['_token']=$input['_token'];
|
|
$supporter_input['workflow_document_id']=$workflow_document->id;
|
|
$supporter_input['user_id']=$supporter_user->id;
|
|
$supporter_input['process_id']=$process_save->id;
|
|
$supporter_input['user_type']='S';
|
|
$supporter_input['user_name']=$supporter_user->first_name.' '.$supporter_user->last_name;
|
|
$supporter_input['user_email']=$supporter_user->email;
|
|
$supporter_input['user_role']=$supporter_user->role_name;
|
|
$supporter_input['added_by']=Auth::user()->id;
|
|
$supporter_department = Department::where('id',$supporter_user->department_id)->first();
|
|
if($supporter_department)
|
|
{
|
|
$supporter_input['user_department']=$supporter_department->name;
|
|
}
|
|
$supporter_save=WorkflowDocumentUser::create($supporter_input);
|
|
|
|
if($supporter_save)
|
|
{
|
|
$link = route('details', base64_encode($workflow_document->id));
|
|
Notification::send(User::findOrFail($supporter_save->user_id), new DocumentNotification($workflow_document->id, "supporter", "delegated", $link));
|
|
}
|
|
}else{
|
|
$exist_supporters = WorkflowDocumentUser::where('workflow_document_id', $workflow_document->id)->where('user_type', 'S')->where('user_id', $supporter_user->id)->update(['status'=>'Y']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Session::flash('success_message', __('Document workflow has been updated successfully'));
|
|
return redirect()->back();
|
|
}
|
|
else
|
|
{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->back();
|
|
}
|
|
}
|
|
|
|
public function getDelegateDocument($id)
|
|
{
|
|
$type='Incoming';
|
|
$id=base64_decode($id);
|
|
$workflowDocumentProcess=WorkflowDocumentProcess::where('workflow_document_id', $id)->orderBy('id', 'asc')->get();
|
|
$workflow_document = WorkflowDocument::where('id', $id)->first();
|
|
if($workflow_document){
|
|
$type_names=json_decode($workflow_document->workflow_type_name, true);
|
|
if(isset($type_names['en']))
|
|
$type=$type_names['en'];
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
$setting = Setting::first();
|
|
$users = User::getUserRole()->get();
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
return view('document-workflows.delegate_document', compact('workflow_document', 'type', 'users', 'departments', 'document_user', 'setting'));
|
|
}else{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->back();
|
|
}
|
|
}
|
|
|
|
|
|
public function search(Request $request, $type)
|
|
{
|
|
$input = $request->all();
|
|
$search_val['search']=$input['search'];
|
|
$search_val['reg_date']=$input['reg_date'];
|
|
$search_val['creator']=$input['creator'];
|
|
$search_val['status']=$input['status'] ?? '0';
|
|
$request->session()->put('search_val', $search_val);
|
|
return redirect()->route('documents', $type);
|
|
}
|
|
|
|
private function my_search($search_val, $wtype=1)
|
|
{
|
|
$a = WorkflowDocument::where('is_deleted', 0);
|
|
$between_date = null;
|
|
$contact_ids = null;
|
|
if(isset($search_val['reg_date']))
|
|
{
|
|
$between_date = array_map('trim', preg_split('/\s*:\s*/', $search_val['reg_date']));
|
|
$between_date[0] = \Carbon\Carbon::createFromFormat('d-m-Y', $between_date[0])->format('Y-m-d');
|
|
$between_date[1] = \Carbon\Carbon::createFromFormat('d-m-Y', $between_date[1])->format('Y-m-d');
|
|
|
|
$a = $a->whereBetween('registration_date', [$between_date[0], $between_date[1]]);
|
|
}
|
|
|
|
if(isset($search_val['search']) && strlen($search_val['search'])>0)
|
|
{
|
|
$document_ids = WorkflowDocumentSender::where('contact_organization_name', 'REGEXP', $search_val['search'])->get(['workflow_document_id'])->pluck('workflow_document_id')->toArray();
|
|
$a = $a->where(function($query) use($search_val, $document_ids){
|
|
$query->where('registration_number', 'REGEXP', $search_val['search'])
|
|
->orWhere('sender_letter_number', 'REGEXP', $search_val['search'])
|
|
->orWhere('topic', 'REGEXP', $search_val['search'])
|
|
->orWhereIn('id', $document_ids);
|
|
});
|
|
}
|
|
|
|
if(isset($search_val['status']) && in_array($search_val['status'], [1, 2]))
|
|
{
|
|
$st = 'Approved';
|
|
$st = ($wtype == 1) ? 'Complete' : $st;
|
|
$not = ($search_val['status'] == 1) ? '=' : '!=';
|
|
$a = $a->where('status', $not, $st);
|
|
}
|
|
|
|
if(isset($search_val['creator']) && ($search_val['creator'] > 0))
|
|
{
|
|
$a = $a->where('creator_id', $search_val['creator']);
|
|
}
|
|
|
|
return $a;
|
|
}
|
|
|
|
public function index(Request $request, $type)
|
|
{
|
|
$setting = Setting::first();
|
|
$workflow_type = WorkflowType::where('name', 'like', '%'.$type.'%')->first();
|
|
$users = User::getUserRole()->get();
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
$limit_val = (isset($setting->data_limit_per_page) && $setting->data_limit_per_page > 0) ? $setting->data_limit_per_page : 10;
|
|
|
|
$search_val = null;
|
|
if($request->session()->has('search_val')){
|
|
$search_val = $request->session()->get('search_val');
|
|
// $request->session()->forget('search_val');
|
|
}
|
|
if(check_permissions(1) === true)
|
|
{
|
|
$workflow_documents = $this->my_search($search_val, $workflow_type->id)->where('workflow_type_id', '=', $workflow_type->id)->orderByDesc('updated_at', 'created_at');
|
|
$workflow_documents = $workflow_documents->paginate($limit_val)->appends([
|
|
'search' => $search_val['search'] ?? '',
|
|
'reg_date' => $search_val['reg_date'] ?? '',
|
|
'creattor' => $search_val['creator'] ?? '',
|
|
'status' => $search_val['status'] ?? '0',
|
|
]);
|
|
}
|
|
else
|
|
{
|
|
$creator = Auth::user()->id;
|
|
$document_ids = WorkflowDocumentUser::where('user_id', $creator)->where('status', 'Y')->get(['workflow_document_id'])->pluck('workflow_document_id')->toArray();
|
|
$workflow_documents = $this->my_search($search_val, $workflow_type->id)
|
|
->where('workflow_type_id', '=', $workflow_type->id)
|
|
->where(function($query) use($creator, $document_ids){
|
|
$query->orWhere('creator_id', $creator)
|
|
->orWhereIn('id', $document_ids);
|
|
})
|
|
->orderByDesc('updated_at', 'created_at');
|
|
$workflow_documents = $workflow_documents->paginate($limit_val)->appends([
|
|
'search' => $search_val['search'] ?? '',
|
|
'reg_date' => $search_val['reg_date'] ?? '',
|
|
'creattor' => $search_val['creator'] ?? '',
|
|
'status' => $search_val['status'] ?? '0',
|
|
]);
|
|
}
|
|
|
|
// dd($search_val);
|
|
$document_user = User::getUserRole()->where('users.id', '=', Auth::user()->id)->first();
|
|
|
|
if($type=='Outgoing')
|
|
return view('document-workflows.outgoing-list', compact('workflow_documents', 'type', 'document_user', 'setting', 'search_val', 'users', 'departments'));
|
|
elseif($type=='Internal')
|
|
return view('document-workflows.internal-list', compact('workflow_documents', 'type', 'document_user', 'setting', 'search_val', 'users', 'departments'));
|
|
else
|
|
return view('document-workflows.index', compact('workflow_documents', 'type', 'document_user', 'setting', 'search_val', 'users', 'departments'));
|
|
}
|
|
|
|
public function relatedDocuments($id)
|
|
{
|
|
$type='Incoming';
|
|
$id=base64_decode($id);
|
|
$workflowDocumentProcess=WorkflowDocumentProcess::where('workflow_document_id', $id)->orderBy('id', 'asc')->get();
|
|
$workflow_document = WorkflowDocument::where('id', $id)->first();
|
|
if($workflow_document){
|
|
$unread_user = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)
|
|
->where('user_id', Auth::user()->id)
|
|
->where('is_read', '0')
|
|
->where('status', 'Y')
|
|
->first();
|
|
if($unread_user){
|
|
$unreadUpdate = WorkflowDocumentUser::where('id', '=', $unread_user->id)->update(['is_read'=>1]);
|
|
}
|
|
$type_names=json_decode($workflow_document->workflow_type_name, true);
|
|
if(isset($type_names['en']))
|
|
$type=$type_names['en'];
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
$setting = Setting::first();
|
|
return view('document-workflows.related_documents', compact('workflow_document', 'type', 'document_user', 'setting'));
|
|
}else{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->back();
|
|
}
|
|
}
|
|
|
|
public function getRelatedDocuments(Request $request)
|
|
{
|
|
$setting = Setting::first();
|
|
$limit_val = (isset($setting->data_limit_per_page) && $setting->data_limit_per_page > 0) ? $setting->data_limit_per_page : 10;
|
|
|
|
if($request->ajax())
|
|
{
|
|
$search = $request->search ?? '';
|
|
$documents = WorkflowDocument::where('is_deleted', 0)
|
|
->where(function($query) use($search){
|
|
$query->orWhere('registration_number', 'REGEXP', $search)
|
|
->orWhere('topic', 'REGEXP', $search);
|
|
})
|
|
->paginate($limit_val, ['id', 'registration_number', 'topic'])->appends([
|
|
'search' => $search
|
|
]);
|
|
|
|
return response()->json($documents);
|
|
}
|
|
}
|
|
|
|
public function workflow($id)
|
|
{
|
|
$replyWorkflowDocumentProcess=[];
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::findOrFail($id);
|
|
if(isset($workflow_document)){
|
|
if($workflow_document->is_workflow_free ==1){
|
|
Session::flash('error_message', __('Workflow is not available for this document.'));
|
|
return redirect()->back();
|
|
}
|
|
if($workflow_document->workflow_type_id == 2 && $workflow_document->reply_for > 0){
|
|
$reply_workflow_document = $workflow_document;
|
|
$workflow_document = WorkflowDocument::where('id', $reply_workflow_document->reply_for)->first();
|
|
$workflowDocumentProcess=WorkflowDocumentProcess::where('workflow_document_id', $workflow_document->id)->orderBy('id', 'asc')->get();
|
|
if(isset($reply_workflow_document))
|
|
{
|
|
$replyWorkflowDocumentProcess=WorkflowDocumentProcess::where('workflow_document_id', $reply_workflow_document->id)->orderBy('id', 'asc')->get();
|
|
}
|
|
$unread_user = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)
|
|
->where('user_id', Auth::user()->id)
|
|
->where('is_read', '0')
|
|
->where('status', 'Y')
|
|
->first();
|
|
if($unread_user){
|
|
$unreadUpdate = WorkflowDocumentUser::where('id', '=', $unread_user->id)->update(['is_read'=>1]);
|
|
}
|
|
}else{
|
|
$workflowDocumentProcess=WorkflowDocumentProcess::where('workflow_document_id', $id)->orderBy('id', 'asc')->get();
|
|
$reply_workflow_document = WorkflowDocument::where('reply_for', $id)->first();
|
|
if(isset($reply_workflow_document))
|
|
{
|
|
$replyWorkflowDocumentProcess=WorkflowDocumentProcess::where('workflow_document_id', $reply_workflow_document->id)->orderBy('id', 'asc')->get();
|
|
}
|
|
$unread_user = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)
|
|
->where('user_id', Auth::user()->id)
|
|
->where('is_read', '0')
|
|
->where('status', 'Y')
|
|
->first();
|
|
if($unread_user){
|
|
$unreadUpdate = WorkflowDocumentUser::where('id', '=', $unread_user->id)->update(['is_read'=>1]);
|
|
}
|
|
}
|
|
$comments = Comment::where('workflow_document_id', $id)->orderBy('id', 'desc')->get();
|
|
return view('document-workflows.workflow', compact('workflowDocumentProcess', 'workflow_document', 'replyWorkflowDocumentProcess', 'comments'));
|
|
}else{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->back();
|
|
}
|
|
|
|
}
|
|
|
|
public function getNextRegNumber($type)
|
|
{
|
|
return response()->json(RegNumber::getNextRegNumber(auth()->user()->id, $type));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$data = request()->all();
|
|
if(isset($data['registration_date']))
|
|
$data['registration_date'] = \Carbon\Carbon::createFromFormat('Y-m-d', $data['registration_date'])->format('d-m-Y');
|
|
if(isset($data['contact_id']))
|
|
$data['contact_id'] = Contact::findOrFail($data['contact_id'])->organization_name;
|
|
|
|
|
|
if(check_permissions(1) !== true)
|
|
{
|
|
$type='Incoming';
|
|
Session::flash('error_message', __('You are not authorized to create a document workflow!'));
|
|
return redirect()->route('documents',$type);
|
|
}
|
|
$setting = Setting::first();
|
|
$workflow_types = WorkflowType::where('status', 1)->orderBy('id', 'asc')->get();
|
|
$priorities = Priority::orderBy('id', 'asc')->get();
|
|
$delivery_types = DeliveryType::orderBy('id', 'asc')->get();
|
|
$document_types = DocumentType::where('status', 1)->where('incoming', 1)->orderBy('id', 'asc')->get();
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
$users = User::getUserRole()->get();
|
|
|
|
return view('document-workflows.create', compact('setting', 'workflow_types', 'priorities', 'delivery_types', 'document_types', 'departments', 'users', 'data'));
|
|
}
|
|
|
|
public function createOutgoing()
|
|
{
|
|
$setting = Setting::first();
|
|
$workflow_types = WorkflowType::orderBy('id', 'asc')->get();
|
|
$priorities = Priority::orderBy('id', 'asc')->get();
|
|
$delivery_types = DeliveryType::orderBy('id', 'asc')->get();
|
|
$document_types = DocumentType::where('status', 1)->where('outgoing', 1)->orderBy('id', 'asc')->get();
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
$users = User:: getUserRole()->get();
|
|
|
|
return view('document-workflows.create_outging', compact('setting', 'workflow_types', 'priorities', 'delivery_types', 'document_types', 'departments','users'));
|
|
}
|
|
|
|
public function createInternal()
|
|
{
|
|
$setting = Setting::first();
|
|
$workflow_types = WorkflowType::orderBy('id', 'asc')->get();
|
|
$priorities = Priority::orderBy('id', 'asc')->get();
|
|
$delivery_types = DeliveryType::orderBy('id', 'asc')->get();
|
|
$document_types = DocumentType::where('status', 1)->where('internal', 1)->orderBy('id', 'asc')->get();
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
$users = User::getUserRole()->get();
|
|
|
|
return view('document-workflows.create_internal', compact('setting', 'workflow_types', 'priorities', 'delivery_types', 'document_types', 'departments','users'));
|
|
}
|
|
|
|
public function createWorkflowfreeOutgoing(Request $request)
|
|
{
|
|
$registration_number ='';
|
|
$reset_flag=false;
|
|
$setting = Setting::first();
|
|
$workflow_types = WorkflowType::orderBy('id', 'asc')->get();
|
|
$priorities = Priority::orderBy('id', 'asc')->get();
|
|
$delivery_types = DeliveryType::orderBy('id', 'asc')->get();
|
|
$document_types = DocumentType::where('status', 1)->where('outgoing', 1)->orderBy('id', 'asc')->get();
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
$users = User::getUserRole()->get();
|
|
|
|
return view('document-workflows.create_workflow_free_outgoing', compact('setting', 'workflow_types', 'priorities', 'delivery_types', 'document_types', 'departments','users'));
|
|
}
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function ddFilesStore(Request $request)
|
|
{
|
|
$input=$request->all();
|
|
if(isset($input['files']) && !empty($input['files']))
|
|
{
|
|
if($request->session()->has('documents')){
|
|
$documents = $request->session()->get('documents');
|
|
$documents->push($input['files']);
|
|
print_r($documents);
|
|
}
|
|
else{
|
|
$documents = collect([$input['files']]);
|
|
$request->session()->put('documents', $documents);
|
|
}
|
|
}
|
|
print_r($request->session()->get('documents'));
|
|
exit;
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$type='Incoming';
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
|
|
$input = $request->all();
|
|
if(isset($input['is_workflow_free']) && $input['is_workflow_free']==1)
|
|
{
|
|
$type = "Outgoing";
|
|
$input['registration_number'] =(isset($input['registration_number']) && strlen($input['registration_number'])>4) ? $input['registration_number'] : RegNumber::getNextRegNumber(auth()->user()->id, RegNumber::OUT);
|
|
}
|
|
elseif(isset($input['workflow_type_id']) && $input['workflow_type_id']== '2')
|
|
{
|
|
$type = "Outgoing";
|
|
$input['temporary_registration_number'] =(isset($input['registration_number']) && strlen($input['registration_number'])>4) ? $input['registration_number'] : RegNumber::getNextRegNumber(auth()->user()->id, RegNumber::TMP);
|
|
}
|
|
elseif(isset($input['workflow_type_id']) && $input['workflow_type_id']== '3')
|
|
{
|
|
$type = "Internal";
|
|
$input['registration_number']=(isset($input['registration_number']) && strlen($input['registration_number'])>4) ? $input['registration_number'] : RegNumber::getNextRegNumber(auth()->user()->id, RegNumber::ITR);
|
|
}
|
|
else
|
|
{
|
|
$input['registration_number']= (isset($input['registration_number']) && strlen($input['registration_number'])>4) ? $input['registration_number'] : RegNumber::getNextRegNumber(auth()->user()->id, RegNumber::INC);
|
|
}
|
|
$place_of_the_documents='documents/'.date('Y').'/'.Auth::user()->id;
|
|
|
|
(isset($input['is_workflow_free']) && $input['is_workflow_free']==1) ? $input['status']='Approved' : $input['status']='Pending';
|
|
|
|
$input['place_of_the_documents']=$place_of_the_documents;
|
|
$input['registration_date']=date('Y-m-d');
|
|
$input['creator_id']=Auth::user()->id;
|
|
$input['creator_name']=$document_user->first_name.' '.$document_user->last_name;
|
|
|
|
if(isset($input['related_documents'])) {
|
|
$input['related_documents'] = json_encode($input['related_documents']);
|
|
}
|
|
if(isset($input['workflow_type_id']) && $input['workflow_type_id'] > 0){
|
|
$workflow_type = WorkflowType::where('id', $input['workflow_type_id'])->first();
|
|
$input['workflow_type_name'] = $workflow_type->name;
|
|
$type_names=json_decode($workflow_type->name, true);
|
|
if(isset($type_names['en']))
|
|
$type = $type_names['en'];
|
|
}
|
|
if(isset($input['priority_id']) && $input['priority_id'] > 0){
|
|
$priority = Priority::where('id', $input['priority_id'])->first();
|
|
$input['priority_name'] = $priority->name;
|
|
$input['max_completion_days'] = $priority->completion_day;
|
|
}
|
|
if(isset($input['delivery_type_id']) && $input['delivery_type_id'] > 0){
|
|
$delivery_type = DeliveryType::where('id', $input['delivery_type_id'])->first();
|
|
$input['delivery_type_name'] = $delivery_type->name;
|
|
}
|
|
if(isset($input['document_type_id']) && $input['document_type_id'] > 0){
|
|
$document_type = DocumentType::where('id', $input['document_type_id'])->first();
|
|
$input['document_type_name'] = $document_type->name;
|
|
}
|
|
if(isset($input['due_date']) && $input['due_date'] != "")
|
|
$input['due_date'] = Carbon\Carbon::createFromFormat('d-m-Y', $input['due_date'])->format('Y-m-d');
|
|
if(isset($input['sender_letter_date']) && $input['sender_letter_date'] != "")
|
|
$input['sender_letter_date'] = Carbon\Carbon::createFromFormat('d-m-Y', $input['sender_letter_date'])->format('Y-m-d');
|
|
$saved_data=WorkflowDocument::create($input);
|
|
if($saved_data)
|
|
{
|
|
RegNumber::updateRegNumber($input['registration_number'] ?? $input['temporary_registration_number']);
|
|
|
|
$process_input['_token']=$input['_token'];
|
|
$process_input['workflow_document_id']=$saved_data->id;
|
|
$process_input['start_date']=date('Y-m-d');
|
|
|
|
if(isset($input['reviewers']) && $input['reviewers']!=''){
|
|
$reviewers=explode('-',$input['reviewers']);
|
|
if($reviewers[0] == 'uid')
|
|
{
|
|
$document_user_for_work = User::getUserDocument()->where('users.id', '=', $reviewers[1])->first();
|
|
}
|
|
elseif($reviewers[0] == 'did')
|
|
{
|
|
$department = Department::where('id',$reviewers[1])->first();
|
|
$document_user_for_work = User::getUserDocument()
|
|
->where('users.department_id', '=', $department->id)
|
|
->orderBy('role_user.role_id', 'asc')
|
|
->first();
|
|
}
|
|
}
|
|
if(!isset($document_user_for_work) || empty($document_user_for_work))
|
|
{
|
|
$document_user_for_work = User::getUserDocument()->where('roles.id', '=', 1)->first();
|
|
}
|
|
$condition = [];
|
|
if($document_user_for_work->id != ""):
|
|
array_push($condition, ['absents.user_id', '=', $document_user_for_work->id]);
|
|
$absent_date = date('Y-m-d');
|
|
array_push($condition, ['absents.start_date', '<=', $absent_date]);
|
|
array_push($condition, ['absents.end_date', '>=', $absent_date]);
|
|
$assign_absences = DB::table('absents')
|
|
->join('assign_absences', 'absents.id', '=', 'assign_absences.absent_id')
|
|
->select('assign_absences.*')
|
|
->where($condition)
|
|
->first();
|
|
if($assign_absences):
|
|
if(isset($document_user_for_work)){
|
|
$is_exist=WorkflowDocumentUser::where('workflow_document_id', $saved_data->id)->where('user_id', $document_user_for_work->id)->first();
|
|
if(!isset($is_exist) || empty($is_exist))
|
|
{
|
|
$supporter_input['_token']=$input['_token'];
|
|
$supporter_input['workflow_document_id']=$saved_data->id;
|
|
$supporter_input['user_id']=$document_user_for_work->id;
|
|
$supporter_input['process_id']=0;
|
|
$supporter_input['user_type']='S';
|
|
$supporter_input['user_name']=$document_user_for_work->first_name.' '.$document_user_for_work->last_name;
|
|
$supporter_input['user_email']=$document_user_for_work->email;
|
|
$supporter_input['user_role']=$document_user_for_work->role_name;
|
|
$supporter_input['added_by']=Auth::user()->id;
|
|
$supporter_department = Department::where('id',$document_user_for_work->department_id)->first();
|
|
if($supporter_department)
|
|
{
|
|
$supporter_input['user_department']=$supporter_department->name;
|
|
}
|
|
$supporter_save=WorkflowDocumentUser::create($supporter_input);
|
|
|
|
if($supporter_save)
|
|
{
|
|
$link = route('details', base64_encode($saved_data->id));
|
|
Notification::send(User::findOrFail($supporter_save->user_id), new DocumentNotification($saved_data->id, "supporter", "created", $link));
|
|
}
|
|
}
|
|
}
|
|
$document_user_for_work = User::join('role_user', 'users.id', '=', 'role_user.user_id')
|
|
->join('roles', 'role_user.role_id', '=', 'roles.id')
|
|
->where('users.id', '=', $assign_absences->user_id)
|
|
->select('users.*', 'roles.name as role_name', 'roles.id as role_id', 'users.id as id')
|
|
->first();
|
|
endif;
|
|
endif;
|
|
|
|
if(isset($input['is_workflow_free']) && $input['is_workflow_free']==1){
|
|
$process_input['status']='A';
|
|
}else{
|
|
$process_input['status']='P';
|
|
}
|
|
$process_input['user_id']=$document_user_for_work->id;
|
|
$process_input['user_name']=$document_user_for_work->first_name.' '.$document_user_for_work->last_name;
|
|
$process_input['user_email']=$document_user_for_work->email;
|
|
$process_input['user_role']=$document_user_for_work->role_name;
|
|
$document_user_for_work_department = Department::where('id',$document_user_for_work->department_id)->first();
|
|
if($document_user_for_work_department)
|
|
{
|
|
$process_input['user_department']=$document_user_for_work_department->name;
|
|
}
|
|
|
|
$process_input['assign_by']=Auth::user()->id;
|
|
$process_input['assigner_name']=$document_user->first_name.' '.$document_user->last_name;
|
|
$process_input['assigner_email']=$document_user->email;
|
|
$process_input['assign_date']=$input['registration_date'] . ' ' . date('H:i:s');
|
|
$process_input['assigner_role']=$document_user->role_name;
|
|
$document_user_department = Department::where('id',$document_user->department_id)->first();
|
|
if($document_user_department)
|
|
{
|
|
$process_input['assigner_department']=$document_user_department->name;
|
|
}
|
|
$process_save=WorkflowDocumentProcess::create($process_input);
|
|
|
|
if($assign_absences):
|
|
$supporter_update = WorkflowDocumentUser::where('workflow_document_id', $saved_data->id)->where('user_type','S')->where('process_id', 0)->update(['process_id' => $process_save->id]);
|
|
endif;
|
|
|
|
$reviewer_input['_token']=$input['_token'];
|
|
$reviewer_input['workflow_document_id']=$saved_data->id;
|
|
$reviewer_input['user_id']=$document_user_for_work->id;
|
|
$reviewer_input['process_id']=$process_save->id;
|
|
$reviewer_input['user_type']='R';
|
|
$reviewer_input['user_name']=$document_user_for_work->first_name.' '.$document_user_for_work->last_name;
|
|
$reviewer_input['user_email']=$document_user_for_work->email;
|
|
$reviewer_input['user_role']=$document_user_for_work->role_name;
|
|
$reviewer_input['added_by']=Auth::user()->id;
|
|
$reviewer_department = Department::where('id',$document_user_for_work->department_id)->first();
|
|
if($reviewer_department)
|
|
{
|
|
$reviewer_input['user_department']=$reviewer_department->name;
|
|
}
|
|
$reviewer_save=WorkflowDocumentUser::create($reviewer_input);
|
|
if($reviewer_save)
|
|
{
|
|
$link = route('details', base64_encode($saved_data->id));
|
|
Notification::send(User::findOrFail($reviewer_save->user_id), new DocumentNotification($saved_data->id, "reveiwer", "created", $link));
|
|
}
|
|
|
|
if(isset($input['supporters']) && is_array($input['supporters'])){
|
|
foreach($input['supporters'] as $supporter){
|
|
$supp_array=explode('-',$supporter);
|
|
if($supp_array[0] == 'uid')
|
|
{
|
|
$supporter_user = User::getUserDocument()->where('users.id', '=', $supp_array[1])->first();
|
|
}
|
|
elseif($supp_array[0] == 'did')
|
|
{
|
|
$department = Department::where('id',$supp_array[1])->first();
|
|
$supporter_user = User::getUserDocument()
|
|
->where('users.department_id', '=', $department->id)
|
|
->orderBy('role_user.role_id', 'asc')
|
|
->first();
|
|
}
|
|
if(isset($supporter_user)){
|
|
$is_exist=WorkflowDocumentUser::where('workflow_document_id', $saved_data->id)->where('user_id', $supporter_user->id)->first();
|
|
if(!isset($is_exist) || empty($is_exist))
|
|
{
|
|
$supporter_input['_token']=$input['_token'];
|
|
$supporter_input['workflow_document_id']=$saved_data->id;
|
|
$supporter_input['user_id']=$supporter_user->id;
|
|
$supporter_input['process_id']=$process_save->id;
|
|
$supporter_input['user_type']='S';
|
|
$supporter_input['user_name']=$supporter_user->first_name.' '.$supporter_user->last_name;
|
|
$supporter_input['user_email']=$supporter_user->email;
|
|
$supporter_input['user_role']=$supporter_user->role_name;
|
|
$supporter_input['added_by']=Auth::user()->id;
|
|
$supporter_department = Department::where('id',$supporter_user->department_id)->first();
|
|
if($supporter_department)
|
|
{
|
|
$supporter_input['user_department']=$supporter_department->name;
|
|
}
|
|
$supporter_save=WorkflowDocumentUser::create($supporter_input);
|
|
|
|
if($supporter_save)
|
|
{
|
|
$link = route('details', base64_encode($saved_data->id));
|
|
Notification::send(User::findOrFail($supporter_save->user_id), new DocumentNotification($saved_data->id, "supporter", "created", $link));
|
|
}
|
|
}else{
|
|
$exist_supporters = WorkflowDocumentUser::where('workflow_document_id', $saved_data->id)->where('user_type', 'S')->where('user_id', $supporter_user->id)->update(['status'=>'Y']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(isset($input['contact_id']) && is_array($input['contact_id'])){
|
|
foreach($input['contact_id'] as $contact){
|
|
$contact_user = Contact::where('id', '=', $contact)->first();
|
|
if(isset($contact_user)){
|
|
$contact_input['_token']=$input['_token'];
|
|
$contact_input['workflow_document_id']=$saved_data->id;
|
|
$contact_input['contact_id']=$contact_user->id;
|
|
$contact_input['contact_organization_name']=$contact_user->organization_name;
|
|
$contact_input['contact_alternative_name']=$contact_user->alternative_name;
|
|
$contact_input['contact_address']=$contact_user->address;
|
|
$contact_input['contact_telephone_number']=$contact_user->telephone_number;
|
|
$contact_save=WorkflowDocumentSender::create($contact_input);
|
|
}
|
|
}
|
|
}
|
|
if(isset($input['file_ids']) && $input['file_ids']!='')
|
|
{
|
|
$file_ids_array = explode(';',$input['file_ids']);
|
|
if(is_array($file_ids_array) && !empty($file_ids_array)){
|
|
foreach($file_ids_array as $key => $file_id){
|
|
$file = WorkflowDocumentFile::where('id',$file_id)->first();
|
|
if(isset($file))
|
|
{
|
|
$update_data = WorkflowDocumentFile::where('id',$file_id)->update([
|
|
'is_temp'=>0,
|
|
'is_signed'=>(isset($input['is_workflow_free']) && $input['is_workflow_free']==1 ? 1 : 0),
|
|
'process_id'=>$process_save->id,
|
|
'workflow_document_id'=>$saved_data->id
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Session::flash('success_message', __('Document has been added successfully'));
|
|
return redirect()->route('documents',$type);
|
|
}
|
|
else
|
|
{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->route('create_document_workflow');
|
|
}
|
|
}
|
|
|
|
public function view($id)
|
|
{
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::where('id', $id)->first();
|
|
$setting = Setting::first();
|
|
$workflow_types = WorkflowType::orderBy('id', 'asc')->get();
|
|
$priorities = Priority::orderBy('id', 'asc')->get();
|
|
$delivery_types = DeliveryType::orderBy('id', 'asc')->get();
|
|
$document_types = DocumentType::orderBy('id', 'asc')->get();
|
|
$senders = Contact::where('status', 1)->where('is_approved', 1)->orderBy('id', 'asc')->get();
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
$users = User::getUserRole()->get();
|
|
|
|
if($workflow_document){
|
|
$unread_user = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)
|
|
->where('user_id', Auth::user()->id)
|
|
->where('is_read', '0')
|
|
->where('status', 'Y')
|
|
->first();
|
|
if($unread_user){
|
|
$unreadUpdate = WorkflowDocumentUser::where('id', '=', $unread_user->id)->update(['is_read'=>1]);
|
|
}
|
|
return view('document-workflows.view', compact('setting', 'workflow_types', 'priorities', 'delivery_types', 'document_types', 'senders', 'departments', 'users', 'workflow_document'));
|
|
}else{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->back();
|
|
}
|
|
}
|
|
|
|
public function reject($id)
|
|
{
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::where('id', $id)->update(['is_rejected'=>1]);
|
|
if($workflow_document)
|
|
{
|
|
$outgoing_workflow_process = WorkflowDocumentProcess::where('workflow_document_id', '=', $id)->where('user_id', '=', Auth::user()->id)->orderBy('id', 'desc')->update(['end_date' => date('Y-m-d'), 'status' => 'RE']);
|
|
|
|
$users = WorkflowDocumentUser::where('workflow_document_id', '=', $id)
|
|
->where('status', 'Y')
|
|
->get();
|
|
$link = route('details', base64_encode($id));
|
|
if(!empty($users))
|
|
{
|
|
foreach($users as $user){
|
|
Notification::send(User::findOrFail($user->user_id), new DocumentNotification($workflow_document->id, "all", "rejected", $link));
|
|
}
|
|
}
|
|
Notification::send(User::findOrFail($workflow_document->creator_id), new DocumentNotification($workflow_document->id, "creator", "rejected", $link));
|
|
Session::flash('success_message', __('Document workflow has been updated successfully'));
|
|
return redirect()->back();
|
|
}
|
|
else
|
|
{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->back();
|
|
}
|
|
}
|
|
|
|
public function documentReply($id)
|
|
{
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::where('id', $id)->first();
|
|
$setting = Setting::first();
|
|
$priorities = Priority::orderBy('id', 'asc')->get();
|
|
$document_types = DocumentType::orderBy('id', 'asc')->get();
|
|
$workflow_process = WorkflowDocumentProcess::where('workflow_document_id', '=', $workflow_document->id)->where('user_id', '=', Auth::user()->id)->orderBy('id', 'desc')->first();
|
|
$approver = User::getUserDocument()
|
|
->where('users.id', '=', $workflow_process->assign_by)
|
|
->first();
|
|
|
|
$users = User::getUserRole()->get();
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
|
|
$approver_department = Department::where('id',$approver->department_id)->first();
|
|
|
|
return view('document-workflows.reply', compact('setting', 'priorities', 'document_types', 'workflow_document', 'approver', 'users', 'departments'));
|
|
}
|
|
|
|
public function approval($id)
|
|
{
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::where('id', $id)->first();
|
|
$setting = Setting::first();
|
|
$priorities = Priority::orderBy('id', 'asc')->get();
|
|
$document_types = DocumentType::orderBy('id', 'asc')->get();
|
|
$senders = Contact::where('status', 1)->where('is_approved', 1)->orderBy('id', 'asc')->get();
|
|
$workflow_process = WorkflowDocumentProcess::where('workflow_document_id', '=', $workflow_document->id)->where('user_id', '=', Auth::user()->id)->orderBy('id', 'desc')->first();
|
|
|
|
$approver = User::getUserDocument()->where('users.id', '=', $workflow_process->assign_by)->first();
|
|
$users = User::getUserRoles()->get();
|
|
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
$approver_department = Department::where('id',$approver->department_id)->first();
|
|
|
|
$documents = WorkflowDocument::orderBy('id', 'desc')->get();
|
|
return view('document-workflows.approval', compact('setting', 'priorities', 'document_types', 'senders', 'documents', 'workflow_document', 'approver', 'users', 'departments'));
|
|
}
|
|
|
|
public function storeReply(Request $request, $id)
|
|
{
|
|
$type='Outgoing';
|
|
$id=base64_decode($id);
|
|
$related_document = WorkflowDocument::findOrFail($id);
|
|
|
|
$data=false;
|
|
$setting = Setting::first();
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
|
|
$input = $request->all();
|
|
$place_of_the_documents='documents/'.date('Y').'/'.Auth::user()->id;
|
|
|
|
$workflow_process = WorkflowDocumentProcess::where('workflow_document_id', '=', $related_document->id)->where('user_id', '=', Auth::user()->id)->orderBy('id', 'desc')->first();
|
|
$update_process = WorkflowDocumentProcess::where('id', $workflow_process->id)->update(['end_date' => date('Y-m-d'), 'status' => 'SA']);
|
|
|
|
$approver = User::getUserDocument()->where('users.id', '=', $workflow_process->assign_by)->first();
|
|
$approver_department = Department::where('id',$approver->department_id)->first();
|
|
|
|
$temporary_registration_number = RegNumber::getNextRegNumber(auth()->user()->id, RegNumber::TMP);
|
|
|
|
$input['status']='Pending';
|
|
$input['place_of_the_documents']=$place_of_the_documents;
|
|
$input['temporary_registration_number']=$temporary_registration_number;
|
|
$input['registration_date']=date('Y-m-d');
|
|
$input['creator_id']=Auth::user()->id;
|
|
$input['creator_name']=$document_user->first_name.' '.$document_user->last_name;
|
|
|
|
if(isset($input['related_documents'])) {
|
|
$input['related_documents'] = json_encode($input['related_documents']);
|
|
}
|
|
$input['reply_for'] = $related_document->id;
|
|
|
|
if(isset($input['workflow_type_id']) && $input['workflow_type_id'] > 0){
|
|
$workflow_type = WorkflowType::where('id', $input['workflow_type_id'])->first();
|
|
$input['workflow_type_name'] = $workflow_type->name;
|
|
$type_names=json_decode($workflow_type->name, true);
|
|
if(isset($type_names['en']))
|
|
$type = $type_names['en'];
|
|
}
|
|
if(isset($input['priority_id']) && $input['priority_id'] > 0){
|
|
$priority = Priority::where('id', $input['priority_id'])->first();
|
|
$input['priority_name'] = $priority->name;
|
|
$input['max_completion_days'] = $priority->completion_day;
|
|
}
|
|
if(isset($input['document_type_id']) && $input['document_type_id'] > 0){
|
|
$document_type = DocumentType::where('id', $input['document_type_id'])->first();
|
|
$input['document_type_name'] = $document_type->name;
|
|
}
|
|
if(isset($input['due_date']) && $input['due_date'] != "")
|
|
$input['due_date'] = Carbon\Carbon::createFromFormat('d-m-Y', $input['due_date'])->format('Y-m-d');
|
|
$saved_data=WorkflowDocument::create($input);
|
|
if($saved_data)
|
|
{
|
|
RegNumber::updateRegNumber($input['registration_number'] ?? $input['temporary_registration_number']);
|
|
$update_process = WorkflowDocumentProcess::where('id', $workflow_process->id)->update(['end_date' => date('Y-m-d'), 'comment' =>$input['comment'], 'status' => 'SA']);
|
|
$process_input['_token']=$input['_token'];
|
|
$process_input['workflow_document_id']=$saved_data->id;
|
|
$process_input['start_date']=date('Y-m-d');
|
|
$process_input['status']='P';
|
|
$process_input['user_id']=$approver->id;
|
|
$process_input['user_name']=$approver->first_name.' '.$approver->last_name;
|
|
$process_input['user_email']=$approver->email;
|
|
$process_input['user_role']=$approver->role_name;
|
|
if($approver_department)
|
|
{
|
|
$process_input['user_department']=$approver_department->name;
|
|
}
|
|
|
|
$process_input['assign_by']=Auth::user()->id;
|
|
$process_input['assigner_name']=$document_user->first_name.' '.$document_user->last_name;
|
|
$process_input['assigner_email']=$document_user->email;
|
|
$process_input['assign_date']=$input['registration_date'] . ' ' . date('H:i:s');
|
|
$process_input['assigner_role']=$document_user->role_name;
|
|
$document_user_department = Department::where('id',$document_user->department_id)->first();
|
|
if($document_user_department)
|
|
{
|
|
$process_input['assigner_department']=$document_user_department->name;
|
|
}
|
|
$process_save=WorkflowDocumentProcess::create($process_input);
|
|
$reviewer_input['_token']=$input['_token'];
|
|
$reviewer_input['workflow_document_id']=$saved_data->id;
|
|
$reviewer_input['user_id']=$approver->id;
|
|
$reviewer_input['process_id']=$process_save->id;
|
|
$reviewer_input['user_type']='R';
|
|
$reviewer_input['user_name']=$approver->first_name.' '.$approver->last_name;
|
|
$reviewer_input['user_email']=$approver->email;
|
|
$reviewer_input['user_role']=$approver->role_name;
|
|
$reviewer_input['added_by']=Auth::user()->id;
|
|
if($approver_department)
|
|
{
|
|
$reviewer_input['user_department']=$approver_department->name;
|
|
}
|
|
$reviewer_save=WorkflowDocumentUser::create($reviewer_input);
|
|
if($reviewer_save)
|
|
{
|
|
$link = route('details', base64_encode($saved_data->id));
|
|
Notification::send(User::findOrFail($reviewer_save->user_id), new DocumentNotification($saved_data->id, "reveiwer", "created", $link));
|
|
}
|
|
if(isset($input['contact_id']) && is_array($input['contact_id'])){
|
|
foreach($input['contact_id'] as $contact){
|
|
$contact_user = Contact::where('id', '=', $contact)->first();
|
|
if(isset($contact_user)){
|
|
$contact_input['_token']=$input['_token'];
|
|
$contact_input['workflow_document_id']=$saved_data->id;
|
|
$contact_input['contact_id']=$contact_user->id;
|
|
$contact_input['contact_organization_name']=$contact_user->organization_name;
|
|
$contact_input['contact_alternative_name']=$contact_user->alternative_name;
|
|
$contact_input['contact_address']=$contact_user->address;
|
|
$contact_input['contact_telephone_number']=$contact_user->telephone_number;
|
|
$contact_save=WorkflowDocumentSender::create($contact_input);
|
|
}
|
|
}
|
|
}
|
|
|
|
if(isset($input['supporters']) && is_array($input['supporters'])){
|
|
foreach($input['supporters'] as $supporter){
|
|
$supp_array=explode('-',$supporter);
|
|
if($supp_array[0] == 'uid')
|
|
{
|
|
$supporter_user = User::getUserDocument()->where('users.id', '=', $supp_array[1])->first();
|
|
}
|
|
elseif($supp_array[0] == 'did')
|
|
{
|
|
$department = Department::where('id',$supp_array[1])->first();
|
|
$supporter_user = User::getUserDocument()
|
|
->where('users.department_id', '=', $department->id)
|
|
->orderBy('role_user.role_id', 'asc')
|
|
->first();
|
|
}
|
|
if(isset($supporter_user)){
|
|
$is_exist=WorkflowDocumentUser::where('workflow_document_id', $saved_data->id)->where('user_id', $supporter_user->id)->first();
|
|
if(!isset($is_exist) || empty($is_exist))
|
|
{
|
|
$supporter_input['_token']=$input['_token'];
|
|
$supporter_input['workflow_document_id']=$saved_data->id;
|
|
$supporter_input['user_id']=$supporter_user->id;
|
|
$supporter_input['process_id']=$process_save->id;
|
|
$supporter_input['user_type']='S';
|
|
$supporter_input['user_name']=$supporter_user->first_name.' '.$supporter_user->last_name;
|
|
$supporter_input['user_email']=$supporter_user->email;
|
|
$supporter_input['user_role']=$supporter_user->role_name;
|
|
$supporter_input['added_by']=Auth::user()->id;
|
|
$supporter_department = Department::where('id',$supporter_user->department_id)->first();
|
|
if($supporter_department)
|
|
{
|
|
$supporter_input['user_department']=$supporter_department->name;
|
|
}
|
|
$supporter_save=WorkflowDocumentUser::create($supporter_input);
|
|
|
|
if($supporter_save)
|
|
{
|
|
$link = route('details', base64_encode($saved_data->id));
|
|
Notification::send(User::findOrFail($supporter_save->user_id), new DocumentNotification($saved_data->id, "supporter", "created", $link));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(isset($input['file_ids']) && $input['file_ids']!='')
|
|
{
|
|
$file_ids_array = explode(';',$input['file_ids']);
|
|
if(is_array($file_ids_array) && !empty($file_ids_array)){
|
|
foreach($file_ids_array as $key => $file_id){
|
|
$file = WorkflowDocumentFile::where('id',$file_id)->first();
|
|
if(isset($file))
|
|
{
|
|
$update_data = WorkflowDocumentFile::where('id',$file_id)->update([
|
|
'is_temp'=>0,
|
|
'is_signed'=>(isset($input['is_workflow_free']) && $input['is_workflow_free']==1 ? 1 : 0),
|
|
'process_id'=>$process_save->id,
|
|
'workflow_document_id'=>$saved_data->id
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Session::flash('success_message', __('Document has been updated successfully'));
|
|
return redirect()->route('documents',$type);
|
|
}
|
|
else
|
|
{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->route('create_document_workflow');
|
|
}
|
|
}
|
|
|
|
public function storeApproval(Request $request, $id)
|
|
{
|
|
$type='Outgoing';
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::findOrFail($id);
|
|
$type = ($workflow_document->workflow_type_id == 3) ? 'Internal' : $type;
|
|
$place_of_the_documents='documents/'.date('Y').'/'.Auth::user()->id;
|
|
|
|
$data=false;
|
|
$new_version = 1;
|
|
$setting = Setting::first();
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
$related_documents = json_decode($workflow_document->related_documents, true);
|
|
if (!empty($related_documents)){
|
|
foreach($related_documents as $key=> $related_document_id){
|
|
$related_document = WorkflowDocument::where('id', $related_document_id)->first();
|
|
break;
|
|
}
|
|
}
|
|
$outgoing_workflow_process = WorkflowDocumentProcess::where('workflow_document_id', '=', $workflow_document->id)->where('user_id', '=', Auth::user()->id)->orderBy('id', 'desc')->first();
|
|
$userAsSupporter = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)->where('user_type','=','S')->where('status', '=', 'Y')->where('user_id', '=', Auth::user()->id)->first();
|
|
$input = $request->all();
|
|
|
|
if($userAsSupporter !== null)
|
|
{
|
|
if(isset($input['is_approved']) && $input['is_approved'] == 1)
|
|
{
|
|
$supporter_action='A';
|
|
$is_approved='Y';
|
|
}
|
|
else
|
|
{
|
|
$supporter_action='N';
|
|
$is_approved='N';
|
|
}
|
|
$update_process_user = WorkflowDocumentUser::where('id', $userAsSupporter->id)->update(['is_approved' => $is_approved]);
|
|
$process_input['_token']=$input['_token'];
|
|
$process_input['workflow_document_id']=$workflow_document->id;
|
|
$process_input['start_date']=date('Y-m-d');
|
|
$process_input['user_id']=$userAsSupporter->user_id;
|
|
$process_input['user_type']='S';
|
|
$process_input['supporter_action']= $supporter_action;
|
|
$process_input['user_name']=$userAsSupporter->user_name;
|
|
$process_input['user_email']=$userAsSupporter->user_email;
|
|
$process_input['user_role']=$userAsSupporter->user_role;
|
|
$process_input['user_department']=$userAsSupporter->user_department;
|
|
$process_input['comment']=$input['comment'];
|
|
|
|
$process_input['assign_date']=date('Y-m-d H:i:s');
|
|
$process_save=WorkflowDocumentProcess::create($process_input);
|
|
$data=true;
|
|
}
|
|
elseif($workflow_document->creator_id == Auth::user()->id)
|
|
{
|
|
$lastProcess=WorkflowDocumentProcess::where('workflow_document_id', $id)->where('user_id', Auth::user()->id)->where('status', 'P')->orderBy('id', 'desc')->first();
|
|
if(empty($lastProcess)){
|
|
$lastProcess=WorkflowDocumentProcess::where('workflow_document_id', $id)->where('user_id', Auth::user()->id)->orderBy('id', 'desc')->first();
|
|
}
|
|
$update_process = WorkflowDocumentProcess::where('id', $outgoing_workflow_process->id)->update(['end_date' => date('Y-m-d'), 'status'=>'SA', 'comment' =>$input['comment']]);
|
|
|
|
$process_input['_token']=$input['_token'];
|
|
$process_input['parent_id']=$outgoing_workflow_process->id;
|
|
$process_input['workflow_document_id']=$workflow_document->id;
|
|
$process_input['start_date']=date('Y-m-d');
|
|
$process_input['user_id']=$lastProcess->assign_by;
|
|
$process_input['user_name']=$lastProcess->assigner_name;
|
|
$process_input['user_email']=$lastProcess->assigner_email;
|
|
$process_input['user_role']=$lastProcess->assigner_role;
|
|
$process_input['user_department']=$lastProcess->assigner_department;
|
|
|
|
$process_input['assign_by']=$lastProcess->user_id;
|
|
$process_input['assigner_name']=$lastProcess->user_name;
|
|
$process_input['assigner_email']=$lastProcess->user_email;
|
|
$process_input['assign_date']=date('Y-m-d H:i:s');
|
|
$process_input['assigner_role']=$lastProcess->user_role;
|
|
$process_input['assigner_department'] = $lastProcess->user_department;
|
|
$process_save=WorkflowDocumentProcess::create($process_input);
|
|
|
|
|
|
$reviewer_input['_token']=$input['_token'];
|
|
$reviewer_input['workflow_document_id']=$workflow_document->id;
|
|
$reviewer_input['user_id']=$lastProcess->assign_by;
|
|
$reviewer_input['process_id']=$process_save->id;
|
|
$reviewer_input['user_type']='R';
|
|
$reviewer_input['user_name']=$lastProcess->assigner_name;
|
|
$reviewer_input['user_email']=$lastProcess->assigner_email;
|
|
$reviewer_input['user_role']=$lastProcess->assigner_role;
|
|
$reviewer_input['user_department']=$lastProcess->assigner_department;
|
|
$reviewer_input['added_by']=Auth::user()->id;
|
|
$reviewer_save=WorkflowDocumentUser::create($reviewer_input);
|
|
|
|
$last_scanned_document_version=WorkflowDocumentFile::where('workflow_document_id','=',$workflow_document->id)->orderBy('id', 'desc')->first();
|
|
if(isset($last_scanned_document_version) && $last_scanned_document_version->version > 0)
|
|
{
|
|
$update_last_scanned_document_version = WorkflowDocumentFile::where('workflow_document_id','=',$workflow_document->id)->update(['status' => 'N']);
|
|
$new_version = ($last_scanned_document_version->version + 1);
|
|
}
|
|
$data=true;
|
|
}
|
|
elseif(isset($input['is_approved']) && $input['is_approved'] == 1)
|
|
{
|
|
if($document_user->role_id ==1 || (isset($input['finalize']) && $input['finalize']==1))
|
|
{
|
|
$update_process = WorkflowDocumentProcess::where('id', $outgoing_workflow_process->id)->update(['end_date' => date('Y-m-d'), 'is_approved'=>'1', 'status'=>'A', 'comment' =>$input['comment']]);
|
|
if(isset($workflow_document->reply_for) && $workflow_document->reply_for > 0){
|
|
$update_reply_for = WorkflowDocument::where('id', $workflow_document->reply_for)->update(['status'=>'Complete']);
|
|
}
|
|
|
|
if($workflow_document->workflow_type_id == 2)
|
|
{
|
|
$registration_number = RegNumber::getNextRegNumber(auth()->user()->id, RegNumber::OUT);
|
|
$documentUpdate = WorkflowDocument::where('id', $workflow_document->id)->update(['registration_number' => $registration_number, 'status'=>'Approved']);
|
|
RegNumber::updateRegNumber($registration_number);
|
|
}
|
|
if($workflow_document->workflow_type_id == 3)
|
|
{
|
|
$documentUpdate = WorkflowDocument::where('id', $workflow_document->id)->update(['status'=>'Approved']);
|
|
RegNumber::updateRegNumber($workflow_document->registration_number);
|
|
}
|
|
|
|
|
|
$last_scanned_document_version=WorkflowDocumentFile::where('workflow_document_id','=',$workflow_document->id)->orderBy('id', 'desc')->first();
|
|
if(isset($last_scanned_document_version) && $last_scanned_document_version->version > 0)
|
|
{
|
|
$update_last_scanned_document_version = WorkflowDocumentFile::where('workflow_document_id','=',$workflow_document->id)->update(['status' => 'N']);
|
|
$new_version = ($last_scanned_document_version->version + 1);
|
|
}
|
|
if($workflow_document){
|
|
$link = route('details', base64_encode($id));
|
|
Notification::send(User::findOrFail($workflow_document->creator_id), new DocumentNotification($workflow_document->id, "creator", "approved", $link));
|
|
$users = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)
|
|
->where('status', 'Y')
|
|
->get();
|
|
if(!empty($users)){
|
|
foreach($users as $user){
|
|
$link = route('details', base64_encode($workflow_document->id));
|
|
Notification::send(User::findOrFail($user->user_id), new DocumentNotification($workflow_document->id, "reveiwer", "approved", $link));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(isset($workflow_document->reply_for) && $workflow_document->reply_for > 0)
|
|
{
|
|
// $related_document_workflow_process = WorkflowDocumentProcess::where('workflow_document_id', '=', $workflow_document->reply_for)->where('user_id', '=', Auth::user()->id)->orderBy('id', 'desc')->first();
|
|
$related_document_workflow_process = WorkflowDocumentProcess::where('workflow_document_id', '=', $workflow_document->reply_for)->orderBy('id', 'desc')->first();
|
|
$approver_id = $related_document_workflow_process->assign_by;
|
|
$approver = User::getUserDocument()->where('users.id', '=', $approver_id)->first();
|
|
}
|
|
else
|
|
{
|
|
if(isset($input['approver_id']) && $input['approver_id']!=''){
|
|
$reviewers=explode('-',$input['approver_id']);
|
|
if($reviewers[0] == 'uid')
|
|
{
|
|
$approver = User::getUserDocument()->where('users.id', '=', $reviewers[1])->first();
|
|
}
|
|
elseif($reviewers[0] == 'did')
|
|
{
|
|
$department = Department::where('id',$reviewers[1])->first();
|
|
$approver = User::getUserDocument()
|
|
->where('users.department_id', '=', $department->id)
|
|
->orderBy('role_user.role_id', 'asc')
|
|
->first();
|
|
}
|
|
}
|
|
}
|
|
$approver_department = Department::where('id',$approver->department_id)->first();
|
|
|
|
$update_process = WorkflowDocumentProcess::where('id', $outgoing_workflow_process->id)->update(['end_date' => date('Y-m-d'), 'is_approved'=>'1', 'comment' =>$input['comment'], 'status' => 'SA']);
|
|
$process_input['_token']=$input['_token'];
|
|
$process_input['workflow_document_id']=$workflow_document->id;
|
|
$process_input['start_date']=date('Y-m-d');
|
|
$process_input['status']='P';
|
|
$process_input['user_id']=$approver->id;
|
|
$process_input['user_name']=$approver->first_name.' '.$approver->last_name;
|
|
$process_input['user_email']=$approver->email;
|
|
$process_input['user_role']=$approver->role_name;
|
|
if($approver_department)
|
|
{
|
|
$process_input['user_department']=$approver_department->name;
|
|
}
|
|
|
|
$process_input['assign_by']=Auth::user()->id;
|
|
$process_input['assigner_name']=$document_user->first_name.' '.$document_user->last_name;
|
|
$process_input['assigner_email']=$document_user->email;
|
|
$process_input['assign_date']=date('Y-m-d H:i:s');
|
|
$process_input['assigner_role']=$document_user->role_name;
|
|
$document_user_department = Department::where('id',$document_user->department_id)->first();
|
|
if($document_user_department)
|
|
{
|
|
$process_input['assigner_department']=$document_user_department->name;
|
|
}
|
|
$process_save=WorkflowDocumentProcess::create($process_input);
|
|
$reviewer_input['_token']=$input['_token'];
|
|
$reviewer_input['workflow_document_id']=$workflow_document->id;
|
|
$reviewer_input['user_id']=$approver->id;
|
|
$reviewer_input['process_id']=$process_save->id;
|
|
$reviewer_input['user_type']='R';
|
|
$reviewer_input['user_name']=$approver->first_name.' '.$approver->last_name;
|
|
$reviewer_input['user_email']=$approver->email;
|
|
$reviewer_input['user_role']=$approver->role_name;
|
|
$reviewer_input['added_by']=Auth::user()->id;
|
|
if($approver_department)
|
|
{
|
|
$reviewer_input['user_department']=$approver_department->name;
|
|
}
|
|
$reviewer_save=WorkflowDocumentUser::create($reviewer_input);
|
|
|
|
$last_scanned_document_version=WorkflowDocumentFile::where('workflow_document_id','=',$workflow_document->id)->orderBy('id', 'desc')->first();
|
|
if(isset($last_scanned_document_version) && $last_scanned_document_version->version > 0)
|
|
{
|
|
$update_last_scanned_document_version = WorkflowDocumentFile::where('workflow_document_id','=',$workflow_document->id)->update(['status' => 'N']);
|
|
$new_version = ($last_scanned_document_version->version + 1);
|
|
}
|
|
|
|
if($reviewer_save){
|
|
$link = route('details', base64_encode($workflow_document->id));
|
|
Notification::send(User::findOrFail($reviewer_save->user_id), new DocumentNotification($workflow_document->id, "reveiwer", "approved", $link));
|
|
}
|
|
}
|
|
$data=true;
|
|
}
|
|
else
|
|
{
|
|
$lastProcess=WorkflowDocumentProcess::where('workflow_document_id', $id)->where('user_id', Auth::user()->id)->where('status', 'P')->orderBy('id', 'desc')->first();
|
|
if(empty($lastProcess)){
|
|
$lastProcess=WorkflowDocumentProcess::where('workflow_document_id', $id)->where('user_id', Auth::user()->id)->orderBy('id', 'desc')->first();
|
|
}
|
|
$update_process = WorkflowDocumentProcess::where('id', $outgoing_workflow_process->id)->update(['end_date' => date('Y-m-d'), 'status'=>'R', 'comment' =>$input['comment']]);
|
|
$process_input['_token']=$input['_token'];
|
|
$process_input['parent_id']=$outgoing_workflow_process->id;
|
|
$process_input['workflow_document_id']=$workflow_document->id;
|
|
$process_input['start_date']=date('Y-m-d');
|
|
$process_input['user_id']=$lastProcess->assign_by;
|
|
$process_input['user_name']=$lastProcess->assigner_name;
|
|
$process_input['user_email']=$lastProcess->assigner_email;
|
|
$process_input['user_role']=$lastProcess->assigner_role;
|
|
$process_input['user_department']=$lastProcess->assigner_department;
|
|
|
|
$process_input['assign_by']=$lastProcess->user_id;
|
|
$process_input['assigner_name']=$lastProcess->user_name;
|
|
$process_input['assigner_email']=$lastProcess->user_email;
|
|
$process_input['assign_date']=date('Y-m-d H:i:s');
|
|
$process_input['assigner_role']=$lastProcess->user_role;
|
|
$process_input['assigner_department'] = $lastProcess->user_department;
|
|
$process_save=WorkflowDocumentProcess::create($process_input);
|
|
|
|
if($lastProcess){
|
|
$link = route('details', base64_encode($workflow_document->id));
|
|
Notification::send(User::findOrFail($lastProcess->assign_by), new DocumentNotification($workflow_document->id, "reveiwer", "approved", $link));
|
|
}
|
|
|
|
$last_scanned_document_version=WorkflowDocumentFile::where('workflow_document_id','=',$workflow_document->id)->orderBy('id', 'desc')->first();
|
|
if(isset($last_scanned_document_version) && $last_scanned_document_version->version > 0)
|
|
{
|
|
$update_last_scanned_document_version = WorkflowDocumentFile::where('workflow_document_id','=',$workflow_document->id)->update(['status' => 'N']);
|
|
$new_version = ($last_scanned_document_version->version + 1);
|
|
}
|
|
$data=true;
|
|
}
|
|
|
|
if(isset($input['file_ids']) && $input['file_ids']!='')
|
|
{
|
|
$file_ids_array = explode(';',$input['file_ids']);
|
|
if(is_array($file_ids_array) && !empty($file_ids_array)){
|
|
foreach($file_ids_array as $key => $file_id){
|
|
$file = WorkflowDocumentFile::where('id',$file_id)->first();
|
|
if(isset($file))
|
|
{
|
|
$update_data = WorkflowDocumentFile::where('id',$file_id)->update([
|
|
'is_temp'=>0,
|
|
'version'=>$new_version,
|
|
'process_id'=>$outgoing_workflow_process->id,
|
|
'workflow_document_id'=>$workflow_document->id
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if($data==true)
|
|
{
|
|
Session::flash('success_message', __('Document has been updated successfully'));
|
|
return redirect()->route('documents',$type);
|
|
}
|
|
else
|
|
{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->back();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$type='Incoming';
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::where('id', $id)->first();
|
|
$setting = Setting::first();
|
|
$workflow_types = WorkflowType::orderBy('id', 'asc')->get();
|
|
$priorities = Priority::orderBy('id', 'asc')->get();
|
|
$delivery_types = DeliveryType::orderBy('id', 'asc')->get();
|
|
$document_types = DocumentType::orderBy('id', 'asc')->get();
|
|
$senders = Contact::where('status', 1)->where('is_approved', 1)->orderBy('id', 'asc')->get();
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
$users = User::getUserRole()->get();
|
|
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
if($workflow_document){
|
|
$unread_user = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)
|
|
->where('user_id', Auth::user()->id)
|
|
->where('is_read', '0')
|
|
->where('status', 'Y')
|
|
->first();
|
|
if($unread_user){
|
|
$unreadUpdate = WorkflowDocumentUser::where('id', '=', $unread_user->id)->update(['is_read'=>1]);
|
|
}
|
|
return view('document-workflows.edit', compact('setting', 'workflow_types', 'priorities', 'delivery_types', 'document_types', 'senders', 'departments', 'users', 'workflow_document', 'document_user'));
|
|
}else{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->route('documents',$type);
|
|
}
|
|
}
|
|
|
|
public function editAsSupporter($id)
|
|
{
|
|
$type='Incoming';
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::where('id', $id)->first();
|
|
$setting = Setting::first();
|
|
$workflow_types = WorkflowType::orderBy('id', 'asc')->get();
|
|
$priorities = Priority::orderBy('id', 'asc')->get();
|
|
$delivery_types = DeliveryType::orderBy('id', 'asc')->get();
|
|
$document_types = DocumentType::orderBy('id', 'asc')->get();
|
|
$senders = Contact::where('status', 1)->where('is_approved', 1)->orderBy('id', 'asc')->get();
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
$users = User::getUserRole()->get();
|
|
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
if($workflow_document){
|
|
$unread_user = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)
|
|
->where('user_id', Auth::user()->id)
|
|
->where('is_read', '0')
|
|
->where('status', 'Y')
|
|
->first();
|
|
if($unread_user){
|
|
$unreadUpdate = WorkflowDocumentUser::where('id', '=', $unread_user->id)->update(['is_read'=>1]);
|
|
}
|
|
return view('document-workflows.edit_as_supporter', compact('setting', 'workflow_types', 'priorities', 'delivery_types', 'document_types', 'senders', 'departments', 'users', 'workflow_document', 'document_user'));
|
|
}else{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->route('documents',$type);
|
|
}
|
|
}
|
|
|
|
public function editAsRegistry($id)
|
|
{
|
|
$type='Incoming';
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::where('id', $id)->first();
|
|
$setting = Setting::first();
|
|
$workflow_types = WorkflowType::orderBy('id', 'asc')->get();
|
|
$priorities = Priority::orderBy('id', 'asc')->get();
|
|
$delivery_types = DeliveryType::orderBy('id', 'asc')->get();
|
|
$document_types = DocumentType::orderBy('id', 'asc')->get();
|
|
$senders = Contact::where('status', 1)->where('is_approved', 1)->orderBy('id', 'asc')->get();
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
|
$users = User::getUserRole()->get();
|
|
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
if($workflow_document){
|
|
$unread_user = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)
|
|
->where('user_id', Auth::user()->id)
|
|
->where('is_read', '0')
|
|
->where('status', 'Y')
|
|
->first();
|
|
if($unread_user){
|
|
$unreadUpdate = WorkflowDocumentUser::where('id', '=', $unread_user->id)->update(['is_read'=>1]);
|
|
}
|
|
return view('document-workflows.edit_as_register', compact('setting', 'workflow_types', 'priorities', 'delivery_types', 'document_types', 'senders', 'departments', 'users', 'workflow_document', 'document_user'));
|
|
}else{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->route('documents',$type);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$type='Incoming';
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::findOrFail($id);
|
|
$setting = Setting::first();
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
$required = '';
|
|
if($request->status =='Delegate')
|
|
{
|
|
$required = 'required';
|
|
}
|
|
$validatedData = $this->validate($request, [
|
|
'reviewers' => $required,
|
|
'comment' => 'max:'.$setting->comment_text_limit,
|
|
]);
|
|
$input = $request->all();
|
|
if(isset($input['related_documents'])) {
|
|
$input['related_documents'] = json_encode($input['related_documents']);
|
|
}
|
|
$input['registration_number'] = $workflow_document->registration_number;
|
|
$input['registration_date'] = $workflow_document->registration_date;
|
|
$input['workflow_type_id'] = $workflow_document->workflow_type_id;
|
|
$input['workflow_type_name'] = $workflow_document->workflow_type_name;
|
|
$input['delivery_type_id'] = $workflow_document->delivery_type_id;
|
|
$input['delivery_type_name'] = $workflow_document->delivery_type_name;
|
|
$input['topic'] = $workflow_document->topic;
|
|
$input['additional_notes'] = $workflow_document->additional_notes;
|
|
|
|
if($input['priority_id'] && $input['priority_id'] > 0){
|
|
$priority = Priority::where('id', $input['priority_id'])->first();
|
|
$input['priority_name'] = $priority->name;
|
|
$input['max_completion_days'] = $priority->completion_day;
|
|
}
|
|
if($input['document_type_id'] && $input['document_type_id'] > 0){
|
|
$document_type = DocumentType::where('id', $input['document_type_id'])->first();
|
|
$input['document_type_name'] = $document_type->name;
|
|
}
|
|
if(isset($input['due_date']) && $input['due_date'] != "")
|
|
$input['due_date'] = Carbon\Carbon::createFromFormat('d-m-Y', $input['due_date'])->format('Y-m-d');
|
|
|
|
$parent_process_comment = $input['comment'];
|
|
$input['comment'] = $workflow_document->comment;
|
|
$saved_data=$workflow_document->fill($input)->save();
|
|
|
|
if($saved_data)
|
|
{
|
|
if($input['status']=='Delegate')
|
|
{
|
|
|
|
$parent_process = WorkflowDocumentProcess::where('user_id', Auth::user()->id)->where('workflow_document_id', $workflow_document->id)->orderBy('id', 'desc')->first();
|
|
$process_input['parent_id']= isset($parent_process->id) ? $parent_process->id : 0;
|
|
$process_input['workflow_document_id']=$workflow_document->id;
|
|
$process_input['start_date']=date('Y-m-d');
|
|
if(isset($input['reviewers']) && $input['reviewers']!=''){
|
|
$reviewers=explode('-',$input['reviewers']);
|
|
if($reviewers[0] == 'uid')
|
|
{
|
|
$document_user_for_work = User::getUserDocument()->where('users.id', '=', $reviewers[1])->first();
|
|
}
|
|
elseif($reviewers[0] == 'did')
|
|
{
|
|
if($workflow_document->workflow_type_id !=2)
|
|
{
|
|
$department = Department::where('id',$reviewers[1])->first();
|
|
$document_user_for_work = User::getUserDocument()
|
|
->where('users.department_id', '=', $department->id)
|
|
->where('role_user.role_id', '>', $document_user->role_id)
|
|
->orderBy('role_user.role_id', 'asc')
|
|
->first();
|
|
}
|
|
else
|
|
{
|
|
$department = Department::where('id',$reviewers[1])->first();
|
|
$document_user_for_work = User::getUserDocument()
|
|
->where('users.department_id', '=', $department->id)
|
|
->where('role_user.role_id', '<', $document_user->role_id)
|
|
->orderBy('role_user.role_id', 'desc')
|
|
->first();
|
|
}
|
|
}
|
|
}
|
|
$condition = [];
|
|
if($document_user_for_work->id != ""):
|
|
array_push($condition, ['absents.user_id', '=', $document_user_for_work->id]);
|
|
$absent_date = date('Y-m-d');
|
|
array_push($condition, ['absents.start_date', '<=', $absent_date]);
|
|
array_push($condition, ['absents.end_date', '>=', $absent_date]);
|
|
$assign_absences = DB::table('absents')
|
|
->join('assign_absences', 'absents.id', '=', 'assign_absences.absent_id')
|
|
->select('assign_absences.*')
|
|
->where($condition)
|
|
->first();
|
|
if($assign_absences):
|
|
if(isset($document_user_for_work)){
|
|
$is_exist=WorkflowDocumentUser::where('workflow_document_id', $workflow_document->id)->where('user_id', $document_user_for_work->id)->first();
|
|
if(!isset($is_exist) || empty($is_exist))
|
|
{
|
|
$supporter_input['_token']=$input['_token'];
|
|
$supporter_input['workflow_document_id']=$workflow_document->id;
|
|
$supporter_input['user_id']=$document_user_for_work->id;
|
|
$supporter_input['process_id']=0;
|
|
$supporter_input['user_type']='S';
|
|
$supporter_input['user_name']=$document_user_for_work->first_name.' '.$document_user_for_work->last_name;
|
|
$supporter_input['user_email']=$document_user_for_work->email;
|
|
$supporter_input['user_role']=$document_user_for_work->role_name;
|
|
$supporter_input['added_by']=Auth::user()->id;
|
|
$supporter_department = Department::where('id',$document_user_for_work->department_id)->first();
|
|
if($supporter_department)
|
|
{
|
|
$supporter_input['user_department']=$supporter_department->name;
|
|
}
|
|
$supporter_save=WorkflowDocumentUser::create($supporter_input);
|
|
|
|
if($supporter_save)
|
|
{
|
|
$link = route('details', base64_encode($workflow_document->id));
|
|
Notification::send(User::findOrFail($supporter_save->user_id), new DocumentNotification($workflow_document->id, "supporter", "updated", $link));
|
|
}
|
|
}
|
|
}
|
|
$document_user_for_work = User::getUserDocument()->where('users.id', '=', $assign_absences->user_id)->first();
|
|
endif;
|
|
endif;
|
|
|
|
$process_input['status']='P';
|
|
$process_input['user_id']=$document_user_for_work->id;
|
|
$process_input['user_name']=$document_user_for_work->first_name.' '.$document_user_for_work->last_name;
|
|
$process_input['user_email']=$document_user_for_work->email;
|
|
$process_input['user_role']=$document_user_for_work->role_name;
|
|
$document_user_for_work_department = Department::where('id',$document_user_for_work->department_id)->first();
|
|
if($document_user_for_work_department)
|
|
{
|
|
$process_input['user_department']=$document_user_for_work_department->name;
|
|
}
|
|
|
|
$process_input['assign_by']=Auth::user()->id;
|
|
$process_input['assigner_name']=$document_user->first_name.' '.$document_user->last_name;
|
|
$process_input['assigner_email']=$document_user->email;
|
|
$process_input['assign_date']=date('Y-m-d H:i:s');
|
|
$process_input['assigner_role']=$document_user->role_name;
|
|
$document_user_department = Department::where('id',$document_user->department_id)->first();
|
|
if($document_user_department)
|
|
{
|
|
$process_input['assigner_department'] = $document_user_department->name;
|
|
}
|
|
|
|
$process_save=WorkflowDocumentProcess::create($process_input);
|
|
if($process_save){
|
|
if(isset($parent_process)){
|
|
$update_parent_process = WorkflowDocumentProcess::where('id', $parent_process->id)->update(['end_date' => date('Y-m-d'), 'status'=>'D', 'comment' =>$parent_process_comment]);
|
|
}
|
|
if($assign_absences):
|
|
$supporter_update = WorkflowDocumentUser::where('workflow_document_id', $saved_data->id)->where('user_type','S')->where('process_id', 0)->update(['process_id' => $process_save->id]);
|
|
endif;
|
|
}
|
|
|
|
$reviewer_input['workflow_document_id']=$workflow_document->id;
|
|
$reviewer_input['user_id']=$document_user_for_work->id;
|
|
$reviewer_input['process_id']=$process_save->id;
|
|
$reviewer_input['user_type']='R';
|
|
$reviewer_input['user_name']=$document_user_for_work->first_name.' '.$document_user_for_work->last_name;
|
|
$reviewer_input['user_email']=$document_user_for_work->email;
|
|
$reviewer_input['user_role']=$document_user_for_work->role_name;
|
|
$reviewer_input['added_by']=Auth::user()->id;
|
|
$supporter_department = Department::where('id',$document_user_for_work->department_id)->first();
|
|
if($supporter_department)
|
|
{
|
|
$reviewer_input['user_department']=$supporter_department->name;
|
|
}
|
|
$reviewer_save=WorkflowDocumentUser::create($reviewer_input);
|
|
|
|
if($reviewer_save){
|
|
$link = route('details', base64_encode($workflow_document->id));
|
|
Notification::send(User::findOrFail($reviewer_save->user_id), new DocumentNotification($workflow_document->id, "reveiwer", "updated", $link));
|
|
}
|
|
}
|
|
|
|
$prev_supporters = WorkflowDocumentUser::where('workflow_document_id', $workflow_document->id)->where('user_type', 'S')->update(['status'=>'N']);
|
|
if(isset($input['supporters']) && is_array($input['supporters'])){
|
|
foreach($input['supporters'] as $supporter){
|
|
$supp_array=explode('-',$supporter);
|
|
if($supp_array[0] == 'uid')
|
|
{
|
|
$supporter_user = User::getUserDocument()->where('users.id', '=', $supp_array[1])->first();
|
|
}
|
|
elseif($supp_array[0] == 'did')
|
|
{
|
|
$department = Department::where('id',$supp_array[1])->first();
|
|
$supporter_user = User::getUserDocument()
|
|
->where('users.department_id', '=', $department->id)
|
|
->orderBy('role_user.role_id', 'asc')
|
|
->first();
|
|
}
|
|
if(isset($supporter_user)){
|
|
$prev_support = WorkflowDocumentUser::where('user_id', $supporter_user->id)->where('workflow_document_id', $workflow_document->id)->first();
|
|
if($prev_support)
|
|
{
|
|
$update_supporter = WorkflowDocumentUser::where('user_id', $supporter_user->id)->where('workflow_document_id', $workflow_document->id)->update(['status'=>'Y']);
|
|
}
|
|
else
|
|
{
|
|
$supporter_input['_token']=$input['_token'];
|
|
$supporter_input['workflow_document_id']=$workflow_document->id;
|
|
$supporter_input['user_id']=$supporter_user->id;
|
|
$supporter_input['process_id']=$process_save->id;
|
|
$supporter_input['user_type']='S';
|
|
$supporter_input['user_name']=$supporter_user->first_name.' '.$supporter_user->last_name;
|
|
$supporter_input['user_email']=$supporter_user->email;
|
|
$supporter_input['user_role']=$supporter_user->role_name;
|
|
$supporter_input['added_by']=Auth::user()->id;
|
|
$supporter_department = Department::where('id',$supporter_user->department_id)->first();
|
|
if($supporter_department)
|
|
{
|
|
$supporter_input['user_department']=$supporter_department->name;
|
|
}
|
|
$supporter_save=WorkflowDocumentUser::create($supporter_input);
|
|
|
|
if($supporter_save){
|
|
$link = route('details', base64_encode($workflow_document->id));
|
|
Notification::send(User::findOrFail($supporter_save->user_id), new DocumentNotification($workflow_document->id, "supporter", "updated", $link));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Session::flash('success_message', __('Document workflow has been updated successfully'));
|
|
return redirect()->route('documents',$type);
|
|
}
|
|
else
|
|
{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->route('document_workflow');
|
|
}
|
|
}
|
|
|
|
public function updateAsSupporter(Request $request, $id)
|
|
{
|
|
$type='Incoming';
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::findOrFail($id);
|
|
$setting = Setting::first();
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
$required = '';
|
|
$input = $request->all();
|
|
if(isset($input['related_documents'])) {
|
|
$input['related_documents'] = json_encode($input['related_documents']);
|
|
}
|
|
|
|
$process_input = $input;
|
|
$saved_data=$workflow_document->fill($input)->save();
|
|
|
|
if($saved_data)
|
|
{
|
|
if(isset($input['supporters']) && is_array($input['supporters'])){
|
|
foreach($input['supporters'] as $supporter){
|
|
$supp_array=explode('-',$supporter);
|
|
if($supp_array[0] == 'uid')
|
|
{
|
|
$supporter_user = User::getUserDocument()->where('users.id', '=', $supp_array[1])->first();
|
|
}
|
|
elseif($supp_array[0] == 'did')
|
|
{
|
|
$department = Department::where('id',$supp_array[1])->first();
|
|
$supporter_user = User::getUserDocument()
|
|
->where('users.department_id', '=', $department->id)
|
|
->orderBy('role_user.role_id', 'asc')
|
|
->first();
|
|
}
|
|
if(isset($supporter_user)){
|
|
$prev_support = WorkflowDocumentUser::where('user_id', $supporter_user->id)->where('workflow_document_id', $workflow_document->id)->first();
|
|
if($prev_support)
|
|
{
|
|
$update_supporter = WorkflowDocumentUser::where('user_id', $supporter_user->id)->where('workflow_document_id', $workflow_document->id)->update(['status'=>'Y']);
|
|
}
|
|
else
|
|
{
|
|
$supporter_input['_token']=$input['_token'];
|
|
$supporter_input['workflow_document_id']=$workflow_document->id;
|
|
$supporter_input['user_id']=$supporter_user->id;
|
|
$supporter_input['user_type']='S';
|
|
$supporter_input['user_name']=$supporter_user->first_name.' '.$supporter_user->last_name;
|
|
$supporter_input['user_email']=$supporter_user->email;
|
|
$supporter_input['user_role']=$supporter_user->role_name;
|
|
$supporter_input['added_by']=Auth::user()->id;
|
|
$supporter_department = Department::where('id',$supporter_user->department_id)->first();
|
|
if($supporter_department)
|
|
{
|
|
$supporter_input['user_department']=$supporter_department->name;
|
|
}
|
|
$supporter_save=WorkflowDocumentUser::create($supporter_input);
|
|
if($supporter_save){
|
|
$link = route('details', base64_encode($workflow_document->id));
|
|
Notification::send(User::findOrFail($supporter_save->user_id), new DocumentNotification($workflow_document->id, "supporter", "updated", $link));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Session::flash('success_message', __('Document workflow has been updated successfully'));
|
|
return redirect()->route('documents',$type);
|
|
}
|
|
else
|
|
{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->route('document_workflow');
|
|
}
|
|
}
|
|
|
|
public function updateAsRegistry(Request $request, $id)
|
|
{
|
|
$type='Incoming';
|
|
$data=false;
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::findOrFail($id);
|
|
$setting = Setting::first();
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
|
|
$input = $request->all();
|
|
$place_of_the_documents=$workflow_document->place_of_the_documents;
|
|
|
|
$workflow_process = WorkflowDocumentProcess::where('workflow_document_id', '=', $workflow_document->id)->orderBy('id', 'asc')->first();
|
|
if(isset($input['file_ids']) && $input['file_ids']!='')
|
|
{
|
|
$file_ids_array = explode(';',$input['file_ids']);
|
|
if(is_array($file_ids_array) && !empty($file_ids_array)){
|
|
foreach($file_ids_array as $key => $file_id){
|
|
$file = WorkflowDocumentFile::where('id',$file_id)->first();
|
|
if(isset($file))
|
|
{
|
|
$update_data = WorkflowDocumentFile::where('id',$file_id)->update([
|
|
'is_temp'=>0,
|
|
'process_id'=>$workflow_process->id,
|
|
'workflow_document_id'=>$workflow_document->id
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Session::flash('success_message', __('Document workflow has been updated successfully'));
|
|
return redirect()->route('documents',$type);
|
|
}
|
|
|
|
public function signedDocumentsStore(Request $request, $id)
|
|
{
|
|
$data=false;
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::findOrFail($id);
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
$input = $request->all();
|
|
$place_of_the_documents=$workflow_document->place_of_the_documents;
|
|
|
|
$workflow_process = WorkflowDocumentProcess::where('workflow_document_id', $workflow_document->id)->orderBy('id', 'desc')->first();
|
|
if(isset($input['file_ids']) && $input['file_ids']!='')
|
|
{
|
|
$version = WorkflowDocumentFile::where('workflow_document_id', $workflow_document->id)->max('version');
|
|
$file_ids_array = explode(';',$input['file_ids']);
|
|
if(is_array($file_ids_array) && !empty($file_ids_array)){
|
|
foreach($file_ids_array as $key => $file_id){
|
|
$file = WorkflowDocumentFile::where('id',$file_id)->first();
|
|
if(isset($file))
|
|
{
|
|
$update_data = WorkflowDocumentFile::where('id',$file_id)->update([
|
|
'is_temp'=>0,
|
|
'is_signed'=>1,
|
|
'version'=>$version,
|
|
'process_id'=>$workflow_process->id,
|
|
'workflow_document_id'=>$workflow_document->id
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Session::flash('success_message', __('Document workflow has been updated successfully'));
|
|
return redirect()->back();
|
|
}
|
|
|
|
public function storeReturn(Request $request, $id)
|
|
{
|
|
$type='Incoming';
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::findOrFail($id);
|
|
$setting = Setting::first();
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
|
|
$lastProcess=WorkflowDocumentProcess::where('workflow_document_id', $id)->where('user_id', Auth::user()->id)->where('status', 'D')->orderBy('id', 'desc')->first();
|
|
if(empty($lastProcess)){
|
|
$lastProcess=WorkflowDocumentProcess::where('workflow_document_id', $id)->where('user_id', Auth::user()->id)->orderBy('id', 'desc')->first();
|
|
}
|
|
$process_input = $request->all();
|
|
|
|
$parent_process = WorkflowDocumentProcess::where('user_id', Auth::user()->id)->where('workflow_document_id', $workflow_document->id)->orderBy('id', 'desc')->first();
|
|
$process_input['parent_id']=$parent_process->id;
|
|
$process_input['workflow_document_id']=$workflow_document->id;
|
|
$process_input['start_date']=date('Y-m-d');
|
|
$process_input['status']='P';
|
|
$parent_process_comment = $process_input['comment'];
|
|
$process_input['comment']='';
|
|
$process_input['user_id']=$lastProcess->assign_by;
|
|
$process_input['user_name']=$lastProcess->assigner_name;
|
|
$process_input['user_email']=$lastProcess->assigner_email;
|
|
$process_input['user_role']=$lastProcess->assigner_role;
|
|
$process_input['user_department']=$lastProcess->assigner_department;
|
|
|
|
$process_input['assign_by']=$lastProcess->user_id;
|
|
$process_input['assigner_name']=$lastProcess->user_name;
|
|
$process_input['assigner_email']=$lastProcess->user_email;
|
|
$process_input['assign_date']=date('Y-m-d H:i:s');
|
|
$process_input['assigner_role']=$lastProcess->user_role;
|
|
$process_input['assigner_department'] = $lastProcess->user_department;
|
|
$process_save=WorkflowDocumentProcess::create($process_input);
|
|
if($process_save){
|
|
$unread_user = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)
|
|
->where('user_id', Auth::user()->id)
|
|
->where('is_read', '0')
|
|
->where('status', 'Y')
|
|
->first();
|
|
if($unread_user){
|
|
$unreadUpdate = WorkflowDocumentUser::where('id', '=', $unread_user->id)->update(['is_read'=>1]);
|
|
}
|
|
if(isset($parent_process)){
|
|
$update_parent_process = WorkflowDocumentProcess::where('id', $parent_process->id)->update(['end_date' => date('Y-m-d'), 'status'=>'R', 'comment' =>$parent_process_comment]);
|
|
}
|
|
if($lastProcess){
|
|
$link = route('details', base64_encode($workflow_document->id));
|
|
Notification::send(User::findOrFail($lastProcess->assign_by), new DocumentNotification($workflow_document->id, "all", "returned", $link));
|
|
}
|
|
|
|
Session::flash('success_message', __('Document workflow has been Returned successfully'));
|
|
return redirect()->route('documents',$type);
|
|
}
|
|
else
|
|
{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->route('document_workflow');
|
|
}
|
|
}
|
|
|
|
public function storeComplete(Request $request, $id)
|
|
{
|
|
$type='Incoming';
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::findOrFail($id);
|
|
$setting = Setting::first();
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
$input = $request->all();
|
|
$process_input = $input;
|
|
$input['status']='Complete';
|
|
$parent_process_comment = $input['comment'];
|
|
$input['comment'] = $workflow_document->comment;
|
|
$saved_data=$workflow_document->fill($input)->save();
|
|
if($saved_data)
|
|
{
|
|
$unread_user = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)
|
|
->where('user_id', Auth::user()->id)
|
|
->where('is_read', '0')
|
|
->where('status', 'Y')
|
|
->first();
|
|
if($unread_user){
|
|
$unreadUpdate = WorkflowDocumentUser::where('id', '=', $unread_user->id)->update(['is_read'=>1, 'status'=>'N']);
|
|
}
|
|
$process = WorkflowDocumentProcess::where('user_id', Auth::user()->id)->where('workflow_document_id', $workflow_document->id)->orderBy('id', 'desc')->first();
|
|
if(isset($process)){
|
|
$update_process = WorkflowDocumentProcess::where('id', $process->id)->update(['end_date' => date('Y-m-d'), 'status'=>'CO', 'comment' =>$parent_process_comment]);
|
|
}
|
|
if($workflow_document){
|
|
$link = route('details', base64_encode($workflow_document->id));
|
|
Notification::send(User::findOrFail($workflow_document->creator_id), new DocumentNotification($workflow_document->id, "creator", "completed", $link));
|
|
$users = WorkflowDocumentUser::where('workflow_document_id', '=', $workflow_document->id)
|
|
->where('status', 'Y')
|
|
->get();
|
|
if(!empty($users)){
|
|
foreach($users as $user){
|
|
Notification::send(User::findOrFail($user->user_id), new DocumentNotification($workflow_document->id, "all", "completed", $link));
|
|
}
|
|
}
|
|
}
|
|
|
|
Session::flash('success_message', __('Document workflow has been Completed successfully'));
|
|
return redirect()->route('documents',$type);
|
|
}
|
|
else
|
|
{
|
|
Session::flash('error_message', __('We are having some problem. Please try later.'));
|
|
return redirect()->route('document_workflow');
|
|
}
|
|
}
|
|
|
|
public function storeFiles(Request $request)
|
|
{
|
|
$input = $request->all();
|
|
// return response()->json(['data'=>$input['files']]);
|
|
if(isset($input['file_api']))
|
|
{
|
|
$filex = new UploadedFile(
|
|
public_path() . '/' . $input['file_api'], pathinfo($input['file_api'])['basename'], mime_content_type(public_path().'/'.$input['file_api']),
|
|
null,
|
|
false
|
|
);
|
|
|
|
$input['files'] = $filex;
|
|
// return response()->json(['data'=>$filex->getClientOriginalExtension()]);
|
|
}
|
|
|
|
$setting = Setting::first();
|
|
$document_user = User::getUserDocument()->where('users.id', '=', Auth::user()->id)->first();
|
|
$place_of_the_documents='documents/'.date('Y').'/'.Auth::user()->id;
|
|
|
|
$input['place_of_the_documents']= $place_of_the_documents;
|
|
$input['user_id']=Auth::user()->id;
|
|
|
|
if(isset($input['files']) && is_array($input['files']) && !empty($input['files']))
|
|
{
|
|
foreach($input['files'] as $key => $file)
|
|
{
|
|
if(isset($file) && $file->getError() == 0 && $file->getClientOriginalName() != "")
|
|
{
|
|
$document_number=1;
|
|
$last_scanned_document=WorkflowDocumentFile::where('uploaded_by','=',Auth::user()->id)->orderBy('id', 'desc')->first();
|
|
if(isset($last_scanned_document) && $last_scanned_document->document_name != '')
|
|
{
|
|
$doc_name = explode('.',$last_scanned_document->document_name);
|
|
$base_name_array = explode('-',$doc_name[0]);
|
|
$base_name = end($base_name_array);
|
|
$document_number = ($base_name + 1);
|
|
}
|
|
$document_name = ($setting->document_name_prefix && $setting->document_name_prefix !="" ? $setting->document_name_prefix."-" : "" ).time().'-'.$document_number.'.'.$file->getClientOriginalExtension();
|
|
$input['document_name']=$document_name;
|
|
|
|
$input['place_of_the_documents']=$place_of_the_documents;
|
|
$input['document_type']='S';
|
|
$input['uploaded_by']=Auth::user()->id;
|
|
$input['uploader_name']=$document_user->first_name.' '.$document_user->last_name;
|
|
$document_save=WorkflowDocumentFile::create($input);
|
|
if($document_save){
|
|
$file->move(public_path($place_of_the_documents), $document_name);
|
|
$files_val[$key]['data']= $document_save;
|
|
$files_val[$key]['type']= 'success';
|
|
$files_val[$key]['message']= __('File uploaded successfully');
|
|
|
|
if(!in_array($file->getClientOriginalExtension(), ['pdf', 'zip', 'tar', 'rar', 'exe', 'gz']))
|
|
{
|
|
shell_exec('export HOME=/tmp && /usr/bin/libreoffice --headless --convert-to pdf ' . public_path($place_of_the_documents) . '/' . $document_name . ' --outdir ' . public_path($place_of_the_documents));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$file = $input['files'];
|
|
$key = 0;
|
|
if(isset($file) && $file->getError() == 0 && $file->getClientOriginalName() != "")
|
|
{
|
|
$document_number=1;
|
|
$last_scanned_document=WorkflowDocumentFile::where('uploaded_by','=',Auth::user()->id)->orderBy('id', 'desc')->first();
|
|
if(isset($last_scanned_document) && $last_scanned_document->document_name != '')
|
|
{
|
|
$doc_name = explode('.',$last_scanned_document->document_name);
|
|
$base_name_array = explode('-',$doc_name[0]);
|
|
$base_name = end($base_name_array);
|
|
$document_number = ($base_name + 1);
|
|
}
|
|
$document_name = ($setting->document_name_prefix && $setting->document_name_prefix !="" ? $setting->document_name_prefix."-" : "" ).time().'-'.$document_number.'.'.$file->getClientOriginalExtension();
|
|
$input['document_name']=$document_name;
|
|
$input['place_of_the_documents']=$place_of_the_documents;
|
|
$input['document_type']='S';
|
|
$input['uploaded_by']=Auth::user()->id;
|
|
$input['uploader_name']=$document_user->first_name.' '.$document_user->last_name;
|
|
$document_save=WorkflowDocumentFile::create($input);
|
|
if($document_save){
|
|
if(isset($input['file_api']))
|
|
\File::copy(public_path($input['file_api']), public_path($place_of_the_documents).'/'.$document_name);
|
|
else
|
|
$file->move(public_path($place_of_the_documents), $document_name);
|
|
$files_val[$key]['data']= $document_save;
|
|
$files_val[$key]['type']= 'success';
|
|
$files_val[$key]['message']= __('File uploaded successfully');
|
|
|
|
|
|
if(!in_array($file->getClientOriginalExtension(), ['pdf', 'zip', 'tar', 'rar', 'exe', 'gz']))
|
|
{
|
|
shell_exec('export HOME=/tmp && /usr/bin/libreoffice --headless --convert-to pdf ' . public_path($place_of_the_documents) . '/' . $document_name . ' --outdir ' . public_path($place_of_the_documents));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return response()->json($files_val);
|
|
}
|
|
|
|
public function deleteFiles(Request $request)
|
|
{
|
|
$input = $request->all();
|
|
|
|
$file = WorkflowDocumentFile::findOrFail($input['id']);
|
|
$delete_file = $file->delete();
|
|
if($delete_file):
|
|
unlink(public_path($file->place_of_the_documents.'/'.$file->document_name));
|
|
endif;
|
|
echo __('Deleted File ').$file->document_name;
|
|
}
|
|
} |