This commit is contained in:
parent
dd02a932ef
commit
1e3a7e5f91
|
@ -0,0 +1,7 @@
|
|||
ALTER TABLE `vn`.`invoiceCorrection` DROP FOREIGN KEY `cplusInvoiceTyoeFk`;
|
||||
ALTER TABLE `vn`.`invoiceCorrection` DROP FOREIGN KEY `invoiceCorrectionType_Fk33`;
|
||||
ALTER TABLE `vn`.`invoiceCorrection` DROP FOREIGN KEY `invoiceCorrection_ibfk_1`;
|
||||
|
||||
ALTER TABLE `vn`.`invoiceCorrection` ADD CONSTRAINT `siiTypeInvoiceOut_FK` FOREIGN KEY (`siiTypeInvoiceOutFk`) REFERENCES `vn`.`siiTypeInvoiceOut`(id) ON UPDATE CASCADE;
|
||||
ALTER TABLE `vn`.`invoiceCorrection` ADD CONSTRAINT `invoiceCorrectionType_FK` FOREIGN KEY (`invoiceCorrectionTypeFk`) REFERENCES `vn`.`invoiceCorrectionType`(id) ON UPDATE CASCADE;
|
||||
ALTER TABLE `vn`.`invoiceCorrection` ADD CONSTRAINT `cplusRectificationType_FK` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `vn`.`cplusRectificationType`(id) ON UPDATE CASCADE;
|
|
@ -14,7 +14,7 @@ BEGIN
|
|||
|
||||
CALL getTaxBases();
|
||||
|
||||
SELECT positive > 0 INTO hasAnyPositiveBase
|
||||
SELECT positive INTO hasAnyPositiveBase
|
||||
FROM tmp.taxBases;
|
||||
|
||||
DROP TEMPORARY TABLE
|
|
@ -14,7 +14,7 @@ BEGIN
|
|||
|
||||
CALL getTaxBases();
|
||||
|
||||
SELECT negative > 0 INTO hasAnyNegativeBase
|
||||
SELECT negative INTO hasAnyNegativeBase
|
||||
FROM tmp.taxBases;
|
||||
|
||||
DROP TEMPORARY TABLE
|
|
@ -26,6 +26,33 @@
|
|||
"invoiceCorrectionTypeFk": {
|
||||
"type": "number",
|
||||
"required": true
|
||||
},
|
||||
"relations": {
|
||||
"correcting": {
|
||||
"type": "belongsTo",
|
||||
"model": "InvoiceOut",
|
||||
"foreignKey": "correctingFk"
|
||||
},
|
||||
"corrected": {
|
||||
"type": "belongsTo",
|
||||
"model": "InvoiceOut",
|
||||
"foreignKey": "correctedFk"
|
||||
},
|
||||
"cplusRectificationType": {
|
||||
"type": "belongsTo",
|
||||
"model": "cplusRectificationType",
|
||||
"foreignKey": "cplusRectificationTypeFk"
|
||||
},
|
||||
"siiTypeInvoiceOut": {
|
||||
"type": "belongsTo",
|
||||
"model": "siiTypeInvoiceOut",
|
||||
"foreignKey": "siiTypeInvoiceOutFk"
|
||||
},
|
||||
"invoiceCorrectionType": {
|
||||
"type": "belongsTo",
|
||||
"model": "invoiceCorrectionType",
|
||||
"foreignKey": "invoiceCorrectionTypeFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,11 +17,6 @@ module.exports = function(Self) {
|
|||
type: 'boolean'
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
arg: 'data',
|
||||
type: 'boolean',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/canBeInvoiced`,
|
||||
verb: 'get'
|
||||
|
@ -63,7 +58,5 @@ module.exports = function(Self) {
|
|||
if (ticketsIds.length == 1 && priceZero)
|
||||
throw new UserError(`A ticket with an amount of zero can't be invoiced`);
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -61,20 +61,19 @@ module.exports = function(Self) {
|
|||
if (!isSameClient)
|
||||
throw new UserError(`You can't invoice tickets from multiple clients`);
|
||||
|
||||
const client = await models.Client.findById(clientId, {
|
||||
fields: ['id', 'hasToInvoiceByAddress']
|
||||
const {hasToInvoiceByAddress} = await models.Client.findById(clientId, {
|
||||
fields: ['hasToInvoiceByAddress']
|
||||
}, myOptions);
|
||||
|
||||
let ticketsByAddress = {[firstTicket.addressFk]: ticketsIds};
|
||||
if (client.hasToInvoiceByAddress) {
|
||||
ticketsByAddress = tickets.reduce((group, ticket) => {
|
||||
const {addressFk} = ticket;
|
||||
let ticketsByAddress = hasToInvoiceByAddress
|
||||
? Object.values(tickets.reduce((group, {id, addressFk}) => {
|
||||
group[addressFk] = group[addressFk] ?? [];
|
||||
group[addressFk].push(ticket.id);
|
||||
group[addressFk].push(id);
|
||||
return group;
|
||||
}, {});
|
||||
}
|
||||
for (const ticketIds of Object.values(ticketsByAddress))
|
||||
}, {}))
|
||||
: [[ticketsIds]];
|
||||
|
||||
for (const ticketIds of ticketsByAddress)
|
||||
invoicesIds.push(await createInvoice(ctx, companyId, ticketIds, invoiceCorrection, myOptions));
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
|
|
@ -106,7 +106,6 @@ module.exports = function(Self) {
|
|||
);
|
||||
}
|
||||
|
||||
if (resultInvoice.id)
|
||||
await Self.rawSql('CALL invoiceOutBooking(?)', [resultInvoice.id], myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
|
|
@ -27,10 +27,7 @@ describe('ticket canBeInvoiced()', () => {
|
|||
WHERE id IN (?)
|
||||
`, [ticketId], options);
|
||||
|
||||
const canBeInvoiced = await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
||||
|
||||
expect(canBeInvoiced).toEqual(false);
|
||||
|
||||
await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
|
@ -59,10 +56,7 @@ describe('ticket canBeInvoiced()', () => {
|
|||
WHERE id IN (?)
|
||||
`, [ticketId], options);
|
||||
|
||||
const canBeInvoiced = await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
||||
|
||||
expect(canBeInvoiced).toEqual(false);
|
||||
|
||||
await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
|
@ -95,10 +89,7 @@ describe('ticket canBeInvoiced()', () => {
|
|||
WHERE id IN (?)
|
||||
`, [ticketId], options);
|
||||
|
||||
const canBeInvoiced = await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
||||
|
||||
expect(canBeInvoiced).toEqual(false);
|
||||
|
||||
await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
|
@ -123,10 +114,7 @@ describe('ticket canBeInvoiced()', () => {
|
|||
WHERE id IN (?)
|
||||
`, [ticketId], options);
|
||||
|
||||
const canBeInvoiced = await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
||||
|
||||
expect(canBeInvoiced).toEqual(true);
|
||||
|
||||
await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
|
|
Loading…
Reference in New Issue