{"size": 2006, "ext": "js", "max_stars_repo_path": "frontend/guest/order/OrderController.js", "max_stars_repo_name": "blindernuka/billett-frontend", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "frontend/guest/order/OrderController.js", "max_issues_repo_name": "blindernuka/billett-frontend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "frontend/guest/order/OrderController.js", "max_forks_repo_name": "blindernuka/billett-frontend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 36.4727272727, "max_line_length": 167, "alphanum_fraction": 0.5104685942}
import {api} from '../../api';

(function() {
    'use strict';

    var module = angular.module('billett.guest');

    module.config(function ($stateProvider) {
        $stateProvider.state('order-complete', {
            url: '/order/complete',
            templateUrl: require('./receipt.html'),
            controller: 'OrderController'
        });
    });

    module.controller('OrderController', function (Page, $http, $location, $scope, Analytics) {
        $http.get(api('order/receipt')).then(function (res) {
            $scope.order = res.data.order;
            $scope.payment = res.data.payment;

            // TODO: don't add multiple times if user is reloading page

            var is_test = res.data.order.order_text_id.slice(-5) == "-TEST";
            Analytics.addTrans(res.data.order.order_text_id, 'Billett UKA på Blindern' + (is_test ? ' (TEST)' : ''), res.data.payment.amount, 0, 0, '', '', '', 'NOK');

            // group the entries by ticketgroup
            var ticketGroups = {};
            angular.forEach(res.data.order.tickets, function(ticket) {
                if (ticket.ticketgroup.id in ticketGroups) {
                    ticketGroups[ticket.ticketgroup.id][5]++;
                } else {
                    ticketGroups[ticket.ticketgroup.id] = [
                        res.data.order.order_text_id,
                        ticket.event.id + '-' + ticket.ticketgroup.id,
                        ticket.event.title + ' (' + ticket.ticketgroup.title + ')',
                        ticket.event.category,
                        ticket.ticketgroup.price + ticket.ticketgroup.fee,
                        1
                    ];
                }
            });
            angular.forEach(ticketGroups, function(group) {
                Analytics.addItem.apply(Analytics, group);
            });

            Analytics.trackTrans();


        }, function (err) {
            //$location.path('/');
            console.log('err', err);
        });
    });
})();
