Browse Source

报销列表费用明细表新增查看自己的报销

anderx 1 year ago
parent
commit
3cd27c01ac

+ 2 - 1
src/main/java/com/goafanti/common/mapper/ExpenseAccountMapper.xml

@@ -707,7 +707,7 @@
 
 
   <select id="selectByMainId" resultMap="MainMap">
-    select b.id,b.check_no,b.total_amount,b.amount,b.aname,b.apply_dep,b.pay_dep,b.real_amount,b.type_other ,b.aid,
+    select b.id,b.check_no,b.total_amount,b.amount,b.aname,b.apply_dep,b.pay_dep,b.real_amount,b.type_other ,b.aid,b.create_time ,
            date_format(b.create_time,'%Y-%m-%d %H:%i:%S')createTimeStr,b.examine_name, dep.name applyDepName,dep2.name payDepName,
            b.remarks,b.eaaid ,eap.name ,eap.bank ,eap.accounts ,b.status,b.process_status,
            c.id sonId,c.total_amount sonTotalAmount,c.settlement_amount sonSettlementAmount,c.amount sonAmount, c.`type` sonType,c.type_other sonTypeOther,
@@ -755,6 +755,7 @@
     <result column="status" jdbcType="INTEGER" property="status" />
     <result column="process_status" jdbcType="INTEGER" property="processStatus" />
     <result column="createTimeStr" jdbcType="VARCHAR" property="createTimeStr" />
+    <result column="create_Time" jdbcType="TIMESTAMP" property="createTime" />
     <result column="examine_name" jdbcType="VARCHAR" property="examineName" />
     <association property="sonList" resultMap="SonExpenseAccountMap"/>
   </resultMap>

+ 15 - 24
src/main/java/com/goafanti/common/utils/pdf/PDFUtils.java

@@ -1,6 +1,8 @@
 package com.goafanti.common.utils.pdf;
 
 import com.goafanti.RD.bo.OutWordRdDetails;
+import com.goafanti.common.constant.AFTConstants;
+import com.goafanti.common.utils.DateUtils;
 import com.goafanti.common.utils.excel.FileUtils;
 import com.goafanti.expenseAccount.bo.MainExpenseAccount;
 import com.itextpdf.text.*;
@@ -123,38 +125,27 @@ public class PDFUtils {
     private static String   CREATETIME="报销日期:";
     private static String   REMARKS="报销事由:";
     private static String   BANK_ACCOUNT="收款方式:";
+    private static String   BLANK="      ";
     public static void pushExpenseTitle(Document document, MainExpenseAccount mainExpenseAccount) throws DocumentException {
 
-        int  x= CHECKNO.length() + mainExpenseAccount.getCheckNo().length()/2 +
-                APPLYDEP.length() + mainExpenseAccount.getApplyDepName().length() +
-                ANAME.length() + mainExpenseAccount.getAname().length();
+
         StringBuilder builder = new StringBuilder();
-        if (x>55){
-            builder.append(CHECKNO).append(mainExpenseAccount.getCheckNo()).append("          ")
-                    .append(APPLYDEP).append(mainExpenseAccount.getApplyDepName()).append("          ")
-                    .append(ANAME).append(mainExpenseAccount.getAname());
-        }else {
-            int y =(60-x)*2;
-            StringBuilder blank= new StringBuilder();
-            for (int i = 0; i < y; i++) {
-                blank.append(" ");
-            }
-            builder.append(CHECKNO).append(mainExpenseAccount.getCheckNo()).append(blank)
-                    .append(APPLYDEP).append(mainExpenseAccount.getApplyDepName()).append(blank)
+        builder.append(CHECKNO).append(mainExpenseAccount.getCheckNo()).append(BLANK)
+                    .append(APPLYDEP).append(mainExpenseAccount.getApplyDepName()).append(BLANK).append(BLANK).append(BLANK)
                     .append(ANAME).append(mainExpenseAccount.getAname());
-        }
         Paragraph tile1=new Paragraph(builder.toString(),getFont(8));
         document.add(tile1);
-        int x2 = CREATETIME.length() + mainExpenseAccount.getCreateTimeStr().length()/2 +
+        String creactTime= DateUtils.formatDate(mainExpenseAccount.getCreateTime(), AFTConstants.YYYYMMDD);
+        int x2 = CREATETIME.length() + creactTime.length()/2 +
                 REMARKS.length() + mainExpenseAccount.getRemarks().length() +
                 BANK_ACCOUNT.length() + mainExpenseAccount.getBank().length() +
                 mainExpenseAccount.getAccounts().length()/2 + mainExpenseAccount.getName().length();
         builder.setLength(0);
         if (x2>55){
-            builder.append(CREATETIME).append(mainExpenseAccount.getCreateTimeStr()).append("          ")
-                    .append(REMARKS).append(mainExpenseAccount.getRemarks()).append("          ")
-                    .append(BANK_ACCOUNT).append(mainExpenseAccount.getBank()).append("  ")
-                    .append(mainExpenseAccount.getAccounts()).append("  ")
+            builder.append(CREATETIME).append(creactTime).append(BLANK)
+                    .append(REMARKS).append(mainExpenseAccount.getRemarks()).append(BLANK)
+                    .append(BANK_ACCOUNT).append(mainExpenseAccount.getBank()).append(BLANK)
+                    .append(mainExpenseAccount.getAccounts()).append(BLANK)
                     .append(mainExpenseAccount.getName());
         }else {
             int y =(60-x2)*2;
@@ -162,10 +153,10 @@ public class PDFUtils {
             for (int i = 0; i < y; i++) {
                 blank.append(" ");
             }
-            builder.append(CREATETIME).append(mainExpenseAccount.getCreateTimeStr()).append(blank)
+            builder.append(CREATETIME).append(creactTime).append(blank)
                     .append(REMARKS).append(mainExpenseAccount.getRemarks()).append(blank)
-                    .append(BANK_ACCOUNT).append(mainExpenseAccount.getBank()).append(" ")
-                    .append(mainExpenseAccount.getAccounts()).append(" ")
+                    .append(BANK_ACCOUNT).append(mainExpenseAccount.getBank()).append(BLANK)
+                    .append(mainExpenseAccount.getAccounts()).append(BLANK)
                     .append(mainExpenseAccount.getName());
         }
         Paragraph tile2=new Paragraph(builder.toString(),getFont(8));

+ 14 - 0
src/main/java/com/goafanti/expenseAccount/bo/MainExpenseAccount.java

@@ -1,6 +1,9 @@
 package com.goafanti.expenseAccount.bo;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
+
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 
 public class MainExpenseAccount  {
@@ -28,6 +31,7 @@ public class MainExpenseAccount  {
     private String bank;
     private String accounts;
     private String createTimeStr;
+    private Date createTime;
     private String examineName;
     /**
      * 0=非审核,1=当前审核,2=我的订单
@@ -37,6 +41,16 @@ public class MainExpenseAccount  {
 
     private List<SonExpenseAccount> sonList;
 
+
+    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
     public BigDecimal getAmount() {
         return amount;
     }

+ 11 - 7
src/main/java/com/goafanti/expenseAccount/bo/SonExpenseAccount.java

@@ -1,6 +1,9 @@
 package com.goafanti.expenseAccount.bo;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
+
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 
 public class SonExpenseAccount {
@@ -13,8 +16,8 @@ public class SonExpenseAccount {
     private Integer type;
     private String typeOther;
     private String userNames;
-    private String releaseStart;
-    private String releaseEnd;
+    private Date releaseStart;
+    private Date releaseEnd;
     private String districtName;
     private Integer secondaryType;
     private String secondaryTypeOther;
@@ -205,20 +208,21 @@ public class SonExpenseAccount {
     public void setUserNames(String userNames) {
         this.userNames = userNames;
     }
-
-    public String getReleaseStart() {
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
+    public Date getReleaseStart() {
         return releaseStart;
     }
 
-    public void setReleaseStart(String releaseStart) {
+    public void setReleaseStart(Date releaseStart) {
         this.releaseStart = releaseStart;
     }
 
-    public String getReleaseEnd() {
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
+    public Date getReleaseEnd() {
         return releaseEnd;
     }
 
-    public void setReleaseEnd(String releaseEnd) {
+    public void setReleaseEnd(Date releaseEnd) {
         this.releaseEnd = releaseEnd;
     }
 

+ 122 - 69
src/main/java/com/goafanti/expenseAccount/service/impl/ExpenseAccountServiceImpl.java

@@ -478,114 +478,167 @@ public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapp
             //默认算60
             PDFUtils.pushExpenseTitle(document,mainExpenseAccount);
             PdfPTable table = new PdfPTable(12);
+            table.setWidthPercentage(100);
             ArrayList<PdfPRow> rows = table.getRows();
-            float[] columnWidths ={10,16,10,32,32,32,10,16,12,12,28,28};
+            float[] columnWidths ={12,24,14,50,50,42,28,18,12,12,50,50};
             table.setWidths(columnWidths);
             table.setSpacingBefore(10f);
             table.setSpacingAfter(10f);
+            //填充表格头部
+            addTitle(rows);
+            //获取填充数据
+            List<Map<Integer,String>> mapList = pushMainExpenseAccount(mainExpenseAccount);
+            //填充数据写入表格
+            pushTable(rows,mapList);
+            document.add(table);
+            document.close();
+            outputStream.close();
+//            FileUtils.writeBytes(realFileName, response.getOutputStream());
+//            FileUtils.deleteFile(realFileName);
+        } catch (DocumentException | IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    private static void addTitle(ArrayList<PdfPRow> rows) {
+        PdfPCell[] cells =new PdfPCell[12];
+        PdfPRow row=new PdfPRow(cells);
+        cells[0] = new PdfPCell(new Phrase("序号",PDFUtils.getFont(8)));
+        cells[1] = new PdfPCell(new Phrase("费用时间",PDFUtils.getFont(8)));
+        cells[2] = new PdfPCell(new Phrase("时长",PDFUtils.getFont(8)));
+        cells[3] = new PdfPCell(new Phrase("出差地址",PDFUtils.getFont(8)));
+        cells[4] = new PdfPCell(new Phrase("出差企业",PDFUtils.getFont(8)));
+        cells[5] = new PdfPCell(new Phrase("合同编号",PDFUtils.getFont(8)));
+        cells[6] = new PdfPCell(new Phrase("类型",PDFUtils.getFont(8)));
+        cells[7] = new PdfPCell(new Phrase("详情",PDFUtils.getFont(8)));
+        cells[8] = new PdfPCell(new Phrase("费用",PDFUtils.getFont(8)));
+        cells[9] = new PdfPCell(new Phrase("实报",PDFUtils.getFont(8)));
+        cells[10] = new PdfPCell(new Phrase("出差事由",PDFUtils.getFont(8)));
+        cells[11] = new PdfPCell(new Phrase("报销订单/部门",PDFUtils.getFont(8)));
+        rows.add(row);
+    }
+
+    private void pushTable(ArrayList<PdfPRow> rows, List<Map<Integer, String>> mapList) {
+        for (Map<Integer, String> map : mapList) {
             PdfPCell[] cells =new PdfPCell[12];
             PdfPRow row=new PdfPRow(cells);
-            cells[0] = new PdfPCell(new Phrase("序号",PDFUtils.getFont(8)));
-            cells[1] = new PdfPCell(new Phrase("费用时间",PDFUtils.getFont(8)));
-            cells[2] = new PdfPCell(new Phrase("时长",PDFUtils.getFont(8)));
-            cells[3] = new PdfPCell(new Phrase("出差地址",PDFUtils.getFont(8)));
-            cells[4] = new PdfPCell(new Phrase("出差企业",PDFUtils.getFont(8)));
-            cells[5] = new PdfPCell(new Phrase("合同编号",PDFUtils.getFont(8)));
-            cells[6] = new PdfPCell(new Phrase("类型",PDFUtils.getFont(8)));
-            cells[7] = new PdfPCell(new Phrase("详情",PDFUtils.getFont(8)));
-            cells[8] = new PdfPCell(new Phrase("费用",PDFUtils.getFont(8)));
-            cells[9] = new PdfPCell(new Phrase("实报",PDFUtils.getFont(8)));
-            cells[10] = new PdfPCell(new Phrase("出差事由",PDFUtils.getFont(8)));
-            cells[11] = new PdfPCell(new Phrase("报销订单/部门",PDFUtils.getFont(8)));
+            for (int i = 0; i < 12; i++) {
+                cells[i] = new PdfPCell(new Phrase(map.get(i),PDFUtils.getFont(8)));
+            }
             rows.add(row);
-            List<SonExpenseAccount> sonList = mainExpenseAccount.getSonList();
-            //序号
-            int index = 0;
-            for (SonExpenseAccount e : sonList) {
+        }
+    }
+
+    private List<Map<Integer, String>> pushMainExpenseAccount(MainExpenseAccount mainExpenseAccount) {
+        List<Map<Integer,String>> mapList = new ArrayList<>();
+        if (mainExpenseAccount.getSonList()!=null){
+            int index=0;
+            for (SonExpenseAccount e : mainExpenseAccount.getSonList()) {
                 List<SonExpenseAccountDetails> detList = e.getDetList();
                 //详情计算,详情完成后需要一个统计
                 int detIndex = 0;
                 for (SonExpenseAccountDetails det : detList) {
                     index++;
                     detIndex++;
-                    PdfPCell[] cells1 =new PdfPCell[12];
-                    PdfPRow row1=new PdfPRow(cells1);
-                    cells1[0] = new PdfPCell(new Phrase(String.valueOf(index),PDFUtils.getFont(8)));
-                    cells1[1] = new PdfPCell(new Phrase(det.getAgreeTime(),PDFUtils.getFont(8)));
-                    if (e.getPublicReleaseType()!=null){
-                        cells1[2] = new PdfPCell(new Phrase(e.getDuration(),PDFUtils.getFont(8)));
-                        cells1[3] = new PdfPCell(new Phrase(e.getDistrictName(),PDFUtils.getFont(8)));
-                        cells1[4] = new PdfPCell(new Phrase(e.getUserNames(),PDFUtils.getFont(8)));
+                    Map<Integer, String> map = new HashMap<>();
+                    map.put(0, String.valueOf(index));
+                    if (detIndex==1){
+                        if (e.getPublicReleaseType()!=null){
+                            map.put(1,DateUtils.formatDate(e.getReleaseStart(),AFTConstants.YYYYMMDDHHMM)+"~"+DateUtils.formatDate(e.getReleaseEnd(),AFTConstants.YYYYMMDDHHMM));
+                            map.put(2,e.getDuration());
+                            map.put(3,e.getDistrictName());
+                            map.put(4,e.getUserNames());
+                            map.put(6,getExpenseType(e));
+                        }else {
+                            map.put(1,det.getAgreeTime());
+                            map.put(2,"");
+                            map.put(3,"");
+                            map.put(4,"");
+                            map.put(6,"");
+                        }
                     }else {
-                        cells1[2] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
-                        cells1[3] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
-                        cells1[4] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
+                        map.put(1,det.getAgreeTime());
+                        map.put(2,"");
+                        map.put(3,"");
+                        map.put(4,"");
+                        map.put(6,"");
                     }
 
-                    cells1[5] = new PdfPCell(new Phrase(e.getContractNo(),PDFUtils.getFont(8)));
-                    cells1[6] = new PdfPCell(new Phrase(getExpenseType(e),PDFUtils.getFont(8)));
-                    cells1[7] = new PdfPCell(new Phrase(getExpenseSecondaryType(e),PDFUtils.getFont(8)));
-                    cells1[8] = new PdfPCell(new Phrase(det.getAmount().stripTrailingZeros().toEngineeringString(),PDFUtils.getFont(8)));
-                    cells1[9] = new PdfPCell(new Phrase(det.getRealAmount().stripTrailingZeros().toEngineeringString(),PDFUtils.getFont(8)));
-                    cells1[10] = new PdfPCell(new Phrase(e.getPlan(),PDFUtils.getFont(8)));
+                    map.put(5,e.getContractNo());
+                    map.put(7,getExpenseSecondaryType(e,det));
+                    map.put(8,getBigDecimalZeros(det.getAmount()));
+                    map.put(9,getBigDecimalZeros(det.getRealAmount()));
+                    map.put(10,e.getPlan());
                     if (index==1){
-                        cells1[11] = new PdfPCell(new Phrase(getOrderNoAndDepartment(e,mainExpenseAccount.getApplyDepName()),PDFUtils.getFont(8)));
+                        map.put(11,getOrderNoAndDepartment(e,mainExpenseAccount.getApplyDepName()));
                     }else {
-                        cells1[11] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
+                        map.put(11,"");
                     }
-                    rows.add(row1);
+                    mapList.add(map);
                     if (detIndex==detList.size()){
-                        addCount(e,rows,index);
+                        index++;
+                        addCount(e.getAmount(),e.getRealAmount(),mapList,index);
                     }
                 }
-
             }
-
-
-            document.add(table);
-            document.close();
-            outputStream.close();
-//            FileUtils.writeBytes(realFileName, response.getOutputStream());
-//            FileUtils.deleteFile(realFileName);
-        } catch (DocumentException | IOException e) {
-            e.printStackTrace();
+            //循环结束新增合计
+            index++;
+            addCount(mainExpenseAccount.getAmount(),mainExpenseAccount.getRealAmount(),mapList,index,1);
         }
+        return  mapList;
+    }
 
+    private String getBigDecimalZeros(BigDecimal amount) {
+        return amount.stripTrailingZeros().toEngineeringString();
     }
 
-    private void addCount(SonExpenseAccount e,ArrayList<PdfPRow> rows,int index) {
-        index++;
-        PdfPCell[] cells =new PdfPCell[12];
-        PdfPRow row=new PdfPRow(cells);
-        cells[0] = new PdfPCell(new Phrase(String.valueOf(index),PDFUtils.getFont(8)));
-        cells[1] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
-        cells[2] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
-        cells[3] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
-        cells[4] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
-        cells[5] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
-        cells[6] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
-        cells[7] = new PdfPCell(new Phrase("小计",PDFUtils.getFont(8)));
-        cells[8] = new PdfPCell(new Phrase(e.getAmount().stripTrailingZeros().toEngineeringString(),PDFUtils.getFont(8)));
-        cells[9] = new PdfPCell(new Phrase(e.getRealAmount().stripTrailingZeros().toEngineeringString(),PDFUtils.getFont(8)));
-        cells[10] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
-        cells[11] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
-        rows.add(row);
+    private void addCount(BigDecimal amount,BigDecimal realAmount,List<Map<Integer, String>> mapList,int index) {
+        addCount(amount,realAmount,mapList,index,0);
+    }
+    private void addCount(BigDecimal amount,BigDecimal realAmount,List<Map<Integer, String>> mapList,int index,int type) {
+        String str="小计";
+        if (type==1)str="合计";
+        Map<Integer, String> map = new HashMap<>();
+        for (int i = 0; i < 12; i++){
+            if (i==0){
+                map.put(i, String.valueOf(index));
+            }else if (i==7){
+                map.put(i, str);
+            }else if (i==8){
+                map.put(i, getBigDecimalZeros(amount));
+            }else if (i==9){
+                map.put(i, getBigDecimalZeros(realAmount));
+            }else {
+                map.put(i, "");
+            }
+        }
+        mapList.add(map);
     }
 
 
+
     private String getOrderNoAndDepartment(SonExpenseAccount e,String applyDepName) {
         return e.getOrderNo()+"\n"+applyDepName;
     }
 
-    private String getExpenseSecondaryType(SonExpenseAccount e) {
+    private String getExpenseSecondaryType(SonExpenseAccount e,SonExpenseAccountDetails det) {
+        if (e.getType()==1){
+            if (det.getType()==1){
+                //交通工具待完善
+            }
+        }
+        if (e.getSecondaryType()==0){
+            return EAsecondaryTypes.getDescByCode(e.getSecondaryType())+"("+e.getSecondaryTypeOther()+")";
+        }
         return EAsecondaryTypes.getDescByCode(e.getSecondaryType());
     }
 
-    private String getDetType(SonExpenseAccountDetails det) {
-        return null;
-    }
 
     private String getExpenseType(SonExpenseAccount e) {
+        if (e.getType()==0){
+            return EATypes.getDescByCode(e.getType())+"("+e.getTypeOther()+")";
+        }
         return EATypes.getDescByCode(e.getType());
     }