You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
6.6 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using Entity.ViewModels;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. using SqlSugar;
  7. using SqlSugar.Base;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. namespace EasyBL.WEBAPP.OPM
  12. {
  13. public class TransferBills_QryService : ServiceBase
  14. {
  15. #region 賬單拋轉(分頁查詢)
  16. /// <summary>
  17. /// 賬單拋轉(分頁查詢)
  18. /// </summary>
  19. /// <param name="i_crm"></param>
  20. /// <returns></returns>
  21. public ResponseMessage QueryPage(RequestMessage i_crm)
  22. {
  23. ResponseMessage rm = null;
  24. string sMsg = null;
  25. var db = SugarBase.GetIntance();
  26. try
  27. {
  28. do
  29. {
  30. var pml = new PageModel
  31. {
  32. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  33. PageSize = _fetchInt(i_crm, @"pageSize")
  34. };
  35. var iPageCount = 0;
  36. var sSortField = _fetchString(i_crm, @"sortField");
  37. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  38. var sBillNO = _fetchString(i_crm, @"BillNO");
  39. var sTransferDateStart = _fetchString(i_crm, @"TransferDateStart");
  40. var sTransferDateEnd = _fetchString(i_crm, @"TransferDateEnd");
  41. var bExcel = _fetchBool(i_crm, @"Excel");
  42. var rTransferDateStart = new DateTime();
  43. var rTransferDateEnd = new DateTime();
  44. if (!string.IsNullOrEmpty(sTransferDateStart))
  45. {
  46. rTransferDateStart = SqlFunc.ToDate(sTransferDateStart);
  47. }
  48. if (!string.IsNullOrEmpty(sTransferDateEnd))
  49. {
  50. rTransferDateEnd = SqlFunc.ToDate(sTransferDateEnd).AddDays(1);
  51. }
  52. pml.DataList = db.Queryable<OVW_OPM_Bills>()
  53. .Where(x => x.OrgID == i_crm.ORIGID)
  54. .WhereIF(!string.IsNullOrEmpty(sBillNO), (t1) => t1.BillNO.Contains(sBillNO))
  55. .WhereIF(!string.IsNullOrEmpty(sTransferDateStart), (t1) => SqlFunc.ToDate(t1.CreateDate) >= rTransferDateStart.Date)
  56. .WhereIF(!string.IsNullOrEmpty(sTransferDateEnd), (t1) => SqlFunc.ToDate(t1.CreateDate) < rTransferDateEnd.Date)
  57. .OrderBy(sSortField, sSortOrder)
  58. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  59. pml.Total = iPageCount;
  60. rm = new SuccessResponseMessage(null, i_crm);
  61. if (bExcel)
  62. {
  63. var sFileName = "拋轉資料";
  64. var oHeader = new Dictionary<string, string>();
  65. var listMerge = new List<Dictionary<string, int>>();
  66. var dicAlain = new Dictionary<string, string>();
  67. var saCustomers1 = pml.DataList;
  68. var saBills = pml.DataList as List<OVW_OPM_Bills>;
  69. var dt_new = saBills.ListToDataTable<OVW_OPM_Bills>();
  70. oHeader = new Dictionary<string, string>
  71. {
  72. { "RowIndex", "項次" },
  73. { "BillNO", "帳單號碼" },
  74. { "ResponsiblePersonCodeName", "業務人員" },
  75. { "Payer", "付款人" },
  76. { "ForeignCurrencyCode", "幣別代號" },
  77. { "ExchangeRate", "匯率" },
  78. { "Advance", "預收金額" },
  79. { "TWNOTaxAmount", "未稅金額" },
  80. { "TaxSum", "稅金" },
  81. { "BillAmount", "含稅金額" },
  82. { "TotalReceivable", "總應收 " },
  83. { "CreateUser", "審核人員" },
  84. { "BillFirstCheckDate", "第一次審核時間" },
  85. { "CreateDate", "最後審核時間" }
  86. };
  87. foreach (DataRow row in dt_new.Rows)
  88. {
  89. row["Advance"] = row["Advance"].ToString() == "" ? "0" : $"{Convert.ToDouble(row["Advance"].ToString()):N2}";
  90. row["TWNOTaxAmount"] = row["TWNOTaxAmount"].ToString() == "" ? "0" : $"{Convert.ToDouble(row["TWNOTaxAmount"].ToString()):N2}";
  91. row["TaxSum"] = row["TaxSum"].ToString() == "" ? "0" : $"{Convert.ToDouble(row["TaxSum"].ToString()):N2}";
  92. row["BillAmount"] = row["BillAmount"].ToString() == "" ? "0" : $"{Convert.ToDouble(row["BillAmount"].ToString()):N2}";
  93. row["TotalReceivable"] = row["TotalReceivable"].ToString() == "" ? "0" : $"{Convert.ToDouble(row["TotalReceivable"].ToString().Replace(",", "")):N2}";
  94. }
  95. dicAlain = ExcelService.GetExportAlain(oHeader, "RowIndex", "Advance,TWNOTaxAmount,TaxSum,TotalReceivable,BillAmount");
  96. var bOk = new ExcelService().CreateExcelByTb(dt_new, out string sPath, oHeader, dicAlain, listMerge, sFileName);
  97. rm.DATA.Add(BLWording.REL, sPath);
  98. }
  99. else
  100. {
  101. rm.DATA.Add(BLWording.REL, pml);
  102. }
  103. } while (false);
  104. }
  105. catch (Exception ex)
  106. {
  107. sMsg = Util.GetLastExceptionMsg(ex);
  108. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(TransferBills_QryService), "", "QueryPage(賬單拋轉(分頁查詢))", "", "", "");
  109. }
  110. finally
  111. {
  112. if (null != sMsg)
  113. {
  114. rm = new ErrorResponseMessage(sMsg, i_crm);
  115. }
  116. }
  117. return rm;
  118. }
  119. #endregion 賬單拋轉(分頁查詢)
  120. }
  121. }