diff --git a/BodyshopUploader/ImEXOnlinePartner.csproj b/BodyshopUploader/ImEXOnlinePartner.csproj index 7298cf8..fb1c7d7 100644 --- a/BodyshopUploader/ImEXOnlinePartner.csproj +++ b/BodyshopUploader/ImEXOnlinePartner.csproj @@ -168,6 +168,7 @@ + @@ -195,6 +196,7 @@ + @@ -346,6 +348,9 @@ 6.0.0.3 + + 3.5.1 + 3.7.2 diff --git a/BodyshopUploader/Utils/ARMSRoData.cs b/BodyshopUploader/Utils/ARMSRoData.cs new file mode 100644 index 0000000..d468dff --- /dev/null +++ b/BodyshopUploader/Utils/ARMSRoData.cs @@ -0,0 +1,240 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using FileHelpers; +using GraphQL; + +namespace BodyshopPartner.Utils +{ + public static class ARMSRoData + { + private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); + + private static string ArmsRoDataQuery = @" +query ENTEGRAL_EXPORT($bodyshopid: uuid!, $start: timestamptz!, $end: timestamptz!) { + jobs(where: {_and: [{_or: [{inproduction: {_eq: true}}, {_and: [{actual_completion: {_gte: $start}}, {actual_completion: {_lte: $end}}]}]}, {shopid: {_eq: $bodyshopid}}]}) { + joblines { + id + line_ind + } + id + ro_number + status + asgn_date + date_open + kmin + scheduled_completion + actual_completion + actual_delivery + date_exported + ins_co_nm + ins_addr1 + ins_addr2 + ins_city + ins_st + ins_zip + ins_ctry + ins_ph1 + ins_ph2 + est_ct_ln + est_ct_fn + insd_fn + insd_ln + ownr_fn + ownr_ln + ownr_co_nm + ownr_addr1 + ownr_addr2 + ownr_city + ownr_st + ownr_zip + ownr_ctry + ownr_ph1 + ownr_ph2 + ownr_ea + clm_ct_fn + clm_ct_ln + v_vin + kmin + plate_no + v_model_yr + v_make_desc + v_model_desc + v_color + driveable + clm_no + policy_no + loss_date + area_of_damage + tlos_ind + parts_tax_rates + federal_tax_rate + state_tax_rate + rate_la1 + rate_la2 + rate_la3 + rate_la4 + rate_laa + rate_lab + rate_lad + rate_lae + rate_laf + rate_lag + rate_lam + rate_lar + rate_las + rate_lau + rate_ma2s + rate_ma2t + rate_ma3s + rate_mabl + rate_macs + rate_mahw + rate_mapa + rate_mash + rate_matd + job_totals + ded_amt + cieca_ttl + adjustment_bottom_line + employee_body_rel { + employee_number + first_name + last_name + } + employee_refinish_rel { + employee_number + first_name + last_name + } + } + bodyshops_by_pk(id: $bodyshopid) { + id + entegral_id + shopname + md_ro_statuses + } +} + + + +"; + + public static async Task GenerateArmsROData() + { + logger.Debug("Generating ARMS Info."); + + + try + { + FileHelperEngine engine = new FileHelperEngine(); + + + var r = new GraphQLRequest + { + Query = ArmsRoDataQuery, + Variables = new + { + start = DateTime.Now.Date.AddDays(-30), + end = DateTime.Now.Date, + bodyshopid = AppMetaData.ActiveShopId + } + }; + + + var data = await Utils.GraphQL.ExecuteQuery(r); + + + + var RepairOrders = new List(); + + Regex ROStripper = new Regex(@"\d"); + + + foreach (dynamic job in data.jobs) + { + + + + var RoNumber = string.Join("", Regex.Matches((string)(job.ro_number?.Value), @"\d").OfType().Select(m => m.Value)); + logger.Debug(RoNumber); + RepairOrders.Add(new ARMSRoDataModel() + { + ShopShortName = int.Parse(data.bodyshops_by_pk.entegral_id?.Value), + RO = int.Parse(RoNumber), + TransType = "Z", //TODO*** Finish this status mapping. + ShopLongName = data.bodyshops_by_pk.shopname?.Value, + EstimatorID = job.est_ct_ln, + EstimatorName = $"{job.est_ct_fn} {job.est_ct_ln}", + BodymanID = job.employee_body_rel?.Value == null ? "" : job.employee_body_rel?.employee_number?.Value, + CustomerFirstName = job.ownr_fn?.Value, + CustomerLastName = job.ownr_ln?.Value, + CustomerStreet = job.ownr_addr1?.Value, + CustomerCity = job.ownr_city?.Value, + CustomerState = job.ownr_st?.Value, + CustomerZip = job.ownr_ph1?.Value, + RetWhslCustomer = "R", + Year = int.Parse(job.v_model_yr?.Value ?? 0), //TODO STRIP TO 2 NUMBERS + Make = job.v_make_desc?.Value, + Model = job.v_model_desc?.Value, + VIN = job.v_vin?.Value, + License = job.plate_no?.Value, + MileageIn = job.kim ?? 0, + CompanyName = job.ins_co_nm?.Value, + InsuranceAddress = job.ins_addr1?.Value, + InsuranceCity = job.ins_city?.Value, + InsuranceState = job.ins_st?.Value, + InsuranceZip = job.ins_zip?.Value, + ClaimType = "N/A", + Claim = job.clm_no?.Value, + DateOpened = job.date_open?.Value,// ? job.date_open : null, + //DateofLoss = job.loss_date?.Value,// ? job.loss_date : null, + PromiseDate = job.scheduled_completion, + CustPickup = job.actual_delivery, + DateClosed = job.date_invoiced, + BodyRate = job.rate_lab, + RefinishRate = job.rate_lar, + MechanicalRate = job.rate_lam, + StructuralRate = job.rate_las, + PMRate = job.rate_mapa, + BMRate = job.rate_mash, + RevisedTotalsBodyHours = job.job_totals?.rates?.lab?.hours?.Value, + RevisedTotalsRefinishHours = job.job_totals?.rates?.lar?.hours?.Value, + RevisedTotalsMechanicalHours = job.job_totals?.rates?.lam?.hours?.Value, + RevisedTotalsStructuralHours = job.job_totals?.rates?.las?.hours?.Value, + RevisedTotalsPartsTotal = job.job_totals?.pars?.parts?.total?.amount?.Value/100, + RevisedTotalsSubletTotal = job.job_totals?.pars?.sublets?.total?.amount?.Value / 100, + RevisedTotalsBodyLaborTotal = job.job_totals?.rates?.lab?.total?.amount?.Value/100, + RevisedTotalsRefinishLaborTotal = job.job_totals?.rates?.lar?.total?.amount?.Value / 100, + RevisedTotalsMechanicalLaborTotal = job.job_totals?.rates?.lam?.total?.amount?.Value / 100, + RevisedTotalsStructuralLaborTotal = job.job_totals?.rates?.las?.total?.amount?.Value / 100, + RevisedTotalsPMTotal = job.job_totals?.rates?.mapa?.total?.amount?.Value / 100, + RevisedTotalsBMTotal = job.job_totals?.rates?.mash?.total?.amount?.Value / 100, + RevisedTotalsSalesTaxTotal = (job.job_totals?.totals?.federal_tax?.amount?.Value + job.job_totals?.totals?.state_tax?.amount?.Value) /100, + RevisedTotalsGrossTotal = job.job_totals?.totals?.total_repairs?.amount?.Value /100, + RevisedTotalsDeductibleTotal = job.ded_amt?.Value, + // RevisedTotalsDepreciationTotal = job.job_totals?.rates?.lab?.hours?.Value, + TotalLossYN = job.tlos_ind, + BodyTechName = job.employee_body_rel?.Value == null ? "" : $"{job.employee_body_rel?.first_name?.Value} {job.employee_body_rel?.last_name?.Value}", + Vehiclecolor = job.v_color?.Value, + PaintTechID = job.employee_refinish_rel?.Value == null ? "" : job.employee_refinish_rel?.employee_number?.Value, + PaintTechName = job.employee_refinish_rel?.Value == null ? "" : $"{job.employee_refinish_rel?.first_name?.Value} {job.employee_refinish_rel?.last_name?.Value}", + ProductionStageCode = "33" //TODO ADD THE REST OF THE CODE + }); + } + + + engine.WriteFile("Output.Txt", RepairOrders); + } + catch (Exception ex) + { + logger.Error(ex, "Exception while creating ARMS RO Data Extract: "); + } + + + } + } +} diff --git a/BodyshopUploader/Utils/ARMSRoDataModel.cs b/BodyshopUploader/Utils/ARMSRoDataModel.cs new file mode 100644 index 0000000..eaa0844 --- /dev/null +++ b/BodyshopUploader/Utils/ARMSRoDataModel.cs @@ -0,0 +1,445 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FileHelpers; + +namespace BodyshopPartner.Utils +{ + [FixedLengthRecord()] + public class ARMSRoDataModel + { + [FieldFixedLength(5)] + public int CustId; + + [FieldFixedLength(30)] + [FieldTrim(TrimMode.Both)] + public string Name; + + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? AddedDate; + + + + [FieldFixedLength(8)] + public int ShopShortName; + [FieldFixedLength(8)] + public int RO; + [FieldFixedLength(1)] + public String TransType; + + + [FieldFixedLength(35)] + public String ShopLongName; + [FieldFixedLength(5)] + public String EstimatorID; + [FieldFixedLength(35)] + public String EstimatorName; + [FieldFixedLength(5)] + public String BodymanID; + [FieldFixedLength(35)] + public String CustomerFirstName; + [FieldFixedLength(35)] + public String CustomerLastName; + [FieldFixedLength(40)] + public String CustomerStreet; + [FieldFixedLength(30)] + public String CustomerCity; + [FieldFixedLength(2)] + public String CustomerState; + [FieldFixedLength(11)] + public String CustomerZip; + [FieldFixedLength(10)] + public int CustomerPhone1; + [FieldFixedLength(10)] + public int CustomerPhone2; + [FieldFixedLength(35)] + public String CustomerSource; + [FieldFixedLength(1)] + public String RetWhslCustomer; + + + [FieldFixedLength(1)] + public String CatMFD; + + + + + [FieldFixedLength(2)] + public int Year; + [FieldFixedLength(20)] + public String Make; + [FieldFixedLength(50)] + public String Model; + [FieldFixedLength(25)] + public String VIN; + [FieldFixedLength(10)] + public String License; + [FieldFixedLength(6)] + public int MileageIn; + [FieldFixedLength(5)] + public String InsuranceCoCode; + [FieldFixedLength(35)] + public String CompanyName; + [FieldFixedLength(40)] + public String InsuranceAddress; + [FieldFixedLength(30)] + public String InsuranceCity; + [FieldFixedLength(2)] + public String InsuranceState; + [FieldFixedLength(11)] + public String InsuranceZip; + [FieldFixedLength(10)] + public int InsurancePhone; + [FieldFixedLength(10)] + public int InsuranceFax; + [FieldFixedLength(4)] + public String ClaimType; + + + + + + + + + + [FieldFixedLength(1)] + public String LossType; + + + + + + [FieldFixedLength(30)] + public String Policy; + [FieldFixedLength(30)] + public String Claim; + [FieldFixedLength(35)] + public String InsuredLastName; + [FieldFixedLength(35)] + public String InsuredFirstName; + [FieldFixedLength(35)] + public String ClaimantLastName; + [FieldFixedLength(35)] + public String ClaimantFirstName; + [FieldFixedLength(25)] + public String Assignment; + [FieldFixedLength(35)] + public String InsuranceAgentLastName; + [FieldFixedLength(35)] + public String InsuranceAgentFirstName; + [FieldFixedLength(10)] + public int InsAgentPhone; + + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? DateOpened; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? DateofLoss; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? AssignedDate; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? TeardownHold; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? CarinShop; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? EstComplete; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? PartsOrder; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? AsstoBody; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? AsstoMech; + [FieldFixedLength(8)] + public DateTime? AsstoPaint; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? AssntoDetail; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? CarComplete; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? PromiseDate; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? CustPickup; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? InsInspDate; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? DateClosed; + + [FieldFixedLength(12)] + public Double? BodyRate; + [FieldFixedLength(12)] + public Double? RefinishRate; + [FieldFixedLength(12)] + public Double? MechanicalRate; + [FieldFixedLength(12)] + public Double? StructuralRate; + [FieldFixedLength(12)] + public Double? PMRate; + [FieldFixedLength(12)] + public Double? BMRate; + [FieldFixedLength(7)] + public Double? RetailWholesaleTaxRate; + [FieldFixedLength(12)] + public Double? StorageRateperDay; + [FieldFixedLength(3)] + public Double? DaysStored; + + [FieldFixedLength(5)] + public Double? BodyHours; + [FieldFixedLength(5)] + public Double? RefinishHours; + [FieldFixedLength(5)] + public Double? MechanicalHours; + [FieldFixedLength(5)] + public Double? StructuralHours; + [FieldFixedLength(12)] + public Double? PartsTotal; + [FieldFixedLength(12)] + public Double? SubletTotal; + [FieldFixedLength(12)] + public Double? BodyLaborTotal; + [FieldFixedLength(12)] + public Double? RefinishLaborTotal; + [FieldFixedLength(12)] + public Double? MechanicalLaborTotal; + [FieldFixedLength(12)] + public Double? StructuralLaborTotal; + [FieldFixedLength(12)] + public Double? MiscellaneousChargeTotal; + [FieldFixedLength(12)] + public Double? PMTotal; + [FieldFixedLength(12)] + public Double? BMTotal; + [FieldFixedLength(12)] + public Double? MiscTotal; + [FieldFixedLength(12)] + public Double? TowingTotal; + [FieldFixedLength(12)] + public Double? StorageTotal; + [FieldFixedLength(12)] + public Double? DetailTotal; + [FieldFixedLength(12)] + public Double? SalesTaxTotal; + [FieldFixedLength(12)] + public Double? GrossTotal; + [FieldFixedLength(12)] + public Double? DeductibleTotal; + [FieldFixedLength(12)] + public Double? DepreciationTotal; + [FieldFixedLength(12)] + public Double? Discount; + [FieldFixedLength(12)] + public Double? CustomerPay; + [FieldFixedLength(12)] + public Double? InsurancePay; + [FieldFixedLength(12)] + public Double? Deposit; + [FieldFixedLength(12)] + public Double? AmountDue; + + [FieldFixedLength(5)] + public Double? SupplementBodyHours; + [FieldFixedLength(5)] + public Double? SupplementRefinishHours; + [FieldFixedLength(5)] + public Double? SupplementMechanicalHours; + [FieldFixedLength(5)] + public Double? SupplementStructuralHours; + [FieldFixedLength(12)] + public Double? SupplementPartsTotal; + [FieldFixedLength(12)] + public Double? SupplementSubletTotal; + [FieldFixedLength(12)] + public Double? SupplementBodyLaborTotal; + [FieldFixedLength(12)] + public Double? SupplementRefinishLaborTotal; + [FieldFixedLength(12)] + public Double? SupplementMechanicalLaborTotal; + [FieldFixedLength(12)] + public Double? SupplementStructuralLaborTotal; + [FieldFixedLength(12)] + public Double? SupplementMiscellaneousChargeTotal; + [FieldFixedLength(12)] + public Double? SupplementPMTotal; + [FieldFixedLength(12)] + public Double? SupplementBMTotal; + [FieldFixedLength(12)] + public Double? SupplementMiscTotal; + [FieldFixedLength(12)] + public Double? SupplementTowingTotal; + [FieldFixedLength(12)] + public Double? SupplementStorageTotal; + [FieldFixedLength(12)] + public Double? SupplementDetailTotal; + [FieldFixedLength(12)] + public Double? SupplementSalesTaxTotal; + [FieldFixedLength(12)] + public Double? SupplementGrossTotal; + [FieldFixedLength(12)] + public Double? SupplementDeductibleTotal; + [FieldFixedLength(12)] + public Double? SupplementDepreciationTotal; + [FieldFixedLength(12)] + public Double? SupplementDiscount; + [FieldFixedLength(12)] + public Double? SupplementCustomerPay; + [FieldFixedLength(12)] + public Double? SupplementInsurancePay; + [FieldFixedLength(12)] + public Double? SupplementDeposit; + [FieldFixedLength(12)] + public Double? SupplementAmountDue; + + [FieldFixedLength(5)] + public Double? RevisedTotalsBodyHours; + + [FieldFixedLength(5)] + public Double? RevisedTotalsRefinishHours; + [FieldFixedLength(5)] + public Double? RevisedTotalsMechanicalHours; + [FieldFixedLength(5)] + public Double? RevisedTotalsStructuralHours; + [FieldFixedLength(12)] + public Double? RevisedTotalsPartsTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsSubletTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsBodyLaborTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsRefinishLaborTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsMechanicalLaborTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsStructuralLaborTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsMiscellaneousChargeTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsPMTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsBMTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsMiscTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsTowingTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsStorageTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsDetailTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsSalesTaxTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsGrossTotal; + + [FieldFixedLength(12)] + public Double? RevisedTotalsDeductibleTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsDepreciationTotal; + [FieldFixedLength(12)] + public Double? RevisedTotalsDiscount; + [FieldFixedLength(12)] + public Double? RevisedTotalsCustomerPay; + [FieldFixedLength(12)] + public Double? RevisedTotalsInsurancePay; + [FieldFixedLength(12)] + public Double? RevisedTotalsDeposit; + [FieldFixedLength(12)] + public Double? RevisedTotalsAmountDue; + + [FieldFixedLength(2)] + public int ProductionStatus; + + [FieldFixedLength(20)] + public String StatusDescription; + + [FieldFixedLength(20)] + public String Hub50Comment; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? Dateofchange; + [FieldFixedLength(20)] + public String BodyTechName; + [FieldFixedLength(1)] + public String TotalLossYN; + [FieldFixedLength(50)] + public String InScreenCommentsLine1; + [FieldFixedLength(50)] + public String InScreenCommentsLine2; + [FieldFixedLength(4)] + public int CustomerPhone2Extension; + [FieldFixedLength(10)] + public int CustomerPhone3; + [FieldFixedLength(4)] + public int CustomerPhone3Extension; + [FieldFixedLength(60)] + public String CustomerFileComments; + [FieldFixedLength(10)] + public String Vehiclecolor; + [FieldFixedLength(4)] + public int VehicleProductionDate; + [FieldFixedLength(10)] + public String VehiclePaintCode; + [FieldFixedLength(10)] + public String VehicleTrimCode; + [FieldFixedLength(10)] + public String VehicleBodyStyle; + [FieldFixedLength(25)] + public String InsideAdjuster; + [FieldFixedLength(25)] + public String OutsideAdjuster; + [FieldFixedLength(20)] + public String AssignmentCaller; + [FieldFixedLength(10)] + public String AssignmentDivision; + [FieldFixedLength(1)] + public String InsuredorClaimantFlag; + [FieldFixedLength(20)] + public String LocationofPrimaryImpact; + [FieldFixedLength(20)] + public String LocationofSecondaryImpact; + [FieldFixedLength(1)] + public String DrivableFlag; + [FieldFixedLength(5)] + public String PaintTechID; + [FieldFixedLength(35)] + public String PaintTechName; + [FieldFixedLength(80)] + public String CustomerEmail; + [FieldFixedLength(12)] + public Double? GSTTax; + [FieldFixedLength(3)] + public String RepairDelayStatusCode; + [FieldFixedLength(80)] + public String RepairDelaycomment; + [FieldFixedLength(3)] + public String ProductionStageCode; + [FieldFixedLength(80)] + public String ProductionStageComment; + [FieldFixedLength(8)] + [FieldConverter(ConverterKind.Date, "ddMMyyyy")] + public DateTime? Vehiclescheduledindate; + + [FieldFixedLength(20)] + public int AlternateRO; + + + } + + +} diff --git a/BodyshopUploader/Utils/HTTPServer.cs b/BodyshopUploader/Utils/HTTPServer.cs index d111c8d..d7c4a3f 100644 --- a/BodyshopUploader/Utils/HTTPServer.cs +++ b/BodyshopUploader/Utils/HTTPServer.cs @@ -91,6 +91,19 @@ namespace BodyshopPartner.Utils HandlePaintScaleExport(req, res); } , "POST"); + Route.Add("/arms/rodata/", (req, res, props) => + { + hlog("Received an ARMS RO DAta Export Request"); + res.WithCORS(); + res.Close(); + }, "OPTIONS"); + Route.Add("/arms/rodata/", + (req, res, props) => { + hlog("Received an ARMS RO DAta Export Request"); + HandleArmsRODataExtract(req, res); + } + , "POST"); + logger.Trace("Starting HTTP server..."); hlog = HttpLogger; try @@ -314,5 +327,10 @@ namespace BodyshopPartner.Utils await Utils.PPGMixData.PushDataToPPG(); res.WithCORS().AsText("OK"); } + private static async void HandleArmsRODataExtract(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res) + { + await Utils.ARMSRoData.GenerateArmsROData(); + res.WithCORS().AsText("OK"); + } } }