diff --git a/user/ajax/ajax_product_edit.php b/user/ajax/ajax_product_edit.php index cb336a32..44d23539 100644 --- a/user/ajax/ajax_product_edit.php +++ b/user/ajax/ajax_product_edit.php @@ -8,7 +8,10 @@ $sql = mysqli_query($mysqli, "SELECT * FROM products WHERE product_id = $product $row = mysqli_fetch_array($sql); $product_name = nullable_htmlentities($row['product_name']); +$product_type = nullable_htmlentities($row['product_type']); $product_description = nullable_htmlentities($row['product_description']); +$product_code = nullable_htmlentities($row['product_code']); +$product_location = nullable_htmlentities($row['product_location']); $product_price = floatval($row['product_price']); $product_created_at = nullable_htmlentities($row['product_created_at']); $category_id = intval($row['product_category_id']); @@ -19,7 +22,7 @@ ob_start(); ?> + +
+ +
+
+ +
+ +
+
+ +
- + +
+ +
+ +
+
+ +
+ +
diff --git a/user/ajax/ajax_product_stock_add.php b/user/ajax/ajax_product_stock_add.php new file mode 100644 index 00000000..9d54977f --- /dev/null +++ b/user/ajax/ajax_product_stock_add.php @@ -0,0 +1,88 @@ + + + +
+ + + + +
+ + diff --git a/user/post/product.php b/user/post/product.php index 5426b0dc..9ef7f7cb 100644 --- a/user/post/product.php +++ b/user/post/product.php @@ -11,8 +11,9 @@ if (isset($_POST['add_product'])) { enforceUserPermission('module_sales', 2); require_once 'product_model.php'; + $type = sanitizeInput($_POST['type']); - mysqli_query($mysqli,"INSERT INTO products SET product_name = '$name', product_description = '$description', product_price = '$price', product_currency_code = '$session_company_currency', product_tax_id = $tax, product_category_id = $category"); + mysqli_query($mysqli,"INSERT INTO products SET product_name = '$name', product_type = '$type', product_description = '$description', product_code = '$code', product_location = '$location', product_price = '$price', product_currency_code = '$session_company_currency', product_tax_id = $tax, product_category_id = $category"); $product_id = mysqli_insert_id($mysqli); @@ -32,7 +33,7 @@ if (isset($_POST['edit_product'])) { $product_id = intval($_POST['product_id']); - mysqli_query($mysqli,"UPDATE products SET product_name = '$name', product_description = '$description', product_price = '$price', product_tax_id = $tax, product_category_id = $category WHERE product_id = $product_id"); + mysqli_query($mysqli,"UPDATE products SET product_name = '$name', product_description = '$description', product_code = '$code', product_location = '$location', product_price = '$price', product_tax_id = $tax, product_category_id = $category WHERE product_id = $product_id"); logAction("Product", "Edit", "$session_name edited product $name", 0, $product_id); @@ -275,3 +276,25 @@ if (isset($_POST['export_products_csv'])) { exit; } + +if (isset($_POST['add_product_stock'])) { + + enforceUserPermission('module_sales', 2); + + $product_id = intval($_POST['product_id']); + $qty = intval($_POST['qty']); + $expense = intval($_POST['expense']); + $note = sanitizeInput($_POST['note']); + + // Get product name + $product_name = sanitizeInput(getFieldById('products', $product_id, 'product_name')); + + mysqli_query($mysqli,"INSERT INTO product_stock SET stock_qty = $qty, stock_expense_id = $expense, stock_note = '$note', stock_product_id = $product_id"); + + logAction("Product", "Stock", "$session_name added $qty units to stock for product $product_name", 0, $product_id); + + flash_alert("Added $qty units to $product_name stock"); + + redirect(); + +} diff --git a/user/post/product_model.php b/user/post/product_model.php index a9947a0c..86911847 100644 --- a/user/post/product_model.php +++ b/user/post/product_model.php @@ -3,6 +3,8 @@ defined('FROM_POST_HANDLER') || die("Direct file access is not allowed"); $name = sanitizeInput($_POST['name']); $description = sanitizeInput($_POST['description']); +$code = sanitizeInput($_POST['code']); +$location = sanitizeInput($_POST['location']); $price = floatval($_POST['price']); $category = intval($_POST['category']); $tax = intval($_POST['tax']); diff --git a/user/products.php b/user/products.php index 3260f672..720541a5 100644 --- a/user/products.php +++ b/user/products.php @@ -9,6 +9,19 @@ require_once "includes/inc_all.php"; // Perms enforceUserPermission('module_sales'); +// Type Filter +if (isset($_GET['type']) && $_GET['type'] == 'product') { + $type_filter = 'product'; + $type_query = "AND product_type = 'product'"; + $type_display = 'Products'; + $type_icon = "fa-box-open"; +} else { + $type_filter = 'service'; + $type_query = "AND product_type = 'service'"; + $type_display = "Services"; + $type_icon = "fa-wrench"; +} + // Category Filter if (isset($_GET['category']) & !empty($_GET['category'])) { $category_query = 'AND (category_id = ' . intval($_GET['category']) . ')'; @@ -21,14 +34,19 @@ if (isset($_GET['category']) & !empty($_GET['category'])) { $sql = mysqli_query( $mysqli, - "SELECT SQL_CALC_FOUND_ROWS * FROM products + "SELECT SQL_CALC_FOUND_ROWS + products.*, + categories.*, + taxes.*, + COALESCE(SUM(product_stock.stock_qty), 0) AS product_qty + FROM products LEFT JOIN categories ON product_category_id = category_id LEFT JOIN taxes ON product_tax_id = tax_id - WHERE (product_name LIKE '%$q%' OR product_description LIKE '%$q%' OR category_name LIKE '%$q%' OR product_price LIKE '%$q%' OR tax_name LIKE '%$q%' OR tax_percent LIKE '%$q%') + LEFT JOIN product_stock ON product_id = stock_product_id + WHERE (product_name LIKE '%$q%' OR product_description LIKE '%$q%' OR product_code LIKE '%$q%' OR product_location LIKE '%$q%' OR category_name LIKE '%$q%' OR product_price LIKE '%$q%' OR tax_name LIKE '%$q%' OR tax_percent LIKE '%$q%') + $type_query AND product_$archive_query $category_query - - ORDER BY $sort $order LIMIT $record_from, $record_to" ); @@ -38,10 +56,10 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-

Products

+

- +