From 41ae07c1254d14af71b88edbfde7ad70eeb3f315 Mon Sep 17 00:00:00 2001 From: PaulGarewal Date: Fri, 6 Sep 2024 15:22:46 -0700 Subject: [PATCH 01/13] feat: Initial add of fertigation to nutrients screen - updated nutrients controller to handle add to field option - logic treats the fertigation as fertilizer atm, needs seperate logic in coming commits --- .../src/SERVERAPI/Controllers/NutrientsController.cs | 7 +++---- app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml | 6 ++++++ .../SERVERAPI/Views/Nutrients/FertigationDetails.cshtml | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs index 68e5c8e2..430d19f8 100644 --- a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs +++ b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs @@ -765,8 +765,8 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) { _ud.UpdateFieldNutrientsFertilizer(fgvm.fieldName, origFertilizer); } - } /* - else + } + else if (fgvm.buttonPressed == "Add to Field") // may need to add update field here as well { if (fgvm.id == null) { @@ -776,9 +776,8 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) { FertigationUpdate(fgvm); } - return Json(ReDisplay("#fertilizer", fgvm.fieldName)); + return Json(new { success = true, reload = true }); } - */ } } catch (Exception ex) diff --git a/app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml b/app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml index 77ce6cd8..ba9f2c01 100644 --- a/app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml +++ b/app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml @@ -477,6 +477,12 @@ $(document).ready(function () { }) }); + $(document).ready(function () { + $("body").on("click", "#submit_button", function () { + $('#buttonPressed').val("Add to Field"); + $("#modForm").submit(); + }) + }); $(document).ready(function () { $("body").on("click", "#rstYield", function () { $('#buttonPressed').val("ResetYield"); diff --git a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml index bc9ea642..73459a6c 100644 --- a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml +++ b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml @@ -256,7 +256,7 @@ @Html.HiddenFor(x => x.fieldName) @Html.HiddenFor(x => x.title) From cfbc526386d079c2af481f99aa24ac62833d2a24 Mon Sep 17 00:00:00 2001 From: PaulGarewal Date: Sun, 8 Sep 2024 21:46:04 -0700 Subject: [PATCH 02/13] Add basic fertigation functionality to nutrients screen - Implement fertigation using existing fertilizer logic - Add isFertigation flag to differentiate entries - Create CalcFertigationViewComponent and corresponding view - Update nutrient calculation to include fertigation entries TODO: Implement fertigation-specific fields and fix display bugfeat: Initial add of fertigation to nutrients screen --- .vscode/launch.json | 30 +++++++ .vscode/tasks.json | 41 +++++++++ .../Controllers/NutrientsController.cs | 6 +- .../src/SERVERAPI/Models.Impl/UserData.cs | 40 +++++++-- .../CalcFertigationViewComponent.cs | 82 +++++++++++++++++ .../CalcFertilizerViewComponent.cs | 16 ++-- .../ViewModels/FertigationDetailsViewModel.cs | 2 + .../Views/Nutrients/Calculate.cshtml | 3 + .../Components/CalcFertigation/Default.cshtml | 87 +++++++++++++++++++ .../Components/CalcFertilizer/Default.cshtml | 2 +- 10 files changed, 293 insertions(+), 16 deletions(-) create mode 100644 .vscode/tasks.json create mode 100644 app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs create mode 100644 app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertigation/Default.cshtml diff --git a/.vscode/launch.json b/.vscode/launch.json index 8e8e3834..725eea9f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -23,6 +23,36 @@ "env": {"DEBUG":"*"}, "args": ["--pr=0","--env=dev"], "console": "integratedTerminal" + }, + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md. + "name": ".NET Core Launch (web)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/app/Server/src/SERVERAPI/bin/Debug/net7.0/SERVERAPI.dll", + "args": [], + "cwd": "${workspaceFolder}/app/Server/src/SERVERAPI", + "stopAtEntry": false, + // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\bNow listening on:\\s+(https?://\\S+)" + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..30fdd5ed --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/app/Server/Server.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/app/Server/Server.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/app/Server/Server.sln" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs index 430d19f8..1ab7764f 100644 --- a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs +++ b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs @@ -262,6 +262,7 @@ public IActionResult FertigationDetails(string fldName, int? id) title = id == null ? "Add" : "Edit", btnText = id == null ? "Add to Field" : "Update Field", id = id, + isFertigation = true }; if (id != null){ @@ -467,6 +468,7 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) decimal nmbrK = 0; int addedId = 0; NutrientFertilizer origFertilizer = new NutrientFertilizer(); + origFertilizer.isFertigation = true; //Utility.CalculateNutrients calculateNutrients = new CalculateNutrients(_env, _ud, _sd); //NOrganicMineralizations nOrganicMineralizations = new NOrganicMineralizations(); @@ -847,7 +849,8 @@ private int FertigationInsert(FertigationDetailsViewModel fgvm) fertP2o5 = Convert.ToDecimal(fgvm.calcP2o5), fertK2o = Convert.ToDecimal(fgvm.calcK2o), liquidDensity = Convert.ToDecimal(fgvm.density), - liquidDensityUnitId = Convert.ToInt32(fgvm.selDensityUnitOption) + liquidDensityUnitId = Convert.ToInt32(fgvm.selDensityUnitOption), + isFertigation = true }; return _ud.AddFieldNutrientsFertilizer(fgvm.fieldName, nf); @@ -1356,6 +1359,7 @@ public IActionResult FertilizerDetails(FertilizerDetailsViewModel fvm) decimal nmbrK = 0; int addedId = 0; NutrientFertilizer origFertilizer = new NutrientFertilizer(); + origFertilizer.isFertigation = false; //Utility.CalculateNutrients calculateNutrients = new CalculateNutrients(_env, _ud, _sd); //NOrganicMineralizations nOrganicMineralizations = new NOrganicMineralizations(); diff --git a/app/Server/src/SERVERAPI/Models.Impl/UserData.cs b/app/Server/src/SERVERAPI/Models.Impl/UserData.cs index ea360ca7..6913f5d6 100644 --- a/app/Server/src/SERVERAPI/Models.Impl/UserData.cs +++ b/app/Server/src/SERVERAPI/Models.Impl/UserData.cs @@ -728,24 +728,48 @@ public int AddFieldNutrientsFertilizer(string fldName, NutrientFertilizer newFer fld.Nutrients = new Nutrients(); fld.Nutrients.nutrientFertilizers = new List(); } - else + else if (fld.Nutrients.nutrientFertilizers == null) { - if (fld.Nutrients.nutrientFertilizers == null) - { - fld.Nutrients.nutrientFertilizers = new List(); - } + fld.Nutrients.nutrientFertilizers = new List(); } foreach (var f in fld.Nutrients.nutrientFertilizers) { nextId = nextId <= f.id ? f.id + 1 : nextId; } - newFert.id = nextId; - fld.Nutrients.nutrientFertilizers.Add(newFert); + // Handle fertigation events + if (newFert.eventsPerSeason > 1 && newFert.isFertigation) + { + for (int i = 0; i < newFert.eventsPerSeason; i++) + { + var fertigationEvent = new NutrientFertilizer + { + id = nextId + i, + fertilizerTypeId = newFert.fertilizerTypeId, + fertilizerId = newFert.fertilizerId, + applUnitId = newFert.applUnitId, + applRate = newFert.applRate / newFert.eventsPerSeason, + applDate = newFert.applDate?.AddDays(i * 7), // Assuming weekly applications + fertN = newFert.fertN / newFert.eventsPerSeason, + fertP2o5 = newFert.fertP2o5 / newFert.eventsPerSeason, + fertK2o = newFert.fertK2o / newFert.eventsPerSeason, + liquidDensity = newFert.liquidDensity, + liquidDensityUnitId = newFert.liquidDensityUnitId, + eventsPerSeason = newFert.eventsPerSeason, + }; + fld.Nutrients.nutrientFertilizers.Add(fertigationEvent); + } + } + else + { + newFert.id = nextId; + fld.Nutrients.nutrientFertilizers.Add(newFert); + } + _ctx.HttpContext.Session.SetObjectAsJson("FarmData", userData); - return newFert.id; + return nextId; } public void AddFieldNutrientsOther(string fldName, NutrientOther newOther) diff --git a/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs b/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs new file mode 100644 index 00000000..faeb4bd5 --- /dev/null +++ b/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs @@ -0,0 +1,82 @@ +using Agri.Data; +using Agri.Models.Configuration; +using Agri.Models.Farm; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Linq; + +namespace SERVERAPI.ViewComponents +{ + public class CalcFertigationViewComponent : ViewComponent + { + private IAgriConfigurationRepository _sd; + private Models.Impl.UserData _ud; + + public CalcFertigationViewComponent(IAgriConfigurationRepository sd, Models.Impl.UserData ud) + { + _sd = sd; + _ud = ud; + } + + public async Task InvokeAsync(string fldName) + { + return View(await GetFertigationAsync(fldName)); + } + + private Task GetFertigationAsync(string fldName) + { + CalcFertigationViewModel fgvm = new CalcFertigationViewModel(); + fgvm.fldFertilizers = new List(); + + List fldFertilizers = _ud.GetFieldNutrientsFertilizers(fldName); + foreach (var f in fldFertilizers.Where(f => f.isFertigation)) + { + DisplayNutrientFertigation dm = new DisplayNutrientFertigation(); + + FertilizerType ft = _sd.GetFertilizerType(f.fertilizerTypeId.ToString()); + + string fertilizerName; + if (ft.Custom) + { + fertilizerName = ft.DryLiquid == "dry" ? "Custom (Dry) " : "Custom (Liquid) "; + fertilizerName = fertilizerName + f.customN.ToString() + "-" + f.customP2o5.ToString() + "-" + f.customK2o.ToString(); + } + else + { + Fertilizer ff = _sd.GetFertilizer(f.fertilizerId.ToString()); + fertilizerName = ff.Name; + } + + dm.fldName = fldName; + dm.fertilizerId = f.id; + dm.fertilizerName = fertilizerName; + dm.valN = f.fertN.ToString("G29"); + dm.valP = f.fertP2o5.ToString("G29"); + dm.valK = f.fertK2o.ToString("G29"); + dm.isFertigation = true; + dm.eventsPerSeason = f.eventsPerSeason; + + fgvm.fldFertilizers.Add(dm); + } + + return Task.FromResult(fgvm); + } + } + public class CalcFertigationViewModel +{ + public List fldFertilizers { get; set; } +} + +public class DisplayNutrientFertigation +{ + public string fldName { get; set; } + public int fertilizerId { get; set; } + public string fertilizerName { get; set; } + public string valN { get; set; } + public string valP { get; set; } + public string valK { get; set; } + public bool isFertigation { get; set; } + public int eventsPerSeason { get; set; } +} +} \ No newline at end of file diff --git a/app/Server/src/SERVERAPI/ViewComponents/CalcFertilizerViewComponent.cs b/app/Server/src/SERVERAPI/ViewComponents/CalcFertilizerViewComponent.cs index c3da8b77..57e14648 100644 --- a/app/Server/src/SERVERAPI/ViewComponents/CalcFertilizerViewComponent.cs +++ b/app/Server/src/SERVERAPI/ViewComponents/CalcFertilizerViewComponent.cs @@ -1,10 +1,10 @@ -using Agri.Data; +using Agri.Data; using Agri.Models.Configuration; using Agri.Models.Farm; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Threading.Tasks; - + namespace SERVERAPI.ViewComponents { public class CalcFertilizer : ViewComponent @@ -16,8 +16,8 @@ public CalcFertilizer(IAgriConfigurationRepository sd, Models.Impl.UserData ud) { _sd = sd; _ud = ud; - } - + } + public async Task InvokeAsync(string fldName) { return View(await GetFertilizerAsync(fldName)); @@ -53,18 +53,20 @@ private Task GetFertilizerAsync(string fldName) dm.valN = f.fertN.ToString("G29"); dm.valP = f.fertP2o5.ToString("G29"); dm.valK = f.fertK2o.ToString("G29"); + dm.isFertigation = f.isFertigation; + dm.eventsPerSeason = f.eventsPerSeason; fvm.fldFertilizers.Add(dm); } return Task.FromResult(fvm); } - } + } public class CalcFertilizerViewModel { public List fldFertilizers { get; set; } - } + } public class DisplayNutrientFertilizer { @@ -74,5 +76,7 @@ public class DisplayNutrientFertilizer public string valN { get; set; } public string valP { get; set; } public string valK { get; set; } + public bool isFertigation { get; set; } + public int eventsPerSeason { get; set; } } } \ No newline at end of file diff --git a/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs b/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs index 035ab510..31906438 100644 --- a/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs +++ b/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs @@ -119,5 +119,7 @@ public class FertigationDetailsViewModel public decimal fertigationTime { get; set;} public decimal totProductVolPerFert { get; set;} public decimal totProductVolPerSeason { get; set;} + + public bool isFertigation { get; set; } } } diff --git a/app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml b/app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml index ba9f2c01..7ff50aa9 100644 --- a/app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml +++ b/app/Server/src/SERVERAPI/Views/Nutrients/Calculate.cshtml @@ -91,6 +91,9 @@
@await Component.InvokeAsync("CalcFertilizer", new { fldName = Model.currFld })
+
+ @await Component.InvokeAsync("CalcFertigation", new { fldName = Model.currFld }) +
@await Component.InvokeAsync("CalcOther", new { fldName = Model.currFld })
diff --git a/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertigation/Default.cshtml b/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertigation/Default.cshtml new file mode 100644 index 00000000..b543b5c0 --- /dev/null +++ b/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertigation/Default.cshtml @@ -0,0 +1,87 @@ +@model CalcFertigationViewModel +@if (Model.fldFertilizers.Count > 0 && Model.fldFertilizers.Any(f => f.isFertigation)) +{ +
+
+
+
+
+
Fertigation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
+
 
+
+ foreach (var m in Model.fldFertilizers) + { +
+
+
+
+
+

@m.fertilizerName

+
+
+
+
+
+
+
+
+
@m.valN
+
@m.valP
+
@m.valK
+
+
+
+
+
+
+
+
+
+
@m.valN
+
@m.valP
+
@m.valK
+
+
+
+
+
+ +
+
+ +
+
+ } +} diff --git a/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertilizer/Default.cshtml b/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertilizer/Default.cshtml index e66b8612..5934f6bd 100644 --- a/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertilizer/Default.cshtml +++ b/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertilizer/Default.cshtml @@ -1,5 +1,5 @@ @model CalcFertilizerViewModel -@if (Model.fldFertilizers.Count > 0) +@if (Model.fldFertilizers.Count > 0 && !Model.fldFertilizers.Any(f => f.isFertigation)) {
From 4c2e54353fe8de64ef263607cef01d4f723a6ab8 Mon Sep 17 00:00:00 2001 From: PaulGarewal Date: Sun, 8 Sep 2024 21:50:42 -0700 Subject: [PATCH 03/13] add missed nutrient fertilizer value --- app/Agri.Models/Farm/NutrientFertilizer.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Agri.Models/Farm/NutrientFertilizer.cs b/app/Agri.Models/Farm/NutrientFertilizer.cs index 45ed3bc9..2571aa88 100644 --- a/app/Agri.Models/Farm/NutrientFertilizer.cs +++ b/app/Agri.Models/Farm/NutrientFertilizer.cs @@ -19,5 +19,7 @@ public class NutrientFertilizer public decimal fertK2o { get; set; } public decimal liquidDensity { get; set; } public int liquidDensityUnitId { get; set; } + public int eventsPerSeason { get; set; } + public bool isFertigation { get; set; } } } \ No newline at end of file From a422356c10ff27aab870717f75c95a222d45c7de Mon Sep 17 00:00:00 2001 From: acatchpole Date: Mon, 9 Sep 2024 16:44:15 -0700 Subject: [PATCH 04/13] WIP --- .../Controllers/NutrientsController.cs | 9 ++++++ .../CalcFertigationViewComponent.cs | 18 +++++++++-- .../ViewModels/FertigationDeleteViewModel.cs | 13 ++++++++ .../Views/Nutrients/FertigationDelete.cshtml | 32 +++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 app/Server/src/SERVERAPI/ViewModels/FertigationDeleteViewModel.cs create mode 100644 app/Server/src/SERVERAPI/Views/Nutrients/FertigationDelete.cshtml diff --git a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs index 1ab7764f..ae6312cc 100644 --- a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs +++ b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs @@ -1797,6 +1797,11 @@ public IActionResult RefreshFertilizerList(string fieldName) return ViewComponent("CalcFertilizer", new { fldName = fieldName }); } + public IActionResult RefreshFertigationList(string fieldName) + { + return ViewComponent("CalcFertigation", new { fldName = fieldName }); + } + public IActionResult RefreshFieldList(string fieldName) { return RedirectToAction("Calculate", "Nutrients", new { nme = fieldName }); @@ -2167,6 +2172,10 @@ public object ReDisplay(string target, string fldName) refresher = "RefreshFertilizerList"; break; + case "#fertigation": + refresher = "RefreshFertigationList"; + break; + case "#prevYearManure": refresher = "RefreshNitrogenCredit"; break; diff --git a/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs b/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs index faeb4bd5..1b0573f2 100644 --- a/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs +++ b/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using System.Linq; +using Newtonsoft.Json; namespace SERVERAPI.ViewComponents { @@ -12,11 +13,13 @@ public class CalcFertigationViewComponent : ViewComponent { private IAgriConfigurationRepository _sd; private Models.Impl.UserData _ud; + private Fertigation _fd; public CalcFertigationViewComponent(IAgriConfigurationRepository sd, Models.Impl.UserData ud) { _sd = sd; _ud = ud; + _fd = GetFertigationData(); } public async Task InvokeAsync(string fldName) @@ -44,7 +47,7 @@ private Task GetFertigationAsync(string fldName) } else { - Fertilizer ff = _sd.GetFertilizer(f.fertilizerId.ToString()); + Fertilizer ff = GetFertigationFertilizer(f.fertilizerId); fertilizerName = ff.Name; } @@ -62,6 +65,17 @@ private Task GetFertigationAsync(string fldName) return Task.FromResult(fgvm); } + public Fertigation GetFertigationData() + { + var filePath = "../../../Agri.Data/SeedData/FertigationData.json"; + var jsonData = System.IO.File.ReadAllText(filePath); + return JsonConvert.DeserializeObject(jsonData); + } + private Fertilizer GetFertigationFertilizer(int id) + { + List fertilizers = _fd.Fertilizers; + return fertilizers.Find(x => x.Id == id); + } } public class CalcFertigationViewModel { @@ -79,4 +93,4 @@ public class DisplayNutrientFertigation public bool isFertigation { get; set; } public int eventsPerSeason { get; set; } } -} \ No newline at end of file +} diff --git a/app/Server/src/SERVERAPI/ViewModels/FertigationDeleteViewModel.cs b/app/Server/src/SERVERAPI/ViewModels/FertigationDeleteViewModel.cs new file mode 100644 index 00000000..3a3e1e13 --- /dev/null +++ b/app/Server/src/SERVERAPI/ViewModels/FertigationDeleteViewModel.cs @@ -0,0 +1,13 @@ +using System.ComponentModel.DataAnnotations; + +namespace SERVERAPI.ViewModels +{ + public class FertigationDeleteViewModel + { + public string act { get; set; } + public string fldName { get; set; } + public int id { get; set; } + [Display(Name = "Fertilizer")] + public string fertilizerName { get; set; } + } +} diff --git a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDelete.cshtml b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDelete.cshtml new file mode 100644 index 00000000..40f9c6ce --- /dev/null +++ b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDelete.cshtml @@ -0,0 +1,32 @@ +@model SERVERAPI.ViewModels.FertigationDeleteViewModel + +@{ + Layout = null; +} +
+ + +
+ + + @Html.HiddenFor(x => x.fldName) + @Html.HiddenFor(x => x.act) + @Html.HiddenFor(x => x.id) +
+
From c65cf73999d39da55611dcc803e320c3ffc72b56 Mon Sep 17 00:00:00 2001 From: PaulGarewal Date: Tue, 10 Sep 2024 09:36:29 -0700 Subject: [PATCH 05/13] WIP --- .../Views/Shared/Components/CalcFertigation/Default.cshtml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 b543b5c0..9e49772c 100644 --- a/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertigation/Default.cshtml +++ b/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertigation/Default.cshtml @@ -7,6 +7,9 @@
Fertigation
+
Scheduling
+
Monthly
+
Date
@@ -77,7 +80,7 @@
-
+
From 7ff46f5207ac5d1b61e77178644aa2d17f95aa47 Mon Sep 17 00:00:00 2001 From: PaulGarewal Date: Tue, 10 Sep 2024 15:52:33 -0700 Subject: [PATCH 06/13] WIP --- app/Agri.Models/Farm/NutrientFertilizer.cs | 3 + .../Controllers/NutrientsController.cs | 127 ++++++++++++++---- .../CalcFertigationViewComponent.cs | 18 ++- .../CalcFertilizerViewComponent.cs | 4 +- .../ViewModels/FertigationDetailsViewModel.cs | 8 +- .../Views/Nutrients/FertigationDetails.cshtml | 58 ++++---- .../Components/CalcFertigation/Default.cshtml | 12 +- 7 files changed, 162 insertions(+), 68 deletions(-) diff --git a/app/Agri.Models/Farm/NutrientFertilizer.cs b/app/Agri.Models/Farm/NutrientFertilizer.cs index 2571aa88..b259b9ab 100644 --- a/app/Agri.Models/Farm/NutrientFertilizer.cs +++ b/app/Agri.Models/Farm/NutrientFertilizer.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel.DataAnnotations; namespace Agri.Models.Farm { @@ -9,6 +10,8 @@ public class NutrientFertilizer public int fertilizerId { get; set; } public int applUnitId { get; set; } public decimal applRate { get; set; } + [DataType(DataType.Date)] + [DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}", ApplyFormatInEditMode = true)] public DateTime? applDate { get; set; } public int applMethodId { get; set; } public decimal? customN { get; set; } diff --git a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs index ae6312cc..8f6eb1fb 100644 --- a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs +++ b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs @@ -17,6 +17,7 @@ using System.IO; using Newtonsoft.Json; using Agri.Models; +using Microsoft.EntityFrameworkCore.Infrastructure; namespace SERVERAPI.Controllers { @@ -262,7 +263,7 @@ public IActionResult FertigationDetails(string fldName, int? id) title = id == null ? "Add" : "Edit", btnText = id == null ? "Add to Field" : "Update Field", id = id, - isFertigation = true + isFertigation = true }; if (id != null){ @@ -281,7 +282,7 @@ public IActionResult FertigationDetails(string fldName, int? id) fgvm.calcK2o = nf.fertK2o.ToString(); if (nf.applDate.HasValue) { - fgvm.applDate = nf.applDate.HasValue ? nf.applDate.Value.ToString("MMM-yyyy") : ""; + fgvm.applDate = nf.applDate.Value.Date; } fgvm.density = nf.liquidDensity.ToString("#.##"); fgvm.selDensityUnitOption = nf.liquidDensityUnitId; @@ -349,7 +350,6 @@ private void FertigationDetail_Reset(ref FertigationDetailsViewModel fgvm) fgvm.totProductVolPerSeason = 0.0M; fgvm.eventsPerSeason = 1; - fgvm.applDate = DateTime.Now.ToShortDateString(); } private void FertigationStillRequired(ref FertigationDetailsViewModel fgvm) @@ -466,9 +466,10 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) decimal nmbrN = 0; decimal nmbrP = 0; decimal nmbrK = 0; - int addedId = 0; + List addedIds = new List(); NutrientFertilizer origFertilizer = new NutrientFertilizer(); origFertilizer.isFertigation = true; + origFertilizer.applDate = origFertilizer.applDate?.Date; //Utility.CalculateNutrients calculateNutrients = new CalculateNutrients(_env, _ud, _sd); //NOrganicMineralizations nOrganicMineralizations = new NOrganicMineralizations(); @@ -667,6 +668,7 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) // } ModelState.Clear(); FertilizerType ft = _sd.GetFertilizerType(fgvm.selTypOption.ToString()); + fgvm.applDate = fgvm.applDate?.Date; // if (ft.DryLiquid == "liquid") // { @@ -683,8 +685,6 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) // } // } // - // date for use in fertigation scheduling, if needed and if in yyyy-mm-dd format for later calcs - fgvm.applDate = string.IsNullOrEmpty(fgvm.applDate) ? null : DateTime.ParseExact(fgvm.applDate, "m/d/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd"); var fertilizerNutrients = _calculateFertigationNutrients.GetFertilizerNutrients(fgvm.selFertOption ?? 0, fgvm.fertilizerType, @@ -696,6 +696,7 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) Convert.ToDecimal(fgvm.valP2o5), Convert.ToDecimal(fgvm.valK2o), fgvm.manualEntry); + Field field = _ud.GetFieldDetails(fgvm.fieldName); @@ -749,7 +750,7 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) // temporarily update the farm data so as to recalc the Still Required amounts if (fgvm.id == null) { - addedId = FertigationInsert(fgvm); + addedIds = FertigationInsert(fgvm); } else { @@ -761,7 +762,10 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) FertigationStillRequired(ref fgvm); if (fgvm.id == null) { - _ud.DeleteFieldNutrientsFertilizer(fgvm.fieldName, addedId); + foreach( int addedId in addedIds){ + _ud.DeleteFieldNutrientsFertilizer(fgvm.fieldName, addedId); + } + } else { @@ -833,27 +837,46 @@ private void FertigationDetailSetup_DefaultDensity(ref FertigationDetailsViewMod } - private int FertigationInsert(FertigationDetailsViewModel fgvm) + private List FertigationInsert(FertigationDetailsViewModel fgvm) { - NutrientFertilizer nf = new NutrientFertilizer() - { - fertilizerTypeId = Convert.ToInt32(fgvm.selTypOption), - fertilizerId = fgvm.selFertOption ?? 0, - applUnitId = Convert.ToInt32(fgvm.selProductRateUnitOption), - applRate = Convert.ToDecimal(fgvm.productRate), - applDate = string.IsNullOrEmpty(fgvm.applDate) ? (DateTime?)null : Convert.ToDateTime(fgvm.applDate), - 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), - fertP2o5 = Convert.ToDecimal(fgvm.calcP2o5), - fertK2o = Convert.ToDecimal(fgvm.calcK2o), - liquidDensity = Convert.ToDecimal(fgvm.density), - liquidDensityUnitId = Convert.ToInt32(fgvm.selDensityUnitOption), - isFertigation = true - }; + List ret = new List(); + for( int x = 0 ; x < fgvm.eventsPerSeason ; x++){ + NutrientFertilizer nf = new NutrientFertilizer() + { + fertilizerTypeId = Convert.ToInt32(fgvm.selTypOption), + fertilizerId = fgvm.selFertOption ?? 0, + applUnitId = Convert.ToInt32(fgvm.selProductRateUnitOption), + applRate = Convert.ToDecimal(fgvm.productRate), + applDate = getIncrementedDate(fgvm.selApplPeriod, 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), + fertP2o5 = Convert.ToDecimal(fgvm.calcP2o5), + fertK2o = Convert.ToDecimal(fgvm.calcK2o), + liquidDensity = Convert.ToDecimal(fgvm.density), + liquidDensityUnitId = Convert.ToInt32(fgvm.selDensityUnitOption), + isFertigation = true + }; + ret.Add( _ud.AddFieldNutrientsFertilizer(fgvm.fieldName, nf)); + } + + + return ret; + } - return _ud.AddFieldNutrientsFertilizer(fgvm.fieldName, nf); + public DateTime? getIncrementedDate(int incrementKey, DateTime? startingDate, int numTimes){ + switch(incrementKey){ + case 1: + return startingDate?.AddMonths(1 * numTimes); + case 2: + return startingDate?.AddDays(14 * numTimes); + case 3: + return startingDate?.AddDays(7 * numTimes); + case 4: + return startingDate?.AddDays(1 * numTimes); + } + return startingDate; } private void FertigationUpdate(FertigationDetailsViewModel fgvm) @@ -863,7 +886,7 @@ private void FertigationUpdate(FertigationDetailsViewModel fgvm) nf.fertilizerId = fgvm.selFertOption ?? 0; nf.applUnitId = Convert.ToInt32(fgvm.selProductRateUnitOption); nf.applRate = Convert.ToDecimal(fgvm.productRate); - nf.applDate = string.IsNullOrEmpty(fgvm.applDate) ? (DateTime?)null : Convert.ToDateTime(fgvm.applDate); + nf.applDate = fgvm.applDate?.Date; nf.customN = fgvm.manualEntry ? Convert.ToDecimal(fgvm.valN) : (decimal?)null; nf.customP2o5 = fgvm.manualEntry ? Convert.ToDecimal(fgvm.valP2o5) : (decimal?)null; nf.customK2o = fgvm.manualEntry ? Convert.ToDecimal(fgvm.valK2o) : (decimal?)null; @@ -883,6 +906,52 @@ public Fertigation GetFertigationData() return JsonConvert.DeserializeObject(jsonData); } + [HttpGet] + public ActionResult FertigationDelete(string fldName, int id) + { + string fertilizerName = string.Empty; + + FertigationDeleteViewModel fgvm = new FertigationDeleteViewModel(); + fgvm.id = id; + fgvm.fldName = fldName; + + NutrientFertilizer nf = _ud.GetFieldNutrientsFertilizer(fldName, id); + FertilizerType ft = _sd.GetFertilizerType(nf.fertilizerTypeId.ToString()); + + if (ft.Custom) + { + fertilizerName = ft.DryLiquid == "dry" ? "Custom (Solid)" : "Custom (Liquid)"; + } + else + { + Fertilizer ff = GetFertigationFertilizer(nf.fertilizerId); + fertilizerName = ff.Name; + } + + fgvm.fertilizerName = fertilizerName; + + fgvm.act = "Delete"; + + return PartialView("FertigationDelete", fgvm); + } + + [HttpPost] + public ActionResult FertigationDelete(FertigationDeleteViewModel dvm) + { + if (ModelState.IsValid) + { + _ud.DeleteFieldNutrientsFertilizer(dvm.fldName, dvm.id); + + 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 @@ -1268,7 +1337,7 @@ public IActionResult FertilizerDetails(string fldName, int? id) fvm.calcK2o = nf.fertK2o.ToString(); if (nf.applDate.HasValue) { - fvm.applDate = nf.applDate.HasValue ? nf.applDate.Value.ToString("MMM-yyyy") : ""; + fvm.applDate = nf.applDate.HasValue ? nf.applDate.Value.ToString("m/d/yyyy") : ""; } if (ft.DryLiquid == "liquid") { diff --git a/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs b/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs index 1b0573f2..19d0cea7 100644 --- a/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs +++ b/app/Server/src/SERVERAPI/ViewComponents/CalcFertigationViewComponent.cs @@ -6,6 +6,8 @@ using System.Threading.Tasks; using System.Linq; using Newtonsoft.Json; +using System; +using System.ComponentModel.DataAnnotations; namespace SERVERAPI.ViewComponents { @@ -53,13 +55,21 @@ 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"); dm.isFertigation = true; dm.eventsPerSeason = f.eventsPerSeason; - + dm.date = f.applDate; + dm.dateAsString = f.applDate?.ToString("dd-MMM"); fgvm.fldFertilizers.Add(dm); } @@ -92,5 +102,9 @@ public class DisplayNutrientFertigation public string valK { get; set; } public bool isFertigation { get; set; } public int eventsPerSeason { get; set; } + [DataType(DataType.Date)] + [DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}", ApplyFormatInEditMode = true)] + public DateTime? date { get; set; } + public string dateAsString { get; set; } } } diff --git a/app/Server/src/SERVERAPI/ViewComponents/CalcFertilizerViewComponent.cs b/app/Server/src/SERVERAPI/ViewComponents/CalcFertilizerViewComponent.cs index 57e14648..627325d9 100644 --- a/app/Server/src/SERVERAPI/ViewComponents/CalcFertilizerViewComponent.cs +++ b/app/Server/src/SERVERAPI/ViewComponents/CalcFertilizerViewComponent.cs @@ -4,6 +4,8 @@ using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Threading.Tasks; +using System.Linq; + namespace SERVERAPI.ViewComponents { @@ -30,7 +32,7 @@ private Task GetFertilizerAsync(string fldName) fvm.fldFertilizers = new List(); List fldFertilizers = _ud.GetFieldNutrientsFertilizers(fldName); - foreach (var f in fldFertilizers) + foreach (var f in fldFertilizers.Where(f => !f.isFertigation)) { DisplayNutrientFertilizer dm = new DisplayNutrientFertilizer(); diff --git a/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs b/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs index 31906438..3bd35e3b 100644 --- a/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs +++ b/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs @@ -66,8 +66,8 @@ public class FertigationDetailsViewModel //#of fertigations per season [Required(ErrorMessage = "Required")] - [Range(1, 9999.99, ErrorMessage = "Required")] - public decimal eventsPerSeason { get; set; } + [Range(1, 9999, ErrorMessage = "Required")] + public int eventsPerSeason { get; set; } //fertigation scheduling public string selFertSchedOption { get; set; } @@ -76,8 +76,8 @@ public class FertigationDetailsViewModel //start date [DataType(DataType.Date)] - [DisplayFormat(DataFormatString = "{0:m/d/yyyy}", ApplyFormatInEditMode = true)] - public string applDate { get; set; } + [DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}", ApplyFormatInEditMode = true)] + public DateTime? applDate { get; set; } public bool manualEntry { get; set; } //calculated //total product volume per fertigation diff --git a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml index 73459a6c..4229f7fb 100644 --- a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml +++ b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml @@ -119,8 +119,8 @@
-
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 34a74b47..16da4516 100644 --- a/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertigation/Default.cshtml +++ b/app/Server/src/SERVERAPI/Views/Shared/Components/CalcFertigation/Default.cshtml @@ -91,7 +91,7 @@
-
From 4e7792216f57fa0369d640a262004f3b24b95d60 Mon Sep 17 00:00:00 2001 From: Dallas Richmond Date: Thu, 12 Sep 2024 10:55:30 -0700 Subject: [PATCH 13/13] WIP deletes individual fertilizers --- app/Agri.Models/Farm/NutrientFertilizer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Agri.Models/Farm/NutrientFertilizer.cs b/app/Agri.Models/Farm/NutrientFertilizer.cs index 8b249704..9e419ea5 100644 --- a/app/Agri.Models/Farm/NutrientFertilizer.cs +++ b/app/Agri.Models/Farm/NutrientFertilizer.cs @@ -26,5 +26,6 @@ public class NutrientFertilizer public bool isFertigation { get; set; } public decimal injectionRate { get; set; } public int injectionRateUnitId { get; set; } + public string groupID { get; set; } } }