Skip to content

Commit 781d6ec

Browse files
authored
New Components - clear_books (#15287)
* clear_books init * new-components * updates * pnpm-lock.yaml * pnpm-lock.yaml * add lineItemsJson prop
1 parent 31a960e commit 781d6ec

File tree

10 files changed

+594
-7
lines changed

10 files changed

+594
-7
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import clearBooks from "../../clear_books.app.mjs";
2+
3+
export default {
4+
key: "clear_books-create-customer",
5+
name: "Create Customer",
6+
description: "Creates a new customer in Clear Books. [See the documentation](https://u.pcloud.link/publink/show?code=XZkThJ5Z4zKewgCL6VBpfxlPeHPDdXXj0Cc7)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
clearBooks,
11+
name: {
12+
type: "string",
13+
label: "Name",
14+
description: "Name of the customer",
15+
},
16+
email: {
17+
type: "string",
18+
label: "Email",
19+
description: "Email address of the customer",
20+
optional: true,
21+
},
22+
phone: {
23+
type: "string",
24+
label: "Phone",
25+
description: "Phone number of the customer",
26+
optional: true,
27+
},
28+
streetAddress: {
29+
type: "string",
30+
label: "Street Address",
31+
description: "Street address of the customer",
32+
optional: true,
33+
},
34+
town: {
35+
type: "string",
36+
label: "Town",
37+
description: "Town of the customer",
38+
optional: true,
39+
},
40+
county: {
41+
type: "string",
42+
label: "County",
43+
description: "County of the customer",
44+
optional: true,
45+
},
46+
postcode: {
47+
type: "string",
48+
label: "Postcode",
49+
description: "Postcode of the customer",
50+
optional: true,
51+
},
52+
countryCode: {
53+
type: "string",
54+
label: "Country Code",
55+
description: "Country code of the customer",
56+
optional: true,
57+
},
58+
},
59+
async run({ $ }) {
60+
const hasAddress = this.streetAddress
61+
|| this.town
62+
|| this.county
63+
|| this.postcode
64+
|| this.countryCode;
65+
66+
const response = await this.clearBooks.createCustomer({
67+
$,
68+
data: {
69+
name: this.name,
70+
email: this.email,
71+
phone: this.phone,
72+
address: hasAddress && {
73+
line1: this.streetAddress,
74+
town: this.town,
75+
county: this.county,
76+
postcode: this.postcode,
77+
countryCode: this.countryCode,
78+
},
79+
},
80+
});
81+
$.export("$summary", `Successfully created customer with ID: ${response.id}`);
82+
return response;
83+
},
84+
};
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import clearBooks from "../../clear_books.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "clear_books-create-purchase-document",
6+
name: "Create Purchase Document",
7+
description: "Creates a new Purchase Document in Clear Books. [See the documentation](https://u.pcloud.link/publink/show?code=XZkThJ5Z4zKewgCL6VBpfxlPeHPDdXXj0Cc7)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
clearBooks,
12+
purchaseType: {
13+
propDefinition: [
14+
clearBooks,
15+
"purchaseType",
16+
],
17+
},
18+
date: {
19+
type: "string",
20+
label: "Date",
21+
description: "The date of the purchase. Format: YYYY-MM-DD",
22+
},
23+
supplierId: {
24+
propDefinition: [
25+
clearBooks,
26+
"supplierId",
27+
],
28+
},
29+
description: {
30+
type: "string",
31+
label: "Description",
32+
description: "Description of the purchase document",
33+
optional: true,
34+
},
35+
numLineItems: {
36+
type: "integer",
37+
label: "Number of Line Items",
38+
description: "The number of line items. Use this to manually enter Unit Price, Quantity, and Description of each line item.",
39+
optional: true,
40+
reloadProps: true,
41+
},
42+
lineItemsJson: {
43+
type: "string",
44+
label: "Line Items JSON",
45+
description: "JSON value containing an array of Line Items. For example: `[{\"description\":\"Line Item 1 Description\",\"unitPrice\":1022,\"quantity\":1,\"accountCode\":\"2001001\"},{\"description\":\"Line Item 2 Description\",\"unitPrice\":1023,\"quantity\":2,\"accountCode\":\"2001001\"}]`. [See documentation](https://u.pcloud.link/publink/show?code=XZkThJ5Z4zKewgCL6VBpfxlPeHPDdXXj0Cc7)",
46+
optional: true,
47+
},
48+
},
49+
additionalProps() {
50+
const props = {};
51+
if (!this.numLineItems) {
52+
return props;
53+
}
54+
for (let i = 1; i <= this.numLineItems; i++) {
55+
props[`line_item_${i}_unit_price`] = {
56+
type: "string",
57+
label: `Line Item ${i} - Unit Price`,
58+
};
59+
props[`line_item_${i}_quantity`] = {
60+
type: "integer",
61+
label: `Line Item ${i} - Quantity`,
62+
};
63+
props[`line_item_${i}_description`] = {
64+
type: "string",
65+
label: `Line Item ${i} - Description`,
66+
};
67+
}
68+
return props;
69+
},
70+
methods: {
71+
buildLineItems() {
72+
const lineItems = [];
73+
for (let i = 1; i <= this.numLineItems; i++) {
74+
lineItems.push({
75+
unitPrice: this[`line_item_${i}_unit_price`],
76+
quantity: this[`line_item_${i}_quantity`],
77+
description: this[`line_item_${i}_description`],
78+
});
79+
}
80+
return lineItems;
81+
},
82+
parseLineItemsJson() {
83+
try {
84+
return Array.isArray(this.lineItemsJson)
85+
? this.lineItemsJson.map((item) => typeof item === "string"
86+
? JSON.parse(item)
87+
: item)
88+
: typeof this.lineItemsJson === "string"
89+
? JSON.parse(this.lineItemsJson)
90+
: this.lineItemsJson;
91+
} catch {
92+
throw new ConfigurationError("Could not parse Line Items JSON");
93+
}
94+
},
95+
},
96+
async run({ $ }) {
97+
if (!this.numLineItems && !this.lineItemsJson) {
98+
throw new ConfigurationError("Please enter at least one line item");
99+
}
100+
101+
const lineItems = [];
102+
if (this.numLineItems) {
103+
const lineItemsManual = this.buildLineItems();
104+
lineItems.push(...lineItemsManual);
105+
}
106+
if (this.lineItemsJson) {
107+
const lineItemsJson = this.parseLineItemsJson();
108+
lineItems.push(...lineItemsJson);
109+
}
110+
111+
const response = await this.clearBooks.createPurchaseDocument({
112+
$,
113+
type: this.purchaseType,
114+
data: {
115+
date: this.date,
116+
supplierId: this.supplierId,
117+
description: this.description,
118+
lineItems,
119+
},
120+
});
121+
$.export("$summary", `Successfully created purchase document with ID ${response.id}`);
122+
return response;
123+
},
124+
};
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import clearBooks from "../../clear_books.app.mjs";
2+
3+
export default {
4+
key: "clear_books-create-supplier",
5+
name: "Create Supplier",
6+
description: "Creates a new supplier in Clear Books. [See the documentation](https://u.pcloud.link/publink/show?code=XZkThJ5Z4zKewgCL6VBpfxlPeHPDdXXj0Cc7)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
clearBooks,
11+
name: {
12+
type: "string",
13+
label: "Name",
14+
description: "Name of the supplier",
15+
},
16+
email: {
17+
type: "string",
18+
label: "Email",
19+
description: "Email address of the supplier",
20+
optional: true,
21+
},
22+
phone: {
23+
type: "string",
24+
label: "Phone",
25+
description: "Phone number of the supplier",
26+
optional: true,
27+
},
28+
streetAddress: {
29+
type: "string",
30+
label: "Street Address",
31+
description: "Street address of the supplier",
32+
optional: true,
33+
},
34+
town: {
35+
type: "string",
36+
label: "Town",
37+
description: "Town of the supplier",
38+
optional: true,
39+
},
40+
county: {
41+
type: "string",
42+
label: "County",
43+
description: "County of the supplier",
44+
optional: true,
45+
},
46+
postcode: {
47+
type: "string",
48+
label: "Postcode",
49+
description: "Postcode of the supplier",
50+
optional: true,
51+
},
52+
countryCode: {
53+
type: "string",
54+
label: "Country Code",
55+
description: "Country code of the supplier",
56+
optional: true,
57+
},
58+
},
59+
async run({ $ }) {
60+
const hasAddress = this.streetAddress
61+
|| this.town
62+
|| this.county
63+
|| this.postcode
64+
|| this.countryCode;
65+
66+
const response = await this.clearBooks.createSupplier({
67+
$,
68+
data: {
69+
name: this.name,
70+
email: this.email,
71+
phone: this.phone,
72+
address: hasAddress && {
73+
line1: this.streetAddress,
74+
town: this.town,
75+
county: this.county,
76+
postcode: this.postcode,
77+
countryCode: this.countryCode,
78+
},
79+
},
80+
});
81+
$.export("$summary", `Successfully created supplier with ID: ${response.id}`);
82+
return response;
83+
},
84+
};

0 commit comments

Comments
 (0)