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";
 }
 public function findKit($bookingID)
 {
     $branch = Branches::find(Session::get('branch'));
     // If the session is not set, default to the IT depot
     if (!isset($branch)) {
         $branch = Branches::find(0);
     }
     // Get Kits to be received
     $data = DB::select('SELECT
                           K.ID AS KitID, K.KitType, K.Name AS KitName, K.AtBranch, K.KitState, K.BarcodeNumber, K.Specialized,  K.SpecializedName,
                           B.ID as BookingID, B.ForBranch, B.StartDate, B.EndDate, B.ShadowStartDate, B.ShadowEndDate, B.Purpose,
                           KS.StateName,
                           KT.Name AS KitTypeName, KT.TypeDescription as KitTypeDesc
                           FROM Booking AS B
                             INNER JOIN Kits as K ON (K.ID = B.KitID)
                               INNER JOIN KitTypes AS KT ON (KT.ID = K.KitType)
                               INNER JOIN KitSTate AS KS ON (KS.ID = K.KitState)
                          WHERE now() BETWEEN DATE_ADD(B.ShadowStartDate, INTERVAL -1 DAY) AND B.ShadowEndDate
                                AND B.ForBranch = ?
                                AND B.ForBranch <> K.AtBranch
                                ORDER BY BookingID
                                ', array($branch->ID));
     // Get Kits to be sent out
     $data2 = DB::select('SELECT
                           K.ID AS KitID, K.KitType, K.Name AS KitName, K.AtBranch, K.KitState, K.BarcodeNumber, K.Specialized,  K.SpecializedName,
                           B.ID as BookingID, B.ForBranch, B.StartDate, B.EndDate, B.ShadowStartDate, B.ShadowEndDate, B.Purpose,
                           KS.StateName,
                           KT.Name AS KitTypeName, KT.TypeDescription as KitTypeDesc
                           FROM Booking AS B
                             INNER JOIN Kits as K ON (K.ID = B.KitID)
                               INNER JOIN KitTypes AS KT ON (KT.ID = K.KitType)
                               INNER JOIN KitSTate AS KS ON (KS.ID = K.KitState)
                          WHERE now() BETWEEN DATE_ADD(B.ShadowStartDate, INTERVAL -1 DAY) AND B.ShadowEndDate
                                AND K.AtBranch = ?
                                AND B.ForBranch <> K.AtBranch
                                ORDER BY BookingID
                                ', array($branch->ID));
     $theBooking = Booking::findOrFail($bookingID);
     $theBookID = $theBooking->ID;
     return CheckIfAuthenticated('members.receiveKitManagement', ['mode' => 'receive', 'branch' => $branch, 'selected_menu' => 'main-menu-receive', 'receiveKits' => $data, 'sendKits' => $data2, 'findBookID' => $theBookID, 'kitTypes' => KitTypes::all()], 'home.index', [], false);
 }
Example #3
0
 public function show2($LogKey1 = NULL, $LogKey2 = NULL)
 {
     $clause = "LogKey1 = " . $LogKey1;
     $filters = array();
     if (Input::get('FILTERS-ALL') != "T") {
         $filters = $this->ArrayOfFilters(Input::all());
         $clause = $this->GetFilterClause($filters) . "LogKey1 = " . $LogKey1;
     } else {
         foreach (LogType::all() as $logType) {
             array_unshift($filters, $logType->ID);
         }
     }
     if ($LogKey2) {
         $clause = $clause . " and LogKey2 = " . $LogKey2;
     }
     $logs = Logs::whereraw($clause)->get();
     $kTyp = KitTypes::find($LogKey1);
     $kit = Kits::find($LogKey2);
     $title = "Log for " . $kTyp->Name . " -> " . $kit->Name;
     if ((int) $kit->Specialized == 1) {
         $title = $title . ' + ' . $kit->SecializedName;
     }
     return CheckIfAuthenticated('Logs.show', ['ID' => $LogKey2, 'logs' => $logs, 'logTitle' => $title, 'logTypes' => LogType::all(), 'filters' => $filters], 'home.index', [], true);
 }
Example #4
0
 public function index()
 {
     return CheckIfAuthenticated('kit.kitManagment', ['selected_menu' => 'main-menu-administration', 'selected_admin_menu' => 'admin-menu-manage-kits', 'kitTypes' => KitTypes::all(), 'branches' => Branches::all(), 'kitStates' => KitState::all()], 'home.index', [], true);
 }
Example #5
0
 public function getInventory()
 {
     $branch = Branches::find(Session::get('branch'));
     // If the session is not set, default to the IT depot
     if (!isset($branch)) {
         $branch = Branches::find(0);
     }
     $data = DB::select('SELECT
                           K.ID AS KitID, K.KitType, K.Name AS KitName, K.AtBranch, K.KitState, K.BarcodeNumber, K.Specialized,  K.SpecializedName,
                           B.ID as BookingID, B.ForBranch, B.StartDate, B.EndDate, B.ShadowStartDate, B.ShadowEndDate, B.Purpose,
                           KS.StateName,
                           KT.Name AS KitTypeName, KT.TypeDescription as KitTypeDesc
                           FROM Booking AS B
                             INNER JOIN Kits as K ON (K.ID = B.KitID)
                               INNER JOIN KitTypes AS KT ON (KT.ID = K.KitType)
                               INNER JOIN KitSTate AS KS ON (KS.ID = K.KitState)
                          WHERE now() BETWEEN DATE_ADD(B.ShadowStartDate, INTERVAL -1 DAY) AND B.ShadowEndDate
                                AND B.ForBranch = ?
                                AND B.ForBranch <> K.AtBranch
                         UNION
                         SELECT
                           K.ID AS KitID, K.KitType, K.Name AS KitName, K.AtBranch, K.KitState, K.BarcodeNumber, K.Specialized,  K.SpecializedName,
                           B.ID as BookingID, B.ForBranch, B.StartDate, B.EndDate, B.ShadowStartDate, B.ShadowEndDate, B.Purpose,
                           KS.StateName,
                           KT.Name AS KitTypeName, KT.TypeDescription as KitTypeDesc
                           FROM Booking AS B
                             INNER JOIN Kits as K ON (K.ID = B.KitID)
                               INNER JOIN KitTypes AS KT ON (KT.ID = K.KitType)
                               INNER JOIN KitSTate AS KS ON (KS.ID = K.KitState)
                          WHERE now() BETWEEN DATE_ADD(B.ShadowStartDate, INTERVAL -1 DAY) AND B.ShadowEndDate
                                AND K.AtBranch = ?
                                AND K.KitState = 1
                                AND B.ForBranch <> K.AtBranch
                         UNION
                         SELECT
                           K.ID AS KitID, K.KitType, K.Name AS KitName, K.AtBranch, K.KitState, K.BarcodeNumber, K.Specialized,  K.SpecializedName,
                           "", "", "", "", "", "", "",
                           KS.StateName,
                           KT.Name AS KitTypeName, KT.TypeDescription as KitTypeDesc
                           FROM Kits AS K
                             INNER JOIN KitTypes AS KT ON (KT.ID = K.KitType)
                             INNER JOIN KitSTate AS KS ON (KS.ID = K.KitState)
                               LEFT JOIN Booking AS B ON (     B.ForBranch <> K.AtBranch
                                                           AND B.KitID = K.ID
                                                           AND now() BETWEEN DATE_ADD(B.ShadowStartDate, INTERVAL -1 DAY) AND B.ShadowEndDate
                                                         )
                          WHERE  B.ID is null
                                 AND K.KitState = 1
                                 AND K.AtBranch = ?
                          ORDER BY KitID
                         ', array($branch->ID, $branch->ID, $branch->ID));
     $allBranches = array();
     foreach (Branches::all() as $brnch) {
         $allBranches[$brnch->ID] = array('ID' => $brnch->ID, 'BranchID' => $brnch->BranchID, 'Name' => $brnch->Name, 'Address' => $brnch->EPLAddress, 'PhoneNumber' => $brnch->PhoneNumber);
     }
     // Build a list of the users bookings.
     $userBookingIDs = array();
     $detRecords = DB::table("BookingDetails")->where('UserID', '=', Auth::user()->id)->where('BookingDetails.Booker', '=', 1)->join('Booking', 'BookingDetails.BookingID', '=', 'Booking.ID')->join('Kits', 'Booking.KitID', '=', 'Kits.ID')->join('Branches', 'Booking.ForBranch', '=', 'Branches.ID')->where('Booking.EndDate', '>=', new DateTime('today'))->select('Kits.Name as KitName', 'BookingDetails.*', 'Kits.KitType', 'Kits.Specialized', 'Kits.SpecializedName', 'Booking.*', 'Branches.BranchID');
     foreach ($detRecords->get() as $det) {
         array_unshift($userBookingIDs, $det->BookingID);
     }
     // union that with the bookings for this branch.
     $bookings = $detRecords->union(DB::table("BookingDetails")->where('BookingDetails.Booker', '=', 1)->join('Booking', 'BookingDetails.BookingID', '=', 'Booking.ID')->wherenotin('Booking.ID', $userBookingIDs)->join('Kits', 'Booking.KitID', '=', 'Kits.ID')->join('Branches', 'Booking.ForBranch', '=', 'Branches.ID')->where('Booking.EndDate', '>=', new DateTime('today'))->select('Kits.Name as KitName', 'BookingDetails.*', 'Kits.KitType', 'Kits.Specialized', 'Kits.SpecializedName', 'Booking.*', 'Branches.BranchID'))->orderBy('StartDate', 'desc');
     // slice out only the columns we need and send them to the client.
     $bookingDetails = array();
     foreach ($bookings->get() as $det) {
         array_unshift($bookingDetails, array('KitID' => $det->KitID, 'type' => $det->KitType, 'Name' => $det->Specialized ? $det->KitName . ' + ' . $det->SpecializedName : $det->KitName, 'Booker' => user::find($det->UserID)->realname, 'Branch' => $det->BranchID, 'Event' => $det->Purpose, 'Start Date' => date("d-m-y", strtotime($det->StartDate)), 'End Date' => date("d-m-y", strtotime($det->EndDate))));
     }
     //get today's date
     $res = array();
     // $res['sql'] = $bookings->toSql();
     $res['kitTypes'] = KitTypes::all();
     $res['data'] = $data;
     $res['branches'] = $allBranches;
     $res['branch_ID'] = $branch->ID;
     $res['branch_BranchID'] = $branch->BranchID;
     $res['branch_name'] = $branch->Name;
     $res['bookings'] = $bookingDetails;
     return json_encode($res);
 }