Compare commits

..

3 Commits

Author SHA1 Message Date
Ollama
9e07f5050a fix: Use explicit transBegin/transCommit/transRollback for atomicity
- Replace transStart/transComplete with transBegin/transCommit/transRollback
- Check all success conditions before committing
- Explicit rollback on failure

Address CodeRabbit review feedback
2026-04-15 15:29:39 +00:00
Ollama
ad06700aea fix: wrap postSave() in single transaction for atomicity
- Remove internal transaction from Item_taxes->save_value() to allow controller-level transaction
- Wrap entire save sequence (item, taxes, quantities, inventory, attributes) in single transaction
- Ensure all operations succeed or all fail together
- Prevents partial writes when saveItemAttributes() fails after item/tax/quantity saves succeed

Fixes #4474
2026-04-15 15:10:13 +00:00
objecttothis
165c3351eb Encourage users to star the project
Added a request to star the project for support.
2026-04-15 16:25:06 +04:00
55 changed files with 350 additions and 355 deletions

View File

@@ -106,7 +106,7 @@ NOTE: If you're running non-release code, please make sure you always run the la
## 🏃 Keep the Machine Running
If you like our project, please consider buying us a coffee through the button below so we can keep adding features.
If you like our project, please consider buying us a coffee through the button below so we can keep adding features. Please star the project if you like it!
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MUN6AEG7NY6H8)\
Or refer to the [FUNDING.yml](.github/FUNDING.yml) file.

View File

@@ -663,10 +663,13 @@ class Items extends Secure_Controller
$employee_id = $this->employee->get_logged_in_employee_info()->person_id;
if ($this->item->save_value($item_data, $item_id)) {
$success = true;
$new_item = false;
// Wrap the entire save sequence in a single transaction for atomicity
$this->db->transBegin();
$success = $this->item->save_value($item_data, $item_id);
$new_item = false;
if ($success) {
if ($item_id === NEW_ENTRY) {
$item_id = $item_data['item_id'];
$new_item = true;
@@ -690,7 +693,7 @@ class Items extends Secure_Controller
$tax_name_index++;
}
$success &= $this->item_taxes->save_value($items_taxes_data, $item_id);
$success = $success && $this->item_taxes->save_value($items_taxes_data, $item_id);
}
// Save item quantity
@@ -711,7 +714,7 @@ class Items extends Secure_Controller
$item_quantity = $this->item_quantity->get_item_quantity($item_id, $location['location_id']);
if ($item_quantity->quantity != $updated_quantity || $new_item) {
$success = $success && $this->item_quantity->save_value($location_detail, $item_id, $location['location_id']);
$success = $success && $this->item_quantity->save_value($location_detail, $item_id, $location['location_id']);
$inv_data = [
'trans_date' => date('Y-m-d H:i:s'),
@@ -726,21 +729,21 @@ class Items extends Secure_Controller
}
}
$success = $success && $this->saveItemAttributes($item_id);
if ($success && $upload_success) {
$message = lang('Items.successful_' . ($new_item ? 'adding' : 'updating')) . ' ' . $item_data['name'];
return $this->response->setJSON(['success' => true, 'message' => $message, 'id' => $item_id]);
} else {
$message = $upload_success ? lang('Items.error_adding_updating') . ' ' . $item_data['name'] : strip_tags($upload_data['error']);
return $this->response->setJSON(['success' => false, 'message' => $message, 'id' => $item_id]);
}
} else {
$message = lang('Items.error_adding_updating') . ' ' . $item_data['name'];
return $this->response->setJSON(['success' => false, 'message' => $message, 'id' => NEW_ENTRY]);
}
// Check all success conditions before committing
if ($success && $upload_success) {
$this->db->transCommit();
$message = lang('Items.successful_' . ($new_item ? 'adding' : 'updating')) . ' ' . $item_data['name'];
return $this->response->setJSON(['success' => true, 'message' => $message, 'id' => $item_id]);
}
// Rollback on failure
$this->db->transRollback();
$message = $upload_success ? lang('Items.error_adding_updating') . ' ' . $item_data['name'] : strip_tags($upload_data['error']);
return $this->response->setJSON(['success' => false, 'message' => $message, 'id' => $item_id]);
}
/**

View File

@@ -37,9 +37,6 @@ class Item_taxes extends Model
{
$success = true;
// Run these queries as a transaction, we want to make sure we do all or nothing
$this->db->transStart();
$this->delete($item_id);
$builder = $this->db->table('items_taxes');
@@ -49,10 +46,6 @@ class Item_taxes extends Model
$success &= $builder->insert($row);
}
$this->db->transComplete();
$success &= $this->db->transStatus();
return $success;
}

View File

@@ -102,12 +102,12 @@
<script type="text/javascript">
// Validation and submit handling
$(document).ready(function() {
const values = [];
const definition_id = <?= esc($definition_id, 'js') ?>;
const is_new = definition_id == 0;
var values = [];
var definition_id = <?= esc($definition_id, 'js') ?>;
var is_new = definition_id == 0;
const disable_definition_types = function() {
const definition_type = $("#definition_type option:selected").text();
var disable_definition_types = function() {
var definition_type = $("#definition_type option:selected").text();
if (definition_type == "DATE" || (definition_type == "GROUP" && !is_new) || definition_type == "DECIMAL") {
$('#definition_type').prop("disabled", true);
@@ -121,7 +121,7 @@
}
disable_definition_types();
const disable_category_dropdown = function() {
var disable_category_dropdown = function() {
if (definition_id == -1) {
$('#definition_name').prop("disabled", true);
$('#definition_type').prop("disabled", true);
@@ -131,11 +131,11 @@
}
disable_category_dropdown();
const show_hide_fields = function(event) {
const is_dropdown = $('#definition_type').val() !== '1';
const is_decimal = $('#definition_type').val() !== '2';
const is_no_group = $('#definition_type').val() !== '0';
const is_category_dropdown = definition_id == -1;
var show_hide_fields = function(event) {
var is_dropdown = $('#definition_type').val() !== '1';
var is_decimal = $('#definition_type').val() !== '2';
var is_no_group = $('#definition_type').val() !== '0';
var is_category_dropdown = definition_id == -1;
$('#definition_value, #definition_list_group').parents('.form-group').toggleClass('hidden', is_dropdown);
$('#definition_unit').parents('.form-group').toggleClass('hidden', is_decimal);
@@ -150,12 +150,12 @@
show_hide_fields();
$('.selectpicker').each(function() {
const $selectpicker = $(this);
var $selectpicker = $(this);
$.fn.selectpicker.call($selectpicker, $selectpicker.data());
});
const remove_attribute_value = function() {
const value = $(this).parents("li").text();
var remove_attribute_value = function() {
var value = $(this).parents("li").text();
if (is_new) {
values.splice($.inArray(value, values), 1);
@@ -168,8 +168,8 @@
$(this).parents("li").remove();
};
const add_attribute_value = function(value) {
const is_event = typeof(value) !== 'string';
var add_attribute_value = function(value) {
var is_event = typeof(value) !== 'string';
if ($("#definition_value").val().match(/(\||_)/g) != null) {
return;
@@ -206,7 +206,7 @@
}
});
const definition_values = <?= json_encode(array_values($definition_values)) ?>;
var definition_values = <?= json_encode(array_values($definition_values)) ?>;
$.each(definition_values, function(index, element) {
add_attribute_value(element);
});

View File

@@ -104,7 +104,7 @@
(function() {
<?= view('partial/datepicker_locale', ['format' => dateformat_bootstrap($config['dateformat'])]) ?>
const enable_delete = function() {
var enable_delete = function() {
$('.remove_attribute_btn').click(function() {
$(this).parents('.form-group').remove();
});
@@ -113,7 +113,7 @@
enable_delete();
$("input[name*='attribute_links']").change(function() {
const definition_id = $(this).data('definition-id');
var definition_id = $(this).data('definition-id');
$("input[name='attribute_ids[" + definition_id + "]']").val('');
}).autocomplete({
source: function(request, response) {
@@ -129,11 +129,11 @@
delay: 10
});
const definition_values = function() {
const result = {};
var definition_values = function() {
var result = {};
$("[name*='attribute_links'").each(function() {
const definition_id = $(this).data('definition-id');
const element = $(this);
var definition_id = $(this).data('definition-id');
var element = $(this);
// For checkboxes, use the visible checkbox, not the hidden input
if (element.attr('type') === 'hidden' && element.siblings('input[type="checkbox"]').length > 0) {
@@ -151,9 +151,9 @@
return result;
};
const refresh = function() {
const definition_id = $("#definition_name option:selected").val();
let attribute_values = definition_values();
var refresh = function() {
var definition_id = $("#definition_name option:selected").val();
var attribute_values = definition_values();
attribute_values[definition_id] = '';
$('#attributes').load('<?= "items/attributes/$item_id" ?>', {
'definition_ids': JSON.stringify(attribute_values)

View File

@@ -308,7 +308,7 @@
);
});
const submit_form = function() {
var submit_form = function() {
$(this).ajaxSubmit({
success: function(response) {
dialog_support.hide();

View File

@@ -139,7 +139,7 @@
<script type="text/javascript">
// Validation and submit handling
$(document).ready(function() {
const check_protocol = function() {
var check_protocol = function() {
if ($('#protocol').val() == 'sendmail') {
$('#mailpath').prop('disabled', false);
$('#smtp_host, #smtp_user, #smtp_pass, #smtp_port, #smtp_timeout, #smtp_crypto').prop('disabled', true);

View File

@@ -467,8 +467,8 @@
<script type="text/javascript">
// Validation and submit handling
$(document).ready(function() {
const enable_disable_gcaptcha_enable = (function() {
const gcaptcha_enable = $("#gcaptcha_enable").is(":checked");
var enable_disable_gcaptcha_enable = (function() {
var gcaptcha_enable = $("#gcaptcha_enable").is(":checked");
if (gcaptcha_enable) {
$("#gcaptcha_site_key, #gcaptcha_secret_key").prop("disabled", !gcaptcha_enable).addClass("required");
$("#config_gcaptcha_site_key, #config_gcaptcha_secret_key").addClass("required");

View File

@@ -198,9 +198,9 @@
<script type="text/javascript">
// Validation and submit handling
$(document).ready(function() {
const enable_disable_invoice_enable = (function() {
const invoice_enabled = $("#invoice_enable").is(":checked");
const work_order_enabled = $("#work_order_enable").is(":checked");
var enable_disable_invoice_enable = (function() {
var invoice_enabled = $("#invoice_enable").is(":checked");
var work_order_enabled = $("#work_order_enable").is(":checked");
$("#sales_invoice_format, #recv_invoice_format, #invoice_default_comments, #invoice_email_message, select[name='invoice_type'], #sales_quote_format, select[name='line_sequence'], #last_used_invoice_number, #last_used_quote_number, #quote_default_comments, #work_order_enable, #work_order_format, #last_used_work_order_number").prop("disabled", !invoice_enabled);
if (invoice_enabled) {
$("#work_order_format, #last_used_work_order_number").prop("disabled", !work_order_enabled);
@@ -210,9 +210,9 @@
return arguments.callee;
})();
const enable_disable_work_order_enable = (function() {
const work_order_enabled = $("#work_order_enable").is(":checked");
const invoice_enabled = $("#invoice_enable").is(":checked");
var enable_disable_work_order_enable = (function() {
var work_order_enabled = $("#work_order_enable").is(":checked");
var invoice_enabled = $("#invoice_enable").is(":checked");
if (invoice_enabled) {
$("#work_order_format, #last_used_work_order_number").prop("disabled", !work_order_enabled);
}

View File

@@ -292,7 +292,7 @@
$('span').tooltip();
$('#currency_symbol, #thousands_separator, #currency_code').change(function() {
const data = {
var data = {
number_locale: $('#number_locale').val()
};
data['save_number_locale'] = $("input[name='save_number_locale']").val();
@@ -336,7 +336,7 @@
}
},
dataFilter: function(data) {
const response = JSON.parse(data);
var response = JSON.parse(data);
$("input[name='save_number_locale']").val(response.save_number_locale);
$('#number_locale_example').text(response.number_locale_example);
$('#currency_symbol').val(response.currency_symbol);

View File

@@ -338,9 +338,9 @@
// Validation and submit handling
$(document).ready(function() {
if (window.localStorage && window.jsPrintSetup) {
const printers = (jsPrintSetup.getPrintersList() && jsPrintSetup.getPrintersList().split(',')) || [];
var printers = (jsPrintSetup.getPrintersList() && jsPrintSetup.getPrintersList().split(',')) || [];
$('#receipt_printer, #invoice_printer, #takings_printer').each(function() {
const $this = $(this)
var $this = $(this)
$(printers).each(function(key, value) {
$this.append($('<option>', {
value: value
@@ -360,7 +360,7 @@
});
}
const dialog_confirmed = window.jsPrintSetup;
var dialog_confirmed = window.jsPrintSetup;
$('#receipt_config_form').validate($.extend(form_support.handler, {
submitHandler: function(form) {

View File

@@ -43,8 +43,8 @@
// Validation and submit handling
$(document).ready(function() {
const enable_disable_customer_reward_enable = (function() {
const customer_reward_enable = $("#customer_reward_enable").is(":checked");
var enable_disable_customer_reward_enable = (function() {
var customer_reward_enable = $("#customer_reward_enable").is(":checked");
$("input[name*='customer_reward']:not(input[name=customer_reward_enable])").prop("disabled", !customer_reward_enable);
$("input[name*='reward_points_']:not(input[name=customer_reward_enable])").prop("disabled", !customer_reward_enable);
if (customer_reward_enable) {
@@ -57,9 +57,9 @@
$("#customer_reward_enable").change(enable_disable_customer_reward_enable);
let table_count = <?= sizeof($customer_rewards) ?>;
var table_count = <?= sizeof($customer_rewards) ?>;
const hide_show_remove = function() {
var hide_show_remove = function() {
if ($("input[name*='customer_rewards']:enabled").length > 1) {
$(".remove_customer_rewards").show();
} else {
@@ -67,27 +67,27 @@
}
};
const add_customer_reward = function() {
let id = $(this).parent().find('input').attr('id');
var add_customer_reward = function() {
var id = $(this).parent().find('input').attr('id');
id = id.replace(/.*?_(\d+)$/g, "$1");
const previous_id = 'customer_reward_' + id;
const previous_id_next = 'reward_points_' + id;
const block = $(this).parent().clone(true);
const new_block = block.insertAfter($(this).parent());
const new_block_id = 'customer_reward_' + ++id;
const new_block_id_next = 'reward_points_' + id;
var previous_id = 'customer_reward_' + id;
var previous_id_next = 'reward_points_' + id;
var block = $(this).parent().clone(true);
var new_block = block.insertAfter($(this).parent());
var new_block_id = 'customer_reward_' + ++id;
var new_block_id_next = 'reward_points_' + id;
$(new_block).find('label').html("<?= lang('Config.customer_reward') ?> " + ++table_count).attr('for', new_block_id).attr('class', 'control-label col-xs-2');
$(new_block).find("input[id='" + previous_id + "']").attr('id', new_block_id).removeAttr('disabled').attr('name', new_block_id).attr('class', 'form-control input-sm').val('');
$(new_block).find("input[id='" + previous_id_next + "']").attr('id', new_block_id_next).removeAttr('disabled').attr('name', new_block_id_next).attr('class', 'form-control input-sm').val('');
hide_show_remove();
};
const remove_customer_reward = function() {
var remove_customer_reward = function() {
$(this).parent().remove();
hide_show_remove();
};
const init_add_remove_tables = function() {
var init_add_remove_tables = function() {
$('.add_customer_reward').click(add_customer_reward);
$('.remove_customer_reward').click(remove_customer_reward);
hide_show_remove();
@@ -96,10 +96,10 @@
};
init_add_remove_tables();
const duplicate_found = false;
var duplicate_found = false;
// Run validator once for all fields
$.validator.addMethod('customer_reward', function(value, element) {
let value_count = 0;
var value_count = 0;
$("input[name*='customer_reward']:not(input[name=customer_reward_enable])").each(function() {
value_count = $(this).val() == value ? value_count + 1 : value_count;
});

View File

@@ -29,9 +29,9 @@
<script type="text/javascript">
// Validation and submit handling
$(document).ready(function() {
let location_count = <?= sizeof($stock_locations) ?>;
var location_count = <?= sizeof($stock_locations) ?>;
const hide_show_remove = function() {
var hide_show_remove = function() {
if ($("input[name*='stock_location']:enabled").length > 1) {
$(".remove_stock_location").show();
} else {
@@ -39,31 +39,31 @@
}
};
const add_stock_location = function() {
const block = $(this).parent().clone(true);
const new_block = block.insertAfter($(this).parent());
const new_block_id = 'stock_location[]';
var add_stock_location = function() {
var block = $(this).parent().clone(true);
var new_block = block.insertAfter($(this).parent());
var new_block_id = 'stock_location[]';
$(new_block).find('label').html("<?= lang('Config.stock_location') ?> " + ++location_count).attr('for', new_block_id).attr('class', 'control-label col-xs-2');
$(new_block).find('input').attr('id', new_block_id).removeAttr('disabled').attr('name', new_block_id).attr('class', 'form-control input-sm').val('');
hide_show_remove();
};
const remove_stock_location = function() {
var remove_stock_location = function() {
$(this).parent().remove();
hide_show_remove();
};
const init_add_remove_locations = function() {
var init_add_remove_locations = function() {
$('.add_stock_location').click(add_stock_location);
$('.remove_stock_location').click(remove_stock_location);
hide_show_remove();
};
init_add_remove_locations();
const duplicate_found = false;
var duplicate_found = false;
// Run validator once for all fields
$.validator.addMethod('stock_location', function(value, element) {
let value_count = 0;
var value_count = 0;
$("input[name*='stock_location']").each(function() {
value_count = $(this).val() == value ? value_count + 1 : value_count;
});

View File

@@ -198,7 +198,7 @@ use Config\OSPOS;
<div style="text-align: center;">
<a class="copy" data-clipboard-action="copy" data-clipboard-target="#issuetemplate">Copy Info</a> | <a href="https://github.com/opensourcepos/opensourcepos/issues/new" target="_blank"> <?= lang('Config.report_an_issue') ?></a>
<script type="text/javascript">
const clipboard = new ClipboardJS('.copy');
var clipboard = new ClipboardJS('.copy');
clipboard.on('success', function(e) {
document.getSelection().removeAllRanges();

View File

@@ -43,8 +43,8 @@
// Validation and submit handling
$(document).ready(function() {
const enable_disable_dinner_table_enable = (function() {
const dinner_table_enable = $("#dinner_table_enable").is(":checked");
var enable_disable_dinner_table_enable = (function() {
var dinner_table_enable = $("#dinner_table_enable").is(":checked");
$("input[name*='dinner_table']:not(input[name=dinner_table_enable])").prop("disabled", !dinner_table_enable);
if (dinner_table_enable) {
$(".add_dinner_table, .remove_dinner_table").show();
@@ -56,9 +56,9 @@
$("#dinner_table_enable").change(enable_disable_dinner_table_enable);
let table_count = <?= sizeof($dinner_tables) ?>;
var table_count = <?= sizeof($dinner_tables) ?>;
const hide_show_remove = function() {
var hide_show_remove = function() {
if ($("input[name*='dinner_tables']:enabled").length > 1) {
$(".remove_dinner_tables").show();
} else {
@@ -66,23 +66,23 @@
}
};
const add_dinner_table = function() {
let id = $(this).parent().find('input').attr('id');
var add_dinner_table = function() {
var id = $(this).parent().find('input').attr('id');
id = id.replace(/.*?_(\d+)$/g, "$1");
const block = $(this).parent().clone(true);
const new_block = block.insertAfter($(this).parent());
const new_block_id = 'dinner_table_' + ++id;
var block = $(this).parent().clone(true);
var new_block = block.insertAfter($(this).parent());
var new_block_id = 'dinner_table_' + ++id;
$(new_block).find('label').html("<?= lang('Config.dinner_table') ?> " + ++table_count).attr('for', new_block_id).attr('class', 'control-label col-xs-2');
$(new_block).find('input').attr('id', new_block_id).removeAttr('disabled').attr('name', new_block_id).attr('class', 'form-control input-sm').val('');
hide_show_remove();
};
const remove_dinner_table = function() {
var remove_dinner_table = function() {
$(this).parent().remove();
hide_show_remove();
};
const init_add_remove_tables = function() {
var init_add_remove_tables = function() {
$('.add_dinner_table').click(add_dinner_table);
$('.remove_dinner_table').click(remove_dinner_table);
hide_show_remove();
@@ -91,10 +91,10 @@
};
init_add_remove_tables();
const duplicate_found = false;
var duplicate_found = false;
// Run validator once for all fields
$.validator.addMethod('dinner_table', function(value, element) {
let value_count = 0;
var value_count = 0;
$("input[name*='dinner_table']:not(input[name=dinner_table_enable])").each(function() {
value_count = $(this).val() == value ? value_count + 1 : value_count;
});

View File

@@ -143,8 +143,8 @@
<script type="text/javascript">
// Validation and submit handling
$(document).ready(function() {
const enable_disable_use_destination_based_tax = (function() {
const use_destination_based_tax = $("#use_destination_based_tax").is(":checked");
var enable_disable_use_destination_based_tax = (function() {
var use_destination_based_tax = $("#use_destination_based_tax").is(":checked");
$("select[name='default_tax_code']").prop("disabled", !use_destination_based_tax);
$("select[name='default_tax_category']").prop("disabled", !use_destination_based_tax);
$("select[name='default_tax_jurisdiction']").prop("disabled", !use_destination_based_tax);

View File

@@ -453,7 +453,7 @@
}
});
const fill_value = function(event, ui) {
var fill_value = function(event, ui) {
event.preventDefault();
$("input[name='sales_tax_code_id']").val(ui.item.value);
$("input[name='sales_tax_code_name']").val(ui.item.label);

View File

@@ -167,10 +167,10 @@
});
$.validator.addMethod('module', function(value, element) {
let result = $('#permission_list input').is(':checked');
var result = $('#permission_list input').is(':checked');
$('.module').each(function(index, element) {
const parent = $(element);
const checked = $(element).is(':checked');
var parent = $(element).parent();
var checked = $(element).is(':checked');
if ($('ul', parent).length > 0 && result) {
result &= !checked || (checked && $('ul > li > input:checked', parent).length > 0);
}
@@ -179,10 +179,10 @@
}, "<?= lang('Employees.subpermission_required') ?>");
$('ul#permission_list > li > input.module').each(function() {
const $this = $(this);
var $this = $(this);
$('ul > li > input,select', $this.parent()).each(function() {
const $that = $(this);
const updateInputs = function(checked) {
var $that = $(this);
var updateInputs = function(checked) {
$that.prop('disabled', !checked);
!checked && $that.prop('checked', false);
}

View File

@@ -1,17 +1,17 @@
const tabLinks = new Array();
const contentDivs = new Array();
var tabLinks = new Array();
var contentDivs = new Array();
function init()
{
// Grab the tab links and content divs from the page
const tabListItems = document.getElementById('tabs').childNodes;
var tabListItems = document.getElementById('tabs').childNodes;
console.log(tabListItems);
for (let i = 0; i < tabListItems.length; i ++)
for (var i = 0; i < tabListItems.length; i ++)
{
if (tabListItems[i].nodeName == "LI")
{
const tabLink = getFirstChildWithTagName(tabListItems[i], 'A');
const id = getHash(tabLink.getAttribute('href'));
var tabLink = getFirstChildWithTagName(tabListItems[i], 'A');
var id = getHash(tabLink.getAttribute('href'));
tabLinks[id] = tabLink;
contentDivs[id] = document.getElementById(id);
}
@@ -19,9 +19,9 @@ function init()
// Assign onclick events to the tab links, and
// highlight the first tab
let i = 0;
var i = 0;
for (const id in tabLinks)
for (var id in tabLinks)
{
tabLinks[id].onclick = showTab;
tabLinks[id].onfocus = function () {
@@ -35,26 +35,26 @@ function init()
}
// Hide all content divs except the first
let j = 0;
var i = 0;
for (const id in contentDivs)
for (var id in contentDivs)
{
if (j != 0)
if (i != 0)
{
console.log(contentDivs[id]);
contentDivs[id].className = 'content hide';
}
j ++;
i ++;
}
}
function showTab()
{
const selectedId = getHash(this.getAttribute('href'));
var selectedId = getHash(this.getAttribute('href'));
// Highlight the selected tab, and dim all others.
// Also show the selected content div, and hide all others.
for (const id in contentDivs)
for (var id in contentDivs)
{
if (id == selectedId)
{
@@ -74,7 +74,7 @@ function showTab()
function getFirstChildWithTagName(element, tagName)
{
for (let i = 0; i < element.childNodes.length; i ++)
for (var i = 0; i < element.childNodes.length; i ++)
{
if (element.childNodes[i].nodeName == tagName)
{
@@ -85,29 +85,28 @@ function getFirstChildWithTagName(element, tagName)
function getHash(url)
{
const hashPos = url.lastIndexOf('#');
var hashPos = url.lastIndexOf('#');
return url.substring(hashPos + 1);
}
function toggle(elem)
{
elem = document.getElementById(elem);
let disp;
if (elem.style && elem.style['display'])
{
// Only works with the "style" attr
disp = elem.style['display'];
var disp = elem.style['display'];
}
else if (elem.currentStyle)
{
// For MSIE, naturally
disp = elem.currentStyle['display'];
var disp = elem.currentStyle['display'];
}
else if (window.getComputedStyle)
{
// For most other browsers
disp = document.defaultView.getComputedStyle(elem, null).getPropertyValue('display');
var disp = document.defaultView.getComputedStyle(elem, null).getPropertyValue('display');
}
// Toggle the state of the "display" style

View File

@@ -78,7 +78,7 @@
!$(this).val() && $(this).val('');
});
const fill_value = function(event, ui) {
var fill_value = function(event, ui) {
event.preventDefault();
$(this).val((ui.item ? ui.item.label : ""));
$("input[name='person_id']").val(ui.item.value);

View File

@@ -235,7 +235,7 @@
}
});
const fill_value = function(event, ui) {
var fill_value = function(event, ui) {
event.preventDefault();
$("input[name='kit_item_id']").val(ui.item.value);
$("input[name='item_name']").val(DOMPurify.sanitize(ui.item.label));

View File

@@ -467,7 +467,7 @@
!$(this).val() && $(this).val('');
});
const fill_tax_category_value = function(event, ui) {
var fill_tax_category_value = function(event, ui) {
event.preventDefault();
$("input[name='tax_category_id']").val(ui.item.value);
$("input[name='tax_category']").val(ui.item.label);
@@ -483,7 +483,7 @@
focus: fill_tax_category_value
});
const fill_low_sell_value = function(event, ui) {
var fill_low_sell_value = function(event, ui) {
event.preventDefault();
$("input[name='low_sell_item_id']").val(ui.item.value);
$("input[name='low_sell_item_name']").val(ui.item.label);
@@ -517,7 +517,7 @@
return value.match(/(\||_)/g) == null;
}, "<?= lang('Attributes.attribute_value_invalid_chars') ?>");
const init_validation = function() {
var init_validation = function() {
$('#item_form').validate($.extend({
submitHandler: function(form, event) { // Event is not used as a parameter here
$(form).ajaxSubmit({

View File

@@ -178,10 +178,10 @@
delay: 10
});
let confirm_message = false;
var confirm_message = false;
$('#tax_percent_name_2, #tax_name_2').prop('disabled', true),
$('#tax_percent_name_1, #tax_name_1').blur(function() {
const disabled = !($('#tax_percent_name_1').val() + $('#tax_name_1').val());
var disabled = !($('#tax_percent_name_1').val() + $('#tax_name_1').val());
$('#tax_percent_name_2, #tax_name_2').prop('disabled', disabled);
confirm_message = disabled ? '' : "<?= lang('Items.confirm_bulk_edit_wipe_taxes') ?>";
});

View File

@@ -115,27 +115,27 @@ use App\Models\Inventory;
});
function display_stock(location_id) {
const item_quantities = <?= json_encode(esc($item_quantities, 'raw')) ?>;
var item_quantities = <?= json_encode(esc($item_quantities, 'raw')) ?>;
document.getElementById("quantity").value = parseFloat(item_quantities[location_id]).toFixed(<?= quantity_decimals() ?>);
const inventory_data = <?= json_encode(esc($inventory_array, 'raw')) ?>;
const employee_data = <?= json_encode(esc($employee_name, 'raw')) ?>;
var inventory_data = <?= json_encode(esc($inventory_array, 'raw')) ?>;
var employee_data = <?= json_encode(esc($employee_name, 'raw')) ?>;
const table = document.getElementById("inventory_result");
var table = document.getElementById("inventory_result");
// Remove old query from tbody
const rowCount = table.rows.length;
for (let index = rowCount; index > 0; index--) {
var rowCount = table.rows.length;
for (var index = rowCount; index > 0; index--) {
table.deleteRow(index - 1);
}
// Add new query to tbody
for (let index = 0; index < inventory_data.length; index++) {
const data = inventory_data[index];
for (var index = 0; index < inventory_data.length; index++) {
var data = inventory_data[index];
if (data['trans_location'] == location_id) {
const tr = document.createElement('tr');
var tr = document.createElement('tr');
let td = document.createElement('td');
var td = document.createElement('td');
td.appendChild(document.createTextNode(data['trans_date']));
tr.appendChild(td);

View File

@@ -136,7 +136,7 @@
});
function fill_quantity(val) {
const item_quantities = <?= json_encode(esc($item_quantities, 'raw')) ?>;
var item_quantities = <?= json_encode(esc($item_quantities, 'raw')) ?>;
document.getElementById('quantity').value = parseFloat(item_quantities[val]).toFixed(<?= quantity_decimals() ?>);
}
</script>

View File

@@ -30,7 +30,7 @@ use App\Models\Employee;
// Set the beginning of time as starting date
$('#daterangepicker').data('daterangepicker').setStartDate("<?= date($config['dateformat'], mktime(0, 0, 0, 01, 01, 2010)) ?>");
// Update the hidden inputs with the selected dates before submitting the search data
start_date = "<?= date('Y-m-d', mktime(0, 0, 0, 01, 01, 2010)) ?>";
var start_date = "<?= date('Y-m-d', mktime(0, 0, 0, 01, 01, 2010)) ?>";
// Override dates from server if provided
<?php if (isset($start_date) && $start_date): ?>

View File

@@ -3,7 +3,7 @@ use Config\OSPOS;
$config = config(OSPOS::class)->settings; ?>
const pickerconfig = function(config) {
var pickerconfig = function(config) {
return $.extend({
format: "<?= $this->data["format"] ?? dateformat_bootstrap($config['dateformat']) . ' ' . dateformat_bootstrap($config['timeformat'])?>",
<?php

View File

@@ -6,8 +6,8 @@
<?php if (empty($config['date_or_time_format'])) { ?>
$('#daterangepicker').css("width", "180");
let start_date = "<?= date('Y-m-d') ?>";
let end_date = "<?= date('Y-m-d') ?>";
var start_date = "<?= date('Y-m-d') ?>";
var end_date = "<?= date('Y-m-d') ?>";
$('#daterangepicker').daterangepicker({
"ranges": {
@@ -112,8 +112,8 @@
});
<?php } else { ?>
$('#daterangepicker').css("width", "305");
let start_date = "<?= date('Y-m-d H:i:s', mktime(0, 0, 0, date("m"), date("d"), date("Y"))) ?>";
let end_date = "<?= date('Y-m-d H:i:s', mktime(23, 59, 59, date("m"), date("d"), date("Y"))) ?>";
var start_date = "<?= date('Y-m-d H:i:s', mktime(0, 0, 0, date("m"), date("d"), date("Y"))) ?>";
var end_date = "<?= date('Y-m-d H:i:s', mktime(23, 59, 59, date("m"), date("d"), date("Y"))) ?>";
$('#daterangepicker').daterangepicker({
"ranges": {
"<?= lang('Datepicker.today') ?>": [

View File

@@ -6,14 +6,14 @@
<script type="text/javascript">
// Live clock
const clock_tick = function clock_tick() {
var clock_tick = function clock_tick() {
setInterval('update_clock();', 1000);
}
// Start the clock immediately
clock_tick();
const update_clock = function update_clock() {
var update_clock = function update_clock() {
document.getElementById('liveclock').innerHTML = moment().format("<?= dateformat_momentjs($config['dateformat'] . ' ' . $config['timeformat']) ?>");
}
@@ -32,11 +32,11 @@
}
});
const csrf_token = function() {
return "<?= esc(csrf_hash(), 'js') ?>";
var csrf_token = function() {
return "<?= csrf_hash() ?>";
};
const csrf_form_base = function() {
var csrf_form_base = function() {
return {
<?= esc(config('Security')->tokenName, 'js') ?>: function() {
return csrf_token()
@@ -44,14 +44,14 @@
}
};
const setup_csrf_token = function() {
var setup_csrf_token = function() {
$('input[name="<?= esc(config('Security')->tokenName, 'js') ?>"]').val(csrf_token());
};
const ajax = $.ajax;
var ajax = $.ajax;
$.ajax = function() {
let args = arguments[0];
var args = arguments[0];
if (args['type'] && args['type'].toLowerCase() == 'post' && csrf_token()) {
if (typeof args['data'] === 'string') {
args['data'] += '&' + $.param(csrf_form_base());
@@ -80,7 +80,7 @@
});
});
const submit = $.fn.submit;
var submit = $.fn.submit;
$.fn.submit = function() {
setup_csrf_token();

View File

@@ -1,7 +1,7 @@
<script type="text/javascript">
(function(lang, $) {
const lines = {
var lines = {
'common_submit': "<?= lang('Common.submit') ?>",
'common_close': "<?= lang('Common.close') ?>"
};

View File

@@ -29,11 +29,11 @@
jsPrintSetup.setOption('footerStrRight', '');
<?php } ?>
const printers = jsPrintSetup.getPrintersList().split(',');
var printers = jsPrintSetup.getPrintersList().split(',');
// Get right printer here..
for (const index in printers) {
const default_ticket_printer = window.localStorage && localStorage['<?= esc($selected_printer, 'js') ?>'];
const selected_printer = printers[index];
for (var index in printers) {
var default_ticket_printer = window.localStorage && localStorage['<?= esc($selected_printer, 'js') ?>'];
var selected_printer = printers[index];
if (selected_printer == default_ticket_printer) {
// Select Epson label printer
jsPrintSetup.setPrinter(selected_printer);

View File

@@ -18,11 +18,11 @@ $filter_select_id = $options['filter_select_id'] ?? 'filters';
<script type="text/javascript">
$(document).ready(function() {
const additional_params = <?= json_encode($additional_params) ?>;
const filter_select_id = '<?= esc($filter_select_id) ?>';
var additional_params = <?= json_encode($additional_params) ?>;
var filter_select_id = '<?= esc($filter_select_id) ?>';
function update_url() {
const params = new URLSearchParams();
var params = new URLSearchParams();
// Add dates
if (typeof start_date !== 'undefined') {
@@ -33,7 +33,7 @@ $filter_select_id = $options['filter_select_id'] ?? 'filters';
}
// Add filters
const filters = $('#' + filter_select_id).val();
var filters = $('#' + filter_select_id).val();
if (filters) {
filters.forEach(function(filter) {
params.append('filters[]', filter);
@@ -42,9 +42,9 @@ $filter_select_id = $options['filter_select_id'] ?? 'filters';
// Add additional params
additional_params.forEach(function(param) {
const element = $('#' + param);
var element = $('#' + param);
if (element.length) {
const value = element.val();
var value = element.val();
if (Array.isArray(value) && value.length > 0) {
value.forEach(function(v) {
params.append(param + '[]', v);
@@ -56,8 +56,8 @@ $filter_select_id = $options['filter_select_id'] ?? 'filters';
});
// Update URL without page reload
const new_url = window.location.pathname;
const params_str = params.toString();
var new_url = window.location.pathname;
var params_str = params.toString();
if (params_str) {
new_url += '?' + params_str;
}

View File

@@ -26,8 +26,8 @@ function safeRemoveItem(key) {
}
// Load saved column visibility from localStorage
const savedVisibility = JSON.parse(safeGetItem('columnVisibility')) || { cost: false, profit: false };
let visibleColumns = savedVisibility;
var savedVisibility = JSON.parse(safeGetItem('columnVisibility')) || { cost: false, profit: false };
var visibleColumns = savedVisibility;
// Function to save column visibility to localStorage
function saveColumnVisibility(visibility) {
@@ -56,13 +56,13 @@ $('#table').bootstrapTable('refreshOptions', {
});
// Initialize visibility settings from localStorage
let summaryVisibility = JSON.parse(safeGetItem('summaryVisibility')) || { cost: false, profit: false };
var summaryVisibility = JSON.parse(safeGetItem('summaryVisibility')) || { cost: false, profit: false };
// Function to apply visibility for cost and profit rows
function applySummaryVisibility() {
const rows = $('#report_summary .summary_row');
const costRow = rows.eq(rows.length - 2); // Second-to-last row
const profitRow = rows.eq(rows.length - 1); // Last row
var rows = $('#report_summary .summary_row');
var costRow = rows.eq(rows.length - 2); // Second-to-last row
var profitRow = rows.eq(rows.length - 1); // Last row
if (summaryVisibility.cost === false) {
costRow.hide(); // Hide the cost row
@@ -90,7 +90,7 @@ $('#toggleCostProfitButton').click(function () {
applySummaryVisibility();
// Initialize dialog (if editable)
const init_dialog = function () {
var init_dialog = function () {
<?php if (isset($editable)): ?>
table_support.submit_handler('<?php echo site_url("reports/get_detailed_{$editable}_row") ?>');
dialog_support.init("a.modal-dlg");

View File

@@ -18,13 +18,13 @@
pageSize: <?= $config['lines_per_page'] ?>,
uniqueId: 'people.person_id',
enableActions: function() {
const email_disabled = $("td input:checkbox:checked").parents("tr").find("td a[href^='mailto:']").length == 0;
var email_disabled = $("td input:checkbox:checked").parents("tr").find("td a[href^='mailto:']").length == 0;
$("#email").prop('disabled', email_disabled);
}
});
$("#email").click(function(event) {
const recipients = $.map($("tr.selected a[href^='mailto:']"), function(element) {
var recipients = $.map($("tr.selected a[href^='mailto:']"), function(element) {
return $(element).attr('href').replace(/^mailto:/, '');
});
location.href = "mailto:" + recipients.join(",");

View File

@@ -76,7 +76,7 @@
$('#datetime').datetimepicker(pickerconfig);
const fill_value = function(event, ui) {
var fill_value = function(event, ui) {
event.preventDefault();
$("input[name='supplier_id']").val(ui.item.value);
$("input[name='supplier_name']").val(ui.item.label);

View File

@@ -533,7 +533,7 @@ if (isset($success)) {
});
$('[name="discount_toggle"]').change(function() {
const input = $("<input>").attr("type", "hidden").attr("name", "discount_type").val(($(this).prop('checked')) ? 1 : 0);
var input = $("<input>").attr("type", "hidden").attr("name", "discount_type").val(($(this).prop('checked')) ? 1 : 0);
$('#cart_' + $(this).attr('data-line')).append($(input));
$('#cart_' + $(this).attr('data-line')).submit();
});

View File

@@ -11,7 +11,7 @@
<script type="text/javascript">
// Labels and data series
const data = {
var data = {
labels: <?= esc(json_encode($labels_1), 'js') ?>,
series: [{
name: '<?= esc($yaxis_title, 'js') ?>',
@@ -20,7 +20,7 @@
};
// We are setting a few options for our chart and override the defaults
const options = {
var options = {
// Specify a fixed width for the chart as a string (i.e. '100px' or '50%')
width: '100%',
@@ -98,7 +98,7 @@
]
};
const responsiveOptions = [
var responsiveOptions = [
['screen and (min-width: 640px)', {
height: '80%',
chartPadding: {

View File

@@ -11,7 +11,7 @@
<script type="text/javascript">
// Labels and data series
const data = {
var data = {
labels: <?= json_encode(esc($labels_1, 'js')) ?>,
series: [{
name: '<?= esc($yaxis_title, 'js') ?>',
@@ -20,7 +20,7 @@
};
// We are setting a few options for our chart and override the defaults
const options = {
var options = {
// Specify a fixed width for the chart as a string (i.e. '100px' or '50%')
width: '100%',
@@ -101,7 +101,7 @@
]
};
const responsiveOptions = [
var responsiveOptions = [
['screen and (min-width: 640px)', {
height: '80%',
chartPadding: {

View File

@@ -11,7 +11,7 @@
<script type="text/javascript">
// Labels and data series
const data = {
var data = {
labels: <?= json_encode(esc($labels_1, 'js')) ?>,
series: [{
name: '<?= esc($yaxis_title, 'js') ?>',
@@ -20,7 +20,7 @@
};
// We are setting a few options for our chart and override the defaults
const options = {
var options = {
// Specify a fixed width for the chart as a string (i.e. '100px' or '50%')
width: '100%',
@@ -150,7 +150,7 @@
]
};
const responsiveOptions = [
var responsiveOptions = [
['screen and (min-width: 640px)', {
height: '80%',
chartPadding: {
@@ -172,7 +172,7 @@
// If the draw event was triggered from drawing a point on the line chart
if (data.type === 'point') {
// We are creating a new path SVG element that draws a triangle around the point coordinates
const circle = new Chartist.Svg('circle', {
var circle = new Chartist.Svg('circle', {
cx: [data.x],
cy: [data.y],
r: [5],

View File

@@ -9,13 +9,13 @@
<script type="text/javascript">
// Labels and data series
const data = {
var data = {
labels: <?= json_encode(esc($labels_1, 'js')) ?>,
series: <?= json_encode(esc($series_data_1, 'js')) ?>
};
// We are setting a few options for our chart and override the defaults
const options = {
var options = {
// Specify a fixed width for the chart as a string (i.e. '100px' or '50%')
width: '100%',
@@ -53,7 +53,7 @@
})
] };
const responsiveOptions = [
var responsiveOptions = [
['screen and (min-width: 640px)', {
height: '80%',
chartPadding: 20
@@ -72,9 +72,9 @@
// Generate random colours for the pie sliced because Chartist is currently limited to 15 colours
chart.on('draw', function(data) {
if (data.type === 'slice') {
const r = Math.floor(Math.random() * 256);
const g = Math.floor(Math.random() * 256);
const b = Math.floor(Math.random() * 256);
var r = Math.floor(Math.random() * 256);
var g = Math.floor(Math.random() * 256);
var b = Math.floor(Math.random() * 256);
data.element.attr({
style: 'fill: #' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)

View File

@@ -87,7 +87,7 @@ if (isset($error)) {
<?= view('partial/daterangepicker') ?>
$("#generate_report").click(function() {
let specific_input_data = $('#specific_input_data').val();
var specific_input_data = $('#specific_input_data').val();
if (!$(".discount_percent").is(":visible")) {
specific_input_data = $('#discount_fixed').val();
}
@@ -97,7 +97,7 @@ if (isset($error)) {
});
function check_discount_type() {
const discount_type = $("#discount_type_id").val();
var discount_type = $("#discount_type_id").val();
if (discount_type == 1) {
$(".discount_percent").hide();

View File

@@ -39,13 +39,13 @@
$(document).ready(function () {
<?= view('partial/bootstrap_tables_locale') ?>
const details_data = <?= json_encode(esc($details_data)) ?>;
var details_data = <?= json_encode(esc($details_data)) ?>;
<?php if ($config['customer_reward_enable'] && !empty($details_data_rewards)) { ?>
const details_data_rewards = <?= json_encode(esc($details_data_rewards)) ?>;
var details_data_rewards = <?= json_encode(esc($details_data_rewards)) ?>;
<?php } ?>
<?= view('partial/visibility_js') ?>
const init_dialog = function () {
var init_dialog = function () {
<?php if (isset($editable)) { ?>
table_support.submit_handler('<?= esc(site_url("reports/get_detailed_$editable" . '_row')) ?>');
dialog_support.init("a.modal-dlg");

View File

@@ -172,7 +172,7 @@
<?= view('partial/datepicker_locale') ?>
const fill_value_customer = function(event, ui) {
var fill_value_customer = function(event, ui) {
event.preventDefault();
$("input[name='customer_id']").val(ui.item.value);
$("input[name='customer_name']").val(ui.item.label);
@@ -188,7 +188,7 @@
focus: fill_value_customer
});
const fill_value_employee = function(event, ui) {
var fill_value_employee = function(event, ui) {
event.preventDefault();
$("input[name='employee_id']").val(ui.item.value);
$("input[name='employee_name']").val(ui.item.label);

View File

@@ -32,7 +32,7 @@ if (isset($error_message)) {
<?php if (!empty($customer_email)): ?>
<script type="text/javascript">
$(document).ready(function() {
const send_email = function() {
var send_email = function() {
$.get('<?= site_url() . "sales/sendPdf/$sale_id_num" ?>',
function(response) {
$.notify({

View File

@@ -28,7 +28,7 @@ if (isset($error_message)) {
<?php if (!empty($customer_email)): ?>
<script type="text/javascript">
$(document).ready(function() {
const send_email = function() {
var send_email = function() {
$.get('<?= site_url() . esc("/sales/sendPdf/$sale_id_num/quote") ?>',
function(response) {
$.notify({

View File

@@ -21,7 +21,7 @@ if (isset($error_message)) {
<?php if (!empty($customer_email)): ?>
<script type="text/javascript">
$(document).ready(function() {
const send_email = function() {
var send_email = function() {
$.get('<?= site_url() . esc("/sales/sendPdf/$sale_id_num/receipt") ?>',
function(response) {
$.notify({

View File

@@ -585,8 +585,8 @@ helper('url');
});
$("input[name='item_number']").change(function() {
const item_id = $(this).parents('tr').find("input[name='item_id']").val();
const item_number = $(this).val();
var item_id = $(this).parents('tr').find("input[name='item_id']").val();
var item_number = $(this).val();
$.ajax({
url: "<?= site_url('sales/changeItemNumber') ?>",
method: 'post',
@@ -599,8 +599,8 @@ helper('url');
});
$("input[name='name']").change(function() {
const item_id = $(this).parents('tr').find("input[name='item_id']").val();
const item_name = $(this).val();
var item_id = $(this).parents('tr').find("input[name='item_id']").val();
var item_name = $(this).val();
$.ajax({
url: "<?= site_url('sales/changeItemName') ?>",
method: 'post',
@@ -613,8 +613,8 @@ helper('url');
});
$("input[name='item_description']").change(function() {
const item_id = $(this).parents('tr').find("input[name='item_id']").val();
const item_description = $(this).val();
var item_id = $(this).parents('tr').find("input[name='item_id']").val();
var item_description = $(this).val();
$.ajax({
url: "<?= site_url('sales/changeItemDescription') ?>",
method: 'post',
@@ -651,7 +651,7 @@ helper('url');
}
});
const clear_fields = function() {
var clear_fields = function() {
if ($(this).val().match("<?= lang(ucfirst($controller_name) . '.start_typing_item_name') . '|' . lang(ucfirst($controller_name) . '.start_typing_customer_name') ?>")) {
$(this).val('');
}
@@ -787,7 +787,7 @@ helper('url');
$('#customer').val(response.id);
$('#select_customer_form').submit();
} else {
const $stock_location = $("select[name='stock_location']").val();
var $stock_location = $("select[name='stock_location']").val();
$('#item_location').val($stock_location);
$('#item').val(response.id);
if (stay_open) {
@@ -804,14 +804,14 @@ helper('url');
});
$('[name="discount_toggle"]').change(function() {
const input = $('<input>').attr('type', 'hidden').attr('name', 'discount_type').val(($(this).prop('checked')) ? 1 : 0);
var input = $('<input>').attr('type', 'hidden').attr('name', 'discount_type').val(($(this).prop('checked')) ? 1 : 0);
$('#cart_' + $(this).attr('data-line')).append($(input));
$('#cart_' + $(this).attr('data-line')).submit();
});
});
function check_payment_type() {
const cash_mode = <?= json_encode($cash_mode) ?>;
var cash_mode = <?= json_encode($cash_mode) ?>;
if ($("#payment_types").val() == "<?= lang(ucfirst($controller_name) . '.giftcard') ?>") {
$("#sale_total").html("<?= to_currency($total) ?>");

View File

@@ -32,7 +32,7 @@ if (isset($error_message)) {
<?php if (!empty($customer_email)): ?>
<script type="text/javascript">
$(document).ready(function() {
const send_email = function() {
var send_email = function() {
$.get('<?= esc("/sales/sendPdf/$sale_id_num") ?>',
function(response) {
$.notify({

View File

@@ -30,7 +30,7 @@ if (isset($error_message)) {
<?php if (!empty($customer_email)): ?>
<script type="text/javascript">
$(document).ready(function() {
const send_email = function() {
var send_email = function() {
$.get('<?= esc("/sales/sendPdf/$sale_id_num/work_order") ?>',
function(response) {
$.notify({

View File

@@ -27,14 +27,14 @@
<?= form_close() ?>
<script type="text/javascript">
// Validation and submit Handling
// Validation and submit handling
$(document).ready(function() {
let tax_categories_count = <?= sizeof($tax_categories) ?>;
var tax_categories_count = <?= sizeof($tax_categories) ?>;
if (tax_categories_count == 0) {
tax_categories_count = 1;
}
const hide_show_remove_tax_category = function() {
var hide_show_remove_tax_category = function() {
if ($("input[name*='tax_category']:enabled").length > 1) {
$(".remove_tax_category").show();
} else {
@@ -42,15 +42,15 @@
}
};
const add_tax_category = function() {
let id = $(this).parent().find('input').attr('id');
var add_tax_category = function() {
var id = $(this).parent().find('input').attr('id');
id = id.replace(/.*?_(\d+)$/g, "$1");
const previous_tax_category_id = 'tax_category_' + id;
const block = $(this).parent().clone(true);
const new_block = block.insertAfter($(this).parent());
var previous_tax_category_id = 'tax_category_' + id;
var block = $(this).parent().clone(true);
var new_block = block.insertAfter($(this).parent());
++tax_categories_count;
const new_tax_category_id = 'tax_category_' + tax_categories_count;
var new_tax_category_id = 'tax_category_' + tax_categories_count;
$(new_block).find('label').html("<?= lang('Taxes.tax_category') ?> " + tax_categories_count).attr('for', new_tax_category_id).attr('class', 'control-label col-xs-2');
$(new_block).find("input[name='tax_category[]']").attr('id', new_tax_category_id).removeAttr('disabled').attr('class', 'form-control input-sm required').val('');
@@ -59,23 +59,23 @@
hide_show_remove_tax_category();
};
const remove_tax_category = function() {
var remove_tax_category = function() {
$(this).parent().remove();
hide_show_remove_tax_category();
};
const init_add_remove_tax_categories = function() {
var init_add_remove_tax_categories = function() {
$('.add_tax_category').click(add_tax_category);
$('.remove_tax_category').click(remove_tax_category);
hide_show_remove_tax_category();
};
init_add_remove_tax_categories();
let duplicate_found = false;
var duplicate_found = false;
// Run validator once for all fields
$.validator.addMethod("check4TaxCategoryDups", function(value, element) {
let value_count = 0;
var value_count = 0;
$('input[name="tax_category[]"]').each(function() {
value_count = $(this).val() == value ? value_count + 1 : value_count;
});

View File

@@ -27,14 +27,14 @@
<?= form_close() ?>
<script type="text/javascript">
// Validation and submit Handling
// Validation and submit handling
$(document).ready(function() {
let tax_code_count = <?= sizeof($tax_codes) ?>;
var tax_code_count = <?= sizeof($tax_codes) ?>;
if (tax_code_count == 0) {
tax_code_count = 1;
}
const hide_show_remove_tax_code = function() {
var hide_show_remove_tax_code = function() {
if ($("input[name*='tax_code']:enabled").length > 1) {
$(".remove_tax_code").show();
} else {
@@ -42,14 +42,14 @@
}
};
const add_tax_code = function() {
let id = $(this).parent().find("input[name='tax_code[]']").attr('id');
var add_tax_code = function() {
var id = $(this).parent().find("input[name='tax_code[]']").attr('id');
id = id.replace(/.*?_(\d+)$/g, "$1");
const previous_tax_code_id = 'tax_code_' + id;
const block = $(this).parent().clone(true);
const new_block = block.insertAfter($(this).parent());
var previous_tax_code_id = 'tax_code_' + id;
var block = $(this).parent().clone(true);
var new_block = block.insertAfter($(this).parent());
++tax_code_count;
const new_tax_code_id = 'tax_code_' + tax_code_count;
var new_tax_code_id = 'tax_code_' + tax_code_count;
$(new_block).find('label').html("<?= lang('Taxes.tax_code') ?> " + tax_code_count).attr('for', new_tax_code_id).attr('class', 'control-label col-xs-2');
$(new_block).find("input[name='tax_code[]']").attr('id', new_tax_code_id).removeAttr('disabled').attr('class', 'form-control text-uppercase required input-sm').val('');
@@ -61,12 +61,12 @@
hide_show_remove_tax_code();
};
const remove_tax_code = function() {
var remove_tax_code = function() {
$(this).parent().remove();
hide_show_remove_tax_code();
};
const init_add_remove_tax_codes = function() {
var init_add_remove_tax_codes = function() {
$('.add_tax_code').click(add_tax_code);
$('.remove_tax_code').click(remove_tax_code);
hide_show_remove_tax_code();
@@ -75,7 +75,7 @@
// Run validator once for all fields
$.validator.addMethod('check4TaxCodeDups', function(value, element) {
let value_count = 0;
var value_count = 0;
$("input[name='tax_code[]']").each(function() {
value_count = $(this).val() == value ? value_count + 1 : value_count;
});

View File

@@ -28,31 +28,31 @@
<?= form_close() ?>
<script type="text/javascript">
// Validation and submit Handling
// Validation and submit handling
$(document).ready(function() {
let tax_jurisdictions_count = <?= sizeof($tax_jurisdictions) ?>;
var tax_jurisdictions_count = <?= sizeof($tax_jurisdictions) ?>;
if (tax_jurisdictions_count == 0) {
tax_jurisdictions_count = 1;
}
const tax_type_options = '<?= esc($tax_type_options, 'js') ?>';
var tax_type_options = '<?= esc($tax_type_options, 'js') ?>';
const hide_show_remove_tax_jurisdiction = function() {
var hide_show_remove_tax_jurisdiction = function() {
if ($("input[name*='tax_jurisdiction']:enabled").length > 1) {
$(".remove_tax_jurisdiction").show();
} else {
$(".remove_tax_jurisdiction").hide();
$(".remove_tax_jurisdictions").hide();
}
};
const add_tax_jurisdiction = function() {
let id = $(this).parent().find('input').attr('id');
var add_tax_jurisdiction = function() {
var id = $(this).parent().find('input').attr('id');
id = id.replace(/.*?_(\d+)$/g, "$1");
const previous_jurisdiction_name_id = 'jurisdiction_name_' + id;
const block = $(this).parent().clone(true);
const new_block = block.insertAfter($(this).parent());
var previous_jurisdiction_name_id = 'jurisdiction_name_' + id;
var block = $(this).parent().clone(true);
var new_block = block.insertAfter($(this).parent());
++tax_jurisdictions_count;
const new_jurisdiction_name_id = 'jurisdiction_name_' + tax_jurisdictions_count;
var new_jurisdiction_name_id = 'jurisdiction_name_' + tax_jurisdictions_count;
$(new_block).find('label').html("<?= lang('Taxes.tax_jurisdiction') ?> " + tax_jurisdictions_count).attr('for', new_jurisdiction_name_id).attr('class', 'control-label col-xs-2');
$(new_block).find("input[name='jurisdiction_name[]']").attr('id', new_jurisdiction_name_id).removeAttr('disabled').attr('class', 'form-control required input-sm').val('');
@@ -65,12 +65,12 @@
hide_show_remove_tax_jurisdiction();
};
const remove_tax_jurisdiction = function() {
var remove_tax_jurisdiction = function() {
$(this).parent().remove();
hide_show_remove_tax_jurisdiction();
};
const init_add_remove_tax_jurisdiction = function() {
var init_add_remove_tax_jurisdiction = function() {
$('.add_tax_jurisdiction').click(add_tax_jurisdiction);
$('.remove_tax_jurisdiction').click(remove_tax_jurisdiction);
hide_show_remove_tax_jurisdiction();
@@ -79,7 +79,7 @@
// Run validator once for all fields
$.validator.addMethod('check4TaxJurisdictionDups', function(value, element) {
let value_count = 0;
var value_count = 0;
$("input[name='jurisdiction_name[]']").each(function() {
value_count = $(this).val() == value ? value_count + 1 : value_count;
});

View File

@@ -20,8 +20,8 @@ import { Stream } from 'readable-stream'
const {finished, pipeline} = Stream.promises
let prod0js;
let prod1js;
var prod0js;
var prod1js;
// Clear and remove the resources folder
gulp.task('clean', function () {
@@ -102,7 +102,7 @@ gulp.task('copy-bootstrap', function() {
gulp.task('debug-js', function() {
const debugjs = gulp.src(['./node_modules/jquery/dist/jquery.js',
var debugjs = gulp.src(['./node_modules/jquery/dist/jquery.js',
'./node_modules/jquery-form/src/jquery.form.js',
'./node_modules/jquery-validation/dist/jquery.validate.js',
'./node_modules/jquery-ui-dist/jquery-ui.js',
@@ -141,9 +141,9 @@ gulp.task('debug-js', function() {
gulp.task('prod-js', function() {
const prod0js = gulp.src('./node_modules/jquery/dist/jquery.min.js').pipe(rev()).pipe(gulp.dest('public/resources'));
var prod0js = gulp.src('./node_modules/jquery/dist/jquery.min.js').pipe(rev()).pipe(gulp.dest('public/resources'));
const opensourcepos1js = gulp.src(['./node_modules/bootstrap/dist/js/bootstrap.min.js',
var opensourcepos1js = gulp.src(['./node_modules/bootstrap/dist/js/bootstrap.min.js',
'./node_modules/bootstrap-table/dist/bootstrap-table.min.js',
'./node_modules/moment/min/moment.min.js',
'./node_modules/jquery-ui-dist/jquery-ui.min.js',
@@ -174,13 +174,13 @@ gulp.task('prod-js', function() {
'./node_modules/chartist-plugin-barlabels/dist/chartist-plugin-barlabels.min.js',
'./node_modules/tableexport.jquery.plugin/tableExport.min.js'], { allowEmpty: true });
const opensourcepos2js = gulp.src(['./node_modules/bootstrap-daterangepicker/daterangepicker.js',
var opensourcepos2js = gulp.src(['./node_modules/bootstrap-daterangepicker/daterangepicker.js',
'./public/js/imgpreview.full.jquery.js',
'./public/js/manage_tables.js',
'./public/js/nominatim.autocomplete.js']).pipe(uglify());
const prod1js = series(opensourcepos1js, opensourcepos2js).pipe(concat('opensourcepos.min.js'))
var prod1js = series(opensourcepos1js, opensourcepos2js).pipe(concat('opensourcepos.min.js'))
.pipe(rev())
.pipe(gulp.dest('./public/resources/'));
@@ -194,21 +194,21 @@ gulp.task('prod-js', function() {
gulp.task('debug-login-js', function() {
// Match only core jQuery (jquery-HASH.js), exclude jquery plugins (jquery-HASH.form.js, etc) and jquery-ui (jquery-ui-HASH.js)
// Pattern: jquery-[hash].js where hash is alphanumeric - core jQuery only
const loginDebugJs = gulp.src(['./public/resources/js/jquery-*.js', '!./public/resources/js/jquery-*.form.js', '!./public/resources/js/jquery-*.validate.js', '!./public/resources/js/jquery-ui-*.js']);
var loginDebugJs = gulp.src(['./public/resources/js/jquery-*.js', '!./public/resources/js/jquery-*.form.js', '!./public/resources/js/jquery-*.validate.js', '!./public/resources/js/jquery-ui-*.js']);
return gulp.src('./app/Views/login.php').pipe(inject(loginDebugJs, {addRootSlash: false, ignorePath: '/public/', starttag: '<!-- inject:login:debug:js -->'})).pipe(gulp.dest('./app/Views'));
});
// Inject jQuery into login.php (production mode) - reuse the jQuery file already created by prod-js
gulp.task('prod-login-js', function() {
// jQuery prod file is already in resources/jquery-*.min.js from prod-js task
const loginProdJs = gulp.src('./public/resources/jquery-*.min.js');
var loginProdJs = gulp.src('./public/resources/jquery-*.min.js');
return gulp.src('./app/Views/login.php').pipe(inject(loginProdJs, {addRootSlash: false, ignorePath: '/public/', starttag: '<!-- inject:login:prod:js -->'})).pipe(gulp.dest('./app/Views'));
});
gulp.task('debug-css', function() {
const debugcss = gulp.src(['./node_modules/jquery-ui-dist/jquery-ui.css',
var debugcss = gulp.src(['./node_modules/jquery-ui-dist/jquery-ui.css',
'./node_modules/bootstrap3-dialog/dist/css/bootstrap-dialog.css',
'./node_modules/jasny-bootstrap/dist/css/jasny-bootstrap.css',
'./node_modules/bootstrap-datetime-picker/css/bootstrap-datetimepicker.css',
@@ -234,23 +234,23 @@ gulp.task('debug-css', function() {
gulp.task('prod-css', function() {
const opensourcepos1css = gulp.src(['./node_modules/jquery-ui-dist/jquery-ui.min.css',
var opensourcepos1css = gulp.src(['./node_modules/jquery-ui-dist/jquery-ui.min.css',
'./node_modules/bootstrap3-dialog/dist/css/bootstrap-dialog.min.css',
'./node_modules/jasny-bootstrap/dist/css/jasny-bootstrap.min.css',
'./node_modules/bootstrap-datetime-picker/css/bootstrap-datetimepicker.min.css']);
const opensourcepos2css = gulp.src(['./node_modules/bootstrap-daterangepicker/daterangepicker.css',
var opensourcepos2css = gulp.src(['./node_modules/bootstrap-daterangepicker/daterangepicker.css',
'./node_modules/bootstrap-tagsinput-2021/src/bootstrap-tagsinput.css']).pipe(cleanCSS({compatibility: 'ie8'}));
const opensourcepos3css = gulp.src(['./node_modules/bootstrap-select/dist/css/bootstrap-select.min.css',
var opensourcepos3css = gulp.src(['./node_modules/bootstrap-select/dist/css/bootstrap-select.min.css',
'./node_modules/bootstrap-table/dist/bootstrap-table.min.css',
'./node_modules/bootstrap-table/dist/extensions/sticky-header/bootstrap-table-sticky-header.min.css',
'./node_modules/bootstrap-toggle/css/bootstrap-toggle.min.css',
'./node_modules/chartist/dist/chartist.min.css']);
const opensourcepos4css = gulp.src('./node_modules/chartist-plugin-tooltips/dist/chartist-plugin-tooltip.css').pipe(cleanCSS({compatibility: 'ie8'}));
var opensourcepos4css = gulp.src('./node_modules/chartist-plugin-tooltips/dist/chartist-plugin-tooltip.css').pipe(cleanCSS({compatibility: 'ie8'}));
const opensourcepos5css = gulp.src(['./node_modules/chartist-plugin-tooltips/dist/chartist-plugin-tooltip.css',
var opensourcepos5css = gulp.src(['./node_modules/chartist-plugin-tooltips/dist/chartist-plugin-tooltip.css',
'./public/css/bootstrap.autocomplete.css',
'./public/css/invoice.css',
'./public/css/ospos.css',
@@ -261,7 +261,7 @@ gulp.task('prod-css', function() {
'./public/css/reports.css'
]).pipe(cleanCSS({compatibility: 'ie8'}));
const prodcss = series(opensourcepos1css, opensourcepos2css, opensourcepos3css, opensourcepos4css, opensourcepos5css)
var prodcss = series(opensourcepos1css, opensourcepos2css, opensourcepos3css, opensourcepos4css, opensourcepos5css)
.pipe(concat('opensourcepos.min.css')).pipe(rev()).pipe(gulp.dest('public/resources'));

View File

@@ -1,16 +1,16 @@
(function(dialog_support, $) {
let btn_id, dialog_ref;
var btn_id, dialog_ref;
const hide = function() {
var hide = function() {
dialog_ref && dialog_ref.close();
};
const clicked_id = function() {
var clicked_id = function() {
return btn_id;
};
const submit = function(button_id) {
var submit = function(button_id) {
return function(dlog_ref) {
const form = $('form', dlog_ref.$modalBody).first();
const validator = form.data('validator');
@@ -27,31 +27,31 @@
}
};
const button_class = {
var button_class = {
'submit' : 'btn-primary',
'delete' : 'btn-danger'
};
const init = function(selector) {
var init = function(selector) {
const buttons = function(event) {
const buttons = [];
let dialog_class = 'modal-dlg';
var buttons = function(event) {
var buttons = [];
var dialog_class = 'modal-dlg';
$.each($(this).attr('class').split(/\s+/), function(classIndex, className) {
const width_class = className.split("modal-dlg-");
var width_class = className.split("modal-dlg-");
if (width_class && width_class.length > 1) {
dialog_class = className;
}
});
const has_new_btn = "btnNew" in $(this).data();
var has_new_btn = "btnNew" in $(this).data();
$.each($(this).data(), function(name, value) {
const btn_class = name.split("btn");
var btn_class = name.split("btn");
if (btn_class && btn_class.length > 1) {
const btn_name = btn_class[1].toLowerCase();
const is_submit = btn_name == 'submit';
const is_new = btn_name === 'new';
const is_enter = has_new_btn ? is_new: is_submit;
var btn_name = btn_class[1].toLowerCase();
var is_submit = btn_name == 'submit';
var is_new = btn_name === 'new';
var is_enter = has_new_btn ? is_new: is_submit;
buttons.push({
id: btn_name,
label: value,
@@ -78,12 +78,12 @@
$(selector).each(function(index, $element) {
return $(selector).off('click').on('click', function(event) {
let $link = $(event.target);
var $link = $(event.target);
$link = !$link.is("a, button") ? $link.parents("a, button") : $link ;
BootstrapDialog.show($.extend({
title: $link.attr('title'),
message: (function() {
const node = $('<div></div>');
var node = $('<div></div>');
$.get($link.attr('href') || $link.data('href'), function(data) {
node.html(data);
});
@@ -107,34 +107,34 @@
(function(table_support, $) {
let enable_actions = function(callback) {
var enable_actions = function(callback) {
return function() {
const selection_empty = selected_rows().length == 0;
var selection_empty = selected_rows().length == 0;
$("#toolbar button:not(.dropdown-toggle)").attr('disabled', selection_empty);
typeof callback == 'function' && callback();
}
};
const table = function() {
var table = function() {
return $("#table").data('bootstrap.table');
}
const selected_ids = function () {
var selected_ids = function () {
return $.map(table().getSelections(), function (element) {
return element[options.uniqueId || 'id'] !== '-' ? element[options.uniqueId || 'id'] : null;
});
};
const selected_rows = function () {
var selected_rows = function () {
return $("#table td input:checkbox:checked").parents("tr");
};
const row_selector = function(id) {
var row_selector = function(id) {
return "tr[data-uniqueid='" + id + "']";
};
const rows_selector = function(ids) {
const selectors = [];
var rows_selector = function(ids) {
var selectors = [];
ids = ids instanceof Array ? ids : ("" + ids).split(":");
$.each(ids, function(index, element) {
selectors.push(row_selector(element));
@@ -142,22 +142,22 @@
return selectors;;
};
const highlight_row = function (id, color) {
var highlight_row = function (id, color) {
$(rows_selector(id)).each(function(index, element) {
const original = $(element).css('backgroundColor');
var original = $(element).css('backgroundColor');
$(element).find("td").animate({backgroundColor: color || '#e1ffdd'}, "slow", "linear")
.animate({backgroundColor: color || '#e1ffdd'}, 5000)
.animate({backgroundColor: original}, "slow", "linear");
});
};
const do_action = function(action) {
var do_action = function(action) {
return function (url, ids) {
if (confirm($.fn.bootstrapTable.defaults.formatConfirmAction(action))) {
$.post((url || options.resource) + '/' + action, {'ids[]': ids || selected_ids()}, function (response) {
// Delete was successful, remove checkbox rows
if (response.success) {
const selector = ids ? row_selector(ids) : selected_rows();
var selector = ids ? row_selector(ids) : selected_rows();
table().collapseAllRows();
$(selector).each(function (index, element) {
$(this).find("td").animate({backgroundColor: "green"}, 1200, "linear")
@@ -183,7 +183,7 @@
};
};
let load_success = function(callback) {
var load_success = function(callback) {
return function(response) {
typeof options.load_callback == 'function' && options.load_callback();
options.load_callback = undefined;
@@ -192,18 +192,18 @@
}
};
let options;
var options;
const toggle_column_visibility = function() {
var toggle_column_visibility = function() {
if (localStorage[options.employee_id]) {
const user_settings = JSON.parse(localStorage[options.employee_id]);
var user_settings = JSON.parse(localStorage[options.employee_id]);
user_settings[options.resource] && $.each(user_settings[options.resource], function(index, element) {
element ? table().showColumn(index) : table().hideColumn(index);
});
}
};
const init = function (_options) {
var init = function (_options) {
options = _options;
enable_actions = enable_actions(options.enableActions);
load_success = load_success(options.onLoadSuccess);
@@ -244,7 +244,7 @@
enable_actions();
},
onColumnSwitch : function(field, checked) {
let user_settings = localStorage[options.employee_id];
var user_settings = localStorage[options.employee_id];
user_settings = (user_settings && JSON.parse(user_settings)) || {};
user_settings[options.resource] = user_settings[options.resource] || {};
user_settings[options.resource][field] = checked;
@@ -264,36 +264,36 @@
dialog_support.init("button.modal-dlg");
};
const init_delete = function (confirmMessage) {
var init_delete = function (confirmMessage) {
$("#delete").click(function(event) {
do_action("delete")();
});
};
const init_restore = function (confirmMessage) {
var init_restore = function (confirmMessage) {
$("#restore").click(function(event) {
do_action("restore")();
});
};
const refresh = function() {
var refresh = function() {
table().refresh();
}
const submit_handler = function(url) {
var submit_handler = function(url) {
return function (resource, response) {
const id = response.id !== undefined ? response.id.toString() : "";
var id = response.id !== undefined ? response.id.toString() : "";
if (!response.success) {
$.notify(response.message, { type: 'danger' });
} else {
const message = response.message;
const selector = rows_selector(response.id);
const rows = $(selector.join(",")).length;
var message = response.message;
var selector = rows_selector(response.id);
var rows = $(selector.join(",")).length;
if (rows > 0 && rows < 15) {
const ids = id.split(":");
var ids = id.split(":");
$.get([url || resource + '/row', id].join("/"), {}, function (response) {
$.each(selector, function (index, element) {
const id = $(element).data('uniqueid');
var id = $(element).data('uniqueid');
table().updateByUniqueId({id: id, row: response[id] || response});
});
dialog_support.init("a.modal-dlg");
@@ -313,7 +313,7 @@
};
};
const handle_submit = submit_handler();
var handle_submit = submit_handler();
$.extend(table_support, {
submit_handler: function(url) {
@@ -372,4 +372,4 @@ function number_sorter(a, b) {
a = +a.replace(/[^\-0-9]+/g, '');
b = +b.replace(/[^\-0-9]+/g, '');
return a - b;
}
}

View File

@@ -5,14 +5,14 @@
return document.location.protocol + '//' + url;
}
const url = http_s('nominatim.openstreetmap.org/search');
var url = http_s('nominatim.openstreetmap.org/search');
const handle_auto_completion = function(fields) {
var handle_auto_completion = function(fields) {
return function(event, ui) {
const results = ui.item.results;
var results = ui.item.results;
if (results != null && results.length > 0) {
// Handle auto completion
for(const i in fields) {
for(var i in fields) {
$("#" + fields[i]).val(results[i]);
}
return false;
@@ -21,11 +21,11 @@
};
};
const create_parser = function(field_name, parse_format)
var create_parser = function(field_name, parse_format)
{
const parse_field = function(format, address)
var parse_field = function(format, address)
{
const fields = [];
var fields = [];
$.each(format.split("|"), function(key, value)
{
if (address[value] && fields.length < 2 && $.inArray(address[value], fields) === -1)
@@ -38,11 +38,11 @@
return function(data)
{
const parsed = [];
var parsed = [];
$.each(data, function(index, value)
{
const row = [];
const address = value.address;
var row = [];
var address = value.address;
$.each(parse_format, function(key, format)
{
row.push(parse_field(format, address));
@@ -57,12 +57,12 @@
};
};
const init = function(options) {
var init = function(options) {
const default_params = function(id, key, language)
var default_params = function(id, key, language)
{
return function() {
const result = {
var result = {
format: 'json',
limit: 5,
addressdetails: 1,
@@ -75,8 +75,8 @@
};
const unique = function(parsed) {
let filtered = [];
var unique = function(parsed) {
var filtered = [];
$.each(parsed, function(index, element)
{
filtered = $.map(filtered, function(el, ind)
@@ -91,12 +91,12 @@
$.each(options.fields, function(key, value)
{
const handle_field_completion = handle_auto_completion(value.dependencies);
var handle_field_completion = handle_auto_completion(value.dependencies);
$("#" + key).autocomplete({
source: function (request, response) {
const params = default_params(key, value.response && value.response.field, options.language);
const request_params = {};
var params = default_params(key, value.response && value.response.field, options.language);
var request_params = {};
options.extra_params && $.each(options.extra_params, function(key, param) {
request_params[key] = typeof param == "function" ? param() : param;
});
@@ -122,7 +122,7 @@
});
};
const nominatim = {
var nominatim = {
init : init
@@ -130,4 +130,4 @@
window['nominatim'] = nominatim;
})(jQuery);
})(jQuery);