Allow users to add supplies onto existing records.

This commit is contained in:
DESKTOP-T0O5CDB\DESK-555BD
2024-11-20 20:48:38 -07:00
parent 8a8d8979a7
commit 1988cf54f5
11 changed files with 66 additions and 36 deletions

View File

@@ -0,0 +1,8 @@
namespace CarCareTracker.Models
{
public class SupplyRequisitionHistory
{
public string CostInputId { get; set; }
public List<SupplyUsageHistory> RequisitionHistory { get; set; } = new List<SupplyUsageHistory>();
}
}

View File

@@ -0,0 +1,8 @@
namespace CarCareTracker.Models
{
public class SupplyStore
{
public string Tab { get; set; }
public bool AdditionalSupplies { get; set; }
}
}

View File

@@ -44,10 +44,7 @@
}
<label for="collisionRecordCost">@translator.Translate(userLanguage, "Cost")</label>
<input type="text" inputmode="decimal" onkeydown="interceptDecimalKeys(event)" onkeyup="fixDecimalInput(this, 2)" id="collisionRecordCost" class="form-control" placeholder="@translator.Translate(userLanguage,"Cost of the repair")" value="@(isNew ? "" : Model.Cost)">
@if (isNew)
{
@await Html.PartialAsync("_SupplyStore", "RepairRecord")
}
@await Html.PartialAsync("_SupplyStore", new SupplyStore { Tab = "RepairRecord", AdditionalSupplies = Model.RequisitionHistory.Any() })
<label for="collisionRecordTag">@translator.Translate(userLanguage, "Tags(optional)")</label>
<select multiple class="form-select" id="collisionRecordTag">
@foreach (string tag in Model.Tags)
@@ -126,7 +123,7 @@
<button type="button" class="btn btn-primary" onclick="saveCollisionRecordToVehicle(true)">@translator.Translate(userLanguage, "Edit Repair Record")</button>
}
</div>
@await Html.PartialAsync("_SupplyRequisitionHistory", Model.RequisitionHistory)
@await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "collisionRecordCost" })
<script>
var uploadedFiles = [];
var selectedSupplies = [];

View File

@@ -21,10 +21,7 @@
<input type="text" id="planRecordDescription" class="form-control" placeholder="@translator.Translate(userLanguage, "Describe the Plan")" value="@Model.Description">
<label for="planRecordCost">@translator.Translate(userLanguage, "Cost")</label>
<input type="text" inputmode="decimal" onkeydown="interceptDecimalKeys(event)" onkeyup="fixDecimalInput(this, 2)" id="planRecordCost" class="form-control" placeholder="@translator.Translate(userLanguage, "Cost of the Plan")" value="@Model.Cost">
@if (isNew)
{
@await Html.PartialAsync("_SupplyStore", "PlanRecord")
}
@await Html.PartialAsync("_SupplyStore", new SupplyStore { Tab = "PlanRecord", AdditionalSupplies = Model.RequisitionHistory.Any() })
<label for="planRecordType">@translator.Translate(userLanguage, "Type")</label>
<select class="form-select" id="planRecordType">
<!option value="ServiceRecord" @(Model.ImportMode == ImportMode.ServiceRecord || isNew ? "selected" : "")>@translator.Translate(userLanguage, "Service")</!option>
@@ -108,7 +105,7 @@
<button type="button" class="btn btn-primary" onclick="savePlanRecordToVehicle(true)">@translator.Translate(userLanguage, "Edit Plan Record")</button>
}
</div>
@await Html.PartialAsync("_SupplyRequisitionHistory", Model.RequisitionHistory)
@await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "planRecordCost" })
<script>
var uploadedFiles = [];
var selectedSupplies = [];

View File

@@ -21,7 +21,7 @@
<input type="text" id="planRecordDescription" class="form-control" placeholder="@translator.Translate(userLanguage, "Describe the Plan")" value="@Model.Description">
<label for="planRecordCost">@translator.Translate(userLanguage, "Cost")</label>
<input type="text" inputmode="decimal" onkeydown="interceptDecimalKeys(event)" onkeyup="fixDecimalInput(this, 2)" id="planRecordCost" class="form-control" placeholder="@translator.Translate(userLanguage, "Cost of the Plan")" value="@Model.Cost">
@await Html.PartialAsync("_SupplyStore", "PlanRecordTemplate")
@await Html.PartialAsync("_SupplyStore", new SupplyStore { Tab = "PlanRecordTemplate", AdditionalSupplies = Model.RequisitionHistory.Any() })
<label for="planRecordType">@translator.Translate(userLanguage, "Type")</label>
<select class="form-select" id="planRecordType">
<!option value="ServiceRecord" @(Model.ImportMode == ImportMode.ServiceRecord || isNew ? "selected" : "")>@translator.Translate(userLanguage, "Service")</!option>
@@ -85,7 +85,7 @@
<button type="button" class="btn btn-secondary" onclick="hideAddPlanRecordModal()">@translator.Translate(userLanguage, "Cancel")</button>
<button type="button" class="btn btn-primary" onclick="savePlanRecordTemplate(true)">@translator.Translate(userLanguage, "Edit Plan Record Template")</button>
</div>
@await Html.PartialAsync("_SupplyRequisitionHistory", Model.RequisitionHistory)
@await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "planRecordCost" })
<script>
var uploadedFiles = [];
var selectedSupplies = [];

View File

@@ -44,10 +44,7 @@
}
<label for="serviceRecordCost">@translator.Translate(userLanguage,"Cost")</label>
<input type="text" inputmode="decimal" onkeydown="interceptDecimalKeys(event)" onkeyup="fixDecimalInput(this, 2)" id="serviceRecordCost" class="form-control" placeholder="@translator.Translate(userLanguage,"Cost of the service")" value="@(isNew ? "" : Model.Cost)">
@if (isNew)
{
@await Html.PartialAsync("_SupplyStore", "ServiceRecord")
}
@await Html.PartialAsync("_SupplyStore", new SupplyStore { Tab = "ServiceRecord", AdditionalSupplies = Model.RequisitionHistory.Any() })
<label for="serviceRecordTag">@translator.Translate(userLanguage,"Tags(optional)")</label>
<select multiple class="form-select" id="serviceRecordTag">
@foreach(string tag in Model.Tags)
@@ -126,7 +123,7 @@
<button type="button" class="btn btn-primary" onclick="saveServiceRecordToVehicle(true)">@translator.Translate(userLanguage,"Edit Service Record")</button>
}
</div>
@await Html.PartialAsync("_SupplyRequisitionHistory", Model.RequisitionHistory)
@await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "serviceRecordCost" })
<script>
var uploadedFiles = [];
var selectedSupplies = [];

View File

@@ -102,7 +102,7 @@
<button type="button" class="btn btn-primary" onclick="saveSupplyRecordToVehicle(true)">@translator.Translate(userLanguage,"Edit Supply Record")</button>
}
</div>
@await Html.PartialAsync("_SupplyRequisitionHistory", Model.RequisitionHistory)
@await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "" })
<script>
var uploadedFiles = [];
getUploadedFilesFromModel();

View File

@@ -1,16 +1,25 @@
@using CarCareTracker.Helper
@inject IConfigHelper config
@inject ITranslationHelper translator
@model List<SupplyUsageHistory>
@model SupplyRequisitionHistory
@{
var userConfig = config.GetUserConfig(User);
var userLanguage = userConfig.UserLanguage;
var showDelete = Model.All(x => x.Id != default);
var showPartNumber = Model.Any(x => !string.IsNullOrWhiteSpace(x.PartNumber));
var showDelete = Model.RequisitionHistory.All(x => x.Id != default);
var showPartNumber = Model.RequisitionHistory.Any(x => !string.IsNullOrWhiteSpace(x.PartNumber));
}
<script>
var supplyUsageHistory = [];
var deletedSupplyUsageHistory = [];
function subtractFromCostInput(costToSubtract){
let costInputId = '@Model.CostInputId';
let costInput = $(`#${costInputId}`);
let newCostAmount = globalParseFloat(costInput.val()) - globalParseFloat(costToSubtract);
if (newCostAmount < 0){
newCostAmount = 0;
}
costInput.val(globalFloatToString(newCostAmount.toFixed(2)));
}
function deleteSupplyUsageHistory(supplyId, quantity, cost, supplyRow){
deletedSupplyUsageHistory.push({
id: decodeHTMLEntities(supplyId),
@@ -19,6 +28,8 @@
});
supplyUsageHistory = supplyUsageHistory.filter(x=>x.id != decodeHTMLEntities(supplyId));
$(supplyRow).parents(".supply-row").remove();
//update cost input value
subtractFromCostInput(decodeHTMLEntities(cost));
}
</script>
<div id="supplyUsageHistoryModalContainer" class="d-none">
@@ -26,7 +37,7 @@
<h5 class="modal-title">@translator.Translate(userLanguage, "Supply Requisition History")</h5>
</div>
<div class="modal-body">
@if (Model.Any())
@if (Model.RequisitionHistory.Any())
{
<div class="row">
<div class="col-12" style="max-height:50vh; overflow-y:auto;">
@@ -49,7 +60,7 @@
</tr>
</thead>
<tbody>
@foreach (SupplyUsageHistory usageHistory in Model)
@foreach (SupplyUsageHistory usageHistory in Model.RequisitionHistory)
{
<script>
supplyUsageHistory.push({ id: decodeHTMLEntities("@usageHistory.Id"), date: decodeHTMLEntities("@usageHistory.Date.ToShortDateString()"), partNumber: decodeHTMLEntities('@usageHistory.PartNumber'), description: decodeHTMLEntities("@usageHistory.Description"), quantity: decodeHTMLEntities("@usageHistory.Quantity.ToString("F")"), cost: decodeHTMLEntities("@usageHistory.Cost.ToString("F")") })

View File

@@ -5,36 +5,51 @@
var userConfig = config.GetUserConfig(User);
var userLanguage = userConfig.UserLanguage;
}
@model string
@model SupplyStore
<div class="row">
<div class="col-12">
<a onclick="showSuppliesModal()" class="btn btn-link">@translator.Translate(userLanguage,"Choose Supplies")</a>
<a onclick="showSuppliesModal()" class="btn btn-link">@translator.Translate(userLanguage,Model.AdditionalSupplies ? "Choose Additional Supplies" : "Choose Supplies")</a>
</div>
</div>
<script>
resetSuppliesModal();
function GetCaller() {
return { tab: '@Model' };
return {
tab: '@Model.Tab',
addToSum: @Model.AdditionalSupplies.ToString().ToLower()
};
}
function resetSuppliesModal() {
$("#inputSuppliesModalContent").html("");
}
function setCostInputWithSupplySum(selectedSum, input){
var addToSum = GetCaller().addToSum;
if (addToSum){
//sum of all requisitioned supplies
var currentSum = supplyUsageHistory.length > 0 ? supplyUsageHistory.map(x => globalParseFloat(x.cost)).reduce((a,b) => a + b) : 0;
selectedSum = globalParseFloat(selectedSum);
var newSum = currentSum + selectedSum;
input.val(globalFloatToString(newSum.toFixed(2)));
} else {
input.val(selectedSum);
}
}
function selectSupplies() {
var selectedSupplyResult = getSuppliesAndQuantity();
var caller = GetCaller().tab;
switch (caller) {
case "ServiceRecord":
$('#serviceRecordCost').val(selectedSupplyResult.totalSum);
setCostInputWithSupplySum(selectedSupplyResult.totalSum, $('#serviceRecordCost'))
break;
case "RepairRecord":
$('#collisionRecordCost').val(selectedSupplyResult.totalSum);
setCostInputWithSupplySum(selectedSupplyResult.totalSum, $('#collisionRecordCost'))
break;
case "UpgradeRecord":
$('#upgradeRecordCost').val(selectedSupplyResult.totalSum);
setCostInputWithSupplySum(selectedSupplyResult.totalSum, $('#upgradeRecordCost'))
break;
case "PlanRecord":
case "PlanRecordTemplate":
$('#planRecordCost').val(selectedSupplyResult.totalSum);
setCostInputWithSupplySum(selectedSupplyResult.totalSum, $('#planRecordCost'))
break;
}
selectedSupplies = getSuppliesAndQuantity().selectedSupplies;

View File

@@ -44,10 +44,7 @@
}
<label for="upgradeRecordCost">@translator.Translate(userLanguage, "Cost")</label>
<input type="text" inputmode="decimal" onkeydown="interceptDecimalKeys(event)" onkeyup="fixDecimalInput(this, 2)" id="upgradeRecordCost" class="form-control" placeholder="@translator.Translate(userLanguage,"Cost of the upgrade/mods")" value="@(isNew ? "" : Model.Cost)">
@if (isNew)
{
@await Html.PartialAsync("_SupplyStore", "UpgradeRecord")
}
@await Html.PartialAsync("_SupplyStore", new SupplyStore { Tab = "UpgradeRecord", AdditionalSupplies = Model.RequisitionHistory.Any() })
<label for="upgradeRecordTag">@translator.Translate(userLanguage, "Tags(optional)")</label>
<select multiple class="form-select" id="upgradeRecordTag">
@foreach (string tag in Model.Tags)
@@ -126,7 +123,7 @@
<button type="button" class="btn btn-primary" onclick="saveUpgradeRecordToVehicle(true)">@translator.Translate(userLanguage, "Edit Upgrade Record")</button>
}
</div>
@await Html.PartialAsync("_SupplyRequisitionHistory", Model.RequisitionHistory)
@await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "upgradeRecordCost" })
<script>
var uploadedFiles = [];
var selectedSupplies = [];

File diff suppressed because one or more lines are too long