Browse Source

超支费用导出Excel

jiangjc 1 year ago
parent
commit
205847fa4e

+ 265 - 3
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -2798,7 +2798,8 @@ Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> PostGroupExtraCost_Detail(Fin_GroupExtraCostDto_Detail dto)
         {
-            if (dto.Id < 1) { 
+            if (dto.Id < 1)
+            {
                 return Ok(JsonView(false, "查询失败"));
             }
 
@@ -2812,7 +2813,8 @@ Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId
                                                 Where f.IsDel=0 And c.CTable = 1015 
 												And f.Id = {0} ", dto.Id);
             Fin_GroupExtraCostDetailView detailView = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostDetailView>(sql).FirstAsync();
-            if (detailView == null) {
+            if (detailView == null)
+            {
                 return Ok(JsonView(false, "查询失败"));
             }
 
@@ -2887,7 +2889,8 @@ Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId
                         }
                     }
 
-                    if (item.PriceDetailType > 0) {
+                    if (item.PriceDetailType > 0)
+                    {
                         if (dic_setData.ContainsKey(item.PriceDetailType))
                         {
                             item.PriceTypeStr = item.PriceTypeStr + " - " + dic_setData[item.PriceDetailType];
@@ -2984,6 +2987,265 @@ Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId
             return Ok(JsonView(true, "", data));
         }
 
+        /// <summary>
+        /// 超支费用
+        /// 导出团组超支费用Excel
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> PostGroupExtraCost_OutputExcel(Fin_GroupExtraCostExcelDto dto)
+        {
+            string sqlGroup = string.Format(@" Select * From Grp_DelegationInfo WIth(Nolock) where Id = {0} ", dto.diId);
+            Grp_DelegationInfo grp_DelegationInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sqlGroup).FirstAsync();
+            if (grp_DelegationInfo == null)
+            {
+                return Ok(JsonView(false, "导出失败,未查询到团组"));
+            }
+
+            Workbook workbook = new Workbook();
+            Worksheet sheet = workbook.Worksheets[0];
+            Cells cells = sheet.Cells;
+
+            //sheet.Protect(Aspose.Cells.ProtectionType.All, "123123", "");//保护工作表
+            //sheet.Protection.IsSelectingLockedCellsAllowed = true;//设置只能选择解锁单元格
+            //sheet.Protection.IsFormattingColumnsAllowed = true;//设置可以调整列
+            //sheet.Protection.IsFormattingRowsAllowed = true;//设置可以调整行
+
+            #region 数据源
+
+            string sqlData = string.Format(@" Select f.PriceType,REPLACE(s2.[Name],'超支费用','') as PriceTypeStr,'('+REPLACE(s3.[Name],'n','')+')' as PriceDetailTypeStr, PriceDt,PriceName,
+Price,PriceCount,s.[Name] as Currency,PriceSum,f.Remark
+From Fin_GroupExtraCost as f With(Nolock)
+Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
+Inner Join Sys_SetData as s With(Nolock) On f.PriceCurrency = s.Id
+Inner Join Sys_SetData as s2 With(Nolock) On f.PriceType = s2.Id
+Inner Join Sys_SetData as s3 With(Nolock) On f.PriceDetailType = s3.Id
+Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
+Order by PriceType ASC,PriceDt ASC ", dto.diId);
+
+            string sqlDataCount = string.Format(@" Select f.PriceType,COUNT(f.PriceType) as DataCount
+From Fin_GroupExtraCost as f With(Nolock)
+Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
+Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
+Group by PriceType ", dto.diId);
+
+
+
+            List<Fin_GroupExtraCost_ExcelView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelView>(sqlData).ToListAsync();
+            List<Fin_GroupExtraCost_ExcelCountView> countList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelCountView>(sqlDataCount).ToListAsync();
+
+            if (dataList.Count < 1 || countList.Count < 1)
+            {
+                return Ok(JsonView(false, "导出失败,未查询到数据"));
+            }
+
+            #endregion
+
+            #region 标题
+
+
+            string cellValue_Header = grp_DelegationInfo.TeamName;
+
+            //Aspose.Cells.Style style1 = workbook.Styles[workbook.Styles.Add()];//新增样式
+            Aspose.Cells.Style style_Header = workbook.CreateStyle();
+            style_Header.HorizontalAlignment = TextAlignmentType.Center;//文字居中
+            style_Header.VerticalAlignment = TextAlignmentType.Center;
+            style_Header.Font.Name = "微软雅黑";//文字字体
+            style_Header.Font.Size = 18;//文字大小
+            style_Header.IsLocked = false;//单元格解锁
+            style_Header.Font.IsBold = false;//粗体
+            style_Header.Font.Color = Color.FromArgb(255, 0, 0);
+            //style1.ForegroundColor = Color.FromArgb(0x99, 0xcc, 0xff);//设置背景色
+            //style1.Pattern = BackgroundType.Solid; //设置背景样式
+            //style1.IsTextWrapped = true;//单元格内容自动换行
+            style_Header.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
+            style_Header.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
+            style_Header.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
+            style_Header.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
+
+            cells.Merge(1, 1, 1, 10);
+            Aspose.Cells.Range range_header = cells.CreateRange(1, 1, 1, 10);
+            range_header.PutValue(cellValue_Header, false, false);
+            range_header.SetStyle(style_Header);
+            cells.SetRowHeight(1, 35);
+            #endregion
+
+            #region 列名
+
+            Aspose.Cells.Style style_colName = workbook.CreateStyle();
+            style_colName.Name = "colName";
+            style_colName.HorizontalAlignment = TextAlignmentType.Center;//文字居中
+            style_colName.VerticalAlignment = TextAlignmentType.Center;
+            style_colName.Font.Name = "微软雅黑";//文字字体
+            style_colName.Font.Size = 12;//文字大小
+            style_colName.IsLocked = false;//单元格解锁
+            style_colName.Font.IsBold = true;//粗体
+            style_colName.Font.Color = Color.FromArgb(0, 0, 0);
+            style_colName.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
+            style_colName.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
+            style_colName.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
+            style_colName.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
+
+            List<Fin_GroupExtraCostExcelColumnSetting> colNameSettingList = new List<Fin_GroupExtraCostExcelColumnSetting>()
+            {
+                new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 1, columnName="类型", columnWidth= 25},
+                new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 2, columnName="时间", columnWidth= 16},
+                new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 3, columnName="内容", columnWidth= 35},
+                new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 4, columnName="单价", columnWidth= 12},
+                new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 5, columnName="数量", columnWidth= 12},
+                new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 6, columnName="货币", columnWidth= 12},
+                new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 7, columnName="费用", columnWidth= 12},
+                new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 8, columnName="汇率", columnWidth= 12},
+                new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 9, columnName="人民币", columnWidth= 12},
+                new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 10, columnName="备注信息", columnWidth= 24}
+            };
+
+            foreach (var col in colNameSettingList)
+            {
+                cells[2, col.columnIndex].PutValue(col.columnName);
+                cells[2, col.columnIndex].SetStyle(style_colName);
+                cells.SetColumnWidth(col.columnIndex, col.columnWidth);
+            }
+            cells.SetRowHeight(2, 25);
+            #endregion
+
+            #region 数据填充
+            Aspose.Cells.Style style_dataCol = workbook.GetNamedStyle("colName");
+            style_dataCol.Font.IsBold = false;
+            style_dataCol.Name = "dataCol";
+
+            Aspose.Cells.Style style_dataBlue = workbook.CreateStyle();
+            style_dataBlue.HorizontalAlignment = TextAlignmentType.Center;//文字居中
+            style_dataBlue.VerticalAlignment = TextAlignmentType.Center;
+            style_dataBlue.Font.Name = "微软雅黑";//文字字体
+            style_dataBlue.Font.Size = 12;//文字大小
+            style_dataBlue.IsLocked = false;//单元格解锁
+            style_dataBlue.Font.IsBold = false;//粗体
+            style_dataBlue.ForegroundColor = Color.FromArgb(189, 215, 238);
+            style_dataBlue.Pattern = BackgroundType.Solid;
+            style_dataBlue.Font.Color = Color.FromArgb(0, 0, 0);
+            style_dataBlue.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
+            style_dataBlue.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
+            style_dataBlue.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
+            style_dataBlue.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
+
+            Aspose.Cells.Style style_dataYellow = workbook.CreateStyle();
+            style_dataYellow.HorizontalAlignment = TextAlignmentType.Center;//文字居中
+            style_dataYellow.VerticalAlignment = TextAlignmentType.Center;
+            style_dataYellow.Font.Name = "微软雅黑";//文字字体
+            style_dataYellow.Font.Size = 12;//文字大小
+            style_dataYellow.IsLocked = false;//单元格解锁
+            style_dataYellow.Font.IsBold = false;//粗体
+            style_dataYellow.ForegroundColor = Color.FromArgb(255, 242, 204);
+            style_dataYellow.Pattern = BackgroundType.Solid;
+            style_dataYellow.Font.Color = Color.FromArgb(0, 0, 0);
+            style_dataYellow.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
+            style_dataYellow.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
+            style_dataYellow.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
+            style_dataYellow.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
+
+
+
+
+            int rowIndex = 4;
+            foreach (var d in dataList)
+            {
+
+
+                //内容
+                string typeStr = d.PriceTypeStr + d.PriceDetailTypeStr;
+                cells["B" + rowIndex.ToString()].PutValue(typeStr);
+                cells["C" + rowIndex.ToString()].PutValue(d.PriceDtStr);
+                cells["D" + rowIndex.ToString()].PutValue(d.PriceName);
+                cells["E" + rowIndex.ToString()].PutValue(d.Price.ToString("#0.00"));
+                cells["F" + rowIndex.ToString()].PutValue(d.PriceCount);
+                cells["G" + rowIndex.ToString()].PutValue(d.Currency);
+                cells["H" + rowIndex.ToString()].PutValue(d.PriceSum.ToString("#0.00"));
+                cells["K" + rowIndex.ToString()].PutValue(d.Remark);
+
+                //样式
+                cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
+                cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
+                cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
+                cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
+                cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
+                cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
+                cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
+                cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
+                cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
+                cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
+
+                //公式
+                cells["H" + rowIndex.ToString()].Formula = string.Format(@"E{0}*F{0}", rowIndex);
+                cells["J" + rowIndex.ToString()].Formula = string.Format(@"H{0}*I{0}", rowIndex);
+
+                cells.SetRowHeight(rowIndex - 1, 25);
+                rowIndex++;
+            }
+
+            cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
+            cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
+            cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
+            cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
+            cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
+            cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
+            cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
+            cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
+            cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
+            cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
+            rowIndex++;
+            cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
+            cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
+            cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
+            cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
+            cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
+            cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
+            cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
+            cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
+            cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
+            cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
+
+            rowIndex = 3;
+            int tempPriceType = 0;
+            foreach (var c in dataList)
+            {
+                if (tempPriceType == c.PriceType)
+                {
+                    continue;
+                }
+                tempPriceType = c.PriceType;
+                int _rowCount = countList.First(s => s.PriceType == tempPriceType).DataCount;
+                cells.Merge(rowIndex, 1, _rowCount, 1);
+                Aspose.Cells.Range tempRange = cells.CreateRange(rowIndex, 1, _rowCount, 1);
+                rowIndex += _rowCount;
+            }
+
+            rowIndex = 4 + dataList.Count;
+            cells["D" + rowIndex.ToString()].PutValue("合计");
+            cells["J" + rowIndex.ToString()].Formula = string.Format(@"SUM(J4,J{0})", rowIndex - 1);
+            cells.SetRowHeight(rowIndex - 1, 25);
+
+            rowIndex++;
+            cells["D" + rowIndex.ToString()].PutValue("服务费10%开票税金8%");
+            cells["J" + rowIndex.ToString()].Formula = string.Format(@"J{0}*1.1*1.08", rowIndex - 1);
+            cells.SetRowHeight(rowIndex - 1, 25);
+            #endregion
+
+            #region IO
+
+            System.IO.MemoryStream ms = workbook.SaveToStream();//生成数据流
+            string fileName = ("GroupExtraCost/超支费用(" + cellValue_Header + ").xlsx");
+            byte[] bt = ms.ToArray();
+            workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
+            #endregion
+
+            string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
+            return Ok(JsonView(true, "成功", new { url = rst }));
+        }
+
+
         #endregion
     }
 }

+ 16 - 2
OASystem/OASystem.Domain/Dtos/Financial/Fin_GroupExtraCostDto.cs

@@ -97,12 +97,26 @@ namespace OASystem.Domain.Dtos.Financial
     {
         public int diId { get; set; }
     }
-    
-    public class Fin_GroupExtraCostDto_Detail: PortDtoBase {
+
+    public class Fin_GroupExtraCostDto_Detail : PortDtoBase
+    {
         public int Id { get; set; }
     }
 
     public class Fin_GroupExtraCostDto_DataListInit : PortDtoBase
     {
     }
+
+    public class Fin_GroupExtraCostExcelDto : PortDtoBase
+    {
+        public int diId { get; set; }
+    }
+
+    public class Fin_GroupExtraCostExcelColumnSetting
+    {
+        public int columnIndex { get; set; }
+        public string columnName { get; set; }
+        public double columnWidth { get; set; }
+        public int rowCount { get; set; } = 1;
+    }
 }

+ 28 - 1
OASystem/OASystem.Domain/ViewModels/Financial/Fin_GroupExtraCostView.cs

@@ -24,7 +24,7 @@ namespace OASystem.Domain.ViewModels.Financial
         public string PriceDt { get; set; }
         public int IsAuditGM { get; set; }
         public string IsAuditGMStr { get; set; }
-        
+
     }
 
     public class Fin_GroupExtraCostDetailView
@@ -56,4 +56,31 @@ namespace OASystem.Domain.ViewModels.Financial
     {
 
     }
+
+    public class Fin_GroupExtraCost_ExcelCountView {
+        public int PriceType { get; set; }
+        public int DataCount { get; set; }
+    }
+
+    public class Fin_GroupExtraCost_ExcelView
+    {
+        public int PriceType { get; set; }
+        public string PriceTypeStr { get; set; }
+        public string PriceDetailTypeStr { get; set; }
+        public DateTime PriceDt { get; set; }
+        public string PriceDtStr
+        {
+            get
+            {
+                return this.PriceDt.ToString("yyyy-MM-dd");
+            }
+        }
+
+        public string PriceName { get; set; }
+        public decimal Price { get; set; }
+        public int PriceCount { get; set; }
+        public string Currency { get; set; }
+        public decimal PriceSum { get; set; }
+        public string Remark { get; set; }
+    }
 }