Beispiel #1
0
 public function finalizeCheckout()
 {
     $database = new DB();
     //if the co_id is unset, this is a new checkout
     if (isset($this->co_id)) {
         //old checkout
         $sql = "UPDATE checkouts SET title='{$this->title}', person_id='{$this->person_id}', co_start='{$this->co_start}', co_end='{$this->co_end}', description='{$this->description}', dr_number='{$this->dr_number}', location='{$this->location}' WHERE co_id='{$this->co_id}'";
         $database->query($sql);
         //set return datetime
         if (isset($this->returned)) {
             $sql = "UPDATE checkouts SET returned='{$this->returned}' WHERE co_id='{$this->co_id}'";
             $database->query($sql);
         }
         //remove all old co_gear relations from table
         $sql = "DELETE FROM co_gear WHERE co_id='{$this->co_id}'";
         $database->query($sql);
     } else {
         //new checkout
         //create the new checkout
         $sql = "INSERT INTO checkouts(title,person_id,co_start,co_end,description,dr_number,location) VALUES('{$this->title}','{$this->person_id}','{$this->co_start}','{$this->co_end}','{$this->description}','{$this->dr_number}','{$this->location}')";
         $database->query($sql);
         //retrieve co_id from newly inserted checkout
         $sql = "SELECT co_id FROM checkouts WHERE person_id='{$this->person_id}' AND co_start='{$this->co_start}' AND co_end='{$this->co_end}' AND description='{$this->description}'";
         $results = $database->select($sql);
         $this->co_id = $results[0]['co_id'];
     }
     //add the checkout gear relations
     foreach ($this->gearList as $gearItem) {
         //check to see if the item is available
         $gearObject = new Gear();
         $gearObject->fetch($gearItem[0]);
         if ($gearObject->availableQty($this->co_start, $this->co_end) > 0) {
             $gear_id = $gearItem[0];
             $gearQty = $gearItem[1];
             $sql = "INSERT INTO co_gear(gear_id,co_id,qty) VALUES('{$gear_id}','{$this->co_id}','{$gearQty}')";
             $database->query($sql);
         } else {
             //requested item not available
             //do some error logging here...
         }
     }
     //foreach
 }
Beispiel #2
0
 public static function getAvailableGearWithTypeAndExclusions($type, $co_id, $co_start, $co_end)
 {
     $results = self::getGearListWithType($type);
     if (is_null($co_id)) {
         //do not exclude any checkouts
         foreach ($results as $row) {
             //check if in stock for dates
             $gearObject = new Gear();
             $gearObject->fetch($row['gear_id']);
             if ($gearObject->availableQty($co_start, $co_end) > 0 && !$gearObject->isDisabled()) {
                 //add object to return array if in stock
                 $availableGear[] = $row;
             }
         }
     } else {
         //with exclusions
         foreach ($results as $row) {
             //check if in stock for dates
             $gearObject = new Gear();
             $gearObject->fetch($row['gear_id']);
             if ($gearObject->availableQtyExcludingCheckout($co_id, $co_start, $co_end) > 0 && !$gearObject->isDisabled()) {
                 //add object to return array if in stock
                 $availableGear[] = $row;
             }
         }
     }
     return $availableGear;
 }
Beispiel #3
0
" />
						<?php 
    //make sure gear list is resubmitted
    foreach ($gearList as $gear) {
        echo "<input type='hidden' name='gear[]' value='{$gear}' />";
    }
    //get quantities...
    if (count($gearToGetQtyFor) == 0) {
        echo "<p><strong>There are no items to get quantity for. Click below to finish</strong></p>";
    } else {
        foreach ($gearToGetQtyFor as $gear) {
            $gearObject = new Gear();
            $gearObject->fetch($gear);
            echo $gearObject->getName() . "&nbsp;&nbsp;&nbsp;";
            echo "<select name='gearQty[]'>";
            $qty = $gearObject->availableQty($co_start, $co_end);
            $currQty = $co->qtyOfItem($gearObject->getID());
            for ($i = 1; $i <= $qty; $i++) {
                if ($i == $currQty) {
                    echo "<option value='{$i}' selected='selected'>{$i}</option>";
                } else {
                    echo "<option value='{$i}'>{$i}</option>";
                }
            }
            echo "</select><br /><br />";
        }
    }
    ?>
						<br />
						<input class="btn btn-success" type="submit" name="submit" value="Submit">
					</form>