erp材料出库单同步接口,材料出库与抽检业务编写,采购收货收货质检逻辑、采购订单同步接口完善、erp成品调拨入库同步
This commit is contained in:
@@ -305,33 +305,51 @@ namespace Tnb.WarehouseMgr
|
||||
LoggerErp2Mes.LogInformation($"【PurchaseOrderInput】ERP传入数据:{JsonConvert.SerializeObject(input)}");
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【PurchaseOrderInput】主表主键不能为空!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"主表主键不能为空!");
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【PurchaseOrderInput】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsPurchaseOrdersDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsPurchaseOrdersDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【PurchaseOrderInput】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【PurchaseOrderInput】主表主键不能为空!");
|
||||
throw new AppFriendlyException($@"主表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【PurchaseOrderInput】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsPurchaseOrdersDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
//if (wmsPurchaseOrdersDistinct.Count() < input.details.Count)
|
||||
//{
|
||||
// _LoggerErp2Mes.LogWarning($@"【PurchaseOrderInput】表体存在物料和批号重复的明细!");
|
||||
// throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
//}
|
||||
|
||||
await db.Ado.BeginTranAsync();
|
||||
// 判断是否为重复传输的采购订单
|
||||
WmsPurchaseOrderH wmsPurchaseOrderRep = await db.Queryable<WmsPurchaseOrderH>().Where(r => r.erp_pk == input.erp_pk).FirstAsync();
|
||||
if (wmsPurchaseOrderRep != null)
|
||||
{
|
||||
// 判断收货单是否已经生成
|
||||
WmsPurchaseH wmsPurchaseH = await db.Queryable<WmsPurchaseH>().Where(r => r.source_id == wmsPurchaseOrderRep.id).FirstAsync();
|
||||
if (wmsPurchaseH != null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【PurchaseOrderInput】wms已创建收货单{wmsPurchaseH.bill_code}!");
|
||||
throw new AppFriendlyException($@"wms已创建收货单{wmsPurchaseH.bill_code}!", 500);
|
||||
}
|
||||
else // 删除数据重新插入
|
||||
{
|
||||
await db.Deleteable<WmsPurchaseOrderH>().Where(r => r.id == wmsPurchaseOrderRep.id).ExecuteCommandAsync();
|
||||
await db.Deleteable<WmsPurchaseOrderD>().Where(r => r.fk_wms_purchase_order_id == wmsPurchaseOrderRep.id).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
WmsPurchaseOrderH wmsPurchaseOrderH = new WmsPurchaseOrderH();
|
||||
string Code = await _billRuleService.GetBillNumber("Purchase");
|
||||
|
||||
@@ -424,32 +442,33 @@ namespace Tnb.WarehouseMgr
|
||||
LoggerErp2Mes.LogInformation($"【OutsourceOrderInput】ERP传入数据:{JsonConvert.SerializeObject(input)}");
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【OutsourceOrderInput】主表主键不能为空!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"主表主键不能为空!");
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【OutsourceOrderInput】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsPurchaseOrdersDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsPurchaseOrdersDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【OutsourceOrderInput】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【OutsourceOrderInput】主表主键不能为空!");
|
||||
throw new AppFriendlyException($@"主表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【OutsourceOrderInput】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsPurchaseOrdersDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsPurchaseOrdersDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【OutsourceOrderInput】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
|
||||
await db.Ado.BeginTranAsync();
|
||||
WmsOutsourceOrderH wmsOutsourceOrderH = new WmsOutsourceOrderH();
|
||||
string Code = await _billRuleService.GetBillNumber("WmsOutsourceOrder");
|
||||
@@ -541,80 +560,80 @@ namespace Tnb.WarehouseMgr
|
||||
LoggerErp2Mes.LogInformation($"【MaterialTransfer】ERP传入数据:{JsonConvert.SerializeObject(input)}");
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
BasWarehouse warehouse_outstock = await db.Queryable<BasWarehouse>().Where(r => r.whcode == input.warehouse_outstock).FirstAsync();
|
||||
BasWarehouse warehouse_instock = await db.Queryable<BasWarehouse>().Where(r => r.whcode == input.warehouse_instock).FirstAsync();
|
||||
if (warehouse_outstock == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【MaterialTransfer】无法查询到出库仓库{input.warehouse_outstock}的档案记录!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"无法查询到出库仓库{input.warehouse_outstock}的档案记录!");
|
||||
}
|
||||
if (warehouse_instock == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【MaterialTransfer】无法查询到入库仓库{input.warehouse_instock}的档案记录!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"无法查询到入库仓库{input.warehouse_instock}的档案记录!");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【MaterialTransfer】主表主键不能为空!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"主表主键不能为空!");
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【MaterialTransfer】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
string transfer_type = "";
|
||||
// 中储仓到暂存仓
|
||||
if (warehouse_outstock.id == WmsWareHouseConst.WAREHOUSE_ZC_ID && warehouse_instock.id == WmsWareHouseConst.WAREHOUSE_ZCC_ID)
|
||||
{
|
||||
int count = input.details.Where(r => string.IsNullOrEmpty(r.station_code)).Count();
|
||||
if (count > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【MaterialTransfer】表体存在未填写工位的明细!");
|
||||
throw new AppFriendlyException($@"表体存在未填写工位的明细!", 500);
|
||||
}
|
||||
|
||||
transfer_type = WmsWareHouseConst.MATERIALTRANSFER_CGCK_CODE;
|
||||
}
|
||||
else if (warehouse_outstock.id == WmsWareHouseConst.WAREHOUSE_CPCRK_ID && warehouse_instock.id == WmsWareHouseConst.WAREHOUSE_CP_ID)
|
||||
{
|
||||
transfer_type = WmsWareHouseConst.MATERIALTRANSFER_WXDBRK_CODE;
|
||||
}
|
||||
else if (warehouse_outstock.id == WmsWareHouseConst.WAREHOUSE_YCL_ID && warehouse_instock.id == WmsWareHouseConst.WAREHOUSE_JZGL_ID)
|
||||
{
|
||||
transfer_type = WmsWareHouseConst.MATERIALTRANSFER_JZGLRK_CODE;
|
||||
}
|
||||
// 暂时其他情况都算齐套出入库类型(未定)
|
||||
else
|
||||
{
|
||||
int count = input.details.Where(r => string.IsNullOrEmpty(r.station_code)).Count();
|
||||
if (count > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【MaterialTransfer】表体存在未填写工位的明细!");
|
||||
throw new AppFriendlyException($@"表体存在未填写工位的明细!", 500);
|
||||
}
|
||||
|
||||
transfer_type = WmsWareHouseConst.MATERIALTRANSFER_QTCRK_CODE;
|
||||
}
|
||||
|
||||
|
||||
var wmsMaterialTransferdsDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsMaterialTransferdsDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【MaterialTransfer】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
BasWarehouse warehouse_outstock = await db.Queryable<BasWarehouse>().Where(r => r.whcode == input.warehouse_outstock).FirstAsync();
|
||||
BasWarehouse warehouse_instock = await db.Queryable<BasWarehouse>().Where(r => r.whcode == input.warehouse_instock).FirstAsync();
|
||||
if (warehouse_outstock == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【MaterialTransfer】无法查询到出库仓库{input.warehouse_outstock}的档案记录!");
|
||||
throw new AppFriendlyException($"无法查询到出库仓库{input.warehouse_outstock}的档案记录!", 500);
|
||||
}
|
||||
if (warehouse_instock == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【MaterialTransfer】无法查询到入库仓库{input.warehouse_instock}的档案记录!");
|
||||
throw new AppFriendlyException($"无法查询到入库仓库{input.warehouse_instock}的档案记录!", 500);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【MaterialTransfer】主表主键不能为空!");
|
||||
throw new AppFriendlyException($@"主表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【MaterialTransfer】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
string transfer_type = "";
|
||||
// 中储仓到暂存仓
|
||||
if (warehouse_outstock.id == WmsWareHouseConst.WAREHOUSE_ZC_ID && warehouse_instock.id == WmsWareHouseConst.WAREHOUSE_ZCC_ID)
|
||||
{
|
||||
int count = input.details.Where(r => string.IsNullOrEmpty(r.station_code)).Count();
|
||||
if (count > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【MaterialTransfer】表体存在未填写工位的明细!");
|
||||
throw new AppFriendlyException($@"表体存在未填写工位的明细!", 500);
|
||||
}
|
||||
|
||||
transfer_type = WmsWareHouseConst.MATERIALTRANSFER_CGCK_CODE;
|
||||
}
|
||||
else if (warehouse_outstock.id == WmsWareHouseConst.WAREHOUSE_CPCRK_ID && warehouse_instock.id == WmsWareHouseConst.WAREHOUSE_CP_ID)
|
||||
{
|
||||
transfer_type = WmsWareHouseConst.MATERIALTRANSFER_WXDBRK_CODE;
|
||||
}
|
||||
else if (warehouse_outstock.id == WmsWareHouseConst.WAREHOUSE_YCL_ID && warehouse_instock.id == WmsWareHouseConst.WAREHOUSE_JZGL_ID)
|
||||
{
|
||||
transfer_type = WmsWareHouseConst.MATERIALTRANSFER_JZGLRK_CODE;
|
||||
}
|
||||
// 暂时其他情况都算齐套出入库类型(未定)
|
||||
else
|
||||
{
|
||||
int count = input.details.Where(r => string.IsNullOrEmpty(r.station_code)).Count();
|
||||
if (count > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【MaterialTransfer】表体存在未填写工位的明细!");
|
||||
throw new AppFriendlyException($@"表体存在未填写工位的明细!", 500);
|
||||
}
|
||||
|
||||
transfer_type = WmsWareHouseConst.MATERIALTRANSFER_QTCRK_CODE;
|
||||
}
|
||||
|
||||
|
||||
var wmsMaterialTransferdsDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsMaterialTransferdsDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【MaterialTransfer】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
|
||||
await db.Ado.BeginTranAsync();
|
||||
WmsMaterialTransfer wmsMaterialTransfer = new WmsMaterialTransfer();
|
||||
string Code = await _billRuleService.GetBillNumber("MaterialTransfer");
|
||||
@@ -702,43 +721,51 @@ namespace Tnb.WarehouseMgr
|
||||
public async Task<Entities.Dto.Outputs.Result> SaleShipping(SaleShippingInput input)
|
||||
{
|
||||
|
||||
|
||||
LoggerErp2Mes.LogInformation($"【SaleShipping】ERP传入数据:{JsonConvert.SerializeObject(input)}");
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【SaleShipping】主表主键不能为空!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"主表主键不能为空!");
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【SaleShipping】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsSaleShippingsDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsSaleShippingsDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【SaleShipping】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
|
||||
BasWarehouse warehouse_outstock = await db.Queryable<BasWarehouse>().Where(r => r.whcode == input.warehouse_code).FirstAsync();
|
||||
if (warehouse_outstock == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【MaterialTransfer】无法查询到出库仓库{input.warehouse_code}的档案记录!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"无法查询到出库仓库{input.warehouse_code}的档案记录!");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【SaleShipping】主表主键不能为空!");
|
||||
throw new AppFriendlyException($@"主表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【SaleShipping】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsSaleShippingsDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsSaleShippingsDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【SaleShipping】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
|
||||
WmsErpWarehouserelaH wmsErpWarehouserelaH = await db.Queryable<WmsErpWarehouserelaH>().Where(r => r.erp_warehousecode == input.erp_wh_type).FirstAsync();
|
||||
if (wmsErpWarehouserelaH == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOrder】不存在erp仓库类型{input.erp_wh_type}对应wms系统的映射关系!");
|
||||
throw new AppFriendlyException($@"不存在erp仓库类型{input.erp_wh_type}对应wms系统的映射关系!", 500);
|
||||
}
|
||||
|
||||
string warehouse_outstock_code = wmsErpWarehouserelaH.wms_warehousecode;
|
||||
|
||||
BasWarehouse warehouse_outstock = await db.Queryable<BasWarehouse>().Where(r => r.whcode == warehouse_outstock_code).FirstAsync();
|
||||
if (warehouse_outstock == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【TransferOrder】无法查询到出库仓库{warehouse_outstock_code}的档案记录!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"无法查询到出库仓库{warehouse_outstock_code}的档案记录!");
|
||||
}
|
||||
await db.Ado.BeginTranAsync();
|
||||
WmsSaleH wmsSaleH = new WmsSaleH();
|
||||
string Code = await _billRuleService.GetBillNumber("WmsSale");
|
||||
@@ -751,6 +778,7 @@ namespace Tnb.WarehouseMgr
|
||||
wmsSaleH.status = WmsWareHouseConst.BILLSTATUS_ADD_ID;
|
||||
wmsSaleH.warehouse_id = warehouse_outstock.id;
|
||||
wmsSaleH.customer_code = input.customer_code;
|
||||
wmsSaleH.erp_wh_type = input.erp_wh_type;
|
||||
var customer = await db.Queryable<BasCustomer>().Where(p => p.customer_code == input.customer_code).FirstAsync();
|
||||
if (customer != null)
|
||||
{
|
||||
@@ -830,39 +858,47 @@ namespace Tnb.WarehouseMgr
|
||||
LoggerErp2Mes.LogInformation($"【TransferOutstock】ERP传入数据:{JsonConvert.SerializeObject(input)}");
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【TransferOutstock】主表主键不能为空!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"主表主键不能为空!");
|
||||
}
|
||||
|
||||
BasWarehouse warehouse_instock = await db.Queryable<BasWarehouse>().Where(r => r.whcode == input.warehouse_instock).FirstAsync();
|
||||
if (warehouse_instock == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【MaterialTransfer】无法查询到入库仓库{input.warehouse_instock}的档案记录!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"无法查询到入库仓库{input.warehouse_instock}的档案记录!");
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOutstock】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsPurchaseOrdersDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsPurchaseOrdersDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOutstock】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【TransferOutstock】主表主键不能为空!");
|
||||
throw new AppFriendlyException($"主表主键不能为空", 500);
|
||||
}
|
||||
|
||||
WmsErpWarehouserelaH wmsErpWarehouserelaH = await db.Queryable<WmsErpWarehouserelaH>().Where(r => r.erp_warehousecode == input.erp_wh_type).FirstAsync();
|
||||
if (wmsErpWarehouserelaH == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOrder】不存在erp仓库类型{input.erp_wh_type}对应wms系统的映射关系!");
|
||||
throw new AppFriendlyException($@"不存在erp仓库类型{input.erp_wh_type}对应wms系统的映射关系!", 500);
|
||||
}
|
||||
|
||||
string warehouse_instock_code = wmsErpWarehouserelaH.wms_warehousecode;
|
||||
|
||||
BasWarehouse warehouse_instock = await db.Queryable<BasWarehouse>().Where(r => r.whcode == warehouse_instock_code).FirstAsync();
|
||||
if (warehouse_instock == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【TransferOrder】无法查询到入库仓库{warehouse_instock_code}的档案记录!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"无法查询到入库仓库{warehouse_instock_code}的档案记录!");
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOutstock】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsPurchaseOrdersDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsPurchaseOrdersDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOutstock】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
await db.Ado.BeginTranAsync();
|
||||
string Code = "";
|
||||
switch (warehouse_instock.id)
|
||||
@@ -883,6 +919,7 @@ namespace Tnb.WarehouseMgr
|
||||
wmsRawmatTransferinstockH.dept_code = input.dept_code;
|
||||
wmsRawmatTransferinstockH.biller = input.biller;
|
||||
wmsRawmatTransferinstockH.erp_wh_type = input.erp_wh_type;
|
||||
wmsRawmatTransferinstockH.org_id = WmsWareHouseConst.AdministratorOrgId;
|
||||
await db.Insertable(wmsRawmatTransferinstockH).ExecuteCommandAsync();
|
||||
|
||||
List<WmsRawmatTransferinstockD> wmsRawmatTransferinstockDs = new List<WmsRawmatTransferinstockD>();
|
||||
@@ -924,6 +961,64 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
await db.Insertable(wmsRawmatTransferinstockDs).ExecuteCommandAsync();
|
||||
|
||||
break;
|
||||
}
|
||||
case WmsWareHouseConst.WAREHOUSE_CP_ID:
|
||||
{
|
||||
WmsTransferInstockH wmsTransferInstockH = new WmsTransferInstockH();
|
||||
Code = await _billRuleService.GetBillNumber("transferInstock");
|
||||
|
||||
wmsTransferInstockH.bill_code = Code;
|
||||
wmsTransferInstockH.erp_bill_code = input.transfer_order;
|
||||
wmsTransferInstockH.outstockorg_code = input.outstockorg_code;
|
||||
wmsTransferInstockH.org_id = WmsWareHouseConst.AdministratorOrgId;
|
||||
wmsTransferInstockH.erp_pk = input.erp_pk;
|
||||
wmsTransferInstockH.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsTransferInstockH.create_time = DateTime.Now;
|
||||
wmsTransferInstockH.dept_code = input.dept_code;
|
||||
wmsTransferInstockH.biller = input.biller;
|
||||
wmsTransferInstockH.erp_wh_type = input.erp_wh_type;
|
||||
await db.Insertable(wmsTransferInstockH).ExecuteCommandAsync();
|
||||
|
||||
List<WmsTransferInstockD> wmsTransferInstockDs = new List<WmsTransferInstockD>();
|
||||
foreach (var detail in input.details)
|
||||
{
|
||||
WmsTransferInstockD wmsTransferInstockD = new WmsTransferInstockD();
|
||||
|
||||
wmsTransferInstockD.bill_id = wmsTransferInstockH.id;
|
||||
wmsTransferInstockD.material_code = detail.material_code;
|
||||
|
||||
var erpExtendField = await db.Queryable<ErpExtendField>().InnerJoin<DictionaryDataEntity>((a, b) => a.table_id == b.Id).Where((a, b) => a.cunitid == detail.unit_code).Select((a, b) => b).FirstAsync();
|
||||
if (erpExtendField != null)
|
||||
{
|
||||
wmsTransferInstockD.unit_code = erpExtendField.EnCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOutstock】表体明细中单位{detail.unit_code}在wms系统中未找到!");
|
||||
throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500);
|
||||
}
|
||||
wmsTransferInstockD.qty = detail.qty;
|
||||
wmsTransferInstockD.stock_location = detail.stock_location;
|
||||
wmsTransferInstockD.pi_code = detail.code_batch;
|
||||
wmsTransferInstockD.erp_line_pk = detail.erp_line_pk;
|
||||
wmsTransferInstockD.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsTransferInstockD.create_time = DateTime.Now;
|
||||
wmsTransferInstockD.xf_qty = 0;
|
||||
wmsTransferInstockD.pr_qty = 0;
|
||||
wmsTransferInstockD.lineno = detail.lineno;
|
||||
var material = await db.Queryable<BasMaterial>().Where(p => p.code == detail.material_code).FirstAsync();
|
||||
if (material != null)
|
||||
{
|
||||
wmsTransferInstockD.material_id = material.id;
|
||||
wmsTransferInstockD.material_desc = material.material_specification;
|
||||
}
|
||||
|
||||
wmsTransferInstockDs.Add(wmsTransferInstockD);
|
||||
}
|
||||
|
||||
await db.Insertable(wmsTransferInstockDs).ExecuteCommandAsync();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -956,48 +1051,48 @@ namespace Tnb.WarehouseMgr
|
||||
LoggerErp2Mes.LogInformation($"【TransferOrder】ERP传入数据:{JsonConvert.SerializeObject(input)}");
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【TransferOrder】主表主键不能为空!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"主表主键不能为空!");
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOrder】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsTransferOrdersDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsTransferOrdersDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOrder】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
|
||||
WmsErpWarehouserelaH wmsErpWarehouserelaH = await db.Queryable<WmsErpWarehouserelaH>().Where(r => r.erp_warehousecode == input.erp_wh_type).FirstAsync();
|
||||
if (wmsErpWarehouserelaH == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOrder】不存在erp仓库类型{input.erp_wh_type}对应wms系统的映射关系!");
|
||||
throw new AppFriendlyException($@"不存在erp仓库类型{input.erp_wh_type}对应wms系统的映射关系!", 500);
|
||||
}
|
||||
|
||||
string warehouse_outstock_code = wmsErpWarehouserelaH.wms_warehousecode;
|
||||
|
||||
BasWarehouse warehouse_outstock = await db.Queryable<BasWarehouse>().Where(r => r.whcode == warehouse_outstock_code).FirstAsync();
|
||||
if (warehouse_outstock == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【MaterialTransfer】无法查询到出库仓库{warehouse_outstock_code}的档案记录!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"无法查询到出库仓库{warehouse_outstock_code}的档案记录!");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【TransferOrder】主表主键不能为空!");
|
||||
throw new AppFriendlyException($@"主表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOrder】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsTransferOrdersDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsTransferOrdersDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOrder】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
|
||||
WmsErpWarehouserelaH wmsErpWarehouserelaH = await db.Queryable<WmsErpWarehouserelaH>().Where(r => r.erp_warehousecode == input.erp_wh_type).FirstAsync();
|
||||
if (wmsErpWarehouserelaH == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOrder】不存在erp仓库类型{input.erp_wh_type}对应wms系统的映射关系!");
|
||||
throw new AppFriendlyException($@"不存在erp仓库类型{input.erp_wh_type}对应wms系统的映射关系!", 500);
|
||||
}
|
||||
|
||||
string warehouse_outstock_code = wmsErpWarehouserelaH.wms_warehousecode;
|
||||
|
||||
BasWarehouse warehouse_outstock = await db.Queryable<BasWarehouse>().Where(r => r.whcode == warehouse_outstock_code).FirstAsync();
|
||||
if (warehouse_outstock == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【TransferOrder】无法查询到出库仓库{warehouse_outstock_code}的档案记录!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"无法查询到出库仓库{warehouse_outstock_code}的档案记录!");
|
||||
}
|
||||
|
||||
await db.Ado.BeginTranAsync();
|
||||
WmsTransferOrderH wmsTransferOrderH = new WmsTransferOrderH();
|
||||
string Code = await _billRuleService.GetBillNumber("WmsTransferOrder");
|
||||
@@ -1192,6 +1287,109 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 材料出库单
|
||||
/// </summary>
|
||||
[HttpPost, NonUnify, AllowAnonymous]
|
||||
public async Task<Entities.Dto.Outputs.Result> RawmatOutstock(RawmatOutstockInput input)
|
||||
{
|
||||
LoggerErp2Mes.LogInformation($"【RawmatOutstock】ERP传入数据:{JsonConvert.SerializeObject(input)}");
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【RawmatOutstock】主表主键不能为空!");
|
||||
throw new AppFriendlyException($@"主表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【RawmatOutstock】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsRawmatOutstocksDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsRawmatOutstocksDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【RawmatOutstock】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
|
||||
await db.Ado.BeginTranAsync();
|
||||
|
||||
WmsRawmatOutstockH wmsRawmatOutstockH = new WmsRawmatOutstockH();
|
||||
string code = await _billRuleService.GetBillNumber("rawmatoutstock");
|
||||
wmsRawmatOutstockH.bill_code = code;
|
||||
wmsRawmatOutstockH.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsRawmatOutstockH.create_time = DateTime.Now;
|
||||
//wmsRawmatOutstockH.biller = input.biller;
|
||||
wmsRawmatOutstockH.department = input.dept_code;
|
||||
wmsRawmatOutstockH.erp_pk = input.erp_pk;
|
||||
wmsRawmatOutstockH.issuance_status = "0";
|
||||
List<WmsRawmatOutstockD> wmsRawmatOutstockDs = new List<WmsRawmatOutstockD>();
|
||||
foreach (var detail in input.details)
|
||||
{
|
||||
WmsRawmatOutstockD wmsRawmatOutstockD = new WmsRawmatOutstockD();
|
||||
wmsRawmatOutstockD.bill_id = wmsRawmatOutstockH.id;
|
||||
wmsRawmatOutstockD.unit = detail.unit_code;
|
||||
var erpExtendField = await db.Queryable<ErpExtendField>().InnerJoin<DictionaryDataEntity>((a, b) => a.table_id == b.Id).Where((a, b) => a.cunitid == detail.unit_code).Select((a, b) => b).FirstAsync();
|
||||
if (erpExtendField != null)
|
||||
{
|
||||
wmsRawmatOutstockD.unit = erpExtendField.EnCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOrder】表体明细中单位{detail.unit_code}在wms系统中未找到!");
|
||||
throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500);
|
||||
}
|
||||
|
||||
wmsRawmatOutstockD.qty = detail.qty;
|
||||
wmsRawmatOutstockD.batchno = detail.code_batch;
|
||||
wmsRawmatOutstockD.erp_line_pk = detail.erp_line_pk;
|
||||
wmsRawmatOutstockD.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsRawmatOutstockD.create_time = DateTime.Now;
|
||||
wmsRawmatOutstockD.lineno = detail.lineno;
|
||||
wmsRawmatOutstockD.actual_outstock_qty = 0;
|
||||
|
||||
var material = await db.Queryable<BasMaterial>().Where(p => p.code == detail.material_code).FirstAsync();
|
||||
if (material != null)
|
||||
{
|
||||
wmsRawmatOutstockD.material_id = material.id;
|
||||
wmsRawmatOutstockD.material_code = material.code;
|
||||
wmsRawmatOutstockD.material_name = material.name;
|
||||
wmsRawmatOutstockD.material_specification = material.material_specification;
|
||||
}
|
||||
|
||||
wmsRawmatOutstockDs.Add(wmsRawmatOutstockD);
|
||||
}
|
||||
|
||||
await db.Insertable(wmsRawmatOutstockH).ExecuteCommandAsync();
|
||||
await db.Insertable(wmsRawmatOutstockDs).ExecuteCommandAsync();
|
||||
|
||||
await db.Ado.CommitTranAsync();
|
||||
|
||||
LoggerErp2Mes.LogInformation($"【RawmatOutstock】成功生成单据:{code}");
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LoggerErp2Mes.LogError($"【RawmatOutstock】{ex.Message}");
|
||||
LoggerErp2Mes.LogError($"【RawmatOutstock】{ex.StackTrace}");
|
||||
await db.Ado.RollbackTranAsync();
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected Task<Entities.Dto.Outputs.Result> ToApiResult(HttpStatusCode statusCode, string msg)
|
||||
|
||||
Reference in New Issue
Block a user