 # Description:
-#   Make an order for easy record.
+#   Make an order for easyily record and calculate total money needed.
 #
 # Dependencies:
 #   

	robot.respond /order all/i, (msg) ->
		date_current = new Date()
		orders = robot.brain.data.orders
		robot.logger.debug Util.inspect(orders)
		totalMoney = 0
		if (orders isnt null)
			robot.logger.debug Util.inspect(order) for order in orders
			totalMoney += parseInt( order.money, 10 ) for order in orders
			msg.reply order for order in orders when order.date.getDate() is date_current.getDate()
			msg.reply "Total money : #{totalMoney}"
		else
			msg.reply "There has no orders."

	rebot.respond /order reset/i, (msg) ->
		robot.brain.data['orders'] = []
		msg.reply "Orders reset !"

	parseTarget = (text) ->
		robot.logger.debug text
		regexPattern = /order .* for \<@?(\S*)\>/i
		matches = text.match regexPattern
		robot.logger.debug Util.inspect(matches)
		matches[1]

		order = new Order name:user, userId:userId, date:date_current, food:food, note:note, money:money

		for _order in robot.brain.data.orders
			if(_order.name is user)
				index = robot.brain.data.orders.indexOf(_order)
				robot.brain.data.orders.splice(index, 1)
				break

		robot.brain.data.orders.push order

		msg.reply "You order #{food} #{note} $#{money} for <@#{userId}|#{user}>}"

	robot.respond /order my/i, (msg) ->
		date_current = new Date()
		user = msg.message.user.name
		order = o for o in robot.brain.data.orders when o.name is user #and o.date.getDate() is date_current.getDate()
		if (order?)
			msg.reply order
		else
