@@ -171,6 +171,46 @@ function onShowEnd() {
171171
172172 $ app ->tpl ->setVar ('template_additional_list ' , $ text );
173173 $ app ->tpl ->setVar ('app_module ' , 'client ' );
174+
175+ //* Set the 'customer no' default value
176+ if ($ this ->id == 0 ) {
177+
178+ if ($ app ->auth ->is_admin ()) {
179+ //* Logged in User is admin
180+ //* get the system config
181+ $ app ->uses ('getconf ' );
182+ $ system_config = $ app ->getconf ->get_global_config ();
183+ if ($ system_config ['misc ' ]['customer_no_template ' ] != '' ) {
184+
185+ //* Set customer no default
186+ $ customer_no = $ app ->functions ->intval ($ system_config ['misc ' ]['customer_no_start ' ]+$ system_config ['misc ' ]['customer_no_counter ' ]);
187+ $ customer_no_string = str_replace ('[CUSTOMER_NO] ' ,$ customer_no ,$ system_config ['misc ' ]['customer_no_template ' ]);
188+ $ app ->tpl ->setVar ('customer_no ' ,$ customer_no_string );
189+
190+ //* save new counter value
191+ $ system_config ['misc ' ]['customer_no_counter ' ]++;
192+ $ system_config_str = $ app ->ini_parser ->get_ini_string ($ system_config );
193+ $ app ->db ->datalogUpdate ('sys_ini ' , "config = ' " .$ app ->db ->quote ($ system_config_str )."' " , 'sysini_id ' , 1 );
194+ }
195+ } else {
196+ //* Logged in user must be a reseller
197+ //* get the record of the reseller
198+ $ client_group_id = $ app ->functions ->intval ($ _SESSION ["s " ]["user " ]["default_group " ]);
199+ $ reseller = $ app ->db ->queryOneRecord ("SELECT client.client_id, client.customer_no_template, client.customer_no_counter, client.customer_no_start FROM sys_group,client WHERE client.client_id = sys_group.client_id and sys_group.groupid = " .$ client_group_id );
200+
201+ if ($ reseller ['customer_no_template ' ] != '' ) {
202+ //* Set customer no default
203+ $ customer_no = $ app ->functions ->intval ($ reseller ['customer_no_start ' ]+$ reseller ['customer_no_counter ' ]);
204+ $ customer_no_string = str_replace ('[CUSTOMER_NO] ' ,$ customer_no ,$ reseller ['customer_no_template ' ]);
205+ $ app ->tpl ->setVar ('customer_no ' ,$ customer_no_string );
206+
207+ //* save new counter value
208+ $ customer_no_counter = $ app ->functions ->intval ($ reseller ['customer_no_counter ' ]+1 );
209+ $ app ->db ->query ("UPDATE client SET customer_no_counter = $ customer_no_counter WHERE client_id = " .$ app ->functions ->intval ($ reseller ['client_id ' ]));
210+ echo "UPDATE client SET customer_no_counter = $ customer_no_counter WHERE client_id = " .$ app ->functions ->intval ($ reseller ['client_id ' ]);
211+ }
212+ }
213+ }
174214
175215 parent ::onShowEnd ();
176216
0 commit comments