const vnReport = require('../../../core/mixins/vn-report.js');
const app = require('vn-loopback/server/server');

module.exports = {
    name: 'extra-community',
    mixins: [vnReport],
    async serverPrefetch() {
        const args = {
            search: this.search,
            landedTo: this.landedEnd,
            shippedFrom: this.shippedStart,
            continent: this.continent,
            id: this.id,
            agencyModeFk: this.agencyModeFk,
            warehouseInFk: this.warehouseInFk,
            warehouseOutFk: this.warehouseOutFk,
            totalEntries: this.totalEntries,
            ref: this.ref,
            cargoSupplierFk: this.cargoSupplierFk
        };
        const ctx = {args: args};
        this.travels = await app.models.Travel.extraCommunityFilter(ctx, this.filter);
    },
    computed: {
        landedEnd: function() {
            if (!this.landedTo) return;
            return this.formatDate(this.landedTo, '%Y-%m-%d');
        },
        shippedStart: function() {
            if (!this.shippedFrom) return;
            return this.formatDate(this.shippedFrom, '%Y-%m-%d');
        }
    },
    methods: {
    },
    props: [
        'filter',
        'search',
        'landedTo',
        'shippedFrom',
        'continent',
        'reference',
        'id',
        'agencyModeFk',
        'warehouseOutFk',
        'warehouseInFk',
        'totalEntries',
        'cargoSupplierFk'
    ]
};