_CraftMaterialPartial.cshtml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. @model GreenTree.Strohrmann.ERP.Web.Models.Business.CraftMaterialModel
  2. @{
  3. var id = Model != null && !String.IsNullOrEmpty(Model.DictIdentifier) ? Model.DictIdentifier : Html.RandomId();
  4. }
  5. <script type="text/javascript">
  6. @{
  7. <text>
  8. function recalculateMaterialValue_@id (input) {
  9. if (input != null && input.name == "CraftMaterials[@id].Value") {
  10. $.ajax({
  11. method: "POST",
  12. url: "@Url.Action("CalculateMaterialCalculationFactor", "Craft")",
  13. data: {
  14. MaterialId: $("input[name='CraftMaterials[@id].MaterialId']").val(),
  15. Amount: $("input[name='CraftMaterials[@id].Amount']").val().replace('.', ','),
  16. Value: $("input[name='CraftMaterials[@id].Value']").val()
  17. },
  18. success: function (data) {
  19. $("input[name='CraftMaterials[@id].CalculationFactor']").val(data);
  20. calculateMaterialAggregation();
  21. },
  22. error: function (msg) {
  23. }
  24. });
  25. } else {
  26. $.ajax({
  27. method: "POST",
  28. url: "@Url.Action("CalculateMaterialValue", "Craft")",
  29. data: {
  30. MaterialId: $("input[name='CraftMaterials[@id].MaterialId']").val(),
  31. Amount: $("input[name='CraftMaterials[@id].Amount']").val().replace('.', ','),
  32. CalculationFactor: $("input[name='CraftMaterials[@id].CalculationFactor']").val().replace('.', ',')
  33. },
  34. success: function (data) {
  35. $("input[name='CraftMaterials[@id].Value']").val(data);
  36. calculateMaterialAggregation();
  37. },
  38. error: function (msg) {
  39. }
  40. });
  41. }
  42. }
  43. </text>
  44. }
  45. </script>
  46. <div class="row align-items-start">
  47. <input type="hidden" asp-for="Index" name="CraftMaterials[@id].Index" />
  48. <input type="hidden" asp-for="DictIdentifier" name="CraftMaterials[@id].DictIdentifier" value="@id" />
  49. <div class="form-group col-md-3">
  50. @if (Model == null || (Model != null && (!Model.Index.HasValue || Model.Index == 0)))
  51. {
  52. <label asp-for="MaterialId" class="control-label"></label>
  53. }
  54. @Html.SearchFor(
  55. m => m.MaterialId,
  56. m => m.MaterialText,
  57. Url.Action("Search", "Material"),
  58. new { name = String.Format("CraftMaterials[{0}].MaterialId", id) },
  59. new
  60. {
  61. name = String.Format("CraftMaterials[{0}].MaterialText", id),
  62. onblur = String.Format("calculateMaterialAggregation(); recalculateMaterialValue_{0}(this);", id)
  63. }
  64. )
  65. @Html.ValidationMessage(String.Format("CraftMaterials[{0}].MaterialId", id), new { @class = "text-danger" })
  66. </div>
  67. <div class="form-group col-md-2">
  68. @if (Model == null || (Model != null && (!Model.Index.HasValue || Model.Index == 0)))
  69. {
  70. <label asp-for="Amount" class="control-label"></label>
  71. }
  72. <div class="input-group">
  73. <div class="input-group-prepend">
  74. <span class="input-group-text">Stk.</span>
  75. </div>
  76. <input name="CraftMaterials[@id].Amount" type="number" min="0.00" step="0.50" class="form-control"
  77. id="CraftMaterials[@id].Amount"
  78. value="@(Model == null ? "0.00" : Model.Amount.ToString("G29"))"
  79. onchange="calculateMaterialAggregation(); recalculateMaterialValue_@id (this);" />
  80. </div>
  81. @Html.ValidationMessage(String.Format("CraftMaterials[{0}].Amount", id), new { @class = "text-danger" })
  82. </div>
  83. <div class="form-group col-md-3">
  84. @if (Model == null || (Model != null && (!Model.Index.HasValue || Model.Index == 0)))
  85. {
  86. <label asp-for="CalculationFactor" class="control-label"></label>
  87. }
  88. <div class="input-group">
  89. <div class="input-group-prepend">
  90. <span class="input-group-text">%</span>
  91. </div>
  92. <input asp-for="CalculationFactor" name="CraftMaterials[@id].CalculationFactor"
  93. type="number" min="0" step="0.5"
  94. value="@((Model == null ? 120f : Model.CalculationFactor).ToString().Replace(',','.'))"
  95. class="form-control" data-aggregation="materialCalculationFactor"
  96. onchange="calculateMaterialAggregation(); recalculateMaterialValue_@id (this);" />
  97. </div>
  98. @Html.ValidationMessage(String.Format("CraftMaterials[{0}].CalculationFactor", id), new { @class = "text-danger" })
  99. </div>
  100. <div class="form-group col-md-3">
  101. @if (Model == null || (Model != null && (!Model.Index.HasValue || Model.Index == 0)))
  102. {
  103. <label asp-for="Value" class="control-label"></label>
  104. }
  105. <div class="input-group">
  106. <div class="input-group-prepend">
  107. <span class="input-group-text">€</span>
  108. </div>
  109. <input asp-for="Value" name="CraftMaterials[@id].Value" type="number" min="0.00" step="1" class="form-control"
  110. data-aggregation="materialValue"
  111. onchange="calculateMaterialAggregation(); recalculateMaterialValue_@id (this);"/>
  112. </div>
  113. @Html.ValidationMessage(String.Format("CraftMaterials[{0}].Value", id), new { @class = "text-danger" })
  114. </div>
  115. <div class="form-group col-md-1 pl-1">
  116. @if (Model != null && Model.Index > 0)
  117. {
  118. <button type="button" class="btn btn-danger" aria-label="Entfernen"
  119. onclick="$(this).closest('.row').remove(); calculateMaterialAggregation();">
  120. <span class="fas fa-trash"></span>
  121. </button>
  122. }
  123. </div>
  124. </div>