<commit_before>'use strict';

var viewInvOrg = {};

viewInvOrg.filterPaidStatus = 'A';
viewInvOrg.filterInvType = 'A';
viewInvOrg.filterInvYear = new Date().getFullYear().toString();

viewInvOrg.init = function(invOrgId, u) {
    console.log('Initializing Invoicing Org');
    viewInvOrg.user = JSON.parse(u);
    moment.locale(viewInvOrg.user.locales.substr(0, 2));

    $('#dueOption').editable({
        source: [
            { value: 1, text: 'Dni splatnosti' },
            { value: 2, text: 'Dátum splatnosti' },
            { value: 3, text: 'min(dni,dátum)' }
        ]
    });

    $('.editable').editable();

    //var invOrgId = getResourceId(location.href);
    $('#filterPaidStatus').val(viewInvOrg.filterPaidStatus);
    $('#filterInvType').val(viewInvOrg.filterInvType);
    $('#filterInvYear').val(viewInvOrg.filterInvYear);

    viewInvOrg.loadManagers(invOrgId);
    viewInvOrg.loadInvoices(invOrgId);
    viewInvOrg.loadTemplates(invOrgId);

    $('#filterPaidStatus').on('change', function(ev) {
        viewInvOrg.filterPaidStatus = ev.target.value;
        console.log(viewInvOrg.filterPaidStatus);
        viewInvOrg.loadInvoices(invOrgId);
    });

    $('#filterInvType').on('change', function(ev) {
        viewInvOrg.filterInvType = ev.target.value;
        console.log(viewInvOrg.filterInvType);
        viewInvOrg.loadInvoices(invOrgId);
    });

    $('#filterInvYear').on('change', function(ev) {
        viewInvOrg.filterInvYear = ev.target.value;
        console.log(viewInvOrg.filterInvYear);
        viewInvOrg.loadInvoices(invOrgId);
    });

    $('#addManager').on('click', function(ev) {
        libModals.editValue(
            '<NAME>',
            'Používateľ',
            'prihlasovacie meno používateľa',
            'text',
            '',
            function(browserEvent, username, onSuccess, onError) {
                if (typeof onSuccess !== 'function')
                    onSuccess = function(u) {
                        return true;
                    };
                if (typeof onError !== 'function')
                    onError = function(msg) {
                        console.log('ERROR: ', msg);
                    };

                libInvOrg.addManager(invOrgId, username, function(res, err) {
                    if (err) return onError(err.message);
                    onSuccess(res);
                });
            },
            function(res) {
                console.log('new invorg manager added');
                viewInvOrg.loadManagers(invOrgId);
            },
            function(msg) {
                alert('Chyba pri pridávaní manažéra organizácie.\n\n' + msg);
            }
        );
    });
};

viewInvOrg.loadInvoices = function(invOrgId) {
    var site =
        location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
    console.log('Loading invoices');
    var t = $('#allInvoices');
    var ti = $('#allInvoices>*'); // all children of specified element
    var q = '&invOrg=' + invOrgId;

    if (viewInvOrg.filterPaidStatus != 'A') q += '&isPaid=' + viewInvOrg.filterPaidStatus;

    if (viewInvOrg.filterInvType != 'A') q += '&type=' + viewInvOrg.filterInvType;

    q += '&year=' + viewInvOrg.filterInvYear;

    $.get(libCommon.getNoCache('/invoice?cmd=getList' + q), function(res) {
        console.log('Server returned invoices', res);
        if (res.result === 'ok') {
            console.log('List of', res.list.length, 'records');
            ti.remove();
            if (res.list.length > 0) {
                console.log('Found ', res.list.length, 'records');
                var c = $('<tr>')
                    .append($('<th>').append('#'))
                    .append($('<th>').append('Organizácia'))
                    .append($('<th>').append('Suma'))
                    .append($('<th>').append('Vystavená'))
                    .append($('<th>').append('Splatná'))
                    .append($('<th>').append('Zaplatená'));
                t.append(c);

                res.list.forEach(function(item) {
                    c = $('<tr>')
                        .append(
                            $('<td>').append(
                                $('<a href="/invoice/' + item._id + '">').append(item.number)
                            )
                        )
                        .append(
                            $('<td>')
                                .append(item.billOrg.name + ', ' + item.billAdr.city + ' ')
                                .append($('<a href="/team/' + item.team + '">').append('[tím]'))
                        )
                        .append($('<td>').append(item.total.toFixed(2)))
                        .append(
                            $('<td>').append(
                                new Date(item.issuedOn).toLocaleDateString(res.user.locales)
                            )
                        )
                        .append(
                            $('<td>').append(
                                new Date(item.dueOn).toLocaleDateString(res.user.locales)
                            )
                        );

                    if (item.paidOn)
                        c.append(
                            $('<td>').append(
                                new Date(item.paidOn).toLocaleDateString(res.user.locales)
                            )
                        );
                    else if ((res.user.isInvoicingOrgManager || res.user.isAdmin) && !item.isDraft)
                        c.append(
                            $('<td>').append(
                                $(
                                    '<button id="PAY' +<commit_msg>open invoice in new tab #95<commit_after>'use strict';

var viewInvOrg = {};

viewInvOrg.filterPaidStatus = 'A';
viewInvOrg.filterInvType = 'A';
viewInvOrg.filterInvYear = new Date().getFullYear().toString();

viewInvOrg.init = function(invOrgId, u) {
    console.log('Initializing Invoicing Org');
    viewInvOrg.user = JSON.parse(u);
    moment.locale(viewInvOrg.user.locales.substr(0, 2));

    $('#dueOption').editable({
        source: [
            { value: 1, text: 'Dni splatnosti' },
            { value: 2, text: 'Dátum splatnosti' },
            { value: 3, text: 'min(dni,dátum)' }
        ]
    });

    $('.editable').editable();

    //var invOrgId = getResourceId(location.href);
    $('#filterPaidStatus').val(viewInvOrg.filterPaidStatus);
    $('#filterInvType').val(viewInvOrg.filterInvType);
    $('#filterInvYear').val(viewInvOrg.filterInvYear);

    viewInvOrg.loadManagers(invOrgId);
    viewInvOrg.loadInvoices(invOrgId);
    viewInvOrg.loadTemplates(invOrgId);

    $('#filterPaidStatus').on('change', function(ev) {
        viewInvOrg.filterPaidStatus = ev.target.value;
        console.log(viewInvOrg.filterPaidStatus);
        viewInvOrg.loadInvoices(invOrgId);
    });

    $('#filterInvType').on('change', function(ev) {
        viewInvOrg.filterInvType = ev.target.value;
        console.log(viewInvOrg.filterInvType);
        viewInvOrg.loadInvoices(invOrgId);
    });

    $('#filterInvYear').on('change', function(ev) {
        viewInvOrg.filterInvYear = ev.target.value;
        console.log(viewInvOrg.filterInvYear);
        viewInvOrg.loadInvoices(invOrgId);
    });

    $('#addManager').on('click', function(ev) {
        libModals.editValue(
            '<NAME>',
            'Používateľ',
            '<NAME>ívateľa',
            'text',
            '',
            function(browserEvent, username, onSuccess, onError) {
                if (typeof onSuccess !== 'function')
                    onSuccess = function(u) {
                        return true;
                    };
                if (typeof onError !== 'function')
                    onError = function(msg) {
                        console.log('ERROR: ', msg);
                    };

                libInvOrg.addManager(invOrgId, username, function(res, err) {
                    if (err) return onError(err.message);
                    onSuccess(res);
                });
            },
            function(res) {
                console.log('new invorg manager added');
                viewInvOrg.loadManagers(invOrgId);
            },
            function(msg) {
                alert('Chyba pri pridávaní manažéra organizácie.\n\n' + msg);
            }
        );
    });
};

viewInvOrg.loadInvoices = function(invOrgId) {
    var site =
        location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
    console.log('Loading invoices');
    var t = $('#allInvoices');
    var ti = $('#allInvoices>*'); // all children of specified element
    var q = '&invOrg=' + invOrgId;

    if (viewInvOrg.filterPaidStatus != 'A') q += '&isPaid=' + viewInvOrg.filterPaidStatus;

    if (viewInvOrg.filterInvType != 'A') q += '&type=' + viewInvOrg.filterInvType;

    q += '&year=' + viewInvOrg.filterInvYear;

    $.get(libCommon.getNoCache('/invoice?cmd=getList' + q), function(res) {
        console.log('Server returned invoices', res);
        if (res.result === 'ok') {
            console.log('List of', res.list.length, 'records');
            ti.remove();
            if (res.list.length > 0) {
                console.log('Found ', res.list.length, 'records');
                var c = $('<tr>')
                    .append($('<th>').append('#'))
                    .append($('<th>').append('Organizácia'))
                    .append($('<th>').append('Suma'))
                    .append($('<th>').append('Vystavená'))
                    .append($('<th>').append('Splatná'))
                    .append($('<th>').append('Zaplatená'));
                t.append(c);

                res.list.forEach(function(item) {
                    c = $('<tr>')
                        .append(
                            $('<td>').append(
                                $('<a href="/invoice/' + item._id + '" target="_blank">').append(
                                    item.number
                                )
                            )
                        )
                        .append(
                            $('<td>')
                                .append(item.billOrg.name + ', ' + item.billAdr.city + ' ')
                                .append($('<a href="/team/' + item.team + '">').append('[tím]'))
                        )
                        .append($('<td>').append(item.total.toFixed(2)))
                        .append(
                            $('<td>').append(
                                new Date(item.issuedOn).toLocaleDateString(res.user.locales)
                            )
                        )
                        .append(
                            $('<td>').append(
                                new Date(item.dueOn).toLocaleDateString(res.user.locales)
                            )
                        );

                    if (item.paidOn)
                        c.append(
                            $('<td>').append(
                                new Date(item.paidOn).toLocaleDateString(res.user.locales)
                            )
                        );
                    else if ((res.user.isInvoicingOrgManager || res.user.isAdmin) && !item.isDraft)
                        c.append(
                            $('<td>').append(
                                $(
                                    '<button id="PAY' +
{'fraction_non_alphanumeric': 0.15347010039284156, 'fraction_numerical': 0.001396769969445657, 'mean_word_length': 1.4400425985090521, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '491697', 'n_tokens_mistral': 3379, 'n_tokens_neox': 3168, 'n_words': 460}