currency type improvement
This commit is contained in:
@@ -26,6 +26,7 @@ use \Espo\ORM\EntityManager;
|
||||
use \Espo\ORM\EntityFactory;
|
||||
use \Espo\ORM\Entity;
|
||||
use \Espo\ORM\IEntity;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
use \Espo\Core\Interfaces\Injectable;
|
||||
|
||||
@@ -63,11 +64,38 @@ class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
{
|
||||
$this->handleEmailAddressParams($params);
|
||||
$this->handlePhoneNumberParams($params);
|
||||
$this->handleCurrencyParams($params);
|
||||
}
|
||||
|
||||
protected function handleCurrencyParams(&$params)
|
||||
{
|
||||
$entityName = $this->entityName;
|
||||
|
||||
$metadata = $this->getMetadata();
|
||||
|
||||
if (!$metadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
$defs = $metadata->get('entityDefs.' . $entityName);
|
||||
|
||||
foreach ($defs['fields'] as $field => $d) {
|
||||
if ($d['type'] == 'currency') {
|
||||
if (empty($params['customJoin'])) {
|
||||
$params['customJoin'] = '';
|
||||
}
|
||||
$alias = Util::toUnderScore($field) . "_currency_alias";
|
||||
$params['customJoin'] .= "
|
||||
LEFT JOIN currency AS `{$alias}` ON {$alias}.id = ".Util::toUnderScore($entityName).".".Util::toUnderScore($field)."_currency
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function handleEmailAddressParams(&$params)
|
||||
{
|
||||
$entityName = $this->entityName;
|
||||
$entityName = $this->entityName;
|
||||
|
||||
$defs = $this->getEntityManager()->getMetadata()->get($entityName);
|
||||
if (!empty($defs['relations']) && array_key_exists('emailAddresses', $defs['relations'])) {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Database\Orm\Fields;
|
||||
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
class Currency extends \Espo\Core\Utils\Database\Orm\Base
|
||||
{
|
||||
protected function load($fieldName, $entityName)
|
||||
{
|
||||
$converedFieldName = $fieldName . 'Converted';
|
||||
|
||||
return array(
|
||||
$entityName => array(
|
||||
'fields' => array(
|
||||
$fieldName => array(
|
||||
"type" => "float",
|
||||
"orderBy" => $converedFieldName . " {direction}"
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Database\Orm\Fields;
|
||||
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
class CurrencyConverted extends \Espo\Core\Utils\Database\Orm\Base
|
||||
{
|
||||
protected function load($fieldName, $entityName)
|
||||
{
|
||||
$currencyColumnName = str_replace('_converted', '', Util::toUnderScore($fieldName));
|
||||
|
||||
$alias = $currencyColumnName . "_currency_alias";
|
||||
|
||||
return array(
|
||||
$entityName => array(
|
||||
'fields' => array(
|
||||
$fieldName => array(
|
||||
'type' => 'float',
|
||||
'select' => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate" ,
|
||||
'where' =>
|
||||
array (
|
||||
"=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate = {value}",
|
||||
">" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate > {value}",
|
||||
"<" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate < {value}",
|
||||
">=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate >= {value}",
|
||||
"<=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <= {value}",
|
||||
"<>" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <> {value}"
|
||||
),
|
||||
'notStorable' => true
|
||||
),
|
||||
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,18 +26,7 @@ use Espo\ORM\Entity;
|
||||
|
||||
class Lead extends \Espo\Core\ORM\Repositories\RDB
|
||||
{
|
||||
public function handleSelectParams(&$params)
|
||||
{
|
||||
parent::handleSelectParams($params);
|
||||
|
||||
if (empty($params['customJoin'])) {
|
||||
$params['customJoin'] = '';
|
||||
}
|
||||
|
||||
$params['customJoin'] .= "
|
||||
LEFT JOIN currency ON currency.id = lead.opportunity_amount_currency
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -26,18 +26,7 @@ use Espo\ORM\Entity;
|
||||
|
||||
class Opportunity extends \Espo\Core\ORM\Repositories\RDB
|
||||
{
|
||||
public function handleSelectParams(&$params)
|
||||
{
|
||||
parent::handleSelectParams($params);
|
||||
|
||||
if (empty($params['customJoin'])) {
|
||||
$params['customJoin'] = '';
|
||||
}
|
||||
|
||||
$params['customJoin'] .= "
|
||||
LEFT JOIN currency ON currency.id = opportunity.amount_currency
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -39,22 +39,11 @@
|
||||
},
|
||||
"opportunityAmount": {
|
||||
"type": "currency",
|
||||
"audited": true,
|
||||
"orderBy": "opportunityAmountConverted {direction}"
|
||||
"audited": true
|
||||
},
|
||||
"opportunityAmountConverted": {
|
||||
"type": "float",
|
||||
"notStorable": true,
|
||||
"readOnly": true,
|
||||
"select": "lead.opportunity_amount * currency.rate",
|
||||
"where": {
|
||||
"=": "lead.opportunity_amount * currency.rate = {value}",
|
||||
">": "lead.opportunity_amount * currency.rate > {value}",
|
||||
"<": "lead.opportunity_amount * currency.rate < {value}",
|
||||
">=": "lead.opportunity_amount * currency.rate >= {value}",
|
||||
"<=": "lead.opportunity_amount * currency.rate <= {value}",
|
||||
"<>": "lead.opportunity_amount * currency.rate <> {value}"
|
||||
}
|
||||
"type": "currencyConverted",
|
||||
"readOnly": true
|
||||
},
|
||||
"website": {
|
||||
"type": "url"
|
||||
|
||||
@@ -7,22 +7,11 @@
|
||||
"amount": {
|
||||
"type": "currency",
|
||||
"required": true,
|
||||
"audited": true,
|
||||
"orderBy": "amountConverted {direction}"
|
||||
"audited": true
|
||||
},
|
||||
"amountConverted": {
|
||||
"type": "float",
|
||||
"notStorable": true,
|
||||
"readOnly": true,
|
||||
"select": "opportunity.amount * currency.rate",
|
||||
"where": {
|
||||
"=": "opportunity.amount * currency.rate = {value}",
|
||||
">": "opportunity.amount * currency.rate > {value}",
|
||||
"<": "opportunity.amount * currency.rate < {value}",
|
||||
">=": "opportunity.amount * currency.rate >= {value}",
|
||||
"<=": "opportunity.amount * currency.rate <= {value}",
|
||||
"<>": "opportunity.amount * currency.rate <> {value}"
|
||||
}
|
||||
"type": "currencyConverted",
|
||||
"readOnly": true
|
||||
},
|
||||
"account": {
|
||||
"type": "link",
|
||||
|
||||
@@ -16,16 +16,18 @@
|
||||
],
|
||||
"actualFields":[
|
||||
"currency",
|
||||
"converted",
|
||||
""
|
||||
],
|
||||
"fields":{
|
||||
"currency":{
|
||||
"type":"varchar",
|
||||
"disabled": true
|
||||
},
|
||||
"converted":{
|
||||
"type":"currencyConverted",
|
||||
"readOnly": true
|
||||
}
|
||||
},
|
||||
"filter": true,
|
||||
"fieldDefs":{
|
||||
"type":"float"
|
||||
}
|
||||
"filter": true
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"params":[
|
||||
],
|
||||
"filter": true,
|
||||
"notCreatable": true,
|
||||
"fieldDefs":{
|
||||
"notStorable":true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('Views.Fields.CurrencyConverted', 'Views.Fields.Float', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user