feat(vtiger-crm): add new invoices trigger
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import newCases from './new-cases/index.js';
|
import newCases from './new-cases/index.js';
|
||||||
import newContacts from './new-contacts/index.js';
|
import newContacts from './new-contacts/index.js';
|
||||||
|
import newInvoices from './new-invoices/index.js';
|
||||||
|
|
||||||
export default [newCases, newContacts];
|
export default [newCases, newContacts, newInvoices];
|
||||||
|
@@ -0,0 +1,41 @@
|
|||||||
|
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||||
|
|
||||||
|
export default defineTrigger({
|
||||||
|
name: 'New invoices',
|
||||||
|
key: 'newInvoices',
|
||||||
|
pollInterval: 15,
|
||||||
|
description: 'Triggers when a new invoice is created.',
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
let offset = 0;
|
||||||
|
const limit = 100;
|
||||||
|
let hasMore = true;
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
operation: 'query',
|
||||||
|
sessionName: $.auth.data.sessionName,
|
||||||
|
query: `SELECT * FROM Invoice ORDER BY createdtime DESC LIMIT ${offset}, ${limit};`,
|
||||||
|
};
|
||||||
|
|
||||||
|
do {
|
||||||
|
const { data } = await $.http.get('/webservice.php', {
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
offset = limit + offset;
|
||||||
|
|
||||||
|
if (!data?.result?.length) {
|
||||||
|
hasMore = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const item of data.result) {
|
||||||
|
$.pushTriggerItem({
|
||||||
|
raw: item,
|
||||||
|
meta: {
|
||||||
|
internalId: item.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} while (hasMore);
|
||||||
|
},
|
||||||
|
});
|
@@ -5,6 +5,8 @@ items:
|
|||||||
desc: Triggers when a new case is created.
|
desc: Triggers when a new case is created.
|
||||||
- name: New contacts
|
- name: New contacts
|
||||||
desc: Triggers when a new contact is created.
|
desc: Triggers when a new contact is created.
|
||||||
|
- name: New invoices
|
||||||
|
desc: Triggers when a new invoice is created.
|
||||||
---
|
---
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
Reference in New Issue
Block a user