finance-widget.js

angular.module('homepage').
directive('financeWidget', function () {
    return {
        controller: 'financeWidgetController',
        restrict: 'E',
        replace: true,
        scope: {
        	data: '=',
            isDemo: '='
        },
        transclude: true,
        templateUrl: 'components/feature-components/finance/finance-widget.html'
    };
}).
controller('financeWidgetController', function ($scope, DateUtility, Server) {
    if($scope.isDemo === true) {
        $scope.stats = {
            count: 1,
            result: {
                myself: {
                    amount_day: 2505,
                    amount_month: 33778
                }
            }
        };
    }
    else {
        var monthRange = DateUtility.getMonthDateRange(new Date());
        var data = {
            startTimestamp: new Date(monthRange.start).getTime(),
            endTimestamp: new Date(monthRange.end).getTime()
        };
        Server.getMoneyWidgetData(data)
            .success(function (result) {
                console.log(result);
                $scope.stats = result;
            });
    }
});