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