From b36ef3a6035c06cbb9d2fdba9e1d1df68068001f Mon Sep 17 00:00:00 2001 From: Doug Hutcheson Date: Tue, 9 Jan 2024 10:17:04 +0800 Subject: [PATCH] ci4-bugfix to items customers and attributes Attributes: Noticed log_message() being called with uppercase letters in the level which causes errors in the system; Customers: improved the layout of the stats page in the information dialog issue 3892; Items: got csv import working issue 3896 and bulk edits working - barcode generation does not work yet. --- app/Controllers/Items.php | 39 ++++++++++++++++------------- app/Models/Attribute.php | 4 +-- app/Models/Item.php | 6 ++--- app/Views/customers/form.php | 25 +++++++++--------- app/Views/items/form_bulk.php | 4 +-- app/Views/items/form_csv_import.php | 14 +++++------ app/Views/items/manage.php | 2 +- 7 files changed, 49 insertions(+), 45 deletions(-) diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index a5d1636b5..43d03d1d9 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -16,6 +16,7 @@ use App\Models\Supplier; use App\Models\Tax_category; use CodeIgniter\Images\Handlers\BaseHandler; +use CodeIgniter\HTTP\DownloadResponse; use Config\OSPOS; use Config\Services; use ReflectionException; @@ -599,7 +600,7 @@ class Items extends Secure_Controller /** * @return void */ - public function bulk_edit(): void //TODO: This function may not be called in the code. Need to confirm + public function getBulkEdit(): void //TODO: This function may not be called in the code. Need to confirm { $suppliers = ['' => lang('Items.none')]; @@ -939,7 +940,7 @@ class Items extends Secure_Controller * @return void * @noinspection PhpUnused */ - public function bulk_update(): void + public function postBulkUpdate(): void { $items_to_update = $this->request->getPost('item_ids'); $item_data = []; @@ -1010,14 +1011,15 @@ class Items extends Secure_Controller * @return void * @noinspection PhpUnused */ - public function generate_csv_file(): void + public function getGenerateCsvFile(): DownloadResponse { + helper('importfile_helper'); $name = 'import_items.csv'; $allowed_locations = $this->stock_location->get_allowed_locations(); - $allowed_attributes = $this->attribute->get_definition_names(false); + $allowed_attributes = $this->attribute->get_definition_names(); $data = generate_import_items_csv($allowed_locations, $allowed_attributes); - $this->response->download($name, $data); + return $this->response->download($name, $data); } /** @@ -1034,8 +1036,9 @@ class Items extends Secure_Controller * @throws ReflectionException * @noinspection PhpUnused */ - public function import_csv_file(): void + public function postImportCsvFile(): void { + helper('importfile_helper'); if($_FILES['file_path']['error'] !== UPLOAD_ERR_OK) { echo json_encode (['success' => false, 'message' => lang('Items.csv_import_failed')]); @@ -1071,8 +1074,8 @@ class Items extends Secure_Controller foreach($csv_rows as $key => $row) { $is_failed_row = false; - $item_id = $row['Id']; - $is_update = !empty($item_id); + $item_id = (int)$row['Id']; + $is_update = ($item_id > 0); $item_data = [ 'item_id' => $item_id, 'name' => $row['Item Name'], @@ -1131,7 +1134,7 @@ class Items extends Secure_Controller { $failed_row = $key+2; $failCodes[] = $failed_row; - log_message('ERROR',"CSV Item import failed on line $failed_row. This item was not imported."); + log_message('error',"CSV Item import failed on line $failed_row. This item was not imported."); } unset($csv_rows[$key]); @@ -1185,7 +1188,7 @@ class Items extends Secure_Controller { if (empty($val) && !$is_update) { - log_message('Error',"Empty required value in $key."); + log_message('error',"Empty required value in $key."); return true; } } @@ -1198,7 +1201,7 @@ class Items extends Secure_Controller { if(!$this->item->exists($item_id)) { - log_message('Error',"non-existent item_id: '$item_id' when either existing item_id or no item_id is required."); + log_message('error',"non-existent item_id: '$item_id' when either existing item_id or no item_id is required."); return true; } } @@ -1208,22 +1211,22 @@ class Items extends Secure_Controller 'cost_price' => $item_data['cost_price'], 'unit_price' => $item_data['unit_price'], 'reorder_level' => $item_data['reorder_level'], - 'supplier_id' => $item_data['supplier_id'], + 'supplier_id' => $row['Supplier ID'], 'Tax 1 Percent' => $row['Tax 1 Percent'], 'Tax 2 Percent' => $row['Tax 2 Percent'] ]; - foreach($allowed_locations as $location_name) +/* foreach($allowed_locations as $location_name) { $check_for_numeric_values[] = $row["location_$location_name"]; } - + */ //Check for non-numeric values which require numeric foreach($check_for_numeric_values as $key => $value) { if(!is_numeric($value) && !empty($value)) { - log_message('Error',"non-numeric: '$value' for '$key' when numeric is required"); + log_message('error',"non-numeric: '$value' for '$key' when numeric is required"); return true; } } @@ -1244,21 +1247,21 @@ class Items extends Secure_Controller if(!empty($attribute_value) && !in_array($attribute_value, $dropdown_values)) { - log_message('Error',"Value: '$attribute_value' is not an acceptable DROPDOWN value"); + log_message('error',"Value: '$attribute_value' is not an acceptable DROPDOWN value"); return true; } break; case DECIMAL: if(!is_numeric($attribute_value) && !empty($attribute_value)) { - log_message('Error',"'$attribute_value' is not an acceptable DECIMAL value"); + log_message('error',"'$attribute_value' is not an acceptable DECIMAL value"); return true; } break; case DATE: if(!valid_date($attribute_value) && !empty($attribute_value)) { - log_message('Error',"'$attribute_value' is not an acceptable DATE value. The value must match the set locale."); + log_message('error',"'$attribute_value' is not an acceptable DATE value. The value must match the set locale."); return true; } break; diff --git a/app/Models/Attribute.php b/app/Models/Attribute.php index 4b1d2f897..01371857d 100644 --- a/app/Models/Attribute.php +++ b/app/Models/Attribute.php @@ -393,7 +393,7 @@ class Attribute extends Model $affected_items[] = $affected_item['item_id']; } - log_message('ERROR', "Attribute_value: '$attribute->attribute_value' cannot be converted to $to. Affected Items: ". implode(',', $affected_items)); + log_message('error', "Attribute_value: '$attribute->attribute_value' cannot be converted to $to. Affected Items: ". implode(',', $affected_items)); unset($affected_items); } } @@ -1028,7 +1028,7 @@ class Attribute extends Model if(!$this->save_link($attribute['item_id'], $definition_id, $new_attribute_id)) { - log_message('Error', 'Transaction failed'); + log_message('error', 'Transaction failed'); $this->db->transRollback(); return false; } diff --git a/app/Models/Item.php b/app/Models/Item.php index 943876a1e..35c31179f 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -469,12 +469,12 @@ class Item extends Model { $builder = $this->db->table('items'); - if($item_id == NEW_ENTRY || !$this->exists($item_id, true)) + if($item_id < 1 || !$this->exists($item_id, true)) { if($builder->insert($item_data)) { - $item_data['item_id'] = $this->db->insertID(); - if($item_data['low_sell_item_id'] == NEW_ENTRY) + $item_data['item_id'] = (int)$this->db->insertID(); + if($item_id < 1) { $builder = $this->db->table('items'); $builder->where('item_id', $item_data['item_id']); diff --git a/app/Views/customers/form.php b/app/Views/customers/form.php index d97b04dfa..04f060286 100644 --- a/app/Views/customers/form.php +++ b/app/Views/customers/form.php @@ -227,8 +227,8 @@
- 'control-label col-xs-3']) ?> -
+ 'control-label col-xs-5']) ?> +
@@ -248,8 +248,8 @@
- 'control-label col-xs-3']) ?> -
+ 'control-label col-xs-5']) ?> +
@@ -269,8 +269,8 @@
- 'control-label col-xs-3']) ?> -
+ 'control-label col-xs-5']) ?> +
@@ -290,8 +290,8 @@
- 'control-label col-xs-3']) ?> -
+ 'control-label col-xs-5']) ?> +
@@ -311,9 +311,10 @@
- 'control-label col-xs-3']) ?> -
+ 'control-label col-xs-5']) ?> +
+ ' ?> 'quantity', 'id' => 'quantity', @@ -326,8 +327,8 @@
- 'control-label col-xs-3']) ?> -
+ 'control-label col-xs-5']) ?> +
'avg_discount', diff --git a/app/Views/items/form_bulk.php b/app/Views/items/form_bulk.php index fd475024f..eaa22f222 100644 --- a/app/Views/items/form_bulk.php +++ b/app/Views/items/form_bulk.php @@ -11,7 +11,7 @@
    - 'item_form', 'class' => 'form-horizontal']) ?> + 'item_form', 'class' => 'form-horizontal']) ?>
    'control-label col-xs-3']) ?> @@ -172,7 +172,7 @@ $(document).ready(function() { $('#category').autocomplete({ - source: "", + source: "", appendTo: '.modal-content', delay: 10 }); diff --git a/app/Views/items/form_csv_import.php b/app/Views/items/form_csv_import.php index 52cf77d8b..5512b8772 100644 --- a/app/Views/items/form_csv_import.php +++ b/app/Views/items/form_csv_import.php @@ -1,10 +1,10 @@
      - 'csv_form', 'class' => 'form-horizontal']) ?> + 'csv_form', 'class' => 'form-horizontal']) ?>
      - +
      @@ -27,23 +27,23 @@ $(document).ready(function() $('#csv_form').validate($.extend({ submitHandler: function(form) { $(form).ajaxSubmit({ - success:function(response) + success: function(response) { dialog_support.hide(); - table_support.handle_submit('', response); + table_support.handle_submit('', response); }, dataType: 'json' }); }, errorLabelContainer: '#error_message_box', - - rules: + + rules: { file_path: 'required' }, - messages: + messages: { file_path: "" } diff --git a/app/Views/items/manage.php b/app/Views/items/manage.php index d9fe2f3ad..9de1d0528 100644 --- a/app/Views/items/manage.php +++ b/app/Views/items/manage.php @@ -89,7 +89,7 @@ $(document).ready(function() -