public function purchase($id) { $punishment = Punishment::find($id); $earning = new Earning(); $earning->project_id = Auth::user()->curr_project_id; $earning->location_id = Auth::user()->location_id; $earning->issue_id = $punishment->issue_id; $earning->employee_id = Auth::user()->employee_id; $earning->earning_date = date('Y-m-d'); $earning->earnable_type = 'Punishment'; $earning->earnable_id = $punishment->id; $earning->code = $this->generateCode(); $earning->signature = $this->generateSignature(); $earning->payment = $punishment->fines; $earning->save(); $punishment->paid = 1; $punishment->save(); return array('code' => $earning->code); }
public function purchaseCost($id) { $registration = Registration::has('issue')->find($id); $earning = new Earning(); $earning->project_id = $registration->project_id; $earning->location_id = $registration->location_id; $earning->issue_id = $registration->issue->id; $earning->employee_id = Auth::user()->employee_id; $earning->earning_date = $registration->registration_date; $earning->earnable_type = 'Registration'; $earning->earnable_id = $registration->id; $earning->code = $this->generateEarningCode(); $earning->signature = $this->generateEarningSignature(); $earning->payment = $registration->registration_cost; $earning->save(); $registration->cost_is_paid = 1; $registration->save(); return array('code' => $earning->code); }
public function store() { $receivables = Input::get('receivables'); $installments = Input::get('installments'); $registrations = Input::get('registrations'); $movements = Input::get('movements'); $punishments = Input::get('punishments'); $resigns = Input::get('resigns'); $code = $this->generateCode(); $signature = Hash::make(date('Y-m-d H:i:s')); try { DB::beginTransaction(); if ($receivables) { foreach ($receivables as $key => $value) { $receivable = explode("#", $value); $earning = new Earning(); $earning->project_id = Auth::user()->curr_project_id; $earning->location_id = Auth::user()->location_id; $earning->issue_id = Input::get('issue_id'); $earning->employee_id = Input::get('employee_id'); $earning->earning_date = Input::get('earning_date'); $earning->earnable_type = 'Receivable'; $earning->earnable_id = $receivable[0]; $earning->code = $code; $earning->signature = $signature; $earning->payment = $receivable[1]; $earning->save(); $receivable = Receivable::find($receivable[0]); $receivable->balance = 0; $receivable->save(); } } if ($installments) { foreach ($installments as $key => $value) { $installment = explode("#", $value); $payment = str_replace(",", ".", $installment[1]); $payment = str_replace(".", "", $payment); $earning = new Earning(); $earning->project_id = Auth::user()->curr_project_id; $earning->location_id = Auth::user()->location_id; $earning->issue_id = Input::get('issue_id'); $earning->employee_id = Input::get('employee_id'); $earning->earning_date = Input::get('earning_date'); $earning->earnable_type = 'Installment'; $earning->earnable_id = $installment[0]; $earning->code = $code; $earning->signature = $signature; $earning->payment = $installment[1]; $earning->save(); $installment = Installment::find($installment[0]); $installment->balance = 0; $installment->paid = 1; $installment->save(); $receivable = Receivable::find($installment->receivable_id); $receivable->balance = $receivable->balance - $payment; $receivable->save(); } } if ($registrations) { foreach ($registrations as $key => $value) { $registration = explode("#", $value); $earning = new Earning(); $earning->project_id = Auth::user()->curr_project_id; $earning->location_id = Auth::user()->location_id; $earning->issue_id = Input::get('issue_id'); $earning->employee_id = Input::get('employee_id'); $earning->earning_date = Input::get('earning_date'); $earning->earnable_type = 'Registration'; $earning->earnable_id = $registration[0]; $earning->code = $code; $earning->signature = $signature; $earning->payment = $registration[1]; $earning->save(); $registration = Registration::find($registration[0]); $registration->cost_is_paid = 1; $registration->save(); } } if ($movements) { foreach ($movements as $key => $value) { $movement = explode("#", $value); $earning = new Earning(); $earning->project_id = Auth::user()->curr_project_id; $earning->location_id = Auth::user()->location_id; $earning->issue_id = Input::get('issue_id'); $earning->employee_id = Input::get('employee_id'); $earning->earning_date = Input::get('earning_date'); $earning->earnable_type = 'Movement'; $earning->earnable_id = $movement[0]; $earning->code = $code; $earning->signature = $signature; $earning->payment = $movement[1] + $movement[2]; $earning->save(); $movement = Movement::find($movement[0]); $movement->paid = 1; $movement->save(); } } if ($punishments) { foreach ($punishments as $key => $value) { $punishment = explode("#", $value); $earning = new Earning(); $earning->project_id = Auth::user()->curr_project_id; $earning->location_id = Auth::user()->location_id; $earning->issue_id = Input::get('issue_id'); $earning->employee_id = Input::get('employee_id'); $earning->earning_date = Input::get('earning_date'); $earning->earnable_type = 'Punishment'; $earning->earnable_id = $punishment[0]; $earning->code = $code; $earning->signature = $signature; $earning->payment = $punishment[1]; $earning->save(); $punishment = Punishment::find($punishment[0]); $punishment->paid = 1; $punishment->save(); } } if ($resigns) { foreach ($resigns as $key => $value) { $resign = explode("#", $value); $earning = new Earning(); $earning->project_id = Auth::user()->curr_project_id; $earning->location_id = Auth::user()->location_id; $earning->issue_id = Input::get('issue_id'); $earning->employee_id = Input::get('employee_id'); $earning->earning_date = Input::get('earning_date'); $earning->earnable_type = 'Resign'; $earning->earnable_id = $resign[0]; $earning->code = $code; $earning->signature = $signature; $earning->payment = $resign[1]; $earning->save(); $resign = Resign::find($resign[0]); $resign->is_earned = 1; $resign->save(); } } DB::commit(); return array('status' => 'succeed', 'code' => $code); } catch (Exception $e) { DB::rollback(); return array('status' => 'failed', 'message' => $e); } }
public function payment($id) { $movement = Movement::find($id); $movement->paid = 1; $movement->save(); $earning = new Earning(); $earning->project_id = Auth::user()->curr_project_id; $earning->location_id = Auth::user()->location_id; $earning->issue_id = $movement->issue_id; $earning->employee_id = $movement->employee_id; $earning->earning_date = date('Y-m-d'); $earning->earnable_type = 'Movement'; $earning->earnable_id = $movement->id; $earning->code = $this->generateEarningCode(); $earning->signature = $this->generateSignature(); $earning->payment = $movement->movement_costs + $movement->upgrade_costs; $earning->save(); }
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)); }
public function earnFines($id) { $resign = Resign::find($id); $earning = new Earning(); $earning->project_id = Auth::user()->curr_project_id; $earning->location_id = Auth::user()->location_id; $earning->issue_id = $resign->issue_id; $earning->employee_id = $resign->employee_id; $earning->earning_date = $resign->resign_date; $earning->earnable_type = 'Resign'; $earning->earnable_id = $resign->id; $earning->code = $this->generateCode(); $earning->signature = $this->generateSignature(); $earning->payment = $resign->fines; $earning->save(); $resign->is_earned = 1; $resign->save(); return Response::json(array('earning' => $earning->code)); }