﻿AG.Data.Stock = {
    GetFavourite: function (stockCode) {
        var requestName = 'Favourite' + '_NoLanguage';
        for (var i = 0; i < stockCode.length; i++) {
            requestName += '_' + stockCode[i];
            stockCode[i] = { Code: stockCode[i] };
        }
        stockCode.push({ Type: AG.Config.CompanyType.Listed });
        stockCode.push({ Type: '00000000-0000-0000-0000-000000000004' });
        stockCode.push({ Type: '00000000-0000-0000-0000-000000000005' });
        return AG.ClientAPI.createData(CompanyRealtime, requestName, stockCode, { static: ['Id', 'Code', 'ClosePrice', 'Diff', 'DiffPercent', 'Modified'] }, undefined, undefined, undefined, 0, 60000);
    },
    GetListSymbol: function () {
        return AG.ClientAPI.createData(CompanyInfomation, 'StockListed', [{ Type: AG.Config.CompanyType.Listed }, { Type: AG.Config.CompanyType.Fund}], { static: ['Id', 'Code', 'Name'] }, [{ Field: 'Code', Direction: 'ASC'}]);
    },
    GetListSymbolByStockExhchange: function (aFloor, aType, key) {
        var requestName = 'StockListed';
        var data = [];
        if (typeof (aFloor) != 'undefined') {
            if (aFloor.length > 0) {
                for (var i = 0; i < aFloor.length; i++) {
                    data.push({ StockExchange: aFloor[i] });
                    requestName += aFloor[i];
                }
            }
        } if (typeof (aType) != 'undefined') {
            if (aType.length > 0) {
                for (var i = 0; i < aType.length; i++) {
                    data.push({ Type: aType[i] });
                    requestName += aType[i];
                }
            }
        }
        if (typeof (key) != 'undefined') {
            if (key != '') {
                var filter = [{ Field: 'Code', Type: 'Static', Index: 0, Operator: 'like', Value: (key + '%')}];
                requestName += key;
            }
        }
        return AG.ClientAPI.createData(CompanyInfomation, requestName, data, { static: ['Id', 'Code', 'Name', 'Type'] }, [{ Field: 'Code', Direction: 'ASC'}], filter);

    },
    GetTopLoser: function (floorId, count) {
        var requestName = 'TopLoser' + '_' + floorId + '_' + count + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ StockExchange: floorId }, { Type: AG.Config.CompanyType.Listed }, { Type: AG.Config.CompanyType.Fund }, { StartIndex: 1 }, { EndIndex: count}], { static: ['Id', 'Code', 'ClosePrice', 'Diff', 'DiffPercent', 'AveragePrice', 'RefPrice', 'ForeignBuyVolume', 'ForeignSellVolume', 'Modified'], dynamic: ['TotalShare', 'CeilingPrice', 'FloorPrice'] }, [{ Field: 'DiffPercent', Direction: 'ASC' }, { Field: 'TotalShare', Direction: 'DESC'}], undefined, undefined, undefined, 0, 60000);
    },
    GetTopGainers: function (floorId, count) {
        var requestName = 'TopGainer' + '_' + floorId + '_' + count + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ StockExchange: floorId }, { Type: AG.Config.CompanyType.Listed }, { Type: AG.Config.CompanyType.Fund }, { StartIndex: 1 }, { EndIndex: count}], { static: ['Id', 'Code', 'ClosePrice', 'Diff', 'DiffPercent', 'AveragePrice', 'RefPrice', 'ForeignBuyVolume', 'ForeignSellVolume', 'Modified'], dynamic: ['TotalShare', 'CeilingPrice', 'FloorPrice'] }, [{ Field: 'DiffPercent', Direction: 'DESC' }, { Field: 'TotalShare', Direction: 'DESC'}], undefined, undefined, undefined, 0, 60000);
    },
    GetTopActives: function (floorId, count) {
        var requestName = 'TopActive' + '_' + floorId + '_' + count + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ StockExchange: floorId }, { Type: AG.Config.CompanyType.Listed }, { Type: AG.Config.CompanyType.Fund }, { StartIndex: 1 }, { EndIndex: count}], { static: ['Id', 'Code', 'ClosePrice', 'Diff', 'DiffPercent', 'AveragePrice', 'RefPrice', 'TotalShare', 'ForeignBuyVolume', 'ForeignSellVolume', 'Modified'], dynamic: ['CeilingPrice', 'FloorPrice'] }, [{ Field: 'TotalShare', Direction: 'DESC'}], undefined, undefined, requestName, 0, 60000);
    },
    GetForeignBuy: function (floorId, count) {
        var requestName = 'ForeignBuy' + '_' + floorId + '_' + count + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ StockExchange: floorId }, { Type: AG.Config.CompanyType.Listed }, { Type: AG.Config.CompanyType.Fund }, { StartIndex: 1 }, { EndIndex: count}], { static: ['Id', 'Code', 'ClosePrice', 'Diff', 'DiffPercent', 'AveragePrice', 'RefPrice', 'Modified', 'ForeignBuyVolume', 'ForeignSellVolume'], dynamic: ['TotalShare', 'CeilingPrice', 'FloorPrice'] }, [{ Field: 'ForeignBuyVolume', Direction: 'DESC'}], undefined, undefined, undefined, 0, 60000);
    },
    GetForeignSell: function (floorId, count) {
        var requestName = 'ForeignSell' + '_' + floorId + '_' + count + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ StockExchange: floorId }, { Type: AG.Config.CompanyType.Listed }, { Type: AG.Config.CompanyType.Fund }, { StartIndex: 1 }, { EndIndex: count}], { static: ['Id', 'Code', 'ClosePrice', 'Diff', 'DiffPercent', 'AveragePrice', 'RefPrice', 'Modified', 'ForeignBuyVolume', 'ForeignSellVolume'], dynamic: ['TotalShare', 'CeilingPrice', 'FloorPrice'] }, [{ Field: 'ForeignSellVolume', Direction: 'DESC'}], undefined, undefined, undefined, 0, 60000);
    },
    GetIndexOverview: function (stockCode) {
        var requestName = 'IndexOverview' + '_' + stockCode + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ Code: stockCode}], { static: ['Id', 'Code', 'ClosePrice', 'OpenPrice', 'Diff', 'DiffPercent', 'TotalShare', 'TotalValue', 'LowestPrice', 'HighestPrice', 'MarketCapitalization', 'Modified'] }, undefined, undefined, undefined, 0, 60000);
    },
    GetPriceAndVolume: function (stockCode) {
        var requestName = 'PriceAndVolume' + '_' + stockCode + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ Code: stockCode}], { static: ['Id', 'Code', 'ClosePrice', 'Highest52Weeks', 'DiffPercentHighest52Weeks', 'DateHighest52Weeks', 'Lowest52Weeks', 'DiffPercentLowest52Weeks', 'DateLowest52Weeks', 'DiffPercent', 'DiffPercentPrice2Days', 'DiffPercentPrice5Days', 'DiffPercentPrice1Month', 'DiffPercentPrice3Months', 'DiffPercentPrice6Months', 'DiffPercentPrice1Year', 'AverageVolume10Days', 'AverageVolume3Months', 'Beta', 'DiffPercentPriceThisYear', 'PE', 'PEHighest52Weeks', 'PELowest52Weeks'], dynamic: ['SessionDate'] });
    },
    GetProfitbilityRatios: function (stockCode) {
        var requestName = 'StockProfitbilityRatios' + '_' + stockCode + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ Code: stockCode}], { static: ['Id', 'Code'], dynamic: ['GrossProfitMarginLFI', 'GrossProfitMarginLTM', 'GrossProfitMarginLFY', 'EBITDAMarginLTM', 'EBITDAMarginLFY', 'IncomeBeforeTaxMarginLFI', 'IncomeBeforeTaxMarginLTM', 'IncomeBeforeTaxMarginLFY', 'IncomeAfterTaxMarginLFI', 'IncomeAfterTaxMarginLTM', 'IncomeAfterTaxMarginLFY', 'OperatingIncomeMarginLFY', 'OperatingIncomeMarginLTM', 'OperatingIncomeMarginLFI'] });
    },
    GetPerShare: function (stockCode) {
        var requestName = 'StockPerShare' + '_' + stockCode + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ Code: stockCode}], { static: ['Id', 'Code'], dynamic: ['RevenueOutstandingShareLFI', 'RevenueOutstandingShareLTM', 'RevenueOutstandingShareLFY', 'EPSLFI', 'EPSLTM', 'EPSLFY', 'DividendShareCommonStockPrimaryLFI', 'DividendShareCommonStockPrimaryLFY', 'TotalCashShorttermInvestmentsShareLFI', 'TotalCashShorttermInvestmentsShareLFY', 'CashFlowShareLFI', 'CashFlowShareLTM', 'CashFlowShareLFY', 'BookValueShareTotalEquityLFI', 'BookValueShareTotalEquityLFY', 'TangibleBookValueTotalEquityLFI', 'TangibleBookValueTotalEquityLFY'] });


    },
    GetGrowthRate: function (stockCode) {
        var requestName = 'StockGrowthRate' + '_' + stockCode + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ Code: stockCode}], { static: ['Id', 'Code'], dynamic: ['RevenueGrowthRateLFI', 'RevenueGrowthRateLFY', 'CAGR', 'Revenue10YearGrowthRate', 'EPSGrowthRateLFI', 'EPSGrowthRateLFY', 'EPS5YearGrowthRate', 'EPS10YearGrowthRate', 'DividendGrowthRateLFY', 'Dividend5YearGrowthRate', 'Dividend10YearGrowthRate'] });


    },
    GetDividend: function (stockCode) {
        var requestName = 'StockDividend' + '_' + stockCode + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ Code: stockCode}], { static: ['Id', 'Code'], dynamic: ['DividendYield', 'AnnualDividend5YearsAverage', 'Dividend5YearGrowthRate', 'DividendPayoutRatioLFI', 'DividendPayoutRatioLTM', 'DividendPayoutRatioLFY'] });


    },
    GetValutationRatios: function (stockCode) {
        var requestName = 'StockValutationRatios' + '_' + stockCode + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ Code: stockCode}], { static: ['Id', 'Code'], dynamic: ['PriceRevenueShareLTM', 'PriceRevenueShareLFY', 'PELTM', 'PELFY', 'PriceCashFlowShareLTM', 'PriceCashFlowShareLFY', 'PriceTangibleBookTotalEquityLFI', 'PriceTangibleBookTotalEquityLFY', 'EVTotalRevenue', 'EVEBITDA', 'EVEBIT', 'EVLFI', 'EVTotalRevenueLFY', 'EVEBITDALFY', 'EVEBITLFY', 'EVLFY'] });


    },
    GetIncomeStatement: function (stockCode) {

        return AG.ClientAPI.createData(CompanyRealtime, 'StockIncomStatement' + '_NoLanguage', [{ Code: stockCode}], { static: ['Id', 'Code'], dynamic: ['TotalRevenueLFI', 'TotalRevenueLTM', 'TotalRevenueLFY', 'EBITDALFI', 'EBITDALTM', 'EBITDALFY', 'EBITLFI', 'EBITLTM', 'EBITLFY', 'IncomeBeforeTaxLFI', 'IncomeBeforeTaxLTM', 'IncomeBeforeTaxLFY', 'IncomeAfterTaxLFI', 'IncomeAfterTaxLTM', 'IncomeAfterTaxLFY', 'IncomeAvailCommonLFI', 'IncomeAvailCommonLTM', 'IncomeAvailCommonLFY'] });

    },
    GetManagementsEfectiveness: function (stockCode) {

        return AG.ClientAPI.createData(CompanyRealtime, 'StockManagementEfectiveness' + '_NoLanguage', [{ Code: stockCode}], { static: ['Id', 'Code'], dynamic: ['ROCLFI', 'ROCLTM', 'ROCLFY', 'ROELTM', 'ROELFY', 'ROALTM', 'ROALFY'] });

    },
    GetFinancialStrength: function (stockCode) {

        return AG.ClientAPI.createData(CompanyRealtime, 'StockFinancialStrength' + '_NoLanguage', [{ Code: stockCode}], { static: ['Id', 'Code'], dynamic: ['QuickRatioLFI', 'QuickRatioLFY', 'CurrentRatioLFI', 'CurrentRatioLFY', 'LongtermDebtTotalEquityLFI', 'LongtermDebtTotalEquityLFY', 'LongtermDebtTotalAssetsLFI', 'LongtermDebtTotalAssetsLFY', 'TotalDebtTotalEquityLFI', 'TotalDebtTotalEquityLFY'] });

    },
    GetEmployees: function (stockCode) {

        return AG.ClientAPI.createData(CompanyRealtime, 'StockEmployees' + '_NoLanguage', [{ Code: stockCode}], { static: ['Id', 'Code'], dynamic: ['TotalEmployees', 'TotalRevenueEmployeeLFI', 'TotalRevenueEmployeeLTM', 'TotalRevenueEmployeeLFY', 'IncomeAfterTaxEmployeeLFI', 'IncomeAfterTaxEmployeeLTM', 'IncomeAfterTaxEmployeeLFY'] });

    },
    GetTechniqueRatio: function (stockCode) {

        return AG.ClientAPI.createData(CompanyRealtime, 'TechniqueRatio' + '_NoLanguage', [{ Code: stockCode}], { static: ['Id', 'Code', 'Volume5Days', 'Volume30Days', 'RSI3Days', 'RSI9Days', 'RSI14Days', 'RSI30Days', 'Beta', 'TotalShare'], dynamic: ['DailyVaR95', 'YearStandardDeviation'] });

    },
    GetProfile: function (stockCode) {

        var requestName = 'StockProfile' + '_' + stockCode + '_NoLanguage';
        var result = AG.ClientAPI.createData(CompanyRealtime, requestName, [{ Code: stockCode}], { static: ['Id', 'Code', 'OutstandingShare', 'PE', 'StockExchange', 'MarketCapitalization', 'Type', 'ClosePrice', 'Highest52Weeks', 'Lowest52Weeks'], dynamic: ['DividendYield', 'DividendLFY', 'DividendPayoutRatioLFY', 'DividendPayoutRatioLFI'] });
        if (result.length > 0) {
            result[0].StockExchange = AG.ClientAPI.createData(StockExchange, 'StockExchange', [{ Id: result[0].StockExchange}], { static: ['Id', 'Name'] }, [], undefined, 0)[0].Name;
        }
        return result;
    },
    GetBasicRatios: function (stockCode) {

        return AG.ClientAPI.createData(CompanyRealtime, 'StockBasicRatios' + '_NoLanguage', [{ Code: stockCode}], { static: ['Id', 'Code'], dynamic: ['RevenueOutstandingShareLFI', 'RevenueOutstandingShareLTM', 'DividendShareCommonStockPrimaryLFI', 'CashFlowShareLFI', 'CashFlowShareLTM', 'BookValueShareTotalEquityLFI', 'TangibleBookValueTotalEquityLFI', 'GrossProfitMarginLFI', 'EBITDAMarginLTM', 'IncomeBeforeTaxMarginLFI', 'IncomeAfterTaxMarginLFI', 'QuickRatioLFI', 'CurrentRatioLFI', 'LongtermDebtTotalEquityLFI', 'LongtermDebtTotalAssetsLFI', 'TotalDebtTotalEquityLFI', 'PriceRevenueShareLTM', 'PELTM', 'PriceCashFlowShareLTM', 'PriceTangibleBookTotalEquityLFI', 'EVTotalRevenue', 'EVEBITDA', 'EVEBIT', 'MarketCapitalization', 'EVLFI', 'ROCLFI', 'ROELTM', 'ROALTM', 'OutstandingShare', 'OperIncomeMarginLFI'] });
    },
    GetKeyFinancialRatioAndStatistics: function (stockCode) {
        var data = [{ Code: stockCode}];
        var field = { static: ['LastFiscalYear'], dynamic: ['TotalDebtTotalAssetLFY', 'ROELFY', 'ROALFY', 'IncomeBeforeTaxMarginLFY', 'IncomeAfterTaxMarginLFY', 'GrossProfitMarginLFY', 'TotalDebtTotalEquityLFY', 'LongtermDebtTotalEquityLFY', 'TotalDebtTotalEquityLFY', 'QuickRatioLFY', 'CurrentRatioLFY'] };
        var requestName = 'GetKeyFinancialRatioAndStatistics' + '_' + stockCode + '_NoLanguage';
        var result = AG.ClientAPI.createData(CompanyRealtime, requestName, data, field);
        data = null, field = null;
        return result;
    },
    GetPriceQuery: function (stockCode, startDate, endDate, startIndex, endIndex, orderBy, orderType) {

        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '') {
            order[0].Direction = orderType;
        }
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var requestName = 'StockPriceQuery' + '_' + stockCode + '_' + startDate + '_' + endDate + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyDaily, requestName, [{ Code: stockCode }, { StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}], { static: ['Id', 'Code', 'OpenPrice', 'ClosePrice', 'Diff', 'DiffPercent', 'RefPrice', 'CeilingPrice', 'FloorPrice', 'AveragePrice', 'TotalShare', 'TotalValue', 'SessionDate'], dynamic: ['MatchTotalShare', 'PutThroughTotalShare'] }, order);
        order = null;

    },
    GetCountPriceQuery: function (stockCode, startDate, endDate) {

        return CompanyDaily.getCount([{ Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}]);
    },
    GetPriceQueryToExcel: function (stockCode, startDate, endDate, orderBy, orderType) {
        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '')
            order[0].Direction = orderType;
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        CompanyDaily.toExcel('PriceQuery', [{ Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}], { static: ['Id', 'Code', 'SessionDate', 'OpenPrice', 'ClosePrice', 'Diff', 'DiffPercent', 'RefPrice', 'CeilingPrice', 'FloorPrice', 'AveragePrice', 'TotalShare', 'TotalValue'] }, order);
        order = null;
    },
    GetForeignTradeDaily: function (stockCode, startDate, endDate, startIndex, endIndex, orderBy, orderType) {

        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '') {
            order[0].Direction = orderType;
        }
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var data;
        data = [{ Code: stockCode }, { StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}];
        var requestName = 'StockForeignTradeDaily' + '_' + stockCode + '_' + startDate + '_' + endDate + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyDaily, requestName, data, { static: ['Id', 'Code', 'SessionDate', 'ForeignOwnedVolume', 'ForeignOwnedRatio', 'ForeignCurrentRoom', 'ForeignBuyVolume', 'ForeignBuyVolumeRatio', 'ForeignSellVolume', 'ForeignSellVolumeRatio', 'ForeignBuyValue', 'ForeignBuyValueRatio', 'ForeignSellValue', 'ForeignSellValueRatio'] }, order);
        order = null;

    },
    GetCountForeignTradeDaily: function (stockCode, startDate, endDate) {

        return CompanyDaily.getCount([{ Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}]);
    },
    GetForeignTradeDailyToExcel: function (stockCode, startDate, endDate, orderBy, orderType) {

        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '')
            order[0].Direction = orderType;

        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var data;
        data = [{ Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}];
        CompanyDaily.toExcel('ForeignTrade', data, { static: ['Id', 'Code', 'SessionDate', 'ForeignOwnedVolume', 'ForeignOwnedRatio', 'ForeignCurrentRoom', 'ForeignBuyVolume', 'ForeignBuyVolumeRatio', 'ForeignSellVolume', 'ForeignSellVolumeRatio', 'ForeignBuyValue', 'ForeignBuyValueRatio', 'ForeignSellValue', 'ForeignSellValueRatio'] }, order);
        order = null;
    },
    GetOrderDaily: function (stockCode, startDate, endDate, startIndex, endIndex, orderBy, orderType) {

        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '') {
            order[0].Direction = orderType;
        }
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var requestName = 'GetOrderDaily' + '_' + stockCode + '_' + startDate + '_' + endDate + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyDaily, requestName, [{ Code: stockCode }, { StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}], { static: ['Id', 'Code', 'SessionDate', 'OpenPrice', 'ClosePrice', 'Diff', 'DiffPercent', 'BidCountOrder', 'BidVolumeOrder', 'OfferCountOrder', 'BidVolumeOrderSurplus', 'TotalShare', 'TotalValue'], dynamic: ['OfferVolumeOrder'] }, order);
        order = null;

    },
    GetCountOrderDaily: function (stockCode, startDate, endDate) {

        return CompanyDaily.getCount([{ Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}]);
    },
    GetOrderDailyToExcel: function (stockCode, startDate, endDate, orderBy, orderType) {

        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '')
            order[0].Direction = orderType;
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        CompanyDaily.toExcel('OrderStatistics', [{ Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}], { static: ['Id', 'Code', 'SessionDate', 'OpenPrice', 'ClosePrice', 'Diff', 'DiffPercent', 'BidCountOrder', 'BidVolumeOrder', 'OfferCountOrder', 'BidVolumeOrderSurplus', 'TotalShare', 'TotalValue'], dynamic: ['OfferVolumeOrder'] }, order);
        order = null;
    },
    GetName: function (stockCode) {

        var objCompany = AG.ClientAPI.createData(CompanyInfomation, ('StockName' + stockCode), [{ Code: stockCode}], { static: ['Id', 'Code', 'Name', 'Industry', 'StockExchange'], dynamic: ['RootIndustry', 'ReportGroup'] });
        if (typeof (objCompany[0].Industry) != 'undefined')
            var objField = AG.ClientAPI.createData(CompanyCategory, ('Industry' + objCompany[0].Industry), [{ Id: objCompany[0].Industry}], { static: ['Id', 'Name'] });
        if (typeof (objCompany[0].RootIndustry) != 'undefined')
            var objRootField = AG.ClientAPI.createData(CompanyCategory, ('RootIndustry' + objCompany[0].RootIndustry), [{ Id: objCompany[0].RootIndustry}], { static: ['Id', 'Name'] });
        if (typeof (objCompany[0].StockExchange) != 'undefined')
            var objStockExchange = AG.ClientAPI.createData(StockExchange, ('StockExchange' + objCompany[0].StockExchange), [{ Id: objCompany[0].StockExchange}], { static: ['Id', 'Name'] });
        var result = { Id: objCompany[0].Id, Code: objCompany[0].Code.trim(), Name: objCompany[0].Name, Industry: objCompany[0].Industry, StockExchange: objCompany[0].StockExchange, ReportGroup: objCompany[0].ReportGroup, RootIndustry: objCompany[0].RootIndustry, IndustryName: typeof (objField) != 'undefined' ? objField[0].Name : '', RootIndustryName: typeof (objRootField) != 'undefined' ? objRootField[0].Name : '', StockExchangeName: typeof (objStockExchange) != 'undefined' ? objStockExchange[0].Name : '' };
        return result;

    },
    GetNextPlan: function (stockCodeId) {

        return AG.ClientAPI.createData(YearPlanning, stockCodeId + '_NoLanguage', [{ Company: stockCodeId }, { StartIndex: 1 }, { EndIndex: 1}], { static: ['Id', 'Code', 'Year', 'EBT', 'NBAT', 'DivInShares', 'DivInCash'], dynamic: ['Sales'] }, [{ Field: 'Year', Direction: 'DESC'}]);
    },
    GetGeneralInfo: function (stockCode) {

        return AG.ClientAPI.createData(CompanyInfomation, 'StockGeneralInfo', [{ Code: stockCode}], { static: ['Id', 'Code', 'Year', 'EBT', 'NBAT', 'DivInShares', 'DivInCash', 'Sales'] });
    },
    GetBusinessActivities: function (stockCode) {

        var objResult = AG.ClientAPI.createData(CompanyInfomation, 'BusinessActivities', [{ Code: stockCode}], { static: ['Id', 'BusinessActivities'] });
        var result = '';
        if (objResult.length > 0)
            result = objResult[0].BusinessActivities && typeof (objResult[0].BusinessActivities) != 'undefined' ? objResult[0].BusinessActivities : '';
        objResult = null;
        return result;
    },
    GetOverview: function (stockCode) {

        var objResult = AG.ClientAPI.createData(CompanyInfomation, 'Overview', [{ Code: stockCode}], { static: ['Id', 'Overview'] });
        var result = '';
        if (objResult.length > 0)
            result = objResult[0].Overview && typeof (objResult[0].Overview) != 'undefined' ? objResult[0].Overview : '';
        objResult = null;
        return result;
    },
    GetBusinessStrategy: function (stockCode) {

        var objResult = AG.ClientAPI.createData(CompanyInfomation, 'BusinessStrategy', [{ Code: stockCode}], { static: ['Id', 'BusinessStrategy'] });
        var result = '';
        if (objResult.length > 0)
            result = objResult[0].BusinessStrategy && typeof (objResult[0].BusinessStrategy) != 'undefined' ? objResult[0].BusinessStrategy : '';
        objResult = null;
        return result;
    },
    GetHeadquarter: function (stockCode) {

        return AG.ClientAPI.createData(CompanyInfomation, 'Headquarter', [{ Code: stockCode}], { static: ['Id', 'Code', 'Headquarter', 'Phone'] });
    },
    GetShareholder: function (stockCodeId, type) {
        var request = 'Shareholder' + '_' + stockCodeId + '_' + type;
        return AG.ClientAPI.createData(Shareholder, request, [{ Company: stockCodeId }, { Type: typeof type != 'undefined' ? type : AG.Config.ShareholderType.Shareholder}], { static: ['Id', 'Code', 'Name', 'HoldingQuantity', 'HoldingPercent'] });
    },
    GetListMajorShareholder: function (stockCodeId, startIndex, endIndex) {

        var order = [{ Field: 'ID', Direction: 'ASC'}];
        var requestName = 'MajorShareholder' + '_' + stockCodeId + '_' + startIndex + '_' + endIndex;
        return AG.ClientAPI.createData(Shareholder, requestName, [{ Company: stockCodeId }, { Type: AG.Config.ShareholderType.MajorShareholder }, { StartIndex: startIndex }, { EndIndex: endIndex}], { static: ['Id', 'Code', 'Name', 'CurrentPosition', 'HoldingQuantity', 'HoldingPercent', 'ExerciseDate'] }, order);
        order = null;
    },
    GetCountMajorShareholder: function (stockCodeId) {

        return Shareholder.getCount([{ Company: stockCodeId }, { Type: AG.Config.ShareholderType.MajorShareholder}]);
    },
    GetCompetitor: function (industryId, startIndex, endIndex, orderBy, orderType) {
        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '')
            order[0].Direction = orderType;
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var requestName = 'Competitor' + '_' + industryId + '_' + startIndex + '_' + endIndex + '_NoLanguage';
        var filter = [{ Field: 'RootIndustry', Type: 'Static', Index: 1, Operator: '=', Value: industryId}];
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ StartIndex: startIndex }, { EndIndex: endIndex }, { Type: AG.Config.CompanyType.Listed }, { Type: AG.Config.CompanyType.Fund }, { StockExchange: '00000000-0000-0000-0000-000000000001' }, { StockExchange: '00000000-0000-0000-0000-000000000002'}], { static: ['Id', 'Code', 'ClosePrice', 'MarketCapitalization', 'PriceBookValueShareTotalEquityLFY', 'PE', 'PB', 'PS'], dynamic: ['GrossProfitMarginLFY', 'PSLTM', 'PELTM', 'LongtermDebtTotalEquityLFY', 'LongtermDebtTotalAssetsLFY', 'TotalDebtTotalEquityLFY', 'EBITDALFY', 'EVLFY', 'ROALTM', 'ROELTM'] }, order, filter);
        order = null;
    },
    GetCountCompetitor: function (industryId) {
        var filter = [{ Field: 'RootIndustry', Type: 'Static', Index: 1, Operator: '=', Value: industryId}];
        return CompanyRealtime.getCount([{ Type: AG.Config.CompanyType.Listed }, { Type: AG.Config.CompanyType.Fund }, { StockExchange: '00000000-0000-0000-0000-000000000001' }, { StockExchange: '00000000-0000-0000-0000-000000000002'}], undefined, undefined, filter);
    },
    GetOverviewCompanyByIndustry: function (industryId, startIndex, endIndex, orderBy, orderType) {
        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'Code', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '')
            order[0].Direction = orderType;
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var requestName = 'ListCompanyByField' + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType;
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ Industry: industryId }, { StartIndex: startIndex }, { EndIndex: endIndex}], { static: ['Id', 'Code', 'Name', 'ClosePrice', 'Diff', 'DiffPercent', 'TotalShare', 'TotalValue', 'MarketCapitalization', 'PE', 'PB'], dynamic: ['EPSLFI'] }, order);
        order = null;
    },
    GetCountOverviewCompanyByIndustry: function (industryId) {

        return CompanyRealtime.getCount([{ Industry: industryId}]);
    },

    GetComparison: function (listSymbol, industryId) {
        var strCompany = "";
        for (var i = 0; i < listSymbol.length; i++) {
            if (i != listSymbol.length - 1) {
                strCompany += listSymbol[i].toString() + ',';
            }
            else strCompany += listSymbol[i].toString();
        }
        var url = '/Handler/WS.StockReport/SearchComparisonData.ashx?' + 'Language=' + agLanguageName + '&Company=' + strCompany + '&IndustryId=' + industryId;
        var result = AG.ClientAPI.getDirectData(url, false, null);
        return result.StockReportDS.CompanyRealtime;
    },
    GetStockScreener: function (filters, startIndex, endIndex, orderBy, orderType) {

        var requestName = startIndex + '_' + endIndex + '_NoLanguage';
        var fields = { static: ['Id', 'Code'], dynamic: [] };
        for (var i = 0; i < filters.length; i++) {
            if (filters[i].Type == 'Static') {
                fields.static.push(filters[i].Field);
            }
            if (filters[i].Type == 'Dynamic') {
                fields.dynamic.push(filters[i].Field);
            }
            requestName += '_' + filters[i].Field + filters[i].Operator + filters[i].Value;
        }
        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '') {
            order[0].Direction = orderType;
        }
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ StartIndex: startIndex }, { EndIndex: endIndex}], fields, order, filters);
        order = null; fields = null, filters = null;
    },
    GetCountStockScreener: function (filter) {

        return CompanyRealtime.getCount([], filter);
    },
    GetStockEscreenerToExcel: function (filters, orderBy, orderType) {

        var arrListParam = filters.split(';');
        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '')
            order[0].Direction = orderType;
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var fields = { static: ['Id', 'Code', 'Name'], dynamic: [] };
        var filter = [];
        var type = 'Static';
        for (var i = 0; i < arrListParam.length; i++) {
            var arrParam = arrListParam[i].split(',');
            switch (arrParam[0]) {
                case 'PELFI':
                    type = 'Dynamic';
                    break;
                default:
                    type = 'Static';
                    break;
            }
            filter.push({ Field: arrParam[0], Type: type, Index: i, Operator: arrParam[1], Value: arrParam[2] });
            if (type == 'Dynamic')
                fields.dynamic.push(arrParam[0]);
            else
                fields.static.push(arrParam[0]);
        }
        CompanyRealtime.toExcel('Stock Screener', [], fields, order, filter);
    },
    GetProfileSummery: function (stockCode) {

        var objCompany = AG.ClientAPI.createData(CompanyInfomation, 'ProfileSummery', [{ Code: stockCode}], { static: ['Id', 'Website', 'InitialListedShare', 'CharteredCapital'], dynamic: ['FirstTradingDate'] });
        var objCompanyRealtime = AG.ClientAPI.createData(CompanyRealtime, 'ProfileSummery' + '_NoLanguage', [{ Code: stockCode}], { static: ['Id', 'OutstandingShare', 'MarketCapitalization', 'Highest52Weeks', 'LastFiscalYear'], dynamic: ['DividendYield', 'ForeignOwnedRatio'] });
        return [{ Website: objCompany[0].Website, InitialListedShare: objCompany[0].InitialListedShare, CharteredCapital: objCompany[0].CharteredCapital, FirstTradingDate: objCompany[0].FirstTradingDate, Logo: '/Handler/WS.StockData/GetCompanyLogo.ashx?StockCode=' + stockCode, OutstandingShare: objCompanyRealtime[0].OutstandingShare, MarketCapitalization: objCompanyRealtime[0].MarketCapitalization, ForeignOwnedRatio: objCompanyRealtime[0].ForeignOwnedRatio, Highest52Weeks: objCompanyRealtime[0].Highest52Weeks, DividendYield: objCompanyRealtime[0].DividendYield, LastFiscalYear: objCompanyRealtime[0].LastFiscalYear}];
        objCompany = null, objCompanyRealtime = null;
    },
    GetMASCategoryStockScreener: function () {
        return [{ Code: 'GeneralInfo', Name: 'Popular Criteria' }, { Code: 'CompanyDescriptors', Name: 'Company Descriptors' }, { Code: 'SizeShareVolume', Name: 'Size & Share Volume' }, { Code: 'PricePriceChanges', Name: 'Price & Price Changes' }, { Code: 'Valuations', Name: 'Valuations' }, { Code: 'Profitability', Name: 'Profitability' }, { Code: 'Growth', Name: 'Growth' }, { Code: 'ManagementRatio', Name: 'Management ratio' }, { Code: 'LiquidityCoverage', Name: 'Liquidity & Coverage'}];
    },
    GetFieldByCategory: function (categoryCode) {
        switch (categoryCode) {
            case 'GeneralInfo':
                return [{ Code: 'StockExchange', Name: 'StockExchange' }, { Code: 'RootIndustry', Name: 'Industry' }, { Code: 'Industry', Name: 'Sub sector' }, { Code: 'TotalEquityLFI', Name: 'Total Equity' }, { Code: 'MarketCapitalization', Name: 'Market Capitalization' }, { Code: 'Beta', Name: 'Beta' }, { Code: 'OutstandingShare', Name: 'Outstanding Share' }, { Code: 'ForeignOwnedRatio', Name: 'Foreign own (%)'}];
                break;
            case 'CompanyDescriptors':
                return [{ Code: 'StockExchange', Name: 'StockExchange' }, { Code: 'RootIndustry', Name: 'Industry' }, { Code: 'Industry', Name: 'Sub sector'}];
                break;
            case 'SizeShareVolume':
                return [{ Code: 'OutstandingShare', Name: 'Outstanding Share' }, { Code: 'MarketCapitalization', Name: 'Market Cap' }, { Code: 'Volume30Days', Name: 'Average trading volume (20days)'}];
                break;
            case 'PricePriceChanges':
                return [{ Code: 'ClosePrice', Name: 'Current Price' }, { Code: 'Highest52Weeks', Name: '52 Week High' }, { Code: 'Lowest52Weeks', Name: '52 Week Low' }, { Code: 'Beta', Name: 'Beta' }, { Code: 'DiffPercentPrice5Days', Name: '% Price Change (1 Week) ' }, { Code: 'DiffPercentPrice1Month', Name: '% Price Change (4 Week) ' }, { Code: 'DiffPercentPrice3Months', Name: '% Price Change (12 Week) ' }, { Code: 'DiffPercentPriceThisYear', Name: '% Price Change (YTD)'}];
                break;
            case 'Valuations':
                return [{ Code: 'PELFY', Name: 'P/E' }, { Code: 'PriceBookValueShareTotalEquityLFY', Name: 'P/B' }, { Code: 'PSLFY', Name: 'P/S' }, { Code: 'BookValueShareTotalEquityLFY', Name: 'Book Value' }, { Code: 'SalesLFY', Name: 'Enterprise Value'}];
                break;
            case 'Profitability':
                return [{ Code: 'ROELTM', Name: 'ROE' }, { Code: 'ROALTM', Name: 'ROA' }, { Code: 'GrossProfitMarginLFY', Name: 'Gross Margin' }, { Code: 'IncomeAfterTaxMarginLFY', Name: 'Net Margin'}];
                break;
            case 'Growth':
                return [{ Code: 'SalesGrowthRateLFY', Name: 'Sales growth rate' }, { Code: 'RevenueGrowthRateLFY', Name: 'Gross profit growth rate' }, { Code: 'IncomeAfterTaxGrowthRateLFY', Name: 'Net profit growth rate' }, { Code: 'TotalAssetGrowthRateLFY', Name: 'Total asset growth rate' }, { Code: 'OwnersEquitiesGrowthRateLFY', Name: "Owners' equities growth rate" }, { Code: 'EPSGrowthRateLFY', Name: 'EPS growth rate'}];
                break;
            case 'ManagementRatio':
                return [{ Code: 'ReceivableTurnoverLFY', Name: "Receivable turnover " }, { Code: 'InventoryTurnoverLFY', Name: 'Inventory turnover' }, { Code: 'PayableTurnoverLFY', Name: 'Payable turnover ' }, { Code: 'CashPeriodLFY', Name: 'Cash period' }, { Code: 'AssetTurnoverLFY', Name: 'Asset turnover' }, { Code: 'LongtermAssetTurnoverLFY', Name: 'Long-term asset turnover' }, { Code: 'FixAssetTurnoverLFY', Name: 'Fix asset turnover'}];
                break;
            case 'LiquidityCoverage':
                return [{ Code: 'TotalDebtTotalAssetLFY', Name: 'Debt / Total Asset' }, { Code: 'TotalDebtTotalEquityLFY', Name: "Debt /Owners' equities" }, { Code: 'CurrentRatioLFY', Name: 'Current ratio' }, { Code: 'QuickRatioLFY', Name: 'Quick ratio' }, { Code: 'CashRatioLFY', Name: "Cash ratio"}];
                break;
        }
    },
    GetCountCompanyByField: function (field, operator, value) {
        return CompanyRealtime.getCount([{}], [{ Field: field, Index: 0, Type: 'Static', Operator: operator, Value: value}]);
    },
    GetCompanyFilter: function (strFilter, startIndex, endIndex, orderBy, orderType) {

        var arrListParam = strFilter.split(';');
        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '')
            order[0].Direction = orderType;
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var fields = { static: ['Id', 'Code', 'Name'], dynamic: [] };
        var filter = [];
        var type = 'Static';
        var dateType = 'decimal(32,2)';
        for (var i = 0; i < arrListParam.length; i++) {
            var arrParam = arrListParam[i].split(',');
            switch (arrParam[0]) {
                case 'MarketCapitalization':
                case 'Beta':
                case 'OutstandingShare':
                case 'ForeignOwnedRatio':
                case 'Volume30Days':
                case 'ClosePrice':
                case 'Highest52Weeks':
                case 'Lowest52Weeks':
                case 'DiffPercentPrice5Days':
                case 'DiffPercentPrice1Month':
                case 'DiffPercentPrice3Months':
                case 'DiffPercentPriceThisYear':
                case 'PriceBookValueShareTotalEquityLFY':
                    type = 'Static';
                    break;
                case 'StockExchange':
                case 'Industry':
                case 'RootIndustry':
                    dateType = 'nvarchar(50)';
                    type = 'Static';
                    break;
                default:
                    type = 'Dynamic';
                    break;
            }
            filter.push({ Field: arrParam[0], Type: type, DataType: dateType, Index: i, Operator: arrParam[1], Value: arrParam[2] });
            if (type == 'Dynamic')
                fields.dynamic.push(arrParam[0]);
            else
                fields.static.push(arrParam[0]);
        }
        var requestName = 'GetCompanyFilter' + '_' + strFilter + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType + "_NoLanguage";
        return AG.ClientAPI.createData(CompanyRealtime, requestName, [{ StartIndex: startIndex }, { EndIndex: endIndex}], fields, order, filter);
        order = null; filter = null, fields = null;
    },
    GetCountCompanyFilter: function (strFilter) {

        var arrListParam = strFilter.split(';');
        var filter = [], data = [{}];
        var type = 'Static';
        var dateType = 'decimal(32,2)';
        for (var i = 0; i < arrListParam.length; i++) {
            var arrParam = arrListParam[i].split(',');
            switch (arrParam[0]) {
                case 'MarketCapitalization':
                case 'Beta':
                case 'OutstandingShare':
                case 'ForeignOwnedRatio':
                case 'Volume30Days':
                case 'ClosePrice':
                case 'Highest52Weeks':
                case 'Lowest52Weeks':
                case 'DiffPercentPrice5Days':
                case 'DiffPercentPrice1Month':
                case 'DiffPercentPrice3Months':
                case 'DiffPercentPriceThisYear':
                case 'PriceBookValueShareTotalEquityLFY':
                    type = 'Static';
                    break;
                case 'StockExchange':
                case 'Industry':
                case 'RootIndustry':
                    dateType = 'nvarchar(50)';
                    type = 'Static';
                    break;
                default:
                    type = 'Dynamic';
                    break;
            }
            filter.push({ Field: arrParam[0], Type: type, DataType: dateType, Index: i, Operator: arrParam[1], Value: arrParam[2] });
        }
        return CompanyRealtime.getCount(data, undefined, undefined, filter);
        data = null, filter = null, fields = null;
    },
    GetInsiderTransaction: function (company, startIndex, endIndex, orderBy, orderType) {

        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '')
            order[0].Direction = orderType;
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var requestName = 'GetInsiderTransaction' + '_' + company + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType;
        return AG.ClientAPI.createData(InsiderTransaction, requestName, [{ Company: company }, { StartIndex: startIndex }, { EndIndex: endIndex}], { static: ['Id', 'Name', 'HoldingQuantityAfterRegistered', 'TradingType', 'HoldingQuantityAfterTransaction', 'EstimatedStartDate', 'EstimatedEndDate'], dynamic: ['CurrentPosition'] }, order);
        order = null;
    },
    GetCountInsiderTransaction: function (company) {
        return InsiderTransaction.getCount([{ Company: company}], undefined);
    },
    //    GetEvent: function (stockCode, type, startDate, endDate, startIndex, endIndex) {

    //        var order = [];
    //        var data = [{ Type: AG.Config.CompanyType.Listed }, { Type: AG.Config.CompanyType.Fund}];
    //        var dataEvent = [{ StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}];
    //        if (stockCode != '')
    //            dataEvent.push({ Company: stockCode });
    //        if (type != AG.Config.Empty && typeof (type) != 'undefined' && type != '')
    //            dataEvent.push({ Type: type });
    //        order.push({ Field: 'ExRightDate', Direction: 'DESC' });
    //        var requestName = 'GetEvent' + '_' + stockCode + '_' + type + '_' + startIndex + '_' + endIndex + '_' + startDate + '_' + endDate;
    //        return AG.ClientAPI.createData(Event, requestName, dataEvent, { static: ['Id', 'ExRightDate', 'EndRegisterDate', 'ExerciseDate', 'Type', 'Name'], dynamic: ['Title', 'Content'] }, order, undefined, [{ Name: 'AG_Stock_Company', Alias: 'E', Join: 'Left Join', JoinColumn: 'Id', MainColumn: 'Company', data: undefined, fields: { static: ['Code']}}]);
    //        order = null; data = null, dataEvent = null;
    //    },
    GetEvent: function (stockCodeId, type, startDate, endDate, startIndex, endIndex) {
        if (typeof (stockCodeId) == 'undefined')
            stockCodeId = '';
        if (typeof (type) == 'undefined')
            type = '';
        if (typeof (startDate) == 'undefined')
            startDate = '';
        if (typeof (endDate) == 'undefined')
            endDate = '';
        if (typeof (startIndex) == 'undefined')
            startIndex = '';
        if (typeof (endIndex) == 'undefined')
            endIndex = '';
        var url = '/Handler/WS.StockData/SearchMarketEvent.ashx?' + '&typeEvent=' + type + '&company=' + stockCodeId + '&startDate=' + startDate + '&endDate=' + endDate + '&startIndex=' + startIndex + '&endIndex=' + endIndex + '&language=' + agLanguageName;
        var objData = AG.ClientAPI.getDirectData(url, false, null);
        if (typeof (objData.StockDataDS.News) == 'undefined') {
            objData.StockDataDS.News = {}
        }
        if (typeof (objData.StockDataDS.News.length) == 'undefined' && typeof (objData.StockDataDS.News) != 'undefined') {
            objData.StockDataDS.News = [objData.StockDataDS.News];
            objData.StockDataDS.News.length = 0;
        }
        return objData.StockDataDS.News;
    },
    //    GetCountEvent: function (stockCode, type, startDate, endDate) {
    //        var data = [{ Type: AG.Config.CompanyType.Listed }, { Type: AG.Config.CompanyType.Fund}];
    //        var dataEvent = [{ StartDate: startDate }, { EndDate: endDate}];
    //        if (stockCode != '')
    //            dataEvent.push({ Company: stockCode });
    //        if (type != AG.Config.Empty && typeof (type) != 'undefined' && type != '')
    //            dataEvent.push({ Type: type });
    //        return Event.getCount(dataEvent);
    //        data = null, dataEvent = null;
    //    },
    GetCountEvent: function (stockCodeId, type, startDate, endDate, startIndex, endIndex) {
        var url = '/Handler/WS.StockData/CountMarketEvent.ashx?' + 'typeEvent=' + type + '&company=' + stockCodeId + '&startDate=' + startDate + '&endDate=' + endDate + '&language=' + agLanguageName;
        return AG.ClientAPI.getDirectData(url, false, null);
    },
    GetEventDetail: function (eventId) {
        var url = "/Handler/WS.StockData/SearchEventDetail.ashx?Language=" + agLanguageName + "&Id=" + eventId;
        var objData = AG.ClientAPI.getDirectData(url, false, null);
        if (typeof (objData.StockDataDS.Event) == 'undefined') {
            objData.StockDataDS.Event = {}
        }
        if (typeof (objData.StockDataDS.Event.length) == 'undefined' && typeof (objData.StockDataDS.Event) != 'undefined')
            objData.StockDataDS.Event = [objData.StockDataDS.Event];
        return objData.StockDataDS.Event;
    },
    GetEventDateInMonth: function (startDate, endDate) {
        var result = [];
        $.ajax({
            url: '/Handler/WS.StockData/GetEventExRightDateList.ashx',
            data: 't=' + new Date(),
            type: 'GET',
            dataType: 'xml',
            cache: true,
            async: false,
            success: function (data) {
                var jsonData = AGFSLib.xmlToJson($('Document', data));
                if (typeof (jsonData.length) == "undefined" && typeof (jsonData.Event) != "undefined")
                    jsonData = [jsonData.Event];
                var position = 0;
                for (var i = 0; i < jsonData.length; i++) {
                    position = result.push(jsonData[i]) - 1;
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                return false;
            }
        })
        return result;
    },
    GetTypeEvent: function () {
        var objEvent = AG.ClientAPI.createData(Config, 'GetTypeEvent', [{ Code: 'Stock.Event'}], { static: ['Id'] });
        var objGroupEvent = AG.ClientAPI.createData(Config, 'GroupEvent', [{ Type: objEvent[0].Id}], { static: ['Id'] });
        var data = [];
        for (var i = 0; i < objGroupEvent.length; i++) {
            data.push({ Type: objGroupEvent[i].Id });
        }
        objEvent = null, objGroupEvent = null;
        return AG.ClientAPI.createData(Config, 'GetEvent', data, { static: ['Id', 'Name'] });
    },
    GetGuruAnalysis: function (nameGuru, pointGuru, stockCode, startIndex, endIndex, orderBy, orderType) {

        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '')
            order[0].Direction = orderType;
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var data = [{ Type: AG.Config.CompanyType.Listed }, { Type: AG.Config.CompanyType.Fund }, { StartIndex: startIndex }, { EndIndex: endIndex}];
        if (stockCode != '')
            data.push({ Code: stockCode });
        var filter = [];
        var fields = { static: ['Id', 'Code', 'ClosePrice', 'MarketCapitalization', 'PE', 'PB', 'PS', 'EBITDAMarginLTM', 'ROALTM', 'ROELTM'], dynamic: [] };
        if (nameGuru != '' && typeof (nameGuru) != 'undefined')
            fields.static.push(nameGuru);
        if (pointGuru != '' && typeof (pointGuru) != 'undefined')
            filter.push({ Field: nameGuru, Type: 'Static', Index: 1, Operator: '>=', Value: pointGuru });
        var requestName = 'GetInsiderTransaction' + '_' + nameGuru + '_' + pointGuru + '_' + stockCode + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType + '_NoLanguage';
        return AG.ClientAPI.createData(CompanyRealtime, requestName, data, fields, order, filter);
        order = null; filter = null, fields = null, data = null;
    },
    GetCountGuruAnalysis: function (nameGuru, pointGuru, stockCode) {
        var data = [{ Type: AG.Config.CompanyType.Listed }, { Type: AG.Config.CompanyType.Fund}];
        if (stockCode != '')
            data.push({ Code: stockCode });
        var filter = [];
        var fields = { static: ['Id', 'Code', 'ClosePrice', 'MarketCapitalization', 'PE', 'PB', 'PS', 'EBITDAMarginLTM', 'ROALTM', 'ROELTM'], dynamic: [] };
        if (nameGuru != '' && typeof (nameGuru) != 'undefined')
            fields.static.push[nameGuru];
        if (pointGuru != '' && typeof (pointGuru) != 'undefined')
            filter.push({ Field: nameGuru, Type: 'Static', Index: 1, Operator: '>=', Value: pointGuru });
        return CompanyRealtime.getCount(data, fields, undefined, filter);
        data = null, filter = null, fields = null;
    },
    GetPointGuruByStockCode: function (stockCode) {
        return AG.ClientAPI.createData(CompanyRealtime, 'GetPointGuruByStockCode' + stockCode, [{ Code: stockCode}], { static: ['Id', 'Lakonishok', 'BenjaminGraham', 'JamesOShaughnessey', 'MartinZweig', 'Piotroski', 'ZacksMagicNumbers', 'Muhlenkamp', 'Templeton'] });
    },
    GetGuruByNameAndStockCode: function (guruName, stockCode) {
        var fields = { static: [], dynamic: [] };
        switch (guruName) {
            case 'Lakonishok':
                fields.dynamic = ['MarketCapitalizationTop30PercentMarket', 'PESmallerThanIndustry', 'PBSmallerThanIndustry', 'RSI14DaysPositive', 'RSI14DaysGreaterThanRSI30Days'];
                break;
            case 'BenjaminGraham':
                fields.dynamic = ['SectorNotFinancial', 'SectorNotFinancial', 'CurrentRatioNotSmallerThan2', 'LongtermDebtDivNetCurrentAssetNotGreaterThan1', 'EPSGrowthRateIn5YearsPeriodNotSmaller0.3', 'EPS3YearsNoNegative', 'PESmallerThan15', 'PEAddPBNotGreaterThan22'];
                break;
            case 'JamesOShaughnessey':
                fields.dynamic = ['MarketCapitalizationSubNotSmallerThan1000Billions', 'EPSGrowthOverIn5YearsPeriod', 'PSSmallerThan1Dot5', 'RSI30DaysTop50Market'];
                break;
            case 'MartinZweig':
                fields.dynamic = ['PEGreaterThan5', 'PENotGreaterThan3AddPEMarket', 'PESmallerThan43', 'SalesGrowthGreaterThanEPSGrowth', 'SalesGrowthGreaterThanSalesGrowthBeforeQuarter', 'EPSLFIPositive', 'EPSLFYPositive', 'EPSBeforeQuarterPositive', 'EPSGrowthRateLFIPositive', 'EPS3QuartersGrowthRateGreaterThanHalfOfLongTermEPSGrowthRate', 'EPS3QuartersGrowthRateSmallerThanEPSCurrentQuarterGrowthRate', 'EPSGrowthGreaterThanEPSGrowthBeforeYear', 'EPSGrowthRatePositiveIn3Years'];
                break;
            case 'Piotroski':
                fields.dynamic = ['PBMin30PercentMarket', 'ROAPositive', 'TotalDebtTotalEquityLFIGreaterThan1', 'LongTermDebtTotalEquityLFYSmallerThanLongTermDebtTotalEquityLFYBefore2Years', 'IncomeAfterTaxLFYGreaterThanIncomeAfterTaxLFYBeforeYear', 'CashFlowFromOperatingActivitiesLFYGreaterThanNetIncomeLFY', 'CashRatioLFYGreaterThanCashRatioLFYBeforeYear', 'SalesTotalAssetsLTMGreaterThanSalesTotalAssetsIndustryLTM'];
                break;
            case 'ZacksMagicNumbers':
                fields.dynamic = ['PESmallerThanIndustry', 'PBSmallerThanIndustry', 'LastPriceDiv52HighestWeeksNotSmallerThan0Dot9', 'EPSLFIDivEPSLFIBeforeGreaterThanIndustry', 'EPSLFIBeforeDivEPSLFIBefore2GreaterThanSubIndustry', 'ClosePriceNotSmallerThan50000', 'AverageVolume30DaysNotSmallerThan50000'];
                break;
            case 'Muhlenkamp':
                fields.dynamic = ['ROEGreaterThanROEIndustry', 'AverageROEIn5YearsGreaterThanROEIndustry', 'PESmallerThanIndustry', 'PBSmallerThan2', 'CARGPositive', 'CAGRGreaterThanIndustry', 'IncomeAfterTaxLFIGreaterThanIncomeAfterTaxLFIIndustry', 'TotalDebtTotalAssetsSmallThanTotalDebtTotalAssetsIndustry', 'CashRatioGreaterThan1', 'FreeCashFlowPositive'];
                break;
            case 'Templeton':
                fields.dynamic = ['PBSmallerThan40PercentMarket', 'PESmallerThanIndustry', 'EPSTrailingGrowthRatePositive', 'EPS5YearsGrowthRatePositive', 'EPSGrowthGreaterThanEPSIndustry', 'OperatingIncomeMarginGreaterThanOperatingIncomeMarginIndustry', 'TotalDebtTotalEquityGreaterThanTotalDebtTotalEquityIndustry', 'TotalAssetsTotalDebtGreaterThanTotalAssetsTotalDebtIndustry', 'ROEGreaterThanIndustry'];
                break;
            default:
                fields.dynamic = ['MarketCapitalizationTop30PercentMarket', 'PESmallerThanIndustry', 'PBSmallerThanIndustry', 'RSI14DaysPositive', 'RSI14DaysGreaterThanRSI30Days'];
                break;
        }
        return AG.ClientAPI.createData(CompanyRealtime, guruName + stockCode + '_NoLanguage', [{ Code: stockCode}], fields);
    },
    GetTypeFinancialReport: function (reportGroup) {
        if (typeof (reportGroup) == 'undefined' || reportGroup == AG.Config.Empty)
            reportGroup = AG.Config.Empty;

        return AG.ClientAPI.createData(FieldCategory, reportGroup, [{ ParentId: reportGroup, Type: AG.Config.DataType.ReportGroup}], { static: ['Id', 'Code', 'Name', 'Level', 'Type', 'PathById'] });
    },
    GetFinancialTime: function (level, startIndex, endIndex, parentId, endDate) {
        var that = this;
        level = parseInt(level);
        var data = [];
        data.push({ Level: level });
        if (typeof startIndex != 'undefined') {
            data.push({ StartIndex: startIndex });
        }
        if (typeof endIndex != 'undefined') {
            data.push({ EndIndex: endIndex });
        }
        var requestName = level + '_' + startIndex + '_' + endIndex + '_' + parentId;
        var order = [{ Field: 'EndDate', Direction: 'DESC'}];
        if (typeof (endDate) == 'undefined') {
            var objDate = new Date();
            endDate = objDate.getFullYear() + '-12-30T00:00:00+07:00';
        }
        var filter = [{ Field: 'EndDate', Type: 'Static', Index: 1, Operator: '<=', Value: endDate}];
        var result;
        result = AG.ClientAPI.createData(FinancialTime, requestName, data, { static: ['Id', 'Name'] }, order, filter);
        data = null, order = null;
        filter = null;
        return result;
    },
    GetFinancialInfomationOverview: function (companyId, timeLevel, startIndex, endIndex, reportGroup) {
        var that = this;
        reportGroup = reportGroup.toLowerCase();
        var endDate = that.GetLastFinancialTime(companyId, timeLevel);
        var objTime = that.GetFinancialTime(timeLevel, startIndex, endIndex, '', endDate.EndDate);
        var data = [{ Company: companyId }, { ReportType: 'All'}];
        for (var i = 0; i < objTime.length; i++) {
            data.push({ FinancialTime: objTime[i].Id });
        }
        var objFinancialReport = FinancialReport;
        requestNameFIO = 'FinancialReportById' + companyId + '_' + timeLevel + '_' + reportGroup + '_' + startIndex + '_' + endIndex;
        objFinancialReport.getFinancialInfoById(requestNameFIO, data, { static: ['Id', 'FinancialTime'] });
        var objFinancialReport = objFinancialReport.data[requestNameFIO];
        return { Time: objTime, financialReport: objFinancialReport };
    },
    GetFinancialInfomation: function (func, companyId, timeLevel, typeFinancialReport, typeCompany, startIndex, endIndex) {
        var that = this;
        var endDate = that.GetLastFinancialTime(companyId, timeLevel);
        var objTime = that.GetFinancialTime(timeLevel, startIndex, endIndex, undefined, endDate.EndDate);
        var data = [{ Company: companyId }, { ReportType: 'All'}];
        for (var i = 0; i < objTime.length; i++) {
            data.push({ FinancialTime: objTime[i].Id });
        }
        var requestNameFR = 'FinancialReport' + companyId + '_' + timeLevel + '_' + typeCompany + '_' + startIndex + '_' + endIndex;
        for (var i = 0; i < typeFinancialReport.length; i++) {
            data.push({ Type: typeFinancialReport[i] });
            requestNameFR += '_' + typeFinancialReport;
        }
        var objFinancialReport = AG.ClientAPI.createData(FinancialReport, requestNameFR, data);
        AG.ClientAPI.add(func, function () { return FinancialReport.pkConditions[requestNameFR].isRun; }, function () { return { Time: objTime, financialReport: AG.ClientAPI.getData(FinancialReport, requestNameFR) }; });
        obj = null, order = null; data = null, objFinancialReport = null;
    },
    GetPerShareOverview: function (func, companyId, data, reportGroup, startIndex, endIndex) {
        var that = this;
        var requestNamePSV = 'GetPerShareOverview' + '_' + companyId + '_' + '_' + reportGroup + '_' + startIndex + '_' + '_' + endIndex;
        for (var i = 0; i < data.length; i++) {
            data[i] = { Code: data[i] };
        }
        data.push({ ParentId: reportGroup });
        var objField = Field.searchField(requestNamePSV, data);
        reportGroup = reportGroup.toLowerCase();
        var endDate = that.GetLastFinancialTime(companyId, 2);
        var objTime = that.GetFinancialTime(1, startIndex, endIndex, '', endDate.EndDate);
        data = [{ Company: companyId }, { ReportType: 'All'}];
        for (var i = 0; i < objTime.length; i++) {
            data.push({ FinancialTime: objTime[i].Id });
        }
        var fields = { static: ['Id', 'FinancialTime'], dynamic: ['EPSLTM', 'PELTM'], field: [] };
        for (var i = 0; i < objField.length; i++) {
            fields.field.push({ Id: objField[i].Id });
        }
        FinancialReport.getFinancialInfoById(requestNamePSV, data, fields);
        AG.ClientAPI.add(func, function () { return FinancialReport.pkConditions[requestNamePSV].isRun; }, function () { return { Time: objTime, financialReport: AG.ClientAPI.getData(FinancialReport, requestNamePSV) }; });
        objField = null, order = null; objFinancialReport = null, data = null, fields = null;
    },
    GetAnnualSummaryData: function (func, companyId, data, timeLevel, startIndex, endIndex, reportGroup) {
        var that = this;
        var requestNameAND = 'GetAnnualSummaryData' + '_' + companyId + '_' + '_' + reportGroup + '_' + timeLevel + '_' + startIndex + '_' + endIndex;
        for (var i = 0; i < data.length; i++) {
            data[i] = { Code: data[i] };
        }
        data.push({ ParentId: reportGroup });
        var objField = Field.searchField(requestNameAND, data);
        var endDate = that.GetLastFinancialTime(companyId, timeLevel);
        var objTime = that.GetFinancialTime(timeLevel, startIndex, endIndex, '', endDate.EndDate);
        data = [{ Company: companyId }, { ReportType: 'All'}];
        for (var i = 0; i < objTime.length; i++) {
            data.push({ FinancialTime: objTime[i].Id });
        }
        var fields = { static: ['Id', 'FinancialTime'], field: [] };
        for (var i = 0; i < objField.length; i++) {
            fields.field.push({ Id: objField[i].Id });
        }
        FinancialReport.getFinancialInfoById(requestNameAND, data, fields);
        AG.ClientAPI.add(func, function () { return FinancialReport.pkConditions[requestNameAND].isRun; }, function () { return { Time: objTime, financialReport: AG.ClientAPI.getData(FinancialReport, requestNameAND) }; });
        objField = null, order = null; objFinancialReport = null, data = null, fields = null;
    },
    GetSnapsotCashFlow: function (func, companyId, code, timeLevel, startIndex, endIndex, reportGroup) {
        var that = this;
        var requestNameFRBFC = 'GetSnapsotCashFlow' + '_' + companyId + '_' + '_' + reportGroup + '_' + timeLevel + '_' + startIndex + '_' + endIndex;
        for (var i = 0; i < code.length; i++) {
            code[i] = { Code: code[i] };
            requestNameFRBFC += '_' + code[i];
        }
        code.push({ ParentId: reportGroup });
        var objField = Field.searchField(requestNameFRBFC, code);
        code = null;
        var endDate = that.GetLastFinancialTime(companyId, timeLevel);
        var objTime = that.GetFinancialTime(timeLevel, startIndex, endIndex, '', endDate.EndDate);
        var data = [{ ReportType: 'All'}];
        for (var i = 0; i < objTime.length; i++) {
            data.push({ FinancialTime: objTime[i].Id });
        }
        data.push({ Company: companyId });
        var fields = { static: ['Id', 'FinancialTime'], field: [] };
        for (var i = 0; i < objField.length; i++) {
            fields.field.push({ Id: objField[i].Id });
        }
        FinancialReport.getFinancialInfoById(requestNameFRBFC, data, fields);
        AG.ClientAPI.add(func, function () { return FinancialReport.pkConditions[requestNameFRBFC].isRun; }, function () { return { Time: objTime, financialReport: AG.ClientAPI.getData(FinancialReport, requestNameFRBFC) }; });
        objField = null, order = null; objFinancialReport = null, data = null, fields = null;
    },
    GetFinancialReportByFieldCode: function (func, companyId, code, timeLevel, startIndex, endIndex, reportGroup) {
        var that = this;
        var requestNameFRBFC = 'GetFinancialReportByFieldCode' + '_' + companyId + '_' + '_' + reportGroup + '_' + timeLevel + '_' + startIndex + '_' + endIndex;
        for (var i = 0; i < code.length; i++) {
            code[i] = { Code: code[i] };
            requestNameFRBFC += '_' + code[i];
        }
        code.push({ ParentId: reportGroup });
        var objField = Field.searchField(requestNameFRBFC, code);
        code = null;
        var endDate = that.GetLastFinancialTime(companyId, timeLevel);
        var objTime = that.GetFinancialTime(timeLevel, startIndex, endIndex, '', endDate.EndDate);
        var data = [{ ReportType: 'All'}];
        for (var i = 0; i < objTime.length; i++) {
            data.push({ FinancialTime: objTime[i].Id });
        }
        data.push({ Company: companyId });
        var fields = { static: ['Id', 'FinancialTime'], field: [] };
        for (var i = 0; i < objField.length; i++) {
            fields.field.push({ Id: objField[i].Id });
        }
        FinancialReport.getFinancialInfoById(requestNameFRBFC, data, fields);
        AG.ClientAPI.add(func, function () { return FinancialReport.pkConditions[requestNameFRBFC].isRun; }, function () { return { Time: objTime, financialReport: AG.ClientAPI.getData(FinancialReport, requestNameFRBFC) }; });
        objField = null, order = null; objFinancialReport = null, data = null, fields = null;
    },
    GetFinancialReportComparison: function (func, companyId, code, timeId, reportGroup) {
        var requestNameFRC = 'GetFinancialReportComparison' + '_' + companyId + '_' + '_' + reportGroup + '_' + timeId;
        for (var i = 0; i < code.length; i++) {
            requestNameFRC += '_' + code[i];
            code[i] = { Code: code[i] };
        }
        code.push({ ParentId: reportGroup });
        var objField = Field.searchField(requestNameFRC, code);
        code = null;
        var fields = { static: ['Id', 'FinancialTime'], field: [] };
        for (var i = 0; i < objField.length; i++) {
            fields.field.push({ Id: objField[i].Id });
        }
        var data = [{ Company: companyId }, { ReportType: 'All' }, { FinancialTime: timeId}];
        FinancialReport.getFinancialInfoById(requestNameFRC, data, fields);
        AG.ClientAPI.add(func, function () { return FinancialReport.pkConditions[requestNameFRC].isRun; }, function () { return { Time: [timeId], financialReport: AG.ClientAPI.getData(FinancialReport, requestNameFRC), Code: companyId, ReportGroup: reportGroup }; });
        objField = null, data = null, fields = null;
    },
    GetLastFinancialTime: function (companyId, timeLevel) {
        var requestName = 'GetLastFinancialTime' + '_' + companyId + '_' + timeLevel;
        var result = AG.ClientAPI.createData(FinancialTime, requestName, [{ Level: timeLevel }, { StartIndex: 1 }, { EndIndex: 1}], { static: ['Id', 'Name', 'EndDate'] }, [{ Field: 'EndDate', Direction: 'DESC'}], undefined);
        if (result.length > 0) {
            return result[0];
        }
        else
            return {};
    },
    GetFinancialAndRatios: function (func, companyId, fReport, fRatio, timeLevel, startIndex, endIndex, reportGroup) {
        var that = this;
        var strfReport = ""; var strfRatio = "", typeReport = "";
        for (var i = 0; i < fReport.length; i++) {
            if (fReport[i] != "" && typeof (fReport[i]) != 'undefined') {
                if (i != fReport.length - 1) {
                    strfReport += fReport[i] + ',';
                } else strfReport += fReport[i];
            }
        }
        if (timeLevel == "1") {
            typeRatio = "LFY";
        }
        else { typeRatio = "LFI" }
        for (var i = 0; i < fRatio.length; i++) {
            if (fRatio[i] != "" && typeof (fRatio[i]) != 'undefined') {
                if (i != fRatio.length - 1) {
                    strfRatio += fRatio[i] + typeRatio + ',';
                } else strfRatio += fRatio[i] + typeRatio;
            }
        }
        var objTypeFR = AG.Data.Stock.GetTypeFinancialReport(reportGroup);
        /* Lấy ra loại báo cáo là Cân đối kế toán  */
        for (var i = 0; i < objTypeFR.length; i++) {
            // Kiểm tra trong chuỗi có "BS"(Cân đối kế toán)
            //if ((objTypeFR[i].Code).indexOf("ARP") > 0) {
            // Lấy ra loại báo cáo
            typeReport += objTypeFR[i].Id + ',';
            //}
        }
        var url = '/Handler/WS.StockData/SearchFinancialReportByFieldCode.ashx?' + 'Language=' + agLanguageName + '&Level=' + timeLevel + '&Company=' + companyId + '&StartIndex=' + startIndex + '&EndIndex=' + endIndex + '&FinancialReport=' + strfReport + '&FinancialRatio=' + strfRatio + '&TypeReport=' + typeReport;
        ///Handler/WS.StockData/SearchFinancialReportByFieldCode.ashx?Language=vi-VN&Level=1&StartIndex=1&EndIndex=4&Company=00000000-0000-0000-0000-000000000003
        AG.ClientAPI.getDataAsync(url, true, func);
    },

    GetFinancialCompanyByFieldCode: function (companyId, fReport, fRatio, timeLevel, finacialTime, reportGroup) {
        var that = this;
        var strfReport = ""; var strfRatio = "";
        for (var i = 0; i < fReport.length; i++) {
            if (fReport[i] != "" && typeof (fReport[i]) != 'undefined') {
                if (i != fReport.length - 1) {
                    strfReport += fReport[i] + ',';
                } else strfReport += fReport[i];
            }
        }
        if (timeLevel == "1") {
            typeRatio = "";
        }
        else { typeRatio = "" }
        for (var i = 0; i < fRatio.length; i++) {
            if (fRatio[i] != "" && typeof (fRatio[i]) != 'undefined') {
                if (i != fRatio.length - 1) {
                    strfRatio += fRatio[i] + typeRatio + ',';
                } else strfRatio += fRatio[i] + typeRatio;
            }
        }
        // Lấy loại công ty
        var typeCompany = reportGroup;
        var objTypeFR = AG.Data.Stock.GetTypeFinancialReport(typeCompany);
        /* Lấy ra loại báo cáo là Cân đối kế toán  */
        for (var i = 0; i < objTypeFR.length; i++) {
            // Kiểm tra trong chuỗi có "BS"(Cân đối kế toán)
            if ((objTypeFR[i].Code).indexOf("ARP") > 0) {
//            if ((objTypeFR[i].Code).indexOf("FR") > 0) {
                // Lấy ra loại báo cáo
                typeReport = objTypeFR[i].Id;
                break;
            }
        }
        var url = '/Handler/WS.StockData/SearchFinancialCompanyByFieldCode.ashx?' + 'Language=' + agLanguageName + '&Company=' + companyId + '&FinancialReport=' + strfReport + '&FinancialRatio=' + strfRatio + '&TypeReport=' + typeReport + '&FinancialTime=' + finacialTime;
        // /Handler/WS.StockData/SearchFinancialCompanyByFieldCode.ashx?Language=vi-VN&Company=00000000-0000-0000-0000-000000000012&FinancialTime=8B61EDF4-4DA8-457D-BB1B-82684F223508&TypeReport=03a587fc-9969-41bd-a8db-30b795dc776e&FinancialRatio=PELFI,EPSLFI&FinancialReport=,
        var result = AG.ClientAPI.getDirectData(url, false, null);
        return result.StockDataDS.FinancialReport;
    }
}
