|
| 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 2025-08-02 21:46:08 |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Diepxuan\Simba\Models; |
| 15 | + |
| 16 | +use Diepxuan\Simba\SModel\InDmKho as Model; |
| 17 | +use Illuminate\Database\Eloquent\Casts\Attribute; |
| 18 | +use Illuminate\Support\Collection; |
| 19 | +use Illuminate\Support\Facades\DB; |
| 20 | + |
| 21 | +class InDmKho extends Model |
| 22 | +{ |
| 23 | + /** |
| 24 | + * Gọi stored procedure asINGetDMKHO để lấy dữ liệu Danh sách kho. |
| 25 | + * |
| 26 | + * @return array |
| 27 | + */ |
| 28 | + public static function getAsINGetDMKHO(array $params): Collection |
| 29 | + { |
| 30 | + // \Debugbar::info($params); |
| 31 | + |
| 32 | + return collect(DB::connection((new static())->getConnectionName())->select( |
| 33 | + <<<'EOF' |
| 34 | + EXECUTE asINGetDMKHO |
| 35 | + @pMa_Cty = :pMa_Cty, |
| 36 | + @pMa_kho = :pMa_kho, |
| 37 | + @pStruct = :pStruct |
| 38 | + EOF |
| 39 | + , |
| 40 | + [ |
| 41 | + 'pMa_Cty' => $params['pMa_Cty'] ?? '', |
| 42 | + 'pMa_kho' => $params['pMa_kho'] ?? null, |
| 43 | + 'pStruct' => $params['pStruct'] ?? null, |
| 44 | + ] |
| 45 | + )); |
| 46 | + } |
| 47 | + |
| 48 | + protected function id(): Attribute |
| 49 | + { |
| 50 | + return Attribute::make( |
| 51 | + get: static fn (mixed $value, array $attributes) => implode('_', [$attributes['ma_cty'], $attributes['ma_kho']]), |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + protected function sku(): Attribute |
| 56 | + { |
| 57 | + return Attribute::make( |
| 58 | + get: static fn (mixed $value, array $attributes) => $attributes['ma_kho'], |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + protected function name(): Attribute |
| 63 | + { |
| 64 | + return Attribute::make( |
| 65 | + get: static fn (mixed $value, array $attributes) => $attributes['ten_kho'], |
| 66 | + ); |
| 67 | + } |
| 68 | +} |
0 commit comments