mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-10-28 19:18:58 -04:00
Refactor Stock_location model to camelCase naming and introduce
is_default and sort_order fields with full migration, UI, and
item-sync support. Multiple follow-up fixes consolidated.
Database
- Add is_default (TINYINT, backfilled to oldest non-deleted row) and
sort_order (nullable unsigned TINYINT unique, dense 0..N-1) columns
via new migration; MySQL 5.7-compatible backfill using user variables
instead of ROW_NUMBER(); down() drops both columns
Model
- Rename show_locations → showLocations (camelCase convention)
- Add getDefaultLocationId(), setDefaultLocation(), saveSortOrder();
validate location existence before setting as default
- delete() compacts sort_order via two-pass CASE update to avoid
collisions after prior reorders
- Atomic sort_order assignment via explicit SQL COUNT query
Controller / Config
- Modularize save logic into sanitizeSubmittedLocations(),
deleteRemovedLocations(), saveSubmittedLocations(),
saveLocationOrderAndDefault(); wrap in single transaction
- Support stock_location_new inputs for new-row creation
- Resolve new-* ID placeholders to real IDs post-save
- Abort loop on save failure; default missing POST arrays to []
- Validate that at least one location array is non-empty
Views
- Add Default column with center-aligned radio buttons; disable for
unsaved rows; use attr() instead of data() for location IDs
- Escape dynamic location IDs against XSS in all affected partials
- form_count_details.php: fall back to default location when current
is undefined; guard quantity input similarly
- Add aria-label to default radio inputs
Libraries / Items
- Widen Item_lib::get_item_location() and get_stock_destination() to
nullable return types
- Guard null location_id in Items::getRow() and getGenerateBarcodes()
- Item::get_multiple_info(): accept ?int $location_id; short-circuit
with where('item_id', -1) instead of always-false where('1','0')
i18n
- Add stock_location_default, stock_location_default_header,
stock_location_name_header across all locale files
Tests
- Stock_locationTest: getDefaultLocationId, setDefaultLocation,
saveSortOrder, delete compaction, saveValue; rename to
testMethod_Scenario convention
- Add ConfigControllerTest / StockLocationsControllerTest with
AdminAuthTrait covering CRUD, reorder, default assignment, and
malformed/empty/blank payload validation
- DatabaseBootstrapTrait-based setup for ItemTest and Stock_locationTest
Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
144 lines
5.5 KiB
PHP
144 lines
5.5 KiB
PHP
<?php
|
|
/**
|
|
* @var object $item_info
|
|
* @var array $stock_locations
|
|
* @var int|null $stock_location
|
|
* @var array $item_quantities
|
|
* @var string $controller_name
|
|
*/
|
|
?>
|
|
|
|
<div id="required_fields_message"><?= lang('Common.fields_required_message') ?></div>
|
|
<ul id="error_message_box" class="error_message_box"></ul>
|
|
|
|
<?= form_open("items/saveInventory/$item_info->item_id", ['id' => 'item_form', 'class' => 'form-horizontal']) ?>
|
|
<fieldset id="inv_item_basic_info">
|
|
|
|
<div class="form-group form-group-sm">
|
|
<?= form_label(lang('Items.item_number'), 'name', ['class' => 'control-label col-xs-3']) ?>
|
|
<div class="col-xs-8">
|
|
<div class="input-group">
|
|
<span class="input-group-addon input-sm"><span class="glyphicon glyphicon-barcode"></span></span>
|
|
<?= form_input([
|
|
'name' => 'item_number',
|
|
'id' => 'item_number',
|
|
'class' => 'form-control input-sm',
|
|
'disabled' => '',
|
|
'value' => $item_info->item_number
|
|
]) ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group form-group-sm">
|
|
<?= form_label(lang('Items.name'), 'name', ['class' => 'control-label col-xs-3']) ?>
|
|
<div class="col-xs-8">
|
|
<?= form_input([
|
|
'name' => 'name',
|
|
'id' => 'name',
|
|
'class' => 'form-control input-sm',
|
|
'disabled' => '',
|
|
'value' => $item_info->name
|
|
]) ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group form-group-sm">
|
|
<?= form_label(lang('Items.category'), 'category', ['class' => 'control-label col-xs-3']) ?>
|
|
<div class="col-xs-8">
|
|
<div class="input-group">
|
|
<span class="input-group-addon input-sm"><span class="glyphicon glyphicon-tag"></span></span>
|
|
<?= form_input([
|
|
'name' => 'category',
|
|
'id' => 'category',
|
|
'class' => 'form-control input-sm',
|
|
'disabled' => '',
|
|
'value' => $item_info->category
|
|
]) ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group form-group-sm">
|
|
<?= form_label(lang('Items.stock_location'), 'stock_location', ['class' => 'control-label col-xs-3']) ?>
|
|
<div class="col-xs-8">
|
|
<?= form_dropdown('stock_location', $stock_locations, $stock_location, ['onchange' => 'fill_quantity(this.value)', 'class' => 'form-control']) ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group form-group-sm">
|
|
<?= form_label(lang('Items.current_quantity'), 'quantity', ['class' => 'control-label col-xs-3']) ?>
|
|
<div class="col-xs-4">
|
|
<?= form_input([
|
|
'name' => 'quantity',
|
|
'id' => 'quantity',
|
|
'class' => 'form-control input-sm',
|
|
'disabled' => '',
|
|
'value' => to_quantity_decimals($item_quantities[$stock_location] ?? current($item_quantities))
|
|
]) ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group form-group-sm">
|
|
<?= form_label(lang('Items.add_minus'), 'quantity', ['class' => 'control-label col-xs-3 text-danger required']) ?>
|
|
<div class="col-xs-4">
|
|
<?= form_input([
|
|
'name' => 'newquantity',
|
|
'id' => 'newquantity',
|
|
'class' => 'form-control input-sm'
|
|
]) ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group form-group-sm">
|
|
<?= form_label(lang('Items.inventory_comments'), 'description', ['class' => 'control-label col-xs-3']) ?>
|
|
<div class="col-xs-8">
|
|
<?= form_textarea([
|
|
'name' => 'trans_comment',
|
|
'id' => 'trans_comment',
|
|
'class' => 'form-control input-sm'
|
|
]) ?>
|
|
</div>
|
|
</div>
|
|
|
|
</fieldset>
|
|
<?= form_close() ?>
|
|
|
|
<script type="text/javascript">
|
|
// Validation and submit handling
|
|
$(document).ready(function() {
|
|
$('#item_form').validate($.extend({
|
|
submitHandler: function(form) {
|
|
$(form).ajaxSubmit({
|
|
success: function(response) {
|
|
dialog_support.hide();
|
|
table_support.handle_submit("<?= esc($controller_name) ?>", response);
|
|
},
|
|
dataType: 'json'
|
|
});
|
|
},
|
|
|
|
errorLabelContainer: '#error_message_box',
|
|
|
|
rules: {
|
|
newquantity: {
|
|
required: true,
|
|
number: true
|
|
}
|
|
},
|
|
|
|
messages: {
|
|
newquantity: {
|
|
required: "<?= lang('Items.quantity_required') ?>",
|
|
number: "<?= lang('Items.quantity_number') ?>"
|
|
}
|
|
}
|
|
}, form_support.error));
|
|
});
|
|
|
|
function fill_quantity(val) {
|
|
const item_quantities = <?= json_encode(esc($item_quantities, 'raw')) ?>;
|
|
document.getElementById('quantity').value = parseFloat(item_quantities[val]).toFixed(<?= quantity_decimals() ?>);
|
|
}
|
|
</script>
|