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();
|
CALL getTaxBases();
|
||||||
|
|
||||||
SELECT positive > 0 INTO hasAnyPositiveBase
|
SELECT positive INTO hasAnyPositiveBase
|
||||||
FROM tmp.taxBases;
|
FROM tmp.taxBases;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE
|
DROP TEMPORARY TABLE
|
|
@ -14,7 +14,7 @@ BEGIN
|
||||||
|
|
||||||
CALL getTaxBases();
|
CALL getTaxBases();
|
||||||
|
|
||||||
SELECT negative > 0 INTO hasAnyNegativeBase
|
SELECT negative INTO hasAnyNegativeBase
|
||||||
FROM tmp.taxBases;
|
FROM tmp.taxBases;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE
|
DROP TEMPORARY TABLE
|
|
@ -26,6 +26,33 @@
|
||||||
"invoiceCorrectionTypeFk": {
|
"invoiceCorrectionTypeFk": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"required": true
|
"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'
|
type: 'boolean'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
|
||||||
arg: 'data',
|
|
||||||
type: 'boolean',
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
http: {
|
||||||
path: `/canBeInvoiced`,
|
path: `/canBeInvoiced`,
|
||||||
verb: 'get'
|
verb: 'get'
|
||||||
|
@ -63,7 +58,5 @@ module.exports = function(Self) {
|
||||||
if (ticketsIds.length == 1 && priceZero)
|
if (ticketsIds.length == 1 && priceZero)
|
||||||
throw new UserError(`A ticket with an amount of zero can't be invoiced`);
|
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)
|
if (!isSameClient)
|
||||||
throw new UserError(`You can't invoice tickets from multiple clients`);
|
throw new UserError(`You can't invoice tickets from multiple clients`);
|
||||||
|
|
||||||
const client = await models.Client.findById(clientId, {
|
const {hasToInvoiceByAddress} = await models.Client.findById(clientId, {
|
||||||
fields: ['id', 'hasToInvoiceByAddress']
|
fields: ['hasToInvoiceByAddress']
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
let ticketsByAddress = {[firstTicket.addressFk]: ticketsIds};
|
let ticketsByAddress = hasToInvoiceByAddress
|
||||||
if (client.hasToInvoiceByAddress) {
|
? Object.values(tickets.reduce((group, {id, addressFk}) => {
|
||||||
ticketsByAddress = tickets.reduce((group, ticket) => {
|
|
||||||
const {addressFk} = ticket;
|
|
||||||
group[addressFk] = group[addressFk] ?? [];
|
group[addressFk] = group[addressFk] ?? [];
|
||||||
group[addressFk].push(ticket.id);
|
group[addressFk].push(id);
|
||||||
return group;
|
return group;
|
||||||
}, {});
|
}, {}))
|
||||||
}
|
: [[ticketsIds]];
|
||||||
for (const ticketIds of Object.values(ticketsByAddress))
|
|
||||||
|
for (const ticketIds of ticketsByAddress)
|
||||||
invoicesIds.push(await createInvoice(ctx, companyId, ticketIds, invoiceCorrection, myOptions));
|
invoicesIds.push(await createInvoice(ctx, companyId, ticketIds, invoiceCorrection, myOptions));
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
|
@ -106,7 +106,6 @@ module.exports = function(Self) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultInvoice.id)
|
|
||||||
await Self.rawSql('CALL invoiceOutBooking(?)', [resultInvoice.id], myOptions);
|
await Self.rawSql('CALL invoiceOutBooking(?)', [resultInvoice.id], myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
|
@ -27,10 +27,7 @@ describe('ticket canBeInvoiced()', () => {
|
||||||
WHERE id IN (?)
|
WHERE id IN (?)
|
||||||
`, [ticketId], options);
|
`, [ticketId], options);
|
||||||
|
|
||||||
const canBeInvoiced = await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
||||||
|
|
||||||
expect(canBeInvoiced).toEqual(false);
|
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
|
@ -59,10 +56,7 @@ describe('ticket canBeInvoiced()', () => {
|
||||||
WHERE id IN (?)
|
WHERE id IN (?)
|
||||||
`, [ticketId], options);
|
`, [ticketId], options);
|
||||||
|
|
||||||
const canBeInvoiced = await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
||||||
|
|
||||||
expect(canBeInvoiced).toEqual(false);
|
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
|
@ -95,10 +89,7 @@ describe('ticket canBeInvoiced()', () => {
|
||||||
WHERE id IN (?)
|
WHERE id IN (?)
|
||||||
`, [ticketId], options);
|
`, [ticketId], options);
|
||||||
|
|
||||||
const canBeInvoiced = await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
||||||
|
|
||||||
expect(canBeInvoiced).toEqual(false);
|
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
|
@ -123,10 +114,7 @@ describe('ticket canBeInvoiced()', () => {
|
||||||
WHERE id IN (?)
|
WHERE id IN (?)
|
||||||
`, [ticketId], options);
|
`, [ticketId], options);
|
||||||
|
|
||||||
const canBeInvoiced = await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
|
||||||
|
|
||||||
expect(canBeInvoiced).toEqual(true);
|
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
|
Loading…
Reference in New Issue