flexbiz-server
Version:
Flexible Server
7 lines (6 loc) • 2.67 kB
JavaScript
const model=global.getModel("vatvao"),controller=require("../../controllers/controller"),vatvao=function($router$$){(new controller($router$$,model,"vatvao",{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$$.thttltsuat||$row$$.thttltsuat.length==0)$row$$.tgtcthue?$row$$.thttltsuat=[{thtien:$row$$.tgtcthue,tthue:$row$$.tgtthue,tsuat:`${Math.round($row$$.tgtthue/
$row$$.tgtcthue*100)}%`}]:$row$$.tgtttbso&&($row$$.thttltsuat=[{thtien:$row$$.tgtttbso,tthue:0,tsuat:0,ma_thue:"KT"}]);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$$.nbmst,$ma_kh$$=$ma_so_thue$$,$dien_thoai$$=$row$$.nbsdthoai,$ten_kh$$=
$row$$.nbten,$dia_chi$$=$row$$.nbdchi;for(let $thue$$ of $row$$.thttltsuat){let $thue_suat$$=$thue$$.tsuat.split("%")[0]||0;$thue_suat$$=Number($thue_suat$$);let $ma_thue$$=$thue$$.ma_thue||$thue_suat$$.toString();if(!$ma_thue$$||isNaN($thue_suat$$))return $next$$("D\u1eef li\u1ec7u kh\u00f4ng h\u1ee3p l\u1ec7");$ma_thue$$.length==1&&($ma_thue$$=`0${$ma_thue$$}`);let $ty_gia$$=$row$$.tgia||1,$t_tien$$=$thue$$.thtien*$ty_gia$$,$t_thue$$=$thue$$.tthue*$ty_gia$$;$columns_new_data$$=$columns_new_data$$.concat({ma_ct:"VATVAO",
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$$})}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 $row$$.ma_ct&&$row$$.ngay_ct&&$row$$.id_ct?$columns_new_data$$.push($row$$):Logger.error("d\u1eef li\u1ec7u kh\u00f4ng h\u1ee3p l\u1ec7",$row$$)}}catch($e$$){return $next$$($e$$)}$next$$(null,
$columns_new_data$$)}})).route()};module.exports=vatvao;