Compare commits
No commits in common. "45199030a04e6ba291d232d2482e64430f194c68" and "efad80970b4876b9c78a296a14e76236c16c91d9" have entirely different histories.
45199030a0
...
efad80970b
@ -1,50 +0,0 @@
|
|||||||
const quantity_lineRegexSelector = `[id^="${idPrefix}"][id$="${quantitySuffix}"]`;
|
|
||||||
const price_lineRegexSelector = `[id^="${idPrefix}"][id$="${priceSuffix}"]`;
|
|
||||||
|
|
||||||
function insertSubtotalField() {
|
|
||||||
// Selecciona la fila de precio unitario para añadir la fila del subtotal después de ella
|
|
||||||
const unitPriceRow = document.querySelector('input[id="id_saleline_set-0-unit_price"]').closest('tr');
|
|
||||||
|
|
||||||
// Crear una nueva fila para el subtotal
|
|
||||||
const subtotalRow = document.createElement('tr');
|
|
||||||
subtotalRow.innerHTML = `
|
|
||||||
<th><label for="id_saleline_set-0-subtotal">Subtotal:</label></th>
|
|
||||||
<td><input type="number" name="saleline_set-0-subtotal" id="id_saleline_set-0-subtotal" readonly></td>
|
|
||||||
`;
|
|
||||||
|
|
||||||
// Insertar la fila del subtotal después de la fila del precio unitario
|
|
||||||
unitPriceRow.after(subtotalRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateSubtotal(id) {
|
|
||||||
const quantityElement = document.getElementById(`id_saleline_set-${id}-quantity`);
|
|
||||||
const unitPriceElement = document.getElementById(`id_saleline_set-${id}-unit_price`);
|
|
||||||
const subtotalElement = document.getElementById(`id_saleline_set-${id}-subtotal`);
|
|
||||||
|
|
||||||
const quantity = parseFloat(quantityElement.value) || 0;
|
|
||||||
const unitPrice = parseFloat(unitPriceElement.value) || 0;
|
|
||||||
const subtotal = quantity * unitPrice;
|
|
||||||
|
|
||||||
subtotalElement.value = subtotal.toFixed(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inserta el campo subtotal al cargar la página
|
|
||||||
window.addEventListener('load', () => {
|
|
||||||
insertSubtotalField();
|
|
||||||
|
|
||||||
complete_form.addEventListener('change', function(event){
|
|
||||||
const quantityInputs = document.querySelectorAll(quantity_lineRegexSelector);
|
|
||||||
const ids = Array.prototype.map.call(quantityInputs, function(input) {
|
|
||||||
return input.id.match(/\d+/)[0];
|
|
||||||
});
|
|
||||||
|
|
||||||
ids.forEach(function(id) {
|
|
||||||
if (event.target.matches(quantity_lineRegexSelector)) {
|
|
||||||
calculateSubtotal(id);
|
|
||||||
}
|
|
||||||
if (event.target.matches(price_lineRegexSelector)) {
|
|
||||||
calculateSubtotal(id);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
|
@ -18,5 +18,4 @@
|
|||||||
<br/><button name="form" type="submit" >Comprar</button>
|
<br/><button name="form" type="submit" >Comprar</button>
|
||||||
<script src="{% static 'js/add_line.js' %}"></script>
|
<script src="{% static 'js/add_line.js' %}"></script>
|
||||||
<script src="{% static 'js/sale_summary.js' %}"></script>
|
<script src="{% static 'js/sale_summary.js' %}"></script>
|
||||||
<script src="{% static 'js/calculate_subtotal_line.js' %}"></script>
|
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
Reference in New Issue
Block a user