app/Http/Controllers/ItemRequestController.php
/*
     * Unit request confirm from central
     * request_id
     * approve items number
     */
Unit request confirm from central
request_id
approve items number
Unit request confirm from central request_id approve items number
public function confirmUnitRequestFromCentral(Request $request){
        try{
            if(!$request->input('request_id'))
                throw new Exception("Must be need request Id");
            if(!$request->input('approval_items'))
                throw new Exception("Must be need number of approval items");
            $centralUser = $request->user();
            $approveItems = (int)$request->input('approval_items');
            $getUnitRequest = KitItemRequest::find($request->input('request_id'));
            if(!$getUnitRequest)
                throw new Exception("Sorry could not found any request");
            if($getUnitRequest->stage == 5 )
                throw new Exception("Already approve this unit request!");
            $centralOfficeId = TermRelation::getCentralInfoByUserId($centralUser->id)->central_office_id;
            $allUnitPendingRequest = KitItemRequest::whereIn('id', array($getUnitRequest->parent_ids))->get();
            if(count($allUnitPendingRequest) > 0 ){
                foreach($allUnitPendingRequest as $UPendingRequest ) {
                    $kit_items = \GuzzleHttp\json_decode($UPendingRequest->kit_items);
                    $unitOfficeId = TermRelation::getUnitInfoByUserId($UPendingRequest->unit_user_id)->unit_id;
                    foreach ($kit_items->kit_types as $kitTypes) {
                        UnitItems::updateUnitItems($kitTypes->type_id, $unitOfficeId, 1, $kitTypes->quantity);
                        CentralItems::updateCentralItems($kitTypes->type_id, $centralOfficeId, 2, $kitTypes->quantity);
                    }
                    $UPendingRequest->approval_items = $approveItems;
                    $UPendingRequest->stage = 5;
                    $UPendingRequest->save();
                }
            }
            $getUnitRequest->approval_items = $approveItems;
            $getUnitRequest->stage = 5;
            $getUnitRequest->save();
            $updateRequestData = $this->updateCentralKitData($getUnitRequest->id, $centralUser->id);
            return ['success'=>true,"message"=>"Confirm unit request from central!", 'data'=>$updateRequestData];
        }catch (Exception $e){
            return ['success'=>false, 'message'=>$e->getMessage()];
        }
    }
public function confirmUnitRequestFromCentral ( Request $ request ) { try { if ( ! $ request -> input ( 'request_id' ) ) throw new Exception ( " Must be need request Id " ) ; if ( ! $ request -> input ( 'approval_items' ) ) throw new Exception ( " Must be need number of approval items " ) ; $ centralUser = $ request -> user ( ) ; $ approveItems = ( int ) $ request -> input ( 'approval_items' ) ; $ getUnitRequest = KitItemRequest :: find ( $ request -> input ( 'request_id' ) ) ; if ( ! $ getUnitRequest ) throw new Exception ( " Sorry could not found any request " ) ; if ( $ getUnitRequest -> stage == 5 ) throw new Exception ( " Already approve this unit request! " ) ; $ centralOfficeId = TermRelation :: getCentralInfoByUserId ( $ centralUser -> id ) -> central_office_id ; $ allUnitPendingRequest = KitItemRequest :: whereIn ( 'id' , array ( $ getUnitRequest -> parent_ids ) ) -> get ( ) ; if ( count ( $ allUnitPendingRequest ) > 0 ) { foreach ( $ allUnitPendingRequest as $ UPendingRequest ) { $ kit_items = \ GuzzleHttp \ json_decode ( $ UPendingRequest -> kit_items ) ; $ unitOfficeId = TermRelation :: getUnitInfoByUserId ( $ UPendingRequest -> unit_user_id ) -> unit_id ; foreach ( $ kit_items -> kit_types as $ kitTypes ) { UnitItems :: updateUnitItems ( $ kitTypes -> type_id , $ unitOfficeId , 1 , $ kitTypes -> quantity ) ; CentralItems :: updateCentralItems ( $ kitTypes -> type_id , $ centralOfficeId , 2 , $ kitTypes -> quantity ) ; } $ UPendingRequest -> approval_items = $ approveItems ; $ UPendingRequest -> stage = 5 ; $ UPendingRequest -> save ( ) ; } } $ getUnitRequest -> approval_items = $ approveItems ; $ getUnitRequest -> stage = 5 ; $ getUnitRequest -> save ( ) ; $ updateRequestData = $ this -> updateCentralKitData ( $ getUnitRequest -> id , $ centralUser -> id ) ; return [ 'success' => true , " message " => " Confirm unit request from central! " , 'data' => $ updateRequestData ] ; } catch ( Exception $ e ) { return [ 'success' => false , 'message' => $ e -> getMessage ( ) ] ; } }
Unit request confirm from central
 request_id
 approve items number
Unit request confirm from central request_id approve items number
// Get each unit pending request //                    $UPendingRequest->kit_items = \GuzzleHttp\json_encode($UPendingRequest->kit_items);