diff --git a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs index c64463e8..1eef1fc0 100644 --- a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs +++ b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs @@ -308,9 +308,9 @@ public IActionResult FertigationDetails(string fldName, int? id, string? groupID } if (ft.Custom) { - fgvm.valN = nf.customN.Value.ToString("0"); - fgvm.valP2o5 = nf.customP2o5.Value.ToString("0"); - fgvm.valK2o = nf.customK2o.Value.ToString("0"); + fgvm.valN = nf.customN.Value.ToString(""); + fgvm.valP2o5 = nf.customP2o5.Value.ToString(""); + fgvm.valK2o = nf.customK2o.Value.ToString(""); fgvm.manualEntry = true; } else @@ -325,6 +325,13 @@ public IActionResult FertigationDetails(string fldName, int? id, string? groupID else { FertigationDetail_Reset(ref fgvm); + if (fgvm.selTypOption == "4") // This is custom liquid fertigation, could be put directly into details reset + { + fgvm.valN = ""; + fgvm.valP2o5 = ""; + fgvm.valK2o = ""; + fgvm.manualEntry = true; + } } FertigationStillRequired(ref fgvm); FertigationDetailsSetup(ref fgvm); @@ -359,6 +366,13 @@ private void FertigationDetail_Reset(ref FertigationDetailsViewModel fgvm) fgvm.totProductVolPerSeason = 0.0M; fgvm.eventsPerSeason = 1; + + // if custom liquid fertigation, we set these to empty for user to change + if (fgvm.selTypOption == "4"){ + fgvm.valN = ""; + fgvm.valP2o5 = ""; + fgvm.valK2o = ""; + } } private void FertigationStillRequired(ref FertigationDetailsViewModel fgvm) @@ -457,6 +471,7 @@ private void FertigationDetailSetup_Fertilizer(ref FertigationDetailsViewModel f fgvm.fertOptions = new List() { new SelectListItem() { Id = 1, Value = "Custom" } }; fgvm.selFertOption = 1; fgvm.stdDensity = true; + fgvm.manualEntry = true; } } else @@ -465,6 +480,13 @@ private void FertigationDetailSetup_Fertilizer(ref FertigationDetailsViewModel f fgvm.selFertOption = 0; } + // if (fgvm.selTypOption == "4") // this is custom liquid fertigation + // { + // fgvm.manualEntry = true; + // fgvm.fertOptions = new List() { new SelectListItem() { Id = 1, Value = "Custom" } }; + // fgvm.selFertOption = 1; + // } + return; } @@ -638,6 +660,44 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) } } + // bool isCustomFertigation = fgvm.selTypOption == "4"; + // fgvm.manualEntry = isCustomFertigation; + + // if (isCustomFertigation) + // { + // // Validate custom nutrient inputs here, may have to be moved and altered + // if (string.IsNullOrEmpty(fgvm.valN)) + // { + // ModelState.AddModelError("valN", "Required"); + // } + // else if (!decimal.TryParse(fgvm.valN, out decimal customN) || customN < 0 || customN > 100) + // { + // ModelState.AddModelError("valN", "Invalid. Must be between 0 and 100."); + // } + + // if (string.IsNullOrEmpty(fgvm.valP2o5)) + // { + // ModelState.AddModelError("valP2o5", "Required"); + // } + // else if (!decimal.TryParse(fgvm.valP2o5, out decimal customP) || customP < 0 || customP > 100) + // { + // ModelState.AddModelError("valP2o5", "Invalid. Must be between 0 and 100."); + // } + + // if (string.IsNullOrEmpty(fgvm.valK2o)) + // { + // ModelState.AddModelError("valK2o", "Required"); + // } + // else if (!decimal.TryParse(fgvm.valK2o, out decimal customK) || customK < 0 || customK > 100) + // { + // ModelState.AddModelError("valK2o", "Invalid. Must be between 0 and 100."); + // } + + // // Set up custom fertilizer options + // fgvm.fertOptions = new List() { new SelectListItem() { Id = 1, Value = "Custom" } }; + // fgvm.selFertOption = 1; + // } + if (fgvm.buttonPressed == "Calculate" && ModelState.IsValid) { ModelState.Clear(); @@ -672,8 +732,6 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) Convert.ToDecimal(fgvm.valK2o), fgvm.manualEntry); - - Field field = _ud.GetFieldDetails(fgvm.fieldName); FertilizerUnit _fU = _sd.GetFertilizerUnit(Convert.ToInt32(fgvm.selProductRateUnitOption)); decimal convertedProductRate = Convert.ToDecimal(fgvm.productRate) * _fU.ConversionToImperialGallonsPerAcre; @@ -839,6 +897,24 @@ private List FertigationInsert(FertigationDetailsViewModel fgvm) injectionRateUnitId = Convert.ToInt32(fgvm.selInjectionRateUnitOption), groupID = groupID }; + + bool isCustomFertigation = fgvm.selTypOption == "4"; + fgvm.manualEntry = isCustomFertigation; + + if (isCustomFertigation) + { + decimal customN = Convert.ToDecimal(fgvm.calcN); + decimal customP = Convert.ToDecimal(fgvm.calcP2o5); + decimal customK = Convert.ToDecimal(fgvm.calcK2o); + + nf.customN = customN; + nf.customP2o5 = customP; + nf.customK2o = customK; + nf.fertN = customN; + nf.fertP2o5 = customP; + nf.fertK2o = customK; + } + ids.Add( _ud.AddFieldNutrientsFertilizer(fgvm.fieldName, nf)); } return ids; @@ -900,6 +976,23 @@ private void FertigationUpdate(FertigationDetailsViewModel fgvm) isFertigation = true }; + bool isCustomFertigation = fgvm.selTypOption == "4"; + fgvm.manualEntry = isCustomFertigation; + + if (isCustomFertigation) + { + decimal customN = Convert.ToDecimal(fgvm.valN); + decimal customP = Convert.ToDecimal(fgvm.valP2o5); + decimal customK = Convert.ToDecimal(fgvm.valK2o); + + nf.customN = customN; + nf.customP2o5 = customP; + nf.customK2o = customK; + nf.fertN = customN; + nf.fertP2o5 = customP; + nf.fertK2o = customK; + } + _ud.AddFieldNutrientsFertilizer(fgvm.fieldName, nf); } } diff --git a/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs b/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs index b8489647..003b8d90 100644 --- a/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs +++ b/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs @@ -79,9 +79,17 @@ public class FertigationDetailsViewModel [DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}", ApplyFormatInEditMode = true)] public DateTime? applDate { get; set; } public bool manualEntry { get; set; } + + [Required(ErrorMessage = "Required")] + [Range(0, 9999, ErrorMessage = "Required")] public string valN { get; set; } + [Required(ErrorMessage = "Required")] + [Range(0, 9999, ErrorMessage = "Required")] public string valP2o5 { get; set; } + [Required(ErrorMessage = "Required")] + [Range(0, 9999, ErrorMessage = "Required")] public string valK2o { get; set; } + public string calcN { get; set; } public string calcP2o5 { get; set; } public string calcK2o { get; set; } diff --git a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml index 4289ef04..2f3c8303 100644 --- a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml +++ b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml @@ -23,30 +23,30 @@
- - @if(Model.selTypOption == "4"){ -
- + @if(Model.selTypOption == "4"){ // if custom liquid fertigation +
+
-
- +
+
-
- +
+
} else { +