modify
This commit is contained in:
@@ -2,16 +2,20 @@
|
||||
using MINOM.COM.Utility;
|
||||
using Model;
|
||||
using Newtonsoft.Json;
|
||||
using OfficeOpenXml;
|
||||
using Org.BouncyCastle.Crypto;
|
||||
using Org.BouncyCastle.Crypto.Tls;
|
||||
using PagedList;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Web.Services;
|
||||
using static TreeView;
|
||||
@@ -2165,4 +2169,78 @@ string sortBy = "", bool sortDesc = false)
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/activity/ComparePreAndOrder")]
|
||||
public IHttpActionResult ComparePreAndOrder([FromBody] Model.ViewModel.activity act)
|
||||
{
|
||||
//用活動撈pre_order
|
||||
//檢查pro_order_detail 的數量跟金額與pre_order登記是否相符
|
||||
var qry = _db.pre_order.AsQueryable();
|
||||
qry = qry.Where(x => x.act_num == act.num);
|
||||
var dqry = _db.pro_order_detail.AsQueryable();
|
||||
dqry = dqry.Where(y => _db.pro_order.Where(z => z.activity_num == act.num).Select(z => z.order_no).ToList().Contains(y.order_no));
|
||||
|
||||
var list = qry.Select(x => new
|
||||
{
|
||||
x.num,
|
||||
x.order_no,
|
||||
x.reg_time,
|
||||
x.receipt_num,
|
||||
x.item_count,
|
||||
x.f_num,
|
||||
x.total_amt,
|
||||
x.admin_num,
|
||||
act_name=_db.activities.Where(w=>w.num==act.num).Select(w=>w.subject).FirstOrDefault(),
|
||||
f_name=_db.followers.Where(z=>z.num==x.f_num).Select(z=>z.u_name).FirstOrDefault(),
|
||||
order_amt=dqry.Where(y=>y.order_no==x.order_no).Sum(y=>y.qty*y.price),
|
||||
order_count=dqry.Where(y=> y.order_no == x.order_no&&!y.parent_num.HasValue).ToList().Count(),
|
||||
}).ToList();
|
||||
string rootPath = HttpRuntime.AppDomainAppPath;
|
||||
string name = $"output{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
|
||||
string fileName = Path.Combine(new string[] { rootPath, "rpt", name });
|
||||
|
||||
var file = new FileInfo($"{fileName}"); // 檔案路徑
|
||||
using (var excel = new ExcelPackage())
|
||||
{
|
||||
LogUtility log = new LogUtility();
|
||||
// 建立分頁
|
||||
var ws = excel.Workbook.Worksheets.Add("MySheet");
|
||||
int i = 0;
|
||||
i++;
|
||||
ws.Cells[i, 1].Value = "序號";
|
||||
ws.Cells[i, 2].Value = "法會名稱";
|
||||
ws.Cells[i, 3].Value = "信眾";
|
||||
ws.Cells[i, 4].Value = "登記數量";
|
||||
ws.Cells[i, 5].Value = "登記金額";
|
||||
ws.Cells[i, 6].Value = "報名數量";
|
||||
ws.Cells[i, 7].Value = "報名金額";
|
||||
ws.Cells[i, 8].Value = "是否相符";
|
||||
i++;
|
||||
foreach (var data in list)
|
||||
{
|
||||
ws.Cells[i, 1].Value = i-1;
|
||||
ws.Cells[i, 2].Value =data.act_name;
|
||||
ws.Cells[i, 3].Value = data.f_name;
|
||||
ws.Cells[i, 4].Value = data.item_count;
|
||||
ws.Cells[i, 5].Value = data.total_amt;
|
||||
ws.Cells[i, 6].Value = data.order_count;
|
||||
ws.Cells[i, 7].Value = data.order_amt;
|
||||
|
||||
if (data.total_amt != data.order_amt || data.item_count != data.order_count)
|
||||
{
|
||||
ws.Cells[i, 8].Value = "否";
|
||||
}
|
||||
else
|
||||
{
|
||||
ws.Cells[i, 8].Value = "是";
|
||||
}
|
||||
}
|
||||
excel.SaveAs(file);
|
||||
}
|
||||
|
||||
return Ok(new { result = "Y", filename = $"rpt/{name}" });
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user