WIP ARMS integration.
This commit is contained in:
240
BodyshopUploader/Utils/ARMSRoData.cs
Normal file
240
BodyshopUploader/Utils/ARMSRoData.cs
Normal file
@@ -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<ARMSRoDataModel> engine = new FileHelperEngine<ARMSRoDataModel>();
|
||||
|
||||
|
||||
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<ARMSRoDataModel>();
|
||||
|
||||
Regex ROStripper = new Regex(@"\d");
|
||||
|
||||
|
||||
foreach (dynamic job in data.jobs)
|
||||
{
|
||||
|
||||
|
||||
|
||||
var RoNumber = string.Join("", Regex.Matches((string)(job.ro_number?.Value), @"\d").OfType<Match>().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: ");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user