Merge branch 'dev' of cys/gszc into master

master
592468495 6 years ago committed by Gitea
commit fe3c82d0cc

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.gszc.build.Result;
import com.gszc.build.ResultBuilder;
import com.gszc.service.CountService;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@ -31,29 +32,52 @@ public class CountController {
@PostMapping("/VATCount")
@ApiOperation(value = "增值税计算器", notes = "增值税计算器")
@ApiImplicitParams({
@ApiImplicitParam(name = "companyType", value = "公司类型1-有限公司 2-个独、合伙企业", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "companyType", value = "公司类型1-有限公司 2-个人独资企业 3-合伙人企业 4-个体工商户", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "invoiceType", value = "开票类型1-普通发票 2-专用发票)", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "specialInvoiceType", value = "专票类型1-服务业 2-商业),不是专票不用填写", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "taxType", value = "纳税性质个体工商户不必填写1-小规模纳税人 2-一般纳税人服务业3-一般纳税人(商业)", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "oneMoney", value = "第一季度开票金额", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "twoMoney", value = "第二季度开票金额", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "threeMoney", value = "第三季度开票金额", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "fourMoney", value = "第四季度开票金额", dataType = "string", paramType = "query"),
})
public Result VATCount(String companyType,String invoiceType,String specialInvoiceType,double oneMoney,double twoMoney,double threeMoney,double fourMoney) {
public Result VATCount(String companyType,String invoiceType,String taxType,String oneMoney,String twoMoney,String threeMoney,String fourMoney) {
JSONObject oneBigDecimal = null;
JSONObject twoBigDecimal = null;
JSONObject threeBigDecimal = null;
JSONObject fourBigDecimal = null;
JSONObject jsonObject = new JSONObject();
try {
oneBigDecimal = countService.VATCount(companyType,invoiceType,specialInvoiceType,oneMoney);
twoBigDecimal = countService.VATCount(companyType,invoiceType,specialInvoiceType,twoMoney);
threeBigDecimal = countService.VATCount(companyType,invoiceType,specialInvoiceType,threeMoney);
fourBigDecimal = countService.VATCount(companyType,invoiceType,specialInvoiceType,fourMoney);
jsonObject.put("one",oneBigDecimal);
jsonObject.put("two",twoBigDecimal);
jsonObject.put("three",threeBigDecimal);
jsonObject.put("four",fourBigDecimal);
boolean isCounted = false;
if(!"".equals(oneMoney)){
oneBigDecimal = countService.VATCount(companyType,invoiceType,taxType,Double.parseDouble(oneMoney));
jsonObject.put("one",oneBigDecimal);
isCounted = true;
}
if(!"".equals(twoMoney)){
twoBigDecimal = countService.VATCount(companyType,invoiceType,taxType,Double.parseDouble(twoMoney));
jsonObject.put("two",twoBigDecimal);
isCounted = true;
}
if(!"".equals(threeMoney)){
threeBigDecimal = countService.VATCount(companyType,invoiceType,taxType,Double.parseDouble(threeMoney));
jsonObject.put("three",threeBigDecimal);
isCounted = true;
}
if(!"".equals(fourMoney)){
fourBigDecimal = countService.VATCount(companyType,invoiceType,taxType,Double.parseDouble(fourMoney));
jsonObject.put("four",fourBigDecimal);
isCounted = true;
}
if(!isCounted){
return ResultBuilder.error("至少需要计算一个季度").build();
}
} catch (Exception e) {
return ResultBuilder.error("参数错误",e).build();
}

@ -4,46 +4,69 @@ import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.DecimalFormat;
@Service
public class CountService {
public JSONObject VATCount(String companyType,String invoiceType,String specialInvoiceType,double money) throws Exception{
public JSONObject VATCount(String companyType,String invoiceType,String taxType,double money) throws Exception{
JSONObject result = new JSONObject();
if(companyType.equals("1")){//有限公司
result = VATCountDetail(invoiceType, money, specialInvoiceType);
}else if(companyType.equals("2")){//个独、合伙企业
result = VATCountDetail(invoiceType, money, specialInvoiceType);
} else {
throw new Exception("公司类型不正确");
switch (companyType){
case "1": //有限公司
case "2": //个人独资企业
case "3": //合伙人企业
result = VATCountDetail(invoiceType,taxType, money);
break;
case "4": //个体工商户,纳税性质只有小规模纳税人
result = VATCountDetail(invoiceType,"1", money);
break;
default:
throw new Exception("公司类型不正确");
}
return result;
}
private JSONObject VATCountDetail(String invoiceType,double money,String specialInvoiceType) throws Exception{
private JSONObject VATCountDetail(String invoiceType,String taxType,double money) throws Exception{
if(money <= 0){
throw new Exception("金额须大于0");
}
JSONObject jsonObject = new JSONObject();
double result = 0;
double rate = 0;
switch (taxType){
case "1":
rate = 0.033;
break;
case "2":
rate = 0.066;
break;
case "3":
rate = 0.143;
break;
default:
throw new Exception("纳税性质不正确");
}
if(invoiceType.equals("1")){//普票类型
result = money/1.03*0.03;
jsonObject.put("rate",3);
}else if(invoiceType.equals("2")){//专票类型
if(specialInvoiceType.equals("1")){
result = money/1.06*0.06;
jsonObject.put("rate",6);
}else if(specialInvoiceType.equals("2")){
result = money/1.13*0.13;
jsonObject.put("rate",13);
}else {
throw new Exception("专票类型不正确");
if(money <= 300000){
rate = 0;
}
result = money * rate;
}else if(invoiceType.equals("2")){//专票类型
result = money * rate;
}else {
throw new Exception("发票类型不正确");
throw new Exception("开票类型不正确");
}
BigDecimal b = new BigDecimal(result);
BigDecimal r = new BigDecimal(rate * 100);
BigDecimal keep = b.setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal ratePercent = r.setScale(2, BigDecimal.ROUND_HALF_UP);
jsonObject.put("money",keep);
jsonObject.put("rate",ratePercent);
return jsonObject;
}

Loading…
Cancel
Save