Last active
July 19, 2018 03:56
-
-
Save hwjeremy/516965767cca95aa3e4e82bc38b90d34 to your computer and use it in GitHub Desktop.
Create a Transaction in Amatino Swift - A double-entry accounting library / framework 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 | |
import Foundation | |
import Amatino | |
try Transaction.create( | |
session: session, | |
entity: entity, | |
transactionTime: Date(), | |
description: "Borrowing some cash to build a new suit", | |
globalUnit: usd, | |
entries: [ | |
Entry(side: .debit, account: suitCash, amount: Decimal(12)), | |
Entry(side: .credit, account: creditCard, amount: Decimal(12)) | |
], | |
callback: { (error: Error?, transaction: Transaction?) in | |
guard error == nil else { | |
// Handle error | |
return | |
} | |
guard let borrowedCashTxId: Int64 = transaction?.id else { | |
// Should never happen, but unwrapping nil ruins everyone's | |
// day so let's be careful! | |
} | |
// Do clever things with newly created Transaction | |
print("Created Transaction with ID: \(borrowedCashTxId))" | |
return | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The parameters passed to
Transaction.create()
may be found in the following gists:session
- Create SessionstarkIndustries
- Retrieve EntitysuitCash
- Create AccountcreditCard
- Equivalent tosuitCash
but using a.liability
typeusd
- Retrieve a GlobalUnit