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;
}
}
......@@ -6,18 +6,18 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="is_default" jdbcType="INTEGER" property="isDefault" />
<result column="period" jdbcType="INTEGER" property="period" />
<result column="group_name" jdbcType="VARCHAR" property="groupName" />
<result column="tax_base" jdbcType="VARCHAR" property="taxBase" />
<result column="tax_rate" jdbcType="DECIMAL" property="taxRate" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="tax_rule_setting_id" jdbcType="BIGINT" property="taxRuleSettingId" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="is_default" jdbcType="INTEGER" property="isDefault"/>
<result column="period" jdbcType="INTEGER" property="period"/>
<result column="group_name" jdbcType="VARCHAR" property="groupName"/>
<result column="tax_base" jdbcType="VARCHAR" property="taxBase"/>
<result column="tax_rate" jdbcType="DECIMAL" property="taxRate"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
<result column="tax_rule_setting_id" jdbcType="BIGINT" property="taxRuleSettingId"/>
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
</resultMap>
<sql id="Example_Where_Clause">
<!--
......@@ -41,7 +41,8 @@
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
<foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem}
</foreach>
</when>
......@@ -74,7 +75,8 @@
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
<foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem}
</foreach>
</when>
......@@ -93,7 +95,8 @@
id, `name`, is_default, period, group_name, tax_base, tax_rate, create_time, update_time,
tax_rule_setting_id, create_by, update_by
</sql>
<select id="selectByExample" parameterType="pwc.taxtech.atms.vat.entity.PeriodTaxRuleSettingExample" resultMap="BaseResultMap">
<select id="selectByExample" parameterType="pwc.taxtech.atms.vat.entity.PeriodTaxRuleSettingExample"
resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
......@@ -102,10 +105,10 @@
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from period_tax_rule_setting
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
......@@ -117,7 +120,7 @@
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from period_tax_rule_setting
where id = #{id,jdbcType=BIGINT}
</select>
......@@ -136,7 +139,7 @@
-->
delete from period_tax_rule_setting
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
</delete>
<insert id="insert" parameterType="pwc.taxtech.atms.vat.entity.PeriodTaxRuleSetting">
......@@ -238,14 +241,15 @@
</if>
</trim>
</insert>
<select id="countByExample" parameterType="pwc.taxtech.atms.vat.entity.PeriodTaxRuleSettingExample" resultType="java.lang.Long">
<select id="countByExample" parameterType="pwc.taxtech.atms.vat.entity.PeriodTaxRuleSettingExample"
resultType="java.lang.Long">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select count(*) from period_tax_rule_setting
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
......@@ -293,7 +297,7 @@
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByExample" parameterType="map">
......@@ -315,7 +319,7 @@
create_by = #{record.createBy,jdbcType=VARCHAR},
update_by = #{record.updateBy,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="pwc.taxtech.atms.vat.entity.PeriodTaxRuleSetting">
......@@ -380,7 +384,8 @@
update_by = #{updateBy,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<select id="selectByExampleWithRowbounds" parameterType="pwc.taxtech.atms.vat.entity.PeriodTaxRuleSettingExample" resultMap="BaseResultMap">
<select id="selectByExampleWithRowbounds" parameterType="pwc.taxtech.atms.vat.entity.PeriodTaxRuleSettingExample"
resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
......@@ -389,13 +394,26 @@
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from period_tax_rule_setting
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="getTaxRuleSetting" resultMap="BaseResultMap">
SELECT
trs.is_default as is_default,
trs.tax_base as tax_base,
trs.tax_rate as tax_rate
FROM period_tax_rule_setting trs
LEFT JOIN period_tax_rule_setting_organization trso
ON trs.tax_rule_setting_id = trso.tax_setting_id
WHERE (trs.is_default = 1
OR trso.organization_id = #{organizationId,jdbcType=VARCHAR})
AND trs.name = #{taxName,jdbcType=VARCHAR}
AND trs.period = #{period,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
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