| @@ -0,0 +1,28 @@ | |||||
| namespace uri_import | |||||
| { | |||||
| public class Common | |||||
| { | |||||
| public EmailSettings Email { get; set; } | |||||
| public AcumaticaSettings Acumatica { get; set; } | |||||
| } | |||||
| public class EmailSettings | |||||
| { | |||||
| public string Username { get; set; } | |||||
| public string Password { get; set; } | |||||
| public int Mailbox { get; set; } | |||||
| public string Url { get; set; } | |||||
| public string Filter { get; set; } | |||||
| } | |||||
| public class AcumaticaSettings | |||||
| { | |||||
| public string Url { get; set; } | |||||
| public string Username { get; set; } | |||||
| public string Password { get; set; } | |||||
| public string Tenant { get; set; } | |||||
| public string Branch { get; set; } | |||||
| public string Locale { get; set; } | |||||
| } | |||||
| } | |||||
| @@ -1,4 +1,4 @@ | |||||
| using System.IO; | |||||
| using System.Net; | using System.Net; | ||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| @@ -22,7 +22,7 @@ namespace uri_import.EClasses | |||||
| public Ex365(string username, string password) | public Ex365(string username, string password) | ||||
| { | { | ||||
| _credential = new NetworkCredential(username, password); | _credential = new NetworkCredential(username, password); | ||||
| _service = new Service("https://outlook.office365.com/ews/Exchange.asmx", _credential); | |||||
| _service = new Service(Program.Cmn.Email.Url, _credential); | |||||
| } | } | ||||
| public Ex365(string username, string password, string url) | public Ex365(string username, string password, string url) | ||||
| @@ -42,7 +42,7 @@ namespace uri_import.EClasses | |||||
| int index = 1; | int index = 1; | ||||
| List<EmailAttachment> list = new List<EmailAttachment>(); | List<EmailAttachment> list = new List<EmailAttachment>(); | ||||
| IsEqualTo restriction = new IsEqualTo(MessagePropertyPath.HasAttachments, hasAttachment); | IsEqualTo restriction = new IsEqualTo(MessagePropertyPath.HasAttachments, hasAttachment); | ||||
| Contains subFilter = new Contains(MessagePropertyPath.Subject, "United Rentals, Inc:", ContainmentMode.Prefixed, ContainmentComparison.IgnoreCase); | |||||
| Contains subFilter = new Contains(MessagePropertyPath.Subject, Program.Cmn.Email.Filter, ContainmentMode.Prefixed, ContainmentComparison.IgnoreCase); | |||||
| ItemShape itemShape = new ItemShape(ShapeType.Id); | ItemShape itemShape = new ItemShape(ShapeType.Id); | ||||
| FindItemResponse response = _service.FindItem(StandardFolder.Inbox, itemShape, subFilter); | FindItemResponse response = _service.FindItem(StandardFolder.Inbox, itemShape, subFilter); | ||||
| for (int i = 0; i < response.Items.Count; i++) | for (int i = 0; i < response.Items.Count; i++) | ||||
| @@ -107,8 +107,8 @@ namespace uri_import.EClasses | |||||
| public SalesOrder SalesOrder { get; set; } | public SalesOrder SalesOrder { get; set; } | ||||
| public string SalesOrderNumber { get; set; } | public string SalesOrderNumber { get; set; } | ||||
| public List<ProductionOrder> ProductionOrders { get { return _productionOrders; } set { _productionOrders = value; } } | public List<ProductionOrder> ProductionOrders { get { return _productionOrders; } set { _productionOrders = value; } } | ||||
| public bool Released { get{return _released;} set{_released = value;}} | |||||
| public bool Linked { get{return _linked;} set{_linked = value;}} | |||||
| public bool Released { get { return _released; } set { _released = value; } } | |||||
| public bool Linked { get { return _linked; } set { _linked = value; } } | |||||
| public List<string> Errors { get { return _errors; } set { _errors = value; } } | public List<string> Errors { get { return _errors; } set { _errors = value; } } | ||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,17 @@ | |||||
| using Newtonsoft.Json; | |||||
| using System.IO; | |||||
| namespace uri_import | |||||
| { | |||||
| public class JSONActions | |||||
| { | |||||
| public static Common ReadSettings(string file) | |||||
| { | |||||
| string text = File.ReadAllText(file); | |||||
| Common c = JsonConvert.DeserializeObject<Common>(text); | |||||
| return c; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -13,16 +13,26 @@ namespace uri_import | |||||
| { | { | ||||
| class Program | class Program | ||||
| { | { | ||||
| public static Common Cmn { get; set; } | |||||
| static void Main(string[] args) | static void Main(string[] args) | ||||
| { | { | ||||
| Cmn = JSONActions.ReadSettings("settings.json"); | |||||
| FileActions.MakeDirectories(); | FileActions.MakeDirectories(); | ||||
| Ex365 exch = new Ex365("mcarman@prelub.com", "Gr@nt@cc3$$", "https://outlook.office365.com/ews/Exchange.asmx", Independentsoft.Exchange.StandardFolder.Inbox); | |||||
| List<EmailAttachment> pos = exch.GetPOs("United Rentals, Inc:"); | |||||
| Ex365 exch = new Ex365(Cmn.Email.Username, | |||||
| Cmn.Email.Password, | |||||
| Cmn.Email.Url, | |||||
| (Independentsoft.Exchange.StandardFolder)Cmn.Email.Mailbox); | |||||
| List<EmailAttachment> pos = exch.GetPOs(Cmn.Email.Filter); | |||||
| List<SalesOrder> sos = new List<SalesOrder>(); | List<SalesOrder> sos = new List<SalesOrder>(); | ||||
| WritePOsToDirectory(pos); | WritePOsToDirectory(pos); | ||||
| try | try | ||||
| { | { | ||||
| var config = AcumaticaREST.Config("https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", null, null); | |||||
| var config = AcumaticaREST.Config(Cmn.Acumatica.Url, | |||||
| Cmn.Acumatica.Username, | |||||
| Cmn.Acumatica.Password, | |||||
| Cmn.Acumatica.Tenant, | |||||
| null, | |||||
| null); | |||||
| foreach (EmailAttachment ea in pos) | foreach (EmailAttachment ea in pos) | ||||
| { | { | ||||
| @@ -32,7 +42,10 @@ namespace uri_import | |||||
| } | } | ||||
| catch (Exception lex) | catch (Exception lex) | ||||
| { | { | ||||
| ea.Errors.Add(string.Format("{0} {1} {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), lex.Message)); | |||||
| ea.Errors.Add(string.Format("{0} {1} {2}", | |||||
| DateTime.Now.ToShortDateString(), | |||||
| DateTime.Now.ToShortTimeString(), | |||||
| lex.Message)); | |||||
| } | } | ||||
| ea.SalesOrder = PDFHelper.PDFBuildSalesOrder(PDFHelper.PDFLinesToText(ea.FilePath)); | ea.SalesOrder = PDFHelper.PDFBuildSalesOrder(PDFHelper.PDFLinesToText(ea.FilePath)); | ||||
| SalesOrder order = ea.SalesOrder; | SalesOrder order = ea.SalesOrder; | ||||
| @@ -49,7 +62,6 @@ namespace uri_import | |||||
| AcumaticaREST.CreateSalesOrder(ref order, config, ea.FileName, ea.Content); | AcumaticaREST.CreateSalesOrder(ref order, config, ea.FileName, ea.Content); | ||||
| ea.SalesOrder.OrderNbr = order.OrderNbr; | ea.SalesOrder.OrderNbr = order.OrderNbr; | ||||
| ea.SalesOrder.ID = order.ID; | ea.SalesOrder.ID = order.ID; | ||||
| //AcumaticaREST.UploadPurchaseOrder(config, ea.SalesOrder, "PurchaseOrder.pdf", ea.Content); | |||||
| int ln = 1; | int ln = 1; | ||||
| foreach (SalesOrderDetail detail in ea.SalesOrder.Details) | foreach (SalesOrderDetail detail in ea.SalesOrder.Details) | ||||
| { | { | ||||
| @@ -61,13 +73,27 @@ namespace uri_import | |||||
| prod.SOOrderType = "SO"; | prod.SOOrderType = "SO"; | ||||
| prod.SOLineNbr = detail.LineNbr; | prod.SOLineNbr = detail.LineNbr; | ||||
| ln = ln + 1; | ln = ln + 1; | ||||
| AcumaticaREST.CreateProductionOrder(config, ref prod, "https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", null, null); | |||||
| AcumaticaREST.CreateProductionOrder(config, | |||||
| ref prod, | |||||
| Cmn.Acumatica.Url, | |||||
| Cmn.Acumatica.Username, | |||||
| Cmn.Acumatica.Password, | |||||
| Cmn.Acumatica.Tenant, | |||||
| null, | |||||
| null); | |||||
| ea.ProductionOrders.Add(prod); | ea.ProductionOrders.Add(prod); | ||||
| } | } | ||||
| } | } | ||||
| foreach (EmailAttachment ea in pos) | foreach (EmailAttachment ea in pos) | ||||
| { | { | ||||
| AcumaticaREST.ReleaseAndLinkProductionOrders(config, ea, "https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", null, null); | |||||
| AcumaticaREST.ReleaseAndLinkProductionOrders(config, | |||||
| ea, | |||||
| Cmn.Acumatica.Url, | |||||
| Cmn.Acumatica.Username, | |||||
| Cmn.Acumatica.Password, | |||||
| Cmn.Acumatica.Tenant, | |||||
| null, | |||||
| null); | |||||
| } | } | ||||
| } | } | ||||
| catch (Exception exception) | catch (Exception exception) | ||||
| @@ -76,15 +102,30 @@ namespace uri_import | |||||
| } | } | ||||
| finally | finally | ||||
| { | { | ||||
| AcumaticaREST.APILogout("https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", null, null); | |||||
| AcumaticaREST.APILogout(Cmn.Acumatica.Url, | |||||
| Cmn.Acumatica.Username, | |||||
| Cmn.Acumatica.Password, | |||||
| Cmn.Acumatica.Tenant, | |||||
| null, | |||||
| null); | |||||
| } | } | ||||
| using (RestService service = new RestService("https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", "en_US")) | |||||
| using (RestService service = new RestService(Cmn.Acumatica.Url, | |||||
| Cmn.Acumatica.Username, | |||||
| Cmn.Acumatica.Password, | |||||
| Cmn.Acumatica.Tenant, | |||||
| Cmn.Acumatica.Locale)) | |||||
| { | { | ||||
| foreach (EmailAttachment ea in pos) | foreach (EmailAttachment ea in pos) | ||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| AcumaticaREST.PutFile(service, ea.SalesOrder, "https://rpmindustries.acumatica.com", "SO", ea.SalesOrder.OrderNbr.Value.ToString(), ea.FileName, ea.Content); | |||||
| AcumaticaREST.PutFile(service, | |||||
| ea.SalesOrder, | |||||
| Cmn.Acumatica.Url, | |||||
| "SO", | |||||
| ea.SalesOrder.OrderNbr.Value.ToString(), | |||||
| ea.FileName, | |||||
| ea.Content); | |||||
| } | } | ||||
| catch { } | catch { } | ||||
| } | } | ||||
| @@ -95,9 +136,11 @@ namespace uri_import | |||||
| { | { | ||||
| foreach (EmailAttachment obj in pos) | foreach (EmailAttachment obj in pos) | ||||
| { | { | ||||
| string path = Path.Combine(FileActions.Attachments, obj.FileName); | |||||
| string path = Path.Combine(FileActions.Attachments, | |||||
| obj.FileName); | |||||
| if (!File.Exists(path)) | if (!File.Exists(path)) | ||||
| File.WriteAllBytes(path, obj.Content); | |||||
| File.WriteAllBytes(path, | |||||
| obj.Content); | |||||
| Console.WriteLine(obj.FilePath); | Console.WriteLine(obj.FilePath); | ||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,17 @@ | |||||
| { | |||||
| "Email": { | |||||
| "Username": "mcarman", | |||||
| "Password": "Gr@nt@cc3$$", | |||||
| "Mailbox": 4, | |||||
| "Url": "https://outlook.office365.com/ews/Exchange.asmx", | |||||
| "Filter": "United Rentals, Inc:" | |||||
| }, | |||||
| "Acumatica": { | |||||
| "Url": "https://rpmindustries.acumatica.com", | |||||
| "Username": "bryckman", | |||||
| "Password": "Washington1", | |||||
| "Tenant": "RPM SANDBOX", | |||||
| "Branch": null, | |||||
| "Locale": "en_US" | |||||
| } | |||||
| } | |||||
| @@ -14,6 +14,7 @@ | |||||
| "Acumatica.SOAPLikeWrapperForREST": "2.2.0", | "Acumatica.SOAPLikeWrapperForREST": "2.2.0", | ||||
| "Independentsoft.Exchange": "3.0.700", | "Independentsoft.Exchange": "3.0.700", | ||||
| "Microsoft.AspNet.WebApi.Client": "5.2.9", | "Microsoft.AspNet.WebApi.Client": "5.2.9", | ||||
| "Newtonsoft.Json": "13.0.1", | |||||
| "iTextSharp": "5.5.13.3" | "iTextSharp": "5.5.13.3" | ||||
| }, | }, | ||||
| "runtime": { | "runtime": { | ||||
| @@ -1 +1 @@ | |||||
| 4e4c11c4c71f46c18965a424b9f9a1438c6d22fe | |||||
| 78d01467e9e3cc497ef927b78a1d505298ac0fad | |||||
| @@ -56,3 +56,4 @@ | |||||
| /Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/obj/Debug/net6.0/uri_import.pdb | /Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/obj/Debug/net6.0/uri_import.pdb | ||||
| /Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/obj/Debug/net6.0/uri_import.genruntimeconfig.cache | /Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/obj/Debug/net6.0/uri_import.genruntimeconfig.cache | ||||
| /Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/obj/Debug/net6.0/ref/uri_import.dll | /Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/obj/Debug/net6.0/ref/uri_import.dll | ||||
| /Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/bin/Debug/net6.0/settings.json | |||||
| @@ -16929,6 +16929,7 @@ | |||||
| "Acumatica.SOAPLikeWrapperForREST >= 2.2.0", | "Acumatica.SOAPLikeWrapperForREST >= 2.2.0", | ||||
| "Independentsoft.Exchange >= 3.0.700", | "Independentsoft.Exchange >= 3.0.700", | ||||
| "Microsoft.AspNet.WebApi.Client >= 5.2.9", | "Microsoft.AspNet.WebApi.Client >= 5.2.9", | ||||
| "Newtonsoft.Json >= 13.0.1", | |||||
| "iTextSharp >= 5.5.13.3" | "iTextSharp >= 5.5.13.3" | ||||
| ] | ] | ||||
| }, | }, | ||||
| @@ -16997,6 +16998,10 @@ | |||||
| "target": "Package", | "target": "Package", | ||||
| "version": "[5.2.9, )" | "version": "[5.2.9, )" | ||||
| }, | }, | ||||
| "Newtonsoft.Json": { | |||||
| "target": "Package", | |||||
| "version": "[13.0.1, )" | |||||
| }, | |||||
| "iTextSharp": { | "iTextSharp": { | ||||
| "target": "Package", | "target": "Package", | ||||
| "version": "[5.5.13.3, )" | "version": "[5.5.13.3, )" | ||||
| @@ -1,6 +1,6 @@ | |||||
| { | { | ||||
| "version": 2, | "version": 2, | ||||
| "dgSpecHash": "B4b8ZmD30OLjaqk4Q6OPh7+OqtVFjvXbHsidJuIJoVxkqWHyCbX6HwI1svFaWxIyFFyRcegok5GCYMGmnGfDCg==", | |||||
| "dgSpecHash": "7WpKbFkHS/s7tOD5MbhBm5xnUQv3bAyqqClFUIT5edY5sOGg/XhzW7kt2OeNB6fPvlsbV7mnaXN0z+1a7bMP0g==", | |||||
| "success": true, | "success": true, | ||||
| "projectFilePath": "/Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/uri_import.csproj", | "projectFilePath": "/Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/uri_import.csproj", | ||||
| "expectedPackageFiles": [ | "expectedPackageFiles": [ | ||||
| @@ -65,6 +65,10 @@ | |||||
| "target": "Package", | "target": "Package", | ||||
| "version": "[5.2.9, )" | "version": "[5.2.9, )" | ||||
| }, | }, | ||||
| "Newtonsoft.Json": { | |||||
| "target": "Package", | |||||
| "version": "[13.0.1, )" | |||||
| }, | |||||
| "iTextSharp": { | "iTextSharp": { | ||||
| "target": "Package", | "target": "Package", | ||||
| "version": "[5.5.13.3, )" | "version": "[5.5.13.3, )" | ||||
| @@ -0,0 +1,17 @@ | |||||
| { | |||||
| "Email": { | |||||
| "Username": "mcarman", | |||||
| "Password": "Gr@nt@cc3$$", | |||||
| "Mailbox": 4, | |||||
| "Url": "https://outlook.office365.com/ews/Exchange.asmx", | |||||
| "Filter": "United Rentals, Inc:" | |||||
| }, | |||||
| "Acumatica": { | |||||
| "Url": "https://rpmindustries.acumatica.com", | |||||
| "Username": "bryckman", | |||||
| "Password": "Washington1", | |||||
| "Tenant": "RPM SANDBOX", | |||||
| "Branch": null, | |||||
| "Locale": "en_US" | |||||
| } | |||||
| } | |||||
| @@ -13,7 +13,10 @@ | |||||
| <PackageReference Include="Independentsoft.Exchange" Version="3.0.700" /> | <PackageReference Include="Independentsoft.Exchange" Version="3.0.700" /> | ||||
| <PackageReference Include="iTextSharp" Version="5.5.13.3" /> | <PackageReference Include="iTextSharp" Version="5.5.13.3" /> | ||||
| <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" /> | <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" /> | ||||
| <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | |||||
| <Content Include="*.json"> | |||||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||||
| </Content> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| </Project> | </Project> | ||||