Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create Many Transactions in Amatino Swift - A double-entry accounting library for iOS & MacOS
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
let tx1Arguments = try TransactionCreateArguments(
transactionTime: Date(),
description: "Raise invoice for slick services",
globalUnit: usd,
entries: [
Entry(side: .debit, account: receivables, amount: Decimal(20)),
Entry(side: .credit, account: revenueAccount, amount: Decimal(20))
]
)
let tx2Arguments = try TransactionCreateArguments(
transactionTime: Date(),
description: "Borrow some Benjamins",
globalUnit: usd,
entries: [
Entry(side: .credit, account: bankLoan, amount: Decimal(200)),
Entry(side: .debit, account: cashAccount, amount: Decimal(200))
]
)
try Transaction.createMany(
session: session,
entity: starkIndustries,
arguments: [tx1Arguments, tx2Arguments],
callback: { (error: Error?, transactions: [Transaction]?) in
guard error == nil else {
// Handle errors
}
guard storedTransactions: [Transactions] = transactions else {
// Should never happen, but guarding against nil is
// spiritually wholesome
}
// Do cool stuff with newly stored Transactions
})
@hwjeremy

This comment has been minimized.

Copy link
Owner Author

@hwjeremy hwjeremy commented Jul 19, 2018

The parameters passed to Transaction.createMany() and the constituent TransactionCreateArguments may be found in the following gists:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment