flexbiz-server 12.1.0 → 12.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/controllers/controller.js +51 -44
- package/server/controllers/controllerRPT.js +59 -39
- package/server/libs/blockchainconnect.js +1 -1
- package/server/libs/prototypes.js +3 -3
- package/server/models/listinfo.js +62 -14
- package/server/modules/vouchers/vo-hd1.js +6 -6
- package/server/modules/vouchers/vo-hd2.js +4 -4
- package/server/modules/vouchers/vo-xhd.js +2 -2
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
dmqct=global.getModel("dmqct"),counter=global.getModel("counter"),async=require("async"),excel=require("../libs/excel"),permission=require("../libs/permission"),fs=require("fs"),link=global.getModel("link"),Moment=require("moment-timezone"),moment=$time$$=>Moment.tz($time$$,configs.timezone||"Asia/Ho_Chi_Minh"),numeral=require("numeral"),Parameter=global.getModel("parameter"),templatevoucher=global.getModel("templatevoucher"),dvcs=global.getModel("dvcs"),{numberToWord,stripHtmlTags,compileHtml,evalute}=
|
|
3
3
|
require("../libs/utils"),redisCache=require("../libs/redis-cache"),path=require("path"),htmlReport=require("../libs/htmlReport"),User=global.getModel("user"),Usergroup=global.getModel("usergroup"),textReport=require("../libs/textReport"),dmqddvt=global.getModel("dmqddvt"),StaticPool=require("../libs/WorkerStaticPool"),ERR_NOT_FOUND="ERR_NOT_FOUND: \u0110\u1ed1i t\u01b0\u1ee3ng n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i",ERR_NOT_FOUND_CODE=1100,ERR_NOT_PERMIT="ERR_NOT_PERMIT: Kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n t\u00e1c v\u1ee5 n\u00e0y",
|
|
4
4
|
ERR_NOT_PERMIT_CODE=1200,ERR_ALREADY_EXIST="ERR_ALREADY_EXIST: \u0110\u1ed1i t\u01b0\u1ee3ng n\u00e0y \u0111\u00e3 th\u1ef1c s\u1ef1 t\u1ed3n t\u1ea1i",ERR_ALREADY_EXIST_CODE=1300,ERR_NOT_HAVE_DATA="ERR_NOT_HAVE_DATA: Kh\u00f4ng c\u00f3 d\u1eef li\u1ec7u",ERR_NOT_HAVE_DATA_CODE=1400,ERR_CAN_NOT_UPDATE="ERR_CAN_NOT_UPDATE: Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",ERR_CAN_NOT_UPDATE_CODE=1500,ERR_DATA_GENERATED="ERR_DATA_GENERATED: \u0110\u00e3 ph\u00e1t sinh d\u1eef li\u1ec7u li\u00ean quan",
|
|
5
|
-
ERR_DATA_GENERATED_CODE=1600,ERR_ID_INVALID="ERR_ID_INVALID: Id kh\u00f4ng h\u1ee3p l\u1ec7",ERR_ID_INVALID_CODE=1700,ERR_KEY_ARISE="ERR_KEY_ARISE_DATA: ",ERR_KEY_ARISE_CODE=1800,ERR_ARISE="ERR_ARISE_DATA: ",ERR_ARISE_CODE=1900,ERR_VERIFY_OTP=4001,BOOK_LOCK=4444,fields_sync_master_detail=["ma_ct","so_ct","ngay_ct"];function bodyToJson($body$$){$body$$.json&&($body$$=JSON.parse($body$$.json));delete $body$$._id;delete $body$$.__v;return $body$$}
|
|
5
|
+
ERR_DATA_GENERATED_CODE=1600,ERR_ID_INVALID="ERR_ID_INVALID: Id kh\u00f4ng h\u1ee3p l\u1ec7",ERR_ID_INVALID_CODE=1700,ERR_KEY_ARISE="ERR_KEY_ARISE_DATA: ",ERR_KEY_ARISE_CODE=1800,ERR_ARISE="ERR_ARISE_DATA: ",ERR_ARISE_CODE=1900,ERR_VERIFY_OTP=4001,BOOK_LOCK=4444,fields_sync_master_detail=["ma_ct","so_ct","ngay_ct"],validator=require("../libs/validator");function bodyToJson($body$$){$body$$.json&&($body$$=JSON.parse($body$$.json));delete $body$$._id;delete $body$$.__v;return $body$$}
|
|
6
6
|
async function asyncBodyToJson($body$$,$ctrl$$,$id_app$$,$voucher_options$$){$voucher_options$$||($voucher_options$$=(await OptionsModel.findOne({id_app:$id_app$$,id_func:$ctrl$$.name},{option:1}).lean()||{}).option);$body$$=bodyToJson($body$$);if($voucher_options$$)for(let $field$$ in $voucher_options$$)!$body$$[$field$$]&&"_id"!==$field$$&&$voucher_options$$[$field$$]&&underscore.has($ctrl$$.model.schema.paths,$field$$)&&($body$$[$field$$]=$voucher_options$$[$field$$]);for(let $key$$ in $body$$)if(Array.isArray($body$$[$key$$])&&
|
|
7
7
|
$body$$[$key$$].forEach($r$$=>{_.isObject($r$$)&&delete $r$$._id}),$body$$[$key$$]&&$body$$[$key$$]instanceof String&&(0==$body$$[$key$$].trim().indexOf("[")||0==$body$$[$key$$].trim().indexOf("{"))&&("mixed"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()||"array"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()))try{$body$$[$key$$]=JSON.parse($body$$[$key$$])}catch($e$$){console.error($e$$)}return $body$$}
|
|
8
8
|
const getData=($id_app$$,$collection$$,$field$$,$condition$$)=>{if("token"===$collection$$||"asskey"===$collection$$)throw`Collection ${$collection$$} is not allow`;"dmkh"===$collection$$&&($collection$$="customer");"dmtk"===$collection$$&&($collection$$="account");let $col$$=mongoose.models[$collection$$];if($col$$){if($col$$.schema.paths.id_app){if(!$id_app$$)throw`Collection ${$collection$$} required id_app`;$condition$$.id_app=$id_app$$}let $fields$$;$field$$&&($fields$$={[$field$$]:1});if("user"===
|
|
@@ -85,11 +85,17 @@ var $_rs_msg_templatePath$$=$app$jscomp$1_dir_root_template_e$$?`${path.dirname(
|
|
|
85
85
|
if(!fs.existsSync($_rs_msg_templatePath$$))return $_rs_msg_templatePath$$="File m\u1eabu excel ch\u01b0a \u0111\u01b0\u1ee3c khai b\u00e1o t\u1ea1i '"+$_rs_msg_templatePath$$+"'",$res$$.status(400).send({error:$_rs_msg_templatePath$$});$app$jscomp$1_dir_root_template_e$$={};$_groupBy_func_string_rs$$.e_view.forEach($item$$=>{for(let $_key$$ in $item$$){let $_v$$=$item$$[$_key$$];if(underscore.isObject($_v$$))for(let $__key$$ in $_v$$){let $__v$$=$_v$$[$__key$$];if(!underscore.isFunction($__v$$))if(0<=
|
|
86
86
|
$__key$$.indexOf("ngay")||0<=$__key$$.indexOf("date"))try{$item$$[`${$_key$$}_${$__key$$}`]=new Date($__v$$)}catch($e$$){$item$$[`${$_key$$}_${$__key$$}`]=$__v$$}else $item$$[`${$_key$$}_${$__key$$}`]=$__v$$}else if($_v$$&&0<=$_key$$.indexOf("ngay")||0<=$_key$$.indexOf("date"))try{let $d$$=moment($_v$$,"YYYY-MM-DD");$d$$.isValid()&&($item$$[`${$_key$$}`]=$d$$.toDate(),$item$$[`${$_key$$}_string`]=$d$$.format("DD/MM/YYYY"))}catch($e$$){console.error("Error convert to date",$_v$$,$e$$)}}});$app$jscomp$1_dir_root_template_e$$.detail=
|
|
87
87
|
$_groupBy_func_string_rs$$.e_view;if($excelTemplate$$&&$excelTemplate$$.handle_data){$_groupBy_func_string_rs$$=`return (async ()=>{
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
try{
|
|
89
|
+
${$excelTemplate$$.handle_data}
|
|
90
|
+
}catch(e){
|
|
91
|
+
return {error:e}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
})`;try{if(($app$jscomp$1_dir_root_template_e$$=await evalute($_groupBy_func_string_rs$$,{data:$app$jscomp$1_dir_root_template_e$$,moment,numeral,_,utils})())&&$app$jscomp$1_dir_root_template_e$$.error)return console.error($app$jscomp$1_dir_root_template_e$$.error,$_groupBy_func_string_rs$$),$res$$.status(400).send({error:$app$jscomp$1_dir_root_template_e$$.error.message||$app$jscomp$1_dir_root_template_e$$.error.error||$app$jscomp$1_dir_root_template_e$$.error})}catch($e$$){return console.error($e$$,
|
|
95
|
+
$_groupBy_func_string_rs$$),$res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$})}}excelReport($_rs_msg_templatePath$$,$app$jscomp$1_dir_root_template_e$$,function($e$$,$result$$){setImmediate(()=>{if($e$$)return console.error($e$$),$res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$});$res$$.setHeader("Content-Type","application/vnd.openxmlformats");$res$$.setHeader("Content-Disposition","attachment; filename="+$ctrl$$.name+".xlsx");$res$$.end($result$$,"binary")})},{timezone:configs.timezone||
|
|
96
|
+
"Asia/Ho_Chi_Minh"})}else $req$$.query.print&&$req$$.query.id_rpt&&global.mongoose.Types.ObjectId.isValid($req$$.query.id_rpt)?htmlReport($req$$.query.id_rpt,{...$req$$.user.current_app_info,...$req$$.query,company:{...$req$$.user.current_app_info},detail:$_groupBy_func_string_rs$$.e_view,details:$_groupBy_func_string_rs$$.e_view}).then($rs$$=>{$res$$.send($rs$$)},$e$$=>{console.error($e$$);$res$$.status(400).send($e$$)}):($_rs_msg_templatePath$$=$_groupBy_func_string_rs$$.e_view,$req$$.query.groupBy?
|
|
97
|
+
($_groupBy_func_string_rs$$=$req$$.query.groupBy.split(","),$_rs_msg_templatePath$$.groupBy($_groupBy_func_string_rs$$,[],($e$$,$_items$$)=>{if($e$$)return console.error($e$$),$res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$});$res$$.send($_items$$)})):$res$$.send($_rs_msg_templatePath$$))})})})})}})}];$_route_name_route_name$$=$_route_name_route_name$$||this.route_name;"GET"===$method$$?(this.router.route($_route_name_route_name$$).get(...$findRoute$$),this.router.route($_route_name_route_name$$+
|
|
98
|
+
"/excel").get(...$findRoute$$)):(this.router.route($_route_name_route_name$$).post(...$findRoute$$),this.router.route($_route_name_route_name$$+"/excel").post(...$findRoute$$))};
|
|
93
99
|
controller.prototype.get=function($route_name$$,$shareRoute$$=!1){let $model$$=this.model,$ctrl$$=this;this.router.route(`${$route_name$$||this.route_name}/:id`).get(function($req$$,$res$$,$next$$){let $id$$=$req$$.params.id;if(!global.mongoose.Types.ObjectId.isValid($id$$))return $res$$.status(404).send({error:ERR_ID_INVALID,code:ERR_ID_INVALID_CODE});async.parallel({c:$callback$$=>{global.clientRedis.get("stp:"+$id$$,async($err_fields$jscomp$2_notfields$$,$obj$jscomp$0$$)=>{if(!$err_fields$jscomp$2_notfields$$&&
|
|
94
100
|
$obj$jscomp$0$$&&$obj$jscomp$0$$._id===$id$$)$callback$$(null,JSON.parse($obj$jscomp$0$$));else{let $field_not_right$$;try{$field_not_right$$=await permission.getFieldNotRight($req$$.user.current_id_app,$req$$.user.email,$ctrl$$.name)}catch($e$$){$field_not_right$$=[]}$err_fields$jscomp$2_notfields$$=$req$$.query.fields;let $gfields$$={};$err_fields$jscomp$2_notfields$$&&(underscore.isArray($err_fields$jscomp$2_notfields$$)?$err_fields$jscomp$2_notfields$$.filter($f$$=>0>$field_not_right$$.indexOf($f$$)).forEach($f$$=>
|
|
95
101
|
{"_id"!=$f$$&&$f$$&&($gfields$$[$f$$]=1)}):underscore.isObject($err_fields$jscomp$2_notfields$$)?$gfields$$={...$gfields$$,...$err_fields$jscomp$2_notfields$$}:$err_fields$jscomp$2_notfields$$.split(",").filter($f$$=>0>$field_not_right$$.indexOf($f$$)).forEach($f$$=>{"_id"!=$f$$&&$f$$&&($gfields$$[$f$$]=1)}));if(!$err_fields$jscomp$2_notfields$$)try{$field_not_right$$.forEach($f$$=>{$f$$&&($gfields$$[$f$$]=0)})}catch($e$$){console.error("Error get field not right",$e$$)}!$err_fields$jscomp$2_notfields$$&&
|
|
@@ -229,49 +235,50 @@ controller.prototype.quickCreate=function(){let $model$$=this.model,$name$$=this
|
|
|
229
235
|
"token"!==$key$$&&"_id"!==$key$$&&(underscore.has($model$$.schema.paths,$key$$)&&($body$jscomp$4_query$$[$key$$]=$_data$$[$key$$]),$body$jscomp$4_query$$.details&&$body$jscomp$4_query$$.details.forEach($d$$=>{$d$$[$key$$]=$_data$$[$key$$]}));create($req$$.user,$ctrl$$,$body$jscomp$4_query$$,($e$$,$rs$$)=>{setImmediate(()=>{$session$$["creating_"+$name$$]=!1;if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)})},
|
|
230
236
|
null,$req$$)};this.router.route(`${this.route_name}/quickcreate/:template_code`).get(function($req$$,$res$$){$createFromTemplate$$($req$$,$res$$)});this.router.route(`${this.route_name}/quickcreate/:template_code`).post(function($req$$,$res$$){$createFromTemplate$$($req$$,$res$$)})};
|
|
231
237
|
const update=async function($user$jscomp$0$$,$ctrl$$,$id$$,$data$jscomp$0$$,$callback$jscomp$1$$,$action$jscomp$0$$,$req$$){delete $data$jscomp$0$$.__v;try{const $model$$=$ctrl$$.model,$unique$$=$ctrl$$.unique,$module$$=$ctrl$$.module,$schema_paths$$=$model$$.schema.paths;underscore.has($schema_paths$$,"ma_ct")&&$ctrl$$.options.isVoucher&&($data$jscomp$0$$.ma_ct=$ctrl$$.name.toUpperCase());delete $data$jscomp$0$$.session_updated;delete $data$jscomp$0$$.session_created;$req$$&&$req$$.cookies&&underscore.has($schema_paths$$,
|
|
232
|
-
"session_updated")&&($data$jscomp$0$$.session_updated=$req$$.
|
|
238
|
+
"session_updated")&&($data$jscomp$0$$.session_updated=$req$$.cookies.uid);const $voucher_options$$=(await OptionsModel.findOne({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name}).lean()||{}).option;let $current_obj$$;if($ctrl$$.options.requireRecaptchaToken){if(!$data$jscomp$0$$["g-recaptcha-response"])return $callback$jscomp$1$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u g-recaptcha-response");try{await permission.verifyReCaptcha($data$jscomp$0$$["g-recaptcha-response"])}catch($e$$){return $callback$jscomp$1$$($e$$.message||
|
|
233
239
|
$e$$.error||$e$$)}}if(0>global.configs.admins.indexOf($user$jscomp$0$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($data$jscomp$0$$,{action:"update",_id:$id$$,user:$user$jscomp$0$$}));if($requireOtp$$)try{await permission.verifyOTP($user$jscomp$0$$.email,$data$jscomp$0$$["otp-id"],$data$jscomp$0$$["otp-code"])}catch($e$$){return $callback$jscomp$1$$({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}async.waterfall([function($callback$$){setImmediate(function(){$model$$.findOne({_id:$id$$}).exec(function($error$$,
|
|
234
|
-
$obj$$){setImmediate(async()=>{if($error$$)return $callback$$($error$$);if(!$obj$$)return $callback$$("Kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y");if($obj$$.ngay_ct&&$obj$$.id_app)try{await new Promise(($rs$$,$rj$$)=>{validator.unlockBook[0]($obj$$.id_app,$obj$$.ngay_ct,$unlock$$=>{if(!$unlock$$)return $rj$$(validator.unlockBook[1]);$rs$$($unlock$$)})})}catch($e$$){return $callback$$($e$$.message
|
|
235
|
-
$obj$$.exfields||{});const $old_obj$$=$obj$$.toObject();$current_obj$$=_.cloneDeep($old_obj$$);const $data_keys$$=Object.keys($data$jscomp$0$$);for(let $key$$ in $old_obj$$)0>$data_keys$$.indexOf($key$$)&&($data$jscomp$0$$[$key$$]=$old_obj$$[$key$$]);$callback$$(null,$obj$$)})})})},function($obj$$,$callback$$){setImmediate(function(){permission.hasRight($user$jscomp$0$$.current_id_app,$user$jscomp$0$$.email,$module$$,"update",
|
|
236
|
-
{...$data$jscomp$0$$,_id:$obj$$._id.toString()},$e$$=>{if($e$$)return $callback$$($e$$);$callback$$(null,$obj$$)});else return $callback$$({error:$error$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})})},{data:$data$jscomp$0$$,obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})},function($obj$$,$callback$$){underscore.has($model$$.schema.paths,"ngay_ct")&&underscore.has($model$$.schema.paths,"so_ct")&&$obj$$.ngay_ct
|
|
237
|
-
id_func:$ctrl$$.name},{option:1}).lean().exec(($e$jscomp$0$$,$rs$jscomp$0$$)=>{setImmediate(()=>{if($rs$jscomp$0$$&&$rs$jscomp$0$$.option&&$rs$jscomp$0$$.option.check_so_ct&&"0"!==$rs$jscomp$0$$.option.check_so_ct){let $query_check$$={id_app:$obj$$.id_app,so_ct:$data$jscomp$0$$.so_ct,_id:{$ne:$obj$$._id.toString()}},$tu_ngay$$;var $date_check_den_ngay$$=$data$jscomp$0$$.ngay_ct||$obj$$.ngay_ct;
|
|
238
|
-
$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("date").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "2":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("month").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("month").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "3":$tu_ngay$$=
|
|
239
|
-
$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "8":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("year").toDate(),$date_check_den_ngay$$=moment($date_check_den_ngay$$).startOf("year").toDate(),$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$}}$model$$.findOne($query_check$$,{so_ct:1}).lean().exec(($e$$,$rs$$)=>
|
|
240
|
-
$callback$$(null,$obj$$)})})}else $callback$$(null,$obj$$)})}):$callback$$(null,$obj$$)},($obj$jscomp$0$$,$callback$jscomp$0$$)=>{(async($obj$$,$callback$$)=>{try{(await permission.getFieldNotRight($obj$$.id_app,$user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>{delete $data$jscomp$0$$[$f$$]})}catch($e$$){console.error("Error get field not right"
|
|
241
|
-
$_obj$$){setImmediate(()=>{if($error$jscomp$0$$)return $callback$$($error$jscomp$0$$);if($ctrl$$.dynamicUpdating)$ctrl$$.dynamicUpdating($user$jscomp$0$$,$_data$jscomp$0$$,$_obj$$,function($error$$,$_data$$){if($error$$)return $callback$$($error$$);for(let $f$$ in $_data$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$$[$f$$])
|
|
242
|
-
$callback$$(null,$obj$$)}})}):$ctrl$$.dynamicUpdating?$ctrl$$.dynamicUpdating($req$$.user,$data$jscomp$0$$,$obj$$,function($error$$,$_data$$){if($error$$)return $callback$$($error$$);for(let $f$$ in $_data$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$$[$f$$]);$callback$$(null,$obj$$)}):$callback$$(null,$obj$$)})})($obj$jscomp$0
|
|
243
|
-
let $c1$$={},$c2$$={};$obj$$.id_app&&($c1$$.id_app=$obj$$.id_app,$c2$$.id_app||($c2$$.id_app=$obj$$.id_app));$unique$$.forEach(function($key$$){$c1$$[$key$$]=$obj$$[$key$$];$ctrl$$.model.schema.paths[$key$$]?("number"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=Number($data$jscomp$0$$[$key$$]):"date"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()
|
|
244
|
-
$c2$$[$key$$]=($data$jscomp$0$$[$key$$]||"").toString():$c2$$[$key$$]=$data$jscomp$0$$[$key$$],$c2$$[$key$$]||($c2$$[$key$$]=$c1$$[$key$$])):console.error("field",$key$$," is not exist. please check unique of controller")});!0!==underscore.isEqual($c1$$,$c2$$)?isExists($model$$,$unique$$,$c2$$,$ctrl$$.replaceIfExists,function($error$jscomp$0$$,$kq$$){setImmediate(()=>{if($error$jscomp$0
|
|
245
|
-
$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$)}else checkReference($model$$,$obj$$,function($error$$){setImmediate(()=>{if($error$$)return console.error("Keys arise data",$c1$$,$c2$$,$error$$),$callback$$({error:ERR_KEY_ARISE+($error$$.error
|
|
246
|
-
"_id"!==$key$$);$unique$$&&($keys$$=$keys$$.filter($key$$=>0>$unique$$.indexOf($key$$).length));if(0===$keys$$.length)return $callback$$(null,$obj$$);checkReference($model$$,$obj$$,function($msgError$$){setImmediate(()=>{if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0
|
|
247
|
-
code:ERR_ARISE_CODE});else $callback$$(null,$obj$$)})},$keys$$)},function($obj$jscomp$1$$,$callback$$){$ctrl$$.validating||($ctrl$$.validating=($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)});$ctrl$$.validating($user$jscomp$0$$,$obj$jscomp$1$$,($error$$,$obj$jscomp$0$$)=>{if($error$$)return $callback$$($error$$);
|
|
248
|
-
function($obj$$,$data$$,$action$$,$fn$$){$fn$$()});$ctrl$$.options.onUpdateExtending($obj$jscomp$0$$,$data$jscomp$0$$,$action$jscomp$0$$,function(){underscore.has($schema_paths$$,"exfields")&&$data$jscomp$0$$.exfields&&($obj$jscomp$0$$.exfields=$data$jscomp$0$$.exfields);delete $data$jscomp$0$$.__v;
|
|
249
|
-
{}));validate($obj$jscomp$0$$,function($msgError$$){setImmediate(()=>{if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$);
|
|
250
|
-
function($obj$$,$callback$$){setImmediate(async()=>{$obj$$.ngay_ct&&($obj$$.ngay_ct=moment($obj$$.ngay_ct).toDate());for(var $$condition_k$$ in $ctrl$$.keyValues)$obj$$[$$condition_k$$]=$ctrl$$.keyValues[$$condition_k$$];Object.keys($model$$.schema.paths).filter($model_path$$=>$obj$$[$model_path$$]&&
|
|
251
|
-
"line"!==$path$$&&"_id"!==$path$$&&"__v"!==$path$$&&0<=fields_sync_master_detail.indexOf($path$$)).forEach($path$$=>{$obj$$[$path$$]&&$obj$$[$model_path$$].filter($detail$$=>!$detail$$[$path$$]).forEach($detail$$=>{$detail$$[$path$$]=$obj$$[$path$$]})})});await createIdRef($model
|
|
252
|
-
$data$jscomp$0$$.$condition,$$condition_k$$._id=$obj$$._id,await $model$$.findOne($$condition_k$$)||($error$jscomp$0$$=ERR_CAN_NOT_UPDATE),delete $data$jscomp$0$$.$condition);if(!$error$jscomp$0$$)try{delete $obj$$.__v,$obj_created$$=await $obj$$.save()}catch($e$$){$error$jscomp$0
|
|
253
|
-
($msgErrors$$=JSON.stringify($error$jscomp$0$$));if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&console.error("onErrorUpdating",$e$$);$callback$$({error:$msgErrors$$,code:ERR_CAN_NOT_UPDATE_CODE})},$current_obj$$);else $callback$$({error:$msgErrors$$,
|
|
254
|
-
newData:$data$jscomp$0$$,id:$obj$$._id.toString()}},$user$jscomp$0$$.email,$req$$.header("user-agent"),$req$$)}),postData($obj_created$$,$ctrl$$,function($msgError$$){$msgError$$?setImmediate(()=>{$current_obj$$&&$model$$.findByIdAndUpdate($current_obj$$._id,{$set:$current_obj$$},function($err$$,$restore_data$$){if($err
|
|
255
|
-
($e$jscomp$0$$,$_d$$)=>{if(!$_d$$)return console.error("Don't find voucher",$current_obj$$._id);postData($_d$$,$ctrl$$,function($e$$){if($e$$)return console.error("can't repost voucher",$e$$);console.log("reposted voucher",$_d$$._id)})})});if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0
|
|
256
|
-
$ctrl$$.emit("updated",$obj_created$$);$obj_created$$=$obj_created$$.toObject();runWebhooks($ctrl$$,$obj_created$$,"UPDATE",$voucher_options$$);$ctrl$$.cacheData($obj_created$$);if($req$$&&!1!==$req$$.query.return_data)$ctrl$$.onView($user$jscomp$0$$,[$obj_created$$],function($error$$,$viewValue$$){setImmediate(()=>
|
|
257
|
-
{req:$req$$});else $callback$$(null,{_id:$obj_created$$._id})})})})},function($obj$$,$callback$$){$ctrl$$.requestApprove($user$jscomp$0$$.current_app_info,$user$jscomp$0$$,$obj$$,$callback$$,$voucher_options$$)},function($obj$jscomp$0$$,$callback$$){void 0!=$obj$jscomp$0$$.trang_thai&&setImmediate(async()=>
|
|
258
|
-
($rs$$.user_approved=$req$$.user.email,$rs$$.user_approved_name=$req$$.user.name,$rs$$.date_approved=new Date,Approve.updateOne({_id:$rs$$._id},$rs$$).then(()=>{Approve.sendNotifyApproved($rs$$,$req$$.query.access_token)}))})});setImmediate(async()=>{(await permission.getFieldNotRight($obj$jscomp$0$$.id_app
|
|
259
|
-
function($error$jscomp$0$$,$obj$$){if($error$jscomp$0$$)return console.error("error when saved",$error$jscomp$0$$),$callback$$($error$jscomp$0$$);$ctrl$$.dynamicUpdated?$ctrl$$.dynamicUpdated($user$jscomp$0$$,$obj$$,function($error$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$$)})
|
|
260
|
-
$obj$jscomp$0$$)}):$callback$$(null,$obj$jscomp$0$$)})}],($e$jscomp$166_name_cached$$,$rs$$)=>{$e$jscomp$166_name_cached$$?(console.error($e$jscomp$166_name_cached$$),$callback$jscomp$1$$($e$jscomp$166_name_cached$$)):($e$jscomp$166_name_cached$$=$model$$.collection.name,$user$jscomp$0$$.current_id_app&&
|
|
240
|
+
$obj$$){setImmediate(async()=>{if($error$$)return $callback$$($error$$);if(!$obj$$)return $callback$$("Kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y");if($obj$$.ngay_ct&&$obj$$.id_app&&$obj$$.schema&&$obj$$.schema.validate&&$obj$$.schema.validate.ngay_ct)try{await new Promise(($rs$$,$rj$$)=>{validator.unlockBook[0]($obj$$.id_app,$obj$$.ngay_ct,$unlock$$=>{if(!$unlock$$)return $rj$$(validator.unlockBook[1]);$rs$$($unlock$$)})})}catch($e$$){return $callback$$($e$$.message||
|
|
241
|
+
$e$$.error||$e$$)}underscore.has($schema_paths$$,"exfields")&&($obj$$.exfields=$obj$$.exfields||{});const $old_obj$$=$obj$$.toObject();$current_obj$$=_.cloneDeep($old_obj$$);const $data_keys$$=Object.keys($data$jscomp$0$$);for(let $key$$ in $old_obj$$)0>$data_keys$$.indexOf($key$$)&&($data$jscomp$0$$[$key$$]=$old_obj$$[$key$$]);$callback$$(null,$obj$$)})})})},function($obj$$,$callback$$){setImmediate(function(){permission.hasRight($user$jscomp$0$$.current_id_app,$user$jscomp$0$$.email,$module$$,"update",
|
|
242
|
+
function($error$$,$hr$$,$c_app$$){setImmediate(()=>{if($hr$$)$ctrl$$.checkData($c_app$$,{...$data$jscomp$0$$,_id:$obj$$._id.toString()},$e$$=>{if($e$$)return $callback$$($e$$);$callback$$(null,$obj$$)});else return $callback$$({error:$error$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})})},{data:$data$jscomp$0$$,obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})},function($obj$$,$callback$$){underscore.has($model$$.schema.paths,"ngay_ct")&&underscore.has($model$$.schema.paths,"so_ct")&&$obj$$.ngay_ct&&
|
|
243
|
+
$data$jscomp$0$$.so_ct&&$obj$$.so_ct!==$data$jscomp$0$$.so_ct?OptionsModel.findOne({id_app:$obj$$.id_app,id_func:$ctrl$$.name},{option:1}).lean().exec(($e$jscomp$0$$,$rs$jscomp$0$$)=>{setImmediate(()=>{if($rs$jscomp$0$$&&$rs$jscomp$0$$.option&&$rs$jscomp$0$$.option.check_so_ct&&"0"!==$rs$jscomp$0$$.option.check_so_ct){let $query_check$$={id_app:$obj$$.id_app,so_ct:$data$jscomp$0$$.so_ct,_id:{$ne:$obj$$._id.toString()}},$tu_ngay$$;var $date_check_den_ngay$$=$data$jscomp$0$$.ngay_ct||$obj$$.ngay_ct;
|
|
244
|
+
switch($rs$jscomp$0$$.option.check_so_ct){case "1":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("date").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("date").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "2":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("month").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("month").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "3":$tu_ngay$$=
|
|
245
|
+
moment($date_check_den_ngay$$).startOf("quarter").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("quarter").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "8":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("year").toDate(),$date_check_den_ngay$$=moment($date_check_den_ngay$$).startOf("year").toDate(),$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$}}$model$$.findOne($query_check$$,{so_ct:1}).lean().exec(($e$$,$rs$$)=>
|
|
246
|
+
{setImmediate(()=>{if($rs$$)return $callback$$("S\u1ed1 ch\u1ee9ng t\u1eeb "+$data$jscomp$0$$.so_ct+" \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ch\u1ecdn m\u1ed9t s\u1ed1 ch\u1ee9ng t\u1eeb kh\u00e1c");$callback$$(null,$obj$$)})})}else $callback$$(null,$obj$$)})}):$callback$$(null,$obj$$)},($obj$jscomp$0$$,$callback$jscomp$0$$)=>{(async($obj$$,$callback$$)=>{try{(await permission.getFieldNotRight($obj$$.id_app,$user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>{delete $data$jscomp$0$$[$f$$]})}catch($e$$){console.error("Error get field not right",
|
|
247
|
+
$e$$)}setImmediate(function(){$ctrl$$.updating?$ctrl$$.updating($user$jscomp$0$$,$data$jscomp$0$$,$obj$$,function($error$jscomp$0$$,$_data$jscomp$0$$,$_obj$$){setImmediate(()=>{if($error$jscomp$0$$)return $callback$$($error$jscomp$0$$);if($ctrl$$.dynamicUpdating)$ctrl$$.dynamicUpdating($user$jscomp$0$$,$_data$jscomp$0$$,$_obj$$,function($error$$,$_data$$){if($error$$)return $callback$$($error$$);for(let $f$$ in $_data$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$$[$f$$]);
|
|
248
|
+
$callback$$(null,$obj$$)});else{for(let $f$$ in $_data$jscomp$0$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$jscomp$0$$[$f$$]);$callback$$(null,$obj$$)}})}):$ctrl$$.dynamicUpdating?$ctrl$$.dynamicUpdating($req$$.user,$data$jscomp$0$$,$obj$$,function($error$$,$_data$$){if($error$$)return $callback$$($error$$);for(let $f$$ in $_data$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$$[$f$$]);$callback$$(null,$obj$$)}):$callback$$(null,$obj$$)})})($obj$jscomp$0$$,
|
|
249
|
+
$callback$jscomp$0$$)},function($obj$$,$callback$$){setImmediate(function(){if(!$unique$$||0===$unique$$.length)return $callback$$(null,$obj$$);let $c1$$={},$c2$$={};$obj$$.id_app&&($c1$$.id_app=$obj$$.id_app,$c2$$.id_app||($c2$$.id_app=$obj$$.id_app));$unique$$.forEach(function($key$$){$c1$$[$key$$]=$obj$$[$key$$];$ctrl$$.model.schema.paths[$key$$]?("number"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=Number($data$jscomp$0$$[$key$$]):"date"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?
|
|
250
|
+
$c2$$[$key$$]=new Date($data$jscomp$0$$[$key$$]):"string"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=($data$jscomp$0$$[$key$$]||"").toString():$c2$$[$key$$]=$data$jscomp$0$$[$key$$],$c2$$[$key$$]||($c2$$[$key$$]=$c1$$[$key$$])):console.error("field",$key$$," is not exist. please check unique of controller")});!0!==underscore.isEqual($c1$$,$c2$$)?isExists($model$$,$unique$$,$c2$$,$ctrl$$.replaceIfExists,function($error$jscomp$0$$,$kq$$){setImmediate(()=>{if($error$jscomp$0$$||
|
|
251
|
+
$kq$$){let $msgError$$=$error$jscomp$0$$||ERR_ALREADY_EXIST;console.error($msgError$$,$c2$$);if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$)}else checkReference($model$$,$obj$$,function($error$$){setImmediate(()=>{if($error$$)return console.error("Keys arise data",$c1$$,$c2$$,$error$$),$callback$$({error:ERR_KEY_ARISE+($error$$.error||
|
|
252
|
+
$error$$.message||$error$$),code:ERR_KEY_ARISE_CODE});$callback$$(null,$obj$$)})},$unique$$)})}):$callback$$(null,$obj$$)})},function($obj$$,$callback$$){let $keys$$=underscore.keys($model$$.referenceKeys).filter($key$$=>"_id"!==$key$$);$unique$$&&($keys$$=$keys$$.filter($key$$=>0>$unique$$.indexOf($key$$).length));if(0===$keys$$.length)return $callback$$(null,$obj$$);checkReference($model$$,$obj$$,function($msgError$$){setImmediate(()=>{if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,
|
|
253
|
+
$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$({error:ERR_ARISE+($msgError$$.error||$msgError$$.message||$msgError$$),code:ERR_ARISE_CODE});else $callback$$(null,$obj$$)})},$keys$$)},function($obj$jscomp$1$$,$callback$$){$ctrl$$.validating||($ctrl$$.validating=($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)});$ctrl$$.validating($user$jscomp$0$$,$obj$jscomp$1$$,($error$$,$obj$jscomp$0$$)=>{if($error$$)return $callback$$($error$$);
|
|
254
|
+
setImmediate(function(){$data$jscomp$0$$.date_updated=new Date;$data$jscomp$0$$.user_updated=$user$jscomp$0$$.email;delete $data$jscomp$0$$.__v;$ctrl$$.options.onUpdateExtending||($ctrl$$.options.onUpdateExtending=function($obj$$,$data$$,$action$$,$fn$$){$fn$$()});$ctrl$$.options.onUpdateExtending($obj$jscomp$0$$,$data$jscomp$0$$,$action$jscomp$0$$,function(){underscore.has($schema_paths$$,"exfields")&&$data$jscomp$0$$.exfields&&($obj$jscomp$0$$.exfields=$data$jscomp$0$$.exfields);delete $data$jscomp$0$$.__v;
|
|
255
|
+
for(let $f$$ in $data$jscomp$0$$)underscore.has($schema_paths$$,$f$$)&&"_id"!==$f$$&&($obj$jscomp$0$$.set($f$$,$data$jscomp$0$$[$f$$]),"exfields"!==$f$$||$obj$jscomp$0$$.exfields||($obj$jscomp$0$$.exfields={}));validate($obj$jscomp$0$$,function($msgError$$){setImmediate(()=>{if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$);
|
|
256
|
+
else $callback$$(null,$obj$jscomp$0$$)})})})})})},function($obj$$,$callback$$){$current_obj$$&&($obj$$._id=$current_obj$$._id);deletePost($user$jscomp$0$$,$obj$$,async $e$$=>{$callback$$($e$$,$obj$$)})},function($obj$$,$callback$$){setImmediate(async()=>{$obj$$.ngay_ct&&($obj$$.ngay_ct=moment($obj$$.ngay_ct).toDate());for(var $$condition_k$$ in $ctrl$$.keyValues)$obj$$[$$condition_k$$]=$ctrl$$.keyValues[$$condition_k$$];Object.keys($model$$.schema.paths).filter($model_path$$=>$obj$$[$model_path$$]&&
|
|
257
|
+
underscore.isArray($obj$$[$model_path$$])).forEach($model_path$$=>{$model$$.schema.paths[$model_path$$].schema&&$model$$.schema.paths[$model_path$$].schema.paths&&Object.keys($model$$.schema.paths[$model_path$$].schema.paths).filter($path$$=>"line"!==$path$$&&"_id"!==$path$$&&"__v"!==$path$$&&0<=fields_sync_master_detail.indexOf($path$$)).forEach($path$$=>{$obj$$[$path$$]&&$obj$$[$model_path$$].filter($detail$$=>!$detail$$[$path$$]).forEach($detail$$=>{$detail$$[$path$$]=$obj$$[$path$$]})})});await createIdRef($model$$,
|
|
258
|
+
$obj$$);$ctrl$$.saving&&await $ctrl$$.saving($user$jscomp$0$$,$obj$$);$ctrl$$.emit("saving",$obj$$);$current_obj$$&&($obj$$._id=$current_obj$$._id);let $obj_created$$,$error$jscomp$0$$;$data$jscomp$0$$.$condition&&($$condition_k$$=$data$jscomp$0$$.$condition,$$condition_k$$._id=$obj$$._id,await $model$$.findOne($$condition_k$$)||($error$jscomp$0$$=ERR_CAN_NOT_UPDATE),delete $data$jscomp$0$$.$condition);if(!$error$jscomp$0$$)try{delete $obj$$.__v,$obj_created$$=await $obj$$.save()}catch($e$$){$error$jscomp$0$$=
|
|
259
|
+
$e$$}if($error$jscomp$0$$){let $msgErrors$$=[];for(let $k$$ in $error$jscomp$0$$.errors)$msgErrors$$.push($error$jscomp$0$$.errors[$k$$].message);0==$msgErrors$$.length&&($msgErrors$$=$error$jscomp$0$$.message);$msgErrors$$||($msgErrors$$=JSON.stringify($error$jscomp$0$$));if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&console.error("onErrorUpdating",$e$$);$callback$$({error:$msgErrors$$,code:ERR_CAN_NOT_UPDATE_CODE})},$current_obj$$);else $callback$$({error:$msgErrors$$,
|
|
260
|
+
code:ERR_CAN_NOT_UPDATE_CODE})}else $req$$&&$req$$.header&&setImmediate(()=>{log.create({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name,action:"UPDATE",data:{oldData:$current_obj$$,newData:$data$jscomp$0$$,id:$obj$$._id.toString()}},$user$jscomp$0$$.email,$req$$.header("user-agent"),$req$$)}),postData($obj_created$$,$ctrl$$,function($msgError$$){$msgError$$?setImmediate(()=>{$current_obj$$&&$model$$.findByIdAndUpdate($current_obj$$._id,{$set:$current_obj$$},function($err$$,$restore_data$$){if($err$$||
|
|
261
|
+
!$restore_data$$)return console.error("can't restore voucher",$err$$||": don't find voucher");console.log("restored data of voucher. posting...");$model$$.findById($current_obj$$._id,($e$jscomp$0$$,$_d$$)=>{if(!$_d$$)return console.error("Don't find voucher",$current_obj$$._id);postData($_d$$,$ctrl$$,function($e$$){if($e$$)return console.error("can't repost voucher",$e$$);console.log("reposted voucher",$_d$$._id)})})});if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,
|
|
262
|
+
$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$)}):setImmediate(()=>{$ctrl$$.emit("saved",$obj_created$$);$ctrl$$.emit("updated",$obj_created$$);$obj_created$$=$obj_created$$.toObject();runWebhooks($ctrl$$,$obj_created$$,"UPDATE",$voucher_options$$);$ctrl$$.cacheData($obj_created$$);if($req$$&&!1!==$req$$.query.return_data)$ctrl$$.onView($user$jscomp$0$$,[$obj_created$$],function($error$$,$viewValue$$){setImmediate(()=>
|
|
263
|
+
{if($error$$)return $callback$$($error$$);$req$$&&pushNotification($ctrl$$,$viewValue$$[0],"update",$current_obj$$,null,{exclude_token:$req$$.query.access_token});$callback$$(null,$viewValue$$[0])})},{req:$req$$});else $callback$$(null,{_id:$obj_created$$._id})})})})},function($obj$$,$callback$$){$ctrl$$.requestApprove($user$jscomp$0$$.current_app_info,$user$jscomp$0$$,$obj$$,$callback$$,$voucher_options$$)},function($obj$jscomp$0$$,$callback$$){void 0!=$obj$jscomp$0$$.trang_thai&&setImmediate(async()=>
|
|
264
|
+
{Approve.findOne({id_ct:$obj$jscomp$0$$._id.toString(),"update_after_approve.data.trang_thai":$obj$jscomp$0$$.trang_thai.toString()}).lean().exec(($e$$,$rs$$)=>{!$rs$$||$rs$$.user_approved||$rs$$.user_denied||($rs$$.user_approved=$req$$.user.email,$rs$$.user_approved_name=$req$$.user.name,$rs$$.date_approved=new Date,Approve.updateOne({_id:$rs$$._id},$rs$$).then(()=>{Approve.sendNotifyApproved($rs$$,$req$$.query.access_token)}))})});setImmediate(async()=>{(await permission.getFieldNotRight($obj$jscomp$0$$.id_app,
|
|
265
|
+
$user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>{delete $obj$jscomp$0$$[$f$$]});$obj$jscomp$0$$.collection_name=$ctrl$$.collection_name;$ctrl$$.updated?$ctrl$$.updated($user$jscomp$0$$,$obj$jscomp$0$$,function($error$jscomp$0$$,$obj$$){if($error$jscomp$0$$)return console.error("error when saved",$error$jscomp$0$$),$callback$$($error$jscomp$0$$);$ctrl$$.dynamicUpdated?$ctrl$$.dynamicUpdated($user$jscomp$0$$,$obj$$,function($error$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$$)}):
|
|
266
|
+
$callback$$(null,$obj$$)},$current_obj$$):$ctrl$$.dynamicUpdated?$ctrl$$.dynamicUpdated($user$jscomp$0$$,$obj$jscomp$0$$,function($error$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$jscomp$0$$)}):$callback$$(null,$obj$jscomp$0$$)})}],($e$jscomp$166_name_cached$$,$rs$$)=>{$e$jscomp$166_name_cached$$?(console.error($e$jscomp$166_name_cached$$),$callback$jscomp$1$$($e$jscomp$166_name_cached$$)):($e$jscomp$166_name_cached$$=$model$$.collection.name,$user$jscomp$0$$.current_id_app&&
|
|
267
|
+
($e$jscomp$166_name_cached$$+=$user$jscomp$0$$.current_id_app),delete global.cacheDatas[$e$jscomp$166_name_cached$$],$callback$jscomp$1$$(null,$rs$$))})}catch($e$$){console.error($e$$),$callback$jscomp$1$$($e$$)}};
|
|
261
268
|
controller.prototype.update=function(){let $ctrl$$=this,$name$$=this.name;this.router.route(this.route_name+"/:id").put(function($req$$,$res$$){let $session$$=$req$$.session;if(!0===$session$$["updating_"+$name$$])return $res$$.status(400).send({error:"\u0110ang x\u1eed l\u00fd d\u1eef li\u1ec7u"});$session$$["updating_"+$name$$]=!0;let $body$$=$req$$.body;$req$$.files&&underscore.extend($body$$,$req$$.files);let $data$$;try{$data$$=bodyToJson($body$$)}catch($e$$){return $res$$.status(400).send({error:$e$$.message||
|
|
262
269
|
$e$$.error||$e$$})}update($req$$.user,$ctrl$$,$req$$.params.id,$data$$,($e$$,$rs$$)=>{setImmediate(()=>{$session$$["updating_"+$name$$]=!1;if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});!1===$req$$.query.return_data?$res$$.send({_id:$rs$$._id.toString()}):$res$$.send($rs$$)})},null,$req$$)})};
|
|
263
270
|
function checkReference($model$jscomp$0$$,$obj$$,$fn$$,$keys$$){$model$jscomp$0$$.referenceKeys?($keys$$||($keys$$=underscore.keys($model$jscomp$0$$.referenceKeys)),async.map($keys$$,function($key$$,$callback$$){setImmediate(()=>{let $ref$$=$model$jscomp$0$$.referenceKeys[$key$$];if(!$ref$$)return $callback$$();let $value$$=$obj$$[$key$$];"_id"===$key$$&&($value$$=$value$$.toString());if(void 0==$value$$||null==$value$$||""==$value$$)return $callback$$();async.map($ref$$,function($r$$,$cb$$){setImmediate(()=>
|
|
264
271
|
{let $model$$=mongoose.models[$r$$.model];if($model$$){let $query$$={id_app:$obj$$.id_app};var $_w_k$$=$r$$.key;$_w_k$$&&($query$$[$_w_k$$]=$value$$);$r$$.where&&(underscore.isObject($r$$.where)&&($query$$=Object.assign($query$$,$r$$.where)),underscore.isFunction($r$$.where)&&($_w_k$$=$r$$.where($obj$$),$query$$=Object.assign($query$$,$_w_k$$)));$model$$.find($query$$).limit(1).lean().exec(function($error$$,$o$$){setImmediate(()=>{if($error$$)return $cb$$($error$$);if($o$$&&0<$o$$.length){let $msgError$$;
|
|
265
|
-
$msgError$$=$r$$.error?(new Function("obj","return `"+$r$$.error.replace("{{VALUE}}",$value$$)+"`"))($obj$$):ERR_DATA_GENERATED;return $cb$$({error:$msgError$$,code:ERR_DATA_GENERATED_CODE})}$cb$$()})})}else $cb$$()})},function($e$$){if($e$$)return $callback$$($e$$);$callback$$()})})},$error$$=>{$fn$$($error$$)})):$fn$$()}
|
|
266
|
-
controller.prototype.delete=function(){let $model$$=this.model,$ctrl$$=this,$module$$=this.module;this.router.route(this.route_name+"/:id").delete(function($req$$,$res$$,$next$$){if(!global.mongoose.Types.ObjectId.isValid($req$$.params.id))return $res$$.status(400).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});$model$$.findOne({_id:$req$$.params.id}).
|
|
267
|
-
$res$$.status(400).send($e$jscomp$171_user$$):$res$$.status(400).send({error:$e$jscomp$171_user$$.message||$e$jscomp$171_user$$.error||$e$jscomp$171_user$$});if(!$obj$$)return $res$$.status(404).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});if($obj$$.ngay_ct&&$obj$$.id_app)try{await new Promise(($rs$$,$rj$$)=>{validator.unlockBook[0]($obj$$.id_app,$obj$$.ngay_ct,$unlock$$=>{if(!$unlock$$)return $rj$$(validator.unlockBook[1])
|
|
268
|
-
$e$$.error||$e$$,code:BOOK_LOCK})}$e$jscomp$171_user$$=$req$$.user;if(0>global.configs.admins.indexOf($e$jscomp$171_user$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($obj$$,{action:"delete",_id:$req$$.params.id,user:$e$jscomp$171_user$$}));if($requireOtp$$)try{await permission.verifyOTP($e$jscomp$171_user$$.email
|
|
269
|
-
$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}setImmediate(()=>{permission.hasRight($obj$$.id_app,$req$$.user.email,$module$$,"delete",function($error$jscomp$0$$,$hr$$){if($hr$$)checkReference($model$$,$obj$$,function($error$$){if($error$$)return $res$$.status(400).send({error:ERR_ARISE+($error$$.error||$error$$.message||$error$$),code:ERR_ARISE_CODE});$req$$.obj=$obj$$;$next$$()});else return $res$$.status(403).send({error:$error$jscomp$0$$||
|
|
270
|
-
function($req$$,$res$$,$next$$){setImmediate(()=>{let $obj$jscomp$1$$=$req$$.obj;$ctrl$$.deleting?$ctrl$$.deleting($req$$.user,$obj$jscomp$1$$,function($e$$,$obj$jscomp$0$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$ctrl$$.dynamicDeleting?$ctrl$$.dynamicDeleting($req$$.user,$obj$jscomp$0$$,function($error$$,$obj$$){if($error$$)return $next$$($error$$)
|
|
271
|
-
{req:$req$$}):$ctrl$$.dynamicDeleting?$ctrl$$.dynamicDeleting($req$$.user,$obj$jscomp$1$$,function($error$$,$obj$$){if($error$$)return $next$$($error$$);$req$$.obj=$obj$$;$next$$()}):($req$$.obj=$obj$jscomp$1$$,$next$$())})},function($req$$,$res$$){setImmediate(()=>{let $obj$jscomp$0$$=$req$$.obj;$ctrl$$.emit("deleting",{...$obj$jscomp$0$$});deletePost($req$$.user,$obj$jscomp$0$$,async $e$jscomp$1$$=>{if($e$jscomp$1$$)return console.error($e$jscomp$1$$)
|
|
272
|
-
$res$$.status(400).send({error:$e$jscomp$1$$.message||$e$jscomp$1$$});if($ctrl$$.dynamicDeletePost)try{await $ctrl$$.dynamicDeletePost($obj$jscomp$0$$)}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$})}$model$$.deleteOne({_id:$obj$jscomp$0$$._id},function($e$jscomp$0$$){if($e$jscomp$0$$)return console.error($e$jscomp$0$$),$e$jscomp$0$$.error?$res$$.status(400).send($e$jscomp$0$$):$res$$.status(400).send({error:$e$jscomp$0$$.message
|
|
273
|
-
{$ctrl$$.deleteData({...$obj$jscomp$0$$});log.create({id_app:$req$$.user.current_id_app,id_func:$ctrl$$.name,action:"DELETE",data:{id:$obj$jscomp$0$$._id,data:$obj$jscomp$0$$}},$req$$.user.email,$req$$.header("user-agent"),$req$$);link.deleteMany({$or:[{id_a:$obj$jscomp$0$$._id},{id_b:$obj$jscomp$0$$._id}]},function($e$$){$e$$&&console.error("Can't delete links\n"+$e$$)})});setImmediate(()=>{$ctrl$$.emit("deleted",$obj$jscomp$0$$);runWebhooks($ctrl$$,$obj$jscomp$0$$,
|
|
274
|
-
$obj$jscomp$0$$,"delete",null,null,{exclude_token:$req$$.query.access_token});setImmediate(()=>{$ctrl$$.deleted?$ctrl$$.deleted($req$$.user,$obj$jscomp$0$$,function($e$$,$obj$$){setImmediate(()=>{if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($obj$$)})}):$res$$.send($obj$jscomp$0$$)})})})})})};
|
|
272
|
+
$msgError$$=$r$$.error?(new Function("obj","return `"+$r$$.error.replace("{{VALUE}}",$value$$)+"`"))($obj$$):ERR_DATA_GENERATED;return $cb$$({error:$msgError$$,code:ERR_DATA_GENERATED_CODE})}$cb$$()})})}else $cb$$()})},function($e$$){if($e$$)return $callback$$($e$$);$callback$$()})})},$error$$=>{$fn$$($error$$)})):$fn$$()}
|
|
273
|
+
controller.prototype.delete=function(){let $model$$=this.model,$ctrl$$=this,$module$$=this.module;this.router.route(this.route_name+"/:id").delete(function($req$$,$res$$,$next$$){if(!global.mongoose.Types.ObjectId.isValid($req$$.params.id))return $res$$.status(400).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});$model$$.findOne({_id:$req$$.params.id}).exec(async function($e$jscomp$171_user$$,$obj$$){if($e$jscomp$171_user$$)return console.error($e$jscomp$171_user$$),$e$jscomp$171_user$$.error?
|
|
274
|
+
$res$$.status(400).send($e$jscomp$171_user$$):$res$$.status(400).send({error:$e$jscomp$171_user$$.message||$e$jscomp$171_user$$.error||$e$jscomp$171_user$$});if(!$obj$$)return $res$$.status(404).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});if($obj$$.ngay_ct&&$obj$$.id_app&&$obj$$.schema&&$obj$$.schema.validate&&$obj$$.schema.validate.ngay_ct)try{await new Promise(($rs$$,$rj$$)=>{validator.unlockBook[0]($obj$$.id_app,$obj$$.ngay_ct,$unlock$$=>{if(!$unlock$$)return $rj$$(validator.unlockBook[1]);
|
|
275
|
+
$rs$$($unlock$$)})})}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$,code:BOOK_LOCK})}$obj$$=$obj$$.toObject();$e$jscomp$171_user$$=$req$$.user;if(0>global.configs.admins.indexOf($e$jscomp$171_user$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($obj$$,{action:"delete",_id:$req$$.params.id,user:$e$jscomp$171_user$$}));if($requireOtp$$)try{await permission.verifyOTP($e$jscomp$171_user$$.email,
|
|
276
|
+
$req$$.query["otp-id"],$req$$.query["otp-code"])}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}setImmediate(()=>{permission.hasRight($obj$$.id_app,$req$$.user.email,$module$$,"delete",function($error$jscomp$0$$,$hr$$){if($hr$$)checkReference($model$$,$obj$$,function($error$$){if($error$$)return $res$$.status(400).send({error:ERR_ARISE+($error$$.error||$error$$.message||$error$$),code:ERR_ARISE_CODE});$req$$.obj=$obj$$;$next$$()});else return $res$$.status(403).send({error:$error$jscomp$0$$||
|
|
277
|
+
ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})},{obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})})},function($req$$,$res$$,$next$$){setImmediate(()=>{let $obj$jscomp$1$$=$req$$.obj;$ctrl$$.deleting?$ctrl$$.deleting($req$$.user,$obj$jscomp$1$$,function($e$$,$obj$jscomp$0$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$ctrl$$.dynamicDeleting?$ctrl$$.dynamicDeleting($req$$.user,$obj$jscomp$0$$,function($error$$,$obj$$){if($error$$)return $next$$($error$$);
|
|
278
|
+
$req$$.obj=$obj$$;$next$$()}):($req$$.obj=$obj$jscomp$0$$,$next$$())},{req:$req$$}):$ctrl$$.dynamicDeleting?$ctrl$$.dynamicDeleting($req$$.user,$obj$jscomp$1$$,function($error$$,$obj$$){if($error$$)return $next$$($error$$);$req$$.obj=$obj$$;$next$$()}):($req$$.obj=$obj$jscomp$1$$,$next$$())})},function($req$$,$res$$){setImmediate(()=>{let $obj$jscomp$0$$=$req$$.obj;$ctrl$$.emit("deleting",{...$obj$jscomp$0$$});deletePost($req$$.user,$obj$jscomp$0$$,async $e$jscomp$1$$=>{if($e$jscomp$1$$)return console.error($e$jscomp$1$$),
|
|
279
|
+
$e$jscomp$1$$.error?$res$$.status(400).send($e$jscomp$1$$):$res$$.status(400).send({error:$e$jscomp$1$$.message||$e$jscomp$1$$});if($ctrl$$.dynamicDeletePost)try{await $ctrl$$.dynamicDeletePost($obj$jscomp$0$$)}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$})}$model$$.deleteOne({_id:$obj$jscomp$0$$._id},function($e$jscomp$0$$){if($e$jscomp$0$$)return console.error($e$jscomp$0$$),$e$jscomp$0$$.error?$res$$.status(400).send($e$jscomp$0$$):$res$$.status(400).send({error:$e$jscomp$0$$.message||
|
|
280
|
+
$e$jscomp$0$$});setImmediate(()=>{$ctrl$$.deleteData({...$obj$jscomp$0$$});log.create({id_app:$req$$.user.current_id_app,id_func:$ctrl$$.name,action:"DELETE",data:{id:$obj$jscomp$0$$._id,data:$obj$jscomp$0$$}},$req$$.user.email,$req$$.header("user-agent"),$req$$);link.deleteMany({$or:[{id_a:$obj$jscomp$0$$._id},{id_b:$obj$jscomp$0$$._id}]},function($e$$){$e$$&&console.error("Can't delete links\n"+$e$$)})});setImmediate(()=>{$ctrl$$.emit("deleted",$obj$jscomp$0$$);runWebhooks($ctrl$$,$obj$jscomp$0$$,
|
|
281
|
+
"DELETE")});pushNotification($ctrl$$,$obj$jscomp$0$$,"delete",null,null,{exclude_token:$req$$.query.access_token});setImmediate(()=>{$ctrl$$.deleted?$ctrl$$.deleted($req$$.user,$obj$jscomp$0$$,function($e$$,$obj$$){setImmediate(()=>{if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($obj$$)})}):$res$$.send($obj$jscomp$0$$)})})})})})};
|
|
275
282
|
controller.prototype.history=function(){let $name$$=this.name;this.router.route(this.route_name+"/g/history/:id").get(function($actions_req$$,$res$$){let $query$$={id_func:$name$$,id_app:$actions_req$$.user.current_id_app,"data.id":$actions_req$$.params.id};($actions_req$$=$actions_req$$.query.actions)?($actions_req$$=$actions_req$$.split(","),$query$$.action={$in:$actions_req$$,$ne:"GET"}):$query$$.action={$ne:"GET"};log.find($query$$).lean().exec(function($e$$,$rs$$){setImmediate(()=>$e$$?(console.error($e$$),
|
|
276
283
|
$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})):$res$$.send($rs$$))})})};
|
|
277
284
|
controller.prototype.logs=function(){let $ctrl$$=this,$name$$=this.name;this.router.route(this.route_name+"/g/log/:action").get(function($req$$,$res$$){var $action$jscomp$3_den_ngay$$=$req$$.params.action.toUpperCase();let $query$$={id_func:$name$$,id_app:$req$$.user.current_id_app};"ALL"!==$action$jscomp$3_den_ngay$$&&($query$$.action=$action$jscomp$3_den_ngay$$);if($req$$.query.tu_ngay){var $date_created_tu_ngay$$=moment(new Date($req$$.query.tu_ngay)).startOf("date").toDate();$date_created_tu_ngay$$=
|
|
@@ -2,42 +2,62 @@
|
|
|
2
2
|
require("../libs/redis-cache"),{evalute,prepareParameters,getParameterData}=require("../libs/utils"),utils=require("../libs/utils"),_=require("lodash");
|
|
3
3
|
class controllerRPT{constructor($router$$,$rptId$$,$fecthData$$,$options$$={}){let $module$$=this.module=$rptId$$;this.router=$router$$;this.options=$options$$;this.fecthDataFunc=$fecthData$$;this.getDataFunc=()=>$options$$.stream?$fecthData$$:global.reportMainPool?($req$$,$callback$$)=>{global.reportMainPool.exec({req:{user:$req$$.user,query:$req$$.query,params:$req$$.params},module:$rptId$$.toUpperCase(),configs:JSON.parse(JSON.stringify(configs))},$response$$=>{setImmediate(async()=>{if($response$$.error)return $callback$$($response$$.error);
|
|
4
4
|
let $data$$=$response$$.result;var $func_string$jscomp$1_rptInfo$$=await reportinfo.findOne({code:($req$$.query.report_info_code||$rptId$$).toLowerCase()}).lean();if($func_string$jscomp$1_rptInfo$$&&$func_string$jscomp$1_rptInfo$$.handle_data_expression_server){if(0<=$func_string$jscomp$1_rptInfo$$.handle_data_expression_server.indexOf("async "))return $callback$$("async function is not allow");$func_string$jscomp$1_rptInfo$$=`return (async ()=>{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
$
|
|
12
|
-
$
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
$req$jscomp$0$$.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
$
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
$
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
$
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
$
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
5
|
+
try{
|
|
6
|
+
${$func_string$jscomp$1_rptInfo$$.handle_data_expression_server}
|
|
7
|
+
}catch(e){
|
|
8
|
+
return {error:e}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
})`;try{let $rs$$=await evalute($func_string$jscomp$1_rptInfo$$,{data:$data$$,moment,numeral,condition:$req$$.query,user:$req$$.user,_,utils,getData:getParameterData})();if($rs$$){if($rs$$.error)return console.error($rs$$.error,$func_string$jscomp$1_rptInfo$$),$callback$$($rs$$.error.message||$rs$$.error);$data$$=$rs$$}}catch($e$$){return console.error($e$$,$func_string$jscomp$1_rptInfo$$),$callback$$($e$$.message||$e$$)}}$callback$$(null,$data$$)})})}:($req$$,$callback$$)=>{$fecthData$$($req$$,
|
|
12
|
+
($e$$,$data$$)=>{setImmediate(async()=>{if($e$$)return $callback$$($e$$);var $func_string_rptInfo$$=await reportinfo.findOne({code:($req$$.query.report_info_code||$rptId$$).toLowerCase()}).lean();if($func_string_rptInfo$$&&$func_string_rptInfo$$.handle_data_expression_server){if(0<=$func_string_rptInfo$$.handle_data_expression_server.indexOf("async "))return $callback$$("async function is not allow");$func_string_rptInfo$$=`return (async ()=>{
|
|
13
|
+
try{
|
|
14
|
+
${$func_string_rptInfo$$.handle_data_expression_server}
|
|
15
|
+
}catch(e){
|
|
16
|
+
return {error:e}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
})`;try{let $rs$$=await evalute($func_string_rptInfo$$,{data:$data$$,moment,numeral,condition:$req$$.query,user:$req$$.user,_,utils,getData:getParameterData})();if($rs$$){if($rs$$.error)return console.error($rs$$.error,$func_string_rptInfo$$),$callback$$($rs$$.error.message||$rs$$.error);$data$$=$rs$$}}catch($e$$){return console.error($e$$,$func_string_rptInfo$$),$callback$$($e$$.message||$e$$)}}$callback$$(null,$data$$)})})};global.report_controllers[$rptId$$.toUpperCase()]=this;
|
|
20
|
+
this.base_path=!1===$options$$.require_id_app?"/":"/:id_app/";const $mainRoute$$=async($req$jscomp$0$$,$res$$)=>{let $body$$={};underscore.isObject($req$jscomp$0$$.body)&&($body$$=$req$jscomp$0$$.body);let $query$$={...$req$jscomp$0$$.query,...$body$$};try{$query$$.tu_ngay&&($query$$.tu_ngay=moment(new Date($query$$.tu_ngay)).startOf("date").toDate());$query$$.den_ngay&&($query$$.den_ngay=moment(new Date($query$$.den_ngay)).endOf("date").toDate());$query$$.tu_ngay_kt&&($query$$.tu_ngay_kt=moment(new Date($query$$.tu_ngay_kt)).startOf("date").toDate());
|
|
21
|
+
$query$$.den_ngay_kt&&($query$$.den_ngay_kt=moment(new Date($query$$.den_ngay_kt)).endOf("date").toDate());$req$jscomp$0$$.query=$query$$;const $_query$$=Object.assign({},$query$$);for(let $q$$ in $_query$$)$_query$$[$q$$]||delete $_query$$[$q$$];delete $_query$$.t;delete $_query$$.jsonstream;let $getData$$,$name_cached$$=$rptId$$;!1!==$options$$.require_id_app&&($name_cached$$+=$req$jscomp$0$$.params.id_app);if($options$$.cache&&!$options$$.stream){let $cacheData$$=await getCacheReport.get[$name_cached$$];
|
|
22
|
+
if($cacheData$$&&3E4>(new Date).getTime()-(new Date($cacheData$$.time)).getTime()){let $_data$$=$cacheData$$.data;delete $_query$$.cType;delete $cacheData$$.query.cType;$_data$$&&underscore.isEqual($cacheData$$.query,JSON.parse(JSON.stringify($_query$$)))?(console.log($rptId$$,"get data from cache"),$getData$$=function($req$$,$callback$$){$callback$$(null,$_data$$)}):(setCacheReport($name_cached$$,""),$getData$$=this.getDataFunc())}else setCacheReport($name_cached$$,""),$getData$$=this.getDataFunc()}else setCacheReport($name_cached$$,
|
|
23
|
+
""),$getData$$=this.getDataFunc();let $streamData$$=function(){let $prechunk$$,$_interval$$,$sendHeader_yn$$,$rows$$=[];$getData$$($req$jscomp$0$$,async($error$$,$data$$,$stream$$)=>{if($error$$){if(!$sendHeader_yn$$||!$options$$.stream)return $res$$.status(400).send({error:$error$$.message||$error$$});$_interval$$&&clearInterval($_interval$$);setTimeout(()=>{$res$$.end(JSON.stringify({error:$error$$.toString()}))},1E3)}else if($options$$.stream)switch($stream$$){case "begin":console.log("begin stream");
|
|
24
|
+
$query$$.jsonstream?$res$$.setHeader("Content-Type","application/jsonstream"):($res$$.setHeader("Content-Type","application/json"),$res$$.setHeader("status",200),$res$$.write(""));$sendHeader_yn$$=!0;$_interval$$=setInterval(()=>{console.log("running stream","log");$res$$.write("")},100);break;case "running":console.log("running stream");$res$$.write("");break;case "data":console.log("data stream");underscore.isArray($data$$)?$rows$$=$rows$$.concat($data$$):$rows$$.push($data$$);$query$$.jsonstream?
|
|
25
|
+
$res$$.write(JSON.stringify($data$$)+"$$end%"):$prechunk$$?$res$$.write(","+JSON.stringify($data$$)):$res$$.write(JSON.stringify($data$$));$prechunk$$=$data$$;break;case "end":$_interval$$&&clearInterval($_interval$$),setImmediate(()=>{log.create({id_app:$req$jscomp$0$$.user.current_id_app,id_func:$rptId$$,action:"VIEWRPT",data:{condition:JSON.stringify($query$$)}},$req$jscomp$0$$.user.email,$req$jscomp$0$$.header("user-agent"),$req$jscomp$0$$)}),setImmediate(()=>{setCacheReport($name_cached$$,{data:$rows$$,
|
|
26
|
+
time:new Date,query:$_query$$})}),setTimeout(function(){console.log("end stream");$res$$.end()},1E3)}else setImmediate(()=>{log.create({id_app:$req$jscomp$0$$.user.current_id_app,id_func:$rptId$$,action:"VIEWRPT",data:{condition:JSON.stringify($query$$)}},$req$jscomp$0$$.user.email,$req$jscomp$0$$.header("user-agent"),$req$jscomp$0$$)}),setImmediate(()=>{setCacheReport($name_cached$$,{data:$data$$,time:new Date,query:$_query$$})}),setImmediate(async()=>{let $report$$=$data$$;if(underscore.isArray($report$$)){if($query$$.fields){let $fields$$=
|
|
27
|
+
$query$$.fields.split(",");$report$$=$report$$.map($item$$=>{let $_item$$={};$fields$$.forEach($field$$=>{$_item$$[$field$$]=$item$$[$field$$]});return $_item$$})}if($query$$.group_by&&$query$$.group_by_summary)try{$report$$=await $report$$.asyncGroupBy($query$$.group_by.split(","),$query$$.group_by_summary.split(","))}catch($e$$){return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})}}$res$$.send($report$$)})})};!1===$options$$.require_id_app?
|
|
28
|
+
$streamData$$():permission.hasRight($req$jscomp$0$$.params.id_app,$req$jscomp$0$$.user.email,$module$$,"view",($error$$,$hr$$)=>{$hr$$?$streamData$$():$res$$.status(403).send({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n xem b\u00e1o c\u00e1o n\u00e0y"})},{notNeedRight:$options$$.notNeedRight})}catch($e$$){return $e$$.error?$res$$.status(500).send($e$$):$res$$.status(500).send({error:$e$$.message||$e$$})}};$router$$.route(`${this.base_path+this.module}`).get($mainRoute$$);$router$$.route(`${this.base_path+
|
|
29
|
+
this.module}`).post($mainRoute$$);$router$$.route(`${this.base_path+this.module}/excel`).get(async($req$jscomp$0$$,$res$$)=>{try{for(var $name_cached$jscomp$1_q$$ in $req$jscomp$0$$.query)$req$jscomp$0$$.query[$name_cached$jscomp$1_q$$]||delete $req$jscomp$0$$.query[$name_cached$jscomp$1_q$$];delete $req$jscomp$0$$.query.t;$req$jscomp$0$$.query.tu_ngay&&($req$jscomp$0$$.query.tu_ngay=moment(new Date($req$jscomp$0$$.query.tu_ngay)).startOf("date").toDate());$req$jscomp$0$$.query.den_ngay&&($req$jscomp$0$$.query.den_ngay=
|
|
30
|
+
moment(new Date($req$jscomp$0$$.query.den_ngay)).endOf("date").toDate());$req$jscomp$0$$.query.tu_ngay_kt&&($req$jscomp$0$$.query.tu_ngay_kt=moment(new Date($req$jscomp$0$$.query.tu_ngay_kt)).startOf("date").toDate());$req$jscomp$0$$.query.den_ngay_kt&&($req$jscomp$0$$.query.den_ngay_kt=moment(new Date($req$jscomp$0$$.query.den_ngay_kt)).endOf("date").toDate());$options$$.onExport||($options$$.onExport=function($app$$,$next$$){$next$$()});let $getData$$;$name_cached$jscomp$1_q$$=$rptId$$;!1!==$options$$.require_id_app&&
|
|
31
|
+
($name_cached$jscomp$1_q$$+=$req$jscomp$0$$.params.id_app);let $cacheData$$=await getCacheReport($name_cached$jscomp$1_q$$);if($options$$.stream&&!$cacheData$$)return $res$$.status(400).send({error:"B\u1ea1n ph\u1ea3i ch\u1ea1y b\u00e1o c\u00e1o tr\u01b0\u1edbc khi xu\u1ea5t d\u1eef li\u1ec7u ra excel"});if($cacheData$$){let $_new_query$$={...$req$jscomp$0$$.query};delete $_new_query$$.id_rpt;delete $_new_query$$.jsonstream;delete $_new_query$$.cType;delete $cacheData$$.query.cType;if(underscore.isEqual($cacheData$$.query,
|
|
32
|
+
JSON.parse(JSON.stringify($_new_query$$))))$getData$$=function($req$$,$callback$$){$callback$$(null,$cacheData$$.data)};else{if($options$$.stream)return console.info("D\u1eef li\u1ec7u \u0111\u00e3 cache kh\u00f4ng ph\u00f9 h\u1ee3p v\u1edbi \u0111i\u1ec1u ki\u1ec7n l\u1ecdc m\u1edbi",$cacheData$$.query,$_new_query$$),$res$$.status(400).send({error:"B\u1ea1n ph\u1ea3i ch\u1ea1y b\u00e1o c\u00e1o tr\u01b0\u1edbc khi xu\u1ea5t d\u1eef li\u1ec7u ra excel"});setCacheReport($name_cached$jscomp$1_q$$,"");
|
|
33
|
+
$getData$$=this.getDataFunc()}}else{if($options$$.stream)return console.info("D\u1eef li\u1ec7u \u0111\u00e3 cache h\u1ebft hi\u1ec7u l\u1ef1c."),$res$$.status(400).send({error:"B\u1ea1n ph\u1ea3i ch\u1ea1y b\u00e1o c\u00e1o tr\u01b0\u1edbc khi xu\u1ea5t d\u1eef li\u1ec7u ra excel"});setCacheReport($name_cached$jscomp$1_q$$,"");$getData$$=this.getDataFunc()}let $streamData$$=function($app$$){$getData$$($req$jscomp$0$$,async function($data$jscomp$3_e$$,$data_report_v$$){if($data$jscomp$3_e$$)return console.error($data$jscomp$3_e$$),
|
|
34
|
+
$data$jscomp$3_e$$.error?$res$$.status(400).send($data$jscomp$3_e$$):$res$$.status(400).send({error:$data$jscomp$3_e$$.message||$data$jscomp$3_e$$});log.create({id_app:$req$jscomp$0$$.user.current_id_app,id_func:$rptId$$,action:"EXCELRPT",data:{condition:JSON.stringify($req$jscomp$0$$.query)}},$req$jscomp$0$$.user.email,$req$jscomp$0$$.header("user-agent"),$req$jscomp$0$$);$data$jscomp$3_e$$=$data_report_v$$;underscore.isArray($data_report_v$$)||($data$jscomp$3_e$$=$data_report_v$$.data||$data_report_v$$.rows||
|
|
35
|
+
[$data_report_v$$]);delete $app$$.participants;delete $app$$.create_db_sql;delete $app$$.expire_date;delete $app$$.sale_online;delete $app$$.viettel_user;delete $app$$.viettel_password;delete $app$$.viettel_url_service;delete $app$$.sip_uri;delete $app$$.sip_password;delete $app$$.sip_websocket;delete $app$$.voiip_access_token;delete $app$$.voiip_webhook;delete $app$$.wallet_address;delete $app$$.wallet_token;delete $app$$.owner;delete $app$$.default_password;delete $app$$.email_host;delete $app$$.email_port;
|
|
36
|
+
delete $app$$.email_secure;delete $app$$.email_authMethod;delete $app$$.email_user;delete $app$$.email_pass;delete $app$$.email_name;delete $app$$.ssl_key;delete $app$$.ssl_cert;delete $app$$.ssl_ca;$app$$.company={...$app$$};underscore.extend($app$$,$req$jscomp$0$$.query);delete $app$$.access_token;for(var $func_string$jscomp$2_key$$ in $app$$)$data_report_v$$=$app$$[$func_string$jscomp$2_key$$],underscore.isDate($data_report_v$$)&&($app$$[$func_string$jscomp$2_key$$+"_string"]=moment($data_report_v$$).format("DD/MM/YYYY"));
|
|
37
|
+
$app$$.detail=$app$$.details=$data$jscomp$3_e$$;$app$$.datasource={...$app$$};if($rptConfig$$&&$rptConfig$$.handle_data_expression){if(0<=$rptConfig$$.handle_data_expression.indexOf("async "))return $res$$.status(400).send({error:"async function is not allow"});$func_string$jscomp$2_key$$=`return (async ()=>{
|
|
38
|
+
try{
|
|
39
|
+
${$rptConfig$$.handle_data_expression}
|
|
40
|
+
}catch(e){
|
|
41
|
+
return {error:e}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
})`;try{if($func_string$jscomp$3_rptInfo$jscomp$2_rs$$=await evalute($func_string$jscomp$2_key$$,{data:$app$$,moment,user:$req$jscomp$0$$.user,utils,numeral,getData:getParameterData})()){if($func_string$jscomp$3_rptInfo$jscomp$2_rs$$.error)return $res$$.status(400).send($func_string$jscomp$3_rptInfo$jscomp$2_rs$$.error);$app$$=$func_string$jscomp$3_rptInfo$jscomp$2_rs$$}}catch($e$$){return console.error($e$$,$func_string$jscomp$2_key$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||
|
|
45
|
+
$e$$})}}var $func_string$jscomp$3_rptInfo$jscomp$2_rs$$=await reportinfo.findOne({code:($req$jscomp$0$$.query.report_info_code||$rptId$$).toLowerCase()}).lean();if($func_string$jscomp$3_rptInfo$jscomp$2_rs$$&&$func_string$jscomp$3_rptInfo$jscomp$2_rs$$.handle_data_expression){if(0<=$func_string$jscomp$3_rptInfo$jscomp$2_rs$$.handle_data_expression.indexOf("async "))return $res$$.status(400).send({error:"async function is not allow"});$func_string$jscomp$3_rptInfo$jscomp$2_rs$$=`return (async ()=>{
|
|
46
|
+
try{
|
|
47
|
+
${$func_string$jscomp$3_rptInfo$jscomp$2_rs$$.handle_data_expression}
|
|
48
|
+
}catch(e){
|
|
49
|
+
return {error:e}
|
|
50
|
+
}
|
|
51
|
+
})`;try{const $rs$$=await evalute($func_string$jscomp$3_rptInfo$jscomp$2_rs$$,{data:$data$jscomp$3_e$$,moment,user:$req$jscomp$0$$.user,utils,numeral,getData:getParameterData})();if($rs$$){if($rs$$.error)return console.error($rs$$.error,$func_string$jscomp$3_rptInfo$jscomp$2_rs$$),$res$$.status(400).send({error:$rs$$.error.message||$rs$$.error});$app$$.detail=$app$$.details=$rs$$}}catch($e$$){return console.error($e$$,$func_string$jscomp$3_rptInfo$jscomp$2_rs$$),$res$$.status(400).send({error:$e$$.message||
|
|
52
|
+
$e$$})}}else $app$$.detail.forEach($r$$=>{for(let $_key$$ in $r$$){let $_v$$=$r$$[$_key$$];if($_v$$&&0<=$_key$$.indexOf("ngay")||0<=$_key$$.indexOf("date"))try{let $d$$=moment($_v$$);$d$$.isValid()&&($r$$[`${$_key$$}`]=$d$$.toDate(),$r$$[`${$_key$$}_string`]=$d$$.format("DD/MM/YYYY"))}catch($e$$){console.error("Error convert to date",$_v$$,$e$$)}}});$rptConfig$$&&$rptConfig$$.parameters&&await prepareParameters($rptConfig$$.parameters,$app$$,$app$$);if($req$jscomp$0$$.query.json)$res$$.json($app$$);
|
|
53
|
+
else $options$$.onExport($app$$,function(){setImmediate(()=>{if($req$jscomp$0$$.query.print)htmlReport($html_template$$,$app$$).then($rs$$=>$res$$.send($rs$$),$error$$=>{$res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$})});else{let $ext$$=$templatePath$$.split(".").pop();"xlsx"===$ext$$?excelReport($templatePath$$,$app$$,function($error$$,$result$$){if($error$$)return console.error("Error export to excel",$error$$),$res$$.status(400).send({error:$error$$.message||$error$$.error||
|
|
54
|
+
$error$$});$res$$.setHeader("Content-Type","application/vnd.openxmlformats");$res$$.setHeader("Content-Disposition","attachment; filename="+$rptId$$+".xlsx");$res$$.end($result$$,"binary")},{timezone:configs.timezone||"Asia/Ho_Chi_Minh"}):textReport($templatePath$$,$app$$,function($error$$,$result$$){if($error$$)return console.error("Error export to text",$error$$),$res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$});"docx"===$ext$$?($res$$.setHeader("Content-Type","application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
|
|
55
|
+
$res$$.setHeader("Content-Disposition","attachment; filename="+$rptId$$+".docx"),$res$$.write($result$$,"binary"),$res$$.end(null,"binary")):$res$$.send($result$$)})}})})})},$id_rpt$$=$req$jscomp$0$$.query.id_rpt,$dir_root_templates$$=configs.paths.templates||__dirname,$templatePath$$,$rptConfig$$,$html_template$$;(new Promise(($resolve$$,$reject$$)=>{$rptConfig$$=$templatePath$$=void 0;if($id_rpt$$&&global.mongoose.Types.ObjectId.isValid($id_rpt$$))rpt.findOne({_id:$id_rpt$$}).lean().exec(async function($error$$,
|
|
56
|
+
$r$$){if($error$$||!$r$$)return console.error("Not found excel template",$id_rpt$$,$error$$),$reject$$($error$$||"Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu");if($req$jscomp$0$$.query.print)$html_template$$=$r$$.html_template;else{if(0<$r$$.file_mau_in.indexOf("/file/download")){$error$$=$r$$.file_mau_in.split("/").pop();const $file$$=global.getModel("file");try{const $_fileMauIn$$=await $file$$.findOne({_id:$error$$}).lean();if(!$_fileMauIn$$)return $reject$$("Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu");
|
|
57
|
+
let $file_name$$=$_fileMauIn$$.file.name,$root$$=configs.paths.uploads;$root$$||($root$$=__dirname,$root$$=path.dirname($root$$),$root$$=path.join($root$$,"uploads"));$templatePath$$=path.join($root$$,$file_name$$)}catch($e$$){return $reject$$($e$$.message||"Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu")}}else $templatePath$$=path.dirname($dir_root_templates$$)+$r$$.file_mau_in;fs.existsSync($templatePath$$)||(console.log("file template not found",$templatePath$$),$templatePath$$=`${path.dirname($dir_root_templates$$)}/templates/excels/reports/${$module$$}.xlsx`);
|
|
58
|
+
fs.existsSync($templatePath$$)||($templatePath$$=`${path.dirname(__dirname)}/templates/excels/reports/${$module$$}.xlsx`);if(!fs.existsSync($templatePath$$))return $reject$$("M\u1eabu kh\u00f4ng t\u1ed3n t\u1ea1i")}$rptConfig$$=$r$$;return $resolve$$($templatePath$$,$html_template$$)});else if($templatePath$$=`${path.dirname($dir_root_templates$$)}/templates/excels/reports/${$module$$}.xlsx`,fs.existsSync($templatePath$$)||($templatePath$$=`${path.dirname(__dirname)}/templates/excels/reports/${$module$$}.xlsx`),
|
|
59
|
+
!fs.existsSync($templatePath$$))return $reject$$("M\u1eabu excel kh\u00f4ng t\u1ed3n t\u1ea1i")})).then(()=>{!1===$options$$.require_id_app?$streamData$$({}):permission.hasRight($req$jscomp$0$$.params.id_app,$req$jscomp$0$$.user.email,$module$$,"view",function($error$$,$hr$$,$app$$){$hr$$?$streamData$$({...$app$$}):$res$$.status(403).send({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n xu\u1ea5t excel b\u00e1o c\u00e1o n\u00e0y"})},{notNeedRight:$options$$.notNeedRight})}).catch($e$$=>{console.error($e$$);
|
|
60
|
+
return $e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})})}catch($e$$){return $e$$.error?$res$$.status(500).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})}})}getData($req$$,$callback$$){setImmediate(()=>{try{this.fecthDataFunc($req$$,$callback$$)}catch($e$$){console.error($e$$),$callback$$($e$$.message)}})}createRoute($routeName$$,$callback$$,$_options$$={method:"GET"}){$_options$$.method=$_options$$.method?$_options$$.method.toUpperCase():
|
|
61
|
+
"GET";const $self$$=this;let $r$$=function($req$$,$res$$){setImmediate(()=>{!1===$self$$.options.require_id_app?$callback$$($req$$,function($e$$,$rs$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)},$res$$):permission.hasRight($req$$.params.id_app,$req$$.user.email,$self$$.module,"view",function($error$$,$hr$$){$hr$$?$callback$$($req$$,function($e$$,$rs$$){if($e$$)return console.error($e$$),$e$$.error?
|
|
62
|
+
$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)},$res$$):$res$$.status(403).send({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n xem b\u00e1o c\u00e1o n\u00e0y"})},{notNeedRight:$self$$.options.notNeedRight||$_options$$.notNeedRight})})};"DELETE"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).delete($r$$):"POST"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).post($r$$):
|
|
63
|
+
"PUT"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).put($r$$):this.router.route(`${this.base_path+this.module}/${$routeName$$}`).get($r$$)}}module.exports=controllerRPT;
|
|
@@ -41,7 +41,7 @@ break;case "profit-sharing":$receiver$$===$owner$$&&($id_invest_noti_sender$jsco
|
|
|
41
41
|
id_product:$events$$["at.idProduct"][$id$jscomp$2_index$jscomp$17_title_token$$],amount:$events$$["at.amount"][$id$jscomp$2_index$jscomp$17_title_token$$],denom:$events$$["at.denom"][$id$jscomp$2_index$jscomp$17_title_token$$],token:$id_invest_noti_sender$jscomp$1_token$$}});break;case "profit-sharing-error":$receiver$$===$owner$$&&($id_invest_noti_sender$jscomp$1_token$$={title:"Kh\u00f4ng th\u1ec3 chia l\u1ee3i nhu\u1eadn",receiver:$receiver$$,body:$memo$$,data:{key:"profit-sharing-error"+$timestamp$$,
|
|
42
42
|
id_profit_sharing:$events$$["at.idProfitSharing"][$id$jscomp$2_index$jscomp$17_title_token$$],id_product:$events$$["at.idProduct"][$id$jscomp$2_index$jscomp$17_title_token$$],amount:$events$$["at.amount"][$id$jscomp$2_index$jscomp$17_title_token$$],denom:$events$$["at.denom"][$id$jscomp$2_index$jscomp$17_title_token$$],token:$events$$["at.token"][$id$jscomp$2_index$jscomp$17_title_token$$]}});break;case "invest-expired":if($receiver$$===$owner$$){let $id_invest$$=Number($events$$["at.idInvestment"][$id$jscomp$2_index$jscomp$17_title_token$$]),
|
|
43
43
|
$token$$=$events$$["at.token"][$id$jscomp$2_index$jscomp$17_title_token$$];global.getModel("assinvestment").updateOne({id:$id_invest$$},{trang_thai:"5"}).then($rs$$=>{console.log("updated expired assinvestment",$id_invest$$,$rs$$)});$token$$&&global.getModel("asssell").updateOne({token:$token$$},{trang_thai:"5"}).then($rs$$=>{console.log("updated expired asssell for token",$token$$,$rs$$)});$id_invest_noti_sender$jscomp$1_token$$={title:"Kho\u1ea3n \u0111\u1ea7u t\u01b0 \u0111\u00e1o h\u1ea1n",receiver:$receiver$$,
|
|
44
|
-
body:$memo$$||`Kho\u1ea3n \u0111\u1ea7u t\u01b0 ${$token$$} \u0111\u00e3 \u0111\u00e1o h\u1ea1n. Ti\u1ec1n g\u1ed1c v\u00e0 l\u00e3i \u0111\u00e3 \u0111\u01b0\u1ee3c chuy\u1ec3n v\u00e0o v\u00ed c\u1ee7a b\u1ea1n`,data:{key:"invest-expired:"+$id_invest$$+$timestamp$$,id_invest:$id_invest$$,token:$token$$}}}break;case "exchange":$id_invest_noti_sender$jscomp$1_token$$={title:"Giao d\u1ecbch c\u1ee7a b\u1ea1n \u0111\u00e3 kh\u1edbp l\u1ec7nh",receiver:$receiver$$,body:$memo$$||`\u0110\u00e3 kh\u1edbp l\u1ec7nh giao d\u1ecbch gi\u1eefa tin mua s\u1ed1 ${$events$$["at.idNeedToBuy"][$id$jscomp$2_index$jscomp$17_title_token$$]} v\u00e0 tin b\u00e1n s\u1ed1 ${$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$]}. V\u00ed c\u1ee7a b\u1ea1n \u0111\u00e3 \u0111\u01b0\u1ee3c c\u1eadp nh\u1eadt s\u1ed1 d\u01b0`,
|
|
44
|
+
body:$memo$$||`Kho\u1ea3n \u0111\u1ea7u t\u01b0 ${$token$$} \u0111\u00e3 \u0111\u00e1o h\u1ea1n. Ti\u1ec1n g\u1ed1c v\u00e0 l\u00e3i \u0111\u00e3 \u0111\u01b0\u1ee3c chuy\u1ec3n v\u00e0o v\u00ed c\u1ee7a b\u1ea1n`,data:{key:"invest-expired:"+$id_invest$$+$timestamp$$,id_invest:$id_invest$$,token:$token$$}}}break;case "exchange":$id_invest_noti_sender$jscomp$1_token$$={title:"Giao d\u1ecbch c\u1ee7a b\u1ea1n \u0111\u00e3 kh\u1edbp l\u1ec7nh",receiver:$receiver$$,create_notify:!1,body:$memo$$||`\u0110\u00e3 kh\u1edbp l\u1ec7nh giao d\u1ecbch gi\u1eefa tin mua s\u1ed1 ${$events$$["at.idNeedToBuy"][$id$jscomp$2_index$jscomp$17_title_token$$]} v\u00e0 tin b\u00e1n s\u1ed1 ${$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$]}. V\u00ed c\u1ee7a b\u1ea1n \u0111\u00e3 \u0111\u01b0\u1ee3c c\u1eadp nh\u1eadt s\u1ed1 d\u01b0`,
|
|
45
45
|
data:{key:`exchange:${$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$]}-${$events$$["at.idNeedToBuy"][$id$jscomp$2_index$jscomp$17_title_token$$]}`+$timestamp$$,id_sell:$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$],id_need_to_buy:$events$$["at.idNeedToBuy"][$id$jscomp$2_index$jscomp$17_title_token$$]}};break;default:console.log("don't implement action",$_u_action$$)}$id_invest_noti_sender$jscomp$1_token$$&&($id_invest_noti_sender$jscomp$1_token$$.user=$u$$.user_created,
|
|
46
46
|
$id_invest_noti_sender$jscomp$1_token$$.data.key=$id_invest_noti_sender$jscomp$1_token$$.user+$id_invest_noti_sender$jscomp$1_token$$.data.key,notificationPool[$id_invest_noti_sender$jscomp$1_token$$.data.key]=$id_invest_noti_sender$jscomp$1_token$$)})})},WS=require("ws");let notiInterval,connectSocket=!1;
|
|
47
47
|
const setupSocket=()=>{if(!connectSocket){var $ws$$=new WS(configs.BLOCKCHAIN_SOCKET);$ws$$.on("error",$e$$=>{connectSocket=!1;console.error("Can't connect to blockchain socket server",$e$$.message);notiInterval&&(clearInterval(notiInterval),notiInterval=null)});$ws$$.on("close",()=>{connectSocket=!1;notiInterval&&(clearInterval(notiInterval),notiInterval=null);setTimeout(()=>{setupSocket()},5E3)});$ws$$.on("open",()=>{console.log("connected to blockchain socket");connectSocket=!0;$ws$$.send(JSON.stringify({jsonrpc:"2.0",
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Date.prototype.nextDay=function($days_of_week_distances$$){if(!$days_of_week_distances$$||0===$days_of_week_distances$$.length)return null;let $d$$=new Date(this.getTime());$days_of_week_distances$$=$days_of_week_distances$$.map($day_of_week_distance$$=>{($day_of_week_distance$$=($day_of_week_distance$$+7-$d$$.getDay())%7)||($day_of_week_distance$$=7);return $day_of_week_distance$$}).sort(($a$$,$b$$)=>$a$$-$b$$);return 0<$days_of_week_distances$$.length?($d$$.setDate($d$$.getDate()+$days_of_week_distances$$[0]),
|
|
3
3
|
$d$$):null};Array.prototype.csum=function($field$$,$condition$$,$exclude$$){return _.reduce(this,function($sum$$,$row_v$$){if(!_.isMatch($row_v$$,$condition$$)||$exclude$$&&_.isMatch($row_v$$,$exclude$$))return $sum$$;$row_v$$=Number($row_v$$[$field$$]||0)||0;isNaN($row_v$$)&&($row_v$$=0);return $sum$$+$row_v$$},0)};
|
|
4
4
|
Array.prototype.cmax=function($field$$,$condition$$){return _.reduce(this,function($max$$,$row$$){let $v$$=$row$$[$field$$];return _.isMatch($row$$,$condition$$)&&!_.isUndefined($v$$)?$max$$?_.isNumber($v$$)?$max$$>$v$$?$max$$:$v$$:_.isString($v$$)?1==$v$$.localeCompare($max$$)?$v$$:$max$$:$v$$:$v$$:$max$$},null)};Array.prototype.reg=function(){if(0==this.length)return"";let $tk$$;this.forEach(function($t$$){""!==$t$$&&($tk$$=$tk$$?$tk$$+"|^"+$t$$:"^"+$t$$)});return $tk$$};
|
|
5
|
-
Array.prototype.groupBy=function($fieldkey$$,$fieldsums$$,$fn$$,$options$$){const $self$$=this;setImmediate(()=>{const $groups$$=_.groupBy($self$$,function($item$$){let $key$$="";if(_.isArray($fieldkey$$)){for(let $k$$ of $fieldkey$$){let $_key$$=$item$$[$k$$];_.isDate($_key$$)&&($_key$$=moment($_key$$).format("YYYY-MM-DD"));!1===$_key$$&&($_key$$="false");$_key$$||($_key$$="");$key$$=$key$$?$key$$+"_"+$_key
|
|
6
|
-
_.isDate($key$$)&&($key$$=moment($key$$).format("YYYY-MM-DD")),!1===$key$$&&($key$$="false"),$key$$||($key$$="__");return $key$$});async.map(_.keys($groups$$),function($key$$,$callback$$){setImmediate(()=>{let $value$$=$groups$$[$key$$],$r$$={};if(_.isArray($fieldkey$$)&&0<$value$$.length)for(let $k$$ of $fieldkey$$)$r$$[$k$$]=$value$$[0][$k$$],$r$$[$k$$]||0==$r$$[$k$$]||0==$r$$[$k$$]||($r$$[$k$$]="");else $r$$[$fieldkey$$]=$key$$;$fieldsums$$.forEach(function($f$$){_.isObject($f$$)
|
|
7
|
-
$value$$.map($v$$=>$v$$[$f$$.value]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0):$r$$[$f$$]=$value$$.map($v$$=>$v$$[$f$$]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$options$$&&$options$$.fieldmaxs&&$options$$.fieldmaxs.forEach(function($f$$){_.isObject($f$$)?$r$$[$f$$.name]=$value$$.cmax($f$$.value):$r$$[$f$$]=$value$$.cmax($f$$)});$callback$$(null,$r$$)})},function($error$$,$result$$){if($error$$)return $fn$$($error$$);$fn$$(null,$result$$)})})};
|
|
5
|
+
Array.prototype.groupBy=function($fieldkey$$,$fieldsums$$,$fn$$,$options$$){const $self$$=this;setImmediate(()=>{const $groups$$=_.groupBy($self$$,function($item$$){let $key$$="";if(_.isArray($fieldkey$$)){for(let $k$$ of $fieldkey$$){let $_key$$=$item$$[$k$$];_.isDate($_key$$)&&($_key$$=moment($_key$$).format("YYYY-MM-DD"));!1===$_key$$&&($_key$$="false");$_key$$||0==$_key$$||($_key$$="");$key$$=$key$$||0==$key$$?$key$$+"_"+$_key$$.toString():$_key$$}_.isString($key$$)&&($key$$=$key$$.trim());$key$$||
|
|
6
|
+
($key$$="ZZZ")}else $key$$=$item$$[$fieldkey$$],_.isDate($key$$)&&($key$$=moment($key$$).format("YYYY-MM-DD")),!1===$key$$&&($key$$="false"),$key$$||0==$key$$||($key$$="__");return $key$$});async.map(_.keys($groups$$),function($key$$,$callback$$){setImmediate(()=>{let $value$$=$groups$$[$key$$],$r$$={};if(_.isArray($fieldkey$$)&&0<$value$$.length)for(let $k$$ of $fieldkey$$)$r$$[$k$$]=$value$$[0][$k$$],$r$$[$k$$]||0==$r$$[$k$$]||0==$r$$[$k$$]||($r$$[$k$$]="");else $r$$[$fieldkey$$]=$key$$;$fieldsums$$.forEach(function($f$$){_.isObject($f$$)?
|
|
7
|
+
$r$$[$f$$.name]=$value$$.map($v$$=>$v$$[$f$$.value]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0):$r$$[$f$$]=$value$$.map($v$$=>$v$$[$f$$]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$options$$&&$options$$.fieldmaxs&&$options$$.fieldmaxs.forEach(function($f$$){_.isObject($f$$)?$r$$[$f$$.name]=$value$$.cmax($f$$.value):$r$$[$f$$]=$value$$.cmax($f$$)});$callback$$(null,$r$$)})},function($error$$,$result$$){if($error$$)return $fn$$($error$$);$fn$$(null,$result$$)})})};
|
|
8
8
|
Array.prototype.asyncGroupBy=function($fieldkey$$,$fieldsums$$,$options$$){let $_this$$=this;return new Promise(($resolve$$,$reject$$)=>{$_this$$.groupBy($fieldkey$$,$fieldsums$$,($error$$,$rs$$)=>{if($error$$)return $reject$$($error$$);$resolve$$($rs$$)},$options$$)})};
|
|
9
9
|
Array.prototype.joinModel=function($id_app$$,$model$$,$joinFields$$,$fn$$){_.isArray($joinFields$$)&&$joinFields$$.forEach($join$$=>{if($join$$.where){let $_where$$={};for(let $key$$ in $join$$.where)$_where$$[$join$$.where[$key$$]]=$key$$;$join$$.where=$_where$$}});_.isArray($id_app$$)&&_.isArray($model$$)&&$model$$.forEach($join$$=>{if($join$$.where){let $_where$$={};for(let $key$$ in $join$$.where)$_where$$[$join$$.where[$key$$]]=$key$$;$join$$.where=$_where$$}});this.joinModel2($id_app$$,$model$$,
|
|
10
10
|
$joinFields$$,$fn$$)};const getFields=$fields$$=>{_.isArray($fields$$)||($fields$$=[$fields$$]);return $fields$$=$fields$$.map(function($map$$){if(_.isObject($map$$)){var $rs$jscomp$1_value$$=$map$$.value;if($map$$.name&&$rs$jscomp$1_value$$)return{[$rs$jscomp$1_value$$]:1};$rs$jscomp$1_value$$={};for(let $key$$ in $map$$)$rs$jscomp$1_value$$[$map$$[$key$$]]=1;return $rs$jscomp$1_value$$}return{[$map$$]:1}}).reduce(($a$$,$b$$)=>({...$a$$,...$b$$}),{})};
|
|
@@ -398,9 +398,17 @@ const post = (_listInfo,obj)=>{
|
|
|
398
398
|
return Promise.all((_listInfo.postinfos||[]).filter(info=>info.model && info.script && info.condition).map(postInfo=>{
|
|
399
399
|
return (async ()=>{
|
|
400
400
|
let script = `return (async ()=>{
|
|
401
|
-
|
|
401
|
+
try{
|
|
402
|
+
${postInfo.script}
|
|
403
|
+
}catch(e){
|
|
404
|
+
console.error(e,${postInfo.script})
|
|
405
|
+
return {error:e}
|
|
406
|
+
}
|
|
402
407
|
})()`
|
|
403
408
|
let data = await evalute(script,{master:{...obj},data:{...obj},moment});
|
|
409
|
+
if(data && data.error){
|
|
410
|
+
throw data.error
|
|
411
|
+
}
|
|
404
412
|
//console.log("post dynamic",postInfo.model,data);
|
|
405
413
|
return new Promise((resolve,reject)=>{
|
|
406
414
|
if(postInfo.model==="socai"){
|
|
@@ -472,13 +480,22 @@ const dynamicCreating = async (listInfo,user,obj,next)=>{
|
|
|
472
480
|
async.parallel([
|
|
473
481
|
(next)=>{
|
|
474
482
|
const func_body = `(async ()=>{
|
|
475
|
-
|
|
483
|
+
try{
|
|
484
|
+
${_listInfo.handle_oncreating_server}
|
|
485
|
+
}catch(e){
|
|
486
|
+
next(e);
|
|
487
|
+
}
|
|
488
|
+
|
|
476
489
|
})();`
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
490
|
+
setImmediate(async ()=>{
|
|
491
|
+
try{
|
|
492
|
+
evalute(func_body,{obj,user,getLib:global.getLib,getModel:global.getModel,utils,async,controller,controllers:global.controllers,joinModel2,next})
|
|
493
|
+
}catch(e){
|
|
494
|
+
console.error("error dynamic create",_listInfo.handle_oncreating_server,e)
|
|
495
|
+
next(e);
|
|
496
|
+
}
|
|
497
|
+
})
|
|
498
|
+
|
|
482
499
|
}
|
|
483
500
|
],(e,rs)=>{
|
|
484
501
|
if(e){
|
|
@@ -504,11 +521,16 @@ const dynamicCreated = async (_listInfo,user,obj,next)=>{
|
|
|
504
521
|
async.parallel([
|
|
505
522
|
(next)=>{
|
|
506
523
|
const func_body = `(async ()=>{
|
|
507
|
-
|
|
524
|
+
try{
|
|
525
|
+
${_listInfo.handle_oncreated_server}
|
|
526
|
+
}catch(e){
|
|
527
|
+
next(e);
|
|
528
|
+
}
|
|
508
529
|
})();`
|
|
509
530
|
try{
|
|
510
531
|
evalute(func_body,{obj,user,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,async,joinModel2,next})
|
|
511
532
|
}catch(e){
|
|
533
|
+
console.error("error dynamic created",_listInfo.handle_oncreated_server,e)
|
|
512
534
|
next(e)
|
|
513
535
|
}
|
|
514
536
|
|
|
@@ -551,11 +573,17 @@ const dynamicUpdating = async (listInfo,user,data,obj,next)=>{
|
|
|
551
573
|
async.parallel([
|
|
552
574
|
(next)=>{
|
|
553
575
|
const func_body = `(async ()=>{
|
|
554
|
-
|
|
576
|
+
try{
|
|
577
|
+
${_listInfo.handle_onupdating_server}
|
|
578
|
+
}catch(e){
|
|
579
|
+
next(e);
|
|
580
|
+
}
|
|
581
|
+
|
|
555
582
|
})();`
|
|
556
583
|
try{
|
|
557
584
|
evalute(func_body,{data,obj,user,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,async,joinModel2,next})
|
|
558
585
|
}catch(e){
|
|
586
|
+
console.error("error dynamic update",_listInfo.handle_onupdating_server,e)
|
|
559
587
|
next(e)
|
|
560
588
|
}
|
|
561
589
|
|
|
@@ -585,11 +613,16 @@ const dynamicUpdated = async (_listInfo,user,obj,next)=>{
|
|
|
585
613
|
async.parallel([
|
|
586
614
|
(next)=>{
|
|
587
615
|
const func_body = `(async ()=>{
|
|
588
|
-
|
|
616
|
+
try{
|
|
617
|
+
${_listInfo.handle_onupdated_server}
|
|
618
|
+
}catch(e){
|
|
619
|
+
next(e)
|
|
620
|
+
}
|
|
589
621
|
})();`
|
|
590
622
|
try{
|
|
591
623
|
evalute(func_body,{obj,user,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,async,joinModel2,next})
|
|
592
624
|
}catch(e){
|
|
625
|
+
console.error("error dynamic updated",_listInfo.handle_onupdated_server,e)
|
|
593
626
|
next(e)
|
|
594
627
|
}
|
|
595
628
|
|
|
@@ -631,11 +664,16 @@ const dynamicDeleting = async (listInfo,user,obj,next)=>{
|
|
|
631
664
|
async.parallel([
|
|
632
665
|
(next)=>{
|
|
633
666
|
const func_body = `(async ()=>{
|
|
634
|
-
|
|
667
|
+
try{
|
|
668
|
+
${_listInfo.handle_ondeleting_server}
|
|
669
|
+
}catch(e){
|
|
670
|
+
next(e);
|
|
671
|
+
}
|
|
635
672
|
})();`
|
|
636
673
|
try{
|
|
637
674
|
evalute(func_body,{obj,user,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,async,joinModel2,next})
|
|
638
675
|
}catch(e){
|
|
676
|
+
console.error("error dynamic delete",_listInfo.handle_ondeleting_server,e)
|
|
639
677
|
next(e)
|
|
640
678
|
}
|
|
641
679
|
|
|
@@ -669,9 +707,19 @@ const onView = async (obj,user,items,next)=>{
|
|
|
669
707
|
async.parallel([
|
|
670
708
|
(next)=>{
|
|
671
709
|
const func_body = `(async ()=>{
|
|
672
|
-
|
|
710
|
+
try{
|
|
711
|
+
${obj.handle_view_server}
|
|
712
|
+
}catch(e){
|
|
713
|
+
next(e);
|
|
714
|
+
}
|
|
715
|
+
|
|
673
716
|
})();`
|
|
674
|
-
|
|
717
|
+
try{
|
|
718
|
+
evalute(func_body,{items,user,getLib:global.getLib,utils,next,async,joinModel2})
|
|
719
|
+
}catch(e){
|
|
720
|
+
console.error("error dynamic view",obj.handle_view_serve,e)
|
|
721
|
+
}
|
|
722
|
+
|
|
675
723
|
}
|
|
676
724
|
],(e,rs)=>{
|
|
677
725
|
if(e) console.error(e);
|
|
@@ -773,7 +821,7 @@ model.createController = (router,_listInfo)=>{
|
|
|
773
821
|
}
|
|
774
822
|
sort = evalute(func_string);
|
|
775
823
|
}catch(e){
|
|
776
|
-
console.error(e);
|
|
824
|
+
console.error("error create sort", _listInfo.sort_by,e);
|
|
777
825
|
}
|
|
778
826
|
}else{
|
|
779
827
|
sort = _listInfo.sort_by.split(",").reduce((sort,b)=>sort[b]=1,{})
|
|
@@ -27,9 +27,9 @@ $app$$.ma_hoa_don||"1",templateCode:$ct$$.ky_hieu_hoa_don||$app$$.ky_hieu_hoa_do
|
|
|
27
27
|
$kh$$.dien_thoai||"",buyerFaxNumber:"",buyerEmail:$kh$$.email||"",buyerBankName:"",buyerBankAccount:"",buyerIdType:"",buyerIdNo:"",buyerCode:"",buyerBirthDay:""},sellerInfo:{sellerLegalName:$app$$.name,sellerTaxCode:$app$$.ma_so_thue,sellerAddressLine:$app$$.address,sellerPhoneNumber:$app$$.phone||"",sellerEmail:$app$$.email||"",sellerBankName:$app$$.ten_ngan_hang||"",sellerBankAccount:$app$$.tai_khoan_ngan_hang||""},itemInfo:$ct$$.details.map(($detail$$,$index$$)=>{let $thue_suat$$=($detail$$.ma_thue?
|
|
28
28
|
$detail$$.thue_suat:$ct$$.thue_suat)||0;return{lineNumber:$index$$+1,selection:0>$detail$$.tien_nt?3:1,itemCode:($index$$+1).toString(),itemName:$detail$$.dien_giai,unitName:0>$detail$$.tien_nt?"":$detail$$.ma_dvt,itemNote:"",unitPrice:0>$detail$$.tien_nt?void 0:$detail$$.gia_ban_nt,quantity:0>$detail$$.tien_nt?void 0:$detail$$.sl_xuat,itemTotalAmountWithoutTax:Math.abs($detail$$.tien_nt),discount:$detail$$.ty_le_ck,itemDiscount:Math.abs($detail$$.tien_ck_nt),itemTotalAmountAfterDiscount:Math.abs($detail$$.tien_nt-
|
|
29
29
|
$detail$$.tien_ck_nt),taxPercentage:"KT"===($detail$$.ma_thue||$ct$$.ma_thue)?0>$detail$$.tien_nt?void 0:-2:$thue_suat$$,taxAmount:Math.abs($detail$$.tien_thue_nt),itemTotalAmountWithTax:Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt+$detail$$.tien_thue_nt),customTaxAmount:"0",batchNo:"",expDate:""}}),summarizeInfo:{sumOfTotalLineAmountWithoutTax:$t_tien_hang$$,discountAmount:$t_ck$$,settlementDiscountAmount:$t_ck$$,totalAmountWithoutTax:$t_tien$$,totalTaxAmount:$t_thue$$,totalAmountWithTax:$t_tien$$+
|
|
30
|
-
$t_thue
|
|
31
|
-
|
|
32
|
-
$
|
|
33
|
-
`${$app$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
$t_thue$$},taxBreakdowns:$taxBreakdowns$$,payments:[{paymentMethodName:$ct$$.hinh_thuc_tt||"TM"}],extAttribute:[],deliveryInfo:{},metadata:[]};$ct$$.ngay_hd||($ct$$.ngay_hd=new Date);let $headers$$,$url$$,$viettel_token$$,$auth$$={username:$app$$.viettel_user.trim(),password:$app$$.viettel_password.trim()};if("1"!=$app$$.viettel_version){$data$jscomp$0$$.generalInvoiceInfo.invoiceIssuedDate=(new Date($ct$$.ngay_hd)).getTime();let $url_token$$=`${$app$$.viettel_url_service.trim()}/auth/login`;$url$$=
|
|
31
|
+
$app$$.viettel_direct_issue?`${$app$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createInvoice/${$app$$.ma_so_thue.trim()}`:`${$app$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app$$.ma_so_thue.trim()}`;try{$viettel_token$$=(await axios({method:"post",url:$url_token$$,data:$auth$$})).data.access_token}catch($e$$){console.error("error when get token viettel",$auth$$,$url_token$$);let $msg_e$$=
|
|
32
|
+
$e$$.response?$e$$.response.data:$e$$.message;$msg_e$$&&$msg_e$$.detail&&($msg_e$$.message=$msg_e$$.detail);return $next$$($msg_e$$||$e$$.message||$e$$.error||$e$$)}$headers$$={Cookie:`"access_token":"${$viettel_token$$}"; access_token=${$viettel_token$$}; session_token=${$viettel_token$$}`,"Content-Type":"application/json"};$auth$$=void 0}else $data$jscomp$0$$.generalInvoiceInfo.invoiceIssuedDate=Moment($ct$$.ngay_hd).format("YYYY-MM-DD"),$url$$=$app$$.viettel_direct_issue?`${$app$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/createInvoice/${$app$$.ma_so_thue.trim()}`:
|
|
33
|
+
`${$app$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app$$.ma_so_thue.trim()}`;console.log("post to viettel...");axios({method:"post",url:$url$$,data:"1"!=$app$$.viettel_version?JSON.stringify($data$jscomp$0$$):$data$jscomp$0$$,auth:$auth$$,headers:$headers$$}).then(async $data$$=>{$data$$=$data$$.data;console.error("result data",$data$$);if(!$data$$)return $next$$("Kh\u00f4ng th\u1ec3 xu\u1ea5t ho\u00e1 \u0111\u01a1n");if($data$$.errorCode)return $next$$($data$$.description);
|
|
34
|
+
$ct$$.result_export_einvoice=$data$$;$ct$$.so_hd=$ct$$.result_export_einvoice.result.invoiceNo;await model.findOneAndUpdate({_id:$ct$$._id},$ct$$);$next$$(null,$data$$)}).catch($e$$=>{console.error("error when export invocie viettel",$e$$.response);let $msg_e$$=$e$$.response?$e$$.response.data:$e$$.message;$msg_e$$.data&&($msg_e$$.message=$msg_e$$.data);$msg_e$$.detail&&($msg_e$$.message=$msg_e$$.detail);$next$$($msg_e$$||$e$$.message||$e$$.error||$e$$)})}catch($e$$){console.log($e$$),$next$$($e$$.message)}},
|
|
35
|
+
{method:"GET"})};
|
|
@@ -37,9 +37,9 @@ $app_msg_e$$.ma_hoa_don||"1",templateCode:$ct$$.ky_hieu_hoa_don||$app_msg_e$$.ky
|
|
|
37
37
|
buyerCountryCode:"",buyerPhoneNumber:$ct$$.dien_thoai||$data$jscomp$0$$.dien_thoai||"",buyerFaxNumber:"",buyerEmail:$data$jscomp$0$$.email||"",buyerBankName:"",buyerBankAccount:"",buyerIdType:"",buyerIdNo:"",buyerCode:"",buyerBirthDay:""},sellerInfo:{sellerLegalName:$app_msg_e$$.name,sellerTaxCode:$app_msg_e$$.ma_so_thue,sellerAddressLine:$app_msg_e$$.address,sellerPhoneNumber:$app_msg_e$$.phone||"",sellerEmail:$app_msg_e$$.email||"",sellerBankName:$app_msg_e$$.ten_ngan_hang||"",sellerBankAccount:$app_msg_e$$.tai_khoan_ngan_hang||
|
|
38
38
|
""},itemInfo:$ct$$.details.map(($detail$$,$index$$)=>{let $thue_suat$$=($detail$$.ma_thue?$detail$$.thue_suat:$ct$$.thue_suat)||0;return{lineNumber:$index$$+1,selection:0>$detail$$.tien_nt?3:1,itemCode:$detail$$.ma_vt,itemName:$detail$$.ten_vt_vat||$detail$$.ten_vt,unitName:0>$detail$$.tien_nt?"":$detail$$.ma_dvt,itemNote:"",unitPrice:0>$detail$$.tien_nt?void 0:$detail$$.gia_ban_nt,quantity:0>$detail$$.tien_nt?void 0:$detail$$.sl_xuat,itemTotalAmountWithoutTax:Math.abs($detail$$.tien_nt),discount:$detail$$.ty_le_ck,
|
|
39
39
|
itemDiscount:Math.abs($detail$$.tien_ck_nt),itemTotalAmountAfterDiscount:Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt),taxPercentage:"KT"===($detail$$.ma_thue||$ct$$.ma_thue)?0>$detail$$.tien_nt?void 0:-2:$thue_suat$$,taxAmount:Math.abs($detail$$.tien_thue_nt),itemTotalAmountWithTax:Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt+$detail$$.tien_thue_nt),customTaxAmount:"0",batchNo:"",expDate:""}}),summarizeInfo:{sumOfTotalLineAmountWithoutTax:$id_app$$,discountAmount:$auth_t_ck$$,settlementDiscountAmount:$auth_t_ck$$,
|
|
40
|
-
totalAmountWithoutTax:$t_tien$$,totalTaxAmount:$t_thue$$,totalAmountWithTax:$t_tien$$+$t_thue
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
totalAmountWithoutTax:$t_tien$$,totalTaxAmount:$t_thue$$,totalAmountWithTax:$t_tien$$+$t_thue$$},taxBreakdowns:$taxBreakdowns$$,payments:[{paymentMethodName:$ct$$.hinh_thuc_tt||"TM"}],extAttribute:[],deliveryInfo:{},metadata:[]};$ct$$.ngay_hd||($ct$$.ngay_hd=new Date);let $viettel_token$$;$auth_t_ck$$={username:$app_msg_e$$.viettel_user.trim(),password:$app_msg_e$$.viettel_password.trim()};if("1"!=$app_msg_e$$.viettel_version){$data$jscomp$0$$.generalInvoiceInfo.invoiceIssuedDate=(new Date($ct$$.ngay_hd)).getTime();
|
|
41
|
+
$id_app$$=$app_msg_e$$.viettel_direct_issue?`${$app_msg_e$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createInvoice/${$app_msg_e$$.ma_so_thue.trim()}`:`${$app_msg_e$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app_msg_e$$.ma_so_thue.trim()}`;var $headers_url_token$$=`${$app_msg_e$$.viettel_url_service.trim()}/auth/login`;try{$viettel_token$$=(await axios({method:"post",url:$headers_url_token$$,
|
|
42
|
+
data:$auth_t_ck$$})).data.access_token}catch($e$$){return console.error("error when get token viettel",$auth_t_ck$$,$headers_url_token$$),($app_msg_e$$=$e$$.response?$e$$.response.data:$e$$.message)&&$app_msg_e$$.detail&&($app_msg_e$$.message=$app_msg_e$$.detail),$next$$($app_msg_e$$||$e$$.message||$e$$.error||$e$$)}$headers_url_token$$={Cookie:`"access_token":"${$viettel_token$$}"; access_token=${$viettel_token$$}; session_token=${$viettel_token$$}`,"Content-Type":"application/json"};$auth_t_ck$$=
|
|
43
|
+
void 0}else $data$jscomp$0$$.generalInvoiceInfo.invoiceIssuedDate=Moment($ct$$.ngay_hd).format("YYYY-MM-DD"),$id_app$$=$app_msg_e$$.viettel_direct_issue?`${$app_msg_e$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/createInvoice/${$app_msg_e$$.ma_so_thue.trim()}`:`${$app_msg_e$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app_msg_e$$.ma_so_thue.trim()}`;axios({method:"post",url:$id_app$$,data:"1"!=$app_msg_e$$.viettel_version?JSON.stringify($data$jscomp$0$$):
|
|
44
44
|
$data$jscomp$0$$,auth:$auth_t_ck$$,headers:$headers_url_token$$}).then(async $data$$=>{$data$$=$data$$.data;if(!$data$$)return $next$$("Kh\u00f4ng th\u1ec3 xu\u1ea5t ho\u00e1 \u0111\u01a1n");if($data$$.errorCode)return $next$$($data$$.description);$ct$$.result_export_einvoice=$data$$;$ct$$.so_hd=$ct$$.result_export_einvoice.result.invoiceNo;await model.findOneAndUpdate({_id:$ct$$._id},$ct$$);$next$$(null,$data$$)}).catch($e$$=>{console.error("error invocie viettel",$e$$.response);let $msg_e$$=$e$$.response?
|
|
45
45
|
$e$$.response.data:$e$$.message;$msg_e$$.data&&($msg_e$$.message=$msg_e$$.data);$msg_e$$.detail&&($msg_e$$.message=$msg_e$$.detail);$next$$($msg_e$$||$e$$.message||$e$$.error||$e$$)})},{method:"GET"})};
|
|
@@ -22,8 +22,8 @@ $taxBreakdowns$$.filter($d$$=>"KT"!==$d$$.ma_thue).map($detail$$=>({taxPercentag
|
|
|
22
22
|
"",buyerFaxNumber:"",buyerEmail:$data$jscomp$0$$.email||"",buyerBankName:"",buyerBankAccount:"",buyerIdType:"",buyerIdNo:"",buyerCode:"",buyerBirthDay:""},sellerInfo:{sellerLegalName:$app_msg_e$$.name,sellerTaxCode:$app_msg_e$$.ma_so_thue,sellerAddressLine:$app_msg_e$$.address,sellerPhoneNumber:$app_msg_e$$.phone||"",sellerEmail:$app_msg_e$$.email||"",sellerBankName:$app_msg_e$$.ten_ngan_hang||"",sellerBankAccount:$app_msg_e$$.tai_khoan_ngan_hang||""},itemInfo:$ct$$.details.map(($detail$$,$index$$)=>
|
|
23
23
|
{let $thue_suat$$=$detail$$.ma_thue?$detail$$.thue_suat:$ct$$.thue_suat;return{lineNumber:$index$$+1,selection:0>$detail$$.tien?3:1,itemCode:$detail$$.ma_vt,itemName:$detail$$.ten_vt_vat||$detail$$.ten_vt,unitName:0>$detail$$.tien_nt?"":$detail$$.ma_dvt,itemNote:"",unitPrice:0>$detail$$.tien_nt?void 0:$detail$$.gia_ban_nt,quantity:0>$detail$$.tien_nt?void 0:$detail$$.sl_xuat,itemTotalAmountWithoutTax:Math.abs($detail$$.tien_hang_nt),discount:$detail$$.ty_le_ck,itemDiscount:Math.abs($detail$$.tien_ck_nt),
|
|
24
24
|
itemTotalAmountAfterDiscount:Math.abs($detail$$.tien_nt),taxPercentage:"KT"===($detail$$.ma_thue||$ct$$.ma_thue)?0>$detail$$.tien_nt?void 0:-2:$thue_suat$$,taxAmount:Math.abs($detail$$.tien_thue_nt),itemTotalAmountWithTax:Math.abs($detail$$.tien_nt+$detail$$.tien_thue_nt),customTaxAmount:"0",batchNo:"",expDate:""}}),summarizeInfo:{sumOfTotalLineAmountWithoutTax:$id_app$$,discountAmount:$auth_t_ck$$,settlementDiscountAmount:$auth_t_ck$$,totalAmountWithoutTax:$t_tien$$,totalTaxAmount:$t_thue$$,totalAmountWithTax:$t_tien$$+
|
|
25
|
-
$t_thue
|
|
26
|
-
|
|
25
|
+
$t_thue$$},taxBreakdowns:$taxBreakdowns$$,payments:[{paymentMethodName:$ct$$.hinh_thuc_tt||"TM"}],extAttribute:[],deliveryInfo:{},metadata:[]};$ct$$.ngay_hd||($ct$$.ngay_hd=new Date);let $viettel_token$$;$auth_t_ck$$={username:$app_msg_e$$.viettel_user.trim(),password:$app_msg_e$$.viettel_password.trim()};if("1"!=$app_msg_e$$.viettel_version){$data$jscomp$0$$.generalInvoiceInfo.invoiceIssuedDate=(new Date($ct$$.ngay_hd)).getTime();var $headers_url_token$$=`${$app_msg_e$$.viettel_url_service.trim()}/auth/login`;
|
|
26
|
+
$id_app$$=$app_msg_e$$.viettel_direct_issue?`${$app_msg_e$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createInvoice/${$app_msg_e$$.ma_so_thue.trim()}`:`${$app_msg_e$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app_msg_e$$.ma_so_thue.trim()}`;try{$viettel_token$$=(await axios({method:"post",url:$headers_url_token$$,data:$auth_t_ck$$})).data.access_token}catch($e$$){return console.error("error when get token viettel",
|
|
27
27
|
$auth_t_ck$$,$headers_url_token$$),($app_msg_e$$=$e$$.response?$e$$.response.data:$e$$.message)&&$app_msg_e$$.detail&&($app_msg_e$$.message=$app_msg_e$$.detail),$next$$($app_msg_e$$||$e$$.message||$e$$.error||$e$$)}$headers_url_token$$={Cookie:`"access_token":"${$viettel_token$$}"; access_token=${$viettel_token$$}; session_token=${$viettel_token$$}`,"Content-Type":"application/json"};$auth_t_ck$$=void 0}else $data$jscomp$0$$.generalInvoiceInfo.invoiceIssuedDate=Moment($ct$$.ngay_hd).format("YYYY-MM-DD"),
|
|
28
28
|
$id_app$$=$app_msg_e$$.viettel_direct_issue?`${$app_msg_e$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/createInvoice/${$app_msg_e$$.ma_so_thue.trim()}`:`${$app_msg_e$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app_msg_e$$.ma_so_thue.trim()}`;axios({method:"post",url:$id_app$$,data:"1"!=$app_msg_e$$.viettel_version?JSON.stringify($data$jscomp$0$$):$data$jscomp$0$$,auth:$auth_t_ck$$,headers:$headers_url_token$$}).then(async $data$$=>{$data$$=$data$$.data;if(!$data$$)return $next$$("Kh\u00f4ng th\u1ec3 xu\u1ea5t ho\u00e1 \u0111\u01a1n");
|
|
29
29
|
if($data$$.errorCode)return $next$$($data$$.description);$ct$$.result_export_einvoice=$data$$;$ct$$.so_hd=$ct$$.result_export_einvoice.result.invoiceNo;await model.findOneAndUpdate({_id:$ct$$._id},$ct$$);$next$$(null,$data$$)}).catch($e$$=>{console.error("error when export invocie viettel",$e$$.response);let $msg_e$$=$e$$.response?$e$$.response.data:$e$$.message;$msg_e$$.data&&($msg_e$$.message=$msg_e$$.data);$msg_e$$.detail&&($msg_e$$.message=$msg_e$$.detail);$next$$($msg_e$$||$e$$.message||$e$$.error||
|