app/Http/Controllers/PurchaseRequestController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request)
    {
        $input = $request->all();
		$rules = array ('requestID' => 'required|numeric',
						'branchID' => 'required|numeric',
						'createdDate' => 'required',
						'expectedDeliveryDate' => 'required',
						);
		$messages = ['requestID.required' => 'Please input the request ID',
					 'requestID.numeric' => 'Please input the request ID in correct format',
					 'branchID.required' => 'Please input the branch id',
					 'branchID.numeric' => 'Please input the branch id in correct format',
					 'createdDate.required' => 'Please input the created date',
					 'expectedDeliveryDate.required' => 'Please input the expected delivery date',
					];
        $validator = Validator::make($input, $rules, $messages);
        if ($validator->fails()) 
		{             
            return back()->withErrors($validator);        
        } 
		else 
		{
			$purchaseRequest = PurchaseRequest::find($request->requestID);
			$purchaseRequest->branchID = $request->branchID;
			$purchaseRequest->createdDate = $request->createdDate;
			$purchaseRequest->expectedDeliveryDate = $request->expectedDeliveryDate;
			$purchaseRequest->status = 'Pending for Mapping';
			$purchaseRequest->remarks = $request->remarks;
			$purchaseRequest->save();
			$virtualItemID = $request->input('virtualItemID', []);
            $itemList = [];
            for ($item = 0; $item < count($virtualItemID); $item++) {
            	$itemList[$item] = self::getItemIDFromVirtualID($virtualItemID[$item]);
            }
            $requiredQuantity = $request->input('requiredQuantity', []);
            for ($item=0; $item < count($virtualItemID); $item++) {
            	PurchaseRequestItem::where('requestID', $request->requestID)->where('itemID', self::getItemIDFromVirtualID($virtualItemID[$item]))->delete();
            	$purchaseRequestItem = new PurchaseRequestItem;
            	if ($virtualItemID[$item] != '') {
            		$purchaseRequestItem->requestID = $request->requestID;
            		$purchaseRequestItem->itemID = self::getItemIDFromVirtualID($virtualItemID[$item]);
            		$purchaseRequestItem->quantity = $requiredQuantity[$item];
            		$purchaseRequestItem->balance = $requiredQuantity[$item];
            		$purchaseRequestItem->save();
            	}
            }
            return Redirect::to('purchaseRequest')->with('success','Successfully updated the purchase request Information!');
		}
    }
public function update ( Request $ request ) { $ input = $ request -> all ( ) ; $ rules = array ( 'requestID' => 'required|numeric' , 'branchID' => 'required|numeric' , 'createdDate' => 'required' , 'expectedDeliveryDate' => 'required' , ) ; $ messages = [ 'requestID.required' => 'Please input the request ID' , 'requestID.numeric' => 'Please input the request ID in correct format' , 'branchID.required' => 'Please input the branch id' , 'branchID.numeric' => 'Please input the branch id in correct format' , 'createdDate.required' => 'Please input the created date' , 'expectedDeliveryDate.required' => 'Please input the expected delivery date' , ] ; $ validator = Validator :: make ( $ input , $ rules , $ messages ) ; if ( $ validator -> fails ( ) ) { return back ( ) -> withErrors ( $ validator ) ; } else { $ purchaseRequest = PurchaseRequest :: find ( $ request -> requestID ) ; $ purchaseRequest -> branchID = $ request -> branchID ; $ purchaseRequest -> createdDate = $ request -> createdDate ; $ purchaseRequest -> expectedDeliveryDate = $ request -> expectedDeliveryDate ; $ purchaseRequest -> status = 'Pending for Mapping' ; $ purchaseRequest -> remarks = $ request -> remarks ; $ purchaseRequest -> save ( ) ; $ virtualItemID = $ request -> input ( 'virtualItemID' , [ ] ) ; $ itemList = [ ] ; for ( $ item = 0 ; $ item < count ( $ virtualItemID ) ; $ item ++ ) { $ itemList [ $ item ] = self :: getItemIDFromVirtualID ( $ virtualItemID [ $ item ] ) ; } $ requiredQuantity = $ request -> input ( 'requiredQuantity' , [ ] ) ; for ( $ item = 0 ; $ item < count ( $ virtualItemID ) ; $ item ++ ) { PurchaseRequestItem :: where ( 'requestID' , $ request -> requestID ) -> where ( 'itemID' , self :: getItemIDFromVirtualID ( $ virtualItemID [ $ item ] ) ) -> delete ( ) ; $ purchaseRequestItem = new PurchaseRequestItem ; if ( $ virtualItemID [ $ item ] != '' ) { $ purchaseRequestItem -> requestID = $ request -> requestID ; $ purchaseRequestItem -> itemID = self :: getItemIDFromVirtualID ( $ virtualItemID [ $ item ] ) ; $ purchaseRequestItem -> quantity = $ requiredQuantity [ $ item ] ; $ purchaseRequestItem -> balance = $ requiredQuantity [ $ item ] ; $ purchaseRequestItem -> save ( ) ; } } return Redirect :: to ( 'purchaseRequest' ) -> with ( 'success' , 'Successfully updated the purchase request Information!' ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .
//return $itemList;