UNPKG

flexbiz-server

Version:

Flexible Server

4 lines (3 loc) 855 B
'use strict';const sophanbokh=global.getModel("sophanbokh"),hspbts=global.getModel("hspbts"),underscore=require("underscore"); module.exports=function($kqtinhkh$$,$fn$$){sophanbokh.deleteMany({id_ts:$kqtinhkh$$.id_ts,thang:$kqtinhkh$$.thang,nam:$kqtinhkh$$.nam},$error$jscomp$2$$=>{if($error$jscomp$2$$)return $fn$$($error$jscomp$2$$);hspbts.find({id_app:$kqtinhkh$$.id_app,id_ts:$kqtinhkh$$.id_ts,thang:$kqtinhkh$$.thang,nam:$kqtinhkh$$.nam}).lean().exec(($error$jscomp$0$$,$hss$$)=>{if($error$jscomp$0$$)return $fn$$($error$jscomp$0$$);let $m$$=$hss$$.csum("he_so");0!==$m$$?$hss$$.forEach($hs$$=>{underscore.extend($hs$$,$kqtinhkh$$); $hs$$.gia_tri_kh_ky=Math.roundBy($hs$$.he_so/$m$$*$kqtinhkh$$.gia_tri_kh_ky,0);delete $hs$$._id}):$hss$$=[$kqtinhkh$$];sophanbokh.create($hss$$,$error$$=>{if($error$$)return $fn$$($error$$);$fn$$(null,$hss$$)})})})};