102 lines
2.6 KiB
JavaScript
102 lines
2.6 KiB
JavaScript
import ngModule from '../module';
|
|
import './style.scss';
|
|
|
|
class Controller {
|
|
constructor($scope, $state, $http, vnApp, $translate) {
|
|
this.$scope = $scope;
|
|
this.vnApp = vnApp;
|
|
this.$translate = $translate;
|
|
this.$http = $http;
|
|
this.$state = $state;
|
|
}
|
|
|
|
get ticket() {
|
|
return this._ticket;
|
|
}
|
|
|
|
set ticket(value) {
|
|
this._ticket = value;
|
|
|
|
if (!value) return;
|
|
|
|
this.$http.get(`/ticket/api/Tickets/${this.ticket.id}/summary`).then(res => {
|
|
if (res && res.data)
|
|
this.summary = res.data;
|
|
});
|
|
}
|
|
|
|
get formattedAddress() {
|
|
if (!this.summary) return;
|
|
|
|
let address = this.summary.address;
|
|
let province = address.province ? `(${address.province.name})` : '';
|
|
|
|
return `${address.street} - ${address.city} ${province}`;
|
|
}
|
|
|
|
showDescriptor(event, itemFk) {
|
|
this.quicklinks = {
|
|
btnThree: {
|
|
icon: 'icon-transaction',
|
|
state: `item.card.diary({
|
|
id: ${itemFk},
|
|
warehouseFk: ${this.ticket.warehouseFk},
|
|
ticketFk: ${this.ticket.id}
|
|
})`,
|
|
tooltip: 'Item diary'
|
|
}
|
|
};
|
|
this.$scope.descriptor.itemFk = itemFk;
|
|
this.$scope.descriptor.parent = event.target;
|
|
this.$scope.descriptor.show();
|
|
}
|
|
|
|
onDescriptorLoad() {
|
|
this.$scope.popover.relocate();
|
|
}
|
|
|
|
get isEditable() {
|
|
try {
|
|
return !this.ticket.state.state.alertLevel;
|
|
} catch (e) {}
|
|
|
|
return true;
|
|
}
|
|
|
|
setOkState() {
|
|
let filter = {where: {code: 'OK'}, fields: ['id']};
|
|
let json = encodeURIComponent(JSON.stringify(filter));
|
|
this.$http.get(`/ticket/api/States?filter=${json}`).then(res => {
|
|
this.changeTicketState(res.data[0].id);
|
|
});
|
|
}
|
|
|
|
changeTicketState(value) {
|
|
let params;
|
|
|
|
if (this.$state.params.id)
|
|
params = {ticketFk: this.$state.params.id, stateFk: value};
|
|
|
|
if (!this.$state.params.id)
|
|
params = {ticketFk: this.ticket.id, stateFk: value};
|
|
|
|
this.$http.post(`/ticket/api/TicketTrackings/changeState`, params).then(() => {
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
if (this.card) this.card.reload();
|
|
});
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];
|
|
|
|
ngModule.component('vnTicketSummary', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
ticket: '<'
|
|
},
|
|
require: {
|
|
card: '?^vnTicketCard'
|
|
}
|
|
});
|