This commit is contained in:
@@ -3766,13 +3766,19 @@ namespace AyaNova.Biz
|
||||
{
|
||||
//static method
|
||||
long WoId = await GetWorkOrderIdFromRelativeAsync(ayaType, id, ct);
|
||||
return await ct.WorkOrderState.AsNoTracking()
|
||||
var currentStatus = await ct.WorkOrderState.AsNoTracking()
|
||||
.Include(z => z.WorkOrderStatus)
|
||||
.Where(z => z.WorkOrderId == WoId)
|
||||
.OrderBy(z => z.Created)
|
||||
.Select(z => z.WorkOrderStatus)
|
||||
.Take(1)
|
||||
.FirstOrDefaultAsync();
|
||||
if (currentStatus == null)
|
||||
{
|
||||
//default
|
||||
return new WorkOrderStatus() { Id = -1, Locked = false, Completed = false };
|
||||
}
|
||||
return currentStatus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2194,78 +2194,36 @@ namespace AyaNova.Util
|
||||
//
|
||||
public async Task SeedWorkOrderAsync(ILogger log, int count)
|
||||
{
|
||||
DateTime seedStartWindow = DateTime.Now.AddYears(-1);
|
||||
DateTime seedEndWindow = DateTime.Now.AddDays(-5);
|
||||
DateTime seedStartWindow = DateTime.Now.AddMonths(-9);
|
||||
DateTime seedEndWindow = DateTime.Now.AddMonths(3);
|
||||
for (int x = 0; x < count; x++)
|
||||
{
|
||||
WorkOrder o = new WorkOrder();
|
||||
o.Notes = Fake.Lorem.Sentence();
|
||||
o.Tags = RandomTags();
|
||||
o.InternalReferenceNumber = "irf-" + Fake.Finance.Account(4);
|
||||
o.Active
|
||||
|
||||
|
||||
var woDate = Fake.Date.Between(seedStartWindow, seedEndWindow);
|
||||
o. = woDate.ToUniversalTime();
|
||||
o.ExpectedReceiveDate = woDate.AddDays(5).ToUniversalTime();
|
||||
|
||||
|
||||
o.VendorMemo = Fake.Lorem.Sentence();
|
||||
if (Fake.Random.Number(1, 10) == 5)
|
||||
o.ProjectId = Fake.Random.Long(1, TotalSeededProjects);
|
||||
|
||||
o.Text1 = Fake.Lorem.Sentence(1, 3);
|
||||
o.Text2 = Fake.Lorem.Sentence(1, 3);
|
||||
|
||||
List<long> partsAdded = new List<long>();
|
||||
int partCount = Fake.Random.Int(1, 5);
|
||||
|
||||
|
||||
|
||||
|
||||
//simulate some items without tax codes
|
||||
bool addTaxCode = (Fake.Random.Number(1, 4) != 3);
|
||||
|
||||
//simulate some items not received
|
||||
bool isReceived = (Fake.Random.Number(1, 4) != 3);
|
||||
|
||||
o.Status = isReceived ? WorkOrderStatus.ClosedFullReceived : WorkOrderStatus.OpenOrdered;
|
||||
|
||||
for (int y = 0; y < partCount; y++)
|
||||
o.CompleteByDate = woDate.AddDays(5).ToUniversalTime();
|
||||
o.CustomerContactName="contact name here";
|
||||
o.CustomerId = Fake.Random.Long(1, TotalSeededCustomers);
|
||||
o.CustomerReferenceNumber = "crf-" + Fake.Finance.Account(4);
|
||||
o.InternalReferenceNumber = "irf-" + Fake.Finance.Account(4);
|
||||
o.ServiceDate=woDate.ToUniversalTime();
|
||||
|
||||
int woItemCount = Fake.Random.Int(1, 3);
|
||||
for (int y = 0; y < woItemCount; y++)
|
||||
{
|
||||
long partId = 0;
|
||||
do
|
||||
{
|
||||
partId = Fake.Random.Long(1, TotalSeededParts);
|
||||
} while (partsAdded.Contains(partId));
|
||||
partsAdded.Add(partId);
|
||||
var qty = Fake.Random.Int(1, 5);
|
||||
var cost = Fake.Random.Decimal(1, 25);
|
||||
|
||||
// 50% chance it has received serial numbers
|
||||
string serials = string.Empty;
|
||||
if (isReceived && Fake.Random.Number() == 1)
|
||||
{
|
||||
var serialStart = Fake.Finance.Account().ToString();
|
||||
for (int si = 0; si < qty; si++)
|
||||
{
|
||||
serials += serialStart + si.ToString() + ", ";
|
||||
|
||||
}
|
||||
serials = serials.TrimEnd().TrimEnd(',');
|
||||
}
|
||||
|
||||
o.Items.Add(new WorkOrderItem()
|
||||
{
|
||||
PartId = partId,
|
||||
PartWarehouseId = Fake.Random.Long(1, 3),
|
||||
QuantityOrdered = qty,
|
||||
QuantityReceived = isReceived ? qty : 0,
|
||||
WorkOrderCost = cost,
|
||||
ReceivedCost = isReceived ? cost : 0,
|
||||
ReceivedDate = isReceived ? o.ExpectedReceiveDate : null,
|
||||
PurchaseTaxCodeId = addTaxCode ? 3 : null,//sales and goods
|
||||
Serials = serials
|
||||
|
||||
// PartId = partId,
|
||||
// PartWarehouseId = Fake.Random.Long(1, 3),
|
||||
// QuantityOrdered = qty,
|
||||
// QuantityReceived = isReceived ? qty : 0,
|
||||
// WorkOrderCost = cost,
|
||||
// ReceivedCost = isReceived ? cost : 0,
|
||||
// ReceivedDate = isReceived ? o.ExpectedReceiveDate : null,
|
||||
// PurchaseTaxCodeId = addTaxCode ? 3 : null,//sales and goods
|
||||
// Serials = serials
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user