Skip to content

Commit bf33004

Browse files
committed
Merge pull request #105 from diepxuan/refactor/timer-system
refactor: hệ thống timer - tách biệt read/write, thêm TimerConfig
1 parent c73339b commit bf33004

9 files changed

Lines changed: 3662 additions & 1 deletion

File tree

docs/CONFIGURATION.md

Lines changed: 422 additions & 0 deletions
Large diffs are not rendered by default.

docs/EXAMPLES.md

Lines changed: 645 additions & 0 deletions
Large diffs are not rendered by default.

docs/README.md

Lines changed: 537 additions & 0 deletions
Large diffs are not rendered by default.

docs/STORED_PROCEDURES/ar.md

Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
# Accounts Receivable (AR) Stored Procedures
2+
3+
Nghiệp vụ phải thu khách hàng.
4+
5+
---
6+
7+
## Giới thiệu
8+
9+
Nhóm stored procedures `AsAR*` xử lý các nghiệp vụ phải thu khách hàng trong hệ thống Simba.
10+
11+
### Chứng từ chính
12+
13+
| Code | Name | Description |
14+
|------|------|-------------|
15+
| `AR1` | Hóa đơn bán hàng | Ghi nhận công nợ phải thu |
16+
| `AR3` | Phiếu thu tiền | Thu tiền từ khách hàng |
17+
| `AR4` | Giấy báo có | Tiền vào từ khách hàng |
18+
19+
### Tables liên quan
20+
21+
| Table | Description |
22+
|-------|-------------|
23+
| `AR_PH1` | Header chứng từ phải thu |
24+
| `AR_CT1` | Chi tiết chứng từ phải thu |
25+
| `ARDMKH` | Danh mục khách hàng |
26+
| `AR_TT` | Theo dõi công nợ phải thu |
27+
| `AR_CDKH` | Công nợ đầu kỳ khách hàng |
28+
29+
---
30+
31+
## Customer Management
32+
33+
### asARInsDMKH - Insert Customer
34+
35+
```php
36+
use Diepxuan\Simba\StoredProcedures\AsARInsDMKH;
37+
38+
AsARInsDMKH::call([
39+
'pMa_cty' => '001',
40+
'pMa_kh' => 'KH001',
41+
'pTen_kh' => 'Cong Ty ABC',
42+
'pDia_chi' => '123 Nguyen Hue, Q1, TP.HCM',
43+
'pMa_so_thue'=> '0312345678',
44+
'pDien_thoai'=> '028.1234567',
45+
'pEmail' => 'contact@abc.com',
46+
'pMa_nht' => 'VCB',
47+
'pSo_tk_nh' => '123456789',
48+
'pUser' => 'admin',
49+
]);
50+
```
51+
52+
### asARUpdDMKH - Update Customer
53+
54+
```php
55+
use Diepxuan\Simba\StoredProcedures\AsARUpdDMKH;
56+
57+
AsARUpdDMKH::call([
58+
'pMa_cty' => '001',
59+
'pMa_kh' => 'KH001',
60+
'pTen_kh' => 'Cong Ty ABC (Updated)',
61+
'pDien_thoai'=> '028.9876543',
62+
'pUser' => 'admin',
63+
]);
64+
```
65+
66+
### asARGetDMKH - Get Customer Info
67+
68+
```php
69+
use Diepxuan\Simba\StoredProcedures\AsARGetDMKH;
70+
71+
$customer = AsARGetDMKH::call([
72+
'pMa_cty' => '001',
73+
'pMa_kh' => 'KH001',
74+
]);
75+
```
76+
77+
---
78+
79+
## Invoice (AR1) Procedures
80+
81+
### asARInsPH1 - Insert Invoice Header
82+
83+
```php
84+
use Diepxuan\Simba\StoredProcedures\AsARInsPH1;
85+
86+
AsARInsPH1::call([
87+
'pMa_cty' => '001',
88+
'pStt_rec' => 'AR120240306001',
89+
'pMa_ct' => 'AR1',
90+
'pSo_ct' => 'HD001',
91+
'pNgay_ct' => '2024-03-06',
92+
'pMa_kh' => 'KH001',
93+
'pPs_no' => 11000000,
94+
'pPs_co' => 0,
95+
'pTien_hang' => 10000000,
96+
'pTien_thue' => 1000000,
97+
'pDien_giai' => 'Hoa don ban hang',
98+
'pUser' => 'admin',
99+
]);
100+
```
101+
102+
### asARInsCT1 - Insert Invoice Detail
103+
104+
```php
105+
use Diepxuan\Simba\StoredProcedures\AsARInsCT1;
106+
107+
AsARInsCT1::call([
108+
'pMa_cty' => '001',
109+
'pStt_rec' => 'AR120240306001',
110+
'pMa_vt' => 'VT001',
111+
'pDvt' => 'Cai',
112+
'pSo_luong' => 10,
113+
'pDon_gia' => 1000000,
114+
'pTien_hang' => 10000000,
115+
'pThue_suat' => 10,
116+
'pTien_thue' => 1000000,
117+
'pTk' => '5111',
118+
'pDien_giai' => 'Ban san pham VT001',
119+
]);
120+
```
121+
122+
---
123+
124+
## Receipt (AR3) Procedures
125+
126+
### asARInsPH3 - Insert Receipt Header
127+
128+
```php
129+
use Diepxuan\Simba\StoredProcedures\AsARInsPH3;
130+
131+
AsARInsPH3::call([
132+
'pMa_cty' => '001',
133+
'pStt_rec' => 'AR320240306001',
134+
'pMa_ct' => 'AR3',
135+
'pSo_ct' => 'PT001',
136+
'pNgay_ct' => '2024-03-06',
137+
'pMa_kh' => 'KH001',
138+
'pPs_no' => 0,
139+
'pPs_co' => 11000000,
140+
'pDien_giai' => 'Thu tien thanh toan HD001',
141+
'pUser' => 'admin',
142+
]);
143+
```
144+
145+
---
146+
147+
## Get Balance Procedures
148+
149+
### asGetSoDuKh - Get Customer Balance
150+
151+
**Mục đích:** Lấy số dư công nợ của khách hàng tại một thời điểm.
152+
153+
```php
154+
use Diepxuan\Simba\StoredProcedures\AsGetSoDuKh;
155+
156+
$balance = AsGetSoDuKh::call([
157+
'pMa_Cty' => '001',
158+
'pMa_kh' => 'KH001',
159+
'pTk' => '131',
160+
'pNgay' => '2024-03-31',
161+
]);
162+
163+
// Result structure
164+
// {
165+
// So_du_no: 5000000,
166+
// So_du_co: 0,
167+
// Cong_no: 5000000 // No - Co
168+
// }
169+
```
170+
171+
---
172+
173+
## Complete Example
174+
175+
### Tạo hóa đơn và thu tiền
176+
177+
```php
178+
use Illuminate\Support\Facades\DB;
179+
use Diepxuan\Simba\StoredProcedures\AsGetSoCt;
180+
use Diepxuan\Simba\StoredProcedures\AsARInsPH1;
181+
use Diepxuan\Simba\StoredProcedures\AsARInsCT1;
182+
use Diepxuan\Simba\StoredProcedures\AsARInsPH3;
183+
use Diepxuan\Simba\StoredProcedures\AsARInsCT3;
184+
use Diepxuan\Simba\StoredProcedures\AsProcessCt;
185+
186+
function createInvoiceAndReceipt(array $invoiceData): array
187+
{
188+
return DB::transaction(function () use ($invoiceData) {
189+
$maCty = '001';
190+
191+
// === TẠO HÓA ĐƠN (AR1) ===
192+
$stt_rec_hd = AsGetSoCt::call([
193+
'pMa_Cty' => $maCty,
194+
'pMa_Ct' => 'AR1',
195+
]);
196+
197+
// Insert Invoice Header
198+
AsARInsPH1::call([
199+
'pMa_cty' => $maCty,
200+
'pStt_rec' => $stt_rec_hd,
201+
'pMa_ct' => 'AR1',
202+
'pSo_ct' => $invoiceData['so_hd'],
203+
'pNgay_ct' => $invoiceData['ngay_hd'],
204+
'pMa_kh' => $invoiceData['ma_kh'],
205+
'pPs_no' => $invoiceData['tong_cong'],
206+
'pPs_co' => 0,
207+
'pTien_hang' => $invoiceData['tien_hang'],
208+
'pTien_thue' => $invoiceData['tien_thue'],
209+
'pDien_giai' => $invoiceData['dien_giai'],
210+
'pUser' => $invoiceData['user'],
211+
]);
212+
213+
// Insert Invoice Details
214+
foreach ($invoiceData['items'] as $item) {
215+
AsARInsCT1::call([
216+
'pMa_cty' => $maCty,
217+
'pStt_rec' => $stt_rec_hd,
218+
'pMa_vt' => $item['ma_vt'],
219+
'pDvt' => $item['dvt'],
220+
'pSo_luong' => $item['so_luong'],
221+
'pDon_gia' => $item['don_gia'],
222+
'pTien_hang' => $item['tien_hang'],
223+
'pThue_suat' => $item['thue_suat'],
224+
'pTien_thue' => $item['tien_thue'],
225+
'pTk' => '5111',
226+
'pDien_giai' => $item['dien_giai'],
227+
]);
228+
}
229+
230+
// Process Invoice
231+
AsProcessCt::call([
232+
'pMa_cty' => $maCty,
233+
'pMa_Ct' => 'AR1',
234+
'pStt_rec' => $stt_rec_hd,
235+
'pMode' => '1',
236+
]);
237+
238+
// === TẠO PHIẾU THU (AR3) ===
239+
$stt_rec_pt = AsGetSoCt::call([
240+
'pMa_Cty' => $maCty,
241+
'pMa_Ct' => 'AR3',
242+
]);
243+
244+
// Insert Receipt Header
245+
AsARInsPH3::call([
246+
'pMa_cty' => $maCty,
247+
'pStt_rec' => $stt_rec_pt,
248+
'pMa_ct' => 'AR3',
249+
'pSo_ct' => $invoiceData['so_pt'],
250+
'pNgay_ct' => $invoiceData['ngay_pt'],
251+
'pMa_kh' => $invoiceData['ma_kh'],
252+
'pPs_no' => 0,
253+
'pPs_co' => $invoiceData['tong_cong'],
254+
'pDien_giai' => 'Thu tien HD ' . $invoiceData['so_hd'],
255+
'pUser' => $invoiceData['user'],
256+
]);
257+
258+
// Insert Receipt Detail (link to invoice)
259+
AsARInsCT3::call([
260+
'pMa_cty' => $maCty,
261+
'pStt_rec' => $stt_rec_pt,
262+
'pTk' => '131',
263+
'pMa_ct' => 'AR1',
264+
'pStt_rec_ct' => $stt_rec_hd,
265+
'pPs_no' => 0,
266+
'pPs_co' => $invoiceData['tong_cong'],
267+
'pDien_giai' => 'Thu tien HD ' . $invoiceData['so_hd'],
268+
]);
269+
270+
// Process Receipt
271+
AsProcessCt::call([
272+
'pMa_cty' => $maCty,
273+
'pMa_Ct' => 'AR3',
274+
'pStt_rec' => $stt_rec_pt,
275+
'pMode' => '1',
276+
]);
277+
278+
return [
279+
'invoice_stt_rec' => $stt_rec_hd,
280+
'receipt_stt_rec' => $stt_rec_pt,
281+
];
282+
});
283+
}
284+
285+
// Usage
286+
$result = createInvoiceAndReceipt([
287+
'so_hd' => 'HD001',
288+
'ngay_hd' => '2024-03-06',
289+
'ma_kh' => 'KH001',
290+
'tien_hang' => 10000000,
291+
'tien_thue' => 1000000,
292+
'tong_cong' => 11000000,
293+
'dien_giai' => 'Ban hang hoa',
294+
'so_pt' => 'PT001',
295+
'ngay_pt' => '2024-03-06',
296+
'user' => 'admin',
297+
'items' => [
298+
[
299+
'ma_vt' => 'VT001',
300+
'dvt' => 'Cai',
301+
'so_luong' => 10,
302+
'don_gia' => 1000000,
303+
'tien_hang' => 10000000,
304+
'thue_suat' => 10,
305+
'tien_thue' => 1000000,
306+
'dien_giai' => 'San pham VT001',
307+
],
308+
],
309+
]);
310+
```
311+
312+
---
313+
314+
## Reports
315+
316+
### asARRptBCCN01 - Báo cáo công nợ khách hàng
317+
318+
```php
319+
use Diepxuan\Simba\StoredProcedures\AsARRptBCCN01;
320+
321+
$report = AsARRptBCCN01::call([
322+
'pMa_cty' => '001',
323+
'pNgay_tu' => '2024-01-01',
324+
'pNgay_den' => '2024-03-31',
325+
'pMa_kh' => 'KH001',
326+
]);
327+
```
328+
329+
### asARRptBK01 - Bảng kê hóa đơn
330+
331+
```php
332+
use Diepxuan\Simba\StoredProcedures\AsARRptBK01;
333+
334+
$report = AsARRptBK01::call([
335+
'pMa_cty' => '001',
336+
'pNgay_tu' => '2024-01-01',
337+
'pNgay_den' => '2024-03-31',
338+
]);
339+
```
340+
341+
---
342+
343+
## Best Practices
344+
345+
1. **Kiểm tra tồn tại khách hàng** trước khi tạo hóa đơn
346+
2. **Sử dụng transaction** cho invoice + receipt
347+
3. **Link chứng từ** đúng cách (stt_rec_ct)
348+
4. **Validate số tiền** trước khi insert
349+
5. **Process ngay** sau khi tạo chứng từ
350+
351+
---
352+
353+
**Cập nhật lần cuối:** 2026-03-06
354+
**Version:** 1.0

0 commit comments

Comments
 (0)