2021-11-09 14:10:43 +00:00
|
|
|
|
import ngModule from '../module';
|
|
|
|
|
import Section from 'salix/components/section';
|
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
|
|
class Controller extends Section {
|
2021-11-10 13:48:17 +00:00
|
|
|
|
constructor($element, $, vnReport, vnEmail) {
|
2021-11-09 14:10:43 +00:00
|
|
|
|
super($element, $);
|
2021-11-10 13:48:17 +00:00
|
|
|
|
this.vnReport = vnReport;
|
|
|
|
|
this.vnEmail = vnEmail;
|
2024-05-06 12:51:53 +00:00
|
|
|
|
this.checked = true;
|
2021-11-09 14:10:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get invoiceOut() {
|
|
|
|
|
return this._invoiceOut;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set invoiceOut(value) {
|
|
|
|
|
this._invoiceOut = value;
|
2021-11-10 13:48:17 +00:00
|
|
|
|
if (value)
|
|
|
|
|
this.id = value.id;
|
2021-11-09 14:10:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 12:15:42 +00:00
|
|
|
|
get hasInvoicing() {
|
|
|
|
|
return this.aclService.hasAny(['invoicing']);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-06 12:51:53 +00:00
|
|
|
|
get isChecked() {
|
|
|
|
|
return this.checked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set isChecked(value) {
|
|
|
|
|
this.checked = value;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 12:30:20 +00:00
|
|
|
|
$onInit() {
|
|
|
|
|
this.$http.get(`CplusRectificationTypes`, {filter: {order: 'description'}})
|
|
|
|
|
.then(res => {
|
|
|
|
|
this.cplusRectificationTypes = res.data;
|
|
|
|
|
this.cplusRectificationType = res.data.filter(type => type.description == 'I – Por diferencias')[0].id;
|
|
|
|
|
});
|
|
|
|
|
this.$http.get(`SiiTypeInvoiceOuts`, {filter: {where: {code: {like: 'R%'}}}})
|
|
|
|
|
.then(res => {
|
|
|
|
|
this.siiTypeInvoiceOuts = res.data;
|
|
|
|
|
this.siiTypeInvoiceOut = res.data.filter(type => type.code == 'R4')[0].id;
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-11-09 14:10:43 +00:00
|
|
|
|
loadData() {
|
|
|
|
|
const filter = {
|
|
|
|
|
include: [
|
|
|
|
|
{
|
|
|
|
|
relation: 'company',
|
|
|
|
|
scope: {
|
|
|
|
|
fields: ['id', 'code']
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
relation: 'client',
|
|
|
|
|
scope: {
|
2024-05-06 12:51:53 +00:00
|
|
|
|
fields: ['id', 'name', 'email', 'hasToInvoiceByAddress']
|
2021-11-09 14:10:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
2021-11-10 13:48:17 +00:00
|
|
|
|
return this.$http.get(`InvoiceOuts/${this.invoiceOut.id}`, {filter})
|
|
|
|
|
.then(res => this.invoiceOut = res.data);
|
2021-11-09 14:10:43 +00:00
|
|
|
|
}
|
|
|
|
|
reload() {
|
|
|
|
|
return this.loadData().then(() => {
|
|
|
|
|
if (this.parentReload)
|
|
|
|
|
this.parentReload();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cardReload() {
|
|
|
|
|
// Prevents error when not defined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deleteInvoiceOut() {
|
|
|
|
|
return this.$http.post(`InvoiceOuts/${this.invoiceOut.id}/delete`)
|
2022-01-20 10:06:15 +00:00
|
|
|
|
.then(() => {
|
|
|
|
|
const isInsideInvoiceOut = this.$state.current.name.startsWith('invoiceOut');
|
|
|
|
|
if (isInsideInvoiceOut)
|
|
|
|
|
this.$state.go('invoiceOut.index');
|
|
|
|
|
else
|
|
|
|
|
this.$state.reload();
|
|
|
|
|
})
|
2021-11-10 13:48:17 +00:00
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted')));
|
2021-11-09 14:10:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bookInvoiceOut() {
|
|
|
|
|
return this.$http.post(`InvoiceOuts/${this.invoiceOut.ref}/book`)
|
|
|
|
|
.then(() => this.$state.reload())
|
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut booked')));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createPdfInvoice() {
|
2021-11-10 13:48:17 +00:00
|
|
|
|
return this.$http.post(`InvoiceOuts/${this.id}/createPdf`)
|
2021-11-09 14:10:43 +00:00
|
|
|
|
.then(() => this.reload())
|
|
|
|
|
.then(() => {
|
|
|
|
|
const snackbarMessage = this.$t(
|
|
|
|
|
`The invoice PDF document has been regenerated`);
|
|
|
|
|
this.vnApp.showSuccess(snackbarMessage);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sendPdfInvoice($data) {
|
2021-11-11 13:46:05 +00:00
|
|
|
|
if (!$data.email)
|
|
|
|
|
return this.vnApp.showError(this.$t(`The email can't be empty`));
|
|
|
|
|
|
2022-09-26 11:33:27 +00:00
|
|
|
|
return this.vnEmail.send(`InvoiceOuts/${this.invoiceOut.ref}/invoice-email`, {
|
2021-11-09 14:10:43 +00:00
|
|
|
|
recipientId: this.invoiceOut.client.id,
|
2022-09-26 11:33:27 +00:00
|
|
|
|
recipient: $data.email
|
2021-11-09 14:10:43 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 06:28:47 +00:00
|
|
|
|
showCsvInvoice() {
|
|
|
|
|
this.vnReport.show(`InvoiceOuts/${this.invoiceOut.ref}/invoice-csv`, {
|
|
|
|
|
recipientId: this.invoiceOut.client.id
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-09 14:10:43 +00:00
|
|
|
|
sendCsvInvoice($data) {
|
2021-11-11 13:46:05 +00:00
|
|
|
|
if (!$data.email)
|
|
|
|
|
return this.vnApp.showError(this.$t(`The email can't be empty`));
|
|
|
|
|
|
2022-10-03 06:28:47 +00:00
|
|
|
|
return this.vnEmail.send(`InvoiceOuts/${this.invoiceOut.ref}/invoice-csv-email`, {
|
2021-11-09 14:10:43 +00:00
|
|
|
|
recipientId: this.invoiceOut.client.id,
|
2022-10-03 06:28:47 +00:00
|
|
|
|
recipient: $data.email
|
2021-11-09 14:10:43 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showExportationLetter() {
|
2022-09-26 11:33:27 +00:00
|
|
|
|
this.vnReport.show(`InvoiceOuts/${this.invoiceOut.ref}/exportation-pdf`, {
|
2021-11-09 14:10:43 +00:00
|
|
|
|
recipientId: this.invoiceOut.client.id,
|
2022-07-21 08:05:37 +00:00
|
|
|
|
refFk: this.invoiceOut.ref
|
2021-11-09 14:10:43 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2022-04-22 09:46:28 +00:00
|
|
|
|
|
2023-07-28 13:21:43 +00:00
|
|
|
|
transferInvoice() {
|
|
|
|
|
const params = {
|
2024-09-04 06:30:01 +00:00
|
|
|
|
id: this.invoiceOut.id,
|
2023-11-20 06:56:15 +00:00
|
|
|
|
newClientFk: this.clientId,
|
2023-11-30 14:16:41 +00:00
|
|
|
|
cplusRectificationTypeFk: this.cplusRectificationType,
|
2023-11-20 06:56:15 +00:00
|
|
|
|
siiTypeInvoiceOutFk: this.siiTypeInvoiceOut,
|
2024-05-06 12:51:53 +00:00
|
|
|
|
invoiceCorrectionTypeFk: this.invoiceCorrectionType,
|
2024-05-31 06:44:30 +00:00
|
|
|
|
makeInvoice: this.checked
|
2023-07-28 13:21:43 +00:00
|
|
|
|
};
|
2024-05-07 09:35:05 +00:00
|
|
|
|
|
2024-05-06 12:51:53 +00:00
|
|
|
|
this.$http.get(`Clients/${this.clientId}`).then(response => {
|
|
|
|
|
const clientData = response.data;
|
|
|
|
|
const hasToInvoiceByAddress = clientData.hasToInvoiceByAddress;
|
|
|
|
|
|
|
|
|
|
if (this.checked && hasToInvoiceByAddress) {
|
2024-05-09 06:05:23 +00:00
|
|
|
|
if (!window.confirm(this.$t('confirmTransferInvoice')))
|
2024-05-08 12:12:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 11:50:51 +00:00
|
|
|
|
this.$http.post(`InvoiceOuts/transfer`, params).then(res => {
|
2024-05-08 12:12:10 +00:00
|
|
|
|
const invoiceId = res.data;
|
|
|
|
|
this.vnApp.showSuccess(this.$t('Transferred invoice'));
|
|
|
|
|
this.$state.go('invoiceOut.card.summary', {id: invoiceId});
|
|
|
|
|
});
|
2023-08-03 12:01:50 +00:00
|
|
|
|
});
|
2023-07-28 13:21:43 +00:00
|
|
|
|
}
|
2021-11-09 14:10:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-10 13:48:17 +00:00
|
|
|
|
Controller.$inject = ['$element', '$scope', 'vnReport', 'vnEmail'];
|
2021-11-09 14:10:43 +00:00
|
|
|
|
|
|
|
|
|
ngModule.vnComponent('vnInvoiceOutDescriptorMenu', {
|
|
|
|
|
template: require('./index.html'),
|
|
|
|
|
controller: Controller,
|
|
|
|
|
bindings: {
|
|
|
|
|
invoiceOut: '<',
|
2021-11-10 13:48:17 +00:00
|
|
|
|
parentReload: '&'
|
2021-11-09 14:10:43 +00:00
|
|
|
|
}
|
|
|
|
|
});
|