Fix datetime attribute formatting (#2232)

This commit is contained in:
jekkos
2019-01-25 09:06:51 +01:00
parent d47099fa23
commit f2d2b1d3e2
5 changed files with 60 additions and 27 deletions

View File

@@ -457,6 +457,50 @@ function dateformat_momentjs($php_format)
return strtr($php_format, $SYMBOLS_MATCHING);
}
function dateformat_mysql()
{
$config = get_instance()->config;
$php_format = $config->item('dateformat') . ' ' . $config->item('timeformat');
$SYMBOLS_MATCHING = array(
// Day
'd' => '%d',
'D' => '%a',
'j' => '%e',
'l' => '%W',
'N' => '',
'S' => '',
'w' => '',
'z' => '',
// Week
'W' => '',
// Month
'F' => '',
'm' => '%m',
'M' => '%b',
'n' => '%c',
't' => '',
// Year
'L' => '',
'o' => '',
'Y' => '%Y',
'y' => '%y',
// Time
'a' => '',
'A' => '%p',
'B' => '',
'g' => '%l',
'G' => '%k',
'h' => '',
'H' => '%k',
'i' => '%i',
's' => '%S',
'u' => '%f'
);
return strtr($php_format, $SYMBOLS_MATCHING);
}
function dateformat_bootstrap($php_format)
{
$SYMBOLS_MATCHING = array(

View File

@@ -90,7 +90,7 @@ function get_sale_data_row($sale)
$row = array (
'sale_id' => $sale->sale_id,
'sale_time' => date($CI->config->item('dateformat') . ' ' . $CI->config->item('timeformat'), strtotime($sale->sale_time)),
'sale_time' => to_datetime(strtotime($sale->sale_time)),
'customer_name' => $sale->customer_name,
'amount_due' => to_currency($sale->amount_due),
'amount_tendered' => to_currency($sale->amount_tendered),
@@ -444,6 +444,7 @@ function get_item_data_row($item)
);
$attribute_values = (property_exists($item, 'attribute_values')) ? $item->attribute_values : "";
$attribute_values = (property_exists($item, 'attribute_datetimevalues')) ? $item->attribute_datetimevalues : $attribute_values;
return $columns + expand_attribute_values($definition_names, $attribute_values) + $icons;
}
@@ -529,7 +530,7 @@ function expand_attribute_values($definition_names, $attribute_values)
$indexed_values = array();
foreach($values as $attribute_value)
{
$exploded_value = explode(':', $attribute_value);
$exploded_value = explode('_', $attribute_value);
$indexed_values[$exploded_value[0]] = isset($exploded_value[1]) ? $exploded_value[1] : '-';
}
@@ -651,7 +652,7 @@ function get_expenses_data_row($expense)
$controller_name = strtolower(get_class($CI));
return array (
'expense_id' => $expense->expense_id,
'date' => date($CI->config->item('dateformat') . ' ' . $CI->config->item('timeformat'), strtotime($expense->date)),
'date' => to_datetime(strtotime($expense->date)),
'supplier_name' => $expense->supplier_name,
'supplier_tax_code' => $expense->supplier_tax_code,
'amount' => to_currency($expense->amount),
@@ -742,11 +743,11 @@ function get_cash_up_data_row($cash_up)
$controller_name = strtolower(get_class($CI));
return array (
'cashup_id' => $cash_up->cashup_id,
'open_date' => date($CI->config->item('dateformat') . ' ' . $CI->config->item('timeformat'), strtotime($cash_up->open_date)),
'open_date' => to_datetime(strtotime($cash_up->open_date)),
'open_employee_id' => $cash_up->open_first_name . ' ' . $cash_up->open_last_name,
'open_amount_cash' => to_currency($cash_up->open_amount_cash),
'transfer_amount_cash' => to_currency($cash_up->transfer_amount_cash),
'close_date' => date($CI->config->item('dateformat') . ' ' . $CI->config->item('timeformat'), strtotime($cash_up->close_date)),
'close_date' => to_datetime(strtotime($cash_up->close_date)),
'close_employee_id' => $cash_up->close_first_name . ' ' . $cash_up->close_last_name,
'closed_amount_cash' => to_currency($cash_up->closed_amount_cash),
'note' => $cash_up->note ? '<span class="glyphicon glyphicon-ok"></span>' : '<span class="glyphicon glyphicon-remove"></span>',

View File

@@ -105,9 +105,9 @@ class Attribute extends CI_Model
*/
public function search($search, $rows = 0, $limit_from = 0, $sort = 'definition.definition_name', $order = 'asc')
{
$this->db->select('definition_group.definition_name AS definition_group, definition.*');
$this->db->select('parent_definition.definition_name AS definition_group, definition.*');
$this->db->from('attribute_definitions AS definition');
$this->db->join('attribute_definitions AS definition_group', 'definition_group.definition_id = definition.definition_fk', 'left');
$this->db->join('attribute_definitions AS parent_definition', 'parent_definition.definition_id = definition.definition_fk', 'left');
$this->db->group_start();
$this->db->like('definition.definition_name', $search);
@@ -452,7 +452,9 @@ class Attribute extends CI_Model
public function get_link_values($item_id, $sale_receiving_fk, $id, $definition_flags)
{
$this->db->select('GROUP_CONCAT(attribute_value SEPARATOR ", ") AS attribute_values, GROUP_CONCAT(attribute_datetime SEPARATOR ", ") AS attribute_datetimevalues');
$format = $this->db->escape(dateformat_mysql());
$this->db->select('GROUP_CONCAT(attribute_value SEPARATOR ', ') AS attribute_values');
$this->db->select("GROUP_CONCAT(DATE_FORMAT(attribute_datetime, $format) SEPARATOR ', ') AS attribute_datetimevalues");
$this->db->from('attribute_links');
$this->db->join('attribute_values', 'attribute_values.attribute_id = attribute_links.attribute_id');
$this->db->join('attribute_definitions', 'attribute_definitions.definition_id = attribute_links.definition_id');
@@ -471,23 +473,7 @@ class Attribute extends CI_Model
$this->db->where('item_id', (int) $item_id);
$this->db->where('definition_flags & ', $definition_flags);
$results = $this->db->get();
if ($results->num_rows() > 0)
{
$row_object = $results->row_object();
$datetime_values = explode(', ', $row_object->attribute_datetimevalues);
$attribute_values = array();
foreach (array_filter($datetime_values) as $datetime_value)
{
$attribute_values[] = to_datetime(strtotime($datetime_value));
}
return implode(',', $attribute_values) . $row_object->attribute_values;
}
return "";
return $this->db->get();
}
public function get_attribute_value($item_id, $definition_id)

View File

@@ -192,7 +192,9 @@ class Item extends CI_Model
if ($attributes_enabled)
{
$this->db->select('GROUP_CONCAT(DISTINCT CONCAT_WS(\':\', definition_id, attribute_value) ORDER BY definition_id SEPARATOR \'|\') AS attribute_values');
$format = $this->db->escape(dateformat_mysql());
$this->db->select('GROUP_CONCAT(DISTINCT CONCAT_WS(\'_\', definition_id, attribute_value) ORDER BY definition_id SEPARATOR \'|\') AS attribute_values');
$this->db->select("GROUP_CONCAT(DISTINCT CONCAT_WS('_', definition_id, DATE_FORMAT(attribute_datetime, $format)) SEPARATOR '|') AS attribute_datetimevalues");
$this->db->join('attribute_links', 'attribute_links.item_id = items.item_id AND attribute_links.receiving_id IS NULL AND attribute_links.sale_id IS NULL AND definition_id IN (' . implode(',', $filters['definition_ids']) . ')', 'left');
$this->db->join('attribute_values', 'attribute_values.attribute_id = attribute_links.attribute_id', 'left');
}

View File

@@ -181,7 +181,7 @@ $(document).ready(function()
});
$.validator.addMethod('valid_chars', function(value, element) {
return value.match(/(\||:)/g) == null;
return value.match(/(\||_)/g) == null;
}, "<?php echo $this->lang->line('attributes_attribute_value_invalid_chars'); ?>");
$('#attribute_form').validate($.extend({