app/Http/Controllers/ItemRequestController.php
/*
    * Get all pending request for central
    */
Get all pending request for central
Get all pending request for central
public function centralLevelPendingRequest(Request $request){
        try{
            $centralUser = $request->user();
            if(!$centralUser || !$centralUser->hasRole('central'))
                throw new Exception("Please try to login as central user!");
            $pendingRequest = KitItemRequest::where([
                'central_user_id'=>$centralUser->id,
                'status'=> 4 
            ])->whereIn('stage', array(1,2,3))->get();
            if(count($pendingRequest) == 0 ){
                return ['success'=>true,'data'=>[]];
            }
            foreach( $pendingRequest as $pRequest){
                $kitItems = \GuzzleHttp\json_decode($pRequest->kit_items);
                if(count($kitItems) > 0 ){
                    foreach ($kitItems as $key=>$subKitItem){ 
                        $kitItems[$key]->quarter_master = TermRelation::getQuarterMasterInfoByUserId($subKitItem->quarter_master_user_id);
                        foreach($subKitItem->kit_items as $q=>$unitLevel) { 
                            $kitItems[$key]->kit_items[$q]->unit = TermRelation::getUnitInfoByUserId($unitLevel->unit_user_id);
                            if (is_array($unitLevel->kit_items)) {
                                foreach ($unitLevel->kit_items as $k => $companyLevel) { 
                                    $kitItems[$key]->kit_items[$q]->kit_items[$k]->company = TermRelation::getCompanyInfoByUserId($companyLevel->company_user_id);
                                    $kitItems[$key]->kit_items[$q]->kit_items[$k]->items = KitItem::getKitItemsByIds(explode(',',$companyLevel->kit_items->kit_ids));
                                }
                            }
                        }
                    }
                }
                $pRequest->kit_items = $kitItems;
                $pRequest->formation = TermRelation::getFormationInfoByUserId($pRequest->district_user_id);
            }
            return ['success'=>true,'data'=>$pendingRequest];
        }catch (Exception $e){
            return ['success'=>false, 'message'=>$e->getMessage()];
        }
    }
public function centralLevelPendingRequest ( Request $ request ) { try { $ centralUser = $ request -> user ( ) ; if ( ! $ centralUser || ! $ centralUser -> hasRole ( 'central' ) ) throw new Exception ( " Please try to login as central user! " ) ; $ pendingRequest = KitItemRequest :: where ( [ 'central_user_id' => $ centralUser -> id , 'status' => 4 ] ) -> whereIn ( 'stage' , array ( 1 , 2 , 3 ) ) -> get ( ) ; if ( count ( $ pendingRequest ) == 0 ) { return [ 'success' => true , 'data' => [ ] ] ; } foreach ( $ pendingRequest as $ pRequest ) { $ kitItems = \ GuzzleHttp \ json_decode ( $ pRequest -> kit_items ) ; if ( count ( $ kitItems ) > 0 ) { foreach ( $ kitItems as $ key => $ subKitItem ) { $ kitItems [ $ key ] -> quarter_master = TermRelation :: getQuarterMasterInfoByUserId ( $ subKitItem -> quarter_master_user_id ) ; foreach ( $ subKitItem -> kit_items as $ q => $ unitLevel ) { $ kitItems [ $ key ] -> kit_items [ $ q ] -> unit = TermRelation :: getUnitInfoByUserId ( $ unitLevel -> unit_user_id ) ; if ( is_array ( $ unitLevel -> kit_items ) ) { foreach ( $ unitLevel -> kit_items as $ k => $ companyLevel ) { $ kitItems [ $ key ] -> kit_items [ $ q ] -> kit_items [ $ k ] -> company = TermRelation :: getCompanyInfoByUserId ( $ companyLevel -> company_user_id ) ; $ kitItems [ $ key ] -> kit_items [ $ q ] -> kit_items [ $ k ] -> items = KitItem :: getKitItemsByIds ( explode ( ',' , $ companyLevel -> kit_items -> kit_ids ) ) ; } } } } } $ pRequest -> kit_items = $ kitItems ; $ pRequest -> formation = TermRelation :: getFormationInfoByUserId ( $ pRequest -> district_user_id ) ; } return [ 'success' => true , 'data' => $ pendingRequest ] ; } catch ( Exception $ e ) { return [ 'success' => false , 'message' => $ e -> getMessage ( ) ] ; } }
Get all pending request for central
Get all pending request for central
//formation // quarter mast //units // company