Esempio n. 1
0
 public function destroy($kitTypeID)
 {
     // This Shall be fun!
     // We have to deconstruct the types based on the forign key dependencys
     // First iterate all the kits, for each kit remove all contents,
     // and then all bookings (and all booking details)
     // then finally we can remove the kit type and then all the logs for that
     // kit type.
     foreach (Kits::where('KitType', '=', $kitTypeID)->get() as $kit) {
         foreach (KitContents::where("KitID", '=', $kit->ID)->get() as $content) {
             KitContents::destroy($content->ID);
         }
         foreach (Booking::where("KitID", '=', $kit->ID)->get() as $booking) {
             foreach (BookingDetails::where("BookingID", '=', $booking->ID)->get() as $detail) {
                 BookingDetails::destroy($detail->ID);
             }
             Booking::destroy($booking->ID);
         }
         Kits::destroy($kit->ID);
     }
     KitTypes::destroy($kitTypeID);
     // Do the logs last, as all the deletes will log the changes of deleting the bits.
     Logs::where('LogKey1', '=', $kitTypeID)->delete();
     return "OK";
 }
Esempio n. 2
0
 public function getLogout()
 {
     $log = Logs::where('user_id', '=', Auth::user()->id)->orderBy('id', 'DESC')->first();
     $log->logout = date('Y-m-d H:i:s', time());
     $log->save();
     Session::flash('success', 'Se ha cerrado sesión satisfactoriamente.');
     Auth::logout();
     return Redirect::to('administrador/login');
 }
Esempio n. 3
0
 public function getReportExport($type, $sdate, $edate)
 {
     list($type, $id) = explode('_', $type);
     $sdate = $sdate . ':00';
     $edate = $edate . ':00';
     // echo $sdate;
     // echo '<br>';
     // echo $edate;
     $rs = Logs::where(DB::raw('last_visit::text'), '>', $sdate)->where(DB::raw('last_visit::text'), '<', $edate)->join("data", "data.id", '=', "logs.data_id")->join("roles", "roles.id", '=', "logs.role_id")->join("v_user_info", "v_user_info.user_id", '=', "logs.userid")->orderBy("last_visit", 'DESC');
     if ($type == 'role') {
         $rs = $rs->where('roles.id', '=', $id)->get();
     } else {
         $rs = $rs->where('data.id', '=', $id)->get();
     }
     //$rs = $rs->where('data.id','=',$id)->get()->toArray();
     //var_dump(count($rs));
     return $rs;
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $issue = Issue::find($id);
     if ($issue == NULL) {
         throw new Exception('Invalid Book ID');
     }
     $issue->added_at_timestamp = date('d-M-y h:i A', strtotime($issue->added_at_timestamp));
     $book = Books::find($issue->book_id);
     $issue->book_name = $book->title;
     $issue->author = $book->author;
     $issue->category = Categories::find($book->category_id)->category;
     $issue->available_status = (bool) $issue->available_status;
     if ($issue->available_status == 1) {
         return $issue;
     }
     $conditions = array('return_time' => 0, 'book_issue_id' => $id);
     $book_issue_log = Logs::where($conditions)->take(1)->get();
     foreach ($book_issue_log as $log) {
         $student_id = $log->student_id;
     }
     $student_data = Student::find($student_id);
     unset($student_data->email_id);
     unset($student_data->books_issued);
     unset($student_data->approved);
     unset($student_data->rejected);
     $student_branch = Branch::find($student_data->branch)->branch;
     $roll_num = $student_data->roll_num . '/' . $student_branch . '/' . substr($student_data->year, 2, 4);
     unset($student_data->roll_num);
     unset($student_data->branch);
     unset($student_data->year);
     $student_data->roll_num = $roll_num;
     $student_data->category = StudentCategories::find($student_data->category)->category;
     $issue->student = $student_data;
     return $issue;
 }
 public function edit($id)
 {
     $issueID = $id;
     $conditions = array('book_issue_id' => $issueID, 'return_time' => 0);
     $log = Logs::where($conditions);
     if (!$log->count()) {
         throw new Exception('Invalid Book ID entered or book already returned');
     } else {
         $log = Logs::where($conditions)->firstOrFail();
         $log_id = $log['id'];
         $student_id = $log['student_id'];
         $issue_id = $log['book_issue_id'];
         DB::transaction(function () use($log_id, $student_id, $issue_id) {
             // change log status by changing return time
             $log_change = Logs::find($log_id);
             $log_change->return_time = time();
             $log_change->save();
             // decrease student book issue counter
             $student = Student::find($student_id);
             $student->books_issued = $student->books_issued - 1;
             $student->save();
             // change issue availability status
             $issue = Issue::find($issue_id);
             $issue->available_status = 1;
             $issue->save();
         });
         return 'Successfully returned';
     }
 }