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