403Webshell
Server IP : 103.234.187.230  /  Your IP : 216.73.216.216
Web Server : Apache
System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/b2c.hellogtx.com/public/js/ng/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/b2c.hellogtx.com/public/js/ng/flight_search_new.js
app.filter('sumOfValue', function () {
    return function (data, key) {
        if (angular.isUndefined(data) || angular.isUndefined(key))
            return 0;
        var sum = 0;
        angular.forEach(data, function (value) {
            sum = sum + parseInt(value[key], 10);
        });
        return sum;
    }
});

app.filter('replace', [function () {
    return function (input, from, to) {
        if (input === undefined) {
            return;
        }
        var regex = new RegExp(from, 'g');
        return input.replace(regex, to);
    };
}]);
app.filter('abs', function () {
    return function (input) {
        return Math.abs(input);
    };
});
// jyt comment this code
app.filter('dynamicFilter', function () {
    return function (FlightData, filterCategories, scope) {
        var filtered = [];

        var productFilters = _.filter(filterCategories, function (fc) {
            return _.any(fc.options, { 'IsIncluded': true });
        });
        _.each(FlightData, function (prod) {
            if (prod) {
                var includeProduct = true;
                _.each(productFilters, function (filter) {
                    var props = _.filter(prod.flt, { 'name': filter.name });
                    if (!_.any(props, function (prop) { return _.any(filter.options, { 'value': prop.value, 'IsIncluded': true }); })) {
                        includeProduct = false;
                    }
                });
                if (includeProduct) {
                    filtered.push(prod);
                }
            }
            
        });
        return filtered;
    };
});
app.controller("FlightListingController", ['$scope', '$http', '$location', '$filter', '$window','$q', function ($scope, $http, $location, $filter, $window,$q) {

    //    var url = SITEURL+"public/data/dynamic/finalresultflight.json";
    var url = SITEURL + "flight/getflightsearch";
    //    alert(url);
    $scope.loadingFlight = true;
    $scope.loadingFlightMore = true;
    $scope.loadingFareRules = true;
    $scope.FilterloadingFlight = true;
    $scope.totalFlightsOutbound = 0;
    $scope.totalFlightsInbound = 0;
    $scope.allTotalFlightsOutbound = 1;
    $scope.totalFlights = 0;
    $scope.limit = 0;
    $scope.limitRound = 0;
    $scope.roundtrip = [];
    $scope.roundtrip2 = [];
    $scope.orderByFlight = '';
    $scope.orderByFlight2 = '';
    $scope.filter = {};
    $scope.reverse = false;
    $scope.reverseR = false;
    $scope.PublishedFare = 'PublishedFare';
    $scope.PublishedFareRound = 'PublishedFare';
    $scope.categories = ['AirlineName'];
    $scope.AirlineName = [];
    $scope.AirlineName__ = [];
    $scope.FiltStopCount = [];
    $scope.ArrPriceUnique = [];
    $scope.class_status = false;

    $scope.searchids = [];
    $scope.resultsetFullOut = [];
    $scope.listOutbound = [];
    $scope.flightlistOutbound = [];
    $scope.Minprice = [];
    $scope.Maxprice = [];
    $scope.MinpriceArr = [];
    $scope.MaxpriceArr = [];
    $scope.MinriceRange = null; // Start with very large number
    $scope.MaxriceRange = null; // Start with 0
    $scope.flightlistInbound = [];
    var absUrl = $location.absUrl();
    var sURLVariables = absUrl.split('?');
    var params = $window.location.search.split('?')[1].split('&');
    var searchids = $location.path();
    var queryString = new Array();
    if ($window.location.search.split('?').length > 1) {
        var params = $window.location.search.split('?')[1].split('&');
        for (var i = 0; i < params.length; i++) {
            var key = params[i].split('=')[0];
            var value = decodeURIComponent(params[i].split('=')[1]);
            queryString[key] = value;
        }
    }
    var data = $("#sessionFlightSearchParams").val();
    var SearchParams = JSON.parse(data);
    console.log("SearchParams==",SearchParams);
    $scope.source_city = (SearchParams.source_city && SearchParams.source_city) || '';
    $scope.destination_city = (SearchParams.destination_city && SearchParams.destination_city) || '';
    $scope.destination = (SearchParams.destination && SearchParams.destination) || '';
    $scope.source = (SearchParams.source && SearchParams.source) || '';
    $scope.strDepatureDate = (SearchParams.strDepatureDate && SearchParams.strDepatureDate) || '';
    $scope.activeCancellers = [];
    $scope.loadingBookNow = false;
    console.log("source_city==",$scope.source_city);
    console.log("destination_city==",$scope.destination_city);
    console.log("source==",$scope.source);
    // Function to get unique values
    function getUniqueAirlines(array) {
        return array.filter(function(item, pos) {
            return array.indexOf(item) === pos;
        });
    }
    function removeDuplicateFlights(flightList) {
        console.log("flightList==",flightList.length);
        if (!flightList || flightList.length === 0) {
            return [];
        }
        var seen = {};
        var uniqueFlights = [];
       
        angular.forEach(flightList, function (flight) {
                // Create unique key from FromUTCTime + ToUTCTime + FlightNumber
                var newKey = flight.FromUTCTime + '' + flight.ToUTCTime + '' + flight.FlightNumber + '' + flight.ICSourceSysId;
                    // console.log("newKey===",newKey);
                
                if (!seen[newKey]) {
                    seen[newKey] = true;
                    uniqueFlights.push(flight);
                    // console.log("seen===",seen);
                } else {
                    // console.log('Duplicate removed:', flight.FlightNumber, 'From:', flight.FromUTCTime, 'To:', flight.ToUTCTime);
                }
        });

        return uniqueFlights;
    }
    var BulkData = [];
    $scope.cancelAllRequests = function() {
         if ($scope.activeCancellers && $scope.activeCancellers.length > 0) {
            angular.forEach($scope.activeCancellers, function(canceller) {
                if (canceller) {
                    canceller.resolve('Request cancelled by user');
                }
            });
            $scope.activeCancellers = [];
        }
    };
    $scope.$on('$destroy', function() {
        $scope.cancelAllRequests();
    });
    if (queryString["searchids"] != null) {
        $scope.cancelAllRequests();
        $scope.searchids = queryString["searchids"].split(',');
        var index = 1;
        angular.forEach($scope.searchids, function (value, key) {
            var canceller = $q.defer();
            $scope.activeCancellers.push(canceller);

            $http({
                method: "POST",
                url: url,
                data: 'searchid=' + value + '&' + sURLVariables[1],
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'X-Requested-With': 'XMLHttpRequest'
                },
                timeout: canceller.promise
            }).then(function successCallback(response) {
                  var idx = $scope.activeCancellers.indexOf(canceller);
                if (idx > -1) {
                    $scope.activeCancellers.splice(idx, 1);
                }

                $scope.flightlistOutboundfull = response.data.outbound;
                $scope.listInbound = response.data.inbound;
                if ((response.data.route === '2') && response.data.interNationalSearch === '1') {
                    // if ((response.data.route === '1' || response.data.route === '2') && response.data.interNationalSearch === '1'&& response.data.FlightType != '2' && response.data.FlightType != '1') {
                    $scope.listOutbound = response.data.outboundCombine;
                } else {
                    $scope.listOutbound = response.data.outbound;
                }
                if(response.data.outbound.length > 0){
                    $scope.flightlistOutbound = $scope.resultsetFullOut = $scope.listOutbound.concat($scope.flightlistOutbound);
                    if(response.data.outbound[0].ICSourceSysId != 17 && response.data.route != 3){
                        $scope.flightlistOutbound = $scope.resultsetFullOut = removeDuplicateFlights($scope.flightlistOutbound);
                    }
               
                }
                if(response.data.inbound.length > 0){
                    $scope.flightlistInbound = $scope.resultsetFullInb =  $scope.listInbound.concat($scope.flightlistInbound);
                     // THEN deduplicate ONLY AFTER concat
                      if(response.data.outbound[0].ICSourceSysId != 17){
                             $scope.flightlistInbound = $scope.resultsetFullInb = removeDuplicateFlights($scope.flightlistInbound);
                      }

                }
                // if (key == 0) {
                if ($scope.flightlistOutbound.length > 0 ) {
                    $scope.loadingFlight = false;
                    $scope.FilterloadingFlight = false;
                }
                if ((response.data.route === '2') && response.data.interNationalSearch === '') {
                    var AirlinesName = [];
                    if ($scope.flightlistOutbound.length > 0) {
                        var resultsetFilteredOut = [];
                        $.each($scope.flightlistOutbound, function (index, element_sp) {
                            var FareArrOut = [];
                            var Ismatched = false;
                            var element_sp1 = element_sp;
                            if (element_sp1.FairRules.length > 0) {
                                $.each(element_sp1.FairRules, function (indexinn, Fare) {
                                    if (Fare.fareIdentifier != 'SPECIAL RETURN') {
                                        FareArrOut.push(Fare);
                                    } else {
                                        Ismatched = true;
                                    }
                                });
                            }
                            element_sp1['FairRules'] = FareArrOut;
                            resultsetFilteredOut.push(element_sp1);
                            if (Ismatched) {
                                AirlinesName.push(element_sp.AirlineName);
                            }
                        });
                        $scope.flightlistOutbound = $scope.resultsetFullOut = resultsetFilteredOut;
                    }
                    if ($scope.flightlistInbound.length > 0) {
                         var resultsetFilteredInb = [];
                         $.each($scope.flightlistInbound, function (index, element_sp) {
                            if (!element_sp) {
                                console.warn(`⚠️ Skipping index ${index} - undefined flight`);
                                return true;  // Continue to next iteration (like continue in for loop)
                            }
                            // Now element_sp is guaranteed to NOT be undefined
                       
                            if (element_sp.FairRules && Array.isArray(element_sp.FairRules)) {
                                var FareArrOut = [];

                                $.each(element_sp.FairRules, function (indexinn, Fare) {
                                    if (Fare && Fare.fareIdentifier !== 'SPECIAL RETURN') {
                                        FareArrOut.push(Fare);
                                    }
                                });

                                element_sp.FairRules = FareArrOut;
                            } else {
                                element_sp.FairRules = [];
                            }

                            resultsetFilteredInb.push(element_sp);
                           
                    });
                        $scope.flightlistInbound = $scope.resultsetFullInb = resultsetFilteredInb;
                    }
                }
                

               
                $scope.outboundList = $scope.outboundCombineFull = response.data.outbound;
                $scope.outboundCombineList = $scope.outboundCombineFull = response.data.outboundCombine;
                $scope.totalFlightsOutbound = response.data.outbound.length;
                $scope.totalFlightsInbound = response.data.inbound.length;
                $scope.interNationalSearch = response.data.interNationalSearch;
                $scope.route = response.data.route;
                $scope.DepartDateArr = response.data.DepartDateArr;
                $scope.travelDates = response.data.travelDates;
                $('.filterbox').show();
                $('.filter-title').show();

                if (dvc === 'm') {
                    $('.mobile_footer_bottomcontinuefixed').show();
                }

                if ((response.data.route === '2') && response.data.interNationalSearch === '') {
                    $('.roundtripbox').show();
                    $('.select_flight_result').show();
                    setTimeout(function () {
                        $('.round-mb-cls-footer').show();
                    }, 2000);
                }
                // no need this data now
                // $scope.arrAirlineName = response.data.arrAirlineName;
                // $scope.AirlineName__ = getUniqueAirlines($scope.arrAirlineName.concat($scope.AirlineName__));
                
                // if (response.data.route !== '3') {
                //     var AName = [];
                //     angular.forEach($scope.AirlineName__, function (value, key) {
                //         var airl = value.split('-');
                //         this.push(airl);
                //     }, AName);

                //     $scope.AirlineName = AName;
                // } else {
                //     $scope.AirlineName = $scope.AirlineName__;
                //     $scope.MultiHead = response.data.MultiHead;

                //     var ANameTBO = [];
                //     // jyt comment
                //     if (response.data.outbound[0].ICSourceSysId == 3) {
                //         angular.forEach($scope.AirlineName__, function (value, key) {
                //             var airl = value.split('-');
                //             this.push(airl);
                //         }, ANameTBO);
                //     }
                //     $scope.AirlineNameTBO = ANameTBO;
                // }
                $scope.Currency = response.data.CurrencyTitle;
                $scope.FiltStopCount = response.data.FiltStopCount;
                $scope.ArrPriceUnique = response.data.ArrPriceUnique;

                if (response.data.route !== '3') {
                    if(response.data.MinriceRange >0){
                        if ($scope.MinriceRange === null || $scope.MinriceRange === 0) {
                            $scope.MinriceRange = response.data.MinriceRange;
                            $scope.MaxriceRange = response.data.MaxriceRange;
                        } else {
                            // Subsequent updates
                            $scope.MinriceRange = Math.min($scope.MinriceRange, response.data.MinriceRange);
                            $scope.MaxriceRange = Math.max($scope.MaxriceRange, response.data.MaxriceRange);
                        }
                        
                        
                        $('#priceRage').val($scope.MinriceRange + '-' + $scope.MaxriceRange);
                        $('.domestround').show();
                        $('#slide_amount').html('<span>' + response.data.CurrencyTitle + ' ' + $scope.MinriceRange + '</span> <span class="rightprice">' + response.data.CurrencyTitle + ' ' + $scope.MaxriceRange + '</span>');
        
                        $("#slider-range").slider({
                            range: true,
                            min: $scope.MinriceRange,
                            max: $scope.MaxriceRange,
                            values: [$scope.MinriceRange, $scope.MaxriceRange],
                            slide: function (event, ui) {
                                $("#slide_amount").html('<span>' + response.data.CurrencyTitle + ' ' + ui.values[0] + "</span> <span class='rightprice'>" + response.data.CurrencyTitle + ' ' + ui.values[1] + '</span>');

                                // Get values
                                var min = ui.values[0];
                                var max = ui.values[1];
                                $('#priceRage').val(min + '-' + max);
                                $scope.MinriceRange = min;
                                $scope.MaxriceRange = max;
                            }
                        });
                    }
                } else {

                    setTimeout(function () {
                        angular.forEach($scope.ArrPriceUnique, function (itemval, keys) {
                            $scope.MinriceRange = itemval.MinriceRange;
                            $scope.MaxriceRange = itemval.MaxriceRange;
                            $('#priceRage' + keys).val($scope.MinriceRange + '-' + $scope.MaxriceRange);
                            $('.domestround').show();
                            $('#slide_amount' + keys).html('<span>' + response.data.CurrencyTitle + ' ' + $scope.MinriceRange + '</span> <span class="rightprice">' + response.data.CurrencyTitle + ' ' + $scope.MaxriceRange + '</span>');

                            $("#slider-range" + keys).slider({
                                range: true,
                                min: $scope.MinriceRange,
                                max: $scope.MaxriceRange,
                                values: [$scope.MinriceRange, $scope.MaxriceRange],
                                slide: function (event, ui) {
                                    $("#slide_amount" + keys).html('<span>' + response.data.CurrencyTitle + ' ' + ui.values[0] + "</span> <span class='rightprice'>" + response.data.CurrencyTitle + ' ' + ui.values[1] + '</span>');

                                    // Get values
                                    var min = ui.values[0];
                                    var max = ui.values[1];
                                    $("#PriceRangeData" + keys).val(min + '_' + max);
                                    $scope.MinriceRange = min;
                                    $scope.MaxriceRange = max;
                                    $scope.filterDataMult(keys);
                                }
                            });
                        });
                    }, 1000);
                }

                if (response.data.route === '3') {
                    setTimeout(function () {

                        $scope.MinriceRange = response.data.MinriceRange;
                        $scope.MaxriceRange = response.data.MaxriceRange;
                        $('#priceRage').val($scope.MinriceRange + '-' + $scope.MaxriceRange);
                        $('.domestround').show();
                        $('#slide_amount').html('<span>' + response.data.CurrencyTitle + ' ' + $scope.MinriceRange + '</span> <span class="rightprice">' + response.data.CurrencyTitle + ' ' + $scope.MaxriceRange + '</span>');
                        
                        $("#slider-range").slider({
                            range: true,
                            min: $scope.MinriceRange,
                            max: $scope.MaxriceRange,
                            values: [$scope.MinriceRange, $scope.MaxriceRange],
                            slide: function (event, ui) {
                                $("#slide_amount").html('<span>' + response.data.CurrencyTitle + ' ' + ui.values[0] + "</span> <span class='rightprice'>" + response.data.CurrencyTitle + ' ' + ui.values[1] + '</span>');

                                // Get values
                                var min = ui.values[0];
                                var max = ui.values[1];
                                $('#priceRage').val(min + '-' + max);
                                $scope.MinriceRange = min;
                                $scope.MaxriceRange = max;
                            }
                        });
                    }, 1000);
                }
                // add daynamic filters regarding to flight search
               if ($scope.flightlistOutbound.length > 0) {
                    var filters = [];
                    var filtersInb = [];
                    
                    if ($scope.route == 3) {
                        _.each($scope.flightlistOutbound, function (values) {
                            if (values.FromUTCTime) {
                                values.FromDateSort = new Date(values.FromUTCTime);
                            } else {
                                values.FromDateSort = null;
                            }
                            $scope.ICSourceSysId = (typeof values.ICSourceSysId !== 'undefined')
                                ? values.ICSourceSysId
                                : values[0].ICSourceSysId;

                            if (values && values.ICSourceSysId == 3) {
                                if (values.SegPro) {
                                    _.each(values.SegPro, function (values__) {
                                        _.each(values__.flt, function (property) {
                                            // REPLACED: _.find with _.find
                                            var existingFilter = _.find(filters, { name: property.name });
                                            if (existingFilter) {
                                                // REPLACED: _.find with _.find
                                                var existingOption = _.find(existingFilter.options, { value: property.value });
                                                if (existingOption) {
                                                    existingOption.count += 1;
                                                } else {
                                                    existingFilter.options.push({ value: property.value, count: 1 });
                                                }
                                            } else {
                                                var filter = {};
                                                filter.name = property.name;
                                                filter.options = [];
                                                filter.options.push({ value: property.value, count: 1 });
                                                filters.push(filter);
                                            }
                                        });
                                    });
                                }
                            } else if (values && values.ICSourceSysId == 7 && response.data.interNationalSearch == 1) {
                                if (values.FD) {
                                    _.each(values.FD, function (values__) {
                                        _.each(values__.flt, function (property) {
                                            // REPLACED: _.find with _.find
                                            var existingFilter = _.find(filters, { name: property.name });
                                            if (existingFilter) {
                                                // REPLACED: _.find with _.find
                                                var existingOption = _.find(existingFilter.options, { value: property.value });
                                                if (existingOption) {
                                                    existingOption.count += 1;
                                                } else {
                                                    existingFilter.options.push({ value: property.value, count: 1 });
                                                }
                                            } else {
                                                var filter = {};
                                                filter.name = property.name;
                                                filter.options = [];
                                                filter.options.push({ value: property.value, count: 1 });
                                                filters.push(filter);
                                            }
                                        });
                                    });
                                }
                            } else if (Array.isArray(values) && response.data.interNationalSearch != 1) {
                                $scope.Filters__ = {};

                                _.each($scope.flightlistOutbound, function (values, index) {
                                    var filterGroup = [];
                                    if (values) {
                                        _.each(values, function (flightOption) {
                                            if (flightOption.flt) {
                                                _.each(flightOption.flt, function (fltItem) {
                                                    var exists = _.find(filterGroup, function (item) {
                                                        return item.name === fltItem.name && item.value === fltItem.value;
                                                    });
                                                    if (!exists) {
                                                        filterGroup.push({
                                                            name: fltItem.name,
                                                            value: fltItem.value
                                                        });
                                                    }
                                                });
                                            }
                                        });
                                    }
                                    var groupedFilters = [];
                                    _.each(_.groupBy(filterGroup, 'name'), function (items, name) {
                                        groupedFilters.push({
                                            name: name,
                                            options: _.map(items, function (i) {
                                                return { value: i.value, IsIncluded: false, count: 1 };
                                            })
                                        });
                                    });
                                    $scope.Filters__[index] = groupedFilters;
                                });
                            }
                        });
                    } else {
                        _.each($scope.flightlistOutbound, function (values) {
                            if (values.FromUTCTime) {
                                values.FromDateSort = new Date(values.FromUTCTime);
                            } else {
                                values.FromDateSort = null;
                            }
                            $scope.ICSourceSysId = (typeof values.ICSourceSysId !== 'undefined')
                                ? values.ICSourceSysId
                                : values[0].ICSourceSysId;
                            
                            if ($scope.ICSourceSysId == 8) {
                                $scope.PublishedFare = 'FromDateSort';
                            }
                            
                            if (values) {
                                if (values.JourneyType == 2 && values.IsInternational == 1) {
                                    if (values.origin.flt) {
                                        _.each(values.origin.flt, function (property) {
                                            // REPLACED: _.find with _.find
                                            var existingFilter = _.find(filters, { name: property.name });
                                            if (existingFilter) {
                                                // REPLACED: _.find with _.find
                                                var existingOption = _.find(existingFilter.options, { value: property.value });
                                                if (existingOption) {
                                                    existingOption.count += 1;
                                                } else {
                                                    existingFilter.options.push({ value: property.value, count: 1 });
                                                }
                                            } else {
                                                var filter = {};
                                                filter.name = property.name;
                                                filter.options = [];
                                                filter.options.push({ value: property.value, count: 1 });
                                                filters.push(filter);
                                            }
                                        });
                                    }
                                    if (values.destination.flt) {
                                        _.each(values.destination.flt, function (property) {
                                            // REPLACED: _.find with _.find
                                            var existingFilter = _.find(filtersInb, { name: property.name });
                                            if (existingFilter) {
                                                // REPLACED: _.find with _.find
                                                var existingOption = _.find(existingFilter.options, { value: property.value });
                                                if (existingOption) {
                                                    existingOption.count += 1;
                                                } else {
                                                    existingFilter.options.push({ value: property.value, count: 1 });
                                                }
                                            } else {
                                                var filter = {};
                                                filter.name = property.name;
                                                filter.options = [];
                                                filter.options.push({ value: property.value, count: 1 });
                                                filtersInb.push(filter);
                                            }
                                        });
                                    }
                                } else {
                                    if (values.flt) {
                                        _.each(values.flt, function (property) {
                                            // REPLACED: _.find with _.find
                                            var existingFilter = _.find(filters, { name: property.name });
                                            if (existingFilter) {
                                                // REPLACED: _.find with _.find
                                                var existingOption = _.find(existingFilter.options, { value: property.value });
                                                if (existingOption) {
                                                    existingOption.count += 1;
                                                } else {
                                                    existingFilter.options.push({ value: property.value, count: 1 });
                                                }
                                            } else {
                                                var filter = {};
                                                filter.name = property.name;
                                                filter.options = [];
                                                filter.options.push({ value: property.value, count: 1 });
                                                filters.push(filter);
                                            }
                                        });
                                    }
                                }
                            }
                        });
                    }

                    if (($scope.route == 3 && $scope.ICSourceSysId == 7 && response.data.interNationalSearch == '')) {
                        // Empty condition
                    } else if (data.MinriceRange > 0) {
                        if ($scope.MinriceRange === null || $scope.MinriceRange === 0) {
                            $scope.MinriceRange = data.MinriceRange;
                            $scope.MaxriceRange = data.MaxriceRange;
                        } else {
                            $scope.MinriceRange = Math.min($scope.MinriceRange, data.MinriceRange);
                            $scope.MaxriceRange = Math.max($scope.MaxriceRange, data.MaxriceRange);
                        }
                        
                        var currency = (data.outbound &&
                            data.outbound[0] &&
                            data.outbound[0].FairRules &&
                            data.outbound[0].FairRules[0] &&
                            data.outbound[0].FairRules[0].Currency)
                            ? data.outbound[0].FairRules[0].Currency
                            : 'INR';
                        
                        $('#priceRange').html('<span>' + currency + ' ' + $scope.MinriceRange + '</span> <span class="rightprice">' + currency + ' ' + $scope.MaxriceRange + '</span>');
                        
                        $("#slider-range").slider({
                            range: true,
                            min: $scope.MinriceRange,
                            max: $scope.MaxriceRange,
                            values: [$scope.MinriceRange, $scope.MaxriceRange],
                            slide: function (event, ui) {
                                $("#priceRange").html('<span>' + currency + ' ' + ui.values[0] + "</span> <span class='rightprice'>" + currency + ' ' + ui.values[1] + '</span>');
                                $scope.MinriceRange = ui.values[0];
                                $scope.MaxriceRange = ui.values[1];
                            }
                        });
                    }
                }

                if (response.data.interNationalSearch == '' && $scope.route == 3 && $scope.ICSourceSysId == 7) {
                    setTimeout(function () {
                        $('.routeBottomDiv').show();
                    }, 1000);
                }

              
                if ($scope.flightlistInbound.length > 0) {
                    // filterdata
                    let dataSlice = $scope.flightlistInbound.filter(function (item) {
                        // Filter only items where FairRules exists and has at least one item
                        return item.FairRules && item.FairRules.length > 0;
                    }).sort(function (a, b) {
                        return parseInt(a.FairRules[0].PublishedFare) - parseInt(b.FairRules[0].PublishedFare);
                    });

                    // Take first 15 items
                    let outDataR = dataSlice.slice(0, 15);

                    // Sort again by PublishedFare (optional if already sorted)
                    outDataR.sort(function (a, b) {
                        return parseInt(a.FairRules[0].PublishedFare) - parseInt(b.FairRules[0].PublishedFare);
                    });
                    // Set the cheapest flight
                    $scope.selectedCheapestDataRetrun = outDataR[0];
                    // Get the fastest flight
                    let fastestDataR = $scope.flightlistInbound.sort(function (a, b) {
                        return $scope.parseDuration(a.FlightDuration) - $scope.parseDuration(b.FlightDuration);
                    });
                    // Set fastest flight
                    $scope.selectedFastestDataReturn = fastestDataR[0];

                    _.each($scope.flightlistInbound, function (values) {
                        if (values) {
                            if (values.flt) {
                                _.each(values.flt, function (property) {
                                    var existingFilter = _.find(filtersInb, { name: property.name });
                                    if (existingFilter) {
                                        var existingOption = _.find(existingFilter.options, { value: property.value });
                                        if (existingOption) {
                                            existingOption.count += 1;
                                        } else {
                                            existingFilter.options.push({ value: property.value, count: 1 });
                                        }
                                    } else {
                                        var filter = {};
                                        filter.name = property.name;
                                        filter.options = [];
                                        filter.options.push({ value: property.value, count: 1 });
                                        filtersInb.push(filter);
                                    }
                                });
                            }
                        }
                    });
                }
                // Sort and assign FiltersInb
                if (filtersInb && filtersInb.length > 0) {
                    filtersInb = _.map(filtersInb, function(filter) {
                        filter.options = _.sortBy(filter.options, function(option) {
                            var timeValue = option.value.split(':')[0];
                            return parseInt(timeValue);
                        });
                        return filter;
                    });
                }

                // Sort and assign filters
                if (filters && filters.length > 0) {
                    filters = _.map(filters, function(filter) {
                        filter.options = _.sortBy(filter.options, function(option) {
                            var timeValue = option.value.split(':')[0];
                            return parseInt(timeValue);
                        });
                        return filter;
                    });
                }

                // Assign to scope AFTER sorting
                $scope.Filters = filters;
                $scope.FiltersInb = filtersInb;
               
                if (data.route == 1) {
                    var AirlinemergedArray = [...new Set($scope.AirlineName.flat())];
                    var Airlinemerged = AirlinemergedArray.map(item => (item.split('-')[1]));
                    var AirlineNew = [];
                    if (Airlinemerged) {
                        _.each(Airlinemerged, function (property) {
                            AirlineNew.push({ value: property });
                        });
                    }
                    $scope.Airlinemerged = [AirlineNew];
                } else {
                    $scope.Airlinemerged = $scope.AirlineName;
                }
            }, function errorCallback(response) {

            }).finally(function () {
                console.log('finally');
                // if (key == 0) {
                // if ($scope.flightlistOutbound.length > 0 ) {
                //     $scope.loadingFlight = false;
                //     $scope.FilterloadingFlight = false;
                // }
                 
                if ($scope.searchids.length === index) {
                    $scope.loadingFlightMore = false;
                    $scope.allTotalFlightsOutbound = $scope.flightlistOutbound.length;
                    if ($scope.flightlistOutbound.length == 0 ) {
                        $scope.loadingFlight = false;
                        $scope.FilterloadingFlight = false;
                    }
                }
                console.log("scope.searchids.length", $scope.searchids.length);
                console.log("index",index);
                console.log("Final loadingFlightMore===", $scope.loadingFlightMore);
                index++;
                
                $scope.hotelType = 'Standard';
                $scope.orderby = 'Price';
                $scope.orderval = false;
                $scope.limit = 15; // total result
                $scope.limitRound = 15; // total result
                $scope.totalFlightsOutbound = $scope.flightlistOutbound.length; // total result
                $scope.totalFlightsInbound = $scope.flightlistInbound.length; // total result
               
                
            });
        }, BulkData);
    }
    
console.log("Final loadingFlightMore===", $scope.loadingFlightMore);
    // $http({
    //     method: "POST",
    //     url: url,
    //     data: sURLVariables[1],
    //     headers: {
    //         'Content-Type': 'application/x-www-form-urlencoded',
    //         'X-Requested-With': 'XMLHttpRequest'
    //     }
    // }).then(function successCallback(response) {
    //     $scope.loadingFlight = false;
    //     $scope.FilterloadingFlight = false;
    //     $scope.flightlistOutboundfull = response.data.outbound;
    //     if ((response.data.route === '2') && response.data.interNationalSearch === '1') {
    //         // if ((response.data.route === '1' || response.data.route === '2') && response.data.interNationalSearch === '1'&& response.data.FlightType != '2' && response.data.FlightType != '1') {
    //         $scope.flightlistOutbound = $scope.resultsetFullOut = response.data.outboundCombine;
    //     } else {
    //         $scope.flightlistOutbound = $scope.resultsetFullOut = response.data.outbound;
    //     }

    //     $scope.flightlistInbound = $scope.resultsetFullInb = response.data.inbound;
    //     $scope.outboundList = $scope.outboundCombineFull = response.data.outbound;
    //     $scope.outboundCombineList = $scope.outboundCombineFull = response.data.outboundCombine;
    //     $scope.totalFlightsOutbound = response.data.outbound.length;
    //     $scope.totalFlightsInbound = response.data.inbound.length;
    //     $scope.interNationalSearch = response.data.interNationalSearch;
    //     $scope.route = response.data.route;
    //     $scope.DepartDateArr = response.data.DepartDateArr;
    //     $scope.travelDates = response.data.travelDates;
    //     $('.filterbox').show();
    //     $('.filter-title').show();

    //     if (dvc === 'm') {
    //         $('.mobile_footer_bottomcontinuefixed').show();
    //     }

    //     if ((response.data.route === '2') && response.data.interNationalSearch === '') {
    //         $('.roundtripbox').show();
    //         $('.select_flight_result').show();
    //         setTimeout(function () {
    //             $('.round-mb-cls-footer').show();
    //         }, 2000);
    //     }
    //     if (response.data.route !== '3') {
    //         var AName = [];
    //         angular.forEach(response.data.arrAirlineName, function (value, key) {
    //             var airl = value.split('-');
    //             this.push(airl);
    //         }, AName);

    //         $scope.AirlineName = AName;
    //     } else {
    //         $scope.AirlineName = response.data.arrAirlineName;
    //         $scope.MultiHead = response.data.MultiHead;

    //         var ANameTBO = [];
    //         // jyt comment
    //         if (response.data.outbound[0].ICSourceSysId == 3) {
    //             angular.forEach(response.data.arrAirlineName, function (value, key) {
    //                 var airl = value.split('-');
    //                 this.push(airl);
    //             }, ANameTBO);
    //         }
    //         $scope.AirlineNameTBO = ANameTBO;
    //     }
    //     $scope.Currency = response.data.CurrencyTitle;
    //     $scope.FiltStopCount = response.data.FiltStopCount;
    //     $scope.ArrPriceUnique = response.data.ArrPriceUnique;

    //     if (response.data.route !== '3') {
    //         $scope.MinriceRange = response.data.MinriceRange;
    //         $scope.MaxriceRange = response.data.MaxriceRange;
    //         $scope.FXMinriceRange = response.data.MinriceRange;
    //         $scope.FXMaxriceRange = response.data.MaxriceRange;
    //         $('#priceRage').val($scope.MinriceRange + '-' + $scope.MaxriceRange);
    //         $('.domestround').show();
    //         $('#slide_amount').html('<span>' + response.data.CurrencyTitle + ' ' + $scope.MinriceRange + '</span> <span class="rightprice">' + response.data.CurrencyTitle + ' ' + $scope.MaxriceRange + '</span>');
    //         //console.log($scope.MinriceRange);
    //         //console.log($scope.MaxriceRange);
    //         $("#slider-range").slider({
    //             range: true,
    //             min: $scope.MinriceRange,
    //             max: $scope.MaxriceRange,
    //             values: [$scope.MinriceRange, $scope.MaxriceRange],
    //             slide: function (event, ui) {
    //                 $("#slide_amount").html('<span>' + response.data.CurrencyTitle + ' ' + ui.values[0] + "</span> <span class='rightprice'>" + response.data.CurrencyTitle + ' ' + ui.values[1] + '</span>');

    //                 // Get values
    //                 var min = ui.values[0];
    //                 var max = ui.values[1];
    //                 $('#priceRage').val(min + '-' + max);
    //                 $scope.MinriceRange = min;
    //                 $scope.MaxriceRange = max;
    //             }
    //         });
    //     } else {

    //         setTimeout(function () {
    //             angular.forEach($scope.ArrPriceUnique, function (itemval, keys) {
    //                 $scope.MinriceRange = itemval.MinriceRange;
    //                 $scope.MaxriceRange = itemval.MaxriceRange;
    //                 $('#priceRage' + keys).val($scope.MinriceRange + '-' + $scope.MaxriceRange);
    //                 $('.domestround').show();
    //                 $('#slide_amount' + keys).html('<span>' + response.data.CurrencyTitle + ' ' + $scope.MinriceRange + '</span> <span class="rightprice">' + response.data.CurrencyTitle + ' ' + $scope.MaxriceRange + '</span>');

    //                 $("#slider-range" + keys).slider({
    //                     range: true,
    //                     min: $scope.MinriceRange,
    //                     max: $scope.MaxriceRange,
    //                     values: [$scope.MinriceRange, $scope.MaxriceRange],
    //                     slide: function (event, ui) {
    //                         $("#slide_amount" + keys).html('<span>' + response.data.CurrencyTitle + ' ' + ui.values[0] + "</span> <span class='rightprice'>" + response.data.CurrencyTitle + ' ' + ui.values[1] + '</span>');

    //                         // Get values
    //                         var min = ui.values[0];
    //                         var max = ui.values[1];
    //                         $("#PriceRangeData" + keys).val(min + '_' + max);
    //                         $scope.MinriceRange = min;
    //                         $scope.MaxriceRange = max;
    //                         $scope.filterDataMult(keys);
    //                     }
    //                 });
    //             });
    //         }, 1000);
    //     }

    //     if (response.data.route === '3') {
    //         setTimeout(function () {

    //             $scope.MinriceRange = response.data.MinriceRange;
    //             $scope.MaxriceRange = response.data.MaxriceRange;
    //             $('#priceRage').val($scope.MinriceRange + '-' + $scope.MaxriceRange);
    //             $('.domestround').show();
    //             $('#slide_amount').html('<span>' + response.data.CurrencyTitle + ' ' + $scope.MinriceRange + '</span> <span class="rightprice">' + response.data.CurrencyTitle + ' ' + $scope.MaxriceRange + '</span>');
    //             //console.log($scope.MinriceRange);
    //             //console.log($scope.MaxriceRange);
    //             $("#slider-range").slider({
    //                 range: true,
    //                 min: $scope.MinriceRange,
    //                 max: $scope.MaxriceRange,
    //                 values: [$scope.MinriceRange, $scope.MaxriceRange],
    //                 slide: function (event, ui) {
    //                     $("#slide_amount").html('<span>' + response.data.CurrencyTitle + ' ' + ui.values[0] + "</span> <span class='rightprice'>" + response.data.CurrencyTitle + ' ' + ui.values[1] + '</span>');

    //                     // Get values
    //                     var min = ui.values[0];
    //                     var max = ui.values[1];
    //                     $('#priceRage').val(min + '-' + max);
    //                     $scope.MinriceRange = min;
    //                     $scope.MaxriceRange = max;
    //                 }
    //             });
    //         }, 1000);
    //     }

    // }, function errorCallback(response) {

    // }).finally(function () {
    //     $scope.loadingFlight = false;
    //     $scope.FilterloadingFlight = false;
    //     $scope.hotelType = 'Standard';
    //     $scope.orderby = 'Price';
    //     $scope.orderval = false;
    //     $scope.limit = 15; // total result
    //     $scope.limitRound = 15; // total result
    //     $scope.totalFlightsOutbound = $scope.flightlistOutbound.length; // total result
    //     $scope.totalFlightsInbound = $scope.flightlistInbound.length; // total result
    //     //$scope.AirlineName = $scope.searchInResponseForFilter( $scope.flightlistOutbound , $scope.AirlineName , 'AirlineName' );
    //     //console.log($scope.AirlineName);


    // });
    $scope.uniqueItems = function (items, key, PublishedFare) {
        var unique = {};
        var uniqueItems = [];
        angular.forEach(items, function (item) {
            var value = item[key];
            var value1 = item[PublishedFare];
            var combinedKey = value + '-' + value1;
            if (!unique[combinedKey]) {
                unique[combinedKey] = true;
                uniqueItems.push(item);
            }
        });
        return uniqueItems;
    };
    // needed to added b2b like filter
     $scope.parseDuration = function (duration) {
        if (!duration) return 0;

        var parts = duration.split(' ');
        var totalMinutes = 0;

        parts.forEach(function (part) {
            if (part.includes('h')) {
                totalMinutes += parseInt(part) * 60;
            }
            if (part.includes('m')) {
                totalMinutes += parseInt(part);
            }
        });

        return totalMinutes;
    };
    $scope.ChangeView = function () {
        $('.ChangeView').toggleClass('combineview');
        if ($('.ChangeView').hasClass('combineview')) {
            $scope.flightlistOutbound = $scope.outboundList;
        } else {
            $scope.flightlistOutbound = $scope.outboundCombineList;
        }
    };
    $scope.getCircularReplacer = function () {
        const seen = new WeakSet();
        return (key, value) => {
            if (typeof value === "object" && value !== null) {
                if (seen.has(value)) {
                    return;
                }
                seen.add(value);
            }
            return value;
        };
    };
    $scope.CombineSelect = function (PriceId, index) {
        //console.log(index);
        var resultsetFiltered = new Array();
        $.each($scope.flightlistOutbound, function (ind, elements) {
            var selectedItem = new Array();
            $.each(elements.CombineTripInfo, function (inde, element) {

                if (element.FairRules[0].PriceID == PriceId) {
                    element['CombineTripInfo'] = [];
                    selectedItem.push(element);
                }
            });

            if (elements.keyIndex == index) {
                var TempEl = [];
                $.each(elements.CombineTripInfo, function (key, value) {
                    value['CombineTripInfo'] = [];
                    TempEl.push(value);
                });
                selectedItem[0]['CombineTripInfo'] = TempEl;
                resultsetFiltered.push(selectedItem[0]);
            } else {
                resultsetFiltered.push(elements);
            }
        });
        //console.log(resultsetFiltered);
        $scope.flightlistOutbound = resultsetFiltered;

    };
    $scope.changeMaxSlider = function () {
        //console.log('ffff');
    };


    $scope.priceRange = function (item) {
        // var resultsetFiltered = [];

        // $.each(item.FairRules, function (index, element) {
        //     console.log(element.PublishedFare);
        //     //return (parseInt(element.PublishedFare) >= $scope.MinriceRange && parseInt(element.PublishedFare) <= $scope.MaxriceRange);
        // });
        // return (parseInt(item['PublishedFare']) >= $scope.MinriceRange && parseInt(item['PublishedFare']) <= $scope.MaxriceRange);
    };

    $scope.filterByFlightMatchingAND = function (data) {
        var matchesAND = true;
        //
        for (var obj in $scope.filter) {
            if ($scope.filter.hasOwnProperty(obj)) {
                if (noSubFilter($scope.filter[obj])) continue;
                if (!$scope.filter[obj][data[obj]]) {
                    matchesAND = false;
                    break;
                }
            }
        }
        return matchesAND;
    };

    function noSubFilter(obj) {
        for (var key in obj) {
            if (obj[key]) return false;
        }
        return true;
    };
    $scope.getItems = function (obj, array) {
        return (array || []).map(function (w) {
            return w[obj];
        }).filter(function (w, idx, arr) {
            if (typeof w === 'undefined') {
                return false;
            }
            return arr.indexOf(w) === idx;
        });
    };
    $scope.loadMoreNew = function () {
        if ($scope.loadingFlight === false) {
            if ($scope.limit + 10 < $scope.flightlistOutbound.length) {
                $scope.limit += 10;
            } else {
                $scope.limit = $scope.flightlistOutbound.length;
            }
        }
    };
    $scope.loadMoreMulti = function (keyH) {
        console.log("keyH====",keyH);
        console.log("flightlistOutbound === ",$scope.flightlistOutbound[keyH]);
        console.log("scope.loadingFlight === ",$scope.loadingFlight);
        if ($("li#liH" + keyH).hasClass("active")) {
            if ($scope.loadingFlight === false) {
                if ($scope.limit + 10 < $scope.flightlistOutbound[keyH].length) {
                    $scope.limit += 10;
                } else {
                    $scope.limit = $scope.flightlistOutbound[keyH].length;
                }
            }
            var the_string = 'multiLimit' + keyH;
            $scope[the_string] = 10;
            console.log("the_string",$scope[the_string]);
        }else{
            console.log("testing....");
            console.log($("li#liH" + keyH).hasClass("active"))
        }

       
    };
    $scope.loadMoreRound = function () {
        if ($scope.loadingFlight === false) {
            if ($scope.limitRound + 10 < $scope.flightlistInbound.length) {
                $scope.limitRound += 10;
            } else {
                $scope.limitRound = $scope.flightlistInbound.length;
            }
        }
    };

    $scope.sortBy = function (PublishedFare) {
        $scope.reverse = ($scope.PublishedFare === PublishedFare) ? !$scope.reverse : false;
        $scope.PublishedFare = PublishedFare;
        $('.onewayflight').click();
    };
    $scope.sortByRound = function (PublishedFareRound) {
        $scope.reverseR = ($scope.PublishedFareRound === PublishedFareRound) ? !$scope.reverseR : false;
        $scope.PublishedFareRound = PublishedFareRound;
        $('.twowayflight').click();
    };
    $scope.filterDataMult = function (keyH) {
        $scope.changeMaxSlider(keyH);
        var filterSTR = {
            'FiltStopCount': [],
            'AirlineName': [],
            'FilterDepartureDtTime': [],
            'Price': [],
            'FilterArrivalDtTime': [],
            'IsBagIncludes': []
        };
        angular.element('.filter-box input:checkbox').each(function () {
            if ($(this).is(":checked")) {
                if ($(this).hasClass('filter-airline' + keyH)) {
                    filterSTR.AirlineName.push($(this).val());
                } else if ($(this).hasClass('filter-stop' + keyH)) {
                    filterSTR.FiltStopCount.push($(this).val());
                } else if ($(this).hasClass('filter-times' + keyH)) {
                    filterSTR.FilterDepartureDtTime.push($(this).val());
                } else if ($(this).hasClass('filter-arrivetimes' + keyH)) {
                    filterSTR.FilterArrivalDtTime.push($(this).val());
                } else if ($(this).hasClass('filter-baggage' + keyH)) {
                    filterSTR.IsBagIncludes.push($(this).val());
                }
            }
        });
        var PriceRangeData = $('#PriceRangeData' + keyH).val();
        var PriceRange = PriceRangeData.split('_');
        if (parseInt(PriceRange[0]) !== '' && PriceRange[0] !== '') {
            filterSTR.Price.push(PriceRange);
        }

        if ((filterSTR.AirlineName.length > 0) || (filterSTR.FiltStopCount.length > 0) || (filterSTR.FilterDepartureDtTime.length > 0) || (filterSTR.FilterArrivalDtTime.length > 0) || (filterSTR.Price.length > 0) || (filterSTR.IsBagIncludes.length > 0)) {
            $scope.flightlistOutbound = this.filterFromMultiArray($scope.resultsetFullOut, filterSTR, keyH);
        } else {
            $scope.flightlistOutbound = $scope.resultsetFullOut;
        }
    };
    $scope.filterDataMultInt = function () {
        var filterSTR = {
            'AirlineName': [],
            'FiltStopCount': [],
            'FiltDepTime': [],
            'FiltArrTime': [],
            'IsBagIncludes': []
        };
        angular.element('.filter-box input:checkbox').each(function () {
            if ($(this).is(":checked")) {
                if ($(this).hasClass('filter-airline')) {
                    filterSTR.AirlineName.push($(this).val());
                } else if ($(this).hasClass('filter-stop')) {
                    filterSTR.FiltStopCount.push($(this).val());
                } else if ($(this).hasClass('filter-times')) {
                    filterSTR.FiltDepTime.push($(this).val());
                } else if ($(this).hasClass('filter-arrivetimes')) {
                    filterSTR.FiltArrTime.push($(this).val());
                } else if ($(this).hasClass('filter-baggage')) {
                    filterSTR.IsBagIncludes.push($(this).val());
                }
            }
        });
        if ((filterSTR.AirlineName.length > 0) || (filterSTR.FiltStopCount.length > 0) || (filterSTR.FiltDepTime.length > 0) || (filterSTR.FiltArrTime.length > 0) || (filterSTR.IsBagIncludes.length > 0)) {
            $scope.flightlistOutbound = this.filterFromMultiIntArray($scope.resultsetFullOut, filterSTR);
        } else {
            $scope.flightlistOutbound = $scope.resultsetFullOut;
        }
    };
    $scope.filterData = function () {
        // declare the variable here
        var filterSTR = {
            'price': [],
            'FiltStopCount': [],
            'FiltStopCountRound': [],
            'FiltStopCountRoundInt': [],
            'AirlineName': [],
            'AirlineNameReturn': [],
            'Times': [],
            'TimesReturn': [],
            'Arrivetimes': [],
            'ArrivetimesReturn': [],
            'baggage': [],
            'meals': [],
            'refundable': [],
            'TimesReturnInt': [],
            'ArrivetimesReturnInt': [],
        };
        angular.element('.filter-box input:checkbox').each(function () {
            if ($(this).is(":checked")) {
                if ($(this).hasClass('filter-airline')) {
                    filterSTR.AirlineName.push($(this).val());
                } else if ($(this).hasClass('filter-airline-return')) {
                    filterSTR.AirlineNameReturn.push($(this).val());
                } else if ($(this).hasClass('filter-stop')) {
                    filterSTR.FiltStopCount.push($(this).val());
                } else if ($(this).hasClass('filter-stop-round')) {
                    filterSTR.FiltStopCountRound.push($(this).val());
                } else if ($(this).hasClass('filter-stop-round-int')) {
                    filterSTR.FiltStopCountRoundInt.push($(this).val());
                } else if ($(this).hasClass('filter-price')) {
                    filterSTR.price.push($(this).val());
                } else if ($(this).hasClass('filter-times')) {
                    filterSTR.Times.push($(this).val());
                } else if ($(this).hasClass('filter-times-return')) {
                    filterSTR.TimesReturn.push($(this).val());
                } else if ($(this).hasClass('filter-times-return-int')) {
                    filterSTR.TimesReturnInt.push($(this).val());
                } else if ($(this).hasClass('filter-arrivetimes')) {
                    filterSTR.Arrivetimes.push($(this).val());
                } else if ($(this).hasClass('filter-arrivetimes-return')) {
                    filterSTR.ArrivetimesReturn.push($(this).val());
                } else if ($(this).hasClass('filter-arrivetimes-return-int')) {
                    filterSTR.ArrivetimesReturnInt.push($(this).val());
                } else if ($(this).hasClass('filter-baggage')) {
                    filterSTR.baggage.push($(this).val());
                } else if ($(this).hasClass('filter-meals')) {
                    filterSTR.meals.push($(this).val());
                } else if ($(this).hasClass('filter-refundable')) {
                    filterSTR.refundable.push($(this).val());
                }

            }
        });

        var filterprice = $('#priceRage').val();
        filterSTR.price.push(filterprice);


        // if filter has any value 
        if ((filterSTR.AirlineName.length > 0) || (filterSTR.FiltStopCount.length > 0) || (filterSTR.FiltStopCountRoundInt.length > 0) || (filterSTR.ArrivetimesReturnInt.length > 0) || (filterSTR.TimesReturnInt.length > 0) || (filterSTR.price.length > 0) || (filterSTR.Times.length > 0) || (filterSTR.Arrivetimes.length > 0) || (filterSTR.baggage.length > 0) || (filterSTR.meals.length > 0) || (filterSTR.refundable.length > 0)) {

            $scope.flightlistOutbound = this.filterFromArray($scope.resultsetFullOut, filterSTR);
            if ($scope.interNationalSearch == '' && $scope.route == '2') {
                $scope.flightlistInbound = this.filterFromArray($scope.resultsetFullInb, filterSTR);
            }
        } else {
            $scope.flightlistOutbound = $scope.resultsetFullOut;
            $scope.flightlistInbound = $scope.resultsetFullInb;
        }
        if ($scope.interNationalSearch == '' && $scope.route == '2') {
            if ((filterSTR.FiltStopCountRound.length > 0) || (filterSTR.price.length > 0) || (filterSTR.TimesReturn.length > 0) || (filterSTR.ArrivetimesReturn.length > 0) || (filterSTR.AirlineNameReturn.length > 0) || (filterSTR.baggage.length > 0) || (filterSTR.meals.length > 0) || (filterSTR.refundable.length > 0)) {
                if ($scope.interNationalSearch && $scope.route == '2') {
                    $scope.flightlistOutbound = this.filterFromArrayReturn($scope.resultsetFullOut, filterSTR);
                } else {
                    $scope.flightlistInbound = this.filterFromArrayReturn($scope.resultsetFullInb, filterSTR);
                }
                // $scope.flightlistInbound = this.filterFromArrayReturn($scope.resultsetFullInb, filterSTR);
            } else {
                $scope.flightlistInbound = $scope.resultsetFullInb;
            }
        }


    };

    $scope.filterFromArray = function (data, filterSTR) {
        var resultsetFiltered = [];


        resultsetFiltered = $scope.applyPriceRangeFilter(data, filterSTR.price);
        resultsetFiltered = $scope.applyStopCountFilter(resultsetFiltered, filterSTR.FiltStopCount);
        resultsetFiltered = $scope.applyStopCountFilterInt(resultsetFiltered, filterSTR.FiltStopCountRoundInt);
        resultsetFiltered = $scope.applyTimesFilter(resultsetFiltered, filterSTR.Times);
        resultsetFiltered = $scope.applyTimesReturnIntFilter(resultsetFiltered, filterSTR.TimesReturnInt);
        resultsetFiltered = $scope.applyArriveTimesFilter(resultsetFiltered, filterSTR.Arrivetimes);
        resultsetFiltered = $scope.applyArrivetimesReturnIntFilter(resultsetFiltered, filterSTR.ArrivetimesReturnInt);
        resultsetFiltered = $scope.applyAirlineFilter(resultsetFiltered, filterSTR.AirlineName);
        resultsetFiltered = $scope.applyBaggageFilter(resultsetFiltered, filterSTR.baggage);
        resultsetFiltered = $scope.applyMealsFilter(resultsetFiltered, filterSTR.meals);
        resultsetFiltered = $scope.applyRefundableFilter(resultsetFiltered, filterSTR.refundable);
        return resultsetFiltered;
    };
    $scope.filterFromMultiArray = function (data, filterSTR, keyH) {
        var resultsetFiltered = [];
        resultsetFiltered = $scope.applyStopMultiFilter(data, filterSTR.FiltStopCount, keyH);
        resultsetFiltered = $scope.applyPriceMultiFilter(resultsetFiltered, filterSTR.Price, keyH);
        resultsetFiltered = $scope.applyDepTimeMultiFilter(resultsetFiltered, filterSTR.FilterDepartureDtTime, keyH);
        resultsetFiltered = $scope.applyArrTimeMultiFilter(resultsetFiltered, filterSTR.FilterArrivalDtTime, keyH);
        resultsetFiltered = $scope.applyAirlineNameMultiFilter(resultsetFiltered, filterSTR.AirlineName, keyH);
        resultsetFiltered = $scope.applyIsBagMultiFilter(resultsetFiltered, filterSTR.IsBagIncludes, keyH);
        return resultsetFiltered;
    };
    $scope.filterFromMultiIntArray = function (data, filterSTR) {
        var resultsetFiltered = [];
        resultsetFiltered = $scope.applyStopMultiInter(data, filterSTR.FiltStopCount);
        resultsetFiltered = $scope.applyAirlineNameMultiInter(resultsetFiltered, filterSTR.AirlineName);
        resultsetFiltered = $scope.applyFiltDepTimeMultiInter(resultsetFiltered, filterSTR.FiltDepTime);
        resultsetFiltered = $scope.applyFiltArrTimeMultiInter(resultsetFiltered, filterSTR.FiltArrTime);
        resultsetFiltered = $scope.applyFiltIsBaggMultiInter(resultsetFiltered, filterSTR.IsBagIncludes);
        return resultsetFiltered;
    };

    $scope.applyPriceMultiFilter = function (data, StopArr, keyH) {
        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, elements) {
            var ChildFiltered = [];
            if (index == keyH) {
                $.each(elements, function (indexn, element) {
                    var IsMatch = false;
                    if (StopArr.length > 0) {
                        $.each(StopArr, function (indexinn, elementinn) {
                            //console.log(elementinn);
                            if ((parseInt(element.PublishedFare) >= parseInt(elementinn[0]) && parseInt(element.PublishedFare) <= parseInt(elementinn[1]))) {
                                IsMatch = true;
                            }
                        });
                    }
                    if (IsMatch) {
                        ChildFiltered.push(element);
                    }
                });
            } else {
                resultsetFiltered.push(elements);
            }
            if (ChildFiltered.length > 0) {
                resultsetFiltered.push(ChildFiltered);
            }
        });

        return resultsetFiltered;
    };
    $scope.applyStopMultiFilter = function (data, StopArr, keyH) {
        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, elements) {
            var ChildFiltered = [];
            if (index == keyH) {
                $.each(elements, function (indexn, element) {
                    var IsMatch = false;
                    if (StopArr.length > 0) {
                        $.each(StopArr, function (indexinn, elementinn) {

                            if (elementinn === element.StopCount) {
                                IsMatch = true;
                            }
                        });
                    }
                    if (IsMatch) {
                        ChildFiltered.push(element);
                    }
                });
            }
            // else {
            //     resultsetFiltered.push(elements);
            //     console.log("if part index value");
            //     console.log(index);
            //     console.log("keyH");
            //     console.log(keyH);
            //     console.log(resultsetFiltered)
            // }

            if (ChildFiltered.length > 0) {
                resultsetFiltered.push(ChildFiltered);
            } else {
                resultsetFiltered.push(ChildFiltered);
            }
        });
        return resultsetFiltered;

    };
    $scope.applyDepTimeMultiFilter = function (data, StopArr, keyH) {
        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, elements) {
            var ChildFiltered = [];
            if (index == keyH) {
                $.each(elements, function (indexn, element) {
                    var IsMatch = false;
                    if (StopArr.length > 0) {
                        $.each(StopArr, function (indexinn, elementinn) {
                            if (elementinn == element.FilterDepartureDtTime) {
                                IsMatch = true;
                            }
                        });
                    }
                    if (IsMatch) {
                        ChildFiltered.push(element);
                    }
                });
            } else {
                resultsetFiltered.push(elements);
            }
            if (ChildFiltered.length > 0) {
                resultsetFiltered.push(ChildFiltered);
            }
        });
        //data[keyH] = ChildFiltered;
        //console.log(resultsetFiltered);
        return resultsetFiltered;
    };
    $scope.applyArrTimeMultiFilter = function (data, StopArr, keyH) {
        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, elements) {
            var ChildFiltered = [];
            if (index == keyH) {
                $.each(elements, function (indexn, element) {
                    var IsMatch = false;
                    if (StopArr.length > 0) {
                        $.each(StopArr, function (indexinn, elementinn) {
                            if (elementinn == element.FilterArrivalDtTime) {
                                IsMatch = true;
                            }
                        });
                    }
                    if (IsMatch) {
                        ChildFiltered.push(element);
                    }
                });
            } else {
                resultsetFiltered.push(elements);
            }
            if (ChildFiltered.length > 0) {
                resultsetFiltered.push(ChildFiltered);
            }
        });
        //data[keyH] = ChildFiltered;
        //console.log(resultsetFiltered);
        return resultsetFiltered;
    };
    $scope.applyAirlineNameMultiFilter = function (data, StopArr, keyH) {
        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, elements) {
            var ChildFiltered = [];
            if (index == keyH) {
                $.each(elements, function (indexn, element) {
                    var IsMatch = false;
                    if (StopArr.length > 0) {
                        $.each(StopArr, function (indexinn, elementinn) {
                            if (elementinn == element.AirlineCode+'-'+element.AirlineName) {
                                IsMatch = true;
                            }
                        });
                    }
                    if (IsMatch) {
                        ChildFiltered.push(element);
                    }
                });
            } else {
                resultsetFiltered.push(elements);
            }
            if (ChildFiltered.length > 0) {
                resultsetFiltered.push(ChildFiltered);
            }
        });
        //data[keyH] = ChildFiltered;
        //console.log(resultsetFiltered);
        return resultsetFiltered;
    };
    $scope.applyIsBagMultiFilter = function (data, StopArr, keyH) {
        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, elements) {
            var ChildFiltered = [];
            if (index == keyH) {
                $.each(elements, function (indexn, element) {
                    var IsMatch = false;
                    if (StopArr.length > 0) {
                        $.each(StopArr, function (indexinn, elementinn) {
                            if (elementinn == element.IsBagIncludes) {
                                IsMatch = true;
                            }
                        });
                    }
                    if (IsMatch) {
                        ChildFiltered.push(element);
                    }
                });
            } else {
                resultsetFiltered.push(elements);
            }
            if (ChildFiltered.length > 0) {
                resultsetFiltered.push(ChildFiltered);
            }
        });
        return resultsetFiltered;
    };
    $scope.applyStopMultiInter = function (data, StopArr) {
        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, elements) {
            var ChildFiltered = [];
            $.each(elements.FD, function (indexn, element) {
                var IsMatch = false;
                if (StopArr.length > 0) {
                    $.each(StopArr, function (indexinn, elementinn) {
                        if (elementinn == element.StopCount) {
                            IsMatch = true;
                        }
                    });
                }
                if (IsMatch) {
                    ChildFiltered.push(element);
                }
            });
            if (ChildFiltered.length > 0) {
                resultsetFiltered.push(elements);
            }
        });
        //data[keyH] = ChildFiltered;
        //console.log(resultsetFiltered);
        return resultsetFiltered;
    };

    $scope.applyAirlineNameMultiInter = function (data, StopArr) {
        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, elements) {
            var ChildFiltered = [];
            $.each(elements.FD, function (indexn, element) {
                var IsMatch = [];
                if (StopArr.length > 0) {
                    $.each(StopArr, function (indexinn, elementinn) {
                        if (elementinn == element.AirlineCode+'-'+element.AirlineName) {
                            IsMatch.push(elementinn);
                        }
                    });
                }
                if (IsMatch.length > 0) {
                    ChildFiltered.push(element);
                }
            });
            if (ChildFiltered.length > 0) {
                resultsetFiltered.push(elements);
            }
        });
        return resultsetFiltered;
    };
    $scope.applyFiltDepTimeMultiInter = function (data, StopArr) {
        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, elements) {
            var ChildFiltered = [];
            $.each(elements.FD, function (indexn, element) {
                var IsMatch = [];
                if (StopArr.length > 0) {
                    $.each(StopArr, function (indexinn, elementinn) {
                        if (elementinn == element.FilterDepartureDtTime) {
                            IsMatch.push(elementinn);
                        }
                    });
                }
                //console.log(IsMatch);
                if (IsMatch.length > 0) {
                    ChildFiltered.push(element);
                }
            });
            if (ChildFiltered.length > 0) {
                resultsetFiltered.push(elements);
            }
        });
        //console.log(resultsetFiltered);
        return resultsetFiltered;
    };
    $scope.applyFiltArrTimeMultiInter = function (data, StopArr) {
        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, elements) {
            var ChildFiltered = [];
            $.each(elements.FD, function (indexn, element) {
                var IsMatch = [];
                if (StopArr.length > 0) {
                    $.each(StopArr, function (indexinn, elementinn) {
                        if (elementinn == element.FilterArrivalDtTime) {
                            IsMatch.push(elementinn);
                        }
                    });
                }
                //console.log(IsMatch);
                if (IsMatch.length > 0) {
                    ChildFiltered.push(element);
                }
            });
            if (ChildFiltered.length > 0) {
                resultsetFiltered.push(elements);
            }
        });
        //console.log(resultsetFiltered);
        return resultsetFiltered;
    };
    $scope.applyFiltIsBaggMultiInter = function (data, StopArr) {
        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, elements) {
            var ChildFiltered = [];
            $.each(elements.FD, function (indexn, element) {
                var IsMatch = [];
                if (StopArr.length > 0) {
                    $.each(StopArr, function (indexinn, elementinn) {
                        if (elementinn == element.IsBagIncludes) {
                            IsMatch.push(elementinn);
                        }
                    });
                }
                //console.log(IsMatch);
                if (IsMatch.length > 0) {
                    ChildFiltered.push(element);
                }
            });
            if (ChildFiltered.length > 0) {
                resultsetFiltered.push(elements);
            }
        });
        //console.log(resultsetFiltered);
        return resultsetFiltered;
    };
    $scope.filterFromArrayReturn = function (data, filterSTR) {

        var resultsetFiltered = [];
        // console.log(filterSTR);
        resultsetFiltered = $scope.applyStopCountFilterReturn(data, filterSTR.FiltStopCountRound);
        resultsetFiltered = $scope.applyPriceRangeFilter(resultsetFiltered, filterSTR.price);
        resultsetFiltered = $scope.applyTimesReturnFilter(resultsetFiltered, filterSTR.TimesReturn);
        resultsetFiltered = $scope.applyArrivetimesReturnFilter(resultsetFiltered, filterSTR.ArrivetimesReturn);
        resultsetFiltered = $scope.applyAirlineFilterReturn(resultsetFiltered, filterSTR.AirlineNameReturn);
        resultsetFiltered = $scope.applyBaggageFilter(resultsetFiltered, filterSTR.baggage);
        resultsetFiltered = $scope.applyMealsFilter(resultsetFiltered, filterSTR.meals);
        resultsetFiltered = $scope.applyRefundableFilter(resultsetFiltered, filterSTR.refundable);

        return resultsetFiltered;
    };

    $scope.applyPriceRangeFilter = function (data, priceArr) {
        var resultsetFiltered = [];
        if (priceArr.length == 0) {
            return data;
        }
        $.each(data, function (index, element) {
            var Ismatched = false;
            $.each(element.FairRules, function (indexpr, FairRules) {
                var PublishedFare = (Math.round(FairRules.PublishedFare));

                if (priceArr.length > 0) {
                    $.each(priceArr, function (indexinn, elementinn) {
                        var elementinnSP = elementinn.split('-');
                        if (PublishedFare >= parseInt(elementinnSP[0]) && PublishedFare <= parseInt(elementinnSP[1])) {
                            Ismatched = true;
                            //resultsetFiltered.push(element);
                        }

                    });
                }

            })
            //console.log(Ismatched);
            if (Ismatched) {
                resultsetFiltered.push(element);
            }
        });
        //console.log(resultsetFiltered);
        return resultsetFiltered;
    };

    $scope.applyAirlineFilterReturn = function (data, airlineArr) {
        // number of nights
        //            console.log(data);
        var resultsetFiltered = [];
        if (airlineArr.length == 0) {
            return data;
        }

        $.each(data, function (index, element) {
            if (airlineArr.length > 0) {
                $.each(airlineArr, function (indexinn, elementinn) {
                    if (elementinn == element.AirlineName) {
                        //if(  $scope.checkAlreadyExistsInArray( element.AirlineName , resultsetFiltered , 'AirlineName' ) == false ) {
                        resultsetFiltered.push(element);
                        //}
                    }
                });
            }
        });
        return resultsetFiltered;
    };



    $scope.applyArrivetimesReturnFilter = function (data, timesArrArrival) {
        var resultsetFiltered = [];
        if (timesArrArrival.length == 0) {
            return data;
        }
        $.each(data, function (index, element) {
            if (timesArrArrival.length > 0) {
                $.each(timesArrArrival, function (indexinn, elementinn) {
                    var elementinnSP = elementinn.split('-');
                    if (element.ArrivalTime >= elementinnSP[0] && element.ArrivalTime <= elementinnSP[1]) {
                        resultsetFiltered.push(element);
                    }
                });
            }
        });
        return resultsetFiltered;

    }



    $scope.applyTimesFilter = function (data, timesArr) {
        var resultsetFiltered = [];
        if (timesArr.length == 0) {
            return data;
        }
        $.each(data, function (index, element) {
            if (timesArr.length > 0) {
                $.each(timesArr, function (indexinn, elementinn) {
                    var elementinnSP = elementinn.split('-');
                    if ($scope.interNationalSearch && $scope.route == '2') {
                        if (element.origin.DepartureTime >= elementinnSP[0] && element.origin.DepartureTime <= elementinnSP[1]) {
                            resultsetFiltered.push(element);
                        }
                    } else {
                        if (element.DepartureTime >= elementinnSP[0] && element.DepartureTime <= elementinnSP[1]) {
                            resultsetFiltered.push(element);
                        }
                    }


                });
            }
        });
        return resultsetFiltered;
    };
    $scope.applyTimesReturnIntFilter = function (data, timesArr) {
        var resultsetFiltered = [];
        if (timesArr.length == 0) {
            return data;
        }
        $.each(data, function (index, element) {
            if (timesArr.length > 0) {
                $.each(timesArr, function (indexinn, elementinn) {
                    var elementinnSP = elementinn.split('-');
                    if (element.destination.DepartureTime >= elementinnSP[0] && element.destination.DepartureTime <= elementinnSP[1]) {
                        resultsetFiltered.push(element);
                    }
                });
            }
        });
        return resultsetFiltered;
    };




    $scope.applyTimesReturnFilter = function (data, timesArr) {
        var resultsetFiltered = [];
        if (timesArr.length == 0) {
            return data;
        }
        $.each(data, function (index, element) {
            if (timesArr.length > 0) {
                $.each(timesArr, function (indexinn, elementinn) {
                    var elementinnSP = elementinn.split('-');
                    if (element.DepartureTime >= elementinnSP[0] && element.DepartureTime <= elementinnSP[1]) {
                        //if(elementinn == element.FilterPrice) {
                        //if(  $scope.checkAlreadyExistsInArray( element.PkgSysId , resultsetFiltered , 'PkgSysId' ) == false ) {
                        resultsetFiltered.push(element);
                        //}
                    }
                });
            }
        });
        return resultsetFiltered;

    }

    $scope.applyArriveTimesFilter = function (data, timesArr) {
        var resultsetFiltered = [];
        if (timesArr.length == 0) {
            return data;
        }
        $.each(data, function (index, element) {
            if (timesArr.length > 0) {
                $.each(timesArr, function (indexinn, elementinn) {

                    var elementinnSP = elementinn.split('-');
                    if ($scope.interNationalSearch && $scope.route == '2') {
                        if (element.origin.ArrivalTime >= elementinnSP[0] && element.origin.ArrivalTime <= elementinnSP[1]) {
                            resultsetFiltered.push(element);
                        }
                    } else {
                        if (element.ArrivalTime >= elementinnSP[0] && element.ArrivalTime <= elementinnSP[1]) {
                            resultsetFiltered.push(element);
                        }
                    }
                });
            }
        });
        return resultsetFiltered;
    };
    $scope.applyArrivetimesReturnIntFilter = function (data, timesArr) {
        var resultsetFiltered = [];
        if (timesArr.length == 0) {
            return data;
        }
        $.each(data, function (index, element) {
            if (timesArr.length > 0) {
                $.each(timesArr, function (indexinn, elementinn) {

                    var elementinnSP = elementinn.split('-');

                    if (element.destination.ArrivalTime >= elementinnSP[0] && element.destination.ArrivalTime <= elementinnSP[1]) {
                        resultsetFiltered.push(element);
                    }
                });
            }
        });
        return resultsetFiltered;
    };





    $scope.applyStopCountFilterReturn = function (data, StopArr) {

        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, element) {
            if (StopArr.length > 0) {
                $.each(StopArr, function (indexinn, elementinn) {

                    if ($scope.interNationalSearch && $scope.route == '2') {
                        if (elementinn == element.destination.StopCount) {
                            resultsetFiltered.push(element);
                        }
                    } else {
                        if (elementinn == element.StopCount) {
                            resultsetFiltered.push(element);
                        }
                    }

                });
            }
        });
        return resultsetFiltered;
    };
    $scope.applyStopCountFilterInt = function (data, StopArr) {

        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, element) {
            if (StopArr.length > 0) {
                $.each(StopArr, function (indexinn, elementinn) {

                    if ($scope.interNationalSearch && $scope.route == '2') {
                        if (elementinn == element.destination.StopCount) {
                            resultsetFiltered.push(element);
                        }
                    } else {
                        if (elementinn == element.StopCount) {
                            resultsetFiltered.push(element);
                        }
                    }

                });
            }
        });
        return resultsetFiltered;
    };

    $scope.applyStopCountFilter = function (data, StopArr) {

        var resultsetFiltered = [];
        if (StopArr.length == 0) {
            return data;
        }
        $.each(data, function (index, element) {
            $scope.ICSourceSysId = element.ICSourceSysId;
            var IsMatch = false;
            if (StopArr.length > 0) {
                $.each(StopArr, function (indexinn, elementinn) {
                    if ($scope.interNationalSearch && $scope.route == '2') {
                        if (elementinn == element.origin.StopCount) {
                            resultsetFiltered.push(element);
                        }
                    } else if ($scope.ICSourceSysId == 3 && $scope.route == '3') {
                        $.each(element.SegPro, function (indexSegPro, elementSegPro) {
                            if (elementinn == elementSegPro.StopCount) {
                                IsMatch = true;
                            }
                        });
                    } else {
                        if (elementinn === element.StopCount) {
                            resultsetFiltered.push(element);
                        }
                    }

                });
            }
            if (IsMatch) {
                resultsetFiltered.push(element);
            }
        });
        return resultsetFiltered;
    };

    $scope.applyAirlineFilter = function (data, nightArr) {
        // number of nights
        var resultsetFiltered = [];
        if (nightArr.length == 0) {
            return data;
        }
        $.each(data, function (index, element) {
            var IsMatch = false;
            $scope.ICSourceSysId = element.ICSourceSysId;
            if (nightArr.length > 0) {
                $.each(nightArr, function (indexinn, elementinn) {
                    if ($scope.ICSourceSysId == 3 && $scope.route == '3') {
                        $.each(element.SegPro, function (indexSegPro, elementSegPro) {
                            if (elementinn == elementSegPro.AirlineName) {
                                IsMatch = true;
                            }
                        });
                    }else if($scope.route == 2 && element.IsInternational == 1){
                        if (elementinn == element.origin.AirlineName || elementinn == element.destination.AirlineName) {
                            IsMatch = true;
                        }
                    } else {
                        if (elementinn == element.AirlineName) {
                            //if(  $scope.checkAlreadyExistsInArray( element.AirlineName , resultsetFiltered , 'AirlineName' ) == false ) {
                            resultsetFiltered.push(element);
                            //}
                        }
                    }

                });
            }
            if (IsMatch) {
                resultsetFiltered.push(element);
            }
        });
        return resultsetFiltered;
    };
    $scope.applyMealsFilter = function (data, nightArr) {
        var resultsetFiltered = [];
        if (nightArr.length == 0) {
            return data;
        }
        $.each(data, function (index, element) {
            if (nightArr.length > 0) {
                $.each(nightArr, function (indexinn, elementinn) {
                    if (elementinn == 1) {
                        var eltrue = false;
                    } else {
                        var eltrue = true;
                    }
                    if (eltrue == element.IsLCC) {
                        //if(  $scope.checkAlreadyExistsInArray( element.AirlineName , resultsetFiltered , 'AirlineName' ) == false ) {
                        resultsetFiltered.push(element);
                        //}
                    }
                });
            }
        });
        return resultsetFiltered;
    };




    $scope.applyBaggageFilter = function (data, BaggagepArr) {
        var resultsetFiltered = [];
        if (BaggagepArr.length == 0) {
            return data;
        }

        $.each(data, function (index, element) {
            if (BaggagepArr.length > 0) {
                $.each(BaggagepArr, function (indexinn, elementinn) {
                    if (JSON.parse(elementinn) == element.IsBagIncludes) {
                        //if(  $scope.checkAlreadyExistsInArray( element.AirlineName , resultsetFiltered , 'AirlineName' ) == false ) {
                        resultsetFiltered.push(element);
                        //}
                    }
                });
            }
        });
        return resultsetFiltered;
    };



    $scope.applyRefundableFilter = function (data, refundableArr) {
        // number of nights
        //            
        var resultsetFiltered = [];
        if (refundableArr.length == 0) {
            return data;
        }

        $.each(data, function (index, element) {
            if (refundableArr.length > 0) {
                $.each(refundableArr, function (indexinn, elementinn) {

                    if (JSON.parse(elementinn) == element.IsRefundable) {
                        //if(  $scope.checkAlreadyExistsInArray( element.AirlineName , resultsetFiltered , 'AirlineName' ) == false ) {
                        resultsetFiltered.push(element);
                        //}
                    }
                });
            }
        });
        return resultsetFiltered;
    };

    $scope.searchInResponseForFilter = function (data, filterValues, type) {
        var finaldata = [];
        var innerkey = '';
        if (type == 'AirlineName') {
            innerkey = 'AirlineName';
            $.each(data, function (index, element) {
                if ($.inArray(element[innerkey], filterValues) != -1) {
                    // push data in final array if already not exists
                    if (($.inArray(element[innerkey], finaldata)) == -1) {
                        finaldata.push(element[innerkey]);
                    }
                }
            });
            return finaldata;
        } else {
            return data;
        }
    };

    $scope.closeBox = function (index) {
        $('#viewdetailsbox_' + index).hide();
    }

    $scope.ViewMoreNew = function (item, DepDare, classss, index, IsLCC, PriceID = null) {
        $('#viewdetailsbox_' + index).show();
        $("#mytrip_fairdeatils_wrapper_" + index).hide();
        $("#view-flight-details-info_" + index).html('<div style="text-align:center;padding-top:30px;"><img src="' + SITEURL + 'public/images/loader.gif"/></div>');
        $scope.PriceID = PriceID;
        $scope.ICSourceSysId = item.ICSourceSysId;
        $scope.apiTraceId = item.apiTraceId;
        $scope.DepDare = DepDare;
        $scope.classss = classss;
        $scope.IsSeriesFareData = item.IsSeriesFareData;
        $scope.FareRules = item.FareRules;
        $scope.AirlineName__ = item.AirlineName;
        $scope.index = index;
        $scope.IsLCC = IsLCC;
        $scope.TotalBaseFare = 0;
        $scope.TotalTaxsandFees = 0;
        $scope.FareBreakdown = [];
        $scope.Currency = item.FairRules[0].Currency;
        $scope.viewmore = item;
        var url = SITEURL + "flight/viewmore";
        $http({
            method: "POST",
            url: url,
            data: {
                item: item,
                PriceID: PriceID
            },
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'X-Requested-With': 'XMLHttpRequest'
            }
        }).then(function successCallback(response) {
            if (response.data.success) {
                setTimeout(function () {
                    $("#view-flight-details-info_" + index).hide();
                    $("#mytrip_fairdeatils_wrapper_" + index).show();
                    $scope.PriceID = PriceID;
                    $scope.ICSourceSysId = item.ICSourceSysId;
                    $scope.apiTraceId = item.apiTraceId;
                    $scope.DepDare = DepDare;
                    $scope.classss = classss;
                    $scope.IsSeriesFareData = item.IsSeriesFareData;
                    $scope.FareRules = item.FareRules;
                    $scope.AirlineName__ = item.AirlineName;
                    $scope.index = index;
                    $scope.IsLCC = IsLCC;
                    $scope.TotalBaseFare = 0;
                    $scope.TotalTaxsandFees = 0;
                    $scope.FareBreakdown = [];
                    $scope.Currency = item.FairRules[0].Currency;
                    // $scope.finalFareSummary = response.data.finalFareSummary;
                    $('.FareSummaryDiv_' + index).html(response.data.html);
                }, 1000);
            } else {
                alert(response.data.message);
            }
        }, function errorCallback(response) {
            alert(response.data);
        });
    };
    $scope.ViewMore = function (item, DepDare, classss, index, IsLCC, PriceID = null, prices = null) {

        $scope.PriceID = PriceID;
        $scope.ApiResultIndex = prices.ApiResultIndex;
        $scope.IsMealIncludes = prices.IsMealIncludes;
        $scope.IsRefundable = prices.Refundable;
        $scope.IsRefundableTxt = prices.IsRefundableTxt;
        $scope.ICSourceSysId = item.ICSourceSysId;
        $scope.apiTraceId = item.apiTraceId;
        $scope.MiniFareRUles = prices.MiniFR;
        $scope.DepDare = DepDare;
        $scope.classss = classss;
        $scope.IsSeriesFareData = item.IsSeriesFareData;
        $scope.FareRules = item.FareRules;
        $scope.AirlineName__ = item.AirlineName;
        $scope.index = index;
        $scope.IsLCC = IsLCC;
        $scope.TotalBaseFare = 0;
        $scope.TotalTaxsandFees = 0;
        $scope.FareBreakdown = [];
        $scope.Currency = item.FairRules[0].Currency;
        $scope.tripbaggageinfo = prices.tripbinfo;
        $scope.tripbaggageinfoKeys = Object.keys($scope.tripbaggageinfo);

        if (PriceID != '') {
            var SelectedPrice = PriceID;
        } else {
            var SelectedPrice = $('#PriceClass_' + index).val();
        }

        $('#myModal_viewmore').modal('show');
        $('#ItemData').val(JSON.stringify(item));
        $('#PriceIDs').val(PriceID);
        var fareArr = [];
        $.each(item.FairRules, function (key, Fare) {
            var CurrencyRate = Fare.CurrencyRate;
            if (SelectedPrice == Fare.PriceID) {
                fareArr.push(Fare);
                $scope.FareBreakdown = Fare.FareBreakdown;
                if (Fare.FareBreakdown) {
                    $.each(Fare.FareBreakdown, function (k, value) {
                        var PBaseFare = value.BaseFare;
                        var MF = value.MF;
                        var YQ = value.YQ;
                        var AGST = value.AGST;
                        var MFT = value.MFT;
                        var OT = value.OT;
                        var YR = value.YR;
                        var MU = value.MU;
                        var FixedMarkUp = value.FixedMarkUp;
                        var GSTOnMarkUp = value.GSTOnMarkUp;
                        $scope.TotalBaseFare += (PBaseFare * CurrencyRate);
                        $scope.TotalTaxsandFees += ((MF + YQ + AGST + MFT + OT + MU + YR + FixedMarkUp + GSTOnMarkUp) * CurrencyRate);
                    });
                }

            }

        });
        $scope.FairRuless = fareArr;
        //console.log($scope.viewmore);
        //itemTemp['FairRules'] = fareArr;
        $scope.viewmore = item;
        $scope.MiniFR = item.MiniFR;
        // console.log($scope.viewmore);
        var url = SITEURL + "flight/viewmore";
        $http({
            method: "POST",
            url: url,
            data: {
                item: item,
                PriceID: PriceID
            },
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'X-Requested-With': 'XMLHttpRequest'
            }
        }).then(function successCallback(response) {
            if (response.data.success) {
                // $scope.finalFareSummary = response.data.finalFareSummary;
                $('.FareSummaryDiv').html(response.data.html);
                $('.viewmoreFlight').html(response.data.viewmoreFlight);
                $('.FlightBaggage').html(response.data.FlightBaggage);
            } else {
                alert(response.data.message);
            }
        }, function errorCallback(response) {
            alert(response.data.message);
        });
    };

    $scope.ViewMoreRound = function (item, DepDare, classss, index, IsLCC, PriceID = null, prices = null) {
        $scope.PriceID = PriceID;
        $scope.viewmore = item;
        $scope.ICSourceSysId = item.ICSourceSysId;
        $scope.apiTraceId = item.apiTraceId;
        $scope.IsSeriesFareData = item.IsSeriesFareData;
        $scope.FareRules = item.FareRules;
        $scope.AirlineName__ = item.AirlineName;
        $scope.DepDare = DepDare;
        $scope.classss = classss;
        $scope.index = index;
        $scope.IsLCC = IsLCC;
        $scope.TotalBaseFare = 0;
        $scope.TotalTaxsandFees = 0;
        $scope.FareBreakdown = [];
        $scope.Currency = item.FairRules[0].Currency;
        $scope.tripbaggageinfo = prices.tripbinfo;
        $scope.tripbaggageinfoKeys = Object.keys($scope.tripbaggageinfo);
        if (PriceID != '') {
            var SelectedPrice = PriceID;
        } else {
            var SelectedPrice = $('#RoundPriceClass_' + index).val();
        }
        $('#myModal_viewmore').modal('show');
        $.each(item.FairRules, function (key, Fare) {
            var CurrencyRate = Fare.CurrencyRate;
            if (SelectedPrice == Fare.PriceID) {
                $scope.FareBreakdown = Fare.FareBreakdown;
                if (Fare.FareBreakdown) {
                    $.each(Fare.FareBreakdown, function (k, value) {
                        var PBaseFare = value.BaseFare;
                        var MF = value.MF;
                        var YQ = value.YQ;
                        var AGST = value.AGST;
                        var MFT = value.MFT;
                        var OT = value.OT;
                        var YR = value.YR;
                        var MU = value.MU;
                        var FixedMarkUp = value.FixedMarkUp;
                        var GSTOnMarkUp = value.GSTOnMarkUp;
                        $scope.TotalBaseFare += (PBaseFare * CurrencyRate);
                        $scope.TotalTaxsandFees += ((MF + YQ + AGST + MFT + OT + MU + YR + FixedMarkUp + GSTOnMarkUp) * CurrencyRate);
                    });
                }

            }

        });

        var url = SITEURL + "flight/viewmore";
        $http({
            method: "POST",
            url: url,
            data: {
                item: item,
                PriceID: PriceID
            },
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'X-Requested-With': 'XMLHttpRequest'
            }
        }).then(function successCallback(response) {
            if (response.data.success) {
                // $scope.finalFareSummary = response.data.finalFareSummary;
                $('.FareSummaryDiv').html(response.data.html);
            } else {
                alert(response.data.message);
            }
        }, function errorCallback(response) {
            alert(response.data.message);
        });
    };

    $scope.onewayflight = function ($scope, index, PriceID) {
        angular.element('.SingleSelect input:radio').each(function (v, k) {
            if ($(this).is(":checked")) {
                //                    $scope.class_status = true;
                if ($scope.item.ICSourceSysId == 16) {
                    $scope.summprice($scope.item, index, PriceID);
                } else {
                    $scope.summprice(PriceID, index, PriceID);
                }
                $scope.duration();
            }
        });

    };
    $scope.twowayflight = function ($scope, index, PriceID) {
        angular.element('.roundSelect input:radio').each(function (v, k) {
            if ($(this).is(":checked")) {
                if ($scope.item.ICSourceSysId == 16) {
                    $scope.summpricetwo($scope.item, index, PriceID);
                } else {
                    $scope.summpricetwo(PriceID, index, PriceID);
                }
                $scope.duration();
            }
        });
    };
    $scope.summpriceMulti = function (ApiResultIndex, item, PriceID, key) {
        $scope.ItemArr = [];
        $scope.FareArr = [];
        $scope.PublishedFareTxt = 0;
        $scope.roundcurrency = '';
        angular.element('.MultipleSelect input[type="radio"]:checked').each(function (v, k) {
            if ($(this).is(":checked")) {
                //console.log($(this).val());
                var pr = $(this).val();
                angular.forEach($scope.flightlistOutbound, function (itemval, keys) {
                    angular.forEach(itemval, function (items, keydd) {
                        $.each(items.FairRules, function (key, Fare) {
                            if (pr == Fare.PriceID) {

                                $scope.ItemArr.push(items);
                                $scope.FareArr.push(Fare);
                                $scope.PublishedFareTxt += Fare.PublishedFare;
                                $scope.roundcurrency = Fare.Currency;
                            }
                        });
                    });
                });
            }
        });
        // console.log($scope.roundcurrency);
        //console.log($scope.ItemArr);
        //console.log($scope.ItemArr);
        $scope.roundtrip = $scope.ItemArr;
        return $scope.roundtrip;
    };
    $scope.summprice = function (ApiResultIndex, index, PriceID) {
        var ShowPriceNoMarkup = $('#ShowPriceNoMarkup').val();
        if (ApiResultIndex) {
            var ICSourceSysId = $scope.flightlistOutbound[0]['ICSourceSysId'];
            $scope.PublishedFareTxt = 0;
            if (ICSourceSysId != 16) {
                var outboundFlightIndex = ApiResultIndex;
                const FareOption = [];
                $.each($scope.flightlistOutbound, function (key, item) {
                    $.each(item.FairRules, function (key, Fares) {
                        if (Fares.PriceID === outboundFlightIndex) {
                            FareOption.push(item)
                        }
                    });
                });
                var Outbound = FareOption[0];
                // console.log(Outbound)
                // var Outbound = $scope.flightlistOutbound.find(function (item) {
                //     console.log(item)
                //     $.each(item.FairRules, function (key, Fares) {
                //         if (Fares.PriceID === outboundFlightIndex) {
                //             FareOption.push(item)
                //         }
                //     })
                //     // if (item.FairRules[0].PriceID === outboundFlightIndex) {
                //     //     return item;
                //     // }
                // });
                $scope.Currency = (Outbound.FairRules[0].Currency);
                $.each(Outbound.FairRules, function (key, Fare) {
                    if (PriceID == Fare.PriceID) {
                        if (ShowPriceNoMarkup == 1) {
                            $scope.PublishedFareTxt = (Fare.PublishedFare - (Fare.FixedMarkUp + Fare.GSTOnMarkUp));
                        } else {
                            $scope.PublishedFareTxt = Fare.PublishedFare;
                        }
                    }
                });
            } else {
                var Outbound = ApiResultIndex;
                $scope.Currency = (Outbound.FairRules[0].Currency);
                $scope.PublishedFareTxt = PriceID.PublishedFareAgent;
            }
            $scope.LocalToTime = Outbound.LocalToTime;
            $scope.roundtrip = Outbound;
            return $scope.roundtrip;
        }
    };
    $scope.summpricetwo = function (ApiResultIndex, index, PriceID) {
        if (ApiResultIndex) {
            var ICSourceSysId = $scope.flightlistInbound[0]['ICSourceSysId'];
            console.log("flightlistInbound ===== summpricetwo",$scope.flightlistInbound);
            var ShowPriceNoMarkup = $('#ShowPriceNoMarkup').val();
            $scope.RPublishedFareTxt = 0;
            if (ICSourceSysId != 16) {
                var inboundFlightIndex = ApiResultIndex;//ApiResultIndex;
                // var Inbound = $scope.flightlistInbound.find(function (item) {
                //     if (item.FairRules[0].PriceID === inboundFlightIndex) {
                //         return item;
                //     }
                // });
                const FareOption = [];
                console.log("flightlistInbound ===== summpricetwo",$scope.flightlistInbound);
                $.each($scope.flightlistInbound, function (key, item) {
                     console.log("item.FairRules ===== summpricetwo",item);
                    
                    $.each(item.FairRules, function (key, Fares) {
                        if (Fares.PriceID === inboundFlightIndex) {
                            FareOption.push(item)
                        }
                    });
                });
                var Inbound = FareOption[0];
                console.log("flightlistInbound ===== summpricetwo",Inbound);
                
                $scope.Currency = (Inbound.FairRules[0].Currency);
                $.each(Inbound.FairRules, function (key, Fare) {
                    if (PriceID == Fare.PriceID) {
                        if (ShowPriceNoMarkup == 1) {
                            $scope.RPublishedFareTxt = (Fare.PublishedFare - (Fare.FixedMarkUp + Fare.GSTOnMarkUp));
                        } else {
                            $scope.RPublishedFareTxt = Fare.PublishedFare;
                        }
                    }
                });
            } else {
                var Inbound = ApiResultIndex;
                $scope.Currency = (Inbound.FairRules[0].Currency);
                $scope.RPublishedFareTxt = PriceID.PublishedFareAgent;
            }
            $scope.LocalFromTime = Inbound.LocalFromTime;
            $scope.duration();
            $scope.roundtrip2 = Inbound;
            return $scope.roundtrip2;
        }
    };


    $scope.duration = function () {
        var t0 = $scope.LocalToTime;
        var t1 = $scope.LocalFromTime;
        var start = t0;
        var end = t1;
        start = new Date(start);
        end = new Date(end);
        var diff = end.getTime() - start.getTime();
        var time_difference = new Object();

        time_difference.hours = Math.floor(diff / 1000 / 60 / 60);
        diff -= time_difference.hours * 1000 * 60 * 60;
        if (time_difference.hours < 10) time_difference.hours = time_difference.hours;

        time_difference.minutes = Math.floor(diff / 1000 / 60);
        diff -= time_difference.minutes * 1000 * 60;
        if (time_difference.minutes < 10) time_difference.minutes = time_difference.minutes;
        //console.log(time_difference);
        if (time_difference.hours < 2) {
            setTimeout(function () {
                $('.bookNowRound').attr('title', 'Departure time must be greater than previous Arrival time by 2 hours.');
                $('.bookNowRound').css('background', '#575251');
            }, 2000);
            $scope.BookingAllowed = false;
        } else {
            $('.bookNowRound').removeAttr('title', '');
            $('.bookNowRound').css('background', '#00783a');
            $scope.BookingAllowed = true;
        }
    };
    $scope.bookNowCom = function (item, index, PriceID = null) {

        if (PriceID != '') {
            var SelectedPrice = PriceID;
        } else {
            var SelectedPrice = $('#PriceClass_' + index).val();
        }

        var url = SITEURL + "flight/book-noow";
        var jsonString = JSON.stringify(item, $scope.getCircularReplacer());
        //var jsonString = JSON.stringify($scope.item);
        //var FairRulesString = JSON.stringify($scope.item.FairRules);
        //var SegmentsString = $($scope.item.Segments).serializeArray();//($scope.item.Segments);
        $http({
            method: "POST",
            url: url,
            data: {
                Outbound: jsonString,
                Inbound: '',
                SingleSelect: SelectedPrice
            },
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'X-Requested-With': 'XMLHttpRequest'
            }
        }).then(function successCallback(response) {
            if (response.data.success) {
                $window.location.href = response.data.url;
            } else {
                alert(response.data.message);
            }
        }, function errorCallback(response) {
            alert(response.data.message);
        });
    };
    $scope.bookNowPop = function (index) {
        $('#booknowpop_' + index).modal('show');
    }
    $scope.bookNowRoundPop = function () {
        $('#bookNowRoundPop__').modal('show');
    }
   
    $scope.bookNow = function ($scope, index, PriceID = null) {

        // Cancel all pending search requests FIRST
        $scope.cancelAllRequests();
        $scope.loadingBookNow = true;
        
        // Create a NEW canceller for THIS booking request
        var bookingCanceller = $q.defer();
        $scope.activeCancellers.push(bookingCanceller);

       
        if (PriceID != '') {
            var SelectedPrice = PriceID;
        } else {
            var SelectedPrice = $('#PriceClass_' + index).val();
        }

        var url = SITEURL + "flight/book-noow";
        var jsonString = JSON.stringify($scope.item, $scope.getCircularReplacer());
        //var jsonString = JSON.stringify($scope.item);
        //var FairRulesString = JSON.stringify($scope.item.FairRules);
        //var SegmentsString = $($scope.item.Segments).serializeArray();//($scope.item.Segments);
        $http({
            method: "POST",
            url: url,
            data: {
                Outbound: jsonString,
                Inbound: '',
                SingleSelect: SelectedPrice,
            },
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'X-Requested-With': 'XMLHttpRequest'
            }
        }).then(function successCallback(response) {
            if (response.data.success) {
                $window.location.href = response.data.url;
            } else {
                alert(response.data.message);
            }
        }, function errorCallback(response) {
            alert(response.data.message);
        });
    };

    $scope.bookNowRound = function (Outbound, Inbound) {
        var SingleSelect = $("input[name=SingleSelect]:checked").val();
        var roundSelect = $("input[name=roundSelect]:checked").val();
        //            console.log(Inbound);
        var url = SITEURL + "flight/book-noow";
        var jsonStringOut = JSON.stringify(Outbound);
        var jsonString = JSON.stringify(Inbound);
        if ($scope.BookingAllowed) {
            $http({
                method: "POST",
                url: url,
                data: {
                    Outbound: jsonStringOut,
                    Inbound: jsonString,
                    SingleSelect: SingleSelect,
                    roundSelect: roundSelect
                },
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'X-Requested-With': 'XMLHttpRequest'
                }
            }).then(function successCallback(response) {
                if (response.data.success) {
                    $window.location.href = response.data.url;
                } else {
                    alert(response.data.message);
                }
            }, function errorCallback(response) {
                alert(response.data.message);
            });
        } else {
            alert('Departure time must be greater than previous Arrival time by 2 hours.');
        }
    };

    $scope.bookNowMulti = function (Outbound, FareArr) {
        var sessionFlightSearchParams = $('#sessionFlightSearchParams').val();
        var url = SITEURL + "flight/book-now-multi";
        var jsonStringOut = JSON.stringify(Outbound);
        var jsonString = JSON.stringify(FareArr);
        $http({
            method: "POST",
            url: url,
            data: {
                Outbound: jsonStringOut,
                FareArr: jsonString
            },
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'X-Requested-With': 'XMLHttpRequest'
            }
        }).then(function successCallback(response) {
            if (response.data.success) {
                $window.location.href = response.data.url;
            } else {
                alert(response.data.message);
            }
        }, function errorCallback(response) {
            alert(response.data.message);
        });

    };



}]);
app.filter('ceilLocale', function() {
    return function(input) {
        if (input != null) {
            return Math.ceil(input).toLocaleString('en-IN');
        }
        return input;
    };
});
$(document).on('click', '.PriceClass', function () {
    var index = $(this).attr('index');
    var value = $(this).val();
    $('#PriceClass_' + index).val(value);
});
$(document).on('click', '.RoundPriceClass', function () {
    var index = $(this).attr('index');
    var value = $(this).val();
    $('#RoundPriceClass_' + index).val(value);
});
app.filter('dynamicFilter', function () {
    return function (FlightData, filterCategories, scope) {
        var filtered = [];

        // REPLACED: _.any with _.some
        var productFilters = _.filter(filterCategories, function (fc) {
            return _.some(fc.options, { 'IsIncluded': true });
        });

        _.each(FlightData, function (prod) {
            if (prod) {
                var includeProduct = true;
                
                _.each(productFilters, function (filter) {
                    var props = _.filter(prod.flt, { 'name': filter.name });
                    
                    // REPLACED: _.any with _.some (nested check)
                    if (!_.some(props, function (prop) { 
                        return _.some(filter.options, { 'value': prop.value, 'IsIncluded': true }); 
                    })) {
                        includeProduct = false;
                    }
                });

                if (includeProduct) {
                    filtered.push(prod);
                }
            }
        });

        return filtered;
    };
});
app.filter('dynamicFilterInr', function () {
    return function (FlightData, FiltersOut, FiltersInb, scope) {
        var filtered = [];
        // ⭐ Separate outbound and inbound filters
        var productFiltersOut = _.filter(FiltersOut || [], function (fc) {
            return _.some(fc.options, { 'IsIncluded': true });
        });
         var productFiltersInb = [];
         if (FiltersInb && FiltersInb.length > 0) {
            var productFiltersInb = _.filter(FiltersInb || [], function (fc) {
                return _.some(fc.options, { 'IsIncluded': true });
            });
        }
        _.each(FlightData, function (prod) {
            var includeProduct = true;

            // ⭐ Check if this is a round-trip (JourneyType=2 & International)
            var isRoundTrip = (prod.JourneyType == 2 && prod.IsInternational == 1);

            // ⭐ Check OUTBOUND filters against origin flight
            _.each(productFiltersOut, function (filter) {
                var allFlt = [];
                // For round-trip, check origin flight; for one-way, check main flight
                if (isRoundTrip && prod.origin && prod.origin.flt) {
                    allFlt = prod.origin.flt;
                } else if (!isRoundTrip && prod.flt) {
                    allFlt = prod.flt;
                }

                var props = _.filter(allFlt, { 'name': filter.name });

                var matched = _.some(props, function (prop) {
                    return _.some(filter.options, { 'value': prop.value, 'IsIncluded': true });
                });

                if (!matched) includeProduct = false;
            });

            // ⭐ Check INBOUND filters against destination flight (only for round-trip)
            if (isRoundTrip && includeProduct) {
                _.each(productFiltersInb, function (filter) {
                    var allFlt = [];
                    
                    if (prod.destination && prod.destination.flt) {
                        allFlt = prod.destination.flt;
                    }

                    var props = _.filter(allFlt, { 'name': filter.name });

                    var matched = _.some(props, function (prop) {
                        return _.some(filter.options, { 'value': prop.value, 'IsIncluded': true });
                    });

                    if (!matched) includeProduct = false;
                });
            }

            if (includeProduct) filtered.push(prod);
        });

        return filtered;
    };
});
app.filter('dynamicFilterDom', function () {
    return function (FlightData, filterCategories, scope) {
        var filtered = [];

        var productFilters = _.filter(filterCategories, function (fc) {
            return _.any(fc.options, { 'IsIncluded': true });
        });
        _.each(FlightData, function (prod) {
            if (prod) {
               
                var includeProduct = true;
                _.each(productFilters, function (filter) {
                    
                    var props = _.filter(prod.flt, { 'name': filter.name });
                    if (!_.any(props, function (prop) {   return _.any(filter.options, { 'value': prop.value, 'IsIncluded': true });})) {
                        includeProduct = false;
                    }
                });
                if (includeProduct) {
                    filtered.push(prod);
                }
            }
        });
        return filtered;
    };
});
app.filter('dynamicFilterMulticity', function () {
    return function (FlightData, filterCategories, scope) {
        var filtered = [];

        // get filters with at least one IsIncluded: true
        var productFilters = _.filter(filterCategories, function (fc) {
            return _.some(fc.options, { 'IsIncluded': true });
        });
        _.each(FlightData, function (prod) {
            if (prod) {
                var includeProduct = false; // default: false

                if (prod.ICSourceSysId == 7 && prod.IsInternational == 1) {
                    // check each FD[] segment
                    _.each(prod.FD, function (prod__) {
                        var segmentMatches = true;

                        _.each(productFilters, function (filter) {
                            var props = _.filter(prod__.flt, { 'name': filter.name });

                            if (!_.some(props, function (prop) {
                                return _.some(filter.options, { 'value': prop.value, 'IsIncluded': true });
                            })) {
                                segmentMatches = false; // this segment doesn't match all filters
                            }
                        });

                        if (segmentMatches) {
                            includeProduct = true; // at least one segment matched all filters
                        }
                    });
                } else if (prod.SegPro) {
                    // backup logic for SegPro, if needed
                    _.each(prod.SegPro, function (prod__) {
                        var segmentMatches = true;

                        _.each(productFilters, function (filter) {
                            var props = _.filter(prod__.flt, { 'name': filter.name });

                            if (!_.some(props, function (prop) {
                                return _.some(filter.options, { 'value': prop.value, 'IsIncluded': true });
                            })) {
                                segmentMatches = false;
                            }
                        });

                        if (segmentMatches) {
                            includeProduct = true;
                        }
                    });
                }

                if (includeProduct) {
                    filtered.push(prod);
                }
            }
        });
        return filtered;
    };
});
// $(document).on('click', '.selectall', function () {
//     var priceIds = $(this).attr('priceIds');
//     var keyIndex = $(this).attr('keyIndex');
//     angular.element(document.getElementById('ElementId')).scope().CombineSelect(priceIds,keyIndex);
//     console.log(priceIds);
//     console.log(keyIndex);
//     $('.trigger_' + priceIds).prop("checked", true);

// });

Youez - 2016 - github.com/yon3zu
LinuXploit