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 transfer($id)
 {
     $book = Booking::where('id_alat', $id)->first();
     $transaksi = new Transaksi();
     $transaksi->id_alat = $book->id_alat;
     $transaksi->id_pengguna = $book->id_pengguna;
     $transaksi->dipinjam = $book->mulai;
     $transaksi->save();
     $book->delete();
     return redirect('/dipinjam');
 }