Files
6e273a2fb1 refactor: Replace var with let/const in JavaScript files (#4503)
* refactor: Replace var with let/const in JavaScript files

- Replace var with let for variables that are reassigned
- Replace var with const for variables that are never reassigned
- Modernize manage_tables.js and nominatim.autocomplete.js
- Skip third-party libraries (imgpreview.full.jquery.js, clipboard.min.js)

Closes #4491

* refactor: Replace var with let/const in inline JavaScript

- Fixed CodeRabbit review: changed enable_actions and load_success
  from const to let in manage_tables.js (they are reassigned in init)
- Replaced all var declarations in inline JavaScript in Views with
  let (for reassigned) or const (for never reassigned)
- Modernized 48 additional files with inline JavaScript

* refactor: Replace var with let/const in remaining JS files

- Modernized gulpfile.js: 3 var declarations replaced
- Modernized app/Views/errors/html/debug.js: all var declarations replaced
- Used const for never-reassigned, let for reassigned variables

* fix: Replace remaining var declarations in Views

- Changed var  to const in sales/register.php
- Changed var  to const in configs/receipt_config.php

These were missed in the initial pass.

* fix: Replace remaining var declarations in gulpfile.js

- Converted 12 remaining var declarations to const
- All variables are function-scoped and never reassigned
- Complete coverage for this file now

* fix: Address CodeRabbit review comments

- items/manage.php: Remove duplicate let declaration for start_date
  (partial/daterangepicker already declares it)
- header_js.php: Escape CSRF hash in JavaScript context
- tax_jurisdictions.php: Fix mismatched selector (remove_tax_jurisdictions
  -> remove_tax_jurisdiction)

* style(views): Replace var with let/const and fix comment casing

- Convert var to let in items/manage.php for JS modernization
- Capitalize \"Submit\" in validation comments across tax view files

Signed-off-by: Travis Garrison <travis@chiraqbookstore.com>

---------

Signed-off-by: Travis Garrison <travis@chiraqbookstore.com>
Co-authored-by: Ollama <ollama@steganos.dev>
Co-authored-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
Co-authored-by: Travis Garrison <travis@chiraqbookstore.com>
2026-08-06 12:15:45 +04:00

71 lines
2.9 KiB
PHP

<?php
/**
* @var string $selected_printer
* @var bool $print_after_sale
* @var array $config
*/
?>
<script type="text/javascript">
function printdoc() {
// Install Firefox addon in order to use this plugin
if (window.jsPrintSetup) {
// Set top margins in millimeters
jsPrintSetup.setOption('marginTop', '<?= $config['print_top_margin'] ?>');
jsPrintSetup.setOption('marginLeft', '<?= $config['print_left_margin'] ?>');
jsPrintSetup.setOption('marginBottom', '<?= $config['print_bottom_margin'] ?>');
jsPrintSetup.setOption('marginRight', '<?= $config['print_right_margin'] ?>');
<?php if (!$config['print_header']) { ?>
// Set page header
jsPrintSetup.setOption('headerStrLeft', '');
jsPrintSetup.setOption('headerStrCenter', '');
jsPrintSetup.setOption('headerStrRight', '');
<?php } ?>
<?php if (!$config['print_footer']) { ?>
// Set empty page footer
jsPrintSetup.setOption('footerStrLeft', '');
jsPrintSetup.setOption('footerStrCenter', '');
jsPrintSetup.setOption('footerStrRight', '');
<?php } ?>
const 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];
if (selected_printer == default_ticket_printer) {
// Select Epson label printer
jsPrintSetup.setPrinter(selected_printer);
// Clears user preferences always silent print value
// to enable using 'printSilent' option
jsPrintSetup.clearSilentPrint();
<?php if (!$config['print_silently']) { ?>
// Suppress print dialog (for this context only)
jsPrintSetup.setOption('printSilent', 1);
<?php } ?>
// Do Print
// When print is submitted it is executed asynchronous and
// script flow continues after print independently of completetion of print process!
jsPrintSetup.print();
}
}
} else {
window.print();
}
}
<?php if ($print_after_sale) { ?>
$(window).on('load', (function() {
// Executes when complete page is fully loaded, including all frames, objects and images
printdoc();
// After a delay, return to sales view
setTimeout(function() {
window.location.href = "<?= site_url('sales') ?>";
}, <?= $config['print_delay_autoreturn'] * 1000 ?>);
}));
<?php } ?>
</script>