Show part lots on part's info page.

This commit is contained in:
Jan Böhmer 2019-08-16 22:54:23 +02:00
parent c2b43f2cfa
commit 7517d83f55
7 changed files with 312 additions and 44 deletions

View file

@ -183,15 +183,6 @@ class Part extends AttachmentContainingDBElement
*/
protected $partLots;
/**
* @var int
* @ORM\Column(type="integer")
* @Assert\GreaterThanOrEqual(0)
*
* @ColumnSecurity(prefix="mininstock", type="integer")
*/
protected $mininstock = 0;
/**
* @var float
* @ORM\Column(type="float")
@ -199,7 +190,7 @@ class Part extends AttachmentContainingDBElement
*
* @ColumnSecurity(prefix="mininstock", type="integer")
*/
protected $minamount;
protected $minamount = 0;
/**
* @var string
@ -306,9 +297,9 @@ class Part extends AttachmentContainingDBElement
*
* @return int count of parts which must be in stock at least
*/
public function getMinInstock(): int
public function getMinAmount(): float
{
return $this->mininstock;
return $this->minamount;
}
/**
@ -687,6 +678,45 @@ class Part extends AttachmentContainingDBElement
return $this;
}
/**
* Checks if this part uses the float amount .
* This setting is based on the part unit (see MeasurementUnit->isInteger()).
* @return bool True if the float amount field should be used. False if the integer instock field should be used.
*/
public function useFloatAmount(): bool
{
if ($this->partUnit instanceof MeasurementUnit) {
return $this->partUnit->isInteger();
}
//When no part unit is set, treat it as part count, and so use the integer value.
return false;
}
/**
* Returns the summed amount of this part (over all part lots)
* @return float
*/
public function getAmountSum() : float
{
//TODO: Find a method to do this natively in SQL, the current method could be a bit slow
$sum = 0;
foreach($this->getPartLots() as $lot) {
//Dont use the instock value, if it is unkown
if ($lot->isInstockUnknown()) {
continue;
}
$sum += $lot->getAmount();
}
if(!$this->useFloatAmount()) {
return $sum;
}
return round($sum);
}
/********************************************************************************
*
* Setters
@ -708,17 +738,18 @@ class Part extends AttachmentContainingDBElement
}
/**
* Set the count of parts which should be in stock at least.
* Set the minimum amount of parts that have to be instock.
* See getPartUnit() for the associated unit.
*
* @param int $new_mininstock the new count of parts which should be in stock at least
*
* @return self
*/
public function setMinInstock(int $new_mininstock): self
public function setMinAmount(float $new_mininstock): self
{
//Assert::natural($new_mininstock, 'The new minimum instock value must be positive! Got %s.');
$this->mininstock = $new_mininstock;
$this->minamount = $new_minamount;
return $this;
}

View file

@ -65,7 +65,7 @@ class PartLot extends DBElement
protected $comment;
/**
* @var \DateTime Set a time until when the lot must be used.
* @var ?\DateTime Set a time until when the lot must be used.
* Set to null, if the lot can be used indefinitley.
* @ORM\Column(type="datetimetz", name="expiration_date", nullable=true)
*/
@ -92,16 +92,11 @@ class PartLot extends DBElement
*/
protected $instock_unknown;
/**
* @var int For integer sizes the instock is saved here.
* @ORM\Column(type="integer", nullable=true)
* @Assert\Positive()
*/
protected $instock;
/**
* @var float For continuos sizes (length, volume, etc.) the instock is saved here.
* @ORM\Column(type="float", nullable=true)
* @ORM\Column(type="float")
* @Assert\Positive()
*/
protected $amount;
@ -122,4 +117,179 @@ class PartLot extends DBElement
{
return 'PL' . $this->getID();
}
/**
* Check if the current part lot is expired.
* This is the case, if the expiration date is greater the the current date.
* @return bool|null True, if the part lot is expired. Returns null, if no expiration date was set.
* @throws \Exception
*/
public function isExpired(): ?bool
{
if ($this->expiration_date == null) {
return null;
}
//Check if the expiration date is bigger then current time
return $this->expiration_date < new \DateTime();
}
/**
* Gets the description of the part lot. Similar to a "name" of the part lot.
* @return string
*/
public function getDescription(): string
{
return $this->description;
}
/**
* Sets the description of the part lot.
* @param string $description
* @return PartLot
*/
public function setDescription(string $description): PartLot
{
$this->description = $description;
return $this;
}
/**
* Gets the comment for this part lot.
* @return string
*/
public function getComment(): string
{
return $this->comment;
}
/**
* Sets the comment for this part lot.
* @param string $comment
* @return PartLot
*/
public function setComment(string $comment): PartLot
{
$this->comment = $comment;
return $this;
}
/**
* Gets the expiration date for the part lot. Returns null, if no expiration date was set.
* @return \DateTime|null
*/
public function getExpirationDate(): ?\DateTime
{
return $this->expiration_date;
}
/**
* Sets the expiration date for the part lot. Set to null, if the part lot does not expires.
* @param \DateTime $expiration_date
* @return PartLot
*/
public function setExpirationDate(?\DateTime $expiration_date): PartLot
{
$this->expiration_date = $expiration_date;
return $this;
}
/**
* Gets the storage locatiion, where this part lot is stored.
* @return Storelocation The store location where this part is stored
*/
public function getStorageLocation(): Storelocation
{
return $this->storage_location;
}
/**
* Sets the storage location, where this part lot is stored
* @param Storelocation $storage_location
* @return PartLot
*/
public function setStorageLocation(Storelocation $storage_location): PartLot
{
$this->storage_location = $storage_location;
return $this;
}
/**
* Return the part that is stored in this part lot.
* @return Part
*/
public function getPart(): Part
{
return $this->part;
}
/**
* Sets the part that is stored in this part lot.
* @param Part $part
* @return PartLot
*/
public function setPart(Part $part): PartLot
{
$this->part = $part;
return $this;
}
/**
* Checks if the instock value in the part lot is unknown.
*
* @return bool
*/
public function isInstockUnknown(): bool
{
return $this->instock_unknown;
}
/**
* Set the unknown instock status of this part lot.
* @param bool $instock_unknown
* @return PartLot
*/
public function setInstockUnknown(bool $instock_unknown): PartLot
{
$this->instock_unknown = $instock_unknown;
return $this;
}
/**
* @return float
*/
public function getAmount(): float
{
if (!$this->part->useFloatAmount()) {
return round($this->amount);
}
return (float) $this->amount;
}
public function setAmount(float $new_amount): PartLot
{
$this->amount = $new_amount;
}
/**
* @return bool
*/
public function isNeedsRefill(): bool
{
return $this->needs_refill;
}
/**
* @param bool $needs_refill
* @return PartLot
*/
public function setNeedsRefill(bool $needs_refill): PartLot
{
$this->needs_refill = $needs_refill;
return $this;
}
}

View file

@ -62,6 +62,8 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Base\PartsContainingDBElement;
use App\Entity\Base\StructuralDBElement;
use App\Form\Type\StructuralEntityType;
use Doctrine\ORM\Mapping as ORM;
/**
@ -70,7 +72,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
* @ORM\Table("`storelocations`")
*/
class Storelocation extends PartsContainingDBElement
class Storelocation extends StructuralDBElement
{
/**
* @ORM\OneToMany(targetEntity="Storelocation", mappedBy="parent")
@ -83,11 +85,6 @@ class Storelocation extends PartsContainingDBElement
*/
protected $parent;
/**
* @ORM\OneToMany(targetEntity="Part", mappedBy="storelocation")
*/
protected $parts;
/**
* @var bool
* @ORM\Column(type="boolean")