dev. convert. viewMaps

This commit is contained in:
Yuri Kuznetsov
2014-01-08 15:10:30 +02:00
parent 5061a319d0
commit d5cd742471
21 changed files with 169 additions and 35 deletions
@@ -0,0 +1,11 @@
<?php
namespace Espo\Core\Exceptions;
class BadRequest extends \Exception
{
protected $code = 400;
}
@@ -2,7 +2,21 @@
namespace Espo\Modules\Crm\Controllers;
use \Espo\Core\Exceptions\Error;
use \Espo\Core\Exceptions\BadRequest;
class Lead extends \Espo\Core\Controllers\Record
{
public function actionConvert($params, $data)
{
if (empty($data['id'])) {
throw new BadRequest();
}
$entity = $this->getRecordService()->convert($data['id'], $data['records']);
if (!empty($entity)) {
return $entity->toArray();
}
throw new Error();
}
}
@@ -2,7 +2,24 @@
namespace Espo\Modules\Crm\Controllers;
use \Espo\Core\Exceptions\Error;
use \Espo\Core\Exceptions\BadRequest;
class Prospect extends \Espo\Core\Controllers\Record
{
public function actionConvert($params, $data)
{
if (empty($data['id'])) {
throw new BadRequest();
}
$entity = $this->getRecordService()->convert($data['id']);
if (!empty($entity)) {
return $entity->toArray();
}
throw new Error();
}
}
@@ -0,0 +1 @@
[{"label":"Overview","rows":[[{"name":"name"},false],[{"name":"website"},{"name":"phone"}],[{"name":"email"},{"name":"fax"}],[{"name":"billingAddress"},{"name":"shippingAddress"}],[{"name":"description"},false]]},{"label":"Details","rows":[[{"name":"type"},{"name":"sicCode"}],[{"name":"industry"},false]]}]
@@ -0,0 +1 @@
[{"label":"Overview","rows":[[{"name":"name"}],[{"name":"email"},{"name":"phone"}],[{"name":"title"},{"name":"doNotCall"}],[{"name":"address"},false],[{"name":"description"},false]]}]
@@ -0,0 +1 @@
[{"label":"Overview","rows":[[{"name":"name"}],[{"name":"stage"},{"name":"amount"}],[{"name":"probability"},{"name":"leadSource"}],[{"name":"closeDate"},false],[{"name":"description"},false]]}]
@@ -1 +1 @@
[{"label":"Overview","rows":[[{"name":"name"},{"name":"account"}],[{"name":"email"},{"name":"phone"}],[{"name":"title"},{"name":"doNotCall"}],[{"name":"address"},{"name":"website"}],[{"name":"description"},false]]}]
[{"label":"Overview","rows":[[{"name":"name"},{"name":"accountName"}],[{"name":"email"},{"name":"phone"}],[{"name":"title"},{"name":"doNotCall"}],[{"name":"address"},{"name":"website"}],[{"name":"description"},false]]}]
@@ -1 +1 @@
["name","email","account"]
["name","email","accountName"]
@@ -1 +1 @@
[{"name":"name","width":30,"link":true},{"name":"email"},{"name":"phone"},{"name":"account"},{"name":"createdAt"}]
[{"name":"name","width":30,"link":true},{"name":"email"},{"name":"phone"},{"name":"accountName"},{"name":"createdAt"}]
@@ -101,17 +101,17 @@
"teams": {
"type": "linkMultiple"
},
"account": {
"createdAccount": {
"type": "link",
"disabled": true,
"readOnly": true
},
"contact": {
"createdContact": {
"type": "link",
"disabled": true,
"readOnly": true
},
"opportunity": {
"createdOpportunity": {
"type": "link",
"disabled": true,
"readOnly": true
@@ -155,15 +155,15 @@
"entity": "Task",
"foreign": "parent"
},
"account": {
"createdAccount": {
"type": "belongsTo",
"entity": "Account"
},
"contact": {
"createdContact": {
"type": "belongsTo",
"entity": "Contact"
},
"opportunity": {
"createdOpportunity": {
"type": "belongsTo",
"entity": "Opportunity"
}
@@ -175,33 +175,22 @@
"email": "email",
"phone": "phone",
"address": "address",
"assignedUser": "assignedUser"
"assignedUser": "assignedUser",
"teams": "teams"
},
"Account": {
"name": "accountName",
"website": "website",
"email": "email",
"phone": "phoneOffice",
"assignedUser": "assignedUser"
"assignedUser": "assignedUser",
"teams": "teams"
},
"Opportunity": {
"amount": "opportunityAmount",
"leadSource": "source",
"assignedUser": "assignedUser"
}
},
"convertLinks": {
"Account": {
"Contact": "contacts",
"Opportunity": "oppotunities"
},
"Contact": {
"Opportunity": "oppotunities"
},
"Lead": {
"Account": "account",
"Contact": "contact",
"Opportunity": "oppotunity"
"assignedUser": "assignedUser",
"teams": "teams"
}
},
"collection": {
@@ -20,7 +20,7 @@
"type": "varchar",
"maxLength": 100
},
"account": {
"accountName": {
"type": "varchar",
"maxLength": 100
},
@@ -1,8 +1,8 @@
{
"viewMaps":{
"views":{
"detail":"Crm:Lead.Detail"
},
"recordViewMaps":{
"recordViews":{
"detail":"Crm:Lead.Record.Detail"
},
"sidePanels":{
@@ -1,5 +1,5 @@
{
"viewMaps":{
"views":{
"detail":"Crm:Meeting.Detail"
},
"sidePanels":{
@@ -1,4 +1,7 @@
{
"views":{
"detail":"Crm:Prospect.Detail"
},
"menu":{
"detail":{
"buttons":[
@@ -0,0 +1,54 @@
<?php
namespace Espo\Modules\Crm\Services;
use \Espo\Core\Exceptions\Error;
use \Espo\Core\Exceptions\Forbidden;
class Lead extends \Espo\Services\Record
{
public function convert($id, $recordsData)
{
$lead = $this->getEntity($id);
if (!$this->getAcl()->check($lead, 'edit')) {
throw new Forbidden();
}
$entityManager = $this->getEntityManager();
if (!empty($recordsData['Account'])) {
$account = $entityManager->getEntity('Account');
$account->set($recordsData['Account']);
$entityManager->saveEntity($account);
$lead->set('createdAccountId', $account->id);
}
if (!empty($recordsData['Opportunity'])) {
$opportunity = $entityManager->getEntity('Opportunity');
$opportunity->set($recordsData['Opportunity']);
if (isset($account)) {
$opportunity->set('accountId', $account->id);
}
$entityManager->saveEntity($opportunity);
$lead->set('createdOpportunityId', $opportunity->id);
}
if (!empty($recordsData['Contact'])) {
$contact = $entityManager->getEntity('Contact');
$contact->set($recordsData['Contact']);
if (isset($account)) {
$contact->set('accountId', $account->id);
}
$entityManager->saveEntity($contact);
if (isset($opportunity)) {
$entityManager->getRepository('Contact')->relate($contact, 'opportunities', $opportunity);
}
$lead->set('createdContactId', $contact->id);
}
$lead->set('status', 'Converted');
$entityManager->saveEntity($lead);
return $lead;
}
}
@@ -0,0 +1,31 @@
<?php
namespace Espo\Modules\Crm\Services;
use \Espo\Core\Exceptions\Error;
use \Espo\Core\Exceptions\Forbidden;
class Prospect extends \Espo\Services\Record
{
public function convert($id)
{
$entityManager = $this->getEntityManager();
$prospect = $this->getEntity($id);
if (!$this->getAcl()->check($prospect, 'delete')) {
throw new Forbidden();
}
if (!$this->getAcl()->check('Lead', 'read')) {
throw new Forbidden();
}
$lead = $entityManager->getEntity('Lead');
$lead->set($prospect->toArray());
$entityManager->removeEntity($prospect);
$entityManager->saveEntity($lead);
return $lead;
}
}
+12
View File
@@ -55,6 +55,18 @@ class EntityManager
{
return $this->getRepository($name)->get($id);
}
public function saveEntity(Entity $entity)
{
$entityName = $entity->getEntityName();
return $this->getRepository($entityName)->save($entity);
}
public function removeEntity(Entity $entity)
{
$entityName = $entity->getEntityName();
return $this->getRepository($entityName)->remove($entity);
}
public function getRepository($name)
{
@@ -1,5 +1,5 @@
{
"recordViewMaps":{
"recordViews":{
"detail":"OutboundEmail.Record.Detail",
"edit":"OutboundEmail.Record.Edit",
"editQuick":"OutboundEmail.Record.Edit"
@@ -1,5 +1,5 @@
{
"recordViewMaps":{
"recordViews":{
"detail":"Role.Record.Detail",
"edit":"Role.Record.Edit",
"editQuick":"Role.Record.Edit"
@@ -4,7 +4,7 @@
"create":false
}
},
"recordViewMaps":{
"recordViews":{
"detail":"Team.Detail",
"edit":"Team.Edit"
}
@@ -1,5 +1,5 @@
{
"recordViewMaps":{
"recordViews":{
"detail":"User.Record.Detail",
"edit":"User.Record.Edit",
"editQuick":"User.Record.Edit"