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.

106 Zeilen
4.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. static void Main(string[] args)
  16. {
  17. FileActions.MakeDirectories();
  18. Ex365 exch = new Ex365("mcarman@prelub.com", "Gr@nt@cc3$$", "https://outlook.office365.com/ews/Exchange.asmx", Independentsoft.Exchange.StandardFolder.Inbox);
  19. List<EmailAttachment> pos = exch.GetPOs("United Rentals, Inc:");
  20. List<SalesOrder> sos = new List<SalesOrder>();
  21. WritePOsToDirectory(pos);
  22. try
  23. {
  24. var config = AcumaticaREST.Config("https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", null, null);
  25. foreach (EmailAttachment ea in pos)
  26. {
  27. try
  28. {
  29. List<string> lines = PDFHelper.PDFLinesToText(ea.FilePath);
  30. }
  31. catch (Exception lex)
  32. {
  33. ea.Errors.Add(string.Format("{0} {1} {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), lex.Message));
  34. }
  35. ea.SalesOrder = PDFHelper.PDFBuildSalesOrder(PDFHelper.PDFLinesToText(ea.FilePath));
  36. SalesOrder order = ea.SalesOrder;
  37. foreach (SalesOrderDetail detail in order.Details)
  38. {
  39. Dictionary<string, CustomField> inner = new Dictionary<string, CustomField>();
  40. CustomBooleanField b = new CustomBooleanField(true, "CustomBooleanField");
  41. inner.Add("AMProdCreate", b);
  42. detail.Custom = new Dictionary<string, Dictionary<string, CustomField>>();
  43. detail.Custom.Add("Transactions", inner);
  44. }
  45. AcumaticaREST.CreateSalesOrder(ref order, config, ea.FileName, ea.Content);
  46. ea.SalesOrder.OrderNbr = order.OrderNbr;
  47. ea.SalesOrder.ID = order.ID;
  48. //AcumaticaREST.UploadPurchaseOrder(config, ea.SalesOrder, "PurchaseOrder.pdf", ea.Content);
  49. int ln = 1;
  50. foreach (SalesOrderDetail detail in ea.SalesOrder.Details)
  51. {
  52. ProductionOrder prod = new ProductionOrder();
  53. prod.OrderType = "RO";
  54. prod.QtytoProduce = detail.OrderQty;
  55. prod.InventoryID = detail.InventoryID;
  56. prod.SOOrderNbr = order.OrderNbr;
  57. prod.SOOrderType = "SO";
  58. prod.SOLineNbr = detail.LineNbr;
  59. ln = ln + 1;
  60. AcumaticaREST.CreateProductionOrder(config, ref prod, "https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", null, null);
  61. ea.ProductionOrders.Add(prod);
  62. }
  63. }
  64. foreach (EmailAttachment ea in pos)
  65. {
  66. AcumaticaREST.ReleaseAndLinkProductionOrders(config, ea, "https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", null, null);
  67. }
  68. }
  69. catch (Exception exception)
  70. {
  71. Console.WriteLine(exception.Message);
  72. }
  73. finally
  74. {
  75. AcumaticaREST.APILogout("https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", null, null);
  76. }
  77. using (RestService service = new RestService("https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", "en_US"))
  78. {
  79. foreach (EmailAttachment ea in pos)
  80. {
  81. try
  82. {
  83. AcumaticaREST.PutFile(service, ea.SalesOrder, "https://rpmindustries.acumatica.com", "SO", ea.SalesOrder.OrderNbr.Value.ToString(), ea.FileName, ea.Content);
  84. }
  85. catch { }
  86. }
  87. }
  88. }
  89. static void WritePOsToDirectory(List<EmailAttachment> pos)
  90. {
  91. foreach (EmailAttachment obj in pos)
  92. {
  93. string path = Path.Combine(FileActions.Attachments, obj.FileName);
  94. if (!File.Exists(path))
  95. File.WriteAllBytes(path, obj.Content);
  96. Console.WriteLine(obj.FilePath);
  97. }
  98. }
  99. }
  100. }