<commit_before>angular.module('orderCloud')
    .factory('ocOrders', ocOrdersService)
;

function ocOrdersService(OrderCloudSDK){
    var service = {
        List: _list
    };
    
    function _list(Parameters, CurrentUser){
        var parameters = angular.copy(Parameters);

        //exclude unsubmitted orders from list
        //parameters.filters = {Status: '!Unsubmitted'};  //TODO: replace this line with below once api can reverse filter enums (EX-1166)
        // parameters.filters = {Status: 'Open|AwaitingApproval|Completed|Canceled|Declined'};

        if(parameters.status){
            angular.extend(parameters.filters, {Status: parameters.status});
        }

        //set outgoing params to iso8601 format as expected by api
        //set returning params to date object as expected by uib-datepicker
        if(parameters.from) {
            var fromDateObj = new Date(parameters.from);
            Parameters.fromDate = fromDateObj;
            parameters.from = (fromDateObj).toISOString();
        }
        if(parameters.to) {
            var toDateObj = new Date(parameters.to);
            Parameters.toDate = toDateObj;
            parameters.to = (toDateObj).toISOString();
        }

        // DateSubmitted calculated with from/to parameters
        if(parameters.from && parameters.to) {
            parameters.filters.DateSubmitted = [('>' + parameters.from), ('<' + parameters.to)];
        } else if(parameters.from && !parameters.to) {
            parameters.filters.DateSubmitted = [('>' + parameters.from)];
        } else if (!parameters.from && parameters.to) {
            parameters.filters.DateSubmitted = [('<' + parameters.to)];
        }

        if(parameters.tab === 'favorites') {
            if(CurrentUser.xp && CurrentUser.xp.FavoriteOrders) {
                angular.extend(parameters.filters, {ID: CurrentUser.xp.FavoriteOrders.join('|')});
            }
        }

        if(parameters.tab === 'grouporders') {
            if(parameters.group) {
                return OrderCloudSDK.Me.ListAddresses()
                    .then(function(addresses) {
                        var shippingAddress = _.where(addresses.Items, {CompanyName: parameters.group});
                        parameters.filters = {ShippingAddressID: shippingAddress[0].ID /*, Status: parameters.status*/};
                        return OrderCloudSDK.Orders.List('Outgoing', parameters);
                    });
            } else {
                return [];
            }
        }

        // list orders with generated parameters
        if(parameters.tab === 'approvals') {
            return OrderCloudSDK.Me.ListApprovableOrders(parameters);
        } else if(parameters.tab === 'all') {
            return OrderCloudSDK.Orders.List('outgoing', parameters);
        } else {
            return OrderCloudSDK.Me.ListOrders(parameters);
        }
    }

    return service;
}<commit_msg>fix: add correct spelling of Cancelled for status filter<commit_after>angular.module('orderCloud')
    .factory('ocOrders', ocOrdersService)
;

function ocOrdersService(OrderCloudSDK){
    var service = {
        List: _list
    };
    
    function _list(Parameters, CurrentUser){
        var parameters = angular.copy(Parameters);

        //exclude unsubmitted orders from list
        //parameters.filters = {Status: '!Unsubmitted'};  //TODO: replace this line with below once api can reverse filter enums (EX-1166)
        parameters.filters = {Status: 'Open|AwaitingApproval|Completed|Cancelled|Declined'};

        if(parameters.status){
            angular.extend(parameters.filters, {Status: parameters.status});
        }

        //set outgoing params to iso8601 format as expected by api
        //set returning params to date object as expected by uib-datepicker
        if(parameters.from) {
            var fromDateObj = new Date(parameters.from);
            Parameters.fromDate = fromDateObj;
            parameters.from = (fromDateObj).toISOString();
        }
        if(parameters.to) {
            var toDateObj = new Date(parameters.to);
            Parameters.toDate = toDateObj;
            parameters.to = (toDateObj).toISOString();
        }

        // DateSubmitted calculated with from/to parameters
        if(parameters.from && parameters.to) {
            parameters.filters.DateSubmitted = [('>' + parameters.from), ('<' + parameters.to)];
        } else if(parameters.from && !parameters.to) {
            parameters.filters.DateSubmitted = [('>' + parameters.from)];
        } else if (!parameters.from && parameters.to) {
            parameters.filters.DateSubmitted = [('<' + parameters.to)];
        }

        if(parameters.tab === 'favorites') {
            if(CurrentUser.xp && CurrentUser.xp.FavoriteOrders) {
                angular.extend(parameters.filters, {ID: CurrentUser.xp.FavoriteOrders.join('|')});
            }
        }

        if(parameters.tab === 'grouporders') {
            if(parameters.group) {
                return OrderCloudSDK.Me.ListAddresses()
                    .then(function(addresses) {
                        var shippingAddress = _.where(addresses.Items, {CompanyName: parameters.group});
                        parameters.filters = {ShippingAddressID: shippingAddress[0].ID, Status: parameters.status};
                        return OrderCloudSDK.Orders.List('Outgoing', parameters);
                    });
            } else {
                return [];
            }
        }

        // list orders with generated parameters
        if(parameters.tab === 'approvals') {
            return OrderCloudSDK.Me.ListApprovableOrders(parameters);
        } else if(parameters.tab === 'all') {
            return OrderCloudSDK.Orders.List('outgoing', parameters);
        } else {
            return OrderCloudSDK.Me.ListOrders(parameters);
        }
    }

    return service;
}
{'fraction_non_alphanumeric': 0.11857774753317454, 'fraction_numerical': 0.003062266076896904, 'mean_word_length': 2.135466666666667, 'pattern_counts': {'":': 0, '<': 7, '<?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': '407933', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1491, 'n_words': 308}