IO-2217 Partner changes for generating part price changes.

This commit is contained in:
Patrick Fic
2023-03-16 13:34:13 -07:00
parent bd3e55a878
commit c16243eb3c
13 changed files with 382 additions and 44 deletions

View File

@@ -81,6 +81,9 @@
<setting name="PaintScaleImportTimer" serializeAs="String"> <setting name="PaintScaleImportTimer" serializeAs="String">
<value>0</value> <value>0</value>
</setting> </setting>
<setting name="PpcExportPath" serializeAs="String">
<value>C:\CIECA\CCC\IMPORT</value>
</setting>
</RomeOnlinePartner.Properties.Settings> </RomeOnlinePartner.Properties.Settings>
</userSettings> </userSettings>
</configuration> </configuration>

View File

@@ -172,6 +172,7 @@
<Compile Include="Utils\Auth.cs" /> <Compile Include="Utils\Auth.cs" />
<Compile Include="Utils\BaseModel.cs" /> <Compile Include="Utils\BaseModel.cs" />
<Compile Include="Utils\BaseViewModel.cs" /> <Compile Include="Utils\BaseViewModel.cs" />
<Compile Include="Utils\CCCPartsPriceChange.cs" />
<Compile Include="Utils\CIECAMonitor.cs"> <Compile Include="Utils\CIECAMonitor.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>

View File

@@ -186,6 +186,15 @@ namespace RomeOnlinePartner.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Brose for PPC Export Path.
/// </summary>
public static string Label_BrowseForPpcExport {
get {
return ResourceManager.GetString("Label_BrowseForPpcExport", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Browse for QuickBooks File. /// Looks up a localized string similar to Browse for QuickBooks File.
/// </summary> /// </summary>
@@ -294,6 +303,15 @@ namespace RomeOnlinePartner.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Parts Price Change Export Path.
/// </summary>
public static string Label_PpcExport {
get {
return ResourceManager.GetString("Label_PpcExport", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to QuickBooks File Path. /// Looks up a localized string similar to QuickBooks File Path.
/// </summary> /// </summary>

View File

@@ -159,6 +159,9 @@
<data name="Label_BrowseForEmsExport" xml:space="preserve"> <data name="Label_BrowseForEmsExport" xml:space="preserve">
<value>Browse for EMS Export Path</value> <value>Browse for EMS Export Path</value>
</data> </data>
<data name="Label_BrowseForPpcExport" xml:space="preserve">
<value>Brose for PPC Export Path</value>
</data>
<data name="Label_BrowseForQb" xml:space="preserve"> <data name="Label_BrowseForQb" xml:space="preserve">
<value>Browse for QuickBooks File</value> <value>Browse for QuickBooks File</value>
</data> </data>
@@ -195,6 +198,9 @@
<data name="Label_PaintScalePath" xml:space="preserve"> <data name="Label_PaintScalePath" xml:space="preserve">
<value>RO -&gt;Paint Scale Path</value> <value>RO -&gt;Paint Scale Path</value>
</data> </data>
<data name="Label_PpcExport" xml:space="preserve">
<value>Parts Price Change Export Path</value>
</data>
<data name="Label_QbFilePath" xml:space="preserve"> <data name="Label_QbFilePath" xml:space="preserve">
<value>QuickBooks File Path</value> <value>QuickBooks File Path</value>
</data> </data>

View File

@@ -200,5 +200,17 @@ namespace RomeOnlinePartner.Properties {
this["PaintScaleImportTimer"] = value; this["PaintScaleImportTimer"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("C:\\CIECA\\CCC\\IMPORT")]
public string PpcExportPath {
get {
return ((string)(this["PpcExportPath"]));
}
set {
this["PpcExportPath"] = value;
}
}
} }
} }

View File

@@ -47,5 +47,8 @@
<Setting Name="PaintScaleImportTimer" Type="System.String" Scope="User"> <Setting Name="PaintScaleImportTimer" Type="System.String" Scope="User">
<Value Profile="(Default)">0</Value> <Value Profile="(Default)">0</Value>
</Setting> </Setting>
<Setting Name="PpcExportPath" Type="System.String" Scope="User">
<Value Profile="(Default)">C:\CIECA\CCC\IMPORT</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View File

@@ -0,0 +1,178 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DotNetDBF;
using Newtonsoft.Json.Linq;
namespace RomeOnlinePartner.Utils
{
class CCCPartsPriceChange
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private static string workingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
private static string emsBasePath = workingDirectory + @"\EmsBase";
private static string TempEmsDir = Properties.Settings.Default.PpcExportPath;
private static Encoding DbfFileCharEncoding = Encoding.ASCII;
private static byte DbfFileSignature = DBFSignature.DBase3; //DBFSignature.WithMemo;
private static byte DbfFileLanguageDriver = 0; //0x37;
public static void SendPartsPriceChange(dynamic Job)
{
Directory.CreateDirectory(TempEmsDir);
GenerateLinFile(Job);
GenerateEnvFile(Job);
}
public static void GenerateLinFile(dynamic Job)
{
try
{
DBFField[] StandardEmsFields = Utils.OEConnection.ReadDbfFields(emsBasePath + @"\EMS.LIN");
using (var fileStream = File.Create(TempEmsDir + $@"\{Utils.OEConnection.GenerateFileName(Job)}.LIN"))
{
using (var writer = new DBFWriter())
{
writer.CharEncoding = DbfFileCharEncoding;
writer.Signature = DbfFileSignature;
writer.LanguageDriver = DbfFileLanguageDriver;
writer.Fields = StandardEmsFields;
foreach (var jobline in Job.joblines)
{
writer.AddRecord(
jobline?.line_no?.Value,
jobline?.line_ind?.Value,
null, //jobline?.line_ref?.Value,
jobline?.tran_code?.Value ?? "2",
null, //jobline?.db_ref?.Value,
jobline?.unq_seq?.Value,
null, //jobline?.who_pays?.Value,
jobline?.line_desc?.Value,
null, //jobline?.part_type?.Value,
//partsOrderLine.jobline?.part_type?.Value,
null, //partsOrderLine.jobline?.part_descj?.Value,
null, //jobline?.glass_flag?.Value,
null, //jobline?.oem_partno?.Value,
null, //jobline?.price_inc?.Value,
null, //jobline?.alt_part_i?.Value,
null, //jobline?.tax_part?.Value,
null, //jobline?.db_price?.Value,
jobline.act_price?.Value,
jobline?.price_j?.Value,
null, //jobline?.cert_part?.Value,
null, //jobline?.part_qty?.Value,
null, //jobline?.alt_co_id?.Value,
null, //jobline?.alt_partno?.Value,
null, //jobline?.alt_overrd?.Value,
null, //jobline?.alt_partm?.Value,
null, //jobline?.prt_dsmk_p?.Value,
null, //jobline?.prt_dsmk_m?.Value,
null, //jobline?.mod_lbr_ty?.Value,
null, //jobline?.db_hrs?.Value,
null, //jobline?.mod_lb_hrs?.Value,
null, //jobline?.lbr_inc?.Value,
null, //jobline?.lbr_op?.Value,
null, //jobline?.lbr_hrs_j?.Value,
null, //jobline?.lbr_typ_j?.Value,
null, //jobline?.lbr_op_j?.Value,
null, //jobline?.paint_stg?.Value,
null, //jobline?.paint_tone?.Value,
null, //jobline?.lbr_tax?.Value,
null, //jobline?.lbr_amt?.Value,
null, //jobline?.misc_amt?.Value,
null, //jobline?.misc_sublt?.Value,
null, //jobline?.misc_tax?.Value,
null, //jobline?.bett_type?.Value,
null, //jobline?.bett_pctg?.Value,
null, //jobline?.bett_amt?.Value,
null //jobline?.bett_tax?.Value
); ;
}
writer.Write(fileStream);
}
}
}
catch (Exception ex)
{
logger.Error(ex, "Error when creating LIN file."); throw ex;
}
}
public static void GenerateEnvFile(dynamic Job)
{
try
{
DBFField[] StandardEmsFields = Utils.OEConnection.ReadDbfFields(emsBasePath + @"\EMS.ENV");
using (var fileStream = File.Create(TempEmsDir + $@"\{Utils.OEConnection.GenerateFileName(Job)}.ENV"))
{
using (var writer = new DBFWriter())
{
writer.CharEncoding = DbfFileCharEncoding;
writer.Signature = DbfFileSignature;
writer.LanguageDriver = DbfFileLanguageDriver;
writer.Fields = StandardEmsFields;
writer.AddRecord(
"C",//EST_SYSTEM,
null,//"21.3",//SW_VERSION,
null,//"OCT_21_V",//DB_VERSION,
null,//DB_DATE
"",//UNQFILE_ID,
Job.ro_number?.Value,//RO_ID,
Job.ciecaid?.Value,//ESTFILE_ID,
null,//GetSupplementNumber(Job),//SUPP_NO,
null, //EST_CTRY,
null,//TOP_SECRET,
null,//H_TRANS_ID,
null,//H_CTRL_NO,
Job.trans_type?.Value,//TRANS_TYPE,
false,//STATUS,
null,// Job.create_dt?.Value,//CREATE_DT,
null,//Job.create_tm?.Value,//CREATE_TM,
null,//TRANSMT_DT,
null,//TRANSMT_TM,
true,//INCL_ADMIN,
true,//INCL_VEH,
Job.incl_est?.Value,//INCL_EST,
true,//INCL_PROFL,
true,//INCL_TOTAL,
false,//INCL_VENDR,
null//EMS_VER,
); ;
writer.Write(fileStream);
}
}
}
catch (Exception ex)
{
logger.Error(ex, "Error when creating ENV file."); throw ex;
}
}
}
}

View File

@@ -65,7 +65,8 @@ namespace RomeOnlinePartner.Utils.Decoder
{ {
var reader = new DBFReader(fis); var reader = new DBFReader(fis);
reader.SetSelectFields(new string[] { "EST_SYSTEM" reader.SetSelectFields(new string[] { "EST_SYSTEM", "ESTFILE_ID"
}); });
var readValues = reader.NextRecord(); var readValues = reader.NextRecord();

View File

@@ -79,6 +79,16 @@ namespace RomeOnlinePartner.Utils
(req, res, props) => { HandleOec(req, res); } (req, res, props) => { HandleOec(req, res); }
, "POST"); , "POST");
Route.Add("/ppc/", (req, res, props) =>
{
hlog("Received an PPC from Rome Online");
res.WithCORS();
res.Close();
}, "OPTIONS");
Route.Add("/ppc/",
(req, res, props) => { HandlePpc(req, res); }
, "POST");
Route.Add("/paintscale/export/", (req, res, props) => Route.Add("/paintscale/export/", (req, res, props) =>
{ {
hlog("Received a Paint Scale Export Request"); hlog("Received a Paint Scale Export Request");
@@ -148,6 +158,27 @@ namespace RomeOnlinePartner.Utils
res.WithCORS().AsText(JsonConvert.SerializeObject(HttpResponse)); res.WithCORS().AsText(JsonConvert.SerializeObject(HttpResponse));
} }
private static void HandlePpc(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res)
{
logger.Trace("/ppc/ - POST");
//Input will be an array of objects containing XMLs.
var requestBody = ParseBody(req);
JObject HttpResponse = new JObject();
try
{
Utils.CCCPartsPriceChange.SendPartsPriceChange(requestBody);
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("error", Ex.ToString());
}
res.WithCORS().AsText(JsonConvert.SerializeObject(HttpResponse));
}
private static void HandleQbPost(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res) private static void HandleQbPost(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res)
{ {

View File

@@ -184,7 +184,21 @@ namespace RomeOnlinePartner.ViewModels
return _browseForEmsFolderCommand; return _browseForEmsFolderCommand;
} }
} }
private ICommand _browseForPpcFolderCommand;
public ICommand BrowseForPpcFolderCommand
{
get
{
if (_browseForPpcFolderCommand == null)
{
_browseForPpcFolderCommand = new RelayCommand(
p => true,
p => BrowseForPpcFolder()
);
}
return _browseForPpcFolderCommand;
}
}
private ICommand _browseForPaintScalePathCommand; private ICommand _browseForPaintScalePathCommand;
public ICommand BrowseForPaintScalePathCommand public ICommand BrowseForPaintScalePathCommand

View File

@@ -242,8 +242,16 @@ namespace RomeOnlinePartner.ViewModels
Properties.Settings.Default.EmsExportPath = dialog.SelectedPath; Properties.Settings.Default.EmsExportPath = dialog.SelectedPath;
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
} }
}
public void BrowseForPpcFolder()
{
var dialog = new Ookii.Dialogs.Wpf.VistaFolderBrowserDialog();
dialog.SelectedPath = Properties.Settings.Default.PpcExportPath;
if (dialog.ShowDialog().GetValueOrDefault())
{
Properties.Settings.Default.PpcExportPath = dialog.SelectedPath;
Properties.Settings.Default.Save();
}
} }
public void BrowseForPaintScalePath() public void BrowseForPaintScalePath()

View File

@@ -153,22 +153,6 @@
Margin="8" Margin="8"
Content="{x:Static p:Resources.Label_RemoveAllPaths}" /> Content="{x:Static p:Resources.Label_RemoveAllPaths}" />
<Separator /> <Separator />
<Button Command="{Binding BrowseForQbFolderCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8"
Content="{x:Static p:Resources.Label_BrowseForQb}" />
<Button Command="{Binding BrowseForEmsFolderCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8"
Content="{x:Static p:Resources.Label_BrowseForEmsExport}" />
<Button Command="{Binding BrowseForPaintScalePathCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8"
Content="{x:Static p:Resources.Label_BrowsePaintScalePath}" />
<Button Command="{Binding BrowseForPaintScaleImportPathCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8"
Content="{x:Static p:Resources.Label_BrowsePaintScaleImportPath}" />
<Button Command="{Binding BrowseForArmsPathPathCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8"
Content="{x:Static p:Resources.Label_BrowseArmsExportPath}" />
<Button Command="{Binding ConfigurePaintScaleCommand, UpdateSourceTrigger=PropertyChanged}" <Button Command="{Binding ConfigurePaintScaleCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8" Margin="8"
Content="{x:Static p:Resources.Label_ConfigurePaintScale}" /> Content="{x:Static p:Resources.Label_ConfigurePaintScale}" />
@@ -248,30 +232,87 @@
</DataGridTemplateColumn> </DataGridTemplateColumn>
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
<DockPanel Grid.Row="1"
<ScrollViewer Grid.Row="1"> <DockPanel
Height="Auto"> Height="Auto">
<TextBox DockPanel.Dock="Top"
Text="{Binding Source={x:Static properties:Settings.Default},
Path=QuickBooksFilePath}"
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_QbFilePath}"
TextChanged="TextBox_TextChanged" />
<TextBox DockPanel.Dock="Top"
Text="{Binding Source={x:Static properties:Settings.Default},
Path=EmsExportPath}"
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_EmsExport}"
TextChanged="EmsExportPath_TextChanged" />
<TextBox DockPanel.Dock="Top"
Text="{Binding Source={x:Static properties:Settings.Default},
Path=PaintScalePath}"
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_PaintScalePath}"
TextChanged="PaintScalePath_TextChanged" />
<Grid DockPanel.Dock="Top" <Grid DockPanel.Dock="Top"
HorizontalAlignment="Stretch"> HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" /> <ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBox DockPanel.Dock="Top"
Grid.Column="0"
Text="{Binding Source={x:Static properties:Settings.Default},
Path=QuickBooksFilePath}"
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_QbFilePath}"
TextChanged="TextBox_TextChanged" />
<Button Command="{Binding BrowseForQbFolderCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8"
Content="{x:Static p:Resources.Label_BrowseForQb}"
ContentStringFormat=""
Grid.Column="1"/>
</Grid>
<Grid DockPanel.Dock="Top"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox DockPanel.Dock="Top"
Grid.Column="0"
Text="{Binding Source={x:Static properties:Settings.Default},
Path=EmsExportPath}"
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_EmsExport}"
TextChanged="EmsExportPath_TextChanged" />
<Button Command="{Binding BrowseForEmsFolderCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8"
Content="{x:Static p:Resources.Label_BrowseForEmsExport}" Grid.Column="1" />
</Grid>
<Grid DockPanel.Dock="Top"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox DockPanel.Dock="Top"
Grid.Column="0"
Text="{Binding Source={x:Static properties:Settings.Default},
Path=PpcExportPath}"
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_PpcExport}"
TextChanged="PpcExportPath_TextChanged" />
<Button Command="{Binding BrowseForPpcFolderCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8"
Content="{x:Static p:Resources.Label_BrowseForPpcExport}"
Grid.Column="1" />
</Grid>
<Grid DockPanel.Dock="Top"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox DockPanel.Dock="Top"
Grid.Column="0"
Text="{Binding Source={x:Static properties:Settings.Default},
Path=PaintScalePath}"
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_PaintScalePath}"
TextChanged="PaintScalePath_TextChanged" />
<Button Command="{Binding BrowseForPaintScalePathCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8"
Content="{x:Static p:Resources.Label_BrowsePaintScalePath}" Grid.Column="1"/>
</Grid>
<Grid DockPanel.Dock="Top"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" <TextBox Grid.Column="0"
Text="{Binding Source={x:Static properties:Settings.Default}, Text="{Binding Source={x:Static properties:Settings.Default},
Path=PaintScaleImportPath}" Path=PaintScaleImportPath}"
@@ -282,20 +323,36 @@
Path=PaintScaleImportTimer}" Path=PaintScaleImportTimer}"
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_PaintScaleImportTimer}" materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_PaintScaleImportTimer}"
TextChanged="PaintScaleImportTimer_TextChanged" /> TextChanged="PaintScaleImportTimer_TextChanged" />
<Button Command="{Binding BrowseForPaintScaleImportPathCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8"
Content="{x:Static p:Resources.Label_BrowsePaintScaleImportPath}" Grid.Column="2"/>
</Grid> </Grid>
<Grid DockPanel.Dock="Top"
<TextBox DockPanel.Dock="Top" HorizontalAlignment="Stretch">
Text="{Binding Source={x:Static properties:Settings.Default}, <Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox DockPanel.Dock="Top"
Grid.Column="0"
Text="{Binding Source={x:Static properties:Settings.Default},
Path=ArmsExportPath}" Path=ArmsExportPath}"
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_ArmsExportPath}" materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_ArmsExportPath}"
TextChanged="ArmsExportPath_TextChanged" /> TextChanged="ArmsExportPath_TextChanged" />
<Button Command="{Binding BrowseForArmsPathPathCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8"
Content="{x:Static p:Resources.Label_BrowseArmsExportPath}" Grid.Column="1"/>
</Grid>
<TextBox Height="Auto" <TextBox Height="Auto"
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_InteractionLog}" materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_InteractionLog}"
Text="{Binding HttpServerLog}" Text="{Binding HttpServerLog}"
TextWrapping="Wrap" TextWrapping="Wrap"
IsReadOnly="True" IsReadOnly="True"
AcceptsReturn="True" /> AcceptsReturn="True" /></DockPanel>
</DockPanel> </ScrollViewer>
</Grid> </Grid>

View File

@@ -73,5 +73,11 @@ namespace RomeOnlinePartner.Views
Properties.Settings.Default.EmsExportPath = ((System.Windows.Controls.TextBox)sender).Text; Properties.Settings.Default.EmsExportPath = ((System.Windows.Controls.TextBox)sender).Text;
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
} }
private void PpcExportPath_TextChanged(object sender, TextChangedEventArgs e)
{
Properties.Settings.Default.PpcExportPath = ((System.Windows.Controls.TextBox)sender).Text;
Properties.Settings.Default.Save();
}
} }
} }