75 lines
2.2 KiB
JavaScript
75 lines
2.2 KiB
JavaScript
import ngModule from '../module';
|
|
|
|
export default class Controller {
|
|
constructor($scope, $state) {
|
|
this.$ = $scope;
|
|
this.ticketSelected = null;
|
|
this.$state = $state;
|
|
}
|
|
|
|
getScopeDates(days) {
|
|
const today = new Date();
|
|
today.setHours(0, 0, 0, 0);
|
|
const daysOnward = new Date(today);
|
|
daysOnward.setDate(today.getDate() + days);
|
|
daysOnward.setHours(23, 59, 59, 999);
|
|
return {shippedFrom: today, shippedTo: daysOnward};
|
|
}
|
|
|
|
onSearch(params) {
|
|
if (params) {
|
|
let newParams = params;
|
|
if (params.scopeDays) {
|
|
const scopeDates = this.getScopeDates(params.scopeDays);
|
|
Object.assign(newParams, scopeDates);
|
|
} else if (Object.entries(params).length == 0)
|
|
newParams = this.getScopeDates(1);
|
|
|
|
this.$.model.applyFilter(null, newParams);
|
|
} else
|
|
this.$.model.clear();
|
|
}
|
|
|
|
stopEvent(event) {
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
}
|
|
|
|
cloneTravel(event, travel) {
|
|
this.stopEvent(event);
|
|
this.travelSelected = travel;
|
|
this.$.clone.show();
|
|
}
|
|
|
|
onCloneAccept(response) {
|
|
if (!(response == 'accept' && this.travelSelected))
|
|
return;
|
|
if (this.travelSelected) {
|
|
const travel = {
|
|
ref: this.travelSelected.ref,
|
|
agencyModeFk: this.travelSelected.agencyFk,
|
|
shipped: this.travelSelected.shipped,
|
|
landed: this.travelSelected.landed,
|
|
warehouseInFk: this.travelSelected.warehouseInFk,
|
|
warehouseOutFk: this.travelSelected.warehouseOutFk
|
|
};
|
|
const queryParams = JSON.stringify(travel);
|
|
this.$state.go('travel.create', {q: queryParams});
|
|
}
|
|
|
|
this.travelSelected = null;
|
|
}
|
|
preview(event, travel) {
|
|
this.stopEvent(event);
|
|
this.travelSelected = travel;
|
|
this.$.summary.show();
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$scope', '$state'];
|
|
|
|
ngModule.component('vnTravelIndex', {
|
|
template: require('./index.html'),
|
|
controller: Controller
|
|
});
|