143 lines
4.1 KiB
JavaScript
143 lines
4.1 KiB
JavaScript
import ngModule from '../module';
|
|
import './style.scss';
|
|
|
|
export default class Controller {
|
|
constructor($scope, $state, $stateParams, $translate, $http) {
|
|
this.$ = $scope;
|
|
this.$http = $http;
|
|
this.$translate = $translate;
|
|
this.$stateParams = $stateParams;
|
|
this.$state = $state;
|
|
this.selectedTicket = null;
|
|
this.moreOptions = [
|
|
{
|
|
name: 'Payment on account...',
|
|
always: true,
|
|
callback: () => {
|
|
this.setBalanceCreateDialog();
|
|
this.$.balanceCreateDialog.show();
|
|
}
|
|
}
|
|
];
|
|
}
|
|
|
|
setBalanceCreateDialog() {
|
|
let data = this.$.tickets;
|
|
let description = [];
|
|
this.$.balanceCreateDialog.amountPaid = 0;
|
|
if (data) {
|
|
for (let i = 0; i < data.length; i++) {
|
|
if (data[i].checked) {
|
|
this.$.balanceCreateDialog.amountPaid += data[i].total;
|
|
this.$.balanceCreateDialog.clientFk = data[i].clientFk;
|
|
description.push(`${data[i].id}`);
|
|
}
|
|
}
|
|
}
|
|
this.$.balanceCreateDialog.description = 'Albaran: ';
|
|
this.$.balanceCreateDialog.description += description.join(', ');
|
|
}
|
|
|
|
getScopeDates(days) {
|
|
const today = new Date();
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
const daysOnward = new Date(today);
|
|
daysOnward.setDate(today.getDate() + days);
|
|
daysOnward.setHours(23, 59, 59, 999);
|
|
|
|
return {from: today, to: daysOnward};
|
|
}
|
|
|
|
onSearch(params) {
|
|
if (params) {
|
|
if (typeof(params.scopeDays) === 'number')
|
|
Object.assign(params, this.getScopeDates(params.scopeDays));
|
|
// Set default params to 1 scope days
|
|
else if (Object.entries(params).length == 0)
|
|
params = this.getScopeDates(1);
|
|
|
|
this.$.model.applyFilter(null, params);
|
|
} else
|
|
this.$.model.clear();
|
|
}
|
|
|
|
goToLines(event, ticketFk) {
|
|
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);
|
|
}
|
|
|
|
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';
|
|
}
|
|
|
|
stateColor(ticket) {
|
|
if (ticket.alertLevelCode === 'OK')
|
|
return 'success';
|
|
else if (ticket.alertLevelCode === 'FREE')
|
|
return 'notice';
|
|
else if (ticket.alertLevel === 1)
|
|
return 'warning';
|
|
else if (ticket.alertLevel === 0)
|
|
return 'alert';
|
|
}
|
|
|
|
totalPriceColor(ticket) {
|
|
const total = parseInt(ticket.total);
|
|
if (total > 0 && total < 50)
|
|
return 'warning';
|
|
}
|
|
|
|
showClientDescriptor(event, clientFk) {
|
|
this.preventDefault(event);
|
|
this.$.clientDescriptor.clientFk = clientFk;
|
|
this.$.clientDescriptor.parent = event.target;
|
|
this.$.clientDescriptor.show();
|
|
}
|
|
|
|
showWorkerDescriptor(event, workerFk) {
|
|
this.preventDefault(event);
|
|
this.selectedWorker = workerFk;
|
|
this.$.workerDescriptor.parent = event.target;
|
|
this.$.workerDescriptor.show();
|
|
}
|
|
|
|
preview(event, ticket) {
|
|
this.preventDefault(event);
|
|
this.selectedTicket = ticket;
|
|
this.$.summary.show();
|
|
}
|
|
|
|
preventDefault(event) {
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$scope', '$state', '$stateParams', '$translate', '$http'];
|
|
|
|
ngModule.component('vnTicketIndex', {
|
|
template: require('./index.html'),
|
|
controller: Controller
|
|
});
|