Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 28 additions & 43 deletions components/zoho_books/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -1,60 +1,45 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import zohoBooks from "../../zoho_books.app.mjs";

export default {
props: {
zohoBooks,
http: "$.interface.http",
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
webhookName: {
type: "string",
label: "Webhook Name",
description: "A name to identify the webhook.",
},
},
methods: {
_getLastDate() {
return this.db.get("lastDate") || 0;
_getHookId() {
return this.db.get("hookId");
},
_setLastDate(lastDate) {
this.db.set("lastDate", lastDate);
},
async emitEvent(maxResults = false) {
const lastDate = this._getLastDate();

const response = this.zohoBooks.paginate({
fn: this.getFunction(),
fieldName: this.getFieldName(),
});

let responseArray = [];
for await (const item of response) {
if (item.created_time <= lastDate) break;
responseArray.push(item);
}

if (responseArray.length) {
if (maxResults && (responseArray.length > maxResults)) {
responseArray.length = maxResults;
}
this._setLastDate(Date.parse(responseArray[0].created_time));
}

for (const item of responseArray.reverse()) {
this.$emit(item, {
id: item[this.getFieldId()],
summary: this.getSummary(item),
ts: Date.parse(item.created_time),
});
}
_setHookId(hookId) {
this.db.set("hookId", hookId);
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
async activate() {
const { webhook } = await this.zohoBooks.createWebhook({
data: {
webhook_name: this.webhookName,
url: this.http.endpoint,
entity: this.getEntity(),
method: "POST",
body_type: "application/json",
raw_data: "${JSONString}",
},
});
this._setHookId(webhook.webhook_id);
},
async deactivate() {
const webhookId = this._getHookId();
await this.zohoBooks.deleteWebhook(webhookId);
},
},
async run() {
await this.emitEvent();
async run({ body }) {
if (body.payload === "") return true;
this.$emit(body, this.generateMeta(body));
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "zoho_books-new-customer-instant",
name: "New Customer (Instant)",
description: "Emit new event when a new customer is created.",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getEntity() {
return "customer";
},
generateMeta({ contact }) {
return {
id: contact.contact_id,
summary: `New Customer: ${contact.contact_name}`,
ts: Date.parse(contact.created_time),
};
},
},
sampleEmit,
};
114 changes: 114 additions & 0 deletions components/zoho_books/sources/new-customer-instant/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
export default {
"contact": {
"contact_id": 460000000026049,
"contact_name": "Bowman and Co",
"company_name": "Bowman and Co",
"has_transaction": true,
"contact_type": "customer",
"customer_sub_type": "business",
"credit_limit": 1000,
"is_taxable": true,
"tax_id": 11149000000061058,
"tax_name": "CGST",
"tax_percentage": 12,
"tax_authority_id": 11149000000061052,
"tax_exemption_id": 11149000000061054,
"tax_authority_name": "string",
"tax_exemption_code": "string",
"place_of_contact": "TN",
"gst_no": "22AAAAA0000A1Z5",
"tax_treatment": "string",
"tax_regime": "general_legal_person",
"legal_name": "ESCUELA KEMPER URGATE",
"is_tds_registered": true,
"vat_treatment": "string",
"gst_treatment": "business_gst",
"is_linked_with_zohocrm": false,
"website": "www.bowmanfurniture.com",
"owner_id": 460000000016051,
"primary_contact_id": 460000000026051,
"payment_terms": 15,
"payment_terms_label": "Net 15",
"currency_id": 460000000000097,
"currency_code": "USD",
"currency_symbol": "$",
"opening_balance_amount": 1200,
"exchange_rate": 1,
"outstanding_receivable_amount": 250,
"outstanding_receivable_amount_bcy": 250,
"unused_credits_receivable_amount": 1369.66,
"unused_credits_receivable_amount_bcy": 1369.66,
"status": "active",
"facebook": "zoho",
"twitter": "zoho",
"payment_reminder_enabled": true,
"custom_fields": [
{
"index": 1,
"value": "GBGD078",
"label": "VAT ID"
}
],
"billing_address": {
"attention": "Mr.John",
"address": "4900 Hopyard Rd",
"street2": "Suite 310",
"state_code": "CA",
"city": "Pleasanton",
"state": "CA",
"zip": 94588,
"country": "U.S.A",
"fax": "+1-925-924-9600",
"phone": "+1-925-921-9201"
},
"shipping_address": {
"attention": "Mr.John",
"address": "4900 Hopyard Rd",
"street2": "Suite 310",
"state_code": "CA",
"city": "Pleasanton",
"state": "CA",
"zip": 94588,
"country": "U.S.A",
"fax": "+1-925-924-9600",
"phone": "+1-925-921-9201"
},
"contact_persons": [
{
"contact_person_id": 460000000026051,
"salutation": "Mr",
"first_name": "Will",
"last_name": "Smith",
"email": "[email protected]",
"phone": "+1-925-921-9201",
"mobile": "+1-4054439562",
"designation": "Sales Executive",
"department": "Sales and Marketing",
"skype": "Zoho",
"is_primary_contact": true,
"enable_portal": true
}
],
"default_templates": {
"invoice_template_id": 460000000052069,
"estimate_template_id": 460000000000179,
"creditnote_template_id": 460000000000211,
"purchaseorder_template_id": 460000000000213,
"salesorder_template_id": 460000000000214,
"retainerinvoice_template_id": 460000000000215,
"paymentthankyou_template_id": 460000000000216,
"retainerinvoice_paymentthankyou_template_id": 460000000000217,
"invoice_email_template_id": 460000000052071,
"estimate_email_template_id": 460000000052073,
"creditnote_email_template_id": 460000000052075,
"purchaseorder_email_template_id": 460000000000218,
"salesorder_email_template_id": 460000000000219,
"retainerinvoice_email_template_id": 460000000000220,
"paymentthankyou_email_template_id": 460000000000221,
"retainerinvoice_paymentthankyou_email_template_id": 460000000000222
},
"notes": "Payment option : Through check",
"created_time": "2013-08-05T12:06:10+0530",
"last_modified_time": "2013-10-07T18:24:51+0530"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "zoho_books-new-expense-instant",
name: "New Expense (Instant)",
description: "Emit new event when a new expense is created.",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getEntity() {
return "expense";
},
generateMeta({ expense }) {
return {
id: expense.expense_id,
summary: `New Expense: ${expense.expense_id}`,
ts: Date.parse(expense.created_time),
};
},
},
sampleEmit,
};
97 changes: 97 additions & 0 deletions components/zoho_books/sources/new-expense-instant/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
export default {
"expense": {
"expense_id": 982000000030049,
"transaction_id": " ",
"transaction_type": "expense",
"gst_no": "22AAAAA0000A1Z5",
"gst_treatment": "business_gst",
"tax_treatment": "vat_registered",
"destination_of_supply": "TN",
"destination_of_supply_state": "TN",
"place_of_supply": "DU",
"hsn_or_sac": 80540,
"source_of_supply": "AP",
"paid_through_account_name": "Petty Cash",
"vat_reg_no": "string",
"reverse_charge_tax_id": 982000000561063,
"reverse_charge_tax_name": "intra",
"reverse_charge_tax_percentage": 10,
"reverse_charge_tax_amount": 12,
"tax_amount": 11.85,
"is_itemized_expense": false,
"is_pre_gst": "fasle",
"trip_id": "",
"trip_number": "",
"reverse_charge_vat_total": 1.2,
"acquisition_vat_total": 0,
"acquisition_vat_summary": [
{
"tax": {
"tax_name": "SalesTax",
"tax_amount": 11.85
}
}
],
"reverse_charge_vat_summary": [
{
"tax": {
"tax_name": "SalesTax",
"tax_amount": 11.85
}
}
],
"expense_item_id": 982000000567220,
"account_id": 982000000561057,
"account_name": "Rent",
"date": "2013-11-18",
"tax_id": 982000000566007,
"tax_name": "SalesTax",
"tax_percentage": 10.5,
"currency_id": 982000000567001,
"currency_code": "USD",
"exchange_rate": 1,
"sub_total": 90,
"total": 100,
"bcy_total": 100,
"amount": 112.5,
"is_inclusive_tax": false,
"reference_number": null,
"description": "Marketing",
"is_billable": true,
"is_personal": false,
"customer_id": 982000000567001,
"customer_name": "Bowman & Co",
"expense_receipt_name": " ",
"expense_receipt_type": " ",
"last_modified_time": " ",
"status": "unbilled",
"invoice_id": " ",
"invoice_number": " ",
"project_id": 982000000567226,
"project_name": " ",
"mileage_rate": " ",
"mileage_type": "non_mileage",
"expense_type": "non-mileage",
"start_reading": " ",
"end_reading": " ",
"line_item": {
"line_item_id": 10763000000140068,
"account_id": 982000000561057,
"account_name": "Rent",
"description": "Marketing",
"tax_amount": 11.85,
"tax_id": 982000000566007,
"tax_name": "SalesTax",
"tax_type": "tax",
"tax_percentage": 10.5,
"item_total": 100,
"item_order": 1,
"amount": 112.5,
"hsn_or_sac": 80540,
"reverse_charge_tax_id": 982000000561063,
"reverse_charge_tax_name": "intra",
"reverse_charge_tax_percentage": 10,
"reverse_charge_tax_amount": 12
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "zoho_books-new-sales-order-instant",
name: "New Sales Order (Instant)",
description: "Emit new event when a new sales order is created.",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getEntity() {
return "salesorder";
},
generateMeta({ salesorder }) {
return {
id: salesorder.salesorder_number,
summary: `New Sales Order: ${salesorder.salesorder_number}`,
ts: Date.parse(salesorder.created_time),
};
},
},
sampleEmit,
};
Loading
Loading