diff --git a/db/dump/dumpedFixtures.sql b/db/dump/dumpedFixtures.sql
index 43eba7f24..5e3438dbf 100644
--- a/db/dump/dumpedFixtures.sql
+++ b/db/dump/dumpedFixtures.sql
@@ -280,7 +280,18 @@ UNLOCK TABLES;
LOCK TABLES `siiTypeInvoiceOut` WRITE;
/*!40000 ALTER TABLE `siiTypeInvoiceOut` DISABLE KEYS */;
-INSERT INTO `siiTypeInvoiceOut` VALUES (1,'F1 - Factura'),(2,'F2 - Factura simplificada (ticket)'),(3,'F3 - Factura emitida en sustitución de facturas simplificadas facturadas y declaradas'),(4,'F4 - Asiento resumen de facturas'),(5,'R1 - Factura rectificativa (Art. 80.1, 80.2 y error fundado en derecho)'),(6,'R2 - Factura rectificativa (Art. 80.3)'),(7,'R3 - Factura rectificativa (Art. 80.4)'),(8,'R4 - Factura rectificativa (Resto)'),(9,'R5 - Factura rectificativa en facturas simplificadas');
+
+INSERT INTO `siiTypeInvoiceOut` (id, code, description) VALUES
+ (1, 'F1', 'Factura'),
+ (2, 'F2', 'Factura simplificada (ticket)'),
+ (3, 'F3', 'Factura emitida en sustitución de facturas simplificadas facturadas y declaradas'),
+ (4, 'F4', 'Asiento resumen de facturas'),
+ (5, 'R1', 'Factura rectificativa (Art. 80.1, 80.2 y error fundado en derecho)'),
+ (6, 'R2', 'Factura rectificativa (Art. 80.3)'),
+ (7, 'R3', 'Factura rectificativa (Art. 80.4)'),
+ (8, 'R4', 'Factura rectificativa (Resto)'),
+ (9, 'R5', 'Factura rectificativa en facturas simplificadas');
+
/*!40000 ALTER TABLE `siiTypeInvoiceOut` ENABLE KEYS */;
UNLOCK TABLES;
diff --git a/db/dump/structure.sql b/db/dump/structure.sql
index 3dab0c5a4..2eecf6c30 100644
--- a/db/dump/structure.sql
+++ b/db/dump/structure.sql
@@ -26001,9 +26001,11 @@ DROP TABLE IF EXISTS `siiTypeInvoiceOut`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `siiTypeInvoiceOut` (
`id` int(10) unsigned NOT NULL,
+ `code` varchar(2) NOT NULL,
`description` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='(*18) TIPO FACTURA (Asientos)REPERCUTIDO - DEVENGADO (477)';
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `code_UNIQUE` (`code`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tipo de Factura Emitidas en el suministro de inmediato';
/*!40101 SET character_set_client = @saved_cs_client */;
--
diff --git a/loopback/locale/es.json b/loopback/locale/es.json
index 239faff34..0dcbe0dc2 100644
--- a/loopback/locale/es.json
+++ b/loopback/locale/es.json
@@ -326,5 +326,16 @@
"The notification subscription of this worker cant be modified": "La subscripción a la notificación de este trabajador no puede ser modificada",
"User disabled": "Usuario desactivado",
"The amount cannot be less than the minimum": "La cantidad no puede ser menor que la cantidad mínima",
- "quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mínima"
-}
+ "quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mínima",
+ "Base negativa para los tickets: 65": "Base negativa para los tickets: 65",
+ "Base negativa para los tickets: 67": "Base negativa para los tickets: 67",
+ "Base negativa para los tickets: 70": "Base negativa para los tickets: 70",
+ "Base negativa para los tickets: 72": "Base negativa para los tickets: 72",
+ "Base negativa para los tickets: 74": "Base negativa para los tickets: 74",
+ "Base negativa para los tickets: 33": "Base negativa para los tickets: 33",
+ "Base negativa para los tickets: 35": "Base negativa para los tickets: 35",
+ "Base negativa para los tickets: 37": "Base negativa para los tickets: 37",
+ "Base negativa para los tickets: 39": "Base negativa para los tickets: 39",
+ "Base negativa para los tickets: 41": "Base negativa para los tickets: 41",
+ "Base negativa para los tickets: 43": "Base negativa para los tickets: 43"
+}
\ No newline at end of file
diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js
index 800a4ea83..dea4b6d00 100644
--- a/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js
+++ b/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js
@@ -24,7 +24,7 @@ describe('InvoiceOut tranferInvoice()', () => {
const options = {transaction: tx};
const args = {
id: '1',
- ref: 'T4444444',
+ refFk: 'T4444444',
newClientFk: 1,
cplusRectificationId: 1,
siiTypeInvoiceOutId: 1,
@@ -49,7 +49,7 @@ describe('InvoiceOut tranferInvoice()', () => {
const options = {transaction: tx};
const args = {
id: '1',
- ref: 'T1111111',
+ refFk: 'T1111111',
newClientFk: 1101,
cplusRectificationId: 1,
siiTypeInvoiceOutId: 1,
diff --git a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js
index dde535c99..dcdd9b9b1 100644
--- a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js
+++ b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js
@@ -12,7 +12,7 @@ module.exports = Self => {
description: 'Issued invoice id'
},
{
- arg: 'ref',
+ arg: 'refFk',
type: 'string',
required: true
},
@@ -22,17 +22,17 @@ module.exports = Self => {
required: true
},
{
- arg: 'cplusRectificationId',
+ arg: 'cplusRectificationFk',
type: 'number',
required: true
},
{
- arg: 'siiTypeInvoiceOutId',
+ arg: 'siiTypeInvoiceOutFk',
type: 'number',
required: true
},
{
- arg: 'invoiceCorrectionTypeId',
+ arg: 'invoiceCorrectionTypeFk',
type: 'number',
required: true
},
@@ -50,14 +50,14 @@ module.exports = Self => {
Self.transferInvoice = async(ctx, options) => {
const models = Self.app.models;
const myOptions = {userId: ctx.req.accessToken.userId};
- const args = ctx.args;
+ const {id, refFk, newClientFk, cplusRectificationFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk} = ctx.args;
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
- const {clientFk} = await models.InvoiceOut.findById(args.id);
+ const {clientFk} = await models.InvoiceOut.findById(id);
- if (clientFk == args.newClientFk)
+ if (clientFk == newClientFk)
throw new UserError(`Select a different client`);
if (!myOptions.transaction) {
@@ -65,10 +65,10 @@ module.exports = Self => {
myOptions.transaction = tx;
}
try {
- const filterRef = {where: {refFk: args.ref}};
+ const filterRef = {where: {refFk: refFk}};
const tickets = await models.Ticket.find(filterRef, myOptions);
const ticketsIds = tickets.map(ticket => ticket.id);
- await models.Ticket.refund(ctx, ticketsIds, null, myOptions);
+ const refundTickets = await models.Ticket.refund(ctx, ticketsIds, null, myOptions);
const filterTicket = {where: {ticketFk: {inq: ticketsIds}}};
@@ -82,20 +82,16 @@ module.exports = Self => {
const clonedTicketIds = [];
for (const clonedTicket of clonedTickets) {
- await clonedTicket.updateAttribute('clientFk', args.newClientFk, myOptions);
+ await clonedTicket.updateAttribute('clientFk', newClientFk, myOptions);
clonedTicketIds.push(clonedTicket.id);
}
- const invoiceIds = await models.Ticket.invoiceTickets(ctx, clonedTicketIds, myOptions);
- const [invoiceId] = invoiceIds;
+ const invoiceCorrection =
+ {correctedFk: id, cplusRectificationFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk};
+ const refundTicketIds = refundTickets.map(ticket => ticket.id);
- await models.InvoiceCorrection.create({
- correctingFk: invoiceId,
- correctedFk: args.id,
- cplusRectificationTypeFk: args.cplusRectificationId,
- siiTypeInvoiceOutFk: args.siiTypeInvoiceOutId,
- invoiceCorrectionTypeFk: args.invoiceCorrectionTypeId
- }, myOptions);
+ await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions);
+ const [[invoiceId]] = await models.Ticket.invoiceTickets(ctx, clonedTicketIds, myOptions);
if (tx) {
await tx.commit();
diff --git a/modules/invoiceOut/back/models/invoice-correction.json b/modules/invoiceOut/back/models/invoice-correction.json
index 43e4f07ef..5924c9232 100644
--- a/modules/invoiceOut/back/models/invoice-correction.json
+++ b/modules/invoiceOut/back/models/invoice-correction.json
@@ -16,13 +16,16 @@
"type": "number"
},
"cplusRectificationTypeFk": {
- "type": "number"
+ "type": "number",
+ "required": true
},
"siiTypeInvoiceOutFk": {
- "type": "number"
+ "type": "number",
+ "required": true
},
"invoiceCorrectionTypeFk": {
- "type": "number"
+ "type": "number",
+ "required": true
}
}
}
diff --git a/modules/invoiceOut/back/models/cplus-invoice-type-477.json b/modules/invoiceOut/back/models/sii-type-invoice-out.json
similarity index 86%
rename from modules/invoiceOut/back/models/cplus-invoice-type-477.json
rename to modules/invoiceOut/back/models/sii-type-invoice-out.json
index 17b312617..58d50a12c 100644
--- a/modules/invoiceOut/back/models/cplus-invoice-type-477.json
+++ b/modules/invoiceOut/back/models/sii-type-invoice-out.json
@@ -12,6 +12,9 @@
"type": "number",
"description": "Identifier"
},
+ "code": {
+ "type": "string"
+ },
"description": {
"type": "string"
}
diff --git a/modules/invoiceOut/front/descriptor-menu/index.html b/modules/invoiceOut/front/descriptor-menu/index.html
index 0052f0c03..267aa0b15 100644
--- a/modules/invoiceOut/front/descriptor-menu/index.html
+++ b/modules/invoiceOut/front/descriptor-menu/index.html
@@ -7,7 +7,8 @@
+ data="siiTypeInvoiceOuts"
+ where="{code: {like: 'R%'}}">
+
+ transferInvoice
+
-
-
-
- #{{id}} - {{::name}}
-
-
-
-
- {{::description}}
-
-
-
-
-
-
-
-
-
-
+
+
+
+ #{{id}} - {{::name}}
+
+
+
+
+ {{::description}}
+
+
+
+
+
+
+ {{::code}} - {{::description}}
+
+
+
+
+
+
diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js
index d3862a753..f9d436092 100644
--- a/modules/invoiceOut/front/descriptor-menu/index.js
+++ b/modules/invoiceOut/front/descriptor-menu/index.js
@@ -129,11 +129,11 @@ class Controller extends Section {
transferInvoice() {
const params = {
id: this.invoiceOut.id,
- ref: this.invoiceOut.ref,
- newClientFk: this.invoiceOut.client.id,
- cplusRectificationId: this.cplusRectificationType,
- siiTypeInvoiceOutId: this.siiTypeInvoiceOut,
- invoiceCorrectionTypeId: this.invoiceCorrectionType
+ refFk: this.invoiceOut.ref,
+ newClientFk: this.clientId,
+ cplusRectificationFk: this.cplusRectificationType,
+ siiTypeInvoiceOutFk: this.siiTypeInvoiceOut,
+ invoiceCorrectionTypeFk: this.invoiceCorrectionType
};
this.$http.post(`InvoiceOuts/transferInvoice`, params).then(res => {
const invoiceId = res.data;
diff --git a/modules/invoiceOut/front/descriptor-menu/locale/es.yml b/modules/invoiceOut/front/descriptor-menu/locale/es.yml
index 0f74b5fec..9456646af 100644
--- a/modules/invoiceOut/front/descriptor-menu/locale/es.yml
+++ b/modules/invoiceOut/front/descriptor-menu/locale/es.yml
@@ -22,4 +22,4 @@ The email can't be empty: El correo no puede estar vacío
The following refund tickets have been created: "Se han creado los siguientes tickets de abono: {{ticketIds}}"
Refund...: Abono...
Transfer invoice to...: Transferir factura a...
-Cplus Type: Cplus Tipo
+Rectificative type: Tipo rectificativa
diff --git a/modules/ticket/back/methods/sale/refund.js b/modules/ticket/back/methods/sale/refund.js
index 17b70f12b..a7831e7e3 100644
--- a/modules/ticket/back/methods/sale/refund.js
+++ b/modules/ticket/back/methods/sale/refund.js
@@ -19,7 +19,7 @@ module.exports = Self => {
}
],
returns: {
- type: ['number'],
+ type: ['object'],
root: true
},
http: {
@@ -54,7 +54,7 @@ module.exports = Self => {
if (tx) await tx.commit();
- return refundsTicket[0];
+ return refundsTicket;
} catch (e) {
if (tx) await tx.rollback();
throw e;
diff --git a/modules/ticket/back/methods/ticket/invoiceTickets.js b/modules/ticket/back/methods/ticket/invoiceTickets.js
index fa3ee93af..29fb1769b 100644
--- a/modules/ticket/back/methods/ticket/invoiceTickets.js
+++ b/modules/ticket/back/methods/ticket/invoiceTickets.js
@@ -10,7 +10,13 @@ module.exports = function(Self) {
description: 'The tickets id',
type: ['number'],
required: true
+ },
+ {
+ arg: 'invoiceCorrection',
+ description: 'The invoice correction',
+ type: 'object',
}
+
],
returns: {
type: ['object'],
@@ -22,7 +28,7 @@ module.exports = function(Self) {
}
});
- Self.invoiceTickets = async(ctx, ticketsIds, options) => {
+ Self.invoiceTickets = async(ctx, ticketsIds, invoiceCorrection, options) => {
const models = Self.app.models;
const date = Date.vnNew();
date.setHours(0, 0, 0, 0);
@@ -68,9 +74,9 @@ module.exports = function(Self) {
const addressIds = result.map(address => address.addressFk);
for (const address of addressIds)
- await createInvoice(ctx, companyId, ticketsIds, address, invoicesIds, myOptions);
+ await createInvoice(ctx, companyId, ticketsIds, address, invoicesIds, invoiceCorrection, myOptions);
} else
- await createInvoice(ctx, companyId, ticketsIds, null, invoicesIds, myOptions);
+ await createInvoice(ctx, companyId, ticketsIds, null, invoicesIds, invoiceCorrection, myOptions);
if (tx) await tx.commit();
} catch (e) {
@@ -85,9 +91,9 @@ module.exports = function(Self) {
return invoicesIds;
};
- async function createInvoice(ctx, companyId, ticketsIds, address, invoicesIds, myOptions) {
+ async function createInvoice(ctx, companyId, ticketsIds, address, invoicesIds, invoiceCorrection, myOptions) {
const models = Self.app.models;
-
+ console.log(ticketsIds, address);
await models.Ticket.rawSql(`
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketToInvoice
(PRIMARY KEY (id))
@@ -98,7 +104,8 @@ module.exports = function(Self) {
${address ? `AND addressFk = ${address}` : ''}
`, [ticketsIds], myOptions);
- const invoiceId = await models.Ticket.makeInvoice(ctx, 'R', companyId, Date.vnNew(), myOptions);
+ const invoiceId =
+ await models.Ticket.makeInvoice(ctx, 'R', companyId, Date.vnNew(), invoiceCorrection, myOptions);
invoicesIds.push(invoiceId);
}
};
diff --git a/modules/ticket/back/methods/ticket/makeInvoice.js b/modules/ticket/back/methods/ticket/makeInvoice.js
index e18e58e0b..9618e49e0 100644
--- a/modules/ticket/back/methods/ticket/makeInvoice.js
+++ b/modules/ticket/back/methods/ticket/makeInvoice.js
@@ -22,6 +22,11 @@ module.exports = function(Self) {
description: 'The invoice date',
type: 'date',
required: true
+ },
+ {
+ arg: 'invoiceCorrection',
+ description: 'The invoice correction',
+ type: 'object',
}
],
returns: {
@@ -34,7 +39,7 @@ module.exports = function(Self) {
}
});
- Self.makeInvoice = async(ctx, invoiceType, companyFk, invoiceDate, options) => {
+ Self.makeInvoice = async(ctx, invoiceType, companyFk, invoiceDate, invoiceCorrection, options) => {
const models = Self.app.models;
invoiceDate.setHours(0, 0, 0, 0);
@@ -67,8 +72,8 @@ module.exports = function(Self) {
const [firstTicket] = tickets;
const clientId = firstTicket.clientFk;
- const clientCanBeInvoiced = await models.Client.canBeInvoiced(clientId, companyFk, myOptions);
- if (!clientCanBeInvoiced)
+ const clientCanBeInvoiced = await models.Client.canBeInvoiced(clientId, companyFk, invoiceCorrection, myOptions);
+ if (!clientCanBeInvoiced && !invoiceCorrection)
throw new UserError(`This client can't be invoiced`);
const query = `SELECT vn.invoiceSerial(?, ?, ?) AS serial`;
@@ -85,6 +90,13 @@ module.exports = function(Self) {
if (!resultInvoice)
throw new UserError('No tickets to invoice', 'notInvoiced');
+ if (invoiceCorrection) {
+ await models.InvoiceCorrection.create(
+ Object.assign(invoiceCorrection, {correctingFk: resultInvoice.id}),
+ myOptions
+ );
+ }
+
if (serial != 'R' && resultInvoice.id)
await Self.rawSql('CALL invoiceOutBooking(?)', [resultInvoice.id], myOptions);
diff --git a/modules/ticket/back/methods/ticket/refund.js b/modules/ticket/back/methods/ticket/refund.js
index 758384ae2..4fed02260 100644
--- a/modules/ticket/back/methods/ticket/refund.js
+++ b/modules/ticket/back/methods/ticket/refund.js
@@ -15,7 +15,7 @@ module.exports = Self => {
}
],
returns: {
- type: ['number'],
+ type: ['object'],
root: true
},
http: {