added method to replenish supplies.

This commit is contained in:
DESKTOP-GENO133\IvanPlex
2024-02-22 10:11:26 -07:00
parent 7099652083
commit dedf8fc2f7
4 changed files with 60 additions and 2 deletions

View File

@@ -35,7 +35,7 @@
<div class="input-group">
<input type="number" inputmode="numeric" id="reminderMileage" class="form-control" placeholder="@translator.Translate(userLanguage,"Future Odometer Reading")" value="@(isNew ? "" : Model.Mileage)">
<div class="input-group-text">
<button type="button" class="btn btn-sm btn-primary" onclick="appendMileageToOdometer(500)">+500</button>
<button type="button" class="btn btn-sm btn-primary zero-y-padding" onclick="appendMileageToOdometer(500)">+500</button>
</div>
</div>
<div class="form-check form-check-inline">

View File

@@ -31,7 +31,12 @@
<div class="row">
<div class="col-md-6 col-12">
<label for="supplyRecordQuantity">@translator.Translate(userLanguage,"Quantity")</label>
<input type="text" inputmode="decimal" id="supplyRecordQuantity" class="form-control" placeholder="@translator.Translate(userLanguage,"Quantity")" value="@(isNew ? "1" : Model.Quantity)">
<div class="input-group">
<input type="text" inputmode="decimal" id="supplyRecordQuantity" class="form-control" placeholder="@translator.Translate(userLanguage,"Quantity")" value="@(isNew ? "1" : Model.Quantity)">
<div class="input-group-text">
<button type="button" class="btn btn-sm zero-y-padding btn-primary" onclick="replenishSupplies()">+</button>
</div>
</div>
</div>
<div class="col-md-6 col-12">
<label for="supplyRecordCost">@translator.Translate(userLanguage,"Cost")</label>

View File

@@ -354,4 +354,8 @@ input[type="file"] {
}
.reminder-calendar-item{
cursor: pointer;
}
.zero-y-padding{
padding-top: 0rem;
padding-bottom: 0rem;
}

View File

@@ -890,4 +890,53 @@ function getAndValidateGenericRecordValues() {
tags: genericTags
}
}
}
function replenishSupplies() {
Swal.fire({
title: 'Replenish Supplies',
html: `
<input type="text" id="inputSupplyAddQuantity" class="swal2-input" placeholder="Quantity">
<br />
<input type="text" id="inputSupplyAddCost" class="swal2-input" placeholder="Cost">
<br />
<span class='small'>leave blank to use unit cost calculation</span>
`,
confirmButtonText: 'Replenish',
focusConfirm: false,
preConfirm: () => {
const replquantity = globalParseFloat($("#inputSupplyAddQuantity").val());
const replcost = $("#inputSupplyAddCost").val();
const parsedReplCost = globalParseFloat(replcost);
var quantitybeforeRepl = globalParseFloat($('#supplyRecordQuantity').val());
if (isNaN(replquantity) || (replcost.trim() != '' && isNaN(parsedReplCost))) {
Swal.showValidationMessage(`Please enter a valid quantity and cost`);
} else if (replcost.trim() == '' && (isNaN(quantitybeforeRepl) || quantitybeforeRepl == 0)){
Swal.showValidationMessage(`Unable to use unit cost calculation, please provide cost`);
}
return { replquantity, replcost, parsedReplCost }
},
}).then(function (result) {
if (result.isConfirmed) {
var replenishedCost = result.value.replcost;
var parsedReplenishedCost = result.value.parsedReplCost;
var replenishedQuantity = result.value.replquantity;
var currentCost = globalParseFloat($('#supplyRecordCost').val())
var currentQuantity = globalParseFloat($('#supplyRecordQuantity').val());
var newQuantity = currentQuantity + replenishedQuantity;
if (replenishedCost.trim() == '') {
var unitCost = currentCost / currentQuantity;
var newCost = newQuantity * unitCost;
//set text fields.
$('#supplyRecordCost').val(globalFloatToString(newCost.toFixed(3).toString()));
$('#supplyRecordQuantity').val(globalFloatToString(newQuantity.toFixed(3).toString()));
} else {
var newCost = currentCost + parsedReplenishedCost;
//set text fields.
$('#supplyRecordCost').val(globalFloatToString(newCost.toFixed(3).toString()));
$('#supplyRecordQuantity').val(globalFloatToString(newQuantity.toFixed(3).toString()));
}
}
});
}