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.

2133 lines
150 KiB

2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using EasyBL.WebApi.Message;
  5. using Entity.Sugar;
  6. using SqlSugar;
  7. using SqlSugar.Base;
  8. using Newtonsoft.Json.Linq;
  9. using EasyBL;
  10. using System.Text.RegularExpressions;
  11. namespace TestAP.Helper
  12. {
  13. public class ConvertData
  14. {
  15. public Dictionary<string, int> dicSucceccCount = new Dictionary<string, int>();
  16. public string StartDate { get; set; } = string.Empty;
  17. public string EndDate { get; set; } = string.Empty;
  18. //出口帳款
  19. public bool ExcExport { get; set; } = false;
  20. //退運出口帳款
  21. public bool ExcExportReturn { get; set; } = false;
  22. //進口帳款
  23. public bool ExcImport { get; set; } = false;
  24. //退運進口帳款
  25. public bool ExcImportReturn { get; set; } = false;
  26. //其他帳款
  27. public bool ExcOther { get; set; } = false;
  28. //退運其他帳款
  29. //其他(駒驛)帳款
  30. public bool ExcOtherTG { get; set; } = false;
  31. //退運其他(駒驛)帳款
  32. //展覽
  33. public bool ExcExhibtion { get; set; } = false;
  34. //客戶
  35. public bool ExcCustomer { get; set; } = false;
  36. //特定帳款號碼
  37. public List<string> BillsNo { get; set; } = new List<string>();
  38. //特定專案號碼
  39. public List<string> ExhibtionsNo { get; set; } = new List<string>();
  40. //特定客戶號碼
  41. public List<string> CustomersNo { get; set; } = new List<string>();
  42. public Dictionary<string, int> StartConvert(out string o_sMsg)
  43. {
  44. string sMsg = null;
  45. o_sMsg = null;
  46. ResponseMessage rm = null;
  47. try
  48. {
  49. rm = SugarBase.ExecTran(db =>
  50. {
  51. do
  52. {
  53. if (string.IsNullOrEmpty(StartDate))
  54. {
  55. sMsg = "請設定StartDate";
  56. break;
  57. }
  58. if (string.IsNullOrEmpty(EndDate))
  59. {
  60. sMsg = "請設定EndDate";
  61. break;
  62. }
  63. Console.WriteLine("轉換進口資料開始...");
  64. sMsg = Import(StartDate, EndDate, db);
  65. if (sMsg != null)
  66. {
  67. break;
  68. }
  69. Console.WriteLine("轉換進口資料結束...");
  70. Console.WriteLine("轉換出口資料開始...");
  71. sMsg = Export(StartDate, EndDate, db);
  72. if (sMsg != null)
  73. {
  74. break;
  75. }
  76. Console.WriteLine("轉換出口資料結束...");
  77. Console.WriteLine("轉換其他資料開始...");
  78. sMsg = Other(StartDate, EndDate, db);
  79. if (sMsg != null)
  80. {
  81. break;
  82. }
  83. Console.WriteLine("轉換其他資料結束...");
  84. Console.WriteLine("轉換其他(駒驛)資料開始...");
  85. sMsg = OtherTG(StartDate, EndDate, db);
  86. if (sMsg != null)
  87. {
  88. break;
  89. }
  90. Console.WriteLine("轉換其他(駒驛)資料結束...");
  91. Console.WriteLine("轉換專案(展覽)資料開始...");
  92. sMsg = Exhibition(StartDate, EndDate, db);
  93. if (sMsg != null)
  94. {
  95. break;
  96. }
  97. Console.WriteLine("轉換專案(展覽)資料結束...");
  98. Console.WriteLine("轉換客戶資料開始...");
  99. sMsg = Customer(StartDate, EndDate, db);
  100. if (sMsg != null)
  101. {
  102. break;
  103. }
  104. Console.WriteLine("轉換客戶資料結束...");
  105. } while (false);
  106. if (sMsg != null)
  107. {
  108. db.Ado.RollbackTran();
  109. }
  110. return rm;
  111. }
  112. );
  113. }
  114. catch (Exception ex)
  115. {
  116. sMsg = ex.Message;
  117. }
  118. if (sMsg != null)
  119. {
  120. o_sMsg = sMsg;
  121. }
  122. return dicSucceccCount;
  123. }
  124. public string Import(string sStartDate, string sEndDate, SqlSugarClient db)
  125. {
  126. string sMsg = null;
  127. DateTime dtSettingStartDate = Convert.ToDateTime(sStartDate);
  128. DateTime dtSettingEnd = Convert.ToDateTime(sEndDate);
  129. #region 進口
  130. var data1 = db.Queryable<OTB_OPM_ImportExhibition>()
  131. .Where(x => x.ModifyDate <= SqlFunc.ToDate(sEndDate) && x.ModifyDate >= SqlFunc.ToDate(sStartDate))
  132. .ToList();
  133. foreach (OTB_OPM_ImportExhibition import in data1)
  134. {
  135. if (ExcImport || BillsNo.Any())
  136. {
  137. //解析bill
  138. if (!string.IsNullOrEmpty(import.Bills))
  139. {
  140. JArray ja = JArray.Parse(import.Bills);
  141. if (ja.Count > 0)
  142. {
  143. var sdb = new SimpleClient<OTB_OPM_ImportExhibition>(db);
  144. var oOpm = sdb.GetById(import.ImportBillNO);
  145. if (oOpm == null)
  146. {
  147. sMsg = $"進口單號:{ import.ImportBillNO } => 系統找不到對應的基本資料,請核查!";
  148. break;
  149. }
  150. foreach (JObject jo in ja.OfType<JObject>())
  151. {
  152. string sBillNo = GetObjectValue(jo, "BillNO");
  153. string sAuditVal = GetObjectValue(jo, "AuditVal");
  154. string sBillCheckDate = GetObjectValue(jo, "BillCheckDate");
  155. string sPayer = GetObjectValue(jo, "Payer");
  156. string sUrl = @"ExhibitionImport_Upd|?Action=Upd&GoTab=3&ImportBillNO=" + oOpm.ImportBillNO + @"&BillNO=" + sBillNo;
  157. if (BillsNo.Any() && !BillsNo.Contains(sBillNo))
  158. {
  159. continue;
  160. }
  161. DateTime dtCreateDate;
  162. if (DateTime.TryParse(sBillCheckDate, out dtCreateDate))
  163. {
  164. if (dtCreateDate <= dtSettingEnd && dtCreateDate >= dtSettingStartDate)
  165. {
  166. var oPayer = new OTB_CRM_Customers();
  167. if (!string.IsNullOrEmpty(sPayer))
  168. {
  169. oPayer = db.Queryable<OTB_CRM_Customers>().Single(it => it.guid == sPayer);
  170. if (oPayer == null)
  171. {
  172. sMsg = $"進口單號:{ import.ImportBillNO } => 系統找不到付款人資訊";
  173. break;
  174. }
  175. }
  176. //狀態4(已銷帳)/6(已作廢)當成已審核拋轉
  177. if (sAuditVal == "2" || sAuditVal == "4" || sAuditVal == "6")
  178. {
  179. #region 審核
  180. var oBillsAdd = new OTB_OPM_Bills
  181. {
  182. OrgID = import.OrgID,
  183. BillNO = sBillNo, //帳款號碼(1)
  184. CheckDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")),//對帳日期(2)
  185. BillType = @"20",//帳別(收付)(3)
  186. CustomerCode = oPayer.CustomerNO //客戶供應商代號(4)
  187. };
  188. var sResponsiblePerson = oOpm.ResponsiblePerson.Split('.')[0];
  189. oBillsAdd.ResponsiblePersonCode = Common.CutByteString(sResponsiblePerson, 11); //業務員代號(5)
  190. oBillsAdd.ResponsiblePersonFullCode = oOpm.ResponsiblePerson; //業務員全代號
  191. oBillsAdd.LastGetBillDate = @""; //最近收付日(6)
  192. oBillsAdd.LastGetBillNO = @""; //最近收付單號(7)
  193. oBillsAdd.TaxType = decimal.Parse(GetObjectValue(jo, "TaxSum").Replace(@",", @"")) > 0 ? @"5" : @"6";//稅別(8)
  194. oBillsAdd.NOTaxAmount = GetObjectValue(jo, "AmountSum"); //未稅金額(9)
  195. oBillsAdd.BillAmount = GetObjectValue(jo, "AmountTaxSum"); //帳款金額(10)
  196. oBillsAdd.PaymentAmount = @"0"; //收付金額(11)
  197. oBillsAdd.Allowance = @"0"; //折讓金額(12)
  198. oBillsAdd.DebtAmount = @"0"; //呆帳金額(13)
  199. oBillsAdd.ExchangeAmount = @"0"; //匯兌損益金額(14)
  200. oBillsAdd.Settle = @"N"; //結清否(15)
  201. oBillsAdd.InvoiceStartNumber = @""; //發票號碼(起)(16)
  202. oBillsAdd.InvoiceEndNumber = @"";//發票號碼(迄)(17)
  203. oBillsAdd.Category = @"";//傳票類別(18)
  204. oBillsAdd.OrderNo = @"";//訂單單號(19)
  205. oBillsAdd.ClosingNote = @"N"; //結帳註記(20)
  206. oBillsAdd.GeneralInvoiceNumber = @""; //立帳總帳傳票號碼(21)
  207. oBillsAdd.GeneralSerialNumber = @""; //立帳總帳傳票序號(22)
  208. oBillsAdd.Remark1 = @""; //備註一(30C)(23)
  209. oBillsAdd.AccountSource = @"0"; //帳款來源(24)
  210. oBillsAdd.UpdateDate = @""; //更新日期(25)
  211. oBillsAdd.UpdatePersonnel = @""; //更新人員(26)
  212. oBillsAdd.DepartmentSiteNumber = oOpm.DepartmentID; //部門\ 工地編號(27)
  213. if (!string.IsNullOrWhiteSpace(oOpm.ExhibitionNO))
  214. {
  215. var oExhibition = db.Queryable<OTB_OPM_Exhibition>().Single(it => it.SN == oOpm.ExhibitionNO.ObjToInt());
  216. oBillsAdd.ProjectNumber = oExhibition == null ? @"" : oExhibition.ExhibitionCode; //專案\ 項目編號(28)
  217. }
  218. else
  219. {
  220. oBillsAdd.ProjectNumber = @""; //專案\ 項目編號(28)
  221. }
  222. oBillsAdd.TransferBNotes = @""; //轉B 帳註記(29)
  223. oBillsAdd.ABNumber = @""; //A|B 帳唯一流水號(30)
  224. oBillsAdd.EnterNumber = @""; //進銷單號(31)
  225. var sCurrency = GetObjectValue(jo, "Currency");
  226. if (import.OrgID == "SG")
  227. {
  228. if (sCurrency == "RMB")
  229. {
  230. sCurrency = "";
  231. }
  232. }
  233. else
  234. {
  235. if (sCurrency == "NTD")
  236. {
  237. sCurrency = "";
  238. }
  239. }
  240. oBillsAdd.ForeignCurrencyCode = sCurrency; //外幣代號(32)
  241. var sExchangeRate = GetObjectValue(jo, "ExchangeRate");
  242. oBillsAdd.ExchangeRate = sExchangeRate; //匯率(33)
  243. oBillsAdd.ForeignAmount = (decimal.Parse(GetObjectValue(jo, "AmountTaxSum")) * decimal.Parse(sExchangeRate == @"" ? @"1" : sExchangeRate)).ToString(); //外幣金額(34)
  244. oBillsAdd.PayAmount = @"0"; //收付沖抵金額(35)
  245. oBillsAdd.RefundAmount = @"0"; //退款金額(36)
  246. oBillsAdd.PaymentTerms = @""; //收付條件(37)
  247. oBillsAdd.AccountDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")); //帳款日期(38)
  248. oBillsAdd.DCreditCardNumber = @""; //預設信用卡號(39)
  249. oBillsAdd.ClosingDate = @""; //結帳日期(40)
  250. oBillsAdd.CusField1 = @""; //自定義欄位一(41)
  251. oBillsAdd.CusField2 = @""; //自定義欄位二(42)
  252. oBillsAdd.CusField3 = @""; //自定義欄位三(43)
  253. oBillsAdd.CusField4 = @""; //自定義欄位四(44)
  254. oBillsAdd.CusField5 = @""; //自定義欄位五(45)
  255. oBillsAdd.CusField6 = @"0"; //自定義欄位六(46)
  256. oBillsAdd.CusField7 = @"0"; //自定義欄位七(47)
  257. oBillsAdd.CusField8 = @"0"; //自定義欄位八(48)
  258. oBillsAdd.CusField9 = @"0"; //自定義欄位九(49)
  259. oBillsAdd.CusField10 = @"0"; //自定義欄位十(50)
  260. oBillsAdd.CusField11 = @""; //自定義欄位十一(51)
  261. oBillsAdd.CusField12 = @""; //自定義欄位十二(52)
  262. oBillsAdd.Remark2 = @""; //備註二(M)(53)
  263. oBillsAdd.TWNOTaxAmount = GetObjectValue(jo, "AmountSum"); //台幣未稅金額(54)
  264. oBillsAdd.TWAmount = GetObjectValue(jo, "AmountTaxSum"); //台幣帳款金額(55)
  265. oBillsAdd.CreateUser = import.ModifyUser;
  266. oBillsAdd.CreateDate = ((DateTime)import.ModifyDate).ToString(@"yyyy/MM/dd HH:mm:ss");
  267. oBillsAdd.BillFirstCheckDate = string.IsNullOrEmpty(GetObjectValue(jo, "BillFirstCheckDate")) ? DateTime.Now.ToString(@"yyyy/MM/dd HH:mm:ss") : GetObjectValue(jo, "BillFirstCheckDate");
  268. oBillsAdd.Advance = GetObjectValue(jo, "Advance"); //預收
  269. oBillsAdd.TaxSum = GetObjectValue(jo, "TaxSum"); //稅額
  270. oBillsAdd.TotalReceivable = GetObjectValue(jo, "TotalReceivable"); //總應收
  271. oBillsAdd.IsRetn = string.IsNullOrEmpty(GetObjectValue(jo, "IsRetn")) ? @"N" : GetObjectValue(jo, "IsRetn"); //是否為退運
  272. oBillsAdd.Url = sUrl; //Url
  273. db.Insertable(oBillsAdd).ExecuteCommand();
  274. if (dicSucceccCount.Keys.Contains("進口審核"))
  275. {
  276. dicSucceccCount["進口審核"] = dicSucceccCount["進口審核"] + 1;
  277. }
  278. else
  279. {
  280. dicSucceccCount.Add("進口審核", 1);
  281. }
  282. #endregion
  283. }
  284. else if (sAuditVal == "5")
  285. {
  286. #region 過帳
  287. var oBillsAdd = new OTB_OPM_Bills
  288. {
  289. OrgID = import.OrgID,
  290. BillNO = sBillNo, //帳款號碼(1)
  291. CheckDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")),//對帳日期(2)
  292. BillType = @"20",//帳別(收付)(3)
  293. CustomerCode = oPayer.CustomerNO //客戶供應商代號(4)
  294. };
  295. var sResponsiblePerson = oOpm.ResponsiblePerson.Split('.')[0];
  296. oBillsAdd.ResponsiblePersonCode = Common.CutByteString(sResponsiblePerson, 11); //業務員代號(5)
  297. oBillsAdd.ResponsiblePersonFullCode = oOpm.ResponsiblePerson; //業務員全代號
  298. oBillsAdd.LastGetBillDate = @""; //最近收付日(6)
  299. oBillsAdd.LastGetBillNO = @""; //最近收付單號(7)
  300. oBillsAdd.TaxType = decimal.Parse(GetObjectValue(jo, "TaxSum").Replace(@",", @"")) > 0 ? @"5" : @"6";//稅別(8)
  301. oBillsAdd.NOTaxAmount = GetObjectValue(jo, "AmountSum"); //未稅金額(9)
  302. oBillsAdd.BillAmount = GetObjectValue(jo, "AmountTaxSum"); //帳款金額(10)
  303. oBillsAdd.PaymentAmount = @"0"; //收付金額(11)
  304. oBillsAdd.Allowance = @"0"; //折讓金額(12)
  305. oBillsAdd.DebtAmount = @"0"; //呆帳金額(13)
  306. oBillsAdd.ExchangeAmount = @"0"; //匯兌損益金額(14)
  307. oBillsAdd.Settle = @"N"; //結清否(15)
  308. oBillsAdd.InvoiceStartNumber = GetObjectValue(jo, "InvoiceNumber"); //發票號碼(起)(16)
  309. oBillsAdd.InvoiceEndNumber = GetObjectValue(jo, "InvoiceNumber");//發票號碼(迄)(17)
  310. oBillsAdd.Category = @"";//傳票類別(18)
  311. oBillsAdd.OrderNo = @"";//訂單單號(19)
  312. oBillsAdd.ClosingNote = @"N"; //結帳註記(20)
  313. oBillsAdd.GeneralInvoiceNumber = @""; //立帳總帳傳票號碼(21)
  314. oBillsAdd.GeneralSerialNumber = @""; //立帳總帳傳票序號(22)
  315. oBillsAdd.Remark1 = @""; //備註一(30C)(23)
  316. oBillsAdd.AccountSource = @"0"; //帳款來源(24)
  317. oBillsAdd.UpdateDate = @""; //更新日期(25)
  318. oBillsAdd.UpdatePersonnel = @""; //更新人員(26)
  319. oBillsAdd.DepartmentSiteNumber = oOpm.DepartmentID; //部門\ 工地編號(27)
  320. if (!string.IsNullOrWhiteSpace(oOpm.ExhibitionNO))
  321. {
  322. var oExhibition = db.Queryable<OTB_OPM_Exhibition>().Single(it => it.SN == oOpm.ExhibitionNO.ObjToInt());
  323. oBillsAdd.ProjectNumber = oExhibition == null ? @"" : oExhibition.ExhibitionCode; //專案\ 項目編號(28)
  324. }
  325. else
  326. {
  327. oBillsAdd.ProjectNumber = @""; //專案\ 項目編號(28)
  328. }
  329. oBillsAdd.TransferBNotes = @""; //轉B 帳註記(29)
  330. oBillsAdd.ABNumber = @""; //A|B 帳唯一流水號(30)
  331. oBillsAdd.EnterNumber = @""; //進銷單號(31)
  332. var sCurrency = GetObjectValue(jo, "Currency");
  333. if (import.OrgID == "SG")
  334. {
  335. if (sCurrency == "RMB")
  336. {
  337. sCurrency = "";
  338. }
  339. }
  340. else
  341. {
  342. if (sCurrency == "NTD")
  343. {
  344. sCurrency = "";
  345. }
  346. }
  347. oBillsAdd.ForeignCurrencyCode = sCurrency; //外幣代號(32)
  348. var sExchangeRate = GetObjectValue(jo, "ExchangeRate");
  349. oBillsAdd.ExchangeRate = sExchangeRate; //匯率(33)
  350. oBillsAdd.ForeignAmount = (decimal.Parse(GetObjectValue(jo, "AmountTaxSum")) * decimal.Parse(sExchangeRate == @"" ? @"1" : sExchangeRate)).ToString(); //外幣金額(34)
  351. oBillsAdd.PayAmount = @"0"; //收付沖抵金額(35)
  352. oBillsAdd.RefundAmount = @"0"; //退款金額(36)
  353. oBillsAdd.PaymentTerms = @""; //收付條件(37)
  354. oBillsAdd.AccountDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")); //帳款日期(38)
  355. oBillsAdd.DCreditCardNumber = @""; //預設信用卡號(39)
  356. oBillsAdd.ClosingDate = @""; //結帳日期(40)
  357. oBillsAdd.CusField1 = @""; //自定義欄位一(41)
  358. oBillsAdd.CusField2 = @""; //自定義欄位二(42)
  359. oBillsAdd.CusField3 = @""; //自定義欄位三(43)
  360. oBillsAdd.CusField4 = @""; //自定義欄位四(44)
  361. oBillsAdd.CusField5 = @""; //自定義欄位五(45)
  362. oBillsAdd.CusField6 = @"0"; //自定義欄位六(46)
  363. oBillsAdd.CusField7 = @"0"; //自定義欄位七(47)
  364. oBillsAdd.CusField8 = @"0"; //自定義欄位八(48)
  365. oBillsAdd.CusField9 = @"0"; //自定義欄位九(49)
  366. oBillsAdd.CusField10 = @"0"; //自定義欄位十(50)
  367. oBillsAdd.CusField11 = @""; //自定義欄位十一(51)
  368. oBillsAdd.CusField12 = @""; //自定義欄位十二(52)
  369. oBillsAdd.Remark2 = @""; //備註二(M)(53)
  370. oBillsAdd.TWNOTaxAmount = GetObjectValue(jo, "AmountSum"); //台幣未稅金額(54)
  371. oBillsAdd.TWAmount = GetObjectValue(jo, "AmountTaxSum"); //台幣帳款金額(55)
  372. oBillsAdd.CreateUser = import.ModifyUser;
  373. oBillsAdd.CreateDate = ((DateTime)import.ModifyDate).ToString(@"yyyy/MM/dd HH:mm:ss");
  374. oBillsAdd.BillFirstCheckDate = string.IsNullOrEmpty(GetObjectValue(jo, "BillFirstCheckDate")) ? DateTime.Now.ToString(@"yyyy/MM/dd HH:mm:ss") : GetObjectValue(jo, "BillFirstCheckDate");
  375. oBillsAdd.Advance = GetObjectValue(jo, "Advance"); //預收
  376. oBillsAdd.TaxSum = GetObjectValue(jo, "TaxSum"); //稅額
  377. oBillsAdd.TotalReceivable = GetObjectValue(jo, "TotalReceivable"); //總應收
  378. oBillsAdd.IsRetn = string.IsNullOrEmpty(GetObjectValue(jo, "IsRetn")) ? @"N" : GetObjectValue(jo, "IsRetn"); //是否為退運
  379. oBillsAdd.Url = sUrl; //Url
  380. db.Insertable(oBillsAdd).ExecuteCommand();
  381. if (dicSucceccCount.Keys.Contains("進口過帳"))
  382. {
  383. dicSucceccCount["進口過帳"] = dicSucceccCount["進口過帳"] + 1;
  384. }
  385. else
  386. {
  387. dicSucceccCount.Add("進口過帳", 1);
  388. }
  389. #endregion
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. }
  397. if (ExcImportReturn || BillsNo.Any())
  398. {
  399. //解析ReturnBill
  400. JArray ja = JArray.Parse(import.ReturnBills);
  401. if (ja.Count > 0)
  402. {
  403. var sdb = new SimpleClient<OTB_OPM_ImportExhibition>(db);
  404. var oOpm = sdb.GetById(import.ImportBillNO);
  405. if (oOpm == null)
  406. {
  407. sMsg = $"退運進口單號:{ import.ImportBillNO } => 系統找不到對應的基本資料,請核查!";
  408. break;
  409. }
  410. foreach (JObject joH in ja.OfType<JObject>())
  411. {
  412. JArray ja1 = JArray.Parse(GetObjectValue(joH, "Bills"));
  413. if (ja1.Count > 0)
  414. {
  415. foreach (JObject jo in ja1.OfType<JObject>())
  416. {
  417. string sBillNo = GetObjectValue(jo, "BillNO");
  418. string sAuditVal = GetObjectValue(jo, "AuditVal");
  419. string sBillCheckDate = GetObjectValue(jo, "BillCheckDate");
  420. string sPayer = GetObjectValue(jo, "Payer");
  421. string sUrl = @"ExhibitionImport_Upd|?Action=Upd&GoTab=5&ImportBillNO=" + oOpm.ImportBillNO + @"&BillNO=" + sBillNo;
  422. if (BillsNo.Any() && !BillsNo.Contains(sBillNo))
  423. {
  424. continue;
  425. }
  426. DateTime dtCreateDate;
  427. if (DateTime.TryParse(sBillCheckDate, out dtCreateDate))
  428. {
  429. if (dtCreateDate <= dtSettingEnd && dtCreateDate >= dtSettingStartDate)
  430. {
  431. var oPayer = new OTB_CRM_Customers();
  432. if (!string.IsNullOrEmpty(sPayer))
  433. {
  434. oPayer = db.Queryable<OTB_CRM_Customers>().Single(it => it.guid == sPayer);
  435. if (oPayer == null)
  436. {
  437. sMsg = $"退運進口單號:{ import.ImportBillNO } => 系統找不到付款人資訊";
  438. break;
  439. }
  440. }
  441. //狀態4(已銷帳)/6(已作廢)當成已審核拋轉
  442. if (sAuditVal == "2" || sAuditVal == "4" || sAuditVal == "6")
  443. {
  444. #region 審核
  445. var oBillsAdd = new OTB_OPM_Bills
  446. {
  447. OrgID = import.OrgID,
  448. BillNO = sBillNo, //帳款號碼(1)
  449. CheckDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")),//對帳日期(2)
  450. BillType = @"20",//帳別(收付)(3)
  451. CustomerCode = oPayer.CustomerNO //客戶供應商代號(4)
  452. };
  453. var sResponsiblePerson = oOpm.ResponsiblePerson.Split('.')[0];
  454. oBillsAdd.ResponsiblePersonCode = Common.CutByteString(sResponsiblePerson, 11); //業務員代號(5)
  455. oBillsAdd.ResponsiblePersonFullCode = oOpm.ResponsiblePerson; //業務員全代號
  456. oBillsAdd.LastGetBillDate = @""; //最近收付日(6)
  457. oBillsAdd.LastGetBillNO = @""; //最近收付單號(7)
  458. oBillsAdd.TaxType = decimal.Parse(GetObjectValue(jo, "TaxSum").Replace(@",", @"")) > 0 ? @"5" : @"6";//稅別(8)
  459. oBillsAdd.NOTaxAmount = GetObjectValue(jo, "AmountSum"); //未稅金額(9)
  460. oBillsAdd.BillAmount = GetObjectValue(jo, "AmountTaxSum"); //帳款金額(10)
  461. oBillsAdd.PaymentAmount = @"0"; //收付金額(11)
  462. oBillsAdd.Allowance = @"0"; //折讓金額(12)
  463. oBillsAdd.DebtAmount = @"0"; //呆帳金額(13)
  464. oBillsAdd.ExchangeAmount = @"0"; //匯兌損益金額(14)
  465. oBillsAdd.Settle = @"N"; //結清否(15)
  466. oBillsAdd.InvoiceStartNumber = @""; //發票號碼(起)(16)
  467. oBillsAdd.InvoiceEndNumber = @"";//發票號碼(迄)(17)
  468. oBillsAdd.Category = @"";//傳票類別(18)
  469. oBillsAdd.OrderNo = @"";//訂單單號(19)
  470. oBillsAdd.ClosingNote = @"N"; //結帳註記(20)
  471. oBillsAdd.GeneralInvoiceNumber = @""; //立帳總帳傳票號碼(21)
  472. oBillsAdd.GeneralSerialNumber = @""; //立帳總帳傳票序號(22)
  473. oBillsAdd.Remark1 = @""; //備註一(30C)(23)
  474. oBillsAdd.AccountSource = @"0"; //帳款來源(24)
  475. oBillsAdd.UpdateDate = @""; //更新日期(25)
  476. oBillsAdd.UpdatePersonnel = @""; //更新人員(26)
  477. oBillsAdd.DepartmentSiteNumber = oOpm.DepartmentID; //部門\ 工地編號(27)
  478. if (!string.IsNullOrWhiteSpace(oOpm.ExhibitionNO))
  479. {
  480. var oExhibition = db.Queryable<OTB_OPM_Exhibition>().Single(it => it.SN == oOpm.ExhibitionNO.ObjToInt());
  481. oBillsAdd.ProjectNumber = oExhibition == null ? @"" : oExhibition.ExhibitionCode; //專案\ 項目編號(28)
  482. }
  483. else
  484. {
  485. oBillsAdd.ProjectNumber = @""; //專案\ 項目編號(28)
  486. }
  487. oBillsAdd.TransferBNotes = @""; //轉B 帳註記(29)
  488. oBillsAdd.ABNumber = @""; //A|B 帳唯一流水號(30)
  489. oBillsAdd.EnterNumber = @""; //進銷單號(31)
  490. var sCurrency = GetObjectValue(jo, "Currency");
  491. if (import.OrgID == "SG")
  492. {
  493. if (sCurrency == "RMB")
  494. {
  495. sCurrency = "";
  496. }
  497. }
  498. else
  499. {
  500. if (sCurrency == "NTD")
  501. {
  502. sCurrency = "";
  503. }
  504. }
  505. oBillsAdd.ForeignCurrencyCode = sCurrency; //外幣代號(32)
  506. var sExchangeRate = GetObjectValue(jo, "ExchangeRate");
  507. oBillsAdd.ExchangeRate = sExchangeRate; //匯率(33)
  508. oBillsAdd.ForeignAmount = (decimal.Parse(GetObjectValue(jo, "AmountTaxSum")) * decimal.Parse(sExchangeRate == @"" ? @"1" : sExchangeRate)).ToString(); //外幣金額(34)
  509. oBillsAdd.PayAmount = @"0"; //收付沖抵金額(35)
  510. oBillsAdd.RefundAmount = @"0"; //退款金額(36)
  511. oBillsAdd.PaymentTerms = @""; //收付條件(37)
  512. oBillsAdd.AccountDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")); //帳款日期(38)
  513. oBillsAdd.DCreditCardNumber = @""; //預設信用卡號(39)
  514. oBillsAdd.ClosingDate = @""; //結帳日期(40)
  515. oBillsAdd.CusField1 = @""; //自定義欄位一(41)
  516. oBillsAdd.CusField2 = @""; //自定義欄位二(42)
  517. oBillsAdd.CusField3 = @""; //自定義欄位三(43)
  518. oBillsAdd.CusField4 = @""; //自定義欄位四(44)
  519. oBillsAdd.CusField5 = @""; //自定義欄位五(45)
  520. oBillsAdd.CusField6 = @"0"; //自定義欄位六(46)
  521. oBillsAdd.CusField7 = @"0"; //自定義欄位七(47)
  522. oBillsAdd.CusField8 = @"0"; //自定義欄位八(48)
  523. oBillsAdd.CusField9 = @"0"; //自定義欄位九(49)
  524. oBillsAdd.CusField10 = @"0"; //自定義欄位十(50)
  525. oBillsAdd.CusField11 = @""; //自定義欄位十一(51)
  526. oBillsAdd.CusField12 = @""; //自定義欄位十二(52)
  527. oBillsAdd.Remark2 = @""; //備註二(M)(53)
  528. oBillsAdd.TWNOTaxAmount = GetObjectValue(jo, "AmountSum"); //台幣未稅金額(54)
  529. oBillsAdd.TWAmount = GetObjectValue(jo, "AmountTaxSum"); //台幣帳款金額(55)
  530. oBillsAdd.CreateUser = import.ModifyUser;
  531. oBillsAdd.CreateDate = ((DateTime)import.ModifyDate).ToString(@"yyyy/MM/dd HH:mm:ss");
  532. oBillsAdd.BillFirstCheckDate = string.IsNullOrEmpty(GetObjectValue(jo, "BillFirstCheckDate")) ? DateTime.Now.ToString(@"yyyy/MM/dd HH:mm:ss") : GetObjectValue(jo, "BillFirstCheckDate");
  533. oBillsAdd.Advance = GetObjectValue(jo, "Advance"); //預收
  534. oBillsAdd.TaxSum = GetObjectValue(jo, "TaxSum"); //稅額
  535. oBillsAdd.TotalReceivable = GetObjectValue(jo, "TotalReceivable"); //總應收
  536. oBillsAdd.IsRetn = string.IsNullOrEmpty(GetObjectValue(jo, "IsRetn")) ? @"N" : GetObjectValue(jo, "IsRetn"); //是否為退運
  537. oBillsAdd.Url = sUrl; //Url
  538. db.Insertable(oBillsAdd).ExecuteCommand();
  539. if (dicSucceccCount.Keys.Contains("退運進口審核"))
  540. {
  541. dicSucceccCount["退運進口審核"] = dicSucceccCount["退運進口審核"] + 1;
  542. }
  543. else
  544. {
  545. dicSucceccCount.Add("退運進口審核", 1);
  546. }
  547. #endregion
  548. }
  549. else if (sAuditVal == "5")
  550. {
  551. #region 過帳
  552. var oBillsAdd = new OTB_OPM_Bills
  553. {
  554. OrgID = import.OrgID,
  555. BillNO = sBillNo, //帳款號碼(1)
  556. CheckDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")),//對帳日期(2)
  557. BillType = @"20",//帳別(收付)(3)
  558. CustomerCode = oPayer.CustomerNO //客戶供應商代號(4)
  559. };
  560. var sResponsiblePerson = oOpm.ResponsiblePerson.Split('.')[0];
  561. oBillsAdd.ResponsiblePersonCode = Common.CutByteString(sResponsiblePerson, 11); //業務員代號(5)
  562. oBillsAdd.ResponsiblePersonFullCode = oOpm.ResponsiblePerson; //業務員全代號
  563. oBillsAdd.LastGetBillDate = @""; //最近收付日(6)
  564. oBillsAdd.LastGetBillNO = @""; //最近收付單號(7)
  565. oBillsAdd.TaxType = decimal.Parse(GetObjectValue(jo, "TaxSum").Replace(@",", @"")) > 0 ? @"5" : @"6";//稅別(8)
  566. oBillsAdd.NOTaxAmount = GetObjectValue(jo, "AmountSum"); //未稅金額(9)
  567. oBillsAdd.BillAmount = GetObjectValue(jo, "AmountTaxSum"); //帳款金額(10)
  568. oBillsAdd.PaymentAmount = @"0"; //收付金額(11)
  569. oBillsAdd.Allowance = @"0"; //折讓金額(12)
  570. oBillsAdd.DebtAmount = @"0"; //呆帳金額(13)
  571. oBillsAdd.ExchangeAmount = @"0"; //匯兌損益金額(14)
  572. oBillsAdd.Settle = @"N"; //結清否(15)
  573. oBillsAdd.InvoiceStartNumber = GetObjectValue(jo, "InvoiceNumber"); //發票號碼(起)(16)
  574. oBillsAdd.InvoiceEndNumber = GetObjectValue(jo, "InvoiceNumber");//發票號碼(迄)(17)
  575. oBillsAdd.Category = @"";//傳票類別(18)
  576. oBillsAdd.OrderNo = @"";//訂單單號(19)
  577. oBillsAdd.ClosingNote = @"N"; //結帳註記(20)
  578. oBillsAdd.GeneralInvoiceNumber = @""; //立帳總帳傳票號碼(21)
  579. oBillsAdd.GeneralSerialNumber = @""; //立帳總帳傳票序號(22)
  580. oBillsAdd.Remark1 = @""; //備註一(30C)(23)
  581. oBillsAdd.AccountSource = @"0"; //帳款來源(24)
  582. oBillsAdd.UpdateDate = @""; //更新日期(25)
  583. oBillsAdd.UpdatePersonnel = @""; //更新人員(26)
  584. oBillsAdd.DepartmentSiteNumber = oOpm.DepartmentID; //部門\ 工地編號(27)
  585. if (!string.IsNullOrWhiteSpace(oOpm.ExhibitionNO))
  586. {
  587. var oExhibition = db.Queryable<OTB_OPM_Exhibition>().Single(it => it.SN == oOpm.ExhibitionNO.ObjToInt());
  588. oBillsAdd.ProjectNumber = oExhibition == null ? @"" : oExhibition.ExhibitionCode; //專案\ 項目編號(28)
  589. }
  590. else
  591. {
  592. oBillsAdd.ProjectNumber = @""; //專案\ 項目編號(28)
  593. }
  594. oBillsAdd.TransferBNotes = @""; //轉B 帳註記(29)
  595. oBillsAdd.ABNumber = @""; //A|B 帳唯一流水號(30)
  596. oBillsAdd.EnterNumber = @""; //進銷單號(31)
  597. var sCurrency = GetObjectValue(jo, "Currency");
  598. if (import.OrgID == "SG")
  599. {
  600. if (sCurrency == "RMB")
  601. {
  602. sCurrency = "";
  603. }
  604. }
  605. else
  606. {
  607. if (sCurrency == "NTD")
  608. {
  609. sCurrency = "";
  610. }
  611. }
  612. oBillsAdd.ForeignCurrencyCode = sCurrency; //外幣代號(32)
  613. var sExchangeRate = GetObjectValue(jo, "ExchangeRate");
  614. oBillsAdd.ExchangeRate = sExchangeRate; //匯率(33)
  615. oBillsAdd.ForeignAmount = (decimal.Parse(GetObjectValue(jo, "AmountTaxSum")) * decimal.Parse(sExchangeRate == @"" ? @"1" : sExchangeRate)).ToString(); //外幣金額(34)
  616. oBillsAdd.PayAmount = @"0"; //收付沖抵金額(35)
  617. oBillsAdd.RefundAmount = @"0"; //退款金額(36)
  618. oBillsAdd.PaymentTerms = @""; //收付條件(37)
  619. oBillsAdd.AccountDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")); //帳款日期(38)
  620. oBillsAdd.DCreditCardNumber = @""; //預設信用卡號(39)
  621. oBillsAdd.ClosingDate = @""; //結帳日期(40)
  622. oBillsAdd.CusField1 = @""; //自定義欄位一(41)
  623. oBillsAdd.CusField2 = @""; //自定義欄位二(42)
  624. oBillsAdd.CusField3 = @""; //自定義欄位三(43)
  625. oBillsAdd.CusField4 = @""; //自定義欄位四(44)
  626. oBillsAdd.CusField5 = @""; //自定義欄位五(45)
  627. oBillsAdd.CusField6 = @"0"; //自定義欄位六(46)
  628. oBillsAdd.CusField7 = @"0"; //自定義欄位七(47)
  629. oBillsAdd.CusField8 = @"0"; //自定義欄位八(48)
  630. oBillsAdd.CusField9 = @"0"; //自定義欄位九(49)
  631. oBillsAdd.CusField10 = @"0"; //自定義欄位十(50)
  632. oBillsAdd.CusField11 = @""; //自定義欄位十一(51)
  633. oBillsAdd.CusField12 = @""; //自定義欄位十二(52)
  634. oBillsAdd.Remark2 = @""; //備註二(M)(53)
  635. oBillsAdd.TWNOTaxAmount = GetObjectValue(jo, "AmountSum"); //台幣未稅金額(54)
  636. oBillsAdd.TWAmount = GetObjectValue(jo, "AmountTaxSum"); //台幣帳款金額(55)
  637. oBillsAdd.CreateUser = import.ModifyUser;
  638. oBillsAdd.CreateDate = ((DateTime)import.ModifyDate).ToString(@"yyyy/MM/dd HH:mm:ss");
  639. oBillsAdd.BillFirstCheckDate = string.IsNullOrEmpty(GetObjectValue(jo, "BillFirstCheckDate")) ? DateTime.Now.ToString(@"yyyy/MM/dd HH:mm:ss") : GetObjectValue(jo, "BillFirstCheckDate");
  640. oBillsAdd.Advance = GetObjectValue(jo, "Advance"); //預收
  641. oBillsAdd.TaxSum = GetObjectValue(jo, "TaxSum"); //稅額
  642. oBillsAdd.TotalReceivable = GetObjectValue(jo, "TotalReceivable"); //總應收
  643. oBillsAdd.IsRetn = string.IsNullOrEmpty(GetObjectValue(jo, "IsRetn")) ? @"N" : GetObjectValue(jo, "IsRetn"); //是否為退運
  644. oBillsAdd.Url = sUrl; //Url
  645. db.Insertable(oBillsAdd).ExecuteCommand();
  646. if (dicSucceccCount.Keys.Contains("退運進口過帳"))
  647. {
  648. dicSucceccCount["退運進口過帳"] = dicSucceccCount["退運進口過帳"] + 1;
  649. }
  650. else
  651. {
  652. dicSucceccCount.Add("退運進口過帳", 1);
  653. }
  654. #endregion
  655. }
  656. }
  657. }
  658. }
  659. }
  660. }
  661. }
  662. }
  663. }
  664. #endregion
  665. return sMsg;
  666. }
  667. public string Export(string sStartDate, string sEndDate, SqlSugarClient db)
  668. {
  669. string sMsg = null;
  670. DateTime dtSettingStartDate = Convert.ToDateTime(sStartDate);
  671. DateTime dtSettingEnd = Convert.ToDateTime(sEndDate);
  672. #region 出口
  673. var data2 = db.Queryable<OTB_OPM_ExportExhibition>()
  674. .Where(x => x.ModifyDate <= SqlFunc.ToDate(sEndDate) && x.ModifyDate >= SqlFunc.ToDate(sStartDate))
  675. .ToList();
  676. foreach (OTB_OPM_ExportExhibition export in data2)
  677. {
  678. if (ExcExport || BillsNo.Any())
  679. {
  680. //解析bill
  681. if (!string.IsNullOrEmpty(export.Bills))
  682. {
  683. JArray ja = JArray.Parse(export.Bills);
  684. if (ja.Count > 0)
  685. {
  686. var sdb = new SimpleClient<OTB_OPM_ExportExhibition>(db);
  687. var oOpm = sdb.GetById(export.ExportBillNO);
  688. if (oOpm == null)
  689. {
  690. sMsg = $"出口單號:{ export.ExportBillNO } => 系統找不到對應的基本資料,請核查!";
  691. break;
  692. }
  693. foreach (JObject jo in ja.OfType<JObject>())
  694. {
  695. string sBillNo = GetObjectValue(jo, "BillNO");
  696. string sAuditVal = GetObjectValue(jo, "AuditVal");
  697. string sBillCheckDate = GetObjectValue(jo, "BillCheckDate");
  698. string sPayer = GetObjectValue(jo, "Payer");
  699. string sUrl = @"ExhibitionExport_Upd|?Action=Upd&GoTab=3&ExportBillNO=" + oOpm.ExportBillNO + @"&BillNO=" + sBillNo;
  700. DateTime dtCreateDate;
  701. if (BillsNo.Any() && !BillsNo.Contains(sBillNo))
  702. {
  703. continue;
  704. }
  705. if (DateTime.TryParse(sBillCheckDate, out dtCreateDate))
  706. {
  707. if (dtCreateDate <= dtSettingEnd && dtCreateDate >= dtSettingStartDate)
  708. {
  709. var oPayer = new OTB_CRM_Customers();
  710. if (!string.IsNullOrEmpty(sPayer))
  711. {
  712. oPayer = db.Queryable<OTB_CRM_Customers>().Single(it => it.guid == sPayer);
  713. if (oPayer == null)
  714. {
  715. sMsg = $"出口單號:{ export.ExportBillNO } => 系統找不到付款人資訊";
  716. break;
  717. }
  718. }
  719. //狀態4(已銷帳)/6(已作廢)當成已審核拋轉
  720. if (sAuditVal == "2" || sAuditVal == "4" || sAuditVal == "6")
  721. {
  722. #region 審核
  723. var oBillsAdd = new OTB_OPM_Bills
  724. {
  725. OrgID = export.OrgID,
  726. BillNO = sBillNo, //帳款號碼(1)
  727. CheckDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")),//對帳日期(2)
  728. BillType = @"20",//帳別(收付)(3)
  729. CustomerCode = oPayer.CustomerNO //客戶供應商代號(4)
  730. };
  731. var sResponsiblePerson = oOpm.ResponsiblePerson.Split('.')[0];
  732. oBillsAdd.ResponsiblePersonCode = Common.CutByteString(sResponsiblePerson, 11); //業務員代號(5)
  733. oBillsAdd.ResponsiblePersonFullCode = oOpm.ResponsiblePerson; //業務員全代號
  734. oBillsAdd.LastGetBillDate = @""; //最近收付日(6)
  735. oBillsAdd.LastGetBillNO = @""; //最近收付單號(7)
  736. oBillsAdd.TaxType = decimal.Parse(GetObjectValue(jo, "TaxSum").Replace(@",", @"")) > 0 ? @"5" : @"6";//稅別(8)
  737. oBillsAdd.NOTaxAmount = GetObjectValue(jo, "AmountSum"); //未稅金額(9)
  738. oBillsAdd.BillAmount = GetObjectValue(jo, "AmountTaxSum"); //帳款金額(10)
  739. oBillsAdd.PaymentAmount = @"0"; //收付金額(11)
  740. oBillsAdd.Allowance = @"0"; //折讓金額(12)
  741. oBillsAdd.DebtAmount = @"0"; //呆帳金額(13)
  742. oBillsAdd.ExchangeAmount = @"0"; //匯兌損益金額(14)
  743. oBillsAdd.Settle = @"N"; //結清否(15)
  744. oBillsAdd.InvoiceStartNumber = @""; //發票號碼(起)(16)
  745. oBillsAdd.InvoiceEndNumber = @"";//發票號碼(迄)(17)
  746. oBillsAdd.Category = @"";//傳票類別(18)
  747. oBillsAdd.OrderNo = @"";//訂單單號(19)
  748. oBillsAdd.ClosingNote = @"N"; //結帳註記(20)
  749. oBillsAdd.GeneralInvoiceNumber = @""; //立帳總帳傳票號碼(21)
  750. oBillsAdd.GeneralSerialNumber = @""; //立帳總帳傳票序號(22)
  751. oBillsAdd.Remark1 = @""; //備註一(30C)(23)
  752. oBillsAdd.AccountSource = @"0"; //帳款來源(24)
  753. oBillsAdd.UpdateDate = @""; //更新日期(25)
  754. oBillsAdd.UpdatePersonnel = @""; //更新人員(26)
  755. oBillsAdd.DepartmentSiteNumber = oOpm.DepartmentID; //部門\ 工地編號(27)
  756. if (!string.IsNullOrWhiteSpace(oOpm.ExhibitionNO))
  757. {
  758. var oExhibition = db.Queryable<OTB_OPM_Exhibition>().Single(it => it.SN == oOpm.ExhibitionNO.ObjToInt());
  759. oBillsAdd.ProjectNumber = oExhibition == null ? @"" : oExhibition.ExhibitionCode; //專案\ 項目編號(28)
  760. }
  761. else
  762. {
  763. oBillsAdd.ProjectNumber = @""; //專案\ 項目編號(28)
  764. }
  765. oBillsAdd.TransferBNotes = @""; //轉B 帳註記(29)
  766. oBillsAdd.ABNumber = @""; //A|B 帳唯一流水號(30)
  767. oBillsAdd.EnterNumber = @""; //進銷單號(31)
  768. var sCurrency = GetObjectValue(jo, "Currency");
  769. if (export.OrgID == "SG")
  770. {
  771. if (sCurrency == "RMB")
  772. {
  773. sCurrency = "";
  774. }
  775. }
  776. else
  777. {
  778. if (sCurrency == "NTD")
  779. {
  780. sCurrency = "";
  781. }
  782. }
  783. oBillsAdd.ForeignCurrencyCode = sCurrency; //外幣代號(32)
  784. var sExchangeRate = GetObjectValue(jo, "ExchangeRate");
  785. oBillsAdd.ExchangeRate = sExchangeRate; //匯率(33)
  786. oBillsAdd.ForeignAmount = (decimal.Parse(GetObjectValue(jo, "AmountTaxSum")) * decimal.Parse(sExchangeRate == @"" ? @"1" : sExchangeRate)).ToString(); //外幣金額(34)
  787. oBillsAdd.PayAmount = @"0"; //收付沖抵金額(35)
  788. oBillsAdd.RefundAmount = @"0"; //退款金額(36)
  789. oBillsAdd.PaymentTerms = @""; //收付條件(37)
  790. oBillsAdd.AccountDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")); //帳款日期(38)
  791. oBillsAdd.DCreditCardNumber = @""; //預設信用卡號(39)
  792. oBillsAdd.ClosingDate = @""; //結帳日期(40)
  793. oBillsAdd.CusField1 = @""; //自定義欄位一(41)
  794. oBillsAdd.CusField2 = @""; //自定義欄位二(42)
  795. oBillsAdd.CusField3 = @""; //自定義欄位三(43)
  796. oBillsAdd.CusField4 = @""; //自定義欄位四(44)
  797. oBillsAdd.CusField5 = @""; //自定義欄位五(45)
  798. oBillsAdd.CusField6 = @"0"; //自定義欄位六(46)
  799. oBillsAdd.CusField7 = @"0"; //自定義欄位七(47)
  800. oBillsAdd.CusField8 = @"0"; //自定義欄位八(48)
  801. oBillsAdd.CusField9 = @"0"; //自定義欄位九(49)
  802. oBillsAdd.CusField10 = @"0"; //自定義欄位十(50)
  803. oBillsAdd.CusField11 = @""; //自定義欄位十一(51)
  804. oBillsAdd.CusField12 = @""; //自定義欄位十二(52)
  805. oBillsAdd.Remark2 = @""; //備註二(M)(53)
  806. oBillsAdd.TWNOTaxAmount = GetObjectValue(jo, "AmountSum"); //台幣未稅金額(54)
  807. oBillsAdd.TWAmount = GetObjectValue(jo, "AmountTaxSum"); //台幣帳款金額(55)
  808. oBillsAdd.CreateUser = export.ModifyUser;
  809. oBillsAdd.CreateDate = ((DateTime)export.ModifyDate).ToString(@"yyyy/MM/dd HH:mm:ss");
  810. oBillsAdd.BillFirstCheckDate = string.IsNullOrEmpty(GetObjectValue(jo, "BillFirstCheckDate")) ? DateTime.Now.ToString(@"yyyy/MM/dd HH:mm:ss") : GetObjectValue(jo, "BillFirstCheckDate");
  811. oBillsAdd.Advance = GetObjectValue(jo, "Advance"); //預收
  812. oBillsAdd.TaxSum = GetObjectValue(jo, "TaxSum"); //稅額
  813. oBillsAdd.TotalReceivable = GetObjectValue(jo, "TotalReceivable"); //總應收
  814. oBillsAdd.IsRetn = string.IsNullOrEmpty(GetObjectValue(jo, "IsRetn")) ? @"N" : GetObjectValue(jo, "IsRetn"); //是否為退運
  815. oBillsAdd.Url = sUrl; //Url
  816. db.Insertable(oBillsAdd).ExecuteCommand();
  817. if (dicSucceccCount.Keys.Contains("出口審核"))
  818. {
  819. dicSucceccCount["出口審核"] = dicSucceccCount["出口審核"] + 1;
  820. }
  821. else
  822. {
  823. dicSucceccCount.Add("出口審核", 1);
  824. }
  825. #endregion
  826. }
  827. else if (sAuditVal == "5")
  828. {
  829. #region 過帳
  830. var oBillsAdd = new OTB_OPM_Bills
  831. {
  832. OrgID = export.OrgID,
  833. BillNO = sBillNo, //帳款號碼(1)
  834. CheckDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")),//對帳日期(2)
  835. BillType = @"20",//帳別(收付)(3)
  836. CustomerCode = oPayer.CustomerNO //客戶供應商代號(4)
  837. };
  838. var sResponsiblePerson = oOpm.ResponsiblePerson.Split('.')[0];
  839. oBillsAdd.ResponsiblePersonCode = Common.CutByteString(sResponsiblePerson, 11); //業務員代號(5)
  840. oBillsAdd.ResponsiblePersonFullCode = oOpm.ResponsiblePerson; //業務員全代號
  841. oBillsAdd.LastGetBillDate = @""; //最近收付日(6)
  842. oBillsAdd.LastGetBillNO = @""; //最近收付單號(7)
  843. oBillsAdd.TaxType = decimal.Parse(GetObjectValue(jo, "TaxSum").Replace(@",", @"")) > 0 ? @"5" : @"6";//稅別(8)
  844. oBillsAdd.NOTaxAmount = GetObjectValue(jo, "AmountSum"); //未稅金額(9)
  845. oBillsAdd.BillAmount = GetObjectValue(jo, "AmountTaxSum"); //帳款金額(10)
  846. oBillsAdd.PaymentAmount = @"0"; //收付金額(11)
  847. oBillsAdd.Allowance = @"0"; //折讓金額(12)
  848. oBillsAdd.DebtAmount = @"0"; //呆帳金額(13)
  849. oBillsAdd.ExchangeAmount = @"0"; //匯兌損益金額(14)
  850. oBillsAdd.Settle = @"N"; //結清否(15)
  851. oBillsAdd.InvoiceStartNumber = GetObjectValue(jo, "InvoiceNumber"); //發票號碼(起)(16)
  852. oBillsAdd.InvoiceEndNumber = GetObjectValue(jo, "InvoiceNumber");//發票號碼(迄)(17)
  853. oBillsAdd.Category = @"";//傳票類別(18)
  854. oBillsAdd.OrderNo = @"";//訂單單號(19)
  855. oBillsAdd.ClosingNote = @"N"; //結帳註記(20)
  856. oBillsAdd.GeneralInvoiceNumber = @""; //立帳總帳傳票號碼(21)
  857. oBillsAdd.GeneralSerialNumber = @""; //立帳總帳傳票序號(22)
  858. oBillsAdd.Remark1 = @""; //備註一(30C)(23)
  859. oBillsAdd.AccountSource = @"0"; //帳款來源(24)
  860. oBillsAdd.UpdateDate = @""; //更新日期(25)
  861. oBillsAdd.UpdatePersonnel = @""; //更新人員(26)
  862. oBillsAdd.DepartmentSiteNumber = oOpm.DepartmentID; //部門\ 工地編號(27)
  863. if (!string.IsNullOrWhiteSpace(oOpm.ExhibitionNO))
  864. {
  865. var oExhibition = db.Queryable<OTB_OPM_Exhibition>().Single(it => it.SN == oOpm.ExhibitionNO.ObjToInt());
  866. oBillsAdd.ProjectNumber = oExhibition == null ? @"" : oExhibition.ExhibitionCode; //專案\ 項目編號(28)
  867. }
  868. else
  869. {
  870. oBillsAdd.ProjectNumber = @""; //專案\ 項目編號(28)
  871. }
  872. oBillsAdd.TransferBNotes = @""; //轉B 帳註記(29)
  873. oBillsAdd.ABNumber = @""; //A|B 帳唯一流水號(30)
  874. oBillsAdd.EnterNumber = @""; //進銷單號(31)
  875. var sCurrency = GetObjectValue(jo, "Currency");
  876. if (export.OrgID == "SG")
  877. {
  878. if (sCurrency == "RMB")
  879. {
  880. sCurrency = "";
  881. }
  882. }
  883. else
  884. {
  885. if (sCurrency == "NTD")
  886. {
  887. sCurrency = "";
  888. }
  889. }
  890. oBillsAdd.ForeignCurrencyCode = sCurrency; //外幣代號(32)
  891. var sExchangeRate = GetObjectValue(jo, "ExchangeRate");
  892. oBillsAdd.ExchangeRate = sExchangeRate; //匯率(33)
  893. oBillsAdd.ForeignAmount = (decimal.Parse(GetObjectValue(jo, "AmountTaxSum")) * decimal.Parse(sExchangeRate == @"" ? @"1" : sExchangeRate)).ToString(); //外幣金額(34)
  894. oBillsAdd.PayAmount = @"0"; //收付沖抵金額(35)
  895. oBillsAdd.RefundAmount = @"0"; //退款金額(36)
  896. oBillsAdd.PaymentTerms = @""; //收付條件(37)
  897. oBillsAdd.AccountDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")); //帳款日期(38)
  898. oBillsAdd.DCreditCardNumber = @""; //預設信用卡號(39)
  899. oBillsAdd.ClosingDate = @""; //結帳日期(40)
  900. oBillsAdd.CusField1 = @""; //自定義欄位一(41)
  901. oBillsAdd.CusField2 = @""; //自定義欄位二(42)
  902. oBillsAdd.CusField3 = @""; //自定義欄位三(43)
  903. oBillsAdd.CusField4 = @""; //自定義欄位四(44)
  904. oBillsAdd.CusField5 = @""; //自定義欄位五(45)
  905. oBillsAdd.CusField6 = @"0"; //自定義欄位六(46)
  906. oBillsAdd.CusField7 = @"0"; //自定義欄位七(47)
  907. oBillsAdd.CusField8 = @"0"; //自定義欄位八(48)
  908. oBillsAdd.CusField9 = @"0"; //自定義欄位九(49)
  909. oBillsAdd.CusField10 = @"0"; //自定義欄位十(50)
  910. oBillsAdd.CusField11 = @""; //自定義欄位十一(51)
  911. oBillsAdd.CusField12 = @""; //自定義欄位十二(52)
  912. oBillsAdd.Remark2 = @""; //備註二(M)(53)
  913. oBillsAdd.TWNOTaxAmount = GetObjectValue(jo, "AmountSum"); //台幣未稅金額(54)
  914. oBillsAdd.TWAmount = GetObjectValue(jo, "AmountTaxSum"); //台幣帳款金額(55)
  915. oBillsAdd.CreateUser = export.ModifyUser;
  916. oBillsAdd.CreateDate = ((DateTime)export.ModifyDate).ToString(@"yyyy/MM/dd HH:mm:ss");
  917. oBillsAdd.BillFirstCheckDate = string.IsNullOrEmpty(GetObjectValue(jo, "BillFirstCheckDate")) ? DateTime.Now.ToString(@"yyyy/MM/dd HH:mm:ss") : GetObjectValue(jo, "BillFirstCheckDate");
  918. oBillsAdd.Advance = GetObjectValue(jo, "Advance"); //預收
  919. oBillsAdd.TaxSum = GetObjectValue(jo, "TaxSum"); //稅額
  920. oBillsAdd.TotalReceivable = GetObjectValue(jo, "TotalReceivable"); //總應收
  921. oBillsAdd.IsRetn = string.IsNullOrEmpty(GetObjectValue(jo, "IsRetn")) ? @"N" : GetObjectValue(jo, "IsRetn"); //是否為退運
  922. oBillsAdd.Url = sUrl; //Url
  923. db.Insertable(oBillsAdd).ExecuteCommand();
  924. if (dicSucceccCount.Keys.Contains("出口過帳"))
  925. {
  926. dicSucceccCount["出口過帳"] = dicSucceccCount["出口過帳"] + 1;
  927. }
  928. else
  929. {
  930. dicSucceccCount.Add("出口過帳", 1);
  931. }
  932. #endregion
  933. }
  934. }
  935. }
  936. }
  937. }
  938. }
  939. }
  940. if (ExcExportReturn || BillsNo.Any())
  941. {
  942. //解析ReturnBill
  943. JArray ja = JArray.Parse(export.ReturnBills);
  944. if (ja.Count > 0)
  945. {
  946. var sdb = new SimpleClient<OTB_OPM_ExportExhibition>(db);
  947. var oOpm = sdb.GetById(export.ExportBillNO);
  948. if (oOpm == null)
  949. {
  950. sMsg = $"退運出口單號:{ export.ExportBillNO } => 系統找不到對應的基本資料,請核查!";
  951. break;
  952. }
  953. foreach (JObject joH in ja.OfType<JObject>())
  954. {
  955. JArray ja1 = JArray.Parse(GetObjectValue(joH, "Bills"));
  956. if (ja1.Count > 0)
  957. {
  958. foreach (JObject jo in ja1.OfType<JObject>())
  959. {
  960. string sBillNo = GetObjectValue(jo, "BillNO");
  961. string sAuditVal = GetObjectValue(jo, "AuditVal");
  962. string sBillCheckDate = GetObjectValue(jo, "BillCheckDate");
  963. string sPayer = GetObjectValue(jo, "Payer");
  964. string sUrl = @"ExhibitionExport_Upd|?Action=Upd&GoTab=5&ExportBillNO=" + oOpm.ExportBillNO + @"&BillNO=" + sBillNo;
  965. DateTime dtCreateDate;
  966. if (BillsNo.Any() && !BillsNo.Contains(sBillNo))
  967. {
  968. continue;
  969. }
  970. if (DateTime.TryParse(sBillCheckDate, out dtCreateDate))
  971. {
  972. if (dtCreateDate <= dtSettingEnd && dtCreateDate >= dtSettingStartDate)
  973. {
  974. var oPayer = new OTB_CRM_Customers();
  975. if (!string.IsNullOrEmpty(sPayer))
  976. {
  977. oPayer = db.Queryable<OTB_CRM_Customers>().Single(it => it.guid == sPayer);
  978. if (oPayer == null)
  979. {
  980. sMsg = $"退運出口單號:{ export.ExportBillNO } => 系統找不到付款人資訊";
  981. break;
  982. }
  983. }
  984. //狀態4(已銷帳)/6(已作廢)當成已審核拋轉
  985. if (sAuditVal == "2" || sAuditVal == "4" || sAuditVal == "6")
  986. {
  987. #region 審核
  988. var oBillsAdd = new OTB_OPM_Bills
  989. {
  990. OrgID = export.OrgID,
  991. BillNO = sBillNo, //帳款號碼(1)
  992. CheckDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")),//對帳日期(2)
  993. BillType = @"20",//帳別(收付)(3)
  994. CustomerCode = oPayer.CustomerNO //客戶供應商代號(4)
  995. };
  996. var sResponsiblePerson = oOpm.ResponsiblePerson.Split('.')[0];
  997. oBillsAdd.ResponsiblePersonCode = Common.CutByteString(sResponsiblePerson, 11); //業務員代號(5)
  998. oBillsAdd.ResponsiblePersonFullCode = oOpm.ResponsiblePerson; //業務員全代號
  999. oBillsAdd.LastGetBillDate = @""; //最近收付日(6)
  1000. oBillsAdd.LastGetBillNO = @""; //最近收付單號(7)
  1001. oBillsAdd.TaxType = decimal.Parse(GetObjectValue(jo, "TaxSum").Replace(@",", @"")) > 0 ? @"5" : @"6";//稅別(8)
  1002. oBillsAdd.NOTaxAmount = GetObjectValue(jo, "AmountSum"); //未稅金額(9)
  1003. oBillsAdd.BillAmount = GetObjectValue(jo, "AmountTaxSum"); //帳款金額(10)
  1004. oBillsAdd.PaymentAmount = @"0"; //收付金額(11)
  1005. oBillsAdd.Allowance = @"0"; //折讓金額(12)
  1006. oBillsAdd.DebtAmount = @"0"; //呆帳金額(13)
  1007. oBillsAdd.ExchangeAmount = @"0"; //匯兌損益金額(14)
  1008. oBillsAdd.Settle = @"N"; //結清否(15)
  1009. oBillsAdd.InvoiceStartNumber = @""; //發票號碼(起)(16)
  1010. oBillsAdd.InvoiceEndNumber = @"";//發票號碼(迄)(17)
  1011. oBillsAdd.Category = @"";//傳票類別(18)
  1012. oBillsAdd.OrderNo = @"";//訂單單號(19)
  1013. oBillsAdd.ClosingNote = @"N"; //結帳註記(20)
  1014. oBillsAdd.GeneralInvoiceNumber = @""; //立帳總帳傳票號碼(21)
  1015. oBillsAdd.GeneralSerialNumber = @""; //立帳總帳傳票序號(22)
  1016. oBillsAdd.Remark1 = @""; //備註一(30C)(23)
  1017. oBillsAdd.AccountSource = @"0"; //帳款來源(24)
  1018. oBillsAdd.UpdateDate = @""; //更新日期(25)
  1019. oBillsAdd.UpdatePersonnel = @""; //更新人員(26)
  1020. oBillsAdd.DepartmentSiteNumber = oOpm.DepartmentID; //部門\ 工地編號(27)
  1021. if (!string.IsNullOrWhiteSpace(oOpm.ExhibitionNO))
  1022. {
  1023. var oExhibition = db.Queryable<OTB_OPM_Exhibition>().Single(it => it.SN == oOpm.ExhibitionNO.ObjToInt());
  1024. oBillsAdd.ProjectNumber = oExhibition == null ? @"" : oExhibition.ExhibitionCode; //專案\ 項目編號(28)
  1025. }
  1026. else
  1027. {
  1028. oBillsAdd.ProjectNumber = @""; //專案\ 項目編號(28)
  1029. }
  1030. oBillsAdd.TransferBNotes = @""; //轉B 帳註記(29)
  1031. oBillsAdd.ABNumber = @""; //A|B 帳唯一流水號(30)
  1032. oBillsAdd.EnterNumber = @""; //進銷單號(31)
  1033. var sCurrency = GetObjectValue(jo, "Currency");
  1034. if (export.OrgID == "SG")
  1035. {
  1036. if (sCurrency == "RMB")
  1037. {
  1038. sCurrency = "";
  1039. }
  1040. }
  1041. else
  1042. {
  1043. if (sCurrency == "NTD")
  1044. {
  1045. sCurrency = "";
  1046. }
  1047. }
  1048. oBillsAdd.ForeignCurrencyCode = sCurrency; //外幣代號(32)
  1049. var sExchangeRate = GetObjectValue(jo, "ExchangeRate");
  1050. oBillsAdd.ExchangeRate = sExchangeRate; //匯率(33)
  1051. oBillsAdd.ForeignAmount = (decimal.Parse(GetObjectValue(jo, "AmountTaxSum")) * decimal.Parse(sExchangeRate == @"" ? @"1" : sExchangeRate)).ToString(); //外幣金額(34)
  1052. oBillsAdd.PayAmount = @"0"; //收付沖抵金額(35)
  1053. oBillsAdd.RefundAmount = @"0"; //退款金額(36)
  1054. oBillsAdd.PaymentTerms = @""; //收付條件(37)
  1055. oBillsAdd.AccountDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")); //帳款日期(38)
  1056. oBillsAdd.DCreditCardNumber = @""; //預設信用卡號(39)
  1057. oBillsAdd.ClosingDate = @""; //結帳日期(40)
  1058. oBillsAdd.CusField1 = @""; //自定義欄位一(41)
  1059. oBillsAdd.CusField2 = @""; //自定義欄位二(42)
  1060. oBillsAdd.CusField3 = @""; //自定義欄位三(43)
  1061. oBillsAdd.CusField4 = @""; //自定義欄位四(44)
  1062. oBillsAdd.CusField5 = @""; //自定義欄位五(45)
  1063. oBillsAdd.CusField6 = @"0"; //自定義欄位六(46)
  1064. oBillsAdd.CusField7 = @"0"; //自定義欄位七(47)
  1065. oBillsAdd.CusField8 = @"0"; //自定義欄位八(48)
  1066. oBillsAdd.CusField9 = @"0"; //自定義欄位九(49)
  1067. oBillsAdd.CusField10 = @"0"; //自定義欄位十(50)
  1068. oBillsAdd.CusField11 = @""; //自定義欄位十一(51)
  1069. oBillsAdd.CusField12 = @""; //自定義欄位十二(52)
  1070. oBillsAdd.Remark2 = @""; //備註二(M)(53)
  1071. oBillsAdd.TWNOTaxAmount = GetObjectValue(jo, "AmountSum"); //台幣未稅金額(54)
  1072. oBillsAdd.TWAmount = GetObjectValue(jo, "AmountTaxSum"); //台幣帳款金額(55)
  1073. oBillsAdd.CreateUser = export.ModifyUser;
  1074. oBillsAdd.CreateDate = ((DateTime)export.ModifyDate).ToString(@"yyyy/MM/dd HH:mm:ss");
  1075. oBillsAdd.BillFirstCheckDate = string.IsNullOrEmpty(GetObjectValue(jo, "BillFirstCheckDate")) ? DateTime.Now.ToString(@"yyyy/MM/dd HH:mm:ss") : GetObjectValue(jo, "BillFirstCheckDate");
  1076. oBillsAdd.Advance = GetObjectValue(jo, "Advance"); //預收
  1077. oBillsAdd.TaxSum = GetObjectValue(jo, "TaxSum"); //稅額
  1078. oBillsAdd.TotalReceivable = GetObjectValue(jo, "TotalReceivable"); //總應收
  1079. oBillsAdd.IsRetn = string.IsNullOrEmpty(GetObjectValue(jo, "IsRetn")) ? @"N" : GetObjectValue(jo, "IsRetn"); //是否為退運
  1080. oBillsAdd.Url = sUrl; //Url
  1081. db.Insertable(oBillsAdd).ExecuteCommand();
  1082. if (dicSucceccCount.Keys.Contains("退運出口審核"))
  1083. {
  1084. dicSucceccCount["退運出口審核"] = dicSucceccCount["退運出口審核"] + 1;
  1085. }
  1086. else
  1087. {
  1088. dicSucceccCount.Add("退運出口審核", 1);
  1089. }
  1090. #endregion
  1091. }
  1092. else if (sAuditVal == "5")
  1093. {
  1094. #region 過帳
  1095. var oBillsAdd = new OTB_OPM_Bills
  1096. {
  1097. OrgID = export.OrgID,
  1098. BillNO = sBillNo, //帳款號碼(1)
  1099. CheckDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")),//對帳日期(2)
  1100. BillType = @"20",//帳別(收付)(3)
  1101. CustomerCode = oPayer.CustomerNO //客戶供應商代號(4)
  1102. };
  1103. var sResponsiblePerson = oOpm.ResponsiblePerson.Split('.')[0];
  1104. oBillsAdd.ResponsiblePersonCode = Common.CutByteString(sResponsiblePerson, 11); //業務員代號(5)
  1105. oBillsAdd.ResponsiblePersonFullCode = oOpm.ResponsiblePerson; //業務員全代號
  1106. oBillsAdd.LastGetBillDate = @""; //最近收付日(6)
  1107. oBillsAdd.LastGetBillNO = @""; //最近收付單號(7)
  1108. oBillsAdd.TaxType = decimal.Parse(GetObjectValue(jo, "TaxSum").Replace(@",", @"")) > 0 ? @"5" : @"6";//稅別(8)
  1109. oBillsAdd.NOTaxAmount = GetObjectValue(jo, "AmountSum"); //未稅金額(9)
  1110. oBillsAdd.BillAmount = GetObjectValue(jo, "AmountTaxSum"); //帳款金額(10)
  1111. oBillsAdd.PaymentAmount = @"0"; //收付金額(11)
  1112. oBillsAdd.Allowance = @"0"; //折讓金額(12)
  1113. oBillsAdd.DebtAmount = @"0"; //呆帳金額(13)
  1114. oBillsAdd.ExchangeAmount = @"0"; //匯兌損益金額(14)
  1115. oBillsAdd.Settle = @"N"; //結清否(15)
  1116. oBillsAdd.InvoiceStartNumber = GetObjectValue(jo, "InvoiceNumber"); //發票號碼(起)(16)
  1117. oBillsAdd.InvoiceEndNumber = GetObjectValue(jo, "InvoiceNumber");//發票號碼(迄)(17)
  1118. oBillsAdd.Category = @"";//傳票類別(18)
  1119. oBillsAdd.OrderNo = @"";//訂單單號(19)
  1120. oBillsAdd.ClosingNote = @"N"; //結帳註記(20)
  1121. oBillsAdd.GeneralInvoiceNumber = @""; //立帳總帳傳票號碼(21)
  1122. oBillsAdd.GeneralSerialNumber = @""; //立帳總帳傳票序號(22)
  1123. oBillsAdd.Remark1 = @""; //備註一(30C)(23)
  1124. oBillsAdd.AccountSource = @"0"; //帳款來源(24)
  1125. oBillsAdd.UpdateDate = @""; //更新日期(25)
  1126. oBillsAdd.UpdatePersonnel = @""; //更新人員(26)
  1127. oBillsAdd.DepartmentSiteNumber = oOpm.DepartmentID; //部門\ 工地編號(27)
  1128. if (!string.IsNullOrWhiteSpace(oOpm.ExhibitionNO))
  1129. {
  1130. var oExhibition = db.Queryable<OTB_OPM_Exhibition>().Single(it => it.SN == oOpm.ExhibitionNO.ObjToInt());
  1131. oBillsAdd.ProjectNumber = oExhibition == null ? @"" : oExhibition.ExhibitionCode; //專案\ 項目編號(28)
  1132. }
  1133. else
  1134. {
  1135. oBillsAdd.ProjectNumber = @""; //專案\ 項目編號(28)
  1136. }
  1137. oBillsAdd.TransferBNotes = @""; //轉B 帳註記(29)
  1138. oBillsAdd.ABNumber = @""; //A|B 帳唯一流水號(30)
  1139. oBillsAdd.EnterNumber = @""; //進銷單號(31)
  1140. var sCurrency = GetObjectValue(jo, "Currency");
  1141. if (export.OrgID == "SG")
  1142. {
  1143. if (sCurrency == "RMB")
  1144. {
  1145. sCurrency = "";
  1146. }
  1147. }
  1148. else
  1149. {
  1150. if (sCurrency == "NTD")
  1151. {
  1152. sCurrency = "";
  1153. }
  1154. }
  1155. oBillsAdd.ForeignCurrencyCode = sCurrency; //外幣代號(32)
  1156. var sExchangeRate = GetObjectValue(jo, "ExchangeRate");
  1157. oBillsAdd.ExchangeRate = sExchangeRate; //匯率(33)
  1158. oBillsAdd.ForeignAmount = (decimal.Parse(GetObjectValue(jo, "AmountTaxSum")) * decimal.Parse(sExchangeRate == @"" ? @"1" : sExchangeRate)).ToString(); //外幣金額(34)
  1159. oBillsAdd.PayAmount = @"0"; //收付沖抵金額(35)
  1160. oBillsAdd.RefundAmount = @"0"; //退款金額(36)
  1161. oBillsAdd.PaymentTerms = @""; //收付條件(37)
  1162. oBillsAdd.AccountDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")); //帳款日期(38)
  1163. oBillsAdd.DCreditCardNumber = @""; //預設信用卡號(39)
  1164. oBillsAdd.ClosingDate = @""; //結帳日期(40)
  1165. oBillsAdd.CusField1 = @""; //自定義欄位一(41)
  1166. oBillsAdd.CusField2 = @""; //自定義欄位二(42)
  1167. oBillsAdd.CusField3 = @""; //自定義欄位三(43)
  1168. oBillsAdd.CusField4 = @""; //自定義欄位四(44)
  1169. oBillsAdd.CusField5 = @""; //自定義欄位五(45)
  1170. oBillsAdd.CusField6 = @"0"; //自定義欄位六(46)
  1171. oBillsAdd.CusField7 = @"0"; //自定義欄位七(47)
  1172. oBillsAdd.CusField8 = @"0"; //自定義欄位八(48)
  1173. oBillsAdd.CusField9 = @"0"; //自定義欄位九(49)
  1174. oBillsAdd.CusField10 = @"0"; //自定義欄位十(50)
  1175. oBillsAdd.CusField11 = @""; //自定義欄位十一(51)
  1176. oBillsAdd.CusField12 = @""; //自定義欄位十二(52)
  1177. oBillsAdd.Remark2 = @""; //備註二(M)(53)
  1178. oBillsAdd.TWNOTaxAmount = GetObjectValue(jo, "AmountSum"); //台幣未稅金額(54)
  1179. oBillsAdd.TWAmount = GetObjectValue(jo, "AmountTaxSum"); //台幣帳款金額(55)
  1180. oBillsAdd.CreateUser = export.ModifyUser;
  1181. oBillsAdd.CreateDate = ((DateTime)export.ModifyDate).ToString(@"yyyy/MM/dd HH:mm:ss");
  1182. oBillsAdd.BillFirstCheckDate = string.IsNullOrEmpty(GetObjectValue(jo, "BillFirstCheckDate")) ? DateTime.Now.ToString(@"yyyy/MM/dd HH:mm:ss") : GetObjectValue(jo, "BillFirstCheckDate");
  1183. oBillsAdd.Advance = GetObjectValue(jo, "Advance"); //預收
  1184. oBillsAdd.TaxSum = GetObjectValue(jo, "TaxSum"); //稅額
  1185. oBillsAdd.TotalReceivable = GetObjectValue(jo, "TotalReceivable"); //總應收
  1186. oBillsAdd.IsRetn = string.IsNullOrEmpty(GetObjectValue(jo, "IsRetn")) ? @"N" : GetObjectValue(jo, "IsRetn"); //是否為退運
  1187. oBillsAdd.Url = sUrl; //Url
  1188. db.Insertable(oBillsAdd).ExecuteCommand();
  1189. if (dicSucceccCount.Keys.Contains("退運出口過帳"))
  1190. {
  1191. dicSucceccCount["退運出口過帳"] = dicSucceccCount["退運出口過帳"] + 1;
  1192. }
  1193. else
  1194. {
  1195. dicSucceccCount.Add("退運出口過帳", 1);
  1196. }
  1197. #endregion
  1198. }
  1199. }
  1200. }
  1201. }
  1202. }
  1203. }
  1204. }
  1205. }
  1206. }
  1207. #endregion
  1208. return sMsg;
  1209. }
  1210. public string Other(string sStartDate, string sEndDate, SqlSugarClient db)
  1211. {
  1212. string sMsg = null;
  1213. DateTime dtSettingStartDate = Convert.ToDateTime(sStartDate);
  1214. DateTime dtSettingEnd = Convert.ToDateTime(sEndDate);
  1215. if (ExcOther || BillsNo.Any())
  1216. {
  1217. #region 其他
  1218. var data3 = db.Queryable<OTB_OPM_OtherExhibition>()
  1219. .Where(x => x.ModifyDate <= SqlFunc.ToDate(sEndDate) && x.ModifyDate >= SqlFunc.ToDate(sStartDate))
  1220. .ToList();
  1221. foreach (OTB_OPM_OtherExhibition other in data3)
  1222. {
  1223. //解析bill
  1224. if (!string.IsNullOrEmpty(other.Bills))
  1225. {
  1226. JArray ja = JArray.Parse(other.Bills);
  1227. if (ja.Count > 0)
  1228. {
  1229. var sdb = new SimpleClient<OTB_OPM_OtherExhibition>(db);
  1230. var oOpm = sdb.GetById(other.Guid);
  1231. if (oOpm == null)
  1232. {
  1233. sMsg = $"其他GUID:{ other.Guid } => 系統找不到對應的基本資料,請核查!";
  1234. break;
  1235. }
  1236. foreach (JObject jo in ja.OfType<JObject>())
  1237. {
  1238. string sBillNo = GetObjectValue(jo, "BillNO");
  1239. string sAuditVal = GetObjectValue(jo, "AuditVal");
  1240. string sBillCheckDate = GetObjectValue(jo, "BillCheckDate");
  1241. string sPayer = GetObjectValue(jo, "Payer");
  1242. string sUrl = @"OtherBusiness_Upd|?Action=Upd&GoTab=2&ExportBillNO=" + oOpm.Guid + @"&BillNO=" + sBillNo;
  1243. DateTime dtCreateDate;
  1244. if (BillsNo.Any() && !BillsNo.Contains(sBillNo))
  1245. {
  1246. continue;
  1247. }
  1248. if (DateTime.TryParse(sBillCheckDate, out dtCreateDate))
  1249. {
  1250. if (dtCreateDate <= dtSettingEnd && dtCreateDate >= dtSettingStartDate)
  1251. {
  1252. var oPayer = new OTB_CRM_Customers();
  1253. if (!string.IsNullOrEmpty(sPayer))
  1254. {
  1255. oPayer = db.Queryable<OTB_CRM_Customers>().Single(it => it.guid == sPayer);
  1256. if (oPayer == null)
  1257. {
  1258. sMsg = $"其他GUID:{ other.Guid } => 系統找不到付款人資訊";
  1259. break;
  1260. }
  1261. }
  1262. //狀態4(已銷帳)/6(已作廢)當成已審核拋轉
  1263. if (sAuditVal == "2" || sAuditVal == "4" || sAuditVal == "6")
  1264. {
  1265. #region 審核
  1266. var oBillsAdd = new OTB_OPM_Bills
  1267. {
  1268. OrgID = other.OrgID,
  1269. BillNO = sBillNo, //帳款號碼(1)
  1270. CheckDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")),//對帳日期(2)
  1271. BillType = @"20",//帳別(收付)(3)
  1272. CustomerCode = oPayer.CustomerNO //客戶供應商代號(4)
  1273. };
  1274. var sResponsiblePerson = oOpm.ResponsiblePerson.Split('.')[0];
  1275. oBillsAdd.ResponsiblePersonCode = Common.CutByteString(sResponsiblePerson, 11); //業務員代號(5)
  1276. oBillsAdd.ResponsiblePersonFullCode = oOpm.ResponsiblePerson; //業務員全代號
  1277. oBillsAdd.LastGetBillDate = @""; //最近收付日(6)
  1278. oBillsAdd.LastGetBillNO = @""; //最近收付單號(7)
  1279. oBillsAdd.TaxType = decimal.Parse(GetObjectValue(jo, "TaxSum").Replace(@",", @"")) > 0 ? @"5" : @"6";//稅別(8)
  1280. oBillsAdd.NOTaxAmount = GetObjectValue(jo, "AmountSum"); //未稅金額(9)
  1281. oBillsAdd.BillAmount = GetObjectValue(jo, "AmountTaxSum"); //帳款金額(10)
  1282. oBillsAdd.PaymentAmount = @"0"; //收付金額(11)
  1283. oBillsAdd.Allowance = @"0"; //折讓金額(12)
  1284. oBillsAdd.DebtAmount = @"0"; //呆帳金額(13)
  1285. oBillsAdd.ExchangeAmount = @"0"; //匯兌損益金額(14)
  1286. oBillsAdd.Settle = @"N"; //結清否(15)
  1287. oBillsAdd.InvoiceStartNumber = @""; //發票號碼(起)(16)
  1288. oBillsAdd.InvoiceEndNumber = @"";//發票號碼(迄)(17)
  1289. oBillsAdd.Category = @"";//傳票類別(18)
  1290. oBillsAdd.OrderNo = @"";//訂單單號(19)
  1291. oBillsAdd.ClosingNote = @"N"; //結帳註記(20)
  1292. oBillsAdd.GeneralInvoiceNumber = @""; //立帳總帳傳票號碼(21)
  1293. oBillsAdd.GeneralSerialNumber = @""; //立帳總帳傳票序號(22)
  1294. oBillsAdd.Remark1 = @""; //備註一(30C)(23)
  1295. oBillsAdd.AccountSource = @"0"; //帳款來源(24)
  1296. oBillsAdd.UpdateDate = @""; //更新日期(25)
  1297. oBillsAdd.UpdatePersonnel = @""; //更新人員(26)
  1298. oBillsAdd.DepartmentSiteNumber = oOpm.DepartmentID; //部門\ 工地編號(27)
  1299. if (!string.IsNullOrWhiteSpace(oOpm.ExhibitionNO))
  1300. {
  1301. var oExhibition = db.Queryable<OTB_OPM_Exhibition>().Single(it => it.SN == oOpm.ExhibitionNO.ObjToInt());
  1302. oBillsAdd.ProjectNumber = oExhibition == null ? @"" : oExhibition.ExhibitionCode; //專案\ 項目編號(28)
  1303. }
  1304. else
  1305. {
  1306. oBillsAdd.ProjectNumber = @""; //專案\ 項目編號(28)
  1307. }
  1308. oBillsAdd.TransferBNotes = @""; //轉B 帳註記(29)
  1309. oBillsAdd.ABNumber = @""; //A|B 帳唯一流水號(30)
  1310. oBillsAdd.EnterNumber = @""; //進銷單號(31)
  1311. var sCurrency = GetObjectValue(jo, "Currency");
  1312. if (other.OrgID == "SG")
  1313. {
  1314. if (sCurrency == "RMB")
  1315. {
  1316. sCurrency = "";
  1317. }
  1318. }
  1319. else
  1320. {
  1321. if (sCurrency == "NTD")
  1322. {
  1323. sCurrency = "";
  1324. }
  1325. }
  1326. oBillsAdd.ForeignCurrencyCode = sCurrency; //外幣代號(32)
  1327. var sExchangeRate = GetObjectValue(jo, "ExchangeRate");
  1328. oBillsAdd.ExchangeRate = sExchangeRate; //匯率(33)
  1329. oBillsAdd.ForeignAmount = (decimal.Parse(GetObjectValue(jo, "AmountTaxSum")) * decimal.Parse(sExchangeRate == @"" ? @"1" : sExchangeRate)).ToString(); //外幣金額(34)
  1330. oBillsAdd.PayAmount = @"0"; //收付沖抵金額(35)
  1331. oBillsAdd.RefundAmount = @"0"; //退款金額(36)
  1332. oBillsAdd.PaymentTerms = @""; //收付條件(37)
  1333. oBillsAdd.AccountDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")); //帳款日期(38)
  1334. oBillsAdd.DCreditCardNumber = @""; //預設信用卡號(39)
  1335. oBillsAdd.ClosingDate = @""; //結帳日期(40)
  1336. oBillsAdd.CusField1 = @""; //自定義欄位一(41)
  1337. oBillsAdd.CusField2 = @""; //自定義欄位二(42)
  1338. oBillsAdd.CusField3 = @""; //自定義欄位三(43)
  1339. oBillsAdd.CusField4 = @""; //自定義欄位四(44)
  1340. oBillsAdd.CusField5 = @""; //自定義欄位五(45)
  1341. oBillsAdd.CusField6 = @"0"; //自定義欄位六(46)
  1342. oBillsAdd.CusField7 = @"0"; //自定義欄位七(47)
  1343. oBillsAdd.CusField8 = @"0"; //自定義欄位八(48)
  1344. oBillsAdd.CusField9 = @"0"; //自定義欄位九(49)
  1345. oBillsAdd.CusField10 = @"0"; //自定義欄位十(50)
  1346. oBillsAdd.CusField11 = @""; //自定義欄位十一(51)
  1347. oBillsAdd.CusField12 = @""; //自定義欄位十二(52)
  1348. oBillsAdd.Remark2 = @""; //備註二(M)(53)
  1349. oBillsAdd.TWNOTaxAmount = GetObjectValue(jo, "AmountSum"); //台幣未稅金額(54)
  1350. oBillsAdd.TWAmount = GetObjectValue(jo, "AmountTaxSum"); //台幣帳款金額(55)
  1351. oBillsAdd.CreateUser = other.ModifyUser;
  1352. oBillsAdd.CreateDate = ((DateTime)other.ModifyDate).ToString(@"yyyy/MM/dd HH:mm:ss");
  1353. oBillsAdd.BillFirstCheckDate = string.IsNullOrEmpty(GetObjectValue(jo, "BillFirstCheckDate")) ? DateTime.Now.ToString(@"yyyy/MM/dd HH:mm:ss") : GetObjectValue(jo, "BillFirstCheckDate");
  1354. oBillsAdd.Advance = GetObjectValue(jo, "Advance"); //預收
  1355. oBillsAdd.TaxSum = GetObjectValue(jo, "TaxSum"); //稅額
  1356. oBillsAdd.TotalReceivable = GetObjectValue(jo, "TotalReceivable"); //總應收
  1357. oBillsAdd.IsRetn = string.IsNullOrEmpty(GetObjectValue(jo, "IsRetn")) ? @"N" : GetObjectValue(jo, "IsRetn"); //是否為退運
  1358. oBillsAdd.Url = sUrl; //Url
  1359. db.Insertable(oBillsAdd).ExecuteCommand();
  1360. if (dicSucceccCount.Keys.Contains("其他審核"))
  1361. {
  1362. dicSucceccCount["其他審核"] = dicSucceccCount["其他審核"] + 1;
  1363. }
  1364. else
  1365. {
  1366. dicSucceccCount.Add("其他審核", 1);
  1367. }
  1368. #endregion
  1369. }
  1370. else if (sAuditVal == "5")
  1371. {
  1372. #region 過帳
  1373. var oBillsAdd = new OTB_OPM_Bills
  1374. {
  1375. OrgID = other.OrgID,
  1376. BillNO = sBillNo, //帳款號碼(1)
  1377. CheckDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")),//對帳日期(2)
  1378. BillType = @"20",//帳別(收付)(3)
  1379. CustomerCode = oPayer.CustomerNO //客戶供應商代號(4)
  1380. };
  1381. var sResponsiblePerson = oOpm.ResponsiblePerson.Split('.')[0];
  1382. oBillsAdd.ResponsiblePersonCode = Common.CutByteString(sResponsiblePerson, 11); //業務員代號(5)
  1383. oBillsAdd.ResponsiblePersonFullCode = oOpm.ResponsiblePerson; //業務員全代號
  1384. oBillsAdd.LastGetBillDate = @""; //最近收付日(6)
  1385. oBillsAdd.LastGetBillNO = @""; //最近收付單號(7)
  1386. oBillsAdd.TaxType = decimal.Parse(GetObjectValue(jo, "TaxSum").Replace(@",", @"")) > 0 ? @"5" : @"6";//稅別(8)
  1387. oBillsAdd.NOTaxAmount = GetObjectValue(jo, "AmountSum"); //未稅金額(9)
  1388. oBillsAdd.BillAmount = GetObjectValue(jo, "AmountTaxSum"); //帳款金額(10)
  1389. oBillsAdd.PaymentAmount = @"0"; //收付金額(11)
  1390. oBillsAdd.Allowance = @"0"; //折讓金額(12)
  1391. oBillsAdd.DebtAmount = @"0"; //呆帳金額(13)
  1392. oBillsAdd.ExchangeAmount = @"0"; //匯兌損益金額(14)
  1393. oBillsAdd.Settle = @"N"; //結清否(15)
  1394. oBillsAdd.InvoiceStartNumber = GetObjectValue(jo, "InvoiceNumber"); //發票號碼(起)(16)
  1395. oBillsAdd.InvoiceEndNumber = GetObjectValue(jo, "InvoiceNumber");//發票號碼(迄)(17)
  1396. oBillsAdd.Category = @"";//傳票類別(18)
  1397. oBillsAdd.OrderNo = @"";//訂單單號(19)
  1398. oBillsAdd.ClosingNote = @"N"; //結帳註記(20)
  1399. oBillsAdd.GeneralInvoiceNumber = @""; //立帳總帳傳票號碼(21)
  1400. oBillsAdd.GeneralSerialNumber = @""; //立帳總帳傳票序號(22)
  1401. oBillsAdd.Remark1 = @""; //備註一(30C)(23)
  1402. oBillsAdd.AccountSource = @"0"; //帳款來源(24)
  1403. oBillsAdd.UpdateDate = @""; //更新日期(25)
  1404. oBillsAdd.UpdatePersonnel = @""; //更新人員(26)
  1405. oBillsAdd.DepartmentSiteNumber = oOpm.DepartmentID; //部門\ 工地編號(27)
  1406. if (!string.IsNullOrWhiteSpace(oOpm.ExhibitionNO))
  1407. {
  1408. var oExhibition = db.Queryable<OTB_OPM_Exhibition>().Single(it => it.SN == oOpm.ExhibitionNO.ObjToInt());
  1409. oBillsAdd.ProjectNumber = oExhibition == null ? @"" : oExhibition.ExhibitionCode; //專案\ 項目編號(28)
  1410. }
  1411. else
  1412. {
  1413. oBillsAdd.ProjectNumber = @""; //專案\ 項目編號(28)
  1414. }
  1415. oBillsAdd.TransferBNotes = @""; //轉B 帳註記(29)
  1416. oBillsAdd.ABNumber = @""; //A|B 帳唯一流水號(30)
  1417. oBillsAdd.EnterNumber = @""; //進銷單號(31)
  1418. var sCurrency = GetObjectValue(jo, "Currency");
  1419. if (other.OrgID == "SG")
  1420. {
  1421. if (sCurrency == "RMB")
  1422. {
  1423. sCurrency = "";
  1424. }
  1425. }
  1426. else
  1427. {
  1428. if (sCurrency == "NTD")
  1429. {
  1430. sCurrency = "";
  1431. }
  1432. }
  1433. oBillsAdd.ForeignCurrencyCode = sCurrency; //外幣代號(32)
  1434. var sExchangeRate = GetObjectValue(jo, "ExchangeRate");
  1435. oBillsAdd.ExchangeRate = sExchangeRate; //匯率(33)
  1436. oBillsAdd.ForeignAmount = (decimal.Parse(GetObjectValue(jo, "AmountTaxSum")) * decimal.Parse(sExchangeRate == @"" ? @"1" : sExchangeRate)).ToString(); //外幣金額(34)
  1437. oBillsAdd.PayAmount = @"0"; //收付沖抵金額(35)
  1438. oBillsAdd.RefundAmount = @"0"; //退款金額(36)
  1439. oBillsAdd.PaymentTerms = @""; //收付條件(37)
  1440. oBillsAdd.AccountDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")); //帳款日期(38)
  1441. oBillsAdd.DCreditCardNumber = @""; //預設信用卡號(39)
  1442. oBillsAdd.ClosingDate = @""; //結帳日期(40)
  1443. oBillsAdd.CusField1 = @""; //自定義欄位一(41)
  1444. oBillsAdd.CusField2 = @""; //自定義欄位二(42)
  1445. oBillsAdd.CusField3 = @""; //自定義欄位三(43)
  1446. oBillsAdd.CusField4 = @""; //自定義欄位四(44)
  1447. oBillsAdd.CusField5 = @""; //自定義欄位五(45)
  1448. oBillsAdd.CusField6 = @"0"; //自定義欄位六(46)
  1449. oBillsAdd.CusField7 = @"0"; //自定義欄位七(47)
  1450. oBillsAdd.CusField8 = @"0"; //自定義欄位八(48)
  1451. oBillsAdd.CusField9 = @"0"; //自定義欄位九(49)
  1452. oBillsAdd.CusField10 = @"0"; //自定義欄位十(50)
  1453. oBillsAdd.CusField11 = @""; //自定義欄位十一(51)
  1454. oBillsAdd.CusField12 = @""; //自定義欄位十二(52)
  1455. oBillsAdd.Remark2 = @""; //備註二(M)(53)
  1456. oBillsAdd.TWNOTaxAmount = GetObjectValue(jo, "AmountSum"); //台幣未稅金額(54)
  1457. oBillsAdd.TWAmount = GetObjectValue(jo, "AmountTaxSum"); //台幣帳款金額(55)
  1458. oBillsAdd.CreateUser = other.ModifyUser;
  1459. oBillsAdd.CreateDate = ((DateTime)other.ModifyDate).ToString(@"yyyy/MM/dd HH:mm:ss");
  1460. oBillsAdd.BillFirstCheckDate = string.IsNullOrEmpty(GetObjectValue(jo, "BillFirstCheckDate")) ? DateTime.Now.ToString(@"yyyy/MM/dd HH:mm:ss") : GetObjectValue(jo, "BillFirstCheckDate");
  1461. oBillsAdd.Advance = GetObjectValue(jo, "Advance"); //預收
  1462. oBillsAdd.TaxSum = GetObjectValue(jo, "TaxSum"); //稅額
  1463. oBillsAdd.TotalReceivable = GetObjectValue(jo, "TotalReceivable"); //總應收
  1464. oBillsAdd.IsRetn = string.IsNullOrEmpty(GetObjectValue(jo, "IsRetn")) ? @"N" : GetObjectValue(jo, "IsRetn"); //是否為退運
  1465. oBillsAdd.Url = sUrl; //Url
  1466. db.Insertable(oBillsAdd).ExecuteCommand();
  1467. if (dicSucceccCount.Keys.Contains("其他過帳"))
  1468. {
  1469. dicSucceccCount["其他過帳"] = dicSucceccCount["其他過帳"] + 1;
  1470. }
  1471. else
  1472. {
  1473. dicSucceccCount.Add("其他過帳", 1);
  1474. }
  1475. #endregion
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. }
  1482. }
  1483. #endregion
  1484. }
  1485. return sMsg;
  1486. }
  1487. public string OtherTG(string sStartDate, string sEndDate, SqlSugarClient db)
  1488. {
  1489. string sMsg = null;
  1490. DateTime dtSettingStartDate = Convert.ToDateTime(sStartDate);
  1491. DateTime dtSettingEnd = Convert.ToDateTime(sEndDate);
  1492. if (ExcOtherTG || BillsNo.Any())
  1493. {
  1494. #region 其他(駒驛)
  1495. var data6 = db.Queryable<OTB_OPM_OtherExhibitionTG>()
  1496. .Where(x => x.ModifyDate <= SqlFunc.ToDate(sEndDate) && x.ModifyDate >= SqlFunc.ToDate(sStartDate))
  1497. .ToList();
  1498. foreach (OTB_OPM_OtherExhibitionTG OtherTG in data6)
  1499. {
  1500. //解析bill
  1501. if (!string.IsNullOrEmpty(OtherTG.Bills))
  1502. {
  1503. JArray ja = JArray.Parse(OtherTG.Bills);
  1504. if (ja.Count > 0)
  1505. {
  1506. var sdb = new SimpleClient<OTB_OPM_OtherExhibitionTG>(db);
  1507. var oOpm = sdb.GetById(OtherTG.Guid);
  1508. if (oOpm == null)
  1509. {
  1510. sMsg = $"其他(駒驛)GUID:{ OtherTG.Guid } => 系統找不到對應的基本資料,請核查!";
  1511. break;
  1512. }
  1513. foreach (JObject jo in ja.OfType<JObject>())
  1514. {
  1515. string sBillNo = GetObjectValue(jo, "BillNO");
  1516. string sAuditVal = GetObjectValue(jo, "AuditVal");
  1517. string sBillCheckDate = GetObjectValue(jo, "BillCheckDate");
  1518. string sPayer = GetObjectValue(jo, "Payer");
  1519. string sUrl = @"OtherExhibitionTG_Upd|?Action=Upd&GoTab=3&Guid=" + oOpm.Guid + @"&BillNO=" + sBillNo;
  1520. DateTime dtCreateDate;
  1521. if (BillsNo.Any() && !BillsNo.Contains(sBillNo))
  1522. {
  1523. continue;
  1524. }
  1525. var oPayer = new OTB_CRM_Customers();
  1526. if (!string.IsNullOrEmpty(sPayer))
  1527. {
  1528. oPayer = db.Queryable<OTB_CRM_Customers>().Single(it => it.guid == sPayer);
  1529. if (oPayer == null)
  1530. {
  1531. sMsg = $"其他(駒驛)GUID:{ OtherTG.Guid } => 系統找不到付款人資訊";
  1532. break;
  1533. }
  1534. }
  1535. //狀態4(已銷帳)/6(已作廢)當成已審核拋轉
  1536. if (sAuditVal == "2" || sAuditVal == "4" || sAuditVal == "6")
  1537. {
  1538. #region 審核
  1539. var oBillsAdd = new OTB_OPM_Bills
  1540. {
  1541. OrgID = OtherTG.OrgID,
  1542. BillNO = sBillNo, //帳款號碼(1)
  1543. CheckDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")),//對帳日期(2)
  1544. BillType = @"20",//帳別(收付)(3)
  1545. CustomerCode = oPayer.CustomerNO //客戶供應商代號(4)
  1546. };
  1547. var sResponsiblePerson = oOpm.ResponsiblePerson.Split('.')[0];
  1548. oBillsAdd.ResponsiblePersonCode = Common.CutByteString(sResponsiblePerson, 11); //業務員代號(5)
  1549. oBillsAdd.ResponsiblePersonFullCode = oOpm.ResponsiblePerson; //業務員全代號
  1550. oBillsAdd.LastGetBillDate = @""; //最近收付日(6)
  1551. oBillsAdd.LastGetBillNO = @""; //最近收付單號(7)
  1552. oBillsAdd.TaxType = decimal.Parse(GetObjectValue(jo, "TaxSum").Replace(@",", @"")) > 0 ? @"5" : @"6";//稅別(8)
  1553. oBillsAdd.NOTaxAmount = GetObjectValue(jo, "AmountSum"); //未稅金額(9)
  1554. oBillsAdd.BillAmount = GetObjectValue(jo, "AmountTaxSum"); //帳款金額(10)
  1555. oBillsAdd.PaymentAmount = @"0"; //收付金額(11)
  1556. oBillsAdd.Allowance = @"0"; //折讓金額(12)
  1557. oBillsAdd.DebtAmount = @"0"; //呆帳金額(13)
  1558. oBillsAdd.ExchangeAmount = @"0"; //匯兌損益金額(14)
  1559. oBillsAdd.Settle = @"N"; //結清否(15)
  1560. oBillsAdd.InvoiceStartNumber = @""; //發票號碼(起)(16)
  1561. oBillsAdd.InvoiceEndNumber = @"";//發票號碼(迄)(17)
  1562. oBillsAdd.Category = @"";//傳票類別(18)
  1563. oBillsAdd.OrderNo = @"";//訂單單號(19)
  1564. oBillsAdd.ClosingNote = @"N"; //結帳註記(20)
  1565. oBillsAdd.GeneralInvoiceNumber = @""; //立帳總帳傳票號碼(21)
  1566. oBillsAdd.GeneralSerialNumber = @""; //立帳總帳傳票序號(22)
  1567. oBillsAdd.Remark1 = @""; //備註一(30C)(23)
  1568. oBillsAdd.AccountSource = @"0"; //帳款來源(24)
  1569. oBillsAdd.UpdateDate = @""; //更新日期(25)
  1570. oBillsAdd.UpdatePersonnel = @""; //更新人員(26)
  1571. oBillsAdd.DepartmentSiteNumber = oOpm.DepartmentID; //部門\ 工地編號(27)
  1572. if (!string.IsNullOrWhiteSpace(oOpm.ExhibitionNO))
  1573. {
  1574. var oExhibition = db.Queryable<OTB_OPM_Exhibition>().Single(it => it.SN == oOpm.ExhibitionNO.ObjToInt());
  1575. oBillsAdd.ProjectNumber = oExhibition == null ? @"" : oExhibition.ExhibitionCode; //專案\ 項目編號(28)
  1576. }
  1577. else
  1578. {
  1579. oBillsAdd.ProjectNumber = @""; //專案\ 項目編號(28)
  1580. }
  1581. oBillsAdd.TransferBNotes = @""; //轉B 帳註記(29)
  1582. oBillsAdd.ABNumber = @""; //A|B 帳唯一流水號(30)
  1583. oBillsAdd.EnterNumber = @""; //進銷單號(31)
  1584. var sCurrency = GetObjectValue(jo, "Currency");
  1585. if (OtherTG.OrgID == "SG")
  1586. {
  1587. if (sCurrency == "RMB")
  1588. {
  1589. sCurrency = "";
  1590. }
  1591. }
  1592. else
  1593. {
  1594. if (sCurrency == "NTD")
  1595. {
  1596. sCurrency = "";
  1597. }
  1598. }
  1599. oBillsAdd.ForeignCurrencyCode = sCurrency; //外幣代號(32)
  1600. var sExchangeRate = GetObjectValue(jo, "ExchangeRate");
  1601. oBillsAdd.ExchangeRate = sExchangeRate; //匯率(33)
  1602. oBillsAdd.ForeignAmount = (decimal.Parse(GetObjectValue(jo, "AmountTaxSum")) * decimal.Parse(sExchangeRate == @"" ? @"1" : sExchangeRate)).ToString(); //外幣金額(34)
  1603. oBillsAdd.PayAmount = @"0"; //收付沖抵金額(35)
  1604. oBillsAdd.RefundAmount = @"0"; //退款金額(36)
  1605. oBillsAdd.PaymentTerms = @""; //收付條件(37)
  1606. oBillsAdd.AccountDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")); //帳款日期(38)
  1607. oBillsAdd.DCreditCardNumber = @""; //預設信用卡號(39)
  1608. oBillsAdd.ClosingDate = @""; //結帳日期(40)
  1609. oBillsAdd.CusField1 = @""; //自定義欄位一(41)
  1610. oBillsAdd.CusField2 = @""; //自定義欄位二(42)
  1611. oBillsAdd.CusField3 = @""; //自定義欄位三(43)
  1612. oBillsAdd.CusField4 = @""; //自定義欄位四(44)
  1613. oBillsAdd.CusField5 = @""; //自定義欄位五(45)
  1614. oBillsAdd.CusField6 = @"0"; //自定義欄位六(46)
  1615. oBillsAdd.CusField7 = @"0"; //自定義欄位七(47)
  1616. oBillsAdd.CusField8 = @"0"; //自定義欄位八(48)
  1617. oBillsAdd.CusField9 = @"0"; //自定義欄位九(49)
  1618. oBillsAdd.CusField10 = @"0"; //自定義欄位十(50)
  1619. oBillsAdd.CusField11 = @""; //自定義欄位十一(51)
  1620. oBillsAdd.CusField12 = @""; //自定義欄位十二(52)
  1621. oBillsAdd.Remark2 = @""; //備註二(M)(53)
  1622. oBillsAdd.TWNOTaxAmount = GetObjectValue(jo, "AmountSum"); //台幣未稅金額(54)
  1623. oBillsAdd.TWAmount = GetObjectValue(jo, "AmountTaxSum"); //台幣帳款金額(55)
  1624. oBillsAdd.CreateUser = OtherTG.ModifyUser;
  1625. oBillsAdd.CreateDate = ((DateTime)OtherTG.ModifyDate).ToString(@"yyyy/MM/dd HH:mm:ss");
  1626. oBillsAdd.BillFirstCheckDate = string.IsNullOrEmpty(GetObjectValue(jo, "BillFirstCheckDate")) ? DateTime.Now.ToString(@"yyyy/MM/dd HH:mm:ss") : GetObjectValue(jo, "BillFirstCheckDate");
  1627. oBillsAdd.Advance = GetObjectValue(jo, "Advance"); //預收
  1628. oBillsAdd.TaxSum = GetObjectValue(jo, "TaxSum"); //稅額
  1629. oBillsAdd.TotalReceivable = GetObjectValue(jo, "TotalReceivable"); //總應收
  1630. oBillsAdd.IsRetn = string.IsNullOrEmpty(GetObjectValue(jo, "IsRetn")) ? @"N" : GetObjectValue(jo, "IsRetn"); //是否為退運
  1631. oBillsAdd.Url = sUrl; //Url
  1632. db.Insertable(oBillsAdd).ExecuteCommand();
  1633. if (dicSucceccCount.Keys.Contains("其他(駒驛)審核"))
  1634. {
  1635. dicSucceccCount["其他(駒驛)審核"] = dicSucceccCount["其他(駒驛)審核"] + 1;
  1636. }
  1637. else
  1638. {
  1639. dicSucceccCount.Add("其他(駒驛)審核", 1);
  1640. }
  1641. #endregion
  1642. }
  1643. else if (sAuditVal == "5")
  1644. {
  1645. #region 過帳
  1646. var oBillsAdd = new OTB_OPM_Bills
  1647. {
  1648. OrgID = OtherTG.OrgID,
  1649. BillNO = sBillNo, //帳款號碼(1)
  1650. CheckDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")),//對帳日期(2)
  1651. BillType = @"20",//帳別(收付)(3)
  1652. CustomerCode = oPayer.CustomerNO //客戶供應商代號(4)
  1653. };
  1654. var sResponsiblePerson = oOpm.ResponsiblePerson.Split('.')[0];
  1655. oBillsAdd.ResponsiblePersonCode = Common.CutByteString(sResponsiblePerson, 11); //業務員代號(5)
  1656. oBillsAdd.ResponsiblePersonFullCode = oOpm.ResponsiblePerson; //業務員全代號
  1657. oBillsAdd.LastGetBillDate = @""; //最近收付日(6)
  1658. oBillsAdd.LastGetBillNO = @""; //最近收付單號(7)
  1659. oBillsAdd.TaxType = decimal.Parse(GetObjectValue(jo, "TaxSum").Replace(@",", @"")) > 0 ? @"5" : @"6";//稅別(8)
  1660. oBillsAdd.NOTaxAmount = GetObjectValue(jo, "AmountSum"); //未稅金額(9)
  1661. oBillsAdd.BillAmount = GetObjectValue(jo, "AmountTaxSum"); //帳款金額(10)
  1662. oBillsAdd.PaymentAmount = @"0"; //收付金額(11)
  1663. oBillsAdd.Allowance = @"0"; //折讓金額(12)
  1664. oBillsAdd.DebtAmount = @"0"; //呆帳金額(13)
  1665. oBillsAdd.ExchangeAmount = @"0"; //匯兌損益金額(14)
  1666. oBillsAdd.Settle = @"N"; //結清否(15)
  1667. oBillsAdd.InvoiceStartNumber = GetObjectValue(jo, "InvoiceNumber"); //發票號碼(起)(16)
  1668. oBillsAdd.InvoiceEndNumber = GetObjectValue(jo, "InvoiceNumber");//發票號碼(迄)(17)
  1669. oBillsAdd.Category = @"";//傳票類別(18)
  1670. oBillsAdd.OrderNo = @"";//訂單單號(19)
  1671. oBillsAdd.ClosingNote = @"N"; //結帳註記(20)
  1672. oBillsAdd.GeneralInvoiceNumber = @""; //立帳總帳傳票號碼(21)
  1673. oBillsAdd.GeneralSerialNumber = @""; //立帳總帳傳票序號(22)
  1674. oBillsAdd.Remark1 = @""; //備註一(30C)(23)
  1675. oBillsAdd.AccountSource = @"0"; //帳款來源(24)
  1676. oBillsAdd.UpdateDate = @""; //更新日期(25)
  1677. oBillsAdd.UpdatePersonnel = @""; //更新人員(26)
  1678. oBillsAdd.DepartmentSiteNumber = oOpm.DepartmentID; //部門\ 工地編號(27)
  1679. if (!string.IsNullOrWhiteSpace(oOpm.ExhibitionNO))
  1680. {
  1681. var oExhibition = db.Queryable<OTB_OPM_Exhibition>().Single(it => it.SN == oOpm.ExhibitionNO.ObjToInt());
  1682. oBillsAdd.ProjectNumber = oExhibition == null ? @"" : oExhibition.ExhibitionCode; //專案\ 項目編號(28)
  1683. }
  1684. else
  1685. {
  1686. oBillsAdd.ProjectNumber = @""; //專案\ 項目編號(28)
  1687. }
  1688. oBillsAdd.TransferBNotes = @""; //轉B 帳註記(29)
  1689. oBillsAdd.ABNumber = @""; //A|B 帳唯一流水號(30)
  1690. oBillsAdd.EnterNumber = @""; //進銷單號(31)
  1691. var sCurrency = GetObjectValue(jo, "Currency");
  1692. if (OtherTG.OrgID == "SG")
  1693. {
  1694. if (sCurrency == "RMB")
  1695. {
  1696. sCurrency = "";
  1697. }
  1698. }
  1699. else
  1700. {
  1701. if (sCurrency == "NTD")
  1702. {
  1703. sCurrency = "";
  1704. }
  1705. }
  1706. oBillsAdd.ForeignCurrencyCode = sCurrency; //外幣代號(32)
  1707. var sExchangeRate = GetObjectValue(jo, "ExchangeRate");
  1708. oBillsAdd.ExchangeRate = sExchangeRate; //匯率(33)
  1709. oBillsAdd.ForeignAmount = (decimal.Parse(GetObjectValue(jo, "AmountTaxSum")) * decimal.Parse(sExchangeRate == @"" ? @"1" : sExchangeRate)).ToString(); //外幣金額(34)
  1710. oBillsAdd.PayAmount = @"0"; //收付沖抵金額(35)
  1711. oBillsAdd.RefundAmount = @"0"; //退款金額(36)
  1712. oBillsAdd.PaymentTerms = @""; //收付條件(37)
  1713. oBillsAdd.AccountDate = Common.FnToTWDate(GetObjectValue(jo, "BillFirstCheckDate")); //帳款日期(38)
  1714. oBillsAdd.DCreditCardNumber = @""; //預設信用卡號(39)
  1715. oBillsAdd.ClosingDate = @""; //結帳日期(40)
  1716. oBillsAdd.CusField1 = @""; //自定義欄位一(41)
  1717. oBillsAdd.CusField2 = @""; //自定義欄位二(42)
  1718. oBillsAdd.CusField3 = @""; //自定義欄位三(43)
  1719. oBillsAdd.CusField4 = @""; //自定義欄位四(44)
  1720. oBillsAdd.CusField5 = @""; //自定義欄位五(45)
  1721. oBillsAdd.CusField6 = @"0"; //自定義欄位六(46)
  1722. oBillsAdd.CusField7 = @"0"; //自定義欄位七(47)
  1723. oBillsAdd.CusField8 = @"0"; //自定義欄位八(48)
  1724. oBillsAdd.CusField9 = @"0"; //自定義欄位九(49)
  1725. oBillsAdd.CusField10 = @"0"; //自定義欄位十(50)
  1726. oBillsAdd.CusField11 = @""; //自定義欄位十一(51)
  1727. oBillsAdd.CusField12 = @""; //自定義欄位十二(52)
  1728. oBillsAdd.Remark2 = @""; //備註二(M)(53)
  1729. oBillsAdd.TWNOTaxAmount = GetObjectValue(jo, "AmountSum"); //台幣未稅金額(54)
  1730. oBillsAdd.TWAmount = GetObjectValue(jo, "AmountTaxSum"); //台幣帳款金額(55)
  1731. oBillsAdd.CreateUser = OtherTG.ModifyUser;
  1732. oBillsAdd.CreateDate = ((DateTime)OtherTG.ModifyDate).ToString(@"yyyy/MM/dd HH:mm:ss");
  1733. oBillsAdd.BillFirstCheckDate = string.IsNullOrEmpty(GetObjectValue(jo, "BillFirstCheckDate")) ? DateTime.Now.ToString(@"yyyy/MM/dd HH:mm:ss") : GetObjectValue(jo, "BillFirstCheckDate");
  1734. oBillsAdd.Advance = GetObjectValue(jo, "Advance"); //預收
  1735. oBillsAdd.TaxSum = GetObjectValue(jo, "TaxSum"); //稅額
  1736. oBillsAdd.TotalReceivable = GetObjectValue(jo, "TotalReceivable"); //總應收
  1737. oBillsAdd.IsRetn = string.IsNullOrEmpty(GetObjectValue(jo, "IsRetn")) ? @"N" : GetObjectValue(jo, "IsRetn"); //是否為退運
  1738. oBillsAdd.Url = sUrl; //Url
  1739. db.Insertable(oBillsAdd).ExecuteCommand();
  1740. if (dicSucceccCount.Keys.Contains("其他(駒驛)過帳"))
  1741. {
  1742. dicSucceccCount["其他(駒驛)過帳"] = dicSucceccCount["其他(駒驛)過帳"] + 1;
  1743. }
  1744. else
  1745. {
  1746. dicSucceccCount.Add("其他(駒驛)過帳", 1);
  1747. }
  1748. #endregion
  1749. }
  1750. }
  1751. }
  1752. }
  1753. }
  1754. #endregion
  1755. }
  1756. return sMsg;
  1757. }
  1758. public string Exhibition(string sStartDate, string sEndDate, SqlSugarClient db, bool ReturnBills = false)
  1759. {
  1760. string sMsg = null;
  1761. if (ExcExhibtion || ExhibtionsNo.Any())
  1762. {
  1763. #region 專案(展覽)
  1764. var data4 = db.Queryable<OTB_OPM_Exhibition>()
  1765. .Where(x => x.CreateDate <= SqlFunc.ToDate(sEndDate) && x.CreateDate >= SqlFunc.ToDate(sStartDate) && x.IsTransfer == "Y")
  1766. .ToList();
  1767. foreach (OTB_OPM_Exhibition exhibition in data4)
  1768. {
  1769. if (ExhibtionsNo.Any() && !ExhibtionsNo.Contains(exhibition.ExhibitionCode))
  1770. {
  1771. continue;
  1772. }
  1773. var oExhibitionsTransferUpd = new OTB_OPM_ExhibitionsTransfer
  1774. {
  1775. OrgID = exhibition.OrgID,
  1776. PrjNO = exhibition.ExhibitionCode,
  1777. PrjName = Common.CutByteString(exhibition.ExhibitioShotName_TW, 60)
  1778. };
  1779. var sCreateUser = exhibition.CreateUser.Split('.')[0];
  1780. oExhibitionsTransferUpd.PrjCharger = Common.CutByteString(sCreateUser, 11);
  1781. oExhibitionsTransferUpd.EndDate = @"";
  1782. db.Insertable(oExhibitionsTransferUpd).ExecuteCommand();
  1783. if (dicSucceccCount.Keys.Contains("專案(展覽)"))
  1784. {
  1785. dicSucceccCount["專案(展覽)"] = dicSucceccCount["專案(展覽)"] + 1;
  1786. }
  1787. else
  1788. {
  1789. dicSucceccCount.Add("專案(展覽)", 1);
  1790. }
  1791. }
  1792. #endregion
  1793. }
  1794. return sMsg;
  1795. }
  1796. public string Customer(string sStartDate, string sEndDate, SqlSugarClient db, bool ReturnBills = false)
  1797. {
  1798. string sMsg = null;
  1799. if (ExcCustomer || ExhibtionsNo.Any())
  1800. {
  1801. #region 客戶
  1802. var data5 = db.Queryable<OTB_CRM_Customers>()
  1803. .Where(x => x.CreateDate <= SqlFunc.ToDate(sEndDate) && x.CreateDate >= SqlFunc.ToDate(sStartDate) && x.IsAudit == "Y")
  1804. .ToList();
  1805. foreach (OTB_CRM_Customers cus in data5)
  1806. {
  1807. var sdb = new SimpleClient<OTB_CRM_Customers>(db);
  1808. var customer = sdb.GetById(cus.guid);
  1809. if (customer == null)
  1810. {
  1811. sMsg = $"客戶GUID:{ cus.guid }系統找不到對應的客戶資料,請核查!";
  1812. break;
  1813. }
  1814. if (ExhibtionsNo.Any() && !ExhibtionsNo.Contains(customer.CustomerNO))
  1815. {
  1816. continue;
  1817. }
  1818. var oCustomersTransferAdd = new OTB_CRM_CustomersTransfer();
  1819. oCustomersTransferAdd.OrgID = customer.OrgID;
  1820. oCustomersTransferAdd.Feild01 = customer.CustomerNO;
  1821. oCustomersTransferAdd.Feild02 = @"0";
  1822. oCustomersTransferAdd.Feild03 = Common.CutByteString(customer.CustomerShotCName, 12);
  1823. oCustomersTransferAdd.Feild04 = Common.CutByteString(customer.CustomerCName == @"" ? customer.CustomerEName : customer.CustomerCName, 60);
  1824. oCustomersTransferAdd.Feild05 = @"";
  1825. oCustomersTransferAdd.Feild06 = @"";
  1826. oCustomersTransferAdd.Feild07 = customer.UniCode;
  1827. oCustomersTransferAdd.Feild08 = @"";
  1828. oCustomersTransferAdd.Feild09 = @"";
  1829. oCustomersTransferAdd.Feild10 = Common.CutByteString(customer.InvoiceAddress, 60);
  1830. oCustomersTransferAdd.Feild11 = Common.CutByteString(customer.Address, 60);
  1831. oCustomersTransferAdd.Feild12 = @"";
  1832. oCustomersTransferAdd.Feild13 = @"";
  1833. oCustomersTransferAdd.Feild14 = Common.CutByteString(customer.Telephone, 20);
  1834. oCustomersTransferAdd.Feild15 = @"";
  1835. oCustomersTransferAdd.Feild16 = Common.CutByteString(customer.FAX, 20);
  1836. oCustomersTransferAdd.Feild17 = @"";
  1837. oCustomersTransferAdd.Feild18 = @"";
  1838. oCustomersTransferAdd.Feild19 = @"";
  1839. oCustomersTransferAdd.Feild20 = @"";
  1840. oCustomersTransferAdd.Feild21 = @"";
  1841. oCustomersTransferAdd.Feild22 = @"";
  1842. oCustomersTransferAdd.Feild23 = Common.CutByteString(customer.Memo, 30);
  1843. oCustomersTransferAdd.Feild24 = @"100";
  1844. oCustomersTransferAdd.Feild25 = @"";
  1845. oCustomersTransferAdd.Feild26 = @"";
  1846. oCustomersTransferAdd.Feild27 = @"100";
  1847. oCustomersTransferAdd.Feild28 = @"";
  1848. oCustomersTransferAdd.Feild29 = Common.CutByteString(customer.CreateUser.Split('.')[0], 11);
  1849. oCustomersTransferAdd.Feild30 = @"";
  1850. oCustomersTransferAdd.Feild31 = @"";
  1851. oCustomersTransferAdd.Feild32 = @"";
  1852. oCustomersTransferAdd.Feild33 = @"";
  1853. oCustomersTransferAdd.Feild34 = @"";
  1854. oCustomersTransferAdd.Feild35 = @"";
  1855. oCustomersTransferAdd.Feild36 = @"";
  1856. oCustomersTransferAdd.Feild37 = @"B,C".IndexOf(customer.TransactionType) > -1 ? @"6" : @"5";
  1857. oCustomersTransferAdd.Feild38 = @"2";
  1858. oCustomersTransferAdd.Feild39 = @"";
  1859. oCustomersTransferAdd.Feild40 = @"";
  1860. oCustomersTransferAdd.Feild41 = @"1";
  1861. oCustomersTransferAdd.Feild42 = @"";
  1862. oCustomersTransferAdd.Feild43 = @"";
  1863. oCustomersTransferAdd.Feild44 = @"";
  1864. oCustomersTransferAdd.Feild45 = @"";
  1865. oCustomersTransferAdd.Feild46 = @"";
  1866. oCustomersTransferAdd.Feild47 = @"";
  1867. oCustomersTransferAdd.Feild48 = @"";
  1868. oCustomersTransferAdd.Feild49 = @"";
  1869. oCustomersTransferAdd.Feild50 = @"";
  1870. oCustomersTransferAdd.Feild51 = @"";
  1871. oCustomersTransferAdd.Feild52 = @"";
  1872. oCustomersTransferAdd.Feild53 = @"";
  1873. oCustomersTransferAdd.Feild54 = @"";
  1874. oCustomersTransferAdd.Feild55 = @"";
  1875. oCustomersTransferAdd.Feild56 = @"";
  1876. oCustomersTransferAdd.Feild57 = @"";
  1877. oCustomersTransferAdd.Feild58 = customer.CustomerNO;
  1878. oCustomersTransferAdd.Feild59 = @"";
  1879. oCustomersTransferAdd.Feild60 = @"";
  1880. oCustomersTransferAdd.Feild61 = @"";
  1881. oCustomersTransferAdd.Feild62 = @"";
  1882. oCustomersTransferAdd.Feild63 = @"";
  1883. oCustomersTransferAdd.Feild64 = @"";
  1884. oCustomersTransferAdd.Feild65 = @"";
  1885. oCustomersTransferAdd.Feild66 = @"";
  1886. oCustomersTransferAdd.Feild67 = @"";
  1887. oCustomersTransferAdd.Feild68 = @"";
  1888. oCustomersTransferAdd.Feild69 = @"";
  1889. oCustomersTransferAdd.Feild70 = @"";
  1890. oCustomersTransferAdd.Feild71 = @"";
  1891. oCustomersTransferAdd.Feild72 = @"";
  1892. oCustomersTransferAdd.Feild73 = @"";
  1893. oCustomersTransferAdd.Feild74 = @"";
  1894. oCustomersTransferAdd.Feild75 = @"";
  1895. oCustomersTransferAdd.Feild76 = @"";
  1896. oCustomersTransferAdd.Feild77 = @"";
  1897. oCustomersTransferAdd.Feild78 = @"";
  1898. oCustomersTransferAdd.Feild79 = @"";
  1899. oCustomersTransferAdd.Feild80 = @"";
  1900. oCustomersTransferAdd.Feild81 = @"";
  1901. oCustomersTransferAdd.Feild82 = Common.CutByteString(customer.CustomerEName, 120);
  1902. var sAddress = customer.Address;
  1903. var cn = new Regex(@"[一-龥]+");//正则表达式 表示汉字范围
  1904. if (cn.IsMatch(sAddress))
  1905. {
  1906. sAddress = @"";
  1907. }
  1908. oCustomersTransferAdd.Feild83 = Common.CutByteString(sAddress, 240);
  1909. oCustomersTransferAdd.Feild84 = @"";
  1910. oCustomersTransferAdd.Feild85 = @"";
  1911. oCustomersTransferAdd.Feild86 = @"";
  1912. oCustomersTransferAdd.Feild87 = @"";
  1913. oCustomersTransferAdd.Feild88 = @"";
  1914. oCustomersTransferAdd.Feild89 = @"";
  1915. oCustomersTransferAdd.Feild90 = @"";
  1916. oCustomersTransferAdd.Feild91 = @"0";
  1917. oCustomersTransferAdd.Feild92 = @"0";
  1918. oCustomersTransferAdd.Feild93 = @"";
  1919. oCustomersTransferAdd.Feild94 = @"";
  1920. oCustomersTransferAdd.Feild95 = @"";
  1921. oCustomersTransferAdd.Feild96 = @"";
  1922. oCustomersTransferAdd.Feild97 = @"";
  1923. oCustomersTransferAdd.Feild98 = @"";
  1924. oCustomersTransferAdd.Feild99 = @"";
  1925. db.Insertable(oCustomersTransferAdd).ExecuteCommand();
  1926. if (dicSucceccCount.Keys.Contains("客戶"))
  1927. {
  1928. dicSucceccCount["客戶"] = dicSucceccCount["客戶"] + 1;
  1929. }
  1930. else
  1931. {
  1932. dicSucceccCount.Add("客戶", 1);
  1933. }
  1934. }
  1935. #endregion
  1936. }
  1937. return sMsg;
  1938. }
  1939. public string GetObjectValue(JObject i_oJObject, string i_sColumn)
  1940. {
  1941. string sReturnValue = string.Empty;
  1942. if (i_oJObject[i_sColumn] != null)
  1943. {
  1944. sReturnValue = i_oJObject[i_sColumn].ToString();
  1945. }
  1946. return sReturnValue;
  1947. }
  1948. public bool StringConvertBool(string i_sValue)
  1949. {
  1950. bool blReturn = false;
  1951. bool.TryParse((i_sValue as string ?? string.Empty), out blReturn);
  1952. return blReturn;
  1953. }
  1954. }
  1955. }