소스 검색

修改发票管理逻辑

y 2 년 전
부모
커밋
9ff50e23e7

+ 1 - 2
src/main/java/com/ydtech/modules/inv/controller/InvAccountIncoiceController.java

@@ -43,8 +43,7 @@ public class InvAccountIncoiceController {
      */
     @Resource
     private InvAccountIncoiceService invAccountIncoiceService;
-    @Autowired
-    private InvAccountOpService invAccountOpService;
+
 
 
     @PostMapping("excel")

+ 48 - 21
src/main/java/com/ydtech/modules/inv/service/impl/InvAccountExcelServiceImpl.java

@@ -14,14 +14,8 @@ import com.ydtech.core.page.PageRequest;
 import com.ydtech.exception.SystemException;
 import com.ydtech.modules.base.controller.BaseController;
 import com.ydtech.modules.inv.dao.InvAccountExcelMapper;
-import com.ydtech.modules.inv.model.InvAccount;
-import com.ydtech.modules.inv.model.InvAccountCard;
-import com.ydtech.modules.inv.model.InvAccountExcel;
-import com.ydtech.modules.inv.model.InvAccountOperate;
-import com.ydtech.modules.inv.service.InvAccountCardService;
-import com.ydtech.modules.inv.service.InvAccountExcelService;
-import com.ydtech.modules.inv.service.InvAccountOperateService;
-import com.ydtech.modules.inv.service.InvAccountService;
+import com.ydtech.modules.inv.model.*;
+import com.ydtech.modules.inv.service.*;
 import com.ydtech.modules.inv.utils.EasyExcelUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -52,6 +46,13 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
     @Autowired
     private EasyExcelUtils easyExcelUtils;
 
+    @Autowired
+    private InvAccountService insAccountService;
+
+    @Autowired
+    private InvAccountOpService insAccountOpService;
+
+
     @Value("${upload.file.path}")
     String uploadFilePath;
 
@@ -110,6 +111,8 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
 
         InvAccountCard outAccountCard = invAccountCardService.getById(invAccountExcel.getOutCardNum());
         InvAccountCard enterAccountCard = invAccountCardService.getById(invAccountExcel.getEnterCardNum());
+        InvAccount outAccount = insAccountService.getById(outAccountCard.getAccountId());
+        InvAccount enterAccount = insAccountService.getById(enterAccountCard.getAccountId());
 
 
         //修改转账状态
@@ -131,8 +134,8 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
             List<InvAccountOperate> list = new ArrayList<>();
             JSONObject outProfit = invAccountExcel.getOutProfit();
             JSONObject entProfit = invAccountExcel.getEntProfit();
-            InvAccountExcel out = outJsonUtil(invAccountExcel, outProfit);
-            InvAccountExcel ent = entJsonUtil(invAccountExcel, entProfit);
+            InvAccountExcel out = outJsonUtil(invAccountExcel, outProfit, outAccount, outAccountCard);
+            InvAccountExcel ent = entJsonUtil(invAccountExcel, entProfit, enterAccount,enterAccountCard);
 
 
             //支出信息
@@ -153,7 +156,7 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
                 throw new RuntimeException("添加转账信息失败");
             }
             JSONObject outProfit = invAccountExcel.getOutProfit();
-            InvAccountExcel out = outJsonUtil(invAccountExcel, outProfit);
+            InvAccountExcel out = outJsonUtil(invAccountExcel, outProfit, outAccount,outAccountCard);
             insAccountOperateService.save(insertOutAccountOperate(out));
 
             //重新将值赋值回去方便编辑
@@ -164,23 +167,47 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
         return HttpResult.ok("", insAccountExcelMapper.updateById(invAccountExcel));
     }
 
-    private InvAccountExcel outJsonUtil(InvAccountExcel invAccountExcel, JSONObject outProfit) {
+    private InvAccountExcel outJsonUtil(InvAccountExcel invAccountExcel, JSONObject outProfit, InvAccount outAccount, InvAccountCard outCard) {
         JSONObject jsonObject = new JSONObject();
-        for (Map.Entry<String, Object> entry : outProfit.entrySet()){
-            BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountExcel.getApplyAmount())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
-            String string = multiply.negate().toString();
-            jsonObject.put(entry.getKey(), string);
+        List<InvAccountOp> list = new ArrayList<>();
+
+        for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
+            if (Integer.parseInt(entry.getValue().toString()) != 0) {
+                InvAccountOp invAccountOp = new InvAccountOp();
+                invAccountOp.setAccountId(outAccount.getAccountId());
+                invAccountOp.setAccountName(outAccount.getAccountName());
+                invAccountOp.setCardNum(outCard.getBankCardNum());
+                invAccountOp.setCardName(outCard.getBankName());
+                invAccountOp.setProfit(entry.getKey());
+                invAccountOp.setMoney(new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountExcel.getApplyAmount())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).negate().toString());
+                BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountExcel.getApplyAmount())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).negate();
+                jsonObject.put(entry.getKey(), multiply);
+                list.add(invAccountOp);
+            }
         }
+        insAccountOpService.saveBatch(list);
         invAccountExcel.setOutProfit(jsonObject);
         return invAccountExcel;
     }
-    private InvAccountExcel entJsonUtil(InvAccountExcel invAccountExcel, JSONObject outProfit) {
+    private InvAccountExcel entJsonUtil(InvAccountExcel invAccountExcel, JSONObject outProfit,InvAccount entAccount,InvAccountCard entCard) {
         JSONObject jsonObject = new JSONObject();
-        for (Map.Entry<String, Object> entry : outProfit.entrySet()){
-            BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountExcel.getApplyAmount())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
-            jsonObject.put(entry.getKey(), multiply);
+        List<InvAccountOp> list = new ArrayList<>();
+        for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
+            if (Integer.parseInt(entry.getValue().toString()) != 0) {
+                InvAccountOp invAccountOp = new InvAccountOp();
+                invAccountOp.setAccountId(entAccount.getAccountId());
+                invAccountOp.setAccountName(entAccount.getAccountName());
+                invAccountOp.setCardNum(entCard.getBankCardNum());
+                invAccountOp.setCardName(entCard.getBankName());
+                invAccountOp.setProfit(entry.getKey());
+                invAccountOp.setMoney(new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountExcel.getApplyAmount())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).toString());
+                BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountExcel.getApplyAmount())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
+                jsonObject.put(entry.getKey(), multiply);
+                list.add(invAccountOp);
+            }
         }
-        invAccountExcel.setOutProfit(jsonObject);
+        insAccountOpService.saveBatch(list);
+        invAccountExcel.setEntProfit(jsonObject);
         return invAccountExcel;
     }
 

+ 46 - 39
src/main/java/com/ydtech/modules/inv/service/impl/InvAccountIncoiceServiceImpl.java

@@ -87,24 +87,23 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
         //进账金额
         String payoutMoney = new BigDecimal(invAccountIncoice.getPayoutMoney()).toString();
         invAccountIncoice1.setPayoutMoney(new BigDecimal(invAccountIncoice1.getPayoutMoney()).add(new BigDecimal(payoutMoney)).toString());
-        invAccountIncoice1.setNotPayoutMoney(new BigDecimal(invAccountIncoice1.getInvoiceMoney()).subtract(new BigDecimal(invAccountIncoice1.getPayoutMoney())).subtract(new BigDecimal(payoutMoney)).toString());
+        invAccountIncoice1.setNotPayoutMoney(new BigDecimal(invAccountIncoice1.getInvoiceMoney()).subtract(new BigDecimal(invAccountIncoice1.getPayoutMoney())).toString());
         invAccountIncoice1.setPayoutTime(invAccountIncoice.getPayoutTime());
 
         if (invAccountIncoice1.getNotPayoutMoney().equals("0")) {
             invAccountIncoice1.setClearFlag("1");
         }
 
-
+        String fundFlow = invAccountIncoice1.getOtherUnit() + "→" + invAccountIncoice1.getInvoiceBy();
         //修改发票增加卡的收入
         InvAccountOperate invAccountOperate = new InvAccountOperate();
         invAccountOperate.setEnterCardId(bankCardNum);
         invAccountOperate.setApplyAmount(payoutMoney);
         invAccountOperate.setRevenueOutlay("0");
-        invAccountOperate.setFundFlow(invAccountIncoice.getFundFlow());
+        invAccountOperate.setFundFlow(fundFlow);
         invAccountOperate.setPayMethod(invAccountIncoice.getPayMethod());
         invAccountOperate.setCompany(invAccountIncoice1.getOtherUnit());
         invAccountOperate.setFundUse(invAccountIncoice.getFundUse());
-        invAccountOperate.setRemark(invAccountIncoice.getRemark());
         invAccountOperate.setFundFen(invAccountIncoice.getFundFen());
         invAccountOperate.setInvoiceId(invAccountIncoice1.getInvoiceId());
         //计算收入百分比
@@ -123,37 +122,37 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
 
 
         List<InvAccountOp> list = new ArrayList<>();
-        for (Map.Entry<String, Object> entry:invAccountOperate.getOutProfit().entrySet()){
-            InvAccountOp invAccountOp = new InvAccountOp();
-            invAccountOp.setAccountId(invAccountIncoice1.getAccountId());
-            invAccountOp.setAccountName(account.getAccountName());
-            invAccountOp.setCardNum(entCard.getBankCardNum());
-            invAccountOp.setCardName(entCard.getBankName());
-            invAccountOp.setProfit(entry.getKey());
-            invAccountOp.setMoney(entry.getValue().toString());
-            invAccountOp.setInvoiceId(invAccountIncoice1.getInvoiceId());
-            list.add(invAccountOp);
+        for (Map.Entry<String, Object> entry : invAccountIncoice.getEntProfit().entrySet()) {
+            if (Integer.parseInt(entry.getValue().toString()) != 0) {
+                InvAccountOp invAccountOp = new InvAccountOp();
+                invAccountOp.setAccountId(invAccountIncoice1.getAccountId());
+                invAccountOp.setAccountName(account.getAccountName());
+                invAccountOp.setCardNum(entCard.getBankCardNum());
+                invAccountOp.setCardName(entCard.getBankName());
+                invAccountOp.setProfit(entry.getKey());
+                invAccountOp.setMoney(new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountIncoice.getPayoutMoney())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).toString());
+                invAccountOp.setInvoiceId(invAccountIncoice1.getInvoiceId());
+                list.add(invAccountOp);
+            }
         }
 
 
-
         //支出操作
         InvAccountOperate outInvAccountOperate = new InvAccountOperate();
-        outInvAccountOperate.setEnterCardId(invAccountIncoice1.getOutBankCardNum());
+        outInvAccountOperate.setEnterCardId(bankCardNum);
         outInvAccountOperate.setApplyAmount(payoutMoney);
         outInvAccountOperate.setRevenueOutlay("1");
-        outInvAccountOperate.setFundFlow(invAccountIncoice.getFundFlow());
+        outInvAccountOperate.setFundFlow(fundFlow);
         outInvAccountOperate.setPayMethod(invAccountIncoice.getPayMethod());
         outInvAccountOperate.setCompany(invAccountIncoice1.getOtherUnit());
         outInvAccountOperate.setFundUse(invAccountIncoice.getFundUse());
         outInvAccountOperate.setFundFen(invAccountIncoice.getFundFen());
-        outInvAccountOperate.setRemark(invAccountIncoice.getRemark());
         outInvAccountOperate.setInvoiceId(invAccountIncoice1.getInvoiceId());
         //计算支出百分比
         JSONObject outProfit = invAccountIncoice.getOutProfit();
         JSONObject outJsonObject = new JSONObject();
         for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
-            BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountIncoice.getPayoutMoney())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
+            BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountIncoice.getPayoutMoney())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).negate();
             outJsonObject.put(entry.getKey(), multiply.negate());
         }
         outInvAccountOperate.setOutProfit(outJsonObject);
@@ -164,22 +163,21 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
         invAccountOperateList.add(invAccountOperate);
 
 
-        for (Map.Entry<String, Object> entry:outInvAccountOperate.getOutProfit().entrySet()){
-            InvAccountOp invAccountOp = new InvAccountOp();
-            invAccountOp.setAccountId(invAccountIncoice1.getAccountId());
-            invAccountOp.setAccountName(account.getAccountName());
-            invAccountOp.setCardNum(outCard.getBankCardNum());
-            invAccountOp.setCardName(outCard.getBankName());
-            invAccountOp.setProfit(entry.getKey());
-            invAccountOp.setMoney(entry.getValue().toString());
-            invAccountOp.setInvoiceId(invAccountIncoice1.getInvoiceId());
-            list.add(invAccountOp);
+        for (Map.Entry<String, Object> entry : outInvAccountOperate.getOutProfit().entrySet()) {
+            if (Integer.parseInt(entry.getValue().toString()) != 0) {
+                InvAccountOp invAccountOp = new InvAccountOp();
+                invAccountOp.setAccountId(invAccountIncoice1.getAccountId());
+                invAccountOp.setAccountName(account.getAccountName());
+                invAccountOp.setCardNum(outCard.getBankCardNum());
+                invAccountOp.setCardName(outCard.getBankName());
+                invAccountOp.setProfit(entry.getKey());
+                invAccountOp.setMoney(new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountIncoice.getPayoutMoney())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).negate().toString());
+                invAccountOp.setInvoiceId(invAccountIncoice1.getInvoiceId());
+                list.add(invAccountOp);
+            }
         }
 
 
-        invAccountOpService.saveBatch(list);
-
-
         //支出卡号
         String outBankCardNum = invAccountIncoice1.getOutBankCardNum();
         //支出账户
@@ -194,13 +192,14 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
         InvAccount outInvAccount = invAccountService.getById(outInvAccountCard.getAccountId());
 
         //转账
-        if (outInvAccount.getOuterFlag().equals("0")){
+        if (outInvAccount.getOuterFlag().equals("0")) {
             if (revInvAccount.getOuterFlag().equals("0")) {
                 InvAccountExcel invAccountExcel = new InvAccountExcel();
                 invAccountExcel.setApplyAmount(invAccountIncoice.getPayoutMoney());
                 List<InvAccountCard> invAccountCards = insideTransfer(outInvAccountCard, revInvAccountCard, invAccountExcel);
                 invAccountCardService.updateBatchById(invAccountCards);
                 invAccountOperateService.saveBatch(invAccountOperateList);
+                invAccountOpService.saveBatch(list);
 
             } else {
                 InvAccountExcel invAccountExcel = new InvAccountExcel();
@@ -209,12 +208,20 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
                 List<InvAccountCard> invAccountCards = enterDeTransfer(outInvAccountCard, revInvAccountCard, invAccountExcel);
                 invAccountCardService.updateBatchById(invAccountCards);
                 invAccountOperateService.saveBatch(invAccountOperateList);
+                invAccountOpService.saveBatch(list);
             }
-        }else {
+        } else {
             InvAccountOperate invAccountOperate1 = new InvAccountOperate();
             invAccountOperate1.setOutCardNum(invAccountIncoice1.getOutBankCardNum());
             invAccountOperate1.setEnterCardId(invAccountIncoice1.getRevBankCardNum());
-            invAccountOperate1.setApplyAmount(invAccountIncoice.getPayoutMoney());
+            invAccountOperate1.setApplyAmount(payoutMoney);
+            invAccountOperate1.setRevenueOutlay("0");
+            invAccountOperate1.setFundFlow(fundFlow);
+            invAccountOperate1.setPayMethod(invAccountIncoice.getPayMethod());
+            invAccountOperate1.setCompany(invAccountIncoice1.getOtherUnit());
+            invAccountOperate1.setFundUse(invAccountIncoice.getFundUse());
+            invAccountOperate1.setFundFen(invAccountIncoice.getFundFen());
+            invAccountOperate1.setInvoiceId(invAccountIncoice1.getInvoiceId());
             invAccountOperateService.insert(invAccountOperate1);
         }
 
@@ -315,12 +322,12 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
             }
         });
         File folder = new File(uploadFilePath);
-        if (folder.exists()){
+        if (folder.exists()) {
             return EasyExcelUtils.downExcel(uploadFilePath, InvAccountIncoice.class, invAccountIncoices);
-        }else {
-            if (folder.mkdirs()){
+        } else {
+            if (folder.mkdirs()) {
                 return EasyExcelUtils.downExcel(uploadFilePath, InvAccountIncoice.class, invAccountIncoices);
-            }else {
+            } else {
                 throw new SystemException("文件导出失败");
             }
 

+ 12 - 8
src/main/java/com/ydtech/modules/inv/service/impl/InvAccountOperateServiceImpl.java

@@ -17,6 +17,8 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Date;
@@ -105,14 +107,16 @@ public class InvAccountOperateServiceImpl extends ServiceImpl<InvAccountOperateM
         List<InvAccountOp> list = new ArrayList<>();
         if (invAccountOperate.getOutProfit()!=null){
             for (Map.Entry<String, Object> entry:invAccountOperate.getOutProfit().entrySet()){
-                InvAccountOp invAccountOp = new InvAccountOp();
-                invAccountOp.setAccountId(enterAccount.getAccountId());
-                invAccountOp.setAccountName(account.getAccountName());
-                invAccountOp.setCardNum(invAccount.getBankCardNum());
-                invAccountOp.setCardName(invAccount.getBankName());
-                invAccountOp.setProfit(entry.getKey());
-                invAccountOp.setMoney(entry.getValue().toString());
-                list.add(invAccountOp);
+                if (Integer.parseInt(entry.getValue().toString()) != 0){
+                    InvAccountOp invAccountOp = new InvAccountOp();
+                    invAccountOp.setAccountId(enterAccount.getAccountId());
+                    invAccountOp.setAccountName(account.getAccountName());
+                    invAccountOp.setCardNum(invAccount.getBankCardNum());
+                    invAccountOp.setCardName(invAccount.getBankName());
+                    invAccountOp.setProfit(entry.getKey());
+                    invAccountOp.setMoney(new BigDecimal(entry.getValue().toString()).multiply(new BigDecimal(invAccountOperate.getApplyAmount())).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString());
+                    list.add(invAccountOp);
+                }
             }
         }
         invAccountOpService.saveBatch(list);