diff --git a/packages/backend/src/apps/vtiger-crm/actions/create-case/fields.js b/packages/backend/src/apps/vtiger-crm/actions/create-case/fields.js new file mode 100644 index 00000000..ad497ac9 --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/actions/create-case/fields.js @@ -0,0 +1,408 @@ +export const fields = [ + { + label: 'Summary', + key: 'summary', + type: 'string', + required: true, + description: '', + variables: true, + }, + { + label: 'Record Currency', + key: 'recordCurrency', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listRecordCurrencies', + }, + ], + }, + }, + { + label: 'Case Title', + key: 'caseTitle', + type: 'string', + required: true, + description: '', + variables: true, + }, + { + label: 'Status', + key: 'status', + type: 'dropdown', + required: true, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listCaseOptions', + }, + { + name: 'parameters.status', + value: 'casestatus', + }, + ], + }, + }, + { + label: 'Priority', + key: 'priority', + type: 'dropdown', + required: true, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listCaseOptions', + }, + { + name: 'parameters.priority', + value: 'casepriority', + }, + ], + }, + }, + { + label: 'Contact Name', + key: 'contactName', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContacts', + }, + ], + }, + }, + { + label: 'Organization Name', + key: 'organizationName', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listOrganizations', + }, + ], + }, + }, + { + label: 'Group', + key: 'group', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listGroups', + }, + ], + }, + }, + { + label: 'Assigned To', + key: 'assignedTo', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Product Name', + key: 'productName', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listProducts', + }, + ], + }, + }, + { + label: 'Channel', + key: 'channel', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listCaseOptions', + }, + { + name: 'parameters.channel', + value: 'casechannel', + }, + ], + }, + }, + { + label: 'Resolution', + key: 'resolution', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Category', + key: 'category', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listCaseOptions', + }, + { + name: 'parameters.category', + value: 'impact_type', + }, + ], + }, + }, + { + label: 'Sub Category', + key: 'subCategory', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listCaseOptions', + }, + { + name: 'parameters.subCategory', + value: 'impact_area', + }, + ], + }, + }, + { + label: 'Resolution Type', + key: 'resolutionType', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listCaseOptions', + }, + { + name: 'parameters.resolutionType', + value: 'resolution_type', + }, + ], + }, + }, + { + label: 'Deferred Date', + key: 'deferredDate', + type: 'string', + required: false, + description: 'format: yyyy-mm-dd', + variables: true, + }, + { + label: 'Service Contracts', + key: 'serviceContracts', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listServiceContracts', + }, + ], + }, + }, + { + label: 'Asset', + key: 'asset', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listAssets', + }, + ], + }, + }, + { + label: 'SLA Name', + key: 'slaName', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listSlaNames', + }, + ], + }, + }, + { + label: 'Is Billable', + key: 'isBillable', + type: 'dropdown', + required: false, + description: '', + variables: true, + options: [ + { label: 'True', value: '1' }, + { label: 'False', value: '-1' }, + ], + }, + { + label: 'Service', + key: 'service', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listServices', + }, + ], + }, + }, + { + label: 'Rate', + key: 'rate', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Service Type', + key: 'serviceType', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listCaseOptions', + }, + { + name: 'parameters.serviceType', + value: 'servicetype', + }, + ], + }, + }, + { + label: 'Service Location', + key: 'serviceLocation', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listCaseOptions', + }, + { + name: 'parameters.serviceLocation', + value: 'servicelocation', + }, + ], + }, + }, + { + label: 'Work Location', + key: 'workLocation', + type: 'string', + required: false, + description: '', + variables: true, + }, +]; diff --git a/packages/backend/src/apps/vtiger-crm/actions/create-case/index.js b/packages/backend/src/apps/vtiger-crm/actions/create-case/index.js new file mode 100644 index 00000000..be770e7d --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/actions/create-case/index.js @@ -0,0 +1,78 @@ +import defineAction from '../../../../helpers/define-action.js'; +import { fields } from './fields.js'; + +export default defineAction({ + name: 'Create case', + key: 'createCase', + description: 'Create a new case.', + arguments: fields, + + async run($) { + const { + summary, + recordCurrency, + caseTitle, + status, + priority, + contactName, + organizationName, + group, + assignedTo, + productName, + channel, + resolution, + category, + subCategory, + resolutionType, + deferredDate, + serviceContracts, + asset, + slaName, + isBillable, + service, + rate, + serviceType, + serviceLocation, + workLocation, + } = $.step.parameters; + + const elementData = { + description: summary, + record_currency_id: recordCurrency, + title: caseTitle, + casestatus: status, + casepriority: priority, + contact_id: contactName, + parent_id: organizationName, + group_id: group, + assigned_user_id: assignedTo, + product_id: productName, + casechannel: channel, + resolution: resolution, + impact_type: category, + impact_area: subCategory, + resolution_type: resolutionType, + deferred_date: deferredDate, + servicecontract_id: serviceContracts, + asset_id: asset, + slaid: slaName, + is_billable: isBillable, + billing_service: service, + rate: rate, + servicetype: serviceType, + servicelocation: serviceLocation, + work_location: workLocation, + }; + + const body = { + operation: 'create', + sessionName: $.auth.data.sessionName, + element: JSON.stringify(elementData), + elementType: 'Cases', + }; + + const response = await $.http.post('/webservice.php', body); + + $.setActionItem({ raw: response.data }); + }, +}); diff --git a/packages/backend/src/apps/vtiger-crm/actions/index.js b/packages/backend/src/apps/vtiger-crm/actions/index.js index 48fe4fc1..a4cd130d 100644 --- a/packages/backend/src/apps/vtiger-crm/actions/index.js +++ b/packages/backend/src/apps/vtiger-crm/actions/index.js @@ -1,6 +1,13 @@ +import createCase from './create-case/index.js'; import createContact from './create-contact/index.js'; import createLead from './create-lead/index.js'; import createOpportunity from './create-opportunity/index.js'; import createTodo from './create-todo/index.js'; -export default [createContact, createLead, createOpportunity, createTodo]; +export default [ + createCase, + createContact, + createLead, + createOpportunity, + createTodo, +]; diff --git a/packages/backend/src/apps/vtiger-crm/dynamic-data/index.js b/packages/backend/src/apps/vtiger-crm/dynamic-data/index.js index f183c9d9..c3ee6aca 100644 --- a/packages/backend/src/apps/vtiger-crm/dynamic-data/index.js +++ b/packages/backend/src/apps/vtiger-crm/dynamic-data/index.js @@ -1,27 +1,37 @@ +import listAssets from './list-assets/index.js'; import listCampaignSources from './list-campaign-sources/index.js'; +import listCaseOptions from './list-case-options/index.js'; import listContactOptions from './list-contact-options/index.js'; import listContacts from './list-contacts/index.js'; +import listGroups from './list-groups/index.js'; import listLeadOptions from './list-lead-options/index.js'; import listMilestones from './list-milestones/index.js'; import listOpportunityOptions from './list-opportunity-options/index.js'; import listOrganizations from './list-organizations/index.js'; +import listProducts from './list-products/index.js'; import listProjects from './list-projects/index.js'; import listRecordCurrencies from './list-record-currencies/index.js'; +import listServiceContracts from './list-service-contracts/index.js'; import listServices from './list-services/index.js'; import listSlaNames from './list-sla-names/index.js'; import listTasks from './list-tasks/index.js'; import listTodoOptions from './list-todo-options/index.js'; export default [ + listAssets, listCampaignSources, + listCaseOptions, listContactOptions, listContacts, + listGroups, listLeadOptions, listMilestones, listOpportunityOptions, listOrganizations, + listProducts, listProjects, listRecordCurrencies, + listServiceContracts, listServices, listSlaNames, listTasks, diff --git a/packages/backend/src/apps/vtiger-crm/dynamic-data/list-assets/index.js b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-assets/index.js new file mode 100644 index 00000000..3606a4f9 --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-assets/index.js @@ -0,0 +1,29 @@ +export default { + name: 'List assets', + key: 'listAssets', + + async run($) { + const assets = { + data: [], + }; + + const params = { + operation: 'query', + sessionName: $.auth.data.sessionName, + query: 'SELECT * FROM Assets ORDER BY createdtime DESC;', + }; + + const { data } = await $.http.get('/webservice.php', { params }); + + if (data.result?.length) { + for (const asset of data.result) { + assets.data.push({ + value: asset.id, + name: `${asset.assetname} (${asset.assetstatus})`, + }); + } + } + + return assets; + }, +}; diff --git a/packages/backend/src/apps/vtiger-crm/dynamic-data/list-case-options/index.js b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-case-options/index.js new file mode 100644 index 00000000..9cc0163b --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-case-options/index.js @@ -0,0 +1,58 @@ +export default { + name: 'List case options', + key: 'listCaseOptions', + + async run($) { + const caseOptions = { + data: [], + }; + const { + status, + priority, + contactName, + productName, + channel, + category, + subCategory, + resolutionType, + serviceType, + serviceLocation, + } = $.step.parameters; + + const picklistFields = [ + status, + priority, + contactName, + productName, + channel, + category, + subCategory, + resolutionType, + serviceType, + serviceLocation, + ]; + + const params = { + operation: 'describe', + sessionName: $.auth.data.sessionName, + elementType: 'Cases', + }; + + const { data } = await $.http.get(`/webservice.php`, { params }); + + if (data.result.fields?.length) { + for (const field of data.result.fields) { + if (picklistFields.includes(field.name)) { + field.type.picklistValues.map((item) => + caseOptions.data.push({ + value: item.value, + name: item.label, + }) + ); + } + } + } + + return caseOptions; + }, +}; diff --git a/packages/backend/src/apps/vtiger-crm/dynamic-data/list-groups/index.js b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-groups/index.js new file mode 100644 index 00000000..51112b04 --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-groups/index.js @@ -0,0 +1,29 @@ +export default { + name: 'List groups', + key: 'listGroups', + + async run($) { + const groups = { + data: [], + }; + + const params = { + operation: 'query', + sessionName: $.auth.data.sessionName, + query: 'SELECT * FROM Groups;', + }; + + const { data } = await $.http.get('/webservice.php', { params }); + + if (data.result?.length) { + for (const group of data.result) { + groups.data.push({ + value: group.id, + name: group.groupname, + }); + } + } + + return groups; + }, +}; diff --git a/packages/backend/src/apps/vtiger-crm/dynamic-data/list-products/index.js b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-products/index.js new file mode 100644 index 00000000..f4be10c4 --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-products/index.js @@ -0,0 +1,29 @@ +export default { + name: 'List products', + key: 'listProducts', + + async run($) { + const products = { + data: [], + }; + + const params = { + operation: 'query', + sessionName: $.auth.data.sessionName, + query: 'SELECT * FROM Products ORDER BY createdtime DESC;', + }; + + const { data } = await $.http.get('/webservice.php', { params }); + + if (data.result?.length) { + for (const product of data.result) { + products.data.push({ + value: product.id, + name: product.productname, + }); + } + } + + return products; + }, +}; diff --git a/packages/backend/src/apps/vtiger-crm/dynamic-data/list-service-contracts/index.js b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-service-contracts/index.js new file mode 100644 index 00000000..d67e5d02 --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-service-contracts/index.js @@ -0,0 +1,29 @@ +export default { + name: 'List service contracts', + key: 'listServiceContracts', + + async run($) { + const serviceContracts = { + data: [], + }; + + const params = { + operation: 'query', + sessionName: $.auth.data.sessionName, + query: 'SELECT * FROM ServiceContracts ORDER BY createdtime DESC;', + }; + + const { data } = await $.http.get('/webservice.php', { params }); + + if (data.result?.length) { + for (const serviceContract of data.result) { + serviceContracts.data.push({ + value: serviceContract.id, + name: serviceContract.subject, + }); + } + } + + return serviceContracts; + }, +}; diff --git a/packages/docs/pages/apps/vtiger-crm/actions.md b/packages/docs/pages/apps/vtiger-crm/actions.md index 6494da09..b4985053 100644 --- a/packages/docs/pages/apps/vtiger-crm/actions.md +++ b/packages/docs/pages/apps/vtiger-crm/actions.md @@ -1,6 +1,8 @@ --- favicon: /favicons/vtiger-crm.svg items: + - name: Create case + desc: Create a new case. - name: Create contact desc: Create a new contact. - name: Create opportunity