ref #5947 refactorWorkerCreate #1802
|
@ -0,0 +1,3 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||||
|
VALUES
|
||||||
|
('WorkerDepartment', '*', '*', 'ALLOW', 'ROLE', 'employee');
|
|
@ -201,7 +201,7 @@ class Controller extends Section {
|
||||||
sendImportSms() {
|
sendImportSms() {
|
||||||
const params = {
|
const params = {
|
||||||
ticketId: this.id,
|
ticketId: this.id,
|
||||||
created: this.ticket.updated
|
shipped: this.ticket.shipped
|
||||||
};
|
};
|
||||||
this.showSMSDialog({
|
this.showSMSDialog({
|
||||||
message: this.$t('Minimum is needed', params)
|
message: this.$t('Minimum is needed', params)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
Make a payment: "Verdnatura communicates:\rYour order is pending of payment.\rPlease, enter the web page and make the payment with card.\rThank you."
|
Make a payment: "Verdnatura communicates:\rYour order is pending of payment.\rPlease, enter the web page and make the payment with card.\rThank you."
|
||||||
Minimum is needed: "Verdnatura communicates:\rA minimum import of 50€ (Without BAT) is needed for your order {{ticketId}} from date {{created | date: 'dd/MM/yyyy'}} to receive it with no extra fees."
|
Minimum is needed: "Verdnatura communicates:\rA minimum import of 50€ (Without BAT) is needed for your order {{ticketId}} from date {{shipped | date: 'dd/MM/yyyy'}} to receive it with no extra fees."
|
||||||
Send changes: "Verdnatura communicates:\rOrder {{ticketId}} date {{created | date: 'dd/MM/yyyy'}}\r{{changes}}"
|
Send changes: "Verdnatura communicates:\rOrder {{ticketId}} date {{created | date: 'dd/MM/yyyy'}}\r{{changes}}"
|
||||||
|
|
|
@ -4,7 +4,7 @@ Show pallet report: Ver hoja de pallet
|
||||||
Change shipped hour: Cambiar hora de envío
|
Change shipped hour: Cambiar hora de envío
|
||||||
Shipped hour: Hora de envío
|
Shipped hour: Hora de envío
|
||||||
Make a payment: "Verdnatura le comunica:\rSu pedido está pendiente de pago.\rPor favor, entre en la página web y efectúe el pago con tarjeta.\rMuchas gracias."
|
Make a payment: "Verdnatura le comunica:\rSu pedido está pendiente de pago.\rPor favor, entre en la página web y efectúe el pago con tarjeta.\rMuchas gracias."
|
||||||
Minimum is needed: "Verdnatura le recuerda:\rEs necesario un importe mínimo de 50€ (Sin IVA) en su pedido {{ticketId}} del día {{created | date: 'dd/MM/yyyy'}} para recibirlo sin portes adicionales."
|
Minimum is needed: "Verdnatura le recuerda:\rEs necesario un importe mínimo de 50€ (Sin IVA) en su pedido {{ticketId}} del día {{shipped | date: 'dd/MM/yyyy'}} para recibirlo sin portes adicionales."
|
||||||
Ticket invoiced: Ticket facturado
|
Ticket invoiced: Ticket facturado
|
||||||
Make invoice: Crear factura
|
Make invoice: Crear factura
|
||||||
Regenerate invoice PDF: Regenerar PDF factura
|
Regenerate invoice PDF: Regenerar PDF factura
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('updateWorkerTimeControlMail()', () => {
|
||||||
|
it('should update WorkerTimeControlMail if exist record', async() => {
|
||||||
|
const tx = await models.WorkerTimeControlMail.beginTransaction({});
|
||||||
|
const args = {
|
||||||
|
workerId: 9,
|
||||||
|
week: 50,
|
||||||
|
year: 2000,
|
||||||
|
state: 'CONFIRMED'
|
||||||
|
};
|
||||||
|
const ctx = {args};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const beforeMail = await models.WorkerTimeControlMail.findOne({
|
||||||
|
where: {
|
||||||
|
workerFk: args.workerId,
|
||||||
|
year: args.year,
|
||||||
|
week: args.week,
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, options);
|
||||||
|
const afterMail = await models.WorkerTimeControlMail.findOne({
|
||||||
|
where: {
|
||||||
|
workerFk: args.workerId,
|
||||||
|
year: args.year,
|
||||||
|
week: args.week,
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
expect(beforeMail.state).toEqual('SENDED');
|
||||||
|
expect(afterMail.state).toEqual(args.state);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should insert WorkerTimeControlMail if exist record', async() => {
|
||||||
|
const tx = await models.WorkerTimeControlMail.beginTransaction({});
|
||||||
|
const args = {
|
||||||
|
workerId: 1,
|
||||||
|
week: 51,
|
||||||
|
year: 2000,
|
||||||
|
state: 'SENDED'
|
||||||
|
};
|
||||||
|
const ctx = {args};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const beforeMail = await models.WorkerTimeControlMail.find({
|
||||||
|
where: {
|
||||||
|
workerFk: args.workerId,
|
||||||
|
year: args.year,
|
||||||
|
week: args.week,
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, options);
|
||||||
|
const afterMail = await models.WorkerTimeControlMail.find({
|
||||||
|
where: {
|
||||||
|
workerFk: args.workerId,
|
||||||
|
year: args.year,
|
||||||
|
week: args.week,
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
expect(beforeMail).toEqual([]);
|
||||||
|
expect(afterMail.length).toEqual(1);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw error if not exist any record in this week', async() => {
|
||||||
|
const tx = await models.WorkerTimeControlMail.beginTransaction({});
|
||||||
|
const ctx = {args: {
|
||||||
|
workerId: 1,
|
||||||
|
week: 1,
|
||||||
|
year: 0,
|
||||||
|
state: 'SENDED'
|
||||||
|
}};
|
||||||
|
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toEqual(`There aren't records for this week`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -40,30 +40,39 @@ module.exports = Self => {
|
||||||
Self.updateWorkerTimeControlMail = async(ctx, options) => {
|
Self.updateWorkerTimeControlMail = async(ctx, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({
|
const [sent] = await models.WorkerTimeControlMail.find({
|
||||||
where: {
|
where: {
|
||||||
workerFk: args.workerId,
|
|
||||||
year: args.year,
|
year: args.year,
|
||||||
week: args.week
|
week: args.week,
|
||||||
}
|
},
|
||||||
|
limit: 1
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (!workerTimeControlMail) throw new UserError(`There aren't records for this week`);
|
if (!sent) throw new UserError(`There aren't records for this week`);
|
||||||
|
|
||||||
await workerTimeControlMail.updateAttributes({
|
const workerTimeControlMail = await models.WorkerTimeControlMail.upsertWithWhere(
|
||||||
|
{
|
||||||
|
year: args.year,
|
||||||
|
week: args.week,
|
||||||
|
workerFk: args.workerId
|
||||||
|
},
|
||||||
|
{
|
||||||
state: args.state,
|
state: args.state,
|
||||||
reason: args.reason || null
|
reason: args.workerId,
|
||||||
}, myOptions);
|
year: args.year,
|
||||||
|
week: args.week,
|
||||||
|
workerFk: args.workerId
|
||||||
|
},
|
||||||
|
myOptions);
|
||||||
|
|
||||||
if (args.state == 'SENDED') {
|
if (args.state == 'SENDED') {
|
||||||
await workerTimeControlMail.updateAttributes({
|
await workerTimeControlMail.updateAttributes({
|
||||||
sendedCounter: workerTimeControlMail.sendedCounter + 1
|
sendedCounter: workerTimeControlMail.sendedCounter ? workerTimeControlMail.sendedCounter + 1 : 1
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,9 +61,8 @@ module.exports = Self => {
|
||||||
const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`;
|
const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`;
|
||||||
ctx.args.url = url;
|
ctx.args.url = url;
|
||||||
|
|
||||||
await Self.sendTemplate(ctx, 'weekly-hour-record');
|
await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions);
|
||||||
|
return Self.sendTemplate(ctx, 'weekly-hour-record');
|
||||||
return models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getMondayDateFromYearWeek(yearNumber, weekNumber) {
|
function getMondayDateFromYearWeek(yearNumber, weekNumber) {
|
||||||
|
|
|
@ -79,30 +79,32 @@
|
||||||
</vn-table>
|
</vn-table>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
|
|
||||||
<vn-button-bar ng-show="$ctrl.state" class="vn-w-lg">
|
<vn-button-bar class="vn-w-lg">
|
||||||
|
<div ng-show="$ctrl.state">
|
||||||
<vn-button
|
<vn-button
|
||||||
label="Satisfied"
|
label="Satisfied"
|
||||||
disabled="$ctrl.state == 'CONFIRMED'"
|
disabled="$ctrl.state == 'CONFIRMED'"
|
||||||
ng-if="$ctrl.isHimSelf"
|
ng-show="$ctrl.isHimSelf"
|
||||||
ng-click="$ctrl.isSatisfied()">
|
ng-click="$ctrl.isSatisfied()">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
<vn-button
|
<vn-button
|
||||||
label="Not satisfied"
|
label="Not satisfied"
|
||||||
disabled="$ctrl.state == 'REVISE'"
|
disabled="$ctrl.state == 'REVISE'"
|
||||||
ng-if="$ctrl.isHimSelf"
|
ng-show="$ctrl.isHimSelf"
|
||||||
ng-click="reason.show()">
|
ng-click="reason.show()">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
<vn-button
|
<vn-button
|
||||||
label="Reason"
|
label="Reason"
|
||||||
ng-if="$ctrl.reason && ($ctrl.isHimSelf || $ctrl.isHr)"
|
ng-show="$ctrl.reason && ($ctrl.isHimSelf || $ctrl.isHr)"
|
||||||
ng-click="reason.show()">
|
ng-click="reason.show()">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
|
</div>
|
||||||
<vn-button
|
<vn-button
|
||||||
label="Resend"
|
label="{{$ctrl.state ? 'Resend' : 'Send'}}"
|
||||||
ng-click="sendEmailConfirmation.show()"
|
ng-click="sendEmailConfirmation.show()"
|
||||||
class="right"
|
class="right"
|
||||||
vn-tooltip="Resend email of this week to the user"
|
vn-tooltip="{{$ctrl.state ? 'Resend' : 'Send'}} email of this week to the user"
|
||||||
ng-show="::$ctrl.isHr">
|
ng-if="$ctrl.isHr && $ctrl.state != 'CONFIRMED' && $ctrl.canResend">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
</vn-button-bar>
|
</vn-button-bar>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -53,6 +53,8 @@ class Controller extends Section {
|
||||||
set worker(value) {
|
set worker(value) {
|
||||||
this._worker = value;
|
this._worker = value;
|
||||||
this.fetchHours();
|
this.fetchHours();
|
||||||
|
if (this.date)
|
||||||
|
this.getWeekData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,6 +112,7 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.weekTotalHours) this.fetchHours();
|
if (!this.weekTotalHours) this.fetchHours();
|
||||||
|
if (this.worker)
|
||||||
this.getWeekData();
|
this.getWeekData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,17 +130,34 @@ class Controller extends Section {
|
||||||
workerFk: this.$params.id,
|
workerFk: this.$params.id,
|
||||||
year: this._date.getFullYear(),
|
year: this._date.getFullYear(),
|
||||||
week: this.getWeekNumber(this._date)
|
week: this.getWeekNumber(this._date)
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
this.$http.get('WorkerTimeControlMails', {filter})
|
this.$http.get('WorkerTimeControlMails', {filter})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const mail = res.data;
|
if (!res.data.length) {
|
||||||
if (!mail.length) {
|
|
||||||
this.state = null;
|
this.state = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.state = mail[0].state;
|
const [mail] = res.data;
|
||||||
this.reason = mail[0].reason;
|
this.state = mail.state;
|
||||||
|
this.reason = mail.reason;
|
||||||
|
});
|
||||||
|
this.canBeResend();
|
||||||
|
}
|
||||||
|
|
||||||
|
canBeResend() {
|
||||||
|
this.canResend = false;
|
||||||
|
const filter = {
|
||||||
|
where: {
|
||||||
|
year: this._date.getFullYear(),
|
||||||
|
week: this.getWeekNumber(this._date)
|
||||||
|
},
|
||||||
|
limit: 1
|
||||||
|
};
|
||||||
|
this.$http.get('WorkerTimeControlMails', {filter})
|
||||||
|
.then(res => {
|
||||||
|
if (res.data.length)
|
||||||
|
this.canResend = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,30 +376,25 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
isSatisfied() {
|
isSatisfied() {
|
||||||
const params = {
|
this.updateWorkerTimeControlMail('CONFIRMED');
|
||||||
workerId: this.worker.id,
|
|
||||||
year: this.date.getFullYear(),
|
|
||||||
week: this.weekNumber,
|
|
||||||
state: 'CONFIRMED'
|
|
||||||
};
|
|
||||||
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
|
||||||
this.$http.post(query, params).then(() => {
|
|
||||||
this.getMailStates(this.date);
|
|
||||||
this.getWeekData();
|
|
||||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isUnsatisfied() {
|
isUnsatisfied() {
|
||||||
if (!this.reason) throw new UserError(`You must indicate a reason`);
|
if (!this.reason) throw new UserError(`You must indicate a reason`);
|
||||||
|
this.updateWorkerTimeControlMail('REVISE', this.reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateWorkerTimeControlMail(state, reason) {
|
||||||
const params = {
|
const params = {
|
||||||
workerId: this.worker.id,
|
workerId: this.worker.id,
|
||||||
year: this.date.getFullYear(),
|
year: this.date.getFullYear(),
|
||||||
week: this.weekNumber,
|
week: this.weekNumber,
|
||||||
state: 'REVISE',
|
state
|
||||||
reason: this.reason
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (reason)
|
||||||
|
params.reason = reason;
|
||||||
|
|
||||||
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
||||||
this.$http.post(query, params).then(() => {
|
this.$http.post(query, params).then(() => {
|
||||||
this.getMailStates(this.date);
|
this.getMailStates(this.date);
|
||||||
|
|
Loading…
Reference in New Issue