diff --git a/db/changes/233801/00-notificationBookEntry.sql b/db/changes/233801/00-notificationBookEntry.sql
new file mode 100644
index 000000000..4b8320450
--- /dev/null
+++ b/db/changes/233801/00-notificationBookEntry.sql
@@ -0,0 +1,14 @@
+
+INSERT IGNORE INTO util.`notification` (id, `name`, description)
+ SELECT MAX(id) + 1, 'book-entry-deleted', 'accounting entries deleted'
+ FROM util.`notification`;
+
+INSERT IGNORE INTO util.`notificationAcl` (notificationFk, roleFk)
+ VALUES(
+ (SELECT id FROM util.`notification` WHERE `name` = 'book-entry-deleted'),
+ (SELECT id FROM vn.`role` r WHERE `name` = 'administrative'));
+
+INSERT IGNORE INTO util.`notificationSubscription` (notificationFk, userFk)
+ VALUES(
+ (SELECT id FROM util.`notification` WHERE `name` = 'book-entry-deleted'),
+ (SELECT id FROM account.`user` WHERE `name` = 'admon'));
diff --git a/modules/invoiceOut/back/methods/invoiceOut/delete.js b/modules/invoiceOut/back/methods/invoiceOut/delete.js
index d8b9d309b..726e455ab 100644
--- a/modules/invoiceOut/back/methods/invoiceOut/delete.js
+++ b/modules/invoiceOut/back/methods/invoiceOut/delete.js
@@ -1,5 +1,4 @@
-
-module.exports = Self => {
+export default Self => {
Self.remoteMethod('delete', {
description: 'Delete a invoiceOut',
accessType: 'WRITE',
@@ -37,7 +36,12 @@ module.exports = Self => {
const tickets = await Self.app.models.Ticket.find({
where: {refFk: invoiceOut.ref}
}, myOptions);
-
+ const bookEntry = await Self.app.models.XDiario.find({
+ where: {
+ SERIE: invoiceOut.ref[0],
+ FACTURA: invoiceOut.miCadena.slice(1)
+ }
+ }, myOptions);
const promises = [];
for (let ticket of tickets)
@@ -47,6 +51,20 @@ module.exports = Self => {
await invoiceOut.destroy(myOptions);
+ if (bookEntry) {
+ const params = {
+ bookEntries: bookEntry.ASIEN,
+ invoiceOutRef: invoiceOut.ref
+ };
+
+ await Self.rawSql('SELECT util.notification_send(?, ?, NULL)',
+ 'book-entry-deleted',
+ params,
+ myOptions);
+
+ await bookEntry.destroy(myOptions);
+ }
+
if (tx) await tx.commit();
return tickets;
diff --git a/print/templates/email/book-entry-deleted/assets/css/import.js b/print/templates/email/book-entry-deleted/assets/css/import.js
new file mode 100644
index 000000000..1582b82c5
--- /dev/null
+++ b/print/templates/email/book-entry-deleted/assets/css/import.js
@@ -0,0 +1,12 @@
+const Stylesheet = require(`vn-print/core/stylesheet`);
+
+const path = require('path');
+const vnPrintPath = path.resolve('print');
+
+module.exports = new Stylesheet([
+ `${vnPrintPath}/common/css/spacing.css`,
+ `${vnPrintPath}/common/css/misc.css`,
+ `${vnPrintPath}/common/css/layout.css`,
+ `${vnPrintPath}/common/css/email.css`])
+ .mergeStyles();
+
diff --git a/print/templates/email/book-entry-deleted/book-entry-deleted.html b/print/templates/email/book-entry-deleted/book-entry-deleted.html
new file mode 100644
index 000000000..9a9f2a93e
--- /dev/null
+++ b/print/templates/email/book-entry-deleted/book-entry-deleted.html
@@ -0,0 +1,8 @@
+
+
+
diff --git a/print/templates/email/book-entry-deleted/book-entry-deleted.js b/print/templates/email/book-entry-deleted/book-entry-deleted.js
new file mode 100644
index 000000000..f7e7ffab4
--- /dev/null
+++ b/print/templates/email/book-entry-deleted/book-entry-deleted.js
@@ -0,0 +1,19 @@
+const Component = require(`vn-print/core/component`);
+const emailBody = new Component();
+
+module.exports = {
+ name: 'book-entries-deleted',
+ components: {
+ 'email-body': emailBody.build(),
+ },
+ props: {
+ bookEntries: {
+ type: Number,
+ required: true
+ },
+ invoiceOutRef: {
+ type: String,
+ required: true
+ }
+ }
+};
diff --git a/print/templates/email/book-entry-deleted/locale/en.yml b/print/templates/email/book-entry-deleted/locale/en.yml
new file mode 100644
index 000000000..c7408f114
--- /dev/null
+++ b/print/templates/email/book-entry-deleted/locale/en.yml
@@ -0,0 +1,5 @@
+Subject: Linked Accounting Entry Deleted
+Title: Linked Accounting Entry Deleted
+Description: The linked accounting entry that was associated with SAGE has been deleted.
+Entry No. {0}
+This entry has been deleted because the associated invoice {0} has been removed.
diff --git a/print/templates/email/book-entry-deleted/locale/es.yml b/print/templates/email/book-entry-deleted/locale/es.yml
new file mode 100644
index 000000000..ff2073b64
--- /dev/null
+++ b/print/templates/email/book-entry-deleted/locale/es.yml
@@ -0,0 +1,5 @@
+subject: Asiento contable enlazado eliminado
+title: Asiento contable enlazado eliminado
+description: Se ha borrado el asiento contable que se encuentraba enlazado a SAGE
+ Asientos nÂș {0}
+ Este asiento se ha borrado porque se ha eliminado la factura asociada {0}