mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-08 01:14:34 +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
|
@ -193,6 +193,10 @@ class LogEntryExtraFormatter
|
|||
htmlspecialchars($this->elementTypeNameGenerator->getLocalizedTypeLabel(PartLot::class))
|
||||
.' ' . $context->getMoveToTargetID();
|
||||
}
|
||||
if ($context->getActionTimestamp()) {
|
||||
$formatter = new \IntlDateFormatter($this->translator->getLocale(), \IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT);
|
||||
$array['log.part_stock_changed.timestamp'] = $formatter->format($context->getActionTimestamp());
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
|
|
|
@ -53,9 +53,10 @@ final class PartLotWithdrawAddHelper
|
|||
* @param PartLot $partLot The partLot from which the instock should be taken (which value should be decreased)
|
||||
* @param float $amount The amount of parts that should be taken from the part lot
|
||||
* @param string|null $comment The optional comment describing the reason for the withdrawal
|
||||
* @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 PartLot The modified part lot
|
||||
*/
|
||||
public function withdraw(PartLot $partLot, float $amount, ?string $comment = null): PartLot
|
||||
public function withdraw(PartLot $partLot, float $amount, ?string $comment = null, ?\DateTimeInterface $action_timestamp = null): PartLot
|
||||
{
|
||||
//Ensure that amount is positive
|
||||
if ($amount <= 0) {
|
||||
|
@ -83,7 +84,7 @@ final class PartLotWithdrawAddHelper
|
|||
$oldAmount = $partLot->getAmount();
|
||||
$partLot->setAmount($oldAmount - $amount);
|
||||
|
||||
$event = PartStockChangedLogEntry::withdraw($partLot, $oldAmount, $partLot->getAmount(), $part->getAmountSum() , $comment);
|
||||
$event = PartStockChangedLogEntry::withdraw($partLot, $oldAmount, $partLot->getAmount(), $part->getAmountSum() , $comment, $action_timestamp);
|
||||
$this->eventLogger->log($event);
|
||||
|
||||
//Apply the comment also to global events, so it gets associated with the elementChanged log entry
|
||||
|
@ -100,9 +101,10 @@ final class PartLotWithdrawAddHelper
|
|||
* @param PartLot $partLot The partLot from which the instock should be taken (which value should be decreased)
|
||||
* @param float $amount The amount of parts that should be taken from the part lot
|
||||
* @param string|null $comment The optional comment describing the reason for the withdrawal
|
||||
* @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 PartLot The modified part lot
|
||||
*/
|
||||
public function add(PartLot $partLot, float $amount, ?string $comment = null): PartLot
|
||||
public function add(PartLot $partLot, float $amount, ?string $comment = null, ?\DateTimeInterface $action_timestamp = null): PartLot
|
||||
{
|
||||
if ($amount <= 0) {
|
||||
throw new \InvalidArgumentException('Amount must be positive');
|
||||
|
@ -123,7 +125,7 @@ final class PartLotWithdrawAddHelper
|
|||
$oldAmount = $partLot->getAmount();
|
||||
$partLot->setAmount($oldAmount + $amount);
|
||||
|
||||
$event = PartStockChangedLogEntry::add($partLot, $oldAmount, $partLot->getAmount(), $part->getAmountSum() , $comment);
|
||||
$event = PartStockChangedLogEntry::add($partLot, $oldAmount, $partLot->getAmount(), $part->getAmountSum() , $comment, $action_timestamp);
|
||||
$this->eventLogger->log($event);
|
||||
|
||||
//Apply the comment also to global events, so it gets associated with the elementChanged log entry
|
||||
|
@ -141,8 +143,9 @@ final class PartLotWithdrawAddHelper
|
|||
* @param PartLot $target The part lot to which the parts should be added
|
||||
* @param float $amount The amount of parts that should be moved
|
||||
* @param string|null $comment A comment describing the reason for the 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.
|
||||
*/
|
||||
public function move(PartLot $origin, PartLot $target, float $amount, ?string $comment = null): void
|
||||
public function move(PartLot $origin, PartLot $target, float $amount, ?string $comment = null, ?\DateTimeInterface $action_timestamp = null): void
|
||||
{
|
||||
if ($amount <= 0) {
|
||||
throw new \InvalidArgumentException('Amount must be positive');
|
||||
|
@ -177,7 +180,7 @@ final class PartLotWithdrawAddHelper
|
|||
//And add it to the target
|
||||
$target->setAmount($target->getAmount() + $amount);
|
||||
|
||||
$event = PartStockChangedLogEntry::move($origin, $oldOriginAmount, $origin->getAmount(), $part->getAmountSum() , $comment, $target);
|
||||
$event = PartStockChangedLogEntry::move($origin, $oldOriginAmount, $origin->getAmount(), $part->getAmountSum() , $comment, $target, $action_timestamp);
|
||||
$this->eventLogger->log($event);
|
||||
|
||||
//Apply the comment also to global events, so it gets associated with the elementChanged log entry
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue