|
|
@@ -12,6 +12,7 @@ import com.goafanti.common.enums.NoticeTypes;
|
|
|
import com.goafanti.common.error.BusinessException;
|
|
|
import com.goafanti.common.model.*;
|
|
|
import com.goafanti.common.utils.*;
|
|
|
+import com.goafanti.common.utils.excel.FileUtils;
|
|
|
import com.goafanti.common.utils.excel.NewExcelUtil;
|
|
|
import com.goafanti.common.utils.pdf.PDFUtils;
|
|
|
import com.goafanti.core.mybatis.BaseMybatisDao;
|
|
|
@@ -24,14 +25,25 @@ import com.goafanti.expenseAccount.Enums.EAsecondaryTypes;
|
|
|
import com.goafanti.expenseAccount.bo.*;
|
|
|
import com.goafanti.expenseAccount.service.ExpenseAccountService;
|
|
|
import com.goafanti.organization.bo.OrganizationListOut;
|
|
|
+import com.itextpdf.text.Document;
|
|
|
+import com.itextpdf.text.DocumentException;
|
|
|
+import com.itextpdf.text.Paragraph;
|
|
|
+import com.itextpdf.text.Phrase;
|
|
|
+import com.itextpdf.text.pdf.PdfPCell;
|
|
|
+import com.itextpdf.text.pdf.PdfPRow;
|
|
|
+import com.itextpdf.text.pdf.PdfPTable;
|
|
|
+import com.itextpdf.text.pdf.PdfWriter;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -436,10 +448,139 @@ public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapp
|
|
|
public Object mainExpenseExport(Integer id, HttpServletResponse response) {
|
|
|
MainExpenseAccount mainExpenseAccount = mainExpense(id);
|
|
|
PDFUtils pdfUtils = new PDFUtils();
|
|
|
- pdfUtils.pushMainExpenseExport(mainExpenseAccount,response,uploadPath);
|
|
|
+ pushMainExpenseExport(mainExpenseAccount,response,uploadPath);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ public void pushMainExpenseExport(MainExpenseAccount mainExpenseAccount,HttpServletResponse response, String uploadPath) {
|
|
|
+ String title = "报销明细表";
|
|
|
+ String attName = String.format("报销明细表_%s.pdf",new Date().getTime());
|
|
|
+ String realFileName = uploadPath+"/tmp/"+new Date().getTime() + ".pdf";
|
|
|
+
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
+ Document document=new Document();
|
|
|
+ try {
|
|
|
+ FileUtils.setAttachmentResponseHeader(response, title,attName);
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(realFileName);
|
|
|
+ PdfWriter.getInstance(document, outputStream);
|
|
|
+ document.open();
|
|
|
+ Paragraph paragraph = new Paragraph(title, PDFUtils.getTitleFont());
|
|
|
+ paragraph.setAlignment(1);
|
|
|
+ document.add(paragraph);
|
|
|
+ //默认算60
|
|
|
+ PDFUtils.pushExpenseTitle(document,mainExpenseAccount);
|
|
|
+ PdfPTable table = new PdfPTable(12);
|
|
|
+ ArrayList<PdfPRow> rows = table.getRows();
|
|
|
+ float[] columnWidths ={10,16,10,32,32,32,10,16,12,12,28,28};
|
|
|
+ table.setWidths(columnWidths);
|
|
|
+ table.setSpacingBefore(10f);
|
|
|
+ table.setSpacingAfter(10f);
|
|
|
+ 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);
|
|
|
+ List<SonExpenseAccount> sonList = mainExpenseAccount.getSonList();
|
|
|
+ //序号
|
|
|
+ int index = 0;
|
|
|
+ for (SonExpenseAccount e : sonList) {
|
|
|
+ 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)));
|
|
|
+ }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)));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)));
|
|
|
+ if (index==1){
|
|
|
+ cells1[11] = new PdfPCell(new Phrase(getOrderNoAndDepartment(e,mainExpenseAccount.getApplyDepName()),PDFUtils.getFont(8)));
|
|
|
+ }else {
|
|
|
+ cells1[11] = new PdfPCell(new Phrase("",PDFUtils.getFont(8)));
|
|
|
+ }
|
|
|
+ rows.add(row1);
|
|
|
+ if (detIndex==detList.size()){
|
|
|
+ addCount(e,rows,index);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ document.add(table);
|
|
|
+ document.close();
|
|
|
+ outputStream.close();
|
|
|
+// FileUtils.writeBytes(realFileName, response.getOutputStream());
|
|
|
+// FileUtils.deleteFile(realFileName);
|
|
|
+ } catch (DocumentException | IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 String getOrderNoAndDepartment(SonExpenseAccount e,String applyDepName) {
|
|
|
+ return e.getOrderNo()+"\n"+applyDepName;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getExpenseSecondaryType(SonExpenseAccount e) {
|
|
|
+ return EAsecondaryTypes.getDescByCode(e.getSecondaryType());
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getDetType(SonExpenseAccountDetails det) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getExpenseType(SonExpenseAccount e) {
|
|
|
+ return EATypes.getDescByCode(e.getType());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
private void pushResettingDebit(InputExpenseAccount in, Integer debitId) {
|
|
|
ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(debitId);
|