Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import app from "../../sage_accounting.app.mjs";
import { optionalParseFloat } from "../../common/utils.mjs";

export default {
key: "sage_accounting-create-contact-payment",
name: "Create Contact Payment",
description: "Creates a new contact payment in Sage Accounting. [See the documentation](https://developer.sage.com/accounting/reference/payments/#operation/postContactPayments)",
version: "0.0.1",
type: "action",
props: {
app,
transactionTypeId: {
propDefinition: [
app,
"transactionTypeId",
],
},
contactId: {
propDefinition: [
app,
"contactId",
],
},
bankAccountId: {
propDefinition: [
app,
"bankAccountId",
],
},
date: {
propDefinition: [
app,
"date",
],
},
totalAmount: {
propDefinition: [
app,
"totalAmount",
],
},
paymentMethodId: {
propDefinition: [
app,
"paymentMethodId",
],
},
netAmount: {
propDefinition: [
app,
"netAmount",
],
},
taxAmount: {
propDefinition: [
app,
"taxAmount",
],
},
currencyId: {
propDefinition: [
app,
"currencyId",
],
},
exchangeRate: {
propDefinition: [
app,
"exchangeRate",
],
},
baseCurrencyNetAmount: {
propDefinition: [
app,
"baseCurrencyNetAmount",
],
},
baseCurrencyTaxAmount: {
propDefinition: [
app,
"baseCurrencyTaxAmount",
],
},
baseCurrencyTotalAmount: {
propDefinition: [
app,
"baseCurrencyTotalAmount",
],
},
baseCurrencyCurrencyCharge: {
propDefinition: [
app,
"baseCurrencyCurrencyCharge",
],
},
paymentReference: {
propDefinition: [
app,
"paymentReference",
],
},
taxRateId: {
propDefinition: [
app,
"taxRateId",
],
},
},
async run({ $ }) {
const data = {
contact_payment: {
transaction_type_id: this.transactionTypeId,
contact_id: this.contactId,
bank_account_id: this.bankAccountId,
date: this.date,
total_amount: parseFloat(this.totalAmount),
payment_method_id: this.paymentMethodId,
net_amount: optionalParseFloat(this.netAmount),
tax_amount: optionalParseFloat(this.taxAmount),
currency_id: this.currencyId,
exchange_rate: optionalParseFloat(this.exchangeRate),
base_currency_net_amount: optionalParseFloat(this.baseCurrencyNetAmount),
base_currency_tax_amount: optionalParseFloat(this.baseCurrencyTaxAmount),
base_currency_total_amount: optionalParseFloat(this.baseCurrencyTotalAmount),
base_currency_currency_charge: optionalParseFloat(this.baseCurrencyCurrencyCharge),
reference: this.paymentReference,
tax_rate_id: this.taxRateId,
},
};

const response = await this.app.createContactPayment({
$,
data,
});

$.export("$summary", `Successfully created contact payment (ID: ${response.id})`);
return response;
},
};
175 changes: 175 additions & 0 deletions components/sage_accounting/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import app from "../../sage_accounting.app.mjs";

export default {
key: "sage_accounting-create-contact",
name: "Create Contact",
description: "Creates a new contact in Sage Accounting. [See the documentation](https://developer.sage.com/accounting/reference/contacts/#tag/Contacts/operation/postContacts)",
version: "0.0.1",
type: "action",
props: {
app,
name: {
propDefinition: [
app,
"name",
],
},
contactTypeIds: {
propDefinition: [
app,
"contactTypeIds",
],
},
reference: {
propDefinition: [
app,
"reference",
],
},
taxNumber: {
propDefinition: [
app,
"taxNumber",
],
},
notes: {
propDefinition: [
app,
"notes",
],
},
locale: {
propDefinition: [
app,
"locale",
],
},
creditLimit: {
propDefinition: [
app,
"creditLimit",
],
},
creditDays: {
propDefinition: [
app,
"creditDays",
],
},
creditTerms: {
propDefinition: [
app,
"creditTerms",
],
},
creditTermsAndConditions: {
propDefinition: [
app,
"creditTermsAndConditions",
],
},
productSalesPriceTypeId: {
propDefinition: [
app,
"productSalesPriceTypeId",
],
},
sourceGuid: {
propDefinition: [
app,
"sourceGuid",
],
},
currencyId: {
propDefinition: [
app,
"currencyId",
],
},
auxReference: {
propDefinition: [
app,
"auxReference",
],
},
registeredNumber: {
propDefinition: [
app,
"registeredNumber",
],
},
taxCalculation: {
propDefinition: [
app,
"taxCalculation",
],
},
auxiliaryAccount: {
propDefinition: [
app,
"auxiliaryAccount",
],
},
destinationVatBlocking: {
propDefinition: [
app,
"destinationVatBlocking",
],
},
defaultSalesLedgerAccountId: {
propDefinition: [
app,
"ledgerAccountId",
],
label: "Default Sales Ledger Account ID",
description: "The ID of the default sales ledger account for the contact",
},
defaultSalesTaxRateId: {
propDefinition: [
app,
"defaultSalesTaxRateId",
],
},
defaultPurchaseLedgerAccountId: {
propDefinition: [
app,
"ledgerAccountId",
],
label: "Default Purchase Ledger Account ID",
description: "The ID of the default purchase ledger account for the contact",
},
},
async run({ $ }) {
const response = await this.app.createContact({
$,
data: {
contact: {
name: this.name,
contact_type_ids: this.contactTypeIds,
reference: this.reference,
default_sales_ledger_account_id: this.defaultSalesLedgerAccountId,
default_sales_tax_rate_id: this.defaultSalesTaxRateId,
default_purchase_ledger_account_id: this.defaultPurchaseLedgerAccountId,
tax_number: this.taxNumber,
notes: this.notes,
locale: this.locale,
credit_limit: this.creditLimit,
credit_days: this.creditDays,
credit_terms: this.creditTerms,
credit_terms_and_conditions: this.creditTermsAndConditions,
product_sales_price_type_id: this.productSalesPriceTypeId,
source_guid: this.sourceGuid,
currency_id: this.currencyId,
aux_reference: this.auxReference,
registered_number: this.registeredNumber,
tax_calculation: this.taxCalculation,
auxiliary_account: this.auxiliaryAccount,
destination_vat_blocking: this.destinationVatBlocking,
},
},
});

$.export("$summary", `Successfully created contact: ${response.name || response.displayed_as}`);
return response;
},
};
Loading
Loading