Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hwjeremy
Last active July 19, 2018 03:56
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/516965767cca95aa3e4e82bc38b90d34 to your computer and use it in GitHub Desktop.
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
// 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
})
@hwjeremy
Copy link
Author

hwjeremy commented Jul 17, 2018

The parameters passed to Transaction.create() 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