public ActionResult New(FlowMaster flow) { if (ModelState.IsValid) { if (base.genericMgr.FindAll<long>("select count(*) from FlowMaster as f where f.Code = ?", flow.Code)[0] > 0) { base.SaveErrorMessage(Resources.ErrorMessage.Errors_Existing_Code, flow.Code); } else if (string.IsNullOrEmpty(flow.PartyFrom)) { base.SaveErrorMessage(Resources.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ProductionPartyFrom); } else if (string.IsNullOrEmpty(flow.LocationFrom)) { base.SaveErrorMessage(Resources.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ProductionLocationFrom); } else if (string.IsNullOrEmpty(flow.LocationTo)) { base.SaveErrorMessage(Resources.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ProductionLocationTo); } else { flow.PartyTo = flow.PartyFrom; flow.IsCheckPartyToAuthority = flow.IsCheckPartyFromAuthority; flow.FlowStrategy = com.Sconit.CodeMaster.FlowStrategy.Manual; flow.Type = com.Sconit.CodeMaster.OrderType.Production; flowMgr.CreateFlow(flow); SaveSuccessMessage(Resources.SCM.FlowMaster.FlowMaster_Added); return RedirectToAction("Edit/" + flow.Code); } } return View(flow); }
public IList<FlowDetail> GetFlowDetailList(FlowMaster flowMaster, bool includeInactiveDetail) { IList<FlowDetail> flowDetails = new List<FlowDetail>(); DateTime dateTimeNow = DateTime.Now; DetachedCriteria criteria = DetachedCriteria.For<FlowDetail>(); criteria.Add(Expression.Eq("Flow", flowMaster.Code)); if (!includeInactiveDetail) { criteria.Add(Expression.Or(Expression.IsNull("StartDate"), Expression.Le("StartDate", dateTimeNow))); criteria.Add(Expression.Or(Expression.IsNull("EndDate"), Expression.Ge("EndDate", dateTimeNow))); } criteria.AddOrder(Order.Asc("Sequence")); criteria.AddOrder(Order.Asc("Id")); flowDetails = this.genericMgr.FindAll<FlowDetail>(criteria); foreach (var flowDetail in flowDetails) { flowDetail.CurrentFlowMaster = flowMaster; flowDetail.DefaultLocationFrom = string.IsNullOrWhiteSpace(flowDetail.LocationFrom) ? flowDetail.CurrentFlowMaster.LocationFrom : flowDetail.LocationFrom; flowDetail.DefaultLocationTo = string.IsNullOrWhiteSpace(flowDetail.LocationTo) ? flowDetail.CurrentFlowMaster.LocationTo : flowDetail.LocationTo; flowDetail.DefaultExtraLocationFrom = string.IsNullOrWhiteSpace(flowDetail.ExtraLocationFrom) ? flowDetail.CurrentFlowMaster.ExtraLocationFrom : flowDetail.ExtraLocationFrom; flowDetail.DefaultExtraLocationTo = string.IsNullOrWhiteSpace(flowDetail.ExtraLocationTo) ? flowDetail.CurrentFlowMaster.ExtraLocationTo : flowDetail.ExtraLocationTo; } return flowDetails; }
public ActionResult New(FlowMaster flow) { if (ModelState.IsValid) { if (base.genericMgr.FindAll<long>("select count(*) from FlowMaster as f where f.Code = ?", flow.Code)[0] > 0) { base.SaveErrorMessage(Resources.ErrorMessage.Errors_Existing_Code, flow.Code); } else if (string.IsNullOrEmpty(flow.PartyFrom)) { base.SaveErrorMessage(Resources.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ProductionPartyFrom); } else if (string.IsNullOrEmpty(flow.LocationFrom)) { base.SaveErrorMessage(Resources.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ProductionLocationFrom); } else if (string.IsNullOrEmpty(flow.LocationTo)) { base.SaveErrorMessage(Resources.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ProductionLocationTo); } else if (flow.TaktTime == 0) { base.SaveErrorMessage("节拍时间必须大于0。"); } //else if (string.IsNullOrEmpty(flow.VirtualOpReference)) //{ // base.SaveErrorMessage("虚拟工位不能为空。"); //} else if (string.IsNullOrWhiteSpace(flow.Routing)) { base.SaveErrorMessage("工艺流程不能为空。"); } else { var hasError = false; if (!string.IsNullOrWhiteSpace(flow.VirtualOpReference)) { var checkeRouting = base.genericMgr.FindAll<RoutingDetail>("select r from RoutingDetail as r where r.Routing=? and r.OpReference=?", new object[] { flow.Routing, flow.VirtualOpReference }); if (checkeRouting == null || checkeRouting.Count == 0) { hasError = true; base.SaveErrorMessage(string.Format("虚拟工位{0}不存在工艺流程{1}中。", flow.VirtualOpReference, flow.Routing)); } } if (!hasError) { flow.PartyTo = flow.PartyFrom; flow.Type = com.Sconit.CodeMaster.OrderType.Production; flowMgr.CreateFlow(flow); SaveSuccessMessage(Resources.SCM.FlowMaster.FlowMaster_Added); return RedirectToAction("Edit/" + flow.Code); } } } return View(flow); }
public ActionResult New(FlowMaster flow) { if (ModelState.IsValid) { if (this.genericMgr.FindAll<long>("select count(*) from FlowMaster as f where f.Code = ?", flow.Code)[0] > 0) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Existing_Code, flow.Code); } else if (string.IsNullOrEmpty(flow.PartyFrom)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_DistributionPartyFrom); } else if (string.IsNullOrEmpty(flow.PartyTo)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_DistributionPartyTo); } else if (string.IsNullOrEmpty(flow.LocationFrom)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_LocationFrom); } else if (string.IsNullOrEmpty(flow.ShipFrom)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ShipFrom); } else if (string.IsNullOrEmpty(flow.ShipTo)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ShipTo); } else if (string.IsNullOrEmpty(flow.BillAddress)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_BillAddress); } //else if (string.IsNullOrEmpty(flow.PriceList)) //{ // base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_PriceList); //} //else if (string.IsNullOrEmpty(flow.SalesOrg)) //{ // base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_SalesOrg); //} //else if (string.IsNullOrEmpty(flow.DistrChan)) //{ // base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_DistrChan); //} else { flow.FlowStrategy = com.Sconit.CodeMaster.FlowStrategy.Manual; flow.Type = com.Sconit.CodeMaster.OrderType.Distribution; flowMgr.CreateFlow(flow); SaveSuccessMessage(Resources.SCM.FlowMaster.FlowMaster_Added); return RedirectToAction("Edit/" + flow.Code); } } return View(flow); }
public IList<Hu> CreateHu(FlowMaster flowMaster, IList<FlowDetail> flowDetailList) { IList<Hu> huList = new List<Hu>(); foreach (FlowDetail flowDetail in flowDetailList) { IDictionary<string, decimal> huIdDic = numberControlMgr.GetHuId(flowDetail); if (huIdDic != null && huIdDic.Count > 0) { foreach (string huId in huIdDic.Keys) { Hu hu = new Hu(); hu.HuId = huId; hu.LotNo = flowDetail.LotNo; hu.Item = flowDetail.Item; hu.ItemDescription = genericMgr.FindById<Item>(flowDetail.Item).Description; hu.BaseUom = flowDetail.BaseUom; hu.Qty = huIdDic[huId]; hu.ManufactureParty = flowDetail.ManufactureParty; hu.ManufactureDate = LotNoHelper.ResolveLotNo(flowDetail.LotNo); hu.PrintCount = 0; hu.ConcessionCount = 0; hu.ReferenceItemCode = flowDetail.ReferenceItemCode; hu.UnitCount = flowDetail.UnitCount; hu.UnitQty = itemMgr.ConvertItemUomQty(flowDetail.Item, flowDetail.Uom, 1, flowDetail.BaseUom); hu.Uom = flowDetail.Uom; hu.IsOdd = hu.Qty < hu.UnitCount; hu.SupplierLotNo = flowDetail.SupplierLotNo; hu.IsChangeUnitCount = flowDetail.IsChangeUnitCount; hu.UnitCountDescription = flowDetail.UnitCountDescription; hu.ContainerDesc = flowDetail.ContainerDescription; hu.LocationTo = flowMaster.PartyTo; genericMgr.Create(hu); //this.AsyncSendPrintData(hu); //创建条码中间表 this.CreateBarCode(hu, string.Empty); huList.Add(hu); } } } return huList; }
public ActionResult New(FlowMaster flow) { //这里有一个奇怪的现象,flow.ResourceGroup 的值如果是通过控件传过来而且值是CodeMaster.ResourceGroup.Other的时候, //ModelState.IsValid 就会等于False,其它的如“采购”路线等不会出现这种情况。 if (flow.ResourceGroup == CodeMaster.ResourceGroup.Other) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ResourceGroup); } if (ModelState.IsValid) { if (this.genericMgr.FindAll<long>("select count(*) from FlowMaster as f where f.Code = ?", flow.Code)[0] > 0) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Existing_Code, flow.Code); } else if (string.IsNullOrEmpty(flow.PartyFrom)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ProductionPartyFrom); } else if (string.IsNullOrEmpty(flow.LocationFrom)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ProductionLocationFrom); } else if (string.IsNullOrEmpty(flow.LocationTo)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ProductionLocationTo); } else { flow.PartyTo = flow.PartyFrom; flow.IsCheckPartyToAuthority = flow.IsCheckPartyFromAuthority; flow.FlowStrategy = com.Sconit.CodeMaster.FlowStrategy.Manual; flow.Type = com.Sconit.CodeMaster.OrderType.Production; flowMgr.CreateFlow(flow); SaveSuccessMessage(Resources.SCM.FlowMaster.FlowMaster_Added); return RedirectToAction("Edit/" + flow.Code); } } return View(flow); }
private IList<FlowBinding> TryLoadFlowBindings(FlowMaster flowMaster) { if (!string.IsNullOrWhiteSpace(flowMaster.Code)) { if (flowMaster.FlowBindings == null) { string hql = "from FlowBinding where MasterFlow.Code = ?"; flowMaster.FlowBindings = this.genericMgr.FindAll<FlowBinding>(hql, flowMaster.Code); } return flowMaster.FlowBindings; } else { return null; } }
private IList<FlowDetail> TryLoadFlowDetails(FlowMaster flowMaster) { if (!string.IsNullOrWhiteSpace(flowMaster.Code)) { if (flowMaster.FlowDetails == null) { string hql = "from FlowDetail where Flow = ? order by Sequence"; flowMaster.FlowDetails = this.genericMgr.FindAll<FlowDetail>(hql, flowMaster.Code); } return flowMaster.FlowDetails; } else { return null; } }
public OrderMaster CreateReturnOrder(FlowMaster flowMaster, IList<RejectDetail> rejectDetailList) { //if (!Utility.SecurityHelper.HasPermission(flowMaster)) //{ // throw new BusinessException("没有此路线{0}的操作权限。", flowMaster.Code); //} if (rejectDetailList == null || rejectDetailList.Count == 0) { throw new BusinessException("退货明细不能为空."); } #region 根据路线生成退货单 FlowMaster returnFlow = flowMgr.GetReverseFlow(flowMaster, rejectDetailList.Select(r => r.Item).Distinct().ToList()); OrderMaster orderMaster = TransferFlow2Order(returnFlow, null); orderMaster.IsQuick = true; orderMaster.SubType = CodeMaster.OrderSubType.Return; orderMaster.WindowTime = DateTime.Now; orderMaster.StartTime = DateTime.Now; orderMaster.EffectiveDate = DateTime.Now; orderMaster.QualityType = CodeMaster.QualityType.Reject; orderMaster.ReferenceOrderNo = rejectDetailList[0].RejectNo; #endregion #region 不合格品单明细变成退货单明细 IList<OrderDetail> orderDetailList = new List<OrderDetail>(); foreach (RejectDetail rejectDetail in rejectDetailList) { if (rejectDetail.HandleQty < rejectDetail.HandledQty + rejectDetail.CurrentHandleQty) { throw new BusinessException("不合格品单物料{0}本次处理数加已处理数超过总处理数.", rejectDetail.Item); } if (orderMaster.OrderDetails != null && orderMaster.OrderDetails.Count > 0) { var q = orderMaster.OrderDetails.Where(o => o.Item == rejectDetail.Item).ToList(); if (q.ToList() == null || q.ToList().Count == 0) { throw new BusinessException("不合格品单物料{0}没找到对应的路线明细.", rejectDetail.Item); } OrderDetail orderDetail = Mapper.Map<OrderDetail, OrderDetail>(q.ToList().First()); orderDetail.QualityType = com.Sconit.CodeMaster.QualityType.Reject; orderDetail.Uom = rejectDetail.Uom; if (string.IsNullOrWhiteSpace(rejectDetailList.First().HuId)) { orderDetail.OrderedQty = rejectDetail.CurrentHandleQty; } orderDetail.LocationFrom = orderMaster.LocationFrom; //orderDetail.LocationFromName = genericMgr.FindById<Location>(rejectDetail.LocationFrom).Name; orderDetail.ManufactureParty = rejectDetail.ManufactureParty; orderDetailList.Add(orderDetail); } else { throw new BusinessException("不合格品单物料{0}没找到对应的路线明细.", rejectDetail.Item); } } if (!string.IsNullOrWhiteSpace(rejectDetailList.First().HuId)) { AddHuToOrderDetailInput(orderDetailList, rejectDetailList.Select(p => p.HuId).Distinct().ToList()); } #endregion #region 创建退货单 orderMaster.OrderDetails = orderDetailList; CreateOrder(orderMaster); #endregion #region 更新明细的已处理不合格品处理单状态 if (orderMaster.Type == CodeMaster.OrderType.CustomerGoods || orderMaster.Type == CodeMaster.OrderType.SubContract || orderMaster.Type == CodeMaster.OrderType.Procurement) { foreach (RejectDetail rejectDetail in rejectDetailList) { rejectDetail.HandledQty += rejectDetail.CurrentHandleQty; genericMgr.Update(rejectDetail); } string hql = "from RejectDetail as r where r.RejectNo = ?"; IList<RejectDetail> remainRejectDetailList = genericMgr.FindAll<RejectDetail>(hql, rejectDetailList[0].RejectNo); var m = remainRejectDetailList.Where(r => (r.HandledQty < r.HandleQty)).ToList(); if (m == null || m.Count == 0) { RejectMaster rejectMaster = genericMgr.FindById<RejectMaster>(rejectDetailList[0].RejectNo); rejectMaster.Status = CodeMaster.RejectStatus.Close; genericMgr.Update(rejectMaster); } } #endregion return orderMaster; }
public OrderMaster TransferFlow2Order(FlowMaster flowMaster, IList<string> itemCodeList, DateTime effectivedate, bool isTransferDetail) { OrderMaster orderMaster = Mapper.Map<FlowMaster, OrderMaster>(flowMaster); orderMaster.IsPrintReceipt = flowMaster.IsPrintRceipt; if (isTransferDetail && (flowMaster.FlowDetails == null || flowMaster.FlowDetails.Count == 0)) { TryLoadFlowDetails(flowMaster, itemCodeList); } #region 查找OrderMaster相关对象 #region 查找Party string selectPartyStatement = "from Party where Code in (?"; IList<object> selectPartyPara = new List<object>(); selectPartyPara.Add(flowMaster.PartyFrom); if (flowMaster.PartyFrom != flowMaster.PartyTo) { selectPartyStatement += ", ?"; selectPartyPara.Add(flowMaster.PartyTo); } selectPartyStatement += ")"; IList<Party> partyList = this.genericMgr.FindAll<Party>(selectPartyStatement, selectPartyPara.ToArray()); #endregion #region 查找Address #region 收集所有地址代码 IList<string> addressCodeList = new List<string>(); if (!string.IsNullOrEmpty(flowMaster.BillAddress)) { addressCodeList.Add(flowMaster.BillAddress); } if (!string.IsNullOrEmpty(flowMaster.ShipFrom)) { addressCodeList.Add(flowMaster.ShipFrom); } if (!string.IsNullOrEmpty(flowMaster.ShipTo)) { addressCodeList.Add(flowMaster.ShipTo); } if (flowMaster.FlowDetails != null) { foreach (string billAddress in flowMaster.FlowDetails.Where(d => !string.IsNullOrEmpty(d.BillAddress)).Select(d => d.BillAddress).Distinct()) { addressCodeList.Add(billAddress); } } #endregion #region 查找Address IList<Address> addressList = null; if (addressCodeList.Count > 0) { string selectAddressStatement = string.Empty; IList<object> selectAddressPara = new List<object>(); foreach (string addressCode in addressCodeList.Distinct()) { if (selectAddressStatement == string.Empty) { selectAddressStatement = "from Address where Code in (?"; } else { selectAddressStatement += ",?"; } selectAddressPara.Add(addressCode); } selectAddressStatement += ")"; addressList = this.genericMgr.FindAll<Address>(selectAddressStatement, selectAddressPara.ToArray()); } #endregion #endregion #region 查找Location #region 收集所有Location代码 IList<string> locationCodeList = new List<string>(); if (!string.IsNullOrEmpty(flowMaster.LocationFrom)) { locationCodeList.Add(flowMaster.LocationFrom); } if (!string.IsNullOrEmpty(flowMaster.LocationTo)) { locationCodeList.Add(flowMaster.LocationTo); } if (flowMaster.FlowDetails != null) { foreach (string locationFromCode in flowMaster.FlowDetails.Where(d => !string.IsNullOrEmpty(d.LocationFrom)).Select(d => d.LocationFrom).Distinct()) { locationCodeList.Add(locationFromCode); } foreach (string locationToCode in flowMaster.FlowDetails.Where(d => !string.IsNullOrEmpty(d.LocationTo)).Select(d => d.LocationTo).Distinct()) { locationCodeList.Add(locationToCode); } } #endregion #region 查找Location IList<Location> locationList = null; if (locationCodeList.Count > 0) { string selectLocationStatement = string.Empty; IList<object> selectLocationPara = new List<object>(); foreach (string locationCode in locationCodeList.Distinct()) { if (selectLocationStatement == string.Empty) { selectLocationStatement = "from Location where Code in (?"; } else { selectLocationStatement += ",?"; } selectLocationPara.Add(locationCode); } selectLocationStatement += ")"; locationList = this.genericMgr.FindAll<Location>(selectLocationStatement, selectLocationPara.ToArray()); } #endregion #endregion #region 查找PriceList #region 收集所有PriceList代码 IList<string> priceListCodeList = new List<string>(); if (!string.IsNullOrEmpty(flowMaster.PriceList)) { priceListCodeList.Add(flowMaster.PriceList); } if (flowMaster.FlowDetails != null) { foreach (string priceListCode in flowMaster.FlowDetails.Where(d => !string.IsNullOrEmpty(d.PriceList)).Select(d => d.PriceList).Distinct()) { priceListCodeList.Add(priceListCode); } } #endregion #region 查找PriceList IList<PriceListMaster> priceListList = null; if (priceListCodeList.Count > 0) { string selectPriceListStatement = string.Empty; IList<object> selectPriceListPara = new List<object>(); foreach (string priceListCode in priceListCodeList.Distinct()) { if (selectPriceListStatement == string.Empty) { selectPriceListStatement = "from PriceListMaster where Code in (?"; } else { selectPriceListStatement += ",?"; } selectPriceListPara.Add(priceListCode); } selectPriceListStatement += ")"; priceListList = this.genericMgr.FindAll<PriceListMaster>(selectPriceListStatement, selectPriceListPara.ToArray()); } #endregion #endregion #endregion #region OrderMaster赋默认值 #region PartyFrom和PartyTo赋值 orderMaster.PartyFromName = partyList.Where(p => p.Code == orderMaster.PartyFrom).Single().Name; orderMaster.PartyToName = partyList.Where(p => p.Code == orderMaster.PartyTo).Single().Name; #endregion #region BillAddress赋值 if (!string.IsNullOrEmpty(flowMaster.BillAddress)) { orderMaster.BillAddressDescription = addressList.Where(a => a.Code == flowMaster.BillAddress).Single().AddressContent; } #endregion #region ShipFrom赋值 if (!string.IsNullOrEmpty(flowMaster.ShipFrom)) { Address shipFrom = addressList.Where(a => a.Code == flowMaster.ShipFrom).Single(); orderMaster.ShipFromAddress = shipFrom.AddressContent; orderMaster.ShipFromCell = shipFrom.MobilePhone; orderMaster.ShipFromTel = shipFrom.TelPhone; orderMaster.ShipFromFax = shipFrom.Fax; orderMaster.ShipFromContact = shipFrom.ContactPersonName; } #endregion #region ShipTo赋值 if (!string.IsNullOrEmpty(flowMaster.ShipTo)) { Address shipTo = addressList.Where(a => a.Code == flowMaster.ShipTo).Single(); orderMaster.ShipToAddress = shipTo.AddressContent; orderMaster.ShipToCell = shipTo.MobilePhone; orderMaster.ShipToTel = shipTo.TelPhone; orderMaster.ShipToFax = shipTo.Fax; orderMaster.ShipToContact = shipTo.ContactPersonName; } #endregion #region LocationFrom赋值 if (!string.IsNullOrWhiteSpace(flowMaster.LocationFrom)) { // orderMaster.LocationFromName = locationList.Where(a => a.Code == flowMaster.LocationFrom).Single().Name; orderMaster.LocationFromName = genericMgr.FindById<Location>(flowMaster.LocationFrom).Name; } #endregion #region LocationTo赋值 if (!string.IsNullOrWhiteSpace(flowMaster.LocationTo)) { // orderMaster.LocationToName = locationList.Where(a => a.Code == flowMaster.LocationTo).Single().Name; orderMaster.LocationToName = genericMgr.FindById<Location>(flowMaster.LocationTo).Name; } #endregion #region PriceList赋值 if (!string.IsNullOrWhiteSpace(flowMaster.PriceList)) { orderMaster.Currency = priceListList.Where(a => a.Code == flowMaster.PriceList).Single().Currency; } #endregion orderMaster.EffectiveDate = effectivedate; orderMaster.SubType = com.Sconit.CodeMaster.OrderSubType.Normal; orderMaster.QualityType = com.Sconit.CodeMaster.QualityType.Qualified; orderMaster.Priority = com.Sconit.CodeMaster.OrderPriority.Normal; orderMaster.Status = com.Sconit.CodeMaster.OrderStatus.Create; orderMaster.OrderStrategy = flowMaster.FlowStrategy; #endregion #region OrderDetail if (isTransferDetail && flowMaster.FlowDetails != null && flowMaster.FlowDetails.Count > 0) { IList<Item> itemList = this.itemMgr.GetItems(flowMaster.FlowDetails.Select(det => det.Item).Distinct().ToList()); int seq = 1; foreach (FlowDetail flowDetail in flowMaster.FlowDetails.OrderBy(d => d.Sequence)) { OrderDetail orderDetail = Mapper.Map<FlowDetail, OrderDetail>(flowDetail); Item item = itemList.Where(a => a.Code == flowDetail.Item).Single(); if (flowDetail.ExternalSequence == 0) { orderDetail.Sequence = seq++; //重新记录顺序 } else { orderDetail.Sequence = flowDetail.ExternalSequence; } //物料描述 orderDetail.ItemDescription = item.Description; if (flowDetail.BindDemand != null) { //订单绑定取被绑定订单相关字段 orderDetail.ManufactureParty = flowDetail.BindDemand.ManufactureParty; orderDetail.QualityType = flowDetail.BindDemand.QualityType; } else { orderDetail.QualityType = CodeMaster.QualityType.Qualified; } //orderDetail.UnitQty = 创建订单时会计算 if (!string.IsNullOrWhiteSpace(flowDetail.LocationFrom)) { orderDetail.LocationFromName = locationList.Where(a => a.Code == flowDetail.LocationFrom).Single().Name; //orderDetail.LocationFromName = genericMgr.FindById<Location>(flowDetail.LocationFrom).Name; } else { orderDetail.LocationFrom = orderMaster.LocationFrom; orderDetail.LocationFromName = orderMaster.LocationFromName; } if (!string.IsNullOrWhiteSpace(flowDetail.LocationTo)) { orderDetail.LocationToName = locationList.Where(a => a.Code == flowDetail.LocationTo).Single().Name; //orderDetail.LocationToName = genericMgr.FindById<Location>(flowDetail.LocationTo).Name; } else { orderDetail.LocationTo = orderMaster.LocationTo; orderDetail.LocationToName = orderMaster.LocationToName; } if (!string.IsNullOrWhiteSpace(flowDetail.BillAddress)) { orderDetail.BillAddressDescription = addressList.Where(a => a.Code == flowDetail.BillAddress).Single().AddressContent; } orderDetail.ReferenceItemCode = string.IsNullOrWhiteSpace(orderDetail.ReferenceItemCode) ? item.ReferenceCode : orderDetail.ReferenceItemCode; //if (orderMaster.Type == com.Sconit.CodeMaster.OrderType.Procurement // || orderMaster.Type == com.Sconit.CodeMaster.OrderType.ScheduleLine // || orderMaster.Type == com.Sconit.CodeMaster.OrderType.Distribution // || orderMaster.Type == com.Sconit.CodeMaster.OrderType.SubContract) //{ // //计算价格 // this.CalculateOrderDetailPrice(orderDetail, orderMaster, effectivedate); //} orderDetail.RequiredQty = flowDetail.OrderQty; orderDetail.OrderedQty = flowDetail.OrderQty; orderMaster.AddOrderDetail(orderDetail); } } #endregion #region OrderBinding TryLoadFlowBindings(flowMaster); if (flowMaster.FlowBindings != null && flowMaster.FlowBindings.Count > 0) { orderMaster.OrderBindings = (from b in flowMaster.FlowBindings select new OrderBinding { BindFlow = b.BindedFlow.Code, BindFlowStrategy = b.BindedFlow.FlowStrategy, BindType = b.BindType, }).ToList(); } #endregion return orderMaster; }
public OrderMaster TransferFlow2Order(FlowMaster flowMaster, IList<string> itemCodeList) { return TransferFlow2Order(flowMaster, itemCodeList, DateTime.Now); }
public IList<Hu> CreateHu(FlowMaster flowMaster, IList<FlowDetail> flowDetailList) { IList<Hu> huList = new List<Hu>(); foreach (FlowDetail flowDetail in flowDetailList) { IDictionary<string, decimal> huIdDic = numberControlMgr.GetHuId(flowDetail); if (huIdDic != null && huIdDic.Count > 0) { foreach (string huId in huIdDic.Keys) { var item = this.itemMgr.GetCacheItem(flowDetail.Item); if (string.IsNullOrWhiteSpace(flowDetail.ReferenceItemCode)) { flowDetail.ReferenceItemCode = item.ReferenceCode; } Hu hu = new Hu(); hu.HuId = huId; hu.LotNo = flowDetail.LotNo; hu.Item = flowDetail.Item; hu.ItemDescription = item.Description; hu.BaseUom = flowDetail.BaseUom; hu.Qty = huIdDic[huId]; hu.ManufactureParty = flowDetail.ManufactureParty; hu.ManufactureDate = flowDetail.ManufactureDate; hu.PrintCount = 0; hu.ConcessionCount = 0; hu.ReferenceItemCode = flowDetail.ReferenceItemCode; hu.UnitCount = flowDetail.UnitCount; hu.UnitQty = itemMgr.ConvertItemUomQty(flowDetail.Item, flowDetail.Uom, 1, flowDetail.BaseUom); hu.Uom = flowDetail.Uom; hu.IsOdd = flowDetail.HuQty < flowDetail.MinUc; hu.SupplierLotNo = flowDetail.SupplierLotNo; hu.IsChangeUnitCount = flowDetail.IsChangeUnitCount; hu.UnitCountDescription = flowDetail.UnitCountDescription; hu.ContainerDesc = flowDetail.ContainerDescription; hu.LocationTo = string.IsNullOrWhiteSpace(flowDetail.LocationTo) ? flowMaster.LocationTo : flowDetail.LocationTo; hu.Flow = flowDetail.Flow; hu.MaterialsGroup = GetMaterialsGroupDescrption(item.MaterialsGroup); hu.HuTemplate = flowMaster.HuTemplate; hu.HuOption = GetHuOption(item); hu.Remark = flowDetail.Remark; if (item.Warranty > 0) { hu.ExpireDate = hu.ManufactureDate.AddDays(item.Warranty); } if (item.WarnLeadTime > 0) { hu.RemindExpireDate = hu.ManufactureDate.AddDays(item.WarnLeadTime); } this.genericMgr.Create(hu); //this.AsyncSendPrintData(hu); huList.Add(hu); } } } return huList; }
//public IOrderMgr orderMgr { get; set; } #endregion public IpMaster TransferFlow2Ip(FlowMaster flowMaster, IList<OrderDetail> orderDetailList) { IpMaster ipMaster = Mapper.Map<FlowMaster, IpMaster>(flowMaster); ipMaster.OrderType = CodeMaster.OrderType.ScheduleLine; ipMaster.OrderSubType = CodeMaster.OrderSubType.Normal; ipMaster.QualityType = CodeMaster.QualityType.Qualified; ipMaster.Status = CodeMaster.IpStatus.Submit; #region 查找IpMaster相关对象 #region 查找Party string selectPartyStatement = "from Party where Code in (?"; IList<object> selectPartyPara = new List<object>(); selectPartyPara.Add(flowMaster.PartyFrom); if (flowMaster.PartyFrom != flowMaster.PartyTo) { selectPartyStatement += ", ?"; selectPartyPara.Add(flowMaster.PartyTo); } selectPartyStatement += ")"; IList<Party> partyList = this.genericMgr.FindAll<Party>(selectPartyStatement, selectPartyPara.ToArray()); #endregion #region 查找Location #region 收集所有Location代码 IList<string> locationCodeList = new List<string>(); if (!string.IsNullOrEmpty(flowMaster.LocationFrom)) { locationCodeList.Add(flowMaster.LocationFrom); } if (!string.IsNullOrEmpty(flowMaster.LocationTo)) { locationCodeList.Add(flowMaster.LocationTo); } if (flowMaster.FlowDetails != null) { foreach (string locationFromCode in flowMaster.FlowDetails.Where(d => !string.IsNullOrEmpty(d.LocationFrom)).Select(d => d.LocationFrom).Distinct()) { locationCodeList.Add(locationFromCode); } foreach (string locationToCode in flowMaster.FlowDetails.Where(d => !string.IsNullOrEmpty(d.LocationTo)).Select(d => d.LocationTo).Distinct()) { locationCodeList.Add(locationToCode); } } #endregion #region 查找Location IList<Location> locationList = null; if (locationCodeList.Count > 0) { string selectLocationStatement = string.Empty; IList<object> selectLocationPara = new List<object>(); foreach (string locationCode in locationCodeList.Distinct()) { if (selectLocationStatement == string.Empty) { selectLocationStatement = "from Location where Code in (?"; } else { selectLocationStatement += ",?"; } selectLocationPara.Add(locationCode); } selectLocationStatement += ")"; locationList = this.genericMgr.FindAll<Location>(selectLocationStatement, selectLocationPara.ToArray()); } #endregion #endregion #region 查找Address #region 收集所有地址代码 IList<string> addressCodeList = new List<string>(); if (!string.IsNullOrEmpty(flowMaster.ShipFrom)) { addressCodeList.Add(flowMaster.ShipFrom); } if (!string.IsNullOrEmpty(flowMaster.ShipTo)) { addressCodeList.Add(flowMaster.ShipTo); } if (flowMaster.FlowDetails != null) { foreach (string billAddress in flowMaster.FlowDetails.Where(d => !string.IsNullOrEmpty(d.BillAddress)).Select(d => d.BillAddress).Distinct()) { addressCodeList.Add(billAddress); } } #endregion #region 查找Address IList<Address> addressList = null; if (addressCodeList.Count > 0) { string selectAddressStatement = string.Empty; IList<object> selectAddressPara = new List<object>(); foreach (string addressCode in addressCodeList.Distinct()) { if (selectAddressStatement == string.Empty) { selectAddressStatement = "from Address where Code in (?"; } else { selectAddressStatement += ",?"; } selectAddressPara.Add(addressCode); } selectAddressStatement += ")"; addressList = this.genericMgr.FindAll<Address>(selectAddressStatement, selectAddressPara.ToArray()); } #endregion #endregion #endregion #region PartyFrom和PartyTo赋值 ipMaster.PartyFromName = partyList.Where(p => p.Code == ipMaster.PartyFrom).Single().Name; ipMaster.PartyToName = partyList.Where(p => p.Code == ipMaster.PartyTo).Single().Name; #endregion #region ShipFrom赋值 if (!string.IsNullOrEmpty(flowMaster.ShipFrom)) { Address shipFrom = addressList.Where(a => a.Code == flowMaster.ShipFrom).Single(); ipMaster.ShipFromAddress = shipFrom.AddressContent; ipMaster.ShipFromCell = shipFrom.MobilePhone; ipMaster.ShipFromTel = shipFrom.TelPhone; ipMaster.ShipFromFax = shipFrom.Fax; ipMaster.ShipFromContact = shipFrom.ContactPersonName; } #endregion #region ShipTo赋值 if (!string.IsNullOrEmpty(flowMaster.ShipTo)) { Address shipTo = addressList.Where(a => a.Code == flowMaster.ShipTo).Single(); ipMaster.ShipToAddress = shipTo.AddressContent; ipMaster.ShipToCell = shipTo.MobilePhone; ipMaster.ShipToTel = shipTo.TelPhone; ipMaster.ShipToFax = shipTo.Fax; ipMaster.ShipToContact = shipTo.ContactPersonName; } #endregion #region 状态 ipMaster.Status = com.Sconit.CodeMaster.IpStatus.Submit; #endregion #region 发出时间 ipMaster.DepartTime = DateTime.Now; #endregion #region 到达时间 ipMaster.ArriveTime = DateTime.Now; #endregion #region 发货单明细 foreach (OrderDetail orderDetail in orderDetailList) { OrderMaster orderMaster = orderDetail.CurrentOrderMaster; FlowDetail flowDetail = flowMaster.FlowDetails.Where(det => det.Item == orderDetail.Item).Single(); IpDetail ipDetail = Mapper.Map<FlowDetail, IpDetail>(flowDetail); ipDetail.Type = CodeMaster.IpDetailType.Normal; ipDetail.OrderNo = orderDetail.OrderNo; ipDetail.OrderType = orderDetail.OrderType; ipDetail.OrderSubType = orderDetail.OrderSubType; ipDetail.OrderDetailId = orderDetail.Id; ipDetail.OrderDetailSequence = orderDetail.Sequence; ipDetail.ItemDescription = orderDetail.ItemDescription; ipDetail.ReferenceItemCode = orderDetail.ReferenceItemCode; ipDetail.ExternalOrderNo = orderDetail.ExternalOrderNo; ipDetail.ExternalSequence = orderDetail.ExternalSequence; if (ipDetail.LocationFrom == null) { ipDetail.LocationFrom = flowMaster.LocationFrom; } if (ipDetail.LocationFrom != null) { ipDetail.LocationFromName = locationList.Where(l => l.Code == ipDetail.LocationFrom).Single().Name; } if (ipDetail.LocationTo == null) { ipDetail.LocationTo = flowMaster.LocationTo; } if (ipDetail.LocationTo != null) { ipDetail.LocationToName = locationList.Where(l => l.Code == ipDetail.LocationTo).Single().Name; } if (orderDetail.StartDate.HasValue) { ipDetail.StartTime = orderDetail.StartDate; } else { ipDetail.StartTime = orderMaster.StartTime; } if (orderDetail.EndDate.HasValue) { ipDetail.WindowTime = orderDetail.EndDate; } else { ipDetail.WindowTime = orderMaster.WindowTime; } ipDetail.Flow = flowMaster.Code; //记录sap采购类型 ipDetail.PSTYP = orderDetail.AUFNR; //ZC1:军车 ZC2:出口车 ZC3:特殊车 ZC5:CKD ipDetail.Tax = orderDetail.Tax; //ipDetail.EffectiveDate = orderMaster.EffectiveDate; ipDetail.IsInspect = orderMaster.IsInspect; ipDetail.UnitQty = orderDetail.UnitQty; //2013-9-22,单位换算出错,此处要去订单中的单位 ipDetail.Uom = orderDetail.Uom; ipDetail.BillTerm = orderDetail.BillTerm; ipDetail.BillAddress = orderDetail.BillAddress; //ASN确认发货的发货库位 ipDetail.Tax = flowDetail.ShipLocation; foreach (OrderDetailInput orderDetailInput in orderDetail.OrderDetailInputs) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ShipQty = orderDetailInput.ShipQty; ipDetailInput.WMSIpSeq = orderDetailInput.WMSIpSeq; ipDetailInput.ConsignmentParty = orderDetailInput.ConsignmentParty; if (string.IsNullOrWhiteSpace(ipDetailInput.ConsignmentParty)) { //如果orderDetailInput没有指定寄售供应商,取orderDetail上的指定寄售供应商 ipDetailInput.ConsignmentParty = orderDetail.ICHARG; } ipDetailInput.OccupyType = orderDetailInput.OccupyType; ipDetailInput.OccupyReferenceNo = orderDetailInput.OccupyReferenceNo; ipDetail.AddIpDetailInput(ipDetailInput); } //计划协议发货检验整包装 if (orderMaster.IsReceiveFulfillUC && ipDetail.ShipQtyInput % ipDetail.UnitCount != 0) { //不是整包装 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ShipQtyNotFulfillUnitCount, orderDetail.Item, orderDetail.UnitCount.ToString("0.##")); } ipMaster.AddIpDetail(ipDetail); } #endregion return ipMaster; }
public static bool HasPermission(FlowMaster flowMaster, bool isSupplier = false, bool isCreateOrder = false) { return HasPermission(flowMaster.Type, flowMaster.IsCheckPartyFromAuthority, flowMaster.IsCheckPartyToAuthority, flowMaster.PartyFrom, flowMaster.PartyTo, isSupplier, false, isCreateOrder); }
public ActionResult _PickScheduleAjaxLoading(string text, bool? includeBlankOption) { IList<PickSchedule> pickScheduleList = new List<PickSchedule>(); FlowMaster flowMstr = new FlowMaster(); string sql = @" from PickSchedule as p where p.PickScheduleNo like ? "; string codeLike ="%" + text + "%"; pickScheduleList = queryMgr.FindAll<PickSchedule>(sql, codeLike); if (includeBlankOption.HasValue && includeBlankOption.Value) { pickScheduleList.Insert(0, new PickSchedule()); } return new JsonResult { Data = new SelectList(pickScheduleList, "PickScheduleNo", "PickScheduleNo") }; }
public ActionResult _ShiftAjaxLoading(string text, string flow, int? resourceGroup, bool? includeBlankOption) { IList<ShiftMaster> shiftMasterList = new List<ShiftMaster>(); FlowMaster flowMstr = new FlowMaster(); if (!string.IsNullOrWhiteSpace(flow)) { flowMstr = genericMgr.FindById<FlowMaster>(flow); } if (!resourceGroup.HasValue && flowMstr.Code != null) { resourceGroup = (int)flowMstr.ResourceGroup; } string sql = @" from ShiftMaster as s where s.Code like ? "; string codeLike = "%"; if (resourceGroup.HasValue) { codeLike = ((com.Sconit.CodeMaster.ResourceGroup)(resourceGroup.Value)).ToString() + codeLike; } shiftMasterList = queryMgr.FindAll<ShiftMaster>(sql, codeLike); if (includeBlankOption.HasValue && includeBlankOption.Value) { shiftMasterList.Insert(0, new ShiftMaster()); } return new JsonResult { Data = new SelectList(shiftMasterList, "Code", "Name") }; }
public IList<FlowDetail> GetFlowDetailList(FlowMaster flowMaster, bool includeInactiveDetail, bool includeReferenceFlow) { var flowDetails = this.GetFlowDetailList(flowMaster, includeInactiveDetail).ToList(); if (includeReferenceFlow) { //int maxFlowDetaiId = flowDetails.Count() == 0 ? 0 : flowDetails.Max(det => det.Id); if (!string.IsNullOrWhiteSpace(flowMaster.ReferenceFlow)) { var refFlowDetails = this.GetFlowDetailList(flowMaster.ReferenceFlow, includeInactiveDetail); var newFlowDetails = Mapper.Map<IList<FlowDetail>, IList<FlowDetail>>(refFlowDetails); foreach (var flowDetail in newFlowDetails) { flowDetail.CurrentFlowMaster = flowMaster; flowDetail.LocationFrom = null; //来源库位制空,取头上的库位 flowDetail.LocationTo = null; //目的库位制空,取头上的库位 flowDetail.DefaultLocationFrom = string.IsNullOrWhiteSpace(flowDetail.LocationFrom) ? flowDetail.CurrentFlowMaster.LocationFrom : flowDetail.LocationFrom; flowDetail.DefaultLocationTo = string.IsNullOrWhiteSpace(flowDetail.LocationTo) ? flowDetail.CurrentFlowMaster.LocationTo : flowDetail.LocationTo; flowDetail.DefaultExtraLocationFrom = string.IsNullOrWhiteSpace(flowDetail.ExtraLocationFrom) ? flowDetail.CurrentFlowMaster.ExtraLocationFrom : flowDetail.ExtraLocationFrom; flowDetail.DefaultExtraLocationTo = string.IsNullOrWhiteSpace(flowDetail.ExtraLocationTo) ? flowDetail.CurrentFlowMaster.ExtraLocationTo : flowDetail.ExtraLocationTo; //if (maxFlowDetaiId > 0) //{ // flowDetail.Id = maxFlowDetaiId++; //为了区分不同的ShipPlan,要给flowdetailId赋不同的值。 //} } flowDetails.AddRange(newFlowDetails); } } return flowDetails; }
private IList<FlowDetail> GetFlowDetails(FlowMaster flowMaster) { #region 读取路线 var flowDetails = this.flowMgr.GetFlowDetailList(flowMaster, false, true); if (flowDetails == null || flowDetails.Count() == 0) { if (flowMaster.IsManualCreateDetail) { flowDetails = new List<FlowDetail>(); var flowDetail = new FlowDetail(); flowDetail.CurrentFlowMaster = flowMaster; flowDetails.Add(flowDetail); } } #endregion return flowDetails; }
public OrderMaster TransferFlow2Order(FlowMaster flowMaster, bool isTransferDetail) { return TransferFlow2Order(flowMaster, null, DateTime.Now, isTransferDetail); }
//新方法 //仍然采用一个计划协议+协议行号对应一张les订单 //因为物料切换目的库位时,光改明细上的库位会有问题 //订单头上很多信息打印在单据上都是错误的 private IList<OrderDetail> CreateLesProcOrder(Entity.SAP.ORD.ProcOrder procOrder, FlowMaster flowMaster, object[] flowDetail, OrderMaster orderMaster, IList<OrderDetail> orderDetailList) { IList<OrderDetail> returnOrderDetailList = new List<OrderDetail>(); try { #region 创建订单头 if (orderMaster == null) { orderMaster = this.orderMgr.TransferFlow2Order(flowMaster, null); orderMaster.ExternalOrderNo = procOrder.EBELN; //计划协议号 orderMaster.ReferenceOrderNo = procOrder.EBELP; //采购凭证的项目编号 orderMaster.WindowTime = DateTime.Now; //窗口时间 orderMaster.StartTime = DateTime.Now; //开始日期 orderMaster.IsInspect = procOrder.NOTQC == "Y" ? false : true; //检验标记 orderMaster.Type = com.Sconit.CodeMaster.OrderType.ScheduleLine; orderMaster.OrderNo = numberControlMgr.GetOrderNo(orderMaster); this.orderMgr.CreateOrder(orderMaster); } else { //提升效率 //当les订单显示为需要检验,但sap显示为免检或les显示为免检,但sap显示为检验时才更新 if (procOrder.NOTQC == "Y" && orderMaster.IsInspect || procOrder.NOTQC == "N" && !orderMaster.IsInspect) { orderMaster.IsInspect = procOrder.NOTQC == "Y" ? false : true; genericMgr.Update(orderMaster); this.genericMgr.FlushSession(); } //if (orderMaster.Flow == flowMaster.Code) //{ // //提升效率 // //当les订单显示为需要检验,但sap显示为免检或les显示为免检,但sap显示为检验时才更新 // if (procOrder.NOTQC == "Y" && orderMaster.IsInspect || procOrder.NOTQC == "N" && !orderMaster.IsInspect) // { // orderMaster.IsInspect = procOrder.NOTQC == "Y" ? false : true; // genericMgr.Update(orderMaster); // } //} //如果路线发生变化,则更新订单头和订单明细的主要信息 //为了避免不必要的错误,路线变化后其他选项信息暂时不copy //切记新维护采购路线时一定要设置允许超发,允许超收,允许asn多次收货 //else //{ //更新订单 //orderMaster.Flow = flowMaster.Code; //orderMaster.FlowDescription = flowMaster != null ? flowMaster.Description : null; //orderMaster.PartyTo = flowMaster != null ? flowMaster.PartyTo : null; //Party partyTo = flowMaster != null ? this.genericMgr.FindById<Party>(flowMaster.PartyTo) : null; //orderMaster.PartyToName = flowMaster != null ? partyTo.Name : null; //orderMaster.ShipTo = flowMaster != null ? flowMaster.ShipTo : null; //Address address = flowMaster != null ? this.genericMgr.FindById<Address>(flowMaster.ShipTo) : null; //orderMaster.ShipToAddress = flowMaster != null ? address.AddressContent : null; //orderMaster.ShipToCell = flowMaster != null ? address.MobilePhone : null; ; //orderMaster.ShipToTel = flowMaster != null ? address.TelPhone : null; //orderMaster.ShipToContact = flowMaster != null ? address.ContactPersonName : null; //orderMaster.ShipToFax = flowMaster != null ? address.Fax : null; //orderMaster.LocationTo = flowMaster != null ? flowMaster.LocationTo : null; //Location location = flowMaster != null ? this.genericMgr.FindById<Location>(flowMaster.LocationTo) : null; //orderMaster.LocationToName = flowMaster != null ? location.Name : null; //orderMaster.IsInspect = procOrder.NOTQC == "Y" ? false : true; //genericMgr.Update(orderMaster); //取最新路线明细数据更新订单明细 //OrderDetail orderDetail = (from o in orderDetailList // where o.ExternalOrderNo == orderMaster.ExternalOrderNo && o.ExternalSequence == orderMaster.ReferenceOrderNo // select o).ToList()[0]; //FlowDetail flowDetail = this.genericMgr.FindAll<FlowDetail>("from FlowDetail where Flow = ? and Item = ?", new object[] { orderMaster.Flow, orderDetail.Item })[0]; //orderDetail.UnitCount = flowDetail.UnitCount; //orderDetail.Uom = flowDetail.Uom; //orderDetail.BaseUom = flowDetail.BaseUom; ////库位取路线头上的 //orderDetail.LocationTo = flowMaster.LocationTo; //orderDetail.LocationToName = genericMgr.FindById<Location>(flowMaster.LocationTo).Name; //genericMgr.Update(orderDetail); //} } #endregion #region 创建订单明细 //int id = 0; //提升效率,但存在风险 IList<OrderDetail> existedOrderDetail = (from o in orderDetailList where o.ExternalOrderNo == procOrder.EBELN && o.ExternalSequence == procOrder.EBELP select o).ToList(); //先更新原有订单 if (existedOrderDetail != null && existedOrderDetail.Count > 0) { //目前来说只有单位和单位换算会更新 decimal sapUnitQty = (procOrder.UMREN == 0 || procOrder.UMREZ == 0) ? 1 : (procOrder.UMREZ / procOrder.UMREN); if (existedOrderDetail[0].Uom != procOrder.MEINS || existedOrderDetail[0].BaseUom != procOrder.LMEIN || existedOrderDetail[0].UnitQty != sapUnitQty) { //PrepareOrderDetail(existedOrderDetail[0], orderMaster, procOrder.ProcOrderDetails[0], procOrder, DateTime.Now); existedOrderDetail[0].Uom = procOrder.MEINS; existedOrderDetail[0].BaseUom = procOrder.LMEIN; existedOrderDetail[0].UnitQty = sapUnitQty; genericMgr.Update(existedOrderDetail[0]); this.genericMgr.FlushSession(); } } //定义宿主订单明细用来copy,一旦首次插入失败,宿主订单将无法赋值可能引起出错 OrderDetail hostOrderDetail = new OrderDetail(); for (int i = 0; i < procOrder.ProcOrderDetails.Count(); i++) { try { #region 只在第一次执行插入,如果失败会存在风险 if (i == 0 && (existedOrderDetail == null || existedOrderDetail.Count == 0)) { //if (flowDetailList == null || flowDetailList.Count == 0) //{ // throw new BusinessException("和计划协议匹配的采购路线{0}物料代码{1}不存在,请联系计划员。", flowMaster.Code, procOrder.ProcOrderDetails[i].MATNR); //} //object[] flowDetail = flowDetailList[0]; OrderDetail orderDetail = new OrderDetail(); orderDetail.UnitCount = (decimal)flowDetail[3]; //orderDetail.IsInspect = flowDetail.IsInspect; //if (!string.IsNullOrEmpty(flowDetail.LocationTo)) //{ // orderDetail.LocationTo = flowDetail.LocationTo; // orderDetail.LocationToName = lesMgr.FindById<Location>(flowDetailList[0].LocationTo).Name; //} PrepareOrderDetail(orderDetail, orderMaster, procOrder.ProcOrderDetails[i], procOrder, DateTime.Now); if (string.IsNullOrWhiteSpace(orderDetail.Uom)) { orderDetail.Uom = (string)flowDetail[4]; } if (string.IsNullOrWhiteSpace(orderDetail.BaseUom)) { orderDetail.BaseUom = (string)flowDetail[5]; } if (string.IsNullOrWhiteSpace(orderDetail.ItemDescription)) { orderDetail.ItemDescription = (string)flowDetail[7]; } if (string.IsNullOrWhiteSpace(orderDetail.ReferenceItemCode)) { orderDetail.ReferenceItemCode = (string)flowDetail[6]; } if (string.IsNullOrWhiteSpace(orderDetail.BillAddress) && !string.IsNullOrWhiteSpace(orderMaster.BillAddress)) { orderDetail.BillAddress = orderMaster.BillAddress; orderDetail.BillAddressDescription = orderMaster.BillAddressDescription; } genericMgr.Create(orderDetail); this.genericMgr.FlushSession(); #region 自己拼Orderdetail,显示用不更新数据库 DateTime EINDT = DateTime.Parse(procOrder.ProcOrderDetails[0].EINDT); //orderDetail.Id = orderDetail.Id + id; orderDetail.StartDate = EINDT; orderDetail.EndDate = EINDT; orderDetail.OrderedQty = procOrder.ProcOrderDetails[0].MENGE; orderDetail.FreezeDays = Convert.ToInt32(procOrder.ETFZ1); orderDetail.Flow = flowMaster.Code; orderDetail.ManufactureParty = flowMaster != null ? flowMaster.PartyFrom : null; //sap的收货数,仅仅是用于需求预测报表,和计划协议的已收数可能有误差 orderDetail.ReceivedQty = procOrder.ProcOrderDetails[i].WEMNG.HasValue ? procOrder.ProcOrderDetails[i].WEMNG.Value : decimal.Zero; returnOrderDetailList.Add(orderDetail); //记录到宿主订单用于复制 hostOrderDetail = orderDetail; //id++; #endregion } else if (existedOrderDetail != null && existedOrderDetail.Count > 0) { OrderDetail newOrderDetail = new OrderDetail(); #region 自己拼Orderdetail,显示用不更新数据库 newOrderDetail.Id = existedOrderDetail[0].Id; newOrderDetail.Item = existedOrderDetail[0].Item; newOrderDetail.ReferenceItemCode = existedOrderDetail[0].ReferenceItemCode; newOrderDetail.ItemDescription = existedOrderDetail[0].ItemDescription; newOrderDetail.ExternalOrderNo = existedOrderDetail[0].ExternalOrderNo; newOrderDetail.ExternalSequence = existedOrderDetail[0].ExternalSequence; newOrderDetail.OrderNo = existedOrderDetail[0].OrderNo; DateTime EINDT = DateTime.Parse(procOrder.ProcOrderDetails[i].EINDT); newOrderDetail.OrderType = CodeMaster.OrderType.ScheduleLine; newOrderDetail.LocationTo = flowMaster.LocationTo; newOrderDetail.ShippedQty = existedOrderDetail[0].ShippedQty; newOrderDetail.ReceivedQty = existedOrderDetail[0].ReceivedQty; newOrderDetail.UnitCount = (decimal)flowDetail[3]; newOrderDetail.Uom = existedOrderDetail[0].Uom; newOrderDetail.StartDate = EINDT; newOrderDetail.EndDate = EINDT; newOrderDetail.OrderedQty = procOrder.ProcOrderDetails[i].MENGE; newOrderDetail.FreezeDays = Convert.ToInt32(procOrder.ETFZ1); newOrderDetail.Flow = flowMaster.Code; newOrderDetail.ManufactureParty = flowMaster != null ? flowMaster.PartyFrom : null; newOrderDetail.BillTerm = existedOrderDetail[0].BillTerm; //sap的收货数,仅仅是用于需求预测报表,和计划协议的已收数可能有误差 newOrderDetail.ReceivedQty = procOrder.ProcOrderDetails[i].WEMNG.HasValue ? procOrder.ProcOrderDetails[i].WEMNG.Value : decimal.Zero; returnOrderDetailList.Add(newOrderDetail); //id++; #endregion } else if (existedOrderDetail == null || existedOrderDetail.Count == 0) { OrderDetail newOrderDetail = new OrderDetail(); //OrderDetail existedDetail = (from o in lesOrderDetailList // where o.ExternalOrderNo == procOrderDetail.EBELN && o.ExternalSequence == procOrderDetail.EBELP // select o).ToList()[0]; #region 自己拼Orderdetail,显示用不更新数据库 newOrderDetail.Id = 0; newOrderDetail.Item = hostOrderDetail.Item; newOrderDetail.ReferenceItemCode = hostOrderDetail.ReferenceItemCode; newOrderDetail.ItemDescription = hostOrderDetail.ItemDescription; newOrderDetail.ExternalOrderNo = hostOrderDetail.ExternalOrderNo; newOrderDetail.ExternalSequence = hostOrderDetail.ExternalSequence; newOrderDetail.OrderNo = hostOrderDetail.OrderNo; DateTime EINDT = DateTime.Parse(procOrder.ProcOrderDetails[i].EINDT); newOrderDetail.OrderType = CodeMaster.OrderType.ScheduleLine; newOrderDetail.LocationTo = flowMaster.LocationTo; newOrderDetail.ShippedQty = 0; newOrderDetail.ReceivedQty = 0; newOrderDetail.UnitCount = hostOrderDetail.UnitCount; newOrderDetail.Uom = hostOrderDetail.Uom; newOrderDetail.StartDate = EINDT; newOrderDetail.EndDate = EINDT; newOrderDetail.OrderedQty = procOrder.ProcOrderDetails[i].MENGE; newOrderDetail.FreezeDays = Convert.ToInt32(procOrder.ETFZ1); newOrderDetail.Flow = flowMaster.Code; newOrderDetail.ManufactureParty = flowMaster != null ? flowMaster.PartyFrom : null; newOrderDetail.BillTerm = hostOrderDetail.BillTerm; //sap的收货数,仅仅是用于需求预测报表,和计划协议的已收数可能有误差 newOrderDetail.ReceivedQty = procOrder.ProcOrderDetails[i].WEMNG.HasValue ? procOrder.ProcOrderDetails[i].WEMNG.Value : decimal.Zero; returnOrderDetailList.Add(newOrderDetail); //id++; #endregion } #endregion } catch (Exception ex) { string logMessage = string.Format("创建采购路线{0}物料代码{1}计划协议号{2}行号{3}的计划协议明细出现异常,异常信息:{4}", orderMaster.Flow, procOrder.ProcOrderDetails[i].MATNR, procOrder.EBELN, procOrder.EBELP, ex.Message); log.Error(logMessage, ex); this.genericMgr.CleanSession(); throw new BusinessException(logMessage); } } #endregion //明细创建成功后,更新订单状态 if (orderMaster.Status == CodeMaster.OrderStatus.Create) { orderMaster.Status = CodeMaster.OrderStatus.Submit; this.genericMgr.Update(orderMaster); this.genericMgr.FlushSession(); } //返回订单明细用于portal显示 return returnOrderDetailList; } catch (Exception ex) { string logMessage = string.Format("创建协议号{0}行号{1}的计划协议出现异常,异常信息:{2}", procOrder.EBELN, procOrder.EBELP, ex.Message); log.Error(logMessage, ex); this.genericMgr.CleanSession(); throw new BusinessException(logMessage); } }
public OrderMaster TransferFlow2Order(FlowMaster flowMaster, IList<string> itemCodeList, DateTime effectivedate) { return TransferFlow2Order(flowMaster, itemCodeList, effectivedate, true); }
public FlowMaster GetReverseFlow(FlowMaster flow, IList<string> itemCodeList) { FlowMaster reverseFlow = new FlowMaster(); Mapper.Map(flow, reverseFlow); reverseFlow.PartyFrom = flow.PartyTo; reverseFlow.PartyTo = flow.PartyFrom; reverseFlow.IsCheckPartyFromAuthority = flow.IsCheckPartyToAuthority; reverseFlow.IsCheckPartyToAuthority = flow.IsCheckPartyFromAuthority; reverseFlow.ShipFrom = flow.ShipTo; reverseFlow.ShipTo = flow.ShipFrom; reverseFlow.LocationFrom = flow.LocationTo; reverseFlow.LocationTo = flow.LocationFrom; reverseFlow.IsShipScanHu = flow.IsReceiveScanHu; reverseFlow.IsReceiveScanHu = flow.IsShipScanHu; reverseFlow.IsShipFifo = flow.IsReceiveFifo; reverseFlow.IsReceiveFifo = flow.IsShipFifo; reverseFlow.IsShipExceed = flow.IsReceiveExceed; reverseFlow.IsReceiveExceed = flow.IsShipExceed; //reverseFlow.IsShipFulfillUC = flow.IsReceiveFulfillUC; //reverseFlow.IsReceiveFulfillUC = flow.IsShipFulfillUC; reverseFlow.IsInspect = flow.IsRejectInspect; reverseFlow.IsRejectInspect = flow.IsInspect; reverseFlow.IsCreatePickList = false; reverseFlow.IsShipByOrder = true; //以后有什么字段再加 #region 路线明细 if (flow.FlowDetails == null || flow.FlowDetails.Count == 0) { string hql = "from FlowDetail where Flow = ?"; IList<object> parm = new List<object>(); parm.Add(flow.Code); if (itemCodeList != null && itemCodeList.Count() > 0) { string whereHql = string.Empty; foreach (string itemCode in itemCodeList.Distinct()) { if (whereHql == string.Empty) { whereHql = " and Item in (?"; } else { whereHql += ",?"; } parm.Add(itemCode); } whereHql += ")"; hql += whereHql; } hql += " order by Sequence"; flow.FlowDetails = this.genericMgr.FindAll<FlowDetail>(hql, parm.ToArray()); } if (flow.FlowDetails != null && flow.FlowDetails.Count > 0) { IList<FlowDetail> reverseFlowDetailList = new List<FlowDetail>(); foreach (FlowDetail flowDetail in flow.FlowDetails) { FlowDetail reverseFlowDetail = new FlowDetail(); Mapper.Map(flowDetail, reverseFlowDetail); reverseFlowDetail.LocationFrom = flowDetail.LocationTo; reverseFlowDetail.LocationTo = flowDetail.LocationFrom; reverseFlowDetail.IsRejectInspect = flowDetail.IsInspect; reverseFlowDetail.IsInspect = flowDetail.IsRejectInspect; //PartyFrom? reverseFlowDetailList.Add(reverseFlowDetail); } reverseFlow.FlowDetails = reverseFlowDetailList; } #endregion return reverseFlow; }
public IList<OrderDetail> TransformFlowMster2OrderDetailList(FlowMaster flow, CodeMaster.OrderSubType orderSubType) { IList<FlowDetail> flowDetailList = flowMgr.GetFlowDetailList(flow, false, true); IList<OrderDetail> orderDetailList = new List<OrderDetail>(); foreach (FlowDetail flowDetail in flowDetailList) { OrderDetail orderDetail = Mapper.Map<FlowDetail, OrderDetail>(flowDetail); if (orderSubType == com.Sconit.CodeMaster.OrderSubType.Return) { orderDetail.LocationFrom = string.IsNullOrWhiteSpace(flowDetail.LocationTo) ? flow.LocationTo : flowDetail.LocationTo; orderDetail.LocationTo = string.IsNullOrWhiteSpace(flowDetail.LocationFrom) ? flow.LocationFrom : flowDetail.LocationFrom; } else { orderDetail.LocationFrom = string.IsNullOrWhiteSpace(flowDetail.LocationFrom) ? flow.LocationFrom : flowDetail.LocationFrom; orderDetail.LocationTo = string.IsNullOrWhiteSpace(flowDetail.LocationTo) ? flow.LocationTo : flowDetail.LocationTo; } if (flow.Type == CodeMaster.OrderType.Production) { orderDetail.Bom = string.IsNullOrWhiteSpace(orderDetail.Bom) ? orderDetail.Item : orderDetail.Bom; } //orderDetail.Id = flowDetail.Id; var item = itemMgr.GetCacheItem(flowDetail.Item); orderDetail.ItemDescription = item.Description; if (string.IsNullOrWhiteSpace(orderDetail.ReferenceItemCode)) { orderDetail.ReferenceItemCode = item.ReferenceCode; } orderDetailList.Add(orderDetail); } return orderDetailList; }
public void CreateFlow(FlowMaster flowMaster) { genericMgr.Create(flowMaster); #region flow strategy FlowStrategy flowStrategy = new FlowStrategy(); flowStrategy.Flow = flowMaster.Code; flowStrategy.Strategy = flowMaster.FlowStrategy; flowStrategy.Description = flowMaster.Description; //默认取小时,以后再改 flowStrategy.TimeUnit = CodeMaster.TimeUnit.Hour; genericMgr.Create(flowStrategy); #endregion }
public OrderMaster CreateReturnOrder(FlowMaster flowMaster, IList<InspectResult> inspectResultList) { //if (!Utility.SecurityHelper.HasPermission(flowMaster)) //{ // throw new BusinessException("没有此路线{0}的操作权限。", flowMaster.Code); //} if (inspectResultList == null || inspectResultList.Count == 0) { throw new BusinessException("退货明细不能为空."); } #region 根据路线生成退货单 FlowMaster returnFlow = flowMgr.GetReverseFlow(flowMaster, inspectResultList.Select(r => r.Item).Distinct().ToList()); OrderMaster orderMaster = TransferFlow2Order(returnFlow, null); orderMaster.IsQuick = true; orderMaster.SubType = CodeMaster.OrderSubType.Return; orderMaster.WindowTime = DateTime.Now; orderMaster.StartTime = DateTime.Now; orderMaster.EffectiveDate = DateTime.Now; orderMaster.QualityType = CodeMaster.QualityType.Reject; orderMaster.ReferenceOrderNo = inspectResultList[0].InspectNo; #endregion #region 不合格品单明细变成退货单明细 IList<OrderDetail> orderDetailList = new List<OrderDetail>(); foreach (var inspectResult in inspectResultList) { if (inspectResult.JudgeQty < inspectResult.HandleQty + inspectResult.CurrentHandleQty) { throw new BusinessException("不合格品物料{0}本次处理数加已处理数超过总处理数.", inspectResult.Item); } if (orderMaster.OrderDetails != null && orderMaster.OrderDetails.Count > 0) { var q = orderMaster.OrderDetails.Where(o => o.Item == inspectResult.Item).ToList(); if (q.ToList() == null || q.ToList().Count == 0) { throw new BusinessException("不合格品物料{0}没找到对应的路线明细.", inspectResult.Item); } OrderDetail orderDetail = Mapper.Map<OrderDetail, OrderDetail>(q.ToList().First()); orderDetail.QualityType = com.Sconit.CodeMaster.QualityType.Reject; orderDetail.Uom = inspectResult.Uom; if (string.IsNullOrWhiteSpace(inspectResultList.First().HuId)) { orderDetail.OrderedQty = inspectResult.CurrentHandleQty; } orderDetail.LocationFrom = orderMaster.LocationFrom; //orderDetail.LocationFromName = genericMgr.FindById<Location>(inspectResult.CurrentLocation).Name; orderDetail.ManufactureParty = inspectResult.ManufactureParty; orderDetailList.Add(orderDetail); } else { throw new BusinessException("不合格品物料{0}没找到对应的路线明细.", inspectResult.Item); } } if (!string.IsNullOrWhiteSpace(inspectResultList.First().HuId)) { AddHuToOrderDetailInput(orderDetailList, inspectResultList.Select(p => p.HuId).Distinct().ToList()); } #endregion #region 创建退货单 orderMaster.OrderDetails = orderDetailList; CreateOrder(orderMaster); #endregion #region 更新明细状态 if (orderMaster.Type == CodeMaster.OrderType.CustomerGoods || orderMaster.Type == CodeMaster.OrderType.SubContract || orderMaster.Type == CodeMaster.OrderType.Procurement) { foreach (var inspectResult in inspectResultList) { inspectResult.HandleQty += inspectResult.CurrentHandleQty; if (inspectResult.HandleQty == inspectResult.JudgeQty) { inspectResult.IsHandle = true; } genericMgr.Update(inspectResult); } } #endregion return orderMaster; }
private IList<FlowDetail> GetFlowDetailList(string refFlowCode, bool includeInactive, bool includeReferenceFlow, FlowMaster baseFlow) { if (refFlowCode != baseFlow.Code) { var flowDetails = this.GetFlowDetailList(refFlowCode, includeInactive).ToList(); if (includeReferenceFlow) { var refflowMaster = this.genericMgr.FindById<Entity.SCM.FlowMaster>(refFlowCode); if (!string.IsNullOrWhiteSpace(refflowMaster.ReferenceFlow) && refflowMaster.IsActive) { var refFlowDetails = this.GetFlowDetailList(refflowMaster.ReferenceFlow, false, true, baseFlow); var newFlowDetails = Mapper.Map<IList<FlowDetail>, IList<FlowDetail>>(refFlowDetails); foreach (var detail in newFlowDetails) { detail.CurrentFlowMaster = baseFlow; } flowDetails.AddRange(newFlowDetails); } } return flowDetails; } return new List<FlowDetail>(); }
private IList<FlowDetail> TryLoadFlowDetails(FlowMaster flowMaster, IList<string> itemCodeList) { if (!string.IsNullOrWhiteSpace(flowMaster.Code)) { if (flowMaster.FlowDetails == null) { string hql = "from FlowDetail where Flow = ?"; IList<object> parm = new List<object>(); parm.Add(flowMaster.Code); if (itemCodeList != null && itemCodeList.Count > 0 && itemCodeList.Count < 2000) { string whereHql = string.Empty; foreach (string itemCode in itemCodeList.Distinct()) { if (whereHql == string.Empty) { whereHql = " and Item in (?"; } else { whereHql += ",?"; } parm.Add(itemCode); } whereHql += ")"; hql += whereHql; } hql += " order by Sequence"; flowMaster.FlowDetails = this.genericMgr.FindAll<FlowDetail>(hql, parm.ToArray()); if (itemCodeList != null && itemCodeList.Count >= 2000) { flowMaster.FlowDetails = flowMaster.FlowDetails.Where(f => itemCodeList.Contains(f.Item)).ToList(); } } return flowMaster.FlowDetails; } else { return null; } }
public void ImportFlow(Stream inputStream, CodeMaster.OrderType flowType) { if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); ImportHelper.JumpRows(rows, 10); #region 列定义 // FlowMaster int colType = 1;//路线类型 int colCode = 2; // 路线代码 int colDesc = 3; // 路线描述 // FlowDet int colItem = 4; // 物料 int colUom = 5; // 单位 int colUnitCount = 6; // 单包装 int colUcDesc = 7; // 单包装 int colMinStock = 8;// int colMaxStock = 9;// // FlowStrategy int colLeadTime = 10; // 提前期 #endregion var errorMessage = new BusinessException(); int colCount = 10; List<List<string>> rowDataList = new List<List<string>>(); var items = this.genericMgr.FindAll<Item>().ToDictionary(d => d.Code, d => d); #region 读取数据 while (rows.MoveNext()) { HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 1, 8)) { break;//边界 } colCount++; var rowData = new List<string>(); #region FlowMaster rowData.Add("0"); rowData.Add(((int)flowType).ToString()); rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colCode))); if (string.IsNullOrWhiteSpace(rowData[2])) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.FlowCodeShouldNotEmpty, colCount.ToString())); } rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colDesc))); if (string.IsNullOrWhiteSpace(rowData[3])) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.FlowDescShouldNotEmpty, colCount.ToString())); } #endregion #region FlowDetail Item item = null; rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colItem))); if (!string.IsNullOrWhiteSpace(rowData[4])) { item = items.ValueOrDefault(rowData[4]); } if (item == null) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineItemNotFound, colCount.ToString(), rowData[4])); continue; } rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colUom))); if (string.IsNullOrWhiteSpace(rowData[5])) { rowData[5] = item.Uom; } else { try { Uom uom = this.genericMgr.FindById<Uom>(rowData[5].ToUpper()); rowData[5] = uom.Code; } catch (Exception) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineUomNotFound, colCount.ToString(), rowData[5])); } } rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colUnitCount))); if (string.IsNullOrWhiteSpace(rowData[6])) { rowData[6] = item.UnitCount.ToString(); } else { decimal unitCount = item.UnitCount; if (!decimal.TryParse(rowData[6], out unitCount)) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineUCIsNotNum, colCount.ToString())); } rowData[6] = unitCount == 0 ? item.UnitCount.ToString() : unitCount.ToString(); } //7 rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colUcDesc))); rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colMinStock))); if (string.IsNullOrWhiteSpace(rowData[8])) { rowData[8] = "0"; } else { decimal decVal = 0m; if (!decimal.TryParse(rowData[8], out decVal)) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineSafeInvIsNotNum, colCount.ToString())); } rowData[8] = decVal.ToString(); } rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colMaxStock))); if (string.IsNullOrWhiteSpace(rowData[9])) { rowData[9] = "0"; } else { decimal decVal = 0m; if (!decimal.TryParse(rowData[9], out decVal)) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineMaxInvIsNotNum, colCount.ToString())); } rowData[9] = decVal.ToString(); } #endregion #region FlowStrategy rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colLeadTime))); if (string.IsNullOrWhiteSpace(rowData[10])) { rowData[10] = "0"; } else { decimal leadTimeVal = 0m; if (!decimal.TryParse(rowData[10], out leadTimeVal)) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineLeantimeIsNotNum, colCount.ToString())); } rowData[10] = leadTimeVal.ToString(); } #endregion rowData.Add(item.Description);//11 rowData.Add(item.Uom);//12 rowData.Add(item.ReferenceCode);//13 rowDataList.Add(rowData); } #endregion #region 验证 //Excle中重复性验证 var flowItems = rowDataList.Where(p => p[0] == "0") .Select(p => new { Type = (CodeMaster.OrderType)(int.Parse(p[1])), Flow = p[2], FlowDescription = p[3], Item = p[4], Uom = p[5], UnitCount = decimal.Parse(p[6]), UcDesc = p[7], MinStock = decimal.Parse(p[8]), MaxStock = decimal.Parse(p[9]), LeadTime = decimal.Parse(p[10]), ItemDescription = p[11], BaseUom = p[12], ReferenceCode = p[13] }); if (flowItems == null || flowItems.Count() == 0) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheImportIsNotEffect); throw errorMessage; } var flowItemGroup = flowItems.GroupBy(p => new { p.Flow, p.Item, p.Uom, p.UnitCount }, (k, g) => new { k, Count = g.Count() }) .Where(p => p.Count > 1).Select(p => new { p.k.Flow, p.k.Item }); foreach (var flowItem in flowItemGroup) { errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.DuplicateFlowDetail, flowItem.Flow, flowItem.Item)); } var distinctFlowItems = flowItems.GroupBy(p => new { p.Flow, p.Item }, (k, g) => new { k, j = g.First() }) .Select(p => p.j); var excelFlowMasterList = distinctFlowItems.GroupBy(p => p.Flow, (k, g) => new { Code = k, List = g }); var flowMasterDic = this.genericMgr.FindAllIn<FlowMaster>("from FlowMaster where Code in(?", excelFlowMasterList.Select(p => p.Code)).ToDictionary(d => d.Code, d => d); var flowStrategyDic = this.genericMgr.FindAllIn<FlowStrategy>("from FlowStrategy where Flow in(?", excelFlowMasterList.Select(p => p.Code)).ToDictionary(d => d.Flow, d => d); var allParty = this.genericMgr.FindAll<Party>().ToDictionary(d => d.Code, d => d.Code); var allPriceList = this.genericMgr.FindAll<PriceListMaster>().ToDictionary(d => d.Code, d => d.Code); var allAddress = this.genericMgr.FindAll<Address>().ToDictionary(d => d.Code, d => d.Code); var allLocation = this.genericMgr.FindAll<Location>().ToDictionary(d => d.Code, d => d.Code); foreach (var excelFlowMaster in excelFlowMasterList) { var firstFlowItem = excelFlowMaster.List.First(); var flowMaster = flowMasterDic.ValueOrDefault(excelFlowMaster.Code); var flowStrategy = flowStrategyDic.ValueOrDefault(excelFlowMaster.Code); if (flowType != firstFlowItem.Type) { errorMessage.AddMessage(Resources.EXT.ServiceLan.FlowTypeIsNotCorrect, firstFlowItem.Type.ToString()); continue; } #region flowMaster if (flowMaster == null) { #region FlowMaster赋值 var flowCodeSplits = excelFlowMaster.Code.Split('-'); var flowDescriptionSplits = firstFlowItem.FlowDescription.Split('-'); var newFlowMaster = new FlowMaster(); newFlowMaster.Code = excelFlowMaster.Code; newFlowMaster.Type = firstFlowItem.Type; newFlowMaster.Description = firstFlowItem.FlowDescription; newFlowMaster.IsListDet = true; newFlowMaster.IsPrintOrder = true; newFlowMaster.IsPrintAsn = true; newFlowMaster.IsPrintRceipt = true; newFlowMaster.IsShipExceed = true; newFlowMaster.IsShipFifo = true; newFlowMaster.IsAllowProvEstRec = true; newFlowMaster.ReceiveGapTo = CodeMaster.ReceiveGapTo.AdjectLocFromInv; //Code Desc1 IsActive Type RefFlow PartyFrom PartyTo ShipFrom ShipTo LocFrom LocTo BillAddr //PriceList Routing ReturnRouting Dock IsAutoCreate IsAutoRelease IsAutoStart IsAutoShip IsAutoReceive //IsAutoBill IsListDet IsManualCreateDet IsListPrice IsPrintOrder IsPrintAsn IsPrintRcpt IsShipExceed //IsRecExceed IsOrderFulfillUC IsShipFulfillUC IsRecFulfillUC IsShipScanHu IsRecScanHu IsCreatePL //IsInspect IsShipFifo IsRejInspect IsRecFifo IsShipByOrder IsAsnUniqueRec IsMRP IsCheckPartyFromAuth //IsCheckPartyToAuth RecGapTo RecTemplate OrderTemplate AsnTemplate HuTemplate BillTerm CreateHuOpt //MaxOrderCount MRPOpt IsPause PauseTime FlowStrategy ExtraDmdSource PickStrategy CreateUser CreateUserNm //CreateDate LastModifyUser LastModifyUserNm LastModifyDate DAUAT LastRefreshDate ResourceGroup //IsAllowProvEstRec UcDeviation OrderDeviation if (firstFlowItem.Type == CodeMaster.OrderType.Procurement || firstFlowItem.Type == CodeMaster.OrderType.CustomerGoods || firstFlowItem.Type == CodeMaster.OrderType.SubContract) { newFlowMaster.PartyFrom = flowCodeSplits[0]; var location = this.genericMgr.FindById<Location>(flowCodeSplits[1]); newFlowMaster.PartyTo = location.Region; if (firstFlowItem.Type == CodeMaster.OrderType.SubContract) { newFlowMaster.LocationFrom = newFlowMaster.PartyFrom; } newFlowMaster.LocationTo = location.Code; newFlowMaster.BillAddress = newFlowMaster.PartyFrom; newFlowMaster.PriceList = newFlowMaster.PartyFrom; newFlowMaster.IsReceiveScanHu = true; newFlowMaster.OrderTemplate = "ORD_Purchase.xls"; newFlowMaster.AsnTemplate = "ASN_Purchase.xls"; newFlowMaster.ReceiptTemplate = "REC_Receipt.xls"; newFlowMaster.HuTemplate = "BarCodePurchase2D.xls"; newFlowMaster.BillTerm = CodeMaster.OrderBillTerm.ReceivingSettlement; newFlowMaster.CreateHuOption = CodeMaster.CreateHuOption.None; newFlowMaster.IsListPrice = true; newFlowMaster.IsAsnUniqueReceive = true; newFlowMaster.IsAllowProvEstRec = true; } else if (firstFlowItem.Type == CodeMaster.OrderType.Distribution || firstFlowItem.Type == CodeMaster.OrderType.SubContractTransfer) { var location = this.genericMgr.FindById<Location>(flowCodeSplits[0]); newFlowMaster.LocationFrom = location.Code; newFlowMaster.PartyFrom = location.Region; newFlowMaster.PartyTo = flowCodeSplits[1]; if (firstFlowItem.Type == CodeMaster.OrderType.SubContractTransfer) { newFlowMaster.LocationTo = newFlowMaster.PartyTo; newFlowMaster.OrderTemplate = "ASN_Transfer.xls"; newFlowMaster.AsnTemplate = "ASN_Transfer.xls"; newFlowMaster.ReceiptTemplate = "REC_InvOut.xls"; newFlowMaster.HuTemplate = "BarCodeMI2D.xls"; } else { newFlowMaster.BillAddress = newFlowMaster.PartyTo; newFlowMaster.PriceList = newFlowMaster.PartyTo; newFlowMaster.OrderTemplate = "ORD_Sale.xls"; newFlowMaster.AsnTemplate = "ASN_Sale.xls"; newFlowMaster.ReceiptTemplate = "REC_Sale.xls"; newFlowMaster.HuTemplate = "BarCodeFI2D.xls"; newFlowMaster.BillTerm = CodeMaster.OrderBillTerm.ReceivingSettlement; newFlowMaster.CreateHuOption = CodeMaster.CreateHuOption.None; } newFlowMaster.IsRejectInspect = true; newFlowMaster.IsShipScanHu = true; newFlowMaster.IsCreatePickList = false; } else if (firstFlowItem.Type == CodeMaster.OrderType.Production) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheProdLineNotFound, excelFlowMaster.Code); } else if (firstFlowItem.Type == CodeMaster.OrderType.Transfer) { var locationFrom = this.genericMgr.FindById<Location>(flowCodeSplits[0]); var locationTo = this.genericMgr.FindById<Location>(flowCodeSplits[1]); newFlowMaster.PartyFrom = locationFrom.Region; newFlowMaster.PartyTo = locationTo.Region; newFlowMaster.LocationFrom = locationFrom.Code; newFlowMaster.LocationTo = locationTo.Code; newFlowMaster.IsShipScanHu = true; newFlowMaster.IsReceiveScanHu = true; newFlowMaster.IsCreatePickList = false; newFlowMaster.OrderTemplate = "ASN_Transfer.xls"; newFlowMaster.AsnTemplate = "ASN_Transfer.xls"; newFlowMaster.ReceiptTemplate = "REC_InvOut.xls"; newFlowMaster.HuTemplate = "BarCodeEX2D.xls"; newFlowMaster.CreateHuOption = CodeMaster.CreateHuOption.None; } newFlowMaster.ShipFrom = newFlowMaster.PartyFrom; newFlowMaster.ShipTo = newFlowMaster.PartyTo; #endregion #region 校验 bool isMark = false; if (!allParty.ContainsKey(newFlowMaster.PartyFrom)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.ThePartyFromNotFound, newFlowMaster.PartyFrom); isMark = true; } if (!allParty.ContainsKey(newFlowMaster.PartyTo)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.ThePartyToNotFound, newFlowMaster.PartyTo); isMark = true; } if (!string.IsNullOrWhiteSpace(newFlowMaster.LocationFrom) && !allLocation.ContainsKey(newFlowMaster.LocationFrom)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheLocFromNotFound, newFlowMaster.LocationFrom); isMark = true; } if (!string.IsNullOrWhiteSpace(newFlowMaster.LocationTo) && !allLocation.ContainsKey(newFlowMaster.LocationTo)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheLocToNotFound, newFlowMaster.LocationTo); isMark = true; } if (!string.IsNullOrWhiteSpace(newFlowMaster.PriceList) && !allPriceList.ContainsKey(newFlowMaster.PriceList)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.ThePriceListNotFound, newFlowMaster.PriceList); isMark = true; } if (!string.IsNullOrWhiteSpace(newFlowMaster.BillAddress) && !allAddress.ContainsKey(newFlowMaster.BillAddress)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheBillAddrNotFound, newFlowMaster.BillAddress); isMark = true; } if (!allAddress.ContainsKey(newFlowMaster.ShipFrom)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheShipAddrNotFound, newFlowMaster.ShipFrom); isMark = true; } if (!allAddress.ContainsKey(newFlowMaster.ShipTo)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheShipToNotFound, newFlowMaster.ShipTo); isMark = true; } #endregion if (!isMark && !errorMessage.HasMessage) { try { this.genericMgr.Create(newFlowMaster); } catch (Exception ex) { errorMessage.AddMessage(ex.Message); } } } else { if (flowMaster.Description != firstFlowItem.FlowDescription && !errorMessage.HasMessage) { flowMaster.Description = firstFlowItem.FlowDescription; this.genericMgr.Update(flowMaster); } } #endregion #region FlowStrategy if (!errorMessage.HasMessage) { if (flowStrategy == null) { //Flow Strategy Desc1 LeadTime EmLeadTime TimeUnit var newFlowStrategy = new FlowStrategy(); newFlowStrategy.Flow = excelFlowMaster.Code; newFlowStrategy.Description = firstFlowItem.FlowDescription; newFlowStrategy.LeadTime = firstFlowItem.LeadTime; newFlowStrategy.TimeUnit = CodeMaster.TimeUnit.Hour; this.genericMgr.Create(newFlowStrategy); } else { flowStrategy.LeadTime = firstFlowItem.LeadTime; this.genericMgr.Update(flowStrategy); } } #endregion #region FlowDetail if (!errorMessage.HasMessage) { var flowDetailDic = this.genericMgr.FindAllIn<FlowDetail> ("from FlowDetail where Flow = ? and Item in(? ", excelFlowMaster.List.Select(p => p.Item), new object[] { excelFlowMaster.Code }) .GroupBy(p => p.Item, (k, g) => new { Item = k, FlowDetails = g }) .ToDictionary(d => d.Item, d => d.FlowDetails); var maxSeq = 10; var maxItemSeq = this.genericMgr.FindAllIn<FlowDetail> ("from FlowDetail where Flow = ? ", new object[] { excelFlowMaster.Code }).Select(p => p.Sequence).Max(); if (flowDetailDic.Values != null && flowDetailDic.Values.Count > 0) { maxSeq = flowDetailDic.Values.Max(p => p.Max(q => q.Sequence)); } foreach (var flowItem in excelFlowMaster.List) { //Id Flow Seq Item RefItemCode Uom BaseUom UC UCDesc MinUC StartDate EndDate Bom LocFrom LocTo //BillAddr PriceList Routing ReturnRouting Strategy ProdScan Container ContainerDesc IsAutoCreate //IsInspect IsRejInspect SafeStock MaxStock MinLotSize OrderLotSize RecLotSize BatchSize RoundUpOpt //BillTerm MrpWeight MrpTotal MrpTotalAdj ExtraDmdSource PickStrategy EBELN EBELP CreateUser //CreateUserNm CreateDate LastModifyUser LastModifyUserNm LastModifyDate BinTo IsChangeUC Machine Uom1 //var item = this.genericMgr.FindById<Item>(flowItem.Item); try { //todo check Details var flowDetail = (flowDetailDic.ValueOrDefault(flowItem.Item) ?? new List<FlowDetail>()) .FirstOrDefault(p => p.UnitCount == flowItem.UnitCount); if (flowDetail == null) { var newFlowDetail = new FlowDetail(); newFlowDetail.Flow = flowItem.Flow; newFlowDetail.Item = flowItem.Item; newFlowDetail.BaseUom = flowItem.BaseUom; newFlowDetail.Uom = flowItem.Uom; //newFlowDetail.ReferenceItemCode = flowItem.ReferenceCode; newFlowDetail.UnitCount = flowItem.UnitCount; newFlowDetail.MinUnitCount = flowItem.UnitCount; newFlowDetail.UnitCountDescription = flowItem.UcDesc; newFlowDetail.Sequence = maxSeq+maxItemSeq; newFlowDetail.SafeStock = flowItem.MinStock; newFlowDetail.MaxStock = flowItem.MaxStock; newFlowDetail.MrpWeight = 1; newFlowDetail.RoundUpOption = Sconit.CodeMaster.RoundUpOption.ToUp; maxSeq += 10; this.genericMgr.Create(newFlowDetail); } else { flowDetail.BaseUom = flowItem.BaseUom; flowDetail.Uom = flowItem.Uom; flowDetail.UnitCount = flowItem.UnitCount; flowDetail.MinUnitCount = flowItem.UnitCount; flowDetail.UnitCountDescription = flowItem.UcDesc; flowDetail.SafeStock = flowItem.MinStock; flowDetail.MaxStock = flowItem.MaxStock; this.genericMgr.Update(flowDetail); } } catch (Exception ex) { errorMessage.AddMessage(ex.Message); } } } #endregion } #endregion if (errorMessage.HasMessage) { throw errorMessage; } }
public ActionResult _Edit(FlowMaster flow) { if (ModelState.IsValid) { if (string.IsNullOrEmpty(flow.PartyFrom)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_TransferPartyFrom); } else if (string.IsNullOrEmpty(flow.PartyTo)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_TransferPartyTo); } else if (string.IsNullOrEmpty(flow.LocationFrom)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_LocationFrom); } else if (string.IsNullOrEmpty(flow.LocationTo)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_LocationTo); } else if (string.IsNullOrEmpty(flow.ShipFrom)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ShipFrom); } else if (string.IsNullOrEmpty(flow.ShipTo)) { base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowMaster.FlowMaster_ShipTo); } else { flow.Type = com.Sconit.CodeMaster.OrderType.Transfer; genericMgr.UpdateWithTrim(flow); SaveSuccessMessage(Resources.SCM.FlowMaster.FlowMaster_Updated); } } return PartialView(flow); }
public IList<FlowDetail> GetFlowDetailList(FlowMaster flowMaster) { return GetFlowDetailList(flowMaster, false, true); }