Skip to content

Commit 402253d

Browse files
committed
Merge pull request #80 from diepxuan/feat/use-stored-procedure-classes
feat: Convert GlCt stored procedure calls to use stored procedure classes
1 parent 49019b6 commit 402253d

3 files changed

Lines changed: 20 additions & 43 deletions

File tree

src/Models/GlCt.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
namespace Diepxuan\Simba\Models;
1515

1616
use Diepxuan\Simba\SModel\GlCt as Model;
17+
use Diepxuan\Simba\StoredProcedures\AsCARptTMNH01;
18+
use Diepxuan\Simba\StoredProcedures\AsGLRptNKC03;
1719
use Illuminate\Database\Eloquent\Builder;
1820
use Illuminate\Support\Collection;
1921
use Illuminate\Support\Facades\DB;
@@ -70,42 +72,28 @@ public function arDmKh()
7072
*/
7173
public static function getCARptTMNH01(array $params): Collection
7274
{
73-
return collect(DB::connection((new static())->getConnectionName())->select('EXEC asCARptTMNH01
74-
@pMa_Cty = :pMa_Cty,
75-
@pNgay_Ct1 = :pNgay_Ct1,
76-
@pNgay_Ct2 = :pNgay_Ct2,
77-
@pTk = :pTk,
78-
@pMa_Nt = :pMa_Nt
79-
', [
80-
'pMa_Cty' => $params['pMa_Cty'],
81-
'pTk' => $params['pTk'],
82-
'pNgay_Ct1' => $params['pNgay_Ct1'],
83-
'pNgay_Ct2' => $params['pNgay_Ct2'],
75+
return AsCARptTMNH01::call([
76+
'pMa_Cty' => $params['pMa_Cty'] ?? '',
77+
'pTk' => $params['pTk'] ?? '',
78+
'pNgay_Ct1' => $params['pNgay_Ct1'] ?? '',
79+
'pNgay_ct2' => $params['pNgay_Ct2'] ?? '',
8480
'pMa_Nt' => $params['ma_Nt'] ?? 'VND',
85-
]));
81+
]);
8682
}
8783

8884
/**
8985
* Gọi stored procedure asGLRptNKC03 để lấy dữ liệu sổ nhật ký thu/chi.
9086
*/
9187
public static function getGLRptNKC03(array $params): Collection
9288
{
93-
return collect(DB::connection((new static())->getConnectionName())->select('EXEC asGLRptNKC03
94-
@pMa_Cty = :pMa_Cty,
95-
@pNgay_Ct1 = :pNgay_Ct1,
96-
@pNgay_Ct2 = :pNgay_Ct2,
97-
@pTk_List = :pTk_List,
98-
@pTkdu_List = :pTkdu_List,
99-
@pMa_Bp = :pMa_Bp,
100-
@pMa_Nt = :pMa_Nt
101-
', [
89+
return AsGLRptNKC03::call([
10290
'pMa_Cty' => $params['pMa_Cty'] ?? '',
10391
'pNgay_Ct1' => $params['pNgay_Ct1'] ?? '2025-05-01',
10492
'pNgay_Ct2' => $params['pNgay_Ct2'] ?? now(),
10593
'pTk_List' => $params['pTk_List'] ?? '',
10694
'pTkdu_List' => $params['pTkdu_List'] ?? '',
10795
'pMa_Bp' => $params['pMa_Bp'] ?? '',
10896
'pMa_Nt' => $params['pMa_Nt'] ?? 'VND',
109-
]));
97+
]);
11098
}
11199
}

src/StoredProcedures/AsCARptTMNH01.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public static function call(array $params): Collection
2323
$connection = (new SModel())->getConnectionName();
2424

2525
return ProcedureCaller::call('asCARptTMNH01', [
26-
26+
'pMa_Cty' => $params['pMa_Cty'] ?? SModel::CTY,
27+
'pTk' => $params['pTk'] ?? '111',
28+
'pNgay_Ct1' => $params['pNgay_Ct1'] ?? '2015-10-01',
29+
'pNgay_ct2' => $params['pNgay_ct2'] ?? '2015-10-31',
30+
'pMa_Nt' => $params['pMa_Nt'] ?? '',
2731
], $connection);
2832
}
2933
}

src/StoredProcedures/AsPostCaph3_glct.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class AsPostCaph3_glct
2020
{
2121
/**
2222
* Call stored procedure asPostCaph3_glct
23+
*
24+
* Note: Stored procedure chỉ có 2 tham số (@pMa_cty, @pStt_rec)
25+
* Các tham số khác được tính toán bên trong stored procedure
2326
*
2427
* @param array $params Procedure parameters
2528
* @return Collection
@@ -29,14 +32,8 @@ public static function call(array $params): Collection
2932
$connection = (new SModel())->getConnectionName();
3033

3134
return ProcedureCaller::call('asPostCaph3_glct', [
32-
'pMa_cty' => $params['pMa_cty'] ?? null,
35+
'pMa_cty' => $params['pMa_cty'] ?? SModel::CTY,
3336
'pStt_rec' => $params['pStt_rec'] ?? null,
34-
'pNamTC' => $params['pNamTC'] ?? null,
35-
'pThangTC' => $params['pThangTC'] ?? null,
36-
'pNgay_ct' => $params['pNgay_ct'] ?? null,
37-
'pNgay_ks' => $params['pNgay_ks'] ?? null,
38-
'pMa_nt0' => $params['pMa_nt0'] ?? null,
39-
'pma_cty' => $params['pma_cty'] ?? null
4037
], $connection);
4138
}
4239

@@ -45,25 +42,13 @@ public static function call(array $params): Collection
4542
*
4643
* @param string $Ma_cty
4744
* @param string $Stt_rec
48-
* @param int $NamTC
49-
* @param int $ThangTC
50-
* @param string $Ngay_ct
51-
* @param string $Ngay_ks
52-
* @param mixed $Ma_nt0
53-
* @param mixed $ma_cty
5445
* @return Collection
5546
*/
56-
public static function callWithParams(string $Ma_cty = null, string $Stt_rec = null, int $NamTC = null, int $ThangTC = null, string $Ngay_ct = null, string $Ngay_ks = null, mixed $Ma_nt0 = null, mixed $ma_cty = null): Collection
47+
public static function callWithParams(string $Ma_cty = null, string $Stt_rec = null): Collection
5748
{
5849
$params = [
5950
'pMa_cty' => $Ma_cty,
6051
'pStt_rec' => $Stt_rec,
61-
'pNamTC' => $NamTC,
62-
'pThangTC' => $ThangTC,
63-
'pNgay_ct' => $Ngay_ct,
64-
'pNgay_ks' => $Ngay_ks,
65-
'pMa_nt0' => $Ma_nt0,
66-
'pma_cty' => $ma_cty
6752
];
6853

6954
return self::call($params);

0 commit comments

Comments
 (0)