flexbiz-server
Version:
Flexible Server
70 lines (69 loc) • 26.7 kB
JavaScript
'use strict';const _=require("underscore"),StaticPool=require("./WorkerStaticPool"),path=require("path"),writtenNumber=require("written-number"),async=require("async"),{VM}=require("vm2"),numeral=require("numeral"),moment=require("moment"),validator=require("validator"),crypto=require("crypto");function evalute($code$$,$sandbox$$={},$timeout$$=2E3){$sandbox$$.Promise=function(){};return(new VM({timeout:$timeout$$,sandbox:$sandbox$$})).run(`(()=>{${$code$$}})()`)}
function JSONParser($str_func$$){0>$str_func$$.indexOf("return ")&&($str_func$$="return "+$str_func$$);return evalute($str_func$$)}
function numberToWord($fractionText_number$$,$options$$){if(void 0===$fractionText_number$$||null===$fractionText_number$$)return"";if($options$$&&$options$$.lang&&"vn"!==$options$$.lang){var $kq_sign$$=writtenNumber($fractionText_number$$,{lang:$options$$.lang});return 0<$kq_sign$$.length?$kq_sign$$.substring(0,1).toUpperCase()+$kq_sign$$.substring(1):""}$kq_sign$$="";0>$fractionText_number$$&&($kq_sign$$="\u00e2m ",$fractionText_number$$=-$fractionText_number$$);$options$$=_.extend({thousand:"ng\u00e0n",
decimal:"ph\u1ea9y"},$options$$);$fractionText_number$$=Number($fractionText_number$$.toFixed(2));var $integerPart_integerText$$=Math.floor($fractionText_number$$),$fractionPart$$=$fractionText_number$$%1;$fractionText_number$$="";$fractionPart$$&&($fractionText_number$$=convertFractionPart($fractionPart$$),$fractionText_number$$=" "+$options$$.decimal+" "+$fractionText_number$$);var $digitGroups$$=breakDownNumber($integerPart_integerText$$).reverse();$integerPart_integerText$$=_.chain($digitGroups$$).map(function($convertedGroup_group$$,
$index$$){$convertedGroup_group$$=convertGroup($convertedGroup_group$$,$index$$===$digitGroups$$.length-1?!1:!0);var $unit$$=unitAt($index$$,$options$$.thousand);$convertedGroup_group$$||0===$index$$%3||($unit$$="");$convertedGroup_group$$&&$unit$$&&($unit$$=" "+$unit$$);return $convertedGroup_group$$+$unit$$}).compact().reverse().join(" ");$kq_sign$$=$kq_sign$$+$integerPart_integerText$$+$fractionText_number$$;return 0<$kq_sign$$.length?$kq_sign$$.substring(0,1).toUpperCase()+$kq_sign$$.substring(1):
""}function unitAt($index$$,$thousand$$){if(0===$index$$)return"";switch($index$$%3){case 0:return"t\u1ec9";case 1:return $thousand$$;case 2:return"tri\u1ec7u"}}
function convertGroup($group$$,$preserveZeros$$){var $DIGITS$$="kh\u00f4ng m\u1ed9t hai ba b\u1ed1n n\u0103m s\u00e1u b\u1ea3y t\u00e1m ch\u00edn".split(" "),$DIGITS_WITH_TENS$$=" m\u1ed1t hai ba b\u1ed1n l\u0103m s\u00e1u b\u1ea3y t\u00e1m ch\u00edn".split(" "),$TENS$$="linh;m\u01b0\u1eddi;hai m\u01b0\u01a1i;ba m\u01b0\u01a1i;b\u1ed1n m\u01b0\u01a1i;n\u0103m m\u01b0\u01a1i;s\u00e1u m\u01b0\u01a1i;b\u1ea3y m\u01b0\u01a1i;t\u00e1m m\u01b0\u01a1i;ch\u00edn m\u01b0\u01a1i".split(";"),$HUNDREDS$$=_.map($DIGITS$$,
function($digit$$){return $digit$$+" tr\u0103m"}),$hundred$$="",$ten$$="",$digit$$="";if($preserveZeros$$&&!$group$$.hundred&&!$group$$.ten&&!$group$$.digit)return"";if($preserveZeros$$||$group$$.hundred)$hundred$$=$HUNDREDS$$[$group$$.hundred];if($preserveZeros$$||$group$$.ten||$group$$.hundred){if($group$$.ten||$group$$.digit)$ten$$=$TENS$$[$group$$.ten];$digit$$=1!==$group$$.ten&&$group$$.ten||!$group$$.digit?$DIGITS_WITH_TENS$$[$group$$.digit]:$DIGITS$$[$group$$.digit]}else $digit$$=$DIGITS$$[$group$$.digit];
$hundred$$&&$ten$$&&($hundred$$+=" ");$ten$$&&$digit$$&&($ten$$+=" ");return[$hundred$$,$ten$$,$digit$$].join("")}
function breakDownNumber($digits_number$$){$digits_number$$=$digits_number$$.toString().split("");$digits_number$$=_.map(_.range(0,(3-$digits_number$$.length%3)%3),function(){return 0}).concat($digits_number$$);return _.chain($digits_number$$).map(Number).groupBy(function($element$$,$index$$){return Math.floor($index$$/3)}).toArray().map(function($group$$){return _.object(["hundred","ten","digit"],$group$$)}).value()}
function convertFractionPart($fractionPart$$){$fractionPart$$=convertGroup(breakDownNumber(100*$fractionPart$$)[0]);var $mapping$$={"m\u01b0\u1eddi":"m\u1ed9t","hai m\u01b0\u01a1i":"hai","ba m\u01b0\u01a1i":"ba","b\u1ed1n m\u01b0\u01a1i":"b\u1ed1n","n\u0103m m\u01b0\u01a1i":"n\u0103m","s\u00e1u m\u01b0\u01a1i":"s\u00e1u","b\u1ea3y m\u01b0\u01a1i":"b\u1ea3y","t\u00e1m m\u01b0\u01a1i":"t\u00e1m","ch\u00edn m\u01b0\u01a1i":"ch\u00edn","m\u1ed9t":"kh\u00f4ng m\u1ed9t",hai:"kh\u00f4ng hai",ba:"kh\u00f4ng ba",
"b\u1ed1n":"kh\u00f4ng b\u1ed1n","n\u0103m":"kh\u00f4ng n\u0103m","s\u00e1u":"kh\u00f4ng s\u00e1u","b\u1ea3y":"kh\u00f4ng b\u1ea3y","t\u00e1m":"kh\u00f4ng t\u00e1m","ch\u00edn":"kh\u00f4ng ch\u00edn"};$fractionPart$$ in $mapping$$&&($fractionPart$$=$mapping$$[$fractionPart$$]);return $fractionPart$$}
function round($number$$,$factor_precision$$){$factor_precision$$||($factor_precision$$=0);isNaN($number$$)&&($number$$=0);$number$$=Number($number$$);$factor_precision$$=Math.pow(10,$factor_precision$$);return Math.round($number$$*$factor_precision$$)/$factor_precision$$}
function getInfoFromQuery($obj$$,$_query$$,$callback$$){setImmediate(()=>{let $query$$;try{$_query$$=$_query$$.trim();if(!$_query$$)return $callback$$();try{$_query$$.startsWith("{")||($_query$$="{"+$_query$$+"}");$_query$$.includes("return ")||($_query$$="return "+$_query$$);if(0<=$_query$$.indexOf("async "))return $callback$$("async function is not allow");$query$$=evalute($_query$$,{obj:$obj$$})}catch($e$$){console.log("error when parse json",$_query$$)}if(!$query$$)return $callback$$("Query is invalid: "+
$_query$$);if(!$query$$.collection||!$query$$.field)return $callback$$();"dmkh"==$query$$.collection&&($query$$.collection="customer");"dmtk"==$query$$.collection&&($query$$.collection="account");let $condition$$=$query$$.condition;if($condition$$){$condition$$=JSON.stringify($condition$$);for($fields_m$$ in $obj$$)$condition$$=$condition$$.replace(new RegExp("m."+$fields_m$$,"g"),$obj$$[$fields_m$$]);$condition$$=JSON.parse($condition$$)}else $condition$$={};let $col$$=global.getModel(""+$query$$.collection);
var $fields_m$$={};$fields_m$$[$query$$.field]=1;$fields_m$$.mnemonic=-1;$fields_m$$.private_key=-1;$obj$$.id_app&&($condition$$.id_app=$obj$$.id_app);$col$$.findOne($condition$$,$fields_m$$).lean().exec(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$rs$$?$callback$$(null,$rs$$[$query$$.field]):$callback$$()})}catch($e$$){console.error($e$$),$callback$$("error execute query: "+$_query$$)}})}
function strip_html_tags($str$$){if(!$str$$)return"";$str$$=$str$$.toString();return $str$$.replace(/<[^>]*>/g,"")}function unescapeHtml($html_text$$){return unescape($html_text$$)}const ngcompile=require("ng-node-compile");
function compileHtml($template$$,$data$$){try{var $ngEnviorment_str_func$$=$template$$;0!==$ngEnviorment_str_func$$.indexOf("return ")&&($ngEnviorment_str_func$$="return `"+$ngEnviorment_str_func$$+"`");$template$$=evalute($ngEnviorment_str_func$$,{...$data$$,moment,numeral,data:$data$$,master:$data$$,obj:$data$$})}catch($e$$){console.error("error compile template js",$template$$,$e$$.message||$e$$,$data$$)}if(0<=$template$$.indexOf("{{")&&0<=$template$$.indexOf("}}")){$ngEnviorment_str_func$$=new ngcompile([]);
try{$template$$=$ngEnviorment_str_func$$.$compile("<span>"+$template$$+"</span>")($data$$)}catch($e$$){console.error("error compile template angularjs",$template$$,$e$$.message||$e$$,$data$$)}}return $template$$}function isSupperAdmin($email$$){return global.configs?configs.supperAdmin===$email$$:!1}
function calcGrid($report$$,$number_columns$$,$callback$$){setImmediate(()=>{var $_number_columns_onImportProcess$$=path.dirname(__dirname)+"/workers/calcGrid.js";global.calcGridPool||(global.calcGridPool=new StaticPool($_number_columns_onImportProcess$$));$_number_columns_onImportProcess$$=_.isObject($number_columns$$)?Object.keys($number_columns$$).join(","):$number_columns$$;global.calcGridPool.exec({report:$report$$,number_columns:$_number_columns_onImportProcess$$},$response$$=>{let $result$$=
$response$$.result||[];_.isObject($number_columns$$)?async.map(Object.keys($number_columns$$),($column$$,$cb$$)=>{setImmediate(()=>{let $cbColumn$$=$number_columns$$[$column$$];$cbColumn$$?async.map($result$$.filter($r$$=>$r$$.cong_thuc),($r$$,$cb2$$)=>{$cbColumn$$(null,$r$$);$cb2$$()},()=>{$cb$$()}):$cb$$()})},()=>{$callback$$($result$$)}):$callback$$($result$$)})})}
const advMapSeries=($arr$$,$action$$,$callback$jscomp$0$$,$options$$={number_group:1,wait_for_next:0})=>{const $number_items_one_group$$=Math.max(1,round($arr$$.length/($options$$.number_group||1)));$arr$$=_.chunk($arr$$,$number_items_one_group$$);async.mapSeries($arr$$,($group$$,$callback$$)=>{async.mapSeries($group$$,($row$$,$cb$$)=>{$action$$($row$$,$cb$$)},($e$$,$rs$$)=>{$options$$.wait_for_next?setTimeout(()=>{console.log("run next group...");$callback$$($e$$,$rs$$)},$options$$.wait_for_next):
(console.log("run next group..."),$callback$$($e$$,$rs$$))})},($e$$,$rs$$)=>{if($e$$)return $callback$jscomp$0$$($e$$);$e$$=$rs$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);$callback$jscomp$0$$(null,$e$$)})},getParameterData=($id_app$$,$collection$$,$field$$,$condition$$)=>{if(0<=global.secu_models.indexOf($collection$$.toLowerCase()))throw`Collection ${$collection$$} is not allow`;"dmkh"===$collection$$&&($collection$$="customer");"dmtk"===$collection$$&&($collection$$="account");let $col$$=mongoose.models[$collection$$];
if($col$$){if($col$$.schema.paths.id_app){if(!$id_app$$)throw`Collection ${$collection$$} required id_app`;$condition$$.id_app=$id_app$$}let $fields$$;$field$$&&($fields$$={[$field$$]:1});if("user"===$collection$$||"participant"===$collection$$)$fields$$={name:1};"app"===$collection$$&&($fields$$||($fields$$={}),$fields$$={...$fields$$,viettel_user:0,viettel_password:0,viettel_url_service:0,sip_uri:0,sip_password:0,sip_websocket:0,voiip_access_token:0,voiip_webhook:0,wallet_address:0,wallet_token:0,
owner:0,default_password:0,email_host:0,email_port:0,email_secure:0,email_authMethod:0,email_user:0,email_pass:0,email_name:0,exfields:0,ssl_key:0,ssl_cert:0,ssl_ca:0});return $col$$.findOne($condition$$,$fields$$).lean()}throw`Error get param data: Collection ${$collection$$} is not exists`;},prepareParameters=async function($parameters$$,$app$$,$obj$$){return new Promise(($resole$$,$reject$$)=>{async.mapSeries($parameters$$,function($p$$,$callback$$){setImmediate(()=>{(async()=>{if("W"===$p$$.type||
"EN"===$p$$.type)try{$app$$[$p$$.name]="EN"===$p$$.type?numberToWord($obj$$[$p$$.value],{lang:"en"}):numberToWord($obj$$[$p$$.value])}catch($e$$){console.error($e$$),$app$$[$p$$.name]=$e$$.message}else if("Q"===$p$$.type)try{var $query$jscomp$2_sandbox$$=await evalute("return {"+$p$$.value+"}",{});if($query$jscomp$2_sandbox$$.collection&&$query$jscomp$2_sandbox$$.field){"dmkh"==$query$jscomp$2_sandbox$$.collection&&($query$jscomp$2_sandbox$$.collection="customer");"dmtk"==$query$jscomp$2_sandbox$$.collection&&
($query$jscomp$2_sandbox$$.collection="account");var $condition$$=$query$jscomp$2_sandbox$$.condition;if($condition$$){$condition$$=JSON.stringify($condition$$);for(let $m$$ in $obj$$)$condition$$=$condition$$.replace(new RegExp("m."+$m$$,"g"),$obj$$[$m$$]);$condition$$=JSON.parse($condition$$)}else $condition$$={};$app$$[$p$$.name]=await getParameterData($app$$.id_app,$query$jscomp$2_sandbox$$.collection,$query$jscomp$2_sandbox$$.field,$condition$$)}}catch($e$$){$app$$[$p$$.name]=$e$$}else if("E"===
$p$$.type&&$p$$.value){$condition$$=$p$$.value;0>$condition$$.indexOf("return ")&&($condition$$=`return ${$condition$$}`);if(0<=$condition$$.indexOf("async "))return $app$$[$p$$.name]="async function is not allow";$condition$$=`return (async ()=>{
${$condition$$}
})`;$query$jscomp$2_sandbox$$={m:$obj$$,master:$obj$$,data:$obj$$,Moment:moment,Numeral:numeral,numberToWord,getData:getParameterData};try{$app$$[$p$$.name]=await evalute($condition$$,$query$jscomp$2_sandbox$$)()}catch($e$$){console.error($e$$,$condition$$),$app$$[$p$$.name]=$e$$.message}}else $app$$[$p$$.name]=$p$$.value})().then(()=>{$callback$$()}).catch(()=>{$callback$$()})})},function($e$$){if($e$$)return $reject$$($e$$);$resole$$()})})},groupBy=($arr$$,$fieldkey$$,$fieldsums$$,$options$$)=>
[...$arr$$].asyncGroupBy($fieldkey$$,$fieldsums$$,$options$$),joinModel2=($arr$$,$id_app$$,$modelName$$,$where$$,$fields$$)=>{$where$$.fields&&$where$$.where&&($where$$=$where$$.where,$fields$$=$where$$.fields);return[...$arr$$].asyncJoinModel2($id_app$$,$modelName$$,{where:$where$$,fields:$fields$$})},count=async($model_name$$,$condition$$)=>{if(0<=global.secu_models.indexOf($model_name$$.toLowerCase()))throw"Not allow";if(!$condition$$)throw"condition missed";if(!$condition$$.id_app)throw"condition missed id_app param";
return await global.getModel($model_name$$).countDocuments($condition$$)},query=async($model_name$$,$condition$$,$options$jscomp$5_rs$$={})=>{if(0<=global.secu_models.indexOf($model_name$$.toLowerCase()))throw"Not allow";if(!$condition$$)throw"condition missed";if($options$jscomp$5_rs$$.action&&"find"!=$options$jscomp$5_rs$$.action){if(global.getModel($model_name$$)[$options$jscomp$5_rs$$.action]&&0<=["getCoinBalance","getInvestBalance","getOwners"].indexOf($options$jscomp$5_rs$$.action))return global.getModel($model_name$$)[$options$jscomp$5_rs$$.action]($condition$$,
$options$jscomp$5_rs$$);throw`${$options$jscomp$5_rs$$.action} is not valid`;}if(!$condition$$.id_app)throw"condition missed id_app param";let $fields$$=$options$jscomp$5_rs$$.fields;$model_name$$=global.getModel($model_name$$).find($condition$$,$fields$$);$options$jscomp$5_rs$$.sort&&($model_name$$=$model_name$$.sort($options$jscomp$5_rs$$.sort));$options$jscomp$5_rs$$.limit&&($model_name$$=$model_name$$.limit($options$jscomp$5_rs$$.limit));$options$jscomp$5_rs$$=await $model_name$$.lean();$options$jscomp$5_rs$$.forEach($r$$=>
{delete $r$$.mnemonic;delete $r$$.private_key;delete $r$$.password;delete $r$$.token;$r$$.local&&(delete $r$$.local.password,delete $r$$.local.repassword,delete $r$$.local.pin)});return $options$jscomp$5_rs$$},getLib=$lib_name$$=>global.getLib($lib_name$$),getCodeChildren=async($model$$,$id_app$$,$code$jscomp$2_rs$$,$field_code$$,$field_mother$$,$chil_condition$$={})=>{let $nh_khs$$;$nh_khs$$=_.isArray($code$jscomp$2_rs$$)?[...$code$jscomp$2_rs$$]:[$code$jscomp$2_rs$$];$code$jscomp$2_rs$$=[...$nh_khs$$];
$chil_condition$$=(await $model$$.find({id_app:$id_app$$,[$field_mother$$]:{$in:$nh_khs$$},...$chil_condition$$},{_id:1,[$field_code$$]:1,[$field_mother$$]:1}).lean()).filter($n$$=>$n$$[$field_code$$]!=$n$$[$field_mother$$]).map($d$$=>$d$$[$field_code$$]);0<$chil_condition$$.length&&($chil_condition$$=await Promise.all($chil_condition$$.map($nh$$=>getCodeChildren($model$$,$id_app$$,$nh$$,$field_code$$,$field_mother$$))),$chil_condition$$=$chil_condition$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]),
$code$jscomp$2_rs$$=[...$chil_condition$$,...$code$jscomp$2_rs$$]);return $code$jscomp$2_rs$$},aggregate=async($model_name$jscomp$2_rs$$,$id_app$$,$stages$$=[])=>{if(0<=global.secu_models.indexOf($model_name$jscomp$2_rs$$))throw"Not allow";$stages$$.forEach($stage$$=>{for(let $key$$ in $stage$$)$stage$$[$key$$].pipeline&&($stage$$[$key$$].pipeline=[{$match:{id_app:$id_app$$}},...$stage$$[$key$$].pipeline])});$stages$$=[{$match:{id_app:$id_app$$}},...$stages$$];$model_name$jscomp$2_rs$$=await global.getModel($model_name$jscomp$2_rs$$).aggregate($stages$$).lean();
$model_name$jscomp$2_rs$$.forEach($r$$=>{delete $r$$.mnemonic;delete $r$$.private_key;delete $r$$.password;delete $r$$.token;$r$$.local&&(delete $r$$.local.password,delete $r$$.local.repassword,delete $r$$.local.pin)});return $model_name$jscomp$2_rs$$},axios=require("axios"),querystring=require("querystring"),getInvoice=async($app$jscomp$1_data$$,$transactionUuid$$)=>{if(!$app$jscomp$1_data$$)throw"Thi\u1ebfu th\u00f4ng tin c\u00f4ng ty";if(!$app$jscomp$1_data$$.viettel_url_service||!$app$jscomp$1_data$$.viettel_user||
!$app$jscomp$1_data$$.viettel_password)throw"Ch\u01b0a khai b\u00e1o th\u00f4ng tin k\u1ebft n\u1ed1i viettel invoice";if(!$app$jscomp$1_data$$.ma_so_thue)throw"Ch\u01b0a khai b\u00e1o m\u00e3 s\u1ed1 thu\u1ebf c\u00f4ng ty";var $auth_url$$={username:$app$jscomp$1_data$$.viettel_user.trim(),password:$app$jscomp$1_data$$.viettel_password.trim()};try{var $headers_viettel_token$$=(await axios({method:"post",url:`${$app$jscomp$1_data$$.viettel_url_service.trim()}/auth/login`,data:$auth_url$$})).data.access_token}catch($e$$){throw console.error("error when get token viettel"),
"Th\u00f4ng tin truy c\u1eadp Viettel invoice kh\u00f4ng \u0111\u00fang";}$auth_url$$=`${$app$jscomp$1_data$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/searchInvoiceByTransactionUuid`;$headers_viettel_token$$={Cookie:`"access_token":"${$headers_viettel_token$$}"; access_token=${$headers_viettel_token$$}; session_token=${$headers_viettel_token$$}`,"Content-Type":"application/x-www-form-urlencoded"};$app$jscomp$1_data$$={supplierTaxCode:$app$jscomp$1_data$$.ma_so_thue,
transactionUuid:$transactionUuid$$};try{let $rs$$=await axios.post($auth_url$$,querystring.stringify($app$jscomp$1_data$$),{headers:$headers_viettel_token$$});console.log("invoice info",$rs$$.data);let $invoice$$=$rs$$.data;$invoice$$.result&&1==$invoice$$.result.length&&($invoice$$.result=$invoice$$.result[0]);return $invoice$$}catch($e$$){if("NOT_FOUND_DATA"===(($e$$.response||{}).data||{}).message)return null;console.error("error get invoice",($e$$.response||{}).data,", data:",$app$jscomp$1_data$$);
throw(($e$$.response||{}).data||{}).data||"Kh\u00f4ng th\u1ec3 l\u1ea5y th\u00f4ng tin ho\u00e1 \u0111\u01a1n n\u00e0y c\u1ee7a transactionUuid "+$transactionUuid$$;}},xml2js=require("xml2js"),xml2json=$string$$=>new Promise(($res$$,$rej$$)=>{xml2js.parseString($string$$,($e$$,$rs$$)=>{if($e$$)return $rej$$($e$$);$res$$($rs$$)})}),base64toJSON=$b$$=>{$b$$=Buffer.from($b$$,"base64");return xml2json($b$$.toString("utf8"))},getInvoices=async($app$jscomp$2_str$$,$condition$jscomp$6_data$$={})=>{if(!$app$jscomp$2_str$$)throw"Thi\u1ebfu th\u00f4ng tin c\u00f4ng ty";
if(!$app$jscomp$2_str$$.vnpt_url_service||!$app$jscomp$2_str$$.vnpt_user||!$app$jscomp$2_str$$.vnpt_password)throw"Ch\u01b0a khai b\u00e1o th\u00f4ng tin k\u1ebft n\u1ed1i VNPT invoice";if(!$app$jscomp$2_str$$.ma_so_thue)throw"Ch\u01b0a khai b\u00e1o m\u00e3 s\u1ed1 thu\u1ebf c\u00f4ng ty";if(!$app$jscomp$2_str$$.ky_hieu_hoa_don)throw"Ch\u01b0a khai b\u00e1o m\u1eabu ho\u00e1 \u0111\u01a1n";if(!$app$jscomp$2_str$$.so_serial)throw"Ch\u01b0a khai b\u00e1o k\u00ed hi\u1ec7u ho\u00e1 \u0111\u01a1n";if(!$condition$jscomp$6_data$$.tu_ngay)throw"\u0110i\u1ec1u ki\u1ec7n thi\u1ebfu t\u1eeb ng\u00e0y (tu_ngay)";
if(!$condition$jscomp$6_data$$.den_ngay)throw"\u0110i\u1ec1u ki\u1ec7n thi\u1ebfu t\u1eeb ng\u00e0y (den_ngay)";const $ERRORS$$={"ERR:1":"T\u00e0i kho\u1ea3n \u0111\u0103ng nh\u1eadp sai ho\u1eb7c kh\u00f4ng c\u00f3 quy\u1ec1n ServiceRole","ERR:2":"Kh\u00f4ng t\u00ecm th\u1ea5y h\u00f3a \u0111\u01a1n","ERR:3":"Sai \u0111\u1ecbnh d\u1ea1ng ng\u00e0y th\u00e1ng","ERR:4":"Kh\u00f4ng l\u1ea5y \u0111\u01b0\u1ee3c b\u1ea3ng h\u00f3a \u0111\u01a1n (sai m\u1eabu s\u1ed1)","ERR:6":"V\u01b0\u1ee3t qu\u00e1 gi\u1edbi h\u1ea1n s\u1ed1 l\u01b0\u1ee3ng h\u00f3a \u0111\u01a1n \u0111\u01b0\u1ee3c ph\u00e9p l\u1ea5y (500 h\u00f3a \u0111\u01a1n)",
"ERR:5":"C\u00f3 l\u1ed7i x\u1ea3y ra","ERR:7":"V\u01b0\u1ee3t qu\u00e1 gi\u1edbi h\u1ea1n 7 ng\u00e0y"};$condition$jscomp$6_data$$=`<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetInvViewByDate xmlns="http://tempuri.org/">
<userName>${$app$jscomp$2_str$$.vnpt_user}</userName>
<userPass>${$app$jscomp$2_str$$.vnpt_password}</userPass>
<pattern>${$app$jscomp$2_str$$.ky_hieu_hoa_don}</pattern>
<serial>${$app$jscomp$2_str$$.so_serial}</serial>
<fromDate>${moment($condition$jscomp$6_data$$.tu_ngay).format("DD/MM/YYYY")}</fromDate>
<toDate>${moment($condition$jscomp$6_data$$.den_ngay).format("DD/MM/YYYY")}</toDate>
</GetInvViewByDate>
</soap:Body>
</soap:Envelope>`;$app$jscomp$2_str$$=(await axios.request({method:"post",maxBodyLength:Infinity,url:$app$jscomp$2_str$$.vnpt_url_service,headers:{SOAPAction:"http://tempuri.org/GetInvViewByDate","Content-Type":"text/xml; charset=utf-8"},data:$condition$jscomp$6_data$$})).data;let $rs$jscomp$0$$=await xml2json($app$jscomp$2_str$$);return new Promise(($resolve$$,$reject$$)=>{try{let $GetInvViewByDateResult$$=($rs$jscomp$0$$["soap:Envelope"]||{})["soap:Body"][0].GetInvViewByDateResponse[0].GetInvViewByDateResult;
if(0<=$GetInvViewByDateResult$$.length&&0<=$GetInvViewByDateResult$$[0].indexOf("ERR:"))return $reject$$($ERRORS$$[$GetInvViewByDateResult$$[0]]);async.map($GetInvViewByDateResult$$,($d$jscomp$0$$,$cb$$)=>{setImmediate(async()=>{try{var $bufferObj$jscomp$1_rs$$=Buffer.from($d$jscomp$0$$,"base64"),$hinh_thuc_tt_invs$$=(await xml2json($bufferObj$jscomp$1_rs$$.toString("utf8"))).DSHDon.HDon;$bufferObj$jscomp$1_rs$$=[];for(let $inv$$ of $hinh_thuc_tt_invs$$){let $dl$$=$inv$$.DLieu[0];$dl$$=(await base64toJSON($dl$$)).HDon.DLHDon[0];
$dl$$.Fkey=$inv$$.Fkey[0];$dl$$.TTChung=$dl$$.TTChung[0];$dl$$.NDHDon=$dl$$.NDHDon[0];$dl$$.NDHDon.NBan=$dl$$.NDHDon.NBan[0];$dl$$.NDHDon.NMua=$dl$$.NDHDon.NMua[0];$dl$$.NDHDon.TToan=$dl$$.NDHDon.TToan[0];delete $dl$$.$;$hinh_thuc_tt_invs$$="";$dl$$.TTChung.TTKhac&&0<$dl$$.TTChung.TTKhac.length&&$dl$$.TTChung.TTKhac[0].TTin&&0<$dl$$.TTChung.TTKhac[0].TTin.length&&"HTTToan"==$dl$$.TTChung.TTKhac[0].TTin[0].TTruong[0]&&($hinh_thuc_tt_invs$$=$dl$$.TTChung.TTKhac[0].TTin[0].DLieu[0]);let $fdata$$={id_invoice:$inv$$.Fkey[0],
so_ct:$dl$$.TTChung.SHDon[0],ngay_ct:new Date($dl$$.TTChung.NLap[0]),so_hd:$dl$$.TTChung.SHDon[0],ngay_hd:new Date($dl$$.TTChung.NLap[0]),ky_hieu_hoa_don:$dl$$.TTChung.KHMSHDon[0],so_serial:$dl$$.TTChung.KHHDon[0],hinh_thuc_tt:$hinh_thuc_tt_invs$$,ma_nt:"VND",ty_gia:1,ten_kh:$dl$$.NDHDon.NMua.Ten[0],ma_so_thue:$dl$$.NDHDon.NMua.MST?$dl$$.NDHDon.NMua.MST[0]:void 0,dia_chi:$dl$$.NDHDon.NMua.DChi?$dl$$.NDHDon.NMua.DChi[0]:void 0,dien_thoai:$dl$$.NDHDon.NMua.SDThoai?$dl$$.NDHDon.NMua.SDThoai[0]:void 0,
details:[]};for(let $dv$$ of $dl$$.NDHDon.DSHHDVu)for(let $hd$$ of $dv$$.HHDVu){let $detail$$={ma_tc:$hd$$.TChat[0],ma_vt:$hd$$.MHHDVu[0],ten_vt:$hd$$.THHDVu[0],ma_dvt:$hd$$.DVTinh[0]||"",sl_xuat:Number($hd$$.SLuong[0]||0),gia_ban_ct:Number($hd$$.DGia[0]||0),gia_ban_ct_nt:Number($hd$$.DGia[0]||0),ty_le_ck:Number($hd$$.TLCKhau[0]||0),tien_ck:Number($hd$$.STCKhau[0]||0),tien_ck_nt:Number($hd$$.STCKhau[0]||0),ma_thue:($hd$$.TSuat[0]||"").replace("%","")};$detail$$.tien_ct=$detail$$.tien_ct_nt=Number($hd$$.ThTien[0]||
0);$detail$$.thue_suat=Number($detail$$.ma_thue||0);$detail$$.tien_thue_nt=$detail$$.tien_thue=Math.round($detail$$.thue_suat*$detail$$.tien_ct_nt/100);$detail$$.tien=$detail$$.tien_nt=$detail$$.tien_ct_nt-$detail$$.tien_ck_nt+$detail$$.tien_thue_nt;$fdata$$.details.push($detail$$)}$fdata$$.t_tien_nt=$fdata$$.t_tien=$fdata$$.details.map($d$$=>$d$$.tien_ct_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$fdata$$.t_thue_nt=$fdata$$.t_thue=$fdata$$.details.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+
$b$$,0);$bufferObj$jscomp$1_rs$$.push($fdata$$)}$cb$$(null,$bufferObj$jscomp$1_rs$$)}catch($e$$){$cb$$($e$$)}})},($e$jscomp$15_invs$$,$rs$$)=>{if($e$jscomp$15_invs$$)return $reject$$($e$jscomp$15_invs$$);$e$jscomp$15_invs$$=$rs$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);$resolve$$($e$jscomp$15_invs$$)})}catch($e$$){$reject$$($e$$)}})},updateInvoice=async($contr$$,$ct$$)=>{let $result_export_einvoice$$=$ct$$.result_export_einvoice||{};$ct$$.so_hd=($result_export_einvoice$$.result||{}).invoiceNo;await $contr$$.model.updateOne({_id:$ct$$._id},
{so_hd:$ct$$.so_hd,result_export_einvoice:$ct$$.result_export_einvoice});$ct$$.so_hd&&await global.getModel("tdttno").updateMany({id_ct:$ct$$._id.toString()},{so_hd:$ct$$.so_hd});$ct$$.so_hd&&await global.getModel("tdttno_tt").updateMany({id_hd:$ct$$._id.toString()},{so_hd:$ct$$.so_hd});$ct$$.so_hd&&await global.getModel("vatra").updateMany({id_ct:$ct$$._id.toString()},{so_hd:$ct$$.so_hd});$contr$$.postData($ct$$,$e$$=>{if($e$$)return console.error($e$$);$contr$$.pushNotification($ct$$)});console.log("da cap nhat hoa don",
$ct$$.result_export_einvoice);return $result_export_einvoice$$},isMobilePhone=($str$$,$locale$$)=>$str$$?validator.isMobilePhone($str$$,$locale$$):!1,generatePasswordHash=function($password$$){return crypto.createHash("sha256").update($password$$+":STP").digest("hex")};
async function isBookLocked($ngay_ct_obj$$){if(!$ngay_ct_obj$$.ngay_ct||!$ngay_ct_obj$$.id_app&&!$ngay_ct_obj$$.ngay_ks)return!1;var $_app_ngay_ks$$=$ngay_ct_obj$$.ngay_ks;if(!$_app_ngay_ks$$){$_app_ngay_ks$$=await global.getModel("app").findOne({_id:$ngay_ct_obj$$.id_app});if(!$_app_ngay_ks$$)return!1;$_app_ngay_ks$$=moment($_app_ngay_ks$$.ngay_ks).endOf("date").toDate()}$ngay_ct_obj$$=moment($ngay_ct_obj$$.ngay_ct).startOf("date").toDate();return $_app_ngay_ks$$.getTime()>$ngay_ct_obj$$.getTime()?
$_app_ngay_ks$$:!1}
async function getLocationByAddress($address$$,$address2$$){try{let $url$jscomp$0$$=`https://api.geoapify.com/v1/geocode/search?text=${encodeURIComponent($address$$)}&apiKey=69ba27248ee845ecae90e5acac5b1de0`,$data$jscomp$0$$=(await axios.get($url$jscomp$0$$)).data.features||[];if(0<$data$jscomp$0$$.length){let $lc$$=$data$jscomp$0$$[0].properties||{};return{latitude:$lc$$.lat,longitude:$lc$$.lon}}if($address2$$){let $url$$=`https://api.geoapify.com/v1/geocode/search?text=${encodeURIComponent($address2$$)}&apiKey=69ba27248ee845ecae90e5acac5b1de0`,$data$$=
(await axios.get($url$$)).data.features||[];if(0<$data$$.length){let $lc$$=$data$$[0].properties||{};return{latitude:$lc$$.lat,longitude:$lc$$.lon}}console.log("Kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y v\u1ecb tr\u00ed c\u1ee7a \u0111\u1ecba ch\u1ec9 2:",{address2:$address2$$,url:$url$$})}else console.log("Kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y v\u1ecb tr\u00ed c\u1ee7a \u0111\u1ecba ch\u1ec9:",{address:$address$$,url:$url$jscomp$0$$})}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 x\u00e1c \u0111\u1ecbnh v\u00ed tr\u00ed c\u1ee7a \u0111\u1ecba ch\u1ec9:",
$address$$,"L\u1ed7i: ",($e$$.response||{}).data||$e$$)}return null}module.exports={isBookLocked,generatePasswordHash,evalute,JSONParser,getParameterData,prepareParameters,advMapSeries,numberToWord,round,getInfoFromQuery,stripHtmlTags:strip_html_tags,unescapeHtml,compileHtml,isSupperAdmin,calcGrid,getInvoice,updateInvoice,getInvoices,query,find:query,count,groupBy,joinModel2,getLib,aggregate,getCodeChildren,isMobilePhone,getLocationByAddress};