Changed product cost to product price as it makes more sense, some cleanup on the new product auto complete feature, added JQueryUI as a local asset instead of a remote asset

This commit is contained in:
johnnyq
2022-01-16 15:29:52 -05:00
parent 07223dc2c2
commit 0d306e961e
10 changed files with 54 additions and 42 deletions

View File

@@ -47,8 +47,8 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Cost <strong class="text-danger">*</strong></label> <label>Price <strong class="text-danger">*</strong></label>
<input type="number" step="0.01" min="0" class="form-control" name="cost" placeholder="Cost" required> <input type="number" step="0.01" min="0" class="form-control" name="price" placeholder="Price" required>
</div> </div>
<div class="form-group"> <div class="form-group">

4
db.sql
View File

@@ -722,7 +722,7 @@ CREATE TABLE `products` (
`product_id` int(11) NOT NULL AUTO_INCREMENT, `product_id` int(11) NOT NULL AUTO_INCREMENT,
`product_name` varchar(200) NOT NULL, `product_name` varchar(200) NOT NULL,
`product_description` text DEFAULT NULL, `product_description` text DEFAULT NULL,
`product_cost` decimal(15,2) NOT NULL, `product_price` decimal(15,2) NOT NULL,
`product_currency_code` varchar(200) NOT NULL, `product_currency_code` varchar(200) NOT NULL,
`product_created_at` datetime NOT NULL, `product_created_at` datetime NOT NULL,
`product_updated_at` datetime DEFAULT NULL, `product_updated_at` datetime DEFAULT NULL,
@@ -1217,4 +1217,4 @@ CREATE TABLE `vendors` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-01-12 19:48:54 -- Dump completed on 2022-01-16 15:27:33

View File

@@ -47,8 +47,8 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Cost <strong class="text-danger">*</strong></label> <label>Price <strong class="text-danger">*</strong></label>
<input type="number" step="0.01" min="0" class="form-control" name="cost" value="<?php echo $product_cost; ?>" required> <input type="number" step="0.01" min="0" class="form-control" name="price" value="<?php echo $product_price; ?>" required>
</div> </div>
<div class="form-group"> <div class="form-group">

View File

@@ -0,0 +1 @@
JQuery UI 1.13.0

7
plugins/jquery-ui/jquery-ui.min.css vendored Normal file

File diff suppressed because one or more lines are too long

6
plugins/jquery-ui/jquery-ui.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1787,11 +1787,11 @@ if(isset($_POST['add_product'])){
$name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']))); $name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])));
$description = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']))); $description = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['description'])));
$cost = floatval($_POST['cost']); $price = floatval($_POST['price']);
$category = intval($_POST['category']); $category = intval($_POST['category']);
$tax = intval($_POST['tax']); $tax = intval($_POST['tax']);
mysqli_query($mysqli,"INSERT INTO products SET product_name = '$name', product_description = '$description', product_cost = '$cost', product_currency_code = '$session_company_currency', product_created_at = NOW(), product_tax_id = $tax, product_category_id = $category, company_id = $session_company_id"); mysqli_query($mysqli,"INSERT INTO products SET product_name = '$name', product_description = '$description', product_price = '$price', product_currency_code = '$session_company_currency', product_created_at = NOW(), product_tax_id = $tax, product_category_id = $category, company_id = $session_company_id");
//logging //logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Product', log_action = 'Create', log_description = '$session_name created product $name', log_created_at = NOW(), company_id = $session_company_id, log_user_id = $session_user_id"); mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Product', log_action = 'Create', log_description = '$session_name created product $name', log_created_at = NOW(), company_id = $session_company_id, log_user_id = $session_user_id");
@@ -1807,11 +1807,11 @@ if(isset($_POST['edit_product'])){
$product_id = intval($_POST['product_id']); $product_id = intval($_POST['product_id']);
$name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']))); $name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])));
$description = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']))); $description = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['description'])));
$cost = floatval($_POST['cost']); $price = floatval($_POST['price']);
$category = intval($_POST['category']); $category = intval($_POST['category']);
$tax = intval($_POST['tax']); $tax = intval($_POST['tax']);
mysqli_query($mysqli,"UPDATE products SET product_name = '$name', product_description = '$description', product_cost = '$cost', product_updated_at = NOW(), product_tax_id = $tax, product_category_id = $category WHERE product_id = $product_id AND company_id = $session_company_id"); mysqli_query($mysqli,"UPDATE products SET product_name = '$name', product_description = '$description', product_price = '$price', product_updated_at = NOW(), product_tax_id = $tax, product_category_id = $category WHERE product_id = $product_id AND company_id = $session_company_id");
//Logging //Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Product', log_action = 'Modified', log_description = '$name', log_created_at = NOW(), company_id = $session_company_id, log_user_id = $session_user_id"); mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Product', log_action = 'Modified', log_description = '$name', log_created_at = NOW(), company_id = $session_company_id, log_user_id = $session_user_id");

View File

@@ -41,7 +41,7 @@ $url_query_strings_sb = http_build_query(array_merge($_GET,array('sb' => $sb, 'o
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM products LEFT JOIN categories ON product_category_id = category_id $sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM products LEFT JOIN categories ON product_category_id = category_id
WHERE products.company_id = $session_company_id WHERE products.company_id = $session_company_id
AND (product_name LIKE '%$q%' OR product_description LIKE '%$q%' OR category_name LIKE '%$q%' OR product_cost LIKE '%$q%') AND (product_name LIKE '%$q%' OR product_description LIKE '%$q%' OR category_name LIKE '%$q%' OR product_price LIKE '%$q%')
ORDER BY $sb $o LIMIT $record_from, $record_to"); ORDER BY $sb $o LIMIT $record_from, $record_to");
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
@@ -77,7 +77,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=product_name&o=<?php echo $disp; ?>">Name</a></th> <th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=product_name&o=<?php echo $disp; ?>">Name</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=category_name&o=<?php echo $disp; ?>">Category</a></th> <th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=category_name&o=<?php echo $disp; ?>">Category</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=product_description&o=<?php echo $disp; ?>">Description</a></th> <th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=product_description&o=<?php echo $disp; ?>">Description</a></th>
<th class="text-right"><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=product_cost&o=<?php echo $disp; ?>">Cost</a></th> <th class="text-right"><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=product_price&o=<?php echo $disp; ?>">Price</a></th>
<th class="text-center">Action</th> <th class="text-center">Action</th>
</tr> </tr>
</thead> </thead>
@@ -93,7 +93,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
}else{ }else{
$product_description_display = $product_description; $product_description_display = $product_description;
} }
$product_cost = $row['product_cost']; $product_price = $row['product_price'];
$product_created_at = $row['product_created_at']; $product_created_at = $row['product_created_at'];
$category_id = $row['category_id']; $category_id = $row['category_id'];
$category_name = $row['category_name']; $category_name = $row['category_name'];
@@ -104,7 +104,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
<td><a class="text-dark" href="#" data-toggle="modal" data-target="#editProductModal<?php echo $product_id; ?>"><?php echo $product_name; ?></a></td> <td><a class="text-dark" href="#" data-toggle="modal" data-target="#editProductModal<?php echo $product_id; ?>"><?php echo $product_name; ?></a></td>
<td><?php echo $category_name; ?></td> <td><?php echo $category_name; ?></td>
<td><?php echo $product_description_display; ?></td> <td><?php echo $product_description_display; ?></td>
<td class="text-right"><?php echo get_currency_symbol($session_company_currency); ?> <?php echo number_format($product_cost,2); ?></td> <td class="text-right"><?php echo get_currency_symbol($session_company_currency); ?> <?php echo number_format($product_price,2); ?></td>
<td> <td>
<div class="dropdown dropleft text-center"> <div class="dropdown dropleft text-center">
<button class="btn btn-secondary btn-sm" type="button" data-toggle="dropdown"> <button class="btn btn-secondary btn-sm" type="button" data-toggle="dropdown">

View File

@@ -76,17 +76,16 @@ if(isset($_GET['quote_id'])){
$quote_badge_color = "secondary"; $quote_badge_color = "secondary";
} }
//Product autocomplete //Product autocomplete
$product_sql = mysqli_query($mysqli,"SELECT product_name AS label, product_description AS description, product_cost AS price FROM products $products_sql = mysqli_query($mysqli,"SELECT product_name AS label, product_description AS description, product_price AS price FROM products WHERE company_id = $session_company_id");
WHERE products.company_id = $session_company_id");
if(mysqli_num_rows($product_sql) > 0){ if(mysqli_num_rows($products_sql) > 0){
while($row = mysqli_fetch_array($product_sql)) { while($row = mysqli_fetch_array($products_sql)){
$products[] = $row; $products[] = $row;
} }
$json_products = (json_encode($products)); $json_products = json_encode($products);
} }
?> ?>
<ol class="breadcrumb d-print-none"> <ol class="breadcrumb d-print-none">
@@ -265,10 +264,10 @@ if(mysqli_num_rows($product_sql) > 0){
<td></td> <td></td>
<td><input type="text" class="form-control" name="name" id="name" placeholder="Item" required></td> <td><input type="text" class="form-control" name="name" id="name" placeholder="Item" required></td>
<td><textarea class="form-control" rows="2" name="description" id="desc" placeholder="Description"></textarea></td> <td><textarea class="form-control" rows="2" name="description" id="desc" placeholder="Description"></textarea></td>
<td><input type="number" step="0.01" min="0" class="form-control" style="text-align: center;" name="qty" placeholder="QTY"></td> <td><input type="number" step="0.01" min="0" class="form-control" id="qty" style="text-align: center;" name="qty" placeholder="QTY"></td>
<td><input type="number" step="0.01" min="0" class="form-control" id="price" style="text-align: right;" name="price" placeholder="Price (<?php echo $client_currency_symbol; ?>)"></td> <td><input type="number" step="0.01" min="0" class="form-control" id="price" style="text-align: right;" name="price" placeholder="Price (<?php echo $client_currency_symbol; ?>)"></td>
<td> <td>
<select class="form-control select2" name="tax_id" required> <select class="form-control select2" id="tax" name="tax_id" required>
<option value="0">None</option> <option value="0">None</option>
<?php <?php
@@ -407,9 +406,8 @@ include("footer.php");
<!-- JSON Autocomplete / type ahead --> <!-- JSON Autocomplete / type ahead -->
<!-- //TODO: Not sure quite how to make this more modular to include elsewhere, I'll leave that design decision down to you.. --> <!-- //TODO: Not sure quite how to make this more modular to include elsewhere, I'll leave that design decision down to you.. -->
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.0/themes/base/jquery-ui.css"> <link rel="stylesheet" href="plugins/jquery-ui/jquery-ui.min.css">
<script src="https://code.jquery.com/jquery-3.6.0.js"></script> <script src="plugins/jquery-ui/jquery-ui.min.js"></script>
<script src="https://code.jquery.com/ui/1.13.0/jquery-ui.js"></script>
<script> <script>
$(function(){ $(function(){
var availableProducts = <?php echo $json_products?>; var availableProducts = <?php echo $json_products?>;
@@ -419,6 +417,7 @@ include("footer.php");
select: function (event, ui){ select: function (event, ui){
$("#name").val(ui.item.label); // Product name field - this seemingly has to referenced as label $("#name").val(ui.item.label); // Product name field - this seemingly has to referenced as label
$("#desc").val(ui.item.description); // Product description field $("#desc").val(ui.item.description); // Product description field
$("#qty").val(1); // Product quantity field automatically make it a 1
$("#price").val(ui.item.price); // Product price field $("#price").val(ui.item.price); // Product price field
return false; return false;
} }

View File

@@ -181,7 +181,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
$quote_created_at = $row['quote_created_at']; $quote_created_at = $row['quote_created_at'];
$client_id = $row['client_id']; $client_id = $row['client_id'];
$client_name = htmlentities($row['client_name']); $client_name = htmlentities($row['client_name']);
//$client_email = $row['client_email']; - Commented Jan 2022 - clients database does not include email column
$client_currency_code = $row['client_currency_code']; $client_currency_code = $row['client_currency_code'];
$category_id = $row['category_id']; $category_id = $row['category_id'];
$category_name = $row['category_name']; $category_name = $row['category_name'];