This commit is contained in:
2021-07-29 19:19:25 +00:00
parent 9014cc33aa
commit c76e1cad3b
3 changed files with 140 additions and 5 deletions

View File

@@ -5249,19 +5249,148 @@ namespace AyaNova.Biz
#if (DEBUG)
log.LogInformation($"PMBiz - processing pm id {pmid}");
#endif
//make new workorder
if (await NewServiceWorkOrderFromPMAsync(ct, log))
var p = await ct.PM.Where(x => x.Id == pmid).FirstOrDefaultAsync();
if (p == null)
{
log.LogError($"PMBiz - PM was not fetchable when attempting to process PM id: {pmid}, deleted during processing?");
continue;
}
//make new workorder
if (await NewServiceWorkOrderFromPMAsync(p, ct, log))
{
//fixup dates and update pm
//fixup dates and update pm
//note p is ready to modify and save here as it's tracked
}
}
}
internal static async Task<bool> NewServiceWorkOrderFromPMAsync(AyContext ct, ILogger log)
internal static async Task<bool> NewServiceWorkOrderFromPMAsync(PM p, AyContext ct, ILogger log)
{
WorkOrder o = new WorkOrder();
o.Address = p.Address;
o.City = p.City;
//o.CompleteByDate=??
o.ContractId = p.ContractId;
o.Country = p.Country;
o.CreatedDate = DateTime.UtcNow;
o.CustomerContactName = p.CustomerContactName;
o.CustomerId = p.CustomerId;
o.CustomerReferenceNumber = p.CustomerReferenceNumber;
o.CustomFields = p.CustomFields;
o.FromPMId = p.Id;
o.InternalReferenceNumber = p.InternalReferenceNumber;
o.Latitude = p.Latitude;
o.Longitude = p.Longitude;
o.Notes = p.Notes;
o.Onsite = p.Onsite;
o.PostAddress = p.PostAddress;
o.PostCity = p.PostCity;
o.PostCode = p.PostCode;
o.PostCountry = p.PostCountry;
o.PostRegion = p.PostRegion;
o.ProjectId = p.ProjectId;
o.Region = p.Region;
o.ServiceDate = p.NextServiceDate;
o.Tags = p.Tags;
if (p.CopyWiki)
o.Wiki = p.Wiki;
if (p.CopyAttachments)
o.GenCopyAttachmentsFrom = new AyaTypeId(AyaType.PM, p.Id);
foreach (PMItem pmi in p.Items)
{
var woi = new WorkOrderItem();
woi.Notes = pmi.Notes;
woi.RequestDate = pmi.RequestDate;
woi.Sequence = pmi.Sequence;
woi.Tags = pmi.Tags;
woi.TechNotes = pmi.TechNotes;
woi.WarrantyService = pmi.WarrantyService;
if (p.CopyWiki)
woi.Wiki = pmi.Wiki;
woi.WorkorderItemPriorityId = pmi.WorkOrderItemPriorityId;
woi.WorkorderItemStatusId = pmi.WorkOrderItemStatusId;
foreach (PMItemUnit pmiunit in pmi.Units)
{
var woiunit = new WorkOrderItemUnit();
woiunit.CustomFields = pmiunit.CustomFields;
woiunit.Notes = pmiunit.Notes;
woiunit.Tags = pmiunit.Tags;
woiunit.UnitId = pmiunit.UnitId;
if (p.CopyWiki)
woiunit.Wiki = pmiunit.Wiki;
woi.Units.Add(woiunit);
}
foreach (PMItemScheduledUser pmsu in pmi.ScheduledUsers)
{
var wois = new WorkOrderItemScheduledUser();
wois.ServiceRateId = pmsu.ServiceRateId;
//Note: sched users were not in v7 pm's but adding "ALL THE THINGS"
//so the dates would be screwed up and could conflict if allow sched conflicts is
//set to false.
//We can't really guess what to schedule as so the sane choice seems to be to
//not set a date but keep them so user can schedule to wherever they want
//as null dates for sched user are supported
wois.StartDate = null;//pmischeduser.StartDate;
wois.StopDate = null;//pmischeduser.StopDate;
wois.Tags = pmsu.Tags;
wois.UserId = pmsu.UserId;
woi.ScheduledUsers.Add(wois);
}
foreach (PMItemPart pmp in pmi.Parts)
{
var wip = new WorkOrderItemPart();
wip.Description = pmp.Description;
wip.PartId = pmp.PartId;
wip.PriceOverride = pmp.PriceOverride;
wip.Quantity = pmp.Quantity;
//wip.Serials=pmp.Serials;
wip.Tags = pmp.Tags;
wip.TaxPartSaleId = pmp.TaxPartSaleId;
woi.Parts.Add(wip);
}
foreach (PMItemLoan pml in pmi.Loans)
{
var wil = new WorkOrderItemLoan();
wil.LoanUnitId = pml.LoanUnitId;
wil.Notes = pml.Notes;
wil.PriceOverride = pml.PriceOverride;
wil.Quantity = pml.Quantity;
wil.Rate = pml.Rate;
wil.Tags = pml.Tags;
wil.TaxCodeId = pml.TaxCodeId;
woi.Loans.Add(wil);
}
foreach(PMItemLabor pmlab in pmi.Labors){
var wilab = new WorkOrderItemLabor();
wilab.NoChargeQuantity=pmlab.NoChargeQuantity;
wilab.PriceOverride=pmlab.PriceOverride;
wilab.ServiceDetails=pmlab.ServiceDetails;
wilab.ServiceRateId=pmlab.ServiceRateId;
wilab.ServiceRateQuantity=pmlab.ServiceRateQuantity;
wilab.Tags=pmlab.Tags;
wilab.TaxCodeSaleId=pmlab.TaxCodeSaleId;
wilab.UserId=pmlab.UserId;
woi.Labors.Add(wilab);
}
//------------
}
return true;
}

View File

@@ -2882,7 +2882,6 @@ namespace AyaNova.Util
};
woItem.ScheduledUsers.Add(woItemScheduledUser);
woItemScheduledUser = new WorkOrderItemScheduledUser()
{
UserId = RandomServiceTechUserId(),