1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IproSync\Models; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Illuminate\Database\Eloquent\Builder; |
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
8
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @property \JsonFieldCast\Json\ArrayOfJsonObjectsField $week_price_list |
12
|
|
|
* @property \JsonFieldCast\Json\ArrayOfJsonObjectsField $group_size |
13
|
|
|
*/ |
14
|
|
|
class MonthCustomRate extends Model |
15
|
|
|
{ |
16
|
|
|
use HasTraitsWithCasts, HasPullAt; |
17
|
|
|
|
18
|
|
|
public $incrementing = false; |
19
|
|
|
|
20
|
|
|
protected $guarded = []; |
21
|
|
|
|
22
|
|
|
protected $casts = [ |
23
|
|
|
'month' => 'date', |
24
|
|
|
'week_price_list' => \JsonFieldCast\Casts\ArrayOfJsonObjectsField::class, |
25
|
|
|
'group_size' => \JsonFieldCast\Casts\ArrayOfJsonObjectsField::class, |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
public function getTable(): string |
29
|
|
|
{ |
30
|
|
|
return config('iprosoftware-sync.tables.custom_rates'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function property(): BelongsTo |
34
|
|
|
{ |
35
|
|
|
return $this->belongsTo(Property::class, 'property_id', 'id'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function scopeYear(Builder $query, Carbon|string|int $year) |
39
|
|
|
{ |
40
|
|
|
if (!($year instanceof Carbon)) { |
41
|
|
|
$year = Carbon::createFromFormat('Y', $year); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$query |
45
|
|
|
->where('month', '>=', $year->startOfYear()->format('Y-m-d')) |
46
|
|
|
->where('month', '<=', $year->endOfYear()->format('Y-m-d')); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function scopeOrderByDate(Builder $query) |
50
|
|
|
{ |
51
|
|
|
$query->orderBy('month', 'ASC'); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|