diff --git a/application/Espo/Core/Utils/Database/Orm/Fields/Currency.php b/application/Espo/Core/Utils/Database/Orm/Fields/Currency.php
index 1febef7540..f3d56094a2 100644
--- a/application/Espo/Core/Utils/Database/Orm/Fields/Currency.php
+++ b/application/Espo/Core/Utils/Database/Orm/Fields/Currency.php
@@ -53,7 +53,8 @@ class Currency extends \Espo\Core\Utils\Database\Orm\Base
"<=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <= {value}",
"<>" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <> {value}"
),
- 'notStorable' => true
+ 'notStorable' => true,
+ 'orderBy' => $converedFieldName . " {direction}"
),
),
),
diff --git a/application/Espo/Core/defaults/config.php b/application/Espo/Core/defaults/config.php
index 4bc28684cc..31e6e67053 100644
--- a/application/Espo/Core/defaults/config.php
+++ b/application/Espo/Core/defaults/config.php
@@ -41,7 +41,7 @@ return array (
'weekStart' => 0,
'thousandSeparator' => ',',
'decimalMark' => '.',
- 'exportDelimiter' => ',',
+ 'exportDelimiter' => ';',
'currencyList' =>
array (
),
diff --git a/application/Espo/Modules/Crm/Resources/i18n/en_US/Opportunity.json b/application/Espo/Modules/Crm/Resources/i18n/en_US/Opportunity.json
index 76ae378181..fd1953f729 100644
--- a/application/Espo/Modules/Crm/Resources/i18n/en_US/Opportunity.json
+++ b/application/Espo/Modules/Crm/Resources/i18n/en_US/Opportunity.json
@@ -10,7 +10,8 @@
"closeDate": "Close Date",
"contacts": "Contacts",
"description": "Description",
- "amountConverted": "Amount (converted)"
+ "amountConverted": "Amount (converted)",
+ "amountWeightedConverted": "Amount Weighted"
},
"links": {
"contacts": "Contacts",
diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Opportunity.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Opportunity.json
index e2ceec880f..ec966bc7fd 100644
--- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Opportunity.json
+++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Opportunity.json
@@ -11,7 +11,23 @@
},
"amountConverted": {
"type": "currencyConverted",
- "readOnly": true
+ "readOnly": true
+ },
+ "amountWeightedConverted": {
+ "type": "float",
+ "readOnly": true,
+ "notStorable": true,
+ "select": "opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100",
+ "where": {
+ "=": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) = {value}",
+ "<": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) < {value}",
+ ">": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) > {value}",
+ "<=": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) <= {value}",
+ ">=": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) >= {value}",
+ "<>": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) <> {value}"
+ },
+ "orderBy": "amountWeightedConverted {direction}",
+ "view": "Fields.CurrencyConverted"
},
"account": {
"type": "link",
diff --git a/application/Espo/ORM/DB/Query.php b/application/Espo/ORM/DB/Query.php
index 4cd463e90d..4898ee2689 100644
--- a/application/Espo/ORM/DB/Query.php
+++ b/application/Espo/ORM/DB/Query.php
@@ -104,7 +104,7 @@ class Query
}
if (empty($params['aggregation'])) {
- $selectPart = $this->getSelect($entity, $params['select']);
+ $selectPart = $this->getSelect($entity, $params['select'], $params['distinct']);
$orderPart = $this->getOrder($entity, $params['orderBy'], $params['order']);
if (!empty($params['additionalColumns']) && is_array($params['additionalColumns']) && !empty($params['relationName'])) {
@@ -179,7 +179,7 @@ class Query
}
}
- protected function getFunctionPart($function, $part)
+ protected function getFunctionPart($function, $part, $entityName, $distinct = false)
{
switch ($function) {
case 'MONTH':
@@ -187,11 +187,19 @@ class Query
case 'DAY':
return "DATE_FORMAT({$part}, '%Y-%m-%d')";
}
+ if ($distinct) {
+ $idPart = $this->toDb($entityName) . ".id";
+ switch ($function) {
+ case 'SUM':
+ case 'COUNT':
+ return $function . "({$part}) * COUNT(DISTINCT {$idPart}) / COUNT({$idPart})";
+ }
+ }
return $function . '(' . $part . ')';
}
- protected function convertComplexExpression($entity, $field, $entityName = null)
+ protected function convertComplexExpression($entity, $field, $entityName = null, $distinct = false)
{
$function = null;
$relName = null;
@@ -216,12 +224,12 @@ class Query
}
}
if ($function) {
- $part = $this->getFunctionPart(strtoupper($function), $part);
+ $part = $this->getFunctionPart(strtoupper($function), $part, $entityName, $distinct);
}
return $part;
}
- protected function getSelect(IEntity $entity, $fields = null)
+ protected function getSelect(IEntity $entity, $fields = null, $distinct = false)
{
$select = "";
$arr = array();
@@ -237,7 +245,7 @@ class Query
if (array_key_exists($field, $entity->fields)) {
$fieldDefs = $entity->fields[$field];
} else {
- $part = $this->convertComplexExpression($entity, $field, $entity->getEntityName());
+ $part = $this->convertComplexExpression($entity, $field, $entity->getEntityName(), $distinct);
$arr[] = $part . ' AS `' . $field . '`';
continue;
}
diff --git a/frontend/client/src/views/fields/currency-converted.js b/frontend/client/src/views/fields/currency-converted.js
index 25cadf4791..20fac901f3 100644
--- a/frontend/client/src/views/fields/currency-converted.js
+++ b/frontend/client/src/views/fields/currency-converted.js
@@ -22,6 +22,16 @@
Espo.define('Views.Fields.CurrencyConverted', 'Views.Fields.Float', function (Dep) {
return Dep.extend({
+
+ detailTemplate: 'fields.currency.detail',
+
+ listTemplate: 'fields.currency.detail',
+
+ data: function () {
+ return _.extend({
+ currencyValue: this.getConfig().get('baseCurrency'),
+ }, Dep.prototype.data.call(this));
+ },
});
});
diff --git a/frontend/html/main.html b/frontend/html/main.html
index 4abbc32cf0..1150e901cd 100644
--- a/frontend/html/main.html
+++ b/frontend/html/main.html
@@ -7,6 +7,8 @@
+
+
diff --git a/package.json b/package.json
index c099a85d7c..3b6bb493f5 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "espocrm",
- "version": "2.5.2",
+ "version": "2.6.0",
"description": "",
"main": "index.php",
"repository": "",