app/Http/Controllers/ItemRequestController.php
/*
     * Create solder request for new product
     * request_type = company | solder
     *
     * @fields(solder_kit_id, request_type, comments, kit_problem)
     */
Create solder request for new product
request_type = company | solder


Create solder request for new product request_type = company | solder
public function SolderRequest(Request $request){
       try{
           $validator = Validator::make($request->all(), [
               'solder_kit_id' => 'required',
               'request_type'=>'required'
           ]);
           if( $validator->fails()){
               $validatorErrors = [];
               foreach($validator->messages()->getMessages() as $fieldName => $messages) {
                   foreach( $messages as $message){
                       $validatorErrors[$fieldName] = $message;
                   }
               }
               throw new Exception(implode(' ',$validatorErrors));
           }
           $actionItem = SolderKits::find( $request->input('solder_kit_id') );
           $terms = TermRelation::where(['user_id'=>$actionItem->user_id, 'term_type'=>0])->first();
           $newRequest = new SolderItemRequest();
           $newRequest->user_id = $terms->user_id;
           $newRequest->company_id = $terms->company_id;
           $newRequest->solder_kit_id = $request->input('solder_kit_id');
           $newRequest->problem_list = $request->input('kit_problem');
           $newRequest->comments = $request->input('comments');
           if( $request->input('request_type') === 'company' )
               $newRequest->status = 1; 
           $newRequest->save();
           $actionItem->status = 1;
           $actionItem->save();
           $notificationSend = KimNotification::sendDownstreamMessage();
           return ['success'=>true, 'message'=>"Request send to the company. Will review as soon as possible!"];
       }catch (Exception $e){
           return ['success'=>false, 'message'=>$e->getMessage()];
       }
   }
public function SolderRequest ( Request $ request ) { try { $ validator = Validator :: make ( $ request -> all ( ) , [ 'solder_kit_id' => 'required' , 'request_type' => 'required' ] ) ; if ( $ validator -> fails ( ) ) { $ validatorErrors = [ ] ; foreach ( $ validator -> messages ( ) -> getMessages ( ) as $ fieldName => $ messages ) { foreach ( $ messages as $ message ) { $ validatorErrors [ $ fieldName ] = $ message ; } } throw new Exception ( implode ( ' ' , $ validatorErrors ) ) ; } $ actionItem = SolderKits :: find ( $ request -> input ( 'solder_kit_id' ) ) ; $ terms = TermRelation :: where ( [ 'user_id' => $ actionItem -> user_id , 'term_type' => 0 ] ) -> first ( ) ; $ newRequest = new SolderItemRequest ( ) ; $ newRequest -> user_id = $ terms -> user_id ; $ newRequest -> company_id = $ terms -> company_id ; $ newRequest -> solder_kit_id = $ request -> input ( 'solder_kit_id' ) ; $ newRequest -> problem_list = $ request -> input ( 'kit_problem' ) ; $ newRequest -> comments = $ request -> input ( 'comments' ) ; if ( $ request -> input ( 'request_type' ) === 'company' ) $ newRequest -> status = 1 ; $ newRequest -> save ( ) ; $ actionItem -> status = 1 ; $ actionItem -> save ( ) ; $ notificationSend = KimNotification :: sendDownstreamMessage ( ) ; return [ 'success' => true , 'message' => " Request send to the company. Will review as soon as possible! " ] ; } catch ( Exception $ e ) { return [ 'success' => false , 'message' => $ e -> getMessage ( ) ] ; } }
Create solder request for new product
 request_type = company | solder
Create solder request for new product request_type = company | solder
// Get current item which assign to solder // Get solder related terms // Request for new item and approve from company // Change solder kit status 1 for pending mode // Send solder notification after accept new kit item request