Commit 246ab479 authored by frank.xa.zhang's avatar frank.xa.zhang

add function GZSD code, need debug later,

some logic didn't finished yet ,   need make a solution for the keyValue function handle
parent c55b5c98
......@@ -36,6 +36,7 @@ public class SpringContextUtil implements ApplicationContextAware {
public static VatEnterpriseAccountMapper vatEnterpriseAccountMapper;
public static BalanceStdManualMapper balanceStdManualMapper;
public static OutputVATInvoiceMapper outputVATInvoiceMapper;
public static PeriodTaxRuleSettingMapper periodTaxRuleSettingMapper;
/**
......@@ -71,5 +72,6 @@ public class SpringContextUtil implements ApplicationContextAware {
vatEnterpriseAccountMapper = webApplicationContext.getBean(VatEnterpriseAccountMapper.class);
balanceStdManualMapper = webApplicationContext.getBean(BalanceStdManualMapper.class);
outputVATInvoiceMapper = webApplicationContext.getBean(OutputVATInvoiceMapper.class);
periodTaxRuleSettingMapper = webApplicationContext.getBean(PeriodTaxRuleSettingMapper.class);
}
}
......@@ -58,4 +58,9 @@ public final class Constant {
public static final String UnbilledDataSource = "UnbilledDataSource";
public static final String AssetListDataSource = "AssetListDataSource";
}
public static class IsDefault {
public static final short Yes = 1;
public static final short No = 0;
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package pwc.taxtech.atms.constant.enums;
public enum FormulaDataSourceDetailType {
BSPLFormulaDataSourceDto(1, pwc.taxtech.atms.dto.vatdto.BSPLFormulaDataSourceDto.class),
FormulaDataSourceDto(1, pwc.taxtech.atms.dto.vatdto.FormulaDataSourceDto.class),
OutputInvoiceDataSourceDto(1, pwc.taxtech.atms.dto.vatdto.OutputInvoiceDataSourceDto.class);
......
package pwc.taxtech.atms.vat.dao;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
......@@ -105,4 +106,6 @@ public interface PeriodTaxRuleSettingMapper extends MyVatMapper {
* @mbg.generated
*/
int updateByPrimaryKey(PeriodTaxRuleSetting record);
List<PeriodTaxRuleSetting> getTaxRuleSetting(@Param("organizationId") String organizationId, @Param("taxName") String taxName, @Param("period") int period);
}
\ No newline at end of file
package pwc.taxtech.atms.vat.service.impl.report.functions;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.Constant;
import pwc.taxtech.atms.constant.enums.EnumOperationType;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceType;
import pwc.taxtech.atms.constant.enums.KeyValueConfigResultType;
import pwc.taxtech.atms.dto.vatdto.FormulaDataSourceDto;
import pwc.taxtech.atms.vat.entity.PeriodTaxRuleSetting;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
/// <summary>
/// 名称:rule engine 中取值(规则设定)
/// 功能:附加税报表中参数取值
/// 备注:申报表取值时首先判断机构是否是特殊情况,及机构名称是否出现在特殊情况中,若没有出现在特殊情况中,则取默认税率和税基;
/// </summary>
/// <param name="taxCategory">税(费)种——“1”城市维护建设税;“2” 教育费附加;“3”地方教育附加;“4”印花税;“5”水利基金;</param>
/// <param name="resultType">“0”一般计税依据(税基),“1” 税率;</param>
/// <returns></returns>
public class GZSD extends FunctionBase implements FreeRefFunction {
public GZSD(FormulaContext formulaContext) {
super(formulaContext);
}
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
if (args.length < 2) {
return null;
}
Integer taxCategory = getIntParam(args[0], ec);
Integer resultType = getIntParam(args[1], ec);
String formulaExpression = "GZSD(" + taxCategory + "," + resultType + ")";
logger.debug(formulaExpression);
String taxName = StringUtils.EMPTY;
switch (taxCategory) {
case 1:
taxName = "城市维护建设税";
break;
case 2:
taxName = "教育费附加";
break;
case 3:
taxName = "地方教育费附加";
break;
case 4:
taxName = "印花税";
break;
case 5:
taxName = "水利基金";
break;
default:
break;
}
List<PeriodTaxRuleSetting> taxRuleSettings =
SpringContextUtil.periodTaxRuleSettingMapper.getTaxRuleSetting(formulaContext.getOrganizationID(),
taxName, formulaContext.getPeriod());
Optional<PeriodTaxRuleSetting> matchedRule = taxRuleSettings.stream().filter(a -> a.getIsDefault() != Constant.IsDefault.Yes).findFirst();
if (!matchedRule.isPresent()) {
matchedRule = Optional.ofNullable(taxRuleSettings.get(0));
if (matchedRule.isPresent()) {
return null;
}
}
if (resultType == 1) {
BigDecimal val = FormulaHelper.roundValue(matchedRule.get().getTaxRate(),
KeyValueConfigResultType.Percentage, null, formulaContext);
NumberFormat nf = NumberFormat.getPercentInstance();
nf.setMaximumFractionDigits(2);
List<FormulaDataSourceDto> dataSourceDtoList = new ArrayList<>();
FormulaDataSourceDto formulaDataSourceDto = new FormulaDataSourceDto();
formulaDataSourceDto.setOperationType(EnumOperationType.Single.getCode());
formulaDataSourceDto.setType(FormulaDataSourceType.Other.getCode());
formulaDataSourceDto.setResultType(KeyValueConfigResultType.Percentage.getCode());
formulaDataSourceDto.setAmount(matchedRule.get().getTaxRate());
formulaDataSourceDto.setName(nf.format(matchedRule.get().getTaxRate()));
dataSourceDtoList.add(formulaDataSourceDto);
Long dataSourceId = saveDataSource(ec, Collections.singletonList(dataSourceDtoList), FormulaDataSourceDetailType.FormulaDataSourceDto, val);
saveFormulaBlock(formulaContext.getPeriod(), ec, formulaExpression, val, dataSourceId);
return new NumberEval(val.doubleValue());
} else {
//todo: @本期应(实)纳税额 ,@GDZC.BQ.QMYE 这种类型的数据,重新计算,按照keyvalue的配置
//return new NumberEval(matchedRule.get().getTaxBase());
}
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment