統計報表,批次報名
This commit is contained in:
@@ -16,6 +16,7 @@ namespace Model.ViewModel
|
||||
// TODO: 在這裡新增建構函式邏輯
|
||||
//
|
||||
}
|
||||
public int id { get; set; }
|
||||
public int num { get; set; }
|
||||
public int kind { get; set; }
|
||||
|
||||
@@ -24,19 +25,25 @@ namespace Model.ViewModel
|
||||
public string subject { get; set; }
|
||||
public string u_name { get; set; }
|
||||
public string pay_type { get; set; }
|
||||
public double amount { get; set; }
|
||||
public decimal amount { get; set; }
|
||||
|
||||
public double price { get; set; }
|
||||
public float price { get; set; }
|
||||
public string pay_mode { get; set; }
|
||||
public string status { get; set; }
|
||||
public int f_num { get; set; }
|
||||
public int acc_num { get; set; }
|
||||
public int acc_kind { get; set; }
|
||||
public double check_amount { get; set; }
|
||||
public double remain_amount { get; set; }
|
||||
public decimal check_amount { get; set; }
|
||||
public decimal remain_amount { get; set; }
|
||||
|
||||
public string check_status { get; set; }
|
||||
public int actItem_num { get; set; }
|
||||
public string draft { get; set; }
|
||||
public int qty { get; set; }
|
||||
public int d_num { get; set; }
|
||||
|
||||
public string s_date { get; set; }
|
||||
public string e_date { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +1,26 @@
|
||||
using Model.ViewModel;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Model.ViewModel;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Results;
|
||||
|
||||
/// <summary>
|
||||
/// StatisticController 的摘要描述
|
||||
/// </summary>
|
||||
public class StatisticController : BaseApiController
|
||||
{
|
||||
|
||||
|
||||
public StatisticController()
|
||||
{
|
||||
//
|
||||
@@ -19,45 +28,6 @@ public class StatisticController : BaseApiController
|
||||
//
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/Statistic/GetStatistic")]
|
||||
public IHttpActionResult GetStatistic([FromBody] Model.ViewModel.statistic s,string statistic_mode)
|
||||
{
|
||||
//statistic_mode :依法會 依信眾 依分類 依付款方式
|
||||
var sqlstr = new StringBuilder(@"with o1 (order_no,price) as (
|
||||
select order_no,sum(isnull(price,0)) as price from pro_order_detail
|
||||
group by order_no
|
||||
)
|
||||
select a.num,a.kind,d.kind kindName,a.subject,isnull(b.order_no,'') order_no,isnull(c.u_name,'') u_name,
|
||||
isnull(bill.pay_type,'') pay_type,o1.price,bill.amount,bill.pay_mode,bill.status,bill.f_num,
|
||||
bill.acc_num,bill.acc_kind,isnull(bill.check_amount,0) check_amount,
|
||||
isnull(bill.remain_amount,0) remain_amount,isnull(bill.check_status,'') check_status
|
||||
from activity a
|
||||
left join pro_order b on a.num=b.activity_num
|
||||
left join transfer_register bill on a.num=bill.activity_num
|
||||
and bill.f_num=b.f_num
|
||||
left join followers c on b.f_num=c.num
|
||||
left join activity_kind d on a.kind=d.num
|
||||
left join o1 on o1.order_no=b.order_no
|
||||
where 1=1 ");
|
||||
var parameters = new List<SqlParameter>();
|
||||
if (s.num!=0)
|
||||
{//查法會
|
||||
sqlstr.Append(" and num=@num ");
|
||||
parameters.Add(new SqlParameter("@num",s.num));
|
||||
}
|
||||
if (s.kind != 0)
|
||||
{//查法會類型
|
||||
sqlstr.Append(" and kind=@kind ");
|
||||
parameters.Add(new SqlParameter("@kind",s.kind));
|
||||
}
|
||||
if (s.f_num != 0)
|
||||
{//查信眾
|
||||
sqlstr.Append(" and f_num=@f_num ");
|
||||
parameters.Add(new SqlParameter("@f_num", s.f_num));
|
||||
}
|
||||
var list=_db.Database.SqlQuery<statistic>(sqlstr.ToString(),parameters.ToArray()).ToList();
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,16 @@
|
||||
using System;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using MINOM.COM.Utility;
|
||||
using Model.ViewModel;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NPOI.SS.UserModel;
|
||||
using OfficeOpenXml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
|
||||
@@ -135,4 +145,207 @@ public class statisticsController: ApiController
|
||||
};
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/statistics/GetStatistic")]
|
||||
public IHttpActionResult GetStatistic(string statistic_mode)
|
||||
{
|
||||
try
|
||||
{
|
||||
var drafts = (from a in _db.transfer_register
|
||||
select a).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");
|
||||
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
|
||||
select new
|
||||
{
|
||||
a.num,
|
||||
a.subject,
|
||||
b.order_no,
|
||||
b.f_num,
|
||||
order_detail_num = c.num,
|
||||
c.actItem_num,
|
||||
item_subject = f.subject,
|
||||
c.qty,
|
||||
c.price
|
||||
}).ToList();
|
||||
|
||||
int i = 0;
|
||||
i++;
|
||||
if (statistic_mode == "01")
|
||||
{
|
||||
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 = "應收";
|
||||
ws.Cells[i, 9].Value = "應付";
|
||||
i++;
|
||||
var list = data.GroupBy(x => new { x.num, x.subject, x.actItem_num, x.item_subject }).Select(y =>
|
||||
new
|
||||
{
|
||||
y.Key.num,
|
||||
y.Key.subject,
|
||||
y.Key.actItem_num,
|
||||
y.Key.item_subject,
|
||||
qty = y.Where(q => q.num == y.Key.num && q.actItem_num == y.Key.actItem_num).Select(q => q.qty).Sum(),
|
||||
price = y.Where(p => p.num == y.Key.num && p.actItem_num == y.Key.actItem_num).Select(p => p.price).FirstOrDefault()
|
||||
}).ToList();
|
||||
foreach (var item in list)
|
||||
{
|
||||
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, 6].Formula = $"=D{i}*E{i}";
|
||||
|
||||
var draftList = (from a in drafts
|
||||
where a.activity_num == item.num
|
||||
select a).ToList();
|
||||
decimal payed = 0;
|
||||
foreach (var items in draftList)
|
||||
{
|
||||
if (items.draft != null)
|
||||
{
|
||||
var jj = JsonConvert.DeserializeObject<JArray>(items.draft);
|
||||
log.writeLogPath(jj.ToString());
|
||||
foreach (var j in jj)
|
||||
{
|
||||
if (item.subject == j["activity_name"].ToString() &&
|
||||
item.item_subject == j["actitem_name"].ToString())
|
||||
{
|
||||
payed = payed + decimal.Parse(j["reconcile"].ToString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
ws.Cells[i, 7].Value = payed;
|
||||
ws.Cells[i, 8].Formula = $"=if(F{i}>G{i},F{i}-G{i},0)";
|
||||
ws.Cells[i, 9].Formula = $"=if(F{i}<G{i},G{i}-F{i},0)";
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
else if (statistic_mode == "02")
|
||||
{
|
||||
var list = (from a in _db.pro_order
|
||||
join b in _db.pro_order_detail on a.order_no equals b.order_no
|
||||
join c in _db.followers on a.f_num equals c.num
|
||||
join d in _db.activities on a.activity_num equals d.num
|
||||
select new
|
||||
{
|
||||
a.order_no,
|
||||
a.f_num,
|
||||
a.activity_num,
|
||||
b.qty,
|
||||
b.price,
|
||||
c.u_name
|
||||
}).ToList();
|
||||
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 = "應付";
|
||||
i++;
|
||||
var g = list.GroupBy(y => new { y.f_num, y.u_name }).Select(y => new
|
||||
{
|
||||
y.Key.f_num,
|
||||
y.Key.u_name,
|
||||
total = y.Where(x => x.f_num == y.Key.f_num).Select(x => x.price * x.qty).Sum()
|
||||
});
|
||||
foreach (var item in g)
|
||||
{
|
||||
ws.Cells[i, 1].Value = i - 1;
|
||||
ws.Cells[i, 2].Value = item.f_num;
|
||||
ws.Cells[i, 3].Value = item.u_name;
|
||||
ws.Cells[i, 4].Value = item.total;
|
||||
var dd = (from a in drafts
|
||||
where a.f_num == item.f_num
|
||||
select a).ToList();
|
||||
decimal payed = 0;
|
||||
foreach (var d in dd)
|
||||
{
|
||||
payed = payed + (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)";
|
||||
ws.Cells[i, 7].Formula = $"=if(D{i}<E{i},E{i}-D{i},0)";
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else if (statistic_mode == "03")
|
||||
{
|
||||
var list = (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.followers on b.f_num equals d.num
|
||||
select new
|
||||
{
|
||||
a.num,a.subject,b.order_no,order_detail_num=c.num,
|
||||
b.f_num,d.u_name,c.price,c.qty
|
||||
}).ToList();
|
||||
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 = "應付";
|
||||
i++;
|
||||
var g = list.GroupBy(y => new { y.num, y.subject, y.f_num, y.u_name }).Select(y=>new
|
||||
{
|
||||
y.Key.num,y.Key.subject,y.Key.f_num,y.Key.u_name,
|
||||
total=y.Where(x=>x.num==y.Key.num&&x.f_num==y.Key.f_num).Select(x=>x.price*x.qty).Sum()
|
||||
});
|
||||
foreach (var item in g)
|
||||
{
|
||||
ws.Cells[i, 1].Value = i - 1;
|
||||
ws.Cells[i, 2].Value = item.subject;
|
||||
ws.Cells[i, 3].Value = item.u_name;
|
||||
ws.Cells[i, 4].Value = item.total;
|
||||
var dd = drafts.Where (y=>y.activity_num==item.num&&y.f_num==item.f_num).
|
||||
Select(y => new { y.check_amount, y.remain_amount }).ToList();
|
||||
|
||||
ws.Cells[i, 5].Value = dd.Sum(y=>y.check_amount);
|
||||
ws.Cells[i, 6].Formula = $"=if(D{i}>E{i},D{i}-E{i},0)";
|
||||
ws.Cells[i, 7].Formula = $"=if(D{i}<E{i},E{i}-D{i},0)";
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// 儲存 Excel
|
||||
excel.SaveAs(file);
|
||||
}
|
||||
|
||||
return Ok(new { result = "Y", filename = $"rpt/{name}" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Ok(new { result = "N", message = ex.Message});
|
||||
//return BadRequest($"{ex.Message}{ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -161,7 +161,18 @@
|
||||
<span class="badge bg-secondary">會計</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<a @click="statistic_query()" class="list-group-item list-group-item-action">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
<div class="d-flex">
|
||||
<i class="bi bi-file-spreadsheet text-secondary me-3 function-icon"></i>
|
||||
<div>
|
||||
<div>統計報表</div>
|
||||
<small class="text-muted"></small>
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge bg-secondary">會計</span>
|
||||
</div>
|
||||
</a>
|
||||
<%-- <a @click="balance_query()" class="list-group-item list-group-item-action">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
<div class="d-flex">
|
||||
@@ -235,10 +246,15 @@
|
||||
'personal-component': httpVueLoader('./personal_reconcile.vue'),
|
||||
'balance-component': httpVueLoader('./balance_reconcile.vue'),
|
||||
'verify_query-component': httpVueLoader('./verify_order_record_query.vue'),
|
||||
'balance_query-component': httpVueLoader('./balance_reconcile_query.vue')
|
||||
'balance_query-component': httpVueLoader('./balance_reconcile_query.vue'),
|
||||
'statistic_query-component': httpVueLoader('./statistic.vue'),
|
||||
},
|
||||
|
||||
methods: {
|
||||
async statistic_query(){
|
||||
this.modify_dialog.show = true
|
||||
this.currentView = 'statistic_query-component'
|
||||
},
|
||||
async balance_query() {
|
||||
this.modify_dialog.show = true
|
||||
this.currentView = 'balance_query-component'
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
<template>
|
||||
<div class="container-fluid">
|
||||
<v-card>
|
||||
<v-card-title class="bg-success white--text text-center">
|
||||
<h5 class="mb-0">統計報表</h5>
|
||||
<v-spacer></v-spacer>
|
||||
<!--<v-btn color="primary" @click="submitData">確認送出</v-btn>-->
|
||||
<v-btn color="primary" class="ml-2" @click="closeWindow">關閉</v-btn>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<v-row>
|
||||
<v-col cols="2" md="2">
|
||||
<v-select :items="category"
|
||||
label="統計分類"
|
||||
item-text="name"
|
||||
item-value="id" v-model="category_id">
|
||||
</v-select>
|
||||
</v-col>
|
||||
<v-col cols="2" md="2">
|
||||
<v-text-field label="法會時間(起)" v-model="query.s_date"></v-text-field>
|
||||
</v-col>
|
||||
<v-col cols="2" md="2">
|
||||
<v-text-field label="法會時間(迄)" v-model="query.e_date"></v-text-field>
|
||||
</v-col>
|
||||
<v-col cols="2" md="2">
|
||||
<v-btn @click.prevent="getRpt()" :disabled="isdisabled">
|
||||
匯出
|
||||
</v-btn>
|
||||
<img src="/admin/images/loading.gif" v-show="isloading"/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
<v-dialog v-model="message_dialog.show" class="dialog_width">
|
||||
<v-card>
|
||||
<v-card-title>
|
||||
{{ message_dialog.message }}
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<v-btn @click.prevent="message_dialog.show=false" v-if="!message_dialog.show_confirm">關閉</v-btn>
|
||||
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
module.exports = {
|
||||
data() {
|
||||
return {
|
||||
message_dialog: { show: false, show_confirm: false, message: "" },
|
||||
category: [
|
||||
{ id: "01", name: "依法會+功德項目", selected: "" },
|
||||
{ id: "02", name: "依信眾", selected: "" },
|
||||
{ id: "03", name: "依法會+信眾", selected: "" },
|
||||
],
|
||||
category_id: "",
|
||||
isdisabled: false,
|
||||
isloading: false,
|
||||
query: {s_date:"",e_date:""}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
closeWindow() {
|
||||
this.$emit('close-dialog');
|
||||
},
|
||||
getRpt() {
|
||||
if (this.category_id == "") {
|
||||
this.message_dialog.message = "請選擇統計類型";
|
||||
this.message_dialog.show = true;
|
||||
return false;
|
||||
}
|
||||
const params = { statistic_mode: this.category_id }
|
||||
const search = {
|
||||
num: 0, kind: 0, kindName: "", order_no: "", u_name: "", pay_type: "", subject: "", amount: 0, price: 0, pay_mode: "", status: "",
|
||||
acc_num: 0, f_num: 0, acc_kind: 0, check_amount: 0, remain_amount: 0, check_status: "", actItem_num: 0, draft: "", d_nnum: 0
|
||||
}
|
||||
this.isdisabled = true;
|
||||
this.isloading = true;
|
||||
axios
|
||||
.post(HTTP_HOST + 'api/statistics/GetStatistic', search, { params: params })
|
||||
.then(response => {
|
||||
if (response.data.result == "N") {
|
||||
this.message_dialog.message = response.data.message;
|
||||
this.message_dialog.show = true;
|
||||
} else if (response.data.result == "Y") {
|
||||
const link = document.createElement('a');
|
||||
link.href = HTTP_HOST + "/" + response.data.filename;
|
||||
link.target = "_blank";
|
||||
|
||||
// 5. Specify the filename for the download
|
||||
//link.setAttribute('download', 'my-downloaded-file.pdf');
|
||||
|
||||
// 6. Append link to the body, click it, and remove it immediately
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
// 7. Free up memory by revoking the object URL
|
||||
//window.URL.revokeObjectURL(blobUrl);
|
||||
//window.open(HTTP_HOST +"/" +response.data.filename, "_blank");
|
||||
}
|
||||
this.isdisabled = false;
|
||||
this.isloading = false;
|
||||
|
||||
})
|
||||
.catch(error => console.log(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
.v-dialog {
|
||||
width: 80% !important;
|
||||
}
|
||||
</style>
|
||||
@@ -162,7 +162,7 @@
|
||||
</v-card>
|
||||
</template>
|
||||
</v-dialog>
|
||||
</v-container>
|
||||
</div>
|
||||
|
||||
|
||||
</template>
|
||||
|
||||
@@ -187,7 +187,7 @@
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-container>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<template>
|
||||
<v-card>
|
||||
<v-card-title class="bg-primary white--text text-center">
|
||||
<h4>批次報名</h4>
|
||||
<div class="ms-auto">
|
||||
<v-btn @click.prevent="batchSave()">儲存</v-btn>
|
||||
<v-btn @click.prevent="back01()">返回</v-btn>
|
||||
</div>
|
||||
</v-card-title>
|
||||
</v-card>
|
||||
</template>
|
||||
<script>
|
||||
module.exports = {
|
||||
props: {
|
||||
num: {
|
||||
type: Number
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
batchSave() {
|
||||
|
||||
},
|
||||
back01() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
|
||||
</style>
|
||||
+1
-1
@@ -42,7 +42,7 @@
|
||||
<add key="UseSearchKeywords" value="true" />
|
||||
<!--網站的簡稱,用來區別session和cookie-->
|
||||
<add key="SC" value="erp17168" />
|
||||
<add key="LogPath" value="C:\\log\\" />
|
||||
<add key="LogPath" value="D:\\log\\" />
|
||||
<!--是否啟用信眾自動編號 (true=啟用, false=停用)-->
|
||||
<add key="IsAutoNumbering" value="true" />
|
||||
</appSettings>
|
||||
|
||||
Reference in New Issue
Block a user