2022-11-14 13:30:35 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import Section from 'salix/components/section';
|
2023-01-31 13:20:08 +00:00
|
|
|
import './style.scss';
|
2022-11-14 13:30:35 +00:00
|
|
|
|
|
|
|
export default class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
|
|
|
this.$checkAll = false;
|
|
|
|
|
|
|
|
this.smartTableOptions = {
|
|
|
|
activeButtons: {
|
|
|
|
search: true,
|
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
field: 'state',
|
|
|
|
searchable: false
|
2023-10-24 07:23:03 +00:00
|
|
|
}, {
|
2022-12-20 10:36:58 +00:00
|
|
|
field: 'futureState',
|
2022-11-14 13:30:35 +00:00
|
|
|
searchable: false
|
2023-10-24 07:23:03 +00:00
|
|
|
}, {
|
2022-11-15 14:30:00 +00:00
|
|
|
field: 'totalWithVat',
|
|
|
|
searchable: false
|
2023-10-24 07:23:03 +00:00
|
|
|
}, {
|
2022-12-20 10:36:58 +00:00
|
|
|
field: 'futureTotalWithVat',
|
2022-11-15 14:30:00 +00:00
|
|
|
searchable: false
|
2023-10-24 07:23:03 +00:00
|
|
|
}, {
|
2022-12-20 10:36:37 +00:00
|
|
|
field: 'shipped',
|
|
|
|
searchable: false
|
2023-10-24 07:23:03 +00:00
|
|
|
}, {
|
2022-12-20 10:36:58 +00:00
|
|
|
field: 'futureShipped',
|
2022-11-16 09:57:15 +00:00
|
|
|
searchable: false
|
2023-10-24 07:23:03 +00:00
|
|
|
}, {
|
2022-11-14 13:30:35 +00:00
|
|
|
field: 'ipt',
|
|
|
|
autocomplete: {
|
|
|
|
url: 'ItemPackingTypes',
|
2023-01-17 07:54:26 +00:00
|
|
|
where: `{isActive: true}`,
|
2022-11-14 13:30:35 +00:00
|
|
|
showField: 'description',
|
2022-12-20 10:36:37 +00:00
|
|
|
valueField: 'code'
|
2022-11-14 13:30:35 +00:00
|
|
|
}
|
2023-10-24 07:23:03 +00:00
|
|
|
}, {
|
2022-12-20 10:36:58 +00:00
|
|
|
field: 'futureIpt',
|
2022-11-14 13:30:35 +00:00
|
|
|
autocomplete: {
|
|
|
|
url: 'ItemPackingTypes',
|
2023-01-17 07:54:26 +00:00
|
|
|
where: `{isActive: true}`,
|
2022-11-14 13:30:35 +00:00
|
|
|
showField: 'description',
|
2022-12-20 10:36:37 +00:00
|
|
|
valueField: 'code'
|
2022-11-14 13:30:35 +00:00
|
|
|
}
|
2023-10-24 07:23:03 +00:00
|
|
|
}, {
|
|
|
|
field: 'futureZoneFk',
|
|
|
|
autocomplete: {
|
|
|
|
url: 'Zones',
|
|
|
|
}
|
2022-11-14 13:30:35 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
};
|
2022-12-20 10:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$postLink() {
|
2022-11-16 09:57:15 +00:00
|
|
|
this.setDefaultFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
setDefaultFilter() {
|
2023-01-16 14:18:24 +00:00
|
|
|
let today = Date.vnNew();
|
2024-07-26 11:47:15 +00:00
|
|
|
today.setHours(0, 0, 0, 0);
|
2022-12-20 10:36:37 +00:00
|
|
|
const tomorrow = new Date(today);
|
2022-11-16 09:57:15 +00:00
|
|
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
2024-07-26 11:47:15 +00:00
|
|
|
tomorrow.setHours(23, 59, 59, 999);
|
|
|
|
|
2023-02-08 12:47:35 +00:00
|
|
|
this.$http.get(`UserConfigs/getUserConfig`)
|
|
|
|
.then(res => {
|
|
|
|
this.filterParams = {
|
|
|
|
dateFuture: tomorrow,
|
|
|
|
dateToAdvance: today,
|
|
|
|
warehouseFk: res.data.warehouseFk
|
|
|
|
};
|
|
|
|
this.$.model.addFilter({}, this.filterParams);
|
|
|
|
});
|
2022-11-14 13:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get checked() {
|
|
|
|
const tickets = this.$.model.data || [];
|
|
|
|
const checkedLines = [];
|
|
|
|
for (let ticket of tickets) {
|
|
|
|
if (ticket.checked)
|
|
|
|
checkedLines.push(ticket);
|
|
|
|
}
|
|
|
|
|
|
|
|
return checkedLines;
|
|
|
|
}
|
|
|
|
|
|
|
|
totalPriceColor(totalWithVat) {
|
2023-02-10 07:46:54 +00:00
|
|
|
return this.isLessThan50(totalWithVat) ? 'warning' : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
totalPriceTitle(totalWithVat) {
|
|
|
|
return this.isLessThan50(totalWithVat) ? 'Less than 50€' : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
isLessThan50(totalWithVat) {
|
|
|
|
return (parseInt(totalWithVat) > 0 && parseInt(totalWithVat) < 50);
|
2022-11-14 13:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get confirmationMessage() {
|
|
|
|
if (!this.$.model) return 0;
|
|
|
|
|
|
|
|
return this.$t(`Advance confirmation`, {
|
|
|
|
checked: this.checked.length
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-31 13:20:08 +00:00
|
|
|
agencies(futureAgency, agency) {
|
|
|
|
return this.$t(`Origin agency`, {agency: futureAgency}) +
|
2023-02-10 07:46:54 +00:00
|
|
|
'\n' + this.$t(`Destination agency`, {agency: agency});
|
2023-01-31 13:20:08 +00:00
|
|
|
}
|
|
|
|
|
2023-10-30 13:16:25 +00:00
|
|
|
async moveTicketsAdvance() {
|
2022-12-20 10:36:58 +00:00
|
|
|
let ticketsToMove = [];
|
2023-10-30 13:16:25 +00:00
|
|
|
for (const ticket of this.checked) {
|
|
|
|
if (!ticket.id) {
|
|
|
|
try {
|
|
|
|
const {query, params} = await this.requestComponentUpdate(ticket, false);
|
|
|
|
this.$http.post(query, params);
|
|
|
|
} catch (e) {}
|
|
|
|
continue;
|
|
|
|
}
|
2022-12-20 10:36:58 +00:00
|
|
|
ticketsToMove.push({
|
|
|
|
originId: ticket.futureId,
|
|
|
|
destinationId: ticket.id,
|
|
|
|
originShipped: ticket.futureShipped,
|
|
|
|
destinationShipped: ticket.shipped,
|
|
|
|
workerFk: ticket.workerFk
|
|
|
|
});
|
2023-10-27 13:06:20 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 10:36:58 +00:00
|
|
|
const params = {tickets: ticketsToMove};
|
2022-11-14 13:30:35 +00:00
|
|
|
return this.$http.post('Tickets/merge', params)
|
|
|
|
.then(() => {
|
2023-10-30 13:16:25 +00:00
|
|
|
this.refresh();
|
|
|
|
if (ticketsToMove.length)
|
|
|
|
this.vnApp.showSuccess(this.$t('Success', {tickets: ticketsToMove.length}));
|
2022-11-14 13:30:35 +00:00
|
|
|
});
|
|
|
|
}
|
2023-10-30 13:16:25 +00:00
|
|
|
|
2023-10-27 13:06:20 +00:00
|
|
|
async getLanded(params) {
|
|
|
|
const query = `Agencies/getLanded`;
|
|
|
|
return this.$http.get(query, {params}).then(res => {
|
|
|
|
if (res.data)
|
|
|
|
return res.data;
|
2023-11-03 06:57:53 +00:00
|
|
|
|
|
|
|
return this.vnApp.showError(
|
|
|
|
this.$t(`No delivery zone available for this landing date`)
|
|
|
|
);
|
2023-10-27 13:06:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async splitTickets() {
|
|
|
|
this.progress = [];
|
|
|
|
this.splitErrors = [];
|
|
|
|
this.$.splitTickets.hide();
|
|
|
|
this.$.splitProgress.enable = true;
|
|
|
|
this.$.splitProgress.cancel = false;
|
|
|
|
this.$.splitProgress.show();
|
2023-10-30 13:16:25 +00:00
|
|
|
|
2023-10-27 13:06:20 +00:00
|
|
|
for (const ticket of this.checked) {
|
|
|
|
if (this.$.splitProgress.cancel) break;
|
|
|
|
try {
|
2023-10-30 13:16:25 +00:00
|
|
|
const {query, params} = await this.requestComponentUpdate(ticket, true);
|
2023-10-27 13:06:20 +00:00
|
|
|
this.$http.post(query, params)
|
|
|
|
.catch(e => {
|
|
|
|
this.splitErrors.push({id: ticket.futureId, reason: e.message});
|
|
|
|
})
|
2023-10-30 13:16:25 +00:00
|
|
|
.finally(() => this.progressAdd(ticket.futureId));
|
|
|
|
} catch (e) {
|
|
|
|
this.splitErrors.push({id: ticket.futureId, reason: e.message});
|
|
|
|
this.progressAdd(ticket.futureId);
|
|
|
|
}
|
2023-10-27 13:06:20 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-14 13:30:35 +00:00
|
|
|
|
2023-10-30 13:16:25 +00:00
|
|
|
progressAdd(ticketId) {
|
|
|
|
this.progress.push(ticketId);
|
|
|
|
if (this.progress.length == this.checked.length) {
|
|
|
|
this.$.splitProgress.enable = false;
|
|
|
|
this.refresh();
|
|
|
|
if ((this.progress.length - this.splitErrors.length) > 0) {
|
|
|
|
this.vnApp.showSuccess(this.$t('Success', {
|
|
|
|
tickets: this.progress.length - this.splitErrors.length
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async requestComponentUpdate(ticket, isWithoutNegatives) {
|
|
|
|
const query = `tickets/${ticket.futureId}/componentUpdate`;
|
|
|
|
if (!ticket.landed) {
|
|
|
|
const newLanded = await this.getLanded({
|
|
|
|
shipped: this.$.model.userParams.dateToAdvance,
|
2023-11-27 14:10:00 +00:00
|
|
|
addressFk: ticket.futureAddressFk,
|
|
|
|
agencyModeFk: ticket.agencyModeFk ?? ticket.futureAgencyModeFk,
|
|
|
|
warehouseFk: ticket.futureWarehouseFk
|
2023-10-30 13:16:25 +00:00
|
|
|
});
|
|
|
|
if (!newLanded)
|
|
|
|
throw new Error(this.$t(`No delivery zone available for this landing date`));
|
|
|
|
|
|
|
|
ticket.landed = newLanded.landed;
|
|
|
|
ticket.zoneFk = newLanded.zoneFk;
|
|
|
|
}
|
|
|
|
const params = {
|
2023-11-27 14:10:00 +00:00
|
|
|
clientFk: ticket.futureClientFk,
|
2023-10-30 13:16:25 +00:00
|
|
|
nickname: ticket.nickname,
|
2023-11-10 07:46:49 +00:00
|
|
|
agencyModeFk: ticket.agencyModeFk ?? ticket.futureAgencyModeFk,
|
2023-11-27 14:10:00 +00:00
|
|
|
addressFk: ticket.futureAddressFk,
|
2023-11-10 07:46:49 +00:00
|
|
|
zoneFk: ticket.zoneFk ?? ticket.futureZoneFk,
|
2023-11-27 14:10:00 +00:00
|
|
|
warehouseFk: ticket.futureWarehouseFk,
|
|
|
|
companyFk: ticket.futureCompanyFk,
|
2023-10-30 13:16:25 +00:00
|
|
|
shipped: this.$.model.userParams.dateToAdvance,
|
|
|
|
landed: ticket.landed,
|
|
|
|
isDeleted: false,
|
|
|
|
isWithoutNegatives,
|
|
|
|
newTicket: ticket.id ?? undefined,
|
|
|
|
keepPrice: true
|
|
|
|
};
|
2023-11-03 06:57:53 +00:00
|
|
|
|
2023-10-30 13:16:25 +00:00
|
|
|
return {query, params};
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
this.$.model.refresh();
|
|
|
|
this.$checkAll = null;
|
|
|
|
}
|
|
|
|
|
2022-11-14 13:30:35 +00:00
|
|
|
exprBuilder(param, value) {
|
|
|
|
switch (param) {
|
2022-11-29 09:29:18 +00:00
|
|
|
case 'id':
|
2022-12-20 10:36:58 +00:00
|
|
|
case 'futureId':
|
2022-11-29 09:29:18 +00:00
|
|
|
case 'liters':
|
2023-01-31 14:09:16 +00:00
|
|
|
case 'futureLiters':
|
2023-10-19 09:58:15 +00:00
|
|
|
case 'lines':
|
2023-01-31 14:09:16 +00:00
|
|
|
case 'futureLines':
|
2023-10-24 07:23:03 +00:00
|
|
|
case 'totalWithVat':
|
|
|
|
case 'futureTotalWithVat':
|
|
|
|
case 'futureZone':
|
|
|
|
case 'notMovableLines':
|
|
|
|
case 'futureZoneFk':
|
|
|
|
return {[param]: value};
|
2022-11-29 09:29:18 +00:00
|
|
|
case 'ipt':
|
2023-10-19 09:58:15 +00:00
|
|
|
return {'ipt': {like: `%${value}%`}};
|
2022-12-20 10:36:58 +00:00
|
|
|
case 'futureIpt':
|
2023-10-19 09:58:15 +00:00
|
|
|
return {'futureIpt': {like: `%${value}%`}};
|
2022-11-14 13:30:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$element', '$scope'];
|
|
|
|
|
|
|
|
ngModule.vnComponent('vnTicketAdvance', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|