2018-11-27 12:28:15 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
|
|
|
|
class Controller {
|
|
|
|
constructor($http, vnApp, $translate, $state, $stateParams) {
|
|
|
|
this.$stateParams = $stateParams;
|
|
|
|
this.$http = $http;
|
|
|
|
this.translate = $translate;
|
|
|
|
this.vnApp = vnApp;
|
|
|
|
this.ticket = {};
|
|
|
|
this.$state = $state;
|
|
|
|
this.clientFk = $stateParams.clientFk;
|
|
|
|
}
|
|
|
|
|
|
|
|
$onInit() {
|
|
|
|
if (this.$stateParams && this.$stateParams.clientFk)
|
|
|
|
this.clientFk = this.$stateParams.clientFk;
|
2019-01-25 10:58:50 +00:00
|
|
|
|
|
|
|
if (window.localStorage && window.localStorage.defaultWarehouseFk)
|
|
|
|
this.warehouseFk = parseInt(window.localStorage.defaultWarehouseFk);
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set ticket(value) {
|
|
|
|
if (value)
|
|
|
|
this._ticket = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
get ticket() {
|
|
|
|
return this._ticket;
|
|
|
|
}
|
|
|
|
|
|
|
|
set clientFk(value) {
|
|
|
|
this.ticket.clientFk = value;
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
let filter = {where: {clientFk: value, isDefaultAddress: true}};
|
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
let query = `/api/Addresses?filter=${filter}`;
|
|
|
|
this.$http.get(query).then(res => {
|
|
|
|
this.addressFk = res.data[0].id;
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
this.addressFk = null;
|
2019-01-25 10:58:50 +00:00
|
|
|
this.getAvailableAgencies();
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get clientFk() {
|
|
|
|
return this.ticket.clientFk;
|
|
|
|
}
|
|
|
|
|
|
|
|
set addressFk(value) {
|
|
|
|
this.ticket.addressFk = value;
|
2019-01-25 10:58:50 +00:00
|
|
|
this.getAvailableAgencies();
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get addressFk() {
|
|
|
|
return this.ticket.addressFk;
|
|
|
|
}
|
|
|
|
|
|
|
|
set landed(value) {
|
|
|
|
this.ticket.landed = value;
|
2019-01-25 10:58:50 +00:00
|
|
|
this.getAvailableAgencies();
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get landed() {
|
|
|
|
return this.ticket.landed;
|
|
|
|
}
|
|
|
|
|
|
|
|
set warehouseFk(value) {
|
|
|
|
this.ticket.warehouseFk = value;
|
|
|
|
this.getAvailableAgencies();
|
|
|
|
}
|
|
|
|
get warehouseFk() {
|
|
|
|
return this.ticket.warehouseFk;
|
|
|
|
}
|
|
|
|
|
|
|
|
getAvailableAgencies() {
|
2019-01-25 10:58:50 +00:00
|
|
|
if (this.ticket.warehouseFk && this.ticket.addressFk && this.ticket.landed && this.ticket.clientFk) {
|
|
|
|
this.ticket.agencyModeFk = null;
|
2018-11-27 12:28:15 +00:00
|
|
|
let filter = {warehouseFk: this.ticket.warehouseFk, addressFk: this.ticket.addressFk, landed: this.ticket.landed};
|
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
let query = `/api/Agencies/getAgenciesWithWarehouse?filter=${filter}`;
|
|
|
|
this.$http.get(query).then(res => {
|
|
|
|
this._availableAgencies = res.data[0];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
this.createTicket();
|
|
|
|
}
|
|
|
|
|
|
|
|
createTicket() {
|
|
|
|
let params = {
|
|
|
|
clientFk: this.ticket.clientFk,
|
|
|
|
landed: this.ticket.landed,
|
|
|
|
addressFk: this.ticket.addressFk,
|
|
|
|
agencyModeFk: this.ticket.agencyModeFk,
|
|
|
|
warehouseFk: this.ticket.warehouseFk,
|
|
|
|
};
|
|
|
|
this.$http.post(`ticket/api/Tickets/new`, params).then(res => {
|
|
|
|
this.vnApp.showSuccess(this.translate.instant('Data saved!'));
|
|
|
|
this.$state.go('ticket.card.summary', {id: res.data.id});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$http', 'vnApp', '$translate', '$state', '$stateParams'];
|
|
|
|
|
|
|
|
ngModule.component('vnTicketCreateCard', {
|
|
|
|
template: require('./card.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
ticket: '<?'
|
|
|
|
}
|
|
|
|
});
|