internal static async Task UpdateStorageMilestone(HttpClient httpClient, int serviceOrderId, Move move, int jobId, Vendor vendorEntity, string regNumber, List <InsuranceClaims> legacyInsuranceClaims) { var legacyStorageEntity = move.StorageAgent; var icRecord = legacyInsuranceClaims.FirstOrDefault(); var soSTUrl = $"/{jobId}/services/orders/{serviceOrderId}?serviceName=ST"; var original = await CallJobsApi(httpClient, soSTUrl, null); var copyOfOriginal = original; var origObj = Convert <GetServiceOrderStorageResponse>(original, regNumber); var modifiedObj = Convert <GetServiceOrderStorageResponse>(copyOfOriginal, regNumber); modifiedObj.VendorId = vendorEntity?.Id; modifiedObj.StorageCostRate = legacyStorageEntity.COST; modifiedObj.StorageCostUnit = legacyStorageEntity.DELY_DOCS; if (icRecord != null) { modifiedObj.InsuranceCostRate = Math.Round((icRecord.PREMIUM_COST * (icRecord.TOTAL_INSURANCE / 1000)).GetValueOrDefault(), 2); } modifiedObj.InsuranceCostUnit = "Monthly"; Trace.WriteLine($"{regNumber}, , Couldn't find Insurance Cost Unit.. defaulting it to Monthly"); await GenerateAndPatch(httpClient, soSTUrl, origObj, modifiedObj); //create a partial delivery entry var pdId = await JobsApi.CreatePartialDelivery(httpClient, jobId, serviceOrderId, regNumber); //update the partial delivery record var pdurl = $"/{jobId}/services/orders/{serviceOrderId}/storage/partialDeliveries"; var originalPartialDeliv = await CallJobsApi(httpClient, pdurl, null); var copyOfOriginalPartialDeliv = originalPartialDeliv; var origPdObj = Convert <SingleResult <IEnumerable <GetStoragePartialDeliveryResponse> > >(originalPartialDeliv, regNumber).Data.Single(pd => pd.Id == pdId); var modifiedPdObj = Convert <SingleResult <IEnumerable <GetStoragePartialDeliveryResponse> > >(copyOfOriginalPartialDeliv, regNumber).Data.Single(pd => pd.Id == pdId); var destination = move.MoveAgents.FirstOrDefault(ma => ma.JobCategory.Equals("DESTINATION")); var weight = destination.SurveyWeight; var partialDeliveryDate = destination.PartialDeliveryDateIn; if (weight.HasValue) { modifiedPdObj.NetWeightLb = weight.ToString(); modifiedPdObj.DateOut = partialDeliveryDate.GetValueOrDefault(DateTime.UtcNow); if (!partialDeliveryDate.HasValue) { Trace.WriteLine($"{regNumber}, , Defaulting date for Partial deliver because ACT_AR_DATE1 is not present here"); } } await GenerateAndPatch(httpClient, pdurl + $"/{pdId}", origPdObj, modifiedPdObj); }
private static async Task <int> addStorageJob(Move move, string regNumber) { Console.WriteLine("Creating a job in Arive"); Trace.WriteLine($"{regNumber}, , Creating a job in Arive"); var url = string.Empty; var movesAccount = _accountEntities.FirstOrDefault(ae => ae.AccountingId.Equals(move.AccountId)); var movesBooker = _vendor.FirstOrDefault(ae => ae.Accounting_SI_Code.Equals(move.Booker)); if (movesAccount == null) { if (move.AccountId.Equals("1674") || move.AccountId.Equals("279029") || move.AccountId.Equals("273923") || move.AccountId.Equals("370377") || move.AccountId.Equals("OM1119")) //Shipper Direct { Trace.WriteLine($"{regNumber}, , Missing Account in Arive {move.AccountId}, thus Defaulting Shipper Direct"); movesAccount = _accountEntities.FirstOrDefault(ae => ae.Id == 283); } else if (move.AccountId.Equals("181359")) { Trace.WriteLine($"{regNumber}, , Missing Account in Arive {move.AccountId}, thus Defaulting Overseas Agent"); movesAccount = _accountEntities.FirstOrDefault(ae => ae.Name == "OVERSEAS AGENT BOOKING"); } else { throw new Exception($"Missing Account in Arive {move.AccountId}"); } } var response = await DetermineBillTo(move.BILL, null, regNumber); if (response.BilltoId == null) { Trace.WriteLine($"{regNumber}, , Missing BillTo in Arive {move.BILL}"); Trace.WriteLine($"{regNumber}, , Defaulting BillTo as Shipper Direct"); response.BilltoId = 283; response.BilltoType = "Account"; } var model = move.ToJobModel(movesAccount.Id, movesBooker?.Id, response.BilltoId, response.BilltoType); model.Job.ExternalReference = regNumber; model.Job.ExternalReferenceDescription = "RegNumber from GMMS : Storage Migration"; string parsedResponse = await JobsApi.CallJobsApi(_httpClient, url, model); Console.WriteLine($"Job created {parsedResponse}"); Trace.WriteLine($"{regNumber},{parsedResponse} , Job created"); return(int.Parse(parsedResponse)); }
private static async Task addJobContacts(Move move, int jobId, string regNumber) { var jobContactList = new List <CreateJobContactDto>(); for (int i = 0; i < 5; i++) { var dictionaryValue = string.Empty; var contactType = string.Empty; switch (i) { case 0: contactType = "Biller Contact"; dictionaryValue = NameTranslator.repo.GetValueOrDefault(move.BILLER.Format()); break; case 1: contactType = "Move Consultant"; var nameToUse = string.Empty; if (!string.IsNullOrEmpty(move.MOVE_MANAGER) && !move.MOVE_MANAGER.Equals("STORAGE")) { nameToUse = move.MOVE_MANAGER.Format(); } else { if (!string.IsNullOrEmpty(move.MOVE_COORDINATOR) && !move.MOVE_COORDINATOR.Equals("STORAGE")) { nameToUse = move.MOVE_COORDINATOR.Format(); } else { Console.WriteLine("Defaulting MoveConsultant to Angela La Fronza due to bad data"); Trace.WriteLine($"{regNumber}, , Defaulting MoveConsultant to Angela La Fronza due to bad data"); nameToUse = "Angela.Lafronza"; } } dictionaryValue = NameTranslator.repo.GetValueOrDefault(nameToUse); if (string.IsNullOrEmpty(dictionaryValue)) { Trace.WriteLine($"{regNumber}, , Move Consultant from GMMS {nameToUse} couldn't be found in Arive thus Defaulting to Angela La Fronza"); dictionaryValue = NameTranslator.repo.GetValueOrDefault("Angela.Lafronza"); } break; case 2: contactType = "Traffic Consultant"; dictionaryValue = NameTranslator.repo.GetValueOrDefault(move.TRAFFIC_MANAGER.Format()); break; case 3: contactType = "Pricing Consultant"; dictionaryValue = NameTranslator.repo.GetValueOrDefault(move.QUOTED_BY.Format()); break; case 4: contactType = "Salesperson Contact"; dictionaryValue = NameTranslator.repo.GetValueOrDefault(move.SALES.Format()); break; } if (!string.IsNullOrEmpty(dictionaryValue)) { var adObj = await SungateApi.GetADName(_httpClient, dictionaryValue, regNumber); if ((adObj == null || adObj.Count == 0) && contactType.Equals("Move Consultant")) { Console.WriteLine("User not found in sungate"); Trace.WriteLine($"{regNumber}, , user not found in sungate"); dictionaryValue = NameTranslator.repo.GetValueOrDefault("Angela.Lafronza"); adObj = await SungateApi.GetADName(_httpClient, dictionaryValue, regNumber); } if (adObj == null || adObj.Count == 0) { Console.WriteLine("User not found in sungate"); Trace.WriteLine($"{regNumber}, , user not found in sungate"); continue; } jobContactList.Add(new CreateJobContactDto { ContactType = contactType, Email = adObj.FirstOrDefault().email, FullName = adObj.FirstOrDefault().fullName, Phone = adObj.FirstOrDefault().phone }); } } Console.WriteLine("Adding Job Contacts"); Trace.WriteLine($"{regNumber}, , Adding Job Contacts"); var url = $"/{jobId}/contacts"; await JobsApi.CallJobsApi(_httpClient, url, jobContactList); }
private static async Task Main(string[] args) { loadAllRecords = true; SetConsoleWriteLine(); SetMovesToImport(loadAllRecords); await RetrieveJobsAccountAndVendor(); Trace.WriteLine($"GMMS REG Number, Arive Job# , Log text "); int counter = 0; var jobId = 0; //Normal Import foreach (var regNumber in movesToImport) { try { Console.WriteLine("-----------------------------------------------------------------------------------"); Console.WriteLine($"Processing { ++counter} records of {movesToImport.Count} to import"); Trace.WriteLine($"{regNumber}, , "); Trace.WriteLine($"{regNumber}, , -----------------------------------------------------------------------------------"); await SungateApi.setApiAccessTokenAsync(_httpClient); var move = await WaterDbAccess.RetrieveWaterRecords(regNumber); if (move == null) { continue; } //Add the job jobId = await addStorageJob(move, regNumber); //update datecreated on the job JobsDbAccess.ChangeDateCreated(jobId, move.DateEntered.GetValueOrDefault(DateTime.UtcNow), regNumber); //Add JobContacts await addJobContacts(move, jobId, regNumber); //Add SuperService var result = await JobsApi.CreateStorageSSO(_httpClient, jobId, regNumber); var ssoId = result.Id; var serviceOrders = await JobsDbAccess.GetServiceOrderForJobs(jobId, regNumber); // ORIGIN var oaVendor = _vendor.Find(v => v.Accounting_SI_Code.Equals(move.OriginAgent.VendorNameId)); await JobsApi.UpdateOriginMilestone(_httpClient, serviceOrders.FirstOrDefault(so => so.ServiceId == 24).Id, oaVendor, move, jobId, regNumber); // DESTINATION var daVendor = _vendor.Find(v => v.Accounting_SI_Code.Equals(move.DestinationAgent.VendorNameId)); await JobsApi.UpdateDestinationMilestone(_httpClient, serviceOrders.FirstOrDefault(so => so.ServiceId == 26).Id, daVendor, move, jobId, regNumber); var legacyInsuranceClaims = await WaterDbAccess.RetrieveInsuranceClaims(move.RegNumber); // STORAGE var transfereeEntity = await JobsDbAccess.GetJobsTransfereeId(jobId); await updateStorageJob(move, jobId, serviceOrders, regNumber, transfereeEntity, legacyInsuranceClaims, ssoId); // INSURANCE await JobsApi.UpdateICtMilestone(_httpClient, serviceOrders.FirstOrDefault(so => so.ServiceId == 27).Id, move, jobId, legacyInsuranceClaims, regNumber); #region JobCost var superServiceOrderId = serviceOrders.FirstOrDefault(so => so.ServiceId == 29).SuperServiceOrderId; try { if (move.READY_TO_ACCRUE_DATE != null) { await JobsDbAccess.LockJC(jobId, regNumber, superServiceOrderId, move.READY_TO_ACCRUE_DATE.Value); await JobsDbAccess.MarkAsPosted(superServiceOrderId, DateTime.Now, true, regNumber, move.ACCRUED_DATE); //await JobsDbAccess.MarkAllAsVoid(superServiceOrderId, regNumber); } } catch (Exception ex) { Console.WriteLine("Error while trying to change JC status manually"); Trace.WriteLine($"{regNumber}, , Error while trying to change JC status manually"); Trace.WriteLine($"{regNumber}, , {ex.Message}"); } #endregion JobCost //Add Notes await AddNotesFromGmmsToArive(move, jobId, regNumber); //Add Prompts await AddPromptsFromGmmsToArive(move, jobId, regNumber); decimal percentage = (decimal)(counter * 100) / movesToImport.Count; Console.WriteLine($"{ Math.Round(percentage, 2)}% Completed "); Trace.WriteLine($"{regNumber}, , EndTime: {DateTime.Now}"); } catch (Exception ex) { Trace.WriteLine($"{regNumber}, , *** ERROR ***"); if (ex.InnerException != null) { Trace.WriteLine($"{regNumber}, , {ex.InnerException.Message}"); } else { Trace.WriteLine($"{regNumber}, , {ex.Message}"); } Console.WriteLine($"**** ERROR ****"); Console.WriteLine($"{ex.Message}"); } Trace.Flush(); } //Remove Prompts from MigrationScript TaskDbAccess.RemovePrompts(); }
private static async Task updateStorageJob(Move move, int jobId, List <ServiceOrder> serviceOrders, string regNumber, Transferee transferee, List <InsuranceClaims> legacyInsuranceClaims, int ssoId) { try { Console.WriteLine("Updating ST"); Trace.WriteLine($"{regNumber}, , Updating ST Expense record"); var vendorEntity = _vendor.FirstOrDefault(v => v.Accounting_SI_Code == move.StorageAgent.VendorNameId); var soId = serviceOrders.FirstOrDefault(so => so.ServiceId == 32 && so.SuperServiceOrderId == ssoId).Id; await JobsApi.UpdateStorageMilestone(_httpClient, soId, move, jobId, vendorEntity, regNumber, legacyInsuranceClaims); var storageRevId = await JobsApi.AddStorageRevRecord(_httpClient, soId, move, jobId, regNumber); dynamic billTo = null; var billToLabel = string.Empty; billTo = _accountEntities.FirstOrDefault(ae => ae.AccountingId.Equals(move.StorageAgent.HOW_SENT)); if (billTo != null) { billToLabel = "Account"; } else { billTo = _vendor.FirstOrDefault(ae => ae.Accounting_SI_Code.Equals(move.StorageAgent.HOW_SENT)); if (billTo != null) { billToLabel = "Vendor"; } } if (billTo == null) { //check to see if billto is transferee var NamesRecord = await WaterDbAccess.GetNames(move.StorageAgent.HOW_SENT); if (NamesRecord != null && NamesRecord.FirstName.Equals(transferee.FirstName, StringComparison.CurrentCultureIgnoreCase) && NamesRecord.LastName.Equals(transferee.LastName, StringComparison.CurrentCultureIgnoreCase)) { billTo = transferee; billToLabel = "Transferee"; } else { Console.WriteLine($"{regNumber}, , Cant find the billto for Storage so we are defaulting it"); Trace.WriteLine($"{regNumber}, , Cant find the billto for Storage so we are defaulting it"); } } if (!string.IsNullOrEmpty(move.StorageAgent.HOW_SENT) && billTo == null) { Trace.WriteLine($"{regNumber}, , Missing Storage BillTo {move.StorageAgent.HOW_SENT}"); } await JobsApi.updateStorageRevRecord(_httpClient, soId, storageRevId, move, jobId, regNumber, billTo, billToLabel, legacyInsuranceClaims); } catch (Exception ex) { Console.WriteLine("Error while updating ST"); Trace.WriteLine($"{regNumber}, , Error while updating ST"); Trace.WriteLine($"{regNumber}, , {ex.Message}"); } }