mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-09 17:39:23 -04:00
Add support for DATETIME in attributes (#68)
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<div class="form-group form-group-sm">
|
||||
<?php echo form_label($this->lang->line('attributes_definition_type'), 'definition_type', array('class'=>'control-label col-xs-3')); ?>
|
||||
<div class='col-xs-8'>
|
||||
<?php echo form_dropdown('definition_type', DEFINITION_TYPES, array_search($definition_info->definition_type, DEFINITION_TYPES), 'id="definition_type" class="form-control" ');?>
|
||||
<?php echo form_dropdown('definition_type', DEFINITION_TYPES, array_search($definition_info->definition_type, DEFINITION_TYPES), 'id="definition_type" class="form-control" ' . ($definition_id != -1 ? 'disabled="disabled"' : ''));?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
$("#remove_attribute_link").click(function() {
|
||||
$(this).parents(".form-group").remove();
|
||||
});
|
||||
<?php $this->load->view('partial/datepicker_locale'); ?>
|
||||
|
||||
$(".datetime").datetimepicker(pickerconfig);
|
||||
|
||||
var enable_delete = function() {
|
||||
$("#remove_attribute_link").click(function() {
|
||||
var parents = $(this).parents(".form-group").remove();
|
||||
});
|
||||
};
|
||||
|
||||
enable_delete();
|
||||
|
||||
$("input[name*='attribute_links']").change(function() {
|
||||
var definition_id = $(this).data('definition-id');
|
||||
@@ -91,7 +100,7 @@ foreach($definition_values as $definition_id => $definition_value)
|
||||
attribute_values[definition_id] = "";
|
||||
$("#attributes").load('<?php echo site_url("items/attributes/$item_id");?>', {
|
||||
'definition_ids': JSON.stringify(attribute_values)
|
||||
});
|
||||
}, enable_delete);
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
@@ -164,7 +164,7 @@
|
||||
'name'=>'date',
|
||||
'id'=>'datetime',
|
||||
'class'=>'form-control input-sm',
|
||||
'value'=>date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), strtotime($person_info->date)),
|
||||
'value'=>to_datetime(strtotime($person_info->date)),
|
||||
'readonly'=>'true')
|
||||
); ?>
|
||||
</div>
|
||||
|
||||
@@ -148,32 +148,7 @@ $(document).ready(function()
|
||||
{
|
||||
<?php $this->load->view('partial/datepicker_locale'); ?>
|
||||
|
||||
$('#datetime').datetimepicker({
|
||||
format: "<?php echo dateformat_bootstrap($this->config->item('dateformat')) . ' ' . dateformat_bootstrap($this->config->item('timeformat'));?>",
|
||||
startDate: "<?php echo date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), mktime(0, 0, 0, 1, 1, 2010));?>",
|
||||
<?php
|
||||
$t = $this->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,
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{
|
||||
?>
|
||||
showMeridian: false,
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
minuteStep: 1,
|
||||
autoclose: true,
|
||||
todayBtn: true,
|
||||
todayHighlight: true,
|
||||
bootcssVer: 3,
|
||||
language: "<?php echo current_language_code(); ?>"
|
||||
});
|
||||
$('#datetime').datetimepicker(pickerconfig)
|
||||
|
||||
var amount_validator = function(field) {
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,34 @@
|
||||
<?php $this->lang->load('calendar'); $this->lang->load('date'); ?>
|
||||
|
||||
var pickerconfig = function(start) {
|
||||
return {
|
||||
format: "<?php echo dateformat_bootstrap($this->config->item('dateformat')) . ' ' . dateformat_bootstrap($this->config->item('timeformat'));?>",
|
||||
startDate: start || "<?php echo to_datetime(DEFAULT_DATETIME); ?>",
|
||||
<?php
|
||||
$t = $this->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,
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{
|
||||
?>
|
||||
showMeridian: false,
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
minuteStep: 1,
|
||||
autoclose: true,
|
||||
todayBtn: true,
|
||||
todayHighlight: true,
|
||||
bootcssVer: 3,
|
||||
language: "<?php echo current_language_code(); ?>"
|
||||
};
|
||||
};
|
||||
|
||||
$.fn.datetimepicker.dates['<?php echo $this->config->item("language"); ?>'] = {
|
||||
days: [
|
||||
"<?php echo $this->lang->line("cal_sunday"); ?>",
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
<link rel="stylesheet" type="text/css" href="dist/opensourcepos.min.css?rel=88039333a5"/>
|
||||
<!-- end mincss template tags -->
|
||||
<!-- start minjs template tags -->
|
||||
<script type="text/javascript" src="dist/opensourcepos.min.js?rel=b84e7f49e4"></script>
|
||||
<script type="text/javascript" src="dist/opensourcepos.min.js?rel=1874cb8e83"></script>
|
||||
<!-- end minjs template tags -->
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
@@ -51,34 +51,8 @@
|
||||
$(document).ready(function()
|
||||
{
|
||||
<?php $this->load->view('partial/datepicker_locale'); ?>
|
||||
|
||||
$('#datetime').datetimepicker(
|
||||
{
|
||||
format: "<?php echo dateformat_bootstrap($this->config->item("dateformat")) . ' ' . dateformat_bootstrap($this->config->item("timeformat"));?>",
|
||||
startDate: "<?php echo date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), mktime(0, 0, 0, 1, 1, 2010));?>",
|
||||
<?php
|
||||
$t = $this->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,
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{
|
||||
?>
|
||||
showMeridian: false,
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
minuteStep: 1,
|
||||
autoclose: true,
|
||||
todayBtn: true,
|
||||
todayHighlight: true,
|
||||
bootcssVer: 3,
|
||||
language: "<?php echo current_language_code(); ?>"
|
||||
});
|
||||
|
||||
$('#datetime').datetimepicker(pickerconfig);
|
||||
|
||||
var fill_value = function(event, ui) {
|
||||
event.preventDefault();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<div class="form-group form-group-sm">
|
||||
<?php echo form_label($this->lang->line('sales_date'), 'date', array('class'=>'control-label col-xs-3')); ?>
|
||||
<div class='col-xs-8'>
|
||||
<?php echo form_input(array('name'=>'date','value'=>date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), strtotime($sale_info['sale_time'])), 'id'=>'datetime', 'class'=>'form-control input-sm'));?>
|
||||
<?php echo form_input(array('name'=>'date','value'=>to_datetime(strtotime($sale_info['sale_time'])), 'id'=>'datetime', 'class'=>'form-control input-sm'));?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -110,32 +110,7 @@ $(document).ready(function()
|
||||
|
||||
<?php $this->load->view('partial/datepicker_locale'); ?>
|
||||
|
||||
$('#datetime').datetimepicker({
|
||||
format: "<?php echo dateformat_bootstrap($this->config->item('dateformat')) . ' ' . dateformat_bootstrap($this->config->item('timeformat'));?>",
|
||||
startDate: "<?php echo date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), mktime(0, 0, 0, 1, 1, 2010));?>",
|
||||
<?php
|
||||
$t = $this->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,
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{
|
||||
?>
|
||||
showMeridian: false,
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
minuteStep: 1,
|
||||
autoclose: true,
|
||||
todayBtn: true,
|
||||
todayHighlight: true,
|
||||
bootcssVer: 3,
|
||||
language: "<?php echo current_language_code(); ?>"
|
||||
});
|
||||
$('#datetime').datetimepicker(pickerconfig);
|
||||
|
||||
var fill_value = function(event, ui) {
|
||||
event.preventDefault();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user