partkeepr

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

commit cd209c7cf72a284be666dcb94dc8d9c0b73789b6
parent 71e542be1487d3954dce67819193fe056d9b96cb
Author: Felicitus <felicitus@felicitus.org>
Date:   Fri, 18 Dec 2015 14:26:42 +0100

Add the initial stock entry, fixes #534

Diffstat:
Mapp/config/config_partkeepr.yml | 2+-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/Editor/PartEditor.js | 17+++++++++++++++++
Msrc/PartKeepr/PartBundle/Action/AddStockAction.php | 4+++-
Msrc/PartKeepr/PartBundle/Action/RemoveStockAction.php | 4+++-
Msrc/PartKeepr/PartBundle/Action/SetStockAction.php | 4+++-
Msrc/PartKeepr/PartBundle/Controller/PartController.php | 4+++-
Msrc/PartKeepr/PartBundle/Entity/Part.php | 17++++++++++++++---
Msrc/PartKeepr/StockBundle/Entity/StockEntry.php | 10+++-------
8 files changed, 47 insertions(+), 15 deletions(-)

diff --git a/app/config/config_partkeepr.yml b/app/config/config_partkeepr.yml @@ -343,7 +343,7 @@ services: arguments: [ { groups: [ "default" ] } ] - method: "initDenormalizationContext" arguments: - - { groups: [ "default" ] } + - { groups: [ "default", "stock" ] } resource.part_attachment.item_operation.custom_get_image: class: "Dunglas\ApiBundle\Api\Operation\Operation" diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/Editor/PartEditor.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/Editor/PartEditor.js @@ -226,6 +226,7 @@ Ext.define('PartKeepr.PartEditor', { fieldLabel: i18n("Stock User"), name: 'initialStockLevelUser', columnWidth: 0.5, + returnObject: true }); basicEditorFields.push({ @@ -357,6 +358,22 @@ Ext.define('PartKeepr.PartEditor', { this.record.setFootprint(null); } + var initialStockLevel = this.initialStockLevel.getValue(); + + if (this.record.phantom && initialStockLevel > 0) { + var stockLevel = Ext.create("PartKeepr.StockBundle.Entity.StockEntry"); + stockLevel.set("stockLevel", initialStockLevel); + stockLevel.setUser(this.initialStockLevelUser.getValue()); + + if (this.initialStockLevelPricePerItem.getValue() === true) { + stockLevel.set("price", this.initialStockLevelPrice.getValue() / initialStockLevel); + } else { + stockLevel.set("price", this.initialStockLevelPrice.getValue()); + } + + this.record.stockLevels().add(stockLevel); + } + }, onEditStart: function () { diff --git a/src/PartKeepr/PartBundle/Action/AddStockAction.php b/src/PartKeepr/PartBundle/Action/AddStockAction.php @@ -65,7 +65,9 @@ class AddStockAction $quantity = $request->request->get("quantity"); $user = $this->userService->getUser(); - $stock = new StockEntry(intval($quantity), $user); + $stock = new StockEntry(); + $stock->setUser($user); + $stock->setStockLevel(intval($quantity)); if ($request->request->has("price") && $request->request->get("price") !== null) { $stock->setPrice(floatval($request->request->get("price"))); diff --git a/src/PartKeepr/PartBundle/Action/RemoveStockAction.php b/src/PartKeepr/PartBundle/Action/RemoveStockAction.php @@ -64,7 +64,9 @@ class RemoveStockAction $quantity = $request->request->get("quantity"); $user = $this->userService->getUser(); - $stock = new StockEntry(0 - intval($quantity), $user); + $stock = new StockEntry(); + $stock->setStockLevel(0 - intval($quantity)); + $stock->setUser($user); if ($request->request->has("comment") && $request->request->get("comment") !== null) { $stock->setComment($request->request->get("comment")); diff --git a/src/PartKeepr/PartBundle/Action/SetStockAction.php b/src/PartKeepr/PartBundle/Action/SetStockAction.php @@ -69,7 +69,9 @@ class SetStockAction if ($correctionQuantity != 0) { - $stock = new StockEntry($correctionQuantity, $user); + $stock = new StockEntry(); + $stock->setStockLevel($correctionQuantity); + $stock->setUser($user); if ($request->request->has("comment") && $request->request->get("comment") !== null) { $stock->setComment($request->request->get("comment")); diff --git a/src/PartKeepr/PartBundle/Controller/PartController.php b/src/PartKeepr/PartBundle/Controller/PartController.php @@ -47,7 +47,9 @@ class PartController extends FOSRestController */ $part = $iriConverter->getItemFromIri($removal->part); - $stock = new StockEntry(0 - intval($removal->amount), $user); + $stock = new StockEntry(); + $stock->setStockLevel(0 - intval($removal->amount)); + $stock->setUser($user); if (!property_exists($removal, "comment")) { $stock->setComment($removal->comment); diff --git a/src/PartKeepr/PartBundle/Entity/Part.php b/src/PartKeepr/PartBundle/Entity/Part.php @@ -147,6 +147,7 @@ class Part extends BaseEntity /** * The stock level history * @ORM\OneToMany(targetEntity="PartKeepr\StockBundle\Entity\StockEntry",mappedBy="part",cascade={"persist", "remove"}) + * @Groups({"stock"}) * * @var ArrayCollection */ @@ -707,11 +708,21 @@ class Part extends BaseEntity * * @param StockEntry $stockEntry */ - public function addStockEntry(StockEntry $stockEntry) + public function addStockLevel(StockEntry $stockEntry) { - $this->executeSaveListener(); $stockEntry->setPart($this); - $this->getStockLevels()->add($stockEntry); + $this->stockLevels->add($stockEntry); + } + + /** + * Removes a stock entry from this part + * + * @param StockEntry $stockEntry + */ + public function removeStockLevel($stockEntry) + { + $stockEntry->setPart(null); + $this->stockLevels->removeElement($stockEntry); } /** diff --git a/src/PartKeepr/StockBundle/Entity/StockEntry.php b/src/PartKeepr/StockBundle/Entity/StockEntry.php @@ -22,7 +22,7 @@ class StockEntry extends BaseEntity private $stockLevel; /** - * @ORM\ManyToOne(targetEntity="PartKeepr\PartBundle\Entity\Part", inversedBy="stockLevels") + * @ORM\ManyToOne(targetEntity="PartKeepr\PartBundle\Entity\Part", inversedBy="stockEntries") * @Groups({"default"}) */ private $part; @@ -34,6 +34,7 @@ class StockEntry extends BaseEntity private $user; /** + * The price per item. * @ORM\Column(type="decimal",precision=13,scale=4,nullable=true) * @Groups({"default"}) * @var float @@ -68,14 +69,9 @@ class StockEntry extends BaseEntity * 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) + public function __construct() { - $this->setStockLevel($stockLevel); - $this->setUser($user); $this->setDateTime(new \DateTime()); $this->setCorrection(false); }