public function update($id) { $movement_costs = Input::get('movement_costs'); $movement_costs = str_replace(",", ".", $movement_costs); $movement_costs = str_replace(".", "", $movement_costs); $movement_costs = substr($movement_costs, 0, -2); $upgrade_costs = Input::get('upgrade_costs'); $upgrade_costs = str_replace(",", ".", $upgrade_costs); $upgrade_costs = str_replace(".", "", $upgrade_costs); $upgrade_costs = substr($upgrade_costs, 0, -2); $movement = Movement::findOrFail($id); $last_course_id = $movement->destination_id; $student_id = $movement->student_id; $movement->destination_id = Input::get('destination_id'); $movement->employee_id = Input::get('employee_id'); $movement->movement_date = Input::get('date'); $movement->movement_costs = $movement_costs; $movement->upgrade_costs = $upgrade_costs; $movement->comments = Input::get('comments'); $movement->save(); if ((double) $upgrade_costs > 0) { $receivable = Receivable::where('registration_id', '=', $placement->registration_id)->first(); $receivable->total = $receivable->total + $upgrade_costs; $receivable->receivable = $receivable->receivable + $upgrade_costs; $receivable->balance = $receivable->balance + $upgrade_costs; $receivable->save(); } $earning_count = Earning::where('earnable_type', '=', 'Movement')->where('earnable_id', '=', $id)->count(); if ($earning_count > 0) { $earning = Earning::where('earnable_type', '=', 'Movement')->where('earnable_id', '=', $id)->first(); $earning->payment = $movement_costs + $upgrade_costs; $earning->save(); } }