diff --git a/application/controllers/Attributes.php b/application/controllers/Attributes.php index 209209517..ac07bb637 100644 --- a/application/controllers/Attributes.php +++ b/application/controllers/Attributes.php @@ -67,11 +67,17 @@ class Attributes extends Secure_Controller //Save definition data $definition_data = array( 'definition_name' => $this->input->post('definition_name'), - 'definition_type' => DEFINITION_TYPES[$this->input->post('definition_type')], 'definition_flags' => $definition_flags, 'definition_fk' => $this->input->post('definition_group') != '' ? $this->input->post('definition_group') : NULL ); + $definition_type = empty($this->input->post('definition_type')) ? NULL : $this->input->post('definition_type'); + + if ($definition_type) + { + $definition_data['definition_type'] = DEFINITION_TYPES[$definition_type]; + } + $definition_name = $this->xss_clean($definition_data['definition_name']); if($this->Attribute->save_definition($definition_data, $definition_id)) diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 0701da955..c8afb50c5 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -546,14 +546,14 @@ class Items extends Secure_Controller } // Save item attributes - $attribute_links = $this->input->post('attribute_links'); + $attribute_links = $this->input->post('attribute_links') != null ? $this->input->post('attribute_links') : array(); $attribute_ids = $this->input->post('attribute_ids'); $this->Attribute->delete_link($item_id); foreach ($attribute_links as $definition_id => $attribute_id) { $definition_type = $this->Attribute->get_info($definition_id)->definition_type; if ($definition_type != DROPDOWN) { - $attribute_id = $this->Attribute->save_value($attribute_id, $definition_id, $item_id, $attribute_ids[$definition_id]); + $attribute_id = $this->Attribute->save_value($attribute_id, $definition_id, $item_id, $attribute_ids[$definition_id], $definition_type); } $this->Attribute->save_link($item_id, $definition_id, $attribute_id); } @@ -764,7 +764,7 @@ class Items extends Secure_Controller // XSS file data sanity check $data = $this->xss_clean($data); - if(sizeof($data) >= 18) + if(sizeof($data) >= 17) { $item_data = array( 'name' => $data[1], @@ -783,7 +783,7 @@ class Items extends Secure_Controller into that directory, so you really can do whatever you want, this probably needs further discussion */ - $pic_file = $data[19]; + $pic_file = $data[14]; /*if(strcmp('.htaccess', $pic_file)==0) { $pic_file=''; @@ -833,7 +833,7 @@ class Items extends Secure_Controller // array to store information if location got a quantity $allowed_locations = $this->Stock_location->get_allowed_locations(); - for($col = 25; $col < $cols; $col = $col + 2) + for($col = 15; $col < $cols; $col = $col + 2) { $location_id = $data[$col]; if(array_key_exists($location_id, $allowed_locations)) diff --git a/application/helpers/locale_helper.php b/application/helpers/locale_helper.php index dc0b837b1..ed3c1c50d 100644 --- a/application/helpers/locale_helper.php +++ b/application/helpers/locale_helper.php @@ -3,6 +3,8 @@ const DEFAULT_LANGUAGE = 'english'; const DEFAULT_LANGUAGE_CODE = 'en-US'; +define('DEFAULT_DATETIME', mktime(0, 0, 0, 1, 1, 2010)); + /** * Currency locale helper */ @@ -299,6 +301,13 @@ function tax_decimals() return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0; } +function to_datetime($datetime) +{ + $config = get_instance()->config; + + return date($config->item('dateformat') . ' ' . $config->item('timeformat'), $datetime); +} + function to_currency($number) { return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY); diff --git a/application/migrations/sqlscripts/attributes.sql b/application/migrations/sqlscripts/attributes.sql index 35e8d6ba1..b1f93780c 100644 --- a/application/migrations/sqlscripts/attributes.sql +++ b/application/migrations/sqlscripts/attributes.sql @@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS `ospos_attribute_definitions` ( CREATE TABLE IF NOT EXISTS `ospos_attribute_values` ( `attribute_id` INT NOT NULL AUTO_INCREMENT, `attribute_value` VARCHAR(45) NULL, + `attribute_datetime` DATETIME NULL, PRIMARY KEY (`attribute_id`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8; diff --git a/application/models/Attribute.php b/application/models/Attribute.php index cb9fcd821..c773a655f 100644 --- a/application/models/Attribute.php +++ b/application/models/Attribute.php @@ -2,10 +2,10 @@ define('GROUP', 'GROUP'); define('DROPDOWN', 'DROPDOWN'); -define('DATE', 'DATE'); +define('DATETIME', 'DATETIME'); define('TEXT', 'TEXT'); -const DEFINITION_TYPES = [GROUP, DROPDOWN, TEXT]; +const DEFINITION_TYPES = [GROUP, DROPDOWN, TEXT, DATETIME]; class Attribute extends CI_Model { @@ -110,6 +110,8 @@ class Attribute extends CI_Model $this->db->from('attribute_definitions'); $this->db->join('attribute_links', 'attribute_links.definition_id = attribute_definitions.definition_id'); $this->db->where('item_id', $item_id); + $this->db->where('receiving_id'); + $this->db->where('sale_id'); $this->db->where('deleted', 0); $results = $this->db->get()->result_array(); @@ -342,13 +344,19 @@ class Attribute extends CI_Model return $suggestions; } - public function save_value($attribute_value, $definition_id, $item_id = FALSE, $attribute_id = FALSE) + public function save_value($attribute_value, $definition_id, $item_id = FALSE, $attribute_id = FALSE, $definition_type = DROPDOWN) { $this->db->trans_start(); if (empty($attribute_id) || empty($item_id)) { - $this->db->insert('attribute_values', array('attribute_value' => $attribute_value)); + if ($definition_type != DATETIME) + { + $this->db->insert('attribute_values', array('attribute_value' => $attribute_value)); + } else + { + $this->db->insert('attribute_values', array('attribute_datetime' => date('Y-m-d H:i:s', strtotime($attribute_value)))); + } $attribute_id = $this->db->insert_id(); $this->db->insert('attribute_links', array( diff --git a/application/views/attributes/form.php b/application/views/attributes/form.php index c14f7f63f..e1d4539b5 100644 --- a/application/views/attributes/form.php +++ b/application/views/attributes/form.php @@ -19,7 +19,7 @@
lang->line('attributes_definition_type'), 'definition_type', array('class'=>'control-label col-xs-3')); ?>
- definition_type, DEFINITION_TYPES), 'id="definition_type" class="form-control" ');?> + definition_type, DEFINITION_TYPES), 'id="definition_type" class="form-control" ' . ($definition_id != -1 ? 'disabled="disabled"' : ''));?>
diff --git a/application/views/attributes/item.php b/application/views/attributes/item.php index c5b2a3e38..2d9e71f63 100644 --- a/application/views/attributes/item.php +++ b/application/views/attributes/item.php @@ -23,12 +23,13 @@ foreach($definition_values as $definition_id => $definition_value) $attribute_id = (empty($attribute_value) || empty($attribute_value->attribute_id)) ? NULL : $attribute_value->attribute_id; echo form_hidden("attribute_ids[$definition_id]", $attribute_id); - if ($definition_value['definition_type'] == DATE) + if ($definition_value['definition_type'] == DATETIME) { - echo form_input(array( - 'name' => 'attribute_links[$definition_id]', - 'value' => date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), strtotime($definition_value['attribute_value'])), - 'class' => 'form-control input-sm', + $value = (empty($attribute_value) || empty($attribute_value->attribute_datetime)) ? DEFAULT_DATETIME : strtotime($attribute_value->attribute_datetime); + echo form_input(array( + 'name' => "attribute_links[$definition_id]", + 'value' => to_datetime($value), + 'class' => 'form-control input-sm datetime', 'data-definition-id' => $definition_id, 'readonly' => 'true')); } @@ -55,9 +56,17 @@ foreach($definition_values as $definition_id => $definition_value) + diff --git a/application/views/receivings/form.php b/application/views/receivings/form.php index 6c10ab591..46bbf4b02 100755 --- a/application/views/receivings/form.php +++ b/application/views/receivings/form.php @@ -51,34 +51,8 @@ $(document).ready(function() { load->view('partial/datepicker_locale'); ?> - - $('#datetime').datetimepicker( - { - format: "config->item("dateformat")) . ' ' . dateformat_bootstrap($this->config->item("timeformat"));?>", - startDate: "config->item('dateformat') . ' ' . $this->config->item('timeformat'), mktime(0, 0, 0, 1, 1, 2010));?>", - config->item('timeformat'); - $m = $t[strlen($t)-1]; - if( strpos($this->config->item('timeformat'), 'a') !== false || strpos($this->config->item('timeformat'), 'A') !== false ) - { - ?> - showMeridian: true, - - showMeridian: false, - - minuteStep: 1, - autoclose: true, - todayBtn: true, - todayHighlight: true, - bootcssVer: 3, - language: "" - }); + + $('#datetime').datetimepicker(pickerconfig); var fill_value = function(event, ui) { event.preventDefault(); diff --git a/application/views/sales/form.php b/application/views/sales/form.php index b882a4e30..eca343ab6 100755 --- a/application/views/sales/form.php +++ b/application/views/sales/form.php @@ -12,7 +12,7 @@
lang->line('sales_date'), 'date', array('class'=>'control-label col-xs-3')); ?>
- 'date','value'=>date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), strtotime($sale_info['sale_time'])), 'id'=>'datetime', 'class'=>'form-control input-sm'));?> + 'date','value'=>to_datetime(strtotime($sale_info['sale_time'])), 'id'=>'datetime', 'class'=>'form-control input-sm'));?>
@@ -110,32 +110,7 @@ $(document).ready(function() load->view('partial/datepicker_locale'); ?> - $('#datetime').datetimepicker({ - format: "config->item('dateformat')) . ' ' . dateformat_bootstrap($this->config->item('timeformat'));?>", - startDate: "config->item('dateformat') . ' ' . $this->config->item('timeformat'), mktime(0, 0, 0, 1, 1, 2010));?>", - config->item('timeformat'); - $m = $t[strlen($t)-1]; - if( strpos($this->config->item('timeformat'), 'a') !== false || strpos($this->config->item('timeformat'), 'A') !== false ) - { - ?> - showMeridian: true, - - showMeridian: false, - - minuteStep: 1, - autoclose: true, - todayBtn: true, - todayHighlight: true, - bootcssVer: 3, - language: "" - }); + $('#datetime').datetimepicker(pickerconfig); var fill_value = function(event, ui) { event.preventDefault(); diff --git a/database/tables.sql b/database/tables.sql index 6e6e83f69..ae75574c3 100644 --- a/database/tables.sql +++ b/database/tables.sql @@ -832,6 +832,7 @@ CREATE TABLE IF NOT EXISTS `ospos_attribute_definitions` ( CREATE TABLE IF NOT EXISTS `ospos_attribute_values` ( `attribute_id` INT NOT NULL AUTO_INCREMENT, `attribute_value` VARCHAR(45) NULL, + `attribute_datetime` DATETIME NULL, PRIMARY KEY (`attribute_id`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; diff --git a/import_items.csv b/import_items.csv index 8e083f017..ffe1b84a5 100644 --- a/import_items.csv +++ b/import_items.csv @@ -1,2 +1,3 @@ -Barcode,Item Name,Category,Supplier ID,Cost Price,Unit Price,Tax 1 Name,Tax 1 Percent,Tax 2 Name ,Tax 2 Percent,Reorder Level,Description,Allow Alt Description,Item has Serial Number,location_id,quantity,pic_idN -33333334,Apple iMac,Computers,,800,1200,Tax 1,8,Tax 2,10,1,Best Computer ever,y,,1,100,null +Barcode,Item Name,Category,Supplier ID,Cost Price,Unit Price,Tax 1 Name,Tax 1 Percent,Tax 2 Name ,Tax 2 Percent,Reorder Level,Description,Allow Alt Description,Item has Serial Number,item_image,location_id,quantity +33333334,Apple iMac,Computers,,800,1200,Tax 1,8,Tax 2,10,1,Best Computer ever,y,,item.jpg,1,100 +ma \ No newline at end of file diff --git a/public/js/manage_tables.js b/public/js/manage_tables.js index a6f5daf0b..f7bfcafb8 100644 --- a/public/js/manage_tables.js +++ b/public/js/manage_tables.js @@ -142,16 +142,17 @@ }); }; - var do_delete = function (url, ids) { - if (confirm($.fn.bootstrapTable.defaults.formatConfirmDelete())) { - $.post((url || options.resource) + '/delete', {'ids[]': ids || selected_ids()}, function (response) { - //delete was successful, remove checkbox rows - if (response.success) { - var selector = ids ? row_selector(ids) : selected_rows(); - table().collapseAllRows(); - $(selector).each(function (index, element) { - $(this).find("td").animate({backgroundColor: "green"}, 1200, "linear") - .end().animate({opacity: 0}, 1200, "linear", function () { + var do_action = function(action) { + return function (url, ids) { + if (confirm($.fn.bootstrapTable.defaults.formatConfirmDelete())) { + $.post((url || options.resource) + '/' + action, {'ids[]': ids || selected_ids()}, function (response) { + //delete was successful, remove checkbox rows + if (response.success) { + var selector = ids ? row_selector(ids) : selected_rows(); + table().collapseAllRows(); + $(selector).each(function (index, element) { + $(this).find("td").animate({backgroundColor: "green"}, 1200, "linear") + .end().animate({opacity: 0}, 1200, "linear", function () { table().remove({ field: options.uniqueId, values: selected_ids() @@ -161,46 +162,17 @@ enable_actions(); } }); - }); - $.notify(response.message, { type: 'success' }); - } else { - $.notify(response.message, { type: 'danger' }); - } - }, "json"); - } else { - return false; - } - }; - - var do_restore = function (url, ids) { - if (confirm($.fn.bootstrapTable.defaults.formatConfirmRestore())) { - $.post((url || options.resource) + '/restore', {'ids[]': ids || selected_ids()}, function (response) { - //restore was successful, remove checkbox rows - if (response.success) { - var selector = ids ? row_selector(ids) : selected_rows(); - table().collapseAllRows(); - $(selector).each(function (index, element) { - $(this).find("td").animate({backgroundColor: "green"}, 1200, "linear") - .end().animate({opacity: 0}, 1200, "linear", function () { - table().remove({ - field: options.uniqueId, - values: selected_ids() - }); - if (index == $(selector).length - 1) { - refresh(); - enable_actions(); - } }); - }); - $.notify(response.message, { type: 'success' }); - } else { - $.notify(response.message, { type: 'danger' }); - } - }, "json"); - } else { - return false; - } - }; + $.notify(response.message, {type: 'success'}); + } else { + $.notify(response.message, {type: 'danger'}); + } + }, "json"); + } else { + return false; + } + }; + }; var load_success = function(callback) { return function(response) { @@ -279,15 +251,11 @@ }; var init_delete = function (confirmMessage) { - $("#delete").click(function (event) { - do_delete(); - }); + $("#delete").click(do_action("delete")); }; var init_restore = function (confirmMessage) { - $("#restore").click(function (event) { - do_restore(); - }); + $("#restore").click(do_action("restore")); }; var refresh = function() { @@ -335,8 +303,8 @@ }, handle_submit: handle_submit, init: init, - do_delete: do_delete, - do_restore: do_restore, + do_delete: do_action("delete"), + do_restore: do_action("restore"), refresh : refresh, selected_ids : selected_ids, });