UNPKG

flexbiz-server

Version:

Flexible Server

12 lines (11 loc) 5.32 kB
'use strict';const model=global.getModel("cdkh"),controller=require("../../controllers/controller"),customer=global.getModel("customer"),dmkho=global.getModel("dmkho"),dmdt=global.getModel("dmdt"),dmnv=global.getModel("dmnv"),contract=global.getModel("contract"),dmbp=global.getModel("dmbp"),dvcs=global.getModel("dvcs"),dmtk=global.getModel("account"),async=require("async"),moment=require("moment"),utils=require("../../libs/utils"),cdkh=function($contr_router$$){$contr_router$$=new controller($contr_router$$, 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".split(" ")});$contr_router$$.route();$contr_router$$.view=function($user$$,$result$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.series({dv:function($callback$$){$result$$.joinModel2($id_app$$,dvcs,{where:{ma_dvcs:"_id"},fields:{ten_dvcs:"ten_dvcs"}},function(){$callback$$()})},kh:function($callback$$){$result$$.joinModel2($id_app$$,customer,{where:"ma_kh",fields:{ten_kh:"ten_kh"}},function(){$callback$$()})}, tk:function($callback$$){$result$$.joinModel2($id_app$$,dmtk,{where:"tk",fields:["ten_tk","ma_nt"]},function(){$callback$$()})},kho:function($callback$$){$result$$.joinModel2($id_app$$,dmkho,{where:"ma_kho",fields:{ten_kho:"ten_kho"}},function(){$callback$$()})},dmbp:function($callback$$){$result$$.joinModel2($id_app$$,dmbp,{where:"ma_bp",fields:{ten_bp:"ten_bp"}},function(){$callback$$()})},dmdt:function($callback$$){$result$$.joinModel2($id_app$$,dmdt,{where:"ma_dt",fields:{ten_dt:"ten_dt"}},function(){$callback$$()})}, contract:function($callback$$){$result$$.joinModel2($id_app$$,contract,{where:{ma_hd:"so_hd"},fields:{ten_hd:"ten_hd"}},function(){$callback$$()})},nv:function($callback$$){$result$$.joinModel2($id_app$$,dmnv,{where:"ma_nv",fields:{ten_nv:"ten_nv"}},function(){$callback$$()})}},function(){$fn$$(null,$result$$)})};$contr_router$$.updating=async function($id_app$jscomp$1_tk_user$$,$data$$,$obj$$,$callback$$){var $_app_ngay_ks$$=await global.getModel("app").findOne({_id:$id_app$jscomp$1_tk_user$$.current_id_app}); if(!$_app_ngay_ks$$)return $callback$$("C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");var $den_ngay_ngay_ks$$=moment([$obj$$.nam,0,1]).startOf("date").toDate();if($den_ngay_ngay_ks$$=await utils.isBookLocked({id_app:$id_app$jscomp$1_tk_user$$.current_id_app,ngay_ct:$den_ngay_ngay_ks$$,ngay_ks:$_app_ngay_ks$$.ngay_ks}))return $callback$$(`\u0110\u00e3 kh\u00f3a s\u1ed5 \u0111\u1ebfn ng\u00e0y ${moment($den_ngay_ngay_ks$$).format("DD/MM/YYYY")}`);$data$$.nam=$data$$.nam||$obj$$.nam;if($data$$.nam&& ($den_ngay_ngay_ks$$=moment([$data$$.nam,0,1]).endOf("year").toDate(),$_app_ngay_ks$$=await utils.isBookLocked({id_app:$id_app$jscomp$1_tk_user$$.current_id_app,ngay_ct:$den_ngay_ngay_ks$$,ngay_ks:$_app_ngay_ks$$.ngay_ks})))return $callback$$(`\u0110\u00e3 kh\u00f3a s\u1ed5 \u0111\u1ebfn ng\u00e0y ${moment($_app_ngay_ks$$).format("DD/MM/YYYY")}`);$id_app$jscomp$1_tk_user$$=$id_app$jscomp$1_tk_user$$.current_id_app;void 0==$data$$.tk&&($data$$.tk=$obj$$.tk);void 0==$data$$.du_no_nt00&&($data$$.du_no_nt00= $obj$$.du_no_nt00);void 0==$data$$.du_co_nt00&&($data$$.du_co_nt00=$obj$$.du_co_nt00);void 0==$data$$.du_no_nt1&&($data$$.du_no_nt1=$obj$$.du_no_nt1);void 0==$data$$.du_co_nt1&&($data$$.du_co_nt1=$obj$$.du_co_nt1);($id_app$jscomp$1_tk_user$$=await dmtk.findOne({tk:$data$$.tk,id_app:$id_app$jscomp$1_tk_user$$},{ma_nt:1}).lean())&&"VND"===$id_app$jscomp$1_tk_user$$.ma_nt&&($data$$.du_no_nt00=$data$$.du_no00,$data$$.du_co_nt00=$data$$.du_co00,$data$$.du_no_nt1=$data$$.du_no1,$data$$.du_co_nt1=$data$$.du_co1); $callback$$(null,$data$$,$obj$$)};$contr_router$$.creating=async function($tk$jscomp$1_user$$,$obj$$,$callback$$){var $_app$jscomp$1_ngay_ks$$=await global.getModel("app").findOne({_id:$tk$jscomp$1_user$$.current_id_app});if(!$_app$jscomp$1_ngay_ks$$)return $callback$$("C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");$obj$$.nam||($obj$$.nam=$_app$jscomp$1_ngay_ks$$.nam_bd);let $den_ngay$$=moment([$obj$$.nam,0,1]).startOf("date").toDate();if($_app$jscomp$1_ngay_ks$$=await utils.isBookLocked({id_app:$tk$jscomp$1_user$$.current_id_app, ngay_ct:$den_ngay$$,ngay_ks:$_app$jscomp$1_ngay_ks$$.ngay_ks}))return $callback$$(`\u0110\u00e3 kh\u00f3a s\u1ed5 \u0111\u1ebfn ng\u00e0y ${moment($_app$jscomp$1_ngay_ks$$).format("DD/MM/YYYY")}`);($tk$jscomp$1_user$$=await dmtk.findOne({tk:$obj$$.tk,id_app:$tk$jscomp$1_user$$.current_id_app},{ma_nt:1}).lean())&&"VND"===$tk$jscomp$1_user$$.ma_nt&&($obj$$.du_no_nt00=$obj$$.du_no00,$obj$$.du_co_nt00=$obj$$.du_co00,$obj$$.du_no_nt1=$obj$$.du_no1,$obj$$.du_co_nt1=$obj$$.du_co1);$callback$$(null,$obj$$)}; $contr_router$$.deleting=async($ngay_ks$jscomp$3_user$$,$obj$$,$callback$$)=>{let $_app$$=await global.getModel("app").findOne({_id:$ngay_ks$jscomp$3_user$$.current_id_app});if(!$_app$$)return $callback$$("C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");let $den_ngay$$=moment([$obj$$.nam,0,1]).startOf("date").toDate();if($ngay_ks$jscomp$3_user$$=await utils.isBookLocked({id_app:$ngay_ks$jscomp$3_user$$.current_id_app,ngay_ct:$den_ngay$$,ngay_ks:$_app$$.ngay_ks}))return $callback$$(`\u0110\u00e3 kh\u00f3a s\u1ed5 \u0111\u1ebfn ng\u00e0y ${moment($ngay_ks$jscomp$3_user$$).format("DD/MM/YYYY")}`); $callback$$(null,$obj$$)}};module.exports=cdkh;