salix/modules/ticket/front/index/index.js

156 lines
4.4 KiB
JavaScript
Raw Normal View History

2018-03-12 13:02:29 +00:00
import ngModule from '../module';
import UserError from 'core/lib/user-error';
import './style.scss';
2018-03-12 13:02:29 +00:00
export default class Controller {
constructor($scope, $state, $stateParams, $translate, $http) {
this.$ = $scope;
this.$http = $http;
2019-03-27 08:58:58 +00:00
this.$translate = $translate;
2019-01-24 07:21:00 +00:00
this.$stateParams = $stateParams;
this.$state = $state;
this.selectedTicket = null;
}
2019-01-23 11:30:32 +00:00
openBalanceDialog() {
const checkedTickets = this.checked;
const description = [];
2019-04-25 05:57:26 +00:00
this.$.balanceCreateDialog.amountPaid = 0;
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) {
this.$.balanceCreateDialog.amountPaid += ticket.total;
this.$.balanceCreateDialog.clientFk = ticket.clientFk;
description.push(`${ticket.id}`);
2019-04-25 05:57:26 +00:00
}
2019-04-25 05:57:26 +00:00
this.$.balanceCreateDialog.description = 'Albaran: ';
this.$.balanceCreateDialog.description += description.join(', ');
this.$.balanceCreateDialog.show();
}
get checked() {
const tickets = this.$.tickets || [];
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
}
2019-07-12 12:00:32 +00:00
getScopeDates(days) {
const today = new Date();
today.setHours(0, 0, 0, 0);
2018-12-12 13:52:20 +00:00
2019-07-12 12:00:32 +00:00
const daysOnward = new Date(today);
daysOnward.setDate(today.getDate() + days);
daysOnward.setHours(23, 59, 59, 999);
2019-07-12 12:00:32 +00:00
return {from: today, to: daysOnward};
2019-01-22 15:18:26 +00:00
}
2018-12-19 07:42:07 +00:00
onSearch(params) {
if (params) {
if (typeof (params.scopeDays) === 'number')
2020-02-05 07:23:23 +00:00
Object.assign(params, this.getScopeDates(params.scopeDays));
2020-02-05 07:24:29 +00:00
// Set default params to 1 scope days
2020-02-05 07:23:23 +00:00
else if (Object.entries(params).length == 0)
params = this.getScopeDates(1);
2019-07-12 12:00:32 +00:00
2020-02-05 07:23:23 +00:00
this.$.model.applyFilter(null, params);
} else
2018-12-19 07:42:07 +00:00
this.$.model.clear();
}
goToLines(event, ticketFk) {
2019-03-27 08:58:58 +00:00
this.preventDefault(event);
let url = this.$state.href('ticket.card.sale', {id: ticketFk}, {absolute: true});
window.open(url, '_blank');
}
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) {
let today = new Date();
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
}
totalPriceColor(ticket) {
const total = parseInt(ticket.total);
if (total > 0 && total < 50)
return 'warning';
}
showClientDescriptor(event, clientFk) {
2019-03-27 08:58:58 +00:00
this.preventDefault(event);
this.$.clientDescriptor.clientFk = clientFk;
this.$.clientDescriptor.parent = event.target;
this.$.clientDescriptor.show();
}
showWorkerDescriptor(event, workerFk) {
2019-03-27 08:58:58 +00:00
this.preventDefault(event);
this.selectedWorker = workerFk;
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.show();
}
2018-04-10 05:48:04 +00:00
2018-04-19 12:56:05 +00:00
preview(event, ticket) {
2019-03-27 08:58:58 +00:00
this.preventDefault(event);
this.selectedTicket = ticket;
this.$.summary.show();
2018-04-19 12:56:05 +00:00
}
2019-03-27 08:58:58 +00:00
preventDefault(event) {
event.preventDefault();
event.stopImmediatePropagation();
}
2018-03-12 13:02:29 +00:00
}
2018-04-10 05:48:04 +00:00
Controller.$inject = ['$scope', '$state', '$stateParams', '$translate', '$http'];
2018-03-12 13:02:29 +00:00
ngModule.component('vnTicketIndex', {
template: require('./index.html'),
2018-03-12 13:02:29 +00:00
controller: Controller
});