2018-03-12 13:02:29 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-18 07:35:59 +00:00
|
|
|
import Section from 'salix/components/section';
|
2020-03-09 10:50:23 +00:00
|
|
|
import UserError from 'core/lib/user-error';
|
2018-11-08 08:20:06 +00:00
|
|
|
import './style.scss';
|
2018-03-12 13:02:29 +00:00
|
|
|
|
2020-03-18 07:35:59 +00:00
|
|
|
export default class Controller extends Section {
|
2020-06-18 13:26:15 +00:00
|
|
|
constructor($element, $, vnReport) {
|
|
|
|
super($element, $);
|
|
|
|
this.vnReport = vnReport;
|
|
|
|
}
|
2021-06-24 11:33:51 +00:00
|
|
|
|
2020-06-17 13:38:37 +00:00
|
|
|
setDelivered() {
|
2020-06-16 10:36:34 +00:00
|
|
|
const checkedTickets = this.checked;
|
|
|
|
let ids = [];
|
|
|
|
|
|
|
|
for (let ticket of checkedTickets)
|
|
|
|
ids.push(ticket.id);
|
|
|
|
|
2020-06-18 11:50:52 +00:00
|
|
|
this.$http.post('TicketTrackings/setDelivered', ids).then(res => {
|
|
|
|
let state = res.data;
|
|
|
|
for (let ticket of checkedTickets) {
|
|
|
|
ticket.stateFk = state.id;
|
|
|
|
ticket.state = state.name;
|
|
|
|
ticket.alertLevel = state.alertLevel;
|
|
|
|
ticket.alertLevelCode = state.code;
|
|
|
|
}
|
2020-06-17 13:38:37 +00:00
|
|
|
this.openDeliveryNotes(ids);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
openDeliveryNotes(ids) {
|
2022-10-04 05:41:40 +00:00
|
|
|
for (let id of ids)
|
|
|
|
this.vnReport.show(`Tickets/${id}/delivery-note-pdf`);
|
2020-06-16 10:36:34 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 10:50:23 +00:00
|
|
|
openBalanceDialog() {
|
|
|
|
const checkedTickets = this.checked;
|
|
|
|
const description = [];
|
2019-04-25 05:57:26 +00:00
|
|
|
this.$.balanceCreateDialog.amountPaid = 0;
|
2020-03-09 10:50:23 +00:00
|
|
|
|
|
|
|
const firstTicketClientId = checkedTickets[0].clientFk;
|
|
|
|
const isSameClient = checkedTickets.every(ticket => {
|
|
|
|
return ticket.clientFk == firstTicketClientId;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!isSameClient)
|
|
|
|
throw new UserError('You cannot make a payment on account from multiple clients');
|
|
|
|
|
|
|
|
for (let ticket of checkedTickets) {
|
2021-03-10 18:25:26 +00:00
|
|
|
this.$.balanceCreateDialog.amountPaid += ticket.totalWithVat;
|
2020-03-09 10:50:23 +00:00
|
|
|
this.$.balanceCreateDialog.clientFk = ticket.clientFk;
|
|
|
|
description.push(`${ticket.id}`);
|
2019-04-25 05:57:26 +00:00
|
|
|
}
|
2020-03-09 10:50:23 +00:00
|
|
|
|
2019-04-25 05:57:26 +00:00
|
|
|
this.$.balanceCreateDialog.description = 'Albaran: ';
|
2019-04-29 08:21:36 +00:00
|
|
|
this.$.balanceCreateDialog.description += description.join(', ');
|
2020-03-09 10:50:23 +00:00
|
|
|
this.$.balanceCreateDialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
get checked() {
|
2020-03-25 13:18:51 +00:00
|
|
|
const tickets = this.$.model.data || [];
|
2020-03-09 10:50:23 +00:00
|
|
|
const checkedLines = [];
|
|
|
|
for (let ticket of tickets) {
|
|
|
|
if (ticket.checked)
|
|
|
|
checkedLines.push(ticket);
|
|
|
|
}
|
|
|
|
|
|
|
|
return checkedLines;
|
|
|
|
}
|
|
|
|
|
|
|
|
get totalChecked() {
|
|
|
|
return this.checked.length;
|
2019-04-25 05:57:26 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 14:10:26 +00:00
|
|
|
get confirmationMessage() {
|
|
|
|
if (!this.$.model) return 0;
|
|
|
|
|
|
|
|
return this.$t(`Are you sure to invoice tickets`, {
|
|
|
|
ticketsAmount: this.totalChecked
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-08 08:20:06 +00:00
|
|
|
onMoreOpen() {
|
|
|
|
let options = this.moreOptions.filter(o => o.always || this.isChecked);
|
|
|
|
this.$.moreButton.data = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
onMoreChange(callback) {
|
|
|
|
callback.call(this);
|
2018-04-10 05:48:04 +00:00
|
|
|
}
|
|
|
|
|
2018-04-19 12:56:05 +00:00
|
|
|
compareDate(date) {
|
2023-01-16 14:18:24 +00:00
|
|
|
let today = Date.vnNew();
|
2018-04-19 12:56:05 +00:00
|
|
|
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';
|
2018-03-12 13:02:29 +00:00
|
|
|
}
|
2018-08-23 08:08:06 +00:00
|
|
|
|
2018-12-21 06:53:04 +00:00
|
|
|
stateColor(ticket) {
|
|
|
|
if (ticket.alertLevelCode === 'OK')
|
2019-02-10 21:52:35 +00:00
|
|
|
return 'success';
|
2018-12-21 06:53:04 +00:00
|
|
|
else if (ticket.alertLevelCode === 'FREE')
|
2019-02-10 21:52:35 +00:00
|
|
|
return 'notice';
|
2018-12-21 06:53:04 +00:00
|
|
|
else if (ticket.alertLevel === 1)
|
2019-02-10 21:52:35 +00:00
|
|
|
return 'warning';
|
2018-12-21 06:53:04 +00:00
|
|
|
else if (ticket.alertLevel === 0)
|
2019-02-10 21:52:35 +00:00
|
|
|
return 'alert';
|
2018-12-21 06:53:04 +00:00
|
|
|
}
|
|
|
|
|
2019-09-24 14:38:57 +00:00
|
|
|
totalPriceColor(ticket) {
|
2021-03-10 18:25:26 +00:00
|
|
|
const total = parseInt(ticket.totalWithVat);
|
2019-10-01 09:06:20 +00:00
|
|
|
if (total > 0 && total < 50)
|
2019-09-24 14:38:57 +00:00
|
|
|
return 'warning';
|
|
|
|
}
|
|
|
|
|
2020-04-25 09:50:04 +00:00
|
|
|
preview(ticket) {
|
2018-10-30 12:58:02 +00:00
|
|
|
this.selectedTicket = ticket;
|
|
|
|
this.$.summary.show();
|
2018-04-19 12:56:05 +00:00
|
|
|
}
|
2020-06-09 10:16:40 +00:00
|
|
|
|
|
|
|
exprBuilder(param, value) {
|
|
|
|
switch (param) {
|
|
|
|
case 'stateFk':
|
|
|
|
return {'ts.stateFk': value};
|
|
|
|
case 'salesPersonFk':
|
|
|
|
return {'c.salesPersonFk': value};
|
|
|
|
case 'provinceFk':
|
|
|
|
return {'a.provinceFk': value};
|
|
|
|
case 'hour':
|
|
|
|
return {'z.hour': value};
|
|
|
|
case 'shipped':
|
|
|
|
return {'t.shipped': {
|
|
|
|
between: this.dateRange(value)}
|
|
|
|
};
|
|
|
|
case 'id':
|
|
|
|
case 'refFk':
|
2020-11-13 06:38:18 +00:00
|
|
|
case 'zoneFk':
|
2020-06-09 10:16:40 +00:00
|
|
|
case 'nickname':
|
|
|
|
case 'agencyModeFk':
|
|
|
|
case 'warehouseFk':
|
|
|
|
return {[`t.${param}`]: value};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dateRange(value) {
|
|
|
|
const minHour = new Date(value);
|
|
|
|
minHour.setHours(0, 0, 0, 0);
|
|
|
|
const maxHour = new Date(value);
|
|
|
|
maxHour.setHours(23, 59, 59, 59);
|
|
|
|
|
|
|
|
return [minHour, maxHour];
|
|
|
|
}
|
2021-06-08 15:30:00 +00:00
|
|
|
|
|
|
|
clientParams() {
|
|
|
|
if (this.$params.q) {
|
|
|
|
const params = JSON.parse(this.$params.q);
|
|
|
|
if (params.clientFk) return {clientFk: params.clientFk};
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
2021-06-24 11:33:51 +00:00
|
|
|
|
|
|
|
makeInvoice() {
|
2021-06-30 14:10:26 +00:00
|
|
|
const ticketsIds = this.checked.map(ticket => ticket.id);
|
|
|
|
return this.$http.post(`Tickets/makeInvoice`, {ticketsIds})
|
2021-06-24 11:33:51 +00:00
|
|
|
.then(() => this.$.model.refresh())
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('Ticket invoiced')));
|
|
|
|
}
|
2018-03-12 13:02:29 +00:00
|
|
|
}
|
2020-06-18 13:26:15 +00:00
|
|
|
Controller.$inject = ['$element', '$scope', 'vnReport'];
|
2018-04-10 05:48:04 +00:00
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnTicketIndex', {
|
2018-05-25 08:03:45 +00:00
|
|
|
template: require('./index.html'),
|
2018-03-12 13:02:29 +00:00
|
|
|
controller: Controller
|
|
|
|
});
|