开票模块发票分配

master
pangyang 3 years ago
parent ec810b73b4
commit 41356f92b1

@ -65,6 +65,10 @@ public class InvLinkInfo {
private BigDecimal rmbFees;
private BigDecimal usdFess;
//发票数量
private int invoiceAmount;
//usd转为人民币金额
private BigDecimal usdInvoiceAmount;
}

@ -197,6 +197,147 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
return split;
}
int getInvoiceAmount(List<InvFeeInfo> fees,InvLinkInfo link,BigDecimal sumfees){
List<InvInvoiceInfo> list = new ArrayList<>();
if(null != fees && fees.size()>0){
BigDecimal checkinvocie = new BigDecimal(0);
if("RMB".equals(fees.get(0).getCurrency())){
checkinvocie = invoiceAmount;
}else{
checkinvocie = invoiceAmount.divide(fees.get(0).getExchangeRate()).setScale(2,BigDecimal.ROUND_HALF_UP);
}
//如果费用总计小于等于最大开票金额
if(checkinvocie.compareTo(sumfees) == 1){
InvInvoiceInfo invoice = new InvInvoiceInfo();
list.add(invoice);
}else{
BigDecimal amount = new BigDecimal(0);
// List<InvInvoiceDetail> details = new ArrayList<>();
List<InvInvoiceSplit> splits = new ArrayList<>();
InvInvoiceInfo invoice = null;
for(int i=0;i<fees.size();i++){
invoice = new InvInvoiceInfo();
InvFeeInfo feeinfo = fees.get(i);
if(i==0){
if(feeinfo.getAmount().compareTo(checkinvocie)==1 || feeinfo.getAmount().compareTo(checkinvocie)==0){
BigDecimal[] results = feeinfo.getAmount().divideAndRemainder(checkinvocie);
int size = results[0].intValue();
for(int m=0;m<size;m++){
invoice = new InvInvoiceInfo();
list.add(invoice);
}
BigDecimal remainAmount = results[1].setScale(2, BigDecimal.ROUND_HALF_UP);
amount = remainAmount;
if(remainAmount.compareTo(new BigDecimal(0))==1){
if((i==fees.size()-1)){
invoice = new InvInvoiceInfo();
list.add(invoice);
}
}
}else{
amount = amount.add(feeinfo.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
}
}else{
amount = amount.add(feeinfo.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
//如果加金额大于指定金额,则不加金额,取前边的数值
if(amount.compareTo(checkinvocie)==1){
BigDecimal checkamount = amount.subtract(feeinfo.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
if(feeinfo.getAmount().compareTo(checkinvocie)==1 || feeinfo.getAmount().compareTo(checkinvocie)==0){
//把以前的
if(checkamount.compareTo(new BigDecimal(0))==1){
invoice = new InvInvoiceInfo();
list.add(invoice);
}
//判断当前金额
BigDecimal[] results = feeinfo.getAmount().divideAndRemainder(checkinvocie);
int size = results[0].intValue();
for(int m=0;m<size;m++){
invoice = new InvInvoiceInfo();
list.add(invoice);
}
BigDecimal remainAmount = results[1].setScale(2, BigDecimal.ROUND_HALF_UP);
amount = remainAmount;
if((i==fees.size()-1) && (amount.compareTo(new BigDecimal(0))== 1)){
invoice = new InvInvoiceInfo();
list.add(invoice);
}
splits = new ArrayList<>();
if(remainAmount.compareTo(new BigDecimal(0))==1){
InvInvoiceSplit split = getInvInvoiceSplit(new InvInvoiceInfo(),new InvInvoiceDetail(),feeinfo,link,amount);
splits.add(split);
}
}else{
//生成发票和发票明细
invoice = new InvInvoiceInfo();
list.add(invoice);
if((i==fees.size()-1) && (feeinfo.getAmount().compareTo(new BigDecimal(0))== 1)){
invoice = new InvInvoiceInfo();
list.add(invoice);
}
amount = feeinfo.getAmount();
}
}else{
//如果amount等于最大开票金额
if(amount.compareTo(checkinvocie)==0){
//生成发票和发票明细
invoice = new InvInvoiceInfo();
list.add(invoice);
amount = new BigDecimal(0);
splits = new ArrayList<>();
}else{
//生成发票分配
InvInvoiceSplit split = getInvInvoiceSplit(new InvInvoiceInfo(),new InvInvoiceDetail(),feeinfo,link,feeinfo.getAmount());
splits.add(split);
if(i==fees.size()-1){
BigDecimal sums = splits.stream().map(InvInvoiceSplit::getAmountTotal).reduce(BigDecimal.ZERO,BigDecimal::add);
invoice = new InvInvoiceInfo();
list.add(invoice);
}
}
}
}
}
}
}
return list.size();
}
void invoicepzRmb(List<InvFeeInfo> fees,InvLinkInfo link,BigDecimal sumfees){
if(null != fees && fees.size()>0){
@ -242,6 +383,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
BigDecimal[] results = feeinfo.getAmount().divideAndRemainder(checkinvocie);
int size = results[0].intValue();
for(int m=0;m<size;m++){
invoice = new InvInvoiceInfo();
BeanUtils.copyProperties(link,invoice);
invoice.setGID(UUID.randomUUID().toString().replace("-", ""));
invoice.setCompId(link.getCompanyId());
@ -256,6 +398,18 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
if(remainAmount.compareTo(new BigDecimal(0))==1){
InvInvoiceSplit split = getInvInvoiceSplit(new InvInvoiceInfo(),new InvInvoiceDetail(),feeinfo,link,amount);
splits.add(split);
if((i==fees.size()-1)){
invoice = new InvInvoiceInfo();
BeanUtils.copyProperties(link,invoice);
invoice.setGID(UUID.randomUUID().toString().replace("-", ""));
invoice.setCompId(link.getCompanyId());
invInvoiceInfoMapper.add(invoice);
InvInvoiceDetail detail = getInvInvoiceDetail(invoice,feeinfo,remainAmount);
invInvoiceDetailMapper.add(detail);
InvInvoiceSplit splitend = getInvInvoiceSplit(invoice, detail,feeinfo,link,remainAmount);
invInvoiceSplitMapper.add(splitend);
}
}
}else{
@ -517,12 +671,20 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
List<InvFeeInfo> fees = invFeeInfoMapper.getListBylink(fee);
BigDecimal sumfees = fees.stream().map(InvFeeInfo::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
int rmbamount = getInvoiceAmount(fees,link,sumfees);
InvFeeInfo feeNoRmb = new InvFeeInfo();
feeNoRmb.setLinkId(info.getGID());
List<InvFeeInfo> feesNoRmb = invFeeInfoMapper.getListBylinkNoRmb(feeNoRmb);
BigDecimal usdfees = feesNoRmb.stream().map(InvFeeInfo::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
int usdamount = getInvoiceAmount(feesNoRmb,link,usdfees);
BigDecimal usdInvoiceAmount = usdfees.multiply(feesNoRmb.get(0).getExchangeRate()).setScale(2,BigDecimal.ROUND_HALF_UP);
link.setUsdInvoiceAmount(usdInvoiceAmount);
link.setInvoiceAmount(rmbamount+usdamount);
link.setBillList(businesses);
link.setRmbFees(sumfees);

Loading…
Cancel
Save