public function add($id)
 {
     $input = Request::all();
     $peminjam = Peminjam::select('id')->where('nim/nip', $input['nipnim'])->first();
     $rules = array('nipnim' => 'required|exists:peminjam,nim/nip');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return view('error');
     } else {
         $check = 0;
         /* Cek apakah barang sedang dipinjam oleh orang lain */
         $check += Transaksi::where('id_alat', $id)->where('dikembalikan', '0000-00-00 00:00:00')->count();
         /* Cek apakah barang sudah dibooking oleh orang lain, kalo dibooking orang tersebut, boleh */
         $check += Booking::where('id_alat', $id)->where('id_pengguna', '<>', $peminjam->id)->where('mulai', '<=', date('Y-m-d H:i:s', time()))->where('selesai', '>=', date('Y-m-d H:i:s', time()))->count();
         /* Cek apakah barang sedang dipelihara */
         $check += Pemeliharaan::where('id_alat', $id)->where('mulai', '<=', date('Y-m-d H:i:s', time()))->where('selesai', '0000-00-00 00:00:00')->count();
         if ($check == 0) {
             $transaksi = new Transaksi();
             $transaksi->id_alat = $id;
             $transaksi->id_pengguna = $peminjam->id;
             $transaksi->dipinjam = date('Y-m-d H:i:s', time());
             $transaksi->save();
             return redirect('/dipinjam');
         } else {
             return view('error');
         }
     }
 }
예제 #2
0
 public function add($id)
 {
     $input = Request::all();
     $peminjam = Peminjam::select('id')->where('nim/nip', $input['nipnim'])->first();
     $rules = array('nipnim' => 'required|exists:peminjam,nim/nip', 'mulai' => 'required', 'selesai' => 'required');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         //return $this->failed(array('message' => $validator->messages()));
         echo "Validation";
         return view('error');
     } else {
         $booking_mulai = date('Y-m-d H:i:s', strtotime($input['mulai']));
         $booking_selesai = date('Y-m-d H:i:s', strtotime($input['selesai']));
         $check = 0;
         /* Cek apakah barang sedang dipinjam oleh orang lain */
         $check += Transaksi::where('id_alat', $id)->where('dikembalikan', '0000-00-00 00:00:00')->count();
         /* Cek apakah barang sudah dibooking oleh orang lain */
         $check += Booking::where('id_alat', $id)->where(function ($query) use($booking_mulai, $booking_selesai) {
             $query->where(function ($query) use($booking_mulai, $booking_selesai) {
                 $query->where('mulai', '>=', $booking_mulai)->where('mulai', '<=', $booking_selesai)->where('selesai', '>=', $booking_selesai);
             })->orwhere(function ($query) use($booking_mulai, $booking_selesai) {
                 $query->where('mulai', '<=', $booking_mulai)->where('selesai', '>', $booking_mulai)->where('mulai', '<', $booking_selesai)->where('selesai', '>=', $booking_selesai);
             })->orwhere(function ($query) use($booking_mulai, $booking_selesai) {
                 $query->where('mulai', '<=', $booking_mulai)->where('selesai', '>=', $booking_mulai)->where('selesai', '<=', $booking_selesai);
             })->orwhere(function ($query) use($booking_mulai, $booking_selesai) {
                 $query->where('mulai', '>=', $booking_mulai)->where('selesai', '<=', $booking_selesai);
             });
         })->count();
         /* Cek apakah barang sedang dipelihara */
         $check += Pemeliharaan::where('id_alat', $id)->where('mulai', '<=', $booking_mulai)->where('selesai', '0000-00-00 00:00:00')->count();
         if ($check == 0) {
             $booking = new Booking();
             $booking->id_alat = $id;
             $booking->id_pengguna = $peminjam->id;
             $booking->mulai = $booking_mulai;
             $booking->selesai = $booking_selesai;
             $booking->save();
             //return $this->success();
             return redirect('/dibooking');
         } else {
             //return $this->failed(array('message' => "Barang belum dikembalikan"));
             echo "Barang belum dikembalikan" . $id;
             return view('error');
         }
     }
 }
예제 #3
0
 public function statistik_kerusakan()
 {
     $input = Request::all();
     $peminjaman = NULL;
     if ($input["type"] == "all") {
         // statistik penggunaan semua barang
         $peminjaman = Pemeliharaan::join('alat', 'pemeliharaan.id_alat', '=', 'alat.id')->select(DB::raw('count(*) as y, alat.nama as name'))->groupBy('alat.nama')->get();
     } else {
         if (is_numeric($input["type"])) {
             // statistik penggunaan per item
             $peminjaman = Pemeliharaan::join('alat', 'pemeliharaan.id_alat', '=', 'alat.id')->where('alat.id', '=', $input['type'])->select(DB::raw('count(*) as y, alat.id as name'))->groupBy('alat.id')->get();
         } else {
             // statistik penggunaan per kategori
             $peminjaman = Pemeliharaan::join('alat', 'pemeliharaan.id_alat', '=', 'alat.id')->where('alat.nama', '=', $input['type'])->select(DB::raw('count(*) as y, alat.id as name'))->groupBy('alat.id')->get();
         }
     }
     return view('statistik', ['statistik_all' => $peminjaman]);
 }
 public function del($id)
 {
     Pemeliharaan::where('id_alat', $id)->where('selesai', '0000-00-00 00:00:00')->update(['selesai' => date('Y-m-d H:i:s', time())]);
     return redirect('/dipelihara');
 }