Project files for the Acumatica Import for United Rentals
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

149 Zeilen
5.8 KiB

  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using uri_import.EClasses;
  5. using uri_import.FClasses;
  6. using uri_import.AClasses;
  7. using uri_import.PClasses;
  8. using Acumatica.Default_20_200_001.Model;
  9. using Acumatica.Manufacturing_21_200_001.Model;
  10. using Acumatica.RESTClient.Model;
  11. namespace uri_import
  12. {
  13. class Program
  14. {
  15. public static Common Cmn { get; set; }
  16. static void Main(string[] args)
  17. {
  18. Cmn = JSONActions.ReadSettings("settings.json");
  19. FileActions.MakeDirectories();
  20. Ex365 exch = new Ex365(Cmn.Email.Username,
  21. Cmn.Email.Password,
  22. Cmn.Email.Url,
  23. (Independentsoft.Exchange.StandardFolder)Cmn.Email.Mailbox);
  24. List<EmailAttachment> pos = exch.GetPOs(Cmn.Email.Filter);
  25. List<SalesOrder> sos = new List<SalesOrder>();
  26. WritePOsToDirectory(pos);
  27. try
  28. {
  29. var config = AcumaticaREST.Config(Cmn.Acumatica.Url,
  30. Cmn.Acumatica.Username,
  31. Cmn.Acumatica.Password,
  32. Cmn.Acumatica.Tenant,
  33. null,
  34. null);
  35. foreach (EmailAttachment ea in pos)
  36. {
  37. try
  38. {
  39. List<string> lines = PDFHelper.PDFLinesToText(ea.FilePath);
  40. }
  41. catch (Exception lex)
  42. {
  43. ea.Errors.Add(string.Format("{0} {1} {2}",
  44. DateTime.Now.ToShortDateString(),
  45. DateTime.Now.ToShortTimeString(),
  46. lex.Message));
  47. }
  48. ea.SalesOrder = PDFHelper.PDFBuildSalesOrder(PDFHelper.PDFLinesToText(ea.FilePath));
  49. SalesOrder order = ea.SalesOrder;
  50. foreach (SalesOrderDetail detail in order.Details)
  51. {
  52. Dictionary<string, CustomField> inner = new Dictionary<string, CustomField>();
  53. CustomBooleanField b = new CustomBooleanField(true, "CustomBooleanField");
  54. inner.Add("AMProdCreate", b);
  55. detail.Custom = new Dictionary<string, Dictionary<string, CustomField>>();
  56. detail.Custom.Add("Transactions", inner);
  57. }
  58. AcumaticaREST.CreateSalesOrder(ref order, config, ea.FileName, ea.Content);
  59. ea.SalesOrder.OrderNbr = order.OrderNbr;
  60. ea.SalesOrder.ID = order.ID;
  61. int ln = 1;
  62. foreach (SalesOrderDetail detail in ea.SalesOrder.Details)
  63. {
  64. ProductionOrder prod = new ProductionOrder();
  65. prod.OrderType = "RO";
  66. prod.QtytoProduce = detail.OrderQty;
  67. prod.InventoryID = detail.InventoryID;
  68. prod.SOOrderNbr = order.OrderNbr;
  69. prod.SOOrderType = "SO";
  70. prod.SOLineNbr = detail.LineNbr;
  71. ln = ln + 1;
  72. AcumaticaREST.CreateProductionOrder(config,
  73. ref prod,
  74. Cmn.Acumatica.Url,
  75. Cmn.Acumatica.Username,
  76. Cmn.Acumatica.Password,
  77. Cmn.Acumatica.Tenant,
  78. null,
  79. null);
  80. ea.ProductionOrders.Add(prod);
  81. }
  82. }
  83. foreach (EmailAttachment ea in pos)
  84. {
  85. AcumaticaREST.ReleaseAndLinkProductionOrders(config,
  86. ea,
  87. Cmn.Acumatica.Url,
  88. Cmn.Acumatica.Username,
  89. Cmn.Acumatica.Password,
  90. Cmn.Acumatica.Tenant,
  91. null,
  92. null);
  93. }
  94. }
  95. catch (Exception exception)
  96. {
  97. Console.WriteLine(exception.Message);
  98. }
  99. finally
  100. {
  101. AcumaticaREST.APILogout(Cmn.Acumatica.Url,
  102. Cmn.Acumatica.Username,
  103. Cmn.Acumatica.Password,
  104. Cmn.Acumatica.Tenant,
  105. null,
  106. null);
  107. }
  108. using (RestService service = new RestService(Cmn.Acumatica.Url,
  109. Cmn.Acumatica.Username,
  110. Cmn.Acumatica.Password,
  111. Cmn.Acumatica.Tenant,
  112. Cmn.Acumatica.Locale))
  113. {
  114. foreach (EmailAttachment ea in pos)
  115. {
  116. try
  117. {
  118. AcumaticaREST.PutFile(service,
  119. ea.SalesOrder,
  120. Cmn.Acumatica.Url,
  121. "SO",
  122. ea.SalesOrder.OrderNbr.Value.ToString(),
  123. ea.FileName,
  124. ea.Content);
  125. }
  126. catch { }
  127. }
  128. }
  129. }
  130. static void WritePOsToDirectory(List<EmailAttachment> pos)
  131. {
  132. foreach (EmailAttachment obj in pos)
  133. {
  134. string path = Path.Combine(FileActions.Attachments,
  135. obj.FileName);
  136. if (!File.Exists(path))
  137. File.WriteAllBytes(path,
  138. obj.Content);
  139. Console.WriteLine(obj.FilePath);
  140. }
  141. }
  142. }
  143. }