| 1 |
<?php |
| 2 |
namespace WeDevs\ERP\HRM\Models; |
| 3 |
|
| 4 |
use WeDevs\ERP\Framework\Model; |
| 5 |
|
| 6 |
/** |
| 7 |
* Class Leave_request |
| 8 |
* |
| 9 |
* @package WeDevs\ERP\HRM\Models |
| 10 |
*/ |
| 11 |
class Leave_request extends Model { |
| 12 |
/** |
| 13 |
* Custom created_at field |
| 14 |
* |
| 15 |
* @since 1.2.0 |
| 16 |
*/ |
| 17 |
const CREATED_AT = 'created_on'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Custom updated_at field |
| 21 |
* |
| 22 |
* @since 1.2.0 |
| 23 |
*/ |
| 24 |
const UPDATED_AT = 'updated_on'; |
| 25 |
protected $primaryKey = 'id'; |
| 26 |
|
| 27 |
protected $table = 'erp_hr_leave_requests'; |
| 28 |
protected $fillable = [ |
| 29 |
'user_id', 'policy_id', 'days', 'start_date', |
| 30 |
'end_date', 'comments', 'reason', 'status' |
| 31 |
]; |
| 32 |
|
| 33 |
/** |
| 34 |
* Relation to Leave model |
| 35 |
* |
| 36 |
* @since 1.2.0 |
| 37 |
* |
| 38 |
* @return object |
| 39 |
*/ |
| 40 |
public function leave() { |
| 41 |
return $this->hasOne( 'WeDevs\ERP\HRM\Models\Leave', 'request_id' ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Relation to Leave_Policies model |
| 46 |
* |
| 47 |
* @since 1.2.0 |
| 48 |
* |
| 49 |
* @return object |
| 50 |
*/ |
| 51 |
public function policy() { |
| 52 |
return $this->belongsTo( 'WeDevs\ERP\HRM\Models\Leave_Policies', 'policy_id' ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Relation to Leave model |
| 57 |
* |
| 58 |
* @since 1.2.0 |
| 59 |
* |
| 60 |
* @return object |
| 61 |
*/ |
| 62 |
public function employee() { |
| 63 |
return $this->belongsTo( 'WeDevs\ERP\HRM\Models\Employee', 'user_id', 'user_id' ); |
| 64 |
} |
| 65 |
|
| 66 |
public function scopeJoinWithPolicy( $query ) { |
| 67 |
global $wpdb; |
| 68 |
return $query->leftJoin( "{$wpdb->prefix}erp_hr_leave_policies", "{$wpdb->prefix}erp_hr_leave_policies.id", "=", "{$wpdb->prefix}erp_hr_leave_requests.policy_id" ); |
| 69 |
} |
| 70 |
|
| 71 |
public function scopeJoinWithEn( $query ) { |
| 72 |
global $wpdb; |
| 73 |
return $query->leftJoin( "{$wpdb->prefix}erp_hr_leave_entitlements", "{$wpdb->prefix}erp_hr_leave_entitlements.policy_id", "=", "{$wpdb->prefix}erp_hr_leave_requests.policy_id" ); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
} |
| 78 |
|