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.

631 lines
43 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using SqlSugar;
  6. using SqlSugar.Base;
  7. using System;
  8. using System.Collections.Generic;
  9. namespace EasyBL.WEBAPP.OPM
  10. {
  11. public class Accounting_QryService : ServiceBase
  12. {
  13. public class BillPayerInfo
  14. {
  15. public int RowIndex { get; set; }
  16. public string ExhibitioName { get; set; }
  17. public string BillNO { get; set; }
  18. public string Payer { get; set; }
  19. public string CreateDate { get; set; }
  20. public string Amount { get; set; }
  21. }
  22. #region 成本押款和稅金查詢
  23. /// <summary>
  24. /// 成本押款和稅金查詢
  25. /// </summary>
  26. /// <param name="i_crm">todo: describe i_crm parameter on GetBillsList</param>
  27. /// <returns></returns>
  28. public ResponseMessage GetBillsList(RequestMessage i_crm)
  29. {
  30. ResponseMessage rm = null;
  31. string sMsg = null;
  32. var db = SugarBase.GetIntance();
  33. var list = new List<BillPayerInfo>();
  34. try
  35. {
  36. do
  37. {
  38. var sFeeClass = _fetchString(i_crm, @"FeeClass");
  39. var sCheckDateStart = _fetchString(i_crm, @"CheckDateStart");
  40. var sCheckDateEnd = _fetchString(i_crm, @"CheckDateEnd");
  41. var rCheckDateStart = SqlFunc.ToDate(sCheckDateStart).Date;
  42. var rCheckDateEnd = SqlFunc.ToDate(sCheckDateEnd).Date;
  43. var saFeeClass = sFeeClass.Split(',');
  44. foreach (string feeclass in saFeeClass)
  45. {
  46. var listIm = db.Queryable<OTB_OPM_ImportExhibition, OTB_OPM_Exhibition>((a, b) =>
  47. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.ExhibitionNO == b.SN.ToString() })
  48. .Where((a, b) => a.OrgID == i_crm.ORIGID && (SqlFunc.Contains(a.ActualCost, feeclass) || SqlFunc.Contains(a.ReturnBills, feeclass)))
  49. .Select((a, b) => new { a.ActualCost, a.ReturnBills, a.ImportBillName, b.ExhibitionCode }).ToList();
  50. foreach (var im in listIm)
  51. {
  52. var JActualCost = (JObject)JsonConvert.DeserializeObject(im.ActualCost);
  53. if (JActualCost[@"FeeItems"] != null)
  54. {
  55. var jaFeeItems = JActualCost[@"FeeItems"] as JArray;
  56. foreach (JObject jo in jaFeeItems)
  57. {
  58. if (jo[@"FinancialCode"] != null && jo[@"FinancialCode"].ToString() == feeclass)
  59. {
  60. var sBillNO = jo[@"BillNO"] == null ? @"" : jo[@"BillNO"].ToString();
  61. var sBillPayer = jo[@"BillPayer"] == null ? @"" : jo[@"BillPayer"].ToString();
  62. var saBillPayer = sBillPayer.Split('-');
  63. var oCustomers = new OTB_CRM_Customers();
  64. if (sBillNO != null)
  65. {
  66. oCustomers = db.Queryable<OTB_CRM_Customers, OTB_OPM_BillInfo>((a, b) =>
  67. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.guid == b.Payer })
  68. .Where((a, b) => a.OrgID == i_crm.ORIGID && b.BillNO == sBillNO)
  69. .Select((a, b) => a).Single();
  70. }
  71. var bpinfo = new BillPayerInfo
  72. {
  73. ExhibitioName = im.ExhibitionCode + @" - " + im.ImportBillName,
  74. BillNO = sBillPayer == @"" ? @"" : saBillPayer[0],
  75. Payer = (oCustomers == null ? @"" : (oCustomers.CustomerNO ?? @"") + @" - ") + (sBillPayer == @"" ? @"" : saBillPayer[1]),
  76. CreateDate = sBillPayer == @"" ? @"" : saBillPayer[2],
  77. Amount = jo[@"FinancialTWAmount"].ToString()
  78. };
  79. list.Add(bpinfo);
  80. }
  81. }
  82. }
  83. var JaReturnBills = (JArray)JsonConvert.DeserializeObject(im.ReturnBills);
  84. foreach (JObject bill in JaReturnBills)
  85. {
  86. if (bill[@"ActualCost"] != null)
  87. {
  88. var JReturnActualCost = (JObject)JsonConvert.DeserializeObject(bill[@"ActualCost"].ToString());
  89. if (JReturnActualCost[@"FeeItems"] != null)
  90. {
  91. var jaFeeItems = JReturnActualCost[@"FeeItems"] as JArray;
  92. foreach (JObject jo in jaFeeItems)
  93. {
  94. if (jo[@"FinancialCode"] != null && jo[@"FinancialCode"].ToString() == feeclass)
  95. {
  96. var sBillNO = jo[@"BillNO"] == null ? @"" : jo[@"BillNO"].ToString();
  97. var sBillPayer = jo[@"BillPayer"] == null ? @"" : jo[@"BillPayer"].ToString();
  98. var saBillPayer = sBillPayer.Split('-');
  99. var oCustomers = new OTB_CRM_Customers();
  100. if (sBillNO != null)
  101. {
  102. oCustomers = db.Queryable<OTB_CRM_Customers, OTB_OPM_BillInfo>((a, b) =>
  103. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.guid == b.Payer })
  104. .Where((a, b) => a.OrgID == i_crm.ORIGID && b.BillNO == sBillNO)
  105. .Select((a, b) => a).Single();
  106. }
  107. var bpinfo = new BillPayerInfo
  108. {
  109. ExhibitioName = im.ExhibitionCode + @" - " + im.ImportBillName,
  110. BillNO = sBillPayer == @"" ? @"" : saBillPayer[0],
  111. Payer = (oCustomers == null ? @"" : (oCustomers.CustomerNO ?? @"") + @" - ") + (sBillPayer == @"" ? @"" : saBillPayer[1]),
  112. CreateDate = sBillPayer == @"" ? @"" : saBillPayer[2],
  113. Amount = jo[@"FinancialTWAmount"].ToString()
  114. };
  115. list.Add(bpinfo);
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. var listEx = db.Queryable<OTB_OPM_ExportExhibition, OTB_OPM_Exhibition>((a, b) =>
  123. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.ExhibitionNO == b.SN.ToString() })
  124. .Where((a, b) => a.OrgID == i_crm.ORIGID && (SqlFunc.Contains(a.ActualCost, feeclass) || SqlFunc.Contains(a.ReturnBills, feeclass)))
  125. .Select((a, b) => new { a.ActualCost, a.ReturnBills, a.ExportBillName, b.ExhibitionCode }).ToList();
  126. foreach (var _ex in listEx)
  127. {
  128. var JActualCost = (JObject)JsonConvert.DeserializeObject(_ex.ActualCost);
  129. if (JActualCost[@"FeeItems"] != null)
  130. {
  131. var jaFeeItems = JActualCost[@"FeeItems"] as JArray;
  132. foreach (JObject jo in jaFeeItems)
  133. {
  134. if (jo[@"FinancialCode"] != null && jo[@"FinancialCode"].ToString() == feeclass)
  135. {
  136. var sBillNO = jo[@"BillNO"] == null ? @"" : jo[@"BillNO"].ToString();
  137. var sBillPayer = jo[@"BillPayer"] == null ? @"" : jo[@"BillPayer"].ToString();
  138. var saBillPayer = sBillPayer.Split('-');
  139. var oCustomers = new OTB_CRM_Customers();
  140. if (sBillNO != null)
  141. {
  142. oCustomers = db.Queryable<OTB_CRM_Customers, OTB_OPM_BillInfo>((a, b) =>
  143. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.guid == b.Payer })
  144. .Where((a, b) => a.OrgID == i_crm.ORIGID && b.BillNO == sBillNO)
  145. .Select((a, b) => a).Single();
  146. }
  147. var bpinfo = new BillPayerInfo
  148. {
  149. ExhibitioName = _ex.ExhibitionCode + @" - " + _ex.ExportBillName,
  150. BillNO = sBillPayer == @"" ? @"" : saBillPayer[0],
  151. Payer = (oCustomers == null ? @"" : (oCustomers.CustomerNO ?? @"") + @" - ") + (sBillPayer == @"" ? @"" : saBillPayer[1]),
  152. CreateDate = sBillPayer == @"" ? @"" : saBillPayer[2],
  153. Amount = jo[@"FinancialTWAmount"].ToString()
  154. };
  155. list.Add(bpinfo);
  156. }
  157. }
  158. }
  159. var JaReturnBills = (JArray)JsonConvert.DeserializeObject(_ex.ReturnBills);
  160. foreach (JObject bill in JaReturnBills)
  161. {
  162. if (bill[@"ActualCost"] != null)
  163. {
  164. var JReturnActualCost = (JObject)JsonConvert.DeserializeObject(bill[@"ActualCost"].ToString());
  165. if (JReturnActualCost[@"FeeItems"] != null)
  166. {
  167. var jaFeeItems = JReturnActualCost[@"FeeItems"] as JArray;
  168. foreach (JObject jo in jaFeeItems)
  169. {
  170. if (jo[@"FinancialCode"] != null && jo[@"FinancialCode"].ToString() == feeclass)
  171. {
  172. var sBillNO = jo[@"BillNO"] == null ? @"" : jo[@"BillNO"].ToString();
  173. var sBillPayer = jo[@"BillPayer"] == null ? @"" : jo[@"BillPayer"].ToString();
  174. var saBillPayer = sBillPayer.Split('-');
  175. var oCustomers = new OTB_CRM_Customers();
  176. if (sBillNO != null)
  177. {
  178. oCustomers = db.Queryable<OTB_CRM_Customers, OTB_OPM_BillInfo>((a, b) =>
  179. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.guid == b.Payer })
  180. .Where((a, b) => a.OrgID == i_crm.ORIGID && b.BillNO == sBillNO)
  181. .Select((a, b) => a).Single();
  182. }
  183. var bpinfo = new BillPayerInfo
  184. {
  185. ExhibitioName = _ex.ExhibitionCode + @" - " + _ex.ExportBillName,
  186. BillNO = sBillPayer == @"" ? @"" : saBillPayer[0],
  187. Payer = (oCustomers == null ? @"" : (oCustomers.CustomerNO ?? @"") + @" - ") + (sBillPayer == @"" ? @"" : saBillPayer[1]),
  188. CreateDate = sBillPayer == @"" ? @"" : saBillPayer[2],
  189. Amount = jo[@"FinancialTWAmount"].ToString()
  190. };
  191. list.Add(bpinfo);
  192. }
  193. }
  194. }
  195. }
  196. }
  197. }
  198. var listOt = db.Queryable<OTB_OPM_OtherExhibition, OTB_OPM_Exhibition>((a, b) =>
  199. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.ExhibitionNO == b.SN.ToString() })
  200. .Where((a, b) => a.OrgID == i_crm.ORIGID && SqlFunc.Contains(a.ActualCost, feeclass))
  201. .Select((a, b) => new { a.ActualCost, a.ImportBillName, b.ExhibitionCode }).ToList();
  202. foreach (var ot in listOt)
  203. {
  204. var JActualCost = (JObject)JsonConvert.DeserializeObject(ot.ActualCost);
  205. if (JActualCost[@"FeeItems"] != null)
  206. {
  207. var jaFeeItems = JActualCost[@"FeeItems"] as JArray;
  208. foreach (JObject jo in jaFeeItems)
  209. {
  210. if (jo[@"FinancialCode"] != null && jo[@"FinancialCode"].ToString() == feeclass)
  211. {
  212. var sBillNO = jo[@"BillNO"] == null ? @"" : jo[@"BillNO"].ToString();
  213. var sBillPayer = jo[@"BillPayer"] == null ? @"" : jo[@"BillPayer"].ToString();
  214. var saBillPayer = sBillPayer.Split('-');
  215. var oCustomers = new OTB_CRM_Customers();
  216. if (sBillNO != null)
  217. {
  218. oCustomers = db.Queryable<OTB_CRM_Customers, OTB_OPM_BillInfo>((a, b) =>
  219. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.guid == b.Payer })
  220. .Where((a, b) => a.OrgID == i_crm.ORIGID && b.BillNO == sBillNO)
  221. .Select((a, b) => a).Single();
  222. }
  223. var bpinfo = new BillPayerInfo
  224. {
  225. ExhibitioName = ot.ExhibitionCode + @" - " + ot.ImportBillName,
  226. BillNO = sBillPayer == @"" ? @"" : saBillPayer[0],
  227. Payer = (oCustomers == null ? @"" : (oCustomers.CustomerNO ?? @"") + @" - ") + (sBillPayer == @"" ? @"" : saBillPayer[1]),
  228. CreateDate = sBillPayer == @"" ? @"" : saBillPayer[2],
  229. Amount = jo[@"FinancialTWAmount"].ToString()
  230. };
  231. list.Add(bpinfo);
  232. }
  233. }
  234. }
  235. }
  236. var listOt_TG = db.Queryable<OTB_OPM_OtherExhibitionTG, OTB_OPM_Exhibition>((a, b) =>
  237. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.ExhibitionNO == b.SN.ToString() })
  238. .Where((a, b) => a.OrgID == i_crm.ORIGID && SqlFunc.Contains(a.ActualCost, feeclass))
  239. .Select((a, b) => new { a.ActualCost, a.ImportBillName, b.ExhibitionCode }).ToList();
  240. foreach (var ot in listOt_TG)
  241. {
  242. var JActualCost = (JObject)JsonConvert.DeserializeObject(ot.ActualCost);
  243. if (JActualCost[@"FeeItems"] != null)
  244. {
  245. var jaFeeItems = JActualCost[@"FeeItems"] as JArray;
  246. foreach (JObject jo in jaFeeItems)
  247. {
  248. if (jo[@"FinancialCode"] != null && jo[@"FinancialCode"].ToString() == feeclass)
  249. {
  250. var sBillNO = jo[@"BillNO"] == null ? @"" : jo[@"BillNO"].ToString();
  251. var sBillPayer = jo[@"BillPayer"] == null ? @"" : jo[@"BillPayer"].ToString();
  252. var saBillPayer = sBillPayer.Split('-');
  253. var oCustomers = new OTB_CRM_Customers();
  254. if (sBillNO != null)
  255. {
  256. oCustomers = db.Queryable<OTB_CRM_Customers, OTB_OPM_BillInfo>((a, b) =>
  257. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.guid == b.Payer })
  258. .Where((a, b) => a.OrgID == i_crm.ORIGID && b.BillNO == sBillNO)
  259. .Select((a, b) => a).Single();
  260. }
  261. var bpinfo = new BillPayerInfo
  262. {
  263. ExhibitioName = ot.ExhibitionCode + @" - " + ot.ImportBillName,
  264. BillNO = sBillPayer == @"" ? @"" : saBillPayer[0],
  265. Payer = (oCustomers == null ? @"" : (oCustomers.CustomerNO ?? @"") + @" - ") + (sBillPayer == @"" ? @"" : saBillPayer[1]),
  266. CreateDate = sBillPayer == @"" ? @"" : saBillPayer[2],
  267. Amount = jo[@"FinancialTWAmount"].ToString()
  268. };
  269. list.Add(bpinfo);
  270. }
  271. }
  272. }
  273. }
  274. }
  275. var listRetn = new List<BillPayerInfo>();
  276. var iRowNumber = 1;
  277. foreach (BillPayerInfo Info in list)
  278. {
  279. var sCreateDate = Info.CreateDate ?? @"";
  280. var rCreateDate = SqlFunc.ToDate(sCreateDate).Date;
  281. if ((sCheckDateStart == @"" && sCheckDateEnd == @"")
  282. || (sCreateDate != @"" && sCheckDateStart != @"" && sCheckDateEnd == @"" && rCheckDateStart <= rCreateDate)
  283. || (sCreateDate != @"" && sCheckDateStart == @"" && sCheckDateEnd != @"" && rCheckDateEnd >= rCreateDate)
  284. || (sCreateDate != @"" && sCheckDateStart != @"" && sCheckDateEnd != @"" && rCheckDateStart <= rCreateDate) && rCheckDateEnd >= rCreateDate)
  285. {
  286. Info.RowIndex = iRowNumber;
  287. listRetn.Add(Info);
  288. iRowNumber++;
  289. }
  290. }
  291. rm = new SuccessResponseMessage(null, i_crm);
  292. rm.DATA.Add(BLWording.REL, listRetn);
  293. } while (false);
  294. }
  295. catch (Exception ex)
  296. {
  297. sMsg = Util.GetLastExceptionMsg(ex);
  298. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Accounting_QryService), @"成本押款和稅金查詢", @"GetBillsList(成本押款和稅金查詢)", @"", @"", @"");
  299. }
  300. finally
  301. {
  302. if (null != sMsg)
  303. {
  304. rm = new ErrorResponseMessage(sMsg, i_crm);
  305. }
  306. }
  307. return rm;
  308. }
  309. #endregion 成本押款和稅金查詢
  310. #region 實際成本押款和稅金查詢匯出
  311. /// <summary>
  312. /// 實際成本押款和稅金查詢匯出
  313. /// </summary>
  314. /// <param name="i_crm">todo: describe i_crm parameter on ExcelBillsList</param>
  315. /// <returns></returns>
  316. public ResponseMessage ExcelBillsList(RequestMessage i_crm)
  317. {
  318. ResponseMessage rm = null;
  319. string sMsg = null;
  320. var db = SugarBase.GetIntance();
  321. var list = new List<BillPayerInfo>();
  322. try
  323. {
  324. do
  325. {
  326. var sFeeClass = _fetchString(i_crm, @"FeeClass");
  327. var sCheckDateStart = _fetchString(i_crm, @"CheckDateStart");
  328. var sCheckDateEnd = _fetchString(i_crm, @"CheckDateEnd");
  329. var rCheckDateStart = SqlFunc.ToDate(sCheckDateStart).Date;
  330. var rCheckDateEnd = SqlFunc.ToDate(sCheckDateEnd).Date;
  331. var saFeeClass = sFeeClass.Split(',');
  332. foreach (string feeclass in saFeeClass)
  333. {
  334. var listIm = db.Queryable<OTB_OPM_ImportExhibition, OTB_OPM_Exhibition>((a, b) =>
  335. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.ExhibitionNO == b.SN.ToString() })
  336. .Where((a, b) => a.OrgID == i_crm.ORIGID && (SqlFunc.Contains(a.ActualCost, feeclass) || SqlFunc.Contains(a.ReturnBills, feeclass)))
  337. .Select((a, b) => new { a.ActualCost, a.ReturnBills, a.ImportBillName, b.ExhibitionCode }).ToList();
  338. foreach (var im in listIm)
  339. {
  340. var JActualCost = (JObject)JsonConvert.DeserializeObject(im.ActualCost);
  341. if (JActualCost[@"FeeItems"] != null)
  342. {
  343. var jaFeeItems = JActualCost[@"FeeItems"] as JArray;
  344. foreach (JObject jo in jaFeeItems)
  345. {
  346. if (jo[@"FinancialCode"] != null && jo[@"FinancialCode"].ToString() == feeclass)
  347. {
  348. var sBillNO = jo[@"BillNO"] == null ? @"" : jo[@"BillNO"].ToString();
  349. var sBillPayer = jo[@"BillPayer"] == null ? @"" : jo[@"BillPayer"].ToString();
  350. var saBillPayer = sBillPayer.Split('-');
  351. var oCustomers = new OTB_CRM_Customers();
  352. if (sBillNO != null)
  353. {
  354. oCustomers = db.Queryable<OTB_CRM_Customers, OTB_OPM_BillInfo>((a, b) =>
  355. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.guid == b.Payer })
  356. .Where((a, b) => a.OrgID == i_crm.ORIGID && b.BillNO == sBillNO)
  357. .Select((a, b) => a).Single();
  358. }
  359. var bpinfo = new BillPayerInfo
  360. {
  361. ExhibitioName = im.ExhibitionCode + @" - " + im.ImportBillName,
  362. BillNO = sBillPayer == @"" ? @"" : saBillPayer[0],
  363. Payer = (oCustomers == null ? @"" : (oCustomers.CustomerNO ?? @"") + @" - ") + (sBillPayer == @"" ? @"" : saBillPayer[1]),
  364. CreateDate = sBillPayer == @"" ? @"" : saBillPayer[2],
  365. Amount = jo[@"FinancialTWAmount"].ToString()
  366. };
  367. list.Add(bpinfo);
  368. }
  369. }
  370. }
  371. var JaReturnBills = (JArray)JsonConvert.DeserializeObject(im.ReturnBills);
  372. foreach (JObject bill in JaReturnBills)
  373. {
  374. if (bill[@"ActualCost"] != null)
  375. {
  376. var JReturnActualCost = (JObject)JsonConvert.DeserializeObject(bill[@"ActualCost"].ToString());
  377. if (JReturnActualCost[@"FeeItems"] != null)
  378. {
  379. var jaFeeItems = JReturnActualCost[@"FeeItems"] as JArray;
  380. foreach (JObject jo in jaFeeItems)
  381. {
  382. if (jo[@"FinancialCode"] != null && jo[@"FinancialCode"].ToString() == feeclass)
  383. {
  384. var sBillNO = jo[@"BillNO"] == null ? @"" : jo[@"BillNO"].ToString();
  385. var sBillPayer = jo[@"BillPayer"] == null ? @"" : jo[@"BillPayer"].ToString();
  386. var saBillPayer = sBillPayer.Split('-');
  387. var oCustomers = new OTB_CRM_Customers();
  388. if (sBillNO != null)
  389. {
  390. oCustomers = db.Queryable<OTB_CRM_Customers, OTB_OPM_BillInfo>((a, b) =>
  391. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.guid == b.Payer })
  392. .Where((a, b) => a.OrgID == i_crm.ORIGID && b.BillNO == sBillNO)
  393. .Select((a, b) => a).Single();
  394. }
  395. var bpinfo = new BillPayerInfo
  396. {
  397. ExhibitioName = im.ExhibitionCode + @" - " + im.ImportBillName,
  398. BillNO = sBillPayer == @"" ? @"" : saBillPayer[0],
  399. Payer = (oCustomers == null ? @"" : (oCustomers.CustomerNO ?? @"") + @" - ") + (sBillPayer == @"" ? @"" : saBillPayer[1]),
  400. CreateDate = sBillPayer == @"" ? @"" : saBillPayer[2],
  401. Amount = jo[@"FinancialTWAmount"].ToString()
  402. };
  403. list.Add(bpinfo);
  404. }
  405. }
  406. }
  407. }
  408. }
  409. }
  410. var listEx = db.Queryable<OTB_OPM_ExportExhibition, OTB_OPM_Exhibition>((a, b) =>
  411. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.ExhibitionNO == b.SN.ToString() })
  412. .Where((a, b) => a.OrgID == i_crm.ORIGID && (SqlFunc.Contains(a.ActualCost, feeclass) || SqlFunc.Contains(a.ReturnBills, feeclass)))
  413. .Select((a, b) => new { a.ActualCost, a.ReturnBills, a.ExportBillName, b.ExhibitionCode }).ToList();
  414. foreach (var _ex in listEx)
  415. {
  416. var JActualCost = (JObject)JsonConvert.DeserializeObject(_ex.ActualCost);
  417. if (JActualCost[@"FeeItems"] != null)
  418. {
  419. var jaFeeItems = JActualCost[@"FeeItems"] as JArray;
  420. foreach (JObject jo in jaFeeItems)
  421. {
  422. if (jo[@"FinancialCode"] != null && jo[@"FinancialCode"].ToString() == feeclass)
  423. {
  424. var sBillNO = jo[@"BillNO"] == null ? @"" : jo[@"BillNO"].ToString();
  425. var sBillPayer = jo[@"BillPayer"] == null ? @"" : jo[@"BillPayer"].ToString();
  426. var saBillPayer = sBillPayer.Split('-');
  427. var oCustomers = new OTB_CRM_Customers();
  428. if (sBillNO != null)
  429. {
  430. oCustomers = db.Queryable<OTB_CRM_Customers, OTB_OPM_BillInfo>((a, b) =>
  431. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.guid == b.Payer })
  432. .Where((a, b) => a.OrgID == i_crm.ORIGID && b.BillNO == sBillNO)
  433. .Select((a, b) => a).Single();
  434. }
  435. var bpinfo = new BillPayerInfo
  436. {
  437. ExhibitioName = _ex.ExhibitionCode + @" - " + _ex.ExportBillName,
  438. BillNO = sBillPayer == @"" ? @"" : saBillPayer[0],
  439. Payer = (oCustomers == null ? @"" : (oCustomers.CustomerNO ?? @"") + @" - ") + (sBillPayer == @"" ? @"" : saBillPayer[1]),
  440. CreateDate = sBillPayer == @"" ? @"" : saBillPayer[2],
  441. Amount = jo[@"FinancialTWAmount"].ToString()
  442. };
  443. list.Add(bpinfo);
  444. }
  445. }
  446. }
  447. var JaReturnBills = (JArray)JsonConvert.DeserializeObject(_ex.ReturnBills);
  448. foreach (JObject bill in JaReturnBills)
  449. {
  450. if (bill[@"ActualCost"] != null)
  451. {
  452. var JReturnActualCost = (JObject)JsonConvert.DeserializeObject(bill[@"ActualCost"].ToString());
  453. if (JReturnActualCost[@"FeeItems"] != null)
  454. {
  455. var jaFeeItems = JReturnActualCost[@"FeeItems"] as JArray;
  456. foreach (JObject jo in jaFeeItems)
  457. {
  458. if (jo[@"FinancialCode"] != null && jo[@"FinancialCode"].ToString() == feeclass)
  459. {
  460. var sBillNO = jo[@"BillNO"] == null ? @"" : jo[@"BillNO"].ToString();
  461. var sBillPayer = jo[@"BillPayer"] == null ? @"" : jo[@"BillPayer"].ToString();
  462. var saBillPayer = sBillPayer.Split('-');
  463. var oCustomers = new OTB_CRM_Customers();
  464. if (sBillNO != null)
  465. {
  466. oCustomers = db.Queryable<OTB_CRM_Customers, OTB_OPM_BillInfo>((a, b) =>
  467. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.guid == b.Payer })
  468. .Where((a, b) => a.OrgID == i_crm.ORIGID && b.BillNO == sBillNO)
  469. .Select((a, b) => a).Single();
  470. }
  471. var bpinfo = new BillPayerInfo
  472. {
  473. ExhibitioName = _ex.ExhibitionCode + @" - " + _ex.ExportBillName,
  474. BillNO = sBillPayer == @"" ? @"" : saBillPayer[0],
  475. Payer = (oCustomers == null ? @"" : (oCustomers.CustomerNO ?? @"") + @" - ") + (sBillPayer == @"" ? @"" : saBillPayer[1]),
  476. CreateDate = sBillPayer == @"" ? @"" : saBillPayer[2],
  477. Amount = jo[@"FinancialTWAmount"].ToString()
  478. };
  479. list.Add(bpinfo);
  480. }
  481. }
  482. }
  483. }
  484. }
  485. }
  486. var listOt = db.Queryable<OTB_OPM_OtherExhibition, OTB_OPM_Exhibition>((a, b) =>
  487. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.ExhibitionNO == b.SN.ToString() })
  488. .Where((a, b) => a.OrgID == i_crm.ORIGID && SqlFunc.Contains(a.ActualCost, feeclass))
  489. .Select((a, b) => new { a.ActualCost, a.ImportBillName, b.ExhibitionCode }).ToList();
  490. foreach (var ot in listOt)
  491. {
  492. var JActualCost = (JObject)JsonConvert.DeserializeObject(ot.ActualCost);
  493. if (JActualCost[@"FeeItems"] != null)
  494. {
  495. var jaFeeItems = JActualCost[@"FeeItems"] as JArray;
  496. foreach (JObject jo in jaFeeItems)
  497. {
  498. if (jo[@"FinancialCode"] != null && jo[@"FinancialCode"].ToString() == feeclass)
  499. {
  500. var sBillNO = jo[@"BillNO"] == null ? @"" : jo[@"BillNO"].ToString();
  501. var sBillPayer = jo[@"BillPayer"] == null ? @"" : jo[@"BillPayer"].ToString();
  502. var saBillPayer = sBillPayer.Split('-');
  503. var oCustomers = new OTB_CRM_Customers();
  504. if (sBillNO != null)
  505. {
  506. oCustomers = db.Queryable<OTB_CRM_Customers, OTB_OPM_BillInfo>((a, b) =>
  507. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.guid == b.Payer })
  508. .Where((a, b) => a.OrgID == i_crm.ORIGID && b.BillNO == sBillNO)
  509. .Select((a, b) => a).Single();
  510. }
  511. var bpinfo = new BillPayerInfo
  512. {
  513. ExhibitioName = ot.ExhibitionCode + @" - " + ot.ImportBillName,
  514. BillNO = sBillPayer == @"" ? @"" : saBillPayer[0],
  515. Payer = (oCustomers == null ? @"" : (oCustomers.CustomerNO ?? @"") + @" - ") + (sBillPayer == @"" ? @"" : saBillPayer[1]),
  516. CreateDate = sBillPayer == @"" ? @"" : saBillPayer[2],
  517. Amount = jo[@"FinancialTWAmount"].ToString()
  518. };
  519. list.Add(bpinfo);
  520. }
  521. }
  522. }
  523. }
  524. var listOt_TG = db.Queryable<OTB_OPM_OtherExhibitionTG, OTB_OPM_Exhibition>((a, b) =>
  525. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.ExhibitionNO == b.SN.ToString() })
  526. .Where((a, b) => a.OrgID == i_crm.ORIGID && SqlFunc.Contains(a.ActualCost, feeclass))
  527. .Select((a, b) => new { a.ActualCost, a.ImportBillName, b.ExhibitionCode }).ToList();
  528. foreach (var ot in listOt_TG)
  529. {
  530. var JActualCost = (JObject)JsonConvert.DeserializeObject(ot.ActualCost);
  531. if (JActualCost[@"FeeItems"] != null)
  532. {
  533. var jaFeeItems = JActualCost[@"FeeItems"] as JArray;
  534. foreach (JObject jo in jaFeeItems)
  535. {
  536. if (jo[@"FinancialCode"] != null && jo[@"FinancialCode"].ToString() == feeclass)
  537. {
  538. var sBillNO = jo[@"BillNO"] == null ? @"" : jo[@"BillNO"].ToString();
  539. var sBillPayer = jo[@"BillPayer"] == null ? @"" : jo[@"BillPayer"].ToString();
  540. var saBillPayer = sBillPayer.Split('-');
  541. var oCustomers = new OTB_CRM_Customers();
  542. if (sBillNO != null)
  543. {
  544. oCustomers = db.Queryable<OTB_CRM_Customers, OTB_OPM_BillInfo>((a, b) =>
  545. new object[] { JoinType.Inner, a.OrgID == b.OrgID && a.guid == b.Payer })
  546. .Where((a, b) => a.OrgID == i_crm.ORIGID && b.BillNO == sBillNO)
  547. .Select((a, b) => a).Single();
  548. }
  549. var bpinfo = new BillPayerInfo
  550. {
  551. ExhibitioName = ot.ExhibitionCode + @" - " + ot.ImportBillName,
  552. BillNO = sBillPayer == @"" ? @"" : saBillPayer[0],
  553. Payer = (oCustomers == null ? @"" : (oCustomers.CustomerNO ?? @"") + @" - ") + (sBillPayer == @"" ? @"" : saBillPayer[1]),
  554. CreateDate = sBillPayer == @"" ? @"" : saBillPayer[2],
  555. Amount = jo[@"FinancialTWAmount"].ToString()
  556. };
  557. list.Add(bpinfo);
  558. }
  559. }
  560. }
  561. }
  562. }
  563. var listRetn = new List<BillPayerInfo>();
  564. var iRowNumber = 1;
  565. foreach (BillPayerInfo Info in list)
  566. {
  567. var sCreateDate = Info.CreateDate ?? @"";
  568. var rCreateDate = SqlFunc.ToDate(sCreateDate).Date;
  569. if ((sCheckDateStart == @"" && sCheckDateEnd == @"")
  570. || (sCreateDate != @"" && sCheckDateStart != @"" && sCheckDateEnd == @"" && rCheckDateStart <= Convert.ToDateTime(sCreateDate))
  571. || (sCreateDate != @"" && sCheckDateStart == @"" && sCheckDateEnd != @"" && rCheckDateEnd >= rCreateDate)
  572. || (sCreateDate != @"" && sCheckDateStart != @"" && sCheckDateEnd != @"" && rCheckDateStart <= rCreateDate) && rCheckDateEnd >= rCreateDate)
  573. {
  574. Info.RowIndex = iRowNumber;
  575. listRetn.Add(Info);
  576. iRowNumber++;
  577. }
  578. }
  579. var sFileName = @"實際成本押款和稅金資料";
  580. var oHeader = new Dictionary<string, string>();
  581. var sHeader1 = @"帳單號碼";
  582. var sHeader2 = @"活動/展覽名稱";
  583. var sHeader3 = @"付款人";
  584. var sHeader4 = @"金額";
  585. var sHeader5 = @"創建時間";
  586. if (i_crm.LANG == @"zh")
  587. {
  588. sHeader1 = ChineseStringUtility.ToSimplified(sHeader1);
  589. sHeader2 = ChineseStringUtility.ToSimplified(sHeader2);
  590. sHeader3 = ChineseStringUtility.ToSimplified(sHeader3);
  591. sHeader4 = ChineseStringUtility.ToSimplified(sHeader4);
  592. sHeader5 = ChineseStringUtility.ToSimplified(sHeader5);
  593. }
  594. oHeader.Add(@"BillNO", sHeader1);
  595. oHeader.Add(@"ExhibitioName", sHeader2);
  596. oHeader.Add(@"Payer", sHeader3);
  597. oHeader.Add(@"Amount", sHeader4);
  598. oHeader.Add(@"CreateDate", sHeader5);
  599. var bOk = new ExcelService().CreateExcelByList(listRetn, out string sPath, oHeader, null, sFileName);
  600. rm = new SuccessResponseMessage(null, i_crm);
  601. rm.DATA.Add(BLWording.REL, sPath);
  602. } while (false);
  603. }
  604. catch (Exception ex)
  605. {
  606. sMsg = Util.GetLastExceptionMsg(ex);
  607. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Accounting_QryService), @"成本押款和稅金查詢匯出", @"ExcelBillsList(成本押款和稅金查詢匯出)", @"", @"", @"");
  608. }
  609. finally
  610. {
  611. if (null != sMsg)
  612. {
  613. rm = new ErrorResponseMessage(sMsg, i_crm);
  614. }
  615. }
  616. return rm;
  617. }
  618. #endregion 實際成本押款和稅金查詢匯出
  619. }
  620. }