Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions GoMoney.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
085F7539291278100094A026 /* ConnectionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 085F7538291278100094A026 /* ConnectionService.swift */; };
086B4FB5291FFF01005C61F6 /* CountryData.plist in Resources */ = {isa = PBXBuildFile; fileRef = 086B4FB4291FFF01005C61F6 /* CountryData.plist */; };
086C5D1A29150B2E00B6DE49 /* calculator.json in Resources */ = {isa = PBXBuildFile; fileRef = 086C5D1929150B2E00B6DE49 /* calculator.json */; };
0875F3092927778000D122C3 /* Double+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0875F3082927778000D122C3 /* Double+Extension.swift */; };
0875F30D292783E200D122C3 /* MoneyFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0875F30C292783E200D122C3 /* MoneyFormatter.swift */; };
0878DBA12924939D004E3FFD /* NewTagViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0878DBA02924939D004E3FFD /* NewTagViewController.swift */; };
0878DBA42924AA15004E3FFD /* IconCollectionVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0878DBA32924AA15004E3FFD /* IconCollectionVC.swift */; };
0878DBA62924AC43004E3FFD /* IconPickerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0878DBA52924AC43004E3FFD /* IconPickerCell.swift */; };
Expand Down Expand Up @@ -210,6 +212,8 @@
085F7538291278100094A026 /* ConnectionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionService.swift; sourceTree = "<group>"; };
086B4FB4291FFF01005C61F6 /* CountryData.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = CountryData.plist; sourceTree = "<group>"; };
086C5D1929150B2E00B6DE49 /* calculator.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = calculator.json; sourceTree = "<group>"; };
0875F3082927778000D122C3 /* Double+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Double+Extension.swift"; sourceTree = "<group>"; };
0875F30C292783E200D122C3 /* MoneyFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoneyFormatter.swift; sourceTree = "<group>"; };
0878DBA02924939D004E3FFD /* NewTagViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTagViewController.swift; sourceTree = "<group>"; };
0878DBA32924AA15004E3FFD /* IconCollectionVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconCollectionVC.swift; sourceTree = "<group>"; };
0878DBA52924AC43004E3FFD /* IconPickerCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconPickerCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -479,6 +483,14 @@
path = Cells;
sourceTree = "<group>";
};
0875F30B292783DB00D122C3 /* Currency */ = {
isa = PBXGroup;
children = (
0875F30C292783E200D122C3 /* MoneyFormatter.swift */,
);
path = Currency;
sourceTree = "<group>";
};
0878DB9D29248C54004E3FFD /* Tags */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -726,6 +738,7 @@
08C872EF28F6CAAB00DC859D /* UIView+Constraint.swift */,
08DB56E828F9035800170C60 /* StackView+Extension.swift */,
08DB56EA28F9053700170C60 /* UIColor+Extension.swift */,
0875F3082927778000D122C3 /* Double+Extension.swift */,
08C1F25C28FE93E900590512 /* DateFormatter+Extension.swift */,
08C1F26928FFBAD500590512 /* UIImage+Extension.swift */,
08DEE9C52900FC4C00EA9A2A /* Date+Extension.swift */,
Expand Down Expand Up @@ -775,6 +788,7 @@
08C8730B28F7B1BD00DC859D /* Common */ = {
isa = PBXGroup;
children = (
0875F30B292783DB00D122C3 /* Currency */,
08F068A929221C79005C58EC /* AsyncImage */,
089CC74A2919D9580070A108 /* FileHelper */,
08DDEB402918A0FE00327474 /* RealmConverter */,
Expand Down Expand Up @@ -1148,6 +1162,7 @@
089CC756291A0C0A0070A108 /* BiometricService.swift in Sources */,
08B48B7C290293AE00344650 /* UIBarButtonItem+Extension.swift in Sources */,
08C8731928F865CA00DC859D /* SignUpPasswordVC.swift in Sources */,
0875F3092927778000D122C3 /* Double+Extension.swift in Sources */,
08EEA00E291CC374003B35B8 /* Widget+Kind.swift in Sources */,
082BF97D28FD68480094FE94 /* Notification+Name.swift in Sources */,
083EA336290659660079605F /* TransactionTag.swift in Sources */,
Expand Down Expand Up @@ -1206,6 +1221,7 @@
08C872CA28F6681600DC859D /* UIViewController+Extension.swift in Sources */,
08C872EA28F6C51200DC859D /* UserDefaultKey.swift in Sources */,
08C872A528F655CD00DC859D /* SceneDelegate.swift in Sources */,
0875F30D292783E200D122C3 /* MoneyFormatter.swift in Sources */,
081DC8A2290274990005374F /* CategoryPickerInputView.swift in Sources */,
085F753129124DF50094A026 /* SettingsTableViewAccessoryCell.swift in Sources */,
);
Expand Down
18 changes: 18 additions & 0 deletions GoMoney/Common/Currency/MoneyFormatter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class MoneyFormatter {
static func formatShorter(amount: Double, currency: CurrencyUnit) -> String {
switch currency {
case .dong:
switch amount {
case 1 ..< 1_000_000:
return amount.formatWithCommas()
default:
let million = amount / 1_000_000
let formated = million.formatWithCommas(minFraction: 2, maxFraction: 2)
return "\(formated)tr"
}

default:
return String(amount.formatWithCommas())
}
}
}
15 changes: 15 additions & 0 deletions GoMoney/Extensions/Double+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

extension Double {
func formatWithCommas(minFraction: Int = 0, maxFraction: Int = 0) -> String {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.minimumFractionDigits = minFraction
numberFormatter.maximumFractionDigits = maxFraction
if let formattedNumber = numberFormatter.string(from: NSNumber(value: self)) {
return formattedNumber
} else {
return String(self)
}
}
}
16 changes: 13 additions & 3 deletions GoMoney/Scences/Home/View/ChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,19 @@ class ChartView: UIView {
{
let savings = incomeSum - expenseSum

monthlyIncomes.amount.text = String(incomeSum)
monthlyExpenses.amount.text = String(expenseSum)
monthlySavings.amount.text = String(savings)
guard
let currency = SettingsManager.shared.getValue(for: .currencyUnit) as? String,
let unit = CurrencyUnit(rawValue: currency)
else {
return
}

monthlyIncomes.amount.text =
"\(MoneyFormatter.formatShorter(amount: incomeSum, currency: unit)) \(currency)"
monthlyExpenses.amount.text =
"\(MoneyFormatter.formatShorter(amount: expenseSum, currency: unit)) \(currency)"
monthlySavings.amount.text =
"\(MoneyFormatter.formatShorter(amount: savings, currency: unit)) \(currency)"

if savings >= 0 {
monthlySavings.amount.textColor = K.Color.saving
Expand Down
5 changes: 4 additions & 1 deletion GoMoney/Scences/Home/View/MonthlyExpenseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import UIKit

class MonthlyExpenseView: UIView {
lazy var label = GMLabel(style: .small)
lazy var amount = GMLabel(style: .largeBold)
lazy var amount = GMLabel(style: .largeBold) {
$0.textAlignment = .right
}

lazy var stackView: UIStackView = .build { [self] in
$0.axis = .vertical
$0.spacing = 8
Expand Down
25 changes: 19 additions & 6 deletions GoMoney/Scences/Home/View/RecentExpenseCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ class RecentExpenseCell: UITableViewCell {
var expense: Expense? {
didSet {
if let expense = expense {
icon.loadIcon(src: expense.tag?.icon)
labelName.text = expense.tag?.name
labelDate.text = expense.getDate(.occuredOn)
labelPrice.text = String(expense.amount)
bindView(transaction: expense)
}
}
}

lazy var icon = GMExpenseIcon()
lazy var labelName = GMLabel(text: "Gas", style: .regularBold)
lazy var labelDate = GMLabel(text: "20/10/2022", style: .small)
lazy var labelName = GMLabel(style: .regularBold)
lazy var labelDate = GMLabel(style: .small)
lazy var labelPrice = GMLabel(style: .regularBold)

lazy var stackInfo: UIStackView = {
Expand Down Expand Up @@ -59,4 +56,20 @@ class RecentExpenseCell: UITableViewCell {
labelPrice.centerYToView(self)
labelPrice.anchor(top: topAnchor, right: rightAnchor, paddingRight: 4)
}

func bindView(transaction: Expense) {
icon.loadIcon(src: transaction.tag?.icon)
labelName.text = transaction.tag?.name
labelDate.text = transaction.getDate(.occuredOn)
let currency = SettingsManager.shared.getValue(for: .currencyUnit)
labelPrice.text = "\(transaction.amount.formatWithCommas()) \(currency)"
switch transaction.type {
case ExpenseType.income.rawValue:
labelPrice.textColor = K.Color.saving
case ExpenseType.expense.rawValue:
labelPrice.textColor = K.Color.debt
default:
break
}
}
}