IO-2217 Partner changes for generating part price changes.
This commit is contained in:
178
BodyshopUploader/Utils/CCCPartsPriceChange.cs
Normal file
178
BodyshopUploader/Utils/CCCPartsPriceChange.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,8 @@ namespace RomeOnlinePartner.Utils.Decoder
|
||||
{
|
||||
var reader = new DBFReader(fis);
|
||||
|
||||
reader.SetSelectFields(new string[] { "EST_SYSTEM"
|
||||
reader.SetSelectFields(new string[] { "EST_SYSTEM", "ESTFILE_ID"
|
||||
|
||||
});
|
||||
var readValues = reader.NextRecord();
|
||||
|
||||
|
||||
@@ -79,6 +79,16 @@ namespace RomeOnlinePartner.Utils
|
||||
(req, res, props) => { HandleOec(req, res); }
|
||||
, "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) =>
|
||||
{
|
||||
hlog("Received a Paint Scale Export Request");
|
||||
@@ -148,6 +158,27 @@ namespace RomeOnlinePartner.Utils
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user