refs #6335 feat(ticketAdvance): use componentUpdate
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
6b94ea7d11
commit
ae160890a8
|
@ -68,7 +68,15 @@ BEGIN
|
|||
origin.futureZoneFk,
|
||||
origin.futureZoneName,
|
||||
origin.classColor futureClassColor,
|
||||
dest.classColor
|
||||
dest.classColor,
|
||||
IFNULL(dest.clientFk, origin.clientFk) clientFk,
|
||||
IFNULL(dest.nickname, origin.nickname) nickname,
|
||||
IFNULL(dest.addressFk, origin.addressFk) addressFk,
|
||||
IFNULL(dest.zoneFk, origin.futureZoneFk) zoneFk,
|
||||
IFNULL(dest.warehouseFk, origin.warehouseFk) warehouseFk,
|
||||
IFNULL(dest.companyFk, origin.companyFk) companyFk,
|
||||
IFNULL(dest.agencyModeFk, origin.agencyModeFk) agencyModeFk,
|
||||
dest.landed
|
||||
FROM (
|
||||
SELECT
|
||||
s.ticketFk,
|
||||
|
@ -76,7 +84,6 @@ BEGIN
|
|||
t.shipped,
|
||||
t.totalWithVat,
|
||||
st.name futureState,
|
||||
t.addressFk,
|
||||
am.name futureAgency,
|
||||
count(s.id) futureLines,
|
||||
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt,
|
||||
|
@ -84,7 +91,13 @@ BEGIN
|
|||
SUM((s.quantity <= IFNULL(st.amount,0))) hasStock,
|
||||
z.id futureZoneFk,
|
||||
z.name futureZoneName,
|
||||
st.classColor
|
||||
st.classColor,
|
||||
t.clientFk,
|
||||
t.nickname,
|
||||
t.addressFk,
|
||||
t.warehouseFk,
|
||||
t.companyFk,
|
||||
t.agencyModeFk
|
||||
FROM ticket t
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
|
@ -103,7 +116,6 @@ BEGIN
|
|||
LEFT JOIN (
|
||||
SELECT
|
||||
t.id ticketFk,
|
||||
t.addressFk,
|
||||
st.name state,
|
||||
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt,
|
||||
t.shipped,
|
||||
|
@ -111,7 +123,15 @@ BEGIN
|
|||
am.name agency,
|
||||
CAST(SUM(litros) AS DECIMAL(10,0)) liters,
|
||||
CAST(COUNT(*) AS DECIMAL(10,0)) `lines`,
|
||||
st.classColor
|
||||
st.classColor,
|
||||
t.clientFk,
|
||||
t.nickname,
|
||||
t.addressFk,
|
||||
t.zoneFk,
|
||||
t.warehouseFk,
|
||||
t.companyFk,
|
||||
t.landed,
|
||||
t.agencyModeFk
|
||||
FROM ticket t
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN saleVolume sv ON sv.saleFk = s.id
|
|
@ -75,8 +75,7 @@ module.exports = Self => {
|
|||
{
|
||||
arg: 'option',
|
||||
type: 'number',
|
||||
description: 'Action id',
|
||||
required: true
|
||||
description: 'Action id'
|
||||
},
|
||||
{
|
||||
arg: 'isWithoutNegatives',
|
||||
|
@ -88,7 +87,18 @@ module.exports = Self => {
|
|||
arg: 'withWarningAccept',
|
||||
type: 'boolean',
|
||||
description: 'Has pressed in confirm message',
|
||||
}],
|
||||
},
|
||||
{
|
||||
arg: 'newTicket',
|
||||
type: 'number',
|
||||
description: 'Ticket id you want to move the lines to, if applicable',
|
||||
},
|
||||
{
|
||||
arg: 'keepPrice',
|
||||
type: 'boolean',
|
||||
description: 'If prices should be maintained',
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
|
@ -101,6 +111,7 @@ module.exports = Self => {
|
|||
|
||||
Self.componentUpdate = async(ctx, options) => {
|
||||
const args = ctx.args;
|
||||
const originalTicketId = args.id;
|
||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
let tx;
|
||||
|
||||
|
@ -141,7 +152,13 @@ module.exports = Self => {
|
|||
|
||||
const salesNewTicketLength = salesNewTicket.length;
|
||||
if (salesNewTicketLength && sales.length != salesNewTicketLength) {
|
||||
const newTicket = await models.Ticket.transferSales(ctx, args.id, null, salesNewTicket, myOptions);
|
||||
const newTicket = await models.Ticket.transferSales(
|
||||
ctx,
|
||||
args.id,
|
||||
args.newTicket,
|
||||
salesNewTicket,
|
||||
myOptions
|
||||
);
|
||||
args.id = newTicket.id;
|
||||
}
|
||||
}
|
||||
|
@ -186,24 +203,32 @@ module.exports = Self => {
|
|||
delete updatedTicket.ctx;
|
||||
delete updatedTicket.option;
|
||||
|
||||
// Force to unroute ticket
|
||||
const hasToBeUnrouted = true;
|
||||
const query = 'CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
const res = await Self.rawSql(query, [
|
||||
args.id,
|
||||
args.clientFk,
|
||||
args.nickname,
|
||||
args.agencyModeFk,
|
||||
args.addressFk,
|
||||
args.zoneFk,
|
||||
args.warehouseFk,
|
||||
args.companyFk,
|
||||
args.shipped,
|
||||
args.landed,
|
||||
args.isDeleted,
|
||||
hasToBeUnrouted,
|
||||
args.option
|
||||
], myOptions);
|
||||
const ticketChages = {
|
||||
clientFk: args.clientFk,
|
||||
nickname: args.nickname,
|
||||
agencyModeFk: args.agencyModeFk,
|
||||
addressFk: args.addressFk,
|
||||
zoneFk: args.zoneFk,
|
||||
warehouseFk: args.warehouseFk,
|
||||
companyFk: args.companyFk,
|
||||
shipped: args.shipped,
|
||||
landed: args.landed,
|
||||
isDeleted: args.isDeleted
|
||||
};
|
||||
|
||||
let response;
|
||||
if (args.keepPrice) {
|
||||
ticketChages.routeFk = null;
|
||||
response = await originalTicket.updateAttributes(ticketChages, myOptions);
|
||||
} else {
|
||||
const hasToBeUnrouted = true;
|
||||
const query = 'CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
response = await Self.rawSql(
|
||||
query,
|
||||
[args.id].concat(Object.values(ticketChages), [hasToBeUnrouted, args.option]),
|
||||
myOptions
|
||||
);
|
||||
}
|
||||
|
||||
if (originalTicket.addressFk != updatedTicket.addressFk && args.id) {
|
||||
await models.TicketObservation.destroyAll({
|
||||
|
@ -256,10 +281,11 @@ module.exports = Self => {
|
|||
}
|
||||
}
|
||||
|
||||
res.id = args.id;
|
||||
if (tx) await tx.commit();
|
||||
response.id = args.id;
|
||||
console.log(originalTicketId, args.newTicket ? ` TRANSFER TO → ` : ` CREATE NEW TICKET → `, args.id);
|
||||
if (tx) await tx.rollback();
|
||||
|
||||
return res;
|
||||
return response;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('ticket componentUpdate()', () => {
|
||||
fdescribe('ticket componentUpdate()', () => {
|
||||
const userID = 1101;
|
||||
const ticketID = 11;
|
||||
const today = Date.vnNew();
|
||||
|
|
|
@ -21,10 +21,17 @@
|
|||
expr-builder="$ctrl.exprBuilder(param, value)"
|
||||
>
|
||||
<slot-actions>
|
||||
<vn-button disabled="$ctrl.checked.length === 0"
|
||||
<vn-button
|
||||
disabled="$ctrl.checked.length === 0"
|
||||
icon="keyboard_double_arrow_left"
|
||||
ng-click="moveTicketsAdvance.show($event)"
|
||||
vn-tooltip="Advance tickets">
|
||||
vn-tooltip="Advance tickets with negatives">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
disabled="$ctrl.checked.length === 0"
|
||||
icon="swap_horiz"
|
||||
ng-click="splitTickets.show($event)"
|
||||
vn-tooltip="Advance tickets without negatives">
|
||||
</vn-button>
|
||||
</slot-actions>
|
||||
<slot-table>
|
||||
|
@ -32,8 +39,14 @@
|
|||
<thead>
|
||||
<tr second-header>
|
||||
<td></td>
|
||||
<th colspan="7" translate>Destination</th>
|
||||
<th colspan="9" translate>Origin</th>
|
||||
<th colspan="7">
|
||||
<span translate>Destination</span>
|
||||
{{model.userParams.dateToAdvance| date: 'dd/MM/yyyy'}}
|
||||
</th>
|
||||
<th colspan="11">
|
||||
<span translate>Origin</span>
|
||||
{{model.userParams.dateFuture | date: 'dd/MM/yyyy'}}
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th shrink>
|
||||
|
@ -48,9 +61,6 @@
|
|||
<th field="id">
|
||||
<span translate>ID</span>
|
||||
</th>
|
||||
<th field="shipped">
|
||||
<span translate>Date</span>
|
||||
</th>
|
||||
<th field="ipt" title="{{'Item Packing Type' | translate}}">
|
||||
<span>IPT</span>
|
||||
</th>
|
||||
|
@ -69,9 +79,6 @@
|
|||
<th separator field="futureId">
|
||||
<span translate>ID</span>
|
||||
</th>
|
||||
<th field="futureShipped">
|
||||
<span translate>Date</span>
|
||||
</th>
|
||||
<th field="futureIpt" title="{{'Item Packing Type' | translate}}">
|
||||
<span>IPT</span>
|
||||
</th>
|
||||
|
@ -117,11 +124,6 @@
|
|||
{{::ticket.id | dashIfEmpty}}
|
||||
</span>
|
||||
</td>
|
||||
<td shrink-date>
|
||||
<span class="chip {{$ctrl.compareDate(ticket.shipped)}}">
|
||||
{{::ticket.shipped | date: 'dd/MM/yyyy'}}
|
||||
</span>
|
||||
</td>
|
||||
<td>{{::ticket.ipt | dashIfEmpty}}</td>
|
||||
<td>
|
||||
<span
|
||||
|
@ -145,11 +147,6 @@
|
|||
{{::ticket.futureId | dashIfEmpty}}
|
||||
</span>
|
||||
</td>
|
||||
<td shrink-date>
|
||||
<span class="chip {{$ctrl.compareDate(ticket.futureShipped)}}">
|
||||
{{::ticket.futureShipped | date: 'dd/MM/yyyy'}}
|
||||
</span>
|
||||
</td>
|
||||
<td>{{::ticket.futureIpt | dashIfEmpty}}</td>
|
||||
<td>
|
||||
<span
|
||||
|
@ -187,6 +184,36 @@
|
|||
question="{{$ctrl.confirmationMessage}}"
|
||||
message="Advance tickets">
|
||||
</vn-confirm>
|
||||
<vn-confirm
|
||||
vn-id="splitTickets"
|
||||
on-accept="$ctrl.splitTickets()"
|
||||
question="{{$ctrl.confirmationMessage}}"
|
||||
message="Advance tickets (without negatives)">
|
||||
</vn-confirm>
|
||||
<!-- Split progress -->
|
||||
<vn-dialog
|
||||
vn-id="splitProgress"
|
||||
message="Split progress">
|
||||
<tpl-body>
|
||||
<vn-vertical>
|
||||
<vn-spinner
|
||||
enable="splitProgress.enable">
|
||||
</vn-spinner>
|
||||
<vn-label-value
|
||||
label="Progres"
|
||||
value="[{{$ctrl.progress.length}}/{{$ctrl.checked.length}}]">
|
||||
</vn-label-value>
|
||||
<vn-label-value
|
||||
ng-if="$ctrl.splitErrors.length"
|
||||
label="Errors list"
|
||||
value="{{$ctrl.splitErrors}}">
|
||||
</vn-label-value>
|
||||
</vn-vertical>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}" ng-click="splitProgress.cancel = true"/>
|
||||
</tpl-buttons>
|
||||
</vn-dialog>
|
||||
<vn-ticket-descriptor-popover
|
||||
vn-id="ticketDescriptor">
|
||||
</vn-ticket-descriptor-popover>
|
||||
|
|
|
@ -75,20 +75,6 @@ export default class Controller extends Section {
|
|||
});
|
||||
}
|
||||
|
||||
compareDate(date) {
|
||||
let today = Date.vnNew();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
let timeTicket = new Date(date);
|
||||
timeTicket.setHours(0, 0, 0, 0);
|
||||
|
||||
let comparation = today - timeTicket;
|
||||
|
||||
if (comparation == 0)
|
||||
return 'warning';
|
||||
if (comparation < 0)
|
||||
return 'success';
|
||||
}
|
||||
|
||||
get checked() {
|
||||
const tickets = this.$.model.data || [];
|
||||
const checkedLines = [];
|
||||
|
@ -136,7 +122,8 @@ export default class Controller extends Section {
|
|||
|
||||
moveTicketsAdvance() {
|
||||
let ticketsToMove = [];
|
||||
this.checked.forEach(ticket => {
|
||||
// falta ver que hacer con los nulls
|
||||
for (ticket of this.checked) {
|
||||
ticketsToMove.push({
|
||||
originId: ticket.futureId,
|
||||
destinationId: ticket.id,
|
||||
|
@ -144,7 +131,8 @@ export default class Controller extends Section {
|
|||
destinationShipped: ticket.shipped,
|
||||
workerFk: ticket.workerFk
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const params = {tickets: ticketsToMove};
|
||||
return this.$http.post('Tickets/merge', params)
|
||||
.then(() => {
|
||||
|
@ -152,6 +140,73 @@ export default class Controller extends Section {
|
|||
this.vnApp.showSuccess(this.$t('Success'));
|
||||
});
|
||||
}
|
||||
async getLanded(params) {
|
||||
const query = `Agencies/getLanded`;
|
||||
return this.$http.get(query, {params}).then(res => {
|
||||
if (res.data)
|
||||
return res.data;
|
||||
else {
|
||||
return this.vnApp.showError(
|
||||
this.$t(`No delivery zone available for this landing date`)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async splitTickets() {
|
||||
this.progress = [];
|
||||
this.splitErrors = [];
|
||||
this.$.splitTickets.hide();
|
||||
this.$.splitProgress.enable = true;
|
||||
this.$.splitProgress.cancel = false;
|
||||
this.$.splitProgress.show();
|
||||
for (const ticket of this.checked) {
|
||||
if (this.$.splitProgress.cancel) break;
|
||||
try {
|
||||
if (!ticket.landed) {
|
||||
const newLanded = await this.getLanded({
|
||||
shipped: this.$.model.userParams.dateToAdvance,
|
||||
addressFk: ticket.addressFk,
|
||||
agencyModeFk: ticket.agencyModeFk,
|
||||
warehouseFk: ticket.warehouseFk
|
||||
});
|
||||
ticket.landed = newLanded?.landed;
|
||||
ticket.zoneFk = newLanded?.zoneFk;
|
||||
}
|
||||
const query = `tickets/${ticket.futureId}/componentUpdate`;
|
||||
const params = {
|
||||
clientFk: ticket.clientFk,
|
||||
nickname: ticket.nickname,
|
||||
agencyModeFk: ticket.agencyModeFk,
|
||||
addressFk: ticket.addressFk,
|
||||
zoneFk: ticket.zoneFk,
|
||||
warehouseFk: ticket.warehouseFk,
|
||||
companyFk: ticket.companyFk,
|
||||
shipped: this.$.model.userParams.dateToAdvance,
|
||||
landed: ticket.landed,
|
||||
isDeleted: false,
|
||||
isWithoutNegatives: true,
|
||||
withWarningAccept: false,
|
||||
newTicket: ticket.id ?? undefined,
|
||||
keepPrice: true
|
||||
};
|
||||
|
||||
this.$http.post(query, params)
|
||||
.catch(e => {
|
||||
this.splitErrors.push({id: ticket.futureId, reason: e.message});
|
||||
})
|
||||
.finally(() => {
|
||||
this.progress.push(ticket.futureId);
|
||||
if (this.progress.length == this.checked.length) {
|
||||
this.$.splitProgress.enable = false;
|
||||
this.$.model.refresh();
|
||||
this.vnApp.showSuccess(this.$t('Success'));
|
||||
this.$checkAll = null;
|
||||
}
|
||||
});
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
exprBuilder(param, value) {
|
||||
switch (param) {
|
||||
|
|
|
@ -114,7 +114,9 @@ class Controller extends Component {
|
|||
isDeleted: this.ticket.isDeleted,
|
||||
option: parseInt(this.ticket.option),
|
||||
isWithoutNegatives: this.ticket.withoutNegatives,
|
||||
withWarningAccept: this.ticket.withWarningAccept
|
||||
withWarningAccept: this.ticket.withWarningAccept,
|
||||
newTicket: null,
|
||||
keepPrice: false
|
||||
};
|
||||
|
||||
this.$http.post(query, params)
|
||||
|
|
Loading…
Reference in New Issue