flexbiz-server 12.5.35 → 12.5.36
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/libs/ckvt.js +12 -268
- package/server/libs/ckvtcapphat.js +1 -1
- package/server/libs/post-sokho.js +13 -13
- package/server/libs/tinhgiatb.js +38 -739
- package/server/models/approve.js +10 -9
- package/server/models/pbl.js +3 -3
- package/server/models/transaction.js +4 -4
- package/server/modules/lists/ls-dmnv.js +4 -8
- package/server/modules/reports/rp-bkchamcong.js +4 -0
- package/server/modules/vouchers/vo-hd2.js +10 -10
- package/server/modules/vouchers/vo-pbl.js +69 -69
- package/server/modules/vouchers/vo-so1.js +20 -20
package/server/models/approve.js
CHANGED
|
@@ -64,20 +64,21 @@ $emails$$=[$rq$$.user_request],$rqs$$=$requests$$.map($a$$=>$a$$.user_request),$
|
|
|
64
64
|
await File.find({id_link:$rq$$.data._id}).lean():void 0},null,$emails$$,!0,!0)}catch($e$$){console.error("Error send email",$e$$.message)}}).catch($e$$=>{console.error($e$$)}):console.log("don't find email template or report template to send notify email to request user")}).catch($e$$=>{console.error($e$$)})}};
|
|
65
65
|
model.approve=async function($encrypted$$,$callback$$,$token$$,$options$$={reason:""}){try{const $result_approve$$=await executeInTransaction(async()=>{console.log("[approve] \u0111ang duy\u1ec7t y\u00eau c\u1ea7u....");let $user_approved$$;if(underscore.isObject($encrypted$$)){var $_c$$=$encrypted$$.id_request;$user_approved$$=$encrypted$$.email;var $approve_user_approved_name$$=$encrypted$$.name;var $key_data_trang_thai$$=$encrypted$$.trang_thai}else $key_data_trang_thai$$=utils.decrypt($encrypted$$),
|
|
66
66
|
$_c$$=$key_data_trang_thai$$.id_request,$user_approved$$=$key_data_trang_thai$$.email,$approve_user_approved_name$$=$key_data_trang_thai$$.name,$key_data_trang_thai$$=$key_data_trang_thai$$.trang_thai;if(!$_c$$||!$user_approved$$)throw"request id and approve user are required";if(!global.mongoose.Types.ObjectId.isValid($_c$$))throw"request id '"+$_c$$+"' is not valid";$_c$$={_id:$_c$$};$key_data_trang_thai$$!==void 0&&$key_data_trang_thai$$!==null&&($_c$$.trang_thai=$key_data_trang_thai$$);const $rq$$=
|
|
67
|
-
await model.findOne($_c$$);if($rq$$.date_approved)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t b\u1edfi "+$rq$$.user_approved_name;if($rq$$.date_denied)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 b\u1ecb t\u1eeb ch\u1ed1i duy\u1ec7t b\u1edfi "+$rq$$.user_denied_name;$rq$$.date_approved=new Date;$rq$$.user_approved=$user_approved$$;$rq$$.user_approved_name=$approve_user_approved_name$$;$rq$$.approved_reason
|
|
68
|
-
$u$$.email.indexOf($user_approved$$)>=0))throw"User n\u00e0y kh\u00f4ng c\u00f3 quy\u1ec1n duy\u1ec7t y\u00eau c\u1ea7u n\u00e0y";$approve_user_approved_name$$=await $rq$$.save();if($rq$$.update_after_approve&&$rq$$.update_after_approve.data){console.log("[approve] t\u00ecm controller c\u1ee7a ch\u1ee9ng t\u1eeb \u0111\u00e3 duy\u1ec7t",$rq$$.update_after_approve.module||$rq$$.update_after_approve.model);let $module_name
|
|
69
|
-
$module_name$$&&($ctrl$$=global.controllers[$module_name$$.toUpperCase()]);let $_m$$;$rq$$.update_after_approve.model?$_m$$=global.getModel($rq$$.update_after_approve.model):$ctrl$$&&($_m$$=$ctrl$$.getProperty("model"));if(!$_m$$){console.error("[approve] kh\u00f4ng t\u00ecm th\u1ea5y model c\u1ee7a ch\u1ee9ng t\u1eeb",$rq$$.update_after_approve.model||$module_name$$.toUpperCase());return}console.log("[approve] c\u1eadp nh\u1eadt data cho ch\u1ee9ng t\u1eeb sau khi duy\u1ec7t..."
|
|
70
|
-
await $_m$$.updateOne({_id:$rq$$.id_ct},$rq$$.update_after_approve.data);if($ctrl$$){const $obj$$=await $_m$$.findOne({_id:$rq$$.id_ct});if($obj$$){onAfterCommit(()=>{$ctrl$$.emit("saved",$obj$$);$ctrl$$.emit("updated",$obj$$)});const $u$$=await global.getModel("user").findOne({email:$user_approved$$});$u$$.current_id_app=$obj$$.id_app;const $app_info$$=await App.findOne({_id:$obj$$.id_app});console.log("[approve] post s\u1ed5 s\u00e1ch sau khi duy\u1ec7t ch\u1ee9ng t\u1eeb...",$ctrl$$.name
|
|
71
|
-
$obj$$.so_ct,$obj$$.trang_thai);await new Promise(($resolve$$,$reject$$)=>{$ctrl$$.postData($obj$$,$e$$=>{if($e$$)return console.error("[approve] [postData]",$e$$,$module_name$$,$obj$$.so_ct,$obj$$.trang_thai),$reject$$($e$$);$resolve$$()},{kiem_tra_han_muc_cong_no:!1})});$ctrl$$.handleAfterAproved&&await $ctrl$$.handleAfterAproved($obj$$,$rq$$);await new Promise(($resolve$$,$reject$$)=>{$ctrl$$.onView($u$$,[$obj$$.toObject()],async($channel_e$$,$rs$$)=>{$channel_e$$&&console.error("[approve][approved][onView]",
|
|
67
|
+
await model.findOne($_c$$);if(!$rq$$)throw"Y\u00eau c\u1ea7u kh\u00f4ng t\u1ed3n t\u1ea1i";if($rq$$.date_approved)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t b\u1edfi "+$rq$$.user_approved_name;if($rq$$.date_denied)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 b\u1ecb t\u1eeb ch\u1ed1i duy\u1ec7t b\u1edfi "+$rq$$.user_denied_name;$rq$$.date_approved=new Date;$rq$$.user_approved=$user_approved$$;$rq$$.user_approved_name=$approve_user_approved_name$$;$rq$$.approved_reason=
|
|
68
|
+
$options$$.reason||"";if(!$rq$$.user_approves||!$rq$$.user_approves.find($u$$=>$u$$.email.indexOf($user_approved$$)>=0))throw"User n\u00e0y kh\u00f4ng c\u00f3 quy\u1ec1n duy\u1ec7t y\u00eau c\u1ea7u n\u00e0y";$approve_user_approved_name$$=await $rq$$.save();if($rq$$.update_after_approve&&$rq$$.update_after_approve.data){console.log("[approve] t\u00ecm controller c\u1ee7a ch\u1ee9ng t\u1eeb \u0111\u00e3 duy\u1ec7t",$rq$$.update_after_approve.module||$rq$$.update_after_approve.model);let $module_name$$=
|
|
69
|
+
$rq$$.update_after_approve.module||$rq$$.update_after_approve.model,$ctrl$$;$module_name$$&&($ctrl$$=global.controllers[$module_name$$.toUpperCase()]);let $_m$$;$rq$$.update_after_approve.model?$_m$$=global.getModel($rq$$.update_after_approve.model):$ctrl$$&&($_m$$=$ctrl$$.getProperty("model"));if(!$_m$$){console.error("[approve] kh\u00f4ng t\u00ecm th\u1ea5y model c\u1ee7a ch\u1ee9ng t\u1eeb",$rq$$.update_after_approve.model||$module_name$$.toUpperCase());return}console.log("[approve] c\u1eadp nh\u1eadt data cho ch\u1ee9ng t\u1eeb sau khi duy\u1ec7t...",
|
|
70
|
+
$module_name$$);await $_m$$.updateOne({_id:$rq$$.id_ct},$rq$$.update_after_approve.data);if($ctrl$$){const $obj$$=await $_m$$.findOne({_id:$rq$$.id_ct});if($obj$$){onAfterCommit(()=>{$ctrl$$.emit("saved",$obj$$);$ctrl$$.emit("updated",$obj$$)});const $u$$=await global.getModel("user").findOne({email:$user_approved$$});$u$$.current_id_app=$obj$$.id_app;const $app_info$$=await App.findOne({_id:$obj$$.id_app});console.log("[approve] post s\u1ed5 s\u00e1ch sau khi duy\u1ec7t ch\u1ee9ng t\u1eeb...",$ctrl$$.name,
|
|
71
|
+
$module_name$$,$obj$$.so_ct,$obj$$.trang_thai);await new Promise(($resolve$$,$reject$$)=>{$ctrl$$.postData($obj$$,$e$$=>{if($e$$)return console.error("[approve] [postData]",$e$$,$module_name$$,$obj$$.so_ct,$obj$$.trang_thai),$reject$$($e$$);$resolve$$()},{kiem_tra_han_muc_cong_no:!1})});$ctrl$$.handleAfterAproved&&await $ctrl$$.handleAfterAproved($obj$$,$rq$$);await new Promise(($resolve$$,$reject$$)=>{$ctrl$$.onView($u$$,[$obj$$.toObject()],async($channel_e$$,$rs$$)=>{$channel_e$$&&console.error("[approve][approved][onView]",
|
|
72
72
|
$channel_e$$);$channel_e$$=`${$module_name$$.toLowerCase()}-${"request_approved"}`;$obj$$.id_app&&($channel_e$$=`${$channel_e$$}-${$obj$$.id_app}`);let $message$$=JSON.stringify($rs$$[0]);try{await global.clientRedis.publish($channel_e$$,$message$$)}catch($e$$){console.error("[approve] [sendNotifyApproved] fire event","request_approved",$e$$)}console.log("[approve][approved][requestApprove] t\u1ea1o y\u00eau c\u1ea7u duy\u1ec7t ti\u1ebfp theo...");$ctrl$$.requestApprove($app_info$$,$u$$,$rs$$[0],
|
|
73
73
|
$e$$=>{if($e$$)return $reject$$($e$$);$resolve$$()},null,$rq$$)})})}else console.error("[approve] kh\u00f4ng tim th\u1ea5y l\u1ed7i data \u0111\u00e3 duy\u1ec7t theo id_ct",$rq$$.id_ct)}else console.error("[approve] kh\u00f4ng t\u00ecm th\u1ea5y controller c\u1ee7a ch\u1ee9ng t\u1eeb",$module_name$$)}else console.log("[approve] kh\u00f4ng c\u00f3 d\u1eef li\u1ec7u c\u1ea7n c\u1eadp nh\u1eadt sau khi \u0111\u00e3 duy\u1ec7t");onAfterCommit(()=>{model.sendNotifyApproved($rq$$,$token$$)});return $approve_user_approved_name$$});
|
|
74
74
|
$callback$$(null,$result_approve$$)}catch($e$$){console.error("[approve][approved]",$e$$),$callback$$($e$$)}};
|
|
75
75
|
model.deny=async function($encrypted$$,$callback$$,$token$$,$options$$={reason:""}){try{const $result_reject$$=await executeInTransaction(async()=>{let $user_denied$$;if(underscore.isObject($encrypted$$)){var $_c$jscomp$2__id$$=$encrypted$$.id_request;$user_denied$$=$encrypted$$.email;var $approve$$=$encrypted$$.name;var $key_data$jscomp$1_trang_thai$$=$encrypted$$.trang_thai}else $key_data$jscomp$1_trang_thai$$=utils.decrypt($encrypted$$),$_c$jscomp$2__id$$=$key_data$jscomp$1_trang_thai$$.id_request,
|
|
76
76
|
$user_denied$$=$key_data$jscomp$1_trang_thai$$.email,$approve$$=$key_data$jscomp$1_trang_thai$$.name,$key_data$jscomp$1_trang_thai$$=$key_data$jscomp$1_trang_thai$$.trang_thai;if(!$_c$jscomp$2__id$$||!$user_denied$$)throw"request id and deny user are required";if(!global.mongoose.Types.ObjectId.isValid($_c$jscomp$2__id$$))throw"request id '"+$_c$jscomp$2__id$$+"' is not valid";$_c$jscomp$2__id$$={_id:$_c$jscomp$2__id$$};$key_data$jscomp$1_trang_thai$$!==void 0&&$key_data$jscomp$1_trang_thai$$!==null&&
|
|
77
|
-
($_c$jscomp$2__id$$.trang_thai=$key_data$jscomp$1_trang_thai$$);const $rq$$=await model.findOne($_c$jscomp$2__id$$);if($rq$$.date_approved)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t b\u1edfi "+$rq$$.user_approved_name;if($rq$$.date_denied)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 b\u1ecb t\u1eeb ch\u1ed1i duy\u1ec7t b\u1edfi "+$rq$$.user_denied_name;$rq$$.date_denied=new Date;$rq$$.user_denied=$user_denied
|
|
78
|
-
$options$$.reason||"";if(!$rq$$.user_approves||!$rq$$.user_approves.find($u$$=>$u$$.email.indexOf($user_denied$$)>=0))throw"User n\u00e0y kh\u00f4ng c\u00f3 quy\u1ec1n duy\u1ec7t y\u00eau c\u1ea7u n\u00e0y";$approve$$=await $rq$$.save();onAfterCommit(async()=>{let $title$$=`[B\u1ecb t\u1eeb ch\u1ed1i] ${$rq$$.title}`;var $option$jscomp$2_template$$=await Options.findOne({id_app:$rq$$.id_app,id_func:{$regex:"^"+$rq$$.ma_ct+"$",$options:"i"}}).lean();
|
|
79
|
-
$option$jscomp$2_template$$.option&&$option$jscomp$2_template$$.option.system&&($option$jscomp$2_template$$.option.system.templateEmail||$option$jscomp$2_template$$.option.system.templateRpt)){var $_data$jscomp$3_app_info$$=await App.findOne({_id:$rq$$.id_app}).lean();if(!$_data$jscomp$3_app_info$$)return console.log("khong the tim thay thong tin cong ty nay");let $requests$$=await model.find({id_ct:$rq$$.data._id}).sort({trang_thai:-1}).lean();
|
|
80
|
-
{where:{user_approved:"email"},fields:{user_approved_name:"name"}});await $requests$$.asyncJoinModel2($rq$$.id_app,participant,{where:{user_denied:"email"},fields:{user_denied_name:"name"}});$option$jscomp$2_template$$=($rq$$.template_content||(($option$jscomp$2_template$$.option||{}).system||{}).templateEmail||(($option$jscomp$2_template$$.option||{}).system||{}).templateRpt).split("<em>").join("").split("</em>").join("");$option$jscomp$2_template
|
|
77
|
+
($_c$jscomp$2__id$$.trang_thai=$key_data$jscomp$1_trang_thai$$);const $rq$$=await model.findOne($_c$jscomp$2__id$$);if(!$rq$$)throw"Y\u00eau c\u1ea7u kh\u00f4ng t\u1ed3n t\u1ea1i";if($rq$$.date_approved)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t b\u1edfi "+$rq$$.user_approved_name;if($rq$$.date_denied)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 b\u1ecb t\u1eeb ch\u1ed1i duy\u1ec7t b\u1edfi "+$rq$$.user_denied_name;$rq$$.date_denied=new Date;$rq$$.user_denied=$user_denied$$;
|
|
78
|
+
$rq$$.user_denied_name=$approve$$;$rq$$.denied_reason=$options$$.reason||"";if(!$rq$$.user_approves||!$rq$$.user_approves.find($u$$=>$u$$.email.indexOf($user_denied$$)>=0))throw"User n\u00e0y kh\u00f4ng c\u00f3 quy\u1ec1n duy\u1ec7t y\u00eau c\u1ea7u n\u00e0y";$approve$$=await $rq$$.save();onAfterCommit(async()=>{let $title$$=`[B\u1ecb t\u1eeb ch\u1ed1i] ${$rq$$.title}`;var $option$jscomp$2_template$$=await Options.findOne({id_app:$rq$$.id_app,id_func:{$regex:"^"+$rq$$.ma_ct+"$",$options:"i"}}).lean();
|
|
79
|
+
if($rq$$.template_content||$option$jscomp$2_template$$&&$option$jscomp$2_template$$.option&&$option$jscomp$2_template$$.option.system&&($option$jscomp$2_template$$.option.system.templateEmail||$option$jscomp$2_template$$.option.system.templateRpt)){var $_data$jscomp$3_app_info$$=await App.findOne({_id:$rq$$.id_app}).lean();if(!$_data$jscomp$3_app_info$$)return console.log("khong the tim thay thong tin cong ty nay");let $requests$$=await model.find({id_ct:$rq$$.data._id}).sort({trang_thai:-1}).lean();
|
|
80
|
+
await $requests$$.asyncJoinModel2($rq$$.id_app,participant,{where:{user_approved:"email"},fields:{user_approved_name:"name"}});await $requests$$.asyncJoinModel2($rq$$.id_app,participant,{where:{user_denied:"email"},fields:{user_denied_name:"name"}});$option$jscomp$2_template$$=($rq$$.template_content||(($option$jscomp$2_template$$.option||{}).system||{}).templateEmail||(($option$jscomp$2_template$$.option||{}).system||{}).templateRpt).split("<em>").join("").split("</em>").join("");$option$jscomp$2_template$$=
|
|
81
|
+
`
|
|
81
82
|
<div>
|
|
82
83
|
<h3>Y\u00eau c\u1ea7u d\u01b0\u1edbi \u0111\u00e2y \u0111\u00e3 b\u1ecb t\u1eeb ch\u1ed1i duy\u1ec7t b\u1edfi ${$rq$$.user_denied_name} </h3>
|
|
83
84
|
<div style='color:red'>L\u00fd do t\u1eeb ch\u1ed1i: ${$rq$$.denied_reason} </div>
|
package/server/models/pbl.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const moment=require("moment"),validVt=require("../libs/validator-vt"),validator=require("../libs/validator"),detailSchema=new Schema({ma_vt:{type:String,required:!0,uppercase:!0,maxlength:1024,trim:!0},ma_dvt:{type:String,required:!0,maxlength:32,trim:!0},px_gia_dd:{type:Boolean,default:!1},ton_kho:{type:Number,default:0},sl_order:{type:Number,default:0},sl_xuat:{type:Number,default:0},sl_gui_bep:{type:Number,default:0},sl_gui_bartender:{type:Number,default:0},sl_ht:{type:Number,default:0},gia_von:{type:Number,
|
|
2
2
|
default:0},gia_von_nt:{type:Number,default:0},tien_xuat:{type:Number,default:0},tien_xuat_nt:{type:Number,default:0},gia_ban:{type:Number,default:0},gia_ban_nt:{type:Number,default:0},tien_hang:{type:Number,default:0},tien_hang_nt:{type:Number,default:0},gia_ban_chua_thue:Boolean,id_cs_ck:String,ty_le_ck:{type:Number,default:0},tien_ck:{type:Number,default:0},tien_ck_nt:{type:Number,default:0},tien:{type:Number,default:0},tien_nt:{type:Number,default:0},gia_ban_ct_nt:{type:Number},gia_ban_ct:{type:Number},
|
|
3
3
|
tien_hang_ct:{type:Number,default:0},tien_hang_ct_nt:{type:Number,default:0},tien_thue_nt:{type:Number},tien_thue:{type:Number},thue_suat:{type:Number},tk_thue_co:String,tk_thue_co_treo:String,cs_discount:Schema.Types.Mixed,cs_tien_ck:{type:Number,default:0},cs_ty_le_ck:{type:Number,default:0},cs_sl_ap_dung:{type:Number,default:0},cs_gt_hd_tu:{type:Number,default:0},cs_gt_hd_den:{type:Number,default:0},ck_sl_tu2:[],tien_evoucher_duoc_pb:{type:Number,default:0},promotion:Schema.Types.Mixed,combo:Schema.Types.Mixed,
|
|
4
|
-
sl_ap_dung_km:{type:Number,default:0},km_yn_for:String,id_cs:String,ma_thue:String,ma_hoa_don:{type:String,uppercase:!0,trim:!0,maxlength:32},ky_hieu_hoa_don:{type:String,uppercase:!0,trim:!0,maxlength:32},ma_tc:{type:String,uppercase:!0,trim:!0,maxlength:32},so_hd:{type:String,uppercase:!0,trim:!0,maxlength:32},so_seri:{type:String,uppercase:!0,trim:!0,maxlength:32},ngay_hd:{type:Date},ma_bp:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_phi:{type:String,
|
|
5
|
-
trim:!0},ma_hd:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_dt:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_nv:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_lo:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},han_sd:{type:Date},ma_tt1:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},ma_tt2:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},ma_tt3:{type:String,default:"",uppercase:!0,
|
|
6
|
-
tien_hang_options_ct:Number,tien_thue_options:Number,sign_user:String,sign_data:Schema.Types.Mixed,signature:String,order_time:{type:Date,default:Date.now},finish_time:{type:Date},ghi_chu:{type:String},exfields_detail:Schema.Types.Mixed,line:{type:Number,default:0},het_hang:{type:Boolean,default:!1}});detailSchema.validate={ma_vt:validVt.existsVt,ma_kho:validVt.existsKho,ma_dvt:validator.existsDvt};
|
|
4
|
+
sl_ap_dung_km:{type:Number,default:0},km_yn_for:String,id_cs:String,ma_thue:String,ma_hoa_don:{type:String,uppercase:!0,trim:!0,maxlength:32},ky_hieu_hoa_don:{type:String,uppercase:!0,trim:!0,maxlength:32},ma_tc:{type:String,uppercase:!0,trim:!0,maxlength:32},so_hd:{type:String,uppercase:!0,trim:!0,maxlength:32},so_seri:{type:String,uppercase:!0,trim:!0,maxlength:32},ngay_hd:{type:Date},ong_ba:String,ma_so_thue:String,ma_bp:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_phi:{type:String,
|
|
5
|
+
uppercase:!0,default:"",maxlength:32,trim:!0},ma_hd:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_dt:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_nv:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_lo:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},han_sd:{type:Date},ma_tt1:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},ma_tt2:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},ma_tt3:{type:String,default:"",uppercase:!0,
|
|
6
|
+
maxlength:32,trim:!0},options:[],tien_hang_options:Number,tien_hang_options_ct:Number,tien_thue_options:Number,sign_user:String,sign_data:Schema.Types.Mixed,signature:String,order_time:{type:Date,default:Date.now},finish_time:{type:Date},ghi_chu:{type:String},exfields_detail:Schema.Types.Mixed,line:{type:Number,default:0},het_hang:{type:Boolean,default:!1}});detailSchema.validate={ma_vt:validVt.existsVt,ma_kho:validVt.existsKho,ma_dvt:validator.existsDvt};
|
|
7
7
|
const pblSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},ma_dvcs:{type:String,required:!0,maxlength:1024},ma_ct:{type:String,default:"PBL",required:!0,uppercase:!0,maxlength:32,trim:!0},ma_gd:{type:String,default:"0",maxlength:32,trim:!0},so_ct:{type:String,uppercase:!0,trim:!0,maxlength:32},ngay_ct:{type:Date,default:Date.now,required:!0},ma_nt:{type:String,required:"ma_nt is required",default:"VND",trim:!0,uppercase:!0,maxlength:32},ty_gia:{type:Number,required:!0,min:0,default:1},
|
|
8
8
|
ma_kh:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ten_kh:String,ma_kho:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ten_kho:String,ma_bp:{type:String,uppercase:!0,maxlength:32,trim:!0},ten_bp:String,ma_ban:{type:String,uppercase:!0,maxlength:32,trim:!0},ma_ban0:{type:String,uppercase:!0,maxlength:32,trim:!0},ma_ca:{type:String,uppercase:!0,maxlength:32,trim:!0},ty_le_ck_hd:{type:Number,default:0},tien_ck_hd:{type:Number,default:0},ong_ba:{type:String,maxlength:1024},sender_email:{type:String,
|
|
9
9
|
maxlength:128},id_trans:{type:String,maxlength:1024},paymentByPoints:{type:Number,default:0},exchangeRate:Number,tien_paymentByPoints:{type:Number,default:0},evouchers:[global.Schema.Types.Mixed],tien_evoucher:Number,tk_no_evoucher:String,tk_co_evoucher:String,pt_thanh_toan:{type:String},tien_thu:{type:Number,default:0},bank_payment_info:{},pt_thanh_toan2:{type:String},tien_thu2:{type:Number,default:0},bank_payment_info2:{},ghi_chu_tt:String,con_no:{type:Number,default:0},phai_tra:{type:Number,default:0},
|
|
@@ -10,7 +10,7 @@ $reject$$)=>{$trans$$.save(async($e_master_users_will_receive$$,$rs$$)=>{if($e_m
|
|
|
10
10
|
$ma_dvcs$$=await global.getModel("dvcs").findOne({id_app:$rs$$.id_app}).lean();$e_master_users_will_receive$$=$rs$$.toObject();$e_master_users_will_receive$$.dien_giai=$e_master_users_will_receive$$.description;$e_master_users_will_receive$$.ma_dvcs=(($ma_dvcs$$||{})._id||"").toString();$details_sc_kh_no_notificationData_title$$=[{tk_no:$rs$$.tk_no,tk_co:$rs$$.tk_co,tien_nt:$rs$$.amount,tien:$rs$$.amount,ma_nt:$rs$$.denom.toUpperCase(),ty_gia:1,ma_kh_no:($details_sc_kh_no_notificationData_title$$||
|
|
11
11
|
{}).ma_kh,ma_kh_co:($kh_co$$||{}).ma_kh}];(new PostSocai($e_master_users_will_receive$$,$details_sc_kh_no_notificationData_title$$)).run($e$$=>{$e$$&&console.error($e$$)})}$e_master_users_will_receive$$=[$rs$$.sender.email,$rs$$.receiver.email];$details_sc_kh_no_notificationData_title$$=`${$data$$.sender_email} \u0111\u00e3 chuy\u1ec3n cho ${$data$$.receiver_email} ${$rs$$.amount} ${$rs$$.denom} v\u1edbi n\u1ed9i dung: ${$data$$.description}`;if($data$$.sender_email===$data$$.id_app||$data$$.receiver_email===
|
|
12
12
|
$data$$.id_app)$details_sc_kh_no_notificationData_title$$=`${$data$$.description}`;$details_sc_kh_no_notificationData_title$$={_id:$rs$$._id,id_app:$data$$.id_app,title:$details_sc_kh_no_notificationData_title$$,body:$details_sc_kh_no_notificationData_title$$,code:"transaction",event:"new",action:"NEW"};global.getModel("app").emitEvent($data$$.id_app,`${$details_sc_kh_no_notificationData_title$$.code}:${$details_sc_kh_no_notificationData_title$$.event}`,$details_sc_kh_no_notificationData_title$$,
|
|
13
|
-
null,$e_master_users_will_receive$$,!0);$resolve$$($rs$$.toObject())})})};model.getTrans=async $id_trans$$=>
|
|
14
|
-
model.balance=async($email$$,$date_to$$)=>{$date_to$$||=new Date;$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"sender.email":$email$$},{"receiver.email":$email$$}]})).map($tran$$=>$tran$$.sender.email===$email$$?0-$tran$$.amount:$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};
|
|
15
|
-
model.in=async($email$$,$date_to$$)=>{$date_to$$||=new Date;$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"receiver.email":$email$$}]})).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};
|
|
16
|
-
model.out=async($email$$,$date_to$$)=>{$date_to$$||=new Date;$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"sender.email":$email$$}]})).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};module.exports=model;
|
|
13
|
+
null,$e_master_users_will_receive$$,!0);$resolve$$($rs$$.toObject())})})};model.getTrans=async $id_trans$$=>model.findOne({id_trans:$id_trans$$});model.deleteTrans=async $id_trans$$=>{$id_trans$$=typeof $id_trans$$==="string"?{id_trans:$id_trans$$}:{...$id_trans$$};console.log("delete transaction",$id_trans$$);await model.deleteMany($id_trans$$)};
|
|
14
|
+
model.balance=async($email$$,$date_to$$)=>{$date_to$$||=new Date;$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"sender.email":$email$$},{"receiver.email":$email$$}]}).inTxn()).map($tran$$=>$tran$$.sender.email===$email$$?0-$tran$$.amount:$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};
|
|
15
|
+
model.in=async($email$$,$date_to$$)=>{$date_to$$||=new Date;$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"receiver.email":$email$$}]}).inTxn()).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};
|
|
16
|
+
model.out=async($email$$,$date_to$$)=>{$date_to$$||=new Date;$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"sender.email":$email$$}]}).inTxn()).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};module.exports=model;
|
|
@@ -7,11 +7,7 @@ dmdoi,[{where:{ma_bp:"ma_bp",ma_doi:"ma_doi"},fields:"ten_doi"}],function(){$cal
|
|
|
7
7
|
function(){$callback$$(null,$items$$)})},$callback$$=>{$items$$.filter($item$$=>$item$$.chuc_vu).joinModel2($user$$.current_id_app,group,[{where:{chuc_vu:"_id"},fields:[{ten_chuc_vu:"group_name"},{color:"color"},{muc_tieu_bieu:"muc_tieu_bieu"}]}],function(){$callback$$(null,$items$$)})},$callback$$=>{async.mapLimit($items$$,20,($item$$,$callback$$)=>{($item$$.bo_phan||[]).filter($item$$=>$item$$.chuc_vu).joinModel2($user$$.current_id_app,group,[{where:{chuc_vu:"_id"},fields:[{ten_chuc_vu:"group_name"},
|
|
8
8
|
{color:"color"},{muc_tieu_bieu:"muc_tieu_bieu"}]}],function(){$callback$$(null,$items$$)})},()=>{$callback$$(null,$items$$)})},$callback$$=>{async.mapLimit($items$$,20,($item$$,$callback$$)=>{($item$$.bo_phan||[]).filter($item$$=>$item$$.ma_bp).joinModel2($user$$.current_id_app,dmbp,[{where:{ma_bp:"ma_bp"},fields:[{ten_bp:"ten_bp"}]}],function(){$callback$$(null,$items$$)})},()=>{$callback$$(null,$items$$)})}],()=>{$items$$.filter($item$$=>$item$$.bo_phan).forEach($item$$=>{$item$$.bo_phan.forEach($bp$$=>
|
|
9
9
|
{$bp$$.active=!$bp$$.den_ngay||$bp$$.den_ngay>=new Date;$bp$$.active&&($item$$.ma_bp=$item$$.map_bp||$bp$$.ma_bp,$item$$.ten_bp=$item$$.ten_bp||$bp$$.ten_bp,$item$$.phu_trach=$item$$.phu_trach||$bp$$.phu_trach,$item$$.chuc_vu=$item$$.chuc_vu||$bp$$.chuc_vu)})});$next$$(null,$items$$)})},onImport:($user$$,$data$$,$columns$$,$next$$)=>{async.mapLimit($data$$,20,function($r$$,$callback$$){async.series({nhom:function($callback$$){$r$$.group_name&&!$r$$.nh_kh?group.findOneAndUpdate({id_app:$user$$.current_id_app,
|
|
10
|
-
group_type:"DMNV",group_name:{$regex:$r$$.group_name,$options:"i"}},{group_name:$r$$.group_name,group_type:"DMNV",status:!0},{new:!0,upsert:!0},function($e$$,$n$$){if($e$$)return $callback$$($e$$);$r$$.nh_nv=$n$$._id.toString();$callback$$(null)}):$callback$$()}},function(){$callback$$()})},function(){$next$$()})},
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
($req$$.condition={user:$req$$.user.email});$req$$.permission=!0;$next$$()}});$contr_router$$.validating=async($id_app_user$$,$obj$$,$next$$,$options$$={})=>{if($options$$.action=="add"&&!$obj$$.ma_nv&&$obj$$.ten_nv){$id_app_user$$=$id_app_user$$.current_id_app;try{let $ma_nv$$=await model.asyncCreateEmployeeCode($id_app_user$$,$obj$$.ten_nv);$obj$$.ma_nv=$ma_nv$$;$next$$(null,$obj$$)}catch($e$$){console.error($e$$),$next$$($e$$)}}else $next$$(null,$obj$$)};$contr_router$$.route();$contr_router$$.on("saved",
|
|
15
|
-
async $data$$=>{let $_usergroup$$;try{$_usergroup$$=await Usergroup.getInfo($data$$.id_app,{is_employee_group:!0})}catch($e$$){return}$data$$.user&&$_usergroup$$&&User.findOne({email:$data$$.user},($e$$,$rs$$)=>{if($rs$$)Participant.createParticipant({id_app:$data$$.id_app,email:$data$$.user,group_id:$_usergroup$$._id,active:!0},$e$$=>{if($e$$)return console.log("can't add user",$data$$.user,"to company")});else{var $result$$=new User;$result$$.email=$data$$.user;$result$$.name=$data$$.ten_nv;$result$$.email2=
|
|
16
|
-
$data$$.email;$result$$.local={};$result$$.local.email=$result$$.email;$result$$.local.name=$result$$.name;$result$$.local.picture="/images/avatar.jpg";$result$$.local.password=$result$$.generateHash($result$$.email+($data$$.default_password||$result$$.email+"@123456"));$result$$.save($e$$=>{if($e$$)return console.log($e$$.message);Participant.createParticipant({id_app:$data$$.id_app,email:$result$$.email,group_id:$_usergroup$$._id,active:!0},$e$$=>{if($e$$)return console.log("can't add user",$result$$.email,
|
|
17
|
-
"to company")})})}})})};module.exports=dmnv;
|
|
10
|
+
group_type:"DMNV",group_name:{$regex:$r$$.group_name,$options:"i"}},{group_name:$r$$.group_name,group_type:"DMNV",status:!0},{new:!0,upsert:!0},function($e$$,$n$$){if($e$$)return $callback$$($e$$);$r$$.nh_nv=$n$$._id.toString();$callback$$(null)}):$callback$$()}},function(){$callback$$()})},function(){$next$$()})},onQuery:($req$$,$next$$)=>{if($req$$.obj&&$req$$.obj.user===$req$$.user.email)return $req$$.permission=!0,$next$$();$req$$.permission||($req$$.condition={user:$req$$.user.email});$req$$.permission=
|
|
11
|
+
!0;$next$$()}});$contr_router$$.validating=async($id_app_user$$,$obj$$,$next$$,$options$$={})=>{if($options$$.action=="add"&&!$obj$$.ma_nv&&$obj$$.ten_nv){$id_app_user$$=$id_app_user$$.current_id_app;try{let $ma_nv$$=await model.asyncCreateEmployeeCode($id_app_user$$,$obj$$.ten_nv);$obj$$.ma_nv=$ma_nv$$;$next$$(null,$obj$$)}catch($e$$){console.error($e$$),$next$$($e$$)}}else $next$$(null,$obj$$)};$contr_router$$.route();$contr_router$$.on("saved",async $data$$=>{let $_usergroup$$;try{$_usergroup$$=
|
|
12
|
+
await Usergroup.getInfo($data$$.id_app,{is_employee_group:!0})}catch($e$$){return}$data$$.user&&$_usergroup$$&&User.findOne({email:$data$$.user},($e$$,$rs$$)=>{if($rs$$)Participant.createParticipant({id_app:$data$$.id_app,email:$data$$.user,group_id:$_usergroup$$._id,active:!0},$e$$=>{if($e$$)return console.log("can't add user",$data$$.user,"to company")});else{var $result$$=new User;$result$$.email=$data$$.user;$result$$.name=$data$$.ten_nv;$result$$.email2=$data$$.email;$result$$.local={};$result$$.local.email=
|
|
13
|
+
$result$$.email;$result$$.local.name=$result$$.name;$result$$.local.picture="/images/avatar.jpg";$result$$.local.password=$result$$.generateHash($result$$.email+($data$$.default_password||$result$$.email+"@123456"));$result$$.save($e$$=>{if($e$$)return console.log($e$$.message);Participant.createParticipant({id_app:$data$$.id_app,email:$result$$.email,group_id:$_usergroup$$._id,active:!0},$e$$=>{if($e$$)return console.log("can't add user",$result$$.email,"to company")})})}})})};module.exports=dmnv;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const chamcong=global.getModel("chamcong"),controller=require("../../controllers/controllerRPT"),async=require("async"),permission=require("../../libs/permission");
|
|
2
|
+
module.exports=function($router$$){new controller($router$$,"bkchamcong",function($req$$,$callback$$){async.map($req$$.query.id_apps||[$req$$.query.id_app],($id_app$$,$callback$$)=>{permission.hasRight($id_app$$,$req$$.user.email,"chamcong","view",async function($error$$,$permission$$){if(!$permission$$)return $callback$$(`B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n v\u1edbi c\u00f4ng ty c\u00f3 id '${$id_app$$}'`);$error$$={};$error$$.id_app=$id_app$$;$error$$.ngay={$gte:$req$$.query.tu_ngay,$lte:$req$$.query.den_ngay};
|
|
3
|
+
$req$$.query.ma_nv&&($error$$.ma_nv=$req$$.query.ma_nv);$req$$.query.ma_bp&&($error$$.ma_bp=$req$$.query.ma_bp);chamcong.find($error$$).lean().then(async $congs$$=>{await $congs$$.asyncJoinModel2($id_app$$,"dmloaicong",[{where:{ma_loai_cong:"ma_loai_cong"},fields:["ten_loai_cong","color"]}]);await $congs$$.asyncJoinModel2($id_app$$,global.getModel("dmnv"),[{where:{ma_nv:"ma_nv"},fields:["ten_nv"]}]);await $congs$$.asyncJoinModel2($id_app$$,global.getModel("dmbp"),[{where:{ma_bp:"ma_bp"},fields:["ten_bp"]}]);
|
|
4
|
+
$callback$$(null,$congs$$)}).catch($e$$=>{$callback$$($e$$)})})},($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$callback$$(null,$rs$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]))})})};
|
|
@@ -25,18 +25,18 @@ $detail$jscomp$4_pk$$.ma_kho=$d$jscomp$6_pk$$.ma_kho_pk_xuat,$detail$jscomp$4_pk
|
|
|
25
25
|
$d$jscomp$8_pk$$.tien_nhap_pk_nt||0,$d$jscomp$6_pk$$.tien_xuat=$d$jscomp$6_pk$$.tien_xuat_nt*($obj$$.ty_gia||1),$d$jscomp$6_pk$$.sl_nhap=0,$d$jscomp$6_pk$$.tien_nhap_nt=$d$jscomp$6_pk$$.tien_nhap=0,$d$jscomp$6_pk$$.tien_hang_nt=$d$jscomp$6_pk$$.tien_hang=0,$d$jscomp$6_pk$$.tien_ck=$d$jscomp$6_pk$$.tien_ck_nt=$d$jscomp$6_pk$$.ty_le_ck=0,$d$jscomp$6_pk$$.tien_phi=$d$jscomp$6_pk$$.tien_phi_nt=0,$product_details_npp$$.push($d$jscomp$6_pk$$);for(let $d$$ of($obj$$.ds_pk_xuat||[]).filter($d$$=>$d$$.ma_pk_xuat&&
|
|
26
26
|
$d$$.sl_pk_xuat))$d$jscomp$8_pk$$={...$d$$},$d$jscomp$8_pk$$.ma_vt=$d$$.ma_pk_xuat,$d$jscomp$8_pk$$.ma_dvt=$d$$.ma_dvt_pk_xuat,$d$jscomp$8_pk$$.ma_kho=$obj$$.ma_kho_npp||$customer$$.ma_kho_npp,$d$jscomp$8_pk$$.ma_kh=$obj$$.ma_kh,$d$jscomp$8_pk$$.nxt=1,$d$jscomp$8_pk$$.tk_co=$obj$$.tk_co,$d$jscomp$8_pk$$.sl_nhap=$d$$.sl_pk_xuat,$d$jscomp$8_pk$$.gia_von_nt=$d$$.gia_von_pk_xuat_nt||0,$d$jscomp$8_pk$$.gia_von=$d$jscomp$8_pk$$.gia_von_nt*($obj$$.ty_gia||1),$d$jscomp$8_pk$$.tien_nhap_nt=$d$$.tien_xuat_pk_nt||
|
|
27
27
|
0,$d$jscomp$8_pk$$.tien_nhap=$d$jscomp$8_pk$$.tien_nhap_nt*($obj$$.ty_gia||1),$d$jscomp$8_pk$$.sl_xuat=0,$d$jscomp$8_pk$$.tien_xuat_nt=$d$jscomp$8_pk$$.tien_xuat=0,$d$jscomp$8_pk$$.tien_hang_nt=$d$jscomp$8_pk$$.tien_hang=0,$d$jscomp$8_pk$$.tien_ck=$d$jscomp$8_pk$$.tien_ck_nt=$d$jscomp$8_pk$$.ty_le_ck=0,$d$jscomp$8_pk$$.tien_phi=$d$jscomp$8_pk$$.tien_phi_nt=0,$product_details_npp$$.push($d$jscomp$8_pk$$);await $product_details$$.filter($d$$=>!$d$$.ma_dvt).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",
|
|
28
|
-
fields:["ma_dvt","tk_vt","tk_gv","tk_tl"]});await ($obj$$.details||[]).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",fields:"ten_phu_cap ten_vt ma_dvt tk_vt tk_gv tk_tl tg_tk".split(" ")});async.series({phu_cap:$callback$$=>{setImmediate(async()=>{let $details_phu_cap$$=_.cloneDeep(($obj$$.details||[]).filter($d$$=>$d$$.luong_tho&&$d$$.tg_tk));$details_phu_cap$$.length==0&&($details_phu_cap$$=_.cloneDeep(($obj$$.details||[]).filter($d$$=>$d$$.luong_tho)));for(var $cust$jscomp$1_d$$ of $details_phu_cap$$)$cust$jscomp$1_d$$.ma_nv=
|
|
28
|
+
fields:["ma_dvt","tk_vt","tk_gv","tk_tl"]});await ($obj$$.details||[]).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",fields:"ten_phu_cap ten_vt ma_dvt tk_vt tk_gv tk_tl tg_tk".split(" ")});let $ket_qua_post_sokho$$;async.series({phu_cap:$callback$$=>{setImmediate(async()=>{let $details_phu_cap$$=_.cloneDeep(($obj$$.details||[]).filter($d$$=>$d$$.luong_tho&&$d$$.tg_tk));$details_phu_cap$$.length==0&&($details_phu_cap$$=_.cloneDeep(($obj$$.details||[]).filter($d$$=>$d$$.luong_tho)));for(var $cust$jscomp$1_d$$ of $details_phu_cap$$)$cust$jscomp$1_d$$.ma_nv=
|
|
29
29
|
$obj$$.ma_nv_giao_hang||$cust$jscomp$1_d$$.ma_nv,$cust$jscomp$1_d$$.thang=(new Date($obj$$.ngay_ct)).getMonth()+1,$cust$jscomp$1_d$$.nam=(new Date($obj$$.ngay_ct)).getFullYear(),$cust$jscomp$1_d$$.ten_phu_cap=$cust$jscomp$1_d$$.ten_phu_cap||$cust$jscomp$1_d$$.ten_vt,$cust$jscomp$1_d$$.tien=$cust$jscomp$1_d$$.luong_tho;$obj$$.ma_kh&&($cust$jscomp$1_d$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,phu_cap:{$gte:0}}).lean())&&($cust$jscomp$1_d$$={ma_nv:$obj$$.ma_nv_giao_hang,
|
|
30
30
|
thang:(new Date($obj$$.ngay_ct)).getMonth()+1,nam:(new Date($obj$$.ngay_ct)).getFullYear(),ten_phu_cap:$cust$jscomp$1_d$$.ten_phu_cap||"Ph\u1ee5 c\u1ea5p theo kh\u00e1ch h\u00e0ng",tien:$cust$jscomp$1_d$$.phu_cap},$details_phu_cap$$.push($cust$jscomp$1_d$$));(new PostBook($obj$$,$details_phu_cap$$,global.getModel("phucap"),async($detail$$,$callback$$)=>{$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})},post_tdttno:function($callback$$){account.findOne({tk:$obj$$.tk_no,
|
|
31
31
|
id_app:$obj$$.id_app},{tk_cn:1},async function($d_chinh_error$$,$tk$$){if($d_chinh_error$$)return $callback$$($d_chinh_error$$);if($tk$$&&$tk$$.tk_cn===!0){const $ma_kh_no$$=$obj$$.ma_kh_no||$obj$$.ma_kh;let $kh_bo_xung$$=($obj$$.details||[]).filter($d$$=>($d$$.ma_kh_no||$d$$.ma_kh)&&($d$$.ma_kh_no||$d$$.ma_kh)!=$ma_kh_no$$);$kh_bo_xung$$.forEach($d$$=>{$d$$.tien_nt=($d$$.tien_ct_nt||0)-($d$$.tien_ck_nt||0)-($d$$.gt_vt_du||0)+($d$$.tien_thue_nt||0);$d$$.tien=$d$$.tien_nt*$obj$$.ty_gia;$d$$.ma_kh=
|
|
32
32
|
$d$$.ma_kh_no||$d$$.ma_kh});$kh_bo_xung$$=await $kh_bo_xung$$.asyncGroupBy(["ma_kh"],["tien_nt","tien"]);const $bao_hiem$$=[];$obj$$.tien_bh_chi&&$obj$$.ma_kh_bh&&($d_chinh_error$$={...$obj$$},$d_chinh_error$$.ma_kh=$obj$$.ma_kh_bh,$d_chinh_error$$.tien_nt=$obj$$.tien_bh_chi,$d_chinh_error$$.tien=$d_chinh_error$$.tien_bh_chi*($obj$$.ty_gia||1),$bao_hiem$$.push($d_chinh_error$$));$d_chinh_error$$=[{...$obj$$}];$d_chinh_error$$.forEach($detail$$=>{$detail$$.ma_kh=$ma_kh_no$$;$detail$$.tien_nt=Math.max(0,
|
|
33
33
|
$obj$$.details.csum("tien_ct_nt")-$obj$$.details.csum("tien_ck_nt")-$obj$$.details.csum("gt_vt_du")-($obj$$.tien_ck_hd||0)+$obj$$.details.csum("tien_thue_nt")+($obj$$.tien_phi_vc_nt||0)-$kh_bo_xung$$.csum("tien_nt")-$bao_hiem$$.csum("tien_nt"));$detail$$.tien=$detail$$.tien_nt*$obj$$.ty_gia});(new PostBook($obj$$,[...$kh_bo_xung$$,...$bao_hiem$$,...$d_chinh_error$$].filter($d$$=>$d$$.tien_nt),Tdttno,function($detail$$,$callback$$){try{$detail$$.so_hd||($detail$$.so_hd=$obj$$.so_ct),$detail$$.ngay_hd||
|
|
34
34
|
($detail$$.ngay_hd=$obj$$.ngay_ct)}catch($e$$){console.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}else Tdttno.deleteMany({id_ct:$obj$$._id},function($error$$){$callback$$($error$$)})})},post_sokho:$callback$$=>{async.parallel({kt:$callback$$=>{$options$$.not_post_sokho?$callback$$():(new PostSokho($obj$$,[...$product_details$$],async($detail$$,$callback$$)=>{$detail$$.nxt=$detail$$.nxt||2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||
|
|
35
|
-
$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e
|
|
36
|
-
$callback$$)=>{$detail$$.nxt=$detail$$.nxt||2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)}):$callback$$()}},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})},post_vatra:function($callback$$){(async()=>{if($obj$$.ngay_hd||$obj$$.vatras&&$obj$$.vatras.length>0){let $details_vatra$$=$obj$$.vatras||[];if($obj$$.ngay_hd){var $d$$=$obj$$.details.map($detail$$=>
|
|
37
|
-
$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue);await $d$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,"vat",{where:"ma_thue",fields:["tk_thue_co"]});$d$$=await $d$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"tien_ct_nt tien_ct tien_nt tien tien_ck tien_ck_nt tien_thue tien_thue_nt".split(" "));
|
|
38
|
-
1){let $tien_thue_nt$$=$d$$.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_thue$$=$d$$.map($d$$=>$d$$.tien_thue).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$d$$[0].tien_thue_nt=$tien_thue_nt$$;$d$$[0].tien_thue=$tien_thue$$}$d$$.forEach($detail$$=>{try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=($detail$$.tien_ct_nt||0)-($detail$$.tien_ck_nt||0),$detail$$.t_tien=($detail$$.tien_ct||0)-($detail$$.tien_ck||0),$detail$$.t_thue_nt=$detail$$.tien_thue_nt,$detail$$.t_thue
|
|
39
|
-
$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){console.error($e$$,$obj$$)}});$details_vatra$$=[...$details_vatra$$,$d$$]}(new PostBook($obj$$,$details_vatra$$,Vatra,($detail$$,$callback$$)=>{$detail$$={...$detail$$};$detail$$.ten_vt=$detail$$.ten_vt||$obj$$.dien_giai;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}else $callback$$()})()},post_socai:function($callback$$){setImmediate(async()=>{let $details$$=[];$options$$.hoach_toan_ck_vt?
|
|
35
|
+
$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$ket_qua_post_sokho$$=$rs$$.rs_sokho;$callback$$(null,$rs$$)})},npp:$callback$$=>{$options$$.not_post_sokho?$callback$$():(new PostBook($obj$$,$product_details_npp$$,global.getModel("sokhonpp"),async($detail$$,$callback$$)=>{$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},tt:$callback$$=>{$options$$.post_sokhott?
|
|
36
|
+
(new PostBook($obj$$,$product_details$$,Sokhott,async($detail$$,$callback$$)=>{$detail$$.nxt=$detail$$.nxt||2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)}):$callback$$()}},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})},post_vatra:function($callback$$){(async()=>{if($obj$$.ngay_hd||$obj$$.vatras&&$obj$$.vatras.length>0){let $details_vatra$$=$obj$$.vatras||[];if($obj$$.ngay_hd){var $d$$=$obj$$.details.map($detail$$=>
|
|
37
|
+
({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue);await $d$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,"vat",{where:"ma_thue",fields:["tk_thue_co"]});$d$$=await $d$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"tien_ct_nt tien_ct tien_nt tien tien_ck tien_ck_nt tien_thue tien_thue_nt".split(" "));
|
|
38
|
+
if($d$$.length==1){let $tien_thue_nt$$=$d$$.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_thue$$=$d$$.map($d$$=>$d$$.tien_thue).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$d$$[0].tien_thue_nt=$tien_thue_nt$$;$d$$[0].tien_thue=$tien_thue$$}$d$$.forEach($detail$$=>{try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=($detail$$.tien_ct_nt||0)-($detail$$.tien_ck_nt||0),$detail$$.t_tien=($detail$$.tien_ct||0)-($detail$$.tien_ck||0),$detail$$.t_thue_nt=$detail$$.tien_thue_nt,$detail$$.t_thue=
|
|
39
|
+
$detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){console.error($e$$,$obj$$)}});$details_vatra$$=[...$details_vatra$$,$d$$]}(new PostBook($obj$$,$details_vatra$$,Vatra,($detail$$,$callback$$)=>{$detail$$={...$detail$$};$detail$$.ten_vt=$detail$$.ten_vt||$obj$$.dien_giai;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}else $callback$$()})()},post_socai:function($callback$$){setImmediate(async()=>{let $details$$=[];$options$$.hoach_toan_ck_vt?
|
|
40
40
|
($obj$$.details.forEach(function($d$jscomp$24_detail$$){$d$jscomp$24_detail$$={...$d$jscomp$24_detail$$};$d$jscomp$24_detail$$.tien_nt=$d$jscomp$24_detail$$.tien_ct_nt;$d$jscomp$24_detail$$.tien=$d$jscomp$24_detail$$.tien_ct?$d$jscomp$24_detail$$.tien_ct:utils.round($d$jscomp$24_detail$$.tien_ct_nt*$obj$$.ty_gia,0);$d$jscomp$24_detail$$.tk_co=$d$jscomp$24_detail$$.tk_dt||$kho$$.tk_dt||$options$$.tk_dt;$d$jscomp$24_detail$$.ma_kh||($d$jscomp$24_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$24_detail$$.tk_no=
|
|
41
41
|
$obj$$.tk_no;$details$$.push($d$jscomp$24_detail$$)}),($obj$$.details||[]).filter($d$$=>$d$$.tien_ck_nt).forEach(function($d$jscomp$26_detail$$){$d$jscomp$26_detail$$={...$d$jscomp$26_detail$$};$d$jscomp$26_detail$$.tk_no=$d$jscomp$26_detail$$.tk_ck||$obj$$.tk_ck||$kho$$.tk_ck||$options$$.tk_ck;$d$jscomp$26_detail$$.ma_kh||($d$jscomp$26_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$26_detail$$.tk_co=$obj$$.tk_no;$d$jscomp$26_detail$$.tien_nt=$d$jscomp$26_detail$$.tien_ck_nt;$d$jscomp$26_detail$$.tien=$d$jscomp$26_detail$$.tien_ck;
|
|
42
42
|
$d$jscomp$26_detail$$.ma_kh_no=$d$jscomp$26_detail$$.ma_kh||$obj$$.ma_kh;$d$jscomp$26_detail$$.ma_kh_co=$obj$$.ma_kh_no||$d$jscomp$26_detail$$.ma_kh||$obj$$.ma_kh;$d$jscomp$26_detail$$.check_balance=!1;$details$$.push($d$jscomp$26_detail$$)})):$obj$$.details.forEach(function($d$jscomp$27_detail$$){$d$jscomp$27_detail$$={...$d$jscomp$27_detail$$};$d$jscomp$27_detail$$.tien_nt=$d$jscomp$27_detail$$.tien_ct_nt-($d$jscomp$27_detail$$.tien_ck_nt||0);$d$jscomp$27_detail$$.tien=utils.round($d$jscomp$27_detail$$.tien_nt*
|
|
@@ -58,10 +58,10 @@ $obj$$.tk_no_hoa_hong_ql||$kho$$.tk_no_hoa_hong_ql||$options$$.tk_no_hoa_hong_ql
|
|
|
58
58
|
{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_ql;$tt$$.tk_co=$r$$.tk_co_hoa_hong_ql;$tt$$.tien_nt=$r$$.tien_hoa_hong_ql;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_kh_hoa_hong_ql;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.dien_giai="Hoa h\u1ed3ng cho \u0111i\u1ec1u h\u00e0nh kinh doanh";$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$o_tt$jscomp$1_tt$$={...$obj$$};$o_tt$jscomp$1_tt$$.tk_no=$obj$$.tk_no;$o_tt$jscomp$1_tt$$.tk_co=
|
|
59
59
|
$obj$$.tk_thue_co;$o_tt$jscomp$1_tt$$.tien_nt=$obj$$.details.csum("tien_thue_nt");$o_tt$jscomp$1_tt$$.tien=$o_tt$jscomp$1_tt$$.tien_nt*$o_tt$jscomp$1_tt$$.ty_gia;$o_tt$jscomp$1_tt$$.dien_giai_thue&&($o_tt$jscomp$1_tt$$.dien_giai=$o_tt$jscomp$1_tt$$.dien_giai_thue);$details$$.push($o_tt$jscomp$1_tt$$);if($obj$$.vatras&&$obj$$.vatras.length>0)for(var $o$jscomp$1_o$$ of $obj$$.vatras)$o$jscomp$1_o$$.tk_no=$obj$$.tk_no,$o$jscomp$1_o$$.tk_co=$o$jscomp$1_o$$.tk_thue_co,$o$jscomp$1_o$$.tien_nt=$o$jscomp$1_o$$.t_thue_nt,
|
|
60
60
|
$o$jscomp$1_o$$.tien=$o$jscomp$1_o$$.t_thue,$o$jscomp$1_o$$.dien_giai_thue&&($o$jscomp$1_o$$.dien_giai=$o$jscomp$1_o$$.dien_giai_thue),$details$$.push($o$jscomp$1_o$$);$obj$$.tk_phi_vc=$obj$$.tk_phi_vc||$options$$.tk_phi_vc;$obj$$.tk_phi_vc&&($o$jscomp$1_o$$={...$obj$$},$o$jscomp$1_o$$.tk_no=$obj$$.tk_no,$o$jscomp$1_o$$.tk_co=$obj$$.tk_phi_vc,$o$jscomp$1_o$$.tien_nt=$obj$$.tien_phi_vc_nt,$o$jscomp$1_o$$.tien=$o$jscomp$1_o$$.tien_nt*$o$jscomp$1_o$$.ty_gia,$o$jscomp$1_o$$.dien_giai="Ph\u00ed giao h\u00e0ng",
|
|
61
|
-
$details$$.push($o$jscomp$1_o$$));const $details_giavon$$=[];[
|
|
62
|
-
()=>{$details_giavon$$.forEach($s$$=>{$s$$.tk_co||($s$$.tk_co=$s$$.tk_vt||$options$$.tk_vt);$s$$.tk_no||($s$$.tk_no=$s$$.tk_gv||$options$$.tk_gv);$s$$.ma_nt="VND";$s$$.ty_gia=1});$callback$$()})}},()=>{$details_giavon$$.forEach($d$$=>{$d$$.ma_kh_no=$d$$.ma_kh||$obj$$.ma_kh;$d$$.ma_kh_co=$d$$.ma_kh||$obj$$.ma_kh});$details$$=$details$$.concat($details_giavon$$);(new PostSocai($obj$$,$details$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e
|
|
63
|
-
{if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:8});$wallet_nhan_vien$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString()
|
|
64
|
-
8);let $amount$$=$obj$$.tien_hoa_hong,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
|
|
61
|
+
$details$$.push($o$jscomp$1_o$$));const $details_giavon$$=[];($ket_qua_post_sokho$$||[]).filter($r$$=>$r$$.nxt!=1).forEach(function($detail$$){$detail$$.toObject&&($detail$$=$detail$$.toObject());$detail$$={...$detail$$};$detail$$.tk_no=$detail$$.tk_gv;$detail$$.ma_kh||($detail$$.ma_kh=$obj$$.ma_kh);$detail$$.tk_co=$detail$$.tk_vt;$detail$$.tien_nt=$detail$$.tien_xuat_nt;$detail$$.tien=$detail$$.tien_xuat;$details_giavon$$.push($detail$$)});async.series({xdtk:$callback$$=>{$details_giavon$$.joinModel2($obj$$.id_app,
|
|
62
|
+
dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv"]},()=>{$details_giavon$$.forEach($s$$=>{$s$$.tk_co||($s$$.tk_co=$s$$.tk_vt||$options$$.tk_vt);$s$$.tk_no||($s$$.tk_no=$s$$.tk_gv||$options$$.tk_gv);$s$$.ma_nt="VND";$s$$.ty_gia=1});$callback$$()})}},()=>{$details_giavon$$.forEach($d$$=>{$d$$.ma_kh_no=$d$$.ma_kh||$obj$$.ma_kh;$d$$.ma_kh_co=$d$$.ma_kh||$obj$$.ma_kh});$details$$=$details$$.concat($details_giavon$$);(new PostSocai($obj$$,$details$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,
|
|
63
|
+
$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:8});$wallet_nhan_vien$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
|
|
64
|
+
$obj$$.user_nv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
|
|
65
65
|
$e$$)}$callback$$()})},thanhtoanhoahonggt:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_gt||!$obj$$.tien_hoa_hong_gt||!$obj$$.user_gt||!$obj$$.chuyen_ngay_gt)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_gt,wallet_type:8});$wallet_gt$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
|
|
66
66
|
$obj$$.user_gt,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong_gt,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_gt=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
|
|
67
67
|
$e$$)}$callback$$()})},thanhtoanhoahongctv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_ctv||!$obj$$.thu_nhap_ctv||!$obj$$.user_ctv||!$obj$$.chuyen_ngay_ctv)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){if($obj$$.user_ctv&&$obj$$.thu_nhap_ctv){let $wallet_ctv$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ctv,wallet_type:8});$wallet_ctv$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
|