clear all
close all

current_month = 50;  %June 2013 = month number 50.

data = xlsread('DollarsSpent.xls');

idx = 1:51;

month = datenum(data(idx,1), data(idx,2), 28);

spent = data(idx,13+3);
cumulative_spent = data(idx,14+3);

linear_spendrate = data(idx,4);
planned_spendrate = data(idx,6);

dollars_left = max(linear_spendrate)-max(cumulative_spent);

Average_Spending = nanmean(spent/1000);
AllowableMonthlySpending = dollars_left/1.5 %(length(month)-current_month);


figure('Position', [ 198         610        1101         403]);
fh = plot(month,cumulative_spent,month,linear_spendrate,month,planned_spendrate,[datenum(month(current_month)) datenum(month(current_month))],[0 linear_spendrate(end)],'--');
legend('Actual Spending','Linear Spend Profile','Planned Spend Profile','Location','NorthWest');
datetick('x','mmm-yyyy','keepticks');
ylabel('Thousands of Dollars');
xlabel('Date');
title('Spending through May 9, 2013');
%foo = axis;
%foo(1) = month(1);
%foo(2) = month(end);
%axis(foo);

print('-dpng','Spending through May 9, 2013');
print('-dpdf','Spending through May 9, 2013');

figure('Position', [ 198         610        1101         403]);
fh = bar(month,spent/1000)
hold on
plot(month,ones(1,length(month))*Average_Spending,'g-',month(current_month:end),ones(1,length(month(current_month:end)))*AllowableMonthlySpending,'r-')
legend('Monthly expenditures',['Average monthly spending:  $' num2str(1000*Average_Spending,5) '/month'],['Allowable average montly spending to end:  $' num2str(1000*AllowableMonthlySpending,5) '/month'],'Location','NorthWest')
datetick('x','mmm-yyyy','keepticks');
ylabel('Thousands of Dollars');
xlabel('Date');


print('-dpng','Spending Averages through May 9, 2013');
print('-dpdf','Spending Averages through May 9, 2013');
