Skip to content

Commit 460581a

Browse files
committed
refactor(simba): deduplicate schema in four metadata models (#218)
Phase 3 simba-model-layer-refactor: chuẩn hóa 4 Model chỉ extend SModel generated. - SysDictionaryInfo, SysReportInfo, SysReportDrillDownInfo, SiDmCt: bỏ khai báo lại ///////. - SysReportInfo (menuid, ma_mau), SysReportDrillDownInfo (menuid, ma_mau, press_key_name), SiDmCt (ma_cty, ma_ct): dùng HasSimbaCompositeKey. - Behavior giữ nguyên: primaryKeyFields, carryFields, scopeCodeName, scopeMenuId, scopeVoucher, headerFieldsForInventory, detailFieldsForInventory. - Sai lệch casts cũ đã loại: SysReportInfo (bang_chu/bang_chu0/hasNT theo docs là NVARCHAR), SiDmCt (VoucherGetWhenOpenForm không có trong docs, DB thật integer). - CI 14/14 pass, lint 4/4, caller laravel-catalog chỉ dùng query/attribute — không phá API.
1 parent a575944 commit 460581a

4 files changed

Lines changed: 79 additions & 144 deletions

File tree

src/Models/SiDmCt.php

Lines changed: 19 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,102 +8,52 @@
88
* @author Tran Ngoc Duc <ductn@diepxuan.com>
99
* @author Tran Ngoc Duc <caothu91@gmail.com>
1010
*
11-
* @lastupdate 2026-06-05 20:58:00
11+
* @lastupdate 2026-06-21
1212
*/
1313

1414
namespace Diepxuan\Simba\Models;
1515

16-
use Diepxuan\Simba\SModel\SModel;
16+
use Diepxuan\Simba\Models\Concerns\HasSimbaCompositeKey;
17+
use Diepxuan\Simba\SModel\SiDmCtModel as SModel;
1718

1819
/**
1920
* Model SiDmCt - Khai báo màn hình nhập chứng từ.
2021
*
2122
* Source: simba-docs/tables/SiDmCt.md.
23+
*
24+
* Schema nằm trọn ở `SiDmCtModel`. Model này chỉ giữ behavior Simba-level
25+
* và `HasSimbaCompositeKey` để thao tác theo composite primary key
26+
* (ma_cty, ma_ct) an toàn.
2227
*/
2328
class SiDmCt extends SModel
2429
{
25-
public $incrementing = false;
26-
public $timestamps = false;
27-
protected $table = 'SiDmCt';
28-
protected $primaryKey = 'ma_ct';
29-
protected $keyType = 'string';
30-
31-
protected $fillable = [
32-
'ma_cty',
33-
'ma_ct',
34-
'phan_he',
35-
'ma_ct_me',
36-
'ten_ct',
37-
'tk_no',
38-
'tk_co',
39-
'ma_nt',
40-
'so_lien',
41-
'stt_nkc',
42-
'stt_ntxt',
43-
'ct_dc',
44-
'loc_nsd',
45-
'vv',
46-
'spct',
47-
'phi',
48-
'bp',
49-
'lo',
50-
'sp_post',
51-
'sp_process',
52-
'ph',
53-
'ct',
54-
'sd',
55-
'nxt',
56-
'menuid',
57-
'vn_prefix',
58-
'vn_postfix',
59-
'vn_sequence',
60-
'vn_pattern',
61-
'vn_width',
62-
'PhFieldlist2IN',
63-
'CtFieldlist2IN',
64-
'kieu_trung_so_ct',
65-
'VoucherGetWhenOpenForm',
66-
];
67-
68-
protected $casts = [
69-
'so_lien' => 'integer',
70-
'stt_nkc' => 'integer',
71-
'stt_ntxt' => 'integer',
72-
'ct_dc' => 'boolean',
73-
'loc_nsd' => 'boolean',
74-
'vv' => 'boolean',
75-
'spct' => 'boolean',
76-
'phi' => 'boolean',
77-
'bp' => 'boolean',
78-
'lo' => 'boolean',
79-
'sd' => 'boolean',
80-
'vn_sequence' => 'integer',
81-
'vn_width' => 'integer',
82-
'kieu_trung_so_ct' => 'integer',
83-
'VoucherGetWhenOpenForm' => 'boolean',
84-
];
30+
use HasSimbaCompositeKey;
8531

8632
/**
87-
* Scope: find voucher metadata by company and voucher code.
33+
* Scope: tìm voucher metadata theo mã công ty + mã chứng từ.
8834
*
89-
* @param mixed $query
35+
* @param \Illuminate\Database\Eloquent\Builder $query
36+
* @return \Illuminate\Database\Eloquent\Builder
9037
*/
9138
public function scopeVoucher($query, string $maCt, string $maCty = SModel::CTY)
9239
{
9340
return $query->where('ma_cty', $maCty)->where('ma_ct', $maCt);
9441
}
9542

9643
/**
97-
* Scope: find voucher metadata by Simba menuid.
44+
* Scope: tìm voucher metadata theo menuid.
9845
*
99-
* @param mixed $query
46+
* @param \Illuminate\Database\Eloquent\Builder $query
47+
* @return \Illuminate\Database\Eloquent\Builder
10048
*/
10149
public function scopeMenuId($query, string $menuId)
10250
{
10351
return $query->where('menuid', $menuId);
10452
}
10553

10654
/**
55+
* Lấy danh sách cột header cho nhập kho từ cột PhFieldlist2IN.
56+
*
10757
* @return list<string>
10858
*/
10959
public function headerFieldsForInventory(): array
@@ -112,10 +62,12 @@ public function headerFieldsForInventory(): array
11262
}
11363

11464
/**
65+
* Lấy danh sách cột detail cho nhập kho từ cột CtFieldlist2IN.
66+
*
11567
* @return list<string>
11668
*/
11769
public function detailFieldsForInventory(): array
11870
{
11971
return array_values(array_filter(array_map('trim', explode(',', (string) $this->CtFieldlist2IN))));
12072
}
121-
}
73+
}

src/Models/SysDictionaryInfo.php

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,26 @@
88
* @author Tran Ngoc Duc <ductn@diepxuan.com>
99
* @author Tran Ngoc Duc <caothu91@gmail.com>
1010
*
11-
* @lastupdate 2026-06-05 20:58:00
11+
* @lastupdate 2026-06-21
1212
*/
1313

1414
namespace Diepxuan\Simba\Models;
1515

16-
use Illuminate\Database\Eloquent\Model;
16+
use Diepxuan\Simba\SModel\sysDictionaryInfoModel as SModel;
1717

1818
/**
19-
* SimbaERP sysDictionaryInfo table model.
19+
* SimbaERP sysDictionaryInfo model.
2020
*
2121
* Source: simba-docs/tables/sysDictionaryInfo.md.
22+
*
23+
* Schema (table, primaryKey, keyType, fillable, casts, timestamps) is owned
24+
* by `sysDictionaryInfoModel`; this class only adds Simba-level helpers.
2225
*/
23-
class SysDictionaryInfo extends Model
26+
class SysDictionaryInfo extends SModel
2427
{
25-
public $incrementing = false;
26-
public $timestamps = false;
27-
protected $connection = 'sqlsrv';
28-
protected $table = 'sysDictionaryInfo';
29-
protected $primaryKey = 'code_name';
30-
protected $keyType = 'string';
31-
32-
protected $fillable = [
33-
'code_name',
34-
'PK',
35-
'code_fname',
36-
'code_length',
37-
'name_fname',
38-
'table_name',
39-
'menuid',
40-
'lookup_when_invalid',
41-
'allow_merge_code',
42-
'dllname',
43-
'view_class_name',
44-
'edit_class_name',
45-
'carry_field_list',
46-
'default_sort',
47-
'copy_vaora',
48-
'par0',
49-
'par1',
50-
'par2',
51-
'par3',
52-
'par4',
53-
'par5',
54-
'par6',
55-
'par7',
56-
'par8',
57-
'par9',
58-
'description',
59-
];
60-
61-
protected $casts = [
62-
'code_length' => 'integer',
63-
'lookup_when_invalid' => 'boolean',
64-
'allow_merge_code' => 'boolean',
65-
'copy_vaora' => 'boolean',
66-
];
67-
6828
/**
29+
* Lấy danh sách cột khóa chính từ cột PK (chuỗi phân tách bằng dấu phẩy).
30+
*
6931
* @return list<string>
7032
*/
7133
public function primaryKeyFields(): array
@@ -74,6 +36,8 @@ public function primaryKeyFields(): array
7436
}
7537

7638
/**
39+
* Lấy danh sách cột carry từ cột carry_field_list.
40+
*
7741
* @return list<string>
7842
*/
7943
public function carryFields(): array
@@ -82,22 +46,24 @@ public function carryFields(): array
8246
}
8347

8448
/**
85-
* Scope: find dictionary metadata by Simba code_name.
49+
* Scope: tìm dictionary metadata theo code_name.
8650
*
87-
* @param mixed $query
51+
* @param \Illuminate\Database\Eloquent\Builder $query
52+
* @return \Illuminate\Database\Eloquent\Builder
8853
*/
8954
public function scopeCodeName($query, string $codeName)
9055
{
9156
return $query->where('code_name', $codeName);
9257
}
9358

9459
/**
95-
* Scope: find dictionary metadata by Simba menuid.
60+
* Scope: tìm dictionary metadata theo menuid.
9661
*
97-
* @param mixed $query
62+
* @param \Illuminate\Database\Eloquent\Builder $query
63+
* @return \Illuminate\Database\Eloquent\Builder
9864
*/
9965
public function scopeMenuId($query, string $menuId)
10066
{
10167
return $query->where('menuid', $menuId);
10268
}
103-
}
69+
}

src/Models/SysReportDrillDownInfo.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,29 @@
22

33
declare(strict_types=1);
44

5+
/*
6+
* @copyright © 2019 Dxvn, Inc.
7+
*
8+
* @author Tran Ngoc Duc <ductn@diepxuan.com>
9+
*
10+
* @lastupdate 2026-06-21
11+
*/
12+
513
namespace Diepxuan\Simba\Models;
614

7-
use Diepxuan\Simba\SModel\SModel;
15+
use Diepxuan\Simba\Models\Concerns\HasSimbaCompositeKey;
16+
use Diepxuan\Simba\SModel\sysReportDrillDownInfoModel as SModel;
817

18+
/**
19+
* SimbaERP sysReportDrillDownInfo model.
20+
*
21+
* Source: simba-docs/tables/sysReportDrillDownInfo.md.
22+
*
23+
* Schema nằm trọn ở `sysReportDrillDownInfoModel`. Model này chỉ bổ sung
24+
* `HasSimbaCompositeKey` để thao tác theo composite primary key
25+
* (menuid, ma_mau, press_key_name) an toàn.
26+
*/
927
class SysReportDrillDownInfo extends SModel
1028
{
11-
public $incrementing = false;
12-
public $timestamps = false;
13-
protected $table = 'sysReportDrillDownInfo';
14-
protected $primaryKey = 'menuid';
15-
protected $keyType = 'string';
16-
17-
protected $fillable = ['menuid','ma_mau','press_key_name','drilldown_menuid','drilldown_menuid1','drilldown_menuid2','drilldown_menuid3','drilldown_menuid4','dllName','command','description','par0','par1','par2','par3','par4','par5','par6','par7','par8','par9'];
18-
}
29+
use HasSimbaCompositeKey;
30+
}

src/Models/SysReportInfo.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22

33
declare(strict_types=1);
44

5+
/*
6+
* @copyright © 2019 Dxvn, Inc.
7+
*
8+
* @author Tran Ngoc Duc <ductn@diepxuan.com>
9+
*
10+
* @lastupdate 2026-06-21
11+
*/
12+
513
namespace Diepxuan\Simba\Models;
614

7-
use Diepxuan\Simba\SModel\SModel;
15+
use Diepxuan\Simba\Models\Concerns\HasSimbaCompositeKey;
16+
use Diepxuan\Simba\SModel\sysReportInfoModel as SModel;
817

18+
/**
19+
* SimbaERP sysReportInfo model.
20+
*
21+
* Source: simba-docs/tables/sysReportInfo.md.
22+
*
23+
* Schema nằm trọn ở `sysReportInfoModel`. Model này chỉ bổ sung
24+
* `HasSimbaCompositeKey` để thao tác theo composite primary key
25+
* (menuid, ma_mau) an toàn.
26+
*/
927
class SysReportInfo extends SModel
1028
{
11-
public $incrementing = false;
12-
public $timestamps = false;
13-
protected $table = 'sysReportInfo';
14-
protected $primaryKey = 'menuid';
15-
protected $keyType = 'string';
16-
17-
protected $fillable = ['menuid','ma_mau','ctlclass','spname','rptname','isdefault','bang_chu','bang_chu0','hasNT','dynReportFields','par0','par1','par2','par3','par4','par5','par6','par7','par8','par9','description_colname'];
18-
19-
protected $casts = [
20-
'isdefault' => 'boolean',
21-
'bang_chu' => 'boolean',
22-
'bang_chu0' => 'boolean',
23-
'hasNT' => 'boolean',
24-
];
25-
}
29+
use HasSimbaCompositeKey;
30+
}

0 commit comments

Comments
 (0)