2019-03-26 13:27:08 +00:00
|
|
|
import ngModule from '../module';
|
2020-04-25 09:50:04 +00:00
|
|
|
import Descriptor from 'salix/components/descriptor';
|
2019-03-26 13:27:08 +00:00
|
|
|
|
2020-04-25 09:50:04 +00:00
|
|
|
class Controller extends Descriptor {
|
2020-03-17 13:43:46 +00:00
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2019-04-18 09:47:31 +00:00
|
|
|
this.moreOptions = [
|
2020-03-31 13:15:16 +00:00
|
|
|
{
|
|
|
|
name: 'Show invoice PDF',
|
|
|
|
callback: this.showInvoiceOutPdf
|
|
|
|
}, {
|
|
|
|
name: 'Delete Invoice',
|
|
|
|
callback: this.showDeleteInvoiceOutDialog,
|
|
|
|
acl: 'invoicing'
|
|
|
|
}, {
|
|
|
|
name: 'Book invoice',
|
|
|
|
callback: this.showBookInvoiceOutDialog,
|
|
|
|
acl: 'invoicing'
|
|
|
|
}
|
2019-04-18 09:47:31 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-04-26 10:05:49 +00:00
|
|
|
onMoreOpen() {
|
|
|
|
let options = this.moreOptions.filter(option => {
|
|
|
|
const hasAclProperty = Object.hasOwnProperty.call(option, 'acl');
|
|
|
|
|
|
|
|
return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl]));
|
|
|
|
});
|
2020-03-20 08:01:14 +00:00
|
|
|
this.$.moreButton.data = options;
|
2019-04-26 10:05:49 +00:00
|
|
|
}
|
|
|
|
|
2019-04-18 09:47:31 +00:00
|
|
|
onMoreChange(callback) {
|
|
|
|
callback.call(this);
|
|
|
|
}
|
|
|
|
|
2019-03-26 13:27:08 +00:00
|
|
|
set invoiceOut(value) {
|
|
|
|
this._invoiceOut = value;
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
this._quicklinks = {
|
|
|
|
btnOne: {
|
|
|
|
icon: 'icon-person',
|
|
|
|
state: `client.card.summary({id: ${value.clientFk}})`,
|
|
|
|
tooltip: 'Client card'
|
|
|
|
},
|
|
|
|
btnTwo: {
|
|
|
|
icon: 'icon-ticket',
|
|
|
|
state: `ticket.index({q: '{"refFk": "${value.ref}"}'})`,
|
|
|
|
tooltip: 'Invoice ticket list'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get invoiceOut() {
|
|
|
|
return this._invoiceOut;
|
|
|
|
}
|
|
|
|
|
2019-04-18 09:47:31 +00:00
|
|
|
showInvoiceOutPdf() {
|
2019-12-24 09:17:41 +00:00
|
|
|
let url = `api/InvoiceOuts/${this.invoiceOut.id}/download?access_token=${this.accessToken}`;
|
2019-04-18 09:47:31 +00:00
|
|
|
window.open(url, '_blank');
|
|
|
|
}
|
|
|
|
|
2019-04-26 10:05:49 +00:00
|
|
|
showDeleteInvoiceOutDialog() {
|
2020-03-17 13:43:46 +00:00
|
|
|
this.$.deleteConfirmation.show();
|
2019-04-26 10:05:49 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 09:03:48 +00:00
|
|
|
showBookInvoiceOutDialog() {
|
2020-03-17 13:43:46 +00:00
|
|
|
this.$.bookConfirmation.show();
|
2019-04-30 09:03:48 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 13:15:16 +00:00
|
|
|
deleteInvoiceOut() {
|
|
|
|
const query = `InvoiceOuts/${this.invoiceOut.id}/delete`;
|
|
|
|
return this.$http.post(query)
|
|
|
|
.then(() => this.$state.go('invoiceOut.index'))
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted')));
|
2019-04-26 10:05:49 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 13:15:16 +00:00
|
|
|
bookInvoiceOut() {
|
|
|
|
const query = `InvoiceOuts/${this.invoiceOut.ref}/book`;
|
|
|
|
return this.$http.post(query)
|
|
|
|
.then(() => this.$state.reload())
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut booked')));
|
2019-04-30 09:03:48 +00:00
|
|
|
}
|
2019-03-26 13:27:08 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 09:50:04 +00:00
|
|
|
ngModule.vnComponent('vnInvoiceOutDescriptor', {
|
2019-03-26 13:27:08 +00:00
|
|
|
template: require('./index.html'),
|
2020-04-25 09:50:04 +00:00
|
|
|
controller: Controller,
|
2019-03-26 13:27:08 +00:00
|
|
|
bindings: {
|
2020-04-25 09:50:04 +00:00
|
|
|
invoiceOut: '<'
|
|
|
|
}
|
2019-03-26 13:27:08 +00:00
|
|
|
});
|