This commit is contained in:
parent
53f37bb0eb
commit
e33861a80d
|
@ -1,4 +1,3 @@
|
|||
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||
|
@ -80,6 +79,11 @@ module.exports = Self => {
|
|||
type: 'boolean',
|
||||
description: 'Whether the invoice is booked or not',
|
||||
},
|
||||
{
|
||||
arg: 'correctedFk',
|
||||
type: 'number',
|
||||
description: 'The corrected invoice',
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
|
@ -93,6 +97,7 @@ module.exports = Self => {
|
|||
|
||||
Self.filter = async(ctx, filter, options) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
|
||||
const myOptions = {};
|
||||
|
@ -105,6 +110,14 @@ module.exports = Self => {
|
|||
dateTo.setHours(23, 59, 0, 0);
|
||||
}
|
||||
|
||||
let correctings;
|
||||
if (args.correctedFk) {
|
||||
correctings = await models.InvoiceInCorrection.find({
|
||||
fields: ['correctingFk'],
|
||||
where: {correctedFk: args.correctedFk}
|
||||
});
|
||||
}
|
||||
|
||||
const where = buildFilter(ctx.args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
|
@ -128,6 +141,8 @@ module.exports = Self => {
|
|||
return {[`ii.${param}`]: value};
|
||||
case 'awbCode':
|
||||
return {'sub.code': value};
|
||||
case 'correctedFk':
|
||||
return {'ii.id': {inq: correctings.map(x => x.correctingFk)}};
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -186,6 +201,7 @@ module.exports = Self => {
|
|||
const itemsIndex = stmts.push(stmt) - 1;
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
console.log(sql);
|
||||
const result = await conn.executeStmt(sql, myOptions);
|
||||
|
||||
return itemsIndex === 0 ? result : result[itemsIndex];
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
"model": "InvoiceCorrectionType",
|
||||
"foreignKey": "invoiceCorrectionTypeFk"
|
||||
},
|
||||
"siiTypeInvoiceOutFk": {
|
||||
"siiTypeInvoiceOut": {
|
||||
"type": "belongsTo",
|
||||
"model": "SiiTypeInvoiceOut",
|
||||
"foreignKey": "siiTypeInvoiceOutFk"
|
||||
|
|
Loading…
Reference in New Issue