commit 4a3dc3e29c6b1fbbb144e71eb4231fa6c52f806e
parent e6621564c3e79b13520945548d4bd980240306c9
Author: Timo A. Hummel <felicitus@felicitus.org>
Date: Wed, 9 Mar 2016 16:10:46 +0100
Merge pull request #600 from tinutac/Patch-#532
[Bugfix] Project Report: Autofill #532
Diffstat:
1 file changed, 26 insertions(+), 19 deletions(-)
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/ProjectReport.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/ProjectReport.js
@@ -314,33 +314,40 @@ Ext.define('PartKeepr.ProjectReportView', {
onAutoFillClick: function ()
{
var partCount = this.reportResult.store.count();
- var cheapest = null;
- var cheapestPrice = null;
+ var cheapestDistributor, activeDistributor;
+ var lowestPrice;
+ var firstPositive;
var activeRecord;
for (var i = 0; i < partCount; i++) {
activeRecord = this.reportResult.store.getAt(i);
+ firstPositive = true;
+ lowestPrice = 0;
+ cheapestDistributor = null;
for (var j = 0; j < activeRecord.getPart().distributors().count(); j++) {
- var activeDistributor = activeRecord.getPart().distributors().getAt(j);
-
- if (cheapestPrice === null && parseFloat(activeDistributor.get("price")) !== 0) {
- cheapestPrice = activeDistributor.get("price");
- cheapest = activeDistributor;
- } else {
- if (parseFloat(activeDistributor.get("price")) !== 0 && parseFloat(
- activeDistributor.get("price")) < cheapestPrice) {
- cheapestPrice = activeDistributor.get("price");
- cheapest = activeDistributor;
- }
- }
-
+ activeDistributor = activeRecord.getPart().distributors().getAt(j);
+ currentPrice = parseFloat(activeDistributor.get("price"));
+
+ if (currentPrice != 0) {
+ if (firstPositive) {
+ lowestPrice = currentPrice;
+ cheapestDistributor = activeDistributor;
+ firstPositive = false;
+ }
+ else {
+ if (currentPrice < lowestPrice) {
+ lowestPrice = currentPrice;
+ cheapestDistributor = activeDistributor;
+ }
+ }
+ }
}
- if (cheapest !== null) {
- activeRecord.setDistributor(cheapest.getDistributor());
- activeRecord.set("distributor_order_number", cheapest.get("orderNumber"));
- activeRecord.set("price", cheapest.get("price"));
+ if (cheapestDistributor !== null) {
+ activeRecord.setDistributor(cheapestDistributor.getDistributor());
+ activeRecord.set("distributor_order_number", cheapestDistributor.get("orderNumber"));
+ activeRecord.set("price", cheapestDistributor.get("price"));
activeRecord.set("sum_order", activeRecord.get("missing") * activeRecord.get("price"));
activeRecord.set("sum", activeRecord.get("quantity") * activeRecord.get("price"));
}