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.

931 lines
53 KiB

3 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. List<CbmVolume> ThisBillCBMUsage = new List<CbmVolume>();
  585. if (bill.IsReturn != "Y")
  586. {
  587. ThisBillCBMUsage = AllCBMUsage.Where(t1 => t1.ParentID == bill.ParentId && t1.IsReturn == bill.IsReturn).ToList();
  588. } else
  589. {
  590. ThisBillCBMUsage = AllCBMUsage.Where(t1 => t1.ParentID == bill.ParentId && t1.IsReturn == bill.IsReturn && t1.ReFlow == bill.ReFlow).ToList();
  591. }
  592. //var ThisBillCBMUsage = AllCBMUsage.Where(t1 => t1.ParentID == bill.ParentId && t1.IsReturn == bill.IsReturn).ToList();
  593. var iInCome = bill.InCome * decimal.Parse(bill.ExchangeRate == "" ? "0" : bill.ExchangeRate);
  594. var iCost = 0;
  595. var iProfit = iInCome - iCost;
  596. iInCome_Sub += int.Parse($@"{iInCome:N0}".Replace(",", ""));
  597. iCost_Sub += int.Parse($@"{iCost:N0}".Replace(",", ""));
  598. var ActualCostFeeItemJson = "";
  599. var sActualCost = "";
  600. var sTransportationMode = "";
  601. CommonRPT.CalcuCostAndProfit(db, ref ActualCostFeeItemJson, ref sActualCost, ref sTransportationMode, bill.BillNO, bill.ParentId, bill.IsReturn, bill.ReFlow, bill.BillType);
  602. var ActualCostFeeItemList = CommonRPT.ToFeeItems(ActualCostFeeItemJson);
  603. var BillFeeItemList = CommonRPT.ToFeeItems(bill.FeeItems);
  604. var SharedActualCost = CommonRPT.GetShareCost(ActualCostFeeItemList, ThisBillCBMUsage, bill.BillNO);
  605. var BillReimburseAmount = BillFeeItemList.Where(c => BillPrepayFeeList.Contains(c.FinancialCode)).Sum(c => c.TWAmount); //帳單內特定費用代碼資料
  606. var ActualBillReimburseAmount = CommonRPT.GetShareCost(ActualCostFeeItemList, ThisBillCBMUsage, bill.BillNO, ActualPrepayFeeList);//抓實際成本的資料
  607. BillReimburseAmount = BillReimburseAmount * decimal.Parse(bill.ExchangeRate == "" ? "1" : bill.ExchangeRate);
  608. iProfit_Sub += int.Parse($@"{iProfit:N0}".Replace(",", ""));
  609. var _projectName = oProjectNumbers.Any(x => x.Key == bill.ProjectNumber) ? oProjectNumbers.Single(x => x.Key == bill.ProjectNumber).Value : "";
  610. var _customerName = oCustomers.Any(x => x.Key == bill.CustomerCode) ? oCustomers.Single(x => x.Key == bill.CustomerCode).Value : "";
  611. ProfitInfo profitInfo = new ProfitInfo()
  612. {
  613. BillNO = bill.BillNO,
  614. ExhibitionName = _projectName,
  615. CustomerName = _customerName,
  616. MemberID = bill.ResponsiblePerson,
  617. BillUntaxAmt = CommonRPT.Rounding(iInCome.Value, RoundingPoint),
  618. SharedActualCost = CommonRPT.Rounding(SharedActualCost, RoundingPoint),
  619. BillReimburseAmount = CommonRPT.Rounding(BillReimburseAmount, RoundingPoint),
  620. ActualBillReimburseAmount = CommonRPT.Rounding(ActualBillReimburseAmount, RoundingPoint),
  621. };
  622. CellsSetValue(cellsApp.workbook, cells, iCurrRow, profitInfo, "");
  623. iCurrRow++;
  624. SubProfits.Add(profitInfo);
  625. }
  626. //添加一個小計
  627. ProfitInfo SubtotalProfitInfo = new ProfitInfo()
  628. {
  629. MemberID = "小計:",
  630. BillUntaxAmt = CommonRPT.Rounding(SubProfits.Sum(c => c.BillUntaxAmt), RoundingPoint),
  631. SharedActualCost = CommonRPT.Rounding(SubProfits.Sum(c => c.SharedActualCost), RoundingPoint),
  632. BillReimburseAmount = CommonRPT.Rounding(SubProfits.Sum(c => c.BillReimburseAmount), RoundingPoint),
  633. ActualBillReimburseAmount = CommonRPT.Rounding(SubProfits.Sum(c => c.ActualBillReimburseAmount), RoundingPoint)
  634. };
  635. CellsSetValue(cellsApp.workbook, cells, iCurrRow, SubtotalProfitInfo, "sub");
  636. AllofPorfits.Add(SubtotalProfitInfo);
  637. iCurrRow++;
  638. }
  639. //總計
  640. if (AllofPorfits.Any())
  641. {
  642. ProfitInfo TotalProfitInfo = new ProfitInfo()
  643. {
  644. MemberID = "總計:",
  645. BillUntaxAmt = CommonRPT.Rounding(AllofPorfits.Sum(c => c.BillUntaxAmt), RoundingPoint),
  646. SharedActualCost = CommonRPT.Rounding(AllofPorfits.Sum(c => c.SharedActualCost), RoundingPoint),
  647. BillReimburseAmount = CommonRPT.Rounding(AllofPorfits.Sum(c => c.BillReimburseAmount), RoundingPoint),
  648. ActualBillReimburseAmount = CommonRPT.Rounding(AllofPorfits.Sum(c => c.ActualBillReimburseAmount), RoundingPoint)
  649. };
  650. CellsSetValue(cellsApp.workbook, cells, iCurrRow, TotalProfitInfo, "total");
  651. }
  652. //cellsApp.sheet.AutoFitColumns();
  653. cellsApp.sheet.AutoFitColumn(3, iStartCurrRow, cellsApp.sheet.Cells.Rows.Count);
  654. cellsApp.sheet.AutoFitRow(iStartCurrRow, 0, 10);
  655. //cellsApp.sheet.AutoFitRows(new AutoFitterOptions() { AutoFitMergedCells = true, IgnoreHidden = true, OnlyAuto = true });
  656. if (File.Exists(sOutPut))
  657. {
  658. File.Delete(sOutPut);
  659. }
  660. //保存
  661. cellsApp.workbook.Save(sOutPut);
  662. if (sFlag == @"pdf")
  663. {
  664. var excelApp = new ExcelEdit();
  665. try
  666. {
  667. excelApp.Open(sOutPut);
  668. sOutPut = sOutPut.Replace(@".xlsx", @".pdf").Replace(@".xls", @".pdf");
  669. excelApp.SaveAsPdf(sOutPut);
  670. excelApp.Close();
  671. }
  672. catch (Exception ex)
  673. {
  674. Logger.Error($"Report(賬單利潤報表)ERROR:{sMsg}, ex.StackTrace:{ ex.StackTrace }");
  675. excelApp.Close();
  676. throw;
  677. }
  678. }
  679. //File.Delete(sTempFile); //刪除臨時文件
  680. sOutPut = sOutPut.Replace(sBase, @"");
  681. rm = new SuccessResponseMessage(null, i_crm);
  682. rm.DATA.Add(BLWording.REL, sOutPut);
  683. } while (false);
  684. }
  685. catch (Exception ex)
  686. {
  687. sMsg = Util.GetLastExceptionMsg(ex);
  688. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(BillsReportService), "", "Report(賬單利潤報表)", "", "", "");
  689. }
  690. finally
  691. {
  692. if (null != sMsg)
  693. {
  694. rm = new ErrorResponseMessage(sMsg, i_crm);
  695. }
  696. }
  697. return rm;
  698. }
  699. #endregion 賬單利潤報表
  700. #region 專案管理資料
  701. /// <summary>
  702. /// 專案管理資料
  703. /// </summary>
  704. /// <param name="i_crm"></param>
  705. /// <returns></returns>
  706. public ResponseMessage GetProjects(RequestMessage i_crm)
  707. {
  708. ResponseMessage rm = null;
  709. string sMsg = null;
  710. var db = SugarBase.GetIntance();
  711. try
  712. {
  713. do
  714. {
  715. var saExhibition = db.Queryable<OTB_OPM_Exhibition>()
  716. .Where(x => x.OrgID == i_crm.ORIGID)
  717. .Select(x => new { id = x.ExhibitionCode, text = "(" + x.ExhibitioShotName_TW + ")" + x.Exhibitioname_TW })
  718. .ToList();
  719. rm = new SuccessResponseMessage(null, i_crm);
  720. rm.DATA.Add(BLWording.REL, saExhibition);
  721. } while (false);
  722. }
  723. catch (Exception ex)
  724. {
  725. sMsg = Util.GetLastExceptionMsg(ex);
  726. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(BillsReportService), "", "GetProjects(專案管理資料)", "", "", "");
  727. }
  728. finally
  729. {
  730. if (null != sMsg)
  731. {
  732. rm = new ErrorResponseMessage(sMsg, i_crm);
  733. }
  734. }
  735. return rm;
  736. }
  737. #endregion 專案管理資料
  738. #region 客戶資料
  739. /// <summary>
  740. /// 客戶資料
  741. /// </summary>
  742. /// <param name="i_crm"></param>
  743. /// <returns></returns>
  744. public ResponseMessage GetPayers(RequestMessage i_crm)
  745. {
  746. ResponseMessage rm = null;
  747. string sMsg = null;
  748. var db = SugarBase.GetIntance();
  749. try
  750. {
  751. do
  752. {
  753. var saCustomers = db.Queryable<OTB_CRM_Customers>()
  754. .Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y")
  755. .Select(x => new { id = x.CustomerNO, text = "(" + x.CustomerShotCName + ")" + SqlFunc.IIF(x.CustomerCName == "", x.CustomerEName, x.CustomerCName) })
  756. .ToList();
  757. rm = new SuccessResponseMessage(null, i_crm);
  758. rm.DATA.Add(BLWording.REL, saCustomers);
  759. } while (false);
  760. }
  761. catch (Exception ex)
  762. {
  763. sMsg = Util.GetLastExceptionMsg(ex);
  764. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(BillsReportService), "", "GetPayers(客戶資料)", "", "", "");
  765. }
  766. finally
  767. {
  768. if (null != sMsg)
  769. {
  770. rm = new ErrorResponseMessage(sMsg, i_crm);
  771. }
  772. }
  773. return rm;
  774. }
  775. #endregion 客戶資料
  776. private void CellsSetValue(Aspose.Cells.Workbook workbook, Cells cells, int irow, ProfitInfo profitInfo, string flag)
  777. {
  778. var style_Text = GetStyle(workbook, 0, false, TextAlignmentType.Left, Color.White, true);
  779. var style_Number = GetStyle(workbook, 0, false, TextAlignmentType.Right, Color.White, true);
  780. style_Number.Number = 4;
  781. var style = GetStyle(workbook, 0, true, TextAlignmentType.Right, Color.White, true);
  782. cells.SetRowHeight(irow, 20);
  783. cells[irow, 0].PutValue(profitInfo.BillNO);
  784. cells[irow, 0].SetStyle(style_Text);
  785. cells[irow, 1].PutValue(profitInfo.ExhibitionName);
  786. cells[irow, 1].SetStyle(style_Text);
  787. cells[irow, 2].PutValue(profitInfo.CustomerName);
  788. cells[irow, 2].SetStyle(style_Text);
  789. cells[irow, 3].PutValue(profitInfo.MemberID);
  790. cells[irow, 3].SetStyle(style_Text);
  791. cells[irow, 4].PutValue(profitInfo.BillUntaxAmt);
  792. cells[irow, 4].SetStyle(style_Number);
  793. cells[irow, 5].PutValue(profitInfo.SharedActualCost);
  794. cells[irow, 5].SetStyle(style_Number);
  795. cells[irow, 6].PutValue(profitInfo.GrossProfit);
  796. cells[irow, 6].SetStyle(style_Number);
  797. cells[irow, 7].PutValue(profitInfo.BillReimburseAmount);
  798. cells[irow, 7].SetStyle(style_Number);
  799. cells[irow, 8].PutValue(profitInfo.ActualBillReimburseAmount);
  800. cells[irow, 8].SetStyle(style_Number);
  801. cells[irow, 9].PutValue(profitInfo.NetProfit);
  802. cells[irow, 9].SetStyle(style_Number);
  803. //cells.Merge(irow, 1, 1, 2);//合并单元格(賬單號碼)
  804. ////依序:展覽簡稱、客戶簡稱、業務員、未稅金額、實際成本、毛利、帳單代墊款、實際代墊款、淨毛利
  805. //var ColumnIndex = new int[] { 3, 6, 10, 13, 16, 19, 22, 25 };
  806. //foreach (var ci in ColumnIndex)
  807. //{
  808. // cells.Merge(irow, ci, 1, 3);//合并单元格(展覽簡稱)
  809. //}
  810. //cells.SetRowHeight(irow, 20);
  811. //var MaxColumnIndex = 1;//ColumnIndex.Last() + 3;
  812. //if (flag == "sub" || flag == "total")
  813. //{
  814. // for (var index = 9; index < MaxColumnIndex; index++)
  815. // {
  816. // cells[irow, index].SetStyle(style);
  817. // }
  818. //}
  819. //else
  820. //{
  821. // for (var index = 1; index < MaxColumnIndex; index++)
  822. // {
  823. // if (index < 10)
  824. // {
  825. // cells[irow, index].SetStyle(style_L);//居左
  826. // }
  827. // else
  828. // {
  829. // cells[irow, index].SetStyle(style_R);//居右(INCOME)
  830. // }
  831. // }
  832. //}
  833. }
  834. /// <summary>
  835. /// 固定的樣式
  836. /// </summary>
  837. /// <param name="sFontSize"></param>
  838. /// <param name="bIsBold"></param>
  839. /// <param name="sAlign"></param>
  840. /// <param name="sBgColor"></param>
  841. /// <param name="bIsWrap"></param>
  842. /// <param name="workbook">todo: describe workbook parameter on GetStyle</param>
  843. /// <returns></returns>
  844. public static Aspose.Cells.Style GetStyle(Aspose.Cells.Workbook workbook, int sFontSize, bool bIsBold, TextAlignmentType sAlign, Color sBgColor, bool bIsWrap)
  845. {
  846. var style = workbook.CreateStyle();
  847. style.HorizontalAlignment = sAlign;//文字居左/中/右 ---TextAlignmentType.Center
  848. //style.Font.Color = Color.Blue;
  849. if (sFontSize != 0)
  850. {
  851. style.Font.Size = sFontSize;//文字大小 ----12
  852. }
  853. style.Font.IsBold = bIsBold;//粗体 ----false
  854. style.ForegroundColor = sBgColor;//背景顏色
  855. style.Pattern = BackgroundType.Solid;//设置背景類型
  856. style.IsTextWrapped = bIsWrap;//单元格内容自动换行
  857. // 邊線設置
  858. style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
  859. return style;
  860. }
  861. public OVW_OPM_BillInfo ToBillInfo(View_OPM_BillIReport billIReport)
  862. {
  863. return new OVW_OPM_BillInfo()
  864. {
  865. OrgID = billIReport.OrgID,
  866. ParentId = billIReport.ParentId,
  867. IsRetn = billIReport.IsReturn,
  868. AuditVal = billIReport.AuditVal,
  869. Volume = billIReport.Volume,
  870. };
  871. }
  872. }
  873. }