|
|
@ -219,11 +219,16 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran |
|
|
|
{ |
|
|
|
using var scope = _serviceProvider.CreateScope(); |
|
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
|
var balance = db.Set<VmiBalance>().FirstOrDefault(o => o.BillType == data.BillType && |
|
|
|
o.PartCode == data.PartCode && |
|
|
|
o.VinCode == data.VinCode && |
|
|
|
o.ErpToLoc == data.ErpToLoc && |
|
|
|
o.OrderNum == data.OrderNum); |
|
|
|
|
|
|
|
var balance = db.Set<VmiBalance>().FirstOrDefault( |
|
|
|
o => o.BillType == data.BillType && |
|
|
|
o.CodeType == data.CodeType && |
|
|
|
o.PartCode == data.PartCode && |
|
|
|
o.VinCode == data.VinCode && |
|
|
|
o.ErpToLoc == data.ErpToLoc && |
|
|
|
o.OrderNum == data.OrderNum && |
|
|
|
o.factory == data.factory && |
|
|
|
o.Configcode == data.Configcode); |
|
|
|
|
|
|
|
var log = new VmiLog |
|
|
|
{ |
|
|
@ -234,20 +239,34 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran |
|
|
|
ChangedBy = _currentUser.UserName, |
|
|
|
ChangedQty = data.Qty, |
|
|
|
}; |
|
|
|
log.InjectFrom(data); |
|
|
|
|
|
|
|
if (balance == null) |
|
|
|
{ |
|
|
|
balance = new VmiBalance(GuidGenerator.Create()); |
|
|
|
balance.InjectFrom(data); |
|
|
|
// 初始化库存
|
|
|
|
balance.Qty = data.Qty; |
|
|
|
balance.SetId(GuidGenerator.Create()); |
|
|
|
await db.Set<VmiBalance>().AddAsync(balance).ConfigureAwait(false); |
|
|
|
//新建库存,库存事务种库存备份的初始库存为0
|
|
|
|
log.InjectFrom(balance); |
|
|
|
log.Qty = 0; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//已有库存,直接备份
|
|
|
|
log.InjectFrom(balance); |
|
|
|
var qty = balance.Qty + data.Qty; |
|
|
|
balance.InjectFrom(data); |
|
|
|
if (logType == VmiLogType.Type100) |
|
|
|
{ |
|
|
|
//发运入库,只更新库存
|
|
|
|
} |
|
|
|
else if (logType == VmiLogType.Type300) |
|
|
|
{ |
|
|
|
//反结入库,只更新库存
|
|
|
|
} |
|
|
|
else if (logType == VmiLogType.Type500) |
|
|
|
{ |
|
|
|
//调整入库,更新库存和其他字段
|
|
|
|
balance.InjectFrom(data); |
|
|
|
} |
|
|
|
// 加库存
|
|
|
|
balance.Qty = qty; |
|
|
|
if (balance.Qty == decimal.Zero) |
|
|
@ -281,33 +300,57 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran |
|
|
|
{ |
|
|
|
using var scope = _serviceProvider.CreateScope(); |
|
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
|
var balance = db.Set<VmiBalance>().FirstOrDefault(o => o.BillType == data.BillType && o.PartCode == data.PartCode && o.VinCode == data.VinCode && o.ErpToLoc == data.ErpToLoc && o.OrderNum == data.OrderNum); |
|
|
|
var balance = db.Set<VmiBalance>().FirstOrDefault( |
|
|
|
o => o.BillType == data.BillType && |
|
|
|
o.CodeType == data.CodeType && |
|
|
|
o.PartCode == data.PartCode && |
|
|
|
o.VinCode == data.VinCode && |
|
|
|
o.ErpToLoc == data.ErpToLoc && |
|
|
|
o.OrderNum == data.OrderNum && |
|
|
|
o.factory == data.factory && |
|
|
|
o.Configcode == data.Configcode); |
|
|
|
var log = new VmiLog |
|
|
|
{ |
|
|
|
LogType = logType, |
|
|
|
ChangedType = VmiType.Out, |
|
|
|
ChangedType = VmiType.In, |
|
|
|
ChangedNumber = changedNumber, |
|
|
|
ChangedTime = DateTime.Now, |
|
|
|
ChangedBy = _currentUser.UserName, |
|
|
|
ChangedQty = data.Qty, |
|
|
|
}; |
|
|
|
log.InjectFrom(data); |
|
|
|
log.LogType = logType; |
|
|
|
log.ChangedType = VmiType.Out; |
|
|
|
log.ChangedTime = DateTime.Now; |
|
|
|
log.ChangedBy = _currentUser.UserName; |
|
|
|
log.ChangedQty = data.Qty; |
|
|
|
|
|
|
|
if (balance == null) |
|
|
|
{ |
|
|
|
balance = new VmiBalance(); |
|
|
|
//负库存出库
|
|
|
|
balance = new VmiBalance(GuidGenerator.Create()); |
|
|
|
balance.InjectFrom(data); |
|
|
|
//新建库存,库存事务种库存备份的初始库存为0
|
|
|
|
log.InjectFrom(data); |
|
|
|
log.Qty = 0; |
|
|
|
// 负库存
|
|
|
|
balance.Qty = -data.Qty; |
|
|
|
balance.SetId(GuidGenerator.Create()); |
|
|
|
await db.Set<VmiBalance>().AddAsync(balance).ConfigureAwait(false); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//已有库存,直接备份
|
|
|
|
log.InjectFrom(data);//更新附加字段
|
|
|
|
log.InjectFrom(balance);//备份库存
|
|
|
|
// 减库存
|
|
|
|
balance.Qty -= data.Qty; ; |
|
|
|
if (logType == VmiLogType.Type200) |
|
|
|
{ |
|
|
|
//结算出库,只更新库存
|
|
|
|
} |
|
|
|
else if (logType == VmiLogType.Type400) |
|
|
|
{ |
|
|
|
//退货出库,只更新库存
|
|
|
|
} |
|
|
|
else if (logType == VmiLogType.Type600) |
|
|
|
{ |
|
|
|
//调整出库,更新库存和其他字段
|
|
|
|
balance.InjectFrom(data); |
|
|
|
} |
|
|
|
if (balance.Qty == decimal.Zero) |
|
|
|
{ |
|
|
|
db.Set<VmiBalance>().Remove(balance); |
|
|
@ -335,7 +378,7 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran |
|
|
|
o.OrderNum == item.OrderNum); |
|
|
|
if (balance == null) |
|
|
|
{ |
|
|
|
balance = new VmiBalance(); |
|
|
|
balance = new VmiBalance(GuidGenerator.Create()); |
|
|
|
balance.InjectFrom(item); |
|
|
|
await _balanceRepository.InsertAsync(balance).ConfigureAwait(false); |
|
|
|
} |
|
|
@ -376,7 +419,7 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran |
|
|
|
var entities = await _balanceRepository.WhereIf(input.Filters?.Count != 0, input.Filters.ToLambda<VmiBalance>()) |
|
|
|
.ToListAsync().ConfigureAwait(false); |
|
|
|
var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss")}.xlsx"; |
|
|
|
var content = this.GetContent<VmiBalance>(entities, "库存备份"); |
|
|
|
var content = this.GetContent(entities, "库存备份"); |
|
|
|
await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false); |
|
|
|
return fileName; |
|
|
|
} |
|
|
@ -393,10 +436,13 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran |
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<PagedResultDto<VmiLog>> Log(RequestDto input) |
|
|
|
public async Task<PagedResultDto<VmiLog>> Log(LogRequestDto input) |
|
|
|
{ |
|
|
|
var entities = await _logRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); |
|
|
|
var totalCount = await _logRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); |
|
|
|
var query = _logRepository.WhereIf(input.Filters?.Count != 0, input.Filters.ToLambda<VmiLog>()) |
|
|
|
.WhereIf(input.LogTypes?.Count != 0, o => input.LogTypes.Contains(o.LogType)); |
|
|
|
var totalCount = await query.CountAsync().ConfigureAwait(false); |
|
|
|
query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); |
|
|
|
var entities = query.Skip(input.SkipCount).Take(input.MaxResultCount).ToList(); |
|
|
|
return new PagedResultDto<VmiLog>(totalCount, entities); |
|
|
|
//return QueryLogFromTSDb(input);
|
|
|
|
} |
|
|
@ -596,3 +642,8 @@ public class BackupListRequest : RequestDto |
|
|
|
[Required] |
|
|
|
public string Name { get; set; } |
|
|
|
} |
|
|
|
|
|
|
|
public class LogRequestDto : RequestDto |
|
|
|
{ |
|
|
|
public List<VmiLogType> LogTypes { get; set; } = new List<VmiLogType>(); |
|
|
|
} |
|
|
|