|
@@ -1,22 +1,26 @@
|
|
package com.bz.smart_city.service.impl.pay;
|
|
package com.bz.smart_city.service.impl.pay;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.bz.smart_city.commom.model.Pagination;
|
|
import com.bz.smart_city.commom.model.Pagination;
|
|
|
|
+import com.bz.smart_city.commom.util.DESDZFP;
|
|
|
|
+import com.bz.smart_city.commom.util.HttpClientUtils;
|
|
|
|
+import com.bz.smart_city.commom.util.RandomUtil;
|
|
import com.bz.smart_city.commom.util.UserUtil;
|
|
import com.bz.smart_city.commom.util.UserUtil;
|
|
import com.bz.smart_city.dto.LoginUser;
|
|
import com.bz.smart_city.dto.LoginUser;
|
|
import com.bz.smart_city.dto.pay.*;
|
|
import com.bz.smart_city.dto.pay.*;
|
|
import com.bz.smart_city.entity.pay.PayBaseAccount;
|
|
import com.bz.smart_city.entity.pay.PayBaseAccount;
|
|
import com.bz.smart_city.entity.pay.PayInvoiceParam;
|
|
import com.bz.smart_city.entity.pay.PayInvoiceParam;
|
|
import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
|
|
import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
|
|
-import com.bz.smart_city.service.pay.PayBaseAccountService;
|
|
|
|
-import com.bz.smart_city.service.pay.PayBaseConfigService;
|
|
|
|
-import com.bz.smart_city.service.pay.PayInvoiceParamService;
|
|
|
|
-import com.bz.smart_city.service.pay.PayPayReceivedService;
|
|
|
|
|
|
+import com.bz.smart_city.service.pay.*;
|
|
|
|
+import com.bz.smart_city.service.pay.archives.PayBaseCustomerandmeterrelaService;
|
|
|
|
+import com.google.gson.JsonObject;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigInteger;
|
|
import java.math.BigInteger;
|
|
|
|
+import java.time.LocalDateTime;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -27,7 +31,7 @@ import java.util.*;
|
|
* @Version V1.0
|
|
* @Version V1.0
|
|
**/
|
|
**/
|
|
@Service
|
|
@Service
|
|
-public class IssueElectronicInvoiceServiceImpl {
|
|
|
|
|
|
+public class IssueElectronicInvoiceServiceImpl implements IssueElectronicInvoiceService {
|
|
@Autowired
|
|
@Autowired
|
|
PayBaseConfigService payBaseConfigService;
|
|
PayBaseConfigService payBaseConfigService;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -36,6 +40,8 @@ public class IssueElectronicInvoiceServiceImpl {
|
|
PayBaseAccountService payBaseAccountService;
|
|
PayBaseAccountService payBaseAccountService;
|
|
@Autowired
|
|
@Autowired
|
|
PayPayReceivedService payPayReceivedService;
|
|
PayPayReceivedService payPayReceivedService;
|
|
|
|
+ @Autowired
|
|
|
|
+ PayBaseCustomerandmeterrelaService payBaseCustomerandmeterrelaService;
|
|
|
|
|
|
private Map<String, String> getPrintParam() {
|
|
private Map<String, String> getPrintParam() {
|
|
Map<String, String> map = new HashMap<>();
|
|
Map<String, String> map = new HashMap<>();
|
|
@@ -43,7 +49,7 @@ public class IssueElectronicInvoiceServiceImpl {
|
|
Pagination<PayBaseConfigDto> payBaseConfigDtoPagination = payBaseConfigService.getAll("PRINT_", 1, 15);
|
|
Pagination<PayBaseConfigDto> payBaseConfigDtoPagination = payBaseConfigService.getAll("PRINT_", 1, 15);
|
|
List<PayBaseConfigDto> payBaseConfigDtos = payBaseConfigDtoPagination.getList();
|
|
List<PayBaseConfigDto> payBaseConfigDtos = payBaseConfigDtoPagination.getList();
|
|
for (PayBaseConfigDto item : payBaseConfigDtos) {
|
|
for (PayBaseConfigDto item : payBaseConfigDtos) {
|
|
- switch (item.getName()) {
|
|
|
|
|
|
+ switch (item.getName().trim()) {
|
|
case "PRINT_INVOICE_ADDRESS":
|
|
case "PRINT_INVOICE_ADDRESS":
|
|
map.put("saleAddress", item.getValue());
|
|
map.put("saleAddress", item.getValue());
|
|
break;
|
|
break;
|
|
@@ -78,14 +84,17 @@ public class IssueElectronicInvoiceServiceImpl {
|
|
}
|
|
}
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
- public BigDecimal saveTwoDecimal(BigDecimal d){
|
|
|
|
- BigDecimal a =d.setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
+
|
|
|
|
+ public BigDecimal saveTwoDecimal(BigDecimal d) {
|
|
|
|
+ BigDecimal a = d.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
return a;
|
|
return a;
|
|
}
|
|
}
|
|
- public BigDecimal saveEightDecimal(BigDecimal d){
|
|
|
|
- BigDecimal a =d.setScale(8,BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
+
|
|
|
|
+ public BigDecimal saveEightDecimal(BigDecimal d) {
|
|
|
|
+ BigDecimal a = d.setScale(8, BigDecimal.ROUND_HALF_UP);
|
|
return a;
|
|
return a;
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @MethodName:
|
|
* @MethodName:
|
|
* @Description: TODO
|
|
* @Description: TODO
|
|
@@ -94,8 +103,7 @@ public class IssueElectronicInvoiceServiceImpl {
|
|
* @Author:
|
|
* @Author:
|
|
* @Date: 2020/7/28
|
|
* @Date: 2020/7/28
|
|
**/
|
|
**/
|
|
- @Async
|
|
|
|
- public void requestPrint(String kpType,String userCode,String payseriesno) {
|
|
|
|
|
|
+ public void requestPrint(String kpType, String userCode, String payseriesno) {
|
|
LoginUser loginUser = UserUtil.getCurrentUser();
|
|
LoginUser loginUser = UserUtil.getCurrentUser();
|
|
String name = loginUser.getName();//操作员姓名
|
|
String name = loginUser.getName();//操作员姓名
|
|
BigInteger siteId = BigInteger.valueOf(loginUser.getSiteId());
|
|
BigInteger siteId = BigInteger.valueOf(loginUser.getSiteId());
|
|
@@ -113,12 +121,18 @@ public class IssueElectronicInvoiceServiceImpl {
|
|
payInvoiceOrderDto.setSaleaddress(invoiceParam.get("saleAddress"));//销方地址
|
|
payInvoiceOrderDto.setSaleaddress(invoiceParam.get("saleAddress"));//销方地址
|
|
payInvoiceOrderDto.setSaletaxnum(invoiceParam.get("saleCode"));//销方税号
|
|
payInvoiceOrderDto.setSaletaxnum(invoiceParam.get("saleCode"));//销方税号
|
|
payInvoiceOrderDto.setChecker(invoiceParam.get("saleChecker"));//复核人
|
|
payInvoiceOrderDto.setChecker(invoiceParam.get("saleChecker"));//复核人
|
|
- payInvoiceOrderDto.setClerk(name);//开票人
|
|
|
|
- payInvoiceOrderDto.setPayee(name);//收款人
|
|
|
|
|
|
+ if(name.length()>4) {
|
|
|
|
+ name = "*" + name.substring(name.length() - 3, name.length());
|
|
|
|
+ payInvoiceOrderDto.setClerk(name);//开票人
|
|
|
|
+ payInvoiceOrderDto.setPayee(name);//收款人
|
|
|
|
+ }
|
|
|
|
+
|
|
payInvoiceOrderDto.setKptype(kpType);//开票类型
|
|
payInvoiceOrderDto.setKptype(kpType);//开票类型
|
|
payInvoiceOrderDto.setTsfs("2");//推送方式
|
|
payInvoiceOrderDto.setTsfs("2");//推送方式
|
|
|
|
+ payInvoiceOrderDto.setInvoicedate(LocalDateTime.now());
|
|
|
|
+ payInvoiceOrderDto.setOrderno(RandomUtil.getRandomString());
|
|
//查询购方相关信息
|
|
//查询购方相关信息
|
|
- PayBaseCustomerandmeterrela payBaseAccount = new PayBaseCustomerandmeterrela();
|
|
|
|
|
|
+ PayBaseCustomerandmeterrela payBaseAccount = payBaseCustomerandmeterrelaService.findAccountByAccountNumber(userCode);
|
|
payInvoiceOrderDto.setBuyername(payBaseAccount.getAccountname());//购方名称
|
|
payInvoiceOrderDto.setBuyername(payBaseAccount.getAccountname());//购方名称
|
|
payInvoiceOrderDto.setPhone(payBaseAccount.getTelephone());//电话
|
|
payInvoiceOrderDto.setPhone(payBaseAccount.getTelephone());//电话
|
|
payInvoiceOrderDto.setAddress(payBaseAccount.getAddress());//地址
|
|
payInvoiceOrderDto.setAddress(payBaseAccount.getAddress());//地址
|
|
@@ -127,9 +141,9 @@ public class IssueElectronicInvoiceServiceImpl {
|
|
|
|
|
|
List<PayInvoiceOrderDetailDto> orderDetailDtos = new ArrayList<>();
|
|
List<PayInvoiceOrderDetailDto> orderDetailDtos = new ArrayList<>();
|
|
//循环加入明细
|
|
//循环加入明细
|
|
- List<PayReceivedInvoiceDto> payReceivedInvoiceDtos = payPayReceivedService.findInvoiceReceivedByPayseriesno(payseriesno,loginUser.getSiteId(),loginUser.getCustomerId());
|
|
|
|
|
|
+ List<PayReceivedInvoiceDto> payReceivedInvoiceDtos = payPayReceivedService.findInvoiceReceivedByPayseriesno(payseriesno, loginUser.getSiteId(), loginUser.getCustomerId());
|
|
//将水费分开,其他类型水费合并todo
|
|
//将水费分开,其他类型水费合并todo
|
|
- for (PayReceivedInvoiceDto item:payReceivedInvoiceDtos) {
|
|
|
|
|
|
+ for (PayReceivedInvoiceDto item : payReceivedInvoiceDtos) {
|
|
PayInvoiceOrderDetailDto orderDetailDto = new PayInvoiceOrderDetailDto();
|
|
PayInvoiceOrderDetailDto orderDetailDto = new PayInvoiceOrderDetailDto();
|
|
PayInvoiceParam payInvoiceParam = invoiceMap.get(item.getFeetype());
|
|
PayInvoiceParam payInvoiceParam = invoiceMap.get(item.getFeetype());
|
|
orderDetailDto.setGoodsname(item.getFeetypename());
|
|
orderDetailDto.setGoodsname(item.getFeetypename());
|
|
@@ -138,22 +152,22 @@ public class IssueElectronicInvoiceServiceImpl {
|
|
//含税标志为0 不含税,税额=round((数量*不含税单价)*税率),2),含税金额=不含税金额+税额
|
|
//含税标志为0 不含税,税额=round((数量*不含税单价)*税率),2),含税金额=不含税金额+税额
|
|
BigDecimal taxAmount = new BigDecimal(0);//税额
|
|
BigDecimal taxAmount = new BigDecimal(0);//税额
|
|
BigDecimal receAmount = item.getReceivedamount();//实收金额
|
|
BigDecimal receAmount = item.getReceivedamount();//实收金额
|
|
- BigDecimal rate =new BigDecimal(payInvoiceParam.getTaxrate());//税率
|
|
|
|
- if(payInvoiceParam.getPricetax().equals("1"))
|
|
|
|
- {
|
|
|
|
- taxAmount = saveTwoDecimal(receAmount.multiply(rate).divide(rate.add(BigDecimal.valueOf(1))));
|
|
|
|
-
|
|
|
|
- }else
|
|
|
|
- {
|
|
|
|
|
|
+ BigDecimal rate = new BigDecimal(payInvoiceParam.getTaxrate());//税率
|
|
|
|
+ if (payInvoiceParam.getPricetax().equals("1")) {
|
|
|
|
+ taxAmount = saveTwoDecimal(receAmount.multiply(rate).divide(rate.add(BigDecimal.valueOf(1)),2, BigDecimal.ROUND_HALF_UP));
|
|
|
|
+ orderDetailDto.setTax(String.valueOf(saveTwoDecimal(taxAmount)));//税额
|
|
|
|
+ orderDetailDto.setTaxfreeamt(String.valueOf(saveTwoDecimal(receAmount.subtract(taxAmount))));//不含税金额
|
|
|
|
+ } else {
|
|
taxAmount = saveTwoDecimal(receAmount.multiply(rate));
|
|
taxAmount = saveTwoDecimal(receAmount.multiply(rate));
|
|
|
|
+ orderDetailDto.setTax(String.valueOf(saveTwoDecimal(taxAmount)));//税额
|
|
|
|
+ orderDetailDto.setTaxfreeamt(String.valueOf(saveTwoDecimal(receAmount.add(taxAmount))));//不含税金额
|
|
}
|
|
}
|
|
- orderDetailDto.setTax(String.valueOf(saveTwoDecimal(taxAmount)));//税额
|
|
|
|
- orderDetailDto.setTaxfreeamt(String.valueOf(saveTwoDecimal(receAmount.subtract(taxAmount))));//不含税金额
|
|
|
|
- if(item.getPrice()!=null) {
|
|
|
|
|
|
+
|
|
|
|
+ if (item.getPrice() != null) {
|
|
orderDetailDto.setPrice(String.valueOf(saveTwoDecimal(item.getPrice())));
|
|
orderDetailDto.setPrice(String.valueOf(saveTwoDecimal(item.getPrice())));
|
|
- orderDetailDto.setNum(String.valueOf(saveEightDecimal(receAmount.subtract(taxAmount).divide(saveTwoDecimal(item.getPrice())))));
|
|
|
|
|
|
+ orderDetailDto.setNum(String.valueOf(receAmount.divide(saveTwoDecimal(item.getPrice()), 8, BigDecimal.ROUND_HALF_UP)));
|
|
}
|
|
}
|
|
- if(!payInvoiceParam.getZerotax().equals("0")) {
|
|
|
|
|
|
+ if (!payInvoiceParam.getZerotax().equals("0")) {
|
|
orderDetailDto.setLslbs(payInvoiceParam.getZerotax());//零税率标志
|
|
orderDetailDto.setLslbs(payInvoiceParam.getZerotax());//零税率标志
|
|
}
|
|
}
|
|
orderDetailDto.setZzstsgl(payInvoiceParam.getOthermanger());//增值税特殊管理
|
|
orderDetailDto.setZzstsgl(payInvoiceParam.getOthermanger());//增值税特殊管理
|
|
@@ -170,6 +184,17 @@ public class IssueElectronicInvoiceServiceImpl {
|
|
orderDetailDtos.add(orderDetailDto);
|
|
orderDetailDtos.add(orderDetailDto);
|
|
}
|
|
}
|
|
payInvoiceOrderDto.setDetail(orderDetailDtos);
|
|
payInvoiceOrderDto.setDetail(orderDetailDtos);
|
|
|
|
+ payInvoiceOrderDto.setEmail("wangyangyang@hxiswater.com");
|
|
payEleInvoiceDto.setOrder(payInvoiceOrderDto);
|
|
payEleInvoiceDto.setOrder(payInvoiceOrderDto);
|
|
|
|
+ //发送开票请求
|
|
|
|
+ String jsonsString = DESDZFP.encrypt(JSON.toJSONString(payEleInvoiceDto));
|
|
|
|
+ Map<String, String> map = new HashMap<String, String>();
|
|
|
|
+ map.put("order", jsonsString);
|
|
|
|
+ try {
|
|
|
|
+ String returnString = HttpClientUtils.doPost("http://nnfpbox.nuonuocs.cn/shop/buyer/allow/cxfKp/cxfServerKpOrderSync.action", map);
|
|
|
|
+ System.out.println("returnString:" + returnString);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|