feat: refs #8077 defaulter filter #3103
|
@ -18,6 +18,11 @@ module.exports = Self => {
|
|||
arg: 'search',
|
||||
type: 'string',
|
||||
description: `If it's and integer searchs by id, otherwise it searchs by name`
|
||||
},
|
||||
{
|
||||
arg: 'sumAmount',
|
||||
type: 'boolean',
|
||||
description: ``
|
||||
robert marked this conversation as resolved
Outdated
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
|
@ -28,6 +33,7 @@ module.exports = Self => {
|
|||
path: `/filter`,
|
||||
verb: 'GET'
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Self.filter = async(ctx, filter, options) => {
|
||||
|
@ -50,14 +56,7 @@ module.exports = Self => {
|
|||
filter = mergeFilters(ctx.args.filter, {where});
|
||||
|
||||
const stmts = [];
|
||||
|
||||
const date = Date.vnNew();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const stmt = new ParameterizedSQL(
|
||||
`SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
DISTINCT c.id clientFk,
|
||||
const fields = ctx.args.sumAmount ? 'sum(d.amount) sumAmount' : ` DISTINCT c.id clientFk,
|
||||
c.name clientName,
|
||||
c.salesPersonFk,
|
||||
c.businessTypeFk = 'worker' isWorker,
|
||||
|
@ -74,7 +73,14 @@ module.exports = Self => {
|
|||
pm.name payMethod,
|
||||
r.finished IS NULL hasRecovery,
|
||||
dp.id departmentFk,
|
||||
dp.name departmentName
|
||||
dp.name departmentName`;
|
||||
const date = Date.vnNew();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const stmt = new ParameterizedSQL(
|
||||
`SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
${fields}
|
||||
FROM defaulter d
|
||||
JOIN client c ON c.id = d.clientFk
|
||||
JOIN country cn ON cn.id = c.countryFk
|
||||
|
@ -101,7 +107,7 @@ module.exports = Self => {
|
|||
, [date]);
|
||||
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
stmt.merge(`GROUP BY d.clientFk`);
|
||||
!ctx.args.sumAmount && stmt.merge(`GROUP BY d.clientFk`);
|
||||
stmt.merge(conn.makeOrderBy(filter.order));
|
||||
stmt.merge(conn.makeLimit(filter));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
si nohi ha descripcio llevau, pero intenta posar algo descriptiu