app/Http/Controllers/ItemRequestController.php
/*
     * Distribute items to the company level
     *
     */
Distribute items to the company level
Distribute items to the company level
public function confirmCompanyRequestByUnit(Request $request){
        try{
            if(!$request->input('condemnation_id'))
                throw new Exception("Condemnation Id required");
            if(!$request->input('request_id'))
                throw new Exception("Request Id required");
            $unitUser = $request->user();
            if(!$unitUser || !$unitUser->hasRole('unit'))
                throw new Exception("Please try to login as unit user!");
            $pendingRequest = KitItemRequest::where([
                'id'=>$request->input('request_id'),
                'stage'=>5
            ])->first();
            if( !$pendingRequest )
                throw new Exception("Sorry could not found any pending request!");
            $pendingRequest->kit_items = \GuzzleHttp\json_decode($pendingRequest->kit_items);
            $companyOfficeId = TermRelation::getCompanyInfoByUserId($pendingRequest->company_user_id)->company_id;
            $unitOfficeId = TermRelation::getUnitInfoByUserId($pendingRequest->unit_user_id)->unit_id;
            foreach($pendingRequest->kit_items->kit_types as $items){
                CompanyItems::updateUnitItems($items->type_id, $companyOfficeId, 1, $items->quantity);
                UnitItems::updateUnitItems($items->type_id, $unitOfficeId, 2, $items->quantity );
            }
            $pendingRequest->kit_items = \GuzzleHttp\json_encode($pendingRequest->kit_items);
            $pendingRequest->stage = 6;
            $pendingRequest->save();
            $this->updateCompanySolderPendingStatus($companyOfficeId);
            return ['success'=>true, "message"=>"Confirm company approval items!"];
        }catch (Exception $e){
            return ['success'=>false, 'message'=>$e->getMessage()];
        }
    }
public function confirmCompanyRequestByUnit ( Request $ request ) { try { if ( ! $ request -> input ( 'condemnation_id' ) ) throw new Exception ( " Condemnation Id required " ) ; if ( ! $ request -> input ( 'request_id' ) ) throw new Exception ( " Request Id required " ) ; $ unitUser = $ request -> user ( ) ; if ( ! $ unitUser || ! $ unitUser -> hasRole ( 'unit' ) ) throw new Exception ( " Please try to login as unit user! " ) ; $ pendingRequest = KitItemRequest :: where ( [ 'id' => $ request -> input ( 'request_id' ) , 'stage' => 5 ] ) -> first ( ) ; if ( ! $ pendingRequest ) throw new Exception ( " Sorry could not found any pending request! " ) ; $ pendingRequest -> kit_items = \ GuzzleHttp \ json_decode ( $ pendingRequest -> kit_items ) ; $ companyOfficeId = TermRelation :: getCompanyInfoByUserId ( $ pendingRequest -> company_user_id ) -> company_id ; $ unitOfficeId = TermRelation :: getUnitInfoByUserId ( $ pendingRequest -> unit_user_id ) -> unit_id ; foreach ( $ pendingRequest -> kit_items -> kit_types as $ items ) { CompanyItems :: updateUnitItems ( $ items -> type_id , $ companyOfficeId , 1 , $ items -> quantity ) ; UnitItems :: updateUnitItems ( $ items -> type_id , $ unitOfficeId , 2 , $ items -> quantity ) ; } $ pendingRequest -> kit_items = \ GuzzleHttp \ json_encode ( $ pendingRequest -> kit_items ) ; $ pendingRequest -> stage = 6 ; $ pendingRequest -> save ( ) ; $ this -> updateCompanySolderPendingStatus ( $ companyOfficeId ) ; return [ 'success' => true , " message " => " Confirm company approval items! " ] ; } catch ( Exception $ e ) { return [ 'success' => false , 'message' => $ e -> getMessage ( ) ] ; } }
Distribute items to the company level
Distribute items to the company level