|
|
@@ -46,6 +46,7 @@ using System.IO.Compression;
|
|
|
using System.Collections;
|
|
|
using System.Data.SqlTypes;
|
|
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
|
|
+using Hangfire.Server;
|
|
|
|
|
|
namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
@@ -406,11 +407,17 @@ namespace Business.ResourceExamineManagement
|
|
|
|
|
|
//产能检查
|
|
|
await ProductiveExamine(bom_number, packages);
|
|
|
- var id = Save(input.tenantId, input.factoryId);
|
|
|
- await GenerateMorder(id);
|
|
|
+ //var id = Save(input.tenantId, input.factoryId);
|
|
|
+ //await GenerateMorder(id);
|
|
|
return null;
|
|
|
throw new NotImplementedException();
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 测试使用新增销售订单数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="tenantId"></param>
|
|
|
+ /// <param name="factoryId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
public long Save(long tenantId, long factoryId)
|
|
|
{
|
|
|
//销售订单
|
|
|
@@ -737,6 +744,7 @@ namespace Business.ResourceExamineManagement
|
|
|
mes_Morder.planner_num = seorderentry.planner_no;
|
|
|
mes_Morder.planner_name = seorderentry.planner_name;
|
|
|
mes_Morder.morder_date = DateTime.Now.Date;
|
|
|
+ //mes_Morder.morder_fstate = "计划";
|
|
|
//TODO:目前没有取值位置
|
|
|
mes_Morder.moentry_prd = null;
|
|
|
mes_Morder.moentry_prdname = null;
|
|
|
@@ -761,24 +769,12 @@ namespace Business.ResourceExamineManagement
|
|
|
mes_Moentry.need_number = seorderentry.qty;
|
|
|
mes_Moentry.remaining_number = 0;
|
|
|
mes_Moentry.factory_id = seorderentry.factory_id;
|
|
|
- using (TransactionScope scope = new TransactionScope())
|
|
|
- {
|
|
|
- await _mes_morder.InsertOne(mes_Morder);
|
|
|
- await _mes_moentry.InsertOne(mes_Moentry);
|
|
|
- scope.Complete();
|
|
|
- }
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 将decimal转换成日期格式
|
|
|
- /// </summary>
|
|
|
- /// <param name="date">yyyyMMddHHmmss</param>
|
|
|
- /// <returns>yyyy-MM-dd HH:mm:ss</returns>
|
|
|
- public static string TransDecimalToDateTime(string date)
|
|
|
- {
|
|
|
- DateTimeFormatInfo dtfi = new CultureInfo("zh-CN", false).DateTimeFormat;
|
|
|
- DateTime dateTime = DateTime.Now;
|
|
|
- DateTime.TryParseExact(date, "yyyyMMddHHmmss", dtfi, DateTimeStyles.None, out dateTime);
|
|
|
- return dateTime.ToString("yyyy-MM-dd HH:mm:ss"); ;
|
|
|
+ //using (TransactionScope scope = new TransactionScope())
|
|
|
+ // {
|
|
|
+ await _mes_morder.InsertOne(mes_Morder);
|
|
|
+ await _mes_moentry.InsertOne(mes_Moentry);
|
|
|
+ //scope.Complete();
|
|
|
+ //}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 检查成品库存
|
|
|
@@ -815,7 +811,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="DeliverDate">交付日期</param>
|
|
|
/// <param name="seorderentry_id">销售订单子表ID</param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<List<mes_morder>> CheckMorder(string bomNumber, decimal? Quantity, DateTime DeliverDate, long seorderentry_id)
|
|
|
+ public async Task<bool> CheckMorder(string bomNumber, decimal? Quantity, DateTime DeliverDate, long seorderentry_id)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(bomNumber) || Quantity != null)
|
|
|
{
|
|
|
@@ -855,7 +851,8 @@ namespace Business.ResourceExamineManagement
|
|
|
if (morderListData.Count == 0)
|
|
|
{
|
|
|
//TODO:后期处理无在制工单返回内容
|
|
|
- throw new NotImplementedException("无可用在制工单!");
|
|
|
+ //throw new NotImplementedException("无可用在制工单!");
|
|
|
+ return false;
|
|
|
}
|
|
|
List<mes_mooccupy> mes_Mooccupies = new List<mes_mooccupy>();
|
|
|
decimal? number = Quantity;
|
|
|
@@ -872,7 +869,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return morderList;
|
|
|
+ return true;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 拼接工单占用表
|
|
|
@@ -903,13 +900,15 @@ namespace Business.ResourceExamineManagement
|
|
|
mes_Mooccupy.moo_mo = item.morder_no;
|
|
|
//占用量=生产计划数量-入库数量-已被占用数量
|
|
|
mes_Mooccupy.moo_qty = item.morder_production_number - item.inventory_number - Sumqty;
|
|
|
- mes_Mooccupy.moo_stime = DateTime.Now;
|
|
|
+ mes_Mooccupy.moo_stime = DateTime.Now.Date;
|
|
|
mes_Mooccupy.moo_etime = DateTime.Now;//日期来源需确定
|
|
|
mes_Mooccupy.moo_state = 1;
|
|
|
mes_Mooccupy.moo_cbr = string.Empty;
|
|
|
//mes_Mooccupy.moo_ctime = ;
|
|
|
mes_Mooccupy.moo_creason = string.Empty;
|
|
|
mes_Mooccupy.tenant_id = seorderentry.tenant_id;//取销售子表企业ID
|
|
|
+ mes_Mooccupy.factory_id = seorderentry.factory_id;
|
|
|
+ mes_Mooccupy.factory_id = seorderentry.factory_id;
|
|
|
return mes_Mooccupy;
|
|
|
}
|
|
|
/// <summary>
|
|
|
@@ -1540,27 +1539,26 @@ namespace Business.ResourceExamineManagement
|
|
|
#endregion
|
|
|
|
|
|
//根据物料id获取物料4个提前期
|
|
|
- private List<ICItemLeadTimeDto> GetLeadTime(List<BomChildExamineDto> returnlist, long factoryid)
|
|
|
+ private List<ICItemLeadTimeDto> GetLeadTime(List<BomChildExamineDto> returnlist, long tenantId, long factoryid)
|
|
|
{
|
|
|
//ToDo:企业Id
|
|
|
ProjectionDefinitionBuilder<ic_factory_details> project = new ProjectionDefinitionBuilder<ic_factory_details>();
|
|
|
- return _ic_factory_details.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.factory_id == factoryid,
|
|
|
+ return _ic_factory_details.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.factory_id == factoryid && p.tenant_id==tenantId && !p.IsDeleted,
|
|
|
project.Include(p => p.icitem_id).Include(p => p.production_leadtime).Include(p => p.stock_leadtime).Include(p => p.transportation_leadtime).Include(p=>p.order_leadtime)).Result.
|
|
|
Select(x => new ICItemLeadTimeDto { item_id = x.icitem_id, transportation_leadtime = x.transportation_leadtime, stock_leadtime = x.stock_leadtime, production_leadtime = x.production_leadtime, order_leadtime=x.order_leadtime }).AsQueryable<ICItemLeadTimeDto>().ToList();
|
|
|
}
|
|
|
|
|
|
//根据物料id获取物料供应商
|
|
|
- private List<ic_item_pur> GetSupplier(List<BomChildExamineDto> returnlist, long factoryid)
|
|
|
+ private List<ic_item_pur> GetSupplier(List<BomChildExamineDto> returnlist, long tenantId,long factoryid)
|
|
|
{
|
|
|
//ToDo:企业Id
|
|
|
- return _ic_item_pur.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.factory_id == factoryid).Result;
|
|
|
+ return _ic_item_pur.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.tenant_id == tenantId && p.factory_id == factoryid && !p.IsDeleted).Result;
|
|
|
}
|
|
|
|
|
|
//根据物料id获取物料采购计划表
|
|
|
- private List<ic_plan> GetICPlan(List<BomChildExamineDto> returnlist, long factoryid)
|
|
|
+ private List<ic_plan> GetICPlan(List<BomChildExamineDto> returnlist, long tenantId,long factoryid)
|
|
|
{
|
|
|
- //ToDo:企业Id
|
|
|
- return _ic_plan.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.factory_id == factoryid).Result;
|
|
|
+ return _ic_plan.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) &&p.tenant_id==tenantId && p.factory_id == factoryid && !p.IsDeleted).Result;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1571,14 +1569,14 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="factoryid">工厂id</param>
|
|
|
/// <param name="deliveryDate">销售订单交付日期</param>
|
|
|
/// <returns></returns>
|
|
|
- private async Task<List<ICItemDateDto>> CheckOnOrder(List<BomChildExamineDto> returnlist, long factoryid, DateTime deliveryDate)
|
|
|
+ private async Task<List<ICItemDateDto>> CheckOnOrder(List<BomChildExamineDto> returnlist, long tenantId, long factoryid, DateTime deliveryDate)
|
|
|
{
|
|
|
//ToDo:企业Id,数据状态过滤以及isdeleted
|
|
|
- var po_list = _srm_po_list.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.factory_id == factoryid && p.rarrdate >= DateTime.Now && p.rarrdate < deliveryDate).Result;
|
|
|
+ var po_list = _srm_po_list.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.tenant_id== tenantId && p.factory_id == factoryid && p.rarrdate >= DateTime.Now && p.rarrdate < deliveryDate && !p.IsDeleted).Result;
|
|
|
var itemlist = new List<ICItemDateDto>();//需要生成采购申请单的物料信息
|
|
|
- var leadTimeList = GetLeadTime(returnlist, factoryid);//提前期列表
|
|
|
- var supplierList = GetSupplier(returnlist, factoryid);//供应商列表
|
|
|
- var planList = GetICPlan(returnlist, factoryid);//plan列表
|
|
|
+ var leadTimeList = GetLeadTime(returnlist, tenantId, factoryid);//提前期列表
|
|
|
+ var supplierList = GetSupplier(returnlist, tenantId, factoryid);//供应商列表
|
|
|
+ var planList = GetICPlan(returnlist, tenantId,factoryid);//plan列表
|
|
|
foreach (var item in returnlist)
|
|
|
{
|
|
|
//缺料
|
|
|
@@ -1590,14 +1588,14 @@ namespace Business.ResourceExamineManagement
|
|
|
//外购生成采购申请单
|
|
|
if (item.erp_cls == 3)
|
|
|
{
|
|
|
- DateTime lastTime=CreateSRMPR(item, factoryid, 2, leadTimeList, supplierList, planList,deliveryDate);
|
|
|
+ DateTime lastTime=CreateSRMPR(item, tenantId, factoryid, 2, leadTimeList, supplierList, planList,deliveryDate);
|
|
|
itemlist.Add(new ICItemDateDto { item_id = item.item_id, dateTime = lastTime });
|
|
|
}
|
|
|
else if (item.erp_cls == 2)
|
|
|
{
|
|
|
//委外生成委外采购申请单和委外工单
|
|
|
- DateTime lastTime=CreateSRMPR(item, factoryid, 1, leadTimeList, supplierList, planList,deliveryDate);
|
|
|
- CreateMesOOder(item, factoryid, leadTimeList, supplierList,deliveryDate);
|
|
|
+ DateTime lastTime=CreateSRMPR(item, tenantId, factoryid, 1, leadTimeList, supplierList, planList,deliveryDate);
|
|
|
+ CreateMesOOder(item, tenantId, factoryid, leadTimeList, supplierList,deliveryDate);
|
|
|
itemlist.Add(new ICItemDateDto { item_id = item.item_id, dateTime = lastTime});
|
|
|
}
|
|
|
}
|
|
|
@@ -1625,7 +1623,7 @@ namespace Business.ResourceExamineManagement
|
|
|
po_Occupy.cby = "";//变更人
|
|
|
po_Occupy.creason = "";//变更原因
|
|
|
po_Occupy.ctime = DateTime.Now;//变更时间
|
|
|
- _srm_po_occupy.InsertOne(po_Occupy);
|
|
|
+ await _srm_po_occupy.InsertOne(po_Occupy);
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
@@ -1647,7 +1645,7 @@ namespace Business.ResourceExamineManagement
|
|
|
po_Occupy.cby = "";//变更人
|
|
|
po_Occupy.creason = "";//变更原因
|
|
|
po_Occupy.ctime = DateTime.Now;//变更时间
|
|
|
- _srm_po_occupy.InsertOne(po_Occupy);
|
|
|
+ await _srm_po_occupy.InsertOne(po_Occupy);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1661,7 +1659,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// </summary>
|
|
|
/// <param name="returnlist"></param>
|
|
|
/// <param name="factoryid"></param>
|
|
|
- private DateTime CreateMesOOder(BomChildExamineDto returnlist, long factoryid, List<ICItemLeadTimeDto> iCItemLeadTimes,List<ic_item_pur> supplierList,DateTime deliveryDate)
|
|
|
+ private DateTime CreateMesOOder(BomChildExamineDto returnlist, long tenantId, long factoryid, List<ICItemLeadTimeDto> iCItemLeadTimes,List<ic_item_pur> supplierList,DateTime deliveryDate)
|
|
|
{
|
|
|
mes_oorder oOrder = new mes_oorder();
|
|
|
oOrder.GenerateNewId();
|
|
|
@@ -1684,7 +1682,7 @@ namespace Business.ResourceExamineManagement
|
|
|
oOrder.bom_number = "";//bom编码
|
|
|
oOrder.unit = returnlist.unit;//单位
|
|
|
oOrder.morder_progress = "";//工单进度
|
|
|
- oOrder.morder_production_number = 120;//工单生产数量(计划数量)
|
|
|
+ oOrder.morder_production_number = returnlist.lack_qty;//工单生产数量(计划数量)
|
|
|
oOrder.need_number = returnlist.lack_qty;//需求数量
|
|
|
oOrder.remaining_number = returnlist.lack_qty;//剩余可用数量
|
|
|
oOrder.work_number = 0;//报工数量
|
|
|
@@ -1701,6 +1699,8 @@ namespace Business.ResourceExamineManagement
|
|
|
oOrder.production_unit = returnlist.unit;//加工单位
|
|
|
oOrder.production_unit_code = "";//加工单位编码
|
|
|
oOrder.need_icitem_status = 1;//所需物料是否充足 1-充足 0-缺料
|
|
|
+ oOrder.tenant_id = tenantId;
|
|
|
+ oOrder.factory_id = factoryid;
|
|
|
_mes_oorder.InsertOne(oOrder);
|
|
|
return DateTime.Now;
|
|
|
}
|
|
|
@@ -1712,7 +1712,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="returnlist"></param>
|
|
|
/// <param name="factoryid"></param>
|
|
|
/// <param name="orderType">1委外采购申请单,2采购申请单</param>
|
|
|
- private DateTime CreateSRMPR(BomChildExamineDto returnlist, long factoryid, int orderType,List<ICItemLeadTimeDto> iCItemLeadTimes, List<ic_item_pur> supplierList, List<ic_plan> planList,DateTime deliveryDate)
|
|
|
+ private DateTime CreateSRMPR(BomChildExamineDto returnlist, long tenantId, long factoryid, int orderType,List<ICItemLeadTimeDto> iCItemLeadTimes, List<ic_item_pur> supplierList, List<ic_plan> planList,DateTime deliveryDate)
|
|
|
{
|
|
|
var leadTime = iCItemLeadTimes.Find(x => x.item_id == returnlist.item_id);
|
|
|
var supplier = supplierList.Find(x => x.icitem_id == returnlist.item_id);//默认取第一个供应商
|
|
|
@@ -1748,6 +1748,8 @@ namespace Business.ResourceExamineManagement
|
|
|
srm_Pr.pr_type = orderType;//申请类型
|
|
|
srm_Pr.currencytype =supplier.currency_type;//币种
|
|
|
srm_Pr.secInv_ratio = plan.secinv_ratio;//安全库存触发采购比例
|
|
|
+ srm_Pr.tenant_id = tenantId;
|
|
|
+ srm_Pr.factory_id = factoryid;
|
|
|
_srm_pr_main.InsertOne(srm_Pr);
|
|
|
decimal? totalLeadTime = leadTime.transportation_leadtime + leadTime.stock_leadtime + leadTime.production_leadtime + leadTime.order_leadtime;
|
|
|
return deliveryDate.AddDays((double)totalLeadTime*-1);//减去提前期
|