2019-03-26 13:27:08 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-17 13:43:46 +00:00
|
|
|
import Component from 'core/lib/component';
|
2019-03-26 13:27:08 +00:00
|
|
|
|
2020-03-17 13:43:46 +00:00
|
|
|
class Controller extends Component {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2019-04-18 09:47:31 +00:00
|
|
|
this.moreOptions = [
|
2019-04-30 09:47:39 +00:00
|
|
|
{callback: this.showInvoiceOutPdf, name: 'Show invoice PDF'},
|
|
|
|
{callback: this.showDeleteInvoiceOutDialog, name: 'Delete Invoice', acl: 'invoicing'},
|
2019-04-30 09:03:48 +00:00
|
|
|
{callback: this.showBookInvoiceOutDialog, name: 'Book invoice', 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]));
|
|
|
|
});
|
|
|
|
this.$scope.moreButton.data = options;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-04-26 10:05:49 +00:00
|
|
|
deleteInvoiceOut(response) {
|
2019-10-30 15:57:14 +00:00
|
|
|
if (response === 'accept') {
|
2019-10-24 22:53:53 +00:00
|
|
|
const query = `InvoiceOuts/${this.invoiceOut.id}/delete`;
|
2019-04-26 10:05:49 +00:00
|
|
|
this.$http.post(query).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('InvoiceOut deleted'));
|
|
|
|
this.$state.go('invoiceOut.index');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 09:03:48 +00:00
|
|
|
bookInvoiceOut(response) {
|
2019-10-30 15:57:14 +00:00
|
|
|
if (response === 'accept') {
|
2019-10-24 22:53:53 +00:00
|
|
|
const query = `InvoiceOuts/${this.invoiceOut.ref}/book`;
|
2019-04-30 09:03:48 +00:00
|
|
|
this.$http.post(query).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('InvoiceOut booked'));
|
2019-04-30 09:47:39 +00:00
|
|
|
this.$state.reload();
|
2019-04-30 09:03:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-26 13:27:08 +00:00
|
|
|
set quicklinks(value = {}) {
|
|
|
|
this._quicklinks = Object.assign(value, this._quicklinks);
|
|
|
|
}
|
|
|
|
|
|
|
|
get quicklinks() {
|
|
|
|
return this._quicklinks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 13:43:46 +00:00
|
|
|
Controller.$inject = ['$element', '$scope'];
|
2019-03-26 13:27:08 +00:00
|
|
|
|
|
|
|
ngModule.component('vnInvoiceOutDescriptor', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
bindings: {
|
|
|
|
invoiceOut: '<',
|
|
|
|
quicklinks: '<'
|
|
|
|
},
|
|
|
|
controller: Controller
|
|
|
|
});
|