|
|
@ -1,28 +1,26 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using SettleAccount.Domain.BQ; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Volo.Abp; |
|
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Win.Abp.Snowflakes; |
|
|
|
using Win.Sfs.BaseData.ImportExcelCommon; |
|
|
|
using Win.Sfs.SettleAccount.CommonManagers; |
|
|
|
using Win.Sfs.SettleAccount.Entities.Prices; |
|
|
|
using Win.Sfs.SettleAccount.MaterialRelationships; |
|
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Win.Sfs.SettleAccount.Bases; |
|
|
|
using Win.Sfs.SettleAccount.CommonManagers; |
|
|
|
using Win.Sfs.SettleAccount.Constant; |
|
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; |
|
|
|
using Win.Sfs.SettleAccount.Entities.Prices; |
|
|
|
using Win.Sfs.SettleAccount.ExcelImporter; |
|
|
|
using Win.Sfs.SettleAccount.ExportReports; |
|
|
|
using OfficeOpenXml; |
|
|
|
using OfficeOpenXml.Core; |
|
|
|
using Win.Sfs.SettleAccount.MaterialRelationships; |
|
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
|
|
|
|
|
namespace Win.Sfs.SettleAccount.Entities.BQ; |
|
|
|
|
|
|
@ -73,6 +71,11 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
/// </summary>
|
|
|
|
private readonly INormalEfCoreRepository<TB_RePartsRelationship, Guid> _tbRePartsRelationshipRepository; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 业务类型
|
|
|
|
/// </summary>
|
|
|
|
private readonly EnumBusinessType _businessType = EnumBusinessType.JisHBPO; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 构造
|
|
|
|
/// </summary>
|
|
|
@ -142,12 +145,19 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
#region 导入数据转换、数据校验
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
var result = await _exportImporter.UploadExcelImport<HBPO_SA_DETAIL_IMPORT_DTO>(files, _excelImportService); |
|
|
|
var importPubSaDetails = ObjectMapper.Map<List<HBPO_SA_DETAIL_IMPORT_DTO>, List<HBPO_SA_DETAIL>>(result); |
|
|
|
var importHBOPSaDetails = ObjectMapper.Map<List<HBPO_SA_DETAIL_IMPORT_DTO>, List<HBPO_SA_DETAIL>>(result); |
|
|
|
|
|
|
|
//Site包含CN1 亦庄
|
|
|
|
//Site包含CN5 顺义
|
|
|
|
var importCN1HBOPSaDetails = importHBOPSaDetails.FindAll(t => t.Site.Contains("CN1")); |
|
|
|
var importCN5HBOPSaDetails = importHBOPSaDetails.FindAll(t => t.Site.Contains("CN5")); |
|
|
|
|
|
|
|
await SaDataHandleAsync(importCN1HBOPSaDetails, "CN1"); |
|
|
|
await SaDataHandleAsync(importCN5HBOPSaDetails, "CN5"); |
|
|
|
return ""; |
|
|
|
|
|
|
|
//结算分组号
|
|
|
|
var hbpoSaGroupNums = importPubSaDetails.Select(t => t.GroupNum).Distinct(); |
|
|
|
var hbpoSaGroupNums = importHBOPSaDetails.Select(t => t.GroupNum).Distinct(); |
|
|
|
|
|
|
|
//已存在的结算分组号
|
|
|
|
var havPubSaGroupNums = (await _hbpoSaDetailRepository.GetListAsync(t => hbpoSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct(); |
|
|
@ -166,12 +176,11 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 处理结算数据
|
|
|
|
//销售价格
|
|
|
|
var priceListEntitys = await _priceListRepository.GetAllAsync(); |
|
|
|
|
|
|
|
importPubSaDetails.ForEach(importPubSaDetail => |
|
|
|
importHBOPSaDetails.ForEach(importPubSaDetail => |
|
|
|
{ |
|
|
|
List<string> luList = importPubSaDetail.LU.Split(" ").ToList(); |
|
|
|
importPubSaDetail.LU = luList[0].Replace(" ", ""); |
|
|
@ -193,7 +202,7 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
}); |
|
|
|
|
|
|
|
//导入的零件号集合
|
|
|
|
var importPubSaLUs = importPubSaDetails.Select(t => t.LU).Distinct(); |
|
|
|
var importPubSaLUs = importHBOPSaDetails.Select(t => t.LU).Distinct(); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)); |
|
|
|
var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct(); |
|
|
|
|
|
|
@ -213,7 +222,7 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
|
|
|
|
#region 入库数据赋值
|
|
|
|
//结算明细
|
|
|
|
hbpoSaDetails = importPubSaDetails; |
|
|
|
hbpoSaDetails = importHBOPSaDetails; |
|
|
|
|
|
|
|
//不可结算 结算分组号码(根据价格区分结算、不可结算)
|
|
|
|
var hbpoNotSaGroupNums = hbpoSaDetails.FindAll(t => t.Price == default(decimal)).Select(t => t.GroupNum).Distinct(); |
|
|
@ -329,5 +338,245 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 删除
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task DeleteListAsync(List<Guid> ids) |
|
|
|
{ |
|
|
|
//结算主表
|
|
|
|
List<HBPO_SA> hbpoSas = new List<HBPO_SA>(); |
|
|
|
//结算明细
|
|
|
|
List<HBPO_SA_DETAIL> hbpoSaDetails = new List<HBPO_SA_DETAIL>(); |
|
|
|
//可结算主表
|
|
|
|
List<HBPO_CAN_SA> hbpoCanSas = new List<HBPO_CAN_SA>(); |
|
|
|
//可结算明细
|
|
|
|
List<HBPO_CAN_SA_DETAIL> hbpoCanSaDetails = new List<HBPO_CAN_SA_DETAIL>(); |
|
|
|
//不可结算
|
|
|
|
List<HBPO_NOT_SA_DETAIL> hbpoNotSaDetails = new List<HBPO_NOT_SA_DETAIL>(); |
|
|
|
|
|
|
|
foreach (var id in ids) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
var hbpoSaDelItems = await GetHBPOSaDelItemsAsync(id); |
|
|
|
|
|
|
|
hbpoSas.AddRange(hbpoSaDelItems.hbpoSas); |
|
|
|
hbpoSaDetails.AddRange(hbpoSaDelItems.hbpoSaDetails); |
|
|
|
hbpoCanSas.AddRange(hbpoSaDelItems.hbpoCanSas); |
|
|
|
hbpoCanSaDetails.AddRange(hbpoSaDelItems.hbpoCanSaDetails); |
|
|
|
hbpoNotSaDetails.AddRange(hbpoSaDelItems.hbpoNotSaDetails); |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
throw; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//删除
|
|
|
|
if (hbpoSas.Any()) |
|
|
|
{ |
|
|
|
await _hbpoSaRepository.DeleteManyAsync(hbpoSas); |
|
|
|
} |
|
|
|
if (hbpoSaDetails.Any()) |
|
|
|
{ |
|
|
|
await _hbpoSaDetailRepository.DeleteManyAsync(hbpoSaDetails); |
|
|
|
} |
|
|
|
if (hbpoCanSas.Any()) |
|
|
|
{ |
|
|
|
await _hbpoCanSaRepository.DeleteManyAsync(hbpoCanSas); |
|
|
|
} |
|
|
|
if (hbpoCanSaDetails.Any()) |
|
|
|
{ |
|
|
|
await _hbpoCanSaDetailRepository.DeleteManyAsync(hbpoCanSaDetails); |
|
|
|
} |
|
|
|
if (hbpoNotSaDetails.Any()) |
|
|
|
{ |
|
|
|
await _hbpoNotSaDetailRepository.DeleteManyAsync(hbpoNotSaDetails); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 私有方法
|
|
|
|
/// <summary>
|
|
|
|
/// 结算数据处理
|
|
|
|
/// </summary>
|
|
|
|
private async Task<string> SaDataHandleAsync(List<HBPO_SA_DETAIL> hbpoSaDetails, string site) |
|
|
|
{ |
|
|
|
//数据校验
|
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
//结算单号
|
|
|
|
var hbpoSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); |
|
|
|
//结算主表
|
|
|
|
var hbpoSa = new HBPO_SA() |
|
|
|
{ |
|
|
|
BillNum = hbpoSaBillNum, |
|
|
|
State = "1", |
|
|
|
BusinessType = _businessType, |
|
|
|
Site = site, |
|
|
|
}; |
|
|
|
//可结算单号
|
|
|
|
var hbpoCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C"); |
|
|
|
//可结算主表
|
|
|
|
var hbpoCanSa = new HBPO_CAN_SA() |
|
|
|
{ |
|
|
|
BillNum = hbpoCanSaBillNum, |
|
|
|
SettleBillNum = hbpoSaBillNum, |
|
|
|
State = SettleBillState.未结状态, |
|
|
|
BusinessType = _businessType, |
|
|
|
Site = site, |
|
|
|
}; |
|
|
|
//可结算明细
|
|
|
|
var hbpoCanSaDetails = new List<HBPO_CAN_SA_DETAIL>(); |
|
|
|
//不可结算明细
|
|
|
|
var hbpoNotSaDetails = new List<HBPO_NOT_SA_DETAIL>(); |
|
|
|
//客户零件关系
|
|
|
|
var materialRelationships = new List<MaterialRelationship>(); |
|
|
|
|
|
|
|
#region 数据校验
|
|
|
|
//结算分组号
|
|
|
|
var hbpoSaGroupNums = hbpoSaDetails.Select(t => t.GroupNum).Distinct(); |
|
|
|
|
|
|
|
//已存在的结算分组号
|
|
|
|
var havPubSaGroupNums = (await _hbpoSaDetailRepository.GetListAsync(t => hbpoSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct(); |
|
|
|
if (havPubSaGroupNums.Any() == true) |
|
|
|
{ |
|
|
|
foreach (var item in havPubSaGroupNums) |
|
|
|
{ |
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"结算分组号{item}已存在", string.Empty)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (checkList.Count > 0) |
|
|
|
{ |
|
|
|
return await ExportErrorReportAsync(checkList); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 处理结算数据
|
|
|
|
//销售价格
|
|
|
|
var priceListEntitys = await _priceListRepository.GetAllAsync(); |
|
|
|
|
|
|
|
hbpoSaDetails.ForEach(hbpoSaDetail => |
|
|
|
{ |
|
|
|
List<string> luList = hbpoSaDetail.LU.Split(" ").ToList(); |
|
|
|
hbpoSaDetail.LU = luList[0].Replace(" ", ""); |
|
|
|
if (luList.Count > 1) |
|
|
|
{ |
|
|
|
luList.RemoveAt(0); |
|
|
|
var luAssemble = luList.Select(t => t.Replace(" ", "")); |
|
|
|
hbpoSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index); |
|
|
|
} |
|
|
|
|
|
|
|
hbpoSaDetail.BillNum = hbpoSaBillNum; |
|
|
|
hbpoSaDetail.KeyCode = hbpoSaDetail.PN + hbpoSaDetail.LU; |
|
|
|
|
|
|
|
//根据物料号、结算日期获取价格
|
|
|
|
var priceListEntity = priceListEntitys.Find(t => t.LU == hbpoSaDetail.LU && hbpoSaDetail.SettleDate > t.BeginTime && hbpoSaDetail.SettleDate < t.EndTime); |
|
|
|
hbpoSaDetail.Price = priceListEntity?.Price ?? default; |
|
|
|
hbpoSaDetail.BusinessType = _businessType; |
|
|
|
}); |
|
|
|
|
|
|
|
//导入的零件号集合
|
|
|
|
var importPubSaLUs = hbpoSaDetails.Select(t => t.LU).Distinct(); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)); |
|
|
|
var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct(); |
|
|
|
|
|
|
|
/* |
|
|
|
* (不存在的客户零件号)差集 |
|
|
|
* 转换为厂内零件号 |
|
|
|
* 转换规则6个空格替换成“-” |
|
|
|
*/ |
|
|
|
var noExistSettleMaterialCodes = importPubSaLUs.Except(materialRelationshipEntitySettleMaterialCodes); |
|
|
|
|
|
|
|
noExistSettleMaterialCodes.ForEach(t => |
|
|
|
{ |
|
|
|
var materialRelationship = new MaterialRelationship(GuidGenerator.Create(), t.Replace(" ", "-"), "", t, _businessType.ToString()); |
|
|
|
materialRelationships.Add(materialRelationship); |
|
|
|
}); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 入库数据赋值
|
|
|
|
//根据价格区分结算、不可结算
|
|
|
|
var hbpoSaDetailsCanSes = hbpoSaDetails.FindAll(t => t.Price != default); |
|
|
|
var hbpoSaDetailsNotCanSes = hbpoSaDetails.FindAll(t => t.Price == default); |
|
|
|
|
|
|
|
//可结算明细
|
|
|
|
hbpoCanSaDetails = ObjectMapper.Map<List<HBPO_SA_DETAIL>, List<HBPO_CAN_SA_DETAIL>>(hbpoSaDetailsCanSes); |
|
|
|
//不可结算明细
|
|
|
|
hbpoNotSaDetails = ObjectMapper.Map<List<HBPO_SA_DETAIL>, List<HBPO_NOT_SA_DETAIL>>(hbpoSaDetailsNotCanSes); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 添加入库
|
|
|
|
await _hbpoSaRepository.InsertAsync(hbpoSa); |
|
|
|
await _hbpoSaDetailRepository.InsertManyAsync(hbpoSaDetails); |
|
|
|
if (hbpoCanSaDetails.Count > 0) |
|
|
|
{ |
|
|
|
hbpoCanSa.InvGroupNum = hbpoCanSaDetails.Count.ToString(); |
|
|
|
hbpoCanSaDetails.ForEach(hbpoCanSaDetail => |
|
|
|
{ |
|
|
|
hbpoCanSaDetail.BillNum = hbpoCanSaDetail.InvGroupNum = hbpoCanSaBillNum; |
|
|
|
hbpoCanSaDetail.BusinessType = _businessType; |
|
|
|
}); |
|
|
|
|
|
|
|
await _hbpoCanSaRepository.InsertAsync(hbpoCanSa); |
|
|
|
await _hbpoCanSaDetailRepository.InsertManyAsync(hbpoCanSaDetails); |
|
|
|
} |
|
|
|
if (hbpoNotSaDetails.Count > 0) |
|
|
|
{ |
|
|
|
hbpoNotSaDetails.ForEach(hbpoNotSaDetail => |
|
|
|
{ |
|
|
|
hbpoNotSaDetail.BusinessType = _businessType; |
|
|
|
}); |
|
|
|
|
|
|
|
await _hbpoNotSaDetailRepository.InsertManyAsync(hbpoNotSaDetails); |
|
|
|
} |
|
|
|
if (materialRelationships.Count > 0) |
|
|
|
{ |
|
|
|
await _materialRelationshipRepository.InsertManyAsync(materialRelationships); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
return ApplicationConsts.SuccessStr; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取结算关联项
|
|
|
|
/// </summary>
|
|
|
|
private async Task<(List<HBPO_SA> hbpoSas, List<HBPO_SA_DETAIL> hbpoSaDetails, List<HBPO_CAN_SA> hbpoCanSas, List<HBPO_CAN_SA_DETAIL> hbpoCanSaDetails, List<HBPO_NOT_SA_DETAIL> hbpoNotSaDetails)> GetHBPOSaDelItemsAsync(Guid id) |
|
|
|
{ |
|
|
|
//结算主表
|
|
|
|
List<HBPO_SA> hbpoSas = new List<HBPO_SA>(); |
|
|
|
//结算明细
|
|
|
|
List<HBPO_SA_DETAIL> hbpoSaDetails = new List<HBPO_SA_DETAIL>(); |
|
|
|
//可结算主表
|
|
|
|
List<HBPO_CAN_SA> hbpoCanSas = new List<HBPO_CAN_SA>(); |
|
|
|
//可结算明细
|
|
|
|
List<HBPO_CAN_SA_DETAIL> hbpoCanSaDetails = new List<HBPO_CAN_SA_DETAIL>(); |
|
|
|
//不可结算
|
|
|
|
List<HBPO_NOT_SA_DETAIL> hbpoNotSaDetails = new List<HBPO_NOT_SA_DETAIL>(); |
|
|
|
|
|
|
|
var hbpoSaEntity = await _hbpoSaRepository.FirstOrDefaultAsync(t => t.Id.Equals(id)); |
|
|
|
if (hbpoSaEntity != null) |
|
|
|
{ |
|
|
|
//结算单据
|
|
|
|
string hbpoSaBillNum = hbpoSaEntity.BillNum; |
|
|
|
|
|
|
|
hbpoCanSas = await _hbpoCanSaRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum); |
|
|
|
//验证可结算主表状态
|
|
|
|
if (hbpoCanSas.Any() && hbpoCanSas.Any(t => t.State != SettleBillState.未结状态)) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"{hbpoSaBillNum} 该单据可结算单状态无法删除!", "400"); |
|
|
|
} |
|
|
|
|
|
|
|
hbpoSas.Add(hbpoSaEntity); |
|
|
|
hbpoSaDetails = await _hbpoSaDetailRepository.GetListAsync(t => t.BillNum == hbpoSaBillNum); |
|
|
|
hbpoCanSaDetails = await _hbpoCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum); |
|
|
|
hbpoNotSaDetails = await _hbpoNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum); |
|
|
|
} |
|
|
|
|
|
|
|
return (hbpoSas, hbpoSaDetails, hbpoCanSas, hbpoCanSaDetails, hbpoNotSaDetails); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|