|
|
@@ -121,12 +121,24 @@ namespace Business.ResourceExamineManagement
|
|
|
private readonly IMongoDB<ic_item_stock> _ic_item_stock;
|
|
|
private IRepository<ic_item_stock, long> _mysql_ic_item_stock;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 物料采购计划表
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<ic_plan> _ic_plan;
|
|
|
+ private IRepository<ic_plan, long> _mysql_ic_plan;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 物料工厂明细表
|
|
|
/// </summary>
|
|
|
private readonly IMongoDB<ic_factory_details> _ic_factory_details;
|
|
|
private IRepository<ic_factory_details, long> _mysql_ic_factory_details;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 物料采购报价单
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<ic_item_pur> _ic_item_pur;
|
|
|
+ private IRepository<ic_item_pur, long> _mysql_ic_item_pur;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 采购申请单
|
|
|
/// </summary>
|
|
|
@@ -235,6 +247,8 @@ namespace Business.ResourceExamineManagement
|
|
|
IMongoDB<crm_seorder> crm_seorder,
|
|
|
IMongoDB<crm_seorderentry> crm_seorderentry,
|
|
|
IMongoDB<srm_po_occupy> srm_po_occupy,
|
|
|
+ IMongoDB<ic_item_pur> ic_item_pur,
|
|
|
+ IMongoDB<ic_plan> ic_plan,
|
|
|
//IMongoDB<ic_substitute> ic_substitute,
|
|
|
//IMongoDB<ic_substitute_all> ic_substitute_all,
|
|
|
//IMongoDB<ic_substitute_all_dtl> ic_substitute_all_dtl,
|
|
|
@@ -259,7 +273,9 @@ namespace Business.ResourceExamineManagement
|
|
|
IRepository<mes_tech_process, long> mysql_mes_tech_process,
|
|
|
IRepository<srm_po_main, long> mysql_srm_po_main,
|
|
|
IRepository<srm_po_list, long> mysql_srm_po_list,
|
|
|
- IRepository<srm_po_occupy, long> mysql_srm_po_occupy
|
|
|
+ IRepository<srm_po_occupy, long> mysql_srm_po_occupy,
|
|
|
+ IRepository<ic_item_pur, long> mysql_ic_item_pur,
|
|
|
+ IRepository<ic_plan, long> mysql_ic_plan
|
|
|
)
|
|
|
{
|
|
|
_mes_technique = mes_technique;
|
|
|
@@ -279,6 +295,8 @@ namespace Business.ResourceExamineManagement
|
|
|
_crm_seorder = crm_seorder;
|
|
|
_crm_seorderentry = crm_seorderentry;
|
|
|
_srm_po_occupy= srm_po_occupy;
|
|
|
+ _ic_item_pur= ic_item_pur;
|
|
|
+ _ic_plan= ic_plan;
|
|
|
//_ic_substitute = ic_substitute;
|
|
|
//_ic_substitute_all = ic_substitute_all;
|
|
|
//_ic_substitute_all_dtl = ic_substitute_all_dtl;
|
|
|
@@ -304,6 +322,8 @@ namespace Business.ResourceExamineManagement
|
|
|
_mysql_srm_po_main = mysql_srm_po_main;
|
|
|
_mysql_srm_po_list = mysql_srm_po_list;
|
|
|
_mysql_srm_po_occupy= mysql_srm_po_occupy;
|
|
|
+ _mysql_ic_item_pur= mysql_ic_item_pur;
|
|
|
+ _mysql_ic_plan= mysql_ic_plan;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -1455,14 +1475,28 @@ namespace Business.ResourceExamineManagement
|
|
|
}*/
|
|
|
#endregion
|
|
|
|
|
|
- //根据物料id获取物料3个提前期
|
|
|
+ //根据物料id获取物料4个提前期
|
|
|
private List<ICItemLeadTimeDto> GetLeadTime(List<BomChildExamineDto> returnlist, 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,
|
|
|
- project.Include(p => p.icitem_id).Include(p => p.production_leadtime).Include(p => p.stock_leadtime).Include(p => p.transportation_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 }).AsQueryable<ICItemLeadTimeDto>().ToList();
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ //ToDo:企业Id
|
|
|
+ return _ic_item_pur.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.factory_id == factoryid).Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据物料id获取物料采购计划表
|
|
|
+ private List<ic_plan> GetICPlan(List<BomChildExamineDto> returnlist, long factoryid)
|
|
|
+ {
|
|
|
+ //ToDo:企业Id
|
|
|
+ return _ic_plan.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.factory_id == factoryid).Result;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1478,7 +1512,9 @@ namespace Business.ResourceExamineManagement
|
|
|
//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 itemlist = new List<ICItemDateDto>();//需要生成采购申请单的物料信息
|
|
|
- var leadTimeList = GetLeadTime(returnlist, factoryid);
|
|
|
+ var leadTimeList = GetLeadTime(returnlist, factoryid);//提前期列表
|
|
|
+ var supplierList = GetSupplier(returnlist, factoryid);//供应商列表
|
|
|
+ var planList = GetICPlan(returnlist, factoryid);//plan列表
|
|
|
foreach (var item in returnlist)
|
|
|
{
|
|
|
//缺料
|
|
|
@@ -1490,13 +1526,15 @@ namespace Business.ResourceExamineManagement
|
|
|
//外购生成采购申请单
|
|
|
if (item.erp_cls == 3)
|
|
|
{
|
|
|
- CreateSRMPR(item, factoryid, 2, leadTimeList);
|
|
|
+ DateTime lastTime=CreateSRMPR(item, factoryid, 2, leadTimeList, supplierList, planList,deliveryDate);
|
|
|
+ itemlist.Add(new ICItemDateDto { item_id = item.item_id, dateTime = lastTime });
|
|
|
}
|
|
|
else if (item.erp_cls == 2)
|
|
|
{
|
|
|
//委外生成委外采购申请单和委外工单
|
|
|
- CreateSRMPR(item, factoryid, 1, leadTimeList);
|
|
|
- CreateMesOOder(item, factoryid, leadTimeList);
|
|
|
+ DateTime lastTime=CreateSRMPR(item, factoryid, 1, leadTimeList, supplierList, planList,deliveryDate);
|
|
|
+ CreateMesOOder(item, factoryid, leadTimeList, supplierList,deliveryDate);
|
|
|
+ itemlist.Add(new ICItemDateDto { item_id = item.item_id, dateTime = lastTime});
|
|
|
}
|
|
|
}else
|
|
|
{
|
|
|
@@ -1558,7 +1596,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// </summary>
|
|
|
/// <param name="returnlist"></param>
|
|
|
/// <param name="factoryid"></param>
|
|
|
- private DateTime CreateMesOOder(BomChildExamineDto returnlist, long factoryid, List<ICItemLeadTimeDto> iCItemLeadTimes)
|
|
|
+ private DateTime CreateMesOOder(BomChildExamineDto returnlist, long factoryid, List<ICItemLeadTimeDto> iCItemLeadTimes,List<ic_item_pur> supplierList,DateTime deliveryDate)
|
|
|
{
|
|
|
mes_oorder oOrder = new mes_oorder();
|
|
|
oOrder.GenerateNewId();
|
|
|
@@ -1609,47 +1647,45 @@ 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)
|
|
|
+ private DateTime CreateSRMPR(BomChildExamineDto returnlist, 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);//默认取第一个供应商
|
|
|
+ var plan = planList.Find(x => x.icitem_id == returnlist.item_id);//
|
|
|
srm_pr_main srm_Pr = new srm_pr_main();
|
|
|
srm_Pr.GenerateNewId();
|
|
|
srm_Pr.pr_billno = getOrderNum("PR");//pr单号
|
|
|
srm_Pr.pr_mono = "";//关联工单号
|
|
|
srm_Pr.entity_id = 1;//工单行号
|
|
|
- srm_Pr.pr_purchaseid = 10021;//供应商id
|
|
|
- srm_Pr.pr_purchasenumber = "BFH21";//供应商编码
|
|
|
- srm_Pr.pr_purchasename = "壳皮有限公司21";//供应商名称
|
|
|
- srm_Pr.pr_purchaser = "10000";//采购员
|
|
|
- srm_Pr.pr_purchaser_num = "10001";//采购员工号(采购信息表)
|
|
|
- srm_Pr.pr_rqty = 20;//需求数量
|
|
|
- srm_Pr.pr_aqty = 1000;//申请数量
|
|
|
- srm_Pr.pr_sqty = 22;//建议数量
|
|
|
- srm_Pr.icitem_id = 10001;//物料id
|
|
|
+ srm_Pr.pr_purchaseid = supplier.supplier_id;//供应商id
|
|
|
+ srm_Pr.pr_purchasenumber = supplier.supplier_number;//供应商编码
|
|
|
+ srm_Pr.pr_purchasename =supplier.supplier_name;//供应商名称
|
|
|
+ srm_Pr.pr_purchaser =supplier.purcher;//采购员
|
|
|
+ srm_Pr.pr_purchaser_num ="";//采购员工号(采购信息表)
|
|
|
+ srm_Pr.pr_rqty =returnlist.lack_qty;//需求数量
|
|
|
+ srm_Pr.pr_aqty = returnlist.lack_qty;//申请数量
|
|
|
+ srm_Pr.pr_sqty = returnlist.lack_qty;//建议数量
|
|
|
+ srm_Pr.icitem_id =returnlist.item_id;//物料id
|
|
|
srm_Pr.icitem_name = returnlist.item_name;//物料名称
|
|
|
srm_Pr.pr_order_type = 1;//单据类型
|
|
|
- srm_Pr.pr_ssend_date = DateTime.Now;//系统建议下单日期
|
|
|
- srm_Pr.pr_sarrive_date = DateTime.Now;//系统建议到达日期(建议到货日期)
|
|
|
- srm_Pr.pr_bsarrive_date = DateTime.Now;//采购员建议到货日期
|
|
|
- srm_Pr.pr_oarrive_date = DateTime.Now;//订单到货日期
|
|
|
- srm_Pr.pr_psend_date = DateTime.Now;//计划下单日期
|
|
|
- srm_Pr.pr_parrive_date = DateTime.Now;//计划到达日期
|
|
|
- srm_Pr.pr_rarrive_date = DateTime.Now;//需求到货日期
|
|
|
- srm_Pr.pr_rparrive_date = DateTime.Now;//再计划到货日期
|
|
|
- srm_Pr.pr_psend_date = DateTime.Now;//计划下单日期
|
|
|
- srm_Pr.pr_pur_affirm_date = DateTime.Now;//采购确认到货日期
|
|
|
- srm_Pr.pr_sysprice = 22;//系统价格(含税)
|
|
|
- srm_Pr.pr_orderprice = 22;//订单价格(含税)
|
|
|
- srm_Pr.pr_price = 22;//采购净价(不含税)
|
|
|
- srm_Pr.pr_rate = (decimal?)0.13;//税率
|
|
|
+ srm_Pr.pr_ssend_date = deliveryDate.AddDays((double)leadTime.order_leadtime * -1);//系统建议下单日期
|
|
|
+ srm_Pr.pr_sarrive_date = deliveryDate.AddDays((double)leadTime.transportation_leadtime * -1);//系统建议到达日期(建议到货日期)
|
|
|
+ srm_Pr.pr_psend_date = deliveryDate.AddDays((double)leadTime.order_leadtime * -1);//计划下单日期
|
|
|
+ srm_Pr.pr_parrive_date = deliveryDate.AddDays((double)leadTime.transportation_leadtime * -1);//计划到达日期
|
|
|
+ srm_Pr.pr_psend_date = deliveryDate.AddDays((double)leadTime.order_leadtime * -1);//计划下单日期
|
|
|
+ srm_Pr.pr_sysprice = returnlist.lack_qty* supplier.netpurchase_price*(1+ supplier.taxrate);//系统价格(含税)
|
|
|
+ srm_Pr.pr_orderprice = returnlist.lack_qty * supplier.netpurchase_price * (1 + supplier.taxrate);//订单价格(含税)
|
|
|
+ srm_Pr.pr_price =supplier.netpurchase_price;//采购净价(不含税)
|
|
|
+ srm_Pr.pr_rate =supplier.taxrate;//税率
|
|
|
srm_Pr.pr_unit = returnlist.unit;//单位
|
|
|
- srm_Pr.state = 22;//状态
|
|
|
- srm_Pr.old_apply_aqty = 22;//已申请数量
|
|
|
- srm_Pr.pr_type = 22;//申请类型
|
|
|
- srm_Pr.currencytype = 22;//币种
|
|
|
- srm_Pr.secInv_ratio = 22;//安全库存触发采购比例
|
|
|
+ srm_Pr.state = 1;//状态
|
|
|
+ srm_Pr.old_apply_aqty = 0;//已申请数量
|
|
|
+ srm_Pr.pr_type = orderType;//申请类型
|
|
|
+ srm_Pr.currencytype =supplier.currency_type;//币种
|
|
|
+ srm_Pr.secInv_ratio = plan.secinv_ratio;//安全库存触发采购比例
|
|
|
_srm_pr_main.InsertOne(srm_Pr);
|
|
|
- var leadTime=iCItemLeadTimes.Select(x => x.item_id == returnlist.item_id).First();
|
|
|
- return DateTime.Now;
|
|
|
+ decimal? totalLeadTime = leadTime.transportation_leadtime + leadTime.stock_leadtime + leadTime.production_leadtime + leadTime.order_leadtime;
|
|
|
+ return deliveryDate.AddDays((double)totalLeadTime*-1);//减去提前期
|
|
|
}
|
|
|
|
|
|
// 生成订单编号 字母+年月日+8位随机数+时间戳
|