Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 public function unPurchase($id)
 {
     $punishment = Punishment::find($id);
     $earning = Earning::where('earnable_type', '=', 'Punishment')->where('earnable_id', '=', $punishment->id)->delete();
     $punishment->paid = 0;
     $punishment->save();
     Session::flash('message', 'Sukses membatalkan pembayaran denda!');
 }
Ejemplo n.º 3
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;
         }
     }
 }
Ejemplo n.º 4
0
 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));
 }