This commit is contained in:
parent
596eb8d695
commit
d37d314304
|
@ -23,23 +23,28 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.changeState = async(ctx, data) => {
|
||||
Self.changeState = async(ctx, params) => {
|
||||
let userId = ctx.req.accessToken.userId;
|
||||
let $ = Self.app.models;
|
||||
|
||||
if (!data.stateFk)
|
||||
if (!params.stateFk && !params.code)
|
||||
throw new UserError('State cannot be blank');
|
||||
|
||||
if (params.code) {
|
||||
let state = await $.State.findOne({where: {code: params.code}, fields: ['id']});
|
||||
params.stateFk = state.id;
|
||||
}
|
||||
|
||||
let isProduction = await $.Account.hasRole(userId, 'production');
|
||||
let isSalesPerson = await $.Account.hasRole(userId, 'salesPerson');
|
||||
|
||||
let ticket = await $.TicketState.findById(
|
||||
data.ticketFk,
|
||||
params.ticketFk,
|
||||
{fields: ['stateFk']}
|
||||
);
|
||||
|
||||
let oldState = await $.State.findById(ticket.stateFk);
|
||||
let newState = await $.State.findById(data.stateFk);
|
||||
let newState = await $.State.findById(params.stateFk);
|
||||
|
||||
let isAllowed = isProduction || isSalesPerson
|
||||
&& oldState.isEditable()
|
||||
|
@ -50,9 +55,9 @@ module.exports = Self => {
|
|||
|
||||
if (newState.code != 'PICKER_DESIGNED') {
|
||||
let worker = await $.Worker.findOne({where: {userFk: userId}});
|
||||
data.workerFk = worker.id;
|
||||
params.workerFk = worker.id;
|
||||
}
|
||||
|
||||
return await $.TicketTracking.create(data);
|
||||
return await $.TicketTracking.create(params);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -17,12 +17,7 @@ class Controller {
|
|||
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;
|
||||
});
|
||||
if (value) this.getSummary();
|
||||
}
|
||||
|
||||
get formattedAddress() {
|
||||
|
@ -34,6 +29,13 @@ class Controller {
|
|||
return `${address.street} - ${address.city} ${province}`;
|
||||
}
|
||||
|
||||
getSummary() {
|
||||
this.$http.get(`/ticket/api/Tickets/${this.ticket.id}/summary`).then(res => {
|
||||
if (res && res.data)
|
||||
this.summary = res.data;
|
||||
});
|
||||
}
|
||||
|
||||
showDescriptor(event, itemFk) {
|
||||
this.quicklinks = {
|
||||
btnThree: {
|
||||
|
@ -64,25 +66,22 @@ class Controller {
|
|||
}
|
||||
|
||||
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;
|
||||
let params = {};
|
||||
|
||||
if (this.$state.params.id)
|
||||
params = {ticketFk: this.$state.params.id, stateFk: value};
|
||||
params = {ticketFk: this.$state.params.id};
|
||||
|
||||
if (!this.$state.params.id)
|
||||
params = {ticketFk: this.ticket.id, stateFk: value};
|
||||
params = {ticketFk: this.ticket.id};
|
||||
|
||||
params.code = 'OK';
|
||||
|
||||
this.$http.post(`/ticket/api/TicketTrackings/changeState`, params).then(() => {
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
if (this.card) this.card.reload();
|
||||
if (this.card)
|
||||
this.card.reload();
|
||||
else
|
||||
this.getSummary();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue