commit 91a98daf883a37471c7556a3169daebe872aad55
parent 0248c8a5b25bcb21eecf13fa542643e6ae53fe4b
Author: Felicia Hummel <felicia@partkeepr.com>
Date: Thu, 1 Jun 2017 18:26:04 +0200
Added support for distributors and individual distributor offers to be included or excluded in the project reports, relates to #866
Diffstat:
7 files changed, 191 insertions(+), 48 deletions(-)
diff --git a/src/PartKeepr/CoreBundle/DoctrineMigrations/Version20170601175559.php b/src/PartKeepr/CoreBundle/DoctrineMigrations/Version20170601175559.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace PartKeepr\CoreBundle\DoctrineMigrations;
+
+use Doctrine\DBAL\Schema\Schema;
+use PartKeepr\DistributorBundle\Entity\Distributor;
+
+/**
+ * Sets all existing distributors to be used for price calculations to reflect behaviour of previous versions.
+ */
+class Version20170601175559 extends BaseMigration
+{
+ /**
+ * @param Schema $schema
+ */
+ public function up(Schema $schema)
+ {
+ $this->performDatabaseUpgrade();
+
+ $distributorRepository = $this->getEM()->getRepository(
+ 'PartKeeprDistributorBundle:Distributor'
+ );
+
+ $distributors = $distributorRepository->findAll();
+
+ foreach ($distributors as $distributor) {
+ /**
+ * @var Distributor
+ */
+ $distributor->setEnabledForReports(true);
+ }
+
+ $this->getEM()->flush();
+
+ }
+
+ /**
+ * @param Schema $schema
+ */
+ public function down(Schema $schema)
+ {
+ // this down() migration is auto-generated, please modify it to your needs
+
+ }
+}
diff --git a/src/PartKeepr/DistributorBundle/Entity/Distributor.php b/src/PartKeepr/DistributorBundle/Entity/Distributor.php
@@ -96,13 +96,28 @@ class Distributor extends BaseEntity
private $skuurl;
/**
- * Sets the name for the distributor.
+ * Defines if the distributor is used for pricing calculations
*
- * @param string $name The distributor's name
+ * @ORM\Column(type="boolean")
+ * @Groups({"default"})
+ * @var bool
*/
- public function setName($name)
+ private $enabledForReports = true;
+
+ /**
+ * @return bool
+ */
+ public function isEnabledForReports()
{
- $this->name = $name;
+ return $this->enabledForReports;
+ }
+
+ /**
+ * @param bool $enabledForReports
+ */
+ public function setEnabledForReports($enabledForReports)
+ {
+ $this->enabledForReports = $enabledForReports;
}
/**
@@ -116,13 +131,13 @@ class Distributor extends BaseEntity
}
/**
- * Sets the address of this distributor.
+ * Sets the name for the distributor.
*
- * @param string $address The address of the distributor
+ * @param string $name The distributor's name
*/
- public function setAddress($address)
+ public function setName($name)
{
- $this->address = $address;
+ $this->name = $name;
}
/**
@@ -136,13 +151,13 @@ class Distributor extends BaseEntity
}
/**
- * Sets the phone number for this distributor.
+ * Sets the address of this distributor.
*
- * @param string $phone The phone number of this distributor
+ * @param string $address The address of the distributor
*/
- public function setPhone($phone)
+ public function setAddress($address)
{
- $this->phone = $phone;
+ $this->address = $address;
}
/**
@@ -156,13 +171,13 @@ class Distributor extends BaseEntity
}
/**
- * Sets the fax number for this distributor.
+ * Sets the phone number for this distributor.
*
- * @param string $fax The fax number
+ * @param string $phone The phone number of this distributor
*/
- public function setFax($fax)
+ public function setPhone($phone)
{
- $this->fax = $fax;
+ $this->phone = $phone;
}
/**
@@ -176,13 +191,13 @@ class Distributor extends BaseEntity
}
/**
- * Sets the comment for this distributor.
+ * Sets the fax number for this distributor.
*
- * @param string $comment The comment for this distributor
+ * @param string $fax The fax number
*/
- public function setComment($comment)
+ public function setFax($fax)
{
- $this->comment = $comment;
+ $this->fax = $fax;
}
/**
@@ -196,13 +211,13 @@ class Distributor extends BaseEntity
}
/**
- * Sets the email for this distributor.
+ * Sets the comment for this distributor.
*
- * @param string $email The email for this distributor
+ * @param string $comment The comment for this distributor
*/
- public function setEmail($email)
+ public function setComment($comment)
{
- $this->email = $email;
+ $this->comment = $comment;
}
/**
@@ -216,13 +231,13 @@ class Distributor extends BaseEntity
}
/**
- * Sets the URL for this distributor.
+ * Sets the email for this distributor.
*
- * @param string $url The URL for this distributor
+ * @param string $email The email for this distributor
*/
- public function setUrl($url)
+ public function setEmail($email)
{
- $this->url = $url;
+ $this->email = $email;
}
/**
@@ -236,13 +251,13 @@ class Distributor extends BaseEntity
}
/**
- * Sets the SKU lookup URL for this distributor.
+ * Sets the URL for this distributor.
*
- * @param string $skuurl The SKU lookup URL for this distributor
+ * @param string $url The URL for this distributor
*/
- public function setSkuurl($skuurl)
+ public function setUrl($url)
{
- $this->skuurl = $skuurl;
+ $this->url = $url;
}
/**
@@ -254,4 +269,14 @@ class Distributor extends BaseEntity
{
return $this->skuurl;
}
+
+ /**
+ * Sets the SKU lookup URL for this distributor.
+ *
+ * @param string $skuurl The SKU lookup URL for this distributor
+ */
+ public function setSkuurl($skuurl)
+ {
+ $this->skuurl = $skuurl;
+ }
}
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Distributor/DistributorEditor.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Distributor/DistributorEditor.js
@@ -7,6 +7,11 @@ Ext.define('PartKeepr.DistributorEditor', {
name: 'name',
fieldLabel: i18n("Distributor")
}, {
+ xtype: 'checkbox',
+ name: 'enabledForReports',
+ boxLabel: i18n("Use this distributor for price calculations in project reports"),
+ hideEmptyLabel: false
+ },{
xtype: 'textarea',
name: 'address',
fieldLabel: i18n("Address")
@@ -27,7 +32,7 @@ Ext.define('PartKeepr.DistributorEditor', {
"Enter the URL of the distributor's SKU URL. Use %s as a placeholder for the SKU. Example: http://de.farnell.com/product/dp/%s"));
}
}
- },
+ }
}, {
xtype: 'textfield',
name: 'email',
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Distributor/DistributorGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Distributor/DistributorGrid.js
@@ -2,7 +2,23 @@ Ext.define('PartKeepr.DistributorGrid', {
extend: 'PartKeepr.EditorGrid',
alias: 'widget.DistributorGrid',
columns: [
- {header: i18n("Distributor"), dataIndex: 'name', flex: 1}
+ {
+ header: i18n("Distributor"),
+ dataIndex: 'name',
+ flex: 1
+ },
+ {
+ header: i18n("Pricing"),
+ dataIndex: 'enabledForReports',
+ width: 80,
+ renderers: [{
+ rtype: 'icon',
+ rendererConfig: {
+ iconCls: 'web-icon fugue-icon money-bag-dollar',
+ title: i18n("Used for price calculations")
+ }
+ }]
+ }
],
addButtonText: i18n("Add Distributor"),
addButtonIconCls: 'web-icon lorry_add',
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/Editor/PartDistributorGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/Editor/PartDistributorGrid.js
@@ -138,8 +138,25 @@ Ext.define('PartKeepr.PartDistributorGrid', {
}
return false;
- },
+ }
}
+ }, {
+ header: i18n("Pricing"),
+ dataIndex: 'distributor.enabledForReports',
+ width: 80,
+ renderers: [{
+ rtype: 'icon',
+ rendererConfig: {
+ iconCls: 'web-icon fugue-icon money-bag-dollar',
+ title: i18n("Distributor is used for price calculations")
+ }
+ }]
+ }, {
+ header: i18n("Ignore"),
+ dataIndex: 'ignoreForReports',
+ tooltip: i18n("Ignore this entry for price calculations"),
+ width: 80,
+ xtype: 'checkcolumn'
}
];
@@ -173,10 +190,6 @@ Ext.define('PartKeepr.PartDistributorGrid', {
{
var fields = PartKeepr.getApplication().getSystemPreference("partkeepr.partDistributor.requiredFields", []);
- if (Ext.Array.contains(fields, field)) {
- return false;
- } else {
- return true;
- }
+ return !Ext.Array.contains(fields, field);
}
});
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/ProjectReport.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/ProjectReport.js
@@ -52,11 +52,8 @@ Ext.define('PartKeepr.ProjectReportView', {
var gridPresetButton = Ext.create("PartKeepr.Components.Grid.GridPresetButton");
this.autoFillButton = Ext.create('Ext.button.Button', {
- text: i18n("Autofill"),
- width: 120,
- margins: {
- right: 20
- },
+ text: i18n("Autofill Distributors"),
+ iconCls: 'fugue-icon notification-counter-02',
listeners: {
click: this.onAutoFillClick,
scope: this
@@ -65,7 +62,7 @@ Ext.define('PartKeepr.ProjectReportView', {
this.removeStockButton = Ext.create('Ext.button.Button', {
text: i18n("Remove parts from stock"),
- width: 160,
+ iconCls: 'fugue-icon notification-counter-03',
listeners: {
click: this.onStockRemovalClick,
scope: this
@@ -138,6 +135,14 @@ Ext.define('PartKeepr.ProjectReportView', {
var filterIds = [];
for (var i = 0; i < distributors.count(); i++)
{
+ if (distributors.getAt(i).getDistributor().get("enabledForReports") === false) {
+ continue;
+ }
+
+ if (distributors.getAt(i).get("ignoreForReports")) {
+ continue;
+ }
+
filterIds.push(distributors.getAt(i).getDistributor().getId());
}
@@ -247,7 +252,7 @@ Ext.define('PartKeepr.ProjectReportView', {
},
processCheapestDistributorForProjectPart: function (projectPart)
{
- cheapestDistributor = this.getCheapestDistributor(projectPart.getPart());
+ var cheapestDistributor = this.getCheapestDistributor(projectPart.getPart());
if (cheapestDistributor !== null)
{
@@ -272,6 +277,15 @@ Ext.define('PartKeepr.ProjectReportView', {
for (var j = 0; j < part.distributors().count(); j++)
{
activeDistributor = part.distributors().getAt(j);
+
+ if (activeDistributor.getDistributor().get("enabledForReports") === false) {
+ continue;
+ }
+
+ if (activeDistributor.get("ignoreForReports") === true) {
+ continue;
+ }
+
currentPrice = parseFloat(activeDistributor.get("price"));
if (currentPrice !== 0)
diff --git a/src/PartKeepr/PartBundle/Entity/PartDistributor.php b/src/PartKeepr/PartBundle/Entity/PartDistributor.php
@@ -82,7 +82,16 @@ class PartDistributor extends BaseEntity
private $sku;
/**
- * Cretes a new part->distributor link. Initializes the packaging unit with a quantity of "1".
+ * Defines if the distributor is ignored for pricing calculations
+ *
+ * @ORM\Column(type="boolean")
+ * @Groups({"default"})
+ * @var bool
+ */
+ private $ignoreForReports;
+
+ /**
+ * Creates a new part->distributor link. Initializes the packaging unit with a quantity of "1".
*/
public function __construct()
{
@@ -90,6 +99,22 @@ class PartDistributor extends BaseEntity
}
/**
+ * @return bool
+ */
+ public function isIgnoreForReports()
+ {
+ return $this->ignoreForReports;
+ }
+
+ /**
+ * @param bool $ignoreForReports
+ */
+ public function setIgnoreForReports($ignoreForReports)
+ {
+ $this->ignoreForReports = $ignoreForReports;
+ }
+
+ /**
* @return mixed
*/
public function getCurrency()