Пример #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     //        return $request->all();
     $messages = array('different' => 'Origin location and destination location cannot be same');
     if ($request->input('activity_type') == "On Day") {
         $this->validate($request, ['cost' => 'required|numeric', 'fare' => 'required|numeric', 'market_price' => 'required|numeric', 'location_id_origin' => 'different:location_id_destination'], $messages);
         $onday = Onday::where("activity_id", '=', $id)->first();
         $onday->type = $request->input('type');
         $onday->location_id_origin = $request->input('location_id_origin');
         $onday->customer_id = $request->input('customer');
         $onday->location_id_destination = $request->input('location_id_destination');
         $onday->cost = $request->input('cost');
         $onday->fare = $request->input('fare');
         $onday->market_price = $request->input('market_price');
         $onday->save();
         $activity = Activity::findOrFail($request->input('activity_id'));
         $activity->comment = $request->input('comment');
         $activity->save();
         //adding onday other costs
         $other_cost = $request->input('other_cost');
         if ($other_cost != null) {
             foreach ($other_cost as $key => $value) {
                 $onday_other_cost = OndayOtherCost::where('onday_id', $onday->id)->where('onday_other_cost_item_id', $key)->first();
                 $temp = $onday_other_cost->cost;
                 $onday_other_cost->cost = $value;
                 $onday->cost = $onday->cost - $temp;
                 $onday->cost = $onday->cost + $value;
                 $onday_other_cost->save();
                 $onday->save();
             }
         }
         return redirect()->route('home');
     } else {
         if ($request->input('activity_type') == "Maintenance") {
             $activity = Activity::findOrFail($request->input('activity_id'));
             $activity->comment = $request->input('comment');
             $activity->save();
             return redirect()->route('home');
         } else {
             if ($request->input('activity_type') == "Nil") {
                 $this->validate($request, ['cost' => 'required|numeric']);
                 $nil = Nil::where("activity_id", '=', $id)->first();
                 $nil->cost = $request->input('cost');
                 $nil->save();
                 $activity = Activity::findOrFail($request->input('activity_id'));
                 $activity->comment = $request->input('comment');
                 $activity->save();
                 return redirect()->route('home');
             }
         }
     }
     return $id;
 }
Пример #2
0
 public function processOndayForm(Request $request)
 {
     $messages = array('different' => 'Origin location and destination location cannot be same');
     $this->validate($request, ['cost' => 'required|numeric', 'fare' => 'required|numeric', 'market_price' => 'required|numeric', 'location_id_origin' => 'different:location_id_destination'], $messages);
     $onday = new Onday();
     $onday->type = $request->input('type');
     $onday->activity_id = $request->input('activity_id');
     $onday->location_id_origin = $request->input('location_id_origin');
     $onday->customer_id = $request->input('customer');
     $onday->location_id_destination = $request->input('location_id_destination');
     $onday->cost = $request->input('cost');
     $onday->fare = $request->input('fare');
     $onday->market_price = $request->input('market_price');
     $onday->save();
     $activity = Activity::findOrFail($request->input('activity_id'));
     $activity->comment = $request->input('comment');
     $activity->save();
     //adding onday other costs
     $other_cost = $request->input('other_cost');
     foreach ($other_cost as $key => $value) {
         if ($value) {
             $onday_other_cost = OndayOtherCost::create(['cost' => $value]);
             $onday_other_cost->onday_id = $onday->id;
             $onday_other_cost->onday_other_cost_item_id = $key;
             $onday_other_cost->save();
             $onday->cost = $onday->cost + $value;
             $onday->save();
         }
     }
     return redirect()->route('home');
 }