Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds new categories for income #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions Expenso.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -48,6 +48,7 @@
73E688DA25FF32790000462A /* ChartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73E688D925FF32790000462A /* ChartView.swift */; };
753CBDD325F36864005762B8 /* BiometricAuthUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 753CBDD225F36864005762B8 /* BiometricAuthUtility.swift */; };
75C6B48025F37FD20079BCFC /* AuthenticationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75C6B47F25F37FD20079BCFC /* AuthenticationViewModel.swift */; };
C081D8C12ACA8165007EC1AE /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C081D8C02ACA8165007EC1AE /* String+Extension.swift */; };
FF29C9FFAF86E0452686C5D0 /* Pods_Expenso.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1B0E373FB89DD0864398FEE7 /* Pods_Expenso.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -98,6 +99,7 @@
753CBDD225F36864005762B8 /* BiometricAuthUtility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BiometricAuthUtility.swift; sourceTree = "<group>"; };
75C6B47F25F37FD20079BCFC /* AuthenticationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationViewModel.swift; sourceTree = "<group>"; };
B07E4D1AF457AB52E048A8B5 /* Pods-Expenso.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Expenso.release.xcconfig"; path = "Target Support Files/Pods-Expenso/Pods-Expenso.release.xcconfig"; sourceTree = "<group>"; };
C081D8C02ACA8165007EC1AE /* String+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -225,6 +227,7 @@
736C721A25CFE8E200720DEA /* LottieView.swift */,
73998C5425DA5578007D735B /* AttachmentHandler.swift */,
73E688D925FF32790000462A /* ChartView.swift */,
C081D8C02ACA8165007EC1AE /* String+Extension.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -475,6 +478,7 @@
73E688DA25FF32790000462A /* ChartView.swift in Sources */,
736C721B25CFE8E200720DEA /* LottieView.swift in Sources */,
738B1C7725C675200067407B /* AddExpenseView.swift in Sources */,
C081D8C12ACA8165007EC1AE /* String+Extension.swift in Sources */,
738B1C8025C6763E0067407B /* ExpenseDetailedView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -606,7 +610,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"Expenso/Preview Content\"";
DEVELOPMENT_TEAM = 7S7EBZGDA6;
DEVELOPMENT_TEAM = CHSQWDTYR9;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Expenso/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
Expand All @@ -615,7 +619,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = com.expenso.Expenso;
PRODUCT_BUNDLE_IDENTIFIER = com.expenso.Expens;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -630,7 +634,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"Expenso/Preview Content\"";
DEVELOPMENT_TEAM = 7S7EBZGDA6;
DEVELOPMENT_TEAM = CHSQWDTYR9;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Expenso/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
Expand All @@ -639,7 +643,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = com.expenso.Expenso;
PRODUCT_BUNDLE_IDENTIFIER = com.expenso.Expens;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
140 changes: 102 additions & 38 deletions Expenso/Configs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,53 +27,117 @@ let UD_EXPENSE_CURRENCY = "expenseCurrency"
let CURRENCY_LIST = ["₹", "$", "€", "¥", "£", "¢", "₭"]

// Transaction types
let TRANS_TYPE_INCOME = "income"
let TRANS_TYPE_EXPENSE = "expense"
//let TRANS_TYPE_INCOME = "income"
//let TRANS_TYPE_EXPENSE = "expense"

// Transaction tags
let TRANS_TAG_TRANSPORT = "transport"
let TRANS_TAG_FOOD = "food"
let TRANS_TAG_HOUSING = "housing"
let TRANS_TAG_INSURANCE = "insurance"
let TRANS_TAG_MEDICAL = "medical"
let TRANS_TAG_SAVINGS = "savings"
let TRANS_TAG_PERSONAL = "personal"
let TRANS_TAG_ENTERTAINMENT = "entertainment"
let TRANS_TAG_OTHERS = "others"
let TRANS_TAG_UTILITIES = "utilities"

func getTransTagIcon(transTag: String) -> String {
switch transTag {
case TRANS_TAG_TRANSPORT: return "trans_type_transport"
case TRANS_TAG_FOOD: return "trans_type_food"
case TRANS_TAG_HOUSING: return "trans_type_housing"
case TRANS_TAG_INSURANCE: return "trans_type_insurance"
case TRANS_TAG_MEDICAL: return "trans_type_medical"
case TRANS_TAG_SAVINGS: return "trans_type_savings"
case TRANS_TAG_PERSONAL: return "trans_type_personal"
case TRANS_TAG_ENTERTAINMENT: return "trans_type_entertainment"
case TRANS_TAG_OTHERS: return "trans_type_others"
case TRANS_TAG_UTILITIES: return "trans_type_utilities"
default: return "trans_type_others"
enum TransactionType: String {
case TRANS_TYPE_INCOME = "income"
case TRANS_TYPE_EXPENSE = "expense"
}

// Transaction tags enum
enum TransactionTags {
case TRANS_TAG_TRANSPORT
case TRANS_TAG_FOOD
case TRANS_TAG_HOUSING
case TRANS_TAG_INSURANCE
case TRANS_TAG_MEDICAL
case TRANS_TAG_SAVINGS
case TRANS_TAG_PERSONAL
case TRANS_TAG_ENTERTAINMENT
case TRANS_TAG_OTHERS
case TRANS_TAG_UTILITIES
case TRANS_TAG_SALARY
case TRANS_TAG_CASHBACK
case TRANS_TAG_INVESTMENTRETURS

var value: String {
switch self {
case .TRANS_TAG_TRANSPORT:
return "transport"
case .TRANS_TAG_FOOD:
return "food"
case .TRANS_TAG_HOUSING:
return "housing"
case .TRANS_TAG_INSURANCE:
return "insurance"
case .TRANS_TAG_MEDICAL:
return "medical"
case .TRANS_TAG_SAVINGS:
return "savings"
case .TRANS_TAG_PERSONAL:
return "personal"
case .TRANS_TAG_ENTERTAINMENT:
return "entertainment"
case .TRANS_TAG_OTHERS:
return "others"
case .TRANS_TAG_UTILITIES:
return "utilities"
case .TRANS_TAG_SALARY:
return "salary"
case .TRANS_TAG_CASHBACK:
return "cashback"
case .TRANS_TAG_INVESTMENTRETURS:
return "investment Returns"
}
}


static func getTransactionTitle(_ type: String) -> String {
let title = switch type {
case TRANS_TAG_TRANSPORT.value:
"transport"
case TRANS_TAG_FOOD.value:
"food"
case TRANS_TAG_HOUSING.value:
"housing"
case TRANS_TAG_INSURANCE.value:
"insurance"
case TRANS_TAG_MEDICAL.value:
"medical"
case TRANS_TAG_SAVINGS.value:
"savings"
case TRANS_TAG_PERSONAL.value:
"personal"
case TRANS_TAG_ENTERTAINMENT.value:
"entertainment"
case TRANS_TAG_OTHERS.value:
"others"
case TRANS_TAG_UTILITIES.value:
"utilities"
case TRANS_TAG_SALARY.value:
"salary"
case TRANS_TAG_CASHBACK.value:
"cashback"
case TRANS_TAG_INVESTMENTRETURS.value:
"investment Returns"
default:
"unknown"
}

return title.capitalized
}
}

func getTransTagTitle(transTag: String) -> String {
func getTransTagIcon(transTag: String) -> String {
switch transTag {
case TRANS_TAG_TRANSPORT: return "Transport"
case TRANS_TAG_FOOD: return "Food"
case TRANS_TAG_HOUSING: return "Housing"
case TRANS_TAG_INSURANCE: return "Insurance"
case TRANS_TAG_MEDICAL: return "Medical"
case TRANS_TAG_SAVINGS: return "Savings"
case TRANS_TAG_PERSONAL: return "Personal"
case TRANS_TAG_ENTERTAINMENT: return "Entertainment"
case TRANS_TAG_OTHERS: return "Others"
case TRANS_TAG_UTILITIES: return "Utilities"
default: return "Unknown"
case TransactionTags.TRANS_TAG_TRANSPORT.value: return "trans_type_transport"
case TransactionTags.TRANS_TAG_FOOD.value: return "trans_type_food"
case TransactionTags.TRANS_TAG_HOUSING.value: return "trans_type_housing"
case TransactionTags.TRANS_TAG_INSURANCE.value: return "trans_type_insurance"
case TransactionTags.TRANS_TAG_MEDICAL.value: return "trans_type_medical"
case TransactionTags.TRANS_TAG_SAVINGS.value: return "trans_type_savings"
case TransactionTags.TRANS_TAG_PERSONAL.value: return "trans_type_personal"
case TransactionTags.TRANS_TAG_ENTERTAINMENT.value: return "trans_type_entertainment"
case TransactionTags.TRANS_TAG_OTHERS.value: return "trans_type_others"
case TransactionTags.TRANS_TAG_UTILITIES.value: return "trans_type_utilities"
default: return "trans_type_others"
}
}



func getDateFormatter(date: Date?, format: String = "yyyy-MM-dd") -> String {
guard let date = date else { return "" }
let dateFormatter = DateFormatter()
Expand Down
25 changes: 25 additions & 0 deletions Expenso/Library/Helpers/DropdownButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,28 @@ struct DropdownButton: View {
}.animation(.spring())
}
}


struct DropdownOptionManager {
func returnDropDowns(_ typeOfTransaction: TransactionType) -> [DropdownOption] {
guard typeOfTransaction == .TRANS_TYPE_INCOME else {
return [
DropdownOption(key: TransactionTags.TRANS_TAG_TRANSPORT.value, val: TransactionTags.TRANS_TAG_TRANSPORT.value.capitalized),
DropdownOption(key: TransactionTags.TRANS_TAG_FOOD.value, val: TransactionTags.TRANS_TAG_FOOD.value.capitalized),
DropdownOption(key: TransactionTags.TRANS_TAG_HOUSING.value, val: TransactionTags.TRANS_TAG_HOUSING.value.capitalized),
DropdownOption(key: TransactionTags.TRANS_TAG_INSURANCE.value, val: TransactionTags.TRANS_TAG_INSURANCE.value.capitalized),
DropdownOption(key: TransactionTags.TRANS_TAG_MEDICAL.value, val: TransactionTags.TRANS_TAG_MEDICAL.value.capitalized),
DropdownOption(key: TransactionTags.TRANS_TAG_PERSONAL.value, val: TransactionTags.TRANS_TAG_PERSONAL.value.capitalized),
DropdownOption(key: TransactionTags.TRANS_TAG_ENTERTAINMENT.value, val: TransactionTags.TRANS_TAG_ENTERTAINMENT.value.capitalized),
DropdownOption(key: TransactionTags.TRANS_TAG_OTHERS.value, val: TransactionTags.TRANS_TAG_OTHERS.value.capitalized),
DropdownOption(key: TransactionTags.TRANS_TAG_UTILITIES.value, val: TransactionTags.TRANS_TAG_UTILITIES.value.capitalized)
]
}

return [
DropdownOption(key: TransactionTags.TRANS_TAG_SALARY.value, val: TransactionTags.TRANS_TAG_SALARY.value.capitalized),
DropdownOption(key: TransactionTags.TRANS_TAG_CASHBACK.value, val: TransactionTags.TRANS_TAG_CASHBACK.value.capitalized),
DropdownOption(key: TransactionTags.TRANS_TAG_INVESTMENTRETURS.value, val:TransactionTags.TRANS_TAG_INVESTMENTRETURS.value.capitalized)
]
}
}
19 changes: 19 additions & 0 deletions Expenso/Library/Helpers/String+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// String+Extension.swift
// Expenso
//
// Created by ahdivio mendes on 02/10/23.
//

import Foundation

extension String {
var capitalized: String {

let firstLetter = self.prefix(1).capitalized

let remainingLetters = self.dropFirst().lowercased()

return firstLetter + remainingLetters
}
}
25 changes: 9 additions & 16 deletions Expenso/Screens/AddExpense/AddExpenseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,18 @@ struct AddExpenseView: View {
@Environment(\.managedObjectContext) var managedObjectContext
@State private var confirmDelete = false
@State var showAttachSheet = false

@StateObject var viewModel: AddExpenseViewModel

let typeOptions = [
DropdownOption(key: TRANS_TYPE_INCOME, val: "Income"),
DropdownOption(key: TRANS_TYPE_EXPENSE, val: "Expense")
]

let tagOptions = [
DropdownOption(key: TRANS_TAG_TRANSPORT, val: "Transport"),
DropdownOption(key: TRANS_TAG_FOOD, val: "Food"),
DropdownOption(key: TRANS_TAG_HOUSING, val: "Housing"),
DropdownOption(key: TRANS_TAG_INSURANCE, val: "Insurance"),
DropdownOption(key: TRANS_TAG_MEDICAL, val: "Medical"),
DropdownOption(key: TRANS_TAG_SAVINGS, val: "Savings"),
DropdownOption(key: TRANS_TAG_PERSONAL, val: "Personal"),
DropdownOption(key: TRANS_TAG_ENTERTAINMENT, val: "Entertainment"),
DropdownOption(key: TRANS_TAG_OTHERS, val: "Others"),
DropdownOption(key: TRANS_TAG_UTILITIES, val: "Utilities")
DropdownOption(key: TransactionType.TRANS_TYPE_INCOME.rawValue, val: "Income"),
DropdownOption(key: TransactionType.TRANS_TYPE_EXPENSE.rawValue, val: "Expense")
]

@State var tagOptions = DropdownOptionManager().returnDropDowns(.TRANS_TYPE_INCOME)




var body: some View {
NavigationView {
ZStack {
Expand Down Expand Up @@ -81,6 +72,7 @@ struct AddExpenseView: View {
backgroundColor: Color.secondary_color, cornerRadius: 4, buttonHeight: 50) { key in
let selectedObj = typeOptions.filter({ $0.key == key }).first
if let object = selectedObj {
tagOptions = DropdownOptionManager().returnDropDowns((object.key == TransactionType.TRANS_TYPE_INCOME.rawValue ) ? .TRANS_TYPE_INCOME : .TRANS_TYPE_EXPENSE)
viewModel.typeTitle = object.val
viewModel.selectedType = key
}
Expand All @@ -92,6 +84,7 @@ struct AddExpenseView: View {
backgroundColor: Color.secondary_color, cornerRadius: 4, buttonHeight: 50) { key in
let selectedObj = tagOptions.filter({ $0.key == key }).first
if let object = selectedObj {
print(object.key)
viewModel.tagTitle = object.val
viewModel.selectedTag = key
}
Expand Down
19 changes: 10 additions & 9 deletions Expenso/Screens/AddExpense/AddExpenseViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class AddExpenseViewModel: ObservableObject {
@Published var occuredOn = Date()
@Published var note = ""
@Published var typeTitle = "Income"
@Published var tagTitle = getTransTagTitle(transTag: TRANS_TAG_TRANSPORT)
@Published var tagTitle = TransactionTags.TRANS_TAG_SALARY.value.capitalized
@Published var showTypeDrop = false
@Published var showTagDrop = false

@Published var selectedType = TRANS_TYPE_INCOME
@Published var selectedTag = TRANS_TAG_TRANSPORT
@Published var selectedType = TransactionType.TRANS_TYPE_INCOME.rawValue
@Published var selectedTag = TransactionTags.TRANS_TAG_SALARY.value

@Published var imageUpdated = false // When transaction edit, check if attachment is updated?
@Published var imageAttached: UIImage? = nil
Expand All @@ -37,16 +37,16 @@ class AddExpenseViewModel: ObservableObject {
self.title = expenseObj?.title ?? ""
if let expenseObj = expenseObj {
self.amount = String(expenseObj.amount)
self.typeTitle = expenseObj.type == TRANS_TYPE_INCOME ? "Income" : "Expense"
self.typeTitle = expenseObj.type == TransactionType.TRANS_TYPE_INCOME.rawValue ? "Income" : "Expense"
} else {
self.amount = ""
self.typeTitle = "Income"
}
self.occuredOn = expenseObj?.occuredOn ?? Date()
self.note = expenseObj?.note ?? ""
self.tagTitle = getTransTagTitle(transTag: expenseObj?.tag ?? TRANS_TAG_TRANSPORT)
self.selectedType = expenseObj?.type ?? TRANS_TYPE_INCOME
self.selectedTag = expenseObj?.tag ?? TRANS_TAG_TRANSPORT
self.tagTitle = TransactionTags.TRANS_TAG_SALARY.value.capitalized
self.selectedType = expenseObj?.type ?? TransactionType.TRANS_TYPE_INCOME.rawValue
self.selectedTag = expenseObj?.tag ?? TransactionTags.TRANS_TAG_SALARY.value.capitalized
if let data = expenseObj?.imageAttached {
self.imageAttached = UIImage(data: data)
}
Expand All @@ -58,8 +58,8 @@ class AddExpenseViewModel: ObservableObject {
}

func getButtText() -> String {
if selectedType == TRANS_TYPE_INCOME { return "\(expenseObj == nil ? "ADD" : "EDIT") INCOME" }
else if selectedType == TRANS_TYPE_EXPENSE { return "\(expenseObj == nil ? "ADD" : "EDIT") EXPENSE" }
if selectedType == TransactionType.TRANS_TYPE_INCOME.rawValue { return "\(expenseObj == nil ? "ADD" : "EDIT") INCOME" }
else if selectedType == TransactionType.TRANS_TYPE_EXPENSE.rawValue { return "\(expenseObj == nil ? "ADD" : "EDIT") EXPENSE" }
else { return "\(expenseObj == nil ? "ADD" : "EDIT") TRANSACTION" }
}

Expand Down Expand Up @@ -122,6 +122,7 @@ class AddExpenseViewModel: ObservableObject {
expense.updatedAt = Date()
expense.type = selectedType
expense.title = titleStr
print("selected tag", selectedTag)
expense.tag = selectedTag
expense.occuredOn = occuredOn
expense.note = note
Expand Down
Loading