import ngModule from '../module'; import Section from 'salix/components/section'; import './style.scss'; export default class Controller extends Section { constructor($element, $) { super($element, $); this.$checkAll = false; this.smartTableOptions = { activeButtons: { search: true, }, columns: [ { field: 'state', searchable: false }, { field: 'futureState', searchable: false }, { field: 'totalWithVat', searchable: false }, { field: 'futureTotalWithVat', searchable: false }, { field: 'shipped', searchable: false }, { field: 'futureShipped', searchable: false }, { field: 'ipt', autocomplete: { url: 'ItemPackingTypes', where: `{isActive: true}`, showField: 'description', valueField: 'code' } }, { field: 'futureIpt', autocomplete: { url: 'ItemPackingTypes', where: `{isActive: true}`, showField: 'description', valueField: 'code' } }, ] }; } $postLink() { this.setDefaultFilter(); } setDefaultFilter() { let today = Date.vnNew(); const tomorrow = new Date(today); tomorrow.setDate(tomorrow.getDate() + 1); this.$http.get(`UserConfigs/getUserConfig`) .then(res => { this.filterParams = { dateFuture: tomorrow, dateToAdvance: today, warehouseFk: res.data.warehouseFk }; this.$.model.addFilter({}, this.filterParams); }); } compareDate(date) { let today = Date.vnNew(); today.setHours(0, 0, 0, 0); let timeTicket = new Date(date); timeTicket.setHours(0, 0, 0, 0); let comparation = today - timeTicket; if (comparation == 0) return 'warning'; if (comparation < 0) return 'success'; } get checked() { const tickets = this.$.model.data || []; const checkedLines = []; for (let ticket of tickets) { if (ticket.checked) checkedLines.push(ticket); } return checkedLines; } dateRange(value) { const minHour = new Date(value); minHour.setHours(0, 0, 0, 0); const maxHour = new Date(value); maxHour.setHours(23, 59, 59, 59); return [minHour, maxHour]; } totalPriceColor(totalWithVat) { return this.isLessThan50(totalWithVat) ? 'warning' : ''; } totalPriceTitle(totalWithVat) { return this.isLessThan50(totalWithVat) ? 'Less than 50€' : ''; } isLessThan50(totalWithVat) { return (parseInt(totalWithVat) > 0 && parseInt(totalWithVat) < 50); } get confirmationMessage() { if (!this.$.model) return 0; return this.$t(`Advance confirmation`, { checked: this.checked.length }); } agencies(futureAgency, agency) { return this.$t(`Origin agency`, {agency: futureAgency}) + '\n' + this.$t(`Destination agency`, {agency: agency}); } moveTicketsAdvance() { let ticketsToMove = []; this.checked.forEach(ticket => { ticketsToMove.push({ originId: ticket.futureId, destinationId: ticket.id, originShipped: ticket.futureShipped, destinationShipped: ticket.shipped, workerFk: ticket.workerFk }); }); const params = {tickets: ticketsToMove}; return this.$http.post('Tickets/merge', params) .then(() => { this.$.model.refresh(); this.vnApp.showSuccess(this.$t('Success')); }); } exprBuilder(param, value) { switch (param) { case 'id': return {'id': value}; case 'futureId': return {'futureId': value}; case 'liters': return {'liters': value}; case 'lines': return {'lines': value}; case 'futureLiters': return {'futureLiters': value}; case 'futureLines': return {'futureLines': value}; case 'ipt': return {or: [ {'ipt': {like: `%${value}%`}}, {'ipt': null} ] }; case 'futureIpt': return {or: [ {'futureIpt': {like: `%${value}%`}}, {'futureIpt': null} ] }; case 'totalWithVat': return {'totalWithVat': value}; case 'futureTotalWithVat': return {'futureTotalWithVat': value}; case 'notMovableLines': return {'notMovableLines': value}; } } } Controller.$inject = ['$element', '$scope']; ngModule.vnComponent('vnTicketAdvance', { template: require('./index.html'), controller: Controller });