Skip to content

Commit

Permalink
Inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
o-psi committed Mar 7, 2024
1 parent 0f07759 commit 0987851
Show file tree
Hide file tree
Showing 17 changed files with 942 additions and 20 deletions.
1 change: 1 addition & 0 deletions database_updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,7 @@
`inventory_client_id` int(11) DEFAULT NULL,
`inventory_ticket_id` int(11) DEFAULT NULL,
`inventory_notes` text DEFAULT NULL,
`inventory_vendor_id` int(11) DEFAULT NULL,
`inventory_quantity` int(11) NOT NULL DEFAULT 0,
`inventory_cost` decimal(15,2) NOT NULL DEFAULT 0.00,
`inventory_created_at` datetime NOT NULL DEFAULT current_timestamp(),
Expand Down
44 changes: 30 additions & 14 deletions db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,9 @@ CREATE TABLE `inventory` (
`inventory_product_id` int(11) NOT NULL,
`inventory_location_id` int(11) NOT NULL,
`inventory_client_id` int(11) DEFAULT NULL,
`inventory_ticket_id` int(11) DEFAULT NULL,
`inventory_serial` varchar(200) DEFAULT NULL,
`inventory_barcode` varchar(200) DEFAULT NULL,
`inventory_vendor_id` int(11) NOT NULL,
`inventory_notes` text DEFAULT NULL,
`inventory_quantity` int(11) NOT NULL DEFAULT 0,
`inventory_cost` decimal(15,2) NOT NULL DEFAULT 0.00,
Expand All @@ -692,19 +694,19 @@ DROP TABLE IF EXISTS `inventory_locations`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `inventory_locations` (
`inventory_location_id` int(11) NOT NULL AUTO_INCREMENT,
`inventory_location_name` varchar(200) NOT NULL,
`inventory_location_description` text DEFAULT NULL,
`inventory_location_address` varchar(200) DEFAULT NULL,
`inventory_location_city` varchar(200) DEFAULT NULL,
`inventory_location_state` varchar(200) DEFAULT NULL,
`inventory_location_zip` varchar(200) DEFAULT NULL,
`inventory_location_country` varchar(200) DEFAULT NULL,
`inventory_location_created_at` datetime NOT NULL DEFAULT current_timestamp(),
`inventory_location_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(),
`inventory_location_archived_at` datetime DEFAULT NULL,
`inventory_location_user_id` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`inventory_location_id`)
`inventory_locations_id` int(11) NOT NULL AUTO_INCREMENT,
`inventory_locations_name` varchar(200) NOT NULL,
`inventory_locations_description` text DEFAULT NULL,
`inventory_locations_address` varchar(200) DEFAULT NULL,
`inventory_locations_city` varchar(200) DEFAULT NULL,
`inventory_locations_state` varchar(200) DEFAULT NULL,
`inventory_locations_zip` varchar(200) DEFAULT NULL,
`inventory_locations_country` varchar(200) DEFAULT NULL,
`inventory_locations_created_at` datetime NOT NULL DEFAULT current_timestamp(),
`inventory_locations_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(),
`inventory_locations_archived_at` datetime DEFAULT NULL,
`inventory_locations_user_id` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`inventory_locations_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

Expand Down Expand Up @@ -1551,6 +1553,20 @@ CREATE TABLE `ticket_attachments` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `ticket_products`
--
DROP TABLE IF EXISTS `ticket_products`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ticket_products` (
`ticket_product_id` int(11) NOT NULL AUTO_INCREMENT,
`ticket_product_product_id` int(11) NOT NULL,
`ticket_product_ticket_id` int(11) NOT NULL,
`ticket_product_quantity` int(11) NOT NULL,
PRIMARY KEY (`ticket_product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;

--
-- Table structure for table `ticket_replies`
--
Expand Down
38 changes: 38 additions & 0 deletions expense_add_modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,45 @@
</div>

<div class="form-row">
<div class="form-group col-md">
<label>Product</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-box"></i></span>
</div>
<select class="form-control select2" name="product">
<option value="">- Product (Optional) -</option>
<?php

$sql = mysqli_query($mysqli, "SELECT product_id, product_name FROM products WHERE product_archived_at IS NULL ORDER BY product_name ASC");
while ($row = mysqli_fetch_array($sql)) {
$product_id = intval($row['product_id']);
$product_name = nullable_htmlentities($row['product_name']);
?>
<option value="<?php echo $product_id; ?>"><?php echo $product_name; ?></option>

<?php
}
?>
</select>
<div class="input-group-append">
<a class="btn btn-secondary" href="products.php" target="_blank"><i class="fas fa-fw fa-plus"></i></a>
</div>
</div>
</div>

<div class="form-group col-md">
<label>Quantity</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-calculator"></i></span>
</div>
<input type="text" class="form-control" inputmode="numeric" pattern="[0-9]*\.?[0-9]{0,2}" name="product_quantity" placeholder="0.00">
</div>
</div>
</div>

<div class="form-row">
<div class="form-group col-md">
<label>Category <strong class="text-danger">*</strong></label>
<div class="input-group">
Expand Down
135 changes: 135 additions & 0 deletions inventory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

// Default Column Sortby/Order Filter
$sort = "inventory_created_at";
$order = "DESC";

require_once "inc_all.php";

//Rebuild URL
$url_query_strings_sort = http_build_query($get_copy);

$sql = mysqli_query(
$mysqli,
"SELECT
product_name,
SUM(inventory_quantity) as total_inventory,
inventory_product_id,
GROUP_CONCAT(DISTINCT inventory_locations_name SEPARATOR ', ') AS inventory_locations
FROM inventory
LEFT JOIN inventory_locations ON inventory_locations_id = inventory_location_id
LEFT JOIN products ON inventory_product_id = product_id
LEFT JOIN users on inventory_locations_user_id = user_id
LEFT JOIN vendors ON inventory_vendor_id = vendor_id
GROUP BY inventory_product_id
");

$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));

?>

<div class="card card-dark">
<div class="card-header py-2">
<h3 class="card-title mt-2"><i class="fas fa-fw fa-box mr-2"></i>Inventory</h3>
</div>

<div class="card-body">
<form class="mb-4" autocomplete="off">
<div class="row">
<div class="col-sm-4">
<div class="input-group">
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(nullable_htmlentities($q)); } ?>" placeholder="Search Inventory">
<div class="input-group-append">
<button class="btn btn-secondary" type="button" data-toggle="collapse" data-target="#advancedFilter"><i class="fas fa-filter"></i></button>
<button class="btn btn-primary"><i class="fa fa-search"></i></button>
</div>
</div>
</div>
<div class="col-sm-8">
<div class="btn-group float-right">
<a href="inventory_locations.php" class="btn btn-outline-primary"><i class="fa fa-fw fa-map-marker-alt mr-2"></i>Locations</b></a>
<div class="dropdown ml-2" id="bulkActionButton" hidden>
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown">
<i class="fas fa-fw fa-layer-group mr-2"></i>Bulk Action (<span id="selectedCount">0</span>)
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#bulkEditCategoryModal">
<i class="fas fa-fw fa-list mr-2"></i>Set Category
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#bulkEditAccountModal">
<i class="fas fa-fw fa-piggy-bank mr-2"></i>Set Account
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#bulkEditClientModal">
<i class="fas fa-fw fa-user mr-2"></i>Set Client
</a>
</div>
</div>
</div>
</div>
</div>
</form>
<hr>
<form id="bulkActions" action="post.php" method="post">
<div class="table-responsive-sm">
<table class="table table-striped table-borderless table-hover">
<thead class="text-dark <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
<tr>
<td class="bg-light pr-0">
<div class="form-check">
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" onclick="checkAll(this)">
</div>
</td>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sort; ?>&sort=inventory_date&order=<?php echo $disp; ?>">Product Name</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sort; ?>&sort=vendor_name&order=<?php echo $disp; ?>">Quantity</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sort; ?>&sort=category_name&order=<?php echo $disp; ?>">Locations</a></th>
<th class="text-center">Manage product</th>
</tr>
</thead>
<tbody>
<?php

while ($row = mysqli_fetch_array($sql)) {
$inventory_id = $row['inventory_id'];
$inventory_name = $row['product_name'];
$inventory_quantity = $row['total_inventory'];
$inventory_product_id = $row['inventory_product_id'];
$inventory_locations = $row['inventory_locations'];
?>

<tr>
<td class="bg-light pr-0">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="selected[]" value="<?php echo $inventory_product_id; ?>">
</div>
</td>
<td><?php echo $inventory_name; ?></td>
<td><?php echo $inventory_quantity; ?></td>
<td><?php echo $inventory_locations; ?></td>
<td class="text-center">
<div class="btn-group">
<a href="inventory_manage.php?inventory_product_id=<?php echo $inventory_product_id; ?>" class="btn btn-primary btn-sm"><i class="fas fa-fw fa-edit"></i></a>
</div>
</td>

<?php
}

?>

</tbody>
</table>
</div>

</form>
<?php require_once "pagination.php";
?>
</div>
</div>

<script src="js/bulk_actions.js"></script>

<?php

require_once "footer.php";
45 changes: 45 additions & 0 deletions inventory_edit_item_location_modal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<div class="modal" id="editInventoryLocations<?php echo $inventory_product_id; ?>" tabindex="-1">
<div class="modal-dialog modal-md">
<div class="modal-content bg-dark">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-fw fa-clone mr-2"></i>Move Inventory</h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" id="inventory_product_id" name="inventory_product_id" value="<?php echo $inventory_product_id; ?>">
<input type="hidden" id="inventory_location_id" name="inventory_location_id" value="<?php echo $inventory_location_id; ?>">
<div class="modal-body bg-white">
<div class="form-row">
<div class="form-group">
<label for="inventory_location_id">Move to location</label>
<select class="form-control select2" id="inventory_new_location_id" name="inventory_new_location_id">
<option value="">Select location</option>
<?php
$inventory_locations = mysqli_query($mysqli, "SELECT * FROM inventory_locations WHERE inventory_locations_id != $inventory_location_id");
while ($inventory_location = mysqli_fetch_array($inventory_locations)) {
echo "<option value='" . $inventory_location['inventory_locations_id'] . "'>" . $inventory_location['inventory_locations_name'] . "</option>";
}
?>
</select>
<small>Choose the location to move the inventory to</small>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="inventory_quantity">Quantity</label>
<input type="number" class="form-control" id="inventory_quantity" name="inventory_quantity" value="<?php echo $inventory_quantity; ?>">
<small class="form-text text-muted">Enter the quantity to move</small>
</div>
</div>
</div>
<div class="modal-footer bg-white">
<button type="submit" id="move_inventory_btn" name="move_inventory" class="btn btn-primary text-bold"><i class="fa fa-fw fa-clone mr-2"></i>Move Inventory</button>
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
</div>
</form>
</div>
</div>
</div>

Loading

0 comments on commit 0987851

Please sign in to comment.