开票注释添加

master
pangyang 2 years ago
parent 70d52f2b0f
commit 0e2ba4c402

@ -66,6 +66,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
//判断是否数字
public static boolean isNumeric(String str){ public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*"); Pattern pattern = Pattern.compile("[0-9]*");
if(str.indexOf(".")>0){//判断是否有小数点 if(str.indexOf(".")>0){//判断是否有小数点
@ -79,6 +80,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
} }
} }
//上传链接、业务数据和费用数据
@Transactional @Transactional
@Override @Override
public HttpResult getlink(String json) { public HttpResult getlink(String json) {
@ -106,6 +108,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
HttpResult result = parameterFeignClient.getParameter(linkinfo.getCompanyId()); HttpResult result = parameterFeignClient.getParameter(linkinfo.getCompanyId());
String amount =(String)result.getData(); String amount =(String)result.getData();
//判断开票限额格式和是否存在
if(null == amount){ if(null == amount){
return HttpResult.error(20060,"linkId="+linkinfo.getLinkId()+",CompanyId="+linkinfo.getCompanyId()+",开票数额不存在,请检查"); return HttpResult.error(20060,"linkId="+linkinfo.getLinkId()+",CompanyId="+linkinfo.getCompanyId()+",开票数额不存在,请检查");
}else{ }else{
@ -138,6 +141,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
} }
} }
//赋值给链表状态
linkinfo.setStatus("0"); linkinfo.setStatus("0");
linkinfo.setSendStatus("0"); linkinfo.setSendStatus("0");
try { try {
@ -150,6 +154,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
// JSONArray array = jsonObj.getJSONArray("BillList"); // JSONArray array = jsonObj.getJSONArray("BillList");
//生成业务信息
List<InvBusinessInfo> array = linkinfo.getBillList(); List<InvBusinessInfo> array = linkinfo.getBillList();
for(int i=0; i<array.size(); i++) { for(int i=0; i<array.size(); i++) {
@ -178,6 +183,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
e.printStackTrace(); e.printStackTrace();
} }
// invBusinessInfoMapper.deleteByGID(businessinfo); // invBusinessInfoMapper.deleteByGID(businessinfo);
//重新上传,如果存在就更新
invBusinessInfoMapper.updateInvBusinessInfo(businessinfo); invBusinessInfoMapper.updateInvBusinessInfo(businessinfo);
gid = businessinfo.getGID(); gid = businessinfo.getGID();
bsno = businessinfo.getBSNO(); bsno = businessinfo.getBSNO();
@ -193,6 +199,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
List<InvFeeInfo> feearray = business.getFeeList(); List<InvFeeInfo> feearray = business.getFeeList();
//重新生成费用信息
for(int j=0; j<feearray.size(); j++) { for(int j=0; j<feearray.size(); j++) {
InvFeeInfo fee = feearray.get(j); InvFeeInfo fee = feearray.get(j);
@ -216,9 +223,12 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
} }
//重新上传的时候删除原来的数据
deleteSplit(linkinfo); deleteSplit(linkinfo);
//生成发票,发票明细,发票分割
createSplit(linkinfo); createSplit(linkinfo);
//判断链接备注情况(remarkTemplate)
List<String> invoiceIds = invInvoiceSplitMapper.getIdsBylinkdId(linkinfo.getGID()); List<String> invoiceIds = invInvoiceSplitMapper.getIdsBylinkdId(linkinfo.getGID());
for(String str : invoiceIds){ for(String str : invoiceIds){
@ -305,6 +315,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
} }
//重新上传时,删除发票、发票明细、分票情况
public void deleteSplit(InvLinkInfo link){ public void deleteSplit(InvLinkInfo link){
List<String> list = invInvoiceSplitMapper.getIdsBylinkdId(link.getGID()); List<String> list = invInvoiceSplitMapper.getIdsBylinkdId(link.getGID());
@ -326,7 +337,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
} }
//组装发票明细
InvInvoiceDetail getInvInvoiceDetail(InvInvoiceInfo invoice,InvFeeInfo feeinfo,BigDecimal amount){ InvInvoiceDetail getInvInvoiceDetail(InvInvoiceInfo invoice,InvFeeInfo feeinfo,BigDecimal amount){
InvInvoiceDetail detail = new InvInvoiceDetail(); InvInvoiceDetail detail = new InvInvoiceDetail();
detail.setGID(UUID.randomUUID().toString().replace("-", "")); detail.setGID(UUID.randomUUID().toString().replace("-", ""));
@ -358,6 +369,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
} }
//组装发票分配
InvInvoiceSplit getInvInvoiceSplit(InvInvoiceInfo invoice,InvInvoiceDetail detail,InvFeeInfo feeinfo,InvLinkInfo link,BigDecimal amount){ InvInvoiceSplit getInvInvoiceSplit(InvInvoiceInfo invoice,InvInvoiceDetail detail,InvFeeInfo feeinfo,InvLinkInfo link,BigDecimal amount){
InvInvoiceSplit split = new InvInvoiceSplit(); InvInvoiceSplit split = new InvInvoiceSplit();
split.setGID(UUID.randomUUID().toString().replace("-", "")); split.setGID(UUID.randomUUID().toString().replace("-", ""));
@ -388,6 +400,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
//开始生成发票、发票明细、发票分配
void invoicepzRmb(List<InvFeeInfo> fees,InvLinkInfo link,BigDecimal sumfees){ void invoicepzRmb(List<InvFeeInfo> fees,InvLinkInfo link,BigDecimal sumfees){
if(null != fees && fees.size()>0){ if(null != fees && fees.size()>0){
@ -407,7 +420,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
//如果费用总计小于等于最大开票金额 //如果费用总计小于等于最大开票金额
if(checkinvocie.compareTo(sumfees) == 1){ if(checkinvocie.compareTo(sumfees) == 1 || checkinvocie.compareTo(sumfees) == 0 ){
InvInvoiceInfo invoice = new InvInvoiceInfo(); InvInvoiceInfo invoice = new InvInvoiceInfo();
BeanUtils.copyProperties(link,invoice); BeanUtils.copyProperties(link,invoice);
invoice.setStatus(null); invoice.setStatus(null);
@ -426,20 +439,19 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
InvInvoiceSplit split = getInvInvoiceSplit(invoice,detail,feeinfo,link,feeinfo.getAmount()); InvInvoiceSplit split = getInvInvoiceSplit(invoice,detail,feeinfo,link,feeinfo.getAmount());
invInvoiceSplitMapper.add(split); invInvoiceSplitMapper.add(split);
} }
}else{ }else{//如果费用总计大于开票限额
BigDecimal amount = new BigDecimal(0); BigDecimal amount = new BigDecimal(0);
// List<InvInvoiceDetail> details = new ArrayList<>(); // List<InvInvoiceDetail> details = new ArrayList<>();
List<InvInvoiceSplit> splits = new ArrayList<>(); List<InvInvoiceSplit> splits = new ArrayList<>();
InvInvoiceInfo invoice = null; InvInvoiceInfo invoice = null;
for(int i=0;i<fees.size();i++){ for(int i=0;i<fees.size();i++){
invoice = new InvInvoiceInfo(); invoice = new InvInvoiceInfo();
InvFeeInfo feeinfo = fees.get(i); InvFeeInfo feeinfo = fees.get(i);
if(i==0){ if(i==0){
//如果当前费用大于或者等于开票限额
if(feeinfo.getAmount().compareTo(checkinvocie)==1 || feeinfo.getAmount().compareTo(checkinvocie)==0){ if(feeinfo.getAmount().compareTo(checkinvocie)==1 || feeinfo.getAmount().compareTo(checkinvocie)==0){
//当前费用对开票限额取余
BigDecimal[] results = feeinfo.getAmount().divideAndRemainder(checkinvocie); BigDecimal[] results = feeinfo.getAmount().divideAndRemainder(checkinvocie);
int size = results[0].intValue(); int size = results[0].intValue();
for(int m=0;m<size;m++){ for(int m=0;m<size;m++){
@ -459,11 +471,15 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
InvInvoiceSplit split = getInvInvoiceSplit(invoice,detail,feeinfo,link,checkinvocie); InvInvoiceSplit split = getInvInvoiceSplit(invoice,detail,feeinfo,link,checkinvocie);
invInvoiceSplitMapper.add(split); invInvoiceSplitMapper.add(split);
} }
//当前费用对开票限额取余所剩的金额
BigDecimal remainAmount = results[1].setScale(2, BigDecimal.ROUND_HALF_UP); BigDecimal remainAmount = results[1].setScale(2, BigDecimal.ROUND_HALF_UP);
amount = remainAmount; amount = remainAmount;
//如果剩余金额大于0
if(remainAmount.compareTo(new BigDecimal(0))==1){ if(remainAmount.compareTo(new BigDecimal(0))==1){
//生成发票分配
InvInvoiceSplit split = getInvInvoiceSplit(new InvInvoiceInfo(),new InvInvoiceDetail(),feeinfo,link,amount); InvInvoiceSplit split = getInvInvoiceSplit(new InvInvoiceInfo(),new InvInvoiceDetail(),feeinfo,link,amount);
splits.add(split); splits.add(split);
//如果是最后一行费用数据,生成发票、发票明细、发票分配
if((i==fees.size()-1)){ if((i==fees.size()-1)){
invoice = new InvInvoiceInfo(); invoice = new InvInvoiceInfo();
BeanUtils.copyProperties(link,invoice); BeanUtils.copyProperties(link,invoice);
@ -484,19 +500,21 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
} }
} }
}else{ }else{//如果当前费用小于开票限额
InvInvoiceSplit split = getInvInvoiceSplit(new InvInvoiceInfo(),new InvInvoiceDetail(),feeinfo,link,feeinfo.getAmount()); InvInvoiceSplit split = getInvInvoiceSplit(new InvInvoiceInfo(),new InvInvoiceDetail(),feeinfo,link,feeinfo.getAmount());
splits.add(split); splits.add(split);
//获取当前费用加上上一次剩余的金额
amount = amount.add(feeinfo.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP); amount = amount.add(feeinfo.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
} }
}else{ }else{
//剩余金额加上当前费用金额
amount = amount.add(feeinfo.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP); amount = amount.add(feeinfo.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
//如果加金额大于指定金额,则不加金额,取前边的数值 //如果加金额大于指定金额,则不加金额,取前边的数值
if(amount.compareTo(checkinvocie)==1){ if(amount.compareTo(checkinvocie)==1){
BigDecimal checkamount = amount.subtract(feeinfo.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP); BigDecimal checkamount = amount.subtract(feeinfo.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
if(feeinfo.getAmount().compareTo(checkinvocie)==1 || feeinfo.getAmount().compareTo(checkinvocie)==0){ if(feeinfo.getAmount().compareTo(checkinvocie)==1 || feeinfo.getAmount().compareTo(checkinvocie)==0){
//把以前的 //把以前的拼装成数据
if(checkamount.compareTo(new BigDecimal(0))==1){ if(checkamount.compareTo(new BigDecimal(0))==1){
InvFeeInfo feeinfoold = fees.get(i-1); InvFeeInfo feeinfoold = fees.get(i-1);
invoice = new InvInvoiceInfo(); invoice = new InvInvoiceInfo();
@ -529,7 +547,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
// invInvoiceSplitMapper.add(splitcheck); // invInvoiceSplitMapper.add(splitcheck);
} }
//判断当前金额 //对当前金额取余
BigDecimal[] results = feeinfo.getAmount().divideAndRemainder(checkinvocie); BigDecimal[] results = feeinfo.getAmount().divideAndRemainder(checkinvocie);
int size = results[0].intValue(); int size = results[0].intValue();
for(int m=0;m<size;m++){ for(int m=0;m<size;m++){
@ -549,9 +567,12 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
InvInvoiceSplit split = getInvInvoiceSplit(invoice,detail,feeinfo,link,checkinvocie); InvInvoiceSplit split = getInvInvoiceSplit(invoice,detail,feeinfo,link,checkinvocie);
invInvoiceSplitMapper.add(split); invInvoiceSplitMapper.add(split);
} }
//当前费用对开票限额取余所剩的金额
BigDecimal remainAmount = results[1].setScale(2, BigDecimal.ROUND_HALF_UP); BigDecimal remainAmount = results[1].setScale(2, BigDecimal.ROUND_HALF_UP);
amount = remainAmount; amount = remainAmount;
//如果是最后一行费用数据,生成发票、发票明细、发票分配
if((i==fees.size()-1) && (amount.compareTo(new BigDecimal(0))== 1)){ if((i==fees.size()-1) && (amount.compareTo(new BigDecimal(0))== 1)){
invoice = new InvInvoiceInfo(); invoice = new InvInvoiceInfo();
BeanUtils.copyProperties(link,invoice); BeanUtils.copyProperties(link,invoice);
@ -593,20 +614,6 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
invInvoiceInfoMapper.add(invoice); invInvoiceInfoMapper.add(invoice);
InvInvoiceDetail detail = getInvInvoiceDetail(invoice,feeinfoold,checkamount); InvInvoiceDetail detail = getInvInvoiceDetail(invoice,feeinfoold,checkamount);
invInvoiceDetailMapper.add(detail); invInvoiceDetailMapper.add(detail);
//生成发票分配
// InvInvoiceSplit split = getInvInvoiceSplit(invoice,detail,feeinfoold,link,checkamount);
// invInvoiceSplitMapper.add(split);
// splits.add(split);
//
// if(null != splits && splits.size()>0){
// for(InvInvoiceSplit sp : splits){
// sp.setInvoiceId(invoice.getGID());
// sp.setInvoiceDetailId(detail.getGID());
// sp.setGID(UUID.randomUUID().toString().replace("-", ""));
// invInvoiceSplitMapper.add(sp);
// }
// }
if(null != splits && splits.size()>0){ if(null != splits && splits.size()>0){
for(InvInvoiceSplit sp : splits){ for(InvInvoiceSplit sp : splits){
@ -634,13 +641,9 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
InvInvoiceSplit spl = getInvInvoiceSplit(invoice,det,feeinfo,link,feeinfo.getAmount()); InvInvoiceSplit spl = getInvInvoiceSplit(invoice,det,feeinfo,link,feeinfo.getAmount());
invInvoiceSplitMapper.add(spl); invInvoiceSplitMapper.add(spl);
} }
amount = feeinfo.getAmount(); amount = feeinfo.getAmount();
//先清空发票分配 //先清空发票分配
splits = new ArrayList<>(); splits = new ArrayList<>();
//把当前的发票分配添加进集合 //把当前的发票分配添加进集合
InvInvoiceSplit spl = getInvInvoiceSplit(invoice,detail,feeinfo,link,feeinfo.getAmount()); InvInvoiceSplit spl = getInvInvoiceSplit(invoice,detail,feeinfo,link,feeinfo.getAmount());
splits.add(spl); splits.add(spl);
@ -650,7 +653,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
}else{ }else{
//如果amount等于最大开票金额 //如果amount等于最大开票金额
if(amount.compareTo(checkinvocie)==0){ if(amount.compareTo(checkinvocie)==0){
//生成发票和发票明细 //生成发票和发票明细、发票配置
invoice = new InvInvoiceInfo(); invoice = new InvInvoiceInfo();
BeanUtils.copyProperties(link,invoice); BeanUtils.copyProperties(link,invoice);
invoice.setStatus(null); invoice.setStatus(null);
@ -678,11 +681,12 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
} }
amount = new BigDecimal(0); amount = new BigDecimal(0);
splits = new ArrayList<>(); splits = new ArrayList<>();
}else{ }else{//如果amount小于最大开票金额
//生成发票分配 //生成发票分配
InvInvoiceSplit split = getInvInvoiceSplit(new InvInvoiceInfo(),new InvInvoiceDetail(),feeinfo,link,feeinfo.getAmount()); InvInvoiceSplit split = getInvInvoiceSplit(new InvInvoiceInfo(),new InvInvoiceDetail(),feeinfo,link,feeinfo.getAmount());
splits.add(split); splits.add(split);
//如果是最后一条记录
if(i==fees.size()-1){ if(i==fees.size()-1){
BigDecimal sums = splits.stream().map(InvInvoiceSplit::getAmountTotal).reduce(BigDecimal.ZERO,BigDecimal::add); BigDecimal sums = splits.stream().map(InvInvoiceSplit::getAmountTotal).reduce(BigDecimal.ZERO,BigDecimal::add);
invoice = new InvInvoiceInfo(); invoice = new InvInvoiceInfo();
@ -728,6 +732,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
// @Transactional // @Transactional
// @Override // @Override
//生成发票、发票明细、发票分配
public HttpResult createSplit(InvLinkInfo info) { public HttpResult createSplit(InvLinkInfo info) {
log.info("连接id====={}",info.getGID()); log.info("连接id====={}",info.getGID());
@ -747,12 +752,14 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
InvFeeInfo fee = new InvFeeInfo(); InvFeeInfo fee = new InvFeeInfo();
fee.setLinkId(info.getGID()); fee.setLinkId(info.getGID());
fee.setCurrency("RMB"); fee.setCurrency("RMB");
//人民币费用合计
List<InvFeeInfo> fees = invFeeInfoMapper.getListBylink(fee); List<InvFeeInfo> fees = invFeeInfoMapper.getListBylink(fee);
BigDecimal sumfees = fees.stream().map(InvFeeInfo::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add); BigDecimal sumfees = fees.stream().map(InvFeeInfo::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
InvFeeInfo feeNoRmb = new InvFeeInfo(); InvFeeInfo feeNoRmb = new InvFeeInfo();
feeNoRmb.setLinkId(info.getGID()); feeNoRmb.setLinkId(info.getGID());
//非人民币费用合计
List<InvFeeInfo> feesNoRmb = invFeeInfoMapper.getListBylinkNoRmb(feeNoRmb); List<InvFeeInfo> feesNoRmb = invFeeInfoMapper.getListBylinkNoRmb(feeNoRmb);
BigDecimal sumNormbfees = feesNoRmb.stream().map(InvFeeInfo::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add); BigDecimal sumNormbfees = feesNoRmb.stream().map(InvFeeInfo::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
@ -761,40 +768,6 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
invoicepzRmb(fees,link,sumfees); invoicepzRmb(fees,link,sumfees);
//创建非人民币发票 //创建非人民币发票
invoicepzRmb(feesNoRmb,link,sumNormbfees); invoicepzRmb(feesNoRmb,link,sumNormbfees);
//
// List<String> invoiceIds = invInvoiceSplitMapper.getIdsBylinkdId(link.getGID());
//
//// List<InvInvoiceInfo> list = invInvoiceInfoMapper.getByIds(link.getGID());
//
// if(null !=invoiceIds && invoiceIds.size()>0){
// ResponseData data = null;
// for(int i=0;i<invoiceIds.size();i++){
// InvInvoiceInfo invoice = invInvoiceInfoMapper.getByGid(invoiceIds.get(i));
// try {
// data = new ResponseData();
// data = UploadData.doPost(cmdName, getKpData(invoice));
// invoice.setSerialNo(data.getSerialNo());
// invoice.setApiSendTime(df.parse(df.format(new Date())));
// invInvoiceInfoMapper.updateById(invoice);
// } catch (Exception e) {
// e.printStackTrace();
// }
// if( i==0 && 0 != data.getCode()){
// throw new RuntimeException("接口调用失败");
// }
//
// }
// }
//
// if(0 !=1 ){
// throw new RuntimeException("接口调用失败");
// }else{
// return HttpResult.ok("开票成功","");
// }
//
return HttpResult.ok("上传数据成功",""); return HttpResult.ok("上传数据成功","");
} }

Loading…
Cancel
Save