First order details draft

This commit is contained in:
Fabian Wunsch 2024-09-05 15:41:00 +02:00
parent 1a0fab0615
commit 62754bdbf3
13 changed files with 170 additions and 7 deletions

View file

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use App\Migration\AbstractMultiPlatformMigration;
use Doctrine\DBAL\Schema\Schema;
final class Version20240905085300 extends AbstractMultiPlatformMigration
{
public function getDescription(): string
{
return 'Added order fields';
}
public function mySQLUp(Schema $schema): void
{
$this->addSql('ALTER TABLE parts ADD orderamount DOUBLE PRECISION NOT NULL DEFAULT 0, ADD orderDate DATETIME');
}
public function mySQLDown(Schema $schema): void
{
$this->addSql('ALTER TABLE `parts` DROP orderamount, DROP orderDate');
}
public function sqLiteUp(Schema $schema): void
{
$this->addSql('ALTER TABLE parts ADD COLUMN orderamount DOUBLE PRECISION NOT NULL DEFAULT 0');
$this->addSql('ALTER TABLE parts ADD COLUMN orderDate DATETIME');
}
public function sqLiteDown(Schema $schema): void
{
$error;
// TODO: implement backwards migration for SQlite
}
}

View file

@ -48,9 +48,9 @@ class LessThanDesiredConstraint extends BooleanConstraint
//If value is true, we want to filter for parts with stock < desired stock //If value is true, we want to filter for parts with stock < desired stock
if ($this->value) { if ($this->value) {
$queryBuilder->andHaving( $this->property . ' < part.minamount'); $queryBuilder->andHaving($this->property . ' + part.orderamount < part.minamount');
} else { } else {
$queryBuilder->andHaving($this->property . ' >= part.minamount'); $queryBuilder->andHaving($this->property . ' + part.orderamount >= part.minamount');
} }
} }
} }

View file

@ -59,6 +59,8 @@ class PartFilter implements FilterInterface
public readonly TextConstraint $comment; public readonly TextConstraint $comment;
public readonly TagsConstraint $tags; public readonly TagsConstraint $tags;
public readonly NumberConstraint $minAmount; public readonly NumberConstraint $minAmount;
public readonly NumberConstraint $orderAmount;
public readonly DateTimeConstraint $orderDelivery;
public readonly BooleanConstraint $favorite; public readonly BooleanConstraint $favorite;
public readonly BooleanConstraint $needsReview; public readonly BooleanConstraint $needsReview;
public readonly NumberConstraint $mass; public readonly NumberConstraint $mass;
@ -124,6 +126,8 @@ class PartFilter implements FilterInterface
$this->lastModified = new DateTimeConstraint('part.lastModified'); $this->lastModified = new DateTimeConstraint('part.lastModified');
$this->minAmount = new NumberConstraint('part.minamount'); $this->minAmount = new NumberConstraint('part.minamount');
$this->orderAmount = new NumberConstraint('part.orderamount');
$this->orderDelivery = new DateTimeConstraint('part.orderDelivery');
/* We have to use an IntConstraint here because otherwise we get just an empty result list when applying the filter /* We have to use an IntConstraint here because otherwise we get just an empty result list when applying the filter
This seems to be related to the fact, that PDO does not have an float parameter type and using string type does not work in this situation (at least in SQLite) This seems to be related to the fact, that PDO does not have an float parameter type and using string type does not work in this situation (at least in SQLite)
TODO: Find a better solution here TODO: Find a better solution here

View file

@ -155,6 +155,15 @@ final class PartsDataTable implements DataTableTypeInterface
'render' => fn($value, Part $context): string => htmlspecialchars($this->amountFormatter->format($value, 'render' => fn($value, Part $context): string => htmlspecialchars($this->amountFormatter->format($value,
$context->getPartUnit())), $context->getPartUnit())),
]) ])
->add('orderamount', TextColumn::class, [
'label' => $this->translator->trans('part.table.orderamount'),
'render' => fn($value, Part $context): string => htmlspecialchars($this->amountFormatter->format($value,
$context->getPartUnit())),
])
->add('orderDelivery', LocaleDateTimeColumn::class, [
'label' => $this->translator->trans('part.table.orderDelivery'),
'timeFormat' => 'none',
])
->add('partUnit', TextColumn::class, [ ->add('partUnit', TextColumn::class, [
'label' => $this->translator->trans('part.table.partUnit'), 'label' => $this->translator->trans('part.table.partUnit'),
'orderField' => 'NATSORT(_partUnit.name)', 'orderField' => 'NATSORT(_partUnit.name)',

View file

@ -60,6 +60,7 @@ use App\Validator\Constraints\UniqueObjectCollection;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
@ -101,9 +102,9 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ApiFilter(LikeFilter::class, properties: ["name", "comment", "description", "ipn", "manufacturer_product_number"])] #[ApiFilter(LikeFilter::class, properties: ["name", "comment", "description", "ipn", "manufacturer_product_number"])]
#[ApiFilter(TagFilter::class, properties: ["tags"])] #[ApiFilter(TagFilter::class, properties: ["tags"])]
#[ApiFilter(BooleanFilter::class, properties: ["favorite" , "needs_review"])] #[ApiFilter(BooleanFilter::class, properties: ["favorite" , "needs_review"])]
#[ApiFilter(RangeFilter::class, properties: ["mass", "minamount"])] #[ApiFilter(RangeFilter::class, properties: ["mass", "minamount", "orderamount"])]
#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)] #[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)]
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])] #[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'orderDelivery', 'addedDate', 'lastModified'])]
class Part extends AttachmentContainingDBElement class Part extends AttachmentContainingDBElement
{ {
use AdvancedPropertyTrait; use AdvancedPropertyTrait;
@ -126,6 +127,15 @@ class Part extends AttachmentContainingDBElement
#[UniqueObjectCollection(fields: ['name', 'group', 'element'])] #[UniqueObjectCollection(fields: ['name', 'group', 'element'])]
protected Collection $parameters; protected Collection $parameters;
/**
* @var \DateTimeInterface|null Set a time when the new order will arive.
* Set to null, if there is no known date or no order.
*/
#[Groups(['extended', 'full', 'import', 'part_lot:read', 'part_lot:write'])]
#[ORM\Column(name: 'orderDelivery', type: Types::DATETIME_MUTABLE, nullable: true)]
#[Year2038BugWorkaround]
protected ?\DateTimeInterface $orderDelivery = null;
/** ************************************************************* /** *************************************************************
* Overridden properties * Overridden properties
@ -216,6 +226,26 @@ class Part extends AttachmentContainingDBElement
parent::__clone(); parent::__clone();
} }
/**
* Gets the expected delivery date of the part. Returns null, if no delivery is due.
*/
public function getOrderDelivery(): ?\DateTimeInterface
{
return $this->orderDelivery;
}
/**
* Sets the expected delivery date of the part. Set to null, if no delivery is due.
*
*
*/
public function setOrderDelivery(?\DateTimeInterface $orderDelivery): self
{
$this->orderDelivery = $orderDelivery;
return $this;
}
#[Assert\Callback] #[Assert\Callback]
public function validate(ExecutionContextInterface $context, $payload): void public function validate(ExecutionContextInterface $context, $payload): void
{ {

View file

@ -55,6 +55,14 @@ trait InstockTrait
#[ORM\Column(type: Types::FLOAT)] #[ORM\Column(type: Types::FLOAT)]
protected float $minamount = 0; protected float $minamount = 0;
/**
* @var float The number of already ordered units
*/
#[Assert\PositiveOrZero]
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\Column(type: Types::FLOAT)]
protected float $orderamount = 0;
/** /**
* @var ?MeasurementUnit the unit in which the part's amount is measured * @var ?MeasurementUnit the unit in which the part's amount is measured
*/ */
@ -137,6 +145,21 @@ trait InstockTrait
return round($this->minamount); return round($this->minamount);
} }
/**
* Get the count of parts which are already ordered.
* If an integer-based part unit is selected, the value will be rounded to integers.
*
* @return float count of parts which are already ordered
*/
public function getOrderAmount(): float
{
if ($this->useFloatAmount()) {
return $this->orderamount;
}
return round($this->orderamount);
}
/** /**
* Checks if this part uses the float amount . * Checks if this part uses the float amount .
* This setting is based on the part unit (see MeasurementUnit->isInteger()). * This setting is based on the part unit (see MeasurementUnit->isInteger()).
@ -158,7 +181,7 @@ trait InstockTrait
*/ */
public function isNotEnoughInstock(): bool public function isNotEnoughInstock(): bool
{ {
return $this->getAmountSum() < $this->getMinAmount(); return ($this->getAmountSum() + $this->getOrderAmount()) < $this->getMinAmount();
} }
/** /**
@ -238,4 +261,19 @@ trait InstockTrait
return $this; return $this;
} }
/**
* Set the amount of already ordered parts.
* See getPartUnit() for the associated unit.
*
* @param float $new_orderamount the new count of parts are already ordered
*
* @return $this
*/
public function setOrderAmount(float $new_orderamount): self
{
$this->orderamount = $new_orderamount;
return $this;
}
} }

View file

@ -202,6 +202,16 @@ class PartFilterType extends AbstractType
'min' => 0, 'min' => 0,
]); ]);
$builder->add('orderAmount', NumberConstraintType::class, [
'label' => 'part.edit.orderstock',
'min' => 0,
]);
$builder->add('orderDelivery', DateTimeConstraintType::class, [
'label' => 'part.edit.orderDelivery',
'input_type' => DateType::class,
]);
$builder->add('lotCount', NumberConstraintType::class, [ $builder->add('lotCount', NumberConstraintType::class, [
'label' => 'part.filter.lot_count', 'label' => 'part.filter.lot_count',
'min' => 0, 'min' => 0,

View file

@ -45,6 +45,7 @@ use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EnumType; use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\ResetType; use Symfony\Component\Form\Extension\Core\Type\ResetType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
@ -96,6 +97,21 @@ class PartBaseType extends AbstractType
'label' => 'part.edit.mininstock', 'label' => 'part.edit.mininstock',
'measurement_unit' => $part->getPartUnit(), 'measurement_unit' => $part->getPartUnit(),
]) ])
->add('orderAmount', SIUnitType::class, [
'attr' => [
'min' => 0,
'placeholder' => 'part.editmininstock.placeholder',
],
'label' => 'part.edit.orderstock',
'measurement_unit' => $part->getPartUnit(),
])
->add('orderDelivery', DateType::class, [
'label' => 'part.edit.orderDelivery',
'attr' => [],
'widget' => 'single_text',
'model_timezone' => 'UTC',
'required' => false,
])
->add('category', StructuralEntityType::class, [ ->add('category', StructuralEntityType::class, [
'class' => Category::class, 'class' => Category::class,
'allow_add' => $this->security->isGranted('@categories.create'), 'allow_add' => $this->security->isGranted('@categories.create'),

View file

@ -136,6 +136,9 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface, Norm
if (empty($data['minamount'])) { if (empty($data['minamount'])) {
$data['minamount'] = 0.0; $data['minamount'] = 0.0;
} }
if (empty($data['orderamount'])) {
$data['orderamount'] = 0.0;
}
$context[self::ALREADY_CALLED] = true; $context[self::ALREADY_CALLED] = true;

View file

@ -133,7 +133,7 @@ final class SandboxedTwigFactory
Supplier::class => ['getShippingCosts', 'getDefaultCurrency'], Supplier::class => ['getShippingCosts', 'getDefaultCurrency'],
Part::class => ['isNeedsReview', 'getTags', 'getMass', 'getIpn', 'getProviderReference', Part::class => ['isNeedsReview', 'getTags', 'getMass', 'getIpn', 'getProviderReference',
'getDescription', 'getComment', 'isFavorite', 'getCategory', 'getFootprint', 'getDescription', 'getComment', 'isFavorite', 'getCategory', 'getFootprint',
'getPartLots', 'getPartUnit', 'useFloatAmount', 'getMinAmount', 'getAmountSum', 'isNotEnoughInstock', 'isAmountUnknown', 'getExpiredAmountSum', 'getPartLots', 'getPartUnit', 'useFloatAmount', 'getMinAmount', 'getOrderAmount', 'getOrderDate', 'getAmountSum', 'isNotEnoughInstock', 'isAmountUnknown', 'getExpiredAmountSum',
'getManufacturerProductUrl', 'getCustomProductURL', 'getManufacturingStatus', 'getManufacturer', 'getManufacturerProductUrl', 'getCustomProductURL', 'getManufacturingStatus', 'getManufacturer',
'getManufacturerProductNumber', 'getOrderdetails', 'isObsolete', 'getManufacturerProductNumber', 'getOrderdetails', 'isObsolete',
'getParameters', 'getGroupedParameters', 'getParameters', 'getGroupedParameters',

View file

@ -10,6 +10,8 @@
{{ form_row(form.category) }} {{ form_row(form.category) }}
{{ form_row(form.tags) }} {{ form_row(form.tags) }}
{{ form_row(form.minAmount) }} {{ form_row(form.minAmount) }}
{{ form_row(form.orderAmount) }}
{{ form_row(form.orderDate) }}
{{ form_row(form.footprint) }} {{ form_row(form.footprint) }}

View file

@ -76,6 +76,17 @@
{% if part.expiredAmountSum > 0 %} {% if part.expiredAmountSum > 0 %}
<span title="{% trans %}part_lots.is_expired{% endtrans %}" class="text-muted">(+{{ part.expiredAmountSum }})</span> <span title="{% trans %}part_lots.is_expired{% endtrans %}" class="text-muted">(+{{ part.expiredAmountSum }})</span>
{% endif %} {% endif %}
{% if part.orderAmount > 0 %}
(+
<span title="{% trans %}orderstock.label{% endtrans %}">{{ part.orderAmount | format_amount(part.partUnit) }}</span>
{% if part.orderDate %}
@
<span class="badge bg-info mb-1" title="{% trans %}part.filter.orderDate{% endtrans %}">
<i class="fas fa-calendar-alt fa-fw"></i> {{ part.orderDate | format_date() }}<br>
</span>
{% endif %}
)
{% endif %}
/ /
<span title="{% trans %}mininstock.label{% endtrans %}">{{ part.minAmount | format_amount(part.partUnit) }}</span> <span title="{% trans %}mininstock.label{% endtrans %}">{{ part.minAmount | format_amount(part.partUnit) }}</span>
</span> </span>

View file

@ -66,6 +66,8 @@
<div class="tab-pane pt-3" id="filter-stocks" role="tabpanel" aria-labelledby="filter-stocks-tab" tabindex="0"> <div class="tab-pane pt-3" id="filter-stocks" role="tabpanel" aria-labelledby="filter-stocks-tab" tabindex="0">
{{ form_row(filterForm.storelocation) }} {{ form_row(filterForm.storelocation) }}
{{ form_row(filterForm.minAmount) }} {{ form_row(filterForm.minAmount) }}
{{ form_row(filterForm.orderAmount) }}
{{ form_row(filterForm.orderDelivery) }}
{{ form_row(filterForm.amountSum) }} {{ form_row(filterForm.amountSum) }}
{{ form_row(filterForm.lessThanDesired) }} {{ form_row(filterForm.lessThanDesired) }}
{{ form_row(filterForm.lotCount) }} {{ form_row(filterForm.lotCount) }}