Commit eb5daca4 authored by frank.xa.zhang's avatar frank.xa.zhang

add function JXFP code, need debug later

parent 246ab479
......@@ -9,6 +9,7 @@ import pwc.taxtech.atms.dao.ProjectServiceTypeMapper;
import pwc.taxtech.atms.dao.dao.ProjectDao;
import pwc.taxtech.atms.service.impl.DistributedIDService;
import pwc.taxtech.atms.vat.dao.*;
import pwc.taxtech.atms.vat.dao.dao.InputVatInvoiceDao;
import pwc.taxtech.atms.vat.dao.dao.VatEnterpriseAccountDao;
//用来获取spring托管的bean
......@@ -37,6 +38,7 @@ public class SpringContextUtil implements ApplicationContextAware {
public static BalanceStdManualMapper balanceStdManualMapper;
public static OutputVATInvoiceMapper outputVATInvoiceMapper;
public static PeriodTaxRuleSettingMapper periodTaxRuleSettingMapper;
public static InputVatInvoiceDao inputVatInvoiceDao;
/**
......@@ -73,5 +75,6 @@ public class SpringContextUtil implements ApplicationContextAware {
balanceStdManualMapper = webApplicationContext.getBean(BalanceStdManualMapper.class);
outputVATInvoiceMapper = webApplicationContext.getBean(OutputVATInvoiceMapper.class);
periodTaxRuleSettingMapper = webApplicationContext.getBean(PeriodTaxRuleSettingMapper.class);
inputVatInvoiceDao = webApplicationContext.getBean(InputVatInvoiceDao.class);
}
}
......@@ -63,4 +63,10 @@ public final class Constant {
public static final short Yes = 1;
public static final short No = 0;
}
public static class InputInvoiceCertificationResult {
public static String CheckPass = "勾选认证";
public static String ScanPass = "扫描认证";
public static String NotPass = "未认证";
}
}
\ No newline at end of file
......@@ -3,8 +3,9 @@ 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);
FormulaDataSourceDto(2, pwc.taxtech.atms.dto.vatdto.FormulaDataSourceDto.class),
InputInvoiceDataSourceDto(3, pwc.taxtech.atms.dto.vatdto.FormulaDataSourceDto.class),
OutputInvoiceDataSourceDto(4, pwc.taxtech.atms.dto.vatdto.OutputInvoiceDataSourceDto.class);
private Integer code;
......
package pwc.taxtech.atms.dto.vatdto;
import lombok.Getter;
import lombok.Setter;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceType;
import java.math.BigDecimal;
import java.util.Date;
@Setter
@Getter
public class InputInvoiceDataSourceDto extends FormulaDataSourceDto {
public InputInvoiceDataSourceDto() {
super();
this.setType(FormulaDataSourceType.InputInvoice.getCode());
}
public int Period;
public Date certificationDate;
public String sellerTaxNumber;
public String invoiceCode;
public String invoiceNumber;
public BigDecimal taxAmount;
public int invoiceType;
}
package pwc.taxtech.atms.vat.dao.dao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.vat.dao.InputVATInvoiceMapper;
import pwc.taxtech.atms.vat.entity.InputVATInvoice;
import pwc.taxtech.atms.vat.entity.InputVATInvoiceExample;
import java.util.List;
@Service
public class InputVatInvoiceDao {
@Autowired
InputVATInvoiceMapper inputVATInvoiceMapper;
public List<InputVATInvoice> getInputVATInvoice(Integer period, Integer invoiceType, String checkPass, String scanPass,String notPass) {
InputVATInvoiceExample example = new InputVATInvoiceExample();
InputVATInvoiceExample.Criteria criteria = example.createCriteria();
InputVATInvoiceExample.Criteria criteria1 = example.createCriteria();
if (period != null) {
criteria.andPeriodIDEqualTo(period);
criteria1.andPeriodIDEqualTo(period);
}
if (invoiceType != null) {
criteria.andInvoiceTypeEqualTo(invoiceType);
criteria1.andInvoiceTypeEqualTo(invoiceType);
}
if(StringUtils.isNotBlank(notPass)){
criteria.andCertificationResultEqualTo(notPass);
criteria1.andCertificationResultEqualTo(notPass);
}
else if(StringUtils.isNotBlank(checkPass)&&StringUtils.isNotBlank(scanPass)){
criteria.andCertificationResultEqualTo(checkPass);
criteria.andCertificationResultEqualTo(scanPass);
example.or(criteria1);
}
return inputVATInvoiceMapper.selectByExample(example);
}
}
......@@ -101,8 +101,6 @@ public class GZSD extends FunctionBase implements FreeRefFunction {
//return new NumberEval(matchedRule.get().getTaxBase());
}
return null;
}
}
package pwc.taxtech.atms.vat.service.impl.report.functions;
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.KeyValueConfigResultType;
import pwc.taxtech.atms.dto.vatdto.InputInvoiceDataSourceDto;
import pwc.taxtech.atms.vat.entity.InputVATInvoice;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/// <summary>
/// 名称:本期/前期认证相符且本期申报抵扣
/// 功能:从导入进项发票明细清单取数
/// 备注:取值表格:进项明细清单
/// 条件字段:
/// 认证期间:"0"当期,"-99"前期(当月之前所有月份,不含当月),"99"所有认证期间
/// 发票类型:“1”增值税专票,“2”货运发票,“3”机动车发票,“4”农产品发票,“5”其他发票(包括空值);
/// 认证结果(认证通过,认证未通过,未认证)
/// 取值字段:金额,税额,份数
/// 在导入进项发票时会去检查是否有重复导入发票现象,不允许重复导入,从而杜绝重复抵扣。
/// </summary>
/// <param name="certificationPeriod">认证期间:“0”当期(当月),“-99”前期(当月之前所有月份,不含当月),"99"所有认证期间</param>
/// <param name="invoiceType">“1”增值税专票,“2”货运发票,“3”机动车发票,“4”农产品发票,“5”其他发票(包括空值)</param>
/// <param name="authenticationType">认证结果:“1”认证通过;“0”认证未通过;“2”未认证</param>
/// <param name="resultType">计算取值:“0”金额;“1”税额;“2”份数;</param>
/// <param name="period">会计期间——“0”当期,1-12为自然月</param>
/// <returns></returns>
public class JXFP extends FunctionBase implements FreeRefFunction {
public JXFP(FormulaContext formulaContext) {
super(formulaContext);
}
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
if (args.length < 5) {
return null;
}
int certificationPeriod = getIntParam(args[0], ec);
int invoiceType = getIntParam(args[1], ec);
int authenticationType = getIntParam(args[2], ec);
int resultType = getIntParam(args[3], ec);
int period = getIntParam(args[3], ec);
String formulaExpression = "JXFP(" + certificationPeriod + "," + invoiceType + ","
+ authenticationType + "," + resultType + "," + period + ")";
logger.debug(formulaExpression);
int[] yearOffset = {};
certificationPeriod = getPeriod(certificationPeriod, yearOffset);
if (yearOffset[0] < 0) {
return null;
}
period = getPeriod(period, yearOffset);
if (yearOffset[0] < 0) {
return null;
}
Calendar calendar = Calendar.getInstance();
calendar.set(formulaContext.getYear(), 1, 1);
Date startDate = calendar.getTime();
calendar.add(Calendar.YEAR, 1);
Date endDate = calendar.getTime();
List<InputVATInvoice> inputVATInvoices;
if (authenticationType == 1 && formulaContext.getIsYear()) {
inputVATInvoices = SpringContextUtil.inputVatInvoiceDao.getInputVATInvoice(null, invoiceType,
Constant.InputInvoiceCertificationResult.CheckPass, Constant.InputInvoiceCertificationResult.ScanPass,
null);
} else if (authenticationType == 1) {
inputVATInvoices = SpringContextUtil.inputVatInvoiceDao.getInputVATInvoice(period, invoiceType,
Constant.InputInvoiceCertificationResult.CheckPass, Constant.InputInvoiceCertificationResult.ScanPass,
null);
}
// 认证未通过与未认证暂认为是同一个意思
else if ((authenticationType == 1 || authenticationType == 2) && formulaContext.getIsYear()) {
inputVATInvoices = SpringContextUtil.inputVatInvoiceDao.getInputVATInvoice(null, invoiceType,
null, null, Constant.InputInvoiceCertificationResult.NotPass);
}
// 认证未通过与未认证暂认为是同一个意思
else if (authenticationType == 0 || authenticationType == 2) {
inputVATInvoices = SpringContextUtil.inputVatInvoiceDao.getInputVATInvoice(period, invoiceType, null,
null, Constant.InputInvoiceCertificationResult.NotPass);
} else {
return null;
}
if (certificationPeriod != -99 && certificationPeriod != 99
&& (certificationPeriod < 1 || certificationPeriod > 12)) {
return null;
} else if (!formulaContext.getIsYear()) {
if (certificationPeriod == -99) {
calendar.set(formulaContext.getYear(), formulaContext.getPeriod(), 1);
endDate = calendar.getTime();
Date finalEndDate = endDate;
inputVATInvoices = inputVATInvoices.stream()
.filter(a -> a.getCertificationDate().before(finalEndDate))
.collect(Collectors.toList());
} else if (certificationPeriod != 99) {
calendar.set(formulaContext.getYear(), certificationPeriod, 1);
startDate = calendar.getTime();
calendar.set(formulaContext.getYear(), certificationPeriod, 1);
calendar.add(Calendar.MONTH, 1);
endDate = calendar.getTime();
Date finalEndDate1 = endDate;
Date finalStartDate = startDate;
inputVATInvoices = inputVATInvoices.stream()
.filter(a -> a.getCertificationDate().after(finalStartDate)
&& a.getCertificationDate().before(finalEndDate1))
.collect(Collectors.toList());
}
}
List<InputInvoiceDataSourceDto> dataSource = new ArrayList();
for (InputVATInvoice x : inputVATInvoices) {
InputInvoiceDataSourceDto inputInvoiceDataSourceDto = new InputInvoiceDataSourceDto();
inputInvoiceDataSourceDto.setAmount(FormulaHelper.roundValue(x.getAmount(), KeyValueConfigResultType.Accounting,
null, formulaContext));
inputInvoiceDataSourceDto.setResultType(KeyValueConfigResultType.Accounting.getCode());
inputInvoiceDataSourceDto.setTaxAmount(FormulaHelper.roundValue(x.getTaxAmount(), KeyValueConfigResultType.Accounting,
null, formulaContext));
inputInvoiceDataSourceDto.setCertificationDate(x.getCertificationDate());
inputInvoiceDataSourceDto.setInvoiceCode(x.getInvoiceCode());
inputInvoiceDataSourceDto.setInvoiceNumber(x.getInvoiceNumber());
inputInvoiceDataSourceDto.setInvoiceType(x.getInvoiceType());
inputInvoiceDataSourceDto.setPeriod(x.getPeriodID());
inputInvoiceDataSourceDto.setSellerTaxNumber(x.getSellerTaxNumber());
inputInvoiceDataSourceDto.setName(Constant.DataSourceName.InputDetailInvoiceDataSource);
inputInvoiceDataSourceDto.setOperationType(EnumOperationType.Single.getCode());
dataSource.add(inputInvoiceDataSourceDto);
}
dataSource = dataSource.stream()
.sorted(Comparator.comparing(InputInvoiceDataSourceDto::getCertificationDate)
.thenComparing(InputInvoiceDataSourceDto::getInvoiceCode)
.thenComparing(InputInvoiceDataSourceDto::getInvoiceNumber))
.collect(Collectors.toList());
if (resultType == 0) {
double val = dataSource.stream().mapToDouble(a -> a.getAmount().doubleValue()).sum();
Long dataSourceId = saveDataSource(ec, Collections.singletonList(dataSource), FormulaDataSourceDetailType.InputInvoiceDataSourceDto, BigDecimal.valueOf(val));
saveFormulaBlock(period, ec, formulaExpression, BigDecimal.valueOf(val), dataSourceId);
return new NumberEval(val);
} else if (resultType == 1) {
double val = dataSource.stream().mapToDouble(a -> a.getTaxAmount().doubleValue()).sum();
Long dataSourceId = saveDataSource(ec, Collections.singletonList(dataSource), FormulaDataSourceDetailType.InputInvoiceDataSourceDto, BigDecimal.valueOf(val));
saveFormulaBlock(period, ec, formulaExpression, BigDecimal.valueOf(val), dataSourceId);
return new NumberEval(val);
} else if (resultType == 2) {
double val = dataSource.size();
Long dataSourceId = saveDataSource(ec, Collections.singletonList(dataSource), FormulaDataSourceDetailType.InputInvoiceDataSourceDto, BigDecimal.valueOf(val));
saveFormulaBlock(period, ec, formulaExpression, BigDecimal.valueOf(val), dataSourceId);
return new NumberEval(val);
}
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