|
|
@@ -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());
|
|
|
}
|
|
|
|