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

class Controller extends Section {
    add() {
        this.$.model.insert({
            dueDated: Date.vnNew(),
            bankFk: this.vnConfig.local.bankFk
        });
    }

    onSubmit() {
        this.$.watcher.check();
        this.$.model.save().then(() => {
            this.$.watcher.notifySaved();
            this.$.watcher.updateOriginalData();
            this.card.reload();
        });
    }

    bankSearchFunc($search) {
        return /^\d+$/.test($search)
            ? {id: $search}
            : {bank: {like: '%' + $search + '%'}};
    }
}

ngModule.vnComponent('vnInvoiceInDueDay', {
    template: require('./index.html'),
    controller: Controller,
    require: {
        card: '^vnInvoiceInCard'
    },
    bindings: {
        invoiceIn: '<'
    }
});