Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 203 |
|
0.00% |
0 / 16 |
CRAP | |
0.00% |
0 / 1 |
| BuyQueue | |
0.00% |
0 / 203 |
|
0.00% |
0 / 16 |
2862 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getAllCurrentQueueItems | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getDbName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAllCurrentQueueItemsSimple | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
20 | |||
| getAllCurrentQueueItemsFull | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
| getAllCurrentQueueItemsLight | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getAllCurrentQueueItemsLightFull | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| getAllCurrentQueueItemsLightSimple | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getOneQueueItem | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| getTodaysBuys | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| setQueueItem | |
0.00% |
0 / 56 |
|
0.00% |
0 / 1 |
182 | |||
| setQueueItemLight | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
42 | |||
| setCurrentQueue | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCurrentQueue | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRecentBuysByID | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
20 | |||
| getRecentBuysByPhoneNum | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Core; |
| 4 | |
| 5 | class BuyQueue extends Store |
| 6 | { |
| 7 | |
| 8 | public $currentQueue = array(); |
| 9 | |
| 10 | public function __construct($typeNum = null) { |
| 11 | parent::__construct(); |
| 12 | if($typeNum !== null) { |
| 13 | parent::createStore($typeNum); |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | public function getAllCurrentQueueItems(?\PDO $db = null, $app = null) { |
| 18 | if($this->billingActive == 2) { |
| 19 | //We know this is a digital sign only store. Use the simplified queue data rather than full |
| 20 | return $this->getAllCurrentQueueItemsSimple($app); |
| 21 | } else { |
| 22 | return $this->getAllCurrentQueueItemsFull($db); |
| 23 | } |
| 24 | |
| 25 | } |
| 26 | public function getDbName() |
| 27 | { |
| 28 | return parent::getDbName(); |
| 29 | } |
| 30 | |
| 31 | private function getAllCurrentQueueItemsSimple($app) { |
| 32 | $simpleQueue = new \BuyerKiosk\SimpleQueue\SimpleQueue($this); |
| 33 | $activeQueue = $simpleQueue->getActiveQueueItems(); |
| 34 | $tempQueue = array(); |
| 35 | foreach($activeQueue as $key => $item) { |
| 36 | if($item->firstName == "" && $item->lastName == "") { |
| 37 | $item->firstName = "#".$item->transID; |
| 38 | $item->lastName = ""; |
| 39 | } |
| 40 | $tempItem = array(); |
| 41 | $tempItem['buyID'] = $item->transID; |
| 42 | $tempItem['timeEntered'] = $item->timeEntered; |
| 43 | $tempItem['timeStarted'] = "0000-00-00 00:00:00"; |
| 44 | $tempItem['timeCompleted'] = $item->timeCompleted; |
| 45 | $tempItem['sortStarted'] = "0000-00-00 00:00:00"; |
| 46 | $tempItem['sortCompleted'] = "0000-00-00 00:00:00"; |
| 47 | $tempItem['firstName'] = $item->firstName; |
| 48 | $tempItem['lastName'] = $item->lastName; |
| 49 | $tempQueue[] = $tempItem; |
| 50 | } |
| 51 | return $tempQueue; |
| 52 | } |
| 53 | private function getAllCurrentQueueItemsFull(\PDO $db) { |
| 54 | $tempQueue = array(); |
| 55 | $queue = $db->query("SELECT * FROM buyQueue,customers WHERE buyQueue.isProcessed = 0 AND customers.customerID = buyQueue.customerID ORDER BY timeStarted DESC, sortCompleted DESC, sortStarted DESC, timeEntered ASC"); |
| 56 | |
| 57 | // Add error checking |
| 58 | if ($queue === false) { |
| 59 | return array(); // Return empty array if query fails |
| 60 | } |
| 61 | |
| 62 | if ($queue->rowCount() > 0) { |
| 63 | while ($data = $queue->fetch(\PDO::FETCH_ASSOC)) { |
| 64 | $tempQueue[] = $this->setQueueItem($data, $db); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | $this->currentQueue = $tempQueue; |
| 69 | return $this->currentQueue; |
| 70 | } |
| 71 | public function getAllCurrentQueueItemsLight(\PDO $db) |
| 72 | { |
| 73 | if($this->billingActive == 2) { |
| 74 | //We know this is a digital sign only store. Use the simplified queue data rather than full |
| 75 | return $this->getAllCurrentQueueItemsLightSimple($db); |
| 76 | } else { |
| 77 | return $this->getAllCurrentQueueItemsLightFull($db); |
| 78 | } |
| 79 | } |
| 80 | private function getAllCurrentQueueItemsLightFull(\PDO $db) { |
| 81 | $tempQueue = array(); |
| 82 | $queue = $db->query("SELECT buyID,timeEntered,timeStarted,sortStarted,sortCompleted,buyerID,firstName,lastName,remainingContainers,numContainers,processedContainers FROM buyQueue,customers WHERE buyQueue.isProcessed = 0 AND customers.customerID = buyQueue.customerID ORDER BY timeStarted DESC, sortCompleted DESC, sortStarted DESC, timeEntered ASC"); |
| 83 | if ($queue) { |
| 84 | $tempQueue = array(); |
| 85 | while ($data = $queue->fetch(\PDO::FETCH_ASSOC)) { |
| 86 | $tempQueue[] = $this->setQueueItemLight($data,$db); |
| 87 | } |
| 88 | //End While |
| 89 | } |
| 90 | $this->currentQueue = $tempQueue; |
| 91 | return $this->currentQueue; |
| 92 | } |
| 93 | private function getAllCurrentQueueItemsLightSimple(\PDO $db) { |
| 94 | |
| 95 | } |
| 96 | |
| 97 | //End getAllCurrentQueueItems |
| 98 | public function getOneQueueItem(\PDO $db, $buyID) |
| 99 | { |
| 100 | if(substr($buyID,0,1) == "B") { |
| 101 | $stmt = $db->prepare("SELECT * FROM buyQueue,customers WHERE buyQueue.drsBuyID = ? AND customers.customerID = buyQueue.customerID"); |
| 102 | $stmt->execute(array($buyID)); |
| 103 | $queue = $stmt; |
| 104 | } else { |
| 105 | $stmt = $db->prepare("SELECT * FROM buyQueue,customers WHERE buyQueue.buyID = ? AND customers.customerID = buyQueue.customerID"); |
| 106 | $stmt->execute(array($buyID)); |
| 107 | $queue = $stmt; |
| 108 | } |
| 109 | if ($queue->rowCount() == 0) { |
| 110 | return NULL; |
| 111 | } |
| 112 | $data = $queue->fetch(\PDO::FETCH_ASSOC); |
| 113 | return $this->setQueueItem($data,$db); |
| 114 | } |
| 115 | |
| 116 | public function getTodaysBuys(\PDO $db) |
| 117 | { |
| 118 | $queue = $db->query("SELECT * FROM buyQueue,customers WHERE buyQueue.isProcessed = 0 AND customers.customerID = buyQueue.customerID ORDER BY timeStarted DESC,sortStarted DESC, timeEntered ASC"); |
| 119 | $tempQueue = array(); |
| 120 | while ($data = $queue->fetch(\PDO::FETCH_ASSOC)) { |
| 121 | $tempQueue[] = $this->setQueueItem($data, $db); |
| 122 | } |
| 123 | return $tempQueue; |
| 124 | } |
| 125 | |
| 126 | public function setQueueItem($data, $db) { |
| 127 | $QueueItem = new \QueueItem(); |
| 128 | |
| 129 | if(isset($data['buyerID']) && !empty($data['buyerID'])) { |
| 130 | $employeeQuery = $db->query("SELECT * FROM employees WHERE employeeID = " . $data["buyerID"]); |
| 131 | if ($employeeQuery && ($employee = $employeeQuery->fetch(\PDO::FETCH_ASSOC))) { |
| 132 | $QueueItem->setBuyerFirstName($employee["employeeFirstName"]); |
| 133 | $QueueItem->setBuyerLastName($employee["employeeLastName"]); |
| 134 | } else { |
| 135 | $QueueItem->setBuyerFirstName(""); |
| 136 | $QueueItem->setBuyerLastName(""); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | if(isset($data['sorterID']) && !empty($data['sorterID'])) { |
| 141 | $sorterQuery = $db->query("SELECT * FROM employees WHERE employeeID = " . $data['sorterID']); |
| 142 | if($sorterQuery && ($sorter = $sorterQuery->fetch(\PDO::FETCH_ASSOC))) { |
| 143 | $QueueItem->setSorterFirstName($sorter['employeeFirstName']); |
| 144 | $QueueItem->setSorterLastName($sorter['employeeLastName']); |
| 145 | } else { |
| 146 | $QueueItem->setSorterFirstName(""); |
| 147 | $QueueItem->setSorterLastName(""); |
| 148 | } |
| 149 | } |
| 150 | $customerAlerts = new \CustomerAlerts($data['customerID'], $this->getTypeNum()); |
| 151 | //buyQueue Table Values |
| 152 | $QueueItem->setBuyID($data["buyID"]); |
| 153 | $QueueItem->setDrsBuyID(isset($data['drsBuyID']) ? $data['drsBuyID'] : null); |
| 154 | $QueueItem->setDailyNum($data["dailyNum"]); |
| 155 | $QueueItem->setTimeEntered($data["timeEntered"]); |
| 156 | $QueueItem->setSortStarted($data["sortStarted"]); |
| 157 | $QueueItem->setSortCompleted($data["sortCompleted"]); |
| 158 | $QueueItem->setTimeStarted($data["timeStarted"]); |
| 159 | $QueueItem->setTimeComplete($data["timeCompleted"]); |
| 160 | $QueueItem->setSorterID($data["sorterID"]); |
| 161 | $QueueItem->setBuyerID($data["buyerID"]); |
| 162 | $QueueItem->setNumContainers($data["numContainers"]); |
| 163 | $QueueItem->setTextMe($data["textMe"]); |
| 164 | $QueueItem->setInStore($data["inStore"]); |
| 165 | $QueueItem->setReturnTime($data["returnTime"]); |
| 166 | $QueueItem->setIsProcessed($data["isProcessed"]); |
| 167 | $QueueItem->setIsReturning($data["isReturning"]); |
| 168 | $QueueItem->setProcessedContainers($data["processedContainers"]); |
| 169 | $QueueItem->setRemainingContainers($data['remainingContainers']); |
| 170 | $QueueItem->setCustomerID($data["customerID"]); |
| 171 | $QueueItem->setDoCount($data["doCount"]); |
| 172 | $QueueItem->setIsNewCustomer($data['isNewCustomer']); |
| 173 | //customer Table Values |
| 174 | $QueueItem->setFirstName($data["firstName"]); |
| 175 | $QueueItem->setLastName($data["lastName"]); |
| 176 | //$QueueItem->setAddress($data["address"]); |
| 177 | //$QueueItem->setCity($data["city"]); |
| 178 | //$QueueItem->setState($data["state"]); |
| 179 | $QueueItem->setPhone($data["phone"]); |
| 180 | //$QueueItem->setZipcode($data["zipcode"]); |
| 181 | $QueueItem->setOnSMS($data["onSMS"]); |
| 182 | $QueueItem->setOnEmail($data["onEmail"]); |
| 183 | //$QueueItem->setDriversLicense($data["driversLicense"]); |
| 184 | $QueueItem->setClearFlags((bool)(int)$data['clearFlags']); |
| 185 | $QueueItem->setAlertsArray($customerAlerts->alertsArray); |
| 186 | if($data['driversLicense'] == "999999999") { |
| 187 | $QueueItem = $this->getRecentBuysByPhoneNum($QueueItem, $data['phone'], $data['buyID']); |
| 188 | } else { |
| 189 | $QueueItem = $this->getRecentBuysByID($QueueItem, $data['driversLicense'], $data['buyID']); |
| 190 | } |
| 191 | if($QueueItem->getHasFlags() == 0 && isset($customerAlerts->alertsArray)) { |
| 192 | $QueueItem->setHasFlags(1); |
| 193 | } |
| 194 | $QueueItem->setRemote($data['remote']); |
| 195 | $QueueItem->setDropOffTime($data['dropOffTime']); |
| 196 | $QueueItem->setHasDroppedOff($data['hasDroppedOff']); |
| 197 | $QueueItem->setUpperBound($data['upperBound']); |
| 198 | $QueueItem->setLowerBound($data['lowerBound']); |
| 199 | $QueueItem->setWaitTime($data['waitTime']); |
| 200 | return $QueueItem; |
| 201 | } |
| 202 | public function setQueueItemLight($data, $db) { |
| 203 | $QueueItemLight = array(); |
| 204 | if(isset($data['buyerID'])) { |
| 205 | $employeeQuery = $db->query("SELECT * FROM employees WHERE employeeID = " . $data["buyerID"]); |
| 206 | if ($employeeQuery) { |
| 207 | $employee = $employeeQuery->fetch(\PDO::FETCH_ASSOC); |
| 208 | $QueueItemLight['buyerFirstName'] = $employee["employeeFirstName"]; |
| 209 | $QueueItemLight['buyerLastName'] = $employee["employeeLastName"]; |
| 210 | } |
| 211 | } |
| 212 | $QueueItemLight['remainingContainers'] = $data['remainingContainers']; |
| 213 | $QueueItemLight['numContainers'] = $data['numContainers']; |
| 214 | $QueueItemLight['processedContainers'] = $data['processedContainers']; |
| 215 | $QueueItemLight['timeEntered'] = $data['timeEntered']; |
| 216 | $QueueItemLight['firstName'] = $data['firstName']; |
| 217 | $QueueItemLight['lastName'] = $data['lastName']; |
| 218 | if($data['timeStarted'] !== '0000-00-00 00:00:00') { |
| 219 | $QueueItemLight['status'] = 3; |
| 220 | } else if($data['sortCompleted'] !== '0000-00-00 00:00:00') { |
| 221 | $QueueItemLight['status'] = 2; |
| 222 | } else if($data['sortStarted'] !== '0000-00-00 00:00:00') { |
| 223 | $QueueItemLight['status'] = 1; |
| 224 | } else { |
| 225 | $QueueItemLight['status'] = 0; |
| 226 | } |
| 227 | return $QueueItemLight; |
| 228 | } |
| 229 | |
| 230 | |
| 231 | public function setCurrentQueue($currentQueue) |
| 232 | { |
| 233 | $this->currentQueue = $currentQueue; |
| 234 | } |
| 235 | |
| 236 | public function getCurrentQueue() |
| 237 | { |
| 238 | return $this->currentQueue; |
| 239 | } |
| 240 | //End getAllCurrentQueueItems |
| 241 | private function getRecentBuysByID(\QueueItem $QueueItem, $driversLicense, $buyID) { |
| 242 | global $buydb_name; |
| 243 | $buysDB = dbConnectByName($buydb_name); |
| 244 | $maxHours = $this->getRecentBuysMaxHours(); |
| 245 | $date = getCurrentDateRange(); |
| 246 | $date['dateStart']->sub(new \DateInterval('PT'.$maxHours.'H')); |
| 247 | $query = "SELECT * FROM systemBuys WHERE driversLicense = '".$driversLicense."' AND timeStamp BETWEEN '".$date['dateStart']->format("Y-m-d H:i:s")."' AND '".$date['dateEnd']->format("Y-m-d H:i:s")."' AND buyID <> ".$buyID." AND origin NOT IN ('pc00','ou00','cm00','se00','pa00') ORDER BY timeStamp DESC"; |
| 248 | $result = $buysDB->query($query); |
| 249 | $fetch = $result->fetchAll(\PDO::FETCH_ASSOC); |
| 250 | $storeController = new \BuyerKiosk\StoreController($this->getTypeNum()); |
| 251 | $store = $storeController->getStore(); |
| 252 | if(is_array($fetch) && count($fetch) > 0) { |
| 253 | $QueueItem->setHasFlags(true); |
| 254 | $QueueItem->setRecentBuys(array()); |
| 255 | foreach($fetch as $row) { |
| 256 | $storeController = new \BuyerKiosk\StoreController($row['origin']); |
| 257 | $store = $storeController->getStore(); |
| 258 | $timeReadable = new \DateTime($row['timeStamp'], new \DateTimeZone('UTC')); |
| 259 | $timeReadable->setTimezone(new \DateTimeZone($this->getTimeZone())); |
| 260 | $tempArray = array( |
| 261 | 'origin' => $row['origin'], |
| 262 | 'timeStamp' => $row['timeStamp'], |
| 263 | 'timeReadable' => $timeReadable->format('m/d g:i A'), |
| 264 | 'customerID' => $row['customerID'], |
| 265 | 'buyID' => $row['buyID'], |
| 266 | 'originCity' => $store->getCity(), |
| 267 | 'originStoreType' => getStoreType($store), |
| 268 | ); |
| 269 | $QueueItem->recentBuys[] = $tempArray; |
| 270 | } |
| 271 | } else { |
| 272 | $QueueItem->hasFlags = false; |
| 273 | $QueueItem->recentBuys = null; |
| 274 | } |
| 275 | return $QueueItem; |
| 276 | } |
| 277 | private function getRecentBuysByPhoneNum(\QueueItem $QueueItem, $phoneNum, $buyID) { |
| 278 | global $buydb_name; |
| 279 | $buysDB = dbConnectByName($buydb_name); |
| 280 | $maxHours = $this->getRecentBuysMaxHours(); |
| 281 | $date = getCurrentDateRange(); |
| 282 | $date['dateStart']->sub(new \DateInterval('PT'.$maxHours.'H')); |
| 283 | $query = "SELECT * FROM systemBuys WHERE phoneNum = '".$phoneNum."' AND timeStamp BETWEEN '".$date['dateStart']->format("Y-m-d H:i:s")."' AND '".$date['dateEnd']->format("Y-m-d H:i:s")."' AND buyID <> ".$buyID." AND origin NOT IN ('ou00','cm00','se00','pa00') ORDER BY timeStamp DESC"; |
| 284 | $result = $buysDB->query($query); |
| 285 | $fetch = $result->fetchAll(\PDO::FETCH_ASSOC); |
| 286 | $store = new \Store(); |
| 287 | $store->createStore($this->getTypeNum()); |
| 288 | if(is_array($fetch) && count($fetch) > 0) { |
| 289 | $QueueItem->setHasFlags(true); |
| 290 | $QueueItem->setRecentBuys(array()); |
| 291 | foreach($fetch as $row) { |
| 292 | $origin = new \Store(); |
| 293 | $origin->createStore($row['origin']); |
| 294 | $timeReadable = new \DateTime($row['timeStamp'], new \DateTimeZone('UTC')); |
| 295 | $timeReadable->setTimezone(new \DateTimeZone($this->getTimeZone())); |
| 296 | $tempArray = array( |
| 297 | 'origin' => $row['origin'], |
| 298 | 'timeStamp' => $row['timeStamp'], |
| 299 | 'timeReadable' => $timeReadable->format('m/d g:i A'), |
| 300 | 'customerID' => $row['customerID'], |
| 301 | 'buyID' => $row['buyID'], |
| 302 | 'originCity' => $origin->getCity(), |
| 303 | 'originStoreType' => getStoreType($origin), |
| 304 | ); |
| 305 | $QueueItem->recentBuys[] = $tempArray; |
| 306 | } |
| 307 | } else { |
| 308 | $QueueItem->hasFlags = false; |
| 309 | $QueueItem->recentBuys = null; |
| 310 | } |
| 311 | return $QueueItem; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | //End Class BuyQueue |