diff --git a/app/Controllers/Item_kits.php b/app/Controllers/Item_kits.php index d84b54c3a..64ff433e2 100644 --- a/app/Controllers/Item_kits.php +++ b/app/Controllers/Item_kits.php @@ -153,14 +153,14 @@ class Item_kits extends Secure_Controller public function postSave(int $item_kit_id = NEW_ENTRY): void { $item_kit_data = [ - 'name' => $this->request->getPost('name', FILTER_SANITIZE_FULL_SPECIAL_CHARS), - 'item_kit_number' => $this->request->getPost('item_kit_number', FILTER_SANITIZE_FULL_SPECIAL_CHARS), - 'item_id' => $this->request->getPost('kit_item_id', FILTER_SANITIZE_NUMBER_INT), - 'kit_discount' => $this->request->getPost('kit_discount', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION), - 'kit_discount_type' => $this->request->getPost('kit_discount_type') == NULL ? PERCENT : $this->request->getPost('kit_discount_type', FILTER_SANITIZE_NUMBER_INT), - 'price_option' => $this->request->getPost('price_option', FILTER_SANITIZE_NUMBER_INT), - 'print_option' => $this->request->getPost('print_option', FILTER_SANITIZE_NUMBER_INT), - 'description' => $this->request->getPost('description', FILTER_SANITIZE_FULL_SPECIAL_CHARS) + 'name' => $this->request->getPost('name'), + 'item_kit_number' => $this->request->getPost('item_kit_number'), + 'item_id' => empty($this->request->getPost('kit_item_id')) ? NULL : intval($this->request->getPost('kit_item_id')), + 'kit_discount' => parse_decimals($this->request->getPost('kit_discount')), + 'kit_discount_type' => $this->request->getPost('kit_discount_type') === NULL ? PERCENT : intval($this->request->getPost('kit_discount_type')), + 'price_option' => $this->request->getPost('price_option') === NULL ? PRICE_ALL : intval($this->request->getPost('price_option')), + 'print_option' => $this->request->getPost('print_option') === NULL ? PRINT_ALL : intval($this->request->getPost('print_option')), + 'description' => $this->request->getPost('description') ]; if($this->item_kit->save_value($item_kit_data, $item_kit_id)) @@ -173,22 +173,29 @@ class Item_kits extends Secure_Controller $new_item = TRUE; } - if($this->request->getPost('item_kit_qty', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION) != NULL) + $item_kit_items_array = $this->request->getPost('item_kit_qty') === NULL ? NULL : $this->request->getPost('item_kit_qty'); + + if($item_kit_items_array != NULL) { $item_kit_items = []; - foreach($this->request->getPost('item_kit_qty', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION) as $item_id => $quantity) + foreach($item_kit_items_array as $item_id => $item_kit_qty) { - $seq = $this->request->getPost("item_kit_seq[$item_id]", FILTER_SANITIZE_NUMBER_INT); $item_kit_items[] = [ 'item_id' => $item_id, - 'quantity' => $quantity, - 'kit_sequence' => $seq + 'quantity' => $item_kit_qty === NULL ? 0 : parse_quantity($item_kit_qty), + 'kit_sequence' => $this->request->getPost("item_kit_seq[$item_id]") === NULL ? 0 : intval($this->request->getPost("item_kit_seq[$item_id]")) ]; } - } - $success = $this->item_kit_items->save_value($item_kit_items, $item_kit_id); + if (!empty($item_kit_items)) + { + $success = $this->item_kit_items->save_value($item_kit_items, $item_kit_id); + } + else + { + $success = TRUE; + } if($new_item) { @@ -235,7 +242,7 @@ class Item_kits extends Secure_Controller } } - public function check_item_number(): void + public function postCheckItemNumber(): void { $exists = $this->item_kit->item_number_exists($this->request->getPost('item_kit_number', FILTER_SANITIZE_FULL_SPECIAL_CHARS), $this->request->getPost('item_kit_id', FILTER_SANITIZE_NUMBER_INT)); echo !$exists ? 'true' : 'false'; diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index 72bd5a981..a5f17d615 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -187,9 +187,9 @@ class Items extends Secure_Controller echo json_encode($suggestions); } - public function suggest(): void + public function getSuggest(): void { - $suggestions = $this->item->get_search_suggestions($this->request->getPostGet('term'), ['search_custom' => FALSE, 'is_deleted' => FALSE], TRUE); + $suggestions = $this->item->get_search_suggestions($this->request->getGet('term'), ['search_custom' => FALSE, 'is_deleted' => FALSE], TRUE); echo json_encode($suggestions); } @@ -201,9 +201,9 @@ class Items extends Secure_Controller echo json_encode($suggestions); } - public function suggest_kits(): void + public function getSuggestKits(): void { - $suggestions = $this->item->get_kit_search_suggestions($this->request->getPostGet('term'), ['search_custom' => FALSE, 'is_deleted' => FALSE], TRUE); + $suggestions = $this->item->get_kit_search_suggestions($this->request->getGet('term'), ['search_custom' => FALSE, 'is_deleted' => FALSE], TRUE); echo json_encode($suggestions); } diff --git a/app/Views/item_kits/form.php b/app/Views/item_kits/form.php index bf117cc32..1d2c9f5f3 100644 --- a/app/Views/item_kits/form.php +++ b/app/Views/item_kits/form.php @@ -49,7 +49,7 @@ 'id' => 'item_name', 'class' => 'form-control input-sm', 'size' => '50', - 'value' => esc($selected_kit_item) + 'value' => $selected_kit_item ]) ?> @@ -253,7 +253,7 @@ $(document).ready(function() $('#item_name').autocomplete({ - source: "", + source: "", minChars: 0, delay: 15, cacheLength: 1,