import ngModule from '../module';
import ModuleCard from 'salix/components/module-card';

class Controller extends ModuleCard {
    reload() {
        let filter = {
            include: [
                {
                    relation: 'agencyMode',
                    scope: {
                        fields: ['name']
                    }
                }, {
                    relation: 'address',
                    scope: {
                        fields: ['nickname']
                    }
                }, {
                    relation: 'rows',
                    scope: {
                        fields: ['id']
                    }
                }, {
                    relation: 'client',
                    scope: {
                        fields: [
                            'salesPersonFk',
                            'name',
                            'isActive',
                            'isFreezed',
                            'isTaxDataChecked'
                        ],
                        include: {
                            relation: 'salesPersonUser',
                            scope: {
                                fields: ['id', 'name']
                            }
                        }
                    }
                }
            ]
        };

        return this.$q.all([
            this.$http.get(`Orders/${this.$params.id}`, {filter})
                .then(res => this.order = res.data),
            this.$http.get(`Orders/${this.$params.id}/getTotal`)
                .then(res => ({total: res.data}))
        ]).then(res => {
            this.order = Object.assign.apply(null, res);
        });
    }
}

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