2023-12-26 13:36:58 +00:00
|
|
|
module.exports = Self => {
|
2023-12-28 14:55:11 +00:00
|
|
|
Self.remoteMethodCtx('corrective', {
|
2023-12-26 13:36:58 +00:00
|
|
|
description: 'Creates a rectificated invoice in',
|
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'id',
|
|
|
|
type: 'number'
|
|
|
|
}, {
|
|
|
|
arg: 'invoiceReason',
|
2023-12-28 14:55:11 +00:00
|
|
|
type: 'number',
|
2023-12-26 13:36:58 +00:00
|
|
|
}, {
|
|
|
|
arg: 'invoiceType',
|
2023-12-28 14:55:11 +00:00
|
|
|
type: 'number',
|
2023-12-26 13:36:58 +00:00
|
|
|
}, {
|
|
|
|
arg: 'invoiceClass',
|
2023-12-28 14:55:11 +00:00
|
|
|
type: 'number'
|
2023-12-26 13:36:58 +00:00
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'number',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
2023-12-28 14:55:11 +00:00
|
|
|
path: '/corrective',
|
2023-12-26 13:36:58 +00:00
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-12-28 14:55:11 +00:00
|
|
|
Self.corrective = async(ctx, id, invoiceReason, invoiceType, invoiceClass, options) => {
|
2023-12-26 13:36:58 +00:00
|
|
|
const models = Self.app.models;
|
|
|
|
const myOptions = {};
|
|
|
|
let tx;
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
|
|
|
if (!myOptions.transaction) {
|
|
|
|
tx = await Self.beginTransaction({});
|
|
|
|
myOptions.transaction = tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const clone = await Self.clone(ctx, id, true, myOptions);
|
|
|
|
await models.InvoiceInCorrection.create({
|
2023-12-28 14:55:11 +00:00
|
|
|
correctingFk: clone.id,
|
|
|
|
correctedFk: id,
|
|
|
|
cplusRectificationTypeFk: invoiceType,
|
2023-12-26 13:36:58 +00:00
|
|
|
siiTypeInvoiceOutFk: invoiceClass,
|
2023-12-28 14:55:11 +00:00
|
|
|
invoiceCorrectionTypeFk: invoiceReason
|
2023-12-26 13:36:58 +00:00
|
|
|
}, myOptions);
|
|
|
|
|
|
|
|
if (tx) await tx.commit();
|
|
|
|
return clone.id;
|
|
|
|
} catch (e) {
|
|
|
|
if (tx) await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|