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.
This commit is contained in:
Doug Hutcheson
2024-01-09 10:17:04 +08:00
committed by jekkos
parent fba33ed995
commit b36ef3a603
7 changed files with 49 additions and 45 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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']);

View File

@@ -227,8 +227,8 @@
<div class="tab-pane" id="customer_stats_info">
<fieldset>
<div class="form-group form-group-sm">
<?= form_label(lang('Customers.total'), 'total', ['class' => 'control-label col-xs-3']) ?>
<div class="col-xs-4">
<?= form_label(lang('Customers.total'), 'total', ['class' => 'control-label col-xs-5']) ?>
<div class="col-xs-5">
<div class="input-group input-group-sm">
<?php if (!is_right_side_currency_symbol()): ?>
<span class="input-group-addon input-sm"><b><?= esc($config['currency_symbol']) ?></b></span>
@@ -248,8 +248,8 @@
</div>
<div class="form-group form-group-sm">
<?= form_label(lang('Customers.max'), 'max', ['class' => 'control-label col-xs-3']) ?>
<div class="col-xs-4">
<?= form_label(lang('Customers.max'), 'max', ['class' => 'control-label col-xs-5']) ?>
<div class="col-xs-5">
<div class="input-group input-group-sm">
<?php if (!is_right_side_currency_symbol()): ?>
<span class="input-group-addon input-sm"><b><?= esc($config['currency_symbol']) ?></b></span>
@@ -269,8 +269,8 @@
</div>
<div class="form-group form-group-sm">
<?= form_label(lang('Customers.min'), 'min', ['class' => 'control-label col-xs-3']) ?>
<div class="col-xs-4">
<?= form_label(lang('Customers.min'), 'min', ['class' => 'control-label col-xs-5']) ?>
<div class="col-xs-5">
<div class="input-group input-group-sm">
<?php if (!is_right_side_currency_symbol()): ?>
<span class="input-group-addon input-sm"><b><?= esc($config['currency_symbol']) ?></b></span>
@@ -290,8 +290,8 @@
</div>
<div class="form-group form-group-sm">
<?= form_label(lang('Customers.average'), 'average', ['class' => 'control-label col-xs-3']) ?>
<div class="col-xs-4">
<?= form_label(lang('Customers.average'), 'average', ['class' => 'control-label col-xs-5']) ?>
<div class="col-xs-5">
<div class="input-group input-group-sm">
<?php if (!is_right_side_currency_symbol()): ?>
<span class="input-group-addon input-sm"><b><?= esc($config['currency_symbol']) ?></b></span>
@@ -311,9 +311,10 @@
</div>
<div class="form-group form-group-sm">
<?= form_label(lang('Customers.quantity'), 'quantity', ['class' => 'control-label col-xs-3']) ?>
<div class="col-xs-4">
<?= form_label(lang('Customers.quantity'), 'quantity', ['class' => 'control-label col-xs-5']) ?>
<div class="col-xs-5">
<div class="input-group input-group-sm">
<span class="input-group-addon input-sm"><b><?= '>' ?></b></span>
<?= form_input ([
'name' => 'quantity',
'id' => 'quantity',
@@ -326,8 +327,8 @@
</div>
<div class="form-group form-group-sm">
<?= form_label(lang('Customers.avg_discount'), 'avg_discount', ['class' => 'control-label col-xs-3']) ?>
<div class="col-xs-3">
<?= form_label(lang('Customers.avg_discount'), 'avg_discount', ['class' => 'control-label col-xs-5']) ?>
<div class="col-xs-5">
<div class="input-group input-group-sm">
<?= form_input ([
'name' => 'avg_discount',

View File

@@ -11,7 +11,7 @@
<ul id="error_message_box" class="error_message_box"></ul>
<?= form_open('items/bulk_update/', ['id' => 'item_form', 'class' => 'form-horizontal']) ?>
<?= form_open('items/bulkUpdate/', ['id' => 'item_form', 'class' => 'form-horizontal']) ?>
<fieldset id="bulk_item_basic_info">
<div class="form-group form-group-sm">
<?= form_label(lang('Items.name'), 'name', ['class' => 'control-label col-xs-3']) ?>
@@ -172,7 +172,7 @@
$(document).ready(function()
{
$('#category').autocomplete({
source: "<?= 'items/suggest_category' ?>",
source: "<?= 'items/suggestCategory' ?>",
appendTo: '.modal-content',
delay: 10
});

View File

@@ -1,10 +1,10 @@
<ul id="error_message_box" class="error_message_box"></ul>
<?= form_open_multipart('items/import_csv_file/', ['id' => 'csv_form', 'class' => 'form-horizontal']) ?>
<?= form_open_multipart('items/importCsvFile/', ['id' => 'csv_form', 'class' => 'form-horizontal']) ?>
<fieldset id="item_basic_info">
<div class="form-group form-group-sm">
<div class="col-xs-12">
<a href="<?= 'items/generate_csv_file' ?>"><?= lang('Common.download_import_template') ?></a>
<a href="<?= esc('items/generateCsvFile') ?>"><?= lang('Common.download_import_template') ?></a>
</div>
</div>
@@ -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('<?= 'items' ?>', response);
table_support.handle_submit('<?= esc('items') ?>', response);
},
dataType: 'json'
});
},
errorLabelContainer: '#error_message_box',
rules:
rules:
{
file_path: 'required'
},
messages:
messages:
{
file_path: "<?= lang('Common.import_full_path') ?>"
}

View File

@@ -89,7 +89,7 @@ $(document).ready(function()
<button id="delete" class="btn btn-default btn-sm print_hide">
<span class="glyphicon glyphicon-trash">&nbsp;</span><?= lang('Common.delete') ?>
</button>
<button id="bulk_edit" class="btn btn-default btn-sm modal-dlg print_hide" data-btn-submit='<?= lang('Common.submit') ?>' data-href='<?= "$controller_name/bulk_edit" ?>'
<button id="bulk_edit" class="btn btn-default btn-sm modal-dlg print_hide" data-btn-submit='<?= lang('Common.submit') ?>' data-href='<?= "items/bulkEdit" ?>'
title='<?= lang('Items.edit_multiple_items') ?>'>
<span class="glyphicon glyphicon-edit">&nbsp;</span><?= lang('Items.bulk_edit') ?>
</button>