Skip to content

Commit 79d5429

Browse files
committed
Request adjustments and adding ledger account types
1 parent aee73b2 commit 79d5429

File tree

6 files changed

+139
-86
lines changed

6 files changed

+139
-86
lines changed

components/sage_accounting/actions/create-contact-payment/create-contact-payment.mjs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,24 @@ export default {
108108
},
109109
async run({ $ }) {
110110
const data = {
111-
transaction_type_id: this.transactionTypeId,
112-
contact_id: this.contactId,
113-
bank_account_id: this.bankAccountId,
114-
date: this.date,
115-
total_amount: parseFloat(this.totalAmount),
116-
payment_method_id: this.paymentMethodId,
117-
net_amount: optionalParseFloat(this.netAmount),
118-
tax_amount: optionalParseFloat(this.taxAmount),
119-
currency_id: this.currencyId,
120-
exchange_rate: optionalParseFloat(this.exchangeRate),
121-
base_currency_net_amount: optionalParseFloat(this.baseCurrencyNetAmount),
122-
base_currency_tax_amount: optionalParseFloat(this.baseCurrencyTaxAmount),
123-
base_currency_total_amount: optionalParseFloat(this.baseCurrencyTotalAmount),
124-
base_currency_currency_charge: optionalParseFloat(this.baseCurrencyCurrencyCharge),
125-
reference: this.paymentReference,
126-
tax_rate_id: this.taxRateId,
111+
contact_payment: {
112+
transaction_type_id: this.transactionTypeId,
113+
contact_id: this.contactId,
114+
bank_account_id: this.bankAccountId,
115+
date: this.date,
116+
total_amount: parseFloat(this.totalAmount),
117+
payment_method_id: this.paymentMethodId,
118+
net_amount: optionalParseFloat(this.netAmount),
119+
tax_amount: optionalParseFloat(this.taxAmount),
120+
currency_id: this.currencyId,
121+
exchange_rate: optionalParseFloat(this.exchangeRate),
122+
base_currency_net_amount: optionalParseFloat(this.baseCurrencyNetAmount),
123+
base_currency_tax_amount: optionalParseFloat(this.baseCurrencyTaxAmount),
124+
base_currency_total_amount: optionalParseFloat(this.baseCurrencyTotalAmount),
125+
base_currency_currency_charge: optionalParseFloat(this.baseCurrencyCurrencyCharge),
126+
reference: this.paymentReference,
127+
tax_rate_id: this.taxRateId,
128+
},
127129
};
128130

129131
const response = await this.app.createContactPayment({

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,29 @@ export default {
143143
const response = await this.app.createContact({
144144
$,
145145
data: {
146-
name: this.name,
147-
contact_type_ids: this.contactTypeIds,
148-
reference: this.reference,
149-
default_sales_ledger_account_id: this.defaultSalesLedgerAccountId,
150-
default_sales_tax_rate_id: this.defaultSalesTaxRateId,
151-
default_purchase_ledger_account_id: this.defaultPurchaseLedgerAccountId,
152-
tax_number: this.taxNumber,
153-
notes: this.notes,
154-
locale: this.locale,
155-
credit_limit: this.creditLimit,
156-
credit_days: this.creditDays,
157-
credit_terms: this.creditTerms,
158-
credit_terms_and_conditions: this.creditTermsAndConditions,
159-
product_sales_price_type_id: this.productSalesPriceTypeId,
160-
source_guid: this.sourceGuid,
161-
currency_id: this.currencyId,
162-
aux_reference: this.auxReference,
163-
registered_number: this.registeredNumber,
164-
tax_calculation: this.taxCalculation,
165-
auxiliary_account: this.auxiliaryAccount,
166-
destination_vat_blocking: this.destinationVatBlocking,
146+
contact: {
147+
name: this.name,
148+
contact_type_ids: this.contactTypeIds,
149+
reference: this.reference,
150+
default_sales_ledger_account_id: this.defaultSalesLedgerAccountId,
151+
default_sales_tax_rate_id: this.defaultSalesTaxRateId,
152+
default_purchase_ledger_account_id: this.defaultPurchaseLedgerAccountId,
153+
tax_number: this.taxNumber,
154+
notes: this.notes,
155+
locale: this.locale,
156+
credit_limit: this.creditLimit,
157+
credit_days: this.creditDays,
158+
credit_terms: this.creditTerms,
159+
credit_terms_and_conditions: this.creditTermsAndConditions,
160+
product_sales_price_type_id: this.productSalesPriceTypeId,
161+
source_guid: this.sourceGuid,
162+
currency_id: this.currencyId,
163+
aux_reference: this.auxReference,
164+
registered_number: this.registeredNumber,
165+
tax_calculation: this.taxCalculation,
166+
auxiliary_account: this.auxiliaryAccount,
167+
destination_vat_blocking: this.destinationVatBlocking,
168+
},
167169
},
168170
});
169171

components/sage_accounting/actions/create-product/create-product.mjs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,25 @@ export default {
1717
propDefinition: [
1818
app,
1919
"ledgerAccountId",
20+
() => ({
21+
type: "SALES",
22+
}),
2023
],
2124
label: "Sales Ledger Account ID",
2225
description: "The sales ledger account for the product",
26+
optional: false,
2327
},
2428
purchaseLedgerAccountId: {
2529
propDefinition: [
2630
app,
2731
"ledgerAccountId",
32+
() => ({
33+
type: "DIRECT_EXPENSES",
34+
}),
2835
],
2936
label: "Purchase Ledger Account ID",
3037
description: "The purchase ledger account for the product",
38+
optional: false,
3139
},
3240
itemCode: {
3341
type: "string",
@@ -118,19 +126,21 @@ export default {
118126
const response = await this.app.createProduct({
119127
$,
120128
data: {
121-
description: this.description,
122-
sales_ledger_account_id: this.salesLedgerAccountId,
123-
purchase_ledger_account_id: this.purchaseLedgerAccountId,
124-
item_code: this.itemCode,
125-
notes: this.notes,
126-
sales_tax_rate_id: this.salesTaxRateId,
127-
usual_supplier_id: this.usualSupplierId,
128-
purchase_tax_rate_id: this.purchaseTaxRateId,
129-
cost_price: this.costPrice,
130-
source_guid: this.sourceGuid,
131-
purchase_description: this.purchaseDescription,
132-
active: this.active,
133-
catalog_item_type_id: this.catalogItemTypeId,
129+
product: {
130+
description: this.description,
131+
sales_ledger_account_id: this.salesLedgerAccountId,
132+
purchase_ledger_account_id: this.purchaseLedgerAccountId,
133+
item_code: this.itemCode,
134+
notes: this.notes,
135+
sales_tax_rate_id: this.salesTaxRateId,
136+
usual_supplier_id: this.usualSupplierId,
137+
purchase_tax_rate_id: this.purchaseTaxRateId,
138+
cost_price: this.costPrice,
139+
source_guid: this.sourceGuid,
140+
purchase_description: this.purchaseDescription,
141+
active: this.active,
142+
catalog_item_type_id: this.catalogItemTypeId,
143+
},
134144
},
135145
});
136146

components/sage_accounting/actions/get-ledger-accounts/get-ledger-accounts.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export default {
88
type: "action",
99
props: {
1010
app,
11+
ledgerAccountType: {
12+
propDefinition: [
13+
app,
14+
"ledgerAccountType",
15+
],
16+
},
1117
itemsPerPage: {
1218
type: "integer",
1319
label: "Max Items",
@@ -29,9 +35,10 @@ export default {
2935
async run({ $ }) {
3036
const response = await this.app.listLedgerAccounts({
3137
$,
32-
page: this.page,
3338
params: {
39+
ledger_account_type_id: this.ledgerAccountType,
3440
items_per_page: this.itemsPerPage,
41+
page: this.page,
3542
},
3643
});
3744

components/sage_accounting/actions/update-contact/update-contact.mjs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,27 +152,29 @@ export default {
152152
$,
153153
contactId: this.contactId,
154154
data: {
155-
name: this.name,
156-
contact_type_ids: this.contactTypeIds,
157-
reference: this.reference,
158-
default_sales_ledger_account_id: this.defaultSalesLedgerAccountId,
159-
default_sales_tax_rate_id: this.defaultSalesTaxRateId,
160-
default_purchase_ledger_account_id: this.defaultPurchaseLedgerAccountId,
161-
tax_number: this.taxNumber,
162-
notes: this.notes,
163-
locale: this.locale,
164-
credit_limit: this.creditLimit,
165-
credit_days: this.creditDays,
166-
credit_terms: this.creditTerms,
167-
credit_terms_and_conditions: this.creditTermsAndConditions,
168-
product_sales_price_type_id: this.productSalesPriceTypeId,
169-
source_guid: this.sourceGuid,
170-
currency_id: this.currencyId,
171-
aux_reference: this.auxReference,
172-
registered_number: this.registeredNumber,
173-
tax_calculation: this.taxCalculation,
174-
auxiliary_account: this.auxiliaryAccount,
175-
destination_vat_blocking: this.destinationVatBlocking,
155+
contact: {
156+
name: this.name,
157+
contact_type_ids: this.contactTypeIds,
158+
reference: this.reference,
159+
default_sales_ledger_account_id: this.defaultSalesLedgerAccountId,
160+
default_sales_tax_rate_id: this.defaultSalesTaxRateId,
161+
default_purchase_ledger_account_id: this.defaultPurchaseLedgerAccountId,
162+
tax_number: this.taxNumber,
163+
notes: this.notes,
164+
locale: this.locale,
165+
credit_limit: this.creditLimit,
166+
credit_days: this.creditDays,
167+
credit_terms: this.creditTerms,
168+
credit_terms_and_conditions: this.creditTermsAndConditions,
169+
product_sales_price_type_id: this.productSalesPriceTypeId,
170+
source_guid: this.sourceGuid,
171+
currency_id: this.currencyId,
172+
aux_reference: this.auxReference,
173+
registered_number: this.registeredNumber,
174+
tax_calculation: this.taxCalculation,
175+
auxiliary_account: this.auxiliaryAccount,
176+
destination_vat_blocking: this.destinationVatBlocking,
177+
},
176178
},
177179
});
178180

components/sage_accounting/sage_accounting.app.mjs

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,28 @@ export default {
77
type: "app",
88
app: "sage_accounting",
99
propDefinitions: {
10+
ledgerAccountType: {
11+
type: "string",
12+
label: "Ledger Account Type",
13+
description: "The type of ledger account to retrieve",
14+
optional: true,
15+
async options({ page = 0 }) {
16+
const ledgerAccountTypes = await this.listLedgerAccountTypes({
17+
params: {
18+
page,
19+
},
20+
});
21+
return ledgerAccountTypes.map((ledgerAccountType) => ({
22+
label: ledgerAccountType.displayed_as,
23+
value: ledgerAccountType.id,
24+
}));
25+
},
26+
},
1027
contactId: {
1128
type: "string",
1229
label: "Contact ID",
1330
description: "The unique identifier for the contact",
14-
async options({ page }) {
31+
async options({ page = 0 }) {
1532
const contacts = await this.listContacts({
1633
params: {
1734
page,
@@ -27,7 +44,7 @@ export default {
2744
type: "string[]",
2845
label: "Contact Type IDs",
2946
description: "The IDs of the Contact Types",
30-
async options({ page }) {
47+
async options({ page = 0 }) {
3148
const contactTypes = await this.listContactTypes({
3249
params: {
3350
page,
@@ -46,7 +63,7 @@ export default {
4663
type: "string",
4764
label: "Currency ID",
4865
description: "The ID of the Currency",
49-
async options({ page }) {
66+
async options({ page = 0 }) {
5067
const currencies = await this.listCurrencies({
5168
params: {
5269
page,
@@ -74,10 +91,13 @@ export default {
7491
type: "string",
7592
label: "Ledger Account ID",
7693
description: "The ID of the ledger account",
77-
async options({ page }) {
94+
async options({
95+
page = 0, type,
96+
}) {
7897
const ledgerAccounts = await this.listLedgerAccounts({
7998
params: {
8099
page,
100+
ledger_account_type_id: type,
81101
},
82102
});
83103
return ledgerAccounts.map((account) => ({
@@ -195,7 +215,7 @@ export default {
195215
type: "string",
196216
label: "Transaction Type ID",
197217
description: "The transaction type of the payment",
198-
async options({ page }) {
218+
async options({ page = 0 }) {
199219
const transactionTypes = await this.listTransactionTypes({
200220
params: {
201221
page,
@@ -211,7 +231,7 @@ export default {
211231
type: "string",
212232
label: "Bank Account ID",
213233
description: "The bank account of the payment",
214-
async options({ page }) {
234+
async options({ page = 0 }) {
215235
const bankAccounts = await this.listBankAccounts({
216236
params: {
217237
page,
@@ -227,7 +247,7 @@ export default {
227247
type: "string",
228248
label: "Payment Method ID",
229249
description: "The ID of the Payment Method",
230-
async options({ page }) {
250+
async options({ page = 0 }) {
231251
const paymentMethods = await this.listPaymentMethods({
232252
params: {
233253
page,
@@ -244,7 +264,7 @@ export default {
244264
type: "string",
245265
label: "Tax Rate ID",
246266
description: "The ID of the Tax Rate",
247-
async options({ page }) {
267+
async options({ page = 0 }) {
248268
const taxRates = await this.listTaxRates({
249269
params: {
250270
page,
@@ -317,10 +337,6 @@ export default {
317337
},
318338
},
319339
methods: {
320-
// this.$auth contains connected account data
321-
authKeys() {
322-
console.log(Object.keys(this.$auth));
323-
},
324340
_baseUrl() {
325341
return "https://api.accounting.sage.com/v3.1";
326342
},
@@ -337,8 +353,16 @@ export default {
337353
},
338354
});
339355
},
340-
async _paginatedRequest(args = {}) {
341-
const response = await this._makeRequest(args);
356+
async _paginatedRequest({
357+
params, ...args
358+
}) {
359+
const response = await this._makeRequest({
360+
params: {
361+
...params,
362+
page: (params.page ?? 0) + 1,
363+
},
364+
...args,
365+
});
342366
return response.$items || response.items || [];
343367
},
344368
async listContactTypes(args) {
@@ -474,5 +498,11 @@ export default {
474498
...args,
475499
});
476500
},
501+
async listLedgerAccountTypes(args) {
502+
return this._paginatedRequest({
503+
path: "/ledger_account_types",
504+
...args,
505+
});
506+
},
477507
},
478508
};

0 commit comments

Comments
 (0)