<commit_before>/*jslint es5: true nomen: true forin: true vars: true*/
(function (global) {
    "use strict";

    global.PosController = function ($scope, api, $timeout, $modal, $http) {

        var getData = function () {
            api.posdata(function (data) {
                $scope.users = data.users;
                $scope.transactions = data.transactions;
                $scope.products = data.products;
                $scope.paytypes = data.paytypes;
            });
        };

        getData();

        //Update data when browser comes back online.
        $scope.$on('online', getData);

        $scope.intro = function () {
            var opts = {
                nextLabel: "Järgmine",
                prevLabel: "Eelmine",
                skipLabel: "Lõpeta"
            };
            global.introJs().setOptions(opts).start();
        };

        $scope.selectedProducts = {};


        $scope.showAllProducts = false;

        $scope.toggleShowAllProducts = function () {
            $scope.showAllProducts = !$scope.showAllProducts;
        };

        $scope.filteredProducts = function () {
            if ($scope.showAllProducts || $scope.products === undefined) {
                return $scope.products;
            }
            return $scope.products.filter(function (product) { return product.quantity > 0; });
        };

        $scope.changeQuantity = function (product, quantity) {
            var selectedProduct = $scope.selectedProducts[product._id];
            if (selectedProduct === undefined) {
                selectedProduct = global.angular.copy(product);
                selectedProduct.quantity = 0;
                $scope.selectedProducts[product._id] = selectedProduct;
            }
            var newQuantity = selectedProduct.quantity + quantity;
            if (newQuantity >= 0) {
                selectedProduct.quantity = newQuantity;
            }
        };

        $scope.quantity = function (product) {
            var qty = 0;
            var selectedProduct = $scope.selectedProducts[product._id];
            if (selectedProduct) {
                qty = selectedProduct.quantity;
            }
            return ' ' + qty + ' ';
        };

        $scope.sum = function () {
            var sum = 0, id;
            for (id in $scope.selectedProducts) {
                var product = $scope.selectedProducts[id];
                sum += product.price * product.quantity;
            }
            return sum;
        };

        $scope.isDisabled = function (paytype) {
            if ($scope.user) {
                return paytype.allowedForStatus.indexOf($scope.user.status) === -1;
            }
            return true;
        };

        var updateStatus = function (message, error) {
            $scope.statusMessage = message;<commit_msg>Fixed problem where adding and removing a product left the product with 0 quantity on the transaction.<commit_after>/*jslint es5: true nomen: true forin: true vars: true*/
(function (global) {
    "use strict";

    global.PosController = function ($scope, api, $timeout, $modal, $http) {

        var getData = function () {
            api.posdata(function (data) {
                $scope.users = data.users;
                $scope.transactions = data.transactions;
                $scope.products = data.products;
                $scope.paytypes = data.paytypes;
            });
        };

        getData();

        //Update data when browser comes back online.
        $scope.$on('online', getData);

        $scope.intro = function () {
            var opts = {
                nextLabel: "Järgmine",
                prevLabel: "Eelmine",
                skipLabel: "Lõpeta"
            };
            global.introJs().setOptions(opts).start();
        };

        $scope.selectedProducts = {};


        $scope.showAllProducts = false;

        $scope.toggleShowAllProducts = function () {
            $scope.showAllProducts = !$scope.showAllProducts;
        };

        $scope.filteredProducts = function () {
            if ($scope.showAllProducts || $scope.products === undefined) {
                return $scope.products;
            }
            return $scope.products.filter(function (product) { return product.quantity > 0; });
        };

        $scope.changeQuantity = function (product, quantity) {
            var selectedProduct = $scope.selectedProducts[product._id];
            if (selectedProduct === undefined) {
                selectedProduct = global.angular.copy(product);
                selectedProduct.quantity = 0;
                $scope.selectedProducts[product._id] = selectedProduct;
            }
            var newQuantity = selectedProduct.quantity + quantity;
            if (newQuantity >= 0) {
                selectedProduct.quantity = newQuantity;
            } else {
                delete $scope.selectedProducts[product._id];
            }
        };

        $scope.quantity = function (product) {
            var qty = 0;
            var selectedProduct = $scope.selectedProducts[product._id];
            if (selectedProduct) {
                qty = selectedProduct.quantity;
            }
            return ' ' + qty + ' ';
        };

        $scope.sum = function () {
            var sum = 0, id;
            for (id in $scope.selectedProducts) {
                var product = $scope.selectedProducts[id];
                sum += product.price * product.quantity;
            }
            return sum;
        };

        $scope.isDisabled = function (paytype) {
            if ($scope.user) {
                return paytype.allowedForStatus.indexOf($scope.user.status) === -1;
            }
            return true;
        };

        var updateStatus = function (message, error) {
            $scope.statusMessage = message;
{'fraction_non_alphanumeric': 0.11321730139582974, 'fraction_numerical': 0.0025848698948819577, 'mean_word_length': 1.60619667714414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '799324', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1421, 'n_words': 318}