IO-227 Succesful export of PPG information.

This commit is contained in:
Patrick Fic
2022-01-18 15:00:27 -08:00
parent d7cde2be37
commit 926f20ba0a
17 changed files with 214 additions and 38 deletions

View File

@@ -79,6 +79,17 @@ namespace BodyshopPartner.Utils
(req, res, props) => { HandleOec(req, res); }
, "POST");
Route.Add("/paintscale/export/", (req, res, props) =>
{
hlog("Received a Paint Scale Export Request");
res.WithCORS();
res.Close();
}, "OPTIONS");
Route.Add("/paintscale/export/",
(req, res, props) => {
hlog("Received a Paint Scale Export Request");
HandlePaintScaleExport(req, res); }
, "POST");
logger.Trace("Starting HTTP server...");
hlog = HttpLogger;
@@ -223,14 +234,14 @@ namespace BodyshopPartner.Utils
{
//Do the scan
//Add the items to the response list.
await JobProcessingQueue.UploadJob(new DTO_QueueItem() { FilePath = requestBody.filepath });
await JobProcessingQueue.UploadJob(new DTO_QueueItem() { FilePath = requestBody.filepath });
HttpResponse.Add("success", true);
}
catch (Exception Ex)
{
logger.Error(Ex, "Error encountered while handling import requests.");
hlog("Error encountered while handling import requests.");
HttpResponse.Add("success" , false);
HttpResponse.Add("success", false);
HttpResponse.Add("error", Ex.ToString());
}
res.WithCORS().AsText(JsonConvert.SerializeObject(HttpResponse));
@@ -256,7 +267,7 @@ namespace BodyshopPartner.Utils
body.Close();
reader.Close();
return JsonConvert.DeserializeObject(s);
return JsonConvert.DeserializeObject(s);
}
public static List<QbRequestItem> ParseRequest(System.Net.HttpListenerRequest req)
@@ -298,6 +309,10 @@ namespace BodyshopPartner.Utils
return XDocument.Parse(input);
}
private static async void HandlePaintScaleExport(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res)
{
await Utils.PPGMixData.PushDataToPPG();
res.WithCORS().AsText("OK");
}
}
}

View File

@@ -6,7 +6,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.IO;
namespace BodyshopPartner.Utils
{
@@ -17,6 +17,7 @@ namespace BodyshopPartner.Utils
bodyshops_by_pk(id:$shopid) {
id
shopname
imexshopid
}
jobs(where: {_or: [{_and: [{scheduled_in: {_lte: $todayplus5}}, {scheduled_in: {_gte: $today}}]}, {inproduction: {_eq: true}}]}) {
id
@@ -37,6 +38,9 @@ namespace BodyshopPartner.Utils
rate_mapa
rate_lab
job_totals
vehicle{
v_paint_codes
}
labhrs: joblines_aggregate(where: {mod_lbr_ty: {_neq: ""LAR""}, removed: {_eq: false}}) {
aggregate {
sum {
@@ -81,15 +85,21 @@ namespace BodyshopPartner.Utils
new XElement("PPG",
new XElement("Header",
new XElement("Protocol", new XElement("Message", "PaintShopInterface"), new XElement("Name", "PPG"), new XElement("Version", "1.5.0")),
new XElement("Transaction", new XElement("TransactionDate", new DateTime().ToString("yyyy-MM-DDTHH:MM:SS"))),
new XElement("Product", new XElement("Name", data?.bodyshop_by_pk?.paintshopid))
new XElement("Transaction",
new XElement("TransactionID", null),
new XElement("TransactionDate", DateTime.Now.ToString("yyyy-MM-hh:mm:ss"))
),
new XElement("Product",
new XElement("Name", "ImEX Online"),
new XElement("Version", null)
)
),
new XElement("DataInterface",
new XElement("ROData",
new XElement("ShopInfo",
new XElement("ShopID", data?.bodyshop_by_pk?.shopname),
new XElement("ShopName", data?.bodyshop_by_pk?.shopname)
new XElement("ShopID", data?.bodyshops_by_pk?.imexshopid?.Value),
new XElement("ShopName", data?.bodyshops_by_pk?.shopname?.Value)
),
new XElement("RepairOrders",
new XElement("ROCount", data?.jobs?.Count)
@@ -99,11 +109,12 @@ namespace BodyshopPartner.Utils
)
);
foreach(dynamic job in data.jobs)
foreach (dynamic job in data.jobs)
{
doc.Element("PPG").Element("DataInterface").Element("ROData").Element("RepairOrders").Add(new XElement("RO",
doc.Element("PPG").Element("DataInterface").Element("ROData").Element("RepairOrders").Add(new XElement("RO",
new XElement("RONumber", job.ro_number?.Value),
new XElement("ROStatus", job.status?.Value),
new XElement("ROStatus", "Open"),
new XElement("Customer", $"{job.ownr_ln}, {job.ownr_fn}"),
new XElement("ROPainterNotes", ""),
new XElement("LicensePlateNum", job.plate_no?.Value),
@@ -111,33 +122,31 @@ namespace BodyshopPartner.Utils
new XElement("ModelYear", job.v_model_yr?.Value),
new XElement("MakeDesc", job.v_make_desc?.Value),
new XElement("ModelName", job.v_model_desc?.Value),
// new XElement("OEMColorCode", job.vehicle?.colorcode),
new XElement("OEMColorCode", job.vehicle?.v_paint_codes?.paint_cd1?.Value),
new XElement("RefinishLaborHours", job.larhrs?.aggregate?.sum.mod_lb_hrs?.Value),
new XElement("InsuranceCompanyName", job.ins_co_nm?.Value),
new XElement("EstimatorName", $"{job.est_ct_ln}, {job.est_ct_fn}"),
new XElement("PaintMaterialsRevenue", 0),
new XElement("PaintMaterialsRevenue", ((float)(job.job_totals?.rates?.mapa?.total?.amount?.Value ?? 0)) / 100),
new XElement("PaintMaterialsRate", job.rate_mapa?.Value),
new XElement("BodyHours", job.labhrs?.aggregate.sum?.mod_lb_hrs?.Value),
new XElement("BodyLaborRate", job.rate_lab?.Value)
//new XElement("TotalCostOfRepairs", job.job_total.totals.subtotal.amount?.Value / 100)
new XElement("BodyLaborRate", job.rate_lab?.Value),
new XElement("TotalCostOfRepairs", ((float)(job.job_totals?.totals?.subtotal?.amount?.Value ?? 0)) / 100)
));
}
Directory.CreateDirectory(Properties.Settings.Default.PaintScalePath);
doc.Save(@"C:\\VPS\\doc.xml");
// doc.Save(Properties.Settings.Default.PaintScalePath);
//Ensure all values for strings are escaped.
doc.Save(Properties.Settings.Default.PaintScalePath + @"\PPGPaint.xml");
//Write the file to the disk and start the timer again.
}
catch (Exception ex)
{
logger.Error(ex);
logger.Error(ex, "Error while pushing data to PPG paint scale.");
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32.TaskScheduler;
namespace BodyshopPartner.Utils
{
public static class PaintScaleConfig
{
private static string workingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public static void RegisterScheduledTask()
{
try
{
Microsoft.Win32.TaskScheduler.Task existingTask = TaskService.Instance.FindTask("ImEX Online Partner - Paint Scale Connection");
if(existingTask != null)
{
TaskService.Instance.RootFolder.DeleteTask("ImEX Online Partner - Paint Scale Connection");
}
Microsoft.Win32.TaskScheduler.Task newTask = TaskService.Instance.AddTask("ImEX Online Partner - Paint Scale Connection", QuickTriggerType.Hourly, "powershell.exe", @"-ExecutionPolicy Bypass -File " + workingDirectory + @"\Utils\Scripts\PaintScaleExport.ps1");
newTask.Run();
}
catch(Exception ex)
{
logger.Error(ex, "Error when trying to register scheduled task.");
}
}
}
}

View File

@@ -0,0 +1,32 @@
#Verify that the partner is running. If not, strat it.
if((Get-Process -Name ImEXOnlinePartner -ErrorAction SilentlyContinue) -eq $null){
& "$Env:USERPROFILE\AppData\Local\ImEXOnlinePartner\ImEXOnlinePartner.exe"
}
$PSversion = $PSVersionTable.PSVersion.Major
function v2 {
# Post request to the partner to trigger the export.
Invoke-WebRequest -Uri http://localhost:1337/paintscale/export/ -Method POST
}
function v1 {
WebRequest = [System.Net.WebRequest]::Create("http://localhost:1337/paintscale/export/")
WebRequest.Method = "POST"
WebRequest.ContentType = "application/json"
Response = $WebRequest.GetResponse()
ResponseStream = $Response.GetResponseStream()
ReadStream = New-Object System.IO.StreamReader $ResponseStream
#Data=$ReadStream.ReadToEnd()
}
Switch ($PSversion) {
1 {v1}
2 {v1}
4 {v2}
5 {v2}
6 {v2}
}

View File

@@ -5,6 +5,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Squirrel;
using Microsoft.Win32.TaskScheduler;
namespace BodyshopPartner.Utils
{
public static class SquirrelAwareHelper
@@ -66,13 +69,30 @@ namespace BodyshopPartner.Utils
Utils.UpdateHandler.ToggleStartWithWindows(true);
mgr.CreateShortcutForThisExe();
},
onAppUpdate: v => {
onAppUpdate: v =>
{
mgr.CreateShortcutForThisExe();
Utils.UpdateHandler.RestoreSettings();
Utils.UpdateHandler.ToggleStartWithWindows(Properties.Settings.Default.StartWithWindows);
Utils.PaintScaleConfig.RegisterScheduledTask();
},
onAppUninstall: v => mgr.RemoveShortcutForThisExe(),
onAppUninstall: v =>
{
mgr.RemoveShortcutForThisExe();
try
{
Microsoft.Win32.TaskScheduler.Task existingTask = TaskService.Instance.FindTask("ImEX Online Partner - Paint Scale Connection");
if (existingTask != null)
{
TaskService.Instance.RootFolder.DeleteTask("ImEX Online Partner - Paint Scale Connection");
}
}
catch (Exception ex)
{
logger.Error(ex, "Error removing task while uninstalling.");
}
},
onFirstRun: () =>
{
logger.Info("We've run for the first time.");