/**
 * edit item form
 * @param $id
 * @param $dbObj
 * @return string
 */
function editItem($id, $dbObj)
{
    $query = "SELECT t1.itemId, t1.name,  t1.image, t2.price, t1.description,\n                            t2.quantity, t3.onsale, t3.salePrice FROM item t1\n                            JOIN inventory t2 ON t1.itemId = t2.itemId\n                            JOIN itemsale t3 ON t2.itemId = t3.itemId WHERE t1.itemId = :itemid";
    $rs = $dbObj->select($query, array(":itemid" => $id));
    $html = "<div class='container'><h2>Edit Item</h2><div class='jumbotron'><form method='POST' action='admin.php'>";
    //save into fields
    foreach ($rs as $result) {
        $obj = new InventoryItem($result);
        $html .= "<label name='id' value='" . $obj->getId() . "'>ID:" . $obj->getId() . "</label><label for='name'>Name: </label>\n                  <br><br><input type='text' name='name' id='name' value='" . $obj->getName() . "'>\n                  <br><br><label for='image'>Image: </label><input type='text' name='image' id='image' value='" . $obj->getImage() . "'>\n                  <br><br><label for='price'>Price: </label><input type='text' name='price' id='price' value='" . $obj->getPrice() . "'>\n                  <br><br><label for='quantity'>Quantity: </label><input type='text' name='quantity' id='quantity' value='" . $obj->getQuantity() . "'>\n                  <br><br><label for='description'>Description: </label><input type='text' name='description' id='description' value='" . $obj->getDescription() . "'>\n                  <br><br><label for='onsale'>On Sale: </label><input type='text' name='onsale' id='onsale' value='" . $obj->getOnSale() . "'>\n                  <br><br><label for='saleprice'>Sale Price: </label><input type='text' name='saleprice' id='saleprice' value='" . $obj->getSalePercent() . "'>";
    }
    $html .= "<br><br><button class='btn btn-primary' name='submit' value='update'>Submit</button></form></div></div>";
    return $html;
}
Пример #2
0
    } else {
        $json["success"] = false;
        $json["message"] = "This item (" . $params["sku"] . ") does not exist in our inventory. Use 'new item' mode when checking an item in to register it.";
    }
    $response->write(json_encode($json));
    return $response->withHeader('Content-type', 'application/json');
});
$app->post('/api/v1/checkout', function ($request, $response, $args) use($app) {
    $params = $request->getParsedBody();
    $json = ["success" => false, "message" => "There was an issue checking out the item (" . $params["sku"] . "). Please contact the tech team!"];
    if (!array_key_exists('identity', $params) || Identity::where('name', $params["identity"])->count() < 1) {
        $json["message"] = "You are not authorized to use the inventory system! Contact your supervisor for access.";
        $response->write(json_encode($json));
        return $response->withHeader('Content-type', 'application/json');
    }
    $item = InventoryItem::where('sku', $params["sku"])->first();
    if ($item && $item->available > 0) {
        $item->checkoutTo($params["identity"]);
        $json["success"] = true;
        $json["message"] = "The item (" . $params["sku"] . ") has been checked out to " . $params["identity"] . " successfully!";
    } elseif ($item) {
        $guardians = $item->currentGuardians();
        $names = [];
        foreach ($guardians as $guardian) {
            $names[$guardian->name] = $guardian->checkout_date;
        }
        $json["message"] = "This item (" . $params["sku"] . ") was not checked back in properly. The following people must check this item back in: " . implode(", ", array_keys($names));
    } else {
        $json["message"] = "This item (" . $params["sku"] . ") does not exist in our inventory. Use 'new item' mode when checking an item in to register it.";
    }
    $response->write(json_encode($json));