Root Zanli
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
o5t6x7pgljbm
/
public_html
/
admin
/
app
/
Models
/
Filename :
AllClaim.php
back
Copy
<?php namespace App\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; class AllClaim extends Model { use SoftDeletes; protected $table = 'all_claims'; protected $primaryKey = 'claim_id'; public $timestamps = true; protected $fillable = [ 'claim_entity_type', 'task_id', 'product_id', 'task_assigned_id', 'product_claimed_id', 'store_id', 'group_id', 'claimed_by_user_id', 'status', 'reviewed_by_user_id', 'updated_by_id', 'created_at', 'updated_at', 'deleted_at', ]; protected $dates = ['deleted_at']; public function claimedByUser(): HasOne{ return $this->hasOne('App\Models\User', 'user_id', 'claimed_by_user_id'); } public function reviewedByUser(): HasOne{ return $this->hasOne('App\Models\User', 'user_id', 'reviewed_by_user_id'); } public function product(): HasOne{ return $this->hasOne('App\Models\Product', 'product_id', 'product_id')->withTrashed(); } public function task(): HasOne{ return $this->hasOne('App\Models\Task', 'task_id', 'task_id')->withTrashed(); } public function taskAssigned(): HasOne{ return $this->hasOne('App\Models\TaskAssigned', 'task_assigned_id', 'task_assigned_id'); } public function productClaimed(): HasOne{ return $this->hasOne('App\Models\ProductClaimed', 'product_claimed_id', 'product_claimed_id'); } public function store(): HasOne{ return $this->hasOne('App\Models\Store', 'store_id', 'store_id'); } public function groupObj(): HasOne{ return $this->hasOne('App\Models\Group', 'group_id', 'group_id'); } public function isCurrentClaim() { if(in_array($this->claim_entity_type,['TASK', 'TASK_AND_PRODUCT'])){ $task = $this->task; $taskSetting = $task->taskSetting; if($taskSetting->repeate_after_days > 0){ $claimDate = Carbon::parse($this->created_at)->startOfDay(); $nextClaimAllowedDate = $claimDate->addDays($taskSetting->repeate_after_days); $canAllowClaimToday = now()->gte($nextClaimAllowedDate); if($canAllowClaimToday){ return false; } else { return true; } } } else if (in_array($this->claim_entity_type,['PRODUCT'])) { $product = $this->product; $productSetting = $product->productSetting; if($productSetting->repeate_after_days > 0){ $claimDate = Carbon::parse($this->created_at)->startOfDay(); $nextClaimAllowedDate = $claimDate->addDays($productSetting->repeate_after_days); $canAllowClaimToday = now()->gte($nextClaimAllowedDate); if($canAllowClaimToday){ return false; } else { return true; } } } return true; } } ?>