調整版型設計
This commit is contained in:
@@ -7,6 +7,7 @@ using NPOI.SS.UserModel;
|
||||
using OfficeOpenXml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -146,10 +147,18 @@ public class statisticsController: ApiController
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
//public static IEnumerable<T> Between<T>(
|
||||
// this IEnumerable<T> source,
|
||||
// T low,
|
||||
// T high) where T : IComparable<T>
|
||||
//{
|
||||
// // 運用 IComparable 比較大小,泛型可支援 int, double, DateTime 等
|
||||
// return source.Where(item => item.CompareTo(low) >= 0 && item.CompareTo(high) <= 0);
|
||||
//}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/statistics/GetStatistic")]
|
||||
public IHttpActionResult GetStatistic(string statistic_mode)
|
||||
public IHttpActionResult GetStatistic(string statistic_mode,string s_date,string e_date)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -166,11 +175,20 @@ public class statisticsController: ApiController
|
||||
LogUtility log = new LogUtility();
|
||||
// 建立分頁
|
||||
var ws = excel.Workbook.Worksheets.Add("MySheet");
|
||||
//var query = _db.activities.AsQueryable();
|
||||
//if (!string.IsNullOrEmpty(s_date))
|
||||
//{
|
||||
// query= query.Where(a => a.startDate_solar.Value.ToString("yyyyMMdd").CompareTo(s_date) >= 0);
|
||||
//}
|
||||
//if (!string.IsNullOrEmpty(e_date))
|
||||
//{
|
||||
// query = query.Where(a => a.endDate_solar.Value.ToString("yyyyMMdd").CompareTo(e_date) <= 0);
|
||||
//}
|
||||
var data = (from a in _db.activities
|
||||
join b in _db.pro_order on a.num equals b.activity_num
|
||||
join c in _db.pro_order_detail on b.order_no equals c.order_no
|
||||
//join d in _db.activity_relating on a.num equals d.activity_num
|
||||
join f in _db.actItems on c.actItem_num equals f.num
|
||||
join f in _db.actItems on c.actItem_num equals f.num
|
||||
select new
|
||||
{
|
||||
a.num,
|
||||
@@ -181,9 +199,19 @@ public class statisticsController: ApiController
|
||||
c.actItem_num,
|
||||
item_subject = f.subject,
|
||||
c.qty,
|
||||
c.price
|
||||
c.price,
|
||||
a.startDate_solar,
|
||||
a.endDate_solar
|
||||
}).ToList();
|
||||
|
||||
if (!string.IsNullOrEmpty(s_date))
|
||||
{
|
||||
data = data.Where(a => a.startDate_solar.Value.ToString("yyyyMMdd").CompareTo(s_date) >= 0).ToList();
|
||||
}
|
||||
if (!string.IsNullOrEmpty(e_date))
|
||||
{
|
||||
data = data.Where(a => a.endDate_solar.Value.ToString("yyyyMMdd").CompareTo(e_date) <= 0).ToList();
|
||||
}
|
||||
int i = 0;
|
||||
i++;
|
||||
if (statistic_mode == "01")
|
||||
@@ -198,7 +226,7 @@ public class statisticsController: ApiController
|
||||
ws.Cells[i, 8].Value = "應收";
|
||||
ws.Cells[i, 9].Value = "應付";
|
||||
i++;
|
||||
var list = data.GroupBy(x => new { x.num, x.subject, x.actItem_num, x.item_subject }).Select(y =>
|
||||
var list = data.ToList().GroupBy(x => new { x.num, x.subject, x.actItem_num, x.item_subject }).Select(y =>
|
||||
new
|
||||
{
|
||||
y.Key.num,
|
||||
@@ -213,8 +241,8 @@ public class statisticsController: ApiController
|
||||
ws.Cells[i, 1].Value = i - 1;
|
||||
ws.Cells[i, 2].Value = item.subject;
|
||||
ws.Cells[i, 3].Value = item.item_subject;
|
||||
ws.Cells[i, 4].Value = item.qty.Value;
|
||||
ws.Cells[i, 5].Value = item.price.Value;
|
||||
ws.Cells[i, 4].Value =item.qty==null?0: item.qty.Value;
|
||||
ws.Cells[i, 5].Value =item.price==null?0: item.price.Value;
|
||||
ws.Cells[i, 6].Formula = $"=D{i}*E{i}";
|
||||
|
||||
var draftList = (from a in drafts
|
||||
@@ -240,13 +268,17 @@ public class statisticsController: ApiController
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var jj = JsonConvert.DeserializeObject<JObject>(items.draft);
|
||||
foreach (var j in jj["pro_order_detail_items"])
|
||||
if (jj["pro_order_detail_items"]!=null)
|
||||
{
|
||||
if (item.subject == j["activity_name"].ToString() &&
|
||||
item.item_subject == j["actitem_name"].ToString())
|
||||
foreach (var j in jj["pro_order_detail_items"])
|
||||
{
|
||||
payed = payed + decimal.Parse(j["reconcile"].ToString());
|
||||
if (item.subject == j["activity_name"].ToString() &&
|
||||
item.item_subject == j["actitem_name"].ToString())
|
||||
{
|
||||
payed = payed + decimal.Parse(j["reconcile"].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -301,7 +333,7 @@ public class statisticsController: ApiController
|
||||
decimal payed = 0;
|
||||
foreach (var d in dd)
|
||||
{
|
||||
payed = payed + (decimal)d.check_amount;// -(decimal)d.remain_amount;
|
||||
payed = payed +d.check_amount==null?0: (decimal)d.check_amount;// -(decimal)d.remain_amount;
|
||||
}
|
||||
ws.Cells[i, 5].Value = payed;
|
||||
ws.Cells[i, 6].Formula = $"=if(D{i}>E{i},D{i}-E{i},0)";
|
||||
@@ -357,7 +389,7 @@ public class statisticsController: ApiController
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Ok(new { result = "N", message = ex.Message});
|
||||
return Ok(new { result = "N", message = ex.Message+ex.StackTrace});
|
||||
//return BadRequest($"{ex.Message}{ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user