Closure migration
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
fe5eb3e13d
commit
5aec280adb
|
@ -920,16 +920,19 @@ INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`)
|
|||
|
||||
INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `created`, `itemFk`, `counter`, `workerFk`, `externalId`, `packagingFk`, `stateTypeFk`)
|
||||
VALUES
|
||||
(1, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 15, 1, 18, 'UR9000006041', 94, 1),
|
||||
(2, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 16, 2, 18, 'UR9000006041', 94, 1),
|
||||
(3, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 3, 18, 'UR9000006041', 94, 2),
|
||||
(4, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 4, 18, 'UR9000006041', 94, 2),
|
||||
(5, 1, 2, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 1, 18, NULL, 94, 3),
|
||||
(6, 7, 3, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL, 1, 18, NULL, 94, 3),
|
||||
(7, 2, 4, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL, 1, 18, NULL, 94, NULL),
|
||||
(8, 3, 5, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), NULL, 1, 18, NULL, 94, 1),
|
||||
(9, 3, 6, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 1, 18, NULL, 94, 2),
|
||||
(10, 7, 7, 71, NOW(), NULL, 1, 18, NULL, 94, 3);
|
||||
(1, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 15, 1, 18, 'UR9000006041', 94, 1),
|
||||
(2, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 16, 2, 18, 'UR9000006041', 94, 1),
|
||||
(3, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 3, 18, 'UR9000006041', 94, 2),
|
||||
(4, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 4, 18, 'UR9000006041', 94, 2),
|
||||
(5, 1, 2, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 1, 18, NULL, 94, 3),
|
||||
(6, 7, 3, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL, 1, 18, NULL, 94, 3),
|
||||
(7, 2, 4, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL, 1, 18, NULL, 94, NULL),
|
||||
(8, 3, 5, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), NULL, 1, 18, NULL, 94, 1),
|
||||
(9, 3, 6, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 1, 18, NULL, 94, 2),
|
||||
(10, 7, 7, 71, NOW(), NULL, 1, 18, NULL, 94, 3),
|
||||
(11, 7, 8, 71, NOW(), NULL, 1, 18, NULL, 94, 3),
|
||||
(12, 7, 9, 71, NOW(), NULL, 1, 18, NULL, 94, 3),
|
||||
(13, 1, 10, 71, NOW(), NULL, 1, 18, NULL, 94, 3);
|
||||
|
||||
|
||||
INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`)
|
||||
|
|
|
@ -19,7 +19,7 @@ module.exports = Self => {
|
|||
|
||||
Self.closeAll = async() => {
|
||||
const toDate = new Date();
|
||||
// toDate.setDate(toDate.getDate() - 1);
|
||||
toDate.setDate(toDate.getDate() - 1);
|
||||
|
||||
const todayMinDate = new Date();
|
||||
todayMinDate.setHours(0, 0, 0, 0);
|
||||
|
@ -28,8 +28,8 @@ module.exports = Self => {
|
|||
todayMaxDate.setHours(23, 59, 59, 59);
|
||||
|
||||
// Prevent closure for current day
|
||||
// if (toDate >= todayMinDate && toDate <= todayMaxDate)
|
||||
// throw new UserError('You cannot close tickets for today');
|
||||
if (toDate >= todayMinDate && toDate <= todayMaxDate)
|
||||
throw new UserError('You cannot close tickets for today');
|
||||
|
||||
const tickets = await Self.rawSql(`
|
||||
SELECT
|
||||
|
@ -55,6 +55,7 @@ module.exports = Self => {
|
|||
WHERE al.code = 'PACKED'
|
||||
AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY)
|
||||
AND util.dayEnd(?)
|
||||
AND t.refFk IS NULL
|
||||
GROUP BY t.id
|
||||
`, [toDate, toDate]);
|
||||
|
||||
|
@ -74,6 +75,8 @@ module.exports = Self => {
|
|||
AND t.routeFk
|
||||
AND z.name LIKE '%MADRID%'`, [toDate, toDate]);
|
||||
|
||||
return true;
|
||||
return {
|
||||
message: 'Success'
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
const closure = require('./closure');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('closeByAgency', {
|
||||
description: 'Makes the closure process by agency mode',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'agencyModeFk',
|
||||
type: ['number'],
|
||||
required: true,
|
||||
description: 'The agencies mode ids',
|
||||
},
|
||||
{
|
||||
arg: 'warehouseFk',
|
||||
type: 'number',
|
||||
description: 'The ticket warehouse id',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'to',
|
||||
type: 'date',
|
||||
description: 'Max closure date',
|
||||
required: true
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/close-by-agency`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.closeByAgency = async ctx => {
|
||||
const args = ctx.args;
|
||||
|
||||
const tickets = await Self.rawSql(`
|
||||
SELECT
|
||||
t.id,
|
||||
t.clientFk,
|
||||
t.companyFk,
|
||||
c.name clientName,
|
||||
c.email recipient,
|
||||
c.salesPersonFk,
|
||||
c.isToBeMailed,
|
||||
c.hasToInvoice,
|
||||
co.hasDailyInvoice,
|
||||
eu.email salesPersonEmail
|
||||
FROM expedition e
|
||||
JOIN ticket t ON t.id = e.ticketFk
|
||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
JOIN alertLevel al ON al.id = ts.alertLevel
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN province p ON p.id = c.provinceFk
|
||||
JOIN country co ON co.id = p.countryFk
|
||||
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
|
||||
WHERE al.code = 'PACKED'
|
||||
AND t.agencyModeFk IN(?)
|
||||
AND t.warehouseFk = ?
|
||||
AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY)
|
||||
AND util.dayEnd(?)
|
||||
AND t.refFk IS NULL
|
||||
GROUP BY e.ticketFk`, [
|
||||
args.agencyModeFk,
|
||||
args.warehouseFk,
|
||||
args.to,
|
||||
args.to
|
||||
]);
|
||||
|
||||
await closure(Self, tickets);
|
||||
|
||||
return {
|
||||
message: 'Success'
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,75 @@
|
|||
const closure = require('./closure');
|
||||
const {Email} = require('vn-print');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('closeByRoute', {
|
||||
description: 'Makes the closure process by route',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'routeFk',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The routes ids',
|
||||
},
|
||||
],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/close-by-route`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.closeByRoute = async ctx => {
|
||||
const args = ctx.args;
|
||||
|
||||
const tickets = await Self.rawSql(`
|
||||
SELECT
|
||||
t.id,
|
||||
t.clientFk,
|
||||
t.companyFk,
|
||||
c.name clientName,
|
||||
c.email recipient,
|
||||
c.salesPersonFk,
|
||||
c.isToBeMailed,
|
||||
c.hasToInvoice,
|
||||
co.hasDailyInvoice,
|
||||
eu.email salesPersonEmail
|
||||
FROM expedition e
|
||||
JOIN ticket t ON t.id = e.ticketFk
|
||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
JOIN alertLevel al ON al.id = ts.alertLevel
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN province p ON p.id = c.provinceFk
|
||||
JOIN country co ON co.id = p.countryFk
|
||||
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
|
||||
WHERE al.code = 'PACKED'
|
||||
AND t.routeFk = ?
|
||||
AND t.refFk IS NULL
|
||||
GROUP BY e.ticketFk`, [args.routeFk]);
|
||||
|
||||
await closure(Self, tickets);
|
||||
|
||||
// Send route report to the agency
|
||||
const [agencyMail] = await Self.rawSql(`
|
||||
SELECT am.reportMail
|
||||
FROM route r
|
||||
JOIN agencyMode am ON am.id = r.agencyModeFk
|
||||
WHERE r.id = ?`, [args.routeFk]);
|
||||
|
||||
if (agencyMail) {
|
||||
const email = new Email('driver-route', {
|
||||
id: args.routeFk,
|
||||
recipient: agencyMail
|
||||
});
|
||||
await email.send();
|
||||
}
|
||||
|
||||
return {
|
||||
message: 'Success'
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,60 @@
|
|||
const closure = require('./closure');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('closeByTicket', {
|
||||
description: 'Makes the closure process by ticket',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The ticket id',
|
||||
http: {source: 'path'}
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/close-by-ticket`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.closeByTicket = async ctx => {
|
||||
const args = ctx.args;
|
||||
|
||||
const tickets = await Self.rawSql(`
|
||||
SELECT
|
||||
t.id,
|
||||
t.clientFk,
|
||||
t.companyFk,
|
||||
c.name clientName,
|
||||
c.email recipient,
|
||||
c.salesPersonFk,
|
||||
c.isToBeMailed,
|
||||
c.hasToInvoice,
|
||||
co.hasDailyInvoice,
|
||||
eu.email salesPersonEmail
|
||||
FROM expedition e
|
||||
JOIN ticket t ON t.id = e.ticketFk
|
||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
JOIN alertLevel al ON al.id = ts.alertLevel
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN province p ON p.id = c.provinceFk
|
||||
JOIN country co ON co.id = p.countryFk
|
||||
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
|
||||
WHERE al.code = 'PACKED'
|
||||
AND t.id = ?
|
||||
AND t.refFk IS NULL
|
||||
GROUP BY e.ticketFk`, [args.id]);
|
||||
|
||||
await closure(Self, tickets);
|
||||
|
||||
return {
|
||||
message: 'Success'
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
module.exports = function(Self) {
|
||||
require('../methods/ticket/getVolume')(Self);
|
||||
require('../methods/ticket/getTotalVolume')(Self);
|
||||
require('../methods/ticket/summary')(Self);
|
||||
require('../methods/ticket/priceDifference')(Self);
|
||||
require('../methods/ticket/componentUpdate')(Self);
|
||||
require('../methods/ticket/new')(Self);
|
||||
require('../methods/ticket/isEditable')(Self);
|
||||
require('../methods/ticket/setDeleted')(Self);
|
||||
require('../methods/ticket/restore')(Self);
|
||||
require('../methods/ticket/getSales')(Self);
|
||||
require('../methods/ticket/getSalesPersonMana')(Self);
|
||||
require('../methods/ticket/filter')(Self);
|
||||
require('../methods/ticket/canBeInvoiced')(Self);
|
||||
require('../methods/ticket/makeInvoice')(Self);
|
||||
require('../methods/ticket/updateEditableTicket')(Self);
|
||||
require('../methods/ticket/isEmpty')(Self);
|
||||
require('../methods/ticket/updateDiscount')(Self);
|
||||
require('../methods/ticket/uploadFile')(Self);
|
||||
require('../methods/ticket/addSale')(Self);
|
||||
require('../methods/ticket/transferSales')(Self);
|
||||
require('../methods/ticket/recalculateComponents')(Self);
|
||||
require('../methods/ticket/sendSms')(Self);
|
||||
require('../methods/ticket/isLocked')(Self);
|
||||
require('../methods/ticket/freightCost')(Self);
|
||||
require('../methods/ticket/getComponentsSum')(Self);
|
||||
require('../methods/ticket/refund')(Self);
|
||||
require('../methods/ticket/deliveryNotePdf')(Self);
|
||||
require('../methods/ticket/deliveryNoteEmail')(Self);
|
||||
require('../methods/ticket/closeAll')(Self);
|
||||
require('../methods/ticket/closeByTicket')(Self);
|
||||
require('../methods/ticket/closeByAgency')(Self);
|
||||
require('../methods/ticket/closeByRoute')(Self);
|
||||
};
|
|
@ -2,35 +2,8 @@
|
|||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
module.exports = Self => {
|
||||
require('../methods/ticket/getVolume')(Self);
|
||||
require('../methods/ticket/getTotalVolume')(Self);
|
||||
require('../methods/ticket/summary')(Self);
|
||||
require('../methods/ticket/priceDifference')(Self);
|
||||
require('../methods/ticket/componentUpdate')(Self);
|
||||
require('../methods/ticket/new')(Self);
|
||||
require('../methods/ticket/isEditable')(Self);
|
||||
require('../methods/ticket/setDeleted')(Self);
|
||||
require('../methods/ticket/restore')(Self);
|
||||
require('../methods/ticket/getSales')(Self);
|
||||
require('../methods/ticket/getSalesPersonMana')(Self);
|
||||
require('../methods/ticket/filter')(Self);
|
||||
require('../methods/ticket/canBeInvoiced')(Self);
|
||||
require('../methods/ticket/makeInvoice')(Self);
|
||||
require('../methods/ticket/updateEditableTicket')(Self);
|
||||
require('../methods/ticket/isEmpty')(Self);
|
||||
require('../methods/ticket/updateDiscount')(Self);
|
||||
require('../methods/ticket/uploadFile')(Self);
|
||||
require('../methods/ticket/addSale')(Self);
|
||||
require('../methods/ticket/transferSales')(Self);
|
||||
require('../methods/ticket/recalculateComponents')(Self);
|
||||
require('../methods/ticket/sendSms')(Self);
|
||||
require('../methods/ticket/isLocked')(Self);
|
||||
require('../methods/ticket/freightCost')(Self);
|
||||
require('../methods/ticket/getComponentsSum')(Self);
|
||||
require('../methods/ticket/refund')(Self);
|
||||
require('../methods/ticket/deliveryNotePdf')(Self);
|
||||
require('../methods/ticket/deliveryNoteEmail')(Self);
|
||||
require('../methods/ticket/closeAll')(Self);
|
||||
// Methods
|
||||
require('./ticket-methods')(Self);
|
||||
|
||||
Self.observe('before save', async function(ctx) {
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
|
|
|
@ -150,7 +150,7 @@
|
|||
</div>
|
||||
<!-- Footer block -->
|
||||
<report-footer id="pageFooter"
|
||||
v-bind:left-text="$t('routeId', [routeId])"
|
||||
v-bind:left-text="$t('routeId', [id])"
|
||||
v-bind="$props">
|
||||
</report-footer>
|
||||
</td>
|
||||
|
|
Loading…
Reference in New Issue