Skip to content

Commit

Permalink
14645 components zoho books (#14764)
Browse files Browse the repository at this point in the history
* [Components] zoho-books #14645
- Component refactoring

Sources
 - New Customer
 - New Expense
 - New Sales Invoice

Actions
 - Create Customer
 - Create Estimate

* pnpm update

* some adjusts

* some adjusts

* Improve description

---------

Co-authored-by: Leo Vu <[email protected]>
  • Loading branch information
luancazarine and vunguyenhung authored Dec 5, 2024
1 parent a8245f7 commit d110209
Show file tree
Hide file tree
Showing 27 changed files with 3,049 additions and 1,154 deletions.
Original file line number Diff line number Diff line change
@@ -1,131 +1,137 @@
// legacy_hash_id: a_XziR2J
import { axios } from "@pipedream/platform";
import { PAYMENT_MODE_OPTIONS } from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";
import zohoBooks from "../../zoho_books.app.mjs";

export default {
key: "zoho_books-create-customer-payment",
name: "Create Customer Payment",
description: "Creates a new payment.",
version: "0.2.1",
description: "Creates a new payment. [See the documentation](https://www.zoho.com/books/api/v3/customer-payments/#create-a-payment)",
version: "0.3.0",
type: "action",
props: {
zoho_books: {
type: "app",
app: "zoho_books",
},
organization_id: {
type: "string",
description: "In Zoho Books, your business is termed as an organization. If you have multiple businesses, you simply set each of those up as an individual organization. Each organization is an independent Zoho Books Organization with it's own organization ID, base currency, time zone, language, contacts, reports, etc.\n\nThe parameter `organization_id` should be sent in with every API request to identify the organization.\n\nThe `organization_id` can be obtained from the GET `/organizations` API's JSON response. Alternatively, it can be obtained from the **Manage Organizations** page in the admin console.",
},
customer_id: {
type: "string",
description: "Customer ID of the customer involved in the payment.",
},
payment_mode: {
type: "string",
description: "Mode through which payment is made. This can be `check`, `cash`, `creditcard`, `banktransfer`, `bankremittance`, `autotransaction` or `others`. Max-length [100]",
options: [
"check",
"cash",
"creditcard",
"banktransfer",
"bankremittance",
"autotransaction",
"others",
zohoBooks,
customerId: {
propDefinition: [
zohoBooks,
"customerId",
],
},
invoices: {
type: "any",
description: "List of invoices associated with the payment. Each invoice object contains `invoice_id`, `invoice_number`, `date`, `invoice_amount`, `amount_applied` and `balance_amount`.",
paymentMode: {
type: "string",
label: "Payment Mode",
description: "Mode through which payment is made.",
options: PAYMENT_MODE_OPTIONS,
},
amount: {
type: "string",
label: "Amount",
description: "Amount paid in the respective payment.",
},
date: {
type: "string",
label: "Date",
description: "Date on which payment is made. Format [yyyy-mm-dd]",
},
reference_number: {
referenceNumber: {
type: "string",
label: "Reference Number",
description: "Reference number generated for the payment. A string of your choice can also be used as the reference number. Max-length [100]",
optional: true,
},
description: {
type: "string",
label: "Description",
description: "Description about the payment.",
optional: true,
},
exchange_rate: {
invoices: {
type: "string[]",
label: "Invoices",
description: "List of invoice objects associated with the payment. Each invoice object contains `invoice_id`, `invoice_number`, `date`, `invoice_amount`, `amount_applied` and `balance_amount`. **Example: {\"invoice_id\": \"90300000079426\", \"amount_applied\": 450}**",
},
exchangeRate: {
type: "string",
label: "Exchange Rate",
description: "Exchange rate for the currency used in the invoices and customer's currency. The payment amount would be the multiplicative product of the original amount and the exchange rate. Default is 1.",
optional: true,
},
bank_charges: {
bankCharges: {
type: "string",
label: "Bank Charges",
description: "Denotes any additional bank charges.",
optional: true,
},
custom_fields: {
type: "any",
description: "Additional fields for the payments.",
customFields: {
propDefinition: [
zohoBooks,
"customFields",
],
description: "A list of Additional field objects for the payments. **Example: {\"label\": \"label\", \"value\": 129890}**",
optional: true,
},
invoice_id: {
type: "string",
description: "ID of the invoice to get payments of.",
optional: true,
invoiceId: {
propDefinition: [
zohoBooks,
"invoiceId",
({ customerId }) => ({
customerId,
}),
],
},
amount_applied: {
amountApplied: {
type: "string",
label: "Amount Applied",
description: "Amount paid for the invoice.",
optional: true,
},
tax_amount_withheld: {
taxAmountWithheld: {
type: "string",
label: "Tax Amount Withheld",
description: "Amount withheld for tax.",
optional: true,
},
account_id: {
type: "string",
description: "ID of the cash/bank account the payment has to be deposited.",
accountId: {
propDefinition: [
zohoBooks,
"accountId",
],
optional: true,
},
contact_persons: {
type: "string",
description: "IDs of the contact personsthe thank you mail has to be triggered.",
contactPersons: {
propDefinition: [
zohoBooks,
"contactPersons",
({ customerId }) => ({
customerId,
}),
],
optional: true,
},
},
async run({ $ }) {
//See the API docs: https://www.zoho.com/books/api/v3/#Customer-Payments_Create_a_payment

if (!this.organization_id || !this.customer_id || !this.payment_mode || !this.invoices || !this.amount || !this.date) {
throw new Error("Must provide organization_id, customer_id, payment_mode, invoices, amount, and date parameters.");
}

return await axios($, {
method: "post",
url: `https://books.${this.zoho_books.$auth.base_api_uri}/api/v3/customerpayments?organization_id=${this.organization_id}`,
headers: {
Authorization: `Zoho-oauthtoken ${this.zoho_books.$auth.oauth_access_token}`,
},
const response = await this.zohoBooks.createCustomerPayment({
$,
data: {
customer_id: this.customer_id,
payment_mode: this.payment_mode,
customer_id: this.customerId,
payment_mode: this.paymentMode,
amount: this.amount,
date: this.date,
reference_number: this.reference_number,
reference_number: this.referenceNumber,
description: this.description,
invoices: this.invoices,
exchange_rate: this.exchange_rate,
bank_charges: this.bank_charges,
custom_fields: this.custom_fields,
invoice_id: this.invoice_id,
amount_applied: this.amount_applied,
tax_amount_withheld: this.tax_amount_withheld,
account_id: this.account_id,
contact_persons: this.contact_persons,
invoices: parseObject(this.invoices),
exchange_rate: this.exchangeRate && parseFloat(this.exchangeRate),
bank_charges: this.bankCharges && parseFloat(this.bankCharges),
custom_fields: parseObject(this.customFields),
invoice_id: this.invoiceId,
amount_applied: this.amountApplied && parseFloat(this.amountApplied),
tax_amount_withheld: this.taxAmountWithheld && parseFloat(this.taxAmountWithheld),
account_id: this.accountId,
contact_persons: parseObject(this.contactPersons),
},
});

$.export("$summary", `Customer payment successfully created with Id: ${response.payment.payment_id}`);
return response;
},
};
166 changes: 166 additions & 0 deletions components/zoho_books/actions/create-customer/create-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// legacy_hash_id: a_Xzi1qo
import {
CUSTOMER_SUB_TYPE_OPTIONS,
LANGUAGE_CODE_OPTIONS,
} from "../../common/constants.mjs";
import {
clearObj,
parseObject,
} from "../../common/utils.mjs";
import zohoBooks from "../../zoho_books.app.mjs";

export default {
key: "zoho_books-create-customer",
name: "Create Customer",
description: "Creates a new customer. [See the documentation](https://www.zoho.com/books/api/v3/items/#create-an-item)",
version: "0.0.1",
type: "action",
props: {
zohoBooks,
contactName: {
type: "string",
label: "Contact Name",
description: "Display Name of the contact. Max-length [200].",
},
companyName: {
type: "string",
label: "Company Name",
description: "Company Name of the contact. Max-length [200].",
optional: true,
},
website: {
type: "string",
label: "Website",
description: "Website of the contact.",
optional: true,
},
languageCode: {
type: "string",
label: "Language Code",
description: "The language of a contact.",
options: LANGUAGE_CODE_OPTIONS,
optional: true,
},
customerSubType: {
type: "string",
label: "Customer Sub Type",
description: "Type of the customer.",
options: CUSTOMER_SUB_TYPE_OPTIONS,
optional: true,
},
creditLimit: {
type: "string",
label: "Credit Limit",
description: "Credit limit for a customer.",
optional: true,
},
tags: {
type: "string[]",
label: "Tags",
description: "An array of tag objects. **Example: {\"tag_id\":\"124567890\",\"tag_option_id\":\"1234567890\"}**",
optional: true,
},
isPortalEnabled: {
type: "boolean",
label: "Is Portal Enabled",
description: "To enable client portal for the contact.",
optional: true,
},
currencyId: {
propDefinition: [
zohoBooks,
"currencyId",
],
optional: true,
},
paymentTerms: {
propDefinition: [
zohoBooks,
"paymentTerms",
],
description: "Net payment term for the customer.",
optional: true,
},
paymentTermsLabel: {
propDefinition: [
zohoBooks,
"paymentTermsLabel",
],
description: "Label for the paymet due details.",
optional: true,
},
notes: {
propDefinition: [
zohoBooks,
"notes",
],
description: "Commennts about the payment made by the contact.",
optional: true,
},
exchangeRate: {
propDefinition: [
zohoBooks,
"exchangeRate",
],
description: "Exchange rate for the opening balance.",
optional: true,
},
vatTreatment: {
propDefinition: [
zohoBooks,
"vatTreatment",
],
optional: true,
},
gstNo: {
propDefinition: [
zohoBooks,
"gstNo",
],
optional: true,
},
avataxUseCode: {
propDefinition: [
zohoBooks,
"avataxUseCode",
],
optional: true,
},
taxId: {
propDefinition: [
zohoBooks,
"taxId",
],
description: "ID of the tax to be associated to the estimate.",
optional: true,
},
},
async run({ $ }) {
const response = await this.zohoBooks.createContact({
$,
data: clearObj({
contact_name: this.contactName,
company_name: this.companyName,
website: this.website,
language_code: this.languageCode,
contact_type: "customer",
customer_sub_type: this.customerSubType,
credit_limit: this.creditLimit,
tags: parseObject(this.tags),
is_portal_enabled: this.isPortalEnabled,
currency_id: this.currencyId,
payment_terms: this.paymentTerms,
payment_terms_label: this.paymentTermsLabel,
notes: this.notes,
exchange_rate: this.exchangeRate && parseFloat(this.exchangeRate),
vat_treatment: this.vatTreatment,
gst_no: this.gstNo,
avatax_use_code: this.avataxUseCode,
tax_id: this.taxId,
}),
});

$.export("$summary", `Contact successfully created with Id: ${response.contact.contact_id}`);
return response;
},
};
Loading

0 comments on commit d110209

Please sign in to comment.