2018-11-27 12:28:15 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-18 07:35:59 +00:00
|
|
|
import Component from 'core/lib/component';
|
2018-11-27 12:28:15 +00:00
|
|
|
|
2020-03-18 07:35:59 +00:00
|
|
|
class Controller extends Component {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2018-11-27 12:28:15 +00:00
|
|
|
this.ticket = {};
|
2020-03-18 07:35:59 +00:00
|
|
|
this.clientFk = this.$params.clientFk;
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$onInit() {
|
2020-03-18 07:35:59 +00:00
|
|
|
if (this.$params && this.$params.clientFk)
|
|
|
|
this.clientId = parseInt(this.$params.clientFk);
|
2019-01-25 10:58:50 +00:00
|
|
|
|
2019-12-26 12:29:50 +00:00
|
|
|
this.warehouseId = this.vnConfig.warehouseFk;
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 06:12:34 +00:00
|
|
|
get ticket() {
|
|
|
|
return this._ticket;
|
|
|
|
}
|
|
|
|
|
2018-11-27 12:28:15 +00:00
|
|
|
set ticket(value) {
|
|
|
|
if (value)
|
|
|
|
this._ticket = value;
|
|
|
|
}
|
|
|
|
|
2019-12-26 06:12:34 +00:00
|
|
|
get clientId() {
|
|
|
|
return this.ticket.clientFk;
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 06:12:34 +00:00
|
|
|
set clientId(value) {
|
2018-11-27 12:28:15 +00:00
|
|
|
this.ticket.clientFk = value;
|
|
|
|
|
|
|
|
if (value) {
|
2019-02-28 07:55:34 +00:00
|
|
|
let filter = {
|
|
|
|
include: {
|
|
|
|
relation: 'defaultAddress',
|
|
|
|
scope: {
|
2019-12-26 06:12:34 +00:00
|
|
|
fields: ['id', 'agencyModeFk']
|
2019-02-28 07:55:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
where: {id: value}
|
|
|
|
};
|
2018-11-27 12:28:15 +00:00
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `Clients?filter=${filter}`;
|
2018-11-27 12:28:15 +00:00
|
|
|
this.$http.get(query).then(res => {
|
2019-12-26 06:12:34 +00:00
|
|
|
const [client] = res.data;
|
|
|
|
this.defaultAddress = client.defaultAddress;
|
|
|
|
this.addressId = this.defaultAddress.id;
|
2018-11-27 12:28:15 +00:00
|
|
|
});
|
|
|
|
} else
|
2019-12-26 06:12:34 +00:00
|
|
|
this.addressId = null;
|
2019-01-25 10:58:50 +00:00
|
|
|
this.getAvailableAgencies();
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 06:12:34 +00:00
|
|
|
get addressId() {
|
|
|
|
return this.ticket.addressFk;
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 06:12:34 +00:00
|
|
|
set addressId(value) {
|
2018-11-27 12:28:15 +00:00
|
|
|
this.ticket.addressFk = value;
|
2019-01-25 10:58:50 +00:00
|
|
|
this.getAvailableAgencies();
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 06:12:34 +00:00
|
|
|
get landed() {
|
|
|
|
return this.ticket.landed;
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-12-26 06:12:34 +00:00
|
|
|
get warehouseId() {
|
|
|
|
return this.ticket.warehouseFk;
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 06:12:34 +00:00
|
|
|
set warehouseId(value) {
|
2018-11-27 12:28:15 +00:00
|
|
|
this.ticket.warehouseFk = value;
|
|
|
|
this.getAvailableAgencies();
|
|
|
|
}
|
2019-12-26 06:12:34 +00:00
|
|
|
|
|
|
|
get agencyModeId() {
|
|
|
|
return this.ticket.agencyModeFk;
|
|
|
|
}
|
|
|
|
|
|
|
|
set agencyModeId(value) {
|
|
|
|
this.ticket.agencyModeFk = value;
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getAvailableAgencies() {
|
2019-11-11 15:32:03 +00:00
|
|
|
let ticket = this.ticket;
|
|
|
|
let params = {
|
|
|
|
warehouseFk: ticket.warehouseFk,
|
|
|
|
addressFk: ticket.addressFk,
|
|
|
|
landed: ticket.landed
|
|
|
|
};
|
|
|
|
|
|
|
|
if (params.warehouseFk && params.addressFk && params.landed) {
|
|
|
|
ticket.agencyModeFk = null;
|
|
|
|
|
2019-12-26 06:12:34 +00:00
|
|
|
this.$http.get(`Agencies/getAgenciesWithWarehouse`, {params}).then(res => {
|
|
|
|
this._availableAgencies = res.data;
|
|
|
|
|
|
|
|
this.agencyModeId = this.defaultAddress.agencyModeFk;
|
|
|
|
});
|
2018-11-27 12:28:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
this.createTicket();
|
|
|
|
}
|
|
|
|
|
|
|
|
createTicket() {
|
|
|
|
let params = {
|
2019-12-26 06:12:34 +00:00
|
|
|
clientId: this.ticket.clientFk,
|
2018-11-27 12:28:15 +00:00
|
|
|
landed: this.ticket.landed,
|
2019-12-26 06:12:34 +00:00
|
|
|
addressId: this.ticket.addressFk,
|
|
|
|
agencyModeId: this.ticket.agencyModeFk,
|
|
|
|
warehouseId: this.ticket.warehouseFk,
|
2018-11-27 12:28:15 +00:00
|
|
|
};
|
2019-10-24 22:53:53 +00:00
|
|
|
this.$http.post(`Tickets/new`, params).then(res => {
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2018-11-27 12:28:15 +00:00
|
|
|
this.$state.go('ticket.card.summary', {id: res.data.id});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnTicketCreateCard', {
|
2018-11-27 12:28:15 +00:00
|
|
|
template: require('./card.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
ticket: '<?'
|
|
|
|
}
|
|
|
|
});
|