Commit 631d2006 authored by tybrandt's avatar tybrandt
Browse files

Displays individual transaction data on the individual transaction view

parent 66ff4e61
......@@ -12,6 +12,7 @@
DE053EA5260478B70015C753 /* Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE053EA4260478B70015C753 /* Transaction.swift */; };
DE512D0225FB039A00EA7816 /* Category.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE512D0125FB039A00EA7816 /* Category.swift */; };
DE731979269A039F00B55301 /* CategoryTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE731978269A039F00B55301 /* CategoryTableViewController.swift */; };
DE845AB326CD9BEB008B39F8 /* TransactionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE845AB226CD9BEB008B39F8 /* TransactionViewController.swift */; };
DEC2565A25E887410003EFC9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2565925E887410003EFC9 /* AppDelegate.swift */; };
DEC2565C25E887410003EFC9 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2565B25E887410003EFC9 /* SceneDelegate.swift */; };
DEC2565E25E887410003EFC9 /* CategoryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2565D25E887410003EFC9 /* CategoryViewController.swift */; };
......@@ -48,6 +49,7 @@
DE053EA4260478B70015C753 /* Transaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Transaction.swift; sourceTree = "<group>"; };
DE512D0125FB039A00EA7816 /* Category.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Category.swift; sourceTree = "<group>"; };
DE731978269A039F00B55301 /* CategoryTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryTableViewController.swift; sourceTree = "<group>"; };
DE845AB226CD9BEB008B39F8 /* TransactionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionViewController.swift; sourceTree = "<group>"; };
DEC2565625E887410003EFC9 /* Budget Tracker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Budget Tracker.app"; sourceTree = BUILT_PRODUCTS_DIR; };
DEC2565925E887410003EFC9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
DEC2565B25E887410003EFC9 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
......@@ -120,12 +122,13 @@
DEC2565D25E887410003EFC9 /* CategoryViewController.swift */,
DEEC3BC625FB1EFA00011733 /* CategoryTableViewCell.swift */,
DE512D0125FB039A00EA7816 /* Category.swift */,
DE731978269A039F00B55301 /* CategoryTableViewController.swift */,
DE053E97260477660015C753 /* TransactionTableViewController.swift */,
DE053E9F2604789B0015C753 /* TransactionTableViewCell.swift */,
DE053EA4260478B70015C753 /* Transaction.swift */,
DE845AB226CD9BEB008B39F8 /* TransactionViewController.swift */,
DEC2569A25E89A400003EFC9 /* AddTransactionViewController.swift */,
DEFCC41626169EAA00F90B8B /* DeletionViewController.swift */,
DE731978269A039F00B55301 /* CategoryTableViewController.swift */,
DEC2565F25E887410003EFC9 /* Main.storyboard */,
DEC2566225E887440003EFC9 /* Assets.xcassets */,
DEC2566425E887440003EFC9 /* LaunchScreen.storyboard */,
......@@ -289,6 +292,7 @@
DE731979269A039F00B55301 /* CategoryTableViewController.swift in Sources */,
DEC2565A25E887410003EFC9 /* AppDelegate.swift in Sources */,
DEC2565C25E887410003EFC9 /* SceneDelegate.swift in Sources */,
DE845AB326CD9BEB008B39F8 /* TransactionViewController.swift in Sources */,
DEFCC41726169EAA00F90B8B /* DeletionViewController.swift in Sources */,
DEC2569B25E89A400003EFC9 /* AddTransactionViewController.swift in Sources */,
DEEC3BC725FB1EFA00011733 /* CategoryTableViewCell.swift in Sources */,
......
......@@ -2,6 +2,6 @@
<Workspace
version = "1.0">
<FileRef
location = "self:">
location = "self:/Users/tybrandt/College/Michigan Hackers/Budget Tracker/Budget Tracker.xcodeproj">
</FileRef>
</Workspace>
......@@ -70,8 +70,12 @@ class AddTransactionViewController: UIViewController, UITextFieldDelegate, UINav
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM dd, yyyy h:mm a z"
let date = dateFormatter.string(from: dateObject)
var desc = descriptionTextField.text ?? "No Description"
if desc.isEmpty {
desc = "No Description"
}
let transaction = Transaction(name: nameTextField.text ?? "", category: categoryTextField.text ?? "",
price: price ?? 0.0, date: date)
price: price ?? 0.0, date: date, desc: desc)
transactions.insert(transaction!, at: 0)
for category in categories {
if categoryTextField.text == category.name {
......
......@@ -211,7 +211,7 @@
<outlet property="date" destination="TY2-fe-Hf6" id="luq-n8-Pjj"/>
<outlet property="name" destination="ZQh-dN-pAc" id="BAX-R7-zkd"/>
<outlet property="price" destination="mCQ-Pi-90k" id="M0O-bG-CnA"/>
<segue destination="0rC-He-XPW" kind="show" id="Nud-lF-Agv"/>
<segue destination="0rC-He-XPW" kind="show" identifier="viewTransaction" id="Nud-lF-Agv"/>
</connections>
</tableViewCell>
</prototypes>
......@@ -229,32 +229,32 @@
<!--No Transaction-->
<scene sceneID="o8p-sp-eDw">
<objects>
<viewController id="0rC-He-XPW" sceneMemberID="viewController">
<viewController id="0rC-He-XPW" customClass="TransactionViewController" customModule="Budget_Tracker" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="blI-Tt-mvl">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Cost:" textAlignment="natural" lineBreakMode="wordWrap" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XPv-ab-wyq">
<rect key="frame" x="20" y="108" width="374" height="29"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Cost:" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XPv-ab-wyq">
<rect key="frame" x="20" y="108" width="374" height="24"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Date:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="svq-2P-GG9">
<rect key="frame" x="20" y="157" width="374" height="29"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Date:" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="svq-2P-GG9">
<rect key="frame" x="20" y="152" width="374" height="24"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Category:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dly-A3-pYD">
<rect key="frame" x="20" y="206" width="374" height="29"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Category:" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dly-A3-pYD">
<rect key="frame" x="20" y="196" width="374" height="24"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Description: No Description" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="sRW-O0-Sxs">
<rect key="frame" x="20" y="255" width="374" height="29"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Description: No Description" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="20" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="sRW-O0-Sxs">
<rect key="frame" x="20" y="240" width="374" height="24"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
......@@ -279,8 +279,17 @@
<navigationItem key="navigationItem" title="No Transaction" id="wl2-h4-Shm">
<barButtonItem key="rightBarButtonItem" title="Remove" id="74P-Oh-vm0">
<color key="tintColor" systemColor="systemRedColor"/>
<connections>
<segue destination="2i0-KG-j1T" kind="presentation" identifier="deleteTransaction" id="oRF-0U-JCh"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="categoryLabel" destination="dly-A3-pYD" id="J7R-7s-6g6"/>
<outlet property="costLabel" destination="XPv-ab-wyq" id="wDQ-7h-V00"/>
<outlet property="dateLabel" destination="svq-2P-GG9" id="A6R-pl-Uwz"/>
<outlet property="descriptionLabel" destination="sRW-O0-Sxs" id="aDJ-X1-1o3"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="nP0-qg-j4P" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
......@@ -362,7 +371,7 @@
<outlet property="date" destination="2oy-Hj-Lk9" id="hLE-Ba-f0J"/>
<outlet property="name" destination="P1H-hf-PPE" id="bBF-Np-UlH"/>
<outlet property="price" destination="kLh-rJ-fhf" id="qWn-dB-gWx"/>
<segue destination="0rC-He-XPW" kind="show" id="mn4-ps-7cL"/>
<segue destination="0rC-He-XPW" kind="show" identifier="viewCategoryTransaction" id="mn4-ps-7cL"/>
</connections>
</tableViewCell>
</prototypes>
......@@ -593,8 +602,8 @@
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="OPk-vX-Zez"/>
<segue reference="mn4-ps-7cL"/>
<segue reference="oRF-0U-JCh"/>
<segue reference="Nud-lF-Agv"/>
</inferredMetricsTieBreakers>
<resources>
<systemColor name="systemBackgroundColor">
......
......@@ -49,7 +49,20 @@ class CategoryTableViewController: UIViewController, UITableViewDelegate, UITabl
guard let deleteView = segue.destination as? DeletionViewController else {return}
deleteView.warningText = "WARNING: This will delete the category and all transactions within it. Proceed?"
deleteView.categorical = true
deleteView.categoryTitle = title!
deleteView.itemTitle = title!
case "viewCategoryTransaction":
guard let transactionView = segue.destination as? TransactionViewController else {
fatalError("Unexpected destination: \(segue.destination)")
}
guard let selectedTransactionCell = sender as? TransactionTableViewCell else {
fatalError("Unexpected sender: \(String(describing: sender))")
}
guard let indexPath = categoryTransactionsTable.indexPath(for: selectedTransactionCell) else {
fatalError("The selected cell is not being displayed by the table")
}
let selectedTransaction = transactions[indexPath.row]
transactionView.title = selectedTransaction.name
transactionView.transaction = selectedTransaction
default:
return
}
......
......@@ -87,7 +87,7 @@ class CategoryViewController: UIViewController, UITableViewDelegate, UITableView
} else if sourceView.confirmed {
var i = 0
for transaction in transactions {
if transaction.category == sourceView.categoryTitle {
if transaction.category == sourceView.itemTitle {
transactions.remove(at: i)
i -= 1
}
......@@ -95,7 +95,7 @@ class CategoryViewController: UIViewController, UITableViewDelegate, UITableView
}
i = 0
for category in categories {
if category.name == sourceView.categoryTitle {
if category.name == sourceView.itemTitle {
categories.remove(at: i)
break
}
......
......@@ -10,7 +10,8 @@ import UIKit
class DeletionViewController: UIViewController {
var confirmed = false
var categorical = false
var categoryTitle = "No Category"
var transactional = false
var itemTitle = "No Category"
var warningText = "WARNING: This will delete all transactions. Proceed?"
@IBOutlet weak var confirmButton: UIButton!
@IBOutlet weak var warningLabel: UILabel!
......
......@@ -12,6 +12,7 @@ class Transaction: NSObject, NSCoding {
var category: String
var price: Double
var date: String
var desc: String
static let DocumentsDirectory = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!
static let ArchiveURL = DocumentsDirectory.appendingPathComponent("transactions")
......@@ -21,13 +22,15 @@ class Transaction: NSObject, NSCoding {
static let category = "category"
static let price = "price"
static let date = "date"
static let desc = "desc"
}
init?(name: String, category: String, price: Double, date: String) {
init?(name: String, category: String, price: Double, date: String, desc: String) {
self.name = name
self.category = category
self.price = price
self.date = date
self.desc = desc
}
init?(name: String) {
......@@ -35,6 +38,7 @@ class Transaction: NSObject, NSCoding {
self.category = ""
self.price = -1.0
self.date = ""
self.desc = "No Description"
}
func encode(with coder: NSCoder) {
......@@ -42,6 +46,7 @@ class Transaction: NSObject, NSCoding {
coder.encode(category, forKey: PropertyKey.category)
coder.encode(price, forKey: PropertyKey.price)
coder.encode(date, forKey: PropertyKey.date)
coder.encode(desc, forKey: PropertyKey.desc)
}
required convenience init?(coder: NSCoder) {
......@@ -49,7 +54,8 @@ class Transaction: NSObject, NSCoding {
guard let category = coder.decodeObject(forKey: PropertyKey.category) as? String else {return nil}
let price = coder.decodeDouble(forKey: PropertyKey.price)
guard let date = coder.decodeObject(forKey: PropertyKey.date) as? String else {return nil}
self.init(name: name, category: category, price: price, date: date)
guard let desc = coder.decodeObject(forKey: PropertyKey.desc) as? String else {return nil}
self.init(name: name, category: category, price: price, date: date, desc: desc)
}
}
......@@ -46,4 +46,25 @@ class TransactionTableViewController: UITableViewController {
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
switch (segue.identifier ?? "") {
case "viewTransaction":
guard let transactionView = segue.destination as? TransactionViewController else {
fatalError("Unexpected destination: \(segue.destination)")
}
guard let selectedTransactionCell = sender as? TransactionTableViewCell else {
fatalError("Unexpected sender: \(String(describing: sender))")
}
guard let indexPath = tableView.indexPath(for: selectedTransactionCell) else {
fatalError("The selected cell is not being displayed by the table")
}
let selectedTransaction = transactions[indexPath.row]
transactionView.title = selectedTransaction.name
transactionView.transaction = selectedTransaction
default:
return
}
}
}
//
// TransactionViewController.swift
// Budget Tracker
//
// Created by Tyler Brandt on 8/18/21.
//
import UIKit
class TransactionViewController: UIViewController {
@IBOutlet weak var costLabel: UILabel!
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var categoryLabel: UILabel!
@IBOutlet weak var descriptionLabel: UILabel!
var transaction = Transaction(name: "")
override func viewDidLoad() {
super.viewDidLoad()
costLabel.text = String(format: "Cost:\t\t\t$%.2f", transaction!.price)
dateLabel.text = "Date:\t\t\t" + transaction!.date
categoryLabel.text = "Category:\t" + transaction!.category
descriptionLabel.text = "Description:\t" + transaction!.desc
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
switch(segue.identifier ?? "") {
case "deleteTransaction":
guard let deleteView = segue.destination as? DeletionViewController else {return}
deleteView.warningText = "WARNING: This will delete the transaction. Proceed?"
deleteView.transactional = true
deleteView.itemTitle = transaction!.name
default:
return
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment