'use strict';

var EmployeeFunctionsCtrl = ['$scope', '$http', function ($scope, $http) {
    $scope.record = {};
    $scope.creditSalary = function () {
        $http.
            post('/api/CreditSalary', {Month:$scope.salaryMonth}).
            success(function (data) {
                $scope.toasts.push({Type:'Success', Message:data.message});
            }).
            error(function (errorMessage) {
                $scope.toasts.push({Type:'Error', Message:errorMessage});
            });
    };
    $scope.attendanceRecordUrl = function () {
        var url = '/AttendanceReport?StartDate=' + $scope.record.Start + "&FinishDate=" + $scope.record.Finish;
        return url;
    }
    $scope.setFile = function (element) {
        $scope.uploadedFile = element.files[0];
    }
    $scope.uploadFingerprints = function () {
        if (!$scope.uploadedFile) {
            $scope.toasts.push({Type:'Error', Message:'Please choose a file first!'});
            return;
        }
        var fd = new FormData();
        fd.append("uploadedFile", $scope.uploadedFile);
        $http
            .post('/api/Fingerprint', fd, {
                headers:{
                    'Content-Type':undefined
                },
                transformRequest:angular.identity
            }).success(function () {
                $scope.toasts.push({Type:'Success', Message:'Data uploaded'});
            }).error(function (data, status, headers, config) {
                $scope.toasts.push({Type:'Error', Message:data});
            });
    };

}]

