123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922 |
- package com.kingdee.eas.custom.compensation.handler;
- import cn.com.servyou.dto.ApiResponse;
- import cn.com.servyou.dto.AsyncResult;
- import cn.com.servyou.dto.declare.CompanyDeclareRequest;
- import cn.com.servyou.dto.tax.*;
- import cn.com.servyou.rmi.client.ClientProxyFactory;
- import cn.com.servyou.service.DeclarationRequest;
- import com.alibaba.fastjson.JSONObject;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.kingdee.bos.BOSException;
- import com.kingdee.bos.Context;
- import com.kingdee.bos.metadata.entity.*;
- import com.kingdee.bos.metadata.query.util.CompareType;
- import com.kingdee.bos.util.EASResource;
- import com.kingdee.eas.basedata.hraux.NationalityInfo;
- import com.kingdee.eas.basedata.person.PersonCollection;
- import com.kingdee.eas.basedata.person.PersonFactory;
- import com.kingdee.eas.basedata.person.PersonInfo;
- import com.kingdee.eas.common.EASBizException;
- import com.kingdee.eas.custom.shuiyou.task.TaskCatalogEnum;
- import com.kingdee.eas.custom.shuiyou.uitls.ISYUtilsFacade;
- import com.kingdee.eas.custom.shuiyou.uitls.SYUtilsFacadeFactory;
- import com.kingdee.eas.custom.shuiyou.utils.ClientProxyFactoryUtils;
- import com.kingdee.eas.util.app.DbUtil;
- import com.kingdee.jdbc.rowset.IRowSet;
- import com.kingdee.shr.base.syssetting.context.SHRContext;
- import com.kingdee.shr.base.syssetting.exception.SHRWebException;
- import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
- import com.kingdee.shr.base.syssetting.web.dynamic.util.DynamicUtil;
- import com.kingdee.shr.base.syssetting.web.dynamic.util.MD5;
- import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
- import com.kingdee.shr.base.syssetting.web.util.UserUtil;
- import com.kingdee.shr.compensation.TbTypeEnum;
- import com.kingdee.shr.compensation.app.incomeTax.ITaxPersonRecordEntry;
- import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordEntryCollection;
- import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordEntryFactory;
- import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordEntryInfo;
- import com.kingdee.shr.compensation.app.tax.*;
- import com.kingdee.shr.compensation.app.tax.base.TaxIncomeItemInfo;
- import com.kingdee.shr.compensation.app.taxCal.*;
- import com.kingdee.shr.compensation.util.*;
- import com.kingdee.shr.compensation.web.handler.tax.IncomeTaxDeclareListHandler;
- import com.kingdee.shr.compensation.web.handler.tax.dto.TaxDeclarExcelRowDTO;
- import com.kingdee.shr.compensation.web.handler.tax.dto.TaxDeclareDTO;
- import com.kingdee.util.StringUtils;
- import org.apache.log4j.Logger;
- import org.apache.poi.hssf.usermodel.*;
- import org.springframework.ui.ModelMap;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.sql.SQLException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * @author qingwu
- * @date 2024/9/18
- * @apiNote 个税申报扩展
- */
- public class IncomeTaxDeclareListHandlerEx extends IncomeTaxDeclareListHandler {
- private static final Logger LOG = Logger.getLogger(IncomeTaxDeclareListHandlerEx.class);
- private Context ctx = SHRContext.getInstance().getContext();
- private ObjectMapper mapper = new ObjectMapper();
- /**
- * 个税申报
- *
- * @param request
- * @param response
- * @param modelMap
- */
- @Override
- public void taxDeclareAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws BOSException, SHRWebException {
- LOG.error("taxDeclareAction-----------start-----------");
- Context ctx = SHRContext.getInstance().getContext();
- try {
- boolean isHaveTaxService = CmpTaxUtil.isHaveTaxService(ctx);
- if (!isHaveTaxService) {
- throw new ShrWebBizException(EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label136", ctx.getLocale()));
- } else {
- String selectedId = request.getParameter("selectedId");
- Map<String, Object> resultMap = new HashMap();
- Map<String, Object> declareData = this.getDeclareData(ctx, selectedId);
- Map<String, Object> paramMap = new HashMap();
- paramMap.put("declaData", declareData.get("WATI_TO_DECLARE"));
- LOG.error("paramMap-----------" + paramMap);
- try {
- //纳税单位
- List<String> advanceDeclareInfo = (List) declareData.get("advanceDeclareInfo");
- LOG.error("advanceDeclareInfo------------" + advanceDeclareInfo);
- if (!advanceDeclareInfo.isEmpty()) {
- throw new ShrWebBizException(this.combineError(advanceDeclareInfo));
- }
- //个税审批 审批状态=审批通过的数据
- List<IncomeTaxDeclarInfo> waitToDeclareList = (List) paramMap.get("declaData");
- if (waitToDeclareList.size() <= 0) {
- resultMap.put("success", false);
- resultMap.put("excel", "");
- resultMap.put("hasErrData", true);
- resultMap.put("hasCheckDataErr", true);
- resultMap.put("info", "不可重复声申报!!");
- JSONUtils.SUCCESS(resultMap);
- return;
- }
- //检查纳税申报数据
- Map<String, Object> checkResultMap = this.checkTaxDeclareData(ctx, request, waitToDeclareList);
- Boolean hasErr = (Boolean) checkResultMap.get("hasErrData");
- if (hasErr != null && hasErr) {
- resultMap.put("success", false);
- resultMap.put("excel", checkResultMap.get("excel"));
- resultMap.put("hasErrData", true);
- resultMap.put("hasCheckDataErr", true);
- resultMap.put("info", "");
- JSONUtils.SUCCESS(resultMap);
- return;
- }
- String errMsg = this.checkTaxCalStatus(ctx, waitToDeclareList);
- if (null != errMsg) {
- resultMap.put("success", false);
- resultMap.put("dataError", true);
- resultMap.put("errMsg", errMsg);
- JSONUtils.SUCCESS(resultMap);
- return;
- }
- checkResultMap = this.checkIncomeTaxIssue(ctx, waitToDeclareList);
- if (checkResultMap != null) {
- checkResultMap.put("success", false);
- JSONUtils.SUCCESS(checkResultMap);
- return;
- }
- //errMsg = this.checkReductionItems(ctx, waitToDeclareList);
- //if (null != errMsg) {
- // resultMap.put("success", false);
- // resultMap.put("reductionError", true);
- // resultMap.put("errMsg", errMsg);
- // JSONUtils.SUCCESS(resultMap);
- // return;
- //}
- //Map<String, Object> taxDeclareResult = IncomeTaxDeclareFacadeFactory.getLocalInstance(ctx).taxDeclare(paramMap);
- //调佣税友纳税申报
- Map<String, Object> taxDeclareResult = callShuiYouTaxDeclare(paramMap);
- Boolean isSuccess = (Boolean) taxDeclareResult.get("success");
- resultMap.put("success", isSuccess);
- resultMap.put("excel", "");
- resultMap.put("hasErrData", !isSuccess);
- resultMap.put("hasCheckDataErr", false);
- resultMap.put("info", declareData.get("info"));
- } catch (Exception var17) {
- var17.printStackTrace();
- LOG.error(var17.getMessage(), var17);
- resultMap.put("success", false);
- resultMap.put("excel", "");
- resultMap.put("hasErrData", true);
- resultMap.put("hasCheckDataErr", false);
- resultMap.put("info", declareData.get("info"));
- resultMap.put("errorMsg", var17.getMessage());
- }
- LOG.error("taxDeclareAction-----------end-----------");
- JSONUtils.SUCCESS(resultMap);
- }
- } catch (JsonProcessingException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
- /**
- * 调佣税友纳税申报
- *
- * @param paramMap
- * @return
- */
- public Map<String, Object> callShuiYouTaxDeclare(Map paramMap) {
- LOG.error("callShuiYouTaxDeclare--------------------paramMap" + paramMap);
- Map<String, Object> resultMap = new HashMap();
- resultMap.put("success", true);
- resultMap.put("msg", "");
- List<IncomeTaxDeclarInfo> waitToDeclareList = (List) paramMap.get("declaData");
- Map<String, Object> requestParamMap = new HashMap();
- List<Object[]> paramList = new ArrayList();
- try {
- if (waitToDeclareList != null && waitToDeclareList.size() > 0) {
- for (int i = 0; i < waitToDeclareList.size(); i++) {
- IncomeTaxDeclarInfo taxDeclarInfo = waitToDeclareList.get(i);
- JSONObject param = new JSONObject();
- param.put("taxDeclarId", taxDeclarInfo.getId());
- param.put("taxDeclarBatchNo", taxDeclarInfo.getBatchNo());
- //纳税单位
- TaxUnitInfo taxUnitInfo = taxDeclarInfo.getTaxUnit();
- //客户端代理工厂
- ClientProxyFactory clientProxyFactory = ClientProxyFactoryUtils.getClientProxyFactory();
- //算税请求接口
- DeclarationRequest declarationRequest = clientProxyFactory.getDeclarationRequest();
- //获取请求参数
- CompanyDeclareRequest declareRequestParameter = getDeclareRequestParameter(taxUnitInfo, taxDeclarInfo);
- LOG.error("declareRequestParameter-----------------" + mapper.writeValueAsString(declareRequestParameter));
- ApiResponse<AsyncResult> apiResponse = declarationRequest.send(declareRequestParameter);
- LOG.error("asyncResultApiResponse-----getCode-------" + apiResponse.getHead().getCode());
- LOG.error("asyncResultApiResponse-----getMsg--------" + apiResponse.getHead().getMsg());
- resultMap.put("msg", mapper.writeValueAsString(declareRequestParameter));
- if (apiResponse.getHead().getCode().equals("00000000")) {
- AsyncResult body = apiResponse.getBody();
- String requestId = body.getRequestId();
- LOG.error("requestId-----" + requestId);
- LOG.error("apiResponse-----" + mapper.writeValueAsString(apiResponse));
- //查询反算反馈结果
- ISYUtilsFacade isyUtilsFacade = SYUtilsFacadeFactory.getLocalInstance(ctx);
- //backTask(url,requestId,回调osf服务,自定义参数,任务类型)
- //isyUtilsFacade.backTask(isyUtilsFacade.getConfig().get("ip") + "/gateway/iit/reverseCalculateTax/getASynIndividualIncomeTaxFeedback", requestId, "synIndividualIncomeTaxService", jsonObject.toString(), TaskCatalogEnum.CAL_GET);
- JSONObject json = new JSONObject();
- json.put("requestId", requestId);
- json.put("param", param.toString());
- isyUtilsFacade.addTask("synIncomeTaxDeclareService", json.toJSONString(), TaskCatalogEnum.UN_CAL_GET, "");
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- resultMap.put("success", false);
- resultMap.put("msg", e.getMessage());
- return resultMap;
- }
- return resultMap;
- }
- /**
- * 获取请求参数
- * 注意:
- * 1.解除劳动合同一次性补偿金、全年一次性奖金所得,不能单独申报,需要同正常工资薪金一起申报。
- * 2.解除劳动合同一次性补偿金、稿酬所得,由于税务规则需要,解除劳动合同一次性补偿金、稿酬所得必须填写免税附表。
- *
- * @param taxUnitInfo
- * @param taxDeclarInfo
- * @return
- */
- private CompanyDeclareRequest getDeclareRequestParameter(TaxUnitInfo taxUnitInfo,
- IncomeTaxDeclarInfo taxDeclarInfo
- ) throws BOSException, JsonProcessingException, EASBizException, SQLException {
- LOG.error("getDeclareRequestParameter-----------taxDeclarInfo-----" + taxDeclarInfo);
- CompanyDeclareRequest declareRequestPara = new CompanyDeclareRequest();
- Map<String, Object> requestParamMap = new HashMap();
- //随机id
- String bizNo = UUID.randomUUID().toString();
- LOG.error("bizNo:" + bizNo);
- //外部业务订单号*
- declareRequestPara.setBizNo(bizNo);
- //企业名称*
- declareRequestPara.setName(taxUnitInfo.getName());
- //税号*
- declareRequestPara.setTaxNo(taxUnitInfo.getTaxNumber());
- //行政区划代码*
- declareRequestPara.setArea(taxUnitInfo.getAreaCode());
- //登记序号
- declareRequestPara.setRegistrationNumber(taxUnitInfo.getRegNumber());
- String declPassword = taxUnitInfo.getDeclPassword();
- if (StringUtils.isEmpty(declPassword)) {
- throw new BOSException("申报密码不能为空!");
- }
- declareRequestPara.setDeclarePassword(Base64Utils.decode(declPassword));
- //所得月份
- String yearMonth = taxDeclarInfo.getYearMonth();
- String replaceYearMonth = yearMonth.replace("-", "");
- LOG.error("replaceYearMonth----------------" + replaceYearMonth);
- //税款所属期YYYYMM*
- declareRequestPara.setMonth(replaceYearMonth);
- //总金额
- //BigDecimal totalMoney = taxDeclarInfo.getTotalMoney();
- //应退税额
- //BigDecimal taxRebate = taxDeclarInfo.getTaxRebate();
- //总人数
- //long totalPerson = taxDeclarInfo.getTotalPerson();
- //申报表分类 1=预扣预缴申报表 2=分类所得申报表 3=非居民所得申报表
- //String tbTble = taxDeclarInfo.getTbType().getValue();
- //纳税单位ID
- //String taxUnitId = taxUnitInfo.getId().toString();
- //Map<String, Object> tbTypeMap = new HashMap();
- //if (totalMoney.compareTo(BigDecimal.ZERO) == 0) {
- // tbTypeMap.put("zje", 0.0);
- //} else {
- // tbTypeMap.put("zje", totalMoney);
- //}
- //
- //if (taxRebate.compareTo(BigDecimal.ZERO) == 0) {
- // tbTypeMap.put("ynse", 0.0);
- //} else {
- // tbTypeMap.put("ynse", taxRebate);
- //}
- //tbTypeMap.put("zrs", totalPerson);
- //Map<String, Object> dataMap = new HashMap();
- //if ("1".equals(tbTble)) {
- // dataMap.put("ykyj", tbTypeMap);
- //} else if ("2".equals(tbTble)) {
- // dataMap.put("flsd", tbTypeMap);
- //} else if ("3".equals(tbTble)) {
- // dataMap.put("fjm", tbTypeMap);
- //}
- //密码类型*
- declareRequestPara.setPasswordType("0");
- //离职日期处理策略 1、不传或传1,代表离职日期自动清空,即人员状态由“非正常”变更为“正常”时,离职日期字段自动清空,默认逻辑。
- //2、传2离职日期不自动清空,即人员状态由“非正常”变更为“正常”时,离职日期不自动清空,客户如需清空需对离职日期字段传入空字符串。
- //declareRequestPara.setResignDateStrategy();
- //批次号
- String batchNo = taxDeclarInfo.getBatchNo();
- LOG.error("taxCalConfigDetailCollection--------taxDeclarInfo---------" + taxDeclarInfo);
- //个税应用+税款计算最终拆分明细表
- ITaxCalConfigDetail taxCalConfigDetail = TaxCalConfigDetailFactory.getLocalInstance(ctx);
- TaxCalConfigDetailCollection taxCalConfigDetailCollection = taxCalConfigDetail.getTaxCalConfigDetailCollection("select *,incomeItem.*, person.* where batchNo = '" + batchNo + "' and state = '20'");
- LOG.error("taxCalConfigDetailCollection-----------------" + taxCalConfigDetailCollection.size());
- //员工信息ID
- Set personIds = new HashSet();
- //综合所得对象
- ComplexIncomeRequest complexIncomeRequest = new ComplexIncomeRequest();
- //正常工资薪金对象
- NormalSalarySpecIncome normalSalarySpecIncome = new NormalSalarySpecIncome();
- //正常工资薪金列表
- List<ComplexIncome> normalSalarySpec = new ArrayList();
- //全年一次性奖金收入
- List<ComplexIncome> annualOneTimeBonusIncome = new ArrayList();
- //全年一次性奖金收入
- List<ComplexIncome> laborRemunerationIncome = new ArrayList();
- if (taxCalConfigDetailCollection.size() > 0) {
- for (int i = 0; i < taxCalConfigDetailCollection.size(); i++) {
- TaxCalConfigDetailInfo taxCalConfigDetailInfo = taxCalConfigDetailCollection.get(i);
- //员工信息
- PersonInfo personInfo = taxCalConfigDetailInfo.getPerson();
- personIds.add(personInfo.getId().toString());
- //所得项目
- TaxIncomeItemInfo incomeItem = taxCalConfigDetailInfo.getIncomeItem();
- //本期收入
- Integer sre = null;
- String getSreSql = "select t1 from T_HR_STaxCalConfigDetail where fid ='" + taxCalConfigDetailInfo.getId().toString() + "'";
- IRowSet iRowSet = DbUtil.executeQuery(ctx, getSreSql);
- while (iRowSet.next()) {
- sre = iRowSet.getInt("t1");
- }
- LOG.error("incomeItem-----------------" + incomeItem);
- //所属项目名称
- String incomeItemName = incomeItem.getName();
- //所属项目编码
- String incomeItemNumber = incomeItem.getNumber();
- //正常工资薪金
- if ("zcgzxjlb".equals(incomeItemNumber)) {
- //getComplexIncome(员工信息对象 ,所属项目,本期收入)
- normalSalarySpec.add(getComplexIncome(personInfo, incomeItemName, sre));
- //正常工资薪金列表 保存数据
- normalSalarySpecIncome.setNormalSalarySpec(normalSalarySpec);
- LOG.error("normalSalarySpecIncome-----------------" + mapper.writeValueAsString(normalSalarySpecIncome));
- complexIncomeRequest.setNormalSalarySpecIncome(normalSalarySpecIncome);
- }
- //全年一次性奖金收入
- if ("qnycxjjlb".equals(incomeItemNumber)) {
- annualOneTimeBonusIncome.add(getComplexIncome(personInfo, incomeItemName, sre));
- LOG.error("annualOneTimeBonusIncome-----------------" + mapper.writeValueAsString(annualOneTimeBonusIncome));
- LOG.error("annualOneTimeBonusIncome-----------------" + annualOneTimeBonusIncome);
- LOG.error("annualOneTimeBonusIncome.size()-----------------" + annualOneTimeBonusIncome.size());
- //全年一次性奖金收入 保存数据
- complexIncomeRequest.setAnnualOneTimeBonusIncome(annualOneTimeBonusIncome);
- }
- //一般劳务报酬所得
- if ("lwbclb".equals(incomeItemNumber)) {
- laborRemunerationIncome.add(getComplexIncome(personInfo, incomeItemName, sre));
- LOG.error("laborRemunerationIncome-----------------" + mapper.writeValueAsString(laborRemunerationIncome));
- //一般劳务报酬所得 保存数据
- complexIncomeRequest.setLaborRemunerationIncome(laborRemunerationIncome);
- }
- }
- }
- //综合所得
- declareRequestPara.setComplexIncomeRequest(complexIncomeRequest);
- //企业员工列表
- List<DetailCompanyEmployee> companyEmployeeList = getCompanyEmployeeList(personIds);
- declareRequestPara.setCompanyEmployeeList(companyEmployeeList);
- LOG.error("companyEmployeeList-----------------" + mapper.writeValueAsString(companyEmployeeList));
- return declareRequestPara;
- }
- /***
- * 员工
- * @return
- */
- private ComplexIncome getComplexIncome(PersonInfo personInfo, String incomeItemName, Integer sre) {
- ComplexIncome complexIncome = new ComplexIncome();
- //姓名
- complexIncome.setName(personInfo.getName());
- //居民身份证
- if (personInfo.getIdCardNO() != null) {
- //证照号码
- complexIncome.setLicenseNumber(personInfo.getIdCardNO());
- //证照类型
- complexIncome.setLicenseType("居民身份证");
- }
- //中国护照不
- if (personInfo.getPassportNO() != null) {
- //证照类型
- complexIncome.setLicenseType("中国护照");
- //证照号码
- complexIncome.setLicenseNumber(personInfo.getPassportNO());
- }
- //收入额
- complexIncome.setIncome(new BigDecimal(sre));
- complexIncome.setIncomeItemName(incomeItemName);
- return complexIncome;
- }
- /**
- * 企业员工列表*
- *
- * @return
- */
- private List<DetailCompanyEmployee> getCompanyEmployeeList(Set personIds) throws BOSException, EASBizException {
- List<DetailCompanyEmployee> companyEmployeeList = new ArrayList<DetailCompanyEmployee>();
- SelectorItemCollection sic = new SelectorItemCollection();
- sic.add("*");
- FilterInfo filterInfo = new FilterInfo();
- filterInfo.getFilterItems().add(new FilterItemInfo("id", personIds, CompareType.INCLUDE));
- EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null); //获取人员数据
- PersonCollection personCollection = PersonFactory.getLocalInstance(ctx).getPersonCollection(entityViewInfo);
- if (personCollection.size() > 0) {
- for (int i = 0; i < personCollection.size(); i++) {
- PersonInfo personInfo = personCollection.get(i);
- companyEmployeeList.add(getDetailCompanyEmployee(personInfo));
- }
- }
- return companyEmployeeList;
- }
- /**
- * 人员
- *
- * @return
- */
- public DetailCompanyEmployee getDetailCompanyEmployee(PersonInfo personInfo) throws BOSException, EASBizException {
- //人员对象
- DetailCompanyEmployee detailCompanyEmployee = new DetailCompanyEmployee();
- ////姓名
- //detailCompanyEmployee.setName("何云");
- ////证件类型
- //detailCompanyEmployee.setLicenseType("居民身份证");
- ////证照号码
- //detailCompanyEmployee.setLicenseNumber("429004198601085125");
- //姓名
- detailCompanyEmployee.setName(personInfo.getName());
- //complexIncome.setName("何云");
- //居民身份证
- if (personInfo.getIdCardNO() != null) {
- //证照号码
- detailCompanyEmployee.setLicenseNumber(personInfo.getIdCardNO());
- //证照类型
- detailCompanyEmployee.setLicenseType("居民身份证");
- //人员地区
- detailCompanyEmployee.setArea("境内");
- }
- //中国护照
- if (personInfo.getPassportNO() != null) {
- //证照类型
- detailCompanyEmployee.setLicenseType("中国护照");
- //证照号码
- detailCompanyEmployee.setLicenseNumber(personInfo.getPassportNO());
- //人员地区
- detailCompanyEmployee.setArea("境外");
- }
- //电话号码
- detailCompanyEmployee.setPhone(personInfo.getCell());
- //人员状态
- detailCompanyEmployee.setState(personInfo.getEmployeeType().getName());
- //人员报税信息->任职受雇从业信息
- ITaxPersonRecordEntry iTaxPersonRecordEntry = TaxPersonRecordEntryFactory.getLocalInstance(ctx);
- TaxPersonRecordEntryCollection taxPersonRecordEntryCollection = iTaxPersonRecordEntry.getTaxPersonRecordEntryCollection("where person.id = '" + personInfo.getId() + "'");
- TaxPersonRecordEntryInfo taxPersonRecordEntryInfo = taxPersonRecordEntryCollection.get(0);
- //任职受雇类型 可选择雇员、保险营销员、证券经纪人、其他、实习学生(全日制学历教育)
- //detailCompanyEmployee.setIsEmployee("其他");
- detailCompanyEmployee.setIsEmployee(taxPersonRecordEntryInfo.getEmployedType().getAlias());
- //受雇日期 YYYY-MM-DD,不能大于当前时间,任职受雇类型选择雇员、保险营销员、证券经纪人时必录
- SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
- detailCompanyEmployee.setEmployedDate(inputFormat.format(taxPersonRecordEntryInfo.getEmployedDate()));
- //性别
- detailCompanyEmployee.setGender(personInfo.getGender().getAlias());
- //出生日期
- detailCompanyEmployee.setBirthday(inputFormat.format(personInfo.getBirthday()));
- //国籍 nationality
- NationalityInfo nationality = personInfo.getNationality();
- detailCompanyEmployee.setNationality(nationality.getName());
- return detailCompanyEmployee;
- }
- private String getCheckSqlByType(Map<String, Object> incomeIdMap, String taxUnitId, String yearMonth, TbTypeEnum typeEnum) {
- StringBuilder sqlBuf = new StringBuilder();
- sqlBuf.append(" SELECT distinct tx.FTAXUNITID,t1.Fname_l2 as TAXNAME,p1.FNUMBER,p1.Fname_l2 as PERSONNAME, ti.fIncomeCode ");
- sqlBuf.append(" FROM T_HR_STaxCalConfigDetail tx ");
- sqlBuf.append(" left join T_HR_TAXUNIT as t1 on t1.fid = tx.FTaxUnitID ");
- sqlBuf.append(" left join T_BD_PERSON as p1 on p1.fid = tx.FPersonId ");
- sqlBuf.append(" left join t_hr_sTaxIncomeItem as ti on tx.fIncomeItemId = ti.fid ");
- String dateFilter = CmpSQLUtil.generateSqlDateFilter("tx.FPeriodBegin", "tx.FPeriodEnd", yearMonth);
- sqlBuf.append(" where ").append(dateFilter);
- sqlBuf.append(" and tx.FTAXUNITID='").append(taxUnitId).append("'");
- sqlBuf.append(" and tx.FSTATE=10");
- sqlBuf.append(" and tx.FIsLast=1");
- sqlBuf.append(" and tx.FIncomeItemId in ").append(incomeIdMap.get(typeEnum.getValue()));
- return sqlBuf.toString();
- }
- //private Map<String, Object> checkTaxDeclareData(Context ctx, List<IncomeTaxDeclarInfo> waitToDeclareList) throws BOSException {
- // Map<String, Object> checkDataResultMap = new HashMap();
- // return null;
- //}
- private Map<String, Object> checkTaxDeclareData(Context ctx, HttpServletRequest request, List<IncomeTaxDeclarInfo> waitToDeclareList) throws BOSException, SQLException, ShrWebBizException {
- Map<String, Object> checkDataResultMap = new HashMap();
- boolean hasErrData = false;
- if (waitToDeclareList != null && waitToDeclareList.size() > 0) {
- List<String> preCheckSql = new ArrayList();
- List<String> specCheckForPre = new ArrayList();
- List<String> notPersonCheckSql = new ArrayList();
- List<String> classifyCheckSql = new ArrayList();
- Map<String, Object> incomeIdMap = new HashMap();
- incomeIdMap.put("1", CmpTaxUtil.genIncomeItemId(ctx, "1"));
- incomeIdMap.put("2", CmpTaxUtil.genIncomeItemId(ctx, "2"));
- incomeIdMap.put("3", CmpTaxUtil.genIncomeItemId(ctx, "3"));
- Iterator i$ = waitToDeclareList.iterator();
- String yearMonth;
- while (i$.hasNext()) {
- IncomeTaxDeclarInfo declareInfo = (IncomeTaxDeclarInfo) i$.next();
- TbTypeEnum tbType = declareInfo.getTbType();
- String taxUnitId = declareInfo.getTaxUnit().getId().toString();
- yearMonth = declareInfo.getYearMonth();
- if (tbType != null) {
- if ("1".equals(tbType.getValue())) {
- preCheckSql.add(this.getCheckSqlByType(incomeIdMap, taxUnitId, yearMonth, TbTypeEnum.SB0701));
- specCheckForPre.add(this.getPreCheckSql(declareInfo));
- } else if ("3".equals(tbType.getValue())) {
- notPersonCheckSql.add(this.getCheckSqlByType(incomeIdMap, taxUnitId, yearMonth, TbTypeEnum.SB0703));
- } else {
- classifyCheckSql.add(this.getCheckSqlByType(incomeIdMap, taxUnitId, yearMonth, TbTypeEnum.SB0702));
- }
- }
- }
- Map<String, String> reasonOperaMap = new HashMap();
- reasonOperaMap.put("noCalDataReson", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label140", ctx.getLocale()));
- reasonOperaMap.put("noCalDataOper", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label141", ctx.getLocale()));
- reasonOperaMap.put("preDataReason", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label142", ctx.getLocale()));
- reasonOperaMap.put("preDataOpera", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label143", ctx.getLocale()));
- List<TaxDeclarExcelRowDTO> taxDeclareExcelRowDTOS = new ArrayList();
- taxDeclareExcelRowDTOS.addAll(this.getExceptData(ctx, preCheckSql, specCheckForPre, reasonOperaMap, TbTypeEnum.SB0701));
- taxDeclareExcelRowDTOS.addAll(this.getExceptData(ctx, classifyCheckSql, specCheckForPre, reasonOperaMap, TbTypeEnum.SB0702));
- taxDeclareExcelRowDTOS.addAll(this.getExceptData(ctx, notPersonCheckSql, specCheckForPre, reasonOperaMap, TbTypeEnum.SB0703));
- String filePath = "";
- if (taxDeclareExcelRowDTOS.size() > 0) {
- hasErrData = true;
- HSSFWorkbook workbook = new HSSFWorkbook();
- yearMonth = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label144", ctx.getLocale());
- this.fillTitle(ctx, workbook, yearMonth.split(","));
- this.fillWorkdBookData(workbook, taxDeclareExcelRowDTOS);
- SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
- File dir = new File(UserUtil.getUserTempDirAbsolutePath(request.getSession()));
- if (!dir.exists()) {
- dir.mkdirs();
- }
- String fileName = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label145", ctx.getLocale()) + "_" + format.format(new Date()) + ".xls";
- String realFileName = MD5.md5Hash(fileName);
- File file = new File(dir, realFileName);
- FileOutputStream out = null;
- try {
- out = new FileOutputStream(file);
- workbook.write(out);
- out.flush();
- } catch (FileNotFoundException var33) {
- LOG.error(var33.getMessage(), var33);
- } catch (IOException var34) {
- LOG.error(var34.getMessage(), var34);
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException var32) {
- LOG.error(var32.getMessage(), var32);
- }
- }
- }
- Map<String, String> params = new HashMap();
- params.put("method", "tmp");
- params.put("file", realFileName);
- params.put("filename", fileName);
- filePath = DynamicUtil.assembleUrl("/downloadfile.do", params);
- }
- checkDataResultMap.put("excel", filePath);
- }
- checkDataResultMap.put("hasErrData", hasErrData);
- return checkDataResultMap;
- }
- private void fillTitle(Context ctx, HSSFWorkbook workbook, String[] titleArr) {
- HSSFSheet sheet = workbook.createSheet();
- HSSFRow createRow = sheet.createRow(0);
- HSSFCell infoCell = createRow.createCell(0);
- infoCell.setCellValue(EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label146", ctx.getLocale()));
- sheet.setColumnWidth(0, 12800);
- createRow = sheet.createRow(1);
- HSSFFont font = workbook.createFont();
- font.setColor((short) 8);
- font.setFontHeightInPoints((short) 12);
- font.setBoldweight((short) 700);
- HSSFCellStyle style = workbook.createCellStyle();
- style.setFont(font);
- style.setAlignment((short) 2);
- style.setVerticalAlignment((short) 1);
- if (titleArr != null && titleArr.length > 0) {
- for (int i = 0; i < titleArr.length; ++i) {
- HSSFCell cell = createRow.createCell(i);
- cell.setCellStyle(style);
- cell.setCellValue(titleArr[i]);
- if (i > 3) {
- sheet.setColumnWidth(i, 15360);
- } else {
- sheet.setColumnWidth(i, 7680);
- }
- }
- }
- }
- private void fillWorkdBookData(HSSFWorkbook workbook, List<TaxDeclarExcelRowDTO> dataList) {
- HSSFSheet sheet = workbook.getSheetAt(0);
- if (dataList != null && dataList.size() > 0) {
- for (int i = 0; i < dataList.size(); ++i) {
- HSSFRow row = sheet.createRow(i + 2);
- TaxDeclarExcelRowDTO excelRowDTO = (TaxDeclarExcelRowDTO) dataList.get(i);
- HSSFCell cell = row.createCell(0);
- cell.setCellValue(excelRowDTO.getPersonNum());
- cell = row.createCell(1);
- cell.setCellValue(excelRowDTO.getPersonName());
- cell = row.createCell(2);
- cell.setCellValue(excelRowDTO.getTaxName());
- cell = row.createCell(3);
- cell.setCellValue(excelRowDTO.getDeclarType());
- cell = row.createCell(4);
- cell.setCellValue(excelRowDTO.getReason());
- cell = row.createCell(5);
- cell.setCellValue(excelRowDTO.getOperation());
- }
- }
- }
- private String getSqlDateFilterLqDate(String dateStr) {
- String[] beginDateArr = dateStr.split("-");
- Calendar calendar = Calendar.getInstance();
- calendar.set(Integer.parseInt(beginDateArr[0]), Integer.parseInt(beginDateArr[1]) - 1, 1, 0, 0, 0);
- Date beginDate = calendar.getTime();
- return CmpDateUtil.toKSqlDate(beginDate);
- }
- private List<TaxDeclarExcelRowDTO> getExceptData(Context ctx, List<String> preCheckSql, List<String> specCheckForPre, Map<String, String> noCalDataOper, TbTypeEnum typeEnum) throws BOSException, SQLException, ShrWebBizException {
- List<TaxDeclarExcelRowDTO> taxDeclarExcelRowDTOS = new ArrayList();
- Iterator i$;
- String s;
- IRowSet rowSet;
- TaxDeclarExcelRowDTO taxDeclareExcelRow;
- if (preCheckSql != null && preCheckSql.size() > 0) {
- i$ = preCheckSql.iterator();
- while (i$.hasNext()) {
- s = (String) i$.next();
- rowSet = DbUtil.executeQuery(ctx, s);
- while (rowSet.next()) {
- taxDeclareExcelRow = new TaxDeclarExcelRowDTO();
- taxDeclareExcelRow.setPersonNum(rowSet.getString("FNUMBER"));
- taxDeclareExcelRow.setPersonName(rowSet.getString("PERSONNAME"));
- String taxUnitName = rowSet.getString("TAXNAME");
- taxDeclareExcelRow.setTaxName(taxUnitName);
- taxDeclareExcelRow.setDeclarType(typeEnum.getAlias());
- taxDeclareExcelRow.setReason((String) noCalDataOper.get("noCalDataReson"));
- taxDeclareExcelRow.setOperation((String) noCalDataOper.get("noCalDataOper"));
- String incomeCode = (String) noCalDataOper.get("fIncomeCode");
- taxDeclarExcelRowDTOS.add(taxDeclareExcelRow);
- }
- }
- }
- if ("1".equals(typeEnum.getValue()) && specCheckForPre != null && specCheckForPre.size() > 0) {
- i$ = specCheckForPre.iterator();
- while (i$.hasNext()) {
- s = (String) i$.next();
- rowSet = DbUtil.executeQuery(ctx, s);
- while (rowSet.next()) {
- taxDeclareExcelRow = new TaxDeclarExcelRowDTO();
- taxDeclareExcelRow.setPersonNum(rowSet.getString("FNUMBER"));
- taxDeclareExcelRow.setPersonName(rowSet.getString("PERSONNAME"));
- taxDeclareExcelRow.setTaxName(rowSet.getString("TAXNAME"));
- taxDeclareExcelRow.setDeclarType(typeEnum.getAlias());
- taxDeclareExcelRow.setReason((String) noCalDataOper.get("preDataReason"));
- taxDeclareExcelRow.setOperation((String) noCalDataOper.get("preDataOpera"));
- taxDeclarExcelRowDTOS.add(taxDeclareExcelRow);
- }
- }
- }
- return taxDeclarExcelRowDTOS;
- }
- private String getPreCheckSql(IncomeTaxDeclarInfo incomeTaxDeclarInfo) {
- StringBuilder sqlBuf = new StringBuilder();
- String yearMonth = incomeTaxDeclarInfo.getYearMonth();
- String taxUnitId = incomeTaxDeclarInfo.getTaxUnit().getId().toString();
- String sql = "select FPersonID from T_HR_STaxCalConfigDetail where FTaxUnitId='" + taxUnitId + "' and FPeriodBegin = " + CmpDateUtil.toKSqlDate(incomeTaxDeclarInfo.getYearMonthDate());
- sqlBuf.append(" SELECT distinct ent.FTAXUNITID, t.Fname_l2 as TAXNAME, p.FNUMBER, p.Fname_l2 as PERSONNAME ");
- sqlBuf.append(" FROM T_HR_STaxPersonRecordEntry ent ");
- sqlBuf.append(" left join T_HR_TAXUNIT as t on t.fid = ent.FTaxUnitID ");
- sqlBuf.append(" left join T_BD_PERSON as p on p.fid = ent.FPersonId ");
- sqlBuf.append(" where ent.FSubmitStatus='2' and ent.FPersonStatus='1' ");
- sqlBuf.append(" and ent.FTaxUnitID='").append(taxUnitId).append("'");
- sqlBuf.append(" and ent.FENDDATE <=").append(this.getSqlDateFilterLqDate(yearMonth));
- sqlBuf.append(" and ent.FPersonID not in ( ").append(sql).append(" )");
- return sqlBuf.toString();
- }
- private Map<String, Object> checkIncomeTaxIssue(Context ctx, List<IncomeTaxDeclarInfo> waitToDeclareList) throws BOSException {
- StringBuilder taxUnitIds = new StringBuilder();
- IncomeTaxDeclarInfo declareInfo;
- for (Iterator i$ = waitToDeclareList.iterator(); i$.hasNext(); taxUnitIds.append(declareInfo.getTaxUnit().getId().toString())) {
- declareInfo = (IncomeTaxDeclarInfo) i$.next();
- if (taxUnitIds.length() > 0) {
- taxUnitIds.append(",");
- }
- }
- String oql = "select person.person.name where taxUnit.id in " + CmpStrUtil.buildInSql(taxUnitIds.toString()) + " and result = " + 1 + " and status = " + 2 + " and inviteStatus = " + 0;
- IncomeTaxIssueCollection collection = IncomeTaxIssueFactory.getLocalInstance(ctx).getIncomeTaxIssueCollection(oql);
- if (collection != null && !collection.isEmpty()) {
- StringBuilder errMsg = new StringBuilder();
- for (int i = 0; i < collection.size() && i != 5; ++i) {
- if (errMsg.length() > 0) {
- errMsg.append(",");
- }
- errMsg.append("[").append(collection.get(i).getPerson().getPerson().getName()).append("]");
- }
- Map<String, Object> map = new HashMap();
- map.put("errMsg", "以下员工存在申诉属实争议,且未进行邀请确认,需要进行发送邀请确认后才可进行个税申报或者进行非正常人员报送(更新人员报税信息中的人员状态为非正常,并进行人员报送成功),员工姓名:" + errMsg.toString() + ",选择[是]则跳转到[申诉争议-申诉属实人员]列表,选择[否]则跳转到[人员报税信息]列表。");
- map.put("issueError", true);
- return map;
- } else {
- return null;
- }
- }
- private String checkTaxCalStatus(Context ctx, List<IncomeTaxDeclarInfo> waitToDeclareList) throws SHRWebException {
- String sql = "select t.fState, u.fName_l2 taxUnitName, d.fIncomeItemId from t_hr_sTaxCalConfigDetail d left join t_hr_sTaxCalInitDetail t on d.fCmpCalTableId = t.fCmpCalTableId and d.fIncomeItemId = t.fIncomeItemId left join t_hr_taxUnit u on d.fTaxUnitId = u.fid where d.fTaxUnitId = ? and d.fPeriodBegin = ?";
- try {
- Iterator i$ = waitToDeclareList.iterator();
- boolean isTaxCalFinished;
- String taxUnitName;
- do {
- if (!i$.hasNext()) {
- return null;
- }
- IncomeTaxDeclarInfo declareInfo = (IncomeTaxDeclarInfo) i$.next();
- String taxUnitId = declareInfo.getTaxUnit().getId().toString();
- Date periodDate = declareInfo.getYearMonthDate();
- Object[] param = new Object[]{taxUnitId, CmpDateUtil.toSqlDate(periodDate)};
- IRowSet rs = DbUtil.executeQuery(ctx, sql, param);
- boolean havingSalaryIncome = false;
- isTaxCalFinished = true;
- taxUnitName = "";
- while (rs.next()) {
- int state = rs.getInt("fState");
- taxUnitName = rs.getString("taxUnitName");
- String incomeItemId = rs.getString("fIncomeItemId");
- if (state != 40) {
- isTaxCalFinished = false;
- }
- if ("8r0AAABCg2PDiOoP".equals(incomeItemId)) {
- havingSalaryIncome = true;
- }
- }
- TbTypeEnum typeEnum = declareInfo.getTbType();
- if (!havingSalaryIncome && typeEnum == TbTypeEnum.SB0701) {
- return "纳税单位[" + taxUnitName + "]当期预扣预缴申报表未包含所得项目为正常工资薪金所得的员工,不允许申报,请确认";
- }
- } while (isTaxCalFinished);
- return "纳税单位【" + taxUnitName + "】存在接口算税未完成的数据,请确认";
- } catch (Exception var15) {
- LOG.error("checkTaxCalStatus error: ", var15);
- throw new SHRWebException(var15.getMessage());
- }
- }
- /**
- * 异常提醒
- *
- * @param advanceDeclareInfo
- * @return
- */
- private String combineError(List<String> advanceDeclareInfo) {
- StringBuilder error = new StringBuilder();
- error.append("以下纳税单位尚未到申报时间,请不要提前申报:");
- Iterator i$ = advanceDeclareInfo.iterator();
- while (i$.hasNext()) {
- String taxUnitInfo = (String) i$.next();
- if (advanceDeclareInfo.indexOf(taxUnitInfo) == 5) {
- error.append("...");
- break;
- }
- if (advanceDeclareInfo.indexOf(taxUnitInfo) > 0) {
- error.append(",");
- }
- String[] arr = taxUnitInfo.split("_");
- error.append(arr[0]).append("【").append(arr[1]).append("】");
- }
- return error.toString();
- }
- /**
- * 获取个税申报审批通过数据
- *
- * @param ctx
- * @param selectedId
- * @return
- * @throws BOSException
- */
- private Map<String, Object> getDeclareData(Context ctx, String selectedId) throws BOSException, JsonProcessingException {
- Map<String, Object> resultMap = new HashMap();
- List<TaxDeclareDTO> declaredList = new ArrayList();
- List<IncomeTaxDeclarInfo> waitToDeclareList = new ArrayList();
- String sqlInString = CmpUtils.spiltToSqlString(selectedId);
- if (StringUtils.isEmpty(sqlInString)) {
- sqlInString = "''";
- }
- String currentYearMonth = CmpDateUtil.getDateStr(new Date(), "yyyy-MM");
- String oqlBuffer = "select id,yearMonth,totalPerson,totalMoney,taxRebate,declareStatus,versionCode,yearMonthDate,tbType,taxUnit.id,taxUnit.name,taxUnit.taxNumber,taxUnit.regNumber,taxUnit.areaCode,taxUnit.declPassword, batchNo where id in ( " + sqlInString + " )";
- LOG.error("getDeclareData----------oqlBuffer------" + oqlBuffer);
- IncomeTaxDeclarCollection declareCollection = IncomeTaxDeclarFactory.getLocalInstance(ctx).getIncomeTaxDeclarCollection(oqlBuffer);
- LOG.error("getDeclareData----------declareCollection------" + declareCollection.size());
- String ms1 = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label137", ctx.getLocale());
- String ms2 = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label138", ctx.getLocale());
- String ms3 = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label139", ctx.getLocale());
- List<String> taxUnitInfo = new ArrayList();
- if (declareCollection != null && declareCollection.size() > 0) {
- for (int i = 0; i < declareCollection.size(); ++i) {
- IncomeTaxDeclarInfo declareInfo = declareCollection.get(i);
- String declareStatus = declareInfo.getDeclareStatus().getValue();
- LOG.error("getDeclareData----------declareStatus------" + declareStatus);
- String taxUnitName = declareInfo.getTaxUnit().getName();
- String tbTypeAlia = declareInfo.getTbType().getAlias();
- if (currentYearMonth.compareTo(declareInfo.getYearMonth()) <= 0) {
- taxUnitInfo.add(declareInfo.getTaxUnit().getName() + "_" + declareInfo.getYearMonth());
- }
- if (!"1".equals(declareStatus) && !"2".equals(declareStatus)) {
- waitToDeclareList.add(declareInfo);
- LOG.error("getDeclareData----------waitToDeclareList------" + waitToDeclareList);
- } else {
- TaxDeclareDTO dto = new TaxDeclareDTO(taxUnitName, tbTypeAlia);
- declaredList.add(dto);
- }
- }
- if (declaredList.size() == declareCollection.size()) {
- resultMap.put("info", ms1);
- } else if (declaredList.size() == 0) {
- resultMap.put("info", ms2);
- } else {
- resultMap.put("info", ms3);
- }
- }
- LOG.error("getDeclareData----------resultMap------" + resultMap);
- resultMap.put("DECLARED", declaredList);
- resultMap.put("advanceDeclareInfo", taxUnitInfo);
- resultMap.put("WATI_TO_DECLARE", waitToDeclareList);
- return resultMap;
- }
- }
|