<commit_before>var Statement = (function(){
    'use strict';
    var moment = require('../../../../lib/moment/moment');
    var StringUtil = require('../../../common_functions/string_util').StringUtil,
        addComma = require('../../../websocket_pages/trade/common').addComma,
        format_money_jp = require('../../../common_functions/currency_to_symbol').format_money_jp,
        toJapanTimeIfNeeded = require('../../../base/utility').toJapanTimeIfNeeded;

    var getStatementData = function(statement, currency, jpClient) {
        var dateObj = new Date(statement["transaction_time"] * 1000),
            momentObj = moment.utc(dateObj),
            dateStr = momentObj.format("YYYY-MM-DD"),
            timeStr = momentObj.format("HH:mm:ss") + ' GMT',
            payout  = parseFloat(statement["payout"]).toFixed(2),
            amount  = addComma(parseFloat(statement["amount"])),
            balance = addComma(parseFloat(statement["balance_after"]));

        var statement_data = {
            'date'    : jpClient ? toJapanTimeIfNeeded(statement["transaction_time"]) : dateStr + "\n" + timeStr,
            'ref'     : statement["transaction_id"],
            'payout'  : isNaN(payout) ? '-' : (jpClient ? format_money_jp(currency, payout) : payout),
            'action'  : StringUtil.toTitleCase(statement["action_type"]),
            'amount'  : jpClient ? format_money_jp(currency, amount) : amount,
            'balance' : jpClient ? format_money_jp(currency, balance) : balance,
            'desc'    : statement["longcode"].replace(/\n/g, '<br />'),
            'id'      : statement["contract_id"],
            'app_id'  : statement["app_id"]
        };

        return statement_data;
    };

    var generateCSV = function(allData){
        var columns = ['date', 'ref', 'payout', 'action', 'desc', 'amount', 'balance'],
            header  = ['Date', 'Reference ID', 'Potential Payout', 'Action', 'Description', 'Credit/Debit'].map(function(str){return page.text.localize(str);});
        header.push(page.text.localize('Balance') + (TUser.get().currency ? ' (' + TUser.get().currency + ')' : ''));
        var sep = ',',
            csv = [header.join(sep)];
        if (allData && allData.length > 0) {
            csv = csv.concat(
                allData.map(function(data){
                    return columns.map(function(key){
                       return (data[key] ? data[key].replace(new RegExp(sep, 'g'), '').replace(new RegExp('\n|<br />', 'g'), ' ') : '');
                    }).join(sep);
                })
            );
        }
        return csv.join('\r\n');
    };

    var attachDatePicker = function() {
        $('#jump-to').datepicker({
            dateFormat: 'yy-mm-dd',
            maxDate   : moment().toDate(),
            onSelect  : function() {
                $('.table-container').remove();
                StatementWS.init();
            }
        });
    };

    var external = {
        getStatementData: getStatementData,
        generateCSV: generateCSV,
        attachDatePicker: attachDatePicker
    };

    return external;
}());

module.exports = {
    Statement: Statement,
};<commit_msg>Fix duplicate result on csv when date picker changed<commit_after>var Statement = (function(){
    'use strict';
    var moment = require('../../../../lib/moment/moment');
    var StringUtil = require('../../../common_functions/string_util').StringUtil,
        addComma = require('../../../websocket_pages/trade/common').addComma,
        format_money_jp = require('../../../common_functions/currency_to_symbol').format_money_jp,
        toJapanTimeIfNeeded = require('../../../base/utility').toJapanTimeIfNeeded;

    var getStatementData = function(statement, currency, jpClient) {
        var dateObj = new Date(statement["transaction_time"] * 1000),
            momentObj = moment.utc(dateObj),
            dateStr = momentObj.format("YYYY-MM-DD"),
            timeStr = momentObj.format("HH:mm:ss") + ' GMT',
            payout  = parseFloat(statement["payout"]).toFixed(2),
            amount  = addComma(parseFloat(statement["amount"])),
            balance = addComma(parseFloat(statement["balance_after"]));

        var statement_data = {
            'date'    : jpClient ? toJapanTimeIfNeeded(statement["transaction_time"]) : dateStr + "\n" + timeStr,
            'ref'     : statement["transaction_id"],
            'payout'  : isNaN(payout) ? '-' : (jpClient ? format_money_jp(currency, payout) : payout),
            'action'  : StringUtil.toTitleCase(statement["action_type"]),
            'amount'  : jpClient ? format_money_jp(currency, amount) : amount,
            'balance' : jpClient ? format_money_jp(currency, balance) : balance,
            'desc'    : statement["longcode"].replace(/\n/g, '<br />'),
            'id'      : statement["contract_id"],
            'app_id'  : statement["app_id"]
        };

        return statement_data;
    };

    var generateCSV = function(allData){
        var columns = ['date', 'ref', 'payout', 'action', 'desc', 'amount', 'balance'],
            header  = ['Date', 'Reference ID', 'Potential Payout', 'Action', 'Description', 'Credit/Debit'].map(function(str){return page.text.localize(str);});
        header.push(page.text.localize('Balance') + (TUser.get().currency ? ' (' + TUser.get().currency + ')' : ''));
        var sep = ',',
            csv = [header.join(sep)];
        if (allData && allData.length > 0) {
            csv = csv.concat(
                allData.map(function(data){
                    return columns.map(function(key){
                       return (data[key] ? data[key].replace(new RegExp(sep, 'g'), '').replace(new RegExp('\n|<br />', 'g'), ' ') : '');
                    }).join(sep);
                })
            );
        }
        return csv.join('\r\n');
    };

    var attachDatePicker = function() {
        $('#jump-to').datepicker({
            dateFormat: 'yy-mm-dd',
            maxDate   : moment().toDate(),
            onSelect  : function() {
                $('.table-container').remove();
                StatementUI.clearTableContent();
                StatementWS.init();
            }
        });
    };

    var external = {
        getStatementData: getStatementData,
        generateCSV: generateCSV,
        attachDatePicker: attachDatePicker
    };

    return external;
}());

module.exports = {
    Statement: Statement,
};
{'fraction_non_alphanumeric': 0.17144638403990026, 'fraction_numerical': 0.0018703241895261845, 'mean_word_length': 2.2360060514372164, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1692953', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1824, 'n_words': 311}