WIP PPG Data Pump
This commit is contained in:
@@ -66,6 +66,9 @@
|
||||
<setting name="StartWithWindows" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
<setting name="PaintScalePath" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
</BodyshopPartner.Properties.Settings>
|
||||
</userSettings>
|
||||
</configuration>
|
||||
|
||||
@@ -188,6 +188,7 @@
|
||||
<Compile Include="Utils\LoginHelpers.cs" />
|
||||
<Compile Include="Utils\Notifications.cs" />
|
||||
<Compile Include="Utils\PowerModeEventHandler.cs" />
|
||||
<Compile Include="Utils\PPGMixData.cs" />
|
||||
<Compile Include="Utils\Queries\JobsQueries.cs" />
|
||||
<Compile Include="Utils\Queries\VehicleQueries.cs" />
|
||||
<Compile Include="Utils\QuickBooksInterop.cs" />
|
||||
|
||||
@@ -168,6 +168,15 @@ namespace BodyshopPartner.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Browse Paint Scale Path.
|
||||
/// </summary>
|
||||
public static string Label_BrowsePaintScalePath {
|
||||
get {
|
||||
return ResourceManager.GetString("Label_BrowsePaintScalePath", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to File Path.
|
||||
/// </summary>
|
||||
|
||||
@@ -153,6 +153,9 @@
|
||||
<data name="Label_BrowseForQb" xml:space="preserve">
|
||||
<value>Browse for QuickBooks File</value>
|
||||
</data>
|
||||
<data name="Label_BrowsePaintScalePath" xml:space="preserve">
|
||||
<value>Browse Paint Scale Path</value>
|
||||
</data>
|
||||
<data name="Label_FilePath" xml:space="preserve">
|
||||
<value>File Path</value>
|
||||
</data>
|
||||
|
||||
14
BodyshopUploader/Properties/Settings.Designer.cs
generated
14
BodyshopUploader/Properties/Settings.Designer.cs
generated
@@ -12,7 +12,7 @@ namespace BodyshopPartner.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
@@ -140,5 +140,17 @@ namespace BodyshopPartner.Properties {
|
||||
this["StartWithWindows"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||
public string PaintScalePath {
|
||||
get {
|
||||
return ((string)(this["PaintScalePath"]));
|
||||
}
|
||||
set {
|
||||
this["PaintScalePath"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,8 @@
|
||||
<Setting Name="StartWithWindows" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
<Setting Name="PaintScalePath" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
148
BodyshopUploader/Utils/PPGMixData.cs
Normal file
148
BodyshopUploader/Utils/PPGMixData.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using GraphQL;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
|
||||
namespace BodyshopPartner.Utils
|
||||
{
|
||||
public static class PPGMixData
|
||||
{
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
private static string PpgDataQuery = @"query PPGDataPump($today: timestamptz!, $todayplus5: timestamptz!, $shopid: uuid!) {
|
||||
bodyshops_by_pk(id:$shopid) {
|
||||
id
|
||||
shopname
|
||||
}
|
||||
jobs(where: {_or: [{_and: [{scheduled_in: {_lte: $todayplus5}}, {scheduled_in: {_gte: $today}}]}, {inproduction: {_eq: true}}]}) {
|
||||
id
|
||||
ro_number
|
||||
status
|
||||
ownr_fn
|
||||
ownr_ln
|
||||
ownr_co_nm
|
||||
v_vin
|
||||
v_model_yr
|
||||
v_make_desc
|
||||
v_model_desc
|
||||
v_color
|
||||
plate_no
|
||||
ins_co_nm
|
||||
est_ct_fn
|
||||
est_ct_ln
|
||||
rate_mapa
|
||||
rate_lab
|
||||
job_totals
|
||||
labhrs: joblines_aggregate(where: {mod_lbr_ty: {_neq: ""LAR""}, removed: {_eq: false}}) {
|
||||
aggregate {
|
||||
sum {
|
||||
mod_lb_hrs
|
||||
}
|
||||
}
|
||||
}
|
||||
larhrs: joblines_aggregate(where: { mod_lbr_ty: { _eq: ""LAR""}, removed: { _eq: false} }) {
|
||||
aggregate {
|
||||
sum {
|
||||
mod_lb_hrs
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
";
|
||||
public static async Task PushDataToPPG()
|
||||
{
|
||||
try
|
||||
{
|
||||
//Get the path for the XML file that should be written. Ensure that we can read and write to that directory.
|
||||
|
||||
//Query the database based on the active shop for all work that's coming within the next 5 days + all active work.
|
||||
|
||||
var r = new GraphQLRequest
|
||||
{
|
||||
Query = PpgDataQuery,
|
||||
Variables = new
|
||||
{
|
||||
today = DateTime.Now.Date,
|
||||
todayplus5 = DateTime.Now.Date.AddDays(5),
|
||||
shopid = AppMetaData.ActiveShopId
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var data = await Utils.GraphQL.ExecuteQuery(r);
|
||||
//Create an XML document node
|
||||
XDocument doc = new XDocument(
|
||||
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("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("RepairOrders",
|
||||
new XElement("ROCount", data?.jobs?.Count)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
foreach(dynamic job in data.jobs)
|
||||
{
|
||||
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("Customer", $"{job.ownr_ln}, {job.ownr_fn}"),
|
||||
new XElement("ROPainterNotes", ""),
|
||||
new XElement("LicensePlateNum", job.plate_no?.Value),
|
||||
new XElement("VIN", job.v_vin?.Value),
|
||||
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("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("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)
|
||||
|
||||
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
|
||||
doc.Save(@"C:\\VPS\\doc.xml");
|
||||
// doc.Save(Properties.Settings.Default.PaintScalePath);
|
||||
//Ensure all values for strings are escaped.
|
||||
|
||||
//Write the file to the disk and start the timer again.
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -167,6 +167,21 @@ namespace BodyshopPartner.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _browseForPaintScalePathCommand;
|
||||
public ICommand BrowseForPaintScalePathCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_browseForPaintScalePathCommand == null)
|
||||
{
|
||||
_browseForPaintScalePathCommand = new RelayCommand(
|
||||
p => true,
|
||||
p => BrowseForPaintScalePath()
|
||||
);
|
||||
}
|
||||
return _browseForPaintScalePathCommand;
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _installUpdatesCommand;
|
||||
public ICommand InstallUpdatesCommand
|
||||
|
||||
@@ -226,6 +226,21 @@ namespace BodyshopPartner.ViewModels
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void BrowseForPaintScalePath()
|
||||
{
|
||||
|
||||
var dialog = new Ookii.Dialogs.Wpf.VistaFolderBrowserDialog();
|
||||
dialog.SelectedPath = Properties.Settings.Default.PaintScalePath;
|
||||
if (dialog.ShowDialog().GetValueOrDefault())
|
||||
{
|
||||
Properties.Settings.Default.PaintScalePath = dialog.SelectedPath;
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void StopAllFolderMonitors()
|
||||
{
|
||||
IndeterminateLoading = true;
|
||||
|
||||
@@ -156,6 +156,12 @@
|
||||
<Button Command="{Binding BrowseForQbFolderCommand, UpdateSourceTrigger=PropertyChanged}"
|
||||
Margin="8"
|
||||
Content="{x:Static p:Resources.Label_BrowseForQb}" />
|
||||
<Button Command="{Binding BrowseForPaintScalePathCommand, UpdateSourceTrigger=PropertyChanged}"
|
||||
Margin="8"
|
||||
Content="{x:Static p:Resources.Label_BrowsePaintScalePath}" />
|
||||
<Button Click="Button_Click"
|
||||
Margin="8"
|
||||
Content="Test" />
|
||||
<Separator />
|
||||
<!--<Button DockPanel.Dock="Top"
|
||||
Margin="8"
|
||||
|
||||
@@ -44,5 +44,9 @@ namespace BodyshopPartner.Views
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Utils.PPGMixData.PushDataToPPG();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user