require 'date'

class Budget
    
    attr_accessor :balance

    def initialize(initial_balance)
        @balance = initial_balance
        @expenses = {}
        @income = {}
        puts "Initial balance: %.2f" % [@balance]
    end

    def add_expense(item, amount, date)
        date = Date.parse(date)
        str = date.strftime('%B %e %Y')
        str1 = date.strftime('%B')

        if @expenses.keys.include?(str1) == false
            @expenses[str1] = amount
        else
            x = @expenses[str1]
            x += amount
            @expenses[str1] = x
        end

        @balance -= amount
        puts "#{item}: An amount of %.2f was deducted from the balance on #{str}" % [amount]
    end

    def add_income(item, amount, date)
        date = Date.parse(date)
        str = date.strftime('%B %e %Y')
        str1 = date.strftime('%B')

        if @income.keys.include?(str1) == false
            @income[str1] = amount
        else
            x = @income[str1]
            x += amount
            @expenses[str1] = x
        end

        @balance += amount
        puts "#{item}: An amount of %.2f was added to the balance on #{str}" % [amount]
    end

    def monthly_report(month, year)
        date = Date.parse("#{year}0#{month}01")
        str = date.strftime('%B %Y')
        str1 = date.strftime('%B')
        puts '===================================='
        puts "MONTHLY REPORT: #{str}"
        puts "Total Expense: %.2f" % @expenses[str1]
        puts "Total Income: %.2f" % @income[str1]
        puts '===================================='
    end

    def current
        puts "Balance: %.2f" % [@balance]
    end

end