diff --git a/db/versions/11065-yellowChrysanthemum/00-modifyInvoiceInPrivileges.sql b/db/versions/11065-yellowChrysanthemum/00-modifyInvoiceInPrivileges.sql
new file mode 100644
index 000000000..b65ca1c17
--- /dev/null
+++ b/db/versions/11065-yellowChrysanthemum/00-modifyInvoiceInPrivileges.sql
@@ -0,0 +1,24 @@
+REVOKE UPDATE ON vn. invoiceIn FROM administrative, hrBoss, buyer, logistic;
+GRANT UPDATE (id,
+ serialNumber,
+ serial,
+ supplierFk,
+ issued,
+ supplierRef,
+ currencyFk,
+ created,
+ companyFk,
+ docFk,
+ booked,
+ operated,
+ siiTypeInvoiceInFk,
+ cplusRectificationTypeFk,
+ cplusSubjectOpFk,
+ cplusTaxBreakFk,
+ siiTrascendencyInvoiceInFk,
+ bookEntried,
+ isVatDeductible,
+ withholdingSageFk,
+ expenseFkDeductible,
+ editorFk
+) ON vn.invoiceIn TO administrative, hrBoss, buyer, logistic;
\ No newline at end of file
diff --git a/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql b/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql
new file mode 100644
index 000000000..5475b70ac
--- /dev/null
+++ b/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql
@@ -0,0 +1,23 @@
+UPDATE salix.ACL
+ SET accessType = 'READ'
+ WHERE principalId IN ('administrative','buyer')
+ AND model = 'invoiceIn'
+ AND property = '*';
+
+INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
+VALUES
+ ('InvoiceIn', 'updateInvoiceIn', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
+ ('InvoiceIn', 'clone', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
+ ('InvoiceIn', 'corrective', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
+ ('InvoiceIn', 'exchangeRateUpdate', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
+ ('InvoiceIn', 'invoiceInEmail', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
+ ('InvoiceIn', 'toBook', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
+ ('InvoiceIn', 'toUnbook', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
+ ('InvoiceIn', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
+ ('InvoiceIn', 'updateInvoiceIn', 'WRITE', 'ALLOW', 'ROLE', 'buyer'),
+ ('InvoiceIn', 'clone', 'WRITE', 'ALLOW', 'ROLE', 'buyer'),
+ ('InvoiceIn', 'corrective', 'WRITE', 'ALLOW', 'ROLE', 'buyer'),
+ ('InvoiceIn', 'exchangeRateUpdate', 'WRITE', 'ALLOW', 'ROLE', 'buyer'),
+ ('InvoiceIn', 'invoiceInEmail', 'WRITE', 'ALLOW', 'ROLE', 'buyer'),
+ ('InvoiceIn', 'toBook', 'WRITE', 'ALLOW', 'ROLE', 'buyer'),
+ ('InvoiceIn', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'buyer');
diff --git a/modules/client/back/models/XDiario.json b/modules/client/back/models/XDiario.json
index be543393d..5c277783a 100644
--- a/modules/client/back/models/XDiario.json
+++ b/modules/client/back/models/XDiario.json
@@ -76,7 +76,16 @@
},
"enlazadoSage": {
"type": "boolean"
- }
+ },
+ "enlazado": {
+ "type": "boolean"
+ },
+ "key": {
+ "type": "number",
+ "mysql": {
+ "columnName": "CLAVE"
+ }
+ }
},
"relations": {
"company": {
diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/toUnbook.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/toUnbook.spec.js
new file mode 100644
index 000000000..b7d98e307
--- /dev/null
+++ b/modules/invoiceIn/back/methods/invoice-in/specs/toUnbook.spec.js
@@ -0,0 +1,32 @@
+const models = require('vn-loopback/server/server').models;
+
+describe('invoiceIn toUnbook()', () => {
+ it('should check that invoiceIn is unbooked', async() => {
+ const userId = 1;
+ const ctx = {
+ req: {
+
+ accessToken: {userId: userId},
+ headers: {origin: 'http://localhost:5000'},
+ }
+ };
+ const invoiceInId = 1;
+ const tx = await models.InvoiceIn.beginTransaction({});
+ const options = {transaction: tx};
+
+ try {
+ await models.InvoiceIn.toBook(ctx, invoiceInId, options);
+ const bookEntry = await models.InvoiceIn.toUnbook(ctx, invoiceInId, options);
+ const invoiceIn = await models.InvoiceIn.findById(invoiceInId, null, options);
+
+ expect(bookEntry.accountingEntries).toEqual(4);
+ expect(bookEntry.isLinked).toBeFalsy();
+ expect(invoiceIn.isBooked).toEqual(false);
+
+ await tx.rollback();
+ } catch (e) {
+ await tx.rollback();
+ throw e;
+ }
+ });
+});
diff --git a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js
new file mode 100644
index 000000000..a697e9ddc
--- /dev/null
+++ b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js
@@ -0,0 +1,80 @@
+module.exports = Self => {
+ Self.remoteMethodCtx('toUnbook', {
+ description: 'To unbook the invoiceIn',
+ accessType: 'WRITE',
+ accepts: {
+ arg: 'id',
+ type: 'number',
+ required: true,
+ description: 'The invoiceIn id',
+ http: {source: 'path'}
+ },
+ returns: {
+ type: 'object',
+ root: true
+ },
+ http: {
+ path: '/:id/toUnbook',
+ verb: 'POST'
+ }
+ });
+
+ Self.toUnbook = async(ctx, invoiceInId, options) => {
+ let tx;
+ const models = Self.app.models;
+ const myOptions = {userId: ctx.req.accessToken.userId};
+
+ if (typeof options == 'object')
+ Object.assign(myOptions, options);
+
+ if (!myOptions.transaction) {
+ tx = await Self.beginTransaction({});
+ myOptions.transaction = tx;
+ }
+
+ try {
+ let isLinked;
+ let accountingEntries;
+
+ let bookEntry = await models.Xdiario.findOne({
+ fields: ['ASIEN'],
+ where: {
+ and: [
+ {key: invoiceInId},
+ {enlazado: false},
+ {enlazadoSage: false}
+ ]
+ }
+ }, myOptions);
+
+ let asien = bookEntry?.ASIEN;
+ if (asien) {
+ accountingEntries = await models.Xdiario.count({ASIEN: asien}, myOptions);
+
+ await models.Xdiario.destroyAll({ASIEN: asien}, myOptions);
+ await Self.updateAll({id: invoiceInId}, {isBooked: false}, myOptions);
+ } else {
+ const linkedBookEntry = await models.Xdiario.findOne({
+ fields: ['ASIEN'],
+ where: {
+ key: invoiceInId,
+ and: [{or: [{enlazado: true, enlazadoSage: true}]}]
+ }
+ }, myOptions);
+
+ asien = linkedBookEntry?.ASIEN;
+ isLinked = true;
+ }
+ if (tx) await tx.commit();
+
+ return {
+ isLinked,
+ bookEntry: asien,
+ accountingEntries
+ };
+ } catch (e) {
+ if (tx) await tx.rollback();
+ throw e;
+ }
+ };
+};
diff --git a/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js
new file mode 100644
index 000000000..92a1ba8ee
--- /dev/null
+++ b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js
@@ -0,0 +1,104 @@
+module.exports = Self => {
+ Self.remoteMethodCtx('updateInvoiceIn', {
+ description: 'To update the invoiceIn attributes',
+ accessType: 'WRITE',
+ accepts: [{
+ arg: 'id',
+ type: 'number',
+ required: true,
+ description: 'The invoiceIn id',
+ http: {source: 'path'}
+ }, {
+ arg: 'supplierFk',
+ type: 'number',
+ required: true
+ }, {
+ arg: 'supplierRef',
+ type: 'any',
+ }, {
+ arg: 'issued',
+ type: 'any',
+ }, {
+ arg: 'operated',
+ type: 'any',
+ }, {
+ arg: 'deductibleExpenseFk',
+ type: 'any',
+ }, {
+ arg: 'dmsFk',
+ type: 'any',
+ }, {
+ arg: 'bookEntried',
+ type: 'any',
+ }, {
+ arg: 'booked',
+ type: 'any',
+ }, {
+ arg: 'currencyFk',
+ type: 'number',
+ required: true
+ }, {
+ arg: 'companyFk',
+ type: 'any',
+ }, {
+ arg: 'withholdingSageFk',
+ type: 'any',
+ },
+ ],
+ returns: {
+ type: 'object',
+ root: true
+ },
+ http: {
+ path: '/:id/updateInvoiceIn',
+ verb: 'PATCH'
+ }
+ });
+
+ Self.updateInvoiceIn = async(ctx,
+ id,
+ supplierFk,
+ supplierRef,
+ issued,
+ operated,
+ deductibleExpenseFk,
+ dmsFk,
+ bookEntried,
+ booked,
+ currencyFk,
+ companyFk,
+ withholdingSageFk,
+ options
+ ) => {
+ let tx;
+ const myOptions = {userId: ctx.req.accessToken.userId};
+
+ if (typeof options == 'object') Object.assign(myOptions, options);
+
+ if (!myOptions.transaction) {
+ tx = await Self.beginTransaction({});
+ myOptions.transaction = tx;
+ }
+
+ try {
+ const invoiceIn = await Self.findById(id, null, myOptions);
+ invoiceIn.updateAttributes({supplierFk,
+ supplierRef,
+ issued,
+ operated,
+ deductibleExpenseFk,
+ dmsFk,
+ bookEntried,
+ booked,
+ currencyFk,
+ companyFk,
+ withholdingSageFk
+ }, myOptions);
+ if (tx) await tx.commit();
+ return invoiceIn;
+ } catch (e) {
+ if (tx) await tx.rollback();
+ throw e;
+ }
+ };
+};
diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js
index 31cdc1abe..1e69c0ef8 100644
--- a/modules/invoiceIn/back/models/invoice-in.js
+++ b/modules/invoiceIn/back/models/invoice-in.js
@@ -11,6 +11,8 @@ module.exports = Self => {
require('../methods/invoice-in/getSerial')(Self);
require('../methods/invoice-in/corrective')(Self);
require('../methods/invoice-in/exchangeRateUpdate')(Self);
+ require('../methods/invoice-in/toUnbook')(Self);
+ require('../methods/invoice-in/updateInvoiceIn')(Self);
Self.rewriteDbError(function(err) {
if (err.code === 'ER_ROW_IS_REFERENCED_2' && err.sqlMessage.includes('vehicleInvoiceIn'))
diff --git a/modules/invoiceIn/front/basic-data/index.html b/modules/invoiceIn/front/basic-data/index.html
index a22abbb33..fbb9b05a2 100644
--- a/modules/invoiceIn/front/basic-data/index.html
+++ b/modules/invoiceIn/front/basic-data/index.html
@@ -1,4 +1,4 @@
-
+