|
8 | 8 | * @author Tran Ngoc Duc <ductn@diepxuan.com> |
9 | 9 | * @author Tran Ngoc Duc <caothu91@gmail.com> |
10 | 10 | * |
11 | | - * @lastupdate 2026-02-26 14:21:52 |
| 11 | + * @lastupdate 2026-02-27 21:55:53 |
12 | 12 | */ |
13 | 13 |
|
14 | 14 | namespace Diepxuan\Simba\StoredProcedures; |
15 | 15 |
|
| 16 | +use Carbon\Carbon; |
16 | 17 | use Diepxuan\Simba\SModel\SModel; |
17 | 18 | use Illuminate\Support\Collection; |
18 | 19 |
|
@@ -69,11 +70,35 @@ class AsGLChuyenSdTk extends StoredProcedure |
69 | 70 | * |
70 | 71 | * @return mixed kết quả trả về từ procedure (có thể chứa output parameter) |
71 | 72 | */ |
72 | | - public static function call(array $params): Collection |
| 73 | + public static function call(array $params) |
73 | 74 | { |
74 | | - return parent::call(array_merge([ |
| 75 | + $params = [ |
75 | 76 | 'pMa_cty' => $params['pMa_cty'] ?? SModel::CTY, |
76 | | - 'pNgay_cnt' => $params['pNgay_cnt'] ?? null, |
77 | | - ], $params)); |
| 77 | + 'pNgay_cnt' => $params['pNgay_cnt'] ?? now()->endOfYear(), |
| 78 | + 'pRet' => ['output' => true, 'type' => 'INT'], |
| 79 | + ...$params, |
| 80 | + ]; |
| 81 | + $ngayCnt = $params['pNgay_cnt'] ?? now()->endOfYear(); |
| 82 | + |
| 83 | + if ($ngayCnt instanceof Carbon) { |
| 84 | + $ngayCnt = $ngayCnt->format('Y-m-d H:i:s'); |
| 85 | + } |
| 86 | + |
| 87 | + $result = parent::call([ |
| 88 | + ...$params, |
| 89 | + 'pNgay_cnt' => $ngayCnt, |
| 90 | + ]); |
| 91 | + |
| 92 | + if ($result instanceof Collection && $result->isNotEmpty()) { |
| 93 | + $firstItem = $result->first(); |
| 94 | + if (\is_object($firstItem) && property_exists($firstItem, 'pRet')) { |
| 95 | + return (float) $firstItem->pRet; |
| 96 | + } |
| 97 | + if (\is_array($firstItem) && isset($firstItem['pRet'])) { |
| 98 | + return (float) $firstItem['pRet']; |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + return 0; |
78 | 103 | } |
79 | 104 | } |
0 commit comments