Skip to content

Instantly share code, notes, and snippets.

@hwjeremy
Created July 19, 2018 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hwjeremy/f22359fb8f6eb0633de0b7c3f0635b07 to your computer and use it in GitHub Desktop.
Save hwjeremy/f22359fb8f6eb0633de0b7c3f0635b07 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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