mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-02 22:44:33 +02:00
Allow to specify an informational field during a part stock operation, where the user can specify, when this operation was really performed
Fixes issue #416
This commit is contained in:
parent
6cff19358a
commit
b447a69dae
6 changed files with 89 additions and 16 deletions
|
@ -41,8 +41,10 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
* @param float $new_total_part_instock The new total instock of the part.
|
||||
* @param string $comment The comment associated with the change.
|
||||
* @param PartLot|null $move_to_target The target lot if the type is TYPE_MOVE.
|
||||
* @param \DateTimeInterface|null $action_timestamp The optional timestamp, where the action happened. Useful if the action happened in the past, and the log entry is created afterwards.
|
||||
*/
|
||||
protected function __construct(PartStockChangeType $type, PartLot $lot, float $old_stock, float $new_stock, float $new_total_part_instock, string $comment, ?PartLot $move_to_target = null)
|
||||
protected function __construct(PartStockChangeType $type, PartLot $lot, float $old_stock, float $new_stock, float $new_total_part_instock, string $comment, ?PartLot $move_to_target = null,
|
||||
?\DateTimeInterface $action_timestamp = null)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
@ -62,6 +64,11 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
$this->extra['c'] = mb_strimwidth($comment, 0, self::COMMENT_MAX_LENGTH, '...');
|
||||
}
|
||||
|
||||
if ($action_timestamp instanceof \DateTimeInterface) {
|
||||
//The action timestamp is saved as an ISO 8601 string
|
||||
$this->extra['a'] = $action_timestamp->format(\DateTimeInterface::ATOM);
|
||||
}
|
||||
|
||||
if ($move_to_target instanceof PartLot) {
|
||||
if ($type !== PartStockChangeType::MOVE) {
|
||||
throw new \InvalidArgumentException('The move_to_target parameter can only be set if the type is "move"!');
|
||||
|
@ -78,11 +85,12 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
* @param float $new_stock The new stock of the lot.
|
||||
* @param float $new_total_part_instock The new total instock of the part.
|
||||
* @param string $comment The comment associated with the change.
|
||||
* @param \DateTimeInterface|null $action_timestamp The optional timestamp, where the action happened. Useful if the action happened in the past, and the log entry is created afterwards.
|
||||
* @return self
|
||||
*/
|
||||
public static function add(PartLot $lot, float $old_stock, float $new_stock, float $new_total_part_instock, string $comment): self
|
||||
public static function add(PartLot $lot, float $old_stock, float $new_stock, float $new_total_part_instock, string $comment, ?\DateTimeInterface $action_timestamp = null): self
|
||||
{
|
||||
return new self(PartStockChangeType::ADD, $lot, $old_stock, $new_stock, $new_total_part_instock, $comment);
|
||||
return new self(PartStockChangeType::ADD, $lot, $old_stock, $new_stock, $new_total_part_instock, $comment, action_timestamp: $action_timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,11 +100,12 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
* @param float $new_stock The new stock of the lot.
|
||||
* @param float $new_total_part_instock The new total instock of the part.
|
||||
* @param string $comment The comment associated with the change.
|
||||
* @param \DateTimeInterface|null $action_timestamp The optional timestamp, where the action happened. Useful if the action happened in the past, and the log entry is created afterwards.
|
||||
* @return self
|
||||
*/
|
||||
public static function withdraw(PartLot $lot, float $old_stock, float $new_stock, float $new_total_part_instock, string $comment): self
|
||||
public static function withdraw(PartLot $lot, float $old_stock, float $new_stock, float $new_total_part_instock, string $comment, ?\DateTimeInterface $action_timestamp = null): self
|
||||
{
|
||||
return new self(PartStockChangeType::WITHDRAW, $lot, $old_stock, $new_stock, $new_total_part_instock, $comment);
|
||||
return new self(PartStockChangeType::WITHDRAW, $lot, $old_stock, $new_stock, $new_total_part_instock, $comment, action_timestamp: $action_timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,10 +116,12 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
* @param float $new_total_part_instock The new total instock of the part.
|
||||
* @param string $comment The comment associated with the change.
|
||||
* @param PartLot $move_to_target The target lot.
|
||||
* @param \DateTimeInterface|null $action_timestamp The optional timestamp, where the action happened. Useful if the action happened in the past, and the log entry is created afterwards.
|
||||
* @return self
|
||||
*/
|
||||
public static function move(PartLot $lot, float $old_stock, float $new_stock, float $new_total_part_instock, string $comment, PartLot $move_to_target): self
|
||||
public static function move(PartLot $lot, float $old_stock, float $new_stock, float $new_total_part_instock, string $comment, PartLot $move_to_target, ?\DateTimeInterface $action_timestamp = null): self
|
||||
{
|
||||
return new self(PartStockChangeType::MOVE, $lot, $old_stock, $new_stock, $new_total_part_instock, $comment, $move_to_target);
|
||||
return new self(PartStockChangeType::MOVE, $lot, $old_stock, $new_stock, $new_total_part_instock, $comment, $move_to_target, action_timestamp: $action_timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,4 +180,18 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
{
|
||||
return $this->extra['m'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp when this action was performed and not when the log entry was created.
|
||||
* This is useful if the action happened in the past, and the log entry is created afterwards.
|
||||
* If the timestamp is not set, null is returned.
|
||||
* @return \DateTimeInterface|null
|
||||
*/
|
||||
public function getActionTimestamp(): ?\DateTimeInterface
|
||||
{
|
||||
if (!empty($this->extra['a'])) {
|
||||
return \DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, $this->extra['a']);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue