mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 18:28:49 +02:00
Added a filter constraint for parts where instock is "less than desired"
Fixes issue #257
This commit is contained in:
parent
8bccab258a
commit
f91b719542
5 changed files with 69 additions and 0 deletions
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2023 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ use App\DataTables\Filters\Constraints\DateTimeConstraint;
|
||||||
use App\DataTables\Filters\Constraints\EntityConstraint;
|
use App\DataTables\Filters\Constraints\EntityConstraint;
|
||||||
use App\DataTables\Filters\Constraints\IntConstraint;
|
use App\DataTables\Filters\Constraints\IntConstraint;
|
||||||
use App\DataTables\Filters\Constraints\NumberConstraint;
|
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\ParameterConstraint;
|
||||||
use App\DataTables\Filters\Constraints\Part\TagsConstraint;
|
use App\DataTables\Filters\Constraints\Part\TagsConstraint;
|
||||||
use App\DataTables\Filters\Constraints\TextConstraint;
|
use App\DataTables\Filters\Constraints\TextConstraint;
|
||||||
|
@ -68,6 +69,15 @@ class PartFilter implements FilterInterface
|
||||||
protected EntityConstraint $storelocation;
|
protected EntityConstraint $storelocation;
|
||||||
protected IntConstraint $lotCount;
|
protected IntConstraint $lotCount;
|
||||||
protected IntConstraint $amountSum;
|
protected IntConstraint $amountSum;
|
||||||
|
protected LessThanDesiredConstraint $lessThanDesired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return LessThanDesiredConstraint
|
||||||
|
*/
|
||||||
|
public function getLessThanDesired(): LessThanDesiredConstraint
|
||||||
|
{
|
||||||
|
return $this->lessThanDesired;
|
||||||
|
}
|
||||||
protected BooleanConstraint $lotNeedsRefill;
|
protected BooleanConstraint $lotNeedsRefill;
|
||||||
protected TextConstraint $lotDescription;
|
protected TextConstraint $lotDescription;
|
||||||
protected BooleanConstraint $lotUnknownAmount;
|
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
|
//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->amountSum = (new IntConstraint('amountSum'))->useHaving();
|
||||||
$this->lotCount = new IntConstraint('COUNT(partLots)');
|
$this->lotCount = new IntConstraint('COUNT(partLots)');
|
||||||
|
$this->lessThanDesired = new LessThanDesiredConstraint();
|
||||||
|
|
||||||
$this->storelocation = new EntityConstraint($nodesListBuilder, Storelocation::class, 'partLots.storage_location');
|
$this->storelocation = new EntityConstraint($nodesListBuilder, Storelocation::class, 'partLots.storage_location');
|
||||||
$this->lotNeedsRefill = new BooleanConstraint('partLots.needs_refill');
|
$this->lotNeedsRefill = new BooleanConstraint('partLots.needs_refill');
|
||||||
|
|
|
@ -206,6 +206,10 @@ class PartFilterType extends AbstractType
|
||||||
'min' => 0,
|
'min' => 0,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$builder->add('lessThanDesired', BooleanConstraintType::class, [
|
||||||
|
'label' => 'part.filter.lessThanDesired'
|
||||||
|
]);
|
||||||
|
|
||||||
$builder->add('lotNeedsRefill', BooleanConstraintType::class, [
|
$builder->add('lotNeedsRefill', BooleanConstraintType::class, [
|
||||||
'label' => 'part.filter.lotNeedsRefill'
|
'label' => 'part.filter.lotNeedsRefill'
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
{{ form_row(filterForm.storelocation) }}
|
{{ form_row(filterForm.storelocation) }}
|
||||||
{{ form_row(filterForm.minAmount) }}
|
{{ form_row(filterForm.minAmount) }}
|
||||||
{{ form_row(filterForm.amountSum) }}
|
{{ form_row(filterForm.amountSum) }}
|
||||||
|
{{ form_row(filterForm.lessThanDesired) }}
|
||||||
{{ form_row(filterForm.lotCount) }}
|
{{ form_row(filterForm.lotCount) }}
|
||||||
{{ form_row(filterForm.lotExpirationDate) }}
|
{{ form_row(filterForm.lotExpirationDate) }}
|
||||||
{{ form_row(filterForm.lotDescription) }}
|
{{ form_row(filterForm.lotDescription) }}
|
||||||
|
|
|
@ -11271,5 +11271,11 @@ Element 3</target>
|
||||||
<target>Part owner must match storage location owner</target>
|
<target>Part owner must match storage location owner</target>
|
||||||
</segment>
|
</segment>
|
||||||
</unit>
|
</unit>
|
||||||
|
<unit id="u6qFa_j" name="part.filter.lessThanDesired">
|
||||||
|
<segment>
|
||||||
|
<source>part.filter.lessThanDesired</source>
|
||||||
|
<target><![CDATA[In stock less than desired (total amount < min. amount)]]></target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue