flexbiz-server 12.0.22 → 12.0.25
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 +2 -3
- package/server/auths/local.js +15 -15
- package/server/controllers/controller.js +27 -26
- package/server/libs/post-book.js +3 -2
- package/server/libs/post-socai.js +4 -3
- package/server/libs/tinhgiatb.js +15 -16
- package/server/modules/lists/ls-file.js +16 -17
- package/server/route.js +3 -5
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "flexbiz-server",
|
|
3
3
|
"main": "./server/app.js",
|
|
4
4
|
"description": "Flexible Server",
|
|
5
|
-
"version": "12.0.
|
|
5
|
+
"version": "12.0.25",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Van Truong Pham",
|
|
8
8
|
"email": "invncur@gmail.com"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"async": "^3.2.0",
|
|
22
22
|
"axios": "^0.20.0",
|
|
23
23
|
"body-parser": "^1.19.0",
|
|
24
|
-
"
|
|
24
|
+
"bwip-js": "^3.1.0",
|
|
25
25
|
"cheerio": "^1.0.0-rc.10",
|
|
26
26
|
"compression": "^1.7.4",
|
|
27
27
|
"compression-webpack-plugin": "^3.0.0",
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
"fluent-ffmpeg": "^2.1.2",
|
|
39
39
|
"gm": "^1.23.1",
|
|
40
40
|
"google-translate": "^3.0.0",
|
|
41
|
-
"jsbarcode": "^3.11.5",
|
|
42
41
|
"jsonwebtoken": "^8.5.1",
|
|
43
42
|
"jspdf": "^2.1.1",
|
|
44
43
|
"jszip": "^3.1.5",
|
package/server/auths/local.js
CHANGED
|
@@ -5,21 +5,21 @@ function saveOTP($Phone$$,$otp_code$$,$callback$$,$expires$$=5){let $expire_time
|
|
|
5
5
|
function findByUsername($username$$,$fn$$){if(!$username$$)return $fn$$("B\u1ea1n ch\u01b0a nh\u1eadp t\u00e0i kho\u1ea3n");User.findOne({$or:[{email:$username$$},{email2:$username$$}]},function($error$$,$result$$){return!$error$$&&$result$$&&$result$$.local?$fn$$(null,$result$$):$fn$$($error$$||`T\u00e0i kho\u1ea3n ${$username$$} kh\u00f4ng t\u1ed3n t\u1ea1i`)})}
|
|
6
6
|
module.exports=async function($app$$,$passport$$){const $rateLimiter$$=await global.createRateLimiterMiddleware(configs.limitRequest.auth||{},"auth");$passport$$.use(new BasicStrategy(function($username$$,$password$$,$done$$){if(!$username$$)return $done$$("B\u1ea1n ch\u01b0a nh\u1eadp t\u00e0i kho\u1ea3n");$username$$=$username$$.trim().toLowerCase();setImmediate(function(){findByUsername($username$$,function($err$$,$user$$){if($err$$)return $done$$($err$$);if(!$user$$)return $done$$("T\u00e0i kho\u1ea3n "+
|
|
7
7
|
$username$$+" ch\u01b0a \u0111\u01b0\u1ee3c \u0111\u0103ng k\u00fd.");if($user$$.local.rspassword)if($user$$.validRspassword($password$$))$user$$.local.password=$user$$.local.rspassword,$user$$.local.rspassword=void 0,User.findOneAndUpdate({email:$user$$.email},{local:$user$$.local},($e$$,$rs$$)=>{if($e$$)return console.error("Can't update password",$user$$.email,$e$$);console.log("updated new password",$user$$.email,$rs$$)});else{if(!$user$$.validPassword($password$$))return $done$$("M\u1eadt kh\u1ea9u kh\u00f4ng ch\u00ednh x\u00e1c.")}else{if(!$user$$.local.password)return $done$$("M\u1eadt kh\u1ea9u cho ng\u01b0\u1eddi d\u00f9ng n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i. H\u00e3y s\u1eed d\u1ee5ng t\u00ednh n\u0103ng kh\u00f4i ph\u1ee5c m\u1eadt kh\u1ea9u \u0111\u1ec3 \u0111\u1eb7t l\u1ea1i m\u1eadt kh\u1ea9u cho ng\u01b0\u1eddi d\u00f9ng n\u00e0y");
|
|
8
|
-
if(!$user$$.validPassword($password$$))return $done$$("M\u1eadt kh\u1ea9u kh\u00f4ng ch\u00ednh x\u00e1c.")}return $done$$(null,$user$$)})})}));$app$$.get("/send-otp/:phone",$rateLimiter$$,async($req_url$$,$res$$)=>{const $Phone$$=$req_url$$.params.phone.trim();if(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
$
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
if(!$user$$.validPassword($password$$))return $done$$("M\u1eadt kh\u1ea9u kh\u00f4ng ch\u00ednh x\u00e1c.")}return $done$$(null,$user$$)})})}));$app$$.get("/send-otp/:phone",$rateLimiter$$,async($req_url$$,$res$$)=>{const $Phone$$=$req_url$$.params.phone.trim();if(!await User.findOne({email:$Phone$$}))return $res$$.status(400).send({error:`T\u00e0i kho\u1ea3n ${$Phone$$} kh\u00f4ng t\u1ed3n t\u1ea1i`});const $otp_code$$=generateOTP();validator.isEmail($Phone$$)?email.sendHtml({to:{address:$Phone$$},
|
|
9
|
+
subject:"M\u00e3 x\u00e1c th\u1ef1c",html:`Xin vui l\u00f2ng g\u1eedi qu\u00fd kh\u00e1ch m\u00e3 x\u00e1c th\u1ef1c: ${$otp_code$$}. M\u00e3 n\u00e0y s\u1ebd h\u1ebft h\u1ea1n s\u1eed d\u1ee5ng sau 5 ph\u00fat.`},function($error$$){$error$$?(console.error("Error send otp to email",$error$$),$res$$.status(400).send(`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi email ${$Phone$$}`)):saveOTP($Phone$$,$otp_code$$,($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)},
|
|
10
|
+
5)},configs.sender_otp):configs.sms.send?configs.sms.send($Phone$$,$otp_code$$,$req_url$$.query.id_app).then($rs$jscomp$0$$=>{$rs$jscomp$0$$.error_message?$res$$.status(400).send({error:$rs$jscomp$0$$.message||$rs$jscomp$0$$.error||$rs$jscomp$0$$.error_message||`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi s\u1ed1 ${$Phone$$}`}):saveOTP($Phone$$,$otp_code$$,($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)})}).catch($e$$=>{console.error("Error send sms",
|
|
11
|
+
$e$$);$res$$.status(400).send({error:$e$$.message||$e$$.error_message||`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi s\u1ed1 ${$Phone$$}`})}):($req_url$$=configs.sms.genUrlSendOTP($Phone$$,$otp_code$$,$req_url$$.query.id_app),request({url:$req_url$$},($error$$,$response$$,$body$$)=>{if($error$$||200!=$response$$.statusCode)$res$$.status(400).send({error:$error$$||`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi s\u1ed1 ${$Phone$$}`});else try{const $info$$=
|
|
12
|
+
JSON.parse($body$$);"100"==$info$$.CodeResult?saveOTP($Phone$$,$otp_code$$,($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)}):(console.error("Error send sms",$info$$),$res$$.status(400).send({error:`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi s\u1ed1 ${$Phone$$}`}))}catch($e$$){$res$$.status(400).send({error:$body$$})}}))});$app$$.get("/verify-otp/:id/:otp",$rateLimiter$$,async function($req$$,$res$$){try{const $id$$=$req$$.params.id;if(!global.mongoose.Types.ObjectId.isValid($id$$))return $res$$.status(400).send({error:"ID c\u1ee7a m\u00e3 x\u00e1c th\u1ef1c n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i",
|
|
13
|
+
code:4001});const $otp_code$$=$req$$.params.otp,$otp$$=await OTP.findById($id$$);if(!$otp$$||$otp$$.otp!=$otp_code$$||$otp$$.verified||$otp$$.expire_time.getTime()<(new Date).getTime())return $res$$.status(400).send({error:"M\u00e3 x\u00e1c th\u1ef1c n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i ho\u1eb7c \u0111\u00e3 h\u1ebft hi\u1ec7u l\u1ef1c",code:4001});await OTP.findOneAndUpdate({_id:$id$$},{verified:!0});let $is_new$$=!1;const $username$$=$otp$$.phone;let $user$$=await User.findOne({email:$username$$});
|
|
14
|
+
if(!$user$$){$user$$=new User;$user$$.email=$username$$;$user$$.local={active:!0};$user$$.local.email=$otp$$.email;$user$$.local.phone=$otp$$.phone;$user$$.local.name=$otp$$.phone;$user$$.name=$otp$$.phone;$is_new$$=!0;try{await $user$$.save()}catch($e$$){return console.log("error verify otp, create user",$e$$),$res$$.status(500).send($e$$)}}else if(!$user$$.local||!$user$$.local.active){$user$$.local=$user$$.local||{};$user$$.local.active=!0;try{await $user$$.save()}catch($e$$){return console.log("error verify otp, create user",
|
|
15
|
+
$e$$),$res$$.status(500).send($e$$)}}if($req$$.query.id_app&&$req$$.query.group_id){const $id_app$$=$req$$.query.id_app,$group_id$$=$req$$.query.group_id,$app$$=await App.findById($id_app$$);$app$$&&Participant.createParticipant({id_app:$id_app$$,email:$user$$.email,name:$user$$.name,group_id:$group_id$$,active:!0},$cust_e$$=>{if($cust_e$$)return console.log("can't add user",$user$$.email,"to company",$app$$.name);$cust_e$$={ten_kh:$user$$.name,email:$user$$.email,dien_thoai:$otp$$.phone,id_app:$id_app$$,
|
|
16
|
+
user_created:$user$$.email,user_updated:$user$$.email,kh_yn:!0,of_user:$user$$.email};try{Customer.asyncCreateCustomer($cust_e$$)}catch($e$$){console.log("Auto create new customer with error:",$e$$.message)}})}const $accessToken$$=generateToken($user$$),$agent$$=$req$$.headers["user-agent"];console.log("create new token for user",$user$$.email);(new Token({email:$user$$.email,token:$accessToken$$,agent:$agent$$,ip:"",once:1==$req$$.query.once||"true"==$req$$.query.once||"1"===$req$$.query.once?!0:
|
|
17
|
+
!1})).save(function($e$$,$rs$$){return $e$$?$res$$.status(500).send($e$$):$res$$.send({token:$accessToken$$,is_new:$is_new$$,once:$rs$$.once})})}catch($e$$){console.log("error verify otp",$e$$),$res$$.status(400).send($e$$.message)}});$app$$.post("/auth/sign",$rateLimiter$$,($req$$,$res$$,$next$$)=>{$passport$$.authenticate("basic",{session:!1},function($err$$,$user$$){if($err$$||!$user$$)return $res$$.status(401).send({message:$err$$||"Unauthorized"});$req$$.user=$user$$;$next$$()})($req$$,$res$$,
|
|
18
|
+
$next$$)},async($req$jscomp$3_user$$,$res$$)=>{let $data$$=$req$jscomp$3_user$$.body;$req$jscomp$3_user$$=$req$jscomp$3_user$$.user;if(!$data$$)return $res$$.status(400).send("Not have data to sign");if(!$data$$.id_app)return $res$$.status(400).send("Data miss id_app property");try{let $signature$$=await Wallet.sign($data$$.id_app,$req$jscomp$3_user$$.email,$data$$);$res$$.send($signature$$)}catch($e$$){return $res$$.status(400).send($e$$.message||$e$$)}});$app$$.get("/auth/local",$rateLimiter$$,
|
|
19
|
+
function($req$$,$res$$,$next$$){let $ip$$=($req$$.ip||$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress).split(".").join("").split(":").join(""),$authorization$$=$req$$.headers.authorization;if(!$authorization$$)return $res$$.status(400).send({message:"Authorization is required"});$authorization$$=Buffer.from($authorization$$.replace("Basic ",""),"base64").toString("utf-8");$authorization$$=$authorization$$.split(":");if(1<$authorization$$.length){let $t_session$$="times_login_"+
|
|
20
|
+
$ip$$+"_"+$authorization$$[0].trim().toLowerCase(),$d_session$$="datetime_login_"+$ip$$+"_"+$authorization$$[0].trim().toLowerCase();$req$$.t_session=$t_session$$;$req$$.d_session=$d_session$$;let $now$$=new Date,$d$$=$now$$,$times_try$$=1;if($req$$.headers.cookie&&$req$$.session){$req$$=$req$$.session;$req$$[$t_session$$]?($times_try$$=$req$$[$t_session$$]+1,$req$$[$t_session$$]=$times_try$$):($req$$[$t_session$$]=$times_try$$,$req$$[$d_session$$]=$now$$);$req$$[$d_session$$]?$d$$=new Date($req$$[$d_session$$]):
|
|
21
|
+
$req$$[$d_session$$]=$now$$;$req$$=$now$$.getTime()-$d$$.getTime();if(18E6>$req$$&&10<$times_try$$)return $res$$.status(400).send({message:"B\u1ea1n \u0111\u0103ng nh\u1eadp sai 10 l\u1ea7n li\u00ean ti\u1ebfp. H\u00e3y th\u1eed l\u1ea1i sau "+Math.round((18E6-$req$$)/6E4,0)+" ph\u00fat"});$next$$()}else global.clientRedis.get($t_session$$,function($err$$,$reply$$){$reply$$?($times_try$$=Number($reply$$)+1,global.clientRedis.set($t_session$$,$times_try$$)):(global.clientRedis.set($t_session$$,$times_try$$),
|
|
22
|
+
global.clientRedis.set($d_session$$,$now$$));global.clientRedis.get($d_session$$,function($err$jscomp$3_time_wait$$,$reply$$){$reply$$?$d$$=new Date($reply$$):global.clientRedis.set($d_session$$,$now$$);$err$jscomp$3_time_wait$$=$now$$.getTime()-$d$$.getTime();if(18E6>$err$jscomp$3_time_wait$$&&10<$times_try$$)return $res$$.status(400).send({message:"B\u1ea1n \u0111\u0103ng nh\u1eadp sai 10 l\u1ea7n li\u00ean ti\u1ebfp. H\u00e3y th\u1eed l\u1ea1i sau "+Math.round((18E6-$err$jscomp$3_time_wait$$)/
|
|
23
23
|
6E4,0)+" ph\u00fat"});$next$$()})})}},function($req$$,$res$$,$next$$){$passport$$.authenticate("basic",{session:!1},function($err$$,$user$$){if($err$$||!$user$$)return $res$$.status(401).send({message:$err$$||"Unauthorized"});if(configs.require_verify&&!$user$$.local.active)return $res$$.status(401).send({require_verify:!0});$req$$.user=$user$$;$next$$()})($req$$,$res$$,$next$$)},async($req$$,$res$$)=>{let $agent$$=$req$$.headers["user-agent"];if($req$$.headers.cookie){var $group_id$jscomp$1_session$$=
|
|
24
24
|
$req$$.session;$group_id$jscomp$1_session$$[$req$$.t_session]=0;$group_id$jscomp$1_session$$[$req$$.d_session]=""}else global.clientRedis.set($req$$.t_session,0),global.clientRedis.set($req$$.d_session,"");log.create({id_app:"LOGIN",id_func:"LOGIN",action:"LOCALLOGIN"},$req$$.user.email,$req$$.header("user-agent"),$req$$);let $user$$=$req$$.user;if($req$$.query.id_app&&$req$$.query.group_id&&global.mongoose.Types.ObjectId.isValid($req$$.query.group_id)){const $id_app$$=$req$$.query.id_app;$group_id$jscomp$1_session$$=
|
|
25
25
|
$req$$.query.group_id;const $app$$=await App.findById($id_app$$),$group$$=await UserGroup.findOne({_id:$group_id$jscomp$1_session$$,is_customer_group:!0});$app$$&&$group$$&&Participant.createParticipant({id_app:$id_app$$,email:$user$$.email,name:$user$$.name,group_id:$group_id$jscomp$1_session$$,active:!0},$cust$jscomp$1_e$$=>{if($cust$jscomp$1_e$$)return console.log("can't add user",$user$$.email,"to company",$app$$.name);$cust$jscomp$1_e$$={ten_kh:$user$$.name,email:$user$$.email,id_app:$id_app$$,
|
|
@@ -16,14 +16,15 @@ this.saving=$options$jscomp$0$$.onSaving;this.creating=$options$jscomp$0$$.onCre
|
|
|
16
16
|
"exfields")&&$items$$.forEach($item$$=>{delete $item$$.__v;$item$$.exfields||($item$$.exfields={})});async.parallel({_user_created:$callback$$=>{$items$$.filter($item$$=>$item$$.user_created).joinModel2(null,User,{where:{user_created:"email"},fields:{name_user_created:"name"}},()=>{$callback$$(null)})},_user_updated:$callback$$=>{$items$$.filter($item$$=>$item$$.user_updated).joinModel2(null,User,{where:{user_updated:"email"},fields:{name_user_updated:"name"}},()=>{$callback$$(null)})},_approve:$callback$$=>
|
|
17
17
|
{async.map($items$$,($item$$,$next$$)=>{setImmediate(()=>{Approve.find({id_ct:$item$$._id.toString()},{title:1,trang_thai:1,user_approved:1,user_approved_name:1,date_approved:1,user_denied:1,user_denied_name:1,date_denied:1}).lean().exec(async($e$$,$rs$$)=>{setImmediate(async()=>{$item$$.approve_data=$rs$$;await $item$$.approve_data.asyncJoinModel2($item$$.id_app,Participant,{where:{user_approved:"email"},fields:{user_approved_name:"name",signature_image:"signature_image"}});await $item$$.approve_data.asyncJoinModel2($item$$.id_app,
|
|
18
18
|
Participant,{where:{user_denied:"email"},fields:{user_denied_name:"name",signature_image:"signature_image"}});$next$$(null)})})})},()=>{$callback$$(null)})},transfer_ct:$callback$$=>{if(underscore.has($schema_paths$$,"id_ct_chuyen")&&$user$$.current_app_info&&$user$$.current_app_info.options&&$user$$.current_app_info.options.id_app_thue)async.map($items$$,($item$$,$next$$)=>{setImmediate(()=>{$model$$.findOne({id_app:$user$$.current_app_info.options.id_app_thue,id_ct_chuyen:$item$$._id.toString()},
|
|
19
|
-
{_id:1}).lean().exec(async($e$$,$rs$$)=>{$rs$$&&($item$$.id_ct_nhan=$rs$$._id);$next$$(null)})})},()=>{$callback$$(null)});else return $callback$$()}
|
|
20
|
-
$
|
|
21
|
-
|
|
22
|
-
$
|
|
23
|
-
$
|
|
24
|
-
$
|
|
25
|
-
$d$$.
|
|
26
|
-
$d$$.
|
|
19
|
+
{_id:1}).lean().exec(async($e$$,$rs$$)=>{$rs$$&&($item$$.id_ct_nhan=$rs$$._id);$next$$(null)})})},()=>{$callback$$(null)});else return $callback$$()},posted:$callback$$=>{$options$$&&$options$$.req&&($options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book)?async.map($items$$,($item$$,$next$$)=>{setImmediate(async()=>{let $book$$=$options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book,$exists$$=await global.getModel($book$$).findOne({id_ct:$item$$._id.toString()},
|
|
20
|
+
{_id:1});$item$$[`${$book$$}_posted`]=!!$exists$$;$next$$()})},()=>{$callback$$(null)}):$callback$$()}},$e$jscomp$0$$=>{if($e$jscomp$0$$)return $next$$($e$jscomp$0$$);if($options$$&&$options$$.req&&($options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book)){let $book$$=$options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book;$items$$=$items$$.filter($r$$=>$options$$.req.query.show_posted_book?$r$$[`${$book$$}_posted`]:!$r$$[`${$book$$}_posted`])}setImmediate(()=>
|
|
21
|
+
{if($self$$.view)try{$self$$.view($user$$,$items$$,function($error$jscomp$0$$,$rs$jscomp$0$$){setImmediate(()=>{if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);$self$$.dynamicView?$self$$.dynamicView($user$$,$rs$jscomp$0$$||$items$$,function($error$$,$rs$$){if($error$$)return $next$$($error$$);$next$$(null,$rs$$||$items$$)}):$next$$(null,$rs$jscomp$0$$||$items$$)})},$options$$)}catch($e$$){console.error("Error on view of",$name$$,$e$$),$next$$(null,$items$$)}else $self$$.dynamicView?$self$$.dynamicView($user$$,
|
|
22
|
+
$items$$,function($error$$,$rs$$){if($error$$)return $next$$($error$$);$next$$(null,$rs$$||$items$$)}):$next$$(null,$items$$)})})};this.excelParse=$options$jscomp$0$$.onExcelParse;this.options=$options$jscomp$0$$;this.replaceIfExists=$options$jscomp$0$$.replaceIfExists;this.notNeedRight=$options$jscomp$0$$.notNeedRight}getProperty($name$$){return this[$name$$]}getNextId(){let $ma_ct$$=this.name;this.router.route(`${this.route_name}/next/:field`).get(($field$$,$res$$)=>{let $id_app$$=$field$$.user.current_id_app;
|
|
23
|
+
$field$$=$field$$.params.field;"so_ct"===$field$$?$res$$.send({[$field$$]:$ma_ct$$}):getNextSequence($id_app$$,$ma_ct$$,$field$$,($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$$)})})}async checkData($appInfo$$,$data$$,$fn$$){const $options$$=this.options;if($data$$.trang_thai&&$data$$.ma_ct){let $tt$$=await trangthai.findOne({ma_ct:$data$$.ma_ct,ma_trang_thai:$data$$.trang_thai},{check_data:1}).lean();
|
|
24
|
+
if($tt$$&&0==$tt$$.check_data)return $fn$$()}async.parallel({checkTonKho:$callback$jscomp$0$$=>{$data$$.details&&$appInfo$$&&$appInfo$$.options&&$appInfo$$.options.khong_xuat_kho_am&&0!=$options$$.check_stock?(async()=>{let $details$$=$data$$.details.filter($d$$=>$d$$.ma_vt&&$d$$.sl_xuat);await $details$$.asyncJoinModel2($appInfo$$._id,dmvt,{where:{ma_vt:"ma_vt"},fields:["tg_tk","kg_kiem_tra_ton_kho","kg_kiem_tra_ton_kho_tt","combo","ten_vt"]});$details$$=$details$$.filter($d$$=>$d$$.tg_tk&&!$d$$.kg_kiem_tra_ton_kho||
|
|
25
|
+
0<($d$$.combo||[]).length);$details$$=$details$$.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($c$$=>{$c$$=$c$$.toObject?$c$$.toObject():{...$c$$};$c$$.sl_xuat*=$detail$$.sl_xuat;$c$$.ma_kho=$detail$$.ma_kho;return $c$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);await $details$$.asyncJoinModel2($appInfo$$._id,dmqddvt,{where:{ma_vt:"ma_vt",ma_dvt:"ma_dvt"},fields:"ty_le_qd"});let $data_sokho$$=[];$data$$._id&&($data_sokho$$=await Sokho.find({id_ct:$data$$._id.toString()}).lean());
|
|
26
|
+
$details$$.forEach($d$$=>{$d$$.he_so_qd=$d$$.ty_le_qd||1;$d$$.sl_xuat_qd=$d$$.he_so_qd*$d$$.sl_xuat});$details$$=await $details$$.asyncGroupBy(["ma_vt","ma_kho","ten_vt"],["sl_xuat_qd"]);async.map($details$$,($d$$,$callback$$)=>{let $ma_kho$$=$d$$.ma_kho||$data$$.ma_kho||$data$$.ma_kho_x,$query$$={ma_vt:$d$$.ma_vt,ma_kho:$ma_kho$$,ngay:new Date,id_app:$appInfo$$._id};$d$$.kg_kiem_tra_ton_kho_tt||($d$$.ma_lo&&($query$$.ma_lo=$d$$.ma_lo),$d$$.han_sd&&($query$$.han_sd=$d$$.han_sd),$d$$.ma_tt1&&($query$$.ma_tt1=
|
|
27
|
+
$d$$.ma_tt1),$d$$.ma_tt2&&($query$$.ma_tt2=$d$$.ma_tt2),$d$$.ma_tt3&&($query$$.ma_tt3=$d$$.ma_tt3));ckvt($query$$,function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$rs$$?($e$$=$rs$$.csum("ton"),$rs$$=$data_sokho$$.filter($s$$=>$s$$.ma_vt===$d$$.ma_vt&&$s$$.ma_kho===$ma_kho$$).reduce(($a$$,$b$$)=>($a$$.sl_xuat_qd||0)+($b$$.sl_xuat_qd||0),0),$d$$.sl_xuat_qd>utils.round($e$$+$rs$$,2)?$callback$$(`S\u1ea3n ph\u1ea9m ${$d$$.ma_vt} - ${$d$$.ten_vt} c\u00f3 s\u1ed1 l\u01b0\u1ee3ng xu\u1ea5t quy \u0111\u1ed5i (${$d$$.sl_xuat_qd}) l\u1edbn h\u01a1n s\u1ed1 l\u01b0\u1ee3ng t\u1ed3n quy \u0111\u1ed5i (${$e$$+
|
|
27
28
|
$rs$$})`):$callback$$()):$callback$$()})},$e$$=>{$callback$jscomp$0$$($e$$)})})():$callback$jscomp$0$$()}},$e$$=>{$fn$$($e$$)})}cacheData($obj$$,$callback$$){$obj$$&&$obj$$.toObject&&($obj$$=$obj$$.toObject());redisCache.set(this.model.collection.name.substring(0,this.model.collection.name.length-1),$obj$$,$callback$$)}deleteData($obj$$,$callback$$){$obj$$&&$obj$$.toObject&&($obj$$=$obj$$.toObject());redisCache.remove(this.model.collection.name.substring(0,this.model.collection.name.length-1),$obj$$,
|
|
28
29
|
$callback$$)}createRoute($routeName_url$$,$callback$$,$_options$$={method:"GET"}){let $self$$=this;$_options$$.method=$_options$$.method?$_options$$.method.toUpperCase():"GET";let $r$$=function($req$$,$res$$){!1===$self$$.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,
|
|
29
30
|
"view",function($error$$,$hr$$){$hr$$?$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$$):$res$$.status(403).send({error:$error$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})},{notNeedRight:$self$$.notNeedRight||$_options$$.notNeedRight})};$routeName_url$$=`${this.route_name}/${$routeName_url$$}`;let $router$$=this.router;"DELETE"==$_options$$.method?$router$$.route($routeName_url$$).delete($r$$):
|
|
@@ -151,8 +152,8 @@ $resolve$$()})})}let $filePath$$=$req$$.files.xlsx.path;excel.parse($filePath$$,
|
|
|
151
152
|
0<Object.keys($d$$).length);if(1E4<$data$$.length)return $session$$["import_"+$name$$]=!1,console.log("Data is too large",$data$$.length),$res$$.status(400).send({error:"S\u1ed1 d\u00f2ng import qu\u00e1 l\u1edbn. M\u1ed7i l\u1ea7n import ch\u1ec9 \u0111\u01b0\u1ee3c ph\u00e9p t\u1ed1i \u0111a 10 000 d\u00f2ng"});$ctrl$$.excelParse&&$ctrl$$.excelParse($data$$,$columns$$);var $dir_workers_poolName$$=configs.paths.workers;let $onImportProcess$$;$dir_workers_poolName$$&&($onImportProcess$$=$dir_workers_poolName$$+
|
|
152
153
|
"/"+$name$$.toLowerCase()+"OnImport.js");$onImportProcess$$&&fs.existsSync($onImportProcess$$)||($dir_workers_poolName$$=path.dirname(__dirname)+"/workers",$onImportProcess$$=$dir_workers_poolName$$+"/"+$name$$.toLowerCase()+"OnImport.js");if(fs.existsSync($onImportProcess$$))$dir_workers_poolName$$=`${$name$$}excelParsePool`,global[$dir_workers_poolName$$]||(global[$dir_workers_poolName$$]=new StaticPool($onImportProcess$$)),global[$dir_workers_poolName$$].exec({user:$req$$.user,data:$data$$,columns:$columns$$,
|
|
153
154
|
configs:{database:configs.database}},$response$$=>{if($response$$.error)return $res$$.status(400).send({error:$response$$.error||"\u0110\u00e3 c\u00f3 l\u1ed7i khi x\u1eed l\u00fd d\u1eef li\u1ec7u"});$req$$.data=$response$$.data||$data$$;$req$$.columns=$response$$.columns||$columns$$;$next$$()});else if($ctrl$$.options.onImport)$ctrl$$.options.onImport($req$$.user,$data$$,$columns$$,function($e$$){setImmediate(()=>{if($e$$)return $session$$["import_"+$name$$]=!1,console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):
|
|
154
|
-
$res$$.status(400).send({error:$e$$.message||$e$$});$req$$.data=$data$$;$req$$.columns=$columns$$;$next$$()})});else setImmediate(()=>{$req$$.data=$data$$;$req$$.columns=$columns$$;$next$$()})})},$parseOptions$$)},function($req$$,$data$jscomp$
|
|
155
|
-
$column_name$$.indexOf("$")?($detail_yn$$=!0,$columns$$=$column_name$$.split("$")[0],$detail_col$$=$column_name$$.split("$")[1],$details$$[$columns$$]||($details$$[$columns$$]={},$details$$[$columns$$].columns=[]),$details$$[$columns$$].columns.push($detail_col$$)):$master_columns$$.push($column_name$$);if(!$detail_yn$$)return $next$$();let $data_new$$=[],$row_master$$,$row_master_exists$$;async.map($data$jscomp$
|
|
155
|
+
$res$$.status(400).send({error:$e$$.message||$e$$});$req$$.data=$data$$;$req$$.columns=$columns$$;$next$$()})});else setImmediate(()=>{$req$$.data=$data$$;$req$$.columns=$columns$$;$next$$()})})},$parseOptions$$)},function($req$$,$data$jscomp$6_res$$,$next$$){console.log("prepare data...");$data$jscomp$6_res$$=$req$$.data;var $columns$$=$req$$.columns;$columns$$._error||($columns$$._error="Error");let $master_columns$$=[],$detail_col$$,$details$$={},$detail_yn$$=!1;for(let $column_name$$ in $columns$$)0<
|
|
156
|
+
$column_name$$.indexOf("$")?($detail_yn$$=!0,$columns$$=$column_name$$.split("$")[0],$detail_col$$=$column_name$$.split("$")[1],$details$$[$columns$$]||($details$$[$columns$$]={},$details$$[$columns$$].columns=[]),$details$$[$columns$$].columns.push($detail_col$$)):$master_columns$$.push($column_name$$);if(!$detail_yn$$)return $next$$();let $data_new$$=[],$row_master$$,$row_master_exists$$;async.map($data$jscomp$6_res$$,($row$$,$cb$$)=>{setImmediate(()=>{$row_master$$={exfields:{}};$row_master_exists$$=
|
|
156
157
|
null;$master_columns$$.forEach(function($column$$){if(0===$column$$.indexOf("exfields.")){let $_c$$=$column$$.replace("exfields.","");$row_master$$.exfields[$_c$$]=$row$$[$column$$]}else $row_master$$[$column$$]=$row$$[$column$$]});for(let $i$$=0;$i$$<$data_new$$.length;$i$$++){let $m$$=$data_new$$[$i$$],$is_eq$$=!0;$master_columns$$.forEach(function($column$$){underscore.isEqual($m$$[$column$$],$row_master$$[$column$$])||($is_eq$$=!1)});$is_eq$$&&($row_master_exists$$=$m$$)}$row_master_exists$$?
|
|
157
158
|
$row_master$$=$row_master_exists$$:$data_new$$.push($row_master$$);let $row_detail$$;for(let $detail_name$$ in $details$$)$row_detail$$={},$details$$[$detail_name$$].columns.forEach(function($column$$){$row$$[$detail_name$$+"$"+$column$$]&&($row_detail$$[$column$$]=$row$$[$detail_name$$+"$"+$column$$])}),$row_master$$[$detail_name$$]||($row_master$$[$detail_name$$]=[]),0<underscore.keys($row_detail$$).length&&$row_master$$[$detail_name$$].push($row_detail$$);$cb$$()})},()=>{$req$$.data=$data_new$$;
|
|
158
159
|
setImmediate(()=>{$next$$()})})},function($req$$,$res$$){let $data$$=$req$$.data||[],$columns$$=$req$$.columns;for(let $row$$ of $data$$){let $_first$$=$row$$._first;$_first$$&&0<$_first$$.length&&underscore.extend($row$$,$_first$$[0])}setImmediate(()=>{log.create({id_app:$req$$.user.current_id_app,id_func:$ctrl$$.name,action:"IMPORTEXCEL",data:{data:$data$$,columns:$columns$$}},$req$$.user.email,$req$$.header("user-agent"),$req$$)});let $values$$=$req$$.query.values;if($values$$){try{$values$$=JSON.parse($values$$)}catch($e$$){console.error($e$$)}$values$$&&
|
|
@@ -165,27 +166,27 @@ $obj$$.toObject());if(!$obj$$._id)return console.error("Error when delete post:
|
|
|
165
166
|
function($detail$$,$callback$$){$callback$$($detail$$)})).remove(function($e$$){$callback$jscomp$0$$($e$$)})})},skkhongton:$callback$jscomp$0$$=>{setImmediate(()=>{(new PostBook($obj$$,$obj$$.details,Sokhokhongton,function($detail$$,$callback$$){$callback$$($detail$$)})).remove(function($e$$){$callback$jscomp$0$$($e$$)})})},vsc:$callback$$=>{setImmediate(()=>{if(global.model_books&&0<=global.model_books.indexOf("vsocai"))return $callback$$();vsocai.deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},
|
|
166
167
|
sc:$callback$$=>{setImmediate(()=>{Socai.deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},vatra:$callback$$=>{setImmediate(()=>{if(global.model_books&&0<=global.model_books.indexOf("vatra"))return $callback$$();Vatra.deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},vatvao:$callback$$=>{setImmediate(()=>{if(global.model_books&&0<=global.model_books.indexOf("vatvao"))return $callback$$();Vatvao.deleteMany({id_ct:$obj$$._id.toString()},
|
|
167
168
|
function($error$$){$callback$$($error$$)})})},tdttno:$callback$$=>{setImmediate(()=>{if(global.model_books&&0<=global.model_books.indexOf("tdttno"))return $callback$$();Tdttno.deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},tdttco:$callback$$=>{setImmediate(()=>{if(global.model_books&&0<=global.model_books.indexOf("tdttco"))return $callback$$();Tdttco.deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},tdttno_tt:$callback$jscomp$0$$=>
|
|
168
|
-
{setImmediate(()=>{Tdttno_tt.deleteMany({id_ct:$obj$$._id.toString()},function($error$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$obj$$.tdttnos?async.map($obj$$.tdttnos,function($detail$$,$callback$$){setImmediate(()=>{Tdttno.findOneAndUpdate({_id:$detail$$.id_hd,so_hd:$detail$$.so_hd},{$set:{tat_toan:!1}},function($error$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);$callback$$()})})})},function($e$$){console.error($e$$);$callback$jscomp$0$$()}):
|
|
169
|
+
{setImmediate(()=>{Tdttno_tt.deleteMany({id_ct:$obj$$._id.toString()},function($error$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$obj$$.tdttnos?async.map($obj$$.tdttnos,function($detail$$,$callback$$){setImmediate(()=>{Tdttno.findOneAndUpdate({_id:$detail$$.id_hd,so_hd:$detail$$.so_hd},{$set:{tat_toan:!1}},function($error$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);$callback$$()})})})},function($e$$){$e$$&&console.error($e$$);$callback$jscomp$0$$()}):
|
|
169
170
|
$callback$jscomp$0$$()})})},tdttco_tt:$callback$jscomp$0$$=>{setImmediate(()=>{Tdttco_tt.deleteMany({id_ct:$obj$$._id.toString()},function($error$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$obj$$.tdttcos?async.map($obj$$.tdttcos,function($detail$$,$callback$$){setImmediate(()=>{Tdttco.findOneAndUpdate({_id:$detail$$.id_hd,so_hd:$detail$$.so_hd},{$set:{tat_toan:!1}},function($error$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);$callback$$()})})})},
|
|
170
|
-
function($e$$){console.error($e$$);$callback$jscomp$0$$()}):$callback$jscomp$0$$()})})}},function($e$$){console.
|
|
171
|
+
function($e$$){$e$$&&console.error($e$$);$callback$jscomp$0$$()}):$callback$jscomp$0$$()})})}},function($e$$){$e$$&&console.error("delete books",$e$$);$callback$jscomp$1$$($e$$,$obj$$)})},runWebhooks=controller.runWebhooks=async($ctrl$$,$obj$$,$action$$,$voucher_options$$)=>{$voucher_options$$||($voucher_options$$=(await OptionsModel.findOne({id_app:$obj$$.id_app,id_func:$ctrl$$.name},{option:1}).lean()||{}).option);if($voucher_options$$&&$voucher_options$$.option_webhooks&&($ctrl$$=$voucher_options$$.option_webhooks.find($w$$=>
|
|
171
172
|
$w$$.action.toUpperCase()===$action$$.toUpperCase()&&$w$$.url))){$voucher_options$$=path.dirname(__dirname)+"/workers/webhook.js";if(!fs.existsSync($voucher_options$$))return console.error("webhook process is not exitst");global.webhookPool||(global.webhookPool=new StaticPool($voucher_options$$));global.webhookPool.exec({data:$obj$$,webhook_configs:$ctrl$$},$response$$=>{$response$$.error?console.error($response$$.error):console.log($response$$)})}},postData=controller.postData=function($obj$$,$ctrl$$,
|
|
172
173
|
$callback$jscomp$0$$){const $post$$=$ctrl$$.dynamicPost||$ctrl$$.post;if(!$post$$)return $callback$jscomp$0$$();let $obj_created$$=$obj$$.toObject?$obj$$.toObject():{...$obj$$};if(!$obj_created$$.ma_ct)return console.error("\u0110\u1ec3 post \u0111\u01b0\u1ee3c data, y\u00eau c\u1ea7u c\u1ea7n c\u00f3 field ma_ct",$obj_created$$),$callback$jscomp$0$$("\u0110\u1ec3 post \u0111\u01b0\u1ee3c data, \u0110\u1ed1i t\u01b0\u1ee3ng c\u1ea7n c\u00f3 d\u1eef li\u1ec7u ma_ct,trang_thai");Object.keys($obj_created$$).forEach($key$$=>
|
|
173
174
|
{let $p$$=$obj_created$$[$key$$];$p$$&&($p$$.toObject&&($obj_created$$[$key$$]=$p$$.toObject()),underscore.isArray($p$$)&&($obj_created$$[$key$$]=$p$$.map($el$$=>$el$$?$el$$.toObject?$el$$.toObject():$el$$:$el$$)))});$ctrl$$.beforePost||($ctrl$$.beforePost=function($obj_created$$,$callback$$){$callback$$(null,null)});$ctrl$$.beforePost($obj_created$$,function($e$jscomp$3$$){if($e$jscomp$3$$)return $callback$jscomp$0$$($e$jscomp$3$$);deletePost($obj_created$$.user_updated,$obj_created$$,async function($e$jscomp$2$$){if($e$jscomp$2$$)return $callback$jscomp$0$$($e$jscomp$2$$);
|
|
174
175
|
if($ctrl$$.dynamicDeletePost)try{await $ctrl$$.dynamicDeletePost($obj_created$$)}catch($e$$){return $callback$jscomp$0$$($e$$.message||$e$$.error||$e$$)}setImmediate(()=>{if($obj_created$$.trang_thai||0==$obj_created$$.trang_thai)$obj_created$$.trang_thai=$obj_created$$.trang_thai.toString();trangthai.findOne({ma_ct:$obj_created$$.ma_ct.toUpperCase(),ma_trang_thai:$obj_created$$.trang_thai},function($e$jscomp$1$$,$trang_thai$$){if($e$jscomp$1$$)return $callback$jscomp$0$$($e$jscomp$1$$);if($trang_thai$$&&
|
|
175
|
-
!$trang_thai$$.post)return $callback$jscomp$0$$();setImmediate(()=>{$post$$($obj_created$$,function($e$jscomp$0$$,$rs$$){setImmediate(()=>{$e$jscomp$0
|
|
176
|
-
$callback$jscomp$0$$($e$jscomp$0$$.message||$e$jscomp$0$$.error||$e$jscomp$0$$)}catch($e$$){return console.error($e$$.message||$e$$.error||$e$$),$callback$jscomp$0$$($e$$)}else $callback$jscomp$0$$($e$jscomp$0$$)})
|
|
177
|
-
{...$_obj$$};$obj$jscomp$0$$._id=$obj$jscomp$0$$._id.toString();$options$$||($options$$={});var $exclude_token$$=$options$$.exclude_token,$trang_thai$$=($obj$jscomp$0$$.trang_thai||(0==$obj$jscomp$0$$.progress?"0":$obj$jscomp$0$$.progress)||
|
|
178
|
-
$rs$$)=>{setImmediate(async()=>{if($rs$$&&$rs$$.option&&$rs$$.option.users_receive_notification)var $notifications_setting_users_receive_notification$$=$rs$$.option.users_receive_notification;$notifications_setting_users_receive_notification$$&&
|
|
179
|
-
$resolve$$(await $n$$($obj$jscomp$0$$)):$resolve$$($n$$)})}))));$notifications_setting_users_receive_notification$$&&($notifications_setting_users_receive_notification$$=$notifications_setting_users_receive_notification$$.filter($u
|
|
180
|
-
$func_string$jscomp$1_n$$=$func_string$jscomp$1_n$$.condition;0>$func_string$jscomp$1_n$$.indexOf("return ")&&($func_string$jscomp$1_n$$=`return ${$func_string$jscomp$1_n$$}`);try{return evalute($func_string$jscomp$1_n$$,
|
|
181
|
-
trang_thai:$trang_thai$$,id_app:$obj$jscomp$0$$.id_app,code:$obj$jscomp$0$$.ma_ct||$ctrl$$.name,id_link:$obj$jscomp$0$$.id_link,code_link:$obj$jscomp$0$$.code_link,event:$eventName$$,action:$eventName$$.toUpperCase(),
|
|
182
|
-
$p$jscomp$0$$.title||$p$jscomp$0$$.content||"",$obj$jscomp$0$$)));$notificationData$$.title||$notificationData$$.body||($exclude_token$$=null);let $users_will_receive$$=$p$jscomp$0$$.users;$users_will_receive$$||
|
|
183
|
-
(await Participant.find({id_app:$obj$jscomp$0$$.id_app,group_id:{$in:$admins_employees_groups_of_user_sandbox$$}}).lean()).map($p$$=>$p$$.email),$users_will_receive$$=$users_will_receive$$.concat($admins_employees_groups_of_user_sandbox$$))}$p$jscomp$0$$.send_phu_trach
|
|
184
|
-
|
|
185
|
-
$p$jscomp$0$$.send_to_customer&&($obj$jscomp$0$$.ma_kh||$obj$jscomp$0$$.id_kh)&&($admins_employees_groups_of_user_sandbox$$=await mongoose.models.customer.getInfo($obj$jscomp$0$$.id_app,{$or:[{ma_kh:$obj$jscomp$0$$.ma_kh},
|
|
186
|
-
($users_will_receive$$=$users_will_receive$$.filter($u$$=>$u$$!==$obj$jscomp$0$$.user_created));if($p$jscomp$0$$.handle_receivers){$admins_employees_groups_of_user_sandbox$$={obj:$obj$jscomp$0$$,users_will_receive:$users_will_receive$$};
|
|
187
|
-
($ctrl$$.options={});$ctrl$$.options.onEmitEvent||($ctrl$$.options.onEmitEvent=($obj$$,$users_will_receive$$,$next$$,$_notificationData$$)=>{$next$$(null,$users_will_receive$$,$_notificationData$$)});$ctrl$$.options.onEmitEvent(Object.assign({}
|
|
188
|
-
app.emitEvent($obj$jscomp$0$$.id_app,`${$ctrl$$.name.toLowerCase()}:${$eventName$$}`,$_notificationData$$||$notificationData$$,$exclude_token$$,$_users_will_receive$$,!0)})},Object.assign({},$notificationData$$),Object.assign({},$p$jscomp$0$$))})}))})})}})};
|
|
176
|
+
!$trang_thai$$.post)return $callback$jscomp$0$$();setImmediate(()=>{$post$$($obj_created$$,function($e$jscomp$0$$,$rs$$){setImmediate(()=>{if($e$jscomp$0$$){let $msg_error$$=$e$jscomp$0$$.message||$e$jscomp$0$$.error||$e$jscomp$0$$.toString();if(0<=$msg_error$$.indexOf("E11000 duplicate")&&(0<=$msg_error$$.indexOf("id_ct_1_nh_dk_1")||0<=$msg_error$$.indexOf("id_ct_1_line_1")))return $callback$jscomp$0$$(null,$rs$$);console.error("error post data",$obj_created$$._id,$msg_error$$);deletePost($obj_created$$.user_updated,
|
|
177
|
+
$obj_created$$,async function($e_delete_post$$){if($e_delete_post$$)return console.error("error delete post",$e_delete_post$$),$callback$jscomp$0$$($e_delete_post$$);console.error("deleted books because error post");if($ctrl$$.dynamicDeletePost)try{return await $ctrl$$.dynamicDeletePost($obj_created$$),$callback$jscomp$0$$($e$jscomp$0$$.message||$e$jscomp$0$$.error||$e$jscomp$0$$)}catch($e$$){return console.error($e$$.message||$e$$.error||$e$$),$callback$jscomp$0$$($e$$)}else $callback$jscomp$0$$($e$jscomp$0$$)})}else $callback$jscomp$0$$(null,
|
|
178
|
+
$rs$$)})})})})})})})},pushNotification=controller.pushNotification=($ctrl$$,$_obj$$,$eventName$$="new",$old_obj$$=null,$justFireEvents$$=!1,$options$$={title:"",data:{}})=>{setImmediate(()=>{if($_obj$$.status){var $obj$jscomp$0$$=$_obj$$.toObject?$_obj$$.toObject():{...$_obj$$};$obj$jscomp$0$$._id=$obj$jscomp$0$$._id.toString();$options$$||($options$$={});var $exclude_token$$=$options$$.exclude_token,$trang_thai$$=($obj$jscomp$0$$.trang_thai||(0==$obj$jscomp$0$$.progress?"0":$obj$jscomp$0$$.progress)||
|
|
179
|
+
"").toString();$old_obj$$&&!$justFireEvents$$&&($old_obj$$.trang_thai||(0==$old_obj$$.progress?"0":$old_obj$$.progress)||"").toString()===$trang_thai$$&&($justFireEvents$$=!0);OptionsModel.findOne({id_app:$obj$jscomp$0$$.id_app,id_func:$ctrl$$.name},{option:1}).lean().exec(async($e$jscomp$0$$,$rs$$)=>{setImmediate(async()=>{if($rs$$&&$rs$$.option&&$rs$$.option.users_receive_notification)var $notifications_setting_users_receive_notification$$=$rs$$.option.users_receive_notification;$notifications_setting_users_receive_notification$$&&
|
|
180
|
+
0!==$notifications_setting_users_receive_notification$$.length||($notifications_setting_users_receive_notification$$=await Promise.all((($ctrl$$.options||{}).users_receive_notification_default||[]).map($n$$=>new Promise($resolve$$=>{setImmediate(async()=>{underscore.isFunction($n$$)?$resolve$$(await $n$$($obj$jscomp$0$$)):$resolve$$($n$$)})}))));$notifications_setting_users_receive_notification$$&&($notifications_setting_users_receive_notification$$=$notifications_setting_users_receive_notification$$.filter($u$$=>
|
|
181
|
+
!$u$$.trang_thai||$u$$.trang_thai.toString()===$trang_thai$$||"delete"===$u$$.trang_thai.toString()),$notifications_setting_users_receive_notification$$=$notifications_setting_users_receive_notification$$.filter($func_string$jscomp$1_n$$=>{if(!$func_string$jscomp$1_n$$.condition)return!0;$func_string$jscomp$1_n$$=$func_string$jscomp$1_n$$.condition;0>$func_string$jscomp$1_n$$.indexOf("return ")&&($func_string$jscomp$1_n$$=`return ${$func_string$jscomp$1_n$$}`);try{return evalute($func_string$jscomp$1_n$$,
|
|
182
|
+
{...$obj$jscomp$0$$,master:$obj$jscomp$0$$,data:$obj$jscomp$0$$})}catch($e$$){return console.error($e$$,$func_string$jscomp$1_n$$),!1}}),$notifications_setting_users_receive_notification$$.forEach(async $p$jscomp$0$$=>{setImmediate(async()=>{let $notificationData$$={_id:$obj$jscomp$0$$._id,trang_thai:$trang_thai$$,id_app:$obj$jscomp$0$$.id_app,code:$obj$jscomp$0$$.ma_ct||$ctrl$$.name,id_link:$obj$jscomp$0$$.id_link,code_link:$obj$jscomp$0$$.code_link,event:$eventName$$,action:$eventName$$.toUpperCase(),
|
|
183
|
+
data:$options$$.data};$justFireEvents$$||"delete"===$eventName$$.toLowerCase()?($notificationData$$.title="",$notificationData$$.body=""):($notificationData$$.body=$p$jscomp$0$$.body?compileHtml($p$jscomp$0$$.body,$obj$jscomp$0$$):"",$notificationData$$.title=stripHtmlTags(compileHtml($options$$.title||$p$jscomp$0$$.title||$p$jscomp$0$$.content||"",$obj$jscomp$0$$)));$notificationData$$.title||$notificationData$$.body||($exclude_token$$=null);let $users_will_receive$$=$p$jscomp$0$$.users;$users_will_receive$$||
|
|
184
|
+
($users_will_receive$$=[]);if($p$jscomp$0$$.send_tat_ca_nhan_vien){var $admins_employees_groups_of_user_sandbox$$=(await Usergroup.find({id_app:$obj$jscomp$0$$.id_app,is_employee_group:!0}).lean()).map($g$$=>$g$$._id.toString());0<$admins_employees_groups_of_user_sandbox$$.length&&($admins_employees_groups_of_user_sandbox$$=(await Participant.find({id_app:$obj$jscomp$0$$.id_app,group_id:{$in:$admins_employees_groups_of_user_sandbox$$}}).lean()).map($p$$=>$p$$.email),$users_will_receive$$=$users_will_receive$$.concat($admins_employees_groups_of_user_sandbox$$))}$p$jscomp$0$$.send_phu_trach&&
|
|
185
|
+
$obj$jscomp$0$$.phu_trach&&($users_will_receive$$=$users_will_receive$$.concat([$obj$jscomp$0$$.phu_trach]));$p$jscomp$0$$.send_admin&&($admins_employees_groups_of_user_sandbox$$=(await Participant.find({id_app:$obj$jscomp$0$$.id_app,admin:!0}).lean()).map($p$$=>$p$$.email),$users_will_receive$$=$users_will_receive$$.concat($admins_employees_groups_of_user_sandbox$$));$p$jscomp$0$$.send_attends&&$obj$jscomp$0$$.attends&&($users_will_receive$$=$users_will_receive$$.concat($obj$jscomp$0$$.attends));
|
|
186
|
+
$p$jscomp$0$$.group_id&&($admins_employees_groups_of_user_sandbox$$=(await Participant.find({id_app:$obj$jscomp$0$$.id_app,group_id:$p$jscomp$0$$.group_id}).lean()).map($u$$=>$u$$.email),$users_will_receive$$=$users_will_receive$$.concat($admins_employees_groups_of_user_sandbox$$));$p$jscomp$0$$.send_to_customer&&($obj$jscomp$0$$.ma_kh||$obj$jscomp$0$$.id_kh)&&($admins_employees_groups_of_user_sandbox$$=await mongoose.models.customer.getInfo($obj$jscomp$0$$.id_app,{$or:[{ma_kh:$obj$jscomp$0$$.ma_kh},
|
|
187
|
+
{_id:$obj$jscomp$0$$.id_kh}]},"of_user"))&&($users_will_receive$$=$users_will_receive$$.concat([$admins_employees_groups_of_user_sandbox$$]));$p$jscomp$0$$.send_to_user_created?$users_will_receive$$=$users_will_receive$$.concat([$obj$jscomp$0$$.user_created]):!1===$p$jscomp$0$$.send_to_user_created&&($users_will_receive$$=$users_will_receive$$.filter($u$$=>$u$$!==$obj$jscomp$0$$.user_created));if($p$jscomp$0$$.handle_receivers){$admins_employees_groups_of_user_sandbox$$={obj:$obj$jscomp$0$$,users_will_receive:$users_will_receive$$};
|
|
188
|
+
try{let $str_func$$=$p$jscomp$0$$.handle_receivers;0!==$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);0>$str_func$$.indexOf("async ")&&($users_will_receive$$=evalute($str_func$$,$admins_employees_groups_of_user_sandbox$$))}catch($e$$){console.error($e$$)}}$ctrl$$.options||($ctrl$$.options={});$ctrl$$.options.onEmitEvent||($ctrl$$.options.onEmitEvent=($obj$$,$users_will_receive$$,$next$$,$_notificationData$$)=>{$next$$(null,$users_will_receive$$,$_notificationData$$)});$ctrl$$.options.onEmitEvent(Object.assign({},
|
|
189
|
+
$obj$jscomp$0$$),$users_will_receive$$,($e$$,$_users_will_receive$$,$_notificationData$$)=>{setImmediate(()=>{if($e$$)return console.error("Error emit events",$e$$);$_users_will_receive$$=underscore.uniq($_users_will_receive$$);0<$_users_will_receive$$.length&&app.emitEvent($obj$jscomp$0$$.id_app,`${$ctrl$$.name.toLowerCase()}:${$eventName$$}`,$_notificationData$$||$notificationData$$,$exclude_token$$,$_users_will_receive$$,!0)})},Object.assign({},$notificationData$$),Object.assign({},$p$jscomp$0$$))})}))})})}})};
|
|
189
190
|
async function createIdRef($model$$,$data$$){$model$$=Object.values($model$$.schema.paths).filter($path$$=>$path$$.options&&$path$$.options.ref&&$path$$.options.localField&&$path$$.options.foreignField);try{return await Promise.all($model$$.map($path$$=>new Promise($resove$$=>{setImmediate(async()=>{let $namePath$$=$path$$.path;var $modelRef_modelRefName$$=$path$$.options.ref,$localField_obj$$=$path$$.options.localField;let $foreignField$$=$path$$.options.foreignField;$data$$[$localField_obj$$]?($modelRef_modelRefName$$=
|
|
190
191
|
mongoose.models[$modelRef_modelRefName$$.toLowerCase()])?($localField_obj$$=await $modelRef_modelRefName$$.findOne({id_app:$data$$.id_app,[$foreignField$$]:$data$$[$localField_obj$$]}).lean(),$data$$[$namePath$$]=$localField_obj$$?$localField_obj$$._id.toString():null):$data$$[$namePath$$]=null:$data$$[$namePath$$]=null;$resove$$($path$$)})})))}catch($e2$$){return console.error("error create ref data",$e2$$),null}}
|
|
191
192
|
async function create($user$jscomp$0$$,$ctrl$$,$data$$,$callback$jscomp$1$$,$id_be_supply_by_user$$,$req$$){try{const $model$$=$ctrl$$.model,$voucher_options$$=(await OptionsModel.findOne({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name}).lean()||{}).option,$schema_paths$$=$model$$.schema.paths;let $v_data$$;try{$v_data$$=await asyncBodyToJson($data$$,$ctrl$$,$user$jscomp$0$$.current_id_app,$voucher_options$$)}catch($e$$){return $callback$jscomp$1$$($e$$.message||$e$$.error||$e$$)}underscore.has($schema_paths$$,
|
package/server/libs/post-book.js
CHANGED
|
@@ -9,5 +9,6 @@ utils.round(($detail$$.sl_nhap||0)*$detail$$.tu/$detail$$.mau,round)):($detail$$
|
|
|
9
9
|
fields:["tu","mau",{he_so_qd:"ty_le_qd"}]}),$details$$.forEach($detail$$=>{$detail$$.he_so_qd=$detail$$.he_so_qd||1;$detail$$.mau&&$detail$$.tu?($detail$$.he_so_qd=$detail$$.tu/$detail$$.mau,$detail$$.sl_xuat_qd=utils.round(($detail$$.sl_xuat||0)*$detail$$.tu/$detail$$.mau,round),$detail$$.sl_nhap_qd=utils.round(($detail$$.sl_nhap||0)*$detail$$.tu/$detail$$.mau,round)):($detail$$.sl_xuat_qd=utils.round(($detail$$.sl_xuat||0)*$detail$$.he_so_qd,round),$detail$$.sl_nhap_qd=utils.round(($detail$$.sl_nhap||
|
|
10
10
|
0)*$detail$$.he_so_qd,round))}));if("vatra"===$model_book$$.modelName.toLowerCase()||"vatvao"===$model_book$$.modelName.toLowerCase()){let $rs$$=await Promise.all($details$$.filter($r$$=>$r$$.so_hd&&$r$$.so_hd.toUpperCase()!==($master$$.ma_ct||"").toUpperCase()).map($detail$$=>(async()=>{let $v$$=await $model_book$$.findOne({id_app:$master$$.id_app,so_hd:$detail$$.so_hd,so_seri:$detail$$.so_seri,ky_hieu_hoa_don:$detail$$.ky_hieu_hoa_don,id_ct:{$ne:$master$$._id.toString()}});return $v$$?$v$$.so_hd:
|
|
11
11
|
""})()));$rs$$=$rs$$.filter($r$$=>$r$$);if(0<$rs$$.length)return $callback$$(`S\u1ed1 ho\u00e1 \u0111\u01a1n ${$rs$$.join(",")} \u0111\u00e3 t\u1ed3n t\u1ea1i`)}$details$$=$details$$.map(($detail$$,$line$$)=>{$detail$$.id_ct=$master$$._id.toString();for(let $attr$$ in $model_book$$.schema.paths)if("id_ct"!=$attr$$&&"_id"!=$attr$$){let $v$$=$detail$$[$attr$$];void 0!=$v$$&&null!=$v$$&&""!=$v$$||void 0==$master$$[$attr$$]||($detail$$[$attr$$]=$master$$[$attr$$])}$detail$$.line=$line$$;delete $detail$$.toObject;
|
|
12
|
-
delete $detail$$._id;delete $detail$$.__v;return $detail$$});const $self$$=this;$self$$.remove($error$$=>{if($error$$)return console.error("error delete data post",$error$$),$callback$$($error$$);$model_book$$.create($details$$,async($e$jscomp$0$$,$rs$$)=>{if($e$jscomp$0$$)
|
|
13
|
-
$master$$._id)
|
|
12
|
+
delete $detail$$._id;delete $detail$$.__v;return $detail$$});const $self$$=this;$self$$.remove($error$$=>{if($error$$)return console.error("error delete data post",$error$$),$callback$$($error$$);if(0==$details$$.length)return $callback$$(null,[]);$model_book$$.create($details$$,async($e$jscomp$0$$,$rs$$)=>{if($e$jscomp$0$$){var $contr_msg_error$$=$e$jscomp$0$$.message||$e$jscomp$0$$.error||$e$jscomp$0$$.toString();0<=$contr_msg_error$$.indexOf("E11000 duplicate")&&0<=$contr_msg_error$$.indexOf("id_ct_1_line_1")?
|
|
13
|
+
($rs$$=await $model_book$$.find({id_ct:$master$$._id.toString()}),0<$rs$$.length?$callback$$(null,$rs$$):(console.error("error save data post",$e$jscomp$0$$,$details$$),$self$$.remove(()=>{$callback$$($e$jscomp$0$$)}))):(console.error("error save data post",$e$jscomp$0$$,$details$$),$self$$.remove(()=>{$callback$$($e$jscomp$0$$)}))}else{if($master$$.ma_ct)if($contr_msg_error$$=global.controllers[$master$$.ma_ct.toUpperCase()]){if(!await $contr_msg_error$$.model.findById($master$$._id)){console.error("Ch\u1ee9ng t\u1eeb kh\u00f4ng t\u1ed3n t\u1ea1i. X\u00f3a s\u1ed5 s\u00e1ch",
|
|
14
|
+
$master$$._id);$self$$.remove(()=>{$callback$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng t\u1ed3n t\u1ea1i")});return}}else console.log("not found controller",$master$$.ma_ct.toUpperCase());$callback$$(null,$rs$$);$rs$$&&"sokho"===$model_book$$.modelName.toLowerCase()&&setImmediate(()=>{tontucthoi.tinhTonTucThoi($rs$$,$e$$=>{$e$$&&console.error("L\u1ed7i t\u00ednh t\u1ed3n t\u1ee9c th\u1eddi v\u1eadt t\u01b0",$rs$$,$e$$)})})}})})};module.exports=post;
|
|
@@ -9,6 +9,7 @@ $resolve$$($details$jscomp$0$$)})};
|
|
|
9
9
|
post.prototype.run=async function($callback$jscomp$0$$=()=>{}){if(!this.details)return $callback$jscomp$0$$(null,null);const $Socai$$=this.model||SocaiModel;let $master$$=this.master,$details$jscomp$0$$=await this.runPrepare(this.prepare,this.details);$details$jscomp$0$$=$details$jscomp$0$$.filter($d$$=>$d$$.tk_no&&$d$$.tk_co);if(!$master$$.ngay_ct)return $callback$jscomp$0$$("ngay_ct is not null");async.map($details$jscomp$0$$,($detail$jscomp$0$$,$callback$$)=>{setImmediate(()=>{$detail$jscomp$0$$.ma_kh_no||
|
|
10
10
|
($detail$jscomp$0$$.ma_kh_no=$detail$jscomp$0$$.ma_kh||$master$$.ma_kh);$detail$jscomp$0$$.ma_kh_co||($detail$jscomp$0$$.ma_kh_co=$detail$jscomp$0$$.ma_kh||$master$$.ma_kh);checkData($master$$.id_app,$master$$.ngay_ct,$detail$jscomp$0$$,($e$$,$detail$$)=>{$callback$$($e$$,$detail$$)})})},($but_toan_loi_e$$,$details$$)=>{if($but_toan_loi_e$$)return $callback$jscomp$0$$($but_toan_loi_e$$);$but_toan_loi_e$$=$details$$.filter($detail$$=>isNaN($detail$$.tien_nt)||isNaN($detail$$.tien));0<$but_toan_loi_e$$.length&&
|
|
11
11
|
console.error("Cac but toan khong hop ly",$but_toan_loi_e$$,"cua chung tu",$master$$._id);let $dks$$=$details$$.filter($detail$$=>!(0===$detail$$.tien_nt&&0===$detail$$.tien)&&!isNaN($detail$$.tien_nt)&&!isNaN($detail$$.tien)).map(($detail$$,$nh_dk$$)=>{for(let $attr$$ in $Socai$$.schema.paths)"id_ct"!=$attr$$&&"_id"!=$attr$$&&(void 0!=$detail$$[$attr$$]&&null!=$detail$$[$attr$$]&&""!=$detail$$[$attr$$]||void 0==$master$$[$attr$$]||($detail$$[$attr$$]=$master$$[$attr$$]));$detail$$.nh_dk=$nh_dk$$;
|
|
12
|
-
$detail$$.id_ct=$master$$._id.toString();delete $detail$$.toObject;delete $detail$$._id;delete $detail$$.__v;return $detail$$});$Socai$$.deleteMany({id_ct:$master$$._id.toString()},$error$$=>{if($error$$)return $callback$jscomp$0$$("Don't remove socai \n"+$error$$);$Socai$$.create($dks$$,async($e$$,$
|
|
13
|
-
$master$$._id.toString(),
|
|
14
|
-
$master$$.
|
|
12
|
+
$detail$$.id_ct=$master$$._id.toString();delete $detail$$.toObject;delete $detail$$._id;delete $detail$$.__v;return $detail$$});$Socai$$.deleteMany({id_ct:$master$$._id.toString()},$error$$=>{if($error$$)return $callback$jscomp$0$$("Don't remove socai \n"+$error$$);if(0==$dks$$.length)return $callback$jscomp$0$$(null,[]);$Socai$$.create($dks$$,async($e$$,$msg_error_rs$$)=>{if($e$$)if($msg_error_rs$$=$e$$.message||$e$$.error||$e$$.toString(),0<=$msg_error_rs$$.indexOf("E11000 duplicate")&&0<=$msg_error_rs$$.indexOf("id_ct_1_nh_dk_1"))if($msg_error_rs$$=
|
|
13
|
+
await $Socai$$.find({id_ct:$master$$._id.toString()}),0<$msg_error_rs$$.length)$callback$jscomp$0$$(null,$msg_error_rs$$);else{console.error("Error save socai",$e$$,$master$$);let $q_remove$$={id_app:$master$$.id_app,id_ct:$master$$._id.toString()};$Socai$$.deleteMany($q_remove$$,($_e$$,$rs$$)=>{console.error("delete socai because error when posting",$master$$._id.toString(),JSON.stringify($rs$$),$q_remove$$);$callback$jscomp$0$$($e$$)})}else{console.error("Error save socai",$e$$,$master$$);let $q_remove$$=
|
|
14
|
+
{id_app:$master$$.id_app,id_ct:$master$$._id.toString()};$Socai$$.deleteMany($q_remove$$,($_e$$,$rs$$)=>{console.error("delete socai because error when posting",$master$$._id.toString(),JSON.stringify($rs$$),$q_remove$$);$callback$jscomp$0$$($e$$)})}else if($master$$.ma_ct){let $contr$$=global.controllers[$master$$.ma_ct.toUpperCase()];$contr$$?await $contr$$.model.findById($master$$._id)?$callback$jscomp$0$$(null,$msg_error_rs$$):$Socai$$.deleteMany({id_ct:$master$$._id.toString()},($_e$$,$rs$$)=>
|
|
15
|
+
{console.error("Ch\u1ee9ng t\u1eeb kh\u00f4ng t\u1ed3n t\u1ea1i. X\u00f3a socai",$master$$._id,$rs$$);$callback$jscomp$0$$($e$$)}):(console.log("not found controller",$master$$.ma_ct.toUpperCase()),$callback$jscomp$0$$(null,$msg_error_rs$$))}else $callback$jscomp$0$$(null,$msg_error_rs$$)})})})};module.exports=post;
|
package/server/libs/tinhgiatb.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
module.exports=function($condition$$,$fn$$){if($condition$$&&$condition$$.tu_thang&&$condition$$.den_thang&&$condition$$.nam&&$condition$$.id_app){$condition$$.tu_thang=Number($condition$$.tu_thang);$condition$$.den_thang=Number($condition$$.den_thang);var $ma_kho$$=$condition$$.ma_kho,$tu_ngay$$=moment(new Date($condition$$.nam,$condition$$.tu_thang-1,15)).startOf("month").toDate(),$den_ngay$$=moment(new Date($condition$$.nam,$condition$$.den_thang-1,15)).endOf("month").toDate(),$id_app$$=$condition$$.id_app,
|
|
3
3
|
$query_dmvt$$={id_app:$id_app$$,gia_xuat:"1"};$condition$$.ma_nvt&&($query_dmvt$$.ma_nvt=$condition$$.ma_nvt);$condition$$.ma_ncc&&($query_dmvt$$.ma_ncc=$condition$$.ma_ncc);$condition$$.ma_vt&&($query_dmvt$$.ma_vt=$condition$$.ma_vt);dmvt.find($query_dmvt$$).lean().exec(function($error$jscomp$3$$,$dmvts$$){async.map($dmvts$$,function($vt$$,$callback$$){setImmediate(()=>{tinhgiatb1vt({id_app:$id_app$$,tu_ngay:$tu_ngay$$,den_ngay:$den_ngay$$,ma_vt:$vt$$.ma_vt,ma_kho:$ma_kho$$},function($error$$,$gia$$){if($error$$)return $callback$$($error$$);
|
|
4
4
|
$gia$$.id_app=$id_app$$;$gia$$.ma_kho=$ma_kho$$;$gia$$.status=!0;$callback$$(null,$gia$$)})})},function($error$jscomp$2$$,$bang_gia$$){if($error$jscomp$2$$)return $fn$$($error$jscomp$2$$);$bang_gia$$=underscore.filter($bang_gia$$,function($r$$){return 0!==$r$$.gia||0!==$r$$.tong_sl||0!==$r$$.tong_tien});$error$jscomp$2$$=[];for(let $t$$=$condition$$.tu_thang;$t$$<=$condition$$.den_thang;$t$$++)$error$jscomp$2$$.push($t$$);async.map($error$jscomp$2$$,function($t$$,$callback$jscomp$1$$){async.map($bang_gia$$,
|
|
5
|
-
function($gia$$,$callback$jscomp$0$$){setImmediate(()=>{$gia$$.thang=$t$$;$gia$$.nam=$condition$$.nam;async.parallel({savetogiatb:function($callback$$){let $query_delete$$={id_app:$id_app$$,ma_vt:$gia$$.ma_vt};$ma_kho$$&&($query_delete$$.ma_kho=$ma_kho$$);giatb.
|
|
5
|
+
function($gia$$,$callback$jscomp$0$$){setImmediate(()=>{$gia$$.thang=$t$$;$gia$$.nam=$condition$$.nam;async.parallel({savetogiatb:function($callback$$){let $query_delete$$={id_app:$id_app$$,ma_vt:$gia$$.ma_vt};$ma_kho$$&&($query_delete$$.ma_kho=$ma_kho$$);giatb.deleteMany($query_delete$$,function($error$jscomp$0$$){if($error$jscomp$0$$)return $callback$$($error$jscomp$0$$);giatb.create($gia$$,function($error$$,$result$$){if($error$$)return console.log("Loi khi luu vao bang gia trung binh thang vat tu "+
|
|
6
6
|
$gia$$.ma_vt,$error$$),$callback$$($error$$);$callback$$(null,$result$$)})})}},function($error$$){if($error$$)return $callback$jscomp$0$$($error$$);$callback$jscomp$0$$(null)})})},function($error$$){if($error$$)return $callback$jscomp$1$$($error$$);$callback$jscomp$1$$(null)})},function($error$jscomp$1$$){if($error$jscomp$1$$)return $fn$$($error$jscomp$1$$);let $vouchers_x$$={},$vouchers_n$$={},$ma_vts$$=underscore.pluck($bang_gia$$,"ma_vt");async.parallel({xuat:function($callback$jscomp$0$$){setImmediate(()=>
|
|
7
7
|
{let $query_sokho_x$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},nxt:2,ma_vt:{$in:$ma_vts$$},px_gia_dd:!1};$ma_kho$$&&($query_sokho_x$$.ma_kho=$ma_kho$$);sokho.find($query_sokho_x$$).lean().exec(function($error$jscomp$0$$,$sks$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);if(!$sks$$||0===$sks$$.length)return $callback$jscomp$0$$(null,$vouchers_x$$);async.map($sks$$,function($sk$$,$callback$$){let $voucher$$=$vouchers_x$$[$sk$$.id_ct],$ct$$=mongoose.models[$sk$$.ma_ct.toLowerCase()];
|
|
8
|
-
!$voucher$$&&$ct$$?$ct$$.
|
|
8
|
+
!$voucher$$&&$ct$$?$ct$$.findById($sk$$.id_ct,function($error$$,$v$$){if($error$$)return $callback$$($error$$);$v$$?($voucher$$=$v$$,$vouchers_x$$[$sk$$.id_ct]=$voucher$$):(sokho.deleteMany({id_ct:$sk$$.id_ct.toString()},($e$$,$rs$$)=>{console.log("Khong tim thay phieu xuat. chuong trinh da xoa phieu nay khoi sokho",$sk$$.id_ct,"ma_ct",$sk$$.ma_ct,$sk$$.so_ct,$sk$$.ngay_ct,$rs$$)}),socai.deleteMany({id_ct:$sk$$.id_ct.toString()},($e$$,$rs$$)=>{console.log("Khong tim thay phieu xuat. chuong trinh da xoa phieu nay khoi socai",
|
|
9
9
|
$sk$$.id_ct,"ma_ct",$sk$$.ma_ct,$sk$$.so_ct,$sk$$.ngay_ct,$rs$$)}));$callback$$()}):$callback$$()},function($error$$){if($error$$)return console.log("co loi lay phieu xuat",$error$$),$callback$jscomp$0$$($error$$);$callback$jscomp$0$$(null,$vouchers_x$$)})})})},nhap:function($callback$jscomp$0$$){setImmediate(()=>{let $query_sokho_n$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},nxt:1,ma_vt:{$in:$ma_vts$$},pn_gia_tb:!0,ma_ct:{$ne:"PXC"}};$ma_kho$$&&($query_sokho_n$$.ma_kho=$ma_kho$$);
|
|
10
|
-
sokho.find($query_sokho_n$$,function($error$jscomp$0$$,$sks$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);if(!$sks$$||0===$sks$$.length)return $callback$jscomp$0$$(null,$vouchers_n$$);async.map($sks$$,function($sk$$,$callback$$){let $voucher$$=$vouchers_n$$[$sk$$.id_ct],$ct$$=mongoose.models[$sk$$.ma_ct.toLowerCase()];!$voucher$$&&$ct$$?$ct$$.
|
|
11
|
-
$voucher$$):(sokho.
|
|
10
|
+
sokho.find($query_sokho_n$$,function($error$jscomp$0$$,$sks$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);if(!$sks$$||0===$sks$$.length)return $callback$jscomp$0$$(null,$vouchers_n$$);async.map($sks$$,function($sk$$,$callback$$){let $voucher$$=$vouchers_n$$[$sk$$.id_ct],$ct$$=mongoose.models[$sk$$.ma_ct.toLowerCase()];!$voucher$$&&$ct$$?$ct$$.findById($sk$$.id_ct,function($error$$,$v$$){if($error$$)return $callback$$($error$$);$v$$?($voucher$$=$v$$,$vouchers_n$$[$sk$$.id_ct]=
|
|
11
|
+
$voucher$$):(sokho.deleteMany({id_ct:$sk$$.id_ct.toString()},($e$$,$rs$$)=>{console.log("Khong tim thay phieu nhap. chuong trinh da xoa phieu nay khoi sokho",$sk$$.id_ct,"ma_ct",$sk$$.ma_ct,$sk$$.so_ct,$sk$$.ngay_ct,$rs$$)}),socai.deleteMany({id_ct:$sk$$.id_ct.toString()},($e$$,$rs$$)=>{console.log("Khong tim thay phieu nhap. chuong trinh da xoa phieu nay khoi socai",$sk$$.id_ct,"ma_ct",$sk$$.ma_ct,$sk$$.so_ct,$sk$$.ngay_ct,$rs$$)}));$callback$$()}):$callback$$()},function($error$$){if($error$$)return console.log("co loi lay phieu nhap",
|
|
12
12
|
$error$$),$callback$jscomp$0$$($error$$);$callback$jscomp$0$$(null,$vouchers_n$$)})})})}},function($error$jscomp$0$$){if($error$jscomp$0$$)return $fn$$($error$jscomp$0$$);async.waterfall([function($callback$jscomp$0$$){async.map(underscore.values($vouchers_x$$),($voucher_x$$,$callback$$)=>{setImmediate(()=>{(async()=>{var $details_details_doi_details_kmc$$=$voucher_x$$.details.filter($d$$=>(!$condition$$.ma_vt||$condition$$.ma_vt===$d$$.ma_vt)&&!$d$$.px_gia_dd&&(!$ma_kho$$||$ma_kho$$===($d$$.ma_kho||
|
|
13
13
|
$voucher_x$$.ma_kho||$voucher_x$$.ma_kho_x)));await Promise.all($details_details_doi_details_kmc$$.map($d$$=>(async()=>{var $gia$$=underscore.find($bang_gia$$,$vt$$=>$d$$.ma_vt===$vt$$.ma_vt);$gia$$=$gia$$?$gia$$.gia:0;let $he_so_qd$$=1,$qd$$=await dmqddvt.findOne({id_app:$voucher_x$$.id_app,ma_vt:$d$$.ma_vt,ma_dvt:$d$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=$qd$$.mau?$qd$$.tu/$qd$$.mau:$qd$$.ty_le_qd);$d$$.gia_von=$d$$.gia_von_nt=$gia$$*$he_so_qd$$;$d$$.tien_xuat=$d$$.tien_xuat_nt=Math.round($d$$.sl_xuat*
|
|
14
14
|
$d$$.gia_von,0);console.log("update gia trung binh xuat hang",{ma_ct:$voucher_x$$.ma_ct,so_ct:$voucher_x$$.so_ct,ma_vt:$d$$.ma_vt,gia_von:$d$$.gia_von,gia_tb:$gia$$,he_so_qd:$he_so_qd$$})})()));$voucher_x$$.details_doi&&($details_details_doi_details_kmc$$=$voucher_x$$.details_doi.filter($d$$=>(!$condition$$.ma_vt||$condition$$.ma_vt===$d$$.ma_vt)&&!$d$$.px_gia_dd&&(!$ma_kho$$||$ma_kho$$===($d$$.ma_kho||$voucher_x$$.ma_kho||$voucher_x$$.ma_kho_x))),await Promise.all($details_details_doi_details_kmc$$.map($d$$=>
|
|
@@ -20,15 +20,14 @@ $d$$.tien_xuat=$d$$.tien_xuat_nt=Math.round(($d$$.sl_xuat||$d$$.sl_km||0)*$d$$.g
|
|
|
20
20
|
$d$$.gia_von_nt=$gia$jscomp$5_gia_chuan$$*$he_so_qd$$;$d$$.tien_xuat=$d$$.tien_xuat_nt=Math.round(($d$$.sl_xuat||0)*$d$$.gia_von,0);console.log("update gia trung binh khuyen mai",{ma_ct:$voucher_x$$.ma_ct,so_ct:$voucher_x$$.so_ct,ma_vt:$d$$.ma_vt,gia_von:$d$$.gia_von,gia_tb:$gia$jscomp$5_gia_chuan$$,he_so_qd:$he_so_qd$$})})()))})());$voucher_x$$.promotion&&($details_details_doi_details_kmc$$=$voucher_x$$.promotion.filter($d$$=>(!$condition$$.ma_vt||$condition$$.ma_vt===$d$$.ma_vt)&&!$d$$.px_gia_dd&&
|
|
21
21
|
(!$ma_kho$$||$ma_kho$$===($d$$.ma_kho||$voucher_x$$.ma_kho||$voucher_x$$.ma_kho_x))),await Promise.all($details_details_doi_details_kmc$$.map($d$$=>(async()=>{var $gia$jscomp$6_gia_chuan$$=underscore.find($bang_gia$$,$vt$$=>$d$$.ma_vt===$vt$$.ma_vt);$gia$jscomp$6_gia_chuan$$=$gia$jscomp$6_gia_chuan$$?$gia$jscomp$6_gia_chuan$$.gia:0;let $he_so_qd$$=1,$qd$$=await dmqddvt.findOne({id_app:$voucher_x$$.id_app,ma_vt:$d$$.ma_vt,ma_dvt:$d$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=$qd$$.mau?$qd$$.tu/$qd$$.mau:
|
|
22
22
|
$qd$$.ty_le_qd);$d$$.gia_von_nt=$gia$jscomp$6_gia_chuan$$*$he_so_qd$$;$d$$.gia_von=$d$$.gia_von_nt;$d$$.tien_xuat_nt=Math.round(($d$$.sl_xuat||$d$$.sl_km||0)*$d$$.gia_von,0);$d$$.tien_xuat=$d$$.tien_xuat_nt;console.log("update gia trung binh khuyen mai chung",{ma_ct:$voucher_x$$.ma_ct,so_ct:$voucher_x$$.so_ct,ma_vt:$d$$.ma_vt,gia_von:$d$$.gia_von,gia_tb:$gia$jscomp$6_gia_chuan$$,he_so_qd:$he_so_qd$$})})())));await $voucher_x$$.save();let $voucher_x_data$$=$voucher_x$$.toObject(),$ctrl$$=global.controllers[$voucher_x_data$$.ma_ct.toUpperCase()];
|
|
23
|
-
$ctrl$$&&$ctrl$$.post&&await (async()=>new Promise(($resolve$$,$reject$$)=>{Controller.postData($voucher_x_data$$,$ctrl$$,($e$$,$rs$$)=>{
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
[{where:"ma_vt",fields:"ten_vt"}],()=>{$fn$$(null,$bang_gia$$)})})})})})})})})})}else $fn$$("L\u1ed7i: T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_thang,den_thang,nam,id_app")};
|
|
23
|
+
$ctrl$$&&$ctrl$$.post&&await (async()=>new Promise(($resolve$$,$reject$$)=>{Controller.postData($voucher_x_data$$,$ctrl$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})}))()})().then($rs$$=>{$callback$$(null,$rs$$)}).catch($e$$=>{$callback$$($e$$)})})},$error$$=>{$callback$jscomp$0$$($error$$,$vouchers_x$$)})},function($_vouchers_x$$,$callback$jscomp$0$$){async.map(underscore.values($vouchers_n$$),($voucher_n$$,$callback$$)=>{setImmediate(()=>{(async()=>{var $details_doi$$=$voucher_n$$.details.filter($d$$=>
|
|
24
|
+
(!$condition$$.ma_vt||$condition$$.ma_vt===$d$$.ma_vt)&&($d$$.pn_gia_tb||"PNC"===$voucher_n$$.ma_ct&&!$d$$.px_gia_dd||"PKK"===$voucher_n$$.ma_ct&&!$d$$.px_gia_dd)&&(!$ma_kho$$||$ma_kho$$===$d$$.ma_kho||$ma_kho$$===$voucher_n$$.ma_kho||$ma_kho$$===$voucher_n$$.ma_kho_n));await Promise.all($details_doi$$.map($d$$=>(async()=>{var $gia$jscomp$7_gia_chuan$$=underscore.find($bang_gia$$,$vt$$=>$d$$.ma_vt===$vt$$.ma_vt);$gia$jscomp$7_gia_chuan$$=$gia$jscomp$7_gia_chuan$$?$gia$jscomp$7_gia_chuan$$.gia:0;let $he_so_qd$$=
|
|
25
|
+
1,$qd$$=await dmqddvt.findOne({id_app:$vouchers_n$$.id_app,ma_vt:$d$$.ma_vt,ma_dvt:$d$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=$qd$$.mau?$qd$$.tu/$qd$$.mau:$qd$$.ty_le_qd);$d$$.gia_von_nt=$gia$jscomp$7_gia_chuan$$*$he_so_qd$$;$d$$.gia_von=$d$$.gia_von_nt;"PNC"===$voucher_n$$.ma_ct||"PKK"===$voucher_n$$.ma_ct?($d$$.tien_xuat_nt=Math.round($d$$.sl_xuat*$d$$.gia_von,0),$d$$.tien_xuat=$d$$.tien_xuat_nt):($d$$.tien_nhap_nt=Math.round($d$$.sl_nhap*$d$$.gia_von,0),$d$$.tien_nhap=$d$$.tien_nhap_nt);console.log("update gia trung binh cho phieu nhap gia tb",
|
|
26
|
+
{ma_ct:$vouchers_n$$.ma_ct,so_ct:$vouchers_n$$.so_ct,ma_vt:$d$$.ma_vt,gia_von:$d$$.gia_von,gia_tb:$gia$jscomp$7_gia_chuan$$,he_so_qd:$he_so_qd$$})})()));$voucher_n$$.details_doi&&($details_doi$$=$voucher_n$$.details_doi.filter($d$$=>(!$condition$$.ma_vt||$condition$$.ma_vt===$d$$.ma_vt)&&$d$$.pn_gia_tb&&(!$ma_kho$$||$ma_kho$$===$d$$.ma_kho)),await Promise.all($details_doi$$.map($d$$=>(async()=>{var $gia$jscomp$8_gia_chuan$$=underscore.find($bang_gia$$,$vt$$=>$d$$.ma_vt===$vt$$.ma_vt);$gia$jscomp$8_gia_chuan$$=
|
|
27
|
+
$gia$jscomp$8_gia_chuan$$?$gia$jscomp$8_gia_chuan$$.gia:0;let $he_so_qd$$=1,$qd$$=await dmqddvt.findOne({id_app:$vouchers_n$$.id_app,ma_vt:$d$$.ma_vt,ma_dvt:$d$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=$qd$$.mau?$qd$$.tu/$qd$$.mau:$qd$$.ty_le_qd);$d$$.gia_von_nt=$gia$jscomp$8_gia_chuan$$*$he_so_qd$$;$d$$.gia_von=$d$$.gia_von_nt;$d$$.tien_xuat_nt=Math.round($d$$.sl_xuat*$d$$.gia_von,0);$d$$.tien_xuat=$d$$.tien_xuat_nt;console.log("update gia trung binh cho phieu nhap gia tb doi hang",{ma_ct:$vouchers_n$$.ma_ct,
|
|
28
|
+
so_ct:$vouchers_n$$.so_ct,ma_vt:$d$$.ma_vt,gia_von:$d$$.gia_von,gia_tb:$gia$jscomp$8_gia_chuan$$,he_so_qd:$he_so_qd$$})})())));await $voucher_n$$.save();let $voucher_n_data$$=$voucher_n$$.toObject(),$ctrl$$=global.controllers[$voucher_n_data$$.ma_ct.toUpperCase()];$ctrl$$&&$ctrl$$.post&&await (async()=>new Promise(($resolve$$,$reject$$)=>{Controller.postData($voucher_n_data$$,$ctrl$$,function($e$$,$rs$$){console.log("posted book",{ma_ct:$vouchers_n$$.ma_ct,so_ct:$vouchers_n$$.so_ct},$e$$);if($e$$)return $reject$$($e$$);
|
|
29
|
+
$resolve$$($rs$$)})}))()})().then($rs$$=>{$callback$$(null,$rs$$)}).catch($e$$=>{$callback$$($e$$)})})},function($error$$){$callback$jscomp$0$$($error$$)})}],function($e$jscomp$1$$){if($e$jscomp$1$$)return $fn$$($e$jscomp$1$$);$e$jscomp$1$$={id_app:$condition$$.id_app,ngay:$den_ngay$$,chenh_lech:1};$condition$$.ma_vt&&($e$jscomp$1$$.ma_vt=$condition$$.ma_vt);$condition$$.ma_kho&&($e$jscomp$1$$.ma_kho=$condition$$.ma_kho);ckvt($e$jscomp$1$$,($e$jscomp$0$$,$rs$jscomp$0$$)=>{if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);
|
|
30
|
+
$rs$jscomp$0$$=underscore.filter($rs$jscomp$0$$,$r$$=>0!==$r$$.du00&&(0==$r$$.ton00||.001>Math.abs($r$$.ton00)));$vouchers_x$$=underscore.sortBy(underscore.values($vouchers_x$$),$v$$=>-(new Date($v$$.ngay_ct)).getTime());$vouchers_n$$=underscore.sortBy(underscore.values($vouchers_n$$),$v$$=>-(new Date($v$$.ngay_ct)).getTime());let $chung_tu_cap_nhat_chenh_lech$$={};async.map($rs$jscomp$0$$,($vt$$,$callback$$)=>{setImmediate(()=>{let $d_voucher$$=null;($d_voucher$$=underscore.find($vouchers_x$$,$x$$=>
|
|
31
|
+
underscore.find($x$$.details,$vc$$=>{if($vc$$.ma_vt!=$vt$$.ma_vt||$vc$$.px_gia_dd||$ma_kho$$&&$ma_kho$$!==$vc$$.ma_kho&&$ma_kho$$!==$x$$.ma_kho)return!1;$vc$$.tien_xuat_nt+=$vt$$.du00;$vc$$.tien_xuat=Math.round($vc$$.tien_xuat_nt,0);return!0})))||($d_voucher$$=underscore.find($vouchers_n$$,$n$$=>underscore.find($n$$.details,$vc$$=>{if($vc$$.ma_vt!=$vt$$.ma_vt||$vc$$.pn_gia_tb||$ma_kho$$&&$ma_kho$$!==$vc$$.ma_kho&&$ma_kho$$!==$n$$.ma_kho)return!1;$vc$$.tien_nhap_nt-=$vt$$.du00;$vc$$.tien_nhap=Math.round($vc$$.tien_nhap_nt,
|
|
32
|
+
0);return!0})));$d_voucher$$&&($chung_tu_cap_nhat_chenh_lech$$[$d_voucher$$._id.toString()]=$d_voucher$$);$callback$$(null,$d_voucher$$)})},$_vouchers_chenh_lech_e$$=>{if($_vouchers_chenh_lech_e$$)return $fn$$($_vouchers_chenh_lech_e$$);$_vouchers_chenh_lech_e$$=underscore.values($chung_tu_cap_nhat_chenh_lech$$);async.map($_vouchers_chenh_lech_e$$,($voucher$$,$callback$$)=>{setImmediate(()=>{$voucher$$.save($error$$=>{if($error$$)return $callback$$($error$$);$error$$=$voucher$$.toObject();let $ctrl$$=
|
|
33
|
+
global.controllers[$error$$.ma_ct.toUpperCase()];$ctrl$$&&$ctrl$$.post?(console.log("repost voucher",$error$$.ma_ct,$error$$.so_ct,"..."),Controller.postData($error$$,$ctrl$$,($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})):$callback$$(null)})})},$e$$=>{if($e$$)return $fn$$($e$$);$bang_gia$$.joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:"ten_vt"}],()=>{$fn$$(null,$bang_gia$$)})})})})})})})})})}else $fn$$("L\u1ed7i: T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_thang,den_thang,nam,id_app")};
|
|
@@ -5,20 +5,19 @@ $extension_root$$=configs.paths.images;$extension_root$$||($extension_root$$=__d
|
|
|
5
5
|
$error$$=10*$value$$.width/100;watermark.embed({type:"image",source:$file_name$$,logo:$file_logo$$,destination:$file_name_watermark$$,position:{logoX:$value$$.width-$error$$-10,logoY:10,logoHeight:$error$$,logoWidth:$error$$}},function($status$$){1===$status$$.status?$resolve$$($file_name_watermark$$):(console.log("status set watermark",$status$$),$resolve$$($file_name$$))})})}):(console.log("file logo watermark is not exists",$file_logo$$),$file_name$$)},configResizeImage=async($_size_file_name_resize$$,
|
|
6
6
|
$file_name$$,$extension$$,$recache$$)=>{let $size$$,$cache$$;if($_size_file_name_resize$$)switch($_size_file_name_resize$$.toString().toUpperCase()){case "64":case "X":$size$$=64;$cache$$=!0;break;case "256":$size$$=256;$cache$$=!0;break;case "S":case "320":$size$$=320;$cache$$=!0;break;case "512":case "M":$size$$=512;$cache$$=!0;break;case "1024":case "L":$size$$=1024;$cache$$=!0;break;case "1080":case "FULLHD":$size$$=1080;$cache$$=!0;break;case "1440":case "2K":$size$$=1440;$cache$$=!0;break;default:try{$size$$=
|
|
7
7
|
Number($_size_file_name_resize$$)}catch($e$$){console.log("size param must be X or S or M or L or a number")}}return $size$$?($_size_file_name_resize$$=`${$file_name$$}.${$size$$}.${$extension$$}`,!$recache$$&&fs.existsSync($_size_file_name_resize$$)?{file_name_resize:$_size_file_name_resize$$,exist:!0}:{cache:$cache$$,size:$size$$,file_name_resize:$_size_file_name_resize$$}):{file_name_resize:$file_name$$}};
|
|
8
|
-
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,"file",{sort:{ten_file:1},onView:($user$$,$items$$,$next$$)=>{$items$$.forEach($item$$=>{$item$$.file&&(delete $item$$.file.encoding,delete $item$$.file.mimetype,delete $item$$.file.path,$item$$.id_app&&configs.api_url&&($item$$.download_link=`${configs.api_url||""}/${$item$$.id_app}/file/download/${$item$$._id.toString()}`))});$next$$(null,$items$$)}});$contr_router$$.creating=async function($file_name$jscomp$
|
|
9
|
-
$obj$$,$fn$$){if($obj$$.file&&$obj$$.read_image){$file_name$jscomp$
|
|
10
|
-
|
|
11
|
-
$obj
|
|
12
|
-
|
|
13
|
-
$output
|
|
14
|
-
$
|
|
15
|
-
|
|
16
|
-
($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
path.
|
|
20
|
-
$
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
fs.createReadStream($output$jscomp$2_rs$$);$readStream$$.on("open",function(){$readStream$$.pipe($res$$)});$readStream$$.on("error",function($err$$){$res$$.end($err$$)})}else $res$$.status(400).send("File n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i")}else $res$$.status(400).send("Kh\u00f4ng t\u00ecm th\u1ea5y file n\u00e0y")})})})})};
|
|
8
|
+
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,"file",{sort:{ten_file:1},onView:($user$$,$items$$,$next$$)=>{$items$$.forEach($item$$=>{$item$$.file&&(delete $item$$.file.encoding,delete $item$$.file.mimetype,delete $item$$.file.path,$item$$.id_app&&configs.api_url&&($item$$.download_link=`${configs.api_url||""}/${$item$$.id_app}/file/download/${$item$$._id.toString()}`))});$next$$(null,$items$$)}});$contr_router$$.creating=async function($file_name$jscomp$2_input_user$$,
|
|
9
|
+
$obj$$,$fn$$){if($obj$$.file&&$obj$$.read_image){$file_name$jscomp$2_input_user$$=$obj$$.file.name;var $extension$jscomp$2_root$$=$obj$$.file.extension.toLowerCase();if(0<=["png","jpg"].indexOf($extension$jscomp$2_root$$)&&($extension$jscomp$2_root$$=configs.paths.uploads,$extension$jscomp$2_root$$||($extension$jscomp$2_root$$=__dirname,$extension$jscomp$2_root$$=path.dirname($extension$jscomp$2_root$$),$extension$jscomp$2_root$$=path.dirname($extension$jscomp$2_root$$),$extension$jscomp$2_root$$=
|
|
10
|
+
path.join($extension$jscomp$2_root$$,"uploads")),$file_name$jscomp$2_input_user$$=path.join($extension$jscomp$2_root$$,$file_name$jscomp$2_input_user$$),fs.existsSync($file_name$jscomp$2_input_user$$))){$extension$jscomp$2_root$$=require("node-tesseract-ocr");const $config$$={lang:"vie+eng"};try{const $text$$=await $extension$jscomp$2_root$$.recognize($file_name$jscomp$2_input_user$$,$config$$);$obj$$.text_from_image=$text$$}catch($error$$){return console.error($error$$),$fn$$($error$$.message)}}}$fn$$(null,
|
|
11
|
+
$obj$$)};$contr_router$$.created=function($file_name$jscomp$3_user$$,$obj$$,$fn$$){if($obj$$.file){$file_name$jscomp$3_user$$=$obj$$.file.name;var $extension$jscomp$3_input$jscomp$1_root$$=$obj$$.file.extension.toLowerCase();if(0<=["mp4","mov","avi"].indexOf($extension$jscomp$3_input$jscomp$1_root$$)){$extension$jscomp$3_input$jscomp$1_root$$=configs.paths.uploads;$extension$jscomp$3_input$jscomp$1_root$$||($extension$jscomp$3_input$jscomp$1_root$$=__dirname,$extension$jscomp$3_input$jscomp$1_root$$=
|
|
12
|
+
path.dirname($extension$jscomp$3_input$jscomp$1_root$$),$extension$jscomp$3_input$jscomp$1_root$$=path.dirname($extension$jscomp$3_input$jscomp$1_root$$),$extension$jscomp$3_input$jscomp$1_root$$=path.join($extension$jscomp$3_input$jscomp$1_root$$,"uploads"));$extension$jscomp$3_input$jscomp$1_root$$=path.join($extension$jscomp$3_input$jscomp$1_root$$,$file_name$jscomp$3_user$$);let $output$$=configs.paths.videos;$output$$||($output$$=__dirname,$output$$=path.dirname($output$$),$output$$=path.dirname($output$$),
|
|
13
|
+
$output$$=path.join($output$$,"videos"));fs.existsSync($output$$)||fs.mkdirSync($output$$);$output$$=path.join($output$$,$obj$$._id.toString());fs.existsSync($output$$)||fs.mkdirSync($output$$);$output$$=path.join($output$$,$file_name$jscomp$3_user$$);convertVideo($extension$jscomp$3_input$jscomp$1_root$$,$output$$).catch($e$$=>{console.error("Can't convert video. Error:",$e$$)})}}else console.log("file not exists",$obj$$);$fn$$(null,$obj$$)};$contr_router$$.deleted=function($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$,
|
|
14
|
+
$rs$$,$next$$){if($rs$$.file){$extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$=$rs$$.file.name;let $root$$=configs.paths.uploads;$root$$||($root$$=__dirname,$root$$=path.dirname($root$$),$root$$=path.dirname($root$$),$root$$=path.join($root$$,"uploads"));$extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$=path.join($root$$,$extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$);fs.existsSync($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$)&&fs.unlink($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$,
|
|
15
|
+
function($e$$){$e$$&&console.error($e$$)});$extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$=$rs$$.file.extension.toLowerCase();0<=["mp4","mov","avi"].indexOf($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$)&&($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$=configs.paths.videos,$extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$||($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$=__dirname,$extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$=
|
|
16
|
+
path.dirname($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$),$extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$=path.dirname($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$),$extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$=path.join($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$,"videos")),$extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$=path.join($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$,$rs$$._id.toString()),
|
|
17
|
+
fs.existsSync($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$)&&deleteFolderRecursive($extension$jscomp$4_file_name$jscomp$4_output$jscomp$1_user$$))}else console.log("file not exists",$rs$$);$next$$(null,$rs$$)};$contr_router$$.route(function($router$$){$router$$.route("/:id_app/file/download/:id").get(function($req$$,$res$$){let $id$$=$req$$.params.id,$size$$=$req$$.query.size||$req$$.query.resize||"FULLHD";app.findOne({_id:$req$$.user.current_id_app}).lean().exec(function($e$$,$app_info$$){if($e$$||
|
|
18
|
+
!$app_info$$)return $res$$.status(400).send("Kh\u00f4ng th\u1ec3 t\u1ea3i file n\u00e0y");model.findOne({_id:$id$$}).lean().exec(async($e$jscomp$4_file_name$$,$rs$$)=>{if($e$jscomp$4_file_name$$)return $res$$.status(400).send($e$jscomp$4_file_name$$);if($rs$$){$e$jscomp$4_file_name$$=$rs$$.file.name;let $extension$$=$rs$$.file.extension,$root$$=configs.paths.uploads;$root$$||($root$$=__dirname,$root$$=path.dirname($root$$),$root$$=path.dirname($root$$),$root$$=path.join($root$$,"uploads"));$e$jscomp$4_file_name$$=
|
|
19
|
+
path.join($root$$,$e$jscomp$4_file_name$$);if(fs.existsSync($e$jscomp$4_file_name$$))if(0<=["png","jpg","jpeg"].indexOf($extension$$)){let $_new_file$$=await setWaterMark4Image($app_info$$,$e$jscomp$4_file_name$$,$extension$$,$req$$.query.recache),$_resize_conf$$=await configResizeImage($size$$,$_new_file$$,$extension$$,$req$$.query.recache);if($_resize_conf$$.exist)return gm($_resize_conf$$.file_name_resize).stream(function($err$$,$stdout$$){$stdout$$.pipe($res$$)});let $_gm$$=gm($_new_file$$);$_gm$$.size(function($error$jscomp$0$$,
|
|
20
|
+
$orgin_file_size$$){$orgin_file_size$$&&$_resize_conf$$.size&&$_resize_conf$$.size<$orgin_file_size$$.width&&$_resize_conf$$.size<$orgin_file_size$$.height&&($_gm$$=$_gm$$.resize($_resize_conf$$.size));$_resize_conf$$.cache?setImmediate(()=>{$_gm$$.write($_resize_conf$$.file_name_resize,function($error$$){if($error$$)console.error("save resize image:",$error$$.message),setImmediate(()=>{$res$$.sendFile($_new_file$$)});else return gm($_resize_conf$$.file_name_resize).stream(function($err$$,$stdout$$){$stdout$$.pipe($res$$)})})}):
|
|
21
|
+
$_gm$$.stream(function($err$$,$stdout$$){$stdout$$.pipe($res$$)})})}else $res$$.download($e$jscomp$4_file_name$$,$rs$$.file.originalname);else $res$$.status(400).send("File n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i")}else $res$$.status(400).send("Kh\u00f4ng t\u00ecm th\u1ea5y file n\u00e0y")})})});$router$$.route("/:id_app/file/stream/:id/:file").get(function($req$$,$res$$){let $id$$=$req$$.params.id;app.findOne({_id:$req$$.user.current_id_app}).lean().exec(function($e$$,$app_info$$){if($e$$||!$app_info$$)return $res$$.status(400).send("Kh\u00f4ng th\u1ec3 stream file n\u00e0y");
|
|
22
|
+
model.findOne({_id:$id$$}).lean().exec(async($e$jscomp$6_file_name$$,$output$jscomp$2_rs$$)=>{if($e$jscomp$6_file_name$$)return $res$$.status(400).send($e$jscomp$6_file_name$$);if($output$jscomp$2_rs$$){$e$jscomp$6_file_name$$=$output$jscomp$2_rs$$.file.name;var $file$jscomp$1_root$$=$req$$.params.file;".ts"==$file$jscomp$1_root$$.substr(-3)&&($e$jscomp$6_file_name$$=$file$jscomp$1_root$$);$file$jscomp$1_root$$=configs.paths.videos;$file$jscomp$1_root$$||($file$jscomp$1_root$$=__dirname,$file$jscomp$1_root$$=
|
|
23
|
+
path.dirname($file$jscomp$1_root$$),$file$jscomp$1_root$$=path.dirname($file$jscomp$1_root$$),$file$jscomp$1_root$$=path.join($file$jscomp$1_root$$,"videos"));$output$jscomp$2_rs$$=path.join($file$jscomp$1_root$$,$output$jscomp$2_rs$$._id.toString(),$e$jscomp$6_file_name$$);if(fs.existsSync($output$jscomp$2_rs$$)){const $readStream$$=fs.createReadStream($output$jscomp$2_rs$$);$readStream$$.on("open",function(){$readStream$$.pipe($res$$)});$readStream$$.on("error",function($err$$){$res$$.end($err$$)})}else $res$$.status(400).send("File n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i")}else $res$$.status(400).send("Kh\u00f4ng t\u00ecm th\u1ea5y file n\u00e0y")})})})})};
|
package/server/route.js
CHANGED
|
@@ -25,8 +25,6 @@ $app$$.use("/public",$public_router$$);const $funcs_public_inited$$={};configs.p
|
|
|
25
25
|
path.join(__dirname,"images"),$imgPath$$=path.join($root_dir$$,$req$$.params.folder,$req$$.params.filename);if(fs.existsSync($imgPath$$)){let $size$$,$cache$$;if($req$$.query.size||$req$$.query.resize)switch(String($req$$.query.size||$req$$.query.resize).toUpperCase()){case "64":case "X":$size$$=64;$cache$$=!0;break;case "128":$size$$=128;$cache$$=!0;break;case "320":case "S":$size$$=320;$cache$$=!0;break;case "512":case "M":$size$$=512;$cache$$=!0;break;case "1024":case "L":$size$$=1024;$cache$$=
|
|
26
26
|
!0;break;default:try{$size$$=Number($req$$.query.size||$req$$.query.resize)}catch($e$$){console.log("size param must be X or S or M or L or a number")}}if($size$$){let $file_name_resize$$=path.join($root_dir$$,$req$$.params.folder,String($size$$)+"."+$req$$.params.filename);if(fs.existsSync($file_name_resize$$))return gm($file_name_resize$$).stream(function($err$$,$stdout$$){$stdout$$.pipe($res$$)});$cache$$?gm($imgPath$$).resize($size$$,null).write($file_name_resize$$,function($error$$){if($error$$)console.log("Can't resize image \n"+
|
|
27
27
|
$error$$),$res$$.sendFile($imgPath$$);else return gm($file_name_resize$$).stream(function($err$$,$stdout$$){$stdout$$.pipe($res$$)})}):gm($imgPath$$).resize($size$$,null).stream(function($err$$,$stdout$$){$stdout$$.pipe($res$$)})}else $res$$.sendFile($imgPath$$)}else $res$$.sendFile(path.join(__dirname,"images","others","noimage.png"))});const $Labelinfo$$=global.getModel("labelinfo");$app$$.get("/labels/:labelid",$createRateLimiterMiddleware_limiter_others$$,function($labelid_req$$,$res$$){$labelid_req$$=
|
|
28
|
-
$labelid_req$$.params.labelid.toUpperCase();$Labelinfo$$.find({labelid:$labelid_req$$}).lean().exec(($e$$,$labels$$)=>{if($e$$)return $res$$.status(400).send($e$$);let $_labels$$={};$labels$$.forEach($l$$=>{$_labels$$[$l$$.textid]=$l$$});$res$$.send($_labels$$)})});const $qr$$=require("qr-image");$app$$.get("/qrcode",$createRateLimiterMiddleware_limiter_others$$,function($req$$,$res$$){let $report$$=$req$$.query.report;$report$$||($report$$=$req$$.query.data)&&($report$$=
|
|
29
|
-
if(!$report$$)return $res$$.status(400).send("miss parameter 'report'");setImmediate(()=>{const $code$$=$qr$$.image($report$$,{type:"svg"});$res$$.type("svg");$code$$.pipe($res$$)})});
|
|
30
|
-
|
|
31
|
-
$app$$.post("/sendmail",function($req$$,$res$$){setImmediate(()=>{let $msg$$=$req$$.body;if("KHGFIUWPPC"!==$msg$$.secretKey)return $res$$.status(400).send("Not allow");if(!$msg$$.to||!$msg$$.subject||!$msg$$.message)return $res$$.status(400).send("Msg is not valid");$nodemailer$$.createTransport({host:"mail.flexbiz.app",port:25,secure:!1,auth:{user:"info",pass:""},tls:{rejectUnauthorized:!1},name:$msg$$.name}).sendMail({from:"info@flexbiz.app",to:$msg$$.to,subject:$msg$$.subject,text:$msg$$.message,
|
|
32
|
-
html:$msg$$.message},$e$$=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send("OK")})})})}$cb$$()};
|
|
28
|
+
$labelid_req$$.params.labelid.toUpperCase();$Labelinfo$$.find({labelid:$labelid_req$$}).lean().exec(($e$$,$labels$$)=>{if($e$$)return $res$$.status(400).send($e$$);let $_labels$$={};$labels$$.forEach($l$$=>{$_labels$$[$l$$.textid]=$l$$});$res$$.send($_labels$$)})});if(configs.has_api_barcode){const $qr$$=require("qr-image");$app$$.get("/qrcode",$createRateLimiterMiddleware_limiter_others$$,function($req$$,$res$$){let $report$$=$req$$.query.report;$report$$||($report$$=$req$$.query.data)&&($report$$=
|
|
29
|
+
Buffer.from($report$$,"base64").toString("utf8"));if(!$report$$)return $res$$.status(400).send("miss parameter 'report'");setImmediate(()=>{const $code$$=$qr$$.image($report$$,{type:"svg"});$res$$.type("svg");$code$$.pipe($res$$)})});const $bwipjs$$=require("bwip-js"),$stream$$=require("stream");$app$$.get("/barcode",$createRateLimiterMiddleware_limiter_others$$,function($height_req$$,$res$$){let $code$$=$height_req$$.query.code||"code128",$data$$=$height_req$$.query.data;$height_req$$=Number($height_req$$.query.height||
|
|
30
|
+
10);if(!$data$$)return $res$$.status(400).send({error:"Thi\u1ebfu c\u00e1c tham s\u1ed1 data"});$bwipjs$$.toBuffer({bcid:$code$$,text:$data$$,scale:3,height:$height_req$$,includetext:!0,textxalign:"center"},function($bufferStream_e$$,$png$$){$bufferStream_e$$?(console.error($bufferStream_e$$,$code$$,$data$$),$res$$.status(400).send({error:$bufferStream_e$$.message||$bufferStream_e$$.error||$bufferStream_e$$})):($bufferStream_e$$=new $stream$$.PassThrough,$bufferStream_e$$.end($png$$),$bufferStream_e$$.pipe($res$$))})})}}$cb$$()};
|