Beispiel #1
0
        public OrderOperation GenerateOrderOperation(OrderHead orderHead, RoutingDetail routingDetail)
        {
            OrderOperation orderOp = new OrderOperation();

            CloneHelper.CopyProperty(routingDetail, orderOp, OrderOperationCloneFields);
            orderOp.OrderHead = orderHead;
            //todo UnitTime和WorkTime计算

            orderHead.AddOrderOperation(orderOp);
            return(orderOp);
        }
Beispiel #2
0
        public void GenerateOrderDetailSubsidiary(OrderDetail orderDetail)
        {
            OrderHead orderHead = orderDetail.OrderHead;
            int       maxOp     = 0; //记录最大工序号,给成品收货时用
            int       minOp     = 0; //记录最小工序号,给返工成品用

            #region 把OrderDetail的收货单位和单位用量转换为BOM单位和单位用量
            //fgUom,fgUnityQty代表接收一个orderDetail.Uom单位(等于订单的收货单位)的FG,等于单位(fgUom)有多少(fgUnityQty)值
            Uom     fgUom      = orderDetail.Uom;
            decimal fgUnityQty = 1;     //运输物品和生产的成品UnitQty默认为1
            //如果和Bom上的单位不一致,转化为Bom上的单位,不然会导致物料回冲不正确。
            if (orderDetail.Bom != null && orderDetail.Uom.Code.ToUpper() != orderDetail.Bom.Uom.Code.ToUpper())
            {
                fgUom      = orderDetail.Bom.Uom;
                fgUnityQty = this.uomConversionMgr.ConvertUomQty(orderDetail.Item, orderDetail.Uom, fgUnityQty, fgUom);
            }
            #endregion

            #region 创建OrderLocTrans

            if (orderDetail.Item.Type == BusinessConstants.CODE_MASTER_ITEM_TYPE_VALUE_K)
            {
                //程序一般不会运行到这里,套件的拆分都在前台进行
                //用户在下订单的时候已经拆分了套件
                //2010-1-19 dingxin
                throw new BusinessErrorException("Order.Error.CreateOrder.ItemTypeK", orderDetail.Item.Code);
            }
            else
            {
                if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT ||
                    orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_CUSTOMERGOODS ||
                    orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_SUBCONCTRACTING)
                {
                    #region 采购,只需要记录入库事务RCT-PO
                    this.orderLocationTransactionMgr.GenerateOrderLocationTransaction(orderDetail, orderDetail.Item, null,
                                                                                      fgUom, maxOp, BusinessConstants.IO_TYPE_OUT, null,
                                                                                      fgUnityQty, orderDetail.DefaultLocationFrom,
                                                                                      false, orderDetail.HuLotSize, true, null, orderDetail.ItemVersion, this.locationMgr.GetRejectLocation());

                    this.orderLocationTransactionMgr.GenerateOrderLocationTransaction(orderDetail, orderDetail.Item, null,
                                                                                      fgUom, maxOp, BusinessConstants.IO_TYPE_IN, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT_PO,
                                                                                      fgUnityQty, orderDetail.DefaultLocationTo,
                                                                                      false, orderDetail.HuLotSize, true, null, orderDetail.ItemVersion, this.locationMgr.GetRejectLocation());
                    #endregion
                }
                else if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION)
                {
                    #region 销售,只需要记录出库事务ISS-SO
                    this.orderLocationTransactionMgr.GenerateOrderLocationTransaction(orderDetail, orderDetail.Item, null,
                                                                                      fgUom, maxOp, BusinessConstants.IO_TYPE_OUT, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_SO,
                                                                                      fgUnityQty, orderDetail.DefaultLocationFrom,
                                                                                      false, orderDetail.HuLotSize, true, null, null, this.locationMgr.GetRejectLocation());

                    this.orderLocationTransactionMgr.GenerateOrderLocationTransaction(orderDetail, orderDetail.Item, null,
                                                                                      fgUom, maxOp, BusinessConstants.IO_TYPE_IN, null,
                                                                                      fgUnityQty, orderDetail.DefaultLocationTo,
                                                                                      false, orderDetail.HuLotSize, true, null, null, this.locationMgr.GetRejectLocation());
                    #endregion
                }
                else if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_TRANSFER)
                {
                    #region 移库,需要记录出库事务ISS-TR和入库事务RCT-TR
                    this.orderLocationTransactionMgr.GenerateOrderLocationTransaction(orderDetail, orderDetail.Item, null,
                                                                                      fgUom, maxOp, BusinessConstants.IO_TYPE_OUT, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_TR,
                                                                                      fgUnityQty, orderDetail.DefaultLocationFrom,
                                                                                      false, orderDetail.HuLotSize, true, null, null, this.locationMgr.GetRejectLocation());

                    this.orderLocationTransactionMgr.GenerateOrderLocationTransaction(orderDetail, orderDetail.Item, null,
                                                                                      fgUom, maxOp, BusinessConstants.IO_TYPE_IN, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT_TR,
                                                                                      fgUnityQty, orderDetail.DefaultLocationTo,
                                                                                      false, orderDetail.HuLotSize, true, null, null, this.locationMgr.GetRejectLocation());
                    #endregion
                }
                //else if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_INSPECTION)
                //{
                //    #region 检验,需要记录出库事务ISS-TR和入库事务RCT-TR
                //    this.orderLocationTransactionMgr.GenerateOrderLocationTransaction(orderDetail, orderDetail.Item, null,
                //                fgUom, maxOp, BusinessConstants.IO_TYPE_OUT, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_TR,
                //                fgUnityQty, orderDetail.DefaultLocationFrom,
                //                false, orderDetail.HuLotSize, true, null, null, this.locationMgr.GetRejectLocation());

                //    this.orderLocationTransactionMgr.GenerateOrderLocationTransaction(orderDetail, orderDetail.Item, null,
                //                fgUom, maxOp, BusinessConstants.IO_TYPE_IN, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT_TR,
                //                fgUnityQty, orderDetail.DefaultLocationTo,
                //                false, orderDetail.HuLotSize, true, null, null, this.locationMgr.GetRejectLocation());
                //    #endregion
                //}
                else if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                {
                    #region 创建生产物料的OrderLocTrans
                    //如果是生产订单,必须要有Bom
                    FillBomForOrderDetail(orderDetail);

                    IList <BomDetail> bomDetailList = this.bomDetailMgr.GetFlatBomDetail(orderDetail.Bom.Code, orderHead.StartTime);
                    foreach (BomDetail bomDetail in bomDetailList)
                    {
                        #region 记录最大工序号
                        //最大工序号是从Bom上取还是从Routing上取?
                        if (maxOp < bomDetail.Operation)
                        {
                            //记录最大工序号
                            maxOp = bomDetail.Operation;
                        }
                        #endregion

                        #region 记录最小工序号
                        //最小工序号是从Bom上取还是从Routing上取?
                        if (minOp > bomDetail.Operation || minOp == 0)
                        {
                            //记录最大工序号
                            minOp = bomDetail.Operation;
                        }
                        #endregion

                        #region 查找物料的来源库位
                        //来源库位查找逻辑BomDetail-->RoutingDetail-->FlowDetail-->Flow
                        Location bomLocFrom = bomDetail.Location;

                        if (orderHead.Routing != null)
                        {
                            //在Routing上查找,并检验Routing上的工序和BOM上的是否匹配
                            RoutingDetail routingDetail = routingDetailMgr.LoadRoutingDetail(orderHead.Routing, bomDetail.Operation, bomDetail.Reference);
                            if (routingDetail != null)
                            {
                                if (bomLocFrom == null)
                                {
                                    bomLocFrom = routingDetail.Location;
                                }

                                //if (maxOp < routingDetail.Operation)
                                //{
                                //    //记录最大工序号
                                //    maxOp = routingDetail.Operation;
                                //}

                                orderHead.AddOrderOperation(this.orderOperationMgr.GenerateOrderOperation(orderHead, routingDetail));
                            }
                            //else
                            //{
                            //    //没有找到和BOM上相匹配的工序
                            //    throw new BusinessErrorException("Order.Error.OpNotMatch", bomDetail.Bom.Code, bomDetail.Item.Code, routing.Code, bomDetail.Operation.ToString(), bomDetail.Reference);
                            //}
                        }

                        if (bomLocFrom == null)
                        {
                            //取默认库位FlowDetail-->Flow
                            bomLocFrom = orderDetail.DefaultLocationFrom;
                        }
                        //string bomLocFromType = bomLocFrom != null ? bomLocFrom.Type : null;
                        #endregion

                        #region 查找物料的目的库位
                        //目的库位,如果是生产类型,直接置为Null,其它情况FlowDetail-->Flow
                        Location bomLocTo = (orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION) ?
                                            orderDetail.DefaultLocationTo : null;
                        //string bomLocToType = bomLocTo != null ? bomLocTo.Type : null;
                        #endregion

                        #region 生产物料,只需要记录出库事务ISS-TR
                        this.orderLocationTransactionMgr.GenerateOrderLocationTransaction(orderDetail, bomDetail.Item, bomDetail,
                                                                                          bomDetail.Uom, bomDetail.Operation, BusinessConstants.IO_TYPE_OUT, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO,
                                                                                          bomDetail.CalculatedQty * fgUnityQty, //返工,原材料数量默认等于0
                                                                                          bomLocFrom, bomDetail.IsShipScanHu, bomDetail.HuLotSize, bomDetail.NeedPrint, bomDetail.BackFlushMethod, null, this.locationMgr.GetRejectLocation());
                        #endregion
                    }
                    #endregion

                    #region 生产成品,只需要记录入库事务RCT-WO
                    this.orderLocationTransactionMgr.GenerateOrderLocationTransaction(orderDetail, orderDetail.Item, null,
                                                                                      fgUom, maxOp, BusinessConstants.IO_TYPE_IN, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT_WO,
                                                                                      fgUnityQty, orderDetail.DefaultLocationTo,
                                                                                      false, orderDetail.HuLotSize, true, null, orderDetail.ItemVersion, this.locationMgr.GetRejectLocation());

                    //返工,把自己添加到物料中
                    if (orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_RWO)
                    {
                        //Location loc = orderDetail.DefaultLocationTo.ActingLocation != null ? orderDetail.DefaultLocationTo.ActingLocation : orderDetail.DefaultLocationTo;
                        Location loc = this.locationMgr.GetRejectLocation();


                        //todo 处理返工的成品是否需要扫描Hu,现在不扫描
                        //返工对成品的投料记RCT-WO事务
                        this.orderLocationTransactionMgr.GenerateOrderLocationTransaction(orderDetail, orderDetail.Item, null,
                                                                                          fgUom, minOp, BusinessConstants.IO_TYPE_OUT, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT_WO,
                                                                                          fgUnityQty, loc,
                                                                                          false, orderDetail.HuLotSize, true, null, null, this.locationMgr.GetRejectLocation());
                    }
                    #endregion
                }
            }
            #endregion

            #region 生产,给没有Op的OrderLocTrans赋值maxOp
            if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
            {
                if (maxOp == 0)
                {
                    EntityPreference entityPreference = this.entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_SEQ_INTERVAL);
                    int seqInterval = int.Parse(entityPreference.Value);
                    maxOp = seqInterval; //默认工序号
                }

                if (orderDetail.OrderLocationTransactions != null && orderDetail.OrderLocationTransactions.Count > 0)
                {
                    foreach (OrderLocationTransaction orderLocationTransaction in orderDetail.OrderLocationTransactions)
                    {
                        if (orderLocationTransaction.Operation == 0)
                        {
                            orderLocationTransaction.Operation = maxOp;
                        }
                    }
                }
            }
            #endregion
        }