2020-01-24 22:57:04 +01:00
|
|
|
<?php
|
2020-02-22 18:14:36 +01:00
|
|
|
/**
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-02-01 16:17:20 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-01-24 22:57:04 +01:00
|
|
|
/**
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Entity\LogSystem;
|
|
|
|
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Entity()
|
|
|
|
*/
|
|
|
|
class InstockChangedLogEntry extends AbstractLogEntry
|
|
|
|
{
|
2022-09-18 22:59:31 +02:00
|
|
|
protected string $typeString = 'instock_changed';
|
2020-01-25 22:52:34 +01:00
|
|
|
|
|
|
|
/**
|
2020-02-01 16:17:20 +01:00
|
|
|
* Get the old instock.
|
2020-01-25 22:52:34 +01:00
|
|
|
*/
|
|
|
|
public function getOldInstock(): int
|
|
|
|
{
|
|
|
|
return $this->extra['o'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-02-01 16:17:20 +01:00
|
|
|
* Get the new instock.
|
2020-01-25 22:52:34 +01:00
|
|
|
*/
|
|
|
|
public function getNewInstock(): int
|
|
|
|
{
|
|
|
|
return $this->extra['n'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-02-01 16:17:20 +01:00
|
|
|
* Gets the comment associated with the instock change.
|
2020-01-25 22:52:34 +01:00
|
|
|
*/
|
|
|
|
public function getComment(): string
|
|
|
|
{
|
|
|
|
return $this->extra['c'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the price that has to be payed for the change (in the base currency).
|
2020-02-01 16:17:20 +01:00
|
|
|
*
|
|
|
|
* @param bool $absolute Set this to true, if you want only get the absolute value of the price (without minus)
|
2020-01-25 22:52:34 +01:00
|
|
|
*/
|
|
|
|
public function getPrice(bool $absolute = false): float
|
|
|
|
{
|
|
|
|
if ($absolute) {
|
|
|
|
return abs($this->extra['p']);
|
|
|
|
}
|
2020-02-01 16:17:20 +01:00
|
|
|
|
2020-01-25 22:52:34 +01:00
|
|
|
return $this->extra['p'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the difference value of the change ($new_instock - $old_instock).
|
2020-02-01 16:17:20 +01:00
|
|
|
*
|
2020-08-21 21:36:22 +02:00
|
|
|
* @param bool $absolute set this to true if you want only the absolute value of the difference
|
2020-02-01 16:17:20 +01:00
|
|
|
*
|
2020-08-21 21:36:22 +02:00
|
|
|
* @return int difference is positive if instock has increased, negative if decreased
|
2020-01-25 22:52:34 +01:00
|
|
|
*/
|
|
|
|
public function getDifference(bool $absolute = false): int
|
|
|
|
{
|
|
|
|
// Check if one of the instock values is unknown
|
2020-02-01 16:17:20 +01:00
|
|
|
if (-2 === $this->getNewInstock() || -2 === $this->getOldInstock()) {
|
2020-01-25 22:52:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$difference = $this->getNewInstock() - $this->getOldInstock();
|
|
|
|
if ($absolute) {
|
|
|
|
return abs($difference);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $difference;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the Change was an withdrawal of parts.
|
2020-02-01 16:17:20 +01:00
|
|
|
*
|
2020-08-21 21:36:22 +02:00
|
|
|
* @return bool true if the change was an withdrawal, false if not
|
2020-01-25 22:52:34 +01:00
|
|
|
*/
|
|
|
|
public function isWithdrawal(): bool
|
|
|
|
{
|
|
|
|
return $this->getNewInstock() < $this->getOldInstock();
|
|
|
|
}
|
2020-02-01 16:17:20 +01:00
|
|
|
}
|