Skip to content

Commit 74099a0

Browse files
committed
Merge pull request #136 from diepxuan/docs/ascadelph2-output-parameter
docs: bổ sung output parameter pRet và documentation cho AsCADelPH2
1 parent 13048c3 commit 74099a0

1 file changed

Lines changed: 79 additions & 5 deletions

File tree

src/StoredProcedures/AsCADelPH2.php

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,100 @@
88
* @author Tran Ngoc Duc <ductn@diepxuan.com>
99
* @author Tran Ngoc Duc <caothu91@gmail.com>
1010
*
11-
* @lastupdate 2026-02-12 12:36:46
11+
* @lastupdate 2026-04-06 07:25:49
1212
*/
1313

1414
namespace Diepxuan\Simba\StoredProcedures;
1515

16+
use Diepxuan\Simba\Helper\ParamHelper;
1617
use Diepxuan\Simba\SModel\SModel;
1718
use Illuminate\Support\Collection;
18-
use Diepxuan\Simba\Helper\ParamHelper;
1919

20+
/**
21+
* Class AsCADelPH2.
22+
*
23+
* Stored procedure: asCADelPH2
24+
* Mục đích: Xóa phiếu thu/chi (bảng CAPH2 - Cash Phiếu 2).
25+
* Procedure thực hiện xóa bản ghi khỏi bảng CAPH2 dựa trên số tham chiếu (stt_rec).
26+
*
27+
* Tham số (theo định nghĩa thực tế trong SQL Server):
28+
* - @pMa_cty (nvarchar(3)): Mã công ty. Bắt buộc.
29+
* - @pStt_rec (nvarchar(20)): Số tham chiếu (stt_rec) của phiếu cần xóa. Bắt buộc.
30+
* - @pLUser (nvarchar(20)): Người dùng thực hiện xóa. Bắt buộc.
31+
* - @pRet (int, OUTPUT): Tham số đầu ra chứa mã lỗi (@@error).
32+
* - 0: Thành công.
33+
* - Khác 0: Mã lỗi SQL Server.
34+
*
35+
* Giá trị trả về:
36+
* - Procedure không trả về result set.
37+
* - Kết quả được trả về qua output parameter @pRet.
38+
* - Để lấy giá trị @pRet, cần đọc từ result của ProcedureCaller (có SELECT @pRet).
39+
*
40+
* Ví dụ gọi:
41+
* ```php
42+
* $result = AsCADelPH2::call([
43+
* 'pMa_cty' => '001',
44+
* 'pStt_rec' => '001wCA40000000676668',
45+
* 'pLUser' => 'DUCTN',
46+
* ]);
47+
*
48+
* // Lấy giá trị output parameter
49+
* $ret = $result->first()->pRet ?? null;
50+
* if ($ret === 0) {
51+
* // Xóa thành công
52+
* } else {
53+
* // Có lỗi xảy ra, $ret chứa mã lỗi
54+
* }
55+
* ```
56+
*
57+
* Lưu ý:
58+
* - Procedure chỉ thực hiện xóa dựa trên stt_rec.
59+
* - Cần đảm bảo stt_rec tồn tại trước khi xóa.
60+
* - Output parameter @pRet được xử lý tự động bởi ProcedureCaller.
61+
*
62+
* @see AsCAGetPH2::call() - Kiểm tra phiếu tồn tại trước khi xóa
63+
*/
2064
class AsCADelPH2
2165
{
66+
/**
67+
* Gọi stored procedure asCADelPH2.
68+
*
69+
* @param array $params Mảng tham số với các khóa tương ứng tên tham số.
70+
* Các parameters có thể thiếu, sẽ dùng giá trị default.
71+
*
72+
* @return Collection kết quả từ procedure (chứa output parameter pRet)
73+
*/
2274
public static function call(array $params): Collection
2375
{
24-
$paramObj = ParamHelper::fromArray($params);
76+
$paramObj = ParamHelper::fromArray($params);
2577
$connection = (new SModel())->getConnectionName();
2678

2779
return ProcedureCaller::call('asCADelPH2', [
28-
'pMa_cty' => $paramObj->pMa_cty ?? null,
80+
'pMa_cty' => $paramObj->pMa_cty ?? null,
2981
'pStt_rec' => $paramObj->pStt_rec ?? null,
30-
'pLUser' => $paramObj->pLUser ?? null,
82+
'pLUser' => $paramObj->pLUser ?? null,
83+
'pRet' => ['type' => 'INT', 'output' => true],
3184
], $connection);
3285
}
86+
87+
/**
88+
* Call stored procedure asCADelPH2 with named parameters (helper method).
89+
*
90+
* @param null|string $Ma_cty Mã công ty
91+
* @param null|string $Stt_rec Số tham chiếu
92+
* @param null|string $LUser Người dùng
93+
*
94+
* @return Collection Kết quả từ procedure
95+
*/
96+
public static function callWithParams(
97+
?string $Ma_cty = null,
98+
?string $Stt_rec = null,
99+
?string $LUser = null,
100+
): Collection {
101+
return self::call([
102+
'pMa_cty' => $Ma_cty,
103+
'pStt_rec' => $Stt_rec,
104+
'pLUser' => $LUser,
105+
]);
106+
}
33107
}

0 commit comments

Comments
 (0)