mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-12 03:14:32 +02:00
Write a special log entry to DB when a user withdraws/add/move parts stock
This commit is contained in:
parent
b2157c93e3
commit
4c94d9c150
6 changed files with 256 additions and 10 deletions
|
@ -31,7 +31,7 @@ use App\Entity\LogSystem\ElementCreatedLogEntry;
|
|||
use App\Entity\LogSystem\ElementDeletedLogEntry;
|
||||
use App\Entity\LogSystem\ElementEditedLogEntry;
|
||||
use App\Entity\LogSystem\ExceptionLogEntry;
|
||||
use App\Entity\LogSystem\InstockChangedLogEntry;
|
||||
use App\Entity\LogSystem\LegacyInstockChangedLogEntry;
|
||||
use App\Entity\LogSystem\SecurityEventLogEntry;
|
||||
use App\Entity\LogSystem\UserLoginLogEntry;
|
||||
use App\Entity\LogSystem\UserLogoutLogEntry;
|
||||
|
@ -155,7 +155,7 @@ class LogEntryExtraFormatter
|
|||
$array['log.element_edited.changed_fields'] = htmlspecialchars(implode(', ', $context->getChangedFields()));
|
||||
}
|
||||
|
||||
if ($context instanceof InstockChangedLogEntry) {
|
||||
if ($context instanceof LegacyInstockChangedLogEntry) {
|
||||
$array[] = $this->translator->trans($context->isWithdrawal() ? 'log.instock_changed.withdrawal' : 'log.instock_changed.added');
|
||||
$array[] = sprintf(
|
||||
'%s <i class="fas fa-long-arrow-alt-right"></i> %s (%s)',
|
||||
|
|
|
@ -2,11 +2,20 @@
|
|||
|
||||
namespace App\Services\Parts;
|
||||
|
||||
use App\Entity\LogSystem\PartStockChangedLogEntry;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\PartLot;
|
||||
use App\Services\LogSystem\EventLogger;
|
||||
|
||||
class PartLotWithdrawAddHelper
|
||||
final class PartLotWithdrawAddHelper
|
||||
{
|
||||
private $eventLogger;
|
||||
|
||||
public function __construct(EventLogger $eventLogger)
|
||||
{
|
||||
$this->eventLogger = $eventLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given part can
|
||||
* @param PartLot $partLot
|
||||
|
@ -80,7 +89,11 @@ class PartLotWithdrawAddHelper
|
|||
}
|
||||
|
||||
//Subtract the amount from the part lot
|
||||
$partLot->setAmount($partLot->getAmount() - $amount);
|
||||
$oldAmount = $partLot->getAmount();
|
||||
$partLot->setAmount($oldAmount - $amount);
|
||||
|
||||
$event = PartStockChangedLogEntry::withdraw($partLot, $oldAmount, $partLot->getAmount(), $part->getAmountSum() , $comment);
|
||||
$this->eventLogger->log($event);
|
||||
|
||||
return $partLot;
|
||||
}
|
||||
|
@ -111,8 +124,11 @@ class PartLotWithdrawAddHelper
|
|||
throw new \RuntimeException("Cannot add to this part lot!");
|
||||
}
|
||||
|
||||
//Subtract the amount from the part lot
|
||||
$partLot->setAmount($partLot->getAmount() + $amount);
|
||||
$oldAmount = $partLot->getAmount();
|
||||
$partLot->setAmount($oldAmount + $amount);
|
||||
|
||||
$event = PartStockChangedLogEntry::add($partLot, $oldAmount, $partLot->getAmount(), $part->getAmountSum() , $comment);
|
||||
$this->eventLogger->log($event);
|
||||
|
||||
return $partLot;
|
||||
}
|
||||
|
@ -154,9 +170,14 @@ class PartLotWithdrawAddHelper
|
|||
throw new \RuntimeException('Not enough stock to withdraw!');
|
||||
}
|
||||
|
||||
$oldOriginAmount = $origin->getAmount();
|
||||
|
||||
//Subtract the amount from the part lot
|
||||
$origin->setAmount($origin->getAmount() - $amount);
|
||||
//And add it to the target
|
||||
$target->setAmount($target->getAmount() + $amount);
|
||||
|
||||
$event = PartStockChangedLogEntry::move($origin, $oldOriginAmount, $origin->getAmount(), $part->getAmountSum() , $comment, $target);
|
||||
$this->eventLogger->log($event);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue