From a7e86bccdac02c733a72a4396db00ce00304cc8d Mon Sep 17 00:00:00 2001 From: acatchpole Date: Fri, 13 Sep 2024 09:30:57 -0700 Subject: [PATCH 1/5] delete working with groupid Co-authored-by: dallascrichmond Co-authored-by: PaulG --- .../Controllers/NutrientsController.cs | 32 +++++-------------- .../Views/Nutrients/FertigationDetails.cshtml | 1 + .../Components/CalcFertigation/Default.cshtml | 10 +++--- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs index 12e5569e..6ef8f3d1 100644 --- a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs +++ b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs @@ -255,7 +255,7 @@ public IActionResult ManureDetails(string fldName, int? id) return PartialView(mvm); } - public IActionResult FertigationDetails(string fldName, int? id) + public IActionResult FertigationDetails(string fldName, int? id, string? groupID) { var fgvm = new FertigationDetailsViewModel() { @@ -264,6 +264,7 @@ public IActionResult FertigationDetails(string fldName, int? id) btnText = id == null ? "Add to Field" : "Update Field", id = id, isFertigation = true, + groupID = groupID, }; if (id != null){ @@ -527,13 +528,6 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) fgvm.density = ""; - // if (fgvm.currUnit != typ.DryLiquid) - // { - // fgvm.currUnit = typ.DryLiquid; - // //fgvm.productRateUnitOptions = _sd.GetFertilizerUnitsDll(fgvm.currUnit).ToList(); - // fgvm.selProductRateUnitOption = fgvm.productRateUnitOptions[0].Id.ToString(); - // fgvm.fertilizerType = typ.DryLiquid; - // } fgvm.fertilizerType = typ.DryLiquid; fgvm.manualEntry = typ.Custom; if (!fgvm.manualEntry) @@ -777,7 +771,7 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) _ud.UpdateFieldNutrientsFertilizer(fgvm.fieldName, origFertilizer); } } - else if (fgvm.buttonPressed == "Add to Field" || fgvm.buttonPressed == "Update Field") // may need to add update field here as well + else if (fgvm.buttonPressed == "Add to Field" || fgvm.buttonPressed == "Update Field") { fgvm.buttonPressed = ""; if (fgvm.id == null) @@ -863,9 +857,6 @@ private List FertigationInsert(FertigationDetailsViewModel fgvm) fertK2o = Convert.ToDecimal(fgvm.calcK2o), liquidDensity = Convert.ToDecimal(fgvm.density), liquidDensityUnitId = Convert.ToInt32(fgvm.selDensityUnitOption), - //eventsPerSeason = fgvm.eventsPerSeason, - //injectionRate = Convert.ToDecimal(fgvm.injectionRate), - //injectionRateUnitId = Convert.ToInt32(fgvm.selInjectionRateUnitOption), isFertigation = true, groupID = groupID }; @@ -891,9 +882,8 @@ private List FertigationInsert(FertigationDetailsViewModel fgvm) private void FertigationUpdate(FertigationDetailsViewModel fgvm) { var existingFertigations = _ud.GetFieldNutrientsFertilizers(fgvm.fieldName) - .Where(nf => nf.id == fgvm.id || (nf.isFertigation && nf.fertilizerTypeId == Convert.ToInt32(fgvm.selTypOption))) + .Where(nf => nf.isFertigation && nf.groupID == fgvm.groupID) .ToList(); - foreach (var existingFert in existingFertigations) { _ud.DeleteFieldNutrientsFertilizer(fgvm.fieldName, existingFert.id); @@ -906,19 +896,16 @@ private void FertigationUpdate(FertigationDetailsViewModel fgvm) fertilizerTypeId = Convert.ToInt32(fgvm.selTypOption), fertilizerId = fgvm.selFertOption ?? 0, applUnitId = Convert.ToInt32(fgvm.selProductRateUnitOption), - applRate = Convert.ToDecimal(fgvm.productRate) / fgvm.eventsPerSeason, + applRate = Convert.ToDecimal(fgvm.productRate), applDate = getIncrementedDate(Int32.Parse(fgvm.selFertSchedOption), fgvm.applDate, x), customN = fgvm.manualEntry ? Convert.ToDecimal(fgvm.valN) : (decimal?)null, customP2o5 = fgvm.manualEntry ? Convert.ToDecimal(fgvm.valP2o5) : (decimal?)null, customK2o = fgvm.manualEntry ? Convert.ToDecimal(fgvm.valK2o) : (decimal?)null, - fertN = Convert.ToDecimal(fgvm.calcN) / fgvm.eventsPerSeason, - fertP2o5 = Convert.ToDecimal(fgvm.calcP2o5) / fgvm.eventsPerSeason, - fertK2o = Convert.ToDecimal(fgvm.calcK2o) / fgvm.eventsPerSeason, + fertN = Convert.ToDecimal(fgvm.calcN), + fertP2o5 = Convert.ToDecimal(fgvm.calcP2o5), + fertK2o = Convert.ToDecimal(fgvm.calcK2o), liquidDensity = Convert.ToDecimal(fgvm.density), liquidDensityUnitId = Convert.ToInt32(fgvm.selDensityUnitOption), - //eventsPerSeason = fgvm.eventsPerSeason, - //injectionRate = Convert.ToDecimal(fgvm.injectionRate), - //injectionRateUnitId = Convert.ToInt32(fgvm.selInjectionRateUnitOption), isFertigation = true }; @@ -969,9 +956,6 @@ public ActionResult FertigationDelete(FertigationDeleteViewModel dvm) { if (ModelState.IsValid) { - //var fertigationToDelete = _ud.GetFieldNutrientsFertilizer(dvm.fldName, dvm.id); - - // have to fix the logic here to delete the correct fertigation, currently it deletes all fertigations var fertigationsToDelete = _ud.GetFieldNutrientsFertilizers(dvm.fldName) .Where(nf => nf.isFertigation && nf.groupID == dvm.groupID) .ToList(); diff --git a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml index 4229f7fb..047aaffe 100644 --- a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml +++ b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml @@ -264,6 +264,7 @@ @Html.HiddenFor(x => x.buttonPressed) @Html.HiddenFor(x => x.selFertSchedOption) @Html.HiddenFor(x => x.applDate) + @Html.HiddenFor(x => x.groupID) @Html.HiddenFor(x => x.valN) @Html.HiddenFor(x => x.valP2o5) diff --git a/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertigation/Default.cshtml b/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertigation/Default.cshtml index 16da4516..87644d23 100644 --- a/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertigation/Default.cshtml +++ b/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertigation/Default.cshtml @@ -40,12 +40,10 @@ bool isFirstItem = true; - string fertilizerKey = ""; - + string currentGroup = ""; foreach (var m in Model.fldFertilizers) { - string currKey = m.fertilizerName + m.eventsPerSeason; - if( fertilizerKey != currKey){ + if( m.groupID != currentGroup){ isFirstItem = true; } @@ -86,7 +84,7 @@ @if (isFirstItem) {
-
@@ -95,7 +93,7 @@ - fertilizerKey = m.fertilizerName + m.eventsPerSeason; + currentGroup = m.groupID; isFirstItem = false; } From f02b93f3a0d948594a9ea1ced0da1a27a596e8ee Mon Sep 17 00:00:00 2001 From: acatchpole Date: Fri, 13 Sep 2024 11:35:19 -0700 Subject: [PATCH 2/5] edit seems to be working --- .../Controllers/NutrientsController.cs | 55 ++++++++----------- .../Views/Nutrients/Calculate.cshtml | 4 +- .../Views/Nutrients/FertigationDetails.cshtml | 22 ++++---- 3 files changed, 35 insertions(+), 46 deletions(-) diff --git a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs index 6ef8f3d1..886f430c 100644 --- a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs +++ b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs @@ -287,7 +287,7 @@ public IActionResult FertigationDetails(string fldName, int? id, string? groupID } fgvm.density = nf.liquidDensity.ToString("#.##"); fgvm.selDensityUnitOption = nf.liquidDensityUnitId; - fgvm.eventsPerSeason = nf.eventsPerSeason; + fgvm.eventsPerSeason = getNumberOfEvents(fgvm); fgvm.selFertSchedOption = nf.applMethodId.ToString(); fgvm.injectionRate = nf.injectionRate.ToString("#.##"); fgvm.selInjectionRateUnitOption = nf.injectionRateUnitId.ToString(); @@ -483,23 +483,6 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) try { - /* - if (fgvm.buttonPressed == "Calculate") - { - if (!ModelState.IsValid) - { - FertigationDetailsSetup(ref fgvm); - return PartialView(fgvm); - } - - // Calculation logic will be implemented here by Adam and the team - // As of now, clear the model state until that ticket is implemented - ModelState.Clear(); - fgvm.btnText = "Add to Field"; - FertigationDetailsSetup(ref fgvm); - return PartialView(fgvm); - } - */ if (fgvm.buttonPressed == "ResetDensity") { ModelState.Clear(); @@ -858,6 +841,7 @@ private List FertigationInsert(FertigationDetailsViewModel fgvm) liquidDensity = Convert.ToDecimal(fgvm.density), liquidDensityUnitId = Convert.ToInt32(fgvm.selDensityUnitOption), isFertigation = true, + //eventsPerSeason = fgvm.eventsPerSeason, groupID = groupID }; ids.Add( _ud.AddFieldNutrientsFertilizer(fgvm.fieldName, nf)); @@ -879,6 +863,14 @@ private List FertigationInsert(FertigationDetailsViewModel fgvm) return startingDate; } + public int getNumberOfEvents(FertigationDetailsViewModel fgvm){ + var fertigations = _ud.GetFieldNutrientsFertilizers(fgvm.fieldName) + .Where(nf => nf.isFertigation && nf.groupID == fgvm.groupID) + .ToList(); + + return fertigations.Count(); + } + private void FertigationUpdate(FertigationDetailsViewModel fgvm) { var existingFertigations = _ud.GetFieldNutrientsFertilizers(fgvm.fieldName) @@ -906,6 +898,8 @@ private void FertigationUpdate(FertigationDetailsViewModel fgvm) fertK2o = Convert.ToDecimal(fgvm.calcK2o), liquidDensity = Convert.ToDecimal(fgvm.density), liquidDensityUnitId = Convert.ToInt32(fgvm.selDensityUnitOption), + groupID = fgvm.groupID, + //eventsPerSeason = fgvm.eventsPerSeason, isFertigation = true }; @@ -960,21 +954,16 @@ public ActionResult FertigationDelete(FertigationDeleteViewModel dvm) .Where(nf => nf.isFertigation && nf.groupID == dvm.groupID) .ToList(); - foreach (var fertigation in fertigationsToDelete) - { - _ud.DeleteFieldNutrientsFertilizer(dvm.fldName, fertigation.id); - } + foreach (var fertigation in fertigationsToDelete) + { + _ud.DeleteFieldNutrientsFertilizer(dvm.fldName, fertigation.id); + } - return Json(ReDisplay("#fertigation", dvm.fldName)); + return Json(ReDisplay("#fertigation", dvm.fldName)); } return PartialView("FertigationDelete", dvm); } - public ActionResult FertigationCalculateDates(CalculateViewModel dvm) - { - return null; - } - private void MaunureStillRequired(ref ManureDetailsViewModel mvm) { //recalc totals for display @@ -2026,7 +2015,7 @@ public IActionResult OtherDetails(OtherDetailsViewModel ovm) { decimal tmp = 0; - if (!(string.IsNullOrEmpty(ovm.ltN))) + if (!string.IsNullOrEmpty(ovm.ltN)) { if (decimal.TryParse(ovm.ltN, out tmp)) { @@ -2048,7 +2037,7 @@ public IActionResult OtherDetails(OtherDetailsViewModel ovm) ovm.ltN = "0"; } - if (!(string.IsNullOrEmpty(ovm.ltP))) + if (!string.IsNullOrEmpty(ovm.ltP)) { if (decimal.TryParse(ovm.ltP, out tmp)) { @@ -2070,7 +2059,7 @@ public IActionResult OtherDetails(OtherDetailsViewModel ovm) ovm.ltP = "0"; } - if (!(string.IsNullOrEmpty(ovm.ltK))) + if (!string.IsNullOrEmpty(ovm.ltK)) { if (decimal.TryParse(ovm.ltK, out tmp)) @@ -2092,7 +2081,7 @@ public IActionResult OtherDetails(OtherDetailsViewModel ovm) { ovm.ltK = "0"; } - if (!(string.IsNullOrEmpty(ovm.yrN))) + if (!string.IsNullOrEmpty(ovm.yrN)) { if (decimal.TryParse(ovm.yrN, out tmp)) { @@ -2114,7 +2103,7 @@ public IActionResult OtherDetails(OtherDetailsViewModel ovm) ovm.yrN = "0"; } - if (!(string.IsNullOrEmpty(ovm.yrP))) + if (!string.IsNullOrEmpty(ovm.yrP)) { if (decimal.TryParse(ovm.yrP, out tmp)) { diff --git a/app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml b/app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml index 7ff50aa9..2a7da854 100644 --- a/app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml +++ b/app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml @@ -476,14 +476,14 @@ $(document).ready(function () { $(document).ready(function () { $("body").on("click", "#calc_button", function () { $('#buttonPressed').val("Calculate"); - $("#modForm").submit(); + //$("#modForm").submit(); }) }); $(document).ready(function () { $("body").on("click", "#submit_button", function () { $('#buttonPressed').val("Add to Field"); - $("#modForm").submit(); + //$("#modForm").submit(); }) }); $(document).ready(function () { diff --git a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml index 047aaffe..d19ffbc9 100644 --- a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml +++ b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml @@ -86,14 +86,14 @@
- +
@@ -196,7 +196,7 @@

K2O

-
@* Temporarily val. need to switch back to calcTotal *@ +
@Model.calcTotalN
@@ -230,21 +230,21 @@ @if (!string.IsNullOrEmpty(Model.totNIcon)) { - } + } @Model.totN
- @if (!string.IsNullOrEmpty(Model.totPIcon)) - { - - } + @if (!string.IsNullOrEmpty(Model.totPIcon)) + { + + } @Model.totP2o5
@if (!string.IsNullOrEmpty(Model.totKIcon)) - { - - } + { + + } @Model.totK2o
From 6d7f7c1385b98b6733041aa5672dd7061bf777da Mon Sep 17 00:00:00 2001 From: acatchpole Date: Fri, 13 Sep 2024 11:54:18 -0700 Subject: [PATCH 3/5] scheduling period persists into edit --- app/Server/src/SERVERAPI/Controllers/NutrientsController.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs index 886f430c..41b56b23 100644 --- a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs +++ b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs @@ -832,6 +832,7 @@ private List FertigationInsert(FertigationDetailsViewModel fgvm) applUnitId = Convert.ToInt32(fgvm.selProductRateUnitOption), applRate = Convert.ToDecimal(fgvm.productRate), applDate = getIncrementedDate(Int32.Parse(fgvm.selFertSchedOption), fgvm.applDate, x), + applMethodId = Convert.ToInt32(fgvm.selFertSchedOption), customN = fgvm.manualEntry ? Convert.ToDecimal(fgvm.valN) : (decimal?)null, customP2o5 = fgvm.manualEntry ? Convert.ToDecimal(fgvm.valP2o5) : (decimal?)null, customK2o = fgvm.manualEntry ? Convert.ToDecimal(fgvm.valK2o) : (decimal?)null, @@ -890,6 +891,7 @@ private void FertigationUpdate(FertigationDetailsViewModel fgvm) applUnitId = Convert.ToInt32(fgvm.selProductRateUnitOption), applRate = Convert.ToDecimal(fgvm.productRate), applDate = getIncrementedDate(Int32.Parse(fgvm.selFertSchedOption), fgvm.applDate, x), + applMethodId = Convert.ToInt32(fgvm.selFertSchedOption), customN = fgvm.manualEntry ? Convert.ToDecimal(fgvm.valN) : (decimal?)null, customP2o5 = fgvm.manualEntry ? Convert.ToDecimal(fgvm.valP2o5) : (decimal?)null, customK2o = fgvm.manualEntry ? Convert.ToDecimal(fgvm.valK2o) : (decimal?)null, From e568d8524c70f7e1afbcfce30c566f3c34659915 Mon Sep 17 00:00:00 2001 From: acatchpole Date: Fri, 13 Sep 2024 11:57:58 -0700 Subject: [PATCH 4/5] injection rate persists into edit --- app/Server/src/SERVERAPI/Controllers/NutrientsController.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs index 41b56b23..a3008842 100644 --- a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs +++ b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs @@ -842,6 +842,8 @@ private List FertigationInsert(FertigationDetailsViewModel fgvm) liquidDensity = Convert.ToDecimal(fgvm.density), liquidDensityUnitId = Convert.ToInt32(fgvm.selDensityUnitOption), isFertigation = true, + injectionRate = Convert.ToDecimal(fgvm.injectionRate), + injectionRateUnitId = Convert.ToInt32(fgvm.selInjectionRateUnitOption), //eventsPerSeason = fgvm.eventsPerSeason, groupID = groupID }; @@ -901,6 +903,8 @@ private void FertigationUpdate(FertigationDetailsViewModel fgvm) liquidDensity = Convert.ToDecimal(fgvm.density), liquidDensityUnitId = Convert.ToInt32(fgvm.selDensityUnitOption), groupID = fgvm.groupID, + injectionRate = Convert.ToDecimal(fgvm.injectionRate), + injectionRateUnitId = Convert.ToInt32(fgvm.selInjectionRateUnitOption), //eventsPerSeason = fgvm.eventsPerSeason, isFertigation = true }; From a9752f38b334c64124fb039ca3dbbd78938fee52 Mon Sep 17 00:00:00 2001 From: PaulGarewal Date: Fri, 13 Sep 2024 13:52:33 -0700 Subject: [PATCH 5/5] removed commented string indexing, small clean up --- .../ViewComponents/CalcFertigationViewComponent.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs b/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs index a65aeeec..31208c15 100644 --- a/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs +++ b/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs @@ -56,14 +56,6 @@ private Task GetFertigationAsync(string fldName) dm.fldName = fldName; dm.fertilizerId = f.id; dm.fertilizerName = fertilizerName; - - // int startIndex = fertilizerName.IndexOf('('); - // int endIndex = fertilizerName.IndexOf(')'); - // if (startIndex != -1 && endIndex != -1 && endIndex > startIndex) - // { - // string result = fertilizerName.Substring(startIndex +1, endIndex - startIndex -1); - // dm.fertilizerName = result; - // } dm.valN = f.fertN.ToString("G29"); dm.valP = f.fertP2o5.ToString("G29"); dm.valK = f.fertK2o.ToString("G29");