_CraftMaterialPartial.cshtml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. function getMaterialUnit_@id () {
  44. $.ajax({
  45. method: "POST",
  46. url: "@Url.Action("GetMaterialUnit", "Craft")",
  47. data: {
  48. MaterialId: $("input[name='CraftMaterials[@id].MaterialId']").val()
  49. },
  50. success: function (data) {
  51. $("#materialUnit_@id").text(data);
  52. },
  53. error: function (msg) {
  54. }
  55. });
  56. }
  57. </text>
  58. }
  59. </script>
  60. <div class="row align-items-start">
  61. <input type="hidden" asp-for="Index" name="CraftMaterials[@id].Index" />
  62. <input type="hidden" asp-for="DictIdentifier" name="CraftMaterials[@id].DictIdentifier" value="@id" />
  63. <div class="form-group col-md-3">
  64. @if (Model == null || (Model != null && (!Model.Index.HasValue || Model.Index == 0)))
  65. {
  66. <label asp-for="MaterialId" class="control-label"></label>
  67. }
  68. @Html.SearchFor(
  69. m => m.MaterialId,
  70. m => m.MaterialText,
  71. Url.Action("Search", "Material"),
  72. new { name = String.Format("CraftMaterials[{0}].MaterialId", id) },
  73. new
  74. {
  75. name = String.Format("CraftMaterials[{0}].MaterialText", id),
  76. onblur = String.Format("calculateMaterialAggregation(); getMaterialUnit_{0}(); recalculateMaterialValue_{0}(this);", id)
  77. }
  78. )
  79. @Html.ValidationMessage(String.Format("CraftMaterials[{0}].MaterialId", id), new { @class = "text-danger" })
  80. </div>
  81. <div class="form-group col-md-2">
  82. @if (Model == null || (Model != null && (!Model.Index.HasValue || Model.Index == 0)))
  83. {
  84. <label asp-for="Amount" class="control-label"></label>
  85. }
  86. <div class="input-group">
  87. <div class="input-group-prepend">
  88. <span id="materialUnit_@id" class="input-group-text">
  89. @(Model == null ? "Stck." : Model.Material.DefaultUnit.ShortName)
  90. </span>
  91. </div>
  92. <input name="CraftMaterials[@id].Amount" type="text" class="form-control"
  93. id="CraftMaterials[@id].Amount" data-restriction="numberOnly"
  94. value="@(Model == null ? 0.00f : Model.Amount)"
  95. onchange="calculateMaterialAggregation(); recalculateMaterialValue_@id (this);" />
  96. </div>
  97. @Html.ValidationMessage(String.Format("CraftMaterials[{0}].Amount", id), new { @class = "text-danger" })
  98. </div>
  99. <div class="form-group col-md-3">
  100. @if (Model == null || (Model != null && (!Model.Index.HasValue || Model.Index == 0)))
  101. {
  102. <label asp-for="CalculationFactor" class="control-label"></label>
  103. }
  104. <div class="input-group">
  105. <div class="input-group-prepend">
  106. <span class="input-group-text">%</span>
  107. </div>
  108. <input asp-for="CalculationFactor" name="CraftMaterials[@id].CalculationFactor"
  109. type="number" min="0" step="0.5"
  110. value="@((Model == null ? 120f : Model.CalculationFactor).ToString().Replace(',','.'))"
  111. class="form-control" data-aggregation="materialCalculationFactor"
  112. onchange="calculateMaterialAggregation(); recalculateMaterialValue_@id (this);" />
  113. </div>
  114. @Html.ValidationMessage(String.Format("CraftMaterials[{0}].CalculationFactor", id), new { @class = "text-danger" })
  115. </div>
  116. <div class="form-group col-md-3">
  117. @if (Model == null || (Model != null && (!Model.Index.HasValue || Model.Index == 0)))
  118. {
  119. <label asp-for="Value" class="control-label"></label>
  120. }
  121. <div class="input-group">
  122. <div class="input-group-prepend">
  123. <span class="input-group-text">@CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol</span>
  124. </div>
  125. <input asp-for="Value" name="CraftMaterials[@id].Value" type="number" min="0.00" step="1" class="form-control"
  126. data-aggregation="materialValue"
  127. onchange="calculateMaterialAggregation(); recalculateMaterialValue_@id (this);"/>
  128. </div>
  129. @Html.ValidationMessage(String.Format("CraftMaterials[{0}].Value", id), new { @class = "text-danger" })
  130. </div>
  131. <div class="form-group col-md-1 pl-1">
  132. @if (Model != null && Model.Index > 0)
  133. {
  134. <button type="button" class="btn btn-danger" aria-label="Entfernen"
  135. onclick="$(this).closest('.row').remove(); calculateMaterialAggregation();">
  136. <span class="fas fa-trash"></span>
  137. </button>
  138. }
  139. </div>
  140. </div>