@agnocon/piece-bexio 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.MIT-AP +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +93 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actions/create-company.d.ts +28 -0
- package/dist/lib/actions/create-company.d.ts.map +1 -0
- package/dist/lib/actions/create-company.js +461 -0
- package/dist/lib/actions/create-company.js.map +1 -0
- package/dist/lib/actions/create-file.d.ts +4 -0
- package/dist/lib/actions/create-file.d.ts.map +1 -0
- package/dist/lib/actions/create-file.js +48 -0
- package/dist/lib/actions/create-file.js.map +1 -0
- package/dist/lib/actions/create-manual-entry.d.ts +7 -0
- package/dist/lib/actions/create-manual-entry.d.ts.map +1 -0
- package/dist/lib/actions/create-manual-entry.js +426 -0
- package/dist/lib/actions/create-manual-entry.js.map +1 -0
- package/dist/lib/actions/create-person.d.ts +30 -0
- package/dist/lib/actions/create-person.d.ts.map +1 -0
- package/dist/lib/actions/create-person.js +477 -0
- package/dist/lib/actions/create-person.js.map +1 -0
- package/dist/lib/actions/create-product.d.ts +34 -0
- package/dist/lib/actions/create-product.d.ts.map +1 -0
- package/dist/lib/actions/create-product.js +527 -0
- package/dist/lib/actions/create-product.js.map +1 -0
- package/dist/lib/actions/create-project.d.ts +17 -0
- package/dist/lib/actions/create-project.d.ts.map +1 -0
- package/dist/lib/actions/create-project.js +316 -0
- package/dist/lib/actions/create-project.js.map +1 -0
- package/dist/lib/actions/create-sales-invoice.d.ts +25 -0
- package/dist/lib/actions/create-sales-invoice.d.ts.map +1 -0
- package/dist/lib/actions/create-sales-invoice.js +615 -0
- package/dist/lib/actions/create-sales-invoice.js.map +1 -0
- package/dist/lib/actions/create-sales-order.d.ts +25 -0
- package/dist/lib/actions/create-sales-order.d.ts.map +1 -0
- package/dist/lib/actions/create-sales-order.js +642 -0
- package/dist/lib/actions/create-sales-order.js.map +1 -0
- package/dist/lib/actions/create-sales-quote.d.ts +28 -0
- package/dist/lib/actions/create-sales-quote.d.ts.map +1 -0
- package/dist/lib/actions/create-sales-quote.js +666 -0
- package/dist/lib/actions/create-sales-quote.js.map +1 -0
- package/dist/lib/actions/create-time-tracking.d.ts +17 -0
- package/dist/lib/actions/create-time-tracking.d.ts.map +1 -0
- package/dist/lib/actions/create-time-tracking.js +380 -0
- package/dist/lib/actions/create-time-tracking.js.map +1 -0
- package/dist/lib/actions/export-invoice-pdf.d.ts +5 -0
- package/dist/lib/actions/export-invoice-pdf.d.ts.map +1 -0
- package/dist/lib/actions/export-invoice-pdf.js +94 -0
- package/dist/lib/actions/export-invoice-pdf.js.map +1 -0
- package/dist/lib/actions/find-account.d.ts +6 -0
- package/dist/lib/actions/find-account.d.ts.map +1 -0
- package/dist/lib/actions/find-account.js +107 -0
- package/dist/lib/actions/find-account.js.map +1 -0
- package/dist/lib/actions/find-company.d.ts +8 -0
- package/dist/lib/actions/find-company.d.ts.map +1 -0
- package/dist/lib/actions/find-company.js +160 -0
- package/dist/lib/actions/find-company.js.map +1 -0
- package/dist/lib/actions/find-country.d.ts +7 -0
- package/dist/lib/actions/find-country.d.ts.map +1 -0
- package/dist/lib/actions/find-country.js +125 -0
- package/dist/lib/actions/find-country.js.map +1 -0
- package/dist/lib/actions/find-person.d.ts +9 -0
- package/dist/lib/actions/find-person.d.ts.map +1 -0
- package/dist/lib/actions/find-person.js +175 -0
- package/dist/lib/actions/find-person.js.map +1 -0
- package/dist/lib/actions/find-product.d.ts +7 -0
- package/dist/lib/actions/find-product.d.ts.map +1 -0
- package/dist/lib/actions/find-product.js +124 -0
- package/dist/lib/actions/find-product.js.map +1 -0
- package/dist/lib/actions/search-invoice.d.ts +7 -0
- package/dist/lib/actions/search-invoice.d.ts.map +1 -0
- package/dist/lib/actions/search-invoice.js +140 -0
- package/dist/lib/actions/search-invoice.js.map +1 -0
- package/dist/lib/actions/search-order.d.ts +7 -0
- package/dist/lib/actions/search-order.d.ts.map +1 -0
- package/dist/lib/actions/search-order.js +139 -0
- package/dist/lib/actions/search-order.js.map +1 -0
- package/dist/lib/actions/search-quote.d.ts +7 -0
- package/dist/lib/actions/search-quote.d.ts.map +1 -0
- package/dist/lib/actions/search-quote.js +140 -0
- package/dist/lib/actions/search-quote.js.map +1 -0
- package/dist/lib/actions/send-sales-invoice.d.ts +9 -0
- package/dist/lib/actions/send-sales-invoice.d.ts.map +1 -0
- package/dist/lib/actions/send-sales-invoice.js +110 -0
- package/dist/lib/actions/send-sales-invoice.js.map +1 -0
- package/dist/lib/actions/update-company.d.ts +29 -0
- package/dist/lib/actions/update-company.d.ts.map +1 -0
- package/dist/lib/actions/update-company.js +506 -0
- package/dist/lib/actions/update-company.js.map +1 -0
- package/dist/lib/actions/update-person.d.ts +31 -0
- package/dist/lib/actions/update-person.d.ts.map +1 -0
- package/dist/lib/actions/update-person.js +524 -0
- package/dist/lib/actions/update-person.js.map +1 -0
- package/dist/lib/actions/update-product.d.ts +34 -0
- package/dist/lib/actions/update-product.d.ts.map +1 -0
- package/dist/lib/actions/update-product.js +556 -0
- package/dist/lib/actions/update-product.js.map +1 -0
- package/dist/lib/auth.d.ts +2 -0
- package/dist/lib/auth.d.ts.map +1 -0
- package/dist/lib/auth.js +51 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/common/client.d.ts +13 -0
- package/dist/lib/common/client.d.ts.map +1 -0
- package/dist/lib/common/client.js +64 -0
- package/dist/lib/common/client.js.map +1 -0
- package/dist/lib/common/index.d.ts +5 -0
- package/dist/lib/common/index.d.ts.map +1 -0
- package/dist/lib/common/index.js +10 -0
- package/dist/lib/common/index.js.map +1 -0
- package/dist/lib/common/props.d.ts +14 -0
- package/dist/lib/common/props.d.ts.map +1 -0
- package/dist/lib/common/props.js +118 -0
- package/dist/lib/common/props.js.map +1 -0
- package/dist/lib/common/types.d.ts +89 -0
- package/dist/lib/common/types.d.ts.map +1 -0
- package/dist/lib/common/types.js +6 -0
- package/dist/lib/common/types.js.map +1 -0
- package/dist/lib/triggers/new-order.d.ts +11 -0
- package/dist/lib/triggers/new-order.d.ts.map +1 -0
- package/dist/lib/triggers/new-order.js +152 -0
- package/dist/lib/triggers/new-order.js.map +1 -0
- package/dist/lib/triggers/new-product.d.ts +3 -0
- package/dist/lib/triggers/new-product.d.ts.map +1 -0
- package/dist/lib/triggers/new-product.js +111 -0
- package/dist/lib/triggers/new-product.js.map +1 -0
- package/dist/lib/triggers/new-project.d.ts +11 -0
- package/dist/lib/triggers/new-project.d.ts.map +1 -0
- package/dist/lib/triggers/new-project.js +141 -0
- package/dist/lib/triggers/new-project.js.map +1 -0
- package/dist/lib/triggers/new-quote.d.ts +11 -0
- package/dist/lib/triggers/new-quote.d.ts.map +1 -0
- package/dist/lib/triggers/new-quote.js +153 -0
- package/dist/lib/triggers/new-quote.js.map +1 -0
- package/dist/lib/triggers/new-sales-invoice.d.ts +11 -0
- package/dist/lib/triggers/new-sales-invoice.d.ts.map +1 -0
- package/dist/lib/triggers/new-sales-invoice.js +153 -0
- package/dist/lib/triggers/new-sales-invoice.js.map +1 -0
- package/dist/lib/triggers/new-updated-company.d.ts +3 -0
- package/dist/lib/triggers/new-updated-company.d.ts.map +1 -0
- package/dist/lib/triggers/new-updated-company.js +122 -0
- package/dist/lib/triggers/new-updated-company.js.map +1 -0
- package/dist/lib/triggers/new-updated-person.d.ts +3 -0
- package/dist/lib/triggers/new-updated-person.d.ts.map +1 -0
- package/dist/lib/triggers/new-updated-person.js +122 -0
- package/dist/lib/triggers/new-updated-person.js.map +1 -0
- package/package.json +48 -0
- package/src/index.ts +89 -0
- package/src/lib/actions/create-company.ts +464 -0
- package/src/lib/actions/create-file.ts +62 -0
- package/src/lib/actions/create-manual-entry.ts +445 -0
- package/src/lib/actions/create-person.ts +481 -0
- package/src/lib/actions/create-product.ts +563 -0
- package/src/lib/actions/create-project.ts +344 -0
- package/src/lib/actions/create-sales-invoice.ts +656 -0
- package/src/lib/actions/create-sales-order.ts +689 -0
- package/src/lib/actions/create-sales-quote.ts +713 -0
- package/src/lib/actions/create-time-tracking.ts +418 -0
- package/src/lib/actions/export-invoice-pdf.ts +104 -0
- package/src/lib/actions/find-account.ts +114 -0
- package/src/lib/actions/find-company.ts +193 -0
- package/src/lib/actions/find-country.ts +127 -0
- package/src/lib/actions/find-person.ts +208 -0
- package/src/lib/actions/find-product.ts +161 -0
- package/src/lib/actions/search-invoice.ts +157 -0
- package/src/lib/actions/search-order.ts +155 -0
- package/src/lib/actions/search-quote.ts +157 -0
- package/src/lib/actions/send-sales-invoice.ts +118 -0
- package/src/lib/actions/update-company.ts +518 -0
- package/src/lib/actions/update-person.ts +536 -0
- package/src/lib/actions/update-product.ts +594 -0
- package/src/lib/auth.ts +44 -0
- package/src/lib/common/client.ts +65 -0
- package/src/lib/common/index.ts +5 -0
- package/src/lib/common/props.ts +127 -0
- package/src/lib/common/types.ts +99 -0
- package/src/lib/triggers/new-order.ts +184 -0
- package/src/lib/triggers/new-product.ts +154 -0
- package/src/lib/triggers/new-project.ts +165 -0
- package/src/lib/triggers/new-quote.ts +186 -0
- package/src/lib/triggers/new-sales-invoice.ts +186 -0
- package/src/lib/triggers/new-updated-company.ts +161 -0
- package/src/lib/triggers/new-updated-person.ts +161 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { createAction, Property, DynamicPropsValue, OAuth2PropertyValue } from '@agnocon/pieces-framework';
|
|
2
|
+
import { bexioAuth } from '../auth';
|
|
3
|
+
import { BexioClient } from '../common/client';
|
|
4
|
+
import { bexioCommonProps } from '../common/props';
|
|
5
|
+
import { BexioManualEntry, BexioManualEntryResponse } from '../common/types';
|
|
6
|
+
|
|
7
|
+
export const createManualEntryAction = createAction({
|
|
8
|
+
auth: bexioAuth,
|
|
9
|
+
name: 'create_manual_entry',
|
|
10
|
+
displayName: 'Create Manual Entry',
|
|
11
|
+
description: 'Create a manual accounting entry (single, compound, or group)',
|
|
12
|
+
audience: 'both',
|
|
13
|
+
aiMetadata: { description: 'Books a manual accounting entry in Bexio in one of three modes: a single debit/credit line, a compound entry distributing a total across several accounts, or a group of multiple complete bookings sharing one reference. Use to post journal entries directly to the ledger; requires a booking date and the entry lines for the chosen mode (account ids resolvable via Find Account). Not idempotent: each call posts new ledger bookings.', idempotent: false },
|
|
14
|
+
props: {
|
|
15
|
+
type: Property.StaticDropdown({
|
|
16
|
+
displayName: 'Entry Type',
|
|
17
|
+
description: 'Choose the type of manual entry',
|
|
18
|
+
required: true,
|
|
19
|
+
defaultValue: 'manual_single_entry',
|
|
20
|
+
options: {
|
|
21
|
+
disabled: false,
|
|
22
|
+
options: [
|
|
23
|
+
{
|
|
24
|
+
label: 'Single Entry - Simple one-line booking',
|
|
25
|
+
value: 'manual_single_entry',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: 'Compound Entry - Total distributed across multiple accounts',
|
|
29
|
+
value: 'manual_compound_entry',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: 'Group Entry - Multiple separate bookings with same reference',
|
|
33
|
+
value: 'manual_group_entry',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
date: Property.ShortText({
|
|
39
|
+
displayName: 'Booking Date',
|
|
40
|
+
description: 'Date of the booking (YYYY-MM-DD)',
|
|
41
|
+
required: true,
|
|
42
|
+
}),
|
|
43
|
+
reference_nr: Property.ShortText({
|
|
44
|
+
displayName: 'Reference Number',
|
|
45
|
+
description: 'Reference number for the booking',
|
|
46
|
+
required: false,
|
|
47
|
+
}),
|
|
48
|
+
entryFields: Property.DynamicProperties({
|
|
49
|
+
auth: bexioAuth,
|
|
50
|
+
displayName: 'Entry Details',
|
|
51
|
+
description: 'Configure the entry details based on selected type',
|
|
52
|
+
required: true,
|
|
53
|
+
refreshers: ['type', 'auth'],
|
|
54
|
+
props: async ({ type, auth }, ctx) => {
|
|
55
|
+
const entryType = (type as unknown as string) || 'manual_single_entry';
|
|
56
|
+
|
|
57
|
+
let accounts: Array<{ id: number; account_no: string; name: string }> = [];
|
|
58
|
+
let taxes: Array<{ id: number; name: string; percentage: string }> = [];
|
|
59
|
+
let currencies: Array<{ id: number; name: string }> = [];
|
|
60
|
+
|
|
61
|
+
if (auth) {
|
|
62
|
+
try {
|
|
63
|
+
const client = new BexioClient(auth);
|
|
64
|
+
accounts = await client.get<Array<{ id: number; account_no: string; name: string }>>('/accounts');
|
|
65
|
+
taxes = await client.get<Array<{ id: number; name: string; percentage: string }>>('/taxes');
|
|
66
|
+
currencies = await client.get<Array<{ id: number; name: string }>>('/3.0/currencies');
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.warn('Failed to fetch accounts/taxes/currencies:', error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const accountOptions = accounts.map((acc) => ({
|
|
73
|
+
label: `${acc.account_no} - ${acc.name}`,
|
|
74
|
+
value: acc.id,
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
const taxOptions = taxes.map((tax) => ({
|
|
78
|
+
label: `${tax.name} (${tax.percentage}%)`,
|
|
79
|
+
value: tax.id,
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
const currencyOptions = currencies.map((curr) => ({
|
|
83
|
+
label: curr.name,
|
|
84
|
+
value: curr.id,
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
if (entryType === 'manual_single_entry') {
|
|
88
|
+
return {
|
|
89
|
+
debit_account: accountOptions.length > 0
|
|
90
|
+
? Property.StaticDropdown({
|
|
91
|
+
displayName: 'Debit Account',
|
|
92
|
+
description: 'The account to debit',
|
|
93
|
+
required: true,
|
|
94
|
+
options: {
|
|
95
|
+
disabled: false,
|
|
96
|
+
options: accountOptions,
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
: Property.Number({
|
|
100
|
+
displayName: 'Debit Account ID',
|
|
101
|
+
description: 'The account ID to debit',
|
|
102
|
+
required: true,
|
|
103
|
+
}),
|
|
104
|
+
credit_account: accountOptions.length > 0
|
|
105
|
+
? Property.StaticDropdown({
|
|
106
|
+
displayName: 'Credit Account',
|
|
107
|
+
description: 'The account to credit',
|
|
108
|
+
required: true,
|
|
109
|
+
options: {
|
|
110
|
+
disabled: false,
|
|
111
|
+
options: accountOptions,
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
: Property.Number({
|
|
115
|
+
displayName: 'Credit Account ID',
|
|
116
|
+
description: 'The account ID to credit',
|
|
117
|
+
required: true,
|
|
118
|
+
}),
|
|
119
|
+
amount: Property.Number({
|
|
120
|
+
displayName: 'Amount',
|
|
121
|
+
description: 'The transaction amount',
|
|
122
|
+
required: true,
|
|
123
|
+
}),
|
|
124
|
+
description: Property.ShortText({
|
|
125
|
+
displayName: 'Description',
|
|
126
|
+
description: 'Description of the transaction',
|
|
127
|
+
required: false,
|
|
128
|
+
}),
|
|
129
|
+
tax_id: taxOptions.length > 0
|
|
130
|
+
? Property.StaticDropdown({
|
|
131
|
+
displayName: 'Tax',
|
|
132
|
+
description: 'Tax rate (optional)',
|
|
133
|
+
required: false,
|
|
134
|
+
options: {
|
|
135
|
+
disabled: false,
|
|
136
|
+
options: taxOptions,
|
|
137
|
+
},
|
|
138
|
+
})
|
|
139
|
+
: Property.Number({
|
|
140
|
+
displayName: 'Tax ID',
|
|
141
|
+
description: 'Tax ID (optional)',
|
|
142
|
+
required: false,
|
|
143
|
+
}),
|
|
144
|
+
tax_account: accountOptions.length > 0
|
|
145
|
+
? Property.StaticDropdown({
|
|
146
|
+
displayName: 'Tax Account',
|
|
147
|
+
description: 'Account for tax calculation',
|
|
148
|
+
required: false,
|
|
149
|
+
options: {
|
|
150
|
+
disabled: false,
|
|
151
|
+
options: accountOptions,
|
|
152
|
+
},
|
|
153
|
+
})
|
|
154
|
+
: Property.Number({
|
|
155
|
+
displayName: 'Tax Account ID',
|
|
156
|
+
description: 'Account ID for tax calculation',
|
|
157
|
+
required: false,
|
|
158
|
+
}),
|
|
159
|
+
currency_id: currencyOptions.length > 0
|
|
160
|
+
? Property.StaticDropdown({
|
|
161
|
+
displayName: 'Currency',
|
|
162
|
+
description: 'Currency (optional)',
|
|
163
|
+
required: false,
|
|
164
|
+
options: {
|
|
165
|
+
disabled: false,
|
|
166
|
+
options: currencyOptions,
|
|
167
|
+
},
|
|
168
|
+
})
|
|
169
|
+
: Property.Number({
|
|
170
|
+
displayName: 'Currency ID',
|
|
171
|
+
description: 'Currency ID (optional)',
|
|
172
|
+
required: false,
|
|
173
|
+
}),
|
|
174
|
+
currency_factor: Property.Number({
|
|
175
|
+
displayName: 'Currency Factor',
|
|
176
|
+
description: 'Exchange rate factor (defaults to 1)',
|
|
177
|
+
required: false,
|
|
178
|
+
}),
|
|
179
|
+
helper_info: Property.MarkDown({
|
|
180
|
+
value: '',
|
|
181
|
+
}),
|
|
182
|
+
entries: Property.Array({
|
|
183
|
+
displayName: 'Entries',
|
|
184
|
+
description: 'Not used for single entries',
|
|
185
|
+
required: false,
|
|
186
|
+
properties: {},
|
|
187
|
+
}),
|
|
188
|
+
};
|
|
189
|
+
} else {
|
|
190
|
+
const isCompound = entryType === 'manual_compound_entry';
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
debit_account: Property.Number({
|
|
194
|
+
displayName: 'Debit Account',
|
|
195
|
+
description: 'Not used for compound/group entries',
|
|
196
|
+
required: false,
|
|
197
|
+
}),
|
|
198
|
+
credit_account: Property.Number({
|
|
199
|
+
displayName: 'Credit Account',
|
|
200
|
+
description: 'Not used for compound/group entries',
|
|
201
|
+
required: false,
|
|
202
|
+
}),
|
|
203
|
+
amount: Property.Number({
|
|
204
|
+
displayName: 'Amount',
|
|
205
|
+
description: 'Not used for compound/group entries',
|
|
206
|
+
required: false,
|
|
207
|
+
}),
|
|
208
|
+
description: Property.ShortText({
|
|
209
|
+
displayName: 'Description',
|
|
210
|
+
description: 'Not used for compound/group entries',
|
|
211
|
+
required: false,
|
|
212
|
+
}),
|
|
213
|
+
tax_id: Property.Number({
|
|
214
|
+
displayName: 'Tax ID',
|
|
215
|
+
description: 'Not used for compound/group entries',
|
|
216
|
+
required: false,
|
|
217
|
+
}),
|
|
218
|
+
tax_account: Property.Number({
|
|
219
|
+
displayName: 'Tax Account',
|
|
220
|
+
description: 'Not used for compound/group entries',
|
|
221
|
+
required: false,
|
|
222
|
+
}),
|
|
223
|
+
currency_id: Property.Number({
|
|
224
|
+
displayName: 'Currency ID',
|
|
225
|
+
description: 'Not used for compound/group entries',
|
|
226
|
+
required: false,
|
|
227
|
+
}),
|
|
228
|
+
currency_factor: Property.Number({
|
|
229
|
+
displayName: 'Currency Factor',
|
|
230
|
+
description: 'Not used for compound/group entries',
|
|
231
|
+
required: false,
|
|
232
|
+
}),
|
|
233
|
+
helper_info: Property.MarkDown({
|
|
234
|
+
value: isCompound
|
|
235
|
+
? 'For compound entries, each entry should have EITHER debit_account_id OR credit_account_id (not both).'
|
|
236
|
+
: 'For group entries, each entry must have BOTH debit_account_id and credit_account_id.',
|
|
237
|
+
}),
|
|
238
|
+
entries: Property.Array({
|
|
239
|
+
displayName: 'Entries',
|
|
240
|
+
description: isCompound
|
|
241
|
+
? 'Multiple entries to distribute the total. Each entry should have either debit_account_id OR credit_account_id (not both).'
|
|
242
|
+
: 'Multiple complete bookings. Each entry must have both debit_account_id and credit_account_id.',
|
|
243
|
+
required: true,
|
|
244
|
+
properties: {
|
|
245
|
+
debit_account_id: accountOptions.length > 0
|
|
246
|
+
? Property.StaticDropdown({
|
|
247
|
+
displayName: 'Debit Account',
|
|
248
|
+
description: isCompound
|
|
249
|
+
? 'Account to debit (leave empty if this is a credit entry)'
|
|
250
|
+
: 'Account to debit',
|
|
251
|
+
required: !isCompound,
|
|
252
|
+
options: {
|
|
253
|
+
disabled: false,
|
|
254
|
+
options: accountOptions,
|
|
255
|
+
},
|
|
256
|
+
})
|
|
257
|
+
: Property.Number({
|
|
258
|
+
displayName: 'Debit Account ID',
|
|
259
|
+
description: isCompound
|
|
260
|
+
? 'Account ID to debit (leave 0 if this is a credit entry)'
|
|
261
|
+
: 'Account ID to debit',
|
|
262
|
+
required: !isCompound,
|
|
263
|
+
}),
|
|
264
|
+
credit_account_id: accountOptions.length > 0
|
|
265
|
+
? Property.StaticDropdown({
|
|
266
|
+
displayName: 'Credit Account',
|
|
267
|
+
description: isCompound
|
|
268
|
+
? 'Account to credit (leave empty if this is a debit entry)'
|
|
269
|
+
: 'Account to credit',
|
|
270
|
+
required: !isCompound,
|
|
271
|
+
options: {
|
|
272
|
+
disabled: false,
|
|
273
|
+
options: accountOptions,
|
|
274
|
+
},
|
|
275
|
+
})
|
|
276
|
+
: Property.Number({
|
|
277
|
+
displayName: 'Credit Account ID',
|
|
278
|
+
description: isCompound
|
|
279
|
+
? 'Account ID to credit (leave 0 if this is a debit entry)'
|
|
280
|
+
: 'Account ID to credit',
|
|
281
|
+
required: !isCompound,
|
|
282
|
+
}),
|
|
283
|
+
amount: Property.Number({
|
|
284
|
+
displayName: 'Amount',
|
|
285
|
+
description: 'The transaction amount',
|
|
286
|
+
required: true,
|
|
287
|
+
}),
|
|
288
|
+
description: Property.ShortText({
|
|
289
|
+
displayName: 'Description',
|
|
290
|
+
description: 'Description for this entry',
|
|
291
|
+
required: false,
|
|
292
|
+
}),
|
|
293
|
+
tax_id: taxOptions.length > 0
|
|
294
|
+
? Property.StaticDropdown({
|
|
295
|
+
displayName: 'Tax',
|
|
296
|
+
description: 'Tax rate (optional)',
|
|
297
|
+
required: false,
|
|
298
|
+
options: {
|
|
299
|
+
disabled: false,
|
|
300
|
+
options: taxOptions,
|
|
301
|
+
},
|
|
302
|
+
})
|
|
303
|
+
: Property.Number({
|
|
304
|
+
displayName: 'Tax ID',
|
|
305
|
+
description: 'Tax ID (optional)',
|
|
306
|
+
required: false,
|
|
307
|
+
}),
|
|
308
|
+
tax_account_id: accountOptions.length > 0
|
|
309
|
+
? Property.StaticDropdown({
|
|
310
|
+
displayName: 'Tax Account',
|
|
311
|
+
description: 'Account for tax calculation (optional)',
|
|
312
|
+
required: false,
|
|
313
|
+
options: {
|
|
314
|
+
disabled: false,
|
|
315
|
+
options: accountOptions,
|
|
316
|
+
},
|
|
317
|
+
})
|
|
318
|
+
: Property.Number({
|
|
319
|
+
displayName: 'Tax Account ID',
|
|
320
|
+
description: 'Account ID for tax calculation (optional)',
|
|
321
|
+
required: false,
|
|
322
|
+
}),
|
|
323
|
+
currency_id: currencyOptions.length > 0
|
|
324
|
+
? Property.StaticDropdown({
|
|
325
|
+
displayName: 'Currency',
|
|
326
|
+
description: 'Currency (optional)',
|
|
327
|
+
required: false,
|
|
328
|
+
options: {
|
|
329
|
+
disabled: false,
|
|
330
|
+
options: currencyOptions,
|
|
331
|
+
},
|
|
332
|
+
})
|
|
333
|
+
: Property.Number({
|
|
334
|
+
displayName: 'Currency ID',
|
|
335
|
+
description: 'Currency ID (optional)',
|
|
336
|
+
required: false,
|
|
337
|
+
}),
|
|
338
|
+
currency_factor: Property.Number({
|
|
339
|
+
displayName: 'Currency Factor',
|
|
340
|
+
description: 'Exchange rate factor (defaults to 1)',
|
|
341
|
+
required: false,
|
|
342
|
+
}),
|
|
343
|
+
},
|
|
344
|
+
}),
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
}),
|
|
349
|
+
},
|
|
350
|
+
async run(context) {
|
|
351
|
+
const client = new BexioClient(context.auth);
|
|
352
|
+
const entryType = context.propsValue.type as 'manual_single_entry' | 'manual_compound_entry' | 'manual_group_entry';
|
|
353
|
+
const entryFields = context.propsValue.entryFields as DynamicPropsValue;
|
|
354
|
+
|
|
355
|
+
let entries: BexioManualEntry[] = [];
|
|
356
|
+
|
|
357
|
+
if (entryType === 'manual_single_entry') {
|
|
358
|
+
const entry: BexioManualEntry = {
|
|
359
|
+
debit_account_id: entryFields['debit_account'] as number,
|
|
360
|
+
credit_account_id: entryFields['credit_account'] as number,
|
|
361
|
+
amount: entryFields['amount'] as number,
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
if (entryFields['description']) {
|
|
365
|
+
entry.description = entryFields['description'] as string;
|
|
366
|
+
}
|
|
367
|
+
if (entryFields['tax_id']) {
|
|
368
|
+
entry.tax_id = entryFields['tax_id'] as number;
|
|
369
|
+
}
|
|
370
|
+
if (entryFields['tax_account']) {
|
|
371
|
+
entry.tax_account_id = entryFields['tax_account'] as number;
|
|
372
|
+
}
|
|
373
|
+
if (entryFields['currency_id']) {
|
|
374
|
+
entry.currency_id = entryFields['currency_id'] as number;
|
|
375
|
+
}
|
|
376
|
+
if (entryFields['currency_factor']) {
|
|
377
|
+
entry.currency_factor = entryFields['currency_factor'] as number;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
entries = [entry];
|
|
381
|
+
} else {
|
|
382
|
+
const entriesArray = entryFields['entries'] as Array<Record<string, unknown>> | undefined;
|
|
383
|
+
|
|
384
|
+
if (!entriesArray || entriesArray.length === 0) {
|
|
385
|
+
throw new Error('At least one entry is required for compound or group entries');
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
entries = entriesArray.map((entry) => {
|
|
389
|
+
const bexioEntry: BexioManualEntry = {
|
|
390
|
+
amount: entry['amount'] as number,
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
const debitAccountId = entry['debit_account_id'] as number | undefined;
|
|
394
|
+
if (debitAccountId && debitAccountId !== 0) {
|
|
395
|
+
bexioEntry.debit_account_id = debitAccountId;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const creditAccountId = entry['credit_account_id'] as number | undefined;
|
|
399
|
+
if (creditAccountId && creditAccountId !== 0) {
|
|
400
|
+
bexioEntry.credit_account_id = creditAccountId;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (entry['description']) {
|
|
404
|
+
bexioEntry.description = entry['description'] as string;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const taxId = entry['tax_id'] as number | undefined;
|
|
408
|
+
if (taxId && taxId !== 0) {
|
|
409
|
+
bexioEntry.tax_id = taxId;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const taxAccountId = entry['tax_account_id'] as number | undefined;
|
|
413
|
+
if (taxAccountId && taxAccountId !== 0) {
|
|
414
|
+
bexioEntry.tax_account_id = taxAccountId;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const currencyId = entry['currency_id'] as number | undefined;
|
|
418
|
+
if (currencyId && currencyId !== 0) {
|
|
419
|
+
bexioEntry.currency_id = currencyId;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (entry['currency_factor']) {
|
|
423
|
+
bexioEntry.currency_factor = entry['currency_factor'] as number;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return bexioEntry;
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const requestBody = {
|
|
431
|
+
type: entryType,
|
|
432
|
+
date: context.propsValue.date,
|
|
433
|
+
reference_nr: context.propsValue.reference_nr,
|
|
434
|
+
entries,
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
const response = await client.post<BexioManualEntryResponse>(
|
|
438
|
+
'/accounts/manual_entries',
|
|
439
|
+
requestBody
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
return response;
|
|
443
|
+
},
|
|
444
|
+
});
|
|
445
|
+
|