UNPKG

kpiplus

Version:

KPI+

1 lines 2.13 kB
var model=require("../../models/cdkh"),controller=require("../../controllers/controller"),app=require("../../models/app"),customer=require("../../models/customer"),dmkho=require("../../models/dmkho"),dmdt=require("../../models/dmdt"),dmnv=require("../../models/dmnv"),contract=require("../../models/contract"),dmbp=require("../../models/dmbp"),dvcs=require("../../models/dvcs"),dmtk=require("../../models/account"),arrayfuncs=require("../../libs/array-funcs"),async=require("async"),cdkh=function(n){var e=this.contr=new controller(n,model,"cdkh",{sort:{ma_dvcs:1,nam:-1,tk:1},unique:["ma_dvcs","tk","ma_kh","ma_kho","ma_dt","ma_bp","ma_hd","ma_nv","nam"]});e.route(),e.view=function(n,e,r){id_app=n.current_id_app,async.parallel({dv:function(n){e.joinModel2(id_app,dvcs,{where:{ma_dvcs:"_id"},fields:{ten_dvcs:"ten_dvcs"}},function(e){n()})},kh:function(n){e.joinModel2(id_app,customer,{where:"ma_kh",fields:{ten_kh:"ten_kh"}},function(e){n()})},tk:function(n){e.joinModel2(id_app,dmtk,{where:"tk",fields:{ten_tk:"ten_tk"}},function(e){n()})},kho:function(n){e.joinModel2(id_app,dmkho,{where:"ma_kho",fields:{ten_kho:"ten_kho"}},function(e){n()})},dmbp:function(n){e.joinModel2(id_app,dmbp,{where:"ma_bp",fields:{ten_bp:"ten_bp"}},function(e){n()})},dmdt:function(n){e.joinModel2(id_app,dmdt,{where:"ma_dt",fields:{ten_dt:"ten_dt"}},function(e){n()})},contract:function(n){e.joinModel2(id_app,contract,{where:{ma_hd:"so_hd"},fields:{ten_hd:"ten_hd"}},function(e){n()})},nv:function(n){e.joinModel2(id_app,dmnv,{where:"ma_nv",fields:{ten_nv:"ten_nv"}},function(e){n()})}},function(n,d){r(null,e)})},e.updating=function(n,e,r,d){if(e.nam)return d(null,e,r);id_app=n.current_id_app,app.findOne({_id:id_app},function(n,t){if(n)return d(n);if(!t)return d(new Error("Create app before creating cdkh"));var i=t.nam_bd;if(e.nam&&e.nam!=i)return d(new Error("bad request"));d(null,e,r)})},e.creating=function(n,e,r){if(e.nam)return r(null,e);id_app=n.current_id_app,app.findOne({_id:id_app},function(n,d){if(n)return r(n);if(!d)return r(new Error("Create app before creating cdkh"));var t=d.nam_bd;e.nam=t,r(null,e)})}};module.exports=cdkh;