import ngModule from '../module';
import Section from 'salix/components/section';
import './style.scss';

export default class Controller extends Section {
    constructor($element, $, vnReport) {
        super($element, $);

        this.vnReport = vnReport;
        const now = Date.vnNew();
        const firstDayOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
        const lastDayOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0);
        this.params = {
            from: firstDayOfMonth,
            to: lastDayOfMonth
        };
        this.$checkAll = false;

        this.smartTableOptions = {
            activeButtons: {
                search: true,
            },
            columns: [
                {
                    field: 'isActive',
                    searchable: false
                },
                {
                    field: 'hasToInvoice',
                    searchable: false
                },
                {
                    field: 'isTaxDataChecked',
                    searchable: false
                },
            ]
        };
    }

    exprBuilder(param, value) {
        switch (param) {
        case 'company':
            return {'company': value};
        case 'country':
            return {'country': value};
        case 'clientId':
            return {'clientId': value};
        case 'clientSocialName':
            return {'clientSocialName': value};
        case 'amount':
            return {'amount': value};
        case 'taxableBase':
            return {'taxableBase': value};
        case 'ticketFk':
            return {'ticketFk': value};
        case 'comercialName':
            return {'comercialName': value};
        }
    }

    downloadCSV() {
        this.vnReport.show('InvoiceOuts/negativeBasesCsv', {
            from: this.params.from,
            to: this.params.to
        });
    }
}

Controller.$inject = ['$element', '$scope', 'vnReport'];

ngModule.vnComponent('vnNegativeBases', {
    template: require('./index.html'),
    controller: Controller
});