edms/app/WorkflowDocument.php

131 lines
3.2 KiB
PHP

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
class WorkflowDocument extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'workflow_documents';
protected $fillable = [
'workflow_type_id',
'workflow_type_name',
'due_date',
'priority_id',
'priority_name',
'max_completion_days',
'temporary_registration_number',
'registration_number',
'registration_date',
'delivery_type_id',
'delivery_type_name',
'document_type_id',
'document_type_name',
'sender_letter_number',
'sender_letter_date',
'topic',
'additional_notes',
'place_of_the_documents',
'comment',
'creator_id',
'creator_name',
'related_documents',
'reply_for',
'is_deleted',
'is_rejected',
'is_workflow_free',
'status',
];
protected $casts = [
'sender_letter_date' => 'date:d-m-Y'
];
public function isSigned()
{
return WorkflowDocumentFile::where('workflow_document_id', $this->id)->where('is_signed', 1)->count() >= 1;
}
public function getRegistrationDate()
{
return ($this->registration_date != null) ? Carbon::parse($this->registration_date)->format('d-m-Y') .' '. Carbon::parse($this->created_at)->format('H:i') : Carbon::parse($this->created_at)->format('d-m-Y H:i');
}
public function getSenderName()
{
$wd = WorkflowDocumentSender::where('workflow_document_id', $this->id)->first();
$wd = ($wd != null) ? $wd->contact_organization_name : '';
if($this->workflow_type_id == 3)
$wd = $this->creator_name;
return $wd;
}
public function getRegNumber()
{
return ($this->registration_number != '') ? $this->registration_number : $this->temporary_registration_number;
}
public function hasSenderAPI()
{
if($this->status != "Approved")
return false;
if(!WorkflowDocumentFile::where('workflow_document_id', $this->id)->where('is_temp', 0)->where('is_signed', 1)->exists())
return false;
if(!in_array(13, auth()->user()->getPermissionList()))
return false;
$remotecontacts = RemoteContact::where('direction', 1)->whereIn('contact_id', WorkflowDocumentSender::where('workflow_document_id', $this->id)->pluck('contact_id')->toArray())->get();
if($remotecontacts)
{
foreach($remotecontacts as $remotecontact)
if($remotecontact->remotecontactapis->where('type', 0)->where('archive', 0)->count() == 1)
return true;
}
return false;
}
public function getReviewerUser()
{
$user = User::find(WorkflowDocumentUser::where('workflow_document_id', $this->id)->where('user_type', "R")->first()->user_id);
if($user)
return $user->getFullName();
return '';
}
public function getSupportUsers()
{
$users = User::whereIn('id', WorkflowDocumentUser::where('workflow_document_id', $this->id)->where('user_type', "S")->pluck('user_id')->toArray())->get();
$res = '';
foreach($users as $user)
$res = $res . $user->last_name . " " . $user->first_name . ", " ;
return substr($res, 0, -2);
}
public function senders()
{
return $this->hasMany(WorkflowDocumentSender::class, 'workflow_document_id', 'id');
}
public function workflowprocesses()
{
return $this->hasMany(WorkflowDocumentProcess::class, 'workflow_document_id', 'id');
}
}