增值税发票保存

This commit is contained in:
hjc 2019-11-22 20:42:09 +08:00
parent e07c0b02f5
commit ff25047310
9 changed files with 249 additions and 48 deletions

View File

@ -10,10 +10,12 @@ import com.cwhelp.common.enums.StatusEnum;
import com.cwhelp.common.utils.*;
import com.cwhelp.common.vo.ResultVo;
import com.cwhelp.component.fileUpload.FileUpload;
import com.cwhelp.component.shiro.ShiroUtil;
import com.cwhelp.devtools.generate.utils.jAngel.utils.StringUtil;
import com.cwhelp.modules.business.domain.BssGoods;
import com.cwhelp.modules.business.domain.BssTaxinfo;
import com.cwhelp.modules.business.domain.BssVatInvoice;
import com.cwhelp.modules.business.service.BssTaxinfoService;
import com.cwhelp.modules.business.service.BssVatInvoiceService;
import com.cwhelp.modules.system.domain.Upload;
import org.apache.shiro.authz.annotation.RequiresPermissions;
@ -28,9 +30,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
@ -45,6 +45,9 @@ public class BssVatInvoiceController {
@Autowired
private BssVatInvoiceService bssVatInvoiceService;
@Autowired
private BssTaxinfoService bssTaxinfoService;
/**
* 列表页面
*/
@ -110,17 +113,29 @@ public class BssVatInvoiceController {
/**
* 保存添加/修改的数据
* @param valid 验证对象
* @param
*/
@PostMapping({"/add","/edit"})
@RequiresPermissions({"bss:vatInvoice:add","bss:vatInvoice:edit"})
@ResponseBody
public ResultVo save(@Validated BssVatInvoiceValid valid, BssVatInvoice bssVatInvoice) {
// public ResultVo save(@Validated @RequestBody BssVatInvoiceValid valid, @RequestBody BssVatInvoice bssVatInvoice) {
public ResultVo save(@Validated @RequestBody BssVatInvoice bssVatInvoice) {
// 复制保留无需修改的数据
if (bssVatInvoice.getId() != null) {
BssVatInvoice beBssVatInvoice = bssVatInvoiceService.getById(bssVatInvoice.getId());
EntityBeanUtil.copyProperties(beBssVatInvoice, bssVatInvoice);
}
if(!StringUtil.isBlank(String.valueOf(bssVatInvoice.getSalerTaxInfoId()))){
bssVatInvoice.setSalerTaxInfo(bssTaxinfoService.getById(bssVatInvoice.getSalerTaxInfoId()));
}
if(!StringUtil.isBlank(String.valueOf(bssVatInvoice.getBuyTaxInfoId()))) {
bssVatInvoice.setBuyTaxInfo(bssTaxinfoService.getById(bssVatInvoice.getBuyTaxInfoId()));
}
List<BssGoods> bssGoods = bssVatInvoice.getBssGoods();
bssGoods.stream().forEach(good ->{
good.setVatInvoice(bssVatInvoice);
});
// 保存数据
bssVatInvoiceService.save(bssVatInvoice);
@ -170,18 +185,43 @@ public class BssVatInvoiceController {
File destFile = FileUpload.getDestFile(upload);
VatInvoiceResult vatInvoiceResult = BaiduAipOCR.queryBaiduVatInvoiceApi(destFile);
WordsResult wordsResult = vatInvoiceResult.getWords_result();
//销售方
BssVatInvoice vatInvoice = new BssVatInvoice();
Long bssplatformId = ShiroUtil.getSubject().getBssPlatform().getId();
//add by hjc 发票上扫到的买卖双方如果不在系统中先入库
if(!StringUtil.isBlank(wordsResult.getSellerRegisterNum())){
BssTaxinfo sellerTaxInfo = new BssTaxinfo();
BssTaxinfo taxNo = bssTaxinfoService.getByTaxNo(wordsResult.getSellerRegisterNum());
if(taxNo == null){
//销售方
sellerTaxInfo.setName(wordsResult.getSellerName());
sellerTaxInfo.setTaxNo(wordsResult.getSellerRegisterNum());
sellerTaxInfo.setAccount(wordsResult.getSellerBank());
sellerTaxInfo.setAddressPhone(wordsResult.getSellerAddress());
//购买方
sellerTaxInfo.setPlatformId(bssplatformId);
bssTaxinfoService.save(sellerTaxInfo);
vatInvoice.setSalerTaxInfoId(sellerTaxInfo.getId());
}else {
vatInvoice.setSalerTaxInfoId(taxNo.getId());
}
}
if(!StringUtil.isBlank(wordsResult.getPurchaserRegisterNum())){
BssTaxinfo purchaserTaxInfo = new BssTaxinfo();
BssTaxinfo taxNo = bssTaxinfoService.getByTaxNo(wordsResult.getPurchaserRegisterNum());
if(taxNo == null){
//购买方
purchaserTaxInfo.setName(wordsResult.getPurchaserName());
purchaserTaxInfo.setTaxNo(wordsResult.getPurchaserRegisterNum());
purchaserTaxInfo.setAccount(wordsResult.getPurchaserBank());
purchaserTaxInfo.setAddressPhone(wordsResult.getPurchaserAddress());
purchaserTaxInfo.setPlatformId(bssplatformId);
bssTaxinfoService.save(purchaserTaxInfo);
vatInvoice.setBuyTaxInfoId(purchaserTaxInfo.getId());
}else{
vatInvoice.setBuyTaxInfoId(taxNo.getId());
}
}
//商品
List<BssGoods> goods = new ArrayList<>();
List<CommodityName> commodityNames = wordsResult.getCommodityName();
@ -215,12 +255,11 @@ public class BssVatInvoiceController {
good.setTaxRate(commodityTaxRates.get(i).getWord());
}
if (ToolUtil.checkListSize(commodityTaxs) && !StringUtil.isBlank(commodityTaxs.get(i).getWord())) {
good.setTaxAmount(new BigDecimal(commodityTaxs.get(i).getWord()));
good.setGoodTaxAmount(new BigDecimal(commodityTaxs.get(i).getWord()));
}
goods.add(good);
}
BssVatInvoice vatInvoice = new BssVatInvoice();
vatInvoice.setInvoiceCode(wordsResult.getInvoiceCode());
vatInvoice.setInvoiceNo(wordsResult.getInvoiceNum());
vatInvoice.setInvoiceDate(wordsResult.getInvoiceDate());
@ -230,8 +269,6 @@ public class BssVatInvoiceController {
vatInvoice.setTotalAmount(new BigDecimal(wordsResult.getAmountInFiguers()));
vatInvoice.setTotalAmountCn(wordsResult.getAmountInWords());
vatInvoice.setRemark(wordsResult.getRemarks());
vatInvoice.setBuyTaxInfo(purchaserTaxInfo);
vatInvoice.setSalerTaxInfo(sellerTaxInfo);
vatInvoice.setBssGoods(goods);
vatInvoice.setInvoiceImg(upload.getPath());
vatInvoice.setInvoiceType(VatInvoiceTypeEnum.getVatInvoiceCode(wordsResult.getInvoiceType()));

View File

@ -127,18 +127,55 @@ layui.use(['element', 'form', 'layer', 'upload'], function () {
}
};
/* 提交表单数据 */
/* 提交表单数据 */ // update by hjc
$(document).on("click", ".ajax-submit", function (e) {
e.preventDefault();
var form = $(this).parents("form");
var url = form.attr("action");
var serializeArray = form.serializeArray();
$.post(url, serializeArray, function (result) {
var _newData = null;
var from = false; // from = true 代表增值税页面请求用设置content-type的请求
for(var i=0; i<serializeArray.length; i++){
if(serializeArray[i].name == 'salerTaxInfoId'){
from = true;
_newData = trans.serialize( serializeArray );
var goods = createGoodsParams();
_newData.bssGoods = goods;
delete _newData.name;
delete _newData.specification;
delete _newData.unit;
delete _newData.num;
delete _newData.unitPrice;
delete _newData.detailAmount;
delete _newData.taxRate;
delete _newData.goodTaxAmount;
break;
}else {
continue;
}
}
if(from){
$.ajax({
url: url,
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(_newData),
success: function(result) {
if (result.data == null) {
result.data = 'submit[refresh]';
}
$.fn.Messager(result);
}
});
}else {
$.post(url, _newData, function(result) {
if (result.data == null) {
result.data = 'submit[refresh]';
}
$.fn.Messager(result);
});
}
});
/* get方式异步 */
@ -406,6 +443,8 @@ layui.use(['element', 'form', 'layer', 'upload'], function () {
$('#taxAmount').val(res.data['taxAmount']);
$('#totalAmount').val(res.data['totalAmount']);
$('#totalAmountCn').val(res.data['totalAmountCn']);
$('#salerTaxInfoId').val(res.data['salerTaxInfoId']);
$('#buyTaxInfoId').val(res.data['buyTaxInfoId']);
form.render("select");
hide.val(res.data['invoiceImg']);
item.addClass('succeed');
@ -413,8 +452,9 @@ layui.use(['element', 'form', 'layer', 'upload'], function () {
/* 实体模型操作 */
var entity = $("#entity");
var goods = res.data['bssGoods'];
var element = null;
for(var i=0; i<goods.length; i++){
var element = entity.children("tr:last-child").clone();
element = entity.children("tr:last-child").clone();
element.find("input[name='name']").val(goods[i].name);
element.find("input[name='specification']").val(goods[i].specification);
element.find("input[name='unit']").val(goods[i].unit);
@ -422,10 +462,9 @@ layui.use(['element', 'form', 'layer', 'upload'], function () {
element.find("input[name='unitPrice']").val(goods[i].unitPrice);
element.find("input[name='detailAmount']").val(goods[i].detailAmount);
element.find("input[name='taxRate']").val(goods[i].taxRate);
element.find("input[name='taxAmount']").val(goods[i].taxAmount);
element.find("input[name='goodTaxAmount']").val(goods[i].goodTaxAmount);
entity.append(element);
// element.children(".entity-number").click();
element.children(".entity-number").click();
$.each(entity.children(), function (key, val) {
$(val).children(".entity-number").text(key + 1);
});
@ -461,4 +500,47 @@ layui.use(['element', 'form', 'layer', 'upload'], function () {
});
});
function createGoodsParams() {
var entity = $("#entity");
var trs = entity.children("tr");
var goods = new Array();
$.each(trs, function(index, element){
var name = element.children[1].children[0].value;
if(name == null || name == '' || name == undefined){
return true;
}
var good = {};
good.name = name;
good.specification = element.children[2].children[0].value;
good.unit = element.children[3].children[0].value;
good.num = element.children[4].children[0].value;
good.unitPrice = element.children[5].children[0].value;
good.detailAmount = element.children[6].children[0].value;
good.taxRate = element.children[7].children[0].value;
good.goodTaxAmount = element.children[8].children[0].value;
goods.push(good);
});
return goods;
}
var trans={
serialize:function(obj){
var o ={};
$.each(obj,function(){
if(o[this.name]){
if(!o[this.name].push){
o[this.name]=[o[this.name]];
}
o[this.name].push(this.value||"");
}else {
o[this.name] = this.value || "";
}
});
return o;
}
}
});

View File

@ -83,6 +83,8 @@
<div class="layui-input-inline">
<input type="text" id="totalAmountCn" name="totalAmountCn" autocomplete="off" class="layui-input">
</div>
<input type="hidden" id="salerTaxInfoId" name="salerTaxInfoId" />
<input type="hidden" id="buyTaxInfoId" name="buyTaxInfoId" />
</div>
</div>
<div class="layui-inline">
@ -102,10 +104,10 @@
<div class="panel-header">
<div class="title">货物信息</div>
<div class="control">
<button class="field-add layui-btn layui-btn-primary layui-btn-xs">
<button class="col-add field-add layui-btn layui-btn-primary layui-btn-xs">
<i class="fa fa-plus-circle"></i>添加
</button>
<button class="field-del layui-btn layui-btn-primary layui-btn-xs">
<button class="col-del field-del layui-btn layui-btn-primary layui-btn-xs">
<i class="fa fa-minus-circle"></i>删除
</button>
</div>
@ -136,13 +138,13 @@
<td class="entity-unitPrice"><input type="text" name="unitPrice"/></td>
<td class="entity-detailAmount"><input type="text" name="detailAmount"/></td>
<td class="entity-taxRate"><input type="text" name="taxRate"/></td>
<td class="entity-taxAmount"><input type="text" name="taxAmount"/></td>
<td class="entity-taxAmount"><input type="text" name="goodTaxAmount"/></td>
</tr>
</tbody>
</table>
</div>
<div class="layui-form-item timo-finally">
<button class="layui-btn ajax-submit"><i class="fa fa-check-circle"></i> 保存</button>
<button class="layui-btn ajax-submit" ><i class="fa fa-check-circle"></i> 保存</button>
<button class="layui-btn btn-secondary close-popup"><i class="fa fa-times-circle"></i> 关闭</button>
</div>
</div>
@ -192,22 +194,73 @@
<script th:replace="/common/template :: script"></script>
<script type="text/javascript" th:src="@{/js/plugins/jquery-3.3.1.min.js}"></script>
<script type="text/javascript" th:src="@{/lib/zTree_v3/js/jquery.ztree.core.min.js}"></script>
<script type="text/javascript" th:src="@{/js/timoTree.js}"></script>
<!--<script type="text/javascript" th:src="@{/lib/zTree_v3/js/jquery.ztree.core.min.js}"></script>-->
<!--<script type="text/javascript" th:src="@{/js/timoTree.js}"></script>-->
<script type="text/javascript">
// 树形菜单
$.fn.selectTree({
rootTree: '顶级菜单'
});
// $.fn.selectTree({
// rootTree: '顶级菜单'
// });
// 验证下拉选择器
layui.config({
base: '[[@{/lib/formSelects-v4/}]]'
}).extend({
formSelects: 'formSelects-v4.min'
// layui.config({
// base: '[[@{/lib/formSelects-v4/}]]'
// }).extend({
// formSelects: 'formSelects-v4.min'
// });
var entity = $("#entity");
var field = null;
// 选中字段
entity.on("click", ".entity-number", function () {
if(field !== null){
$(field).css("background-color", "#FFFFFF");
$(field).css("color", "#666666");
}
if(field !== this){
$(this).css("background-color", "#5FB878");
$(this).css("color", "#FFFFFF");
field = this;
}else{
field = null;
}
});
// 添加行
$(".col-add").on("click", function (e) {
e.preventDefault();
var element = entity.children("tr:last-child").clone();
element.find("input").val("");
if(field == null){
entity.append(element);
}else {
$(field).parent().after(element);
}
element.children(".entity-number").click();
resetNumber();
});
// 删除行
$(".col-del").on("click", function (e) {
e.preventDefault();
if(field != null){
if (entity.children("tr").length == 1) {
return;
}
$(field).parent().remove();
entity.children("tr:last-child").children(".entity-number").click();
resetNumber();
}
});
// 重置字段编号
var resetNumber = function(){
entity.children().each(function (key, val) {
$(val).children(".entity-number").text(key + 1);
});
};
</script>
<script type="text/javascript" th:src="@{/js/generate.code.js}"></script>
<script type="text/javascript" th:src="@{/js/build.js}"></script>
<!--<script type="text/javascript" th:src="@{/js/generate.code.js}"></script>-->
<!--<script type="text/javascript" th:src="@{/js/build.js}"></script>-->
</body>
</html>

View File

@ -20,7 +20,7 @@
</div>
<form class="user-edit" th:action="@{/userInfo}">
<input type="hidden" name="username" th:value="${user.username}"/>
<input type="hidden" name="bssDept" th:value="${user.dept?.id}"/>
<input type="hidden" name="bssDept" th:value="${user.dept.id}"/>
<div class="layui-form-item">
<label class="layui-form-label">用户昵称</label>
<div class="layui-input-inline">

View File

@ -38,7 +38,7 @@ public class BssGoods implements Serializable {
private BigDecimal detailAmount;
// 税额
@Column(name = "tax_amount")
private BigDecimal taxAmount;
private BigDecimal goodTaxAmount;
// 税率
@Column(name = "tax_rate")
private String taxRate;

View File

@ -12,6 +12,9 @@ import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@ -33,32 +36,42 @@ public class BssVatInvoice implements Serializable {
private Long id;
// 发票代码
@Column(name = "invoice_code")
@NotEmpty(message = "发票代码不能为空")
private String invoiceCode;
// 发票号码
@Column(name = "invoice_no")
@NotEmpty(message = "发票号码不能为空")
private String invoiceNo;
// 发票日期
@Column(name = "invoice_date")
@NotEmpty(message = "发票日期不能为空")
@Pattern(regexp = "[0-9]{4}-[0-9]{2}-[0-9]{2}", message = "日期格式不正确")
private String invoiceDate;
// 校验码
@Column(name = "check_code")
@NotEmpty(message = "校验码不能为空")
private String checkCode;
// 发票金额
@Column(name = "invoice_money")
@NotNull(message = "发票金额不能为空")
private BigDecimal invoiceMoney;
// 税额
@Column(name = "tax_amount")
@NotNull(message = "税额不能为空")
private BigDecimal taxAmount;
// 总金额
@Column(name = "total_amount")
@NotNull(message = "总金额不能为空")
private BigDecimal totalAmount;
// 总金额(大写)
@Column(name = "total_amount_cn")
@NotEmpty(message = "总金额(大写)不能为空")
private String totalAmountCn;
//发票类型
//增值税普通发票 0; 增值税专用发票 1
@Column(name = "invoice_type")
@NotNull(message = "发票类型不能为空")
private Integer invoiceType;
// 备注
@ -73,7 +86,6 @@ public class BssVatInvoice implements Serializable {
@JsonIgnore
private BssTaxinfo buyTaxInfo;
// 销售方纳税人信息
// 购买方纳税人信息
@OneToOne(fetch=FetchType.LAZY)
@NotFound(action= NotFoundAction.IGNORE)
@JoinColumn(name="saler_tax_info_id")
@ -91,4 +103,10 @@ public class BssVatInvoice implements Serializable {
// 更新时间
@LastModifiedDate
private Date updateDate;
@Transient
private Long buyTaxInfoId;
@Transient
private Long salerTaxInfoId;
}

View File

@ -8,4 +8,5 @@ import com.cwhelp.modules.system.repository.BaseRepository;
* @date 2019/08/16
*/
public interface BssTaxinfoRepository extends BaseRepository<BssTaxinfo, Long> {
BssTaxinfo getByTaxNo(String taxNo);
}

View File

@ -38,4 +38,9 @@ public interface BssTaxinfoService {
*/
@Transactional
Boolean updateStatus(StatusEnum statusEnum, List<Long> idList);
/**
* 根据纳税人识别号查询数据
*/
BssTaxinfo getByTaxNo(String taxNo);
}

View File

@ -24,6 +24,11 @@ public class BssTaxinfoServiceImpl implements BssTaxinfoService {
@Autowired
private BssTaxinfoRepository bssTaxinfoRepository;
@Override
public BssTaxinfo getByTaxNo(String taxNo) {
return bssTaxinfoRepository.getByTaxNo(taxNo);
}
/**
* 根据ID查询数据
* @param id 主键ID