Refactor + fix detailed reports (#68)

This commit is contained in:
jekkos
2018-10-09 08:54:49 +02:00
committed by jekkos
parent 9c5ec71c19
commit fd00a74225
10 changed files with 68 additions and 26 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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;
}, "<?php echo $this->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 && $('<input>').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: "<?php echo $this->lang->line('attributes_definition_name_required'); ?>",
definition_type: "<?php echo $this->lang->line('attributes_definition_type_required'); ?>"
}
}, form_support.error));
});
</script>

View File

@@ -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'");
}
?>
<span class="input-group-addon input-sm btn btn-default remove_attribute_btn"><span class="glyphicon glyphicon-trash"></span></span>

View File

@@ -438,6 +438,10 @@ $(document).ready(function()
})
});
$.validator.addMethod('valid_chars', function(value, element) {
return value.match(/(\||:)/g) == null;
}, "<?php echo $this->lang->line('attributes_attribute_value_invalid_chars'); ?>");
$('#item_form').validate($.extend({
submitHandler: function(form, event) {
$(form).ajaxSubmit({