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.

921 lines
53 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using Entity.ViewModels;
  4. using Microsoft.Office.Interop.Excel;
  5. using Aspose.Cells;
  6. using Newtonsoft.Json;
  7. using Newtonsoft.Json.Linq;
  8. using SqlSugar;
  9. using SqlSugar.Base;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Drawing;
  15. using EasyBL;
  16. namespace EasyBL.WEBAPP.OPM
  17. {
  18. public class BillsReportService : ServiceBase
  19. {
  20. #region 賬單利潤報表
  21. /// <summary>
  22. /// 賬單利潤報表
  23. /// </summary>
  24. /// <param name="i_crm"></param>
  25. /// <returns></returns>
  26. public ResponseMessage Report(RequestMessage i_crm)
  27. {
  28. ResponseMessage rm = null;
  29. string sMsg = null;
  30. var sOutPut = Common.ConfigGetValue(@"", @"OutFilesPath");
  31. var db = SugarBase.GetIntance();
  32. try
  33. {
  34. do
  35. {
  36. var sProjectNO = _fetchString(i_crm, @"ProjectNO");
  37. var sPayer = _fetchString(i_crm, @"Payer");
  38. var sResponsiblePerson = _fetchString(i_crm, @"ResponsiblePerson");
  39. //var sBillNO = _fetchString(i_crm, @"BillNO");
  40. var sBillNODateStart = _fetchString(i_crm, @"BillNODateStart");
  41. var sBillNODateEnd = _fetchString(i_crm, @"BillNODateEnd");
  42. var sOrderBy = _fetchString(i_crm, @"OrderBy");
  43. var sFlag = _fetchString(i_crm, @"Flag");
  44. var rBillNODateStart = new DateTime();
  45. var rBillNODateEnd = new DateTime();
  46. if (!string.IsNullOrEmpty(sBillNODateStart))
  47. {
  48. rBillNODateStart = SqlFunc.ToDate(sBillNODateStart);
  49. }
  50. if (!string.IsNullOrEmpty(sBillNODateEnd))
  51. {
  52. rBillNODateEnd = SqlFunc.ToDate(sBillNODateEnd).AddDays(1);
  53. }
  54. var view = db.Queryable<OVW_OPM_Bills, OTB_OPM_BillInfo>
  55. ((t1, t2) =>
  56. new object[] {
  57. JoinType.Inner, t1.OrgID == t2.OrgID && t1.BillNO == t2.BillNO
  58. }
  59. )
  60. .Where((t1, t2) => t1.OrgID == i_crm.ORIGID)
  61. .WhereIF(!string.IsNullOrEmpty(sProjectNO), (t1) => t1.ProjectNumber.Contains(sProjectNO))
  62. .WhereIF(!string.IsNullOrEmpty(sPayer), (t1) => t1.CustomerCode.Contains(sPayer))
  63. .WhereIF(!string.IsNullOrEmpty(sResponsiblePerson), (t1) => t1.ResponsiblePersonFullCode.Contains(sResponsiblePerson))
  64. //.WhereIF(!string.IsNullOrEmpty(sBillNO), (t1) => t1.BillNO.Contains(sBillNO))
  65. .WhereIF(!string.IsNullOrEmpty(sBillNODateStart), (t1) => SqlFunc.ToDate(t1.CreateDate) >= rBillNODateStart.Date)
  66. .WhereIF(!string.IsNullOrEmpty(sBillNODateEnd), (t1) => SqlFunc.ToDate(t1.CreateDate) <= rBillNODateEnd.Date);
  67. var saBills = view.Select((t1, t2) =>
  68. new View_OPM_BillIReport
  69. {
  70. BillNO = t2.BillNO,
  71. BillType = t2.BillType,
  72. ParentId = t2.ParentId,
  73. ProjectNumber = t1.ProjectNumber,
  74. CustomerCode = t1.CustomerCode,
  75. ResponsiblePerson = t1.ResponsiblePersonFullCode,
  76. Currency = t2.Currency,
  77. ExchangeRate = t2.ExchangeRate,
  78. InCome = t1.TotalReceivable,
  79. })
  80. .MergeTable()
  81. .OrderBy(sOrderBy, "asc")
  82. .ToList();
  83. var sProjectNumbers = view.Select((t1) => "," + t1.ProjectNumber + ",").ToJson();
  84. var sCustomerCodes = view.Select((t1) => "," + t1.CustomerCode + ",").ToJson();
  85. var sParentIds = view.Select((t1, t2) => "," + t2.ParentId + ",").ToJson();
  86. var oProjectNumbers = db.Queryable<OTB_OPM_Exhibition>()
  87. .Where(x => x.OrgID == i_crm.ORIGID && sProjectNumbers.Contains(x.ExhibitionCode) && x.Effective == "Y")
  88. .Select<KeyValuePair<string, string>>("ExhibitionCode,ExhibitioShotName_TW")
  89. .ToList();
  90. var oCustomers = db.Queryable<OTB_CRM_CustomersMST, OTB_CRM_Customers>
  91. ((t1, t2) =>
  92. new object[] {
  93. JoinType.Inner, t1.OrgID == t2.OrgID && t1.customer_guid == t2.guid
  94. }
  95. )
  96. .Where((t1, t2) => t1.OrgID == i_crm.ORIGID && sCustomerCodes.Contains(t1.CustomerNO) && t2.Effective == "Y")
  97. .Select<KeyValuePair<string, string>>("t1.CustomerNO,t2.CustomerShotCName")
  98. .ToList();
  99. var viewExpIm = db.Queryable<OTB_OPM_ImportExhibition>()
  100. .Where(x => x.OrgID == i_crm.ORIGID && sParentIds.Contains(x.ImportBillNO))
  101. .Select(x => new ExpInfo
  102. {
  103. Id = x.ImportBillNO,
  104. ActualCost = x.ActualCost,
  105. ReturnBills = x.ReturnBills,
  106. RefNumber = x.RefNumber,
  107. ExpNO = x.ExhibitionNO
  108. });
  109. var viewExpEx = db.Queryable<OTB_OPM_ExportExhibition>()
  110. .Where(x => x.OrgID == i_crm.ORIGID && sParentIds.Contains(x.ExportBillNO))
  111. .Select(x => new ExpInfo
  112. {
  113. Id = x.ExportBillNO,
  114. ActualCost = x.ActualCost,
  115. ReturnBills = x.ReturnBills,
  116. RefNumber = x.RefNumber,
  117. ExpNO = x.ExhibitionNO
  118. });
  119. var viewExpOth = db.Queryable<OTB_OPM_OtherExhibition>()
  120. .Where(x => x.OrgID == i_crm.ORIGID && sParentIds.Contains(x.Guid))
  121. .Select(x => new ExpInfo
  122. {
  123. Id = x.Guid,
  124. ActualCost = x.ActualCost,
  125. ReturnBills = "",
  126. RefNumber = "",
  127. ExpNO = x.ExhibitionNO
  128. });
  129. var viewExpOthtG = db.Queryable<OTB_OPM_OtherExhibitionTG>()
  130. .Where(x => x.OrgID == i_crm.ORIGID && sParentIds.Contains(x.Guid))
  131. .Select(x => new ExpInfo
  132. {
  133. Id = x.Guid,
  134. ActualCost = x.ActualCost,
  135. ReturnBills = "",
  136. RefNumber = "",
  137. ExpNO = x.ExhibitionNO
  138. });
  139. var saExps = db.UnionAll(viewExpIm, viewExpEx, viewExpOth, viewExpOthtG).ToList();
  140. var sProjectName = "";
  141. var sCustomerName = "";
  142. if (!string.IsNullOrEmpty(sProjectNO))
  143. {
  144. sProjectName = db.Queryable<OTB_OPM_Exhibition>().Single(x => x.OrgID == i_crm.ORIGID && x.ExhibitionCode == sProjectNO).ExhibitioShotName_TW;
  145. }
  146. if (!string.IsNullOrEmpty(sPayer))
  147. {
  148. sCustomerName = db.Queryable<OTB_CRM_CustomersMST, OTB_CRM_Customers>
  149. ((t1, t2) =>
  150. new object[] {
  151. JoinType.Inner, t1.OrgID == t2.OrgID && t1.customer_guid == t2.guid
  152. }
  153. )
  154. .Select((t1, t2) => new OTB_CRM_Customers()
  155. {
  156. CustomerNO = t1.CustomerNO,
  157. CustomerShotCName = t2.CustomerShotCName,
  158. CustomerShotEName = t2.CustomerShotEName
  159. })
  160. .Single((t1) => t1.OrgID == i_crm.ORIGID && t1.CustomerNO == sPayer)
  161. .CustomerShotCName;
  162. }
  163. var oTempl = db.Queryable<OTB_SYS_OfficeTemplate>().Single(it => it.OrgID == i_crm.ORIGID && it.TemplID == "BillReport");
  164. if (oTempl == null)
  165. {
  166. sMsg = @"請檢查模版設定";
  167. break;
  168. }
  169. var oFile = db.Queryable<OTB_SYS_Files>().Single(it => it.OrgID == i_crm.ORIGID && it.ParentID == oTempl.FileID);
  170. if (oFile == null)
  171. {
  172. sMsg = @"系統找不到對應的報表模版";
  173. break;
  174. }
  175. var sTempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, oFile.FilePath);//Word模版路徑
  176. var sBase = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"");
  177. sOutPut = sBase + sOutPut;
  178. Common.FnCreateDir(sOutPut);//如果不存在就創建文件夾
  179. var sFileName = "利潤報表" + DateTime.Now.ToString(@"yyyy-MM-dd");
  180. //建立臨時文件
  181. var sTempFile = Path.GetTempPath() + sFileName + @".xlsx";
  182. sOutPut += sFileName + @".xlsx";
  183. if (File.Exists(sTempFile))
  184. {
  185. File.Delete(sTempFile);
  186. }
  187. File.Copy(sTempPath, sTempFile);
  188. var excelApp = new ExcelEdit();
  189. excelApp.Open(sTempFile);
  190. excelApp.app.Visible = false;
  191. excelApp.app.DisplayAlerts = false;
  192. excelApp.ws = excelApp.wb.Worksheets[1];
  193. var wsName = excelApp.ws.Name;
  194. try
  195. {
  196. var iCurrRow = 5;
  197. var iInCome_Total = 0;
  198. var iCost_Total = 0;
  199. var iProfit_Total = 0;
  200. //展覽
  201. excelApp.SetCellValue(wsName, 2, 3, sProjectName);
  202. //客戶
  203. excelApp.SetCellValue(wsName, 2, 8, sCustomerName);
  204. //業務
  205. excelApp.SetCellValue(wsName, 2, 15, sResponsiblePerson ?? "");
  206. //賬單時間
  207. excelApp.SetCellValue(wsName, 3, 3, sBillNODateStart + "~" + sBillNODateEnd);
  208. //列表人
  209. excelApp.SetCellValue(wsName, 3, 15, i_crm.USERID);
  210. //列印時間
  211. excelApp.SetCellValue(wsName, 3, 18, DateTime.Now.ToString(@"yyyy/MM/dd"));
  212. Microsoft.Office.Interop.Excel.Range range = excelApp.ws.Range[excelApp.ws.Cells[5, 1], excelApp.ws.Cells[5, 19]];
  213. Microsoft.Office.Interop.Excel.Range range_SubTotal = excelApp.ws.Range[excelApp.ws.Cells[6, 1], excelApp.ws.Cells[6, 19]];
  214. var group = saBills.GroupBy(p => sOrderBy == "ProjectNumber" ? p.ProjectNumber : sOrderBy == "CustomerCode" ? p.CustomerCode : p.ResponsiblePerson);
  215. foreach (IGrouping<string, View_OPM_BillIReport> bills in group)
  216. {
  217. var iInCome_Sub = 0;
  218. var iCost_Sub = 0;
  219. var iProfit_Sub = 0;
  220. var _bills = bills.OrderBy(x => x.ProjectNumber).OrderBy(x => x.ParentId);
  221. foreach (View_OPM_BillIReport bill in _bills)
  222. {
  223. var iInCome = bill.InCome * decimal.Parse(bill.ExchangeRate == "" ? "0" : bill.ExchangeRate);
  224. var iCost = 0;
  225. var iProfit = iInCome - iCost;
  226. iInCome_Sub += int.Parse($@"{iInCome:N0}".Replace(",", ""));
  227. iCost_Sub += int.Parse($@"{iCost:N0}".Replace(",", ""));
  228. iProfit_Sub += int.Parse($@"{iProfit:N0}".Replace(",", ""));
  229. var _projectName = oProjectNumbers.Any(x => x.Key == bill.ProjectNumber) ? oProjectNumbers.Single(x => x.Key == bill.ProjectNumber).Value : "";
  230. var _customerName = oCustomers.Any(x => x.Key == bill.CustomerCode) ? oCustomers.Single(x => x.Key == bill.CustomerCode).Value : "";
  231. excelApp.SetCellValue(wsName, iCurrRow, 2, bill.BillNO);
  232. excelApp.SetCellValue(wsName, iCurrRow, 4, _projectName);
  233. excelApp.SetCellValue(wsName, iCurrRow, 7, _customerName);
  234. excelApp.SetCellValue(wsName, iCurrRow, 10, bill.ResponsiblePerson);
  235. excelApp.SetCellValue(wsName, iCurrRow, 11, $@"{iInCome:N0}");
  236. excelApp.SetCellValue(wsName, iCurrRow, 14, iCost == 0 ? "" : $@"{iCost:N0}");
  237. excelApp.SetCellValue(wsName, iCurrRow, 17, $@"{iProfit:N0}");
  238. //複製并添加行
  239. range.Copy();
  240. range.Insert(XlDirection.xlDown);
  241. iCurrRow++;
  242. }
  243. if (sOrderBy == "ProjectNumber" || sOrderBy == "ResponsiblePerson")
  244. {
  245. var group_exp = bills.GroupBy(p => p.ParentId);
  246. foreach (IGrouping<string, View_OPM_BillIReport> bill_exp in group_exp)
  247. {
  248. var exp = saExps.Single(x => x.Id == bill_exp.Key);
  249. var exp_group = bill_exp.First();
  250. var iInCome_Cost = 0;
  251. var iCost_Cost = 0;
  252. var cost = (JObject)JsonConvert.DeserializeObject(exp.ActualCost);
  253. var iAmountTaxSum = double.Parse((cost.GetValue("AmountTaxSum") ?? "0").ToString().Replace(",", ""));
  254. iAmountTaxSum = ExhibitionHelper.Round(iAmountTaxSum, 0);
  255. iCost_Cost += int.Parse(iAmountTaxSum.ToString());
  256. if (exp_group.BillType == "ExhibitionImport_Upd" || exp_group.BillType == "ExhibitionExport_Upd")
  257. {
  258. var cost_rtns = (JArray)JsonConvert.DeserializeObject(exp.ReturnBills);
  259. foreach (var _cost_rtn in cost_rtns)
  260. {
  261. var _cost = (JObject)((JObject)_cost_rtn).GetValue("ActualCost");
  262. var iAmountTaxSum_ = double.Parse((_cost.GetValue("AmountTaxSum") ?? "0").ToString().Replace(",", ""));
  263. iAmountTaxSum_ = ExhibitionHelper.Round(iAmountTaxSum_, 0);
  264. iCost_Cost += int.Parse(iAmountTaxSum_.ToString());
  265. }
  266. }
  267. var iProfit_Cost = iInCome_Cost - iCost_Cost;
  268. iInCome_Sub += 0;
  269. iCost_Sub += iCost_Cost;
  270. iProfit_Sub += iProfit_Cost;
  271. if (iCost_Cost != 0)
  272. {
  273. var _projectName = oProjectNumbers.Any(x => x.Key == exp_group.ProjectNumber) ? oProjectNumbers.Single(x => x.Key == exp_group.ProjectNumber).Value : "";
  274. excelApp.SetCellValue(wsName, iCurrRow, 2, exp.RefNumber);
  275. excelApp.SetCellValue(wsName, iCurrRow, 4, _projectName);
  276. excelApp.SetCellValue(wsName, iCurrRow, 7, "");
  277. excelApp.SetCellValue(wsName, iCurrRow, 10, exp_group.ResponsiblePerson);
  278. excelApp.SetCellValue(wsName, iCurrRow, 11, "");
  279. excelApp.SetCellValue(wsName, iCurrRow, 14, $@"{iCost_Cost:N0}");
  280. excelApp.SetCellValue(wsName, iCurrRow, 17, $@"{iProfit_Cost:N0}");
  281. //複製并添加行
  282. range.Copy();
  283. range.Insert(XlDirection.xlDown);
  284. iCurrRow++;
  285. }
  286. }
  287. }
  288. //添加一個空行
  289. range.Insert(XlDirection.xlDown);
  290. Microsoft.Office.Interop.Excel.Range range_prev = excelApp.ws.Range[excelApp.ws.Cells[iCurrRow, 1], excelApp.ws.Cells[iCurrRow, 19]];
  291. //複製小計行
  292. range_SubTotal.Copy(range_prev);
  293. excelApp.SetCellValue(wsName, iCurrRow, 11, iInCome_Sub == 0 ? "" : $@"{iInCome_Sub:N0}");
  294. excelApp.SetCellValue(wsName, iCurrRow, 14, iCost_Sub == 0 ? "" : $@"{iCost_Sub:N0}");
  295. excelApp.SetCellValue(wsName, iCurrRow, 17, iProfit_Sub == 0 ? "" : $@"{iProfit_Sub:N0}");
  296. iCurrRow++;
  297. iInCome_Total += iInCome_Sub;
  298. iCost_Total += iCost_Sub;
  299. iProfit_Total += iProfit_Sub;
  300. }
  301. if (sOrderBy == "CustomerCode")
  302. {
  303. var group_exp = saBills.GroupBy(p => p.ParentId);
  304. var iInCome_Sub = 0;
  305. var iCost_Sub = 0;
  306. var iProfit_Sub = 0;
  307. foreach (IGrouping<string, View_OPM_BillIReport> bill_exp in group_exp)
  308. {
  309. var exp = saExps.Single(x => x.Id == bill_exp.Key);
  310. var exp_group = bill_exp.First();
  311. var iInCome_Cost = 0;
  312. var iCost_Cost = 0;
  313. var cost = (JObject)JsonConvert.DeserializeObject(exp.ActualCost);
  314. var iAmountTaxSum = double.Parse((cost.GetValue("AmountTaxSum") ?? "0").ToString().Replace(",", ""));
  315. iAmountTaxSum = ExhibitionHelper.Round(iAmountTaxSum, 0);
  316. iCost_Cost += int.Parse(iAmountTaxSum.ToString());
  317. if (exp_group.BillType == "ExhibitionImport_Upd" || exp_group.BillType == "ExhibitionExport_Upd")
  318. {
  319. var cost_rtns = (JArray)JsonConvert.DeserializeObject(exp.ReturnBills);
  320. foreach (var _cost_rtn in cost_rtns)
  321. {
  322. var _cost = (JObject)((JObject)_cost_rtn).GetValue("ActualCost");
  323. var iAmountTaxSum_ = double.Parse((_cost.GetValue("AmountTaxSum") ?? "0").ToString().Replace(",", ""));
  324. iAmountTaxSum_ = ExhibitionHelper.Round(iAmountTaxSum_, 0);
  325. iCost_Cost += int.Parse(iAmountTaxSum_.ToString());
  326. }
  327. }
  328. var iProfit_Cost = iInCome_Cost - iCost_Cost;
  329. iInCome_Sub += 0;
  330. iCost_Sub += iCost_Cost;
  331. iProfit_Sub += iProfit_Cost;
  332. if (iCost_Cost != 0)
  333. {
  334. var _projectName = oProjectNumbers.Any(x => x.Key == exp_group.ProjectNumber) ? oProjectNumbers.Single(x => x.Key == exp_group.ProjectNumber).Value : "";
  335. excelApp.SetCellValue(wsName, iCurrRow, 2, exp.RefNumber);
  336. excelApp.SetCellValue(wsName, iCurrRow, 4, _projectName);
  337. excelApp.SetCellValue(wsName, iCurrRow, 7, "");
  338. excelApp.SetCellValue(wsName, iCurrRow, 10, exp_group.ResponsiblePerson);
  339. excelApp.SetCellValue(wsName, iCurrRow, 11, "");
  340. excelApp.SetCellValue(wsName, iCurrRow, 14, $@"{iCost_Cost:N0}");
  341. excelApp.SetCellValue(wsName, iCurrRow, 17, $@"{iProfit_Cost:N0}");
  342. //複製并添加行
  343. range.Copy();
  344. range.Insert(XlDirection.xlDown);
  345. iCurrRow++;
  346. }
  347. }
  348. //添加一個空行
  349. range.Insert(XlDirection.xlDown);
  350. Microsoft.Office.Interop.Excel.Range range_prev = excelApp.ws.Range[excelApp.ws.Cells[iCurrRow, 1], excelApp.ws.Cells[iCurrRow, 19]];
  351. //複製小計行
  352. range_SubTotal.Copy(range_prev);
  353. excelApp.SetCellValue(wsName, iCurrRow, 11, iInCome_Sub == 0 ? "" : $@"{iInCome_Sub:N0}");
  354. excelApp.SetCellValue(wsName, iCurrRow, 14, iCost_Sub == 0 ? "" : $@"{iCost_Sub:N0}");
  355. excelApp.SetCellValue(wsName, iCurrRow, 17, iProfit_Sub == 0 ? "" : $@"{iProfit_Sub:N0}");
  356. iCurrRow++;
  357. iInCome_Total += iInCome_Sub;
  358. iCost_Total += iCost_Sub;
  359. iProfit_Total += iProfit_Sub;
  360. }
  361. range.Delete();
  362. //range_SubTotal.Delete();
  363. //總計
  364. excelApp.SetCellValue(wsName, 3, 8, iProfit_Total == 0 ? "" : $@"{iProfit_Total:N0}");
  365. if (iProfit_Total != 0)
  366. {
  367. excelApp.SetCellValue(wsName, iCurrRow, 10, "總計:");
  368. excelApp.SetCellValue(wsName, iCurrRow, 11, iInCome_Total == 0 ? "" : $@"{iInCome_Total:N0}");
  369. excelApp.SetCellValue(wsName, iCurrRow, 14, iCost_Total == 0 ? "" : $@"{iCost_Total:N0}");
  370. excelApp.SetCellValue(wsName, iCurrRow, 17, iProfit_Total == 0 ? "" : $@"{iProfit_Total:N0}");
  371. }
  372. excelApp.Save();
  373. if (File.Exists(sOutPut))
  374. {
  375. File.Delete(sOutPut);
  376. }
  377. if (sFlag == @"pdf")
  378. {
  379. sOutPut = sOutPut.Replace(@".xlsx", @".pdf").Replace(@".xls", @".pdf");
  380. excelApp.SaveAsPdf(sOutPut);
  381. }
  382. else
  383. {
  384. File.Copy(sTempFile, sOutPut);
  385. }
  386. excelApp.Close();
  387. File.Delete(sTempFile); //刪除臨時文件
  388. sOutPut = sOutPut.Replace(sBase, @"");
  389. rm = new SuccessResponseMessage(null, i_crm);
  390. rm.DATA.Add(BLWording.REL, sOutPut);
  391. }
  392. catch (Exception ex)
  393. {
  394. rm = new SuccessResponseMessage(null, i_crm);
  395. sMsg = ex.Message;
  396. excelApp.Close();
  397. throw new Exception(ex.Message, ex);
  398. }
  399. } while (false);
  400. }
  401. catch (Exception ex)
  402. {
  403. sMsg = Util.GetLastExceptionMsg(ex);
  404. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(BillsReportService), "", "Report(賬單利潤報表)", "", "", "");
  405. }
  406. finally
  407. {
  408. if (null != sMsg)
  409. {
  410. rm = new ErrorResponseMessage(sMsg, i_crm);
  411. }
  412. }
  413. return rm;
  414. }
  415. #endregion 賬單利潤報表
  416. #region 賬單利潤報表
  417. /// <summary>
  418. /// 賬單利潤報表
  419. /// </summary>
  420. /// <param name="i_crm"></param>
  421. /// <returns></returns>
  422. public ResponseMessage ReportPro(RequestMessage i_crm)
  423. {
  424. ResponseMessage rm = null;
  425. string sMsg = null;
  426. var sOutPut = Common.ConfigGetValue(@"", @"OutFilesPath");
  427. var db = SugarBase.GetIntance();
  428. var CurrencyName = CommonRPT.GetCurrencyUnit(i_crm.ORIGID);
  429. var RoundingPoint = CommonRPT.GetRoundingPoint(i_crm.ORIGID);
  430. try
  431. {
  432. do
  433. {
  434. #region 篩選資料
  435. var sResponsibleDeptID = _fetchString(i_crm, @"ResponsibleDeptID");
  436. var sResponsiblePerson = _fetchString(i_crm, @"ResponsiblePerson");
  437. var sProjectNO = _fetchString(i_crm, @"ProjectNO");
  438. var sPayer = _fetchString(i_crm, @"Payer");
  439. //var sBillNO = _fetchString(i_crm, @"BillNO");
  440. var sBillAuditDateStart = _fetchString(i_crm, @"BillAuditDateStart");
  441. var sBillAuditDateEnd = _fetchString(i_crm, @"BillAuditDateEnd");
  442. var sBillWriteOffDateStart = _fetchString(i_crm, @"BillWriteOffDateStart");
  443. var sBillWriteOffDateEnd = _fetchString(i_crm, @"BillWriteOffDateEnd");
  444. var sOrderBy = _fetchString(i_crm, @"OrderBy");
  445. var sFlag = _fetchString(i_crm, @"Flag");
  446. var Filter = new CVPFilter();
  447. var ChildDeptIDs = CommonRPT.GetChildDepteList(db, i_crm.ORIGID, sResponsibleDeptID);
  448. var MatchedExps = CommonRPT.GetMatchedExps(db, i_crm.ORIGID, ChildDeptIDs, sResponsiblePerson);
  449. var MatchedExpGuids = MatchedExps.Select(x => x.Guid).ToList().Distinct().ToArray();
  450. Filter.SetBill(sBillAuditDateStart, sBillAuditDateEnd, sBillWriteOffDateStart, sBillWriteOffDateEnd);
  451. var view = db.Queryable<OVW_OPM_Bills, OTB_OPM_BillInfo>
  452. ((t1, t2) =>
  453. new object[] {
  454. JoinType.Inner, t1.OrgID == t2.OrgID && t1.BillNO == t2.BillNO
  455. }
  456. )
  457. .Where((t1, t2) => t1.OrgID == i_crm.ORIGID && CommonRPT.PassStatus.Contains(t2.AuditVal))
  458. .WhereIF(!string.IsNullOrEmpty(sProjectNO), (t1) => t1.ProjectNumber.Contains(sProjectNO))
  459. .WhereIF(!string.IsNullOrEmpty(sPayer), (t1) => t1.CustomerCode.Contains(sPayer))
  460. .WhereIF(!string.IsNullOrEmpty(sResponsibleDeptID) || !string.IsNullOrEmpty(sResponsiblePerson),
  461. (t1, t2) => SqlFunc.ContainsArray(MatchedExpGuids, t2.ParentId))
  462. .WhereIF(!string.IsNullOrEmpty(Filter.sBillAuditDateStart), (t1, t2) => SqlFunc.ToDate(t2.BillFirstCheckDate) >= Filter.rBillAuditDateStart.Date)
  463. .WhereIF(!string.IsNullOrEmpty(Filter.sBillAuditDateEnd), (t1, t2) => SqlFunc.ToDate(t2.BillFirstCheckDate) < Filter.rBillAuditDateEnd.Date)
  464. .WhereIF(!string.IsNullOrEmpty(Filter.sBillWriteOffDateStart), (t1, t2) => SqlFunc.ToDate(t2.BillWriteOffDate) >= Filter.rBillWriteOffDateStart.Date)
  465. .WhereIF(!string.IsNullOrEmpty(Filter.sBillWriteOffDateEnd), (t1, t2) => SqlFunc.ToDate(t2.BillWriteOffDate) < Filter.rBillWriteOffDateEnd.Date);
  466. //OVW_OPM_Bills, OTB_OPM_BillInfo
  467. var saBills = view.Select((t1, t2) =>
  468. new View_OPM_BillIReport
  469. {
  470. BillNO = t2.BillNO,
  471. BillType = t2.BillType,
  472. ParentId = t2.ParentId,
  473. ProjectNumber = t1.ProjectNumber,
  474. CustomerCode = t1.CustomerCode,
  475. ResponsiblePerson = t1.ResponsiblePersonFullCode,
  476. Currency = t2.Currency,
  477. ExchangeRate = t2.ExchangeRate,
  478. InCome = t1.TWNOTaxAmount, //未稅總計
  479. OrgID = t2.OrgID,
  480. IsReturn = t2.IsRetn,
  481. Volume = t2.Volume,
  482. AuditVal = t2.AuditVal,
  483. ReFlow = t2.ReFlow,
  484. FeeItems = t2.FeeItems
  485. })
  486. .MergeTable()
  487. .OrderBy(sOrderBy, "asc")
  488. .ToList();
  489. var sProjectNumbers = view.Select((t1) => "," + t1.ProjectNumber + ",").ToJson();
  490. var sCustomerCodes = view.Select((t1) => "," + t1.CustomerCode + ",").ToJson();
  491. var sParentIds = view.Select((t1, t2) => "," + t2.ParentId + ",").ToJson();
  492. var oProjectNumbers = db.Queryable<OTB_OPM_Exhibition>()
  493. .Where(x => x.OrgID == i_crm.ORIGID && sProjectNumbers.Contains(x.ExhibitionCode) && x.Effective == "Y")
  494. .Select<KeyValuePair<string, string>>("ExhibitionCode,ExhibitioShotName_TW")
  495. .ToList();
  496. var oCustomers = db.Queryable<OTB_CRM_CustomersMST, OTB_CRM_Customers>
  497. ((t1, t2) =>
  498. new object[] {
  499. JoinType.Inner, t1.OrgID == t2.OrgID && t1.customer_guid == t2.guid
  500. }
  501. )
  502. .Where((t1, t2) => t1.OrgID == i_crm.ORIGID && sCustomerCodes.Contains(t1.CustomerNO) && t2.Effective == "Y")
  503. .Select<KeyValuePair<string, string>>("t1.CustomerNO,t2.CustomerShotCName")
  504. .ToList();
  505. #endregion
  506. //帳單代墊款代碼
  507. var saBillPrepayFee = Common.GetSystemSetting(db, i_crm.ORIGID, "PrepayForCustomerCode");
  508. var BillPrepayFeeList = saBillPrepayFee.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
  509. //實際代墊款代碼
  510. var saActualPrepayFee = Common.GetSystemSetting(db, i_crm.ORIGID, "ActualPrepayForCustomerCode");
  511. var ActualPrepayFeeList = saActualPrepayFee.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
  512. var sProjectName = "";
  513. var sCustomerName = "";
  514. if (!string.IsNullOrEmpty(sProjectNO))
  515. {
  516. sProjectName = db.Queryable<OTB_OPM_Exhibition>().Single(x => x.OrgID == i_crm.ORIGID && x.ExhibitionCode == sProjectNO).ExhibitioShotName_TW;
  517. }
  518. if (!string.IsNullOrEmpty(sPayer))
  519. {
  520. sCustomerName = db.Queryable<OTB_CRM_CustomersMST, OTB_CRM_Customers>
  521. ((t1, t2) =>
  522. new object[] {
  523. JoinType.Inner, t1.OrgID == t2.OrgID && t1.customer_guid == t2.guid
  524. }
  525. )
  526. .Select((t1, t2) => new OTB_CRM_Customers()
  527. {
  528. CustomerNO = t1.CustomerNO,
  529. CustomerShotCName = t2.CustomerShotCName,
  530. CustomerShotEName = t2.CustomerShotEName
  531. })
  532. .Single((t1) => t1.OrgID == i_crm.ORIGID && t1.CustomerNO == sPayer)
  533. .CustomerShotCName;
  534. }
  535. var oTempl = db.Queryable<OTB_SYS_OfficeTemplate>().Single(it => it.OrgID == i_crm.ORIGID && it.TemplID == "BillReportPro");
  536. if (oTempl == null)
  537. {
  538. sMsg = @"請檢查模版設定";
  539. break;
  540. }
  541. var oFile = db.Queryable<OTB_SYS_Files>().Single(it => it.OrgID == i_crm.ORIGID && it.ParentID == oTempl.FileID);
  542. if (oFile == null)
  543. {
  544. sMsg = @"系統找不到對應的報表模版";
  545. break;
  546. }
  547. var sTempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, oFile.FilePath);//Word模版路徑
  548. var sBase = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"");
  549. sOutPut = sBase + sOutPut;
  550. Common.FnCreateDir(sOutPut);//如果不存在就創建文件夾
  551. var sFileName = "利潤報表" + DateTime.Now.ToString(@"yyyy-MM-dd") + "_" + Guid.NewGuid();
  552. //建立臨時文件
  553. var sTempFile = Path.GetTempPath() + sFileName + @".xlsx";
  554. sOutPut += sFileName + @".xlsx";
  555. if (File.Exists(sTempFile))
  556. {
  557. File.Delete(sTempFile);
  558. }
  559. File.Copy(sTempPath, sTempFile);
  560. var cellsApp = new ExcelService(sTempFile);
  561. var cells = cellsApp.sheet.Cells;//单元格
  562. var iCurrRow = 4;
  563. var iStartCurrRow = iCurrRow;
  564. cells[1, 1].PutValue(sProjectName);//展覽
  565. cells[1, 4].PutValue(sCustomerName);//客戶
  566. cells[1, 7].PutValue(string.Join(",", ChildDeptIDs));//部門
  567. cells[1, 9].PutValue(i_crm.USERID);//列表人
  568. cells[2, 1].PutValue(sBillAuditDateStart + "~" + sBillAuditDateEnd);//賬單時間
  569. cells[2, 4].PutValue(sBillWriteOffDateStart + "~" + sBillWriteOffDateEnd);//帳單銷帳區間
  570. cells[2, 7].PutValue(sResponsiblePerson ?? "");//業務
  571. cells[2, 9].PutValue(DateTime.Now.ToString(@"yyyy/MM/dd"));//列印時間
  572. var AllofPorfits = new List<ProfitInfo>();
  573. var AllCBMUsage = CommonRPT.GetAllCBMUsages(db, i_crm.ORIGID);
  574. var group = saBills.GroupBy(p => sOrderBy == "ProjectNumber" ? p.ProjectNumber : sOrderBy == "CustomerCode" ? p.CustomerCode : p.ResponsiblePerson);
  575. foreach (IGrouping<string, View_OPM_BillIReport> bills in group)
  576. {
  577. var iInCome_Sub = 0;
  578. var iCost_Sub = 0;
  579. var iProfit_Sub = 0;
  580. var _bills = bills.OrderBy(x => x.BillType).ThenBy(x => x.ProjectNumber).ThenBy(x => x.ParentId);
  581. var SubProfits = new List<ProfitInfo>();
  582. foreach (View_OPM_BillIReport bill in _bills)
  583. {
  584. var ThisBillCBMUsage = AllCBMUsage.Where(t1 => t1.ParentID == bill.ParentId && t1.IsReturn == bill.IsReturn).ToList();
  585. var iInCome = bill.InCome * decimal.Parse(bill.ExchangeRate == "" ? "0" : bill.ExchangeRate);
  586. var iCost = 0;
  587. var iProfit = iInCome - iCost;
  588. iInCome_Sub += int.Parse($@"{iInCome:N0}".Replace(",", ""));
  589. iCost_Sub += int.Parse($@"{iCost:N0}".Replace(",", ""));
  590. var ActualCostFeeItemJson = "";
  591. var sActualCost = "";
  592. var sTransportationMode = "";
  593. CommonRPT.CalcuCostAndProfit(db, ref ActualCostFeeItemJson, ref sActualCost, ref sTransportationMode, bill.BillNO, bill.ParentId, bill.IsReturn, bill.ReFlow, bill.BillType);
  594. var ActualCostFeeItemList = CommonRPT.ToFeeItems(ActualCostFeeItemJson);
  595. var BillFeeItemList = CommonRPT.ToFeeItems(bill.FeeItems);
  596. var SharedActualCost = CommonRPT.GetShareCost(ActualCostFeeItemList, ThisBillCBMUsage, bill.BillNO);
  597. var BillReimburseAmount = BillFeeItemList.Where(c => BillPrepayFeeList.Contains(c.FinancialCode)).Sum(c => c.TWAmount); //帳單內特定費用代碼資料
  598. var ActualBillReimburseAmount = CommonRPT.GetShareCost(ActualCostFeeItemList, ThisBillCBMUsage, bill.BillNO, ActualPrepayFeeList);//抓實際成本的資料
  599. iProfit_Sub += int.Parse($@"{iProfit:N0}".Replace(",", ""));
  600. var _projectName = oProjectNumbers.Any(x => x.Key == bill.ProjectNumber) ? oProjectNumbers.Single(x => x.Key == bill.ProjectNumber).Value : "";
  601. var _customerName = oCustomers.Any(x => x.Key == bill.CustomerCode) ? oCustomers.Single(x => x.Key == bill.CustomerCode).Value : "";
  602. ProfitInfo profitInfo = new ProfitInfo()
  603. {
  604. BillNO = bill.BillNO,
  605. ExhibitionName = _projectName,
  606. CustomerName = _customerName,
  607. MemberID = bill.ResponsiblePerson,
  608. BillUntaxAmt = CommonRPT.Rounding(iInCome.Value, RoundingPoint),
  609. SharedActualCost = CommonRPT.Rounding(SharedActualCost, RoundingPoint),
  610. BillReimburseAmount = CommonRPT.Rounding(BillReimburseAmount, RoundingPoint),
  611. ActualBillReimburseAmount = CommonRPT.Rounding(ActualBillReimburseAmount, RoundingPoint),
  612. };
  613. CellsSetValue(cellsApp.workbook, cells, iCurrRow, profitInfo, "");
  614. iCurrRow++;
  615. SubProfits.Add(profitInfo);
  616. }
  617. //添加一個小計
  618. ProfitInfo SubtotalProfitInfo = new ProfitInfo()
  619. {
  620. MemberID = "小計:",
  621. BillUntaxAmt = CommonRPT.Rounding(SubProfits.Sum(c => c.BillUntaxAmt), RoundingPoint),
  622. SharedActualCost = CommonRPT.Rounding(SubProfits.Sum(c => c.SharedActualCost), RoundingPoint),
  623. BillReimburseAmount = CommonRPT.Rounding(SubProfits.Sum(c => c.BillReimburseAmount), RoundingPoint),
  624. ActualBillReimburseAmount = CommonRPT.Rounding(SubProfits.Sum(c => c.ActualBillReimburseAmount), RoundingPoint)
  625. };
  626. CellsSetValue(cellsApp.workbook, cells, iCurrRow, SubtotalProfitInfo, "sub");
  627. AllofPorfits.Add(SubtotalProfitInfo);
  628. iCurrRow++;
  629. }
  630. //總計
  631. if (AllofPorfits.Any())
  632. {
  633. ProfitInfo TotalProfitInfo = new ProfitInfo()
  634. {
  635. MemberID = "總計:",
  636. BillUntaxAmt = CommonRPT.Rounding(AllofPorfits.Sum(c => c.BillUntaxAmt), RoundingPoint),
  637. SharedActualCost = CommonRPT.Rounding(AllofPorfits.Sum(c => c.SharedActualCost), RoundingPoint),
  638. BillReimburseAmount = CommonRPT.Rounding(AllofPorfits.Sum(c => c.BillReimburseAmount), RoundingPoint),
  639. ActualBillReimburseAmount = CommonRPT.Rounding(AllofPorfits.Sum(c => c.ActualBillReimburseAmount), RoundingPoint)
  640. };
  641. CellsSetValue(cellsApp.workbook, cells, iCurrRow, TotalProfitInfo, "total");
  642. }
  643. //cellsApp.sheet.AutoFitColumns();
  644. cellsApp.sheet.AutoFitColumn(3, iStartCurrRow, cellsApp.sheet.Cells.Rows.Count);
  645. cellsApp.sheet.AutoFitRow(iStartCurrRow, 0, 10);
  646. //cellsApp.sheet.AutoFitRows(new AutoFitterOptions() { AutoFitMergedCells = true, IgnoreHidden = true, OnlyAuto = true });
  647. if (File.Exists(sOutPut))
  648. {
  649. File.Delete(sOutPut);
  650. }
  651. //保存
  652. cellsApp.workbook.Save(sOutPut);
  653. if (sFlag == @"pdf")
  654. {
  655. var excelApp = new ExcelEdit();
  656. try
  657. {
  658. excelApp.Open(sOutPut);
  659. sOutPut = sOutPut.Replace(@".xlsx", @".pdf").Replace(@".xls", @".pdf");
  660. excelApp.SaveAsPdf(sOutPut);
  661. excelApp.Close();
  662. }
  663. catch (Exception ex)
  664. {
  665. Logger.Error($"Report(賬單利潤報表)ERROR:{sMsg}, ex.StackTrace:{ ex.StackTrace }");
  666. excelApp.Close();
  667. throw;
  668. }
  669. }
  670. //File.Delete(sTempFile); //刪除臨時文件
  671. sOutPut = sOutPut.Replace(sBase, @"");
  672. rm = new SuccessResponseMessage(null, i_crm);
  673. rm.DATA.Add(BLWording.REL, sOutPut);
  674. } while (false);
  675. }
  676. catch (Exception ex)
  677. {
  678. sMsg = Util.GetLastExceptionMsg(ex);
  679. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(BillsReportService), "", "Report(賬單利潤報表)", "", "", "");
  680. }
  681. finally
  682. {
  683. if (null != sMsg)
  684. {
  685. rm = new ErrorResponseMessage(sMsg, i_crm);
  686. }
  687. }
  688. return rm;
  689. }
  690. #endregion 賬單利潤報表
  691. #region 專案管理資料
  692. /// <summary>
  693. /// 專案管理資料
  694. /// </summary>
  695. /// <param name="i_crm"></param>
  696. /// <returns></returns>
  697. public ResponseMessage GetProjects(RequestMessage i_crm)
  698. {
  699. ResponseMessage rm = null;
  700. string sMsg = null;
  701. var db = SugarBase.GetIntance();
  702. try
  703. {
  704. do
  705. {
  706. var saExhibition = db.Queryable<OTB_OPM_Exhibition>()
  707. .Where(x => x.OrgID == i_crm.ORIGID)
  708. .Select(x => new { id = x.ExhibitionCode, text = "(" + x.ExhibitioShotName_TW + ")" + x.Exhibitioname_TW })
  709. .ToList();
  710. rm = new SuccessResponseMessage(null, i_crm);
  711. rm.DATA.Add(BLWording.REL, saExhibition);
  712. } while (false);
  713. }
  714. catch (Exception ex)
  715. {
  716. sMsg = Util.GetLastExceptionMsg(ex);
  717. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(BillsReportService), "", "GetProjects(專案管理資料)", "", "", "");
  718. }
  719. finally
  720. {
  721. if (null != sMsg)
  722. {
  723. rm = new ErrorResponseMessage(sMsg, i_crm);
  724. }
  725. }
  726. return rm;
  727. }
  728. #endregion 專案管理資料
  729. #region 客戶資料
  730. /// <summary>
  731. /// 客戶資料
  732. /// </summary>
  733. /// <param name="i_crm"></param>
  734. /// <returns></returns>
  735. public ResponseMessage GetPayers(RequestMessage i_crm)
  736. {
  737. ResponseMessage rm = null;
  738. string sMsg = null;
  739. var db = SugarBase.GetIntance();
  740. try
  741. {
  742. do
  743. {
  744. var saCustomers = db.Queryable<OTB_CRM_Customers>()
  745. .Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y")
  746. .Select(x => new { id = x.CustomerNO, text = "(" + x.CustomerShotCName + ")" + SqlFunc.IIF(x.CustomerCName == "", x.CustomerEName, x.CustomerCName) })
  747. .ToList();
  748. rm = new SuccessResponseMessage(null, i_crm);
  749. rm.DATA.Add(BLWording.REL, saCustomers);
  750. } while (false);
  751. }
  752. catch (Exception ex)
  753. {
  754. sMsg = Util.GetLastExceptionMsg(ex);
  755. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(BillsReportService), "", "GetPayers(客戶資料)", "", "", "");
  756. }
  757. finally
  758. {
  759. if (null != sMsg)
  760. {
  761. rm = new ErrorResponseMessage(sMsg, i_crm);
  762. }
  763. }
  764. return rm;
  765. }
  766. #endregion 客戶資料
  767. private void CellsSetValue(Aspose.Cells.Workbook workbook, Cells cells, int irow, ProfitInfo profitInfo, string flag)
  768. {
  769. var style_Text = GetStyle(workbook, 0, false, TextAlignmentType.Left, Color.White, true);
  770. var style_Number = GetStyle(workbook, 0, false, TextAlignmentType.Right, Color.White, true);
  771. style_Number.Number = 4;
  772. var style = GetStyle(workbook, 0, true, TextAlignmentType.Right, Color.White, true);
  773. cells.SetRowHeight(irow, 20);
  774. cells[irow, 0].PutValue(profitInfo.BillNO);
  775. cells[irow, 0].SetStyle(style_Text);
  776. cells[irow, 1].PutValue(profitInfo.ExhibitionName);
  777. cells[irow, 1].SetStyle(style_Text);
  778. cells[irow, 2].PutValue(profitInfo.CustomerName);
  779. cells[irow, 2].SetStyle(style_Text);
  780. cells[irow, 3].PutValue(profitInfo.MemberID);
  781. cells[irow, 3].SetStyle(style_Text);
  782. cells[irow, 4].PutValue(profitInfo.BillUntaxAmt);
  783. cells[irow, 4].SetStyle(style_Number);
  784. cells[irow, 5].PutValue(profitInfo.SharedActualCost);
  785. cells[irow, 5].SetStyle(style_Number);
  786. cells[irow, 6].PutValue(profitInfo.GrossProfit);
  787. cells[irow, 6].SetStyle(style_Number);
  788. cells[irow, 7].PutValue(profitInfo.BillReimburseAmount);
  789. cells[irow, 7].SetStyle(style_Number);
  790. cells[irow, 8].PutValue(profitInfo.ActualBillReimburseAmount);
  791. cells[irow, 8].SetStyle(style_Number);
  792. cells[irow, 9].PutValue(profitInfo.NetProfit);
  793. cells[irow, 9].SetStyle(style_Number);
  794. //cells.Merge(irow, 1, 1, 2);//合并单元格(賬單號碼)
  795. ////依序:展覽簡稱、客戶簡稱、業務員、未稅金額、實際成本、毛利、帳單代墊款、實際代墊款、淨毛利
  796. //var ColumnIndex = new int[] { 3, 6, 10, 13, 16, 19, 22, 25 };
  797. //foreach (var ci in ColumnIndex)
  798. //{
  799. // cells.Merge(irow, ci, 1, 3);//合并单元格(展覽簡稱)
  800. //}
  801. //cells.SetRowHeight(irow, 20);
  802. //var MaxColumnIndex = 1;//ColumnIndex.Last() + 3;
  803. //if (flag == "sub" || flag == "total")
  804. //{
  805. // for (var index = 9; index < MaxColumnIndex; index++)
  806. // {
  807. // cells[irow, index].SetStyle(style);
  808. // }
  809. //}
  810. //else
  811. //{
  812. // for (var index = 1; index < MaxColumnIndex; index++)
  813. // {
  814. // if (index < 10)
  815. // {
  816. // cells[irow, index].SetStyle(style_L);//居左
  817. // }
  818. // else
  819. // {
  820. // cells[irow, index].SetStyle(style_R);//居右(INCOME)
  821. // }
  822. // }
  823. //}
  824. }
  825. /// <summary>
  826. /// 固定的樣式
  827. /// </summary>
  828. /// <param name="sFontSize"></param>
  829. /// <param name="bIsBold"></param>
  830. /// <param name="sAlign"></param>
  831. /// <param name="sBgColor"></param>
  832. /// <param name="bIsWrap"></param>
  833. /// <param name="workbook">todo: describe workbook parameter on GetStyle</param>
  834. /// <returns></returns>
  835. public static Aspose.Cells.Style GetStyle(Aspose.Cells.Workbook workbook, int sFontSize, bool bIsBold, TextAlignmentType sAlign, Color sBgColor, bool bIsWrap)
  836. {
  837. var style = workbook.CreateStyle();
  838. style.HorizontalAlignment = sAlign;//文字居左/中/右 ---TextAlignmentType.Center
  839. //style.Font.Color = Color.Blue;
  840. if (sFontSize != 0)
  841. {
  842. style.Font.Size = sFontSize;//文字大小 ----12
  843. }
  844. style.Font.IsBold = bIsBold;//粗体 ----false
  845. style.ForegroundColor = sBgColor;//背景顏色
  846. style.Pattern = BackgroundType.Solid;//设置背景類型
  847. style.IsTextWrapped = bIsWrap;//单元格内容自动换行
  848. // 邊線設置
  849. style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
  850. return style;
  851. }
  852. public OVW_OPM_BillInfo ToBillInfo(View_OPM_BillIReport billIReport)
  853. {
  854. return new OVW_OPM_BillInfo()
  855. {
  856. OrgID = billIReport.OrgID,
  857. ParentId = billIReport.ParentId,
  858. IsRetn = billIReport.IsReturn,
  859. AuditVal = billIReport.AuditVal,
  860. Volume = billIReport.Volume,
  861. };
  862. }
  863. }
  864. }