Last active
March 21, 2023 18:14
-
-
Save patrick711/fb3e762aae893b4152aad19e6ab072e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SPS_OrderToCashSetup : CustomizationPlugin | |
{ | |
//This method executed right after website files were updated, but before website was restarted | |
//Method invoked on each cluster node in cluster environment | |
//Method invoked only if runtimecompilation is enabled | |
//Do not access custom code published to bin folder, it may not be loaded yet | |
public override void OnPublished() | |
{ | |
this.WriteLog("OnPublished Event"); | |
} | |
//This method executed after customization was published and website was restarted. | |
public override void UpdateDatabase() | |
{ | |
this.WriteLog("UpdateDatabase Event"); | |
#region SPSCommerce EDI Setup | |
#region Set Credentials | |
this.WriteLog("Enter credentials"); | |
ISPSConnSetup graph = PXGraph.CreateInstance<Mapadoc.ISPSConnSetup>(); | |
ISPSConn myConn = graph.connection.Select(); | |
if (myConn == null) | |
myConn = new ISPSConn(); | |
myConn.URL = "https://externalsite.com/"; | |
myConn.CustomerID = "TestingCredential"; | |
myConn.Password = "Password"; | |
graph.connection.Update(myConn); | |
graph.Actions.PressSave(); | |
#endregion | |
#region Set Permissions | |
this.WriteLog("Set Permissions"); | |
ISPSConngraph connectionMgr = PXGraph.CreateInstance<ISPSConngraph>(); | |
ISPSCustomerSettings my_settings = connectionMgr.settings.Select(); | |
if (my_settings == null) | |
my_settings = new ISPSCustomerSettings(); | |
my_settings.OutboundInventoryAdviceEnabled = true; | |
connectionMgr.settings.Update(my_settings); | |
connectionMgr.Actions.PressSave(); | |
#endregion | |
#endregion | |
#region SPSCommerce Demo Data Setup | |
var graph = PXGraph.CreateInstance<Mapadoc.ISPSInbound850RcvProcess>(); | |
var list = graph.orders.Select().RowCast<ISPSSOOrder>().ToList(); | |
this.WriteLog(list.Count() + " Record(s) found"); | |
if (!list.Where(x => x.ErrorStatus == "Ok" || x.ErrorStatus == "Warning").Any()) | |
{ | |
this.WriteLog("No Records Ready for testing"); | |
var docList = PXSelect<ISPSSOOrder, Where<ISPSSOOrder.imported, Equal<True>>>.Select(graph).RowCast<ISPSSOOrder>().ToList(); | |
if (docList.Any()) | |
{ | |
this.WriteLog("Update previously imported Records"); | |
foreach (var item in docList) | |
{ | |
item.Imported = 0; | |
graph.orders.Update(item); | |
} | |
graph.Persist(); | |
} | |
else | |
{ | |
this.WriteLog("Create New Records"); | |
CreateSOHeaders(graph); | |
CreateSOOrderLog(graph); | |
CreateSOLines(graph); | |
CreateSOCharges(graph); | |
CreateShipToContact(graph); | |
CreateAddress(graph); | |
graph.Persist(); | |
} | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment