|
Lines 136-141
Link Here
|
| 136 |
type_fees['[% debit_type.code | html %]'] = "[% IF debit_type.default_amount %][% debit_type.default_amount | $Price on_editing => 1 %][% END %]"; |
136 |
type_fees['[% debit_type.code | html %]'] = "[% IF debit_type.default_amount %][% debit_type.default_amount | $Price on_editing => 1 %][% END %]"; |
| 137 |
[% END %] |
137 |
[% END %] |
| 138 |
$(document).ready(function(){ |
138 |
$(document).ready(function(){ |
|
|
139 |
|
| 140 |
document.getElementById('barcode').addEventListener('input', function () { |
| 141 |
var barcode = this.value; |
| 142 |
if (barcode.length > 0) { |
| 143 |
fetchReplacementPrice(barcode); |
| 144 |
} |
| 145 |
}); |
| 146 |
|
| 147 |
function fetchReplacementPrice(barcode) { |
| 148 |
$.ajax({ |
| 149 |
url: `/api/v1/items?external_id=${barcode}`, |
| 150 |
method: 'GET', |
| 151 |
dataType: 'json', |
| 152 |
success: function (data) { |
| 153 |
// Check if data is an array and has at least one item |
| 154 |
if (Array.isArray(data) && data.length > 0) { |
| 155 |
// Filter the data to find the item with an exact barcode match |
| 156 |
var matchedItem = data.find(item => item.external_id === barcode); |
| 157 |
|
| 158 |
if (matchedItem) { |
| 159 |
var replacementPrice = matchedItem.replacement_price || matchedItem.purchase_price; |
| 160 |
if (replacementPrice !== null && replacementPrice !== undefined) { |
| 161 |
$('#amount').val(replacementPrice.toFixed(2)); |
| 162 |
return; |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
var selectedType = $('#type').val(); |
| 167 |
$('#amount').val(type_fees[selectedType] || ''); |
| 168 |
}, |
| 169 |
error: function() { |
| 170 |
alert( _("An error occurred. Check the logs for details.") ); |
| 171 |
} |
| 172 |
}); |
| 173 |
} |
| 174 |
|
| 139 |
$('#maninvoice').preventDoubleFormSubmit(); |
175 |
$('#maninvoice').preventDoubleFormSubmit(); |
| 140 |
$("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit"); |
176 |
$("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit"); |
| 141 |
$("#invoice_type").on("change",function(){ |
177 |
$("#invoice_type").on("change",function(){ |
| 142 |
- |
|
|