public function destroy($id)
 {
     $issues = Issue::where('registration_id', '=', $id)->delete();
     $placements = Placement::where('registration_id', '=', $id)->delete();
     $receivables = Receivable::where('registration_id', '=', $id)->get();
     foreach ($receivables as $receivable) {
         $installments = Installment::where('receivable_id', '=', $receivable->id)->get();
         foreach ($installments as $installment) {
             $earnings = Earning::where('earnable_type', '=', 'Installment')->where('earnable_id', '=', $installment->id)->get();
             foreach ($earnings as $earning) {
                 $earning->delete();
             }
             $installment->delete();
         }
         $earnings = Earning::where('earnable_type', '=', 'Receivable')->where('earnable_id', '=', $receivable->id)->delete();
         $reductions = Reduction::where('receivable_id', '=', $receivable->id)->delete();
         $receivable->delete();
     }
     Registration::destroy($id);
     Session::flash('message', 'Sukses membatalkan Pendaftaran!, Semua Data terkait pendaftaran ini telah dihapus!');
 }
 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;
 }
 /**
  * Show the form for creating a new resource.
  * GET /housedue/create
  *
  * @return Response
  */
 public function create()
 {
     $houses = House::all();
     $receivables = Receivable::all();
     $frequencies = Frequency::all();
     return View::make('backend.code.housedue.create', compact('houses', 'receivables', 'frequencies'));
 }
 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)!');
 }
Example #5
0
 public function loadEarnables($issue_id)
 {
     $issue = Issue::find($issue_id);
     $receivable = Receivable::with('installments_not_paid')->where('issue_id', '=', $issue_id)->first();
     $registrations = Registration::where('student_id', '=', $issue->student_id)->where('cost_is_paid', '=', 0)->get();
     $movements = Movement::where('issue_id', '=', $issue_id)->get();
     $punishments = Punishment::where('issue_id', '=', $issue_id)->where('paid', '=', 0)->get();
     $resigns = Resign::where('issue_id', '=', $issue_id)->where('is_earned', '=', 0)->get();
     $responses = array('receivable' => $receivable, 'registrations' => $registrations, 'movements' => $movements, 'punishments' => $punishments, 'resigns' => $resigns);
     return $responses;
 }
 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');
 }
Example #7
0
 public function normalizeIssue()
 {
     $issues = Issue::all();
     foreach ($issues as $issue) {
         // Normalize Educations
         $educations = Education::where('student_id', '=', $issue->student_id)->get();
         foreach ($educations as $education) {
             $education->student_id = $issue->id;
             $education->save();
         }
         // Normalize Placements
         $placements = Placement::where('student_id', '=', $issue->student_id)->get();
         foreach ($placements as $placement) {
             $placement->student_id = $issue->id;
             $placement->save();
         }
         // Normalize Receivables
         $receivables = Receivable::where('student_id', '=', $issue->student_id)->get();
         foreach ($receivables as $receivable) {
             $receivable->student_id = $issue->id;
             $receivable->save();
         }
     }
 }
Example #8
0
 public function createInvoice($id)
 {
     $receivables = Receivable::all();
     $houses = House::findOrFail($id);
     return View::make('backend.code.invoice.create', compact('houses', 'receivables'));
 }
 /**
  * Show the form for editing the specified resource.
  * GET /properties/{id}/edit
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $properties = Property::find($id);
     $owners = Owner::where('agent_id', '=', Sentry::getUser()->id)->get();
     $deposits = Receivable::where('receivable_type', '=', 'deposit')->get();
     $others = Receivable::where('receivable_type', '=', 'recurrent')->get();
     if (is_null($properties)) {
         return Redirect::route('admin.property.index');
     }
     return View::make('backend.code.property.edit', compact('properties', 'owners', 'deposits', 'others'));
 }
 /**
  * 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');
 }
Example #11
0
 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;
         }
     }
 }
 /**
  * Show the form for creating a new resource.
  * GET /invoice/create
  *
  * @return Response
  */
 public function create()
 {
     $invoices = Invoice::all();
     $receivables = Receivable::all();
     return View::make('backend.code.invoicedetail.create', compact('invoices', 'receivables'));
 }
Example #13
0
 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();
     }
 }
 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));
 }