app/Http/Controllers/ItemRequestController.php
/*
     * Accept pending request for district/formation
     */
Accept pending request for district/formation
Accept pending request for district / formation
public function acceptPendingRequestForDistrict(Request $request){
        try{
            if(!$request->input('request_id'))
                throw new Exception("Must be need request Id");
            if(!$request->input('delivery_item_number'))
                throw new Exception("Must be need number of delivery items");
            $deliveryItems = (int)$request->input('delivery_item_number');
            $centralUser = $request->user();
            if(!$centralUser || !$centralUser->hasRole('central'))
                throw new Exception("Please logged in as a central level");
            $pendingRequest = KitItemRequest::where([
                'id'=>$request->input('request_id'),
                'status'=> 4 
            ])->whereIn('stage', array(1,2))->first();
            $centralTerms = TermRelation::where(['user_id'=>$centralUser->id,'role'=>1,'term_type'=>0])->first();
            $centralItems = KitItem::getFreeItemNumberByCentralOffice($centralTerms->central_office_id);
            $itemDeliverable = floor($centralItems*66/100);
            if($itemDeliverable < $deliveryItems)
                throw new Exception("Sorry you do not have this amount of item");
            $pendingRequest->stage = 2;
            $pendingRequest->approval_items = $deliveryItems;
            $pendingRequest->save();
            $confirmToDistrictOffice = KitItemRequest::where([
                'id'=>$pendingRequest->parent_ids,
                'stage'=>4,
                'status'=>3
            ])->first();
            $confirmToDistrictOffice->approval_items = $deliveryItems;
            $confirmToDistrictOffice->stage = 5;
            $confirmToDistrictOffice->save();
            return ['success'=>true,"message"=>"Approve successful!"];
        }catch (Exception $e){
            return ['success'=>false, 'message'=>$e->getMessage()];
        }
    }
public function acceptPendingRequestForDistrict ( Request $ request ) { try { if ( ! $ request -> input ( 'request_id' ) ) throw new Exception ( " Must be need request Id " ) ; if ( ! $ request -> input ( 'delivery_item_number' ) ) throw new Exception ( " Must be need number of delivery items " ) ; $ deliveryItems = ( int ) $ request -> input ( 'delivery_item_number' ) ; $ centralUser = $ request -> user ( ) ; if ( ! $ centralUser || ! $ centralUser -> hasRole ( 'central' ) ) throw new Exception ( " Please logged in as a central level " ) ; $ pendingRequest = KitItemRequest :: where ( [ 'id' => $ request -> input ( 'request_id' ) , 'status' => 4 ] ) -> whereIn ( 'stage' , array ( 1 , 2 ) ) -> first ( ) ; $ centralTerms = TermRelation :: where ( [ 'user_id' => $ centralUser -> id , 'role' => 1 , 'term_type' => 0 ] ) -> first ( ) ; $ centralItems = KitItem :: getFreeItemNumberByCentralOffice ( $ centralTerms -> central_office_id ) ; $ itemDeliverable = floor ( $ centralItems * 66 / 100 ) ; if ( $ itemDeliverable < $ deliveryItems ) throw new Exception ( " Sorry you do not have this amount of item " ) ; $ pendingRequest -> stage = 2 ; $ pendingRequest -> approval_items = $ deliveryItems ; $ pendingRequest -> save ( ) ; $ confirmToDistrictOffice = KitItemRequest :: where ( [ 'id' => $ pendingRequest -> parent_ids , 'stage' => 4 , 'status' => 3 ] ) -> first ( ) ; $ confirmToDistrictOffice -> approval_items = $ deliveryItems ; $ confirmToDistrictOffice -> stage = 5 ; $ confirmToDistrictOffice -> save ( ) ; return [ 'success' => true , " message " => " Approve successful! " ] ; } catch ( Exception $ e ) { return [ 'success' => false , 'message' => $ e -> getMessage ( ) ] ; } }
Accept pending request for district/formation
Accept pending request for district / formation
//formation // Send notification