Files
opensourcepos/app/Views/reports/tabular_details.php
objecttothis 29a9b1a7e7 Bugfix: Resolve Race Condition in Rewards and Gift Card Spending (#4640)
* Implement atomic updates for gift card and reward point decrements, enhance error handling for insufficient balances, and add regression tests for concurrency safety.

* Add translations for insufficient gift card balance and reward points error messages across all supported languages.

* Reorder `clear_suspended_sale_detail` call to ensure transactional consistency.

* Reorder `clear_all` call to align with success and error handling logic.

* Ensure soft-deleted gift cards are excluded in balance updates.

* Refactor change_quantity logic with atomic upserts, improve error handling for insufficient stock, and update related tests and constants.

* Added check for NEW_ENTRY

* Added unit tests to test changes.

* Fix class name casing in ItemQuantityTest for consistency.

* Fix Bulgarian translations for insufficient balance error messages in Sales module.

* Fix Greek translations for insufficient balance error messages in Sales module.

* Fix Armenian translations for insufficient balance error messages in Sales module.

* Fix Tamil translations for insufficient balance error messages in Sales module.

* Implement race condition testing for database methods with concurrent process support.

* Fix class name casing in ItemTest for consistency.

* Improve concurrent process handling in race condition tests; add readiness and synchronization barriers.

* Improve handling of process I/O streams and timeout management in race condition tests.

* Add test for decrementing gift card value when marked as deleted

* Add `finally` block to ensure proper cleanup in async database race condition tests

* Improve error handling and timeout management in async database race condition tests.

* Refactor test utilities to use shared `EmployeeFixtureTrait` and `ItemFixtureTrait`.

* Track process exit codes explicitly in race condition tests for improved error detection and debugging.

* Improve error handling in `ConcurrentDbRaceTrait` by adding exceptions for `mysqli_poll` and `mysqli_reap_async_query`.

Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>

---------

Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
2026-08-20 02:24:23 +04:00

96 lines
3.5 KiB
PHP

<?php
/**
* @var string $title
* @var string $subtitle
* @var array $overall_summary_data
* @var array $details_data
* @var array $headers
* @var array $summary_data
* @var array $config
*/
?>
<?= view('partial/header') ?>
<div id="page_title"><?= esc($title) ?></div>
<div id="page_subtitle"><?= esc($subtitle) ?></div>
<div id="toolbar">
<div class="pull-left form-inline" role="toolbar">
<!-- Toggle Button -->
<button id="toggleCostProfitButton" class="btn btn-default btn-sm print_hide">
<?php echo lang('Reports.toggle_cost_and_profit'); ?>
</button>
</div>
</div>
<div id="table_holder">
<table id="table"></table>
</div>
<div id="report_summary">
<?php foreach ($overall_summary_data as $name => $value) { ?>
<div class="summary_row"><?= lang("Reports.$name") . ': ' . esc(to_currency($value)) ?></div>
<?php } ?>
</div>
<script type="text/javascript">
$(document).ready(function () {
<?= view('partial/bootstrap_tables_locale') ?>
const 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)) ?>;
<?php } ?>
<?= view('partial/visibility_js') ?>
$('#table')
.addClass("table-striped")
.addClass("table-bordered")
.bootstrapTable({
columns: applyColumnVisibility(<?= transform_headers(esc($headers['summary']), true) ?>),
stickyHeader: true,
stickyHeaderOffsetLeft: $('#table').offset().left + 'px',
stickyHeaderOffsetRight: $('#table').offset().right + 'px',
pageSize: <?= $config['lines_per_page'] ?>,
pagination: true,
sortable: true,
showColumns: true,
uniqueId: 'id',
showExport: true,
exportDataType: 'all',
exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'xlsx', 'pdf'],
data: <?= json_encode($summary_data) ?>,
iconSize: 'sm',
paginationVAlign: 'bottom',
detailView: true,
escape: true,
search: true,
onPageChange: init_dialog,
onPostBody: function () {
dialog_support.init("a.modal-dlg");
},
onExpandRow: function (index, row, $detail) {
$detail.html('<table></table>').find("table").bootstrapTable({
columns: <?= transform_headers_readonly(esc($headers['details'])) ?>,
data: details_data[(!isNaN(row.id) && row.id) || $(row[0] || row.id).text().replace(
/(POS|RECV)\s*/g, '')]
});
<?php if ($config['customer_reward_enable'] && !empty($details_data_rewards)) { ?>
$detail.append('<table></table>').find("table").bootstrapTable({
columns: <?= transform_headers_readonly(esc($headers['details_rewards'])) ?>,
data: details_data_rewards[(!isNaN(row.id) && row.id) || $(row[0] || row.id).text().replace(
/(POS|RECV)\s*/g, '')]
});
<?php } ?>
}
});
init_dialog();
});
</script>
<?= view('partial/footer') ?>