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

add function XXPF code, need debug later

refactor previous code, make some method as base class public method
parent c8b6338d
......@@ -35,6 +35,7 @@ public class SpringContextUtil implements ApplicationContextAware {
public static VatEnterpriseAccountDao vatEnterpriseAccountDao;
public static VatEnterpriseAccountMapper vatEnterpriseAccountMapper;
public static BalanceStdManualMapper balanceStdManualMapper;
public static OutputVATInvoiceMapper outputVATInvoiceMapper;
/**
......@@ -69,5 +70,6 @@ public class SpringContextUtil implements ApplicationContextAware {
vatEnterpriseAccountDao = webApplicationContext.getBean(VatEnterpriseAccountDao.class);
vatEnterpriseAccountMapper = webApplicationContext.getBean(VatEnterpriseAccountMapper.class);
balanceStdManualMapper = webApplicationContext.getBean(BalanceStdManualMapper.class);
outputVATInvoiceMapper = webApplicationContext.getBean(OutputVATInvoiceMapper.class);
}
}
......@@ -42,4 +42,20 @@ public final class Constant {
public static final String IMAGE_FORMART_ = "png";
public static final String EMPTY = "";
public static class DataSourceName {
public static final String KeyValueDataSource = "KeyValueDataSource";
public static final String InputInvoiceDataSource = "IncomeDataSource";
public static final String InputDetailInvoiceDataSource = "IncomeDetailDataSource";
public static final String OutputInvoiceDataSource = "OutputInvoiceDataSource";
public static final String VoucherDataSource = "VoucherDataSource";
public static final String ReportDataSource = "ReportDataSource";
public static final String ConditionDataSource = "ConditionDataSource";
public static final String MinConditionDataSource = "MinConditionDataSource";
public static final String MaxConditionDataSource = "MaxConditionDataSource";
public static final String SAPDataSource = "SAPDataSource";
public static final String LandSellDataSource = "LandSellDataSource";
public static final String UnbilledDataSource = "UnbilledDataSource";
public static final String AssetListDataSource = "AssetListDataSource";
}
}
\ No newline at end of file
package pwc.taxtech.atms.constant.enums;
public enum EnumOperationType {
Single(0),
Add(1),
Sub(2),
Mul(3),
Div(4);
private Integer code;
EnumOperationType(Integer code) {
this.code = code;
}
public Integer getCode() {
return code;
}
}
......@@ -2,7 +2,8 @@ package pwc.taxtech.atms.constant.enums;
public enum FormulaDataSourceDetailType {
BSPLFormulaDataSourceDto(1, pwc.taxtech.atms.dto.vatdto.BSPLFormulaDataSourceDto.class);
BSPLFormulaDataSourceDto(1, pwc.taxtech.atms.dto.vatdto.BSPLFormulaDataSourceDto.class),
OutputInvoiceDataSourceDto(1, pwc.taxtech.atms.dto.vatdto.OutputInvoiceDataSourceDto.class);
private Integer code;
......
......@@ -24,7 +24,7 @@ public class DataSourceDto {
// 1: Formula, 2: Voucher, 3: OutputInvoice, 4: InputInvoice, 5: CustomInvoice, 6: KeyIn, 7: RelatedModel, 8: SapDaily
Integer dataSourceType;
BigDecimal amount;
private BigDecimal amount;
String description;
// 1: +, 2: -, 3: *, 4: /
......
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;
@Getter
@Setter
public class OutputInvoiceDataSourceDto extends FormulaDataSourceDto {
public OutputInvoiceDataSourceDto() {
super();
this.setType(FormulaDataSourceType.OutputInvoice.getCode());
}
private Long id;
private int period;
private Date invoiceDate;
private String buyerName;
private String invoiceCode;
private String invoiceNumber;
private BigDecimal taxRate;
private BigDecimal taxAmount;
private Integer invoiceType;
private String dataSourceId;
//数据源名称
private String dataSourceName;
}
package pwc.taxtech.atms.dto.vatdto;
import lombok.Getter;
import lombok.Setter;
import pwc.taxtech.atms.vat.entity.OutputVATInvoice;
import pwc.taxtech.atms.vat.entity.OutputVATInvoiceItem;
@Getter
@Setter
public class OutputVATInvoiceDto {
private String invoiceID;
private OutputVATInvoice invoice;
private OutputVATInvoiceItem invoiceItem;
}
......@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.RowBounds;
import pwc.taxtech.atms.MyVatMapper;
import pwc.taxtech.atms.dto.vatdto.OutputVATInvoiceDto;
import pwc.taxtech.atms.dto.vatdto.OutputVATInvoiceInfoDto;
import pwc.taxtech.atms.dto.vatdto.QueryOutputDto;
import pwc.taxtech.atms.vat.entity.OutputVATInvoice;
......@@ -181,4 +182,6 @@ public interface OutputVATInvoiceMapper extends MyVatMapper {
" AND o.PeriodID = #{period}" +
" ")
List<OutputVATInvoiceInfoDto> queryOutputDetailWithItem(Integer period);
List<OutputVATInvoiceDto> getVatInvoiceWithItems(String dbName);
}
\ No newline at end of file
......@@ -26,11 +26,7 @@ import pwc.taxtech.atms.dto.vatdto.PeriodCellTemplateConfigExtendDto;
import pwc.taxtech.atms.entitiy.Project;
import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.service.ReportGenerator;
import pwc.taxtech.atms.vat.service.impl.report.functions.BB;
import pwc.taxtech.atms.vat.service.impl.report.functions.FSJZ;
import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaContext;
import pwc.taxtech.atms.vat.service.impl.report.functions.ND;
import pwc.taxtech.atms.vat.service.impl.report.functions.SGSR;
import pwc.taxtech.atms.vat.service.impl.report.functions.*;
import java.io.File;
import java.io.FileNotFoundException;
......@@ -281,9 +277,9 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
* @param workbook 工作簿
*/
private void addFunctionsToWorkbook(Workbook workbook, FormulaContext formulaContext) {
String[] functionNames = {"SGSR", "FSJZ", "ND", "BB"};
String[] functionNames = {"SGSR", "FSJZ", "ND", "BB","XXFP"};
FreeRefFunction[] functionImpls = {new SGSR(formulaContext), new FSJZ(formulaContext), new ND(formulaContext),
new BB(formulaContext)};
new BB(formulaContext),new XXFP(formulaContext)};
UDFFinder udfs = new DefaultUDFFinder(functionNames, functionImpls);
UDFFinder udfToolpack = new AggregatingUDFFinder(udfs);
workbook.addToolPack(udfToolpack);
......
package pwc.taxtech.atms.vat.service.impl.report.functions;
import com.alibaba.fastjson.JSON;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
......@@ -9,8 +8,10 @@ import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.constant.enums.KeyValueConfigResultType;
import pwc.taxtech.atms.dto.vatdto.BSPLFormulaDataSourceDto;
import pwc.taxtech.atms.dto.vatdto.FormulaDataSourceDto;
import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.entity.Balance;
import pwc.taxtech.atms.vat.entity.BalanceStdManual;
import pwc.taxtech.atms.vat.entity.VatEnterpriseAccount;
import pwc.taxtech.atms.vat.entity.VatStandardAccount;
import java.math.BigDecimal;
import java.util.ArrayList;
......@@ -90,7 +91,7 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
}
BigDecimal val = new BigDecimal(0);
List<FormulaDataSourceDto> formulaDataSourceDtoList = new ArrayList<>();
List<Object> formulaDataSourceDtoList = new ArrayList<>();
if (balanceStdManual != null) {
List<VatEnterpriseAccount> vatEnterpriseAccountList = SpringContextUtil
.vatEnterpriseAccountMapper
......@@ -132,49 +133,9 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
}
//todo: sava data
//save datasource
DataSource dataSource = new DataSource();
Long dataSourceID = SpringContextUtil.distributedIDService.nextId();
dataSource.setId(dataSourceID);
dataSource.setType(1);
dataSource.setName("ReportDataSource");
dataSource.setAmount(val);
dataSource.setDescription("");
dataSource.setCreateBy("Admin");
dataSource.setUpdateBy("Admin");
dataSource.setCreateTime(creatime);
dataSource.setUpdateTime(creatime);
dataSource.setRowIndex(ec.getRowIndex());
dataSource.setColumnIndex(ec.getColumnIndex());
dataSource.setRowName("");
dataSource.setColumnName("");
SpringContextUtil.dataSourceMapper.insertSelective(dataSource);
for (FormulaDataSourceDto aFormulaDataSourceDtoList : formulaDataSourceDtoList) {
BSPLFormulaDataSourceDto bsplFormulaDataSourceDto = ((BSPLFormulaDataSourceDto) aFormulaDataSourceDtoList);
DataSourceDetail dataSourceDetail = new DataSourceDetail();
dataSourceDetail.setId(SpringContextUtil.distributedIDService.nextId());
dataSourceDetail.setDataSourceId(dataSourceID);
dataSourceDetail.setDataSourceType(FormulaDataSourceDetailType.BSPLFormulaDataSourceDto.getCode());
dataSourceDetail.setItemValue(JSON.toJSONString(bsplFormulaDataSourceDto));
SpringContextUtil.dataSourceDetailMapper.insertSelective(dataSourceDetail);
}
Long dataSourceID = saveDataSource(ec, formulaDataSourceDtoList, FormulaDataSourceDetailType.BSPLFormulaDataSourceDto, val);
//save formulablock
Long cellTemplateID = getCellTemplateID(period, ec);
PeriodFormulaBlock periodFormulaBlock = new PeriodFormulaBlock();
periodFormulaBlock.setId(SpringContextUtil.distributedIDService.nextId());
periodFormulaBlock.setPeriod(period);
periodFormulaBlock.setReportId(0L);
periodFormulaBlock.setCellTemplateId(cellTemplateID);
periodFormulaBlock.setFormulaExpression(formulaExpression);
periodFormulaBlock.setData(val.toString());
periodFormulaBlock.setDataSourceId(dataSourceID);
periodFormulaBlock.setCreateBy("Admin");
periodFormulaBlock.setCreateTime(creatime);
periodFormulaBlock.setUpdateBy("Admin");
periodFormulaBlock.setUpdateTime(creatime);
SpringContextUtil.periodFormulaBlockMapper.insertSelective(periodFormulaBlock);
saveFormulaBlock(period, ec, formulaExpression, val, dataSourceID);
return new NumberEval(val.doubleValue());
} else {
......@@ -196,7 +157,7 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
}
BigDecimal val = new BigDecimal(0);
List<FormulaDataSourceDto> dsList = new ArrayList<>();
List<Object> dsList = new ArrayList<>();
if (balance != null) {
if (period == 99) {
val = new BigDecimal(((balance.getYearDebitNet() != null ? balance.getYearDebitNet() : 0).doubleValue()
......@@ -232,51 +193,12 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
? FormulaHelper.roundValue(val, KeyValueConfigResultType.Accounting, null, formulaContext)
: new BigDecimal(0);
}
//todo: sava data
//save datasource
DataSource dataSource = new DataSource();
Long dataSourceID = SpringContextUtil.distributedIDService.nextId();
dataSource.setId(dataSourceID);
dataSource.setType(1);
dataSource.setName("ReportDataSource");
dataSource.setAmount(val);
dataSource.setDescription("");
dataSource.setCreateBy("Admin");
dataSource.setUpdateBy("Admin");
dataSource.setCreateTime(creatime);
dataSource.setUpdateTime(creatime);
dataSource.setRowIndex(ec.getRowIndex());
dataSource.setColumnIndex(ec.getColumnIndex());
dataSource.setRowName("");
dataSource.setColumnName("");
SpringContextUtil.dataSourceMapper.insertSelective(dataSource);
for (FormulaDataSourceDto aFormulaDataSourceDtoList : dsList) {
BSPLFormulaDataSourceDto bsplFormulaDataSourceDto = ((BSPLFormulaDataSourceDto) aFormulaDataSourceDtoList);
DataSourceDetail dataSourceDetail = new DataSourceDetail();
dataSourceDetail.setId(SpringContextUtil.distributedIDService.nextId());
dataSourceDetail.setDataSourceId(dataSourceID);
dataSourceDetail.setDataSourceType(FormulaDataSourceDetailType.BSPLFormulaDataSourceDto.getCode());
dataSourceDetail.setItemValue(JSON.toJSONString(bsplFormulaDataSourceDto));
SpringContextUtil.dataSourceDetailMapper.insertSelective(dataSourceDetail);
}
Long dataSourceID = saveDataSource(ec, dsList, FormulaDataSourceDetailType.BSPLFormulaDataSourceDto, val);
//save formulablock
Long cellTemplateID = getCellTemplateID(period, ec);
PeriodFormulaBlock periodFormulaBlock = new PeriodFormulaBlock();
periodFormulaBlock.setId(SpringContextUtil.distributedIDService.nextId());
periodFormulaBlock.setPeriod(period);
periodFormulaBlock.setReportId(0L);//todo:update reportID when report data generated
periodFormulaBlock.setCellTemplateId(cellTemplateID);
periodFormulaBlock.setFormulaExpression(formulaExpression);
periodFormulaBlock.setData(val.toString());
periodFormulaBlock.setDataSourceId(dataSourceID);
periodFormulaBlock.setCreateBy("Admin");
periodFormulaBlock.setCreateTime(creatime);
periodFormulaBlock.setUpdateBy("Admin");
periodFormulaBlock.setUpdateTime(creatime);
SpringContextUtil.periodFormulaBlockMapper.insertSelective(periodFormulaBlock);
saveFormulaBlock(period, ec, formulaExpression, val, dataSourceID);
return new NumberEval(val.doubleValue());
}
}
......
package pwc.taxtech.atms.vat.service.impl.report.functions;
import com.alibaba.fastjson.JSON;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.vat.entity.DataSource;
import pwc.taxtech.atms.vat.entity.DataSourceDetail;
import pwc.taxtech.atms.vat.entity.PeriodFormulaBlock;
import pwc.taxtech.atms.vat.service.impl.FormulaAgent;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
public class FunctionBase {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
protected FormulaContext formulaContext;
final FormulaAgent agent;
public FunctionBase(FormulaContext formulaContext){
public FunctionBase(FormulaContext formulaContext) {
this.formulaContext = formulaContext;
this.agent = formulaContext.getFormulaAgent();
}
......@@ -43,9 +53,9 @@ public class FunctionBase {
}
}
public Long getCellTemplateID(int period, OperationEvaluationContext ec){
public Long getCellTemplateID(int period, OperationEvaluationContext ec) {
return FormulaHelper
.getCellTemplateIDWithTemplateCodeAndColumnIndexAndRowIndex(ec.getWorkbook().getSheetName(ec.getSheetIndex()),ec.getColumnIndex(),ec.getRowIndex(),period,formulaContext);
.getCellTemplateIDWithTemplateCodeAndColumnIndexAndRowIndex(ec.getWorkbook().getSheetName(ec.getSheetIndex()), ec.getColumnIndex(), ec.getRowIndex(), period, formulaContext);
}
public int getYear(int parameterYear) {
......@@ -58,4 +68,75 @@ public class FunctionBase {
}
}
public int getPeriod(int parameterPeriod, int[] yearOffset) {
if (yearOffset.length == 0) {
yearOffset = new int[10];
}
yearOffset[0] = 0;
if (parameterPeriod == -99) {
return parameterPeriod;
} else if (parameterPeriod <= -1) {
int period = parameterPeriod + formulaContext.getPeriod();
while (period <= 0) {
yearOffset[0]--;
period += 12;
}
return period;
} else if (parameterPeriod == 0) {
return formulaContext.getPeriod();
} else {
return parameterPeriod;
}
}
public Long saveDataSource(OperationEvaluationContext ec, List<Object> dataSourceList,
FormulaDataSourceDetailType formulaDataSourceDetailType, BigDecimal val) {
Date creatime = new Date();
DataSource dataSource = new DataSource();
Long dataSourceID = SpringContextUtil.distributedIDService.nextId();
dataSource.setId(dataSourceID);
dataSource.setType(1);
dataSource.setName("ReportDataSource");
dataSource.setAmount(val);
dataSource.setDescription("");
dataSource.setCreateBy("Admin");
dataSource.setUpdateBy("Admin");
dataSource.setCreateTime(creatime);
dataSource.setUpdateTime(creatime);
dataSource.setRowIndex(ec.getRowIndex());
dataSource.setColumnIndex(ec.getColumnIndex());
dataSource.setRowName("");
dataSource.setColumnName("");
SpringContextUtil.dataSourceMapper.insertSelective(dataSource);
for (Object obj : dataSourceList) {
DataSourceDetail dataSourceDetail = new DataSourceDetail();
dataSourceDetail.setId(SpringContextUtil.distributedIDService.nextId());
dataSourceDetail.setDataSourceId(dataSourceID);
dataSourceDetail.setDataSourceType(formulaDataSourceDetailType.getCode());
dataSourceDetail.setItemValue(JSON.toJSONString(obj));
SpringContextUtil.dataSourceDetailMapper.insertSelective(dataSourceDetail);
}
return dataSourceID;
}
public void saveFormulaBlock(int period, OperationEvaluationContext ec,
String formulaExpression, BigDecimal val, Long dataSourceID) {
Long cellTemplateID = getCellTemplateID(period, ec);
Date creatime = new Date();
PeriodFormulaBlock periodFormulaBlock = new PeriodFormulaBlock();
periodFormulaBlock.setId(SpringContextUtil.distributedIDService.nextId());
periodFormulaBlock.setPeriod(period);
periodFormulaBlock.setReportId(0L);
periodFormulaBlock.setCellTemplateId(cellTemplateID);
periodFormulaBlock.setFormulaExpression(formulaExpression);
periodFormulaBlock.setData(val.toString());
periodFormulaBlock.setDataSourceId(dataSourceID);
periodFormulaBlock.setCreateBy("Admin");
periodFormulaBlock.setCreateTime(creatime);
periodFormulaBlock.setUpdateBy("Admin");
periodFormulaBlock.setUpdateTime(creatime);
SpringContextUtil.periodFormulaBlockMapper.insertSelective(periodFormulaBlock);
}
}
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.KeyValueConfigResultType;
import pwc.taxtech.atms.dto.vatdto.OutputInvoiceDataSourceDto;
import pwc.taxtech.atms.dto.vatdto.OutputVATInvoiceDto;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/// <summary>
/// 名称:销项发票
/// 功能:从发票取数,一般取发票金额或税额汇总数
/// </summary>
/// <param name="taxRate">税率取值为17%,13%,11%,6%,5%, 3%,1.5%,若所有税率都取则为99</param>
/// <param name="invoiceType">发票类型——两种取值结果“1”专用发票和“0”除专用发票以外其他发票,若所有发票都取则为99</param>
/// <param name="amountType">取值——两种取值结果“金额”0和“税额”1</param>
/// <param name="period">会计期间(开票日期)——三种取值结果 “-1”指上期,“0”当期,“99”当前累计(从期初到目前)</param>
/// <returns></returns>
public class XXFP extends FunctionBase implements FreeRefFunction {
public XXFP(FormulaContext formulaContext) {
super(formulaContext);
}
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
if (args.length < 4) {
return null;
}
String taxRate = getStringParam(args[0], ec);
int invoiceType = getIntParam(args[1], ec);
int amountType = getIntParam(args[2], ec);
int period = getIntParam(args[3], ec);
String formulaExpression = "XXFP(\"" + taxRate + "\"," + invoiceType + "," + amountType + "," + period + ")";
logger.debug(formulaExpression);
Integer curYear = formulaContext.getYear();
int[] yearOffset = {};
period = getPeriod(period, yearOffset);
curYear = curYear + yearOffset[0];
BigDecimal taxRateVal = new BigDecimal("-1");
if (!taxRate.endsWith("%")) {
if (taxRate.equals("99")) {
taxRateVal = new BigDecimal("99");
} else {
return null;
}
} else {
taxRate = StringUtils.removeEnd(taxRate, "%");
try {
taxRateVal = BigDecimal.valueOf(Double.parseDouble(taxRate));
} catch (NumberFormatException ex) {
return null;
}
taxRateVal = taxRateVal.divide(new BigDecimal("100"), 2, BigDecimal.ROUND_HALF_UP); //保留两位小数,然后四舍五入
}
String dbName = SpringContextUtil.projectDao.getDbNameWithYearAndOrgID(formulaContext.getOrganizationID(), curYear);
List<OutputVATInvoiceDto> outputInvoice = SpringContextUtil.outputVATInvoiceMapper.getVatInvoiceWithItems(dbName);
if (invoiceType != 99) {
outputInvoice = outputInvoice.stream()
.filter(a -> a.getInvoice().getInvoiceType() == invoiceType)
.collect(Collectors.toList());
}
if (taxRateVal.compareTo(new BigDecimal("99")) != 0) {
BigDecimal finalTaxRateVal = taxRateVal;
outputInvoice = outputInvoice.stream()
.filter(a -> a.getInvoiceItem().getTaxRate().compareTo(finalTaxRateVal) == 0)
.collect(Collectors.toList());
}
if (period != 99) {
int finalPeriod = period;
outputInvoice = outputInvoice.stream().filter(a -> a.getInvoice().getPeriodID().equals(finalPeriod)).collect(Collectors.toList());
}
List<OutputInvoiceDataSourceDto> dataSource = new ArrayList();
for (OutputVATInvoiceDto x : outputInvoice) {
OutputInvoiceDataSourceDto outputInvoiceDataSourceDto = new OutputInvoiceDataSourceDto();
outputInvoiceDataSourceDto.setAmount(FormulaHelper.roundValue(x.getInvoiceItem().getAmount(),
KeyValueConfigResultType.Accounting, null, formulaContext));
outputInvoiceDataSourceDto.setResultType(KeyValueConfigResultType.Accounting.getCode());
outputInvoiceDataSourceDto.setTaxAmount(FormulaHelper.roundValue(x.getInvoiceItem().getAmount(),
KeyValueConfigResultType.Accounting, null, formulaContext));
outputInvoiceDataSourceDto.setTaxRate(x.getInvoiceItem().getTaxRate());
outputInvoiceDataSourceDto.setBuyerName(x.getInvoice().getBuyerName());
outputInvoiceDataSourceDto.setInvoiceCode(x.getInvoice().getClassCode());
outputInvoiceDataSourceDto.setInvoiceNumber(x.getInvoice().getInvoiceNumber());
outputInvoiceDataSourceDto.setInvoiceDate(x.getInvoice().getInvoiceDate());
outputInvoiceDataSourceDto.setInvoiceType(x.getInvoice().getInvoiceType());
outputInvoiceDataSourceDto.setPeriod(x.getInvoice().getPeriodID());
outputInvoiceDataSourceDto.setName(Constant.DataSourceName.OutputInvoiceDataSource);
outputInvoiceDataSourceDto.setOperationType(EnumOperationType.Single.getCode());
dataSource.add(outputInvoiceDataSourceDto);
}
if (amountType == 0) {
double val = dataSource.stream().mapToDouble(a -> a.getAmount().doubleValue()).sum();
Long dataSoureId = saveDataSource(ec, Collections.singletonList(dataSource),
FormulaDataSourceDetailType.OutputInvoiceDataSourceDto, new BigDecimal(val));
saveFormulaBlock(period, ec, formulaExpression, new BigDecimal(val), dataSoureId);
return new NumberEval(val);
} else if (amountType == 1) {
double val = dataSource.stream().mapToDouble(a -> a.getTaxAmount().doubleValue()).sum();
Long dataSoureId = saveDataSource(ec, Collections.singletonList(dataSource),
FormulaDataSourceDetailType.OutputInvoiceDataSourceDto, new BigDecimal(val));
saveFormulaBlock(period, ec, formulaExpression, new BigDecimal(val), dataSoureId);
return new NumberEval(val);
}
return null;
}
}
......@@ -6,22 +6,22 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<id column="InvoiceID" jdbcType="VARCHAR" property="invoiceID" />
<result column="InvoiceType" jdbcType="INTEGER" property="invoiceType" />
<result column="ClassCode" jdbcType="VARCHAR" property="classCode" />
<result column="InvoiceNumber" jdbcType="VARCHAR" property="invoiceNumber" />
<result column="BuyerName" jdbcType="VARCHAR" property="buyerName" />
<result column="BuyerTaxNumber" jdbcType="VARCHAR" property="buyerTaxNumber" />
<result column="BankAccount" jdbcType="VARCHAR" property="bankAccount" />
<result column="PhoneNum" jdbcType="VARCHAR" property="phoneNum" />
<result column="InvoiceDate" jdbcType="TIMESTAMP" property="invoiceDate" />
<result column="SeqNo" jdbcType="INTEGER" property="seqNo" />
<result column="PeriodID" jdbcType="INTEGER" property="periodID" />
<result column="Status" jdbcType="INTEGER" property="status" />
<result column="CreatorID" jdbcType="VARCHAR" property="creatorID" />
<result column="CreateTime" jdbcType="TIMESTAMP" property="createTime" />
<result column="PartAccntedPeriod" jdbcType="INTEGER" property="partAccntedPeriod" />
<result column="AccntedPeriod" jdbcType="INTEGER" property="accntedPeriod" />
<id column="InvoiceID" jdbcType="VARCHAR" property="invoiceID"/>
<result column="InvoiceType" jdbcType="INTEGER" property="invoiceType"/>
<result column="ClassCode" jdbcType="VARCHAR" property="classCode"/>
<result column="InvoiceNumber" jdbcType="VARCHAR" property="invoiceNumber"/>
<result column="BuyerName" jdbcType="VARCHAR" property="buyerName"/>
<result column="BuyerTaxNumber" jdbcType="VARCHAR" property="buyerTaxNumber"/>
<result column="BankAccount" jdbcType="VARCHAR" property="bankAccount"/>
<result column="PhoneNum" jdbcType="VARCHAR" property="phoneNum"/>
<result column="InvoiceDate" jdbcType="TIMESTAMP" property="invoiceDate"/>
<result column="SeqNo" jdbcType="INTEGER" property="seqNo"/>
<result column="PeriodID" jdbcType="INTEGER" property="periodID"/>
<result column="Status" jdbcType="INTEGER" property="status"/>
<result column="CreatorID" jdbcType="VARCHAR" property="creatorID"/>
<result column="CreateTime" jdbcType="TIMESTAMP" property="createTime"/>
<result column="PartAccntedPeriod" jdbcType="INTEGER" property="partAccntedPeriod"/>
<result column="AccntedPeriod" jdbcType="INTEGER" property="accntedPeriod"/>
</resultMap>
<sql id="Example_Where_Clause">
<!--
......@@ -45,7 +45,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>
......@@ -78,7 +79,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>
......@@ -98,7 +100,8 @@
PhoneNum, InvoiceDate, SeqNo, PeriodID, `Status`, CreatorID, CreateTime, PartAccntedPeriod,
AccntedPeriod
</sql>
<select id="selectByExample" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoiceExample" resultMap="BaseResultMap">
<select id="selectByExample" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoiceExample"
resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
......@@ -107,10 +110,10 @@
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from OutputVATInvoice
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
......@@ -122,7 +125,7 @@
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from OutputVATInvoice
where InvoiceID = #{invoiceID,jdbcType=VARCHAR}
</select>
......@@ -141,7 +144,7 @@
-->
delete from OutputVATInvoice
<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.OutputVATInvoice">
......@@ -269,14 +272,15 @@
</if>
</trim>
</insert>
<select id="countByExample" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoiceExample" resultType="java.lang.Long">
<select id="countByExample" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoiceExample"
resultType="java.lang.Long">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select count(*) from OutputVATInvoice
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
......@@ -336,7 +340,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">
......@@ -362,7 +366,7 @@
PartAccntedPeriod = #{record.partAccntedPeriod,jdbcType=INTEGER},
AccntedPeriod = #{record.accntedPeriod,jdbcType=INTEGER}
<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.OutputVATInvoice">
......@@ -443,7 +447,8 @@
AccntedPeriod = #{accntedPeriod,jdbcType=INTEGER}
where InvoiceID = #{invoiceID,jdbcType=VARCHAR}
</update>
<select id="selectByExampleWithRowbounds" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoiceExample" resultMap="BaseResultMap">
<select id="selectByExampleWithRowbounds" parameterType="pwc.taxtech.atms.vat.entity.OutputVATInvoiceExample"
resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
......@@ -452,43 +457,44 @@
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from OutputVATInvoice
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<resultMap id="OutputVATInvoiceInfoDto" type="pwc.taxtech.atms.dto.vatdto.OutputVATInvoiceInfoDto">
<id column="InvoiceID" jdbcType="VARCHAR" property="invoiceID" />
<result column="InvoiceType" jdbcType="INTEGER" property="invoiceType" />
<result column="InvoiceType" jdbcType="INTEGER" property="invoiceType" />
<result column="InvoiceTypeName" jdbcType="VARCHAR" property="invoiceTypeName" />
<result column="ClassCode" jdbcType="VARCHAR" property="classCode" />
<result column="InvoiceNumber" jdbcType="VARCHAR" property="invoiceNumber" />
<result column="BuyerName" jdbcType="VARCHAR" property="buyerName" />
<result column="BuyerTaxNumber" jdbcType="VARCHAR" property="buyerTaxNumber" />
<result column="BankAccount" jdbcType="VARCHAR" property="bankAccount" />
<result column="PhoneNum" jdbcType="VARCHAR" property="phoneNum" />
<result column="InvoiceDate" jdbcType="TIMESTAMP" property="invoiceDate" />
<result column="CodeVersion" jdbcType="VARCHAR" property="codeVersion" />
<result column="ProductName" jdbcType="VARCHAR" property="productName" />
<result column="DocumentNum" jdbcType="VARCHAR" property="documentNum" />
<result column="ProductStandard" jdbcType="VARCHAR" property="productStandard" />
<result column="Unit" jdbcType="VARCHAR" property="unit" />
<result column="Quantity" jdbcType="INTEGER" property="quantity" />
<result column="UnitPrice" jdbcType="DOUBLE" property="unitPrice" />
<result column="Amount" jdbcType="DECIMAL" property="amount" />
<result column="TaxRate" jdbcType="DECIMAL" property="taxRate" />
<result column="TaxAmount" jdbcType="DECIMAL" property="taxAmount" />
<result column="TaxClassCode" jdbcType="VARCHAR" property="taxClassCode" />
<result column="PeriodID" jdbcType="INTEGER" property="periodID" />
<result column="IsDuplicate" jdbcType="INTEGER" property="isDuplicate" />
<result column="AmountDifference" jdbcType="DECIMAL" property="amountDifference" />
<id column="InvoiceID" jdbcType="VARCHAR" property="invoiceID"/>
<result column="InvoiceType" jdbcType="INTEGER" property="invoiceType"/>
<result column="InvoiceType" jdbcType="INTEGER" property="invoiceType"/>
<result column="InvoiceTypeName" jdbcType="VARCHAR" property="invoiceTypeName"/>
<result column="ClassCode" jdbcType="VARCHAR" property="classCode"/>
<result column="InvoiceNumber" jdbcType="VARCHAR" property="invoiceNumber"/>
<result column="BuyerName" jdbcType="VARCHAR" property="buyerName"/>
<result column="BuyerTaxNumber" jdbcType="VARCHAR" property="buyerTaxNumber"/>
<result column="BankAccount" jdbcType="VARCHAR" property="bankAccount"/>
<result column="PhoneNum" jdbcType="VARCHAR" property="phoneNum"/>
<result column="InvoiceDate" jdbcType="TIMESTAMP" property="invoiceDate"/>
<result column="CodeVersion" jdbcType="VARCHAR" property="codeVersion"/>
<result column="ProductName" jdbcType="VARCHAR" property="productName"/>
<result column="DocumentNum" jdbcType="VARCHAR" property="documentNum"/>
<result column="ProductStandard" jdbcType="VARCHAR" property="productStandard"/>
<result column="Unit" jdbcType="VARCHAR" property="unit"/>
<result column="Quantity" jdbcType="INTEGER" property="quantity"/>
<result column="UnitPrice" jdbcType="DOUBLE" property="unitPrice"/>
<result column="Amount" jdbcType="DECIMAL" property="amount"/>
<result column="TaxRate" jdbcType="DECIMAL" property="taxRate"/>
<result column="TaxAmount" jdbcType="DECIMAL" property="taxAmount"/>
<result column="TaxClassCode" jdbcType="VARCHAR" property="taxClassCode"/>
<result column="PeriodID" jdbcType="INTEGER" property="periodID"/>
<result column="IsDuplicate" jdbcType="INTEGER" property="isDuplicate"/>
<result column="AmountDifference" jdbcType="DECIMAL" property="amountDifference"/>
</resultMap>
<select id="selectOutputVATInvoiceInfoLeftJoinItem" parameterType="pwc.taxtech.atms.dto.vatdto.QueryOutputDto" resultMap="OutputVATInvoiceInfoDto">
<select id="selectOutputVATInvoiceInfoLeftJoinItem" parameterType="pwc.taxtech.atms.dto.vatdto.QueryOutputDto"
resultMap="OutputVATInvoiceInfoDto">
SELECT
o.InvoiceID,
o.InvoiceType,
......@@ -524,4 +530,84 @@
AND ProductName LIKE concat('%',#{query.productName,jdbcType=VARCHAR,'%'})
</if>
</select>
<resultMap id="outputVATInvoiceDto" type="pwc.taxtech.atms.dto.vatdto.OutputVATInvoiceDto">
<id property="invoiceID" column="invoice_id"/>
<association property="invoice" javaType="pwc.taxtech.atms.vat.entity.OutputVATInvoice">
<id column="InvoiceID" property="invoiceID"/>
<result column="InvoiceType" property="invoiceType"/>
<result column="ClassCode" property="classCode"/>
<result column="InvoiceNumber" property="invoiceNumber"/>
<result column="BuyerName" property="buyerName"/>
<result column="BuyerTaxNumber" property="buyerTaxNumber"/>
<result column="BankAccount" property="bankAccount"/>
<result column="PhoneNum" property="phoneNum"/>
<result column="InvoiceDate" property="invoiceDate"/>
<result column="SeqNo" property="seqNo"/>
<result column="PeriodID" property="periodID"/>
<result column="STATUS" property="status"/>
<result column="CreatorID" property="creatorID"/>
<result column="CreateTime" property="createTime"/>
<result column="PartAccntedPeriod" property="partAccntedPeriod"/>
<result column="AccntedPeriod" property="accntedPeriod"/>
</association>
<association property="invoiceItem" javaType="pwc.taxtech.atms.vat.entity.OutputVATInvoiceItem">
<id column="ItemID" property="itemID"/>
<result column="InvoiceID" property="invoiceID"/>
<result column="CodeVersion" property="codeVersion"/>
<result column="ProductName" property="productName"/>
<result column="DocumentNum" property="documentNum"/>
<result column="ProductStandard" property="productStandard"/>
<result column="Unit" property="unit"/>
<result column="Quantity" property="quantity"/>
<result column="UnitPrice" property="unitPrice"/>
<result column="Amount" property="amount"/>
<result column="TaxRate" property="taxRate"/>
<result column="TaxAmount" property="taxAmount"/>
<result column="SeqNo" property="seqNo"/>
<result column="TaxClassCode" property="taxClassCode"/>
<result column="CreatorID" property="creatorID"/>
<result column="CreateTime" property="createTime"/>
<result column="PeriodID" property="periodID"/>
</association>
</resultMap>
<select id="getVatInvoiceWithItems" resultMap="outputVATInvoiceDto" parameterType="java.lang.String">
SELECT
invoice.InvoiceID,
invoice.InvoiceType,
invoice.ClassCode,
invoice.InvoiceNumber,
invoice.BuyerName,
invoice.BuyerTaxNumber,
invoice.BankAccount,
invoice.PhoneNum,
invoice.InvoiceDate,
invoice.SeqNo,
invoice.PeriodID,
invoice.`STATUS`,
invoice.CreatorID,
invoice.CreateTime,
invoice.PartAccntedPeriod,
invoice.AccntedPeriod,
invoiceItem.ItemID,
invoiceItem.InvoiceID,
invoiceItem.CodeVersion,
invoiceItem.ProductName,
invoiceItem.DocumentNum,
invoiceItem.ProductStandard,
invoiceItem.Unit,
invoiceItem.Quantity,
invoiceItem.UnitPrice,
invoiceItem.Amount,
invoiceItem.TaxRate,
invoiceItem.TaxAmount,
invoiceItem.SeqNo,
invoiceItem.TaxClassCode,
invoiceItem.CreatorID,
invoiceItem.CreateTime,
invoiceItem.PeriodID
FROM ${dbName}.OutputVATInvoice invoice
JOIN ${dbName}.OutputVATInvoiceItem invoiceItem
ON invoice.InvoiceID = invoiceItem.InvoiceID
ORDER BY invoice.PeriodID,invoice.ClassCode,invoice.InvoiceNumber,invoiceItem.SeqNo
</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