system.controller("PrintifyReportController", PrintifyReportController);

function PrintifyReportController($scope, $http, $rootScope, Upload, $window) {

    this.__proto__ = new BaseController($scope, $http, $rootScope, Upload);

    const TOKEN_STORAGE = 'printifyToken';
    $scope.report = {
        limit: 1000
    }

    $scope.initialize = function () {
        var printifyToken = localStorage.getItem(TOKEN_STORAGE);
        if (printifyToken && printifyToken != '') {
            $scope.report.token = printifyToken;
        }
    };

    $scope.exportExcel = function () {
        if (!$scope.report.token || $scope.report.token == '') {
            toastr.error('Xin mời nhập Access Token.');
            return;
        } else {
            localStorage.setItem(TOKEN_STORAGE, $scope.report.token);
        }

        var exportUrl = '/print-suppliers/transaction/printify?token=' + $scope.report.token + '&limit=' + $scope.report.limit;
        $window.open(exportUrl, '_blank');
    }


    $scope.initialize();
}