public function total() { if (!($total = Cache::read('receivables_total_' . $this->key, 'expenses'))) { $receivable = new Receivable(); $total = $receivable->find('all', array('fields' => array('sum(value) as total'), 'conditions' => array('or' => array('Receivable.user_id' => $this->Authorization->User->id(), 'Receivable.team_id' => $this->Authorization->User->Team->id())))); Cache::write('receivables_total_' . $this->key, $total, 'expenses'); } return isset($total[0][0]) ? round($total[0][0]['total'], 2) : 0; }
public function makeCash($id) { $receivable = Receivable::find($id); $receivable->payment = 'Cash'; $receivable->save(); $installments = Installment::where('receivable_id', '=', $receivable->id)->get(); foreach ($installments as $installment) { $installment->delete(); } Session::flash('message', 'Pembayaran Tagihan menjadi Tunai (Tanpa Angsuran)!'); }
public function destroy($id) { $reduction = Reduction::find($id); $receivable = Receivable::find($reduction->receivable_id); switch ($reduction->reductable_type) { case 'Discount': $receivable->billable += $reduction->reductable->nominal; $receivable->receivable += $reduction->reductable->nominal; $receivable->balance += $reduction->reductable->nominal; $receivable->save(); break; case 'Charge': $receivable->receivable += $reduction->reductable->nominal; $receivable->save(); break; case 'Promotion': if ($reductable->discount > 0.0) { $receivable->billable += $reduction->reductable->discount / 100 * $reduction->receivable->total; $receivable->receivable += $reduction->reductable->discount / 100 * $reduction->receivable->total; $receivable->balance += $reduction->reductable->discount / 100 * $reduction->receivable->total; $receivable->save(); } else { $receivable->billable += $reduction->reductable->nominal; $receivable->receivable += $reduction->reductable->nominal; $receivable->balance += $reduction->reductable->nominal; $receivable->save(); } break; case 'Voucher': if ($reductable->discount > 0.0) { $receivable->billable += $reduction->reductable->discount / 100 * $reduction->receivable->total; $receivable->receivable += $reduction->reductable->discount / 100 * $reduction->receivable->total; $receivable->balance += $reduction->reductable->discount / 100 * $reduction->receivable->total; $receivable->save(); } else { $receivable->billable += $reduction->reductable->nominal; $receivable->receivable += $reduction->reductable->nominal; $receivable->balance += $reduction->reductable->nominal; $receivable->save(); } break; } Reduction::destroy($id); Session::flash('message', 'Sukses Menghapus Potongan Biaya Bimbingan'); }
/** * Remove the specified resource from storage. * DELETE /accountreceivables/{id} * * @param int $id * @return Response */ public function destroy($id) { Receivable::find($id)->delete(); return Redirect::route('receivable'); }
public function destroy($code) { $earnings = Earning::where('code', '=', $code)->get(); foreach ($earnings as $earning) { switch ($earning->earnable_type) { case 'Receivable': $receivable = Receivable::find($earning->earnable_id); $receivable->balance += $receivable->balance + $earning->payment; $receivable->save(); $earning->delete(); break; case 'Installment': $installment = Installment::find($earning->earnable_id); $installment->balance += $installment->balance + $earning->payment; $installment->paid = 0; $installment->save(); $earning->delete(); break; case 'Registration': $registration = Registration::find($earning->earnable_id); $registration->cost_is_paid = 0; $registration->save(); $earning->delete(); break; case 'Movement': $movement = Movement::find($earning->earnable_id); $movement->paid = 0; $movement->save(); $earning->delete(); break; case 'Punishment': $punishment = Punishment::find($earning->earnable_id); $punishment->paid = 0; $punishment->save(); $earning->delete(); break; case 'Resign': $resign = Resign::find($earning->earnable_id); $resign->is_earned = 0; $resign->save(); $earning->delete(); break; default: $earning->delete(); break; } } }
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)); }