; ; AutoHotkey Version: 1.x ; Language: English ; Platform: Win9x/NT ; Author: MJ2P ; ; Script Function: Ledger will help you keep track of your finances ; It can calculate current and available balance based on the amout of cash and any overdraft facilities you have ; It will also keep track of debts and bills so that you will always know how much money you have ; ; #NoEnv SendMode Input FileCreateDir, C:\Program Files\Ledger SetWorkingDir C:\Program Files\Ledger ;;;;;;;;;;;;;;;;;;;;;;;;; Function to add a month to TimeStamp AddMonth(Input_Var) { StringMid, Month, Input_Var, 5, 2 Loop { Input_Var += 1, D StringMid, Month_Check, Input_Var, 5, 2 If (Month_Check != Month) { Break } } FormatTime, Input_Var, %Input_Var%, yyyyMM Return Input_Var } ;;;;;;;;;;;;;;;;;;;;;;;;; First Run IfNotExist, C:\Program Files\Ledger\Transaction Data { Gui, 6:Font, s12, Verdana Gui, 6:Add, Text, w500 Section Center, Enter the date you wish to start from Gui, 6:Add, DateTime, w200 xs+150 vStart_Date_Raw 1, dd MMMM yyyy Gui, 6:Add, Text, w500 xs y+20 Section Center, Enter the balance of your bank account on the date above Gui, 6:Add, Edit, w200 xs+150 vStart_Balance, Gui, 6:Add, Text, w500 xs y+20 Section Center, Enter the amount of your overdraft facility Gui, 6:Add, Edit, w200 xs+150 vOverDraft, Gui, 6:Add, Text, w500 xs y+20 Section Center, Enter the amount of Cash you have Gui, 6:Add, Edit, w200 xs+150 vCash, Gui, 6:Add, Button, xs+100 w300, Done Gui, 6:Show, AutoFit, Ledger - Setup Return 6ButtonDone: Gui, 6:Submit, NoHide If Start_Balance = { MsgBox, 16, Ledger - Setup, Please enter a balance for your bank account Reload Sleep, 2000 } If OverDraft = { OverDraft = 0 } If Cash = { Cash = 0 } FileCreateDir, C:\Program Files\Ledger\Transaction Data FormatTime, Start_Date, %Start_Date_Raw%, yyyyMM FormatTime, Start_Day, %Start_Date_Raw%, dd IniWrite, %Start_Date%, Ledger.ini, Start_Date, Date IniWrite, %Start_Day%, Ledger.ini, Start_Date, Day FormatTime, Check_Now, %A_Now%, yyyyMM Loop { If (Start_Date > Check_Now) { Break } IniWrite, 0, Ledger.ini, Running_Balance, %Start_Date% Start_Date := AddMonth(Start_Date) } IniWrite, 0, Ledger.ini, Total_Running, Value IniWrite, %Start_Balance%, Ledger.ini, Start_Balance, Value IniWrite, %OverDraft%, Ledger.ini, OverDraft, Value IniWrite, %Cash%, Ledger.ini, Cash, Value Reload Sleep, 2000 } ;;;;;;;;;;;;;;;;;;;;;;;;; Get the Types for Spending and Income as well as the Cash and OverDraft values IniRead, Cash_Amount, Ledger.ini, Cash, Value IniRead, OverDraft, Ledger.ini, OverDraft, Value IniRead, Spending_Types, Ledger.ini, Types, Spending, %A_Space% IniRead, Income_Types, Ledger.ini, Types, Income, %A_Space% IniRead, Debtors, Ledger.ini, Types, Debtors, %A_Space% Spending_Types = %Spending_Types%%Debtors% Sort, Spending_Types, D| Sort, Income_Types, D| ;;;;;;;;;;;;;;;;;;;;;;; Create the Gui IniRead, Start_Date, Ledger.ini, Start_Date, Date IniRead, Start_Day, Ledger.ini, Start_Date, Day Gui, +Theme Gui, Font, s12, Verdana Gui, Add, Text, y+20 w220 Section Right, Statement for: Gui, Add, DateTime, ys w180 vStatement_Date gDateTime 1 Range%Start_Date%%Start_Day%, MMMM yyyy Gui, Add, ListView, xs Grid R30 w530 +Report Section gEdit_Transaction, Date|Paid Out|Paid In|Type|Balance Gui, Add, Tab2, ys w530 h200 +Theme -Background Buttons, Spending|Income|Debts|Bills|Cash|Overdraft Gui, Tab, Cash Gui, Add, Text, y+50 w200 Section Right, Amount of Cash Gui, Add, Edit, ys w200 Section vCash_Amount, %Cash_Amount% Gui, Add, Button, xs w200, Enter Gui, Tab, Debts Gui, Add, ListView, Section y+50 Grid R10 w480 +Report gEdit_Debt, Amount|Debtor Gui, Add, Button, xs w480, Add new debt Gui, Tab, Bills Gui, Add, ListView, Section y+50 Grid R10 w480 +Report gEdit_Bill, Due Date|Amount|Payee Gui, Add, Button, xs w480 Section, Add new bill Gui, Tab, Overdraft Gui, Add, Text, y+50 w200 Section Right, Overdraft Limit Gui, Add, Edit, ys w200 Section vNew_OverDraft, %OverDraft% Gui, Add, Button, xs w200, Change Gui, Tab, Spending Gui, Add, Text, y+20 w200 Section Right, Spend Date Gui, Add, DateTime, ys w290 vSpend_Date Range%Start_Date%%Start_Day%, LongDate Gui, Add, Text, xs Section w10 Right, £ Gui, Add, Edit, ys w175 Section vAmount_Spent, Gui, Add, DropDownList, R15 ys w290 vSpending_Type, Choose Spending Type||%Spending_Types% Gui, Add, Button, w290 h45 xs+190 Section gSpend, Enter Spending Details Gui, Add, Edit, xs-210 y+50 w240 Section vNew_Spending_Type, Gui, Add, Button, ys w240, Add New Spending Type Gui, Add, Button, xs+255 w240, Delete Spending Types Gui, Tab, Income Gui, Add, Text, y+20 w200 Section Right, Income Date Gui, Add, DateTime, ys w290 vIncome_Date Range%Start_Date%%Start_Day%, LongDate Gui, Add, Text, xs Section w10 Right, £ Gui, Add, Edit, ys w175 Section vAmount_Earned, Gui, Add, DropDownList, R15 ys w290 vIncome_Type, Choose Income Type||%Income_Types% Gui, Add, Button, w290 h45 xs+190 Section gIncome, Enter Income Details Gui, Add, Edit, xs-210 y+50 w240 Section vNew_Income_Type Gui, Add, Button, ys w240, Add New Income Type Gui, Add, Button, xs+255 w240, Delete Income Types Gui, Tab Gui, Font, s14, Verdana Gui, Add, Text, xs y+100 w500 Center Section, Your current balance is £%Balance% Gui, Add, Text, xs y+30 Center w500 Section, Available balance is £%Available_Balance% Gui, Tab, Debts Gui, Add, Text, xs y+30 Center w500, Total Debt is £%Total_Debt% Gui, Tab, Bills Gui, Add, Text, xs Center w500, Available balance after bills is £%Available_bills% Gui, Show, , Ledger ScanData() Return ;;;;;;;;;;;;;;;;;;;;;;; Function for entering data into main ListView ScanData() { Gui, Submit, NoHide Gui, 1:Default Gui, ListView, SysListView321 ; Scan the monthly bills to see if any need to be deducted from the balance FormatTime, Now, %A_Now%, yyyyMMdd IniRead, Dates_List, Ledger.ini, Bills_Monthly, List, %A_Space% New_Dates_List = Loop, Parse, Dates_List, | { If (A_LoopField = "") { Continue } If (A_LoopField <= Now) { IniRead, Bill_Amount, Ledger.ini, Bills_Monthly, %A_LoopField%_Amount IniRead, Bill_Type, Ledger.ini, Bills_Monthly, %A_LoopField%_Type FormatTime, Bill_Day, %A_LoopField%, dd FormatTime, Ini_Date, %A_LoopField%, yyyyMM Loop { IniRead, Check_Amount, Transaction Data\%Ini_Date%.ini, %Bill_Day%, %A_Index%_Amount, %A_Space% If (Check_Amount = "") || (Check_Amount = "ERROR") { Prefix := A_Index Break } } IniWrite, %Bill_Amount%, Transaction Data\%Ini_Date%.ini, %Bill_Day%, %Prefix%_Amount IniWrite, %Bill_Type%, Transaction Data\%Ini_Date%.ini, %Bill_Day%, %Prefix%_Type IniWrite, Out, Transaction Data\%Ini_Date%.ini, %Bill_Day%, %Prefix%_Out_In New_Date := AddMonth(A_LoopField) FormatTime, New_Date, %New_Date%, yyyyMM New_Date = %New_Date%%Bill_Day% New_Dates_List = %New_Dates_List%%New_Date%| IniDelete, Ledger.ini, Bills_Monthly, %A_LoopField%_Amount IniDelete, Ledger.ini, Bills_Monthly, %A_LoopField%_Type IniWrite, %Bill_Amount%, Ledger.ini, Bills_Monthly, %New_Date%_Amount IniWrite, %Bill_Type%, Ledger.ini, Bills_Monthly, %New_Date%_Type } Else { New_Dates_List = %New_Dates_List%%A_LoopField%| } } IniWrite, %New_Dates_List%, Ledger.ini, Bills_Monthly, List ; Scan the selected date and generate the statement for that month LV_Delete() Scan_Day = 01 GuiControlGet, Statement_Date, , SysDateTimePick321 FormatTime, Ini_Date, %Statement_Date%, yyyyMM Formattime, Month, %Statement_Date%, MM Loop { Scan_Day_Length := StrLen(Scan_Day) If Scan_Day_Length = 1 { Scan_Day = 0%Scan_Day% } Prefix = 1 If Scan_Day = 31 { Break } Loop, { IniRead, %Prefix%_Amount_%Scan_Day%, Transaction Data\%Ini_Date%.ini, %Scan_Day%, %Prefix%_Amount If (%Prefix%_Amount_%Scan_Day% = "") || (%Prefix%_Amount_%Scan_Day% = "ERROR") { Break } Prefix += 1 %Scan_Day%_Num = %Prefix% } Prefix = 1 Loop { IniRead, %Prefix%_Out_In_%Scan_Day%, Transaction Data\%Ini_Date%.ini, %Scan_Day%, %Prefix%_Out_In If (%Prefix%_Out_In_%Scan_Day% = "") || (%Prefix%_Out_In_%Scan_Day% = "ERROR") { Break } Prefix += 1 } Prefix = 1 Loop { IniRead, %Prefix%_Type_%Scan_Day%, Transaction Data\%Ini_Date%.ini, %Scan_Day%, %Prefix%_Type If (%Prefix%_Type_%Scan_Day% = "") || (%Prefix%_Type_%Scan_Day% = "ERROR") { Break } Prefix += 1 } Scan_Day += 1 } ; When each month is generated the monthly total balance is recalculated to catch any new transactions Balance = 0 IniRead, Start_Date, Ledger.ini, Start_Date, Date IniRead, Balance, Ledger.ini, Start_Balance, Value If (Start_Date != Ini_Date) { Loop { If (Start_Date >= Ini_Date) { Break } IniRead, Running, Ledger.ini, Running_Balance, %Start_Date% Balance := Round((Balance + Running), 2) Start_Date := AddMonth(Start_Date) } } Scan_Day = 1 Running = 0 Loop { Scan_Day_Length := StrLen(Scan_Day) If Scan_Day_Length = 1 { Scan_Day = 0%Scan_Day% } Prefix = 1 If Scan_Day = 31 { Break } Loop_Num := %Scan_Day%_Num Loop, %Loop_Num% { Date = %Scan_Day%/%Month% Amount := %Prefix%_Amount_%Scan_Day% Type := %Prefix%_Type_%Scan_Day% If %Prefix%_Out_In_%Scan_Day% = Out { Balance := Round((Balance - Amount), 2) Running := Round((Running - Amount), 2) LV_Add("", Date, Amount, "", Type, Balance) } If %Prefix%_Out_In_%Scan_Day% = In { Balance := Round((Balance + Amount), 2) Running := Round((Running + Amount), 2) LV_Add("", Date, "", Amount, Type, Balance) } Prefix += 1 } Scan_Day += 1 } LV_ModifyCol(1, 70) LV_ModifyCol(2, 92) LV_ModifyCol(3, 92) LV_ModifyCol(4, 170) LV_ModifyCol(5, 102) ; Write the newly calulated monthly balance to the data file. Add up all the monthly totals and add the figure to the starting balance IniWrite, %Running%, Ledger.ini, Running_Balance, %Ini_Date% IniRead, Start_Date, Ledger.ini, Start_Date, Date FormatTime, Now, %A_Now%, yyyyMM Total_Running = 0 Loop { If (Start_Date > Now) { Break } IniRead, Running, Ledger.ini, Running_Balance, %Start_Date% Total_Running := Round((Total_Running + Running), 2) Start_Date := AddMonth(Start_Date) } IniWrite, %Total_Running%, Ledger.ini, Total_Running, Value IniRead, Start_Balance, Ledger.ini, Start_Balance, Value IniRead, OverDraft, Ledger.ini, OverDraft, Value IniRead, Cash_Amount, Ledger.ini, Cash, Value Current_Balance := Round((Start_Balance + Total_Running), 2) GuiControl, , Static8, Your current balance is £%Current_Balance% Available_Balance := Round((Current_Balance + OverDraft + Cash_Amount), 2) GuiControl, , Static9, Available balance is £%Available_Balance% ; Scan the debts and display on the Debts tab Gui, ListView, SysListView322 LV_Delete() IniRead, Debtors, Ledger.ini, Types, Debtors, %A_Space% Total_Debt = 0 Loop, Parse, Debtors, | { IniRead, Debt_Amount, Ledger.ini, Debts, %A_LoopField%, If (Debt_Amount = "ERROR") { Continue } Debt_Amount := Round(Debt_Amount, 2) LV_Add("", Debt_Amount, A_LoopField) Total_Debt := Round((Total_Debt + Debt_Amount), 2) } GuiControl, , Static10, Total Debt is £%Total_Debt% ; Scan the bills Gui, ListView, SysListView323 LV_Delete() IniRead, Bills_List, Ledger.ini, Types, Bills, %A_Space% Total_Bills = 0 Loop, Parse, Bills_List, | { If (A_LoopField = "") { Continue } IniRead, Bill_Amount, Ledger.ini, Bills, %A_LoopField%, %A_Space% LV_Add("", "-", Bill_Amount, A_LoopField) Total_Bills := Round((Total_Bills + Bill_Amount), 2) } IniRead, Dates_List, Ledger.ini, Bills_Monthly, List, %A_Space% Sort, Dates_List, D| Loop, Parse, Dates_List, | { If (A_LoopField = "") { Continue } IniRead, Bill_Amount, Ledger.ini, Bills_Monthly, %A_LoopField%_Amount, %A_Space% IniRead, Bill_Type, Ledger.ini, Bills_Monthly, %A_LoopField%_Type, %A_Space% FormatTime, Date, %A_LoopField%, dd/MM LV_Add("", Date, Bill_Amount, Bill_Type) Total_Bills := Round((Total_Bills + Bill_Amount), 2) } GuiControl, , Static11, Total bill amount is £%Total_Bills% } ;;;;;;;;;;;;;;;;;;;;;;; Generate Statement for selected month DateTime: Gui, Submit, NoHide FormatTime, Check_Date, %Statement_Date%, yyyyMM IfNotExist, Transaction Data\%Check_Date%.ini { FormatTime, Display_Date, %Statement_Date%, MMMM yyyy MsgBox, 16, Ledger, There are no transactions for %Display_Date%, 5 Return } ScanData() Return ;;;;;;;;;;;;;;;;;;;;; Edit Transactions Edit_Transaction: Gui, 1:Default Gui, ListView, SysListView321 Gui, Submit, NoHide if A_GuiEvent = DoubleClick { LV_GetText(Date, A_EventInfo, 1) LV_GetText(Amount, A_EventInfo, 2) In_Out = Out If (Amount = "") { LV_GetText(Amount, A_EventInfo, 3) In_Out = In } LV_GetText(Type, A_EventInfo, 4) If Date = Date { Msgbox, 16, Ledger, There is no data here, 5 Return } StringLeft, Year_Month, Statement_Date, 6 StringLeft, Day, Date, 2 Full_Date = %Year_Month%%Day% FormatTime, Display_Date, %Full_Date%, dd / MM / yyyy Prefix = 1 Loop { IniRead, Check_Amount, Transaction Data\%Year_Month%.ini, %Day%, %Prefix%_Amount IniRead, Check_Type, Transaction Data\%Year_Month%.ini, %Day%, %Prefix%_Type If (Check_Amount = Amount) && (Check_Type = Type) { Prefix_Number := Prefix Break } Prefix += 1 } IniRead, Start_Date, Ledger.ini, Start_Date, Date IniRead, Start_Day, Ledger.ini, Start_Date, Day Gui, 2:+ToolWindow +Owner Gui, 2:Font, s12, Verdana Gui, 2:Add, Text, w70 Section Right, Date Gui, 2:Add, DateTime, w300 ys vNew_Date Choose%Full_Date% Range%Start_Date%%Start_Day%, dd MMMM yyyy Gui, 2:Add, Text, w70 xs Section Right, Amount Gui, 2:Add, Edit, w300 ys vNew_Amount, %Amount% Gui, 2:Add, Radio, w70 vIn xs+150 Section, In Gui, 2:Add, Radio, w70 vOut ys, Out If In_Out = In { GuiControl, 2:, In, 1 IniRead, Types, Ledger.ini, Types, Income } Else { GuiControl, 2:, Out, 1 IniRead, Types, Ledger.ini, Types, Spending } Loop, Parse, Types, | { If (A_LoopField = Type) { Choose_Num := A_Index Break } } Gui, 2:Add, Text, xs-180 Section w100 Right, Type Gui, 2:Add, DropDownList, R15 ys w300 vNew_Type Choose%Choose_Num%, %Types% Gui, 2:Add, Button, Section xs+35 w180, Delete Gui, 2:Add, Button, ys w180, Submit Gui, 2:Show, AutoFit, Transaction Edit } Return 2ButtonDelete: Gui, 2:Submit IniDelete, Transaction Data\%Year_Month%.ini, %Day%, %Prefix_Number%_Amount IniDelete, Transaction Data\%Year_Month%.ini, %Day%, %Prefix_Number%_Out_In IniDelete, Transaction Data\%Year_Month%.ini, %Day%, %Prefix_Number%_Type This := Prefix_Number Next := (Prefix_Number + 1) Loop { IniRead, Next_Amount, Transaction Data\%Year_Month%.ini, %Day%, %Next%_Amount If (Next_Amount = "") || (Next_Amount="ERROR") { Break } IniWrite, %Next_Amount%, Transaction Data\%Year_Month%.ini, %Day%, %This%_Amount IniRead, Next_Out_In, Transaction Data\%Year_Month%.ini, %Day%, %Next%_Out_In IniWrite, %Next_Out_In%, Transaction Data\%Year_Month%.ini, %Day%, %This%_Out_In IniRead, Next_Type, Transaction Data\%Year_Month%.ini, %Day%, %Next%_Type IniWrite, %Next_Type%, Transaction Data\%Year_Month%.ini, %Day%, %This%_Type This += 1 Next += 1 } ScanData() Gui, 2:Destroy Return 2ButtonSubmit: Gui, 2:Submit FormatTime, Ini_Date, %New_Date%, yyyyMM FormatTime, New_Day, %New_Date%, dd If (Day != New_Day) { IniDelete, Transaction Data\%Year_Month%.ini, %Day%, %Prefix_Number%_Amount IniDelete, Transaction Data\%Year_Month%.ini, %Day%, %Prefix_Number%_Out_In IniDelete, Transaction Data\%Year_Month%.ini, %Day%, %Prefix_Number%_Type This := Prefix_Number Next := (Prefix_Number + 1) Loop { IniRead, Next_Amount, Transaction Data\%Year_Month%.ini, %Day%, %Next%_Amount If (Next_Amount = "") || (Next_Amount="ERROR") { Break } IniWrite, %Next_Amount%, Transaction Data\%Year_Month%.ini, %Day%, %This%_Amount IniRead, Next_Out_In, Transaction Data\%Year_Month%.ini, %Day%, %Next%_Out_In IniWrite, %Next_Out_In%, Transaction Data\%Year_Month%.ini, %Day%, %This%_Out_In IniRead, Next_Type, Transaction Data\%Year_Month%.ini, %Day%, %Next%_Type IniWrite, %Next_Type%, Transaction Data\%Year_Month%.ini, %Day%, %This%_Type This += 1 Next += 1 } Loop { IniRead, Amount_Check, Transaction Data\%Ini_Date%.ini, %New_Day%, %A_Index%_Amount If (Amount_Check = "") || (Amount_Check = "ERROR") { New_Prefix := A_Index Break } } IniWrite, %New_Amount%, Transaction Data\%Ini_Date%.ini, %New_Day%, %New_Prefix%_Amount IniWrite, %New_Type%, Transaction Data\%Ini_Date%.ini, %New_Day%, %New_Prefix%_Type If In = 1 { IniWrite, In, Transaction Data\%Ini_Date%.ini, %New_Day%, %New_Prefix%_Out_In } If Out = 1 { IniWrite, Out, Transaction Data\%Ini_Date%.ini, %New_Day%, %New_Prefix%_Out_In } } Else { IniWrite, %New_Amount%, Transaction Data\%Ini_Date%.ini, %New_Day%, %Prefix_Number%_Amount IniWrite, %New_Type%, Transaction Data\%Ini_Date%.ini, %New_Day%, %Prefix_Number%_Type If In = 1 { IniWrite, In, Transaction Data\%Ini_Date%.ini, %New_Day%, %Prefix_Number%_Out_In } If Out = 1 { IniWrite, Out, Transaction Data\%Ini_Date%.ini, %New_Day%, %Prefix_Number%_Out_In } } ScanData() Gui, 2:Destroy Return 2GuiClose: Gui, 2:Destroy Gui, 1:Default Return ;;;;;;;;;;;;;;;;;;;;;; Spending Tab ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;; Add a new Spend transaction Spend: Gui, 1:Default Gui, ListView, SysListView321 Gui, Submit, NoHide If (Spend_Date > A_Now) { MsgBox, 16, Ledger, You cannot enter transactions for future dates, 5 Return } If Spending_Type = Choose Spending Type { MsgBox, 16, Ledger, Please choose a Spending Type, 5 Return } If (Amount_Spent = "") { MsgBox, 16, Ledger, Please input an Amount, 5 Return } Amount_Spent := Round(Amount_Spent, 2) FormatTime, Ini_Date, %Spend_Date%, yyyyMM FormatTime, Day, %Spend_Date%, dd Loop { IniRead, Amount, Transaction Data\%Ini_Date%.ini, %Day%, %A_Index%_Amount If (Amount = "ERROR") || (Amount = "") { Trans_Num := A_Index Break } } IniWrite, %Amount_Spent%, Transaction Data\%Ini_Date%.ini, %Day%, %Trans_Num%_Amount Iniwrite, Out, Transaction Data\%Ini_Date%.ini, %Day%, %Trans_Num%_Out_In IniWrite, %Spending_Type%, Transaction Data\%Ini_Date%.ini, %Day%, %Trans_Num%_Type IniRead, Debtors, Ledger.ini, Types, Debtors IfInString, Debtors, %Spending_Type% { IniRead, Current_Debt, Ledger.ini, Debts, %Spending_Type% New_Debt := Round((Current_Debt - Amount_Spent), 2) IniWrite, %New_Debt%, Ledger.ini, Debts, %Spending_Type% } GuiControl, , SysDateTimePick321, %Spend_Date% GuiControl, , Edit3 GuiControl, Choose, ComboBox1, 1 ScanData() Return ;;;;;;;;;;;;;;;;;;;;;;; Add a new Spending Type ButtonAddNewSpendingType: Gui, Submit, NoHide IfInString, A_LoopField, %New_Spending_Type% { MsgBox, 16, Ledger, %New_Spending_Type% already exists as a spending type, 5 Return } IniWrite, %Spending_Types%%New_Spending_Type%|, Ledger.ini, Types, Spending ControlGetPos, x, y, , , Edit4 ToolTip, Added, %x%, %y% SetTimer, ToolTip_Off, -1500 IniRead, Spending_Types, Ledger.ini, Types, Spending, %A_Space% IniRead, Debtors, Ledger.ini, Types, Debtors, %A_Space% Spending_Types = %Spending_Types%%Debtors% Sort, Spending_Types, D| GuiControl, , ComboBox1, |Choose Spending Type||%Spending_Types% GuiControl, , Edit4, Return ;;;;;;;;;;;;;;;;;;;;;;; Delete Spending Types ButtonDeleteSpendingTypes: Gui, 3:+Owner +ToolWindow Gui, 3:Font, s12, Verdana Gui, 3:Add, ListBox, R15 w400 Section vSelected_Spending_Type, %Spending_Types% Gui, 3:Add, Button, xs w190 Section, Exit Gui, 3:Add, Button, ys w190, Delete Gui, 3:Show, Autofit, Delete Spending Types Return 3ButtonExit: 3GuiClose: Gui, 3:Destroy Gui, 1:Default Return 3ButtonDelete: Gui, 3:Submit, NoHide IniRead, Spending_Types, Ledger.ini, Types, Spending New_List = Loop, Parse, Spending_Types, | { If (A_LoopField = Selected_Spending_Type) || (A_LoopField = "") { Continue } New_List = %New_List%%A_LoopField%| } ToolTip, Deleted SetTimer, ToolTip_Off, -1000 IniWrite, %New_List%, Ledger.ini, Types, Spending GuiControl, 3:, Selected_Spending_Type, |%New_List% Gui, 1:Default Spending_Types := New_List GuiControl, , ComboBox1, |Choose Spending Type||%New_List% Return ;;;;;;;;;;;;;;;;;;;;;; Income Tab ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;; Add a new Income transaction Income: Gui, 1:Default Gui, ListView, SysListView321 Gui, Submit, NoHide If (Income_Date > A_Now) { MsgBox, 16, Ledger, You cannot enter transactions for future dates, 5 Return } If Income_Type = Choose Income Type { MsgBox, 16, Ledger, Please choose an Income Type, 5 Return } If (Amount_Earned = "") { MsgBox, 16, Ledger, Please input an Amount, 5 Return } Amount_Earned := Round(Amount_Earned, 2) FormatTime, Ini_Date, %Income_Date%, yyyyMM FormatTime, Day, %Income_Date%, dd Loop { IniRead, Amount, Transaction Data\%Ini_Date%.ini, %Day%, %A_Index%_Amount If (Amount = "ERROR") || (Amount = "") { Trans_Num := A_Index Break } } IniWrite, %Amount_Earned%, Transaction Data\%Ini_Date%.ini, %Day%, %Trans_Num%_Amount IniWrite, In, Transaction Data\%Ini_Date%.ini, %Day%, %Trans_Num%_Out_In IniWrite, %Income_Type%, Transaction Data\%Ini_Date%.ini, %Day%, %Trans_Num%_Type GuiControl, , SysDateTimePick321, %Income_Date% GuiControl, , Edit5 GuiControl, Choose, ComboBox2, 1 ScanData() Return ;;;;;;;;;;;;;;;;;;;;;;; Add a new Income Type ButtonAddNewIncomeType: Gui, Submit, NoHide Loop, Parse, Income_Types, | { If A_loopField = %New_Income_Type% { MsgBox, 16, Ledger, %New_Income_Type% already exists as an income type, 5 Return } } IniWrite, %Income_Types%%New_Income_Type%|, Ledger.ini, Types, Income ControlGetPos, x, y, , , Edit6 ToolTip, Added, %x%, %y% SetTimer, ToolTip_Off, -1500 IniRead, Income_Types, Ledger.ini, Types, Income Sort, Income_Types, D| GuiControl, , ComboBox2, |Choose Income Type||%Income_Types% GuiControl, , Edit6, Return ;;;;;;;;;;;;;;;;;;;;;;; Delete Income Types ButtonDeleteIncomeTypes: Gui, 4:+Theme +Owner +ToolWindow Gui, 4:Font, s12, Verdana Gui, 4:Add, ListBox, R15 w400 Section vSelected_Income_Type, %Income_Types% Gui, 4:Add, Button, xs w190 Section, Exit Gui, 4:Add, Button, ys w190, Delete Gui, 4:Show, Autofit, Delete Income Types Return 4ButtonExit: 4GuiClose: Gui, 4:Destroy Gui, 1:Default Return 4ButtonDelete: Gui, 4:Submit, NoHide IniRead, Income_Types, Ledger.ini, Types, Income New_List = Loop, Parse, Income_Types, | { If (A_LoopField = Selected_Income_Type) || (A_LoopField = "") { Continue } New_List = %New_List%%A_LoopField%| } ToolTip, Deleted SetTimer, ToolTip_Off, -1000 IniWrite, %New_List%, Ledger.ini, Types, Income GuiControl, 4:, Selected_Income_Type, |%New_List% Gui, 1:Default Income_Types := New_List GuiControl, , ComboBox2, |Choose Income Type||%New_List% Return ;;;;;;;;;;;;;;;;;;;;;; Cash Tab ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ButtonEnter: Gui, Submit, NoHide IniWrite, %Cash_Amount%, Ledger.ini, Cash, Value ScanData() Return ;;;;;;;;;;;;;;;;;;;;;;; OverDraft Tab ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ButtonChange: Gui, Submit, NoHide IniWrite, %New_OverDraft%, Ledger.ini, OverDraft, Value ScanData() Return ;;;;;;;;;;;;;;;;;;;;;;; Debts Tab ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ButtonAddnewdebt: Gui, Submit, NoHide IniRead, Start_Date, Ledger.ini, Start_Date, Date IniRead, Start_Day, Ledger.ini, Start_Date, Day Gui, 5:+Theme +Owner +ToolWindow Gui, 5:Font, s12, Verdana Gui, 5:Add, Text, w150 Section Right, Name of Debtor Gui, 5:Add, Edit, w200 ys vName, Gui, 5:Add, Text, w150 Section xs y+15 Right, Amount owed Gui, 5:Add, Edit, w200 ys vAmount, Gui, 5:Add, Button, w175 xs Section, Exit Gui, 5:Add, Button, w175 ys, Submit Gui, 5:Show, AutoFit, Ledger - Debts Return 5ButtonExit: 5GuiClose: Gui, 5:Destroy Gui, 1:Default Return 5ButtonSubmit: Gui, 5:Submit Gui, 5:Destroy Gui, 1:Default If (Name = "") || (Amount = "") { MsgBox, 16, Ledger - Debts, Name of debtor and amount cannot be empty.`n`nPlease enter a value for each Gui, 5:Destroy Return } IniRead, Debtors, Ledger.ini, Types, Debtors, %A_Space% New_Debtors = IfInString, Debtors, %Name% { MsgBox, 16, Ledger - Debts, A Debtor with that name already exists.`n`nPlease choose another Gui, 5:Destroy Return } Else { New_Debtors = %Debtors%%Name%| } IniWrite, %New_Debtors%, Ledger.ini, Types, Debtors IniRead, Spending_Types, Ledger.ini, Types, Spending, %A_Space% IniRead, Debtors, Ledger.ini, Types, Debtors, %A_Space% Spending_Types = %Spending_Types%%Debtors% Sort, Spending_Types, D| GuiControl, , ComboBox1, |Choose Spending Type||%Spending_Types% IniWrite, %Amount%, Ledger.ini, Debts, %Name% ScanData() Return Edit_Debt: Gui, 1:Default Gui, ListView, SysListView322 If A_GuiEvent = DoubleClick { LV_GetText(Amount, A_EventInfo, 1) LV_GetText(Debtor, A_EventInfo, 2) If (Amount = "Amount") { Msgbox, 16, Ledger - Debts, There is no data here Return } Gui, 6:+Theme +Owner +ToolWindow Gui, 6:Font, s12, Verdana Gui, 6:Add, Text, w150 Section Right, Name of Debtor Gui, 6:Add, Edit, w200 ys vNew_Name, %Debtor% Gui, 6:Add, Text, w150 Section xs y+15 Right, Amount Owed Gui, 6:Add, Edit, w200 ys vNew_Amount, %Amount% Gui, 6:Add, Button, w175 xs Section, Delete Gui, 6:Add, Button, w175 ys, Submit Gui, 6:Show, AutoFit, Ledger - Debts } Return 6ButtonSubmit: Gui, 6:Submit Gui, 6:Destroy Gui, 1:Default If (New_Name = "") || (New_Amount = "") { MsgBox, 16, Ledger - Debts, Name of debtor and amount cannot be empty.`n`nPlease enter a value for each Gui, 6:Destroy Return } IniRead, Debtors, Ledger.ini, Types, Debtors New_Debtors = Loop, Parse, Debtors, | { If (A_LoopField = "") { Continue } If (A_LoopField = Debtor) { New_Debtors = %New_Debtors%%New_Name%| } Else { New_Debtors = %New_Debtors%%A_LoopField%| } } IniWrite, %New_Debtors%, Ledger.ini, Types, Debtors IniDelete, Ledger.ini, Debts, %Debtor% IniWrite, %New_Amount%, Ledger.ini, Debts, %New_Name% IniRead, Spending_Types, Ledger.ini, Types, Spending, %A_Space% IniRead, Debtors, Ledger.ini, Types, Debtors, %A_Space% Spending_Types = %Spending_Types%%Debtors% Sort, Spending_Types, D| GuiControl, , ComboBox1, |Choose Spending Type||%Spending_Types% ScanData() Return 6ButtonDelete: Gui, 6:Submit Gui, 6:Destroy Gui, 1:Default IniRead, Debtors, Ledger.ini, Types, Debtors New_Debtors = Loop, Parse, Debtors, | { If (A_LoopField = Debtor) || (A_LoopField = "") { Continue } Else { New_Debtors = %New_Debtors%%A_LoopField%| } } IniWrite, %New_Debtors%, Ledger.ini, Types, Debtors IniDelete, Ledger.ini, Debts, Debtor IniRead, Spending_Types, Ledger.ini, Types, Spending, %A_Space% IniRead, Debtors, Ledger.ini, Types, Debtors, %A_Space% Spending_Types = %Spending_Types%%Debtors% Sort, Spending_Types, D| GuiControl, , ComboBox1, |Choose Spending Type||%Spending_Types% ScanData() Return 6GuiClose: Gui, 6:Destroy Gui, 1:Default Return ;;;;;;;;;;;;;;;;;;;;;;; Bills Tab ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ButtonAddnewbill: Gui, Submit, NoHide IniRead, Start_Date, Ledger.ini, Start_Date, Date IniRead, Start_Day, Ledger.ini, Start_Date, Day Gui, 7:+Theme +Owner +ToolWindow Gui, 7:Font, s12, Verdana Gui, 7:Add, Text, w150 Section Right, Name of Bill Gui, 7:Add, Edit, w200 ys vName, Gui, 7:Add, Text, w150 Section xs y+15 Right, Bill Amount Gui, 7:Add, Edit, w200 ys vAmount, Gui, 7:Add, Text, xs w150 Section Right Disabled, First payment date Gui, 7:Add, DateTime, vFirst_Date w200 ys Disabled 1, dd MMMM yyyy Gui, 7:Add, CheckBox, w280 xs+80 Section gDebit vDebit, Paid by monthly Direct Debit? Gui, 7:Add, Button, w175 xs-80 Section, Exit Gui, 7:Add, Button, w175 ys, Submit Gui, 7:Show, AutoFit, Ledger - Debts Return Debit: Gui, 7:Submit, NoHide GuiControl, Enable%Debit%, Static3 GuiControl, Enable%Debit%, SysDateTimePick321 Return 7ButtonExit: 7GuiClose: Gui, 7:Destroy Gui, 1:Default Return 7ButtonSubmit: Gui, 7:Submit Gui, 1:Default If (Name = "") || (Amount = "") { MsgBox, 16, Ledger - Bills, Name of debtor and amount cannot be empty.`n`nPlease enter a value for each Gui, 7:Destroy Return } If (Debit = 1) { FormatTime, First_Date, %First_Date%, yyyyMMdd IniRead, Dates_List, Ledger.ini, Bills_Monthly, List, %A_Space% IfNotInString, Dates_List, %First_Date% { Dates_List = %Dates_List%%First_Date%| } IniWrite, %Dates_List%, Ledger.ini, Bills_Monthly, List IniRead, Current_Amount, Ledger.ini, Bills, %First_Date%, 0 Amount := Round((Current_Amount + Amount), 2) IniWrite, %Amount%, Ledger.ini, Bills_Monthly, %First_Date%_Amount IniWrite, %Name%, Ledger.ini, Bills_Monthly, %First_Date%_Type } Else { IniRead, Bills, Ledger.ini, Types, Bills, %A_Space% New_Bills = IfInString, Bills, %Name% { MsgBox, 16, Ledger - Bills, A Bill with that name already exists.`n`nPlease choose another Gui, 7:Destroy Return } Else { New_Bills = %Bills%%Name%| } IniWrite, %New_Bills%, Ledger.ini, Types, Bills IniWrite, %Amount%, Ledger.ini, Bills, %Name% } Gui, 7:Destroy Gui, 1:Default ScanData() Return Edit_Bill: Gui, 1:Default Gui, ListView, SysListView323 If A_GuiEvent = DoubleClick { LV_GetText(Date, A_EventInfo, 1) LV_GetText(Amount, A_EventInfo, 2) LV_GetText(Payee, A_EventInfo, 3) If (Date = "Due Date") { Msgbox, 16, Ledger - Bills, There is no data here Return } StringLeft, Day, Date, 2 StringRight, Month, Date, 2 Date = %A_yyyy%%Month%%Day% Debit = 0 Gui, 8:+Theme +Owner +ToolWindow Gui, 8:Font, s12, Verdana Gui, 8:Add, Text, w150 Section Right, Name of Payee Gui, 8:Add, Edit, w200 ys vNew_Name, %Payee% Gui, 8:Add, Text, w150 Section xs y+15 Right, Bill Gui, 8:Add, Edit, w200 ys vNew_Amount, %Amount% Gui, 8:Add, Text, xs w150 Section Right Disabled, Due Date Gui, 8:Add, DateTime, vNew_Date w200 ys Disabled 1 Choose%Date%, dd MMMM yyyy Gui, 8:Add, Button, w175 xs Section, Delete Gui, 8:Add, Button, w175 ys, Submit Gui, 8:Show, AutoFit, Ledger - Debts If Date != %A_yyyy%-- { Debit = 1 Gui, 8:Default GuiControl, Enable, Static3 GuiControl, Enable, SysDateTimePick321 } } Return 8GuiClose: Gui, 8:Destroy Gui, 1:Default Return 8ButtonSubmit: Gui, 8:Submit If (Debit = 0) { IniRead, Bills_List, Ledger.ini, Types, Bills, %A_Space% New_Bills_List = Loop, Parse, Bills_List, | { If (A_LoopField = "") { Continue } If (A_LoopField = Payee) { New_Bills_List = %New_Bills_List%%A_LoopField% } Else { New_Bills_List = %New_Bills_List%%A_LoopField% } } IniWrite, %New_Bills_List%, Ledger.ini, Types, Bills IniWrite, %New_Amount%, Ledger.ini, Bills, %New_Name% IniDelete, Ledger.ini, Bills, %Payee% } Else { FormatTime, New_Date, %New_Date%, yyyyMMdd IniRead, Date_List, Ledger.ini, Bills_Monthly, List, %A_Space% New_Dates_List = Loop, Parse, Date_List, | { If (A_LoopField = "") { Continue } If (A_LoopField = Date) { New_Dates_List = %New_Dates_List%%New_Date% } Else { New_Dates_List = %New_Dates_List%%A_LoopField%| } } IniWrite, %New_Dates_List%, Ledger.ini, Bills_Monthly, List IniWrite, %New_Amount%, Ledger.ini, Bills_Monthly, %New_Date%_Amount IniWrite, %New_Name%, Ledger.ini, Bills_Monthly, %New_Date%_Type IniDelete, Ledger.ini, Bills_Monthly, %Date%_Amount IniDelete, Ledger.ini, Bills_Monthly, %Date%_Type } Gui, 8:Destroy Gui, 1:Default ScanData() Return 8ButtonDelete: Gui, 8:Submit If (Debit = 0) { IniRead, Bills_List, Ledger.ini, Types, Bills, %A_Space% New_Bills_List = Loop, Parse, Bills_List, | { If (A_LoopField = Payee) || (A_LoopField = "") { Continue } Else { New_Bills_List = %New_Bills_List%%A_LoopField% } } IniWrite, %New_Bills_List%, Ledger.ini, Types, Bills IniDelete, Ledger.ini, Bills, %Payee% } Else { FormatTime, New_Date, %New_Date%, yyyyMMdd IniRead, Date_List, Ledger.ini, Bills_Monthly, List, %A_Space% New_Dates_List = Loop, Parse, Date_List, | { If (A_LoopField = Date) || (A_LoopField = "") { Continue } Else { New_Dates_List = %New_Dates_List%%A_LoopField%| } } IniWrite, %New_Dates_List%, Ledger.ini, Bills_Monthly, List IniDelete, Ledger.ini, Bills_Monthly, %Date%_Amount IniDelete, Ledger.ini, Bills_Monthly, %Date%_Type } Gui, 8:Destroy Gui, 1:Default ScanData() Return ;;;;;;;;;;;;;;;;;;;;;;; Turn Tooltip off ToolTip_Off: ToolTip Return ;;;;;;;;;;;;;;;;;;;;; Close GuiClose: OnExit: ExitApp