flexbiz-server
Version:
Flexible Server
6 lines (5 loc) • 2.17 kB
JavaScript
const model=global.getModel("vatra"),controller=require("../../controllers/controller"),vatra=function($router$$){(new controller($router$$,model,"vatra",{sort:{ngay_hd:-1},onImport:async($id_app_user$$,$data_so_hd$$,$columns_new_data$$,$next$$)=>{$columns_new_data$$=[];$id_app_user$$=$id_app_user$$.current_id_app;try{for(let $row$$ of $data_so_hd$$)if($row$$.id&&$row$$.thttltsuat&&$row$$.thttltsuat.length>0){let $so_ct$$=$row$$.shdon,$id_ct$$=$row$$.id,$_curr$$=await model.findOne({id_ct:$id_ct$$,
id_app:$id_app_user$$}).lean();if(!$_curr$$||!$_curr$$.id_hd){let $ngay_ct$$=new Date($row$$.tdlap);$data_so_hd$$=$so_ct$$;let $ngay_hd$$=$ngay_ct$$,$ma_so_thue$$=$row$$.nmmst,$ma_kh$$=$ma_so_thue$$,$dien_thoai$$=$row$$.nbsdthoai,$ten_kh$$=$row$$.nmten,$dia_chi$$=$row$$.nmdchi;for(let $thue$$ of $row$$.thttltsuat){let $ma_thue$$=$thue$$.tsuat.split("%")[0],$thue_suat$$=Number($ma_thue$$);if(!$ma_thue$$||isNaN($thue_suat$$))return $next$$("D\u1eef li\u1ec7u kh\u00f4ng h\u1ee3p l\u1ec7");let $ty_gia$$=
$row$$.tgia||1,$t_tien$$=$thue$$.thtien*$ty_gia$$,$t_thue$$=$thue$$.tthue*$ty_gia$$,$new_row$$={ma_ct:"VATRA",id_ct:$id_ct$$,so_ct:$so_ct$$,ngay_ct:$ngay_ct$$,co_quan_thue:$row$$.cqt,ma_hoa_don:$row$$.khmshdon,ky_hieu_hoa_don:$row$$.khhdon,ma_tc:$row$$.tchat,so_hd:$data_so_hd$$,ngay_hd:$ngay_hd$$,ma_nt:$row$$.dvtte,ty_gia:$ty_gia$$,ma_kh:$ma_kh$$,ten_kh:$ten_kh$$,dia_chi:$dia_chi$$,ma_so_thue:$ma_so_thue$$,dien_giai:$row$$.gchu,ma_thue:$ma_thue$$,thue_suat:$thue_suat$$,t_tien_nt:$thue$$.thtien,t_tien:$t_tien$$,
t_thue_nt:$thue$$.tthue,t_thue:$t_thue$$,t_hd_nt:$thue$$.thtien=$thue$$.tthue,t_hd:$t_tien$$+$t_thue$$,hddt:$row$$};$columns_new_data$$=$columns_new_data$$.concat($new_row$$)}await model.deleteMany({id_app:$id_app_user$$,id_ct:$id_ct$$});await global.getModel("customer").findOne({id_app:$id_app_user$$,ma_kh:$ma_kh$$},{_id:1}).lean()||await global.getModel("customer").create({id_app:$id_app_user$$,ma_kh:$ma_kh$$,ten_kh:$ten_kh$$,dia_chi:$dia_chi$$,ma_so_thue:$ma_so_thue$$,dien_thoai:$dien_thoai$$})}}else $columns_new_data$$.push($row$$)}catch($e$$){return $next$$($e$$)}$next$$(null,
$columns_new_data$$)}})).route()};module.exports=vatra;