UNPKG

kpiplus

Version:

KPI+

1 lines 904 B
var async=require("async"),underscore=require("underscore"),stp=require("stp-utils"),controller=require("../../controllers/controllerRPT");module.exports=function(r){new controller(r,"search",function(r,e){if(!r.query.collections)return e("Báo cáo này yêu cầu các tham số: collections,value");var n=[],o=stp.parse("{"+r.query.collections+"}"),c=underscore.keys(o);async.map(c,function(e,c){var t=e;"dmkh"==e&&(t="customer"),"dmtk"==e&&(t="account"),"dmnt"==e&&(t="currency");var u=require("../../models/"+t),i={id_app:r.query.id_app,$or:[]};o[e].split(",").forEach(function(e){var n={};n[e]={$regex:r.query.value,$options:"i"},i.$or.push(n)}),u.find(i).lean().exec(function(r,o){if(r)return c(r);var t;o.forEach(function(r){if(!t)for(var o in r)if("title"==o||0===o.indexOf("ten_")){t=o;break}r.collection_name=e,r.title=r[t],n.push(r)}),c(null)})},function(r,o){if(r)return e(r);e(null,n)})})};