Skip to content

Commit

Permalink
Added filtering for the distributor order number, fixes #120
Browse files Browse the repository at this point in the history
  • Loading branch information
Felicitus committed Mar 25, 2012
1 parent b91f015 commit 6224a3e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/backend/de/RaumZeitLabor/PartKeepr/Part/PartService.php
Expand Up @@ -82,6 +82,15 @@ public function filterCallback ($queryBuilder) {
break;
}

/**
* 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
*/
Expand Down
10 changes: 8 additions & 2 deletions src/frontend/js/Components/Part/PartFilterPanel.js
Expand Up @@ -30,7 +30,8 @@ Ext.define('PartKeepr.PartFilterPanel', {
columnWidth: 0.5,
layout: 'anchor',
items: [
this.stockFilter
this.stockFilter,
this.distributorOrderNumberFilter
]
};

Expand Down Expand Up @@ -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();
},
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
40 changes: 40 additions & 0 deletions 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,
Expand Down Expand Up @@ -38,6 +40,44 @@ public function testCreatePartWithoutCategory () {
$service->create();
}

/**
* 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.
*
Expand Down

0 comments on commit 6224a3e

Please sign in to comment.