Skip to content

Commit d29663d

Browse files
committed
Merge pull request #96 from diepxuan/feat/procedurecaller-refactor
refactor: shorten ProcedureCaller
1 parent 615db01 commit d29663d

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

src/StoredProcedures/AsGLChuyenSdTk.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
* @author Tran Ngoc Duc <ductn@diepxuan.com>
99
* @author Tran Ngoc Duc <caothu91@gmail.com>
1010
*
11-
* @lastupdate 2026-02-26 14:21:52
11+
* @lastupdate 2026-02-27 21:55:53
1212
*/
1313

1414
namespace Diepxuan\Simba\StoredProcedures;
1515

16+
use Carbon\Carbon;
1617
use Diepxuan\Simba\SModel\SModel;
1718
use Illuminate\Support\Collection;
1819

@@ -69,11 +70,35 @@ class AsGLChuyenSdTk extends StoredProcedure
6970
*
7071
* @return mixed kết quả trả về từ procedure (có thể chứa output parameter)
7172
*/
72-
public static function call(array $params): Collection
73+
public static function call(array $params)
7374
{
74-
return parent::call(array_merge([
75+
$params = [
7576
'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;
78103
}
79104
}

src/StoredProcedures/ProcedureCaller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @author Tran Ngoc Duc <ductn@diepxuan.com>
99
* @author Tran Ngoc Duc <caothu91@gmail.com>
1010
*
11-
* @lastupdate 2026-02-25 15:13:06
11+
* @lastupdate 2026-02-27 21:55:53
1212
*/
1313

1414
namespace Diepxuan\Simba\StoredProcedures;
@@ -32,7 +32,7 @@ class ProcedureCaller
3232
*
3333
* @return mixed kết quả trả về từ procedure (tùy thuộc vào procedure)
3434
*/
35-
public static function call(string $name, array $params = [], ?string $connection = null): Collection
35+
public static function call(string $name, array $params = [], ?string $connection = null)
3636
{
3737
$placeholders = '';
3838
if (!empty($params)) {

src/StoredProcedures/StoredProcedure.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
* @author Tran Ngoc Duc <ductn@diepxuan.com>
99
* @author Tran Ngoc Duc <caothu91@gmail.com>
1010
*
11-
* @lastupdate 2026-02-26 11:12:40
11+
* @lastupdate 2026-02-27 21:46:55
1212
*/
1313

1414
namespace Diepxuan\Simba\StoredProcedures;
1515

1616
use Diepxuan\Simba\SModel\SModel;
17-
use Illuminate\Support\Collection;
1817

1918
class StoredProcedure
2019
{
@@ -27,7 +26,7 @@ class StoredProcedure
2726
*
2827
* @return mixed kết quả trả về từ procedure (có thể chứa output parameter)
2928
*/
30-
public static function call(array $params): Collection
29+
public static function call(array $params)
3130
{
3231
$connection = (new SModel())->getConnectionName();
3332

0 commit comments

Comments
 (0)