partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 65d6e5ba18f9df99fad1cae5d0c826e652ffa635
parent 98160a55218ae5c1930b11bdfd3240e518fb7d68
Author: Felicitus <felicitus@felicitus.org>
Date:   Wed, 16 Sep 2015 19:26:22 +0200

Moved the stockentry entity to its own bundle, fixed the part stock history

Diffstat:
Mapp/AppKernel.php | 1+
Mapp/config/config.yml | 13+++++++++++++
Msrc/PartKeepr/AuthBundle/Entity/User.php | 2++
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartStockHistory.js | 36++++++++++++++++++++++--------------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/StockReport/AbstractStockHistoryGrid.js | 297+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js | 2+-
Msrc/PartKeepr/PartBundle/Action/AddStockAction.php | 5+++--
Msrc/PartKeepr/PartBundle/Action/RemoveStockAction.php | 5+++--
Msrc/PartKeepr/PartBundle/Action/SetStockAction.php | 5+++--
Msrc/PartKeepr/PartBundle/Entity/Part.php | 4++--
Msrc/PartKeepr/PartBundle/Listeners/StockLevelListener.php | 2+-
Asrc/PartKeepr/StockBundle/Entity/StockEntry.php | 253+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/StockBundle/PartKeeprStockBundle.php | 9+++++++++
Dsrc/backend/PartKeepr/Stock/StockEntry.php | 243-------------------------------------------------------------------------------
14 files changed, 468 insertions(+), 409 deletions(-)

diff --git a/app/AppKernel.php b/app/AppKernel.php @@ -90,6 +90,7 @@ class AppKernel extends Kernel $bundles[] = new PartKeepr\FootprintBundle\PartKeeprFootprintBundle(); $bundles[] = new PartKeepr\UnitBundle\PartKeeprUnitBundle(); $bundles[] = new PartKeepr\PartBundle\PartKeeprPartBundle(); + $bundles[] = new PartKeepr\StockBundle\PartKeeprStockBundle(); $bundles[] = new PartKeepr\DistributorBundle\PartKeeprDistributorBundle(); $bundles[] = new PartKeepr\ManufacturerBundle\PartKeeprManufacturerBundle(); $bundles[] = new PartKeepr\ImageBundle\PartKeeprImageBundle(); diff --git a/app/config/config.yml b/app/config/config.yml @@ -693,6 +693,19 @@ services: arguments: - { groups: [ "default" ] } + resource.stock_entry: + parent: "api.resource" + arguments: [ "PartKeepr\StockBundle\Entity\StockEntry" ] + tags: [ { name: "api.resource" } ] + calls: + - method: "initFilters" + arguments: [ [ "@doctrine_reflection_service.search_filter" ] ] + - method: "initNormalizationContext" + arguments: [ { groups: [ "default" ] } ] + - method: "initDenormalizationContext" + arguments: + - { groups: [ "default" ] } + # ######################## Storage Location Categories###################################### resource.storage_location_category.item_operation.move: diff --git a/src/PartKeepr/AuthBundle/Entity/User.php b/src/PartKeepr/AuthBundle/Entity/User.php @@ -4,6 +4,7 @@ namespace PartKeepr\AuthBundle\Entity; use Doctrine\ORM\Mapping as ORM; use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService; use PartKeepr\Util\BaseEntity; +use Symfony\Component\Serializer\Annotation\Groups; /** * @ORM\Entity @@ -16,6 +17,7 @@ class User extends BaseEntity { /** * @ORM\Column(length=50) + * @Groups({"default"}) */ private $username; diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartStockHistory.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartStockHistory.js @@ -1,19 +1,27 @@ Ext.define('PartKeepr.PartStockHistory', { - extend: 'PartKeepr.AbstractStockHistoryGrid', - alias: 'widget.PartStockHistory', - - initComponent: function () { - this.callParent(); - - this.on("activate", this.onActivate, this); - }, - /** + extend: 'PartKeepr.AbstractStockHistoryGrid', + alias: 'widget.PartStockHistory', + + part: null, + + initComponent: function () + { + this.callParent(); + + this.on("activate", this.onActivate, this); + }, + /** * Called when the view is activated. */ - onActivate: function () { - var proxy = this.store.getProxy(); - proxy.extraParams.part = this.part; - - this.store.load(); + onActivate: function () + { + var filter = Ext.create("Ext.util.Filter", { + property: 'part', + operator: '=', + value: this.part + }); + + this.store.clearFilter(true); + this.store.addFilter(filter); } }); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StockReport/AbstractStockHistoryGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StockReport/AbstractStockHistoryGrid.js @@ -2,156 +2,170 @@ * Represents the stock history grid. */ Ext.define('PartKeepr.AbstractStockHistoryGrid', { - extend: 'PartKeepr.BaseGrid', - - pageSize: 25, - - defineColumns: function () { - this.columns = [{ - header: "", - xtype:'actioncolumn', - dataIndex: 'direction', - renderer: function (val) { - if (val == "out") - { - return '<img title="'+i18n("Parts removed")+'" src="resources/silkicons/brick_delete.png"/>'; - } else { - return '<img title="'+i18n("Parts added")+'" src="resources/silkicons/brick_add.png"/>'; - } - }, - width: 20 - }, - {header: i18n("Date"), dataIndex: 'dateTime', width: 120}, - { - header: i18n("User"), - dataIndex: 'user_id', - flex: 1, - minWidth: 80, - renderer: function (val, p, rec) { - return rec.get("username"); - }, - editor: { - xtype: 'UserComboBox' - } - }, - {header: i18n("Amount"), dataIndex: 'stockLevel', width: 50, - editor: { - xtype:'numberfield', - allowBlank:false - }}, - - { - header: i18n("Price"), - editor: { - xtype:'CurrencyField', - allowBlank:false - }, - dataIndex: 'price', - width: 60, - renderer: function (val, p, rec) { - if (rec.get("dir") == "out") { - return "-"; - } else { - return PartKeepr.getApplication().formatCurrency(val); - } - } - },{ - header: i18n("Comment"), - dataIndex: 'comment', - renderer: Ext.util.Format.htmlEncode, - width: 60, - editor: { - xtype:'textfield', - allowBlank:true - } - }]; - }, - model: 'PartKeepr.Stock.StockEntry', + extend: 'PartKeepr.BaseGrid', + + pageSize: 25, + + defineColumns: function () + { + this.columns = [ + { + header: "", + xtype: 'actioncolumn', + dataIndex: 'direction', + renderer: function (val) + { + if (val == "out") { + return '<img title="' + i18n( + "Parts removed") + '" src="resources/silkicons/brick_delete.png"/>'; + } else { + return '<img title="' + i18n("Parts added") + '" src="resources/silkicons/brick_add.png"/>'; + } + }, + width: 20 + }, + {header: i18n("Date"), dataIndex: 'dateTime', width: 120}, + { + header: i18n("User"), + flex: 1, + minWidth: 80, + renderer: function (val, p, rec) + { + if (rec.getUser() !== null) { + return rec.getUser().get("username"); + } + }, + editor: { + xtype: 'UserComboBox' + } + }, + { + header: i18n("Amount"), dataIndex: 'stockLevel', width: 50, + editor: { + xtype: 'numberfield', + allowBlank: false + } + }, + + { + header: i18n("Price"), + editor: { + xtype: 'CurrencyField', + allowBlank: false + }, + dataIndex: 'price', + width: 60, + renderer: function (val, p, rec) + { + if (rec.get("dir") == "out") { + return "-"; + } else { + return PartKeepr.getApplication().formatCurrency(val); + } + } + }, { + header: i18n("Comment"), + dataIndex: 'comment', + renderer: Ext.util.Format.htmlEncode, + width: 60, + editor: { + xtype: 'textfield', + allowBlank: true + } + } + ]; + }, + model: 'PartKeepr.StockBundle.Entity.StockEntry', /** * Initializes the stock history grid. */ - initComponent: function () { - - this.defineColumns(); - - var config = { - autoLoad: false, - autoSync: true, - remoteFilter: true, - remoteSort: true, - model: this.model, - sorters: [{ - property: 'dateTime', - direction:'DESC' - }], - pageSize: this.pageSize }; - - this.store = Ext.create('Ext.data.Store', config); - - this.editing = Ext.create('Ext.grid.plugin.CellEditing', { + initComponent: function () + { + + this.defineColumns(); + + var config = { + autoLoad: false, + autoSync: true, + remoteFilter: true, + remoteSort: true, + model: this.model, + sorters: [ + { + property: 'dateTime', + direction: 'DESC' + } + ], + pageSize: this.pageSize + }; + + this.store = Ext.create('Ext.data.Store', config); + + this.editing = Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 }); - - this.plugins = [ this.editing ]; - - this.bottomToolbar = Ext.create("Ext.toolbar.Paging", { - store: this.store, - enableOverflow: true, - dock: 'bottom', - displayInfo: false - }); - - - this.dockedItems = new Array(); - this.dockedItems.push(this.bottomToolbar); - - this.editing.on("beforeedit", this.onBeforeEdit, this); - - this.callParent(); + + this.plugins = [this.editing]; + + this.bottomToolbar = Ext.create("Ext.toolbar.Paging", { + store: this.store, + enableOverflow: true, + dock: 'bottom', + displayInfo: false + }); + + + this.dockedItems = new Array(); + this.dockedItems.push(this.bottomToolbar); + + this.editing.on("beforeedit", this.onBeforeEdit, this); + + this.callParent(); }, /** * Called before editing a cell. Checks if the user may actually make the requested changes. - * + * * @param e Passed from ExtJS * @returns {Boolean} */ - onBeforeEdit: function (e) { - - // Checks if the usernames match - var sameUser = e.record.get("username") == PartKeepr.getApplication().getUsername(); - - switch (e.field) { - case "price": - // Check the direction is "out". If yes, editing the price field is not allowed - if (e.record.get("direction") == "out") { - return false; - } - - // If it's not the same user or an admin, editing is not allowed - if ( !sameUser && !PartKeepr.getApplication().isAdmin()) { - return false; - } - break; - case "stockLevel": - // Only an admin may edit the amount. Regular users must put the stock back in manually. - if (!PartKeepr.getApplication().isAdmin()) { - return false; - } - break; - case "user": - if (!PartKeepr.getApplication().isAdmin()) { - return false; - } - break; - case "comment": - if ( !sameUser && !PartKeepr.getApplication().isAdmin()) { - return false; - } - break; - default: - return true; - } - - return true; + onBeforeEdit: function (e) + { + + // Checks if the usernames match + var sameUser = e.record.get("username") == PartKeepr.getApplication().getUsername(); + + switch (e.field) { + case "price": + // Check the direction is "out". If yes, editing the price field is not allowed + if (e.record.get("direction") == "out") { + return false; + } + + // If it's not the same user or an admin, editing is not allowed + if (!sameUser && !PartKeepr.getApplication().isAdmin()) { + return false; + } + break; + case "stockLevel": + // Only an admin may edit the amount. Regular users must put the stock back in manually. + if (!PartKeepr.getApplication().isAdmin()) { + return false; + } + break; + case "user": + if (!PartKeepr.getApplication().isAdmin()) { + return false; + } + break; + case "comment": + if (!sameUser && !PartKeepr.getApplication().isAdmin()) { + return false; + } + break; + default: + return true; + } + + return true; } -});- \ No newline at end of file +}); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js b/src/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js @@ -273,7 +273,7 @@ Ext.application({ this.userPreferenceStore = Ext.create("Ext.data.Store", { - model: 'PartKeepr.UserPreference.UserPreference', + model: 'PartKeepr.AuthBundle.Entity.UserPreference', pageSize: 99999999, autoLoad: false, listeners: { diff --git a/src/PartKeepr/PartBundle/Action/AddStockAction.php b/src/PartKeepr/PartBundle/Action/AddStockAction.php @@ -7,7 +7,7 @@ use Dunglas\ApiBundle\Model\DataProviderInterface; use PartKeepr\AuthBundle\Services\UserService; use PartKeepr\CategoryBundle\Exception\RootNodeNotFoundException; use PartKeepr\PartBundle\Entity\Part; -use PartKeepr\Stock\StockEntry; +use PartKeepr\StockBundle\Entity\StockEntry; use Symfony\Bridge\Doctrine\ManagerRegistry; use Symfony\Component\HttpFoundation\Request; @@ -46,7 +46,8 @@ class AddStockAction /** * Retrieves a collection of resources. * - * @param Request $request + * @param Request $request The request + * @param int $id The ID of the part * * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable * diff --git a/src/PartKeepr/PartBundle/Action/RemoveStockAction.php b/src/PartKeepr/PartBundle/Action/RemoveStockAction.php @@ -7,7 +7,7 @@ use Dunglas\ApiBundle\Model\DataProviderInterface; use PartKeepr\AuthBundle\Services\UserService; use PartKeepr\CategoryBundle\Exception\RootNodeNotFoundException; use PartKeepr\PartBundle\Entity\Part; -use PartKeepr\Stock\StockEntry; +use PartKeepr\StockBundle\Entity\StockEntry; use Symfony\Bridge\Doctrine\ManagerRegistry; use Symfony\Component\HttpFoundation\Request; @@ -45,7 +45,8 @@ class RemoveStockAction /** * Retrieves a collection of resources. * - * @param Request $request + * @param Request $request The request + * @param int $id The ID of the part * * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable * diff --git a/src/PartKeepr/PartBundle/Action/SetStockAction.php b/src/PartKeepr/PartBundle/Action/SetStockAction.php @@ -7,7 +7,7 @@ use Dunglas\ApiBundle\Model\DataProviderInterface; use PartKeepr\AuthBundle\Services\UserService; use PartKeepr\CategoryBundle\Exception\RootNodeNotFoundException; use PartKeepr\PartBundle\Entity\Part; -use PartKeepr\Stock\StockEntry; +use PartKeepr\StockBundle\Entity\StockEntry; use Symfony\Bridge\Doctrine\ManagerRegistry; use Symfony\Component\HttpFoundation\Request; @@ -45,7 +45,8 @@ class SetStockAction /** * Retrieves a collection of resources. * - * @param Request $request + * @param Request $request The request + * @param int $id The ID of the part * * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable * diff --git a/src/PartKeepr/PartBundle/Entity/Part.php b/src/PartKeepr/PartBundle/Entity/Part.php @@ -8,7 +8,7 @@ use PartKeepr\FootprintBundle\Entity\Footprint; use PartKeepr\Part\Exceptions\CategoryNotAssignedException; use PartKeepr\Part\Exceptions\StorageLocationNotAssignedException; use PartKeepr\PartKeepr; -use PartKeepr\Stock\StockEntry; +use PartKeepr\StockBundle\Entity\StockEntry; use PartKeepr\StorageLocationBundle\Entity\StorageLocation; use PartKeepr\Util\BaseEntity; use PartKeepr\Util\Exceptions\OutOfRangeException; @@ -153,7 +153,7 @@ class Part extends BaseEntity /** * The stock level history - * @ORM\OneToMany(targetEntity="PartKeepr\Stock\StockEntry",mappedBy="part",cascade={"persist", "remove"}) + * @ORM\OneToMany(targetEntity="PartKeepr\StockBundle\Entity\StockEntry",mappedBy="part",cascade={"persist", "remove"}) * * @var ArrayCollection */ diff --git a/src/PartKeepr/PartBundle/Listeners/StockLevelListener.php b/src/PartKeepr/PartBundle/Listeners/StockLevelListener.php @@ -3,7 +3,7 @@ namespace PartKeepr\PartBundle\Listeners; use Doctrine\ORM\Event\OnFlushEventArgs; use PartKeepr\PartBundle\Entity\Part; -use PartKeepr\Stock\StockEntry; +use PartKeepr\StockBundle\Entity\StockEntry; use Symfony\Component\DependencyInjection\ContainerAware; class StockLevelListener extends ContainerAware diff --git a/src/PartKeepr/StockBundle/Entity/StockEntry.php b/src/PartKeepr/StockBundle/Entity/StockEntry.php @@ -0,0 +1,253 @@ +<?php +namespace PartKeepr\StockBundle\Entity; + +use Doctrine\ORM\Mapping as ORM; +use PartKeepr\AuthBundle\Entity\User; +use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService; +use PartKeepr\PartBundle\Entity\Part; +use PartKeepr\Util\BaseEntity; +use Symfony\Component\Serializer\Annotation\Groups; + +/** + * @ORM\Entity + * @ORM\HasLifecycleCallbacks + * @TargetService(uri="/api/stock_entries") + */ +class StockEntry extends BaseEntity +{ + /** + * @ORM\Column(type="integer") + * @Groups({"default"}) + */ + private $stockLevel; + + /** + * @ORM\ManyToOne(targetEntity="PartKeepr\PartBundle\Entity\Part", inversedBy="stockLevels") + * @Groups({"default"}) + */ + private $part; + + /** + * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User") + * @Groups({"default"}) + */ + private $user; + + /** + * @ORM\Column(type="decimal",precision=13,scale=4,nullable=true) + * @Groups({"default"}) + * @var float + */ + private $price; + + /** + * @ORM\Column(type="datetime") + * @Groups({"default"}) + * @var \DateTime + */ + private $dateTime; + + /** + * Indicates if the stock level is a correction entry. + * + * @ORM\Column(type="boolean") + * @Groups({"default"}) + * @var boolean + */ + private $correction; + + /** + * @ORM\Column(type="string",nullable=true) + * @Groups({"default"}) + * @var string + */ + private $comment; + + + /** + * Creates a new stock entry. A stock entry tracks how many parts + * were the stockLevel is the amount of items added/removed, + * by which user and how much the user paid for it (for adding parts only!) + * + * @param int $stockLevel The stock level. Positive value means added parts, negative values means removed parts. + * @param \PartKeepr\AuthBundle\Entity\User $user The user who removed/added parts + */ + public function __construct($stockLevel, User $user = null) + { + $this->setStockLevel($stockLevel); + $this->setUser($user); + $this->setDateTime(new \DateTime()); + $this->setCorrection(false); + } + + + /** + * Sets the date+time + * + * @param \DateTime $dateTime The date+time + */ + private function setDateTime(\DateTime $dateTime) + { + $this->dateTime = $dateTime; + } + + /** + * Returns the date+time when the record was created. + * + * @return \DateTime The date+time when the record was created + */ + public function getDateTime() + { + return $this->dateTime; + } + + /** + * Sets if the stock entry is a correction record. + * + * @param $bCorrection boolean True if the record is a correction record, false otherwise + */ + public function setCorrection($bCorrection) + { + $this->correction = $bCorrection; + } + + /** + * Returns if the entry is a correction entry. + * + * @return boolean True if the entry is a correction entry, false otherwise + */ + public function getCorrection() + { + return $this->correction; + } + + /** + * Sets the price for the item stored. + * + * Please note that the price is for a single item only, and can be null. + * + * @param float $price The price to set + */ + public function setPrice($price) + { + $this->price = $price; + } + + /** + * Returns the price for this entry. The price is for a single item only. + * + * @return float The price for this entry. + */ + public function getPrice() + { + return $this->price; + } + + /** + * Sets the stock level for this entry. + * + * Negative values means part removal, positive values means part adding. + * + * @param int $stockLevel The stock level + */ + public function setStockLevel($stockLevel) + { + $this->stockLevel = $stockLevel; + } + + /** + * Returns the stock level for this entry. + * + * @return int The stock level + */ + public function getStockLevel() + { + return $this->stockLevel; + } + + /** + * Sets the part assigned to this entry. + * + * @param Part $part The part to set + */ + public function setPart(Part $part) + { + $this->part = $part; + } + + /** + * Returns the part assigned to this entry. + * + * @return Part $part The part + */ + public function getPart() + { + return $this->part; + } + + /** + * Sets the user assigned to this entry. + * + * @param User $user The user The user to set + */ + public function setUser(User $user = null) + { + $this->user = $user; + } + + /** + * Returns the user for this entry + * + * @return User the user + */ + public function getUser() + { + return $this->user; + } + + /** + * If the stock level is negative, we can't have a price. + * + * @ORM\PrePersist + */ + public function checkPrice() + { + if ($this->getStockLevel() < 0 && $this->getPrice() !== null) { + $this->setPrice(null); + } + } + + /** + * Returns if the current stock entry is a removal. + * + * @return boolean True if the entry is a removal, false otherwise + */ + public function isRemoval() + { + if ($this->getStockLevel() < 0) { + return true; + } else { + return false; + } + } + + /** + * Sets a comment + * + * @param string $comment + */ + public function setComment($comment) + { + $this->comment = $comment; + } + + /** + * Returns the comment + * + * @return string The comment + */ + public function getComment() + { + return $this->comment; + } +} diff --git a/src/PartKeepr/StockBundle/PartKeeprStockBundle.php b/src/PartKeepr/StockBundle/PartKeeprStockBundle.php @@ -0,0 +1,9 @@ +<?php +namespace PartKeepr\StockBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +class PartKeeprStockBundle extends Bundle +{ + +} diff --git a/src/backend/PartKeepr/Stock/StockEntry.php b/src/backend/PartKeepr/Stock/StockEntry.php @@ -1,243 +0,0 @@ -<?php -namespace PartKeepr\Stock; - -use Doctrine\ORM\Mapping as ORM; -use PartKeepr\AuthBundle\Entity\User; -use PartKeepr\PartBundle\Entity\Part; -use PartKeepr\Util\BaseEntity; - -/** - * @ORM\Entity - * @ORM\HasLifecycleCallbacks - */ -class StockEntry extends BaseEntity -{ - /** - * @ORM\Column(type="integer") - */ - private $stockLevel; - - /** - * @ORM\ManyToOne(targetEntity="PartKeepr\PartBundle\Entity\Part", inversedBy="stockLevels") - */ - private $part; - - /** - * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User") - */ - private $user; - - /** - * @ORM\Column(type="decimal",precision=13,scale=4,nullable=true) - * @var float - */ - private $price; - - /** - * @ORM\Column(type="datetime") - * @var \DateTime - */ - private $dateTime; - - /** - * Indicates if the stock level is a correction entry. - * - * @ORM\Column(type="boolean") - * @var boolean - */ - private $correction; - - /** - * @ORM\Column(type="string",nullable=true) - * @var string - */ - private $comment; - - - /** - * Creates a new stock entry. A stock entry tracks how many parts - * were the stockLevel is the amount of items added/removed, - * by which user and how much the user paid for it (for adding parts only!) - * - * @param int $stockLevel The stock level. Positive value means added parts, negative values means removed parts. - * @param \PartKeepr\AuthBundle\Entity\User $user The user who removed/added parts - */ - public function __construct($stockLevel, User $user = null) - { - $this->setStockLevel($stockLevel); - $this->setUser($user); - $this->setDateTime(new \DateTime()); - $this->setCorrection(false); - } - - - /** - * Sets the date+time - * - * @param \DateTime $dateTime The date+time - */ - private function setDateTime(\DateTime $dateTime) - { - $this->dateTime = $dateTime; - } - - /** - * Returns the date+time when the record was created. - * - * @return \DateTime The date+time when the record was created - */ - public function getDateTime() - { - return $this->dateTime; - } - - /** - * Sets if the stock entry is a correction record. - * - * @param $bCorrection boolean True if the record is a correction record, false otherwise - */ - public function setCorrection($bCorrection) - { - $this->correction = $bCorrection; - } - - /** - * Returns if the entry is a correction entry. - * - * @return boolean True if the entry is a correction entry, false otherwise - */ - public function getCorrection() - { - return $this->correction; - } - - /** - * Sets the price for the item stored. - * - * Please note that the price is for a single item only, and can be null. - * - * @param float $price The price to set - */ - public function setPrice($price) - { - $this->price = $price; - } - - /** - * Returns the price for this entry. The price is for a single item only. - * - * @return float The price for this entry. - */ - public function getPrice() - { - return $this->price; - } - - /** - * Sets the stock level for this entry. - * - * Negative values means part removal, positive values means part adding. - * - * @param int $stockLevel The stock level - */ - public function setStockLevel($stockLevel) - { - $this->stockLevel = $stockLevel; - } - - /** - * Returns the stock level for this entry. - * - * @return int The stock level - */ - public function getStockLevel() - { - return $this->stockLevel; - } - - /** - * Sets the part assigned to this entry. - * - * @param Part $part The part to set - */ - public function setPart(Part $part) - { - $this->part = $part; - } - - /** - * Returns the part assigned to this entry. - * - * @return Part $part The part - */ - public function getPart() - { - return $this->part; - } - - /** - * Sets the user assigned to this entry. - * - * @param User $user The user The user to set - */ - public function setUser(User $user = null) - { - $this->user = $user; - } - - /** - * Returns the user for this entry - * - * @return User the user - */ - public function getUser() - { - return $this->user; - } - - /** - * If the stock level is negative, we can't have a price. - * - * @ORM\PrePersist - */ - public function checkPrice() - { - if ($this->getStockLevel() < 0 && $this->getPrice() !== null) { - $this->setPrice(null); - } - } - - /** - * Returns if the current stock entry is a removal. - * - * @return boolean True if the entry is a removal, false otherwise - */ - public function isRemoval() - { - if ($this->getStockLevel() < 0) { - return true; - } else { - return false; - } - } - - /** - * Sets a comment - * - * @param string $comment - */ - public function setComment($comment) - { - $this->comment = $comment; - } - - /** - * Returns the comment - * - * @return string The comment - */ - public function getComment() - { - return $this->comment; - } -}