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.

667 lines
32 KiB

2 years ago
  1. using Entity.Sugar;
  2. using Newtonsoft.Json.Linq;
  3. using SqlSugar;
  4. using SqlSugar.Base;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Configuration;
  8. using System.Data;
  9. using System.Globalization;
  10. using System.IO;
  11. using System.Net;
  12. using System.Runtime.InteropServices;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using System.Web;
  16. using System.Xml;
  17. using DocumentFormat.OpenXml.Wordprocessing;
  18. using DocumentFormat.OpenXml.Packaging;
  19. using System.Linq;
  20. using Newtonsoft.Json;
  21. using EasyBL.WebApi.Message;
  22. namespace EasyBL
  23. {
  24. /// <summary>
  25. /// Common 的摘要描述
  26. /// </summary>
  27. public class CommonRPT
  28. {
  29. private static bool? ShowSource;
  30. public static string FilePath = @"Document\EurotranFile\RPT";
  31. public static string PassStatus = "2,4,5";
  32. public static bool RPTShow()
  33. {
  34. if (ShowSource == null)
  35. {
  36. ShowSource = !string.IsNullOrWhiteSpace(Common.GetAppSettings("RPTShowSource").Trim());
  37. }
  38. return ShowSource.Value;
  39. }
  40. /// <summary>
  41. /// 相對應組織的幣別單位
  42. /// </summary>
  43. /// <param name="OrgID"></param>
  44. /// <returns></returns>
  45. public static string GetCurrencyUnit(string OrgID)
  46. {
  47. if (OrgID.ToUpper() == "SG")
  48. return "RMB¥";
  49. return "NT$";
  50. }
  51. /// <summary>
  52. /// 相對應組織的進位
  53. /// </summary>
  54. /// <param name="OrgID"></param>
  55. /// <returns></returns>
  56. public static int GetRoundingPoint(string OrgID)
  57. {
  58. var RoundingPoint = 0;
  59. if (OrgID == "SG")
  60. {
  61. RoundingPoint = 2;
  62. }
  63. return RoundingPoint;
  64. }
  65. /// <summary>
  66. /// 取得負責的業務,若負責人員為空,則撈出該部門所有的人。
  67. /// </summary>
  68. /// <param name="i_crm"></param>
  69. /// <param name="db"></param>
  70. /// <param name="sResponsibleDeptID"></param>
  71. /// <param name="sResponsiblePerson"></param>
  72. /// <returns></returns>
  73. public static string GetResponsiblePersons(SqlSugarClient db, string OrgID, string sResponsibleDeptID, string sResponsiblePerson)
  74. {
  75. var Result = sResponsiblePerson;
  76. if (string.IsNullOrEmpty(sResponsiblePerson) && !string.IsNullOrEmpty(sResponsibleDeptID))
  77. {
  78. var spOrgID = new SugarParameter("@OrgID", OrgID);
  79. var spDepartID = new SugarParameter("@DepartID", sResponsibleDeptID);
  80. var AllOfDepartMembers = db.Ado.SqlQuery<string>(@"select MemberID from [dbo].[OVW_SYS_Members]
  81. where OrgID = @OrgID and DepartmentID in
  82. ( SELECT * FROM [dbo].[OFN_SYS_GetChilDepartmentIdByDepartmentId] (@OrgID, @DepartID)) ", spOrgID, spDepartID).ToArray();
  83. var AllOfDepartIDs = db.Ado.SqlQuery<string>(@"SELECT * FROM [dbo].[OFN_SYS_GetChilDepartmentIdByDepartmentId] (@OrgID, @DepartID)", spOrgID, spDepartID).ToArray();
  84. //找出進口/出口/其他/其他(TG)屬於該部門的業務人員
  85. var cmdExport = db.Queryable<OTB_OPM_ExportExhibition>()
  86. .Where(x => x.OrgID == OrgID && AllOfDepartIDs.Contains(x.DepartmentID))
  87. .Select(x => new OTB_OPM_ExportExhibition()
  88. {
  89. ResponsiblePerson = x.ResponsiblePerson,
  90. DepartmentID = x.DepartmentID
  91. });
  92. var cmdImport = db.Queryable<OTB_OPM_ImportExhibition>()
  93. .Where(x => x.OrgID == OrgID && AllOfDepartIDs.Contains(x.DepartmentID))
  94. .Select(x => new OTB_OPM_ExportExhibition()
  95. {
  96. ResponsiblePerson = x.ResponsiblePerson,
  97. DepartmentID = x.DepartmentID
  98. });
  99. var cmdOther = db.Queryable<OTB_OPM_OtherExhibition>()
  100. .Where(x => x.OrgID == OrgID && AllOfDepartIDs.Contains(x.DepartmentID))
  101. .Select(x => new OTB_OPM_ExportExhibition()
  102. {
  103. ResponsiblePerson = x.ResponsiblePerson,
  104. DepartmentID = x.DepartmentID
  105. });
  106. var cmdOtherTG = db.Queryable<OTB_OPM_OtherExhibitionTG>()
  107. .Where(x => x.OrgID == OrgID && AllOfDepartIDs.Contains(x.DepartmentID))
  108. .Select(x => new OTB_OPM_ExportExhibition()
  109. {
  110. ResponsiblePerson = x.ResponsiblePerson,
  111. DepartmentID = x.DepartmentID
  112. });
  113. List<OTB_OPM_ExportExhibition> lResponseDept = db.UnionAll(cmdExport, cmdImport, cmdOther, cmdOtherTG).ToList();
  114. List<string> lPersonList = AllOfDepartMembers.ToList(); //人員清單
  115. var MembersOfBills = lResponseDept.Select(p => p.ResponsiblePerson).Distinct().ToList();
  116. lPersonList = lPersonList.Concat(MembersOfBills).Distinct().ToList();
  117. Result = string.Join(",", lPersonList);
  118. }
  119. return Result;
  120. }
  121. public static string[] GetChildDepteList(SqlSugarClient db, string OrgID, string sResponsibleDeptID)
  122. {
  123. var Result = new string[] { };
  124. if (!string.IsNullOrEmpty(sResponsibleDeptID))
  125. {
  126. var spOrgID = new SugarParameter("@OrgID", OrgID);
  127. var spDepartID = new SugarParameter("@DepartID", sResponsibleDeptID);
  128. var AllOfDepartIDs = db.Ado.SqlQuery<string>(@"SELECT * FROM [dbo].[OFN_SYS_GetChilDepartmentIdByDepartmentId] (@OrgID, @DepartID)", spOrgID, spDepartID).ToArray();
  129. Result = AllOfDepartIDs;
  130. }
  131. return Result;
  132. }
  133. public static List<OVW_OPM_ALLExps> GetMatchedExps(SqlSugarClient db, string OrgID, string[] ResponsibleDeptIDs, string ResponsiblePerson)
  134. {
  135. return db.Queryable<OVW_OPM_ALLExps>()
  136. .Where(t1 => t1.OrgID == OrgID && t1.IsVoid == "N")
  137. .WhereIF(ResponsibleDeptIDs.Any(), t1 => SqlFunc.ContainsArray(ResponsibleDeptIDs, t1.DepartmentID))
  138. .WhereIF(!string.IsNullOrWhiteSpace(ResponsiblePerson), t1 => t1.ResponsiblePerson == ResponsiblePerson)
  139. .ToList();
  140. }
  141. /// <summary>
  142. /// 取得相對應excel
  143. /// </summary>
  144. /// <param name="RPTCode"></param>
  145. /// <param name="RPTName"></param>
  146. /// <returns></returns>
  147. public static Tuple<string, string> GetExcutePath(string RPTCode, string RPTName)
  148. {
  149. var sOutPut = Common.ConfigGetValue(@"", @"OutFilesPath");
  150. var sTempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FilePath);
  151. sTempPath = Path.Combine(sTempPath, RPTCode + ".xlsx");
  152. var sBase = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"");
  153. sOutPut = sBase + sOutPut;
  154. Common.FnCreateDir(sOutPut);//如果不存在就創建文件夾
  155. var sFileName = RPTName + DateTime.Now.ToString(@"yyyy-MM-dd") + "_" + Guid.NewGuid();
  156. //建立臨時文件
  157. var sTempFile = Path.GetTempPath() + sFileName + @".xlsx";
  158. sOutPut += sFileName + @".xlsx";
  159. if (File.Exists(sTempFile))
  160. {
  161. File.Delete(sTempFile);
  162. }
  163. File.Copy(sTempPath, sTempFile);
  164. return new Tuple<string, string>(sOutPut, sTempFile);
  165. }
  166. /// <summary>
  167. /// 根據CBM占比平攤成本
  168. /// </summary>
  169. /// <param name="db"></param>
  170. /// <param name="_BillInfo"></param>
  171. /// <param name="actualCost"></param>
  172. /// <returns></returns>
  173. public static ShareCost GetSharedActualCost(SqlSugarClient db, OVW_OPM_BillInfo _BillInfo, string actualCost)
  174. {
  175. string PassStatus = CommonRPT.PassStatus;
  176. var sAuditVal = _BillInfo.AuditVal == null ? "" : _BillInfo.AuditVal;
  177. var UsedVolume = _BillInfo.Volume == null ? "0" : _BillInfo.Volume;
  178. double dUsedVolume = 0;
  179. double dActualCost = 0;
  180. double.TryParse(UsedVolume, out dUsedVolume);
  181. double.TryParse(actualCost, out dActualCost);
  182. if (PassStatus.Contains(sAuditVal) && dUsedVolume > 0)
  183. {
  184. var spOrgID = new SugarParameter("@OrgID", _BillInfo.OrgID);
  185. var spParentId = new SugarParameter("@ParentId", _BillInfo.ParentId);
  186. var spIsReturn = new SugarParameter("@IsRetn", _BillInfo.IsRetn);
  187. var sVolumes = db.Ado.SqlQuery<string>("SELECT Volume FROM OVW_OPM_BillInfo WHERE OrgID =@OrgID and ParentId = @ParentId and IsRetn = @IsRetn and AuditVal in('2','4','5')", spOrgID, spParentId, spIsReturn).ToArray();
  188. var dVolumes = sVolumes.Sum(c =>
  189. {
  190. double.TryParse(c, out double Result);
  191. return Result;
  192. });
  193. if (dVolumes == 0)
  194. return new ShareCost();
  195. var Persent = dUsedVolume / dVolumes;
  196. var ShareCost = new ShareCost()
  197. {
  198. Persent = Persent,
  199. SharedActualCost = Math.Round(dActualCost * Persent, MidpointRounding.AwayFromZero)
  200. };
  201. return ShareCost;
  202. }
  203. else
  204. {
  205. return new ShareCost();
  206. }
  207. }
  208. public static List<CbmVolume> GetAllCBMUsages(SqlSugarClient db, string OrgID)
  209. {
  210. var PassStatus = new string[] { "2", "4", "5" };
  211. var CbmVolumes = db.Queryable<OVW_OPM_BillInfo>().Where(t1 => t1.OrgID == OrgID && SqlFunc.ContainsArray(PassStatus, t1.AuditVal))
  212. .Select(t1 => new CbmVolume() { OrgID = t1.OrgID, ParentID = t1.ParentId, BillNO = t1.BillNO, sVolumes = t1.Volume, IsReturn = t1.IsRetn }).ToList();
  213. return CbmVolumes;
  214. }
  215. /// <summary>
  216. /// 取得帳單項目中的代墊款
  217. /// </summary>
  218. /// <param name="saPrepayFee"></param>
  219. /// <param name="bills"></param>
  220. /// <param name="bindToBillNo"></param>
  221. /// <returns></returns>
  222. public static double GetPrepayForCustomer(string saPrepayFee, string bills, string bindToBillNo = "")
  223. {
  224. if (!saPrepayFee.Any() || string.IsNullOrWhiteSpace(bills))
  225. return 0;
  226. var JABills = JArray.Parse(bills);
  227. var FoundPrepayFeeItem = JABills.Where(jo => jo["FinancialCode"] != null && saPrepayFee.Contains(jo["FinancialCode"].ToString()))
  228. .Select(jo =>
  229. {
  230. double FinancialAmount = 0;
  231. double FinancialTWAmount = 0;
  232. var FinancialCode = jo["FinancialCode"] == null ? "" : jo["FinancialCode"].ToString();
  233. if (saPrepayFee.Contains(FinancialCode))
  234. {
  235. double.TryParse(jo["FinancialAmount"]?.ToString(), out FinancialAmount);
  236. double.TryParse(jo["FinancialTWAmount"]?.ToString(), out FinancialTWAmount);
  237. }
  238. var FinancialBillNO = jo["BillNO"] == null ? "" : jo["BillNO"].ToString();
  239. var NoneEmpty = !string.IsNullOrWhiteSpace(FinancialBillNO) && !string.IsNullOrWhiteSpace(bindToBillNo);
  240. if (NoneEmpty && bindToBillNo != FinancialBillNO)
  241. {
  242. return new { FinancialAmount = 0.0, FinancialTWAmount = 0.0 };
  243. }
  244. return new { FinancialAmount, FinancialTWAmount };
  245. }).ToList();
  246. return FoundPrepayFeeItem.Sum(f => f.FinancialTWAmount);
  247. }
  248. public static decimal GetShareCost(List<FeeItem> feeItems, List<CbmVolume> cbmVolumes, string AllocatedBillNO, string[] MatchFeeCode = null)
  249. {
  250. var Cost = decimal.Zero;
  251. var GeneralCBMPercent = CbmVolume.GetCBMPercent(cbmVolumes, AllocatedBillNO);
  252. if (MatchFeeCode != null && MatchFeeCode.Any())
  253. {
  254. feeItems = feeItems.Where(c => MatchFeeCode.Contains(c.FinancialCode)).ToList();
  255. }
  256. //分成1.不指定均攤、2.指定均攤
  257. foreach (var feeItem in feeItems)
  258. {
  259. var NoAllocated = feeItem.AllocatedToBillNOs.Count == 0;
  260. switch (NoAllocated)
  261. {
  262. case true:
  263. {
  264. Cost += (feeItem.TWAmount * GeneralCBMPercent);
  265. }
  266. break;
  267. case false:
  268. {
  269. var CheckSignedBillNO = feeItem.AllocatedToBillNOs.Any(c => c == AllocatedBillNO);
  270. if (CheckSignedBillNO)
  271. {
  272. var AllocatedCBMVolumes = cbmVolumes.Where(c => feeItem.AllocatedToBillNOs.Contains(c.BillNO)).ToList();
  273. var AllocatedCBMPercent = CbmVolume.GetCBMPercent(AllocatedCBMVolumes, AllocatedBillNO);
  274. Cost += (feeItem.TWAmount * AllocatedCBMPercent.ObjToDecimal());
  275. }
  276. }
  277. break;
  278. }
  279. }
  280. return Cost;
  281. }
  282. /// <summary>
  283. /// 轉換成FeeItems
  284. /// </summary>
  285. /// <param name="ItemsJsons"></param>
  286. /// <returns></returns>
  287. public static List<FeeItem> ToFeeItems(string ItemsJsons)
  288. {
  289. var FeeItems = new List<FeeItem>();
  290. var JABills = JArray.Parse(ItemsJsons);
  291. foreach (var JABill in JABills)
  292. {
  293. var FinancialCode = JABill["FinancialCode"].ObjToString();
  294. var FinancialAmount = JABill["FinancialAmount"].ObjToDecimal();
  295. var FinancialTWAmount = JABill["FinancialTWAmount"].ObjToDecimal();
  296. var sBillNOs = JABill["BillNO"].ObjToString();
  297. var BindToBillNOList = sBillNOs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  298. FeeItems.Add(new FeeItem()
  299. {
  300. FinancialCode = FinancialCode,
  301. OriginalCurrencyAmount = FinancialAmount,
  302. TWAmount = FinancialTWAmount,
  303. AllocatedToBillNOs = BindToBillNOList,
  304. });
  305. }
  306. return FeeItems;
  307. }
  308. /// <summary>
  309. /// 取得進出口、其他、其他駒奕中
  310. /// 實際成本項目、實際成本
  311. /// </summary>
  312. /// <param name="db"></param>
  313. /// <param name="ActualCostFeeItems"></param>
  314. /// <param name="sActualCost"></param>
  315. /// <param name="sTransportationMode"></param>
  316. /// <param name="_sBillNO"></param>
  317. /// <param name="sId"></param>
  318. /// <param name="sIsRetn"></param>
  319. /// <param name="sReFlow"></param>
  320. /// <param name="sBillType"></param>
  321. public static void CalcuCostAndProfit(SqlSugarClient db, ref string ActualCostFeeItems, ref string sActualCost, ref string sTransportationMode, string _sBillNO, string sId, string sIsRetn, string sReFlow, string sBillType)
  322. {
  323. if (sBillType == "OtherBusiness_Upd")
  324. {
  325. // OTB_OPM_OtherExhibition.ActualCost
  326. var oOther = db.Queryable<OTB_OPM_OtherExhibition>().Single(it => it.Guid == sId);
  327. if (oOther != null)
  328. {
  329. var joActualCost = (JObject)JsonConvert.DeserializeObject(oOther.ActualCost);
  330. ActualCostFeeItems = joActualCost["FeeItems"] != null ? joActualCost["FeeItems"].ToString() : "";
  331. if (joActualCost["AmountTaxSum"] != null)
  332. {
  333. sActualCost = joActualCost["AmountTaxSum"].ToString();
  334. }
  335. }
  336. }
  337. else if (sBillType == "ExhibitionImport_Upd")
  338. {
  339. // OTB_OPM_ImportExhibition.ReturnBills
  340. // OTB_OPM_ImportExhibition.ReImports
  341. // OTB_OPM_ImportExhibition.ActualCost
  342. // OTB_OPM_ImportExhibition.TransportationMode
  343. var oImport = db.Queryable<OTB_OPM_ImportExhibition>().Single(it => it.ImportBillNO == sId);
  344. if (oImport != null)
  345. {
  346. if (sIsRetn == "Y")
  347. {
  348. var jaReturnBills = (JArray)JsonConvert.DeserializeObject(oImport.ReturnBills);
  349. for (var idx = 0; idx < jaReturnBills.Count; idx++)
  350. {
  351. if (sReFlow == (idx + 1).ToString())
  352. {
  353. var joReturn = (JObject)jaReturnBills[idx];
  354. ActualCostFeeItems = ((JObject)joReturn["ActualCost"])["FeeItems"] != null ? ((JObject)joReturn["ActualCost"])["FeeItems"].ToString() : "";
  355. if (((JObject)joReturn["ActualCost"])["AmountTaxSum"] != null)
  356. {
  357. sActualCost = ((JObject)joReturn["ActualCost"])["AmountTaxSum"].ToString();
  358. }
  359. break;
  360. }
  361. }
  362. var jaReImports = (JArray)JsonConvert.DeserializeObject(oImport.ReImports);
  363. for (var idx = 0; idx < jaReImports.Count; idx++)
  364. {
  365. if (sReFlow == idx.ToString())
  366. {
  367. var joReturn = (JObject)jaReImports[idx];
  368. sTransportationMode = ((JObject)joReturn["ReImportData"])["TransportationMode"].ToString();
  369. break;
  370. }
  371. }
  372. }
  373. else
  374. {
  375. var joActualCost = (JObject)JsonConvert.DeserializeObject(oImport.ActualCost);
  376. ActualCostFeeItems = joActualCost["FeeItems"] != null ? joActualCost["FeeItems"].ToString() : "";
  377. if (joActualCost["AmountTaxSum"] != null)
  378. {
  379. sActualCost = joActualCost["AmountTaxSum"].ToString();
  380. }
  381. sTransportationMode = oImport.TransportationMode;
  382. }
  383. }
  384. }
  385. else if (sBillType == "ExhibitionExport_Upd")
  386. {
  387. // OTB_OPM_ExportExhibition.ReturnBills
  388. // OTB_OPM_ExportExhibition.Exhibitors
  389. // OTB_OPM_ExportExhibition.ActualCost
  390. // OTB_OPM_ExportExhibition.TransportationMode
  391. var oExport = db.Queryable<OTB_OPM_ExportExhibition>().Single(it => it.ExportBillNO == sId);
  392. if (oExport != null)
  393. {
  394. if (sIsRetn == "Y")
  395. {
  396. var jaReturns = (JArray)JsonConvert.DeserializeObject(oExport.ReturnBills);
  397. var sBillParentId = "";
  398. foreach (JObject jo in jaReturns)
  399. {
  400. var jaReturnBills = (JArray)jo["Bills"];
  401. foreach (JObject joBill in jaReturnBills)
  402. {
  403. if (joBill["BillNO"].ToString() == _sBillNO)
  404. {
  405. ActualCostFeeItems = ((JObject)jo["ActualCost"])["FeeItems"] != null ? ((JObject)jo["ActualCost"])["FeeItems"].ToString() : "";
  406. if (((JObject)jo["ActualCost"])["AmountTaxSum"] != null)
  407. {
  408. sActualCost = ((JObject)jo["ActualCost"])["AmountTaxSum"].ToString();
  409. }
  410. sBillParentId = joBill["parentid"].ToString();
  411. break;
  412. }
  413. }
  414. if (sActualCost != "")
  415. {
  416. break;
  417. }
  418. }
  419. var jaExhibitors = (JArray)JsonConvert.DeserializeObject(oExport.Exhibitors);
  420. foreach (JObject joExhibitor in jaExhibitors)
  421. {
  422. if (sBillParentId != "" && joExhibitor["guid"].ToString() == sBillParentId)
  423. {
  424. if (joExhibitor[nameof(sReFlow)] != null)
  425. {
  426. if (((JObject)joExhibitor[nameof(sReFlow)])["TransportationMode"] != null)
  427. {
  428. sTransportationMode = ((JObject)joExhibitor[nameof(sReFlow)])["TransportationMode"].ToString();
  429. }
  430. }
  431. break;
  432. }
  433. }
  434. }
  435. else
  436. {
  437. var joActualCost = (JObject)JsonConvert.DeserializeObject(oExport.ActualCost);
  438. ActualCostFeeItems = joActualCost["FeeItems"] != null ? joActualCost["FeeItems"].ToString() : "";
  439. if (joActualCost["AmountTaxSum"] != null)
  440. {
  441. sActualCost = joActualCost["AmountTaxSum"].ToString();
  442. }
  443. sTransportationMode = oExport.TransportationMode;
  444. }
  445. }
  446. }
  447. }
  448. public static void CalcuCostAndProfitFast(List<dynamic> db, ref string ActualCostFeeItems, ref string sActualCost, ref string sTransportationMode, string _sBillNO, string sId, string sIsRetn, string sReFlow, string sBillType)
  449. {
  450. if (sBillType == "OtherBusiness_Upd")
  451. {
  452. var oOther = db.Where(t1 => t1.ExFeild1 == sBillType).FirstOrDefault(it => it.Guid == sId);
  453. if (oOther != null)
  454. {
  455. var joActualCost = (JObject)JsonConvert.DeserializeObject(oOther.ActualCost);
  456. ActualCostFeeItems = joActualCost["FeeItems"] != null ? joActualCost["FeeItems"].ToString() : "";
  457. if (joActualCost["AmountTaxSum"] != null)
  458. {
  459. sActualCost = joActualCost["AmountTaxSum"].ToString();
  460. }
  461. }
  462. }
  463. else if (sBillType == "ExhibitionImport_Upd")
  464. {
  465. var oImport = db.Where(t1 => t1.ExFeild1 == sBillType).FirstOrDefault(it => it.ImportBillNO == sId);
  466. if (oImport != null)
  467. {
  468. if (sIsRetn == "Y")
  469. {
  470. var jaReturnBills = (JArray)JsonConvert.DeserializeObject(oImport.ReturnBills);
  471. for (var idx = 0; idx < jaReturnBills.Count; idx++)
  472. {
  473. if (sReFlow == (idx + 1).ToString())
  474. {
  475. var joReturn = (JObject)jaReturnBills[idx];
  476. ActualCostFeeItems = ((JObject)joReturn["ActualCost"])["FeeItems"] != null ? ((JObject)joReturn["ActualCost"])["FeeItems"].ToString() : "";
  477. if (((JObject)joReturn["ActualCost"])["AmountTaxSum"] != null)
  478. {
  479. sActualCost = ((JObject)joReturn["ActualCost"])["AmountTaxSum"].ToString();
  480. }
  481. break;
  482. }
  483. }
  484. var jaReImports = (JArray)JsonConvert.DeserializeObject(oImport.ReImports);
  485. for (var idx = 0; idx < jaReImports.Count; idx++)
  486. {
  487. if (sReFlow == idx.ToString())
  488. {
  489. var joReturn = (JObject)jaReImports[idx];
  490. sTransportationMode = ((JObject)joReturn["ReImportData"])["TransportationMode"].ToString();
  491. break;
  492. }
  493. }
  494. }
  495. else
  496. {
  497. var joActualCost = (JObject)JsonConvert.DeserializeObject(oImport.ActualCost);
  498. ActualCostFeeItems = joActualCost["FeeItems"] != null ? joActualCost["FeeItems"].ToString() : "";
  499. if (joActualCost["AmountTaxSum"] != null)
  500. {
  501. sActualCost = joActualCost["AmountTaxSum"].ToString();
  502. }
  503. sTransportationMode = oImport.TransportationMode;
  504. }
  505. }
  506. }
  507. else if (sBillType == "ExhibitionExport_Upd")
  508. {
  509. var oExport = db.Where(t1 => t1.ExFeild1 == sBillType).FirstOrDefault(it => it.ExportBillNO == sId);
  510. if (oExport != null)
  511. {
  512. if (sIsRetn == "Y")
  513. {
  514. var jaReturns = (JArray)JsonConvert.DeserializeObject(oExport.ReturnBills);
  515. var sBillParentId = "";
  516. foreach (JObject jo in jaReturns)
  517. {
  518. var jaReturnBills = (JArray)jo["Bills"];
  519. foreach (JObject joBill in jaReturnBills)
  520. {
  521. if (joBill["BillNO"].ToString() == _sBillNO)
  522. {
  523. ActualCostFeeItems = ((JObject)jo["ActualCost"])["FeeItems"] != null ? ((JObject)jo["ActualCost"])["FeeItems"].ToString() : "";
  524. if (((JObject)jo["ActualCost"])["AmountTaxSum"] != null)
  525. {
  526. sActualCost = ((JObject)jo["ActualCost"])["AmountTaxSum"].ToString();
  527. }
  528. sBillParentId = joBill["parentid"].ToString();
  529. break;
  530. }
  531. }
  532. if (sActualCost != "")
  533. {
  534. break;
  535. }
  536. }
  537. var jaExhibitors = (JArray)JsonConvert.DeserializeObject(oExport.Exhibitors);
  538. foreach (JObject joExhibitor in jaExhibitors)
  539. {
  540. if (sBillParentId != "" && joExhibitor["guid"].ToString() == sBillParentId)
  541. {
  542. if (joExhibitor[nameof(sReFlow)] != null)
  543. {
  544. if (((JObject)joExhibitor[nameof(sReFlow)])["TransportationMode"] != null)
  545. {
  546. sTransportationMode = ((JObject)joExhibitor[nameof(sReFlow)])["TransportationMode"].ToString();
  547. }
  548. }
  549. break;
  550. }
  551. }
  552. }
  553. else
  554. {
  555. var joActualCost = (JObject)JsonConvert.DeserializeObject(oExport.ActualCost);
  556. ActualCostFeeItems = joActualCost["FeeItems"] != null ? joActualCost["FeeItems"].ToString() : "";
  557. if (joActualCost["AmountTaxSum"] != null)
  558. {
  559. sActualCost = joActualCost["AmountTaxSum"].ToString();
  560. }
  561. sTransportationMode = oExport.TransportationMode;
  562. }
  563. }
  564. }
  565. }
  566. #region 取得部門資料
  567. public static Dictionary<string, Tuple<string, string, string, string, string>> GetDeptInfos(SqlSugarClient db, string OrgID = "TE")
  568. {
  569. var DeptDic = new Dictionary<string, Tuple<string, string, string, string, string>>();
  570. var spOrgID = new SugarParameter("@OrgID", OrgID);
  571. var spDeptID = new SugarParameter("@DeptID", "");
  572. var DataJArrays = db.Ado.SqlQueryDynamic(@"WITH SupperDeptID(OrgID,DepartmentID,DepartmentName,ParentDepartmentID,ParentDepartmentName,Level)
  573. as(
  574. select OrgID,DepartmentID,DepartmentName,ParentDepartmentID, DepartmentName as ParentDepartmentName, 0 as Level from OTB_SYS_Departments where Len(ParentDepartmentID) =0
  575. UNION ALL
  576. Select sub.OrgID, sub.DepartmentID, sub.DepartmentName, sub.ParentDepartmentID, Supper.DepartmentName as ParentDepartmentName, Supper.Level +1 as Level
  577. from OTB_SYS_Departments Sub,SupperDeptID Supper
  578. WHere Sub.ParentDepartmentID = Supper.DepartmentID and sub.OrgID = Supper.OrgID
  579. )
  580. Select *from SupperDeptID where OrgID = 'TE' Order By OrgID, Level", spOrgID, spDeptID);
  581. foreach (var row in DataJArrays)
  582. {
  583. var DepartmentID = row["DepartmentID"].ToString() ?? "";
  584. var DepartmentName = row["DepartmentName"].ToString() ?? "";
  585. var ParentDepartmentID = row["ParentDepartmentID"].ToString() ?? "";
  586. var ParentDepartmentName = row["ParentDepartmentName"].ToString() ?? "";
  587. var Level = row["Level"].ToString() ?? "";
  588. var DepInfo = new Tuple<string, string, string, string, string>(DepartmentID, DepartmentName, ParentDepartmentID, ParentDepartmentName, Level);
  589. DeptDic.Add(DepartmentID, DepInfo);
  590. }
  591. return DeptDic;
  592. }
  593. //public static string GetRelativeMember(SqlSugarClient db, string OrgID, string DeptID, string Member)
  594. //{
  595. // var Result = "";
  596. // if (string.IsNullOrEmpty(Member) && !string.IsNullOrEmpty(DeptID))
  597. // {
  598. // var spOrgID = new SugarParameter("@OrgID", OrgID);
  599. // var spDepartID = new SugarParameter("@DepartID", DeptID);
  600. // var AllOfDepartMembers = db.Ado.SqlQuery<string>(@"select MemberID from [dbo].[OVW_SYS_Members]
  601. // where OrgID = @OrgID and DepartmentID in
  602. // ( SELECT * FROM [dbo].[OFN_SYS_GetChilDepartmentIdByDepartmentId] (@OrgID, @DepartID) ) ",
  603. // spOrgID, spDepartID).ToArray();
  604. // Result = string.Join(",", AllOfDepartMembers);
  605. // }
  606. // return Result;
  607. //}
  608. #endregion
  609. public static decimal Rounding(decimal value, int digit)
  610. {
  611. if (digit <= 0)
  612. return Math.Round(value, MidpointRounding.AwayFromZero);
  613. else
  614. return Math.Round(value, digit, MidpointRounding.AwayFromZero);
  615. }
  616. public static decimal Rounding(double value, int digit)
  617. {
  618. double result = 0.0;
  619. if (digit <= 0)
  620. result = Math.Round(value, MidpointRounding.AwayFromZero);
  621. else
  622. result = Math.Round(value, digit, MidpointRounding.AwayFromZero);
  623. return Convert.ToDecimal(result);
  624. }
  625. }
  626. }