diff --git a/src/DataTables/Filters/Constraints/Part/LessThanDesiredConstraint.php b/src/DataTables/Filters/Constraints/Part/LessThanDesiredConstraint.php
new file mode 100644
index 00000000..34d5c157
--- /dev/null
+++ b/src/DataTables/Filters/Constraints/Part/LessThanDesiredConstraint.php
@@ -0,0 +1,47 @@
+.
+ */
+
+namespace App\DataTables\Filters\Constraints\Part;
+
+use App\DataTables\Filters\Constraints\BooleanConstraint;
+use Doctrine\ORM\QueryBuilder;
+
+class LessThanDesiredConstraint extends BooleanConstraint
+{
+ public function __construct(string $property = null, string $identifier = null, ?bool $default_value = null)
+ {
+ parent::__construct($property ?? 'amountSum', $identifier, $default_value);
+ }
+
+ public function apply(QueryBuilder $queryBuilder): void
+ {
+ //Do not apply a filter if value is null (filter is set to ignore)
+ if(!$this->isEnabled()) {
+ return;
+ }
+
+ //If value is true, we want to filter for parts with stock < desired stock
+ if ($this->value) {
+ $queryBuilder->andHaving('amountSum < part.minamount');
+ } else {
+ $queryBuilder->andHaving('amountSum >= part.minamount');
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DataTables/Filters/PartFilter.php b/src/DataTables/Filters/PartFilter.php
index dabf005e..9ce90cd6 100644
--- a/src/DataTables/Filters/PartFilter.php
+++ b/src/DataTables/Filters/PartFilter.php
@@ -26,6 +26,7 @@ use App\DataTables\Filters\Constraints\DateTimeConstraint;
use App\DataTables\Filters\Constraints\EntityConstraint;
use App\DataTables\Filters\Constraints\IntConstraint;
use App\DataTables\Filters\Constraints\NumberConstraint;
+use App\DataTables\Filters\Constraints\Part\LessThanDesiredConstraint;
use App\DataTables\Filters\Constraints\Part\ParameterConstraint;
use App\DataTables\Filters\Constraints\Part\TagsConstraint;
use App\DataTables\Filters\Constraints\TextConstraint;
@@ -68,6 +69,15 @@ class PartFilter implements FilterInterface
protected EntityConstraint $storelocation;
protected IntConstraint $lotCount;
protected IntConstraint $amountSum;
+ protected LessThanDesiredConstraint $lessThanDesired;
+
+ /**
+ * @return LessThanDesiredConstraint
+ */
+ public function getLessThanDesired(): LessThanDesiredConstraint
+ {
+ return $this->lessThanDesired;
+ }
protected BooleanConstraint $lotNeedsRefill;
protected TextConstraint $lotDescription;
protected BooleanConstraint $lotUnknownAmount;
@@ -108,6 +118,7 @@ class PartFilter implements FilterInterface
//We have to use Having here, as we use an alias column which is not supported on the where clause and would result in an error
$this->amountSum = (new IntConstraint('amountSum'))->useHaving();
$this->lotCount = new IntConstraint('COUNT(partLots)');
+ $this->lessThanDesired = new LessThanDesiredConstraint();
$this->storelocation = new EntityConstraint($nodesListBuilder, Storelocation::class, 'partLots.storage_location');
$this->lotNeedsRefill = new BooleanConstraint('partLots.needs_refill');
diff --git a/src/Form/Filters/PartFilterType.php b/src/Form/Filters/PartFilterType.php
index 347948a2..668ea5ec 100644
--- a/src/Form/Filters/PartFilterType.php
+++ b/src/Form/Filters/PartFilterType.php
@@ -206,6 +206,10 @@ class PartFilterType extends AbstractType
'min' => 0,
]);
+ $builder->add('lessThanDesired', BooleanConstraintType::class, [
+ 'label' => 'part.filter.lessThanDesired'
+ ]);
+
$builder->add('lotNeedsRefill', BooleanConstraintType::class, [
'label' => 'part.filter.lotNeedsRefill'
]);
diff --git a/templates/parts/lists/_filter.html.twig b/templates/parts/lists/_filter.html.twig
index 9cf2ee02..4c40cd09 100644
--- a/templates/parts/lists/_filter.html.twig
+++ b/templates/parts/lists/_filter.html.twig
@@ -62,6 +62,7 @@
{{ form_row(filterForm.storelocation) }}
{{ form_row(filterForm.minAmount) }}
{{ form_row(filterForm.amountSum) }}
+ {{ form_row(filterForm.lessThanDesired) }}
{{ form_row(filterForm.lotCount) }}
{{ form_row(filterForm.lotExpirationDate) }}
{{ form_row(filterForm.lotDescription) }}
diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf
index eeee86b6..f436a5e1 100644
--- a/translations/messages.en.xlf
+++ b/translations/messages.en.xlf
@@ -11271,5 +11271,11 @@ Element 3
Part owner must match storage location owner
+
+
+ part.filter.lessThanDesired
+
+
+