diff --git a/web/App_Code/Model/Model.Context.cs b/web/App_Code/Model/Model.Context.cs index 5362fde..d90a711 100644 --- a/web/App_Code/Model/Model.Context.cs +++ b/web/App_Code/Model/Model.Context.cs @@ -95,6 +95,10 @@ namespace Model public virtual DbSet AncestralTabletStatus { get; set; } public virtual DbSet GuaDanOrderGuest { get; set; } public virtual DbSet auto_enroll { get; set; } + public virtual DbSet receipt_detail { get; set; } + public virtual DbSet receipt_master { get; set; } + public virtual DbSet receipt_style { get; set; } + public virtual DbSet receipt_style_d { get; set; } public virtual int pager_eztrust(Nullable startRowIndex, Nullable pageSize, string tableName, string columnName, string sqlWhere, string orderBy, ObjectParameter rowCount) { diff --git a/web/App_Code/Model/Model.cs b/web/App_Code/Model/Model.cs index 43d509f..e9ae360 100644 --- a/web/App_Code/Model/Model.cs +++ b/web/App_Code/Model/Model.cs @@ -694,8 +694,8 @@ namespace Model public int num { get; set; } public int f_num { get; set; } - public System.DateTime start_date { get; set; } - public System.DateTime end_date { get; set; } + public Nullable start_date { get; set; } + public Nullable end_date { get; set; } public string receipt_title { get; set; } public string receipt_address { get; set; } @@ -1539,6 +1539,85 @@ namespace Model using System; using System.Collections.Generic; + public partial class receipt_detail + { + public int num { get; set; } + public Nullable receipt_num { get; set; } + public string title { get; set; } + public Nullable amt { get; set; } + public string receipt_no { get; set; } + public string caseofficer { get; set; } + public string c_user { get; set; } + public string c_date { get; set; } + public string c_time { get; set; } + public string u_user { get; set; } + public string u_date { get; set; } + public string u_time { get; set; } + public string addr { get; set; } + } +} +namespace Model +{ + using System; + using System.Collections.Generic; + + public partial class receipt_master + { + public int num { get; set; } + public string order_no { get; set; } + public Nullable total_amt { get; set; } + public string receipt_date { get; set; } + public Nullable style_num { get; set; } + public string c_user { get; set; } + public string c_date { get; set; } + public string c_time { get; set; } + public string u_user { get; set; } + public string u_date { get; set; } + public string u_time { get; set; } + public string source { get; set; } + } +} +namespace Model +{ + using System; + using System.Collections.Generic; + + public partial class receipt_style + { + public int num { get; set; } + public string name { get; set; } + public string c_user { get; set; } + public string c_date { get; set; } + public string c_time { get; set; } + public string u_user { get; set; } + public string u_date { get; set; } + public string u_time { get; set; } + } +} +namespace Model +{ + using System; + using System.Collections.Generic; + + public partial class receipt_style_d + { + public int num { get; set; } + public Nullable style_num { get; set; } + public string item_name { get; set; } + public string item_value { get; set; } + public string c_user { get; set; } + public string c_date { get; set; } + public string c_time { get; set; } + public string u_user { get; set; } + public string u_date { get; set; } + public string u_time { get; set; } + } +} +namespace Model +{ + using System; + using System.Collections.Generic; + public partial class Region { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] diff --git a/web/App_Code/Model/Model.edmx b/web/App_Code/Model/Model.edmx index 1029793..5d5431a 100644 --- a/web/App_Code/Model/Model.edmx +++ b/web/App_Code/Model/Model.edmx @@ -343,10 +343,10 @@ - - + + - + @@ -419,7 +419,7 @@ - + @@ -795,6 +795,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1140,15 +1203,15 @@ - - + + - + - + @@ -2188,6 +2251,10 @@ + + + + @@ -2246,8 +2313,8 @@ - - + + @@ -2953,7 +3020,7 @@ - + @@ -4620,6 +4687,10 @@ + + + + @@ -5343,10 +5414,10 @@ - - + + - + @@ -5376,6 +5447,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -6447,6 +6581,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/App_Code/Model/Model.edmx.diagram b/web/App_Code/Model/Model.edmx.diagram index f56637a..83927fa 100644 --- a/web/App_Code/Model/Model.edmx.diagram +++ b/web/App_Code/Model/Model.edmx.diagram @@ -165,6 +165,10 @@ + + + + diff --git a/web/App_Code/Model/ViewModel/receipt.cs b/web/App_Code/Model/ViewModel/receipt.cs new file mode 100644 index 0000000..c3925d0 --- /dev/null +++ b/web/App_Code/Model/ViewModel/receipt.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +namespace Model.ViewModel +{ + /// + /// receipt 的摘要描述 + /// + public class receipt_master + { + public receipt_master() + { + // + // TODO: 在這裡新增建構函式邏輯 + // + } + + public int? num { get; set; } + public string order_no { get; set; } + public int? total_amt { get; set; } + public int? style_num { get; set; } + public string source { get; set; } + public string receipt_date { get; set; } + public List list { get;set ; } + + } + + public class receipt_detail + { + public receipt_detail() + { + } + public int? num { get; set; } + public int? receipt_num { get; set; } + public string title { get; set; } + public string receipt_no { get; set; } + public int? amt { get; set; } + public string caseofficer { get; set; } + public string addr { get; set; } + } +} \ No newline at end of file diff --git a/web/App_Code/api/FollowerController.cs b/web/App_Code/api/FollowerController.cs index 386502c..01b01c6 100644 --- a/web/App_Code/api/FollowerController.cs +++ b/web/App_Code/api/FollowerController.cs @@ -738,8 +738,8 @@ public class FollowerController : ApiController list = prod.Select(x => new { num = x.num, - auto_enroll_start_date = x.start_date.ToString("yyyy-MM-dd"), - auto_enroll_end_date = x.end_date.ToString("yyyy-MM-dd"), + auto_enroll_start_date = x.start_date.Value.ToString("yyyy-MM-dd"), + auto_enroll_end_date = x.end_date.Value.ToString("yyyy-MM-dd"), auto_enroll_receipt_title = x.receipt_title?? "", auto_enroll_receipt_address = x.receipt_address?? "", }), @@ -768,7 +768,7 @@ public class FollowerController : ApiController ; _db.auto_enroll.Add(autoEnroll); _db.SaveChanges(); - CreateOrdersForActivities(item.f_num, autoEnroll.num, item.start_date, item.end_date, item.receipt_title, item.receipt_address); + CreateOrdersForActivities(item.f_num, autoEnroll.num, item.start_date.Value, item.end_date.Value, item.receipt_title, item.receipt_address); } else { @@ -781,7 +781,7 @@ public class FollowerController : ApiController autoEnroll.receipt_title = item.receipt_title?.Trim() ?? null; autoEnroll.receipt_address = item.receipt_address?.Trim() ?? null; _db.SaveChanges(); - CreateOrdersForActivities(item.f_num, autoEnroll.num, item.start_date, item.end_date, item.receipt_title, item.receipt_address); + CreateOrdersForActivities(item.f_num, autoEnroll.num, item.start_date.Value, item.end_date.Value, item.receipt_title, item.receipt_address); } try @@ -789,8 +789,8 @@ public class FollowerController : ApiController var ret = new { num = autoEnroll.num, - start_date = autoEnroll.start_date.ToString("yyyy-MM-dd"), - end_date = autoEnroll.end_date.ToString("yyyy-MM-dd"), + start_date = autoEnroll.start_date.Value.ToString("yyyy-MM-dd"), + end_date = autoEnroll.end_date.Value.ToString("yyyy-MM-dd"), receipt_title = autoEnroll.receipt_title, receipt_address = autoEnroll.receipt_address, }; diff --git a/web/App_Code/api/orderController.cs b/web/App_Code/api/orderController.cs index 9079577..a826abe 100644 --- a/web/App_Code/api/orderController.cs +++ b/web/App_Code/api/orderController.cs @@ -391,6 +391,7 @@ public class orderController : ApiController o_detail.qty = detail.qty; o_detail.printed_files = detail.printed_files; o_detail.style = detail.style; + o_detail.print_id = GenerateSequentialId(o_detail, order); Newtonsoft.Json.Linq.JArray mid_items = new Newtonsoft.Json.Linq.JArray(); foreach (var data in detail.mid_items) { @@ -514,6 +515,8 @@ public class orderController : ApiController qry = qry.Where(o => o.f_num != null && o.follower != null && encrypt.DecryptAutoKey(o.follower.id_code) == q.f_user.id_code); } + sortBy = sortBy ?? string.Empty; + if (sortBy.Equals("order_no")) { if (sortDesc) @@ -580,6 +583,7 @@ public class orderController : ApiController uptime=x.up_time?.ToString("yyyy-MM-dd"), keyin1_txt = Model.pro_order.keyin1_value_to_text(x.keyin1), status = x.activity.activity_check.FirstOrDefault(a => x.activity_num == a.activity_num && x.f_num == a.f_num)?.status ?? 0, + amt = _db.pro_order_detail.Where(y => y.order_no == x.order_no).Select(y => new {y.price,y.qty}).Sum(y => y.price*y.qty), }), count = count }; diff --git a/web/App_Code/api/receiptController.cs b/web/App_Code/api/receiptController.cs new file mode 100644 index 0000000..7c51570 --- /dev/null +++ b/web/App_Code/api/receiptController.cs @@ -0,0 +1,481 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Drawing; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Vml; +using DocumentFormat.OpenXml.Wordprocessing; +using Model; +using NPOI.OpenXmlFormats.Wordprocessing; +using NPOI.Util; +using PagedList; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Web; +using System.Web.Http; +using System.Web.UI.WebControls; +using Break = DocumentFormat.OpenXml.Wordprocessing.Break; +using Paragraph = DocumentFormat.OpenXml.Wordprocessing.Paragraph; +using Run = DocumentFormat.OpenXml.Wordprocessing.Run; +using Table = DocumentFormat.OpenXml.Wordprocessing.Table; +using Text = DocumentFormat.OpenXml.Wordprocessing.Text; + +/// +/// receiptController 的摘要描述 +/// +[ezAuthorize] +public class receiptController: ApiController +{ + private Model.ezEntities _db = new Model.ezEntities(); + public receiptController() + { + // + // TODO: 在這裡新增建構函式邏輯 + // + } + + public string generend_receiptNo(string source) + { + string start = source + "A"; + string no = start + DateTime.Now.ToString("yyyyMMdd"); + var qry = _db.receipt_detail.Where(x => x.receipt_no.StartsWith(no)); + var receipt_no=qry.Select(x => x.receipt_no).Max(); + if (!string.IsNullOrEmpty(receipt_no)) + { + receipt_no= receipt_no.Remove(0,(start + DateTime.Now.ToString("yyyyMMdd")).Length); + return start + DateTime.Now.ToString("yyyyMMdd")+string.Format("{0:D4}", Int32.Parse(receipt_no)+1); + } + else + { + return start + DateTime.Now.ToString("yyyyMMdd") + "0001"; + } + } + + [HttpPost] + [Route("api/receipt/UpdateReceiptWithDetail")] + public IHttpActionResult UpdateReceiptWithDetail([FromBody] Model.ViewModel.receipt_master receipt) + { + int master_no = 0; + try + { + //Model.receipt_master m = new Model.receipt_master(); + List list = new List(); + var master = _db.receipt_master.Where(x => x.num == receipt.num).FirstOrDefault(); + if (master != null) + { + master.u_time = DateTime.Now.ToString("HHmmss"); + master.u_date = DateTime.Now.ToString("yyyyMMdd"); + } + master_no=master.num; + //m.receipt_date = receipt.receipt_date; + //m.order_no = receipt.order_no; + //m.total_amt = receipt.total_amt; + //m.style_num = receipt.style_num; + //m.source = receipt.source; + //m.num=(int)receipt.num; + + //m.c_date = DateTime.Now.ToString("yyyyMMdd"); + //m.c_time = DateTime.Now.ToString("HHmmss"); + //m.u_time = DateTime.Now.ToString("HHmmss"); + //m.u_date = DateTime.Now.ToString("yyyyMMdd"); + //_db.receipt_master.Add(m); + //_db.SaveChanges(); + //master_no = m.num; + string pre_no = string.Empty; + foreach (var d in receipt.list) + { + if (d.num == 0) + { + + + receipt_detail dd = new receipt_detail(); + if (string.IsNullOrEmpty(pre_no)) + { + dd.receipt_no = generend_receiptNo(master.source); + } + else + { + string new_no = pre_no.Remove(0, 10); + dd.receipt_no = master.source + "A" + DateTime.Now.ToString("yyyyMMdd") + string.Format("{0:D4}", Int32.Parse(new_no) + 1); + } + dd.addr = d.addr; + dd.title = d.title; + dd.amt = d.amt; + dd.caseofficer = d.caseofficer; + dd.receipt_num = master.num; + dd.c_date = DateTime.Now.ToString("yyyyMMdd"); + dd.c_time = DateTime.Now.ToString("HHmmss"); + dd.u_time = DateTime.Now.ToString("HHmmss"); + dd.u_date = DateTime.Now.ToString("yyyyMMdd"); + pre_no = dd.receipt_no; + list.Add(dd); + } + else + { + var dd=_db.receipt_detail.Where(x=>x.num==d.num).FirstOrDefault(); + dd.title=d.title; + dd.amt=d.amt; + dd.caseofficer=d.caseofficer; + dd.u_time = DateTime.Now.ToString("HHmmss"); + dd.u_date = DateTime.Now.ToString("yyyyMMdd"); + } + } + _db.receipt_detail.AddRange(list); + _db.SaveChanges(); + return Ok(new { result = "Y", message = "存檔成功" }); + } + catch (Exception ex) + { + var s = _db.receipt_master.Where(x => x.num == master_no).FirstOrDefault(); + if (s != null) + { + _db.receipt_master.Remove(s); + _db.SaveChanges(); + } + return Ok(new { result = "N", message = $"存檔失敗,{ex.Message} {ex.StackTrace}" }); + } + + } + + + [HttpPost] + [Route("api/receipt/SaveReceiptWithDetail")] + public IHttpActionResult SaveReceiptWithDetail([FromBody] Model.ViewModel.receipt_master receipt) + { + int master_no = 0; + try + { + Model.receipt_master m = new Model.receipt_master(); + List list = new List(); + m.receipt_date = receipt.receipt_date; + m.order_no = receipt.order_no; + m.total_amt = receipt.total_amt; + m.style_num = receipt.style_num; + m.source = receipt.source; + + m.c_date = DateTime.Now.ToString("yyyyMMdd"); + m.c_time = DateTime.Now.ToString("HHmmss"); + m.u_time= DateTime.Now.ToString("HHmmss"); + m.u_date = DateTime.Now.ToString("yyyyMMdd"); + _db.receipt_master.Add(m); + _db.SaveChanges(); + master_no = m.num; + string pre_no = string.Empty; + foreach (var d in receipt.list) + { + + receipt_detail dd = new receipt_detail(); + if (string.IsNullOrEmpty(pre_no)) + { + dd.receipt_no = generend_receiptNo(m.source); + } + else + { + string new_no = pre_no.Remove(0,10); + dd.receipt_no = m.source + "A" + DateTime.Now.ToString("yyyyMMdd") + string.Format("{0:D4}", Int32.Parse(new_no)+1); + } + dd.addr = d.addr; + dd.title = d.title; + dd.amt = d.amt; + dd.caseofficer = d.caseofficer; + dd.receipt_num = m.num; + dd.c_date = DateTime.Now.ToString("yyyyMMdd"); + dd.c_time = DateTime.Now.ToString("HHmmss"); + dd.u_time = DateTime.Now.ToString("HHmmss"); + dd.u_date = DateTime.Now.ToString("yyyyMMdd"); + pre_no = dd.receipt_no; + list.Add(dd); + } + _db.receipt_detail.AddRange(list); + _db.SaveChanges(); + return Ok(new {result="Y",message="存檔成功"}); + } + catch (Exception ex) + { + var s=_db.receipt_master.Where(x=>x.num==master_no).FirstOrDefault(); + if (s != null) + { + _db.receipt_master.Remove(s); + _db.SaveChanges(); + } + return Ok(new { result = "N", message = $"存檔失敗,{ex.Message} {ex.StackTrace}" }); + } + + } + + [HttpPost] + [Route("api/receipt/GetList")] + public IHttpActionResult GetList([FromBody] Model.ViewModel.receipt_master r, + int page, int pageSize = 10, string sortBy = "", bool sortDesc = false) + { + var qry = _db.receipt_master.AsQueryable(); + if (r.num.HasValue) + qry = qry.Where(x => x.num == r.num.Value); + if (!string.IsNullOrEmpty(r.receipt_date)) + qry = qry.Where(x=>x.receipt_date==r.receipt_date); + if (!string.IsNullOrEmpty(r.source)) + qry = qry.Where(x => x.source == r.source); + if (!string.IsNullOrEmpty(r.order_no)) + qry = qry.Where(x => x.order_no == r.order_no); + + qry=qry.OrderBy(x => x.num); + var count = qry.Count(); + var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList(); + var ret = new + { + list = qryList.Select(x => new + { + x.num,x.source,x.order_no,x.total_amt,x.receipt_date,x.style_num, + follower=_db.pro_order.Where(y=>y.order_no==x.order_no).Select(y=>new { + u_name=_db.followers.Where(z=>z.num==y.f_num).Select(z=>z.u_name).FirstOrDefault(), + }).FirstOrDefault(), + receipt_count=_db.receipt_detail.Where(w=>w.receipt_num==x.num).Count() + }), + count=count + }; + if (ret.list == null) throw new HttpResponseException(HttpStatusCode.NotFound); + return Ok(ret); + } + + [HttpPost] + [Route("api/receipt/GetData")] + public IHttpActionResult GetData([FromBody] Model.ViewModel.receipt_master r) + { + var qry = _db.receipt_master.AsQueryable(); + if (r.num.HasValue) + qry = qry.Where(x => x.num == r.num.Value); + if (!string.IsNullOrEmpty(r.receipt_date)) + qry = qry.Where(x => x.receipt_date == r.receipt_date); + if (!string.IsNullOrEmpty(r.source)) + qry = qry.Where(x => x.source == r.source); + if (!string.IsNullOrEmpty(r.order_no)) + qry = qry.Where(x => x.order_no == r.order_no); + + qry = qry.OrderBy(x => x.num); + var ret = new + { + data = qry.Select(x => new + { + x.num, + x.source, + x.order_no, + x.total_amt, + x.receipt_date, + x.style_num, + follower = _db.pro_order.Where(y => y.order_no == x.order_no).Select(y => new { + u_name = _db.followers.Where(z => z.num == y.f_num).Select(z => z.u_name).FirstOrDefault(), + }).FirstOrDefault(), + receipt_detail = _db.receipt_detail.Where(w => w.receipt_num == x.num).ToList(), + orderdetails=_db.pro_order_detail.Where(q=>q.order_no==x.order_no).Select(q=>new + { + records=_db.pro_order_record.Where(rc=>rc.detail_num==q.num).Select(rc=>rc.price).ToList(), + }).ToList() + }).FirstOrDefault(), + + }; + if (ret.data == null) throw new HttpResponseException(HttpStatusCode.NotFound); + return Ok(ret); + } + + [HttpPost] + [Route("api/receipt/GetAllStyle")] + public IHttpActionResult GetAllStyle() + { + var qry = _db.receipt_style.AsQueryable(); + return Ok(new { result = "Y", list = qry.ToList() }); + } + + + [HttpPost] + [Route("api/receipt/PrintReceipt")] + public HttpResponseMessage PrintReceipt([FromBody] Model.receipt_master r) + { + var qry=_db.receipt_master.AsQueryable(); + qry = qry.Where(x=>x.num==r.num); + + var data = qry.Select(x=>new + { + x.num,x.receipt_date,x.source,x.order_no,x.style_num, + details=_db.receipt_detail.Where(y=>y.receipt_num==x.num).ToList(), + styleDetail=_db.receipt_style_d.Where(z=>z.style_num==x.style_num).ToList(), + }).FirstOrDefault(); + + + try + { + string templatePath = HttpContext.Current.Server.MapPath("~/rpt/sample/receipt_sample01.docx"); + + if (!File.Exists(templatePath)) + { + return Request.CreateResponse(HttpStatusCode.NotFound, "Template file not found."); + } + byte[] templateBytes = File.ReadAllBytes(templatePath); + + // 2. 建立記憶體串流 + MemoryStream outputStream = new MemoryStream(); + outputStream.Write(templateBytes, 0, templateBytes.Length); + + // 3. 使用 Open XML 處理記憶體中的資料 + using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(outputStream, true)) + { + var body = wordDoc.MainDocumentPart.Document.Body; + var templateTable = body.Elements().FirstOrDefault(); + + if (templateTable != null && data.details != null && data.details.Count > 0) + { + OpenXmlElement currentAnchor = templateTable; + // 建立全域計數器 (請實作於迴圈外部,避免歸零) + int docPrIdCounter = 1000; + int vmlIdCounter = 2000; + for (int i = 0; i < data.details.Count; i++) + { + Table newTable = (Table)templateTable.CloneNode(true); + + + + // --- 步驟 A:修復 DrawingML 的 docPr ID --- + foreach (var docPr in newTable.Descendants()) + { + docPr.Id = (uint)docPrIdCounter++; + // 順便變更 Name,避免如 "直線接點 2" 的名稱重複 + docPr.Name = $"直線接點_{docPrIdCounter}"; + } + + // --- 步驟 B:修復 VML 的 id 與 o:spid --- + foreach (var line in newTable.Descendants()) + { + string newSpid = $"_x0000_s{vmlIdCounter++}"; + + // 更新原本的 v:line id + line.Id = $"直線接點_{vmlIdCounter}"; + + // o:spid 屬於 Office 擴充屬性,透過 SetAttribute 強制覆寫 + var oNamespace = "urn:schemas-microsoft-com:office:office"; + line.SetAttribute(new OpenXmlAttribute("spid", "o", oNamespace, newSpid)); + } + // 移除複製出來的書籤標籤,保持結構乾淨 + var bookmarksStarts = newTable.Descendants().ToList(); + var bookmarksEnds = newTable.Descendants().ToList(); + + foreach (var bm in bookmarksStarts) bm.Remove(); + foreach (var bm in bookmarksEnds) bm.Remove(); + + foreach (var p in newTable.Descendants()) + { + p.RsidParagraphAddition = null; + p.RsidParagraphDeletion = null; + p.RsidParagraphProperties = null; + p.RsidRunAdditionDefault = null; + } + var textElements = newTable.Descendants().ToList(); + foreach (var textNode in textElements) + { + // 檢查文字節點是否包含指定的關鍵字,並進行置換 + if (textNode.Text.Contains("$CompanyTitle")) + { + var companyTitle = data.styleDetail.Where(x => x.item_name == "CompanyTitle").Select(x => x.item_value).FirstOrDefault(); + textNode.Text = textNode.Text.Replace("$CompanyTitle", companyTitle ?? ""); + } + if (textNode.Text.Contains("$ApproveNo")) + { + var approveNo = data.styleDetail.Where(x => x.item_name == "ApproveNo").Select(x => x.item_value).FirstOrDefault(); + textNode.Text = textNode.Text.Replace("$ApproveNo", approveNo ?? ""); + } + if (textNode.Text.Contains("$CompanyTaxNo")) + { + var companyTaxNo = data.styleDetail.Where(x => x.item_name == "CompanyTaxNo").Select(x => x.item_value).FirstOrDefault(); + textNode.Text = textNode.Text.Replace("$CompanyTaxNo", companyTaxNo ?? ""); + } + if (textNode.Text.Contains("$CompanyAddr")) + { + var companyAddr = data.styleDetail.Where(x => x.item_name == "CompanyAddr").Select(x => x.item_value).FirstOrDefault(); + textNode.Text = textNode.Text.Replace("$CompanyAddr", companyAddr ?? ""); + } + if (textNode.Text.Contains("$CompanyTel")) + { + var companyTel = data.styleDetail.Where(x => x.item_name == "CompanyTel").Select(x => x.item_value).FirstOrDefault(); + textNode.Text = textNode.Text.Replace("$CompanyTel", companyTel ?? ""); + } + if (textNode.Text.Contains("$ReceiptNo")) + { + + textNode.Text = textNode.Text.Replace("$ReceiptNo", data.details[i].receipt_no ?? ""); + } + if (textNode.Text.Contains("$ReceiptDate")) + { + textNode.Text = textNode.Text.Replace("$ReceiptDate", data.receipt_date ?? ""); + } + if (textNode.Text.Contains("$ReceiptTitle")) + { + textNode.Text = textNode.Text.Replace("$ReceiptTitle", data.details[i].title ?? ""); + } + if (textNode.Text.Contains("$ReceiptAmt")) + { + textNode.Text = textNode.Text.Replace("$ReceiptAmt", data.details[i].amt.ToString() ?? ""); + } + if (textNode.Text.Contains("$Charge")) + { + textNode.Text = textNode.Text.Replace("$Charge", "" ?? ""); + } + if (textNode.Text.Contains("$Caseofficer")) + { + textNode.Text = textNode.Text.Replace("$Caseofficer", data.details[i].caseofficer ?? ""); + } + + } + + currentAnchor= body.InsertAfter(newTable, currentAnchor); + //currentAnchor = newTable; + + if (i < data.details.Count - 1) + { + + Paragraph pageBreakParagraph = new Paragraph( + new Run( + new Break() { Type = BreakValues.Page } + ) + ); + + // 🔥【關鍵修正】將分頁段落插入到剛才產生的新表格後方 + currentAnchor = body.InsertAfter(pageBreakParagraph, currentAnchor); + } + } + + body.RemoveChild(templateTable); + wordDoc.MainDocumentPart.Document.Save(); + } + } // wordDoc 關閉,確認資料完全寫入 outputStream + + // 🔥 關鍵步驟:重設記憶體串流指標到起點 + outputStream.Position = 0; + + // 4. 建立 HttpResponseMessage + HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); + + // 將記憶體流包裝成 StreamContent + response.Content = new StreamContent(outputStream); + + // 設定 Content-Type 標頭(Word 專用 MIME Type) + response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + + // 設定 Content-Disposition 標頭,指定為附件並提供預設檔名 + string fileName = $"Report_{DateTime.Now:yyyyMMddHHmmss}.docx"; + response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") + { + FileName = fileName + }; + + return response; + } + catch (Exception ex) + { + // Log exception details appropriately here + return Request.CreateResponse(HttpStatusCode.InternalServerError, $"Generation failed: {ex.Message}"); + } + } + + +} \ No newline at end of file diff --git a/web/admin/activity/item_reg.aspx.cs b/web/admin/activity/item_reg.aspx.cs index 1df4cd4..ac2a18d 100644 --- a/web/admin/activity/item_reg.aspx.cs +++ b/web/admin/activity/item_reg.aspx.cs @@ -170,7 +170,7 @@ public partial class admin_activity_item_reg : MyWeb.config Model.actItem_files file=new Model.actItem_files(); file.actItem_num= _id; file.files_num = 211; - file.file.reg_time=DateTime.Now; + file.reg_time=DateTime.Now; _db.actItem_files.Add(file); _db.SaveChanges(); Model.admin_log admin_log = new Model.admin_log(); diff --git a/web/admin/item/TabletDesigner.aspx b/web/admin/item/TabletDesigner.aspx index e2ef7cf..331334e 100644 --- a/web/admin/item/TabletDesigner.aspx +++ b/web/admin/item/TabletDesigner.aspx @@ -511,11 +511,11 @@ await axios .post(HTTP_HOST + 'api/tablet/GetTabletElement', {}) .then(response => { - console.log(response) + //console.log(response) //if (response.result=="Y") { if (response.status == "200") { let data = response.data; - console.log("data:",data) + //console.log("data:",data) if (data.result == "Y") { data.data.forEach(x => { self.tabletElements.push(x); @@ -826,9 +826,18 @@ createEl(el, slice) { let html = ''; + let fontSize = el.style.fontSize; // 1. 智慧名單渲染 if (el.type === 'roster') { - html = this.renderRoster(slice, el); + let perRow = Math.floor(Number(el.height) / Number(el.textHeight)); + let rows = Math.ceil(Number(slice.length) / Number(perRow));//總行數 + let rowWidth = Math.floor(Number(el.width) / rows); + let fontSize = Math.floor(rowWidth / 2); + if (fontSize > el.style.fontSize) { + fontSize = el.style.fontSize; + rowWidth = fontSize * 2; + } + html = this.renderRoster(slice, el, rowWidth); } // 2. 正名合併置中 else if (el.type === 'combined-center') { @@ -843,11 +852,27 @@ html = el.text.replace(/(\d+)/g, '$1'); } else if (el.id === 'title1') { - html = this.renderNameList(slice, el); + let perRow = Math.floor(Number(el.height) / Number(el.textHeight)); + let rows = Math.ceil(Number(slice.length) / Number(perRow));//總行數 + let rowWidth = Math.floor(Number(el.width) / rows); + fontSize = Math.floor(rowWidth / 2); + //console.log(el.height, el.textHeight, perRow, rows, rowWidth, fontSize) + if (fontSize > el.style.fontSize) { + fontSize = el.style.fontSize; + rowWidth = fontSize * 2; + } + html = this.renderNameList(slice, el, rowWidth); } else if (el.id === 'alive') { - console.log("createEl:",slice,el) - html = this.renderLiveList(slice, el); + let perRow = Math.floor(Number(el.height) / Number(el.textHeight)); + let rows = Math.ceil(Number(slice.length) / Number(perRow));//總行數 + let rowWidth = Math.floor(Number(el.width) / rows); + fontSize = Math.floor(rowWidth / 2); + if (fontSize > el.style.fontSize) { + fontSize = el.style.fontSize; + rowWidth = fontSize * 2; + } + html = this.renderLiveList(slice, el, rowWidth); } else { html = el.text; @@ -855,12 +880,12 @@ return $(`
`) .css({ - position: "absolute", left: el.x + "mm", top: el.y + "mm", fontSize: el.style.fontSize + 'pt', fontFamily: el.style.fontFamily, "z-index": 9999, visibility: el.style.visibility + position: "absolute", left: el.x + "mm", top: el.y + "mm", fontSize: fontSize + 'pt', fontFamily: el.style.fontFamily, "z-index": 9999, visibility: el.style.visibility //position: "absolute", left: el.startX + "mm", top: el.startY + "mm", fontSize: el.fontSize + 'pt', fontFamily: el.fontFamily, "z-index": 9999, visibility: el.isActive }) .html(html); }, - renderNameList(names, el) { + renderNameList(names, el,rowWidth) { let $namelist = $(`
`).css({ "writing-mode": "vertical rl", display: "flex", @@ -880,16 +905,16 @@ //"row-gap": "1px", let self = this; names.forEach(n => { - $namelist.append(self.renderNameSpan(n, el)) + $namelist.append(self.renderNameSpan(n, el,rowWidth)) }) return $namelist; }, - renderNameSpan(name, el) { + renderNameSpan(name, el,rowWidth) { return $(`${name}`).css({ display: "block", "min-height": `${el.textHeight}px`, "max-height": `${el.height}px`, - width: `${el.textWidth}px`, + width: `${rowWidth}px`, "text-align": "justify", "text-align-last": "justify", @@ -897,8 +922,8 @@ "text-justify": "inter-character", });// "margin-bottom": `${el.textSpan}px`, }, - renderLiveList(names, el) { - console.log("renderLiveList:",names); + renderLiveList(names, el,rowWidth) { + //console.log("renderLiveList:",names); //$("#imp-text").updateActive("text",names) let $namelist = $(`
`).css({ "writing-mode": "vertical rl", @@ -919,18 +944,17 @@ //"row-gap": "1px", let self = this; names.forEach(n => { - $namelist.append(self.renderLiveSpan(n, el)) + $namelist.append(self.renderLiveSpan(n, el,rowWidth)) }) return $namelist; }, - renderLiveSpan(name, el) { - console.log("renderLiveSpan:", name, el - ); + renderLiveSpan(name, el, rowWidth) { + //console.log("renderLiveSpan:", name, el ); return $(`${name}`).css({ display: "block", "min-height": `${el.textHeight}px`, "max-height": `${el.height}px`, - width: `${el.textWidth}px`, + width: `${rowWidth}px`, "text-align": "justify", "text-align-last": "justify", @@ -1000,9 +1024,9 @@ }, select(id) { - console.log("QQ:",id); + //console.log("QQ:",id); this.activeId = id; - console.log("QQ:",this.elements); + //console.log("QQ:",this.elements); const el = this.elements.find(x => x.id === id); const el1 = this.elements.find(x => x.id === "titletriangle"); $('#attr-box').removeClass('d-none'); @@ -1024,7 +1048,7 @@ }, updateActive(key, val) { - console.log("updateActive:",key, val) + //console.log("updateActive:",key, val) const el = this.elements.find(x => x.id === this.activeId); if (key === 'fontSize') el.style.fontSize = parseFloat(val); @@ -1042,7 +1066,7 @@ position: "absolute", left: el.startX + "mm", top: el.startY + "mm", fontSize: el.style.fontSize + 'pt', fontFamily: el.fontFamily, "z-index": 9999, visibility: el.style.isActive }).html(this.renderRoster(names.slice(0 * this.rosterLimit, (0 + 1) * this.rosterLimit), el)); } else if (el.type == "combined-center") { - console.log("combined-center"); + //console.log("combined-center"); const parts = el.text.split('\n'); html = `
@@ -1058,16 +1082,33 @@ } else if (this.activeId === "title1") { let names = el.text.split('\n').filter(s => s.trim()); let slice = names.slice(0 * this.rosterLimit, (0 + 1) * this.rosterLimit); - html = this.renderNameList(slice, el); + let perRow = Math.floor(Number(el.height) / Number(el.textHeight)); + let rows = Math.ceil(Number(slice.length) / Number(perRow));//總行數 + let rowWidth = Math.floor(Number(el.width) / rows); + let fontSize = Math.floor(rowWidth / 2); + if (fontSize > el.style.fontSize) { + fontSize = el.style.fontSize; + rowWidth = fontSize * 2; + } + //console.log(el.height, el.textHeight, perRow, rows, rowWidth, fontSize) + html = this.renderNameList(slice, el, rowWidth);//el.style.fontSize $(`.tablet-element[id="${this.activeId}"]`).css({ - position: "absolute", left: el.x + "mm", top: el.y + "mm", fontSize: el.style.fontSize + 'pt', fontFamily: el.style.fontFamily, "z-index": 9999, visibility: el.style.visibility + position: "absolute", left: el.x + "mm", top: el.y + "mm", fontSize: fontSize + 'pt', fontFamily: el.style.fontFamily, "z-index": 9999, visibility: el.style.visibility }).html(html); } else if (this.activeId === "alive") { let names = el.text.split('\n').filter(s => s.trim()); let slice = names.slice(0 * this.rosterLimit, (0 + 1) * this.rosterLimit); - html = this.renderLiveList(slice, el); + let perRow = Math.floor(Number(el.height) / Number(el.textHeight)); + let rows = Math.ceil(Number(slice.length) / Number(perRow));//總行數 + let rowWidth = Math.floor(Number(el.width) / rows); + let fontSize = Math.floor(rowWidth / 2); + if (fontSize > el.style.fontSize) { + fontSize = el.style.fontSize; + rowWidth = fontSize * 2; + } + html = this.renderLiveList(slice, el, rowWidth); $(`.tablet-element[id="${this.activeId}"]`).css({ - position: "absolute", left: el.x + "mm", top: el.y + "mm", fontSize: el.style.fontSize + 'pt', fontFamily: el.style.fontFamily, "z-index": 9999, visibility: el.style.visibility + position: "absolute", left: el.x + "mm", top: el.y + "mm", fontSize: fontSize + 'pt', fontFamily: el.style.fontFamily, "z-index": 9999, visibility: el.style.visibility }).html(html); } else if (this.activeId==="righttitle") { $(`.tablet-element[id="${this.activeId}"]`).css({ @@ -1095,11 +1136,11 @@ //this.render(); }, displayItem(id) { - console.log("displayItem:", this.elements, id); + //console.log("displayItem:", this.elements, id); let el = this.elements.find(x => x.id === id); el.style.visibility = el.style.visibility === "hidden" ? "" : "hidden"; //要判斷如果所在位置超出範圍,要拉回來放 - console.log("displayItem:", this.paper, el) + //console.log("displayItem:", this.paper, el) if (el.x > this.paper.width) { el.x = this.paper.width/2 } @@ -1197,7 +1238,7 @@ orientation: $("#paperOrientation").val(), printPageCount: $("#perpage").val(), rosterLimit: 8, detail: detail } - console.log(master); + //console.log(master); let path = "SavDegignerData"; if (this.styleID != null && this.styleID != "") { path = "UpdateDegignerData" diff --git a/web/admin/order/fastSignUp3.vue b/web/admin/order/fastSignUp3.vue index 51fd5b6..08f6707 100644 --- a/web/admin/order/fastSignUp3.vue +++ b/web/admin/order/fastSignUp3.vue @@ -386,10 +386,10 @@ return ""; } let data = JSON.parse(item.f_num_tablet) - let left = data.left_items - let mid = data.mid_items - let mid_right = data.mid_right - let mid_left=data.mid_left + let left = data?.left_items + let mid = data?.mid_items + let mid_right = data?.mid_right + let mid_left=data?.mid_left let returnVal = "" if (left) { returnVal = "陽上:" + left.map(x => x.fam_name).join("、") @@ -418,7 +418,7 @@ this.tablet_list.forEach(x => { if (x.actitem_num_checked && x.actitem_num_checked == true) { - console.log("OOQ:", x) + //console.log("OOQ:", x) //console.log("OOQ:", x.num) let actItem = this.act_items.find(y => y.act_item_selected.val == x.actitem_num_selected.val) detail.push({ @@ -456,7 +456,7 @@ this.message_dialog.show_confirm = false this.message_dialog.show = true this.message_dialog.message =error - console.log(error) + //console.log(error) }); } } diff --git a/web/admin/order/fastSignUp4.vue b/web/admin/order/fastSignUp4.vue index 08bc50b..75dbd35 100644 --- a/web/admin/order/fastSignUp4.vue +++ b/web/admin/order/fastSignUp4.vue @@ -4,8 +4,8 @@

快速報名

- 儲存 - 返回 + 儲存 + 返回
@@ -24,13 +24,13 @@ - e + + label="*國籍">--> + label="*性別">--> + label="*身分別">--> + label="生日">--> + label="生日">--> + label="存/歿">--> 加入 @@ -165,7 +165,7 @@ item-value="val" v-model="alive_new.islive"> + label="存/歿">--> 加入 @@ -187,7 +187,14 @@ -
+ + + {{ snackbar.text }} + + + + + + + + + +
+ + + + + + + + + + + + 共 {{ data_table.count }} 筆, 頁數: + + + + + + + + + + + 查詢:{{search_dialog.current.title}} + mdi-close + + + + + + + + 查詢 + 清除條件 + + + + + + + + + + + + + +
+
+ + + + + + diff --git a/web/admin/receipt/index.aspx.cs b/web/admin/receipt/index.aspx.cs new file mode 100644 index 0000000..ff084c3 --- /dev/null +++ b/web/admin/receipt/index.aspx.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +public partial class admin_receipt_index : MyWeb.config +{ + protected void Page_Load(object sender, EventArgs e) + { + + } +} \ No newline at end of file diff --git a/web/admin/receipt/receipt.vue b/web/admin/receipt/receipt.vue new file mode 100644 index 0000000..0a4313d --- /dev/null +++ b/web/admin/receipt/receipt.vue @@ -0,0 +1,539 @@ + + + \ No newline at end of file diff --git a/web/rpt/sample/receipt_sample01.docx b/web/rpt/sample/receipt_sample01.docx new file mode 100644 index 0000000..646cbef Binary files /dev/null and b/web/rpt/sample/receipt_sample01.docx differ