@@ -89,8 +89,7 @@ public static function save($id, $result, $inputs, $userLogin)
8989 $ user = null ;
9090 $ mode = "" ;
9191 if ($ id ){
92- $ user = User::where ('active ' , '1 ' )->where ('nip ' , $ id )->firstOrFail ();
93-
92+ $ user = User::where ('active ' , '1 ' )->where ('id ' , $ id )->firstOrFail ();
9493 $ user ->update ([
9594 'full_name ' => $ inputs ['full_name ' ],
9695 'position_id ' => $ inputs ['position_id ' ] ?? null ,
@@ -226,29 +225,38 @@ public static function searchUser($respon)
226225 return $ respon ;
227226 }
228227
229- public static function searchUserSuratKeluar ($ respon , $ permission , $ loginid )
228+ public static function searchUserSuratKeluar ($ respon , $ loginid )
230229 {
231230 $ qCek = User::join ('gen_position as gp ' , 'gp.id ' , 'position_id ' )
232- ->where ('gen_user.active ' , '1 ' )->where ('gen_user.id ' , $ loginid )
233- ->where ('gp.active ' , '1 ' )
234- ->select ('gen_user.id as id ' , DB ::raw ("coalesce(gp.parent_id, 0) as parent_id " ) , 'gp.position_name ' )->first ();
235-
236- $ query = User::leftJoin ('gen_position as gp ' , 'gp.id ' , 'position_id ' )->where ('gen_user.active ' ,'1 ' );
237- switch ($ permission ) {
238- case 'suratKeluar_approve ' :
239- $ query = $ query ->where ('gp.id ' , 3 );
240- break ;
241- case 'suratKeluar_verify ' :
242- $ query = $ query ->where ('gp.id ' , 4 );
243- break ;
244- case 'suratKeluar_agenda ' :
245- $ query = $ query ->where ('gp.id ' , 2 );
246- break ;
247- case 'suratKeluar_save ' :
248- $ query = $ query ->where ('gp.id ' , $ qCek ->parent_id );
249- break ;
250- default :
251- $ query = $ query ;
231+ ->where ('gen_user.active ' , '1 ' )
232+ ->where ('gen_user.id ' , $ loginid )
233+ ->where ('gp.active ' , '1 ' )
234+ ->select (
235+ 'gen_user.id as id ' ,
236+ DB ::raw ("coalesce(gp.parent_id, 0) as parent_id " ) ,
237+ 'gp.position_name ' ,
238+ 'is_parent ' ,
239+ 'is_admin ' ,
240+ 'is_sekretaris ' ,
241+ 'is_subagumum ' ,
242+ 'is_officer ' )
243+ ->first ();
244+
245+ $ query = User::leftJoin ('gen_position as gp ' , 'gp.id ' , 'position_id ' )
246+ ->where ('gen_user.active ' ,'1 ' );
247+
248+ if ($ qCek ->is_admin ){
249+ $ query = $ query ;
250+ } else if ($ qCek ->is_sekretaris ){
251+ $ query = $ query ->where ('is_subagumum ' , '1 ' );
252+ } else if ($ qCek ->is_subagumum ){
253+ $ query = $ query ->where ('is_kadin ' , '1 ' );
254+ } else if ($ qCek ->is_parent ){
255+ $ query = $ query ->where ('is_sekretaris ' , '1 ' );
256+ } else if ($ qCek ->parent_id ){
257+ $ query = $ query ->where ('gp.id ' , $ qCek ->parent_id );
258+ } else {
259+ $ query = $ query ;
252260 }
253261
254262 $ data = $ query ->select ('gen_user.id ' , DB ::raw ("full_name || ' - ' || coalesce(position_name,'') as text " ))
@@ -263,9 +271,11 @@ public static function searchUserSuratKeluar($respon, $permission, $loginid)
263271 public static function searchUserTtd ($ respon , $ loginid )
264272 {
265273 $ query = User::leftJoin ('gen_position as gp ' , 'gp.id ' , 'position_id ' )
266- ->where ('gen_user.active ' ,'1 ' )->whereIn ('gp.id ' , [2 ,3 ])
274+ ->where ('gen_user.active ' ,'1 ' )
275+ ->whereRaw ("(is_kadin = '1' or is_sekretaris = '1') " )
267276 ->select ('gen_user.id ' , DB ::raw ("full_name || ' - ' || coalesce(position_name,'') as text " ))
268277 ->get ();
278+
269279 $ respon ['success ' ] = true ;
270280 $ respon ['state_code ' ] = 200 ;
271281 $ respon ['data ' ] = $ query ;
@@ -276,25 +286,22 @@ public static function searchUserTtd($respon, $loginid)
276286 public static function searchUserSuratMasuk ($ respon , $ loginid )
277287 {
278288 $ qCek = User::join ('gen_position as gp ' , 'gp.id ' , 'position_id ' )
279- ->where ('gen_user.active ' , '1 ' )->where ('gen_user.id ' , $ loginid )
280- ->where ('gp.active ' , '1 ' )
281- ->select ('gen_user.id as id ' , 'gp.id as position_id ' , 'gp.position_name ' )->first ();
289+ ->where ('gen_user.active ' , '1 ' )
290+ ->where ('gen_user.id ' , $ loginid )
291+ ->where ('gp.active ' , '1 ' )
292+ ->select ('gen_user.id as id ' , 'gp.id as position_id ' , 'gp.position_name ' , 'is_sekretaris ' , 'is_kadin ' , 'is_admin ' , 'is_officer ' )
293+ ->first ();
282294
283295 if ($ qCek != null ){
284296 $ query = User::leftJoin ('gen_position as gp ' , 'gp.id ' , 'position_id ' )->where ('gen_user.active ' ,'1 ' );
285- switch ($ qCek ->position_id ) {
286- case 1 :
287- $ query = $ query ;
288- break ;
289- case 4 :
290- $ query = $ query ->whereIn ('gp.id ' , [2 ,3 ]);
291- break ;
292- case 2 :
293- case 3 :
294- $ query = $ query ->where ('gp.is_parent ' , '1 ' );
295- break ;
296- default :
297- $ query = $ query ->where ('gp.parent_id ' , $ qCek ->position_id );
297+ if ($ qCek ->is_admin ){
298+ $ query = $ query ;
299+ } else if ($ qCek ->is_sekretaris || $ qCek ->is_kadin ){
300+ $ query = $ query ->where ('gp.is_parent ' , '1 ' );
301+ } else if ($ qCek ->is_officer ){
302+ $ query = $ query ->whereRaw ("(is_kadin = '1' or is_sekretaris = '1') " );
303+ } else {
304+ $ query = $ query ->where ('gp.parent_id ' , $ qCek ->position_id );
298305 }
299306
300307 $ data = $ query ->select ('gen_user.id ' , DB ::raw ("full_name || ' - ' || coalesce(position_name,'') as text " ))
0 commit comments