Created
July 19, 2018 03:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The parameters passed to
Transaction.createMany()
and the constituentTransactionCreateArguments
may be found in the following gists:session
- Create SessionstarkIndustries
- Retrieve Entityusd
- Retrieve a GlobalUnitreceivables
,revenueAccount
,bankLoan
, andcashAccount
are examples of Accounts created using the technique exemplified in Create Account.