|
|
@ -122,6 +122,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
/// <summary>
|
|
|
|
/// 导入
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// JisBBAC结算数据导入(导入文件中包含买单件BBAC的数据)
|
|
|
|
/// 导入文件规则
|
|
|
|
/// * MovementType = 967,代表退货需要标记为负数
|
|
|
|
/// * MovementType = 966,代表正常发货标记正数
|
|
|
|
/// * PN中存在RO的数据为买单件BBAC的数据
|
|
|
|
/// 买单价PN特殊处理
|
|
|
|
/// * 获取导入PN后2位为生产码类型
|
|
|
|
/// * 获取导入PN前7位为PN
|
|
|
|
/// 验证结算分组号是否已存在
|
|
|
|
/// </remarks>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<IActionResult> ImportAsync([FromForm] BBACSaImportRequestDto bbacSaImportRequestDto) |
|
|
|
{ |
|
|
@ -158,7 +169,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
*/ |
|
|
|
maiDanSaDetails.ForEach(maiDanSaDetail => |
|
|
|
{ |
|
|
|
maiDanSaDetail.PartCode = maiDanSaDetail.PN[^2..]; |
|
|
|
maiDanSaDetail.ProductionCodeType = maiDanSaDetail.PN[^2..]; |
|
|
|
maiDanSaDetail.PN = maiDanSaDetail.PN[..7]; |
|
|
|
}); |
|
|
|
|
|
|
@ -247,63 +258,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
/// <summary>
|
|
|
|
/// 删除
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task DeleteAsync(Guid id) |
|
|
|
{ |
|
|
|
//结算主表
|
|
|
|
BBAC_SA bbacSaDelEntity; |
|
|
|
//结算明细
|
|
|
|
List<BBAC_SA_DETAIL> bbacSaDetailDelEntitys; |
|
|
|
//可结算主表
|
|
|
|
List<BBAC_CAN_SA> bbacCanSaDelEntitys; |
|
|
|
//可结算明细
|
|
|
|
List<BBAC_CAN_SA_DETAIL> bbacCanSaDetailDelEntitys; |
|
|
|
//不可结算
|
|
|
|
List<BBAC_NOT_SA_DETAIL> bbacNotSaDetailDelEntitys; |
|
|
|
|
|
|
|
bbacSaDelEntity = await _bbacSaRepository.FindAsync(id).ConfigureAwait(false); |
|
|
|
if (bbacSaDelEntity == null) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"未获取到结算单!", "400"); |
|
|
|
} |
|
|
|
//结算单据
|
|
|
|
string bbacSaBillNum = bbacSaDelEntity.BillNum; |
|
|
|
|
|
|
|
bbacCanSaDelEntitys = await _bbacCanSaRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum).ConfigureAwait(false); |
|
|
|
//验证可结算主表状态
|
|
|
|
if (bbacCanSaDelEntitys.Any(t => t.State != SettleBillState.未结状态)) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"该单据可结算单状态无法删除!", "400"); |
|
|
|
} |
|
|
|
|
|
|
|
bbacSaDetailDelEntitys = await _bbacSaDetailRepository.GetListAsync(t => t.BillNum == bbacSaBillNum).ConfigureAwait(false); |
|
|
|
bbacCanSaDetailDelEntitys = await _bbacCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum).ConfigureAwait(false); |
|
|
|
bbacNotSaDetailDelEntitys = await _bbacNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum).ConfigureAwait(false); |
|
|
|
|
|
|
|
//删除
|
|
|
|
await _bbacSaRepository.DeleteAsync(bbacSaDelEntity).ConfigureAwait(false); |
|
|
|
if (bbacSaDetailDelEntitys.Any()) |
|
|
|
{ |
|
|
|
await _bbacSaDetailRepository.DeleteManyAsync(bbacSaDetailDelEntitys).ConfigureAwait(false); |
|
|
|
} |
|
|
|
if (bbacCanSaDelEntitys.Any()) |
|
|
|
{ |
|
|
|
await _bbacCanSaRepository.DeleteManyAsync(bbacCanSaDelEntitys).ConfigureAwait(false); |
|
|
|
} |
|
|
|
if (bbacCanSaDetailDelEntitys.Any()) |
|
|
|
{ |
|
|
|
await _bbacCanSaDetailRepository.DeleteManyAsync(bbacCanSaDetailDelEntitys).ConfigureAwait(false); |
|
|
|
} |
|
|
|
if (bbacNotSaDetailDelEntitys.Any()) |
|
|
|
{ |
|
|
|
await _bbacNotSaDetailRepository.DeleteManyAsync(bbacNotSaDetailDelEntitys).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 删除
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// 同时删除
|
|
|
|
/// 结算主表、明细表
|
|
|
|
/// 可结算主表、明细表
|
|
|
|
/// 不可结算明细表(不可结算没主表)
|
|
|
|
/// </remarks>
|
|
|
|
[HttpPost] |
|
|
|
public async Task DeleteListAsync(List<Guid> ids) |
|
|
|
{ |
|
|
@ -364,6 +324,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
/// <summary>
|
|
|
|
/// 处理结算数据
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// 零件号(Lu)格式处理
|
|
|
|
/// 零件号可能存在颜色码 颜色码和塑件码中间统一用6个空格替换
|
|
|
|
/// PN有0开头的数据过滤 '‘’符号
|
|
|
|
/// </remarks>
|
|
|
|
private List<BBAC_SA_DETAIL> HandleSaDetails(List<BBAC_SA_DETAIL> bbacSaDetails) |
|
|
|
{ |
|
|
|
bbacSaDetails.ForEach(bbacSaDetail => |
|
|
@ -378,15 +343,18 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
} |
|
|
|
bbacSaDetail.PN = Regex.Replace(bbacSaDetail.PN, "['‘’]", ""); |
|
|
|
}); |
|
|
|
return GroupPnLu(bbacSaDetails); |
|
|
|
return bbacSaDetails; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 结算数据分组Pn、Lu
|
|
|
|
/// 结算数据分组
|
|
|
|
/// </summary>
|
|
|
|
private List<BBAC_SA_DETAIL> GroupPnLu(List<BBAC_SA_DETAIL> bbacSaDetails) |
|
|
|
/// <remarks>
|
|
|
|
/// 根据PN、客户零件号、结算分组、结算日期分组合计数量
|
|
|
|
/// </remarks>
|
|
|
|
private List<BBAC_SA_DETAIL> GroupSaDetails(List<BBAC_SA_DETAIL> bbacSaDetails) |
|
|
|
{ |
|
|
|
return bbacSaDetails.GroupBy(t => new { t.PN, t.LU }).Select(t => |
|
|
|
return bbacSaDetails.GroupBy(t => new { t.PN, t.LU, t.GroupNum, t.SettleDate }).Select(t => |
|
|
|
{ |
|
|
|
var bbacSaDetail = t.First(); |
|
|
|
bbacSaDetail.Qty = t.Sum(t => t.Qty); |
|
|
@ -397,8 +365,16 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
/// <summary>
|
|
|
|
/// 结算数据处理
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// 匹配价格
|
|
|
|
/// * 根据客户编码、业务、零件号、时间匹配价格
|
|
|
|
/// 匹配对应的厂内零件号
|
|
|
|
/// 结算数据入库
|
|
|
|
/// * 入库 结算主表、结算明细表、可结算主表、可结算明细表、不可结算明细表
|
|
|
|
/// </remarks>
|
|
|
|
private async Task SaDataHandleAsync(List<BBAC_SA_DETAIL> bbacSaDetails) |
|
|
|
{ |
|
|
|
bbacSaDetails = GroupSaDetails(bbacSaDetails); |
|
|
|
//结算单号
|
|
|
|
var bbacSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); |
|
|
|
//结算主表
|
|
|
@ -442,7 +418,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
//导入的零件号集合
|
|
|
|
var importPubSaLUs = bbacSaDetails.Select(t => t.LU).Distinct(); |
|
|
|
//销售价格
|
|
|
|
|
|
|
|
var priceListEntitys = GetPriceListEntitys(importPubSaLUs); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => new List<EnumBusinessType> { EnumBusinessType.JisBBAC, EnumBusinessType.MaiDanJianBBAC }.Contains(t.BusinessType) && importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); |
|
|
|
bbacSaDetails.ForEach(bbacSaDetail => |
|
|
@ -517,6 +492,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
/// <summary>
|
|
|
|
/// 获取结算关联项
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// 根据结算主表Id获取关联的结算主表、结算明细表、可结算主表、可结算明细表、不可结算明细表要删除的数据
|
|
|
|
/// 验证可结算主表状态
|
|
|
|
/// 只有可结算主表状态为未结状态时才可以删除结算数据
|
|
|
|
/// </remarks>
|
|
|
|
private async Task<(List<BBAC_SA> bbacSas, List<BBAC_SA_DETAIL> bbacSaDetails, List<BBAC_CAN_SA> bbacCanSas, List<BBAC_CAN_SA_DETAIL> bbacCanSaDetails, List<BBAC_NOT_SA_DETAIL> bbacNotSaDetails)> GetBBACSaDelItemsAsync(Guid id) |
|
|
|
{ |
|
|
|
//结算主表
|
|
|
|