88 * @author Tran Ngoc Duc <ductn@diepxuan.com>
99 * @author Tran Ngoc Duc <caothu91@gmail.com>
1010 *
11- * @lastupdate 2026-05-11 23:45:32
11+ * @lastupdate 2026-06-06 08:25:00
1212 */
1313
1414namespace Diepxuan \Simba \Models ;
1515
16- use Illuminate \ Database \ Eloquent \ Model ;
16+ use Diepxuan \ Simba \ SModel \ SModel ;
1717
1818/**
19- * SimbaERP sysMenu table model .
19+ * Model sysMenu - SimbaERP menu metadata .
2020 *
21- * Maps the menu structure from SimbaERP's SQL Server database.
22- * Menu ID format: XX.YY.ZZ (module.group.item)
21+ * Source: simba-docs/data/sysMenu.md.
2322 */
24- class SysMenu extends Model
23+ class SysMenu extends SModel
2524{
26- // Type constants
2725 public const TYPE_MODULE_ROOT = '5 ' ;
2826 public const TYPE_GROUP = '' ;
2927 public const TYPE_VOUCHER = '1 ' ;
3028 public const TYPE_MASTER = '2 ' ;
3129 public const TYPE_REPORT = '4 ' ;
3230 public const TYPE_UTILITY = '3 ' ;
3331 public const TYPE_SETUP = '6 ' ;
34- public $ incrementing = false ;
35- public $ timestamps = false ;
36- protected $ connection = 'sqlsrv ' ;
37- protected $ table = 'sysMenu ' ;
38- protected $ primaryKey = 'menuid ' ;
32+
33+ public $ incrementing = false ;
34+ public $ timestamps = false ;
35+ protected $ table = 'sysMenu ' ;
36+ protected $ primaryKey = 'menuid ' ;
37+ protected $ keyType = 'string ' ;
3938
4039 protected $ fillable = [
41- 'menuid ' , 'stt ' , 'type ' , 'moduleid ' , 'bar ' , 'short_name ' ,
42- 'dllName ' , 'command ' , 'code_name ' , 'report ' , 'basicright ' ,
43- 'form ' , 'form_show_type ' , 'opt ' ,
44- 'par1 ' , 'par2 ' , 'par3 ' , 'par4 ' , 'par5 ' , 'par6 ' , 'par7 ' , 'par8 ' ,
45- 'picture1 ' , 'picture2 ' , 'rowid ' , 'developer ' , 'maintainer ' ,
46- 'used ' , 'active ' , 'zmenuid ' ,
40+ 'menuid ' ,
41+ 'stt ' ,
42+ 'type ' ,
43+ 'moduleid ' ,
44+ 'bar ' ,
45+ 'short_name ' ,
46+ 'dllName ' ,
47+ 'command ' ,
48+ 'code_name ' ,
49+ 'report ' ,
50+ 'basicright ' ,
51+ 'form ' ,
52+ 'form_show_type ' ,
53+ 'opt ' ,
54+ 'par1 ' ,
55+ 'par2 ' ,
56+ 'par3 ' ,
57+ 'par4 ' ,
58+ 'par5 ' ,
59+ 'par6 ' ,
60+ 'par7 ' ,
61+ 'par8 ' ,
62+ 'picture1 ' ,
63+ 'picture2 ' ,
64+ 'rowid ' ,
65+ 'developer ' ,
66+ 'maintainer ' ,
67+ 'used ' ,
68+ 'active ' ,
69+ 'zmenuid ' ,
70+ ];
71+
72+ protected $ casts = [
73+ 'report ' => 'boolean ' ,
74+ 'basicright ' => 'boolean ' ,
75+ 'form ' => 'boolean ' ,
76+ 'form_show_type ' => 'integer ' ,
77+ 'rowid ' => 'integer ' ,
78+ 'used ' => 'boolean ' ,
79+ 'active ' => 'boolean ' ,
4780 ];
4881
49- /**
50- * Get parent menu_id from hierarchical structure XX.YY.ZZ
51- * 02.10.02 → 02.10.00
52- * 02.10.00 → 02.00.00
53- * 02.00.00 → null (root).
54- */
82+ public function getDisplayName (): string
83+ {
84+ return $ this ->bar ?: $ this ->short_name ?: $ this ->menuid ?: '' ;
85+ }
86+
5587 public function getParentMenuId (): ?string
5688 {
57- $ parts = explode ('. ' , $ this ->menuid );
89+ $ parts = explode ('. ' , ( string ) $ this ->menuid );
5890 if (3 !== \count ($ parts )) {
5991 return null ;
6092 }
6193
6294 if ('00 ' !== $ parts [2 ]) {
6395 return "{$ parts [0 ]}. {$ parts [1 ]}.00 " ;
6496 }
97+
6598 if ('00 ' !== $ parts [1 ]) {
6699 return "{$ parts [0 ]}.00.00 " ;
67100 }
@@ -71,120 +104,31 @@ public function getParentMenuId(): ?string
71104
72105 public function isRoot (): bool
73106 {
74- return self ::TYPE_MODULE_ROOT === $ this ->type ;
107+ return self ::TYPE_MODULE_ROOT === ( string ) $ this ->type ;
75108 }
76109
77110 public function isGroup (): bool
78111 {
79- return self ::TYPE_GROUP === $ this -> type || null === $ this ->type ;
112+ return self ::TYPE_GROUP === ( string ) $ this ->type ;
80113 }
81114
82115 public function isVoucher (): bool
83116 {
84- return self ::TYPE_VOUCHER === $ this ->type ;
117+ return self ::TYPE_VOUCHER === ( string ) $ this ->type ;
85118 }
86119
87120 public function isMasterData (): bool
88121 {
89- return self ::TYPE_MASTER === $ this ->type ;
122+ return self ::TYPE_MASTER === ( string ) $ this ->type ;
90123 }
91124
92125 public function isReport (): bool
93126 {
94- return self ::TYPE_REPORT === $ this ->type ;
95- }
96-
97- public function isUtility (): bool
98- {
99- return self ::TYPE_UTILITY === $ this ->type ;
127+ return self ::TYPE_REPORT === (string ) $ this ->type ;
100128 }
101129
102130 public function isSetup (): bool
103131 {
104- return self ::TYPE_SETUP === $ this ->type ;
105- }
106-
107- /**
108- * Get filter params (par1-par8) as array.
109- */
110- public function getParams (): array
111- {
112- $ params = [];
113- for ($ i = 1 ; $ i <= 8 ; ++$ i ) {
114- $ key = "par {$ i }" ;
115- if ($ this ->{$ key }) {
116- $ params [$ key ] = $ this ->{$ key };
117- }
118- }
119-
120- return $ params ;
121- }
122-
123- /**
124- * Scope: active menus only.
125- *
126- * @param mixed $query
127- */
128- public function scopeActive ($ query )
129- {
130- return $ query ->where ('active ' , 1 );
131- }
132-
133- /**
134- * Scope: filter by module.
135- *
136- * @param mixed $query
137- */
138- public function scopeModule ($ query , string $ moduleId )
139- {
140- return $ query ->where ('moduleid ' , $ moduleId );
141- }
142-
143- /**
144- * Scope: filter by type.
145- *
146- * @param mixed $query
147- */
148- public function scopeType ($ query , string $ type )
149- {
150- return $ query ->where ('type ' , $ type );
151- }
152-
153- /**
154- * Get all menus ordered hierarchically.
155- *
156- * @param mixed $query
157- */
158- public function scopeOrdered ($ query )
159- {
160- return $ query ->orderBy ('menuid ' );
161- }
162-
163- /**
164- * Get icon filename from picture1.
165- */
166- public function getIconName (): string
167- {
168- if ($ this ->picture1 ) {
169- return pathinfo ($ this ->picture1 , PATHINFO_FILENAME );
170- }
171-
172- return match ($ this ->type ) {
173- self ::TYPE_MODULE_ROOT => 'cube ' ,
174- self ::TYPE_VOUCHER => 'document-text ' ,
175- self ::TYPE_MASTER => 'folder ' ,
176- self ::TYPE_REPORT => 'chart-bar ' ,
177- self ::TYPE_UTILITY => 'wrench ' ,
178- self ::TYPE_SETUP => 'cog ' ,
179- default => 'folder ' ,
180- };
181- }
182-
183- /**
184- * Get display name (prefer bar over short_name).
185- */
186- public function getDisplayName (): string
187- {
188- return $ this ->bar ?: $ this ->short_name ?: $ this ->menuid ;
132+ return self ::TYPE_SETUP === (string ) $ this ->type ;
189133 }
190134}
0 commit comments