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.

1165 lines
84 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity;
  3. using Entity.Sugar;
  4. using Entity.ViewModels;
  5. using Newtonsoft.Json;
  6. using Newtonsoft.Json.Linq;
  7. using SqlSugar;
  8. using SqlSugar.Base;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.Drawing;
  13. namespace EasyBL.WEBAPP.OPM
  14. {
  15. public class ExhibitionImport_QryService : ServiceBase
  16. {
  17. #region 進口分頁查詢
  18. /// <summary>
  19. /// 進口分頁查詢
  20. /// </summary>
  21. /// <param name="i_crm"></param>
  22. /// <returns></returns>
  23. public ResponseMessage QueryPage(RequestMessage i_crm)
  24. {
  25. ResponseMessage rm = null;
  26. string sMsg = null;
  27. var db = SugarBase.GetIntance();
  28. try
  29. {
  30. do
  31. {
  32. var pml = new PageModel
  33. {
  34. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  35. PageSize = _fetchInt(i_crm, @"pageSize")
  36. };
  37. var iPageCount = 0;
  38. var sSortField = _fetchString(i_crm, @"sortField");
  39. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  40. var sRefNumber = _fetchString(i_crm, @"RefNumber");
  41. var sImportBillName = _fetchString(i_crm, @"ImportBillName");
  42. var sBillNO = _fetchString(i_crm, @"BillNO");
  43. var sExhibitionDateStart = _fetchString(i_crm, @"ExhibitionDateStart");
  44. var sExhibitionDateEnd = _fetchString(i_crm, @"ExhibitionDateEnd");
  45. var sAgent = _fetchString(i_crm, @"Agent");
  46. var sResponsiblePerson = _fetchString(i_crm, @"ResponsiblePerson");
  47. var sImportPerson = _fetchString(i_crm, @"ImportPerson");
  48. var sDeclarationClass = _fetchString(i_crm, @"DeclarationClass");
  49. var sBillLadNO = _fetchString(i_crm, @"BillLadNO");
  50. var sJobTracking = _fetchString(i_crm, @"JobTracking");
  51. var sIsIncludeVoid = _fetchString(i_crm, @"IsIncludeVoid");
  52. var sSupplier = _fetchString(i_crm, @"Supplier");
  53. var sREF = _fetchString(i_crm, @"REF");
  54. var sDepartmentID = _fetchString(i_crm, @"DepartmentID");
  55. var sFlow_Status = _fetchString(i_crm, @"Flow_Status");
  56. var bExcel = _fetchBool(i_crm, @"Excel");
  57. var sExcelType = _fetchString(i_crm, @"ExcelType");
  58. string[] saJobTracking = null;
  59. string[] saIsIncludeVoid = null;
  60. var rExhibitionDateStart = new DateTime();
  61. var rExhibitionDateEnd = new DateTime();
  62. if (!string.IsNullOrEmpty(sExhibitionDateStart))
  63. {
  64. rExhibitionDateStart = SqlFunc.ToDate(sExhibitionDateStart);
  65. }
  66. if (!string.IsNullOrEmpty(sExhibitionDateEnd))
  67. {
  68. rExhibitionDateEnd = SqlFunc.ToDate(sExhibitionDateEnd).AddDays(1);
  69. }
  70. if (!string.IsNullOrEmpty(sJobTracking))
  71. {
  72. saJobTracking = sJobTracking.Split(',');
  73. }
  74. if (!string.IsNullOrEmpty(sIsIncludeVoid))
  75. {
  76. saIsIncludeVoid = sIsIncludeVoid.Split(',');
  77. }
  78. var spOrgID = new SugarParameter("@OrgID", i_crm.ORIGID);
  79. var spUserID = new SugarParameter("@UserID", i_crm.USERID);
  80. var spDepartmentID = new SugarParameter("@DepartmentID", sDepartmentID);
  81. var saRoles = db.Queryable<OTB_SYS_MembersToRule>().Where(x => x.OrgID == i_crm.ORIGID && x.MemberID == i_crm.USERID).Select(x => x.RuleID).ToList().ToArray();
  82. var saChildDeptIds = db.Ado.SqlQuery<string>("select DepartmentId from [dbo].[OFN_SYS_GetChilDepartmentIdByDepartmentId](@OrgID,@DepartmentID)", spOrgID, spDepartmentID).ToArray();
  83. var saDeptIdsByUser = db.Ado.SqlQuery<string>("SELECT DepartmentId FROM [dbo].[OFN_SYS_GetChilDepartmentIdByUserID](@OrgID,@UserID)", spOrgID, spUserID).ToArray();
  84. var saChildUserIds = db.Ado.SqlQuery<string>("SELECT MemberID FROM [dbo].[OFN_SYS_GetMemberIDDownByChief](@OrgID,@UserID)", spOrgID, spUserID).ToArray();
  85. pml.DataList = db.Queryable<OTB_OPM_ImportExhibition, OTB_SYS_Members, OTB_OPM_Exhibition, OTB_CRM_Customers, OTB_CRM_Customers>
  86. ((t1, t2, t3, t7, t8) =>
  87. new object[] {
  88. JoinType.Inner, t1.OrgID == t2.OrgID && t1.ResponsiblePerson == t2.MemberID,
  89. JoinType.Left, t1.OrgID == t3.OrgID && t1.ExhibitionNO == t3.SN.ToString(),
  90. JoinType.Left, t1.OrgID == t7.OrgID && t1.Supplier == t7.guid,
  91. JoinType.Left, t1.OrgID == t8.OrgID && t1.Agent == t8.guid
  92. }
  93. )
  94. .Where((t1) => t1.OrgID == i_crm.ORIGID)
  95. .WhereIF(!string.IsNullOrEmpty(sRefNumber), (t1) => t1.RefNumber.Contains(sRefNumber))
  96. .WhereIF(!string.IsNullOrEmpty(sImportBillName), (t1, t2, t3) => (t3.Exhibitioname_TW + t3.Exhibitioname_EN + t3.ExhibitioShotName_TW).Contains(sImportBillName))
  97. .WhereIF(!string.IsNullOrEmpty(sResponsiblePerson), (t1) => t1.ResponsiblePerson == sResponsiblePerson)
  98. .WhereIF(!string.IsNullOrEmpty(sImportPerson), (t1) => t1.ImportPerson.Contains(sImportPerson))
  99. .WhereIF(!string.IsNullOrEmpty(sDeclarationClass), (t1) => t1.DeclarationClass == sDeclarationClass)
  100. .WhereIF(!string.IsNullOrEmpty(sAgent), (t1, t2, t3, t7, t8) => (t8.CustomerCName + t8.CustomerEName).Contains(sAgent))
  101. .WhereIF(!string.IsNullOrEmpty(sSupplier), (t1, t2, t3, t7) => (t7.CustomerCName + t7.CustomerEName).Contains(sSupplier))
  102. .WhereIF(!string.IsNullOrEmpty(sBillLadNO), (t1) => (t1.BillLadNO + t1.ReImports).Contains(sBillLadNO))
  103. .WhereIF(!string.IsNullOrEmpty(sFlow_Status), (t1) => t1.Flow_Status == sFlow_Status)
  104. .WhereIF(!string.IsNullOrEmpty(sBillNO), (t1) => (t1.Bills + t1.ReturnBills).Contains("\"BillNO\":%\"" + sBillNO))
  105. .WhereIF(!string.IsNullOrEmpty(sREF), (t1) => t1.REF.Contains(sREF))
  106. .WhereIF(!string.IsNullOrEmpty(sDepartmentID), (t1) => SqlFunc.ContainsArray(saChildDeptIds, t1.DepartmentID))
  107. .WhereIF(!string.IsNullOrEmpty(sJobTracking), (t1) => SqlFunc.ContainsArray(saJobTracking, t1.Release))
  108. .WhereIF(!string.IsNullOrEmpty(sIsIncludeVoid), (t1) => SqlFunc.ContainsArray(saIsIncludeVoid, t1.IsVoid))
  109. .WhereIF(!string.IsNullOrEmpty(sExhibitionDateStart), (t1) => t1.ExhibitionDateStart >= rExhibitionDateStart.Date)
  110. .WhereIF(!string.IsNullOrEmpty(sExhibitionDateEnd), (t1) => t1.ExhibitionDateEnd <= rExhibitionDateEnd.Date)
  111. .Where((t1) => t1.CreateUser == i_crm.USERID || t1.ResponsiblePerson == i_crm.USERID || SqlFunc.ContainsArray(saDeptIdsByUser, t1.DepartmentID) ||
  112. SqlFunc.Subqueryable<OTB_SYS_Members>().Where(c => c.MemberID == t1.CreateUser && c.OrgID == t1.OrgID).Select(c => c.ImmediateSupervisor) == i_crm.USERID ||
  113. SqlFunc.Subqueryable<OTB_SYS_Members>().Where(p => p.MemberID == t1.ResponsiblePerson && p.OrgID == t1.OrgID).Select(c => c.ImmediateSupervisor) == i_crm.USERID || SqlFunc.ContainsArray(saChildUserIds, t1.CreateUser) || SqlFunc.ContainsArray(saChildUserIds, t1.ResponsiblePerson) || SqlFunc.ContainsArray(saRoles, "Account") || SqlFunc.ContainsArray(saRoles, "CDD") || SqlFunc.ContainsArray(saRoles, "Admin") || SqlFunc.ContainsArray(saRoles, "Manager"))
  114. .Select((t1, t2, t3, t7, t8) => new View_OPM_ImportExhibition
  115. {
  116. ImportBillNO = t1.ImportBillNO,
  117. RefNumber = t1.RefNumber,
  118. ImportBillName = t3.Exhibitioname_TW,
  119. ExhibitionDateStart = t1.ExhibitionDateStart,
  120. BillLadNO = t1.BillLadNO,
  121. IsVoid = t1.IsVoid,
  122. ReImports = t1.ReImports,
  123. ReturnBills = SqlFunc.IsNull(t1.ReturnBills, "[]"),
  124. REF = t1.REF,
  125. Flow_Status = t1.Flow_Status,
  126. SupplierCName = SqlFunc.IIF(SqlFunc.HasValue(t7.CustomerCName), t7.CustomerCName, t7.CustomerEName),
  127. AgentName = SqlFunc.IIF(SqlFunc.HasValue(t8.CustomerCName), t8.CustomerCName, t8.CustomerEName),
  128. ResponsiblePersonName = t2.MemberName,
  129. IsAlert = SqlFunc.MappingColumn(t1.ImportBillNO, "[dbo].[OFN_OPM_CheckDate](t1.Release,t1.ExhibitionDateStart,5)"),
  130. Bills = SqlFunc.IsNull(t1.Bills, "[]"),
  131. IsSendMail = t1.IsSendMail
  132. })
  133. .MergeTable()
  134. .OrderByIF(string.IsNullOrEmpty(sSortField), "IsAlert desc,ExhibitionDateStart desc,ImportBillName,RefNumber desc")
  135. .OrderByIF(!string.IsNullOrEmpty(sSortField), sSortField + " " + sSortOrder)
  136. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  137. pml.Total = iPageCount;
  138. rm = new SuccessResponseMessage(null, i_crm);
  139. if (bExcel)
  140. {
  141. }
  142. else
  143. {
  144. rm.DATA.Add(BLWording.REL, pml);
  145. }
  146. } while (false);
  147. }
  148. catch (Exception ex)
  149. {
  150. sMsg = Util.GetLastExceptionMsg(ex);
  151. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.OPM.ExhibitionImport_QryService", "", "QueryPage(進口分頁查詢)", "", "", "");
  152. }
  153. finally
  154. {
  155. if (null != sMsg)
  156. {
  157. rm = new ErrorResponseMessage(sMsg, i_crm);
  158. }
  159. }
  160. return rm;
  161. }
  162. #endregion 進口分頁查詢
  163. #region 進口分頁查詢
  164. /// <summary>
  165. /// 進口分頁查詢
  166. /// </summary>
  167. /// <param name="i_crm"></param>
  168. /// <returns></returns>
  169. public ResponseMessage GetExcel(RequestMessage i_crm)
  170. {
  171. ResponseMessage rm = null;
  172. string sMsg = null;
  173. var db = SugarBase.GetIntance();
  174. try
  175. {
  176. do
  177. {
  178. var pml = new PageModel
  179. {
  180. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  181. PageSize = _fetchInt(i_crm, @"pageSize")
  182. };
  183. var iPageCount = 0;
  184. var sSortField = _fetchString(i_crm, @"sortField");
  185. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  186. var sRefNumber = _fetchString(i_crm, @"RefNumber");
  187. var sImportBillName = _fetchString(i_crm, @"ImportBillName");
  188. var sBillNO = _fetchString(i_crm, @"BillNO");
  189. var sExhibitionDateStart = _fetchString(i_crm, @"ExhibitionDateStart");
  190. var sExhibitionDateEnd = _fetchString(i_crm, @"ExhibitionDateEnd");
  191. var sAgent = _fetchString(i_crm, @"Agent");
  192. var sResponsiblePerson = _fetchString(i_crm, @"ResponsiblePerson");
  193. var sImportPerson = _fetchString(i_crm, @"ImportPerson");
  194. var sDeclarationClass = _fetchString(i_crm, @"DeclarationClass");
  195. var sBillLadNO = _fetchString(i_crm, @"BillLadNO");
  196. var sJobTracking = _fetchString(i_crm, @"JobTracking");
  197. var sIsIncludeVoid = _fetchString(i_crm, @"IsIncludeVoid");
  198. var sSupplier = _fetchString(i_crm, @"Supplier");
  199. var sREF = _fetchString(i_crm, @"REF");
  200. var sDepartmentID = _fetchString(i_crm, @"DepartmentID");
  201. var sFlow_Status = _fetchString(i_crm, @"Flow_Status");
  202. var bExcel = _fetchBool(i_crm, @"Excel");
  203. var sExcelType = _fetchString(i_crm, @"ExcelType");
  204. string[] saJobTracking = null;
  205. string[] saIsIncludeVoid = null;
  206. var rExhibitionDateStart = new DateTime();
  207. var rExhibitionDateEnd = new DateTime();
  208. if (!string.IsNullOrEmpty(sExhibitionDateStart))
  209. {
  210. rExhibitionDateStart = SqlFunc.ToDate(sExhibitionDateStart);
  211. }
  212. if (!string.IsNullOrEmpty(sExhibitionDateEnd))
  213. {
  214. rExhibitionDateEnd = SqlFunc.ToDate(sExhibitionDateEnd).AddDays(1);
  215. }
  216. if (!string.IsNullOrEmpty(sJobTracking))
  217. {
  218. saJobTracking = sJobTracking.Split(',');
  219. }
  220. if (!string.IsNullOrEmpty(sIsIncludeVoid))
  221. {
  222. saIsIncludeVoid = sIsIncludeVoid.Split(',');
  223. }
  224. var spOrgID = new SugarParameter("@OrgID", i_crm.ORIGID);
  225. var spUserID = new SugarParameter("@UserID", i_crm.USERID);
  226. var spDepartmentID = new SugarParameter("@DepartmentID", sDepartmentID);
  227. var saRoles = db.Queryable<OTB_SYS_MembersToRule>().Where(x => x.OrgID == i_crm.ORIGID && x.MemberID == i_crm.USERID).Select(x => x.RuleID).ToList().ToArray();
  228. var saChildDeptIds = db.Ado.SqlQuery<string>("select DepartmentId from [dbo].[OFN_SYS_GetChilDepartmentIdByDepartmentId](@OrgID,@DepartmentID)", spOrgID, spDepartmentID).ToArray();
  229. var saDeptIdsByUser = db.Ado.SqlQuery<string>("SELECT DepartmentId FROM [dbo].[OFN_SYS_GetChilDepartmentIdByUserID](@OrgID,@UserID)", spOrgID, spUserID).ToArray();
  230. var saChildUserIds = db.Ado.SqlQuery<string>("SELECT MemberID FROM [dbo].[OFN_SYS_GetMemberIDDownByChief](@OrgID,@UserID)", spOrgID, spUserID).ToArray();
  231. pml.DataList = db.Queryable<OTB_OPM_ImportExhibition, OTB_SYS_Members, OTB_OPM_Exhibition, OTB_SYS_Arguments, OTB_SYS_Arguments, OTB_SYS_Arguments, OTB_CRM_Customers, OTB_CRM_Customers, OTB_CRM_Customers>
  232. ((t1, t2, t3, t4, t5, t6, t7, t8, t9) =>
  233. new object[] {
  234. JoinType.Inner, t1.OrgID == t2.OrgID && t1.ResponsiblePerson == t2.MemberID,
  235. JoinType.Left, t1.OrgID == t3.OrgID && t1.ExhibitionNO == t3.SN.ToString(),
  236. JoinType.Left, t1.OrgID == t4.OrgID && t1.DeclarationClass == t4.ArgumentID && t4.ArgumentClassID == "DeclClass",
  237. JoinType.Left, t1.OrgID == t5.OrgID && t1.TransportationMode == t5.ArgumentID && t5.ArgumentClassID == "Transport",
  238. JoinType.Left, t1.OrgID == t6.OrgID && t1.CustomsClearance == t6.ArgumentID && t6.ArgumentClassID == "Clearance",
  239. JoinType.Left, t1.OrgID == t7.OrgID && t1.Supplier == t7.guid,
  240. JoinType.Left, t1.OrgID == t8.OrgID && t1.Agent == t8.guid,
  241. JoinType.Left, t1.OrgID == t9.OrgID && t1.ImportPerson == t9.guid
  242. }
  243. )
  244. .Where((t1) => t1.OrgID == i_crm.ORIGID)
  245. .WhereIF(!string.IsNullOrEmpty(sRefNumber), (t1) => t1.RefNumber.Contains(sRefNumber))
  246. .WhereIF(!string.IsNullOrEmpty(sImportBillName), (t1, t2, t3) => (t3.Exhibitioname_TW + t3.Exhibitioname_EN + t3.ExhibitioShotName_TW).Contains(sImportBillName))
  247. .WhereIF(!string.IsNullOrEmpty(sResponsiblePerson), (t1) => t1.ResponsiblePerson == sResponsiblePerson)
  248. .WhereIF(!string.IsNullOrEmpty(sImportPerson), (t1) => t1.ImportPerson.Contains(sImportPerson))
  249. .WhereIF(!string.IsNullOrEmpty(sDeclarationClass), (t1) => t1.DeclarationClass == sDeclarationClass)
  250. .WhereIF(!string.IsNullOrEmpty(sAgent), (t1, t2, t3, t4, t5, t6, t7, t8) => (t8.CustomerCName + t8.CustomerEName).Contains(sAgent))
  251. .WhereIF(!string.IsNullOrEmpty(sSupplier), (t1, t2, t3, t4, t5, t6, t7) => (t7.CustomerCName + t7.CustomerEName).Contains(sSupplier))
  252. .WhereIF(!string.IsNullOrEmpty(sBillLadNO), (t1) => (t1.BillLadNO + t1.ReImports).Contains(sBillLadNO))
  253. .WhereIF(!string.IsNullOrEmpty(sFlow_Status), (t1) => t1.Flow_Status == sFlow_Status)
  254. .WhereIF(!string.IsNullOrEmpty(sBillNO), (t1) => (t1.Bills + t1.ReturnBills).Contains(sBillNO))
  255. .WhereIF(!string.IsNullOrEmpty(sREF), (t1) => t1.REF.Contains(sREF))
  256. .WhereIF(!string.IsNullOrEmpty(sDepartmentID), (t1) => SqlFunc.ContainsArray(saChildDeptIds, t1.DepartmentID))
  257. .WhereIF(!string.IsNullOrEmpty(sJobTracking), (t1) => SqlFunc.ContainsArray(saJobTracking, t1.Release))
  258. .WhereIF(!string.IsNullOrEmpty(sIsIncludeVoid), (t1) => SqlFunc.ContainsArray(saIsIncludeVoid, t1.IsVoid))
  259. .WhereIF(!string.IsNullOrEmpty(sExhibitionDateStart), (t1) => t1.ExhibitionDateStart >= rExhibitionDateStart.Date)
  260. .WhereIF(!string.IsNullOrEmpty(sExhibitionDateEnd), (t1) => t1.ExhibitionDateEnd <= rExhibitionDateEnd.Date)
  261. .Where((t1) => t1.CreateUser == i_crm.USERID || t1.ResponsiblePerson == i_crm.USERID || SqlFunc.ContainsArray(saDeptIdsByUser, t1.DepartmentID) ||
  262. SqlFunc.Subqueryable<OTB_SYS_Members>().Where(c => c.MemberID == t1.CreateUser && c.OrgID == t1.OrgID).Select(c => c.ImmediateSupervisor) == i_crm.USERID ||
  263. SqlFunc.Subqueryable<OTB_SYS_Members>().Where(p => p.MemberID == t1.ResponsiblePerson && p.OrgID == t1.OrgID).Select(c => c.ImmediateSupervisor) == i_crm.USERID || SqlFunc.ContainsArray(saChildUserIds, t1.CreateUser) || SqlFunc.ContainsArray(saChildUserIds, t1.ResponsiblePerson) || SqlFunc.ContainsArray(saRoles, "Account") || SqlFunc.ContainsArray(saRoles, "CDD") || SqlFunc.ContainsArray(saRoles, "Admin") || SqlFunc.ContainsArray(saRoles, "Manager"))
  264. .Select((t1, t2, t3, t4, t5, t6, t7, t8, t9) => new View_OPM_ImportExhibition
  265. {
  266. OrgID = t1.OrgID,
  267. ImportBillNO = t1.ImportBillNO,
  268. ExhibitionNO = t1.ExhibitionNO,
  269. RefNumber = t1.RefNumber,
  270. ImportPerson = t1.ImportPerson,
  271. ImportDeclarationNO = t1.ImportDeclarationNO,
  272. ExportBillNO = t1.ExportBillNO,
  273. ExportDeclarationNO = t1.ExportDeclarationNO,
  274. ImportBillName = t3.Exhibitioname_TW,
  275. ImportBillEName = t3.Exhibitioname_EN,
  276. ExhibitioShotName_TW = t3.ExhibitioShotName_TW,
  277. ExhibitionDateStart = t1.ExhibitionDateStart,
  278. ExhibitionDateEnd = t1.ExhibitionDateEnd,
  279. Hall = t1.Hall,
  280. MuseumMumber = t1.MuseumMumber,
  281. DeclarationClass = t1.DeclarationClass,
  282. ResponsiblePerson = t1.ResponsiblePerson,
  283. Agent = t1.Agent,
  284. Payer = t1.Payer,
  285. Supplier = t1.Supplier,
  286. Suppliers = t1.Suppliers,
  287. ContactorName = t1.ContactorName,
  288. BillLadNO = t1.BillLadNO,
  289. BillLadNOSub = t1.BillLadNOSub,
  290. ContainerNumber = t1.ContainerNumber,
  291. Telephone = t1.Telephone,
  292. ShipmentPort = t1.ShipmentPort,
  293. DestinationPort = t1.DestinationPort,
  294. _ArrivalTime = SqlFunc.MappingColumn(t1.ImportBillNO, "CONVERT(VARCHAR(16),ArrivalTime, 120)"),
  295. StoragePlace = t1.StoragePlace,
  296. BoxNo = t1.BoxNo,
  297. Unit = t1.Unit,
  298. Weight = t1.Weight,
  299. Size = t1.Size,
  300. Volume = t1.Volume,
  301. VolumeWeight = t1.VolumeWeight,
  302. Price = t1.Price,
  303. GoodsType = t1.GoodsType,
  304. Currency = t1.Currency,
  305. ExchangeRate = t1.ExchangeRate,
  306. _FreePeriod = SqlFunc.MappingColumn(t1.ImportBillNO, "CONVERT(VARCHAR(16),FreePeriod, 23)"),
  307. Release = t1.Release,
  308. SitiContactor = t1.SitiContactor,
  309. SitiTelephone = t1.SitiTelephone,
  310. _ApproachTime = SqlFunc.MappingColumn(t1.ImportBillNO, "CONVERT(VARCHAR(16),ApproachTime, 120)"),
  311. _ExitTime = SqlFunc.MappingColumn(t1.ImportBillNO, "CONVERT(VARCHAR(16),ExitTime, 120)"),
  312. TransportationMode = t1.TransportationMode,
  313. CustomsClearance = t1.CustomsClearance,
  314. SignatureFileId = t1.SignatureFileId,
  315. Memo = t1.Memo,
  316. IsVoid = t1.IsVoid,
  317. Import = t1.Import,
  318. ReImports = t1.ReImports,
  319. ReturnBills = SqlFunc.IsNull(t1.ReturnBills, "[]"),
  320. CostData = t1.CostData,
  321. ReturnLoan = t1.ReturnLoan,
  322. TaxInformation = t1.TaxInformation,
  323. REF = t1.REF,
  324. Flow_Status = t1.Flow_Status,
  325. ExhibitionDate = SqlFunc.MappingColumn(t1.ImportBillNO, "CONVERT(varchar(100),t1.ExhibitionDateStart, 111)+'~'+CONVERT(VARCHAR(100),t1.ExhibitionDateEnd, 111)"),
  326. SupplierCName = SqlFunc.IIF(SqlFunc.HasValue(t7.CustomerCName), t7.CustomerCName, t7.CustomerEName),
  327. SupplierEName = t7.CustomerEName,
  328. AgentName = SqlFunc.IIF(SqlFunc.HasValue(t8.CustomerCName), t8.CustomerCName, t8.CustomerEName),
  329. ResponsiblePersonName = t2.MemberName,
  330. DeclarationClassName = t4.ArgumentValue,
  331. TransportationModeName = t5.ArgumentValue,
  332. CustomsClearanceName = t6.ArgumentValue,
  333. IsAlert = SqlFunc.MappingColumn(t1.ImportBillNO, "[dbo].[OFN_OPM_CheckDate](t1.Release,t1.ExhibitionDateStart,5)"),
  334. DepartmentID = t1.DepartmentID,
  335. Bills = SqlFunc.IsNull(t1.Bills, "[]"),
  336. ImportPersonName = SqlFunc.IsNull(t9.CustomerCName, t9.CustomerEName),
  337. SupplierType = t1.SupplierType,
  338. IsSendMail = t1.IsSendMail
  339. })
  340. .MergeTable()
  341. .OrderByIF(string.IsNullOrEmpty(sSortField), "IsAlert desc,ExhibitionDateStart desc,ImportBillName,RefNumber desc")
  342. .OrderByIF(!string.IsNullOrEmpty(sSortField), sSortField + " " + sSortOrder)
  343. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  344. pml.Total = iPageCount;
  345. rm = new SuccessResponseMessage(null, i_crm);
  346. if (bExcel)
  347. {
  348. var sFileName = "";
  349. var oHeader_Last = new object();
  350. var oHeader = new Dictionary<string, string>();
  351. var listMerge = new List<Dictionary<string, int>>();
  352. var dicAlain = new Dictionary<string, string>();
  353. var Export_BusinessTrackingSchedule_List = new List<Dictionary<string, object>>();
  354. var Export_BusinessTrackingSchedule_Group = new Dictionary<string, object>();
  355. var saCustomers1 = pml.DataList;
  356. var saBasicInformation = pml.DataList as List<View_OPM_ImportExhibition>;
  357. var dt_new = saBasicInformation.ListToDataTable<View_OPM_ImportExhibition>();
  358. switch (sExcelType)
  359. {
  360. case "Import_BasicInformation":
  361. {
  362. sFileName = "出口基本資料";
  363. oHeader = new Dictionary<string, string>
  364. {
  365. { "RowIndex", "項次" },
  366. { "RefNumber", "查詢號碼" },
  367. { "ImportBillNO", "帳單號碼" },
  368. { "ExportBillNO", "退運帳單號碼" },
  369. { "ResponsiblePersonName", "負責業務" },
  370. { "ImportBillName", "展覽名稱" },
  371. { "ImportBillEName", "英文展名" },
  372. { "ExhibitionDate", "展覽日期起訖" },
  373. { "Hall", "館別" },
  374. { "MuseumMumber", "攤位號碼" },
  375. { "SupplierCName", "參展廠商" },
  376. { "AgentName", "國外代理" },
  377. { "DeclarationClassName", "報關類別" },
  378. { "ImportDeclarationNO", "進口報單號碼" },
  379. { "ContainerNumber", "貨櫃號碼" },
  380. { "Payer", "付款人" },
  381. { "BillLadNO", "提單號碼" },
  382. { "BillLadNOSub", "分提單號碼" },
  383. { "BoxNo", "件數" },
  384. { "Unit", "單位" },
  385. { "Weight", "毛重(G.W.)" },
  386. { "Price", "貨價" },
  387. { "ShipmentPort", "起運地" },
  388. { "DestinationPort", "目的地" },
  389. { "_ArrivalTime", "預計抵達時間" },
  390. { "StoragePlace", "貨物儲放倉庫" },
  391. { "GoodsType", "貨型" },
  392. { "Size", "尺寸" },
  393. { "Volume", "材積重(CBM)" },
  394. { "VolumeWeight", "材積重(C.W.)" },
  395. { "_FreePeriod", "免費期" },
  396. { "TransportationModeName", "運送方式" },
  397. { "CustomsClearanceName", "通關方式" },
  398. { "SitiContactor", "現場聯絡人" },
  399. { "SitiTelephone", "現場聯絡電話" },
  400. { "_ApproachTime", "進場時間" },
  401. { "_ExitTime", "退場時間" },
  402. { "Memo", "特別注意事項" }
  403. };
  404. var list_Halls1 = db.Queryable<OTB_SYS_Arguments>()
  405. .Where(it => it.OrgID == i_crm.ORIGID && it.ArgumentClassID == "Hall").ToList();
  406. var m = new Map();
  407. foreach (OTB_SYS_Arguments arg in list_Halls1)
  408. {
  409. m.Put(arg.ArgumentID, arg.ArgumentValue);
  410. }
  411. foreach (DataRow row in dt_new.Rows)
  412. {
  413. row["Hall"] = m[row["Hall"].ToString()] ?? "";
  414. var sBills = "";
  415. var sReBills = "";
  416. var JaBills = (JArray)JsonConvert.DeserializeObject(row["Bills"].ToString());
  417. var JaReturns = (JArray)JsonConvert.DeserializeObject(row["ReturnBills"].ToString());
  418. var builder = new System.Text.StringBuilder();
  419. builder.Append(sBills);
  420. foreach (JObject bill in JaBills)
  421. {
  422. builder.Append(bill["BillNO"] + ",");
  423. }
  424. sBills = builder.ToString();
  425. foreach (JObject rebill in JaReturns)
  426. {
  427. if (rebill["Bills"] != null)
  428. {
  429. var JReBills = (JArray)JsonConvert.DeserializeObject(rebill["Bills"].ToString());
  430. var builder1 = new System.Text.StringBuilder();
  431. builder1.Append(sReBills);
  432. foreach (JObject bill in JReBills)
  433. {
  434. builder1.Append(bill["BillNO"] + ",");
  435. }
  436. sReBills = builder1.ToString();
  437. }
  438. }
  439. row["ImportBillNO"] = sBills;
  440. row["ExportBillNO"] = sReBills;
  441. }
  442. dicAlain = ExcelService.GetExportAlain(oHeader, "RefNumber,_ClosingDate,_ClosingDate,_ArrivalTime,_ExitTime,_FreePeriod,_ApproachTime");
  443. oHeader_Last = oHeader;
  444. }
  445. break;
  446. case "Import_BusinessTrackingSchedule":
  447. {
  448. var Import_BusinessTrackingSchedule_List = new List<Dictionary<string, object>>();
  449. var Import_BusinessTrackingSchedule_Group = new Dictionary<string, object>();
  450. sFileName = "進口業務追蹤進度表";
  451. oHeader = new Dictionary<string, string>
  452. {
  453. { "RowIndex", "項次" },
  454. { "RefNumber", "查詢號碼" },
  455. { "ImportBillNO", "帳單號碼" },
  456. { "ExportBillNO", "退運帳單號碼" },
  457. { "ResponsiblePersonName", "負責業務" },
  458. { "ImportBillName", "展覽名稱" },
  459. { "ImportBillEName", "英文展名" },
  460. { "ExhibitionDate", "展覽日期起訖" },
  461. { "Hall", "館別" },
  462. { "MuseumMumber", "攤位號碼" },
  463. { "SupplierCName", "參展廠商" },
  464. { "AgentName", "國外代理" },
  465. { "DeclarationClassName", "報關類別" },
  466. { "ImportDeclarationNO", "進口報單號碼" },
  467. { "ContainerNumber", "貨櫃號碼" },
  468. { "Payer", "付款人" },
  469. { "BillLadNO", "提單號碼" },
  470. { "BillLadNOSub", "分提單號碼" },
  471. { "BoxNo", "件數" },
  472. { "Unit", "單位" },
  473. { "Weight", "毛重(G.W.)" },
  474. { "ShipmentPort", "起運地" },
  475. { "DestinationPort", "目的地" },
  476. { "ArrivalTime", "預計抵達時間" },
  477. { "StoragePlace", "貨物儲放倉庫" },
  478. { "GoodsType", "貨型" },
  479. { "Size", "尺寸" },
  480. { "Volume", "材積(CBM)" },
  481. { "VolumeWeight", "材積重(C.W.)" },
  482. { "Price", "貨價" },
  483. { "FreePeriod", "免費期" },
  484. { "TransportationModeName", "運送方式" },
  485. { "CustomsClearanceName", "通關方式" },
  486. { "SitiContactor", "現場聯絡人" },
  487. { "SitiTelephone", "現場聯絡電話" },
  488. { "_ApproachTime", "進場時間" },
  489. { "_ExitTime", "退場時間" },
  490. { "Memo", "特別注意事項" }
  491. };
  492. dicAlain = ExcelService.GetExportAlain(oHeader, new string[] { "Email", "Contactor", "ContactorEmail" });
  493. Import_BusinessTrackingSchedule_Group.Add("Header", oHeader);
  494. Import_BusinessTrackingSchedule_Group.Add("HeaderName", "基本資料");
  495. Import_BusinessTrackingSchedule_Group.Add("Color", Color.Chocolate);
  496. Import_BusinessTrackingSchedule_List.Add(Import_BusinessTrackingSchedule_Group);
  497. oHeader = new Dictionary<string, string>();
  498. Import_BusinessTrackingSchedule_Group = new Dictionary<string, object>();
  499. oHeader.Add("Import_ReceiveFile_Date", "已收文件");
  500. oHeader.Add("Import_GoodsArrival_Date", "貨物抵達");
  501. oHeader.Add("Import_CustomsDeclaration_Date", "報關作業");
  502. oHeader.Add("Import_CargoRelease_Date", "貨物放行");
  503. oHeader.Add("Import_ExhibitionWarehouse_Date", "轉至展館倉庫");
  504. oHeader.Add("Import_Sign_Date", "客戶簽收");
  505. Import_BusinessTrackingSchedule_Group.Add("Header", oHeader);
  506. Import_BusinessTrackingSchedule_Group.Add("HeaderName", "貨物進口");
  507. Import_BusinessTrackingSchedule_Group.Add("Color", Color.Aqua);
  508. Import_BusinessTrackingSchedule_List.Add(Import_BusinessTrackingSchedule_Group);
  509. oHeader = new Dictionary<string, string>();
  510. Import_BusinessTrackingSchedule_Group = new Dictionary<string, object>();
  511. var list_Halls2 = db.Queryable<OTB_SYS_Arguments>()
  512. .Where(it => it.OrgID == i_crm.ORIGID && it.ArgumentClassID == "Hall").ToList();
  513. var mH = new Map();
  514. foreach (OTB_SYS_Arguments arg in list_Halls2)
  515. {
  516. mH.Put(arg.ArgumentID, arg.ArgumentValue);
  517. }
  518. var ja = new JArray();
  519. foreach (DataRow row in dt_new.Rows)
  520. {
  521. var jaReImports = (JArray)JsonConvert.DeserializeObject(row["ReImports"].ToString());
  522. if (jaReImports.Count > ja.Count)
  523. {
  524. ja = jaReImports;
  525. }
  526. row["Hall"] = mH[row["Hall"].ToString()] ?? "";
  527. var sBills = "";
  528. var sReBills = "";
  529. var JaBills = (JArray)JsonConvert.DeserializeObject(row["Bills"].ToString());
  530. var JaReturns = (JArray)JsonConvert.DeserializeObject(row["ReturnBills"].ToString());
  531. var builder = new System.Text.StringBuilder();
  532. builder.Append(sBills);
  533. foreach (JObject bill in JaBills)
  534. {
  535. builder.Append(bill["BillNO"] + ",");
  536. }
  537. sBills = builder.ToString();
  538. foreach (JObject rebill in JaReturns)
  539. {
  540. if (rebill["Bills"] != null)
  541. {
  542. var JReBills = (JArray)JsonConvert.DeserializeObject(rebill["Bills"].ToString());
  543. var builder1 = new System.Text.StringBuilder();
  544. builder1.Append(sReBills);
  545. foreach (JObject bill in JReBills)
  546. {
  547. builder1.Append(bill["BillNO"] + ",");
  548. }
  549. sReBills = builder1.ToString();
  550. }
  551. }
  552. row["ImportBillNO"] = sBills;
  553. row["ExportBillNO"] = sReBills;
  554. }
  555. for (var idx = 1; idx <= ja.Count; idx++)
  556. {
  557. oHeader.Add("ReImport" + idx + "_FileValidation_Date", "文件確認");
  558. oHeader.Add("ReImport" + idx + "_ReCustomsDeclaration_Date", "報關作業");
  559. oHeader.Add("ReImport" + idx + "_ReCargoRelease_Date", "貨物放行");
  560. oHeader.Add("ReImport" + idx + "_HuiYun_Date", "回運中");
  561. oHeader.Add("ReImport" + idx + "_ReachDestination_Date", "抵達目的地");
  562. oHeader.Add("ReImport" + idx + "_Sign_Date", "客戶簽收");
  563. Import_BusinessTrackingSchedule_Group.Add("Header", oHeader);
  564. Import_BusinessTrackingSchedule_Group.Add("HeaderName", "退運資料" + idx);
  565. Import_BusinessTrackingSchedule_Group.Add("Color", Color.Yellow);
  566. Import_BusinessTrackingSchedule_List.Add(Import_BusinessTrackingSchedule_Group);
  567. oHeader = new Dictionary<string, string>();
  568. Import_BusinessTrackingSchedule_Group = new Dictionary<string, object>();
  569. dt_new.Columns.Add("ReImport" + idx + "_FileValidation_Date");
  570. dt_new.Columns.Add("ReImport" + idx + "_ReCustomsDeclaration_Date");
  571. dt_new.Columns.Add("ReImport" + idx + "_ReCargoRelease_Date");
  572. dt_new.Columns.Add("ReImport" + idx + "_HuiYun_Date");
  573. dt_new.Columns.Add("ReImport" + idx + "_ReachDestination_Date");
  574. dt_new.Columns.Add("ReImport" + idx + "_Sign_Date");
  575. }
  576. dt_new.Columns.Add("Import_ReceiveFile_Date");
  577. dt_new.Columns.Add("Import_GoodsArrival_Date");
  578. dt_new.Columns.Add("Import_CustomsDeclaration_Date");
  579. dt_new.Columns.Add("Import_CargoRelease_Date");
  580. dt_new.Columns.Add("Import_ExhibitionWarehouse_Date");
  581. dt_new.Columns.Add("Import_Sign_Date");
  582. foreach (DataRow row in dt_new.Rows)
  583. {
  584. var jImport = (JObject)JsonConvert.DeserializeObject(row["Import"].ToString());
  585. var jaReImports = (JArray)JsonConvert.DeserializeObject(row["ReImports"].ToString());
  586. if (jImport != null)
  587. {
  588. row["Import_ReceiveFile_Date"] = ((JObject)jImport["ReceiveFile"])["Date"];
  589. row["Import_GoodsArrival_Date"] = ((JObject)jImport["GoodsArrival"])["Date"];
  590. row["Import_CustomsDeclaration_Date"] = ((JObject)jImport["CustomsDeclaration"])["Date"];
  591. row["Import_CargoRelease_Date"] = ((JObject)jImport["CargoRelease"])["Date"];
  592. row["Import_ExhibitionWarehouse_Date"] = jImport["ExhibitionWarehouse"] == null ? "" : ((JObject)jImport["ExhibitionWarehouse"])["Date"];
  593. row["Import_Sign_Date"] = ((JObject)jImport["Sign"])["Date"];
  594. };
  595. if (jaReImports != null && jaReImports.Count > 0)
  596. {
  597. var iIndex = 1;
  598. foreach (JObject jo in jaReImports)
  599. {
  600. var jFlow = (JObject)jo["ReImport"];
  601. row["ReImport" + iIndex + "_FileValidation_Date"] = ((JObject)jFlow["FileValidation"])["Date"];
  602. row["ReImport" + iIndex + "_ReCustomsDeclaration_Date"] = ((JObject)jFlow["ReCustomsDeclaration"])["Date"];
  603. row["ReImport" + iIndex + "_ReCargoRelease_Date"] = ((JObject)jFlow["ReCargoRelease"])["Date"];
  604. row["ReImport" + iIndex + "_HuiYun_Date"] = ((JObject)jFlow["HuiYun"])["Date"];
  605. row["ReImport" + iIndex + "_ReachDestination_Date"] = ((JObject)jFlow["ReachDestination"])["Date"];
  606. row["ReImport" + iIndex + "_Sign_Date"] = ((JObject)jFlow["Sign"])["Date"];
  607. iIndex++;
  608. }
  609. };
  610. }
  611. oHeader_Last = Import_BusinessTrackingSchedule_List;
  612. }
  613. break;
  614. case "Import_ReturnRecord":
  615. sFileName = "進口退運記錄表";
  616. var Import_ReturnRecordHeader_List = new List<Dictionary<string, object>>();
  617. var Import_ReturnRecordHeader_Group = new Dictionary<string, object>();
  618. oHeader = new Dictionary<string, string>
  619. {
  620. { "RowIndex", "項次" },
  621. { "ImportBillName", "展覽名稱" },
  622. { "ImportBillEName", "英文展名" },
  623. { "SupplierCName", "參展廠商" },
  624. { "ImportDeclarationNO", "進口報單號碼" },
  625. { "ExportBillNO", "退運出口帳單號碼" },
  626. { "DeclarationClassName", "報關類別" },
  627. { "ShipmentPort", "起運地" },
  628. { "BoxNo", "件數" },
  629. { "Unit", "單位" },
  630. { "Weight", "毛重(G.W.)" },
  631. { "Volume", "材積(CBM)" },
  632. { "VolumeWeight", "材積重(C.W.)" }
  633. };
  634. Import_ReturnRecordHeader_Group.Add("Header", oHeader);
  635. Import_ReturnRecordHeader_Group.Add("HeaderName", "基本資料");
  636. Import_ReturnRecordHeader_Group.Add("Color", Color.Chocolate);
  637. Import_ReturnRecordHeader_List.Add(Import_ReturnRecordHeader_Group);
  638. oHeader = new Dictionary<string, string>();
  639. Import_ReturnRecordHeader_Group = new Dictionary<string, object>();
  640. var jaRe = new JArray();
  641. foreach (DataRow row in dt_new.Rows)
  642. {
  643. var jaReImports = (JArray)JsonConvert.DeserializeObject(row["ReImports"].ToString());
  644. if (jaReImports.Count > jaRe.Count)
  645. {
  646. jaRe = jaReImports;
  647. }
  648. }
  649. for (var idx = 1; idx <= jaRe.Count; idx++)
  650. {
  651. oHeader.Add("ReImport" + idx + "_ReturnOrNotItems", "回運/不回運項目");
  652. oHeader.Add("ReImport" + idx + "_EnteringData", "進倉資料");
  653. oHeader.Add("ReImport" + idx + "_ReShipmentPort", "目的地");
  654. oHeader.Add("ReImport" + idx + "_ShippingAgency", "船代");
  655. oHeader.Add("ReImport" + idx + "_TransportationMode", "運送方式");
  656. oHeader.Add("ReImport" + idx + "_ReturnNumber", "退運件數");
  657. oHeader.Add("ReImport" + idx + "_Unit", "單位");
  658. oHeader.Add("ReImport" + idx + "_HeavyTruckBack", "退運材重");
  659. oHeader.Add("ReImport" + idx + "_LadingBill", "S/O");
  660. oHeader.Add("ReImport" + idx + "_FlightInformation", "班機資料");
  661. oHeader.Add("ReImport" + idx + "_ShippingMarks", "嘜頭");
  662. oHeader.Add("ReImport" + idx + "_Memo", "備註");
  663. oHeader.Add("ReImport" + idx + "_ArrivalTime", "預計抵達時間");
  664. Import_ReturnRecordHeader_Group.Add("Header", oHeader);
  665. Import_ReturnRecordHeader_Group.Add("HeaderName", "退運資料" + idx);
  666. Import_ReturnRecordHeader_Group.Add("Color", Color.Yellow);
  667. Import_ReturnRecordHeader_List.Add(Import_ReturnRecordHeader_Group);
  668. oHeader = new Dictionary<string, string>();
  669. Import_ReturnRecordHeader_Group = new Dictionary<string, object>();
  670. dt_new.Columns.Add("ReImport" + idx + "_ReturnOrNotItems");
  671. dt_new.Columns.Add("ReImport" + idx + "_EnteringData");
  672. dt_new.Columns.Add("ReImport" + idx + "_ReShipmentPort");
  673. dt_new.Columns.Add("ReImport" + idx + "_ShippingAgency");
  674. dt_new.Columns.Add("ReImport" + idx + "_TransportationMode");
  675. dt_new.Columns.Add("ReImport" + idx + "_ReturnNumber");
  676. dt_new.Columns.Add("ReImport" + idx + "_Unit");
  677. dt_new.Columns.Add("ReImport" + idx + "_HeavyTruckBack");
  678. dt_new.Columns.Add("ReImport" + idx + "_LadingBill");
  679. dt_new.Columns.Add("ReImport" + idx + "_FlightInformation");
  680. dt_new.Columns.Add("ReImport" + idx + "_ShippingMarks");
  681. dt_new.Columns.Add("ReImport" + idx + "_Memo");
  682. dt_new.Columns.Add("ReImport" + idx + "_ArrivalTime");
  683. }
  684. foreach (DataRow row in dt_new.Rows)
  685. {
  686. var jaReImports = (JArray)JsonConvert.DeserializeObject(row["ReImports"].ToString());
  687. if (jaReImports != null && jaReImports.Count > 0)
  688. {
  689. var iIndex = 1;
  690. foreach (JObject jo in jaReImports)
  691. {
  692. var jReImportData = (JObject)jo["ReImportData"];
  693. row["ReImport" + iIndex + "_ReturnOrNotItems"] = jReImportData["ReturnOrNotItems"];
  694. row["ReImport" + iIndex + "_EnteringData"] = jReImportData["EnteringData"];
  695. row["ReImport" + iIndex + "_ReShipmentPort"] = jReImportData["ReShipmentPort"];
  696. row["ReImport" + iIndex + "_ShippingAgency"] = jReImportData["ShippingAgency"];
  697. row["ReImport" + iIndex + "_ReShipmentPort"] = jReImportData["ReShipmentPort"];
  698. var sTransportationMode = jReImportData["TransportationMode"].ToString();
  699. if (sTransportationMode != "")
  700. {
  701. var oArgument = db.Queryable<OTB_SYS_Arguments>()
  702. .Single(it => it.OrgID == i_crm.ORIGID && it.ArgumentClassID == "Transport" && it.ArgumentID == sTransportationMode);
  703. if (oArgument == null)
  704. {
  705. oArgument = new OTB_SYS_Arguments();
  706. }
  707. row["ReImport" + iIndex + "_TransportationMode"] = oArgument.ArgumentValue ?? "";
  708. }
  709. row["ReImport" + iIndex + "_ReturnNumber"] = jReImportData["ReturnNumber"];
  710. row["ReImport" + iIndex + "_Unit"] = jReImportData["Unit"];
  711. row["ReImport" + iIndex + "_HeavyTruckBack"] = jReImportData["HeavyTruckBack"];
  712. row["ReImport" + iIndex + "_LadingBill"] = jReImportData["LadingBill"];
  713. row["ReImport" + iIndex + "_FlightInformation"] = jReImportData["FlightInformation"];
  714. row["ReImport" + iIndex + "_ShippingMarks"] = jReImportData["ShippingMarks"];
  715. row["ReImport" + iIndex + "_Memo"] = jReImportData["Memo"];
  716. row["ReImport" + iIndex + "_ArrivalTime"] = jReImportData["ArrivalTime"];
  717. iIndex++;
  718. }
  719. };
  720. }
  721. oHeader_Last = Import_ReturnRecordHeader_List;
  722. break;
  723. case "Import_AreasList":
  724. sFileName = "進口退押款清冊";
  725. oHeader_Last = new Dictionary<string, string>
  726. {
  727. { "RowIndex", "項次" },
  728. { "ImportBillName", "展覽名稱" },
  729. { "ImportBillEName", "英文展名" },
  730. { "SupplierCName", "參展廠商" },
  731. { "ImportDeclarationNO", "進口報單號碼" },
  732. { "Import_CustomsDeclaration_Date", "進口報關日" },
  733. { "ReturnLoan_Margin", "保證金金額" },
  734. { "ReturnedData_ReturnOrNotItems", "回運項次" },
  735. { "ReturnLoan_VerificationDate", "核銷日期" },
  736. { "ReturnedData_ReImportDeclarationNO", "出口報單號碼" },
  737. { "ReImport_ReCustomsDeclaration_Date", "出口報關日" },
  738. { "ReImport_ReCargoRelease_Date", "出口日期" },
  739. { "ReturnLoan_ToPayTaxes", "抵繳稅捐" },
  740. { "ReturnLoan_RefundAmount", "已退款金額" },
  741. { "ReturnLoan_ImportDate", "滙入日期" }
  742. };
  743. dt_new.Columns.Add("Import_CustomsDeclaration_Date");
  744. dt_new.Columns.Add("ReturnLoan_Margin");
  745. dt_new.Columns.Add("ReturnedData_ReturnOrNotItems");
  746. dt_new.Columns.Add("ReturnedData_ReImportDeclarationNO");
  747. dt_new.Columns.Add("ReImport_ReCustomsDeclaration_Date");
  748. dt_new.Columns.Add("ReImport_ReCargoRelease_Date");
  749. dt_new.Columns.Add("ReturnLoan_ToPayTaxes");
  750. dt_new.Columns.Add("ReturnLoan_RefundAmount");
  751. dt_new.Columns.Add("ReturnLoan_ImportDate");
  752. dt_new.Columns.Add("ReturnLoan_VerificationDate");
  753. foreach (DataRow row in dt_new.Rows)
  754. {
  755. var jImport = (JObject)JsonConvert.DeserializeObject(row["Import"].ToString());
  756. var jaReImports = (JArray)JsonConvert.DeserializeObject(row["ReImports"].ToString());
  757. var jReturnLoan = (JObject)JsonConvert.DeserializeObject(row["ReturnLoan"].ToString());
  758. var jTaxInformation = (JObject)JsonConvert.DeserializeObject(row["TaxInformation"].ToString());
  759. if (jImport != null)
  760. {
  761. row["Import_CustomsDeclaration_Date"] = ((JObject)jImport["CustomsDeclaration"])["Date"];
  762. };
  763. if (jaReImports != null)
  764. {
  765. if (jaReImports != null && jaReImports.Count > 0)
  766. {
  767. var sReImport_ReCustomsDeclaration_Date = "";
  768. var sReImport_ReCargoRelease_Date = "";
  769. var sReturnedData_ReturnOrNotItems = "";
  770. var sReturnedData_ReImportDeclarationNO = "";
  771. var builder = new System.Text.StringBuilder();
  772. builder.Append(sReImport_ReCustomsDeclaration_Date);
  773. var builder1 = new System.Text.StringBuilder();
  774. builder1.Append(sReturnedData_ReturnOrNotItems);
  775. var builder2 = new System.Text.StringBuilder();
  776. builder2.Append(sReImport_ReCargoRelease_Date);
  777. var builder3 = new System.Text.StringBuilder();
  778. builder3.Append(sReturnedData_ReImportDeclarationNO);
  779. foreach (JObject jo in jaReImports)
  780. {
  781. var oReImport = (JObject)jo["ReImport"];
  782. var oReImportData = (JObject)jo["ReImportData"];
  783. builder.Append("[" + ((JObject)oReImport["ReCustomsDeclaration"])["Date"] + "] ");
  784. builder2.Append("[" + ((JObject)oReImport["ReCargoRelease"])["Date"] + "] ");
  785. builder1.Append(oReImportData["ReturnOrNotItems"] + " | ");
  786. builder3.Append(oReImportData["ReImportDeclarationNO"] + " | ");
  787. }
  788. sReturnedData_ReImportDeclarationNO = builder3.ToString();
  789. sReImport_ReCargoRelease_Date = builder2.ToString();
  790. sReturnedData_ReturnOrNotItems = builder1.ToString();
  791. sReImport_ReCustomsDeclaration_Date = builder.ToString();
  792. row["ReImport_ReCustomsDeclaration_Date"] = sReImport_ReCustomsDeclaration_Date;
  793. row["ReImport_ReCargoRelease_Date"] = sReImport_ReCargoRelease_Date;
  794. row["ReturnedData_ReturnOrNotItems"] = (sReturnedData_ReturnOrNotItems + "*").Replace("| *", "");
  795. row["ReturnedData_ReImportDeclarationNO"] = (sReturnedData_ReImportDeclarationNO + "*").Replace("| *", "");
  796. }
  797. };
  798. if (jReturnLoan != null)
  799. {
  800. row["ReturnLoan_Margin"] = "$ " + $"{double.Parse((jReturnLoan["Margin"] != null && jReturnLoan["Margin"].ToString() != "") ? jReturnLoan["Margin"].ToString() : "0"):N0}";
  801. row["ReturnLoan_ToPayTaxes"] = "$ " + $"{double.Parse((jReturnLoan["ToPayTaxes"] != null && jReturnLoan["ToPayTaxes"].ToString() != "") ? jReturnLoan["ToPayTaxes"].ToString() : "0"):N0}";
  802. row["ReturnLoan_RefundAmount"] = "$ " + $"{double.Parse((jReturnLoan["RefundAmount"] != null && jReturnLoan["RefundAmount"].ToString() != "") ? jReturnLoan["RefundAmount"].ToString() : "0"):N0}";
  803. row["ReturnLoan_ImportDate"] = jReturnLoan["ImportDate"];
  804. row["ReturnLoan_VerificationDate"] = jReturnLoan["VerificationDate"];
  805. };
  806. }
  807. dicAlain = ExcelService.GetExportAlain(oHeader, "RowIndex", "ReturnLoan_Margin,ReturnLoan_ToPayTaxes,ReturnLoan_RefundAmount");
  808. break;
  809. case "Import_BondedSheet":
  810. sFileName = "保稅工作表";
  811. var Import_BondedSheet_List = new List<Dictionary<string, object>>();
  812. var Import_BondedSheet_Group = new Dictionary<string, object>();
  813. oHeader = new Dictionary<string, string>
  814. {
  815. { "RowIndex", "項次" },
  816. { "TaxInformation_BondedWarehouseCode", "保稅倉庫代碼" },
  817. { "ImportBillName", "中文展名" },
  818. { "ImportBillEName", "英文展名" },
  819. { "SupplierCName", "展商" }
  820. };
  821. Import_BondedSheet_Group.Add("Header", oHeader);
  822. Import_BondedSheet_Group.Add("HeaderName", "基本資料");
  823. Import_BondedSheet_Group.Add("Color", Color.Chocolate);
  824. Import_BondedSheet_List.Add(Import_BondedSheet_Group);
  825. oHeader = new Dictionary<string, string>();
  826. Import_BondedSheet_Group = new Dictionary<string, object>();
  827. oHeader.Add("ImportDeclarationNO", "報單號碼");
  828. oHeader.Add("GoodsType", "貨型");
  829. oHeader.Add("BoxNo", "件數");
  830. oHeader.Add("Unit", "單位");
  831. oHeader.Add("TaxInformation_ReleaseDate", "放行日期");
  832. oHeader.Add("TaxInformation_JincangDate", "進倉日期");
  833. oHeader.Add("TaxInformation_Customs", "海關");
  834. oHeader.Add("TaxInformation_SendCar", "派車");
  835. oHeader.Add("TaxInformation_WarehouseDate", "出倉日期");
  836. oHeader.Add("TaxInformation_WarehouseCustoms", "海關");
  837. oHeader.Add("TaxInformation_CustomsBill", "出倉單");
  838. oHeader.Add("TaxInformation_StorageDate", "回儲日期");
  839. oHeader.Add("TaxInformation_StorageDateCustoms", "海關");
  840. oHeader.Add("TaxInformation_StorageDateBill", "回儲單");
  841. Import_BondedSheet_Group.Add("Header", oHeader);
  842. Import_BondedSheet_Group.Add("HeaderName", "D8");
  843. Import_BondedSheet_Group.Add("Color", Color.Aqua);
  844. Import_BondedSheet_List.Add(Import_BondedSheet_Group);
  845. oHeader = new Dictionary<string, string>();
  846. Import_BondedSheet_Group = new Dictionary<string, object>();
  847. oHeader.Add("TaxInformation_D5OrderNumber", "報單號碼");
  848. oHeader.Add("TaxInformation_D5Number", "件數");
  849. oHeader.Add("TaxInformation_D5Unit", "單位");
  850. oHeader.Add("TaxInformation_D5Customs", "海關");
  851. oHeader.Add("TaxInformation_D5SendCar", "派車");
  852. oHeader.Add("TaxInformation_D5WarehouseDate", "出倉日期");
  853. Import_BondedSheet_Group.Add("Header", oHeader);
  854. Import_BondedSheet_Group.Add("HeaderName", "D5");
  855. Import_BondedSheet_Group.Add("Color", Color.HotPink);
  856. Import_BondedSheet_List.Add(Import_BondedSheet_Group);
  857. oHeader = new Dictionary<string, string>();
  858. Import_BondedSheet_Group = new Dictionary<string, object>();
  859. oHeader.Add("TaxInformation_D2OrderNumber", "報單號碼");
  860. oHeader.Add("TaxInformation_Memo", "備註");
  861. oHeader.Add("TaxInformation_DefImportedItems", "原進口項次");
  862. oHeader.Add("TaxInformation_DeclarationDate", "報關傳輸日期");
  863. oHeader.Add("TaxInformation_CustomsApplicationIn", "申請海關(驗)");
  864. oHeader.Add("TaxInformation_CustomsApplicationOut", "申請海關(出)");
  865. oHeader.Add("TaxInformation_SingleDate", "投單日期");
  866. oHeader.Add("TaxInformation_InspectionDate", "驗貨日期");
  867. oHeader.Add("TaxInformation_TaxDate", "繳稅日期");
  868. oHeader.Add("TaxInformation_D2WarehouseDate", "出倉日期");
  869. Import_BondedSheet_Group.Add("Header", oHeader);
  870. Import_BondedSheet_Group.Add("HeaderName", "D2");
  871. Import_BondedSheet_Group.Add("Color", Color.Yellow);
  872. Import_BondedSheet_List.Add(Import_BondedSheet_Group);
  873. oHeader = new Dictionary<string, string>();
  874. Import_BondedSheet_Group = new Dictionary<string, object>();
  875. dt_new.Columns.Add("TaxInformation_BondedWarehouseCode");
  876. dt_new.Columns.Add("TaxInformation_ReleaseDate");
  877. dt_new.Columns.Add("TaxInformation_JincangDate");
  878. dt_new.Columns.Add("TaxInformation_Customs");
  879. dt_new.Columns.Add("TaxInformation_SendCar");
  880. dt_new.Columns.Add("TaxInformation_WarehouseDate");
  881. dt_new.Columns.Add("TaxInformation_WarehouseCustoms");
  882. dt_new.Columns.Add("TaxInformation_CustomsBill");
  883. dt_new.Columns.Add("TaxInformation_StorageDate");
  884. dt_new.Columns.Add("TaxInformation_StorageDateCustoms");
  885. dt_new.Columns.Add("TaxInformation_StorageDateBill");
  886. dt_new.Columns.Add("TaxInformation_D5OrderNumber");
  887. dt_new.Columns.Add("TaxInformation_D5Number");
  888. dt_new.Columns.Add("TaxInformation_D5Unit");
  889. dt_new.Columns.Add("TaxInformation_D5Customs");
  890. dt_new.Columns.Add("TaxInformation_D5SendCar");
  891. dt_new.Columns.Add("TaxInformation_D5WarehouseDate");
  892. dt_new.Columns.Add("TaxInformation_D2OrderNumber");
  893. dt_new.Columns.Add("TaxInformation_Memo");
  894. dt_new.Columns.Add("TaxInformation_DefImportedItems");
  895. dt_new.Columns.Add("TaxInformation_DeclarationDate");
  896. dt_new.Columns.Add("TaxInformation_CustomsApplicationIn");
  897. dt_new.Columns.Add("TaxInformation_CustomsApplicationOut");
  898. dt_new.Columns.Add("TaxInformation_SingleDate");
  899. dt_new.Columns.Add("TaxInformation_InspectionDate");
  900. dt_new.Columns.Add("TaxInformation_TaxDate");
  901. dt_new.Columns.Add("TaxInformation_D2WarehouseDate");
  902. foreach (DataRow row in dt_new.Rows)
  903. {
  904. var jTaxInformation = (JObject)JsonConvert.DeserializeObject(row["TaxInformation"].ToString());
  905. if (jTaxInformation != null)
  906. {
  907. row["TaxInformation_BondedWarehouseCode"] = jTaxInformation["BondedWarehouseCode"];
  908. row["TaxInformation_ReleaseDate"] = jTaxInformation["ReleaseDate"];
  909. row["TaxInformation_JincangDate"] = jTaxInformation["JincangDate"];
  910. row["TaxInformation_Customs"] = jTaxInformation["Customs"];
  911. row["TaxInformation_SendCar"] = jTaxInformation["SendCar"];
  912. row["TaxInformation_WarehouseDate"] = jTaxInformation["WarehouseDate"];
  913. row["TaxInformation_WarehouseCustoms"] = jTaxInformation["WarehouseCustoms"];
  914. row["TaxInformation_CustomsBill"] = jTaxInformation["CustomsBill"] != null ? "√" : "";
  915. row["TaxInformation_StorageDate"] = jTaxInformation["StorageDate"];
  916. row["TaxInformation_StorageDateCustoms"] = jTaxInformation["StorageDateCustoms"];
  917. row["TaxInformation_StorageDateBill"] = jTaxInformation["StorageDateBill"] != null ? "√" : "";
  918. row["TaxInformation_D5OrderNumber"] = jTaxInformation["D5OrderNumber"];
  919. row["TaxInformation_D5OrderNumber"] = jTaxInformation["D5OrderNumber"];
  920. row["TaxInformation_D5Number"] = jTaxInformation["D5Number"];
  921. row["TaxInformation_D5Unit"] = jTaxInformation["D5Unit"];
  922. row["TaxInformation_D5Customs"] = jTaxInformation["D5Customs"];
  923. row["TaxInformation_D5SendCar"] = jTaxInformation["D5SendCar"];
  924. row["TaxInformation_D5WarehouseDate"] = jTaxInformation["D5WarehouseDate"];
  925. row["TaxInformation_D2OrderNumber"] = jTaxInformation["D2OrderNumber"];
  926. row["TaxInformation_Memo"] = jTaxInformation["Memo"];
  927. row["TaxInformation_DefImportedItems"] = jTaxInformation["DefImportedItems"];
  928. row["TaxInformation_DeclarationDate"] = jTaxInformation["DeclarationDate"];
  929. row["TaxInformation_CustomsApplicationIn"] = jTaxInformation["CustomsApplicationIn"];
  930. row["TaxInformation_CustomsApplicationOut"] = jTaxInformation["CustomsApplicationOut"];
  931. row["TaxInformation_InspectionDate"] = jTaxInformation["InspectionDate"];
  932. row["TaxInformation_TaxDate"] = jTaxInformation["TaxDate"];
  933. row["TaxInformation_D2WarehouseDate"] = jTaxInformation["D2WarehouseDate"];
  934. };
  935. }
  936. oHeader_Last = Import_BondedSheet_List;
  937. break;
  938. case "Import_AdvanceAndRetreatWorkSheet":
  939. sFileName = "進口進退場工作表";
  940. oHeader_Last = new Dictionary<string, string>
  941. {
  942. { "RowIndex", "項次" },
  943. { "ImportBillName", "展覽名稱" },
  944. { "SupplierEName", "參展商英文名稱" },
  945. { "SupplierCName", "參展商中文名稱" },
  946. { "Hall", "館別" },
  947. { "MuseumMumber", "攤位號碼" },
  948. { "SitiContactor", "現場聯絡人" },
  949. { "SitiTelephone", "現場聯絡電話" },
  950. { "BillLadNO", "提單號碼" },
  951. { "BoxNo", "件數" },
  952. { "Unit", "單位" },
  953. { "Weight", "毛重(G.W.)" },
  954. { "Volume", "材積(CBM)" },
  955. { "VolumeWeight", "材積重(C.W.)" },
  956. { "_ApproachTime", "進場時間" },
  957. { "_ExitTime", "退場時間" }
  958. };
  959. var list_Halls3 = db.Queryable<OTB_SYS_Arguments>()
  960. .Where(it => it.OrgID == i_crm.ORIGID && it.ArgumentClassID == "Hall").ToList();
  961. var mHall = new Map();
  962. foreach (OTB_SYS_Arguments arg in list_Halls3)
  963. {
  964. mHall.Put(arg.ArgumentID, arg.ArgumentValue);
  965. }
  966. var dt = saBasicInformation.ListToDataTable<View_OPM_ImportExhibition>();
  967. dt.Clear();
  968. var iRowIndex = 1;
  969. foreach (DataRow row in dt_new.Rows)
  970. {
  971. if (row["SupplierType"].ToString() == "S")
  972. {
  973. var row_new = dt.NewRow();
  974. row_new["RowIndex"] = iRowIndex;
  975. row_new["ImportBillName"] = row["ImportBillName"];
  976. row_new["SupplierEName"] = row["SupplierEName"];
  977. row_new["SupplierCName"] = row["SupplierCName"];
  978. row_new["Hall"] = mHall[row["Hall"].ToString()] ?? "";
  979. row_new["MuseumMumber"] = row["MuseumMumber"];
  980. row_new["SitiContactor"] = row["SitiContactor"];
  981. row_new["SitiTelephone"] = row["SitiTelephone"];
  982. row_new["BillLadNO"] = row["BillLadNO"];
  983. row_new["BoxNo"] = row["BoxNo"];
  984. row_new["Unit"] = row["Unit"];
  985. row_new["Weight"] = row["Weight"];
  986. row_new["Volume"] = row["Volume"];
  987. row_new["VolumeWeight"] = row["VolumeWeight"];
  988. row_new["_ApproachTime"] = row["_ApproachTime"];
  989. row_new["_ExitTime"] = row["_ExitTime"];
  990. dt.Rows.Add(row_new);
  991. iRowIndex++;
  992. }
  993. else
  994. {
  995. var jaSuppliers = (JArray)JsonConvert.DeserializeObject(row["Suppliers"].ToString());
  996. foreach (JObject jo in jaSuppliers)
  997. {
  998. var row_new = dt.NewRow();
  999. row_new["RowIndex"] = iRowIndex;
  1000. row_new["ImportBillName"] = row["ImportBillName"];
  1001. row_new["SupplierEName"] = jo["SupplierEName"];
  1002. row_new["SupplierCName"] = jo["SupplierName"];
  1003. row_new["Hall"] = mHall[jo["Hall"].ToString()] ?? "";
  1004. row_new["MuseumMumber"] = jo["MuseumMumber"];
  1005. row_new["SitiContactor"] = jo["ContactorName"];
  1006. row_new["SitiTelephone"] = jo["Telephone"];
  1007. row_new["BillLadNO"] = row["BillLadNO"];
  1008. row_new["BoxNo"] = jo["BoxNo"];
  1009. row_new["Unit"] = jo["Unit"];
  1010. row_new["Weight"] = jo["Weight"];
  1011. row_new["Volume"] = jo["Volume"];
  1012. row_new["VolumeWeight"] = jo["VolumeWeight"];
  1013. row_new["_ApproachTime"] = jo["ApproachTime"];
  1014. row_new["_ExitTime"] = jo["ExitTime"];
  1015. dt.Rows.Add(row_new);
  1016. iRowIndex++;
  1017. }
  1018. }
  1019. }
  1020. dt_new = dt;
  1021. break;
  1022. default:
  1023. {
  1024. break;
  1025. }
  1026. }
  1027. var bOk = new ExcelService().CreateExcelByTb(dt_new, out string sPath, oHeader_Last, dicAlain, listMerge, sFileName);
  1028. rm.DATA.Add(BLWording.REL, sPath);
  1029. }
  1030. else
  1031. {
  1032. rm.DATA.Add(BLWording.REL, pml);
  1033. }
  1034. } while (false);
  1035. }
  1036. catch (Exception ex)
  1037. {
  1038. sMsg = Util.GetLastExceptionMsg(ex);
  1039. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.OPM.ExhibitionImport_QryService", "", "GetExcel(進口匯出)", "", "", "");
  1040. }
  1041. finally
  1042. {
  1043. if (null != sMsg)
  1044. {
  1045. rm = new ErrorResponseMessage(sMsg, i_crm);
  1046. }
  1047. }
  1048. return rm;
  1049. }
  1050. #endregion 進口分頁查詢
  1051. #region 進口單筆查詢
  1052. /// <summary>
  1053. /// 進口單筆查詢
  1054. /// </summary>
  1055. /// <param name="i_crm"></param>
  1056. /// <returns></returns>
  1057. public ResponseMessage QueryOne(RequestMessage i_crm)
  1058. {
  1059. ResponseMessage rm = null;
  1060. string sMsg = null;
  1061. var db = SugarBase.GetIntance();
  1062. try
  1063. {
  1064. do
  1065. {
  1066. var sId = _fetchString(i_crm, @"Guid");
  1067. var oImportExhibition = db.Queryable<OTB_OPM_ImportExhibition, OTB_OPM_Exhibition, OTB_CRM_Customers, OTB_CRM_Customers>
  1068. ((t1, t2, t3, t4) =>
  1069. new object[] {
  1070. JoinType.Inner, t1.OrgID == t2.OrgID && t1.ExhibitionNO == t2.SN.ToString(),
  1071. JoinType.Left, t1.OrgID == t3.OrgID && t1.Supplier == t3.guid,
  1072. JoinType.Left, t1.OrgID == t4.OrgID && t1.Agent == t4.guid
  1073. }
  1074. )
  1075. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID && t1.ImportBillNO == sId)
  1076. .Select((t1, t2, t3, t4) => new View_OPM_ImportExhibition
  1077. {
  1078. ImportBillNO = SqlFunc.GetSelfAndAutoFill(t1.ImportBillNO),
  1079. Exhibitioname_TW = t2.Exhibitioname_TW,
  1080. Exhibitioname_EN = t2.Exhibitioname_EN,
  1081. SupplierCName = SqlFunc.IIF(SqlFunc.HasValue(t3.CustomerCName), t3.CustomerCName, t3.CustomerEName),
  1082. AgentName = SqlFunc.IIF(SqlFunc.HasValue(t4.CustomerCName), t4.CustomerCName, t4.CustomerEName)
  1083. }).Single();
  1084. rm = new SuccessResponseMessage(null, i_crm);
  1085. rm.DATA.Add(BLWording.REL, oImportExhibition);
  1086. } while (false);
  1087. }
  1088. catch (Exception ex)
  1089. {
  1090. sMsg = Util.GetLastExceptionMsg(ex);
  1091. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.OPM.ExhibitionImport_QryService", "", "QueryOne(進口單筆查詢)", "", "", "");
  1092. }
  1093. finally
  1094. {
  1095. if (null != sMsg)
  1096. {
  1097. rm = new ErrorResponseMessage(sMsg, i_crm);
  1098. }
  1099. }
  1100. return rm;
  1101. }
  1102. #endregion 進口單筆查詢
  1103. }
  1104. }