Skip to content

Commit d1206e7

Browse files
committed
[Components] the_bookie #13973
Actions - Create Contact - Create Sales Invoice - Find Contacts Sources - New Contact Created - New Invoice Created - New Invoice Paid
1 parent 27b7ce9 commit d1206e7

File tree

18 files changed

+534
-486
lines changed

18 files changed

+534
-486
lines changed

components/the_bookie/actions/create-contact/create-contact.mjs

Lines changed: 109 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,135 @@
1-
import { axios } from "@pipedream/platform";
1+
import { ConfigurationError } from "@pipedream/platform";
22
import thebookie from "../../the_bookie.app.mjs";
33

44
export default {
55
key: "the_bookie-create-contact",
66
name: "Create Contact",
7-
description: "Instantly creates a new contact in the address book. [See the documentation](https://app.thebookie.nl/nl/help/category/developers/)",
8-
version: "0.0.{{ts}}",
7+
description: "Instantly creates a new contact in the address book. [See the documentation](https://app.thebookie.nl/nl/help/article/api-documentatie/#contact_create)",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
11-
the_bookie,
12-
name: {
11+
thebookie,
12+
organisationName: {
1313
type: "string",
14-
label: "Name",
15-
description: "The name of the contact",
14+
label: "Organisation Name",
15+
description: "The contact's organization name",
16+
},
17+
street: {
18+
type: "string",
19+
label: "Street",
20+
description: "The contact's address street",
21+
optional: true,
22+
},
23+
streetNumber: {
24+
type: "string",
25+
label: "Street Number",
26+
description: "The contact's address number",
27+
optional: true,
28+
},
29+
streetNumberAddition: {
30+
type: "string",
31+
label: "Street Number Addition",
32+
description: "The contact's address number addition",
33+
optional: true,
34+
},
35+
extraAddressLine: {
36+
type: "string",
37+
label: "Extra Address Line",
38+
description: "The contact's extra address line",
39+
optional: true,
40+
},
41+
postalCode: {
42+
type: "string",
43+
label: "Postal Code",
44+
description: "The contact's address postal code",
45+
optional: true,
46+
},
47+
town: {
48+
type: "string",
49+
label: "Town",
50+
description: "The contact's city",
51+
optional: true,
52+
},
53+
country: {
54+
type: "string",
55+
label: "Country",
56+
description: "The contact's country",
57+
optional: true,
58+
},
59+
isSupplier: {
60+
type: "boolean",
61+
label: "Is Supplier",
62+
description: "Whether the contact is supplier or not",
63+
optional: true,
64+
},
65+
isClient: {
66+
type: "boolean",
67+
label: "Is Client",
68+
description: "Whether the contact is client or not",
69+
optional: true,
1670
},
1771
email: {
1872
type: "string",
1973
label: "Email",
20-
description: "The email of the contact",
74+
description: "The contact's email address",
75+
optional: true,
2176
},
22-
phoneNumber: {
77+
telephoneNumber: {
2378
type: "string",
24-
label: "Phone Number",
25-
description: "The phone number of the contact",
79+
label: "Telephone Number",
80+
description: "The contact's telephone number",
81+
optional: true,
82+
},
83+
mobileNumber: {
84+
type: "string",
85+
label: "Mobile Number",
86+
description: "The contact's mobile number",
87+
optional: true,
2688
},
27-
address: {
89+
firstName: {
2890
type: "string",
29-
label: "Address",
30-
description: "The address of the contact",
91+
label: "First Name",
92+
description: "First name of the contact",
3193
optional: true,
3294
},
33-
notes: {
95+
lastName: {
3496
type: "string",
35-
label: "Notes",
36-
description: "Any extra notes for the contact",
97+
label: "Last Name",
98+
description: "Last name of the contact",
99+
optional: true,
100+
},
101+
extraInfo: {
102+
type: "string",
103+
label: "Extra Info",
104+
description: "An additional info",
37105
optional: true,
38106
},
39107
},
40108
async run({ $ }) {
41-
const response = await this.the_bookie.createContact({
42-
name: this.name,
43-
email: this.email,
44-
phoneNumber: this.phoneNumber,
45-
address: this.address,
46-
notes: this.notes,
109+
if (!this.isClient && !this.isSupplier) {
110+
throw new ConfigurationError("'Is Supplier' or 'Is Client' must be true (or both)");
111+
}
112+
113+
const response = await this.thebookie.createContact({
114+
$,
115+
data: {
116+
organisation_name: this.organisationName,
117+
street: this.street,
118+
street_number: this.streetNumber,
119+
street_number_addition: this.streetNumberAddition,
120+
extra_address_line: this.extraAddressLine,
121+
postal_code: this.postalCode,
122+
town: this.town,
123+
country: this.country,
124+
is_supplier: this.isSupplier,
125+
is_client: this.isClient,
126+
email: this.email,
127+
telephone_number: this.telephoneNumber,
128+
mobile_number: this.mobileNumber,
129+
first_name: this.firstName,
130+
last_name: this.lastName,
131+
extra_info: this.extraInfo,
132+
},
47133
});
48134

49135
$.export("$summary", `Successfully created contact with ID ${response.id}`);
Lines changed: 66 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,99 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import fs from "fs";
3+
import {
4+
checkTmp, parseObject,
5+
} from "../../common/utils.mjs";
16
import theBookie from "../../the_bookie.app.mjs";
2-
import { axios } from "@pipedream/platform";
37

48
export default {
59
key: "the_bookie-create-sales-invoice",
610
name: "Create Sales Invoice",
7-
description: "Creates a new sales invoice. [See the documentation](https://app.thebookie.nl/nl/help/category/developers/)",
11+
description: "Creates a new sales invoice. [See the documentation](https://app.thebookie.nl/nl/help/article/api-documentatie/#salesentry_create)",
812
version: "0.0.1",
913
type: "action",
1014
props: {
1115
theBookie,
12-
invoiceNumber: {
16+
contactId: {
1317
propDefinition: [
1418
theBookie,
15-
"invoiceNumber",
19+
"contactId",
1620
],
1721
},
18-
clientIdentifier: {
19-
propDefinition: [
20-
theBookie,
21-
"clientIdentifier",
22-
],
22+
invoiceNumber: {
23+
type: "string",
24+
label: "Invoice Number",
25+
description: "The number of the invoice",
2326
},
24-
productServiceDetails: {
25-
propDefinition: [
26-
theBookie,
27-
"productServiceDetails",
28-
],
27+
invoiceDate: {
28+
type: "string",
29+
label: "Invoice Date",
30+
description: "The date of the invoice. **Format: YYYY-MM-DD**",
2931
},
30-
appliedDiscounts: {
31-
propDefinition: [
32-
theBookie,
33-
"appliedDiscounts",
32+
expirationDate: {
33+
type: "string",
34+
label: "Expiration Date",
35+
description: "The expiration date of the invoice. **Format: YYYY-MM-DD**",
36+
},
37+
btwShifted: {
38+
type: "string",
39+
label: "VAT shifted",
40+
description: "The VAT type",
41+
options: [
3442
{
35-
optional: true,
43+
label: "No (standard)",
44+
value: "NONE",
3645
},
37-
],
38-
},
39-
taxInformation: {
40-
propDefinition: [
41-
theBookie,
42-
"taxInformation",
4346
{
44-
optional: true,
47+
label: "Shifted within The Netherlands",
48+
value: "NL",
4549
},
46-
],
47-
},
48-
dueDate: {
49-
propDefinition: [
50-
theBookie,
51-
"dueDate",
5250
{
53-
optional: true,
51+
label: "Shifted within EU",
52+
value: "EU",
5453
},
55-
],
56-
},
57-
paymentTerms: {
58-
propDefinition: [
59-
theBookie,
60-
"paymentTerms",
6154
{
62-
optional: true,
55+
label: "Shifted outside EU",
56+
value: "NON_EU",
6357
},
6458
],
59+
optional: true,
60+
},
61+
journalEntryLines: {
62+
type: "string[]",
63+
label: "Journal Entry Lines",
64+
description: "An array of stringified objects of item entry lines. **Example: { \"description\": \"Boekregel 1\", \"btw_type\": \"PROCENT_21\", \"amount\": \"1200.0\", \"quantity\": \"2.00\"}** btw_type can be only 'PERCENT_9', 'PERCENT_21' or 'PERCENT_0'",
65+
optional: true,
66+
},
67+
attachment: {
68+
type: "string",
69+
label: "Attachment",
70+
description: "The path to the pdf file saved to the `/tmp` directory (e.g. `/tmp/example.pdf`). [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory).",
71+
optional: true,
6572
},
6673
},
6774
async run({ $ }) {
75+
if (!this.journalEntryLines) {
76+
throw new ConfigurationError("At least one (1) 'Journal Entry Line' should be added");
77+
}
78+
if (this.attachment) {
79+
this.attachment = fs.readFileSync(checkTmp(this.attachment), {
80+
encoding: "base64",
81+
});
82+
}
6883
const response = await this.theBookie.createInvoice({
69-
invoiceNumber: this.invoiceNumber,
70-
clientIdentifier: this.clientIdentifier,
71-
productServiceDetails: this.productServiceDetails,
72-
appliedDiscounts: this.appliedDiscounts,
73-
taxInformation: this.taxInformation,
74-
dueDate: this.dueDate,
75-
paymentTerms: this.paymentTerms,
84+
$,
85+
data: {
86+
contact_id: this.contactId,
87+
invoice_number: this.invoiceNumber,
88+
invoice_date: this.invoiceDate,
89+
expiration_date: this.expirationDate,
90+
btw_shifted: this.btwShifted,
91+
journal_entry_lines: parseObject(this.journalEntryLines),
92+
attachment: this.attachment,
93+
},
7694
});
7795

78-
$.export("$summary", `Successfully created invoice with number ${response.invoiceNumber}`);
96+
$.export("$summary", `Successfully created invoice with number ${this.invoiceNumber}`);
7997
return response;
8098
},
8199
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { capitalize } from "../../common/utils.mjs";
2+
import theBookie from "../../the_bookie.app.mjs";
3+
4+
export default {
5+
key: "the_bookie-find-contact",
6+
name: "Find Contacts",
7+
description: "Find a contact from the address book. [See the documentation](https://app.thebookie.nl/nl/help/article/api-documentatie/#contact_list)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
theBookie,
12+
search: {
13+
type: "string",
14+
label: "Search",
15+
description: "Search by company name.",
16+
optional: true,
17+
},
18+
isClient: {
19+
type: "boolean",
20+
label: "Is Client",
21+
description: "Return only client contacts.",
22+
optional: true,
23+
},
24+
isSupplier: {
25+
type: "boolean",
26+
label: "Is Supplier",
27+
description: "Return only supplier contacts.",
28+
optional: true,
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = this.theBookie.paginate({
33+
$,
34+
fn: this.theBookie.searchContact,
35+
params: {
36+
search: this.search,
37+
is_client: capitalize(this.isClient),
38+
is_supplier: capitalize(this.isSupplier),
39+
},
40+
});
41+
42+
const responseArray = [];
43+
44+
for await (const item of response) {
45+
responseArray.push(item);
46+
}
47+
48+
$.export("$summary", `Found ${responseArray.length} contact(s)`);
49+
return responseArray;
50+
},
51+
};

0 commit comments

Comments
 (0)