public function update($id) { $fines = Input::get('fines'); $fines = str_replace(",", ".", $fines); $fines = str_replace(".", "", $fines); $fines = substr($fines, 0, -2); $punishment = new Punishment(); $punishment->release_date = Input::get('release_date'); $punishment->fines = $fines; $punishment->comments = Input::get('comments'); $punishment->save(); Session::flash('message', 'Sukses mengupdate Info Denda!'); }
public function purchase($id) { $payment = Input::get('payment'); $payment = str_replace(",", ".", $payment); $payment = str_replace(".", "", $payment); $payment = substr($payment, 0, -2); $fines = Input::get('fines'); $fines = str_replace(",", ".", $fines); $fines = str_replace(".", "", $fines); $fines = substr($fines, 0, -2); $installment = Installment::find($id); $installment->balance = $installment->balance - $payment; if ($installment->balance > 0) { $installment->paid = 0; } else { $installment->paid = 1; } $installment->save(); $earning_code = $this->generateCode(); $signature = Hash::make(date('Y-m-d H:i:s')); $earning = new Earning(); $earning->project_id = Auth::user()->curr_project_id; $earning->location_id = Auth::user()->location_id; $earning->issue_id = $installment->receivable->issue_id; $earning->employee_id = Input::get('employee_id'); $earning->earning_date = Input::get('earning_date'); $earning->earnable_type = 'Installment'; $earning->earnable_id = $installment->id; $earning->code = $earning_code; $earning->signature = $signature; $earning->payment = $payment; $earning->save(); if ($fines > 0) { $punishment = new Punishment(); $punishment->project_id = Auth::user()->curr_project_id; $punishment->location_id = Auth::user()->location_id; $punishment->issue_id = $installment->receivable->issue_id; $punishment->installment_id = $installment->id; $punishment->release_date = Input::get('earning_date'); $punishment->fines = $fines; $punishment->paid = 1; $punishment->save(); $earning = new Earning(); $earning->project_id = Auth::user()->curr_project_id; $earning->location_id = Auth::user()->location_id; $earning->issue_id = $installment->receivable->issue_id; $earning->employee_id = Input::get('employee_id'); $earning->earning_date = Input::get('earning_date'); $earning->earnable_type = 'Punishment'; $earning->earnable_id = $punishment->id; $earning->code = $earning_code; $earning->signature = $signature; $earning->payment = $fines; $earning->save(); } $receivable = Receivable::find($installment->receivable_id); $receivable->balance = $receivable->balance - $payment; $receivable->save(); return Response::json(array('status' => 'Succeed', 'earning' => $earning->code)); }