|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * @copyright © 2019 Dxvn, Inc. |
| 7 | + * |
| 8 | + * @author Tran Ngoc Duc <ductn@diepxuan.com> |
| 9 | + * @author Tran Ngoc Duc <caothu91@gmail.com> |
| 10 | + * |
| 11 | + * @lastupdate 2026-05-14 09:12:27 |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Diepxuan\Simba\Models; |
| 15 | + |
| 16 | +use Diepxuan\Simba\SModel\PoPh3Model as Model; |
| 17 | +use Illuminate\Database\Eloquent\Builder; |
| 18 | + |
| 19 | +/** |
| 20 | + * Class PoPh3. |
| 21 | + * |
| 22 | + * Hóa đơn mua hàng - Header (PO3). |
| 23 | + */ |
| 24 | +class PoPh3 extends Model |
| 25 | +{ |
| 26 | + /** Filter theo tìm kiếm (số hóa đơn, số chứng từ, diễn giải) */ |
| 27 | + public function scopeFilterBySearch(Builder $query, ?string $search): Builder |
| 28 | + { |
| 29 | + if (!empty($search)) { |
| 30 | + return $query->where(static function ($q) use ($search): void { |
| 31 | + $q->where('so_hd', 'like', "%{$search}%") |
| 32 | + ->orWhere('so_ct', 'like', "%{$search}%") |
| 33 | + ->orWhere('dien_giai', 'like', "%{$search}%") |
| 34 | + ; |
| 35 | + }); |
| 36 | + } |
| 37 | + |
| 38 | + return $query; |
| 39 | + } |
| 40 | + |
| 41 | + /** Filter theo mã khách hàng/NCC */ |
| 42 | + public function scopeFilterByMaKh(Builder $query, ?string $maKh): Builder |
| 43 | + { |
| 44 | + if (!empty($maKh)) { |
| 45 | + return $query->where('ma_kh', $maKh); |
| 46 | + } |
| 47 | + |
| 48 | + return $query; |
| 49 | + } |
| 50 | + |
| 51 | + /** Filter theo ngày chứng từ */ |
| 52 | + public function scopeFilterByNgayCt(Builder $query, ?string $fromDate, ?string $toDate): Builder |
| 53 | + { |
| 54 | + if (!empty($fromDate)) { |
| 55 | + $query->whereDate('ngay_ct', '>=', $fromDate); |
| 56 | + } |
| 57 | + if (!empty($toDate)) { |
| 58 | + $query->whereDate('ngay_ct', '<=', $toDate); |
| 59 | + } |
| 60 | + |
| 61 | + return $query; |
| 62 | + } |
| 63 | + |
| 64 | + /** Relationship với chi tiết vật tư */ |
| 65 | + public function chiTiets() |
| 66 | + { |
| 67 | + return $this->hasMany(PoCt3::class, 'stt_rec', 'stt_rec'); |
| 68 | + } |
| 69 | + |
| 70 | + /** Relationship với chi phí */ |
| 71 | + public function chiPhis() |
| 72 | + { |
| 73 | + return $this->hasMany(PoCp3::class, 'stt_rec', 'stt_rec'); |
| 74 | + } |
| 75 | + |
| 76 | + /** Relationship với nhà cung cấp */ |
| 77 | + public function nhaCungCap() |
| 78 | + { |
| 79 | + return $this->belongsTo(ArDmKh::class, 'ma_kh', 'ma_kh'); |
| 80 | + } |
| 81 | +} |
0 commit comments