diff --git a/assets/controllers/pages/dont_check_quantity_checkbox_controller.js b/assets/controllers/pages/dont_check_quantity_checkbox_controller.js
new file mode 100644
index 00000000..2abd3d77
--- /dev/null
+++ b/assets/controllers/pages/dont_check_quantity_checkbox_controller.js
@@ -0,0 +1,65 @@
+/*
+ * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
+ *
+ * Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+import {Controller} from "@hotwired/stimulus";
+
+/**
+ * This controller is used on a checkbox, which toggles the max value of all number input fields
+ */
+export default class extends Controller {
+
+ _checkbox;
+
+ getCheckbox() {
+ if (this._checkbox) {
+ return this._checkbox;
+ }
+
+ //Find the checkbox inside the controller element
+ this._checkbox = this.element.querySelector('input[type="checkbox"]');
+ return this._checkbox;
+ }
+
+ connect() {
+ //Add event listener to the checkbox
+ this.getCheckbox().addEventListener('change', this.toggleInputLimits.bind(this));
+ }
+
+ toggleInputLimits() {
+ //Find all input fields with the data-toggle-input-limits-target="max"
+ const inputFields = document.querySelectorAll("input[type='number']");
+
+ inputFields.forEach((inputField) => {
+ //Ensure that the input field has either a max or a data-max attribute
+ if (!inputField.hasAttribute('max') && !inputField.hasAttribute('data-max')) {
+ return;
+ }
+
+ //If the checkbox is checked, rename the max attribute to data-max
+ if (this.getCheckbox().checked) {
+ inputField.setAttribute('data-max', inputField.getAttribute('max'));
+ inputField.removeAttribute('max');
+ } else {
+ //If the checkbox is not checked, rename the data-max attribute back to max
+ inputField.setAttribute('max', inputField.getAttribute('data-max'));
+ inputField.removeAttribute('data-max');
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/src/Form/ProjectSystem/ProjectBuildType.php b/src/Form/ProjectSystem/ProjectBuildType.php
index 82489471..3fdc491f 100644
--- a/src/Form/ProjectSystem/ProjectBuildType.php
+++ b/src/Form/ProjectSystem/ProjectBuildType.php
@@ -62,6 +62,15 @@ class ProjectBuildType extends AbstractType implements DataMapperInterface
'disabled' => !$this->security->isGranted('@parts_stock.withdraw'),
]);
+ $builder->add('dontCheckQuantity', CheckboxType::class, [
+ 'label' => 'project.build.dont_check_quantity',
+ 'help' => 'project.build.dont_check_quantity.help',
+ 'required' => false,
+ 'attr' => [
+ 'data-controller' => 'pages--dont-check-quantity-checkbox'
+ ]
+ ]);
+
$builder->add('comment', TextType::class, [
'label' => 'part.info.withdraw_modal.comment',
'help' => 'part.info.withdraw_modal.comment.hint',
@@ -124,6 +133,7 @@ class ProjectBuildType extends AbstractType implements DataMapperInterface
}
$forms['comment']->setData($data->getComment());
+ $forms['dontCheckQuantity']->setData($data->isDontCheckQuantity());
$forms['addBuildsToBuildsPart']->setData($data->getAddBuildsToBuildsPart());
if (isset($forms['buildsPartLot'])) {
$forms['buildsPartLot']->setData($data->getBuildsPartLot());
@@ -150,6 +160,8 @@ class ProjectBuildType extends AbstractType implements DataMapperInterface
}
$data->setComment($forms['comment']->getData());
+ $data->setDontCheckQuantity($forms['dontCheckQuantity']->getData());
+
if (isset($forms['buildsPartLot'])) {
$lot = $forms['buildsPartLot']->getData();
if (!$lot) { //When the user selected "Create new lot", create a new lot
diff --git a/src/Helpers/Projects/ProjectBuildRequest.php b/src/Helpers/Projects/ProjectBuildRequest.php
index 36035744..c2c2ad90 100644
--- a/src/Helpers/Projects/ProjectBuildRequest.php
+++ b/src/Helpers/Projects/ProjectBuildRequest.php
@@ -47,6 +47,8 @@ final class ProjectBuildRequest
private bool $add_build_to_builds_part = false;
+ private bool $dont_check_quantity = false;
+
/**
* @param Project $project The project that should be build
* @param int $number_of_builds The number of builds that should be created
@@ -283,4 +285,26 @@ final class ProjectBuildRequest
{
return $this->number_of_builds;
}
+
+ /**
+ * If Set to true, the given withdraw amounts are used without any checks for requirements.
+ * @return bool
+ */
+ public function isDontCheckQuantity(): bool
+ {
+ return $this->dont_check_quantity;
+ }
+
+ /**
+ * Set to true, the given withdraw amounts are used without any checks for requirements.
+ * @param bool $dont_check_quantity
+ * @return $this
+ */
+ public function setDontCheckQuantity(bool $dont_check_quantity): ProjectBuildRequest
+ {
+ $this->dont_check_quantity = $dont_check_quantity;
+ return $this;
+ }
+
+
}
diff --git a/src/Validator/Constraints/ProjectSystem/ValidProjectBuildRequestValidator.php b/src/Validator/Constraints/ProjectSystem/ValidProjectBuildRequestValidator.php
index e5de07d2..2d59e648 100644
--- a/src/Validator/Constraints/ProjectSystem/ValidProjectBuildRequestValidator.php
+++ b/src/Validator/Constraints/ProjectSystem/ValidProjectBuildRequestValidator.php
@@ -69,12 +69,12 @@ class ValidProjectBuildRequestValidator extends ConstraintValidator
->addViolation();
}
- if ($withdraw_sum > $needed_amount) {
+ if ($withdraw_sum > $needed_amount && $value->isDontCheckQuantity() === false) {
$this->buildViolationForLot($lot, 'validator.project_build.lot_bigger_than_needed')
->addViolation();
}
- if ($withdraw_sum < $needed_amount) {
+ if ($withdraw_sum < $needed_amount && $value->isDontCheckQuantity() === false) {
$this->buildViolationForLot($lot, 'validator.project_build.lot_smaller_than_needed')
->addViolation();
}
diff --git a/templates/projects/build/_form.html.twig b/templates/projects/build/_form.html.twig
index 4a02dd4d..a8f772e9 100644
--- a/templates/projects/build/_form.html.twig
+++ b/templates/projects/build/_form.html.twig
@@ -74,6 +74,9 @@
{{ form_row(form.comment) }}
+
+{{ form_row(form.dontCheckQuantity) }}
+
{{ form_row(form.addBuildsToBuildsPart) }}
{% if form.buildsPartLot is defined %}
diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf
index 92e04ef6..b1387196 100644
--- a/translations/messages.en.xlf
+++ b/translations/messages.en.xlf
@@ -11603,5 +11603,17 @@ Please note, that you can not impersonate a disabled user. If you try you will g
Show available Part-DB updates
+
+
+ project.build.dont_check_quantity
+ Do not check quantities
+
+
+
+
+ project.build.dont_check_quantity.help
+ If this option is selected, the given withdraw quantities are used as given, no matter if more or less parts are actually required to build this project.
+
+