partkeepr

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

commit 6224a3eba7224d1f3da9944f8a573d3677fbf6e5
parent b91f015daa4b5261a818a2ddef14890d5ef32616
Author: Felicitus <felicitus@felicitus.org>
Date:   Sun, 25 Mar 2012 03:57:51 +0200

Added filtering for the distributor order number, fixes #120

Diffstat:
Msrc/backend/de/RaumZeitLabor/PartKeepr/Part/PartService.php | 9+++++++++
Msrc/frontend/js/Components/Part/PartFilterPanel.js | 10++++++++--
Mtests/Part/PartServiceTest.php | 40++++++++++++++++++++++++++++++++++++++++
3 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Part/PartService.php b/src/backend/de/RaumZeitLabor/PartKeepr/Part/PartService.php @@ -83,6 +83,15 @@ class PartService extends Service implements RestfulService { } /** + * Query by the distributor's order number + */ + if ($this->getParameter("distributorOrderNumber")) { + $queryBuilder->leftJoin("q.distributors", "di"); + $queryBuilder->andWhere("LOWER(di.orderNumber) LIKE :orderNumber"); + $queryBuilder->setParameter("orderNumber", "%".strtolower($this->getParameter("distributorOrderNumber"))."%"); + } + + /** * Filter by the price */ if ($this->getParameter("withoutPrice") === true || $this->getParameter("withoutPrice") === "true") { diff --git a/src/frontend/js/Components/Part/PartFilterPanel.js b/src/frontend/js/Components/Part/PartFilterPanel.js @@ -30,7 +30,8 @@ Ext.define('PartKeepr.PartFilterPanel', { columnWidth: 0.5, layout: 'anchor', items: [ - this.stockFilter + this.stockFilter, + this.distributorOrderNumberFilter ] }; @@ -81,6 +82,7 @@ Ext.define('PartKeepr.PartFilterPanel', { this.storageLocationFilter.setValue(""); this.categoryFilter.setValue({ category: 'all'}); this.stockFilter.setValue({ stock: 'any'}); + this.distributorOrderNumberFilter.setValue(""); this.onApply(); }, @@ -140,6 +142,10 @@ Ext.define('PartKeepr.PartFilterPanel', { fieldLabel: i18n("Item Price"), boxLabel: i18n("Show Parts without Price only") }); + + this.distributorOrderNumberFilter = Ext.create("Ext.form.field.Text", { + fieldLabel: i18n("Order Number") + }); }, /** * Applies the filter parameters to the passed extraParams object. @@ -149,7 +155,7 @@ Ext.define('PartKeepr.PartFilterPanel', { extraParams.withoutPrice = this.partsWithoutPrice.getValue(); extraParams.categoryScope = this.categoryFilter.getValue().category; extraParams.stockMode = this.stockFilter.getValue().stock; - + extraParams.distributorOrderNumber = this.distributorOrderNumberFilter.getValue(); /** * Get the raw (=text) value. I really wish that ExtJS would handle selected values (from a store) * distinct than entered values. diff --git a/tests/Part/PartServiceTest.php b/tests/Part/PartServiceTest.php @@ -1,6 +1,8 @@ <?php namespace de\RaumZeitLabor\PartKeepr\Tests\Part; +use de\RaumZeitLabor\PartKeepr\Distributor\DistributorService; + use de\RaumZeitLabor\PartKeepr\PartCategory\PartCategoryManager, de\RaumZeitLabor\PartKeepr\Part\PartService, de\RaumZeitLabor\PartKeepr\PartKeepr, @@ -39,6 +41,44 @@ class PartServiceTest extends \PHPUnit_Framework_TestCase { } /** + * Tests if a part can be found by its order number. + */ + public function testPartSearchByOrderNumber () { + $partName = "testPartSearchByOrderNumber"; + + /* Create a distributor */ + $distributor = array( + "name" => $partName + ); + + $service = new DistributorService($distributor); + $distributor = $service->create(); + + /* Create a part with a distributor and a specific order number */ + $part = array( + "name" => $partName, + "category" => 1, + "distributors" => array( + array( + "distributor_id" => $distributor["data"]["id"], + "orderNumber" => $partName // Re-use $partName as orderNumber + )), + "storageLocation" => self::$storageLocation + ); + + $service = new PartService($part); + $service->create(); + + PartKeepr::getEM()->flush(); + + $service = new PartService(array("distributorOrderNumber" => $partName)); + + $response = $service->get(); + + $this->assertEquals(1, $response["totalCount"], "The resultset totalCount is wrong."); + } + + /** * Tests if a part with an initial stock level > 0 is created correctly. * * This was fixed with