diff --git a/application/controllers/Items.php b/application/controllers/Items.php index d557b3cef..51bdf61db 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -416,6 +416,10 @@ class Items extends Secure_Controller { $values['selected_value'] = $definition_ids[$definition_id]; } + else + { + $values['selected_value'] = ''; + } unset($data['definition_names'][$definition_id]); } diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index 807ce314e..7fe7760a7 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -1251,7 +1251,7 @@ class Reports extends Secure_Controller { $quantity_purchased .= ' [' . $this->Stock_location->get_location_name($drow['item_location']) . ']'; } - $details_data[$row['sale_id']][] = $this->xss_clean(array_merge(array( + $details_data[$row['sale_id']][] = $this->xss_clean(array( $drow['name'], $drow['category'], $drow['serialnumber'], @@ -1262,8 +1262,11 @@ class Reports extends Secure_Controller to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), - ($drow['discount_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount'])), - explode('|', (isset($drow['attribute_values'])) ? $drow['attribute_values'] : ""))); + ($drow['discount_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount']))); + + $attribute_values = (isset($drow['attribute_values'])) ? $drow['attribute_values'] : ''; + append_attribute_values($details_data[$row['sale_id']][0], $definition_names, $attribute_values); + $details_data[$row['sale_id']][0] = array_values($details_data[$row['sale_id']][0]); } if(isset($report_data['rewards'][$key])) @@ -1364,14 +1367,17 @@ class Reports extends Secure_Controller { $quantity_purchased .= ' [' . $this->Stock_location->get_location_name($drow['item_location']) . ']'; } - $details_data[$row['receiving_id']][] = $this->xss_clean(array_merge(array( + $details_data[$row['receiving_id']][] = $this->xss_clean(array( $drow['item_number'], $drow['name'], $drow['category'], $quantity_purchased, to_currency($drow['total']), - ($drow['discount_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount'])), - explode('|', (isset($drow['attribute_values'])) ? $drow['attribute_values'] : ""))); + ($drow['discount_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount']))); + + $attribute_values = (isset($drow['attribute_values'])) ? $drow['attribute_values'] : ''; + append_attribute_values($details_data[$row['receiving_id']][0], $definition_names, $attribute_values); + $details_data[$row['receiving_id']][0] = array_values($details_data[$row['receiving_id']][0]); } } diff --git a/application/helpers/tabular_helper.php b/application/helpers/tabular_helper.php index eb98d15e4..ebd24ced8 100644 --- a/application/helpers/tabular_helper.php +++ b/application/helpers/tabular_helper.php @@ -411,19 +411,8 @@ function get_item_data_row($item) array('class' => 'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title' => $CI->lang->line($controller_name.'_update')) )); - $attribute_values = explode('|', (property_exists($item, 'attribute_values')) ? $item->attribute_values : ""); - - $indexed_values = array(); - foreach($attribute_values as $attribute_value) - { - $exploded_value = explode(':', $attribute_value); - $indexed_values[$exploded_value[0]] = isset($exploded_value[1]) ? $exploded_value[1] : ''; - } - - foreach($definition_names as $definition_id => $definition_name) - { - $result[$definition_id] = isset($indexed_values[$definition_id]) ? $indexed_values[$definition_id] : ''; - } + $attribute_values = (property_exists($item, 'attribute_values')) ? $item->attribute_values : ""; + append_attribute_values($result, $definition_names, $attribute_values); return $result; } @@ -548,6 +537,24 @@ function get_item_kit_data_row($item_kit) )); } +function append_attribute_values(&$result, $definition_names, $attribute_values) +{ + $values = explode('|', $attribute_values); + + $indexed_values = array(); + foreach($values as $attribute_value) + { + $exploded_value = explode(':', $attribute_value); + $indexed_values[$exploded_value[0]] = isset($exploded_value[1]) ? $exploded_value[1] : '-'; + } + + foreach($definition_names as $definition_id => $definition_name) + { + $attribute_value = isset($indexed_values[$definition_id]) ? $indexed_values[$definition_id] : '-'; + $result[$definition_id] = $attribute_value; + } +} + function get_attribute_definition_manage_table_headers() { $CI =& get_instance(); diff --git a/application/language/en-GB/attributes_lang.php b/application/language/en-GB/attributes_lang.php index 59cc84a02..0da58a38f 100644 --- a/application/language/en-GB/attributes_lang.php +++ b/application/language/en-GB/attributes_lang.php @@ -5,7 +5,7 @@ $lang["attributes_definition_cannot_be_deleted"] = "Could not delete selected at $lang["attributes_definition_flags"] = "Attribute Visibility"; $lang["attributes_definition_group"] = "Group"; $lang["attributes_definition_id"] = "Id"; -$lang["attributes_definition_name"] = "Add Attribute"; +$lang["attributes_definition_name"] = "Attribute Name"; $lang["attributes_definition_one_or_multiple"] = "attribute(s)"; $lang["attributes_definition_successful_adding"] = "You have successfully added item"; $lang["attributes_definition_successful_deleted"] = "You have successfully deleted"; @@ -23,3 +23,6 @@ $lang["attributes_show_in_receivings_visibility"] = "Receivings"; $lang["attributes_show_in_sales"] = "Show in sales"; $lang["attributes_show_in_sales_visibility"] = "Sales"; $lang["attributes_update"] = "Update Attribute"; +$lang["attributes_definition_name_required"] = "Attribute name is a required field"; +$lang["attributes_definition_type_required"] = "Attriubte type is a required field"; +$lang["attributes_attribute_value_invalid_chars"] = "Attribute value cannot contain ':' or '|'"; diff --git a/application/language/en-US/attributes_lang.php b/application/language/en-US/attributes_lang.php index 59cc84a02..2d3c4bf84 100644 --- a/application/language/en-US/attributes_lang.php +++ b/application/language/en-US/attributes_lang.php @@ -5,7 +5,7 @@ $lang["attributes_definition_cannot_be_deleted"] = "Could not delete selected at $lang["attributes_definition_flags"] = "Attribute Visibility"; $lang["attributes_definition_group"] = "Group"; $lang["attributes_definition_id"] = "Id"; -$lang["attributes_definition_name"] = "Add Attribute"; +$lang["attributes_definition_name"] = "Attribute Name"; $lang["attributes_definition_one_or_multiple"] = "attribute(s)"; $lang["attributes_definition_successful_adding"] = "You have successfully added item"; $lang["attributes_definition_successful_deleted"] = "You have successfully deleted"; @@ -23,3 +23,6 @@ $lang["attributes_show_in_receivings_visibility"] = "Receivings"; $lang["attributes_show_in_sales"] = "Show in sales"; $lang["attributes_show_in_sales_visibility"] = "Sales"; $lang["attributes_update"] = "Update Attribute"; +$lang["attributes_definition_name_required"] = "Attribute name is a required field"; +$lang["attributes_definition_type_required"] = "Attriubte type is a required field"; +$lang["attributes_attribute_value_invalid_chars"] = "Attribute value cannot contain ':' or '|'"; \ No newline at end of file diff --git a/application/models/reports/Detailed_receivings.php b/application/models/reports/Detailed_receivings.php index 261cbff61..c2f3f795b 100644 --- a/application/models/reports/Detailed_receivings.php +++ b/application/models/reports/Detailed_receivings.php @@ -102,7 +102,7 @@ class Detailed_receivings extends Report $this->db->join('items', 'receivings_items_temp.item_id = items.item_id'); if (count($inputs['definition_ids']) > 0) { - $this->db->select('GROUP_CONCAT(DISTINCT IFNULL(attribute_value, \'-\') ORDER BY definition_id SEPARATOR \'|\') AS attribute_values'); + $this->db->select('GROUP_CONCAT(DISTINCT CONCAT_WS(\':\', definition_id, attribute_value) ORDER BY definition_id SEPARATOR \'|\') AS attribute_values'); $this->db->join('attribute_links', 'attribute_links.item_id = items.item_id AND attribute_links.receiving_id = receivings_items_temp.receiving_id AND definition_id IN (' . implode(',', $inputs['definition_ids']) . ')', 'left'); $this->db->join('attribute_values', 'attribute_values.attribute_id = attribute_links.attribute_id', 'left'); $this->db->group_by('receivings_items_temp.receiving_id, receivings_items_temp.item_id'); diff --git a/application/models/reports/Detailed_sales.php b/application/models/reports/Detailed_sales.php index e3caff0b2..a63655fa1 100644 --- a/application/models/reports/Detailed_sales.php +++ b/application/models/reports/Detailed_sales.php @@ -148,7 +148,7 @@ class Detailed_sales extends Report $this->db->from('sales_items_temp'); if (count($inputs['definition_ids']) > 0) { - $this->db->select('GROUP_CONCAT(DISTINCT IFNULL(attribute_value, \'-\') ORDER BY definition_id SEPARATOR \'|\') AS attribute_values'); + $this->db->select('GROUP_CONCAT(DISTINCT CONCAT_WS(\':\', definition_id, attribute_value) ORDER BY definition_id SEPARATOR \'|\') AS attribute_values'); $this->db->join('attribute_links', 'attribute_links.item_id = sales_items_temp.item_id AND attribute_links.sale_id = sales_items_temp.sale_id AND definition_id IN (' . implode(',', $inputs['definition_ids']) . ')', 'left'); $this->db->join('attribute_values', 'attribute_values.attribute_id = attribute_links.attribute_id', 'left'); $this->db->group_by('sales_items_temp.sale_id, sales_items_temp.item_id'); diff --git a/application/views/attributes/form.php b/application/views/attributes/form.php index 0562e8b77..e092d3143 100644 --- a/application/views/attributes/form.php +++ b/application/views/attributes/form.php @@ -104,6 +104,11 @@ $(document).ready(function() { var is_event = typeof(value) !== 'string'; + if (!$('#attribute_form').valid()) + { + return; + } + if (is_event) { value = $('#definition_value').val(); @@ -142,12 +147,16 @@ $(document).ready(function() add_attribute_value(element); }); + $.validator.addMethod('valid_chars', function(value, element) { + return value.match(/(\||:)/g) == null; + }, "lang->line('attributes_attribute_value_invalid_chars'); ?>"); + $('#attribute_form').validate($.extend({ submitHandler: function(form) { $(form).ajaxSubmit({ beforeSerialize: function($form, options) { - $("select[disabled='disabled']").removeAttr('disabled'); + $("select").removeAttr('disabled'); is_new && $('').attr({ id: 'definition_values', type: 'hidden', @@ -166,8 +175,14 @@ $(document).ready(function() rules: { definition_name: 'required', + definition_value: 'valid_chars', definition_type: 'required' - } + }, + messages: + { + definition_name: "lang->line('attributes_definition_name_required'); ?>", + definition_type: "lang->line('attributes_definition_type_required'); ?>" + } }, form_support.error)); }); diff --git a/application/views/attributes/item.php b/application/views/attributes/item.php index 7be6db019..7d42fff7f 100644 --- a/application/views/attributes/item.php +++ b/application/views/attributes/item.php @@ -39,7 +39,7 @@ foreach($definition_values as $definition_id => $definition_value) else if ($definition_value['definition_type'] == TEXT) { $value = (empty($attribute_value) || empty($attribute_value->attribute_value)) ? $definition_value['selected_value'] : $attribute_value->attribute_value; - echo form_input("attribute_links[$definition_id]", $value, "class='form-control' data-definition-id='$definition_id'"); + echo form_input("attribute_links[$definition_id]", $value, "class='form-control valid_chars' data-definition-id='$definition_id'"); } ?> diff --git a/application/views/items/form.php b/application/views/items/form.php index fd16a9a97..ca7bf739b 100644 --- a/application/views/items/form.php +++ b/application/views/items/form.php @@ -438,6 +438,10 @@ $(document).ready(function() }) }); + $.validator.addMethod('valid_chars', function(value, element) { + return value.match(/(\||:)/g) == null; + }, "lang->line('attributes_attribute_value_invalid_chars'); ?>"); + $('#item_form').validate($.extend({ submitHandler: function(form, event) { $(form).ajaxSubmit({