|
|
|
@@ -13,16 +13,26 @@ namespace uri_import |
|
|
|
{
|
|
|
|
class Program
|
|
|
|
{
|
|
|
|
public static Common Cmn { get; set; }
|
|
|
|
static void Main(string[] args)
|
|
|
|
{
|
|
|
|
Cmn = JSONActions.ReadSettings("settings.json");
|
|
|
|
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>();
|
|
|
|
WritePOsToDirectory(pos);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
@@ -32,7 +42,10 @@ namespace uri_import |
|
|
|
}
|
|
|
|
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));
|
|
|
|
SalesOrder order = ea.SalesOrder;
|
|
|
|
@@ -49,7 +62,6 @@ namespace uri_import |
|
|
|
AcumaticaREST.CreateSalesOrder(ref order, config, ea.FileName, ea.Content);
|
|
|
|
ea.SalesOrder.OrderNbr = order.OrderNbr;
|
|
|
|
ea.SalesOrder.ID = order.ID;
|
|
|
|
//AcumaticaREST.UploadPurchaseOrder(config, ea.SalesOrder, "PurchaseOrder.pdf", ea.Content);
|
|
|
|
int ln = 1;
|
|
|
|
foreach (SalesOrderDetail detail in ea.SalesOrder.Details)
|
|
|
|
{
|
|
|
|
@@ -61,13 +73,27 @@ namespace uri_import |
|
|
|
prod.SOOrderType = "SO";
|
|
|
|
prod.SOLineNbr = detail.LineNbr;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
@@ -76,15 +102,30 @@ namespace uri_import |
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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 { }
|
|
|
|
}
|
|
|
|
@@ -95,9 +136,11 @@ namespace uri_import |
|
|
|
{
|
|
|
|
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))
|
|
|
|
File.WriteAllBytes(path, obj.Content);
|
|
|
|
File.WriteAllBytes(path,
|
|
|
|
obj.Content);
|
|
|
|
Console.WriteLine(obj.FilePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|