Beispiel #1
0
        public void AddHuInProcessLocationDetails(InProcessLocationDetail inProcessLocationDetail)
        {
            if (this.HuInProcessLocationDetails == null)
            {
                this.HuInProcessLocationDetails = new List <InProcessLocationDetail>();
            }

            this.HuInProcessLocationDetails.Add(inProcessLocationDetail);
        }
        public void AddInProcessLocationDetail(InProcessLocationDetail inProcessLocationDetail)
        {
            if (this.InProcessLocationDetails == null)
            {
                this.InProcessLocationDetails = new List<InProcessLocationDetail>();
            }

            this.InProcessLocationDetails.Add(inProcessLocationDetail);
        }
        public void CreateInProcessLocationDetail(InProcessLocation inProcessLocation, OrderLocationTransaction outOrderLocationTransaction, IList<InventoryTransaction> inventoryTransactionList)
        {
            if (inventoryTransactionList != null && inventoryTransactionList.Count > 0)
            {
                InProcessLocationDetail mergedInProcessLocationDetail = null;

                foreach (InventoryTransaction inventoryTransaction in inventoryTransactionList)
                {
                    if (inventoryTransaction.Hu == null && !inventoryTransaction.IsConsignment)
                    {
                        #region �ϲ���������
                        //û��HU && �Ǽ��۲ſ��Ժϲ�
                        if (mergedInProcessLocationDetail == null)
                        {
                            mergedInProcessLocationDetail = new InProcessLocationDetail();
                            mergedInProcessLocationDetail.InProcessLocation = inProcessLocation;
                            mergedInProcessLocationDetail.OrderLocationTransaction = outOrderLocationTransaction;
                        }

                        mergedInProcessLocationDetail.Qty += (0 - inventoryTransaction.Qty) / outOrderLocationTransaction.UnitQty;
                        #endregion
                    }
                    else
                    {
                        InProcessLocationDetail inProcessLocationDetail = new InProcessLocationDetail();
                        inProcessLocationDetail.InProcessLocation = inProcessLocation;
                        inProcessLocationDetail.OrderLocationTransaction = outOrderLocationTransaction;
                        if (inventoryTransaction.Hu != null)
                        {
                            inProcessLocationDetail.HuId = inventoryTransaction.Hu.HuId;
                            inProcessLocationDetail.LotNo = inventoryTransaction.Hu.LotNo;
                        }
                        inProcessLocationDetail.IsConsignment = inventoryTransaction.IsConsignment;
                        inProcessLocationDetail.PlannedBill = inventoryTransaction.PlannedBill;
                        inProcessLocationDetail.Qty = (0 - inventoryTransaction.Qty) / outOrderLocationTransaction.UnitQty;

                        inProcessLocation.AddInProcessLocationDetail(inProcessLocationDetail);

                        this.CreateInProcessLocationDetail(inProcessLocationDetail);
                    }
                }

                if (mergedInProcessLocationDetail != null)
                {
                    inProcessLocation.AddInProcessLocationDetail(mergedInProcessLocationDetail);

                    this.CreateInProcessLocationDetail(mergedInProcessLocationDetail);
                }
            }
        }
        public void CreateInProcessLocationDetail(InProcessLocation inProcessLocation, OrderLocationTransaction outOrderLocationTransaction, IList<InventoryTransaction> inventoryTransactionList)
        {
            if (inventoryTransactionList != null && inventoryTransactionList.Count > 0)
            {
                InProcessLocationDetail mergedInProcessLocationDetail = null;

                foreach (InventoryTransaction inventoryTransaction in inventoryTransactionList)
                {
                    if (inventoryTransaction.Hu == null && !inventoryTransaction.IsConsignment)
                    {
                        #region 合并发货数量
                        //没有HU && 非寄售才可以合并
                        if (mergedInProcessLocationDetail == null)
                        {
                            mergedInProcessLocationDetail = new InProcessLocationDetail();
                            mergedInProcessLocationDetail.InProcessLocation = inProcessLocation;
                            mergedInProcessLocationDetail.OrderLocationTransaction = outOrderLocationTransaction;
                            mergedInProcessLocationDetail.Item = outOrderLocationTransaction.OrderDetail.Item;
                            mergedInProcessLocationDetail.ReferenceItemCode = outOrderLocationTransaction.OrderDetail.ReferenceItemCode;
                            mergedInProcessLocationDetail.CustomerItemCode = outOrderLocationTransaction.OrderDetail.CustomerItemCode;
                            mergedInProcessLocationDetail.Uom = outOrderLocationTransaction.OrderDetail.Uom;
                            mergedInProcessLocationDetail.UnitCount = outOrderLocationTransaction.OrderDetail.UnitCount;
                            mergedInProcessLocationDetail.LocationFrom = outOrderLocationTransaction.OrderDetail.LocationFrom;
                            mergedInProcessLocationDetail.LocationTo = outOrderLocationTransaction.OrderDetail.LocationTo;
                        }

                        mergedInProcessLocationDetail.Qty += (0 - inventoryTransaction.Qty) / outOrderLocationTransaction.UnitQty;
                        #endregion
                    }
                    else
                    {
                        InProcessLocationDetail inProcessLocationDetail = new InProcessLocationDetail();
                        inProcessLocationDetail.InProcessLocation = inProcessLocation;
                        inProcessLocationDetail.OrderLocationTransaction = outOrderLocationTransaction;
                        if (inventoryTransaction.Hu != null)
                        {
                            inProcessLocationDetail.HuId = inventoryTransaction.Hu.HuId;
                            inProcessLocationDetail.LotNo = inventoryTransaction.Hu.LotNo;
                        }
                        inProcessLocationDetail.IsConsignment = inventoryTransaction.IsConsignment;
                        inProcessLocationDetail.PlannedBill = inventoryTransaction.PlannedBill;
                        inProcessLocationDetail.Qty = (0 - inventoryTransaction.Qty) / outOrderLocationTransaction.UnitQty;
                        inProcessLocationDetail.Item = outOrderLocationTransaction.OrderDetail.Item;
                        inProcessLocationDetail.ReferenceItemCode = outOrderLocationTransaction.OrderDetail.ReferenceItemCode;
                        inProcessLocationDetail.CustomerItemCode = outOrderLocationTransaction.OrderDetail.CustomerItemCode;
                        inProcessLocationDetail.Uom = outOrderLocationTransaction.OrderDetail.Uom;
                        inProcessLocationDetail.UnitCount = outOrderLocationTransaction.OrderDetail.UnitCount;
                        inProcessLocationDetail.LocationFrom = outOrderLocationTransaction.OrderDetail.LocationFrom;
                        inProcessLocationDetail.LocationTo = outOrderLocationTransaction.OrderDetail.LocationTo;

                        inProcessLocation.AddInProcessLocationDetail(inProcessLocationDetail);

                        this.CreateInProcessLocationDetail(inProcessLocationDetail);
                    }
                }

                if (mergedInProcessLocationDetail != null)
                {
                    inProcessLocation.AddInProcessLocationDetail(mergedInProcessLocationDetail);

                    this.CreateInProcessLocationDetail(mergedInProcessLocationDetail);
                }
            }
        }
 public void RecordOrderShipQty(int orderLocationTransactionId, InProcessLocationDetail inProcessLocationDetail, bool checkExcceed)
 {
     RecordOrderShipQty(this.orderLocationTransactionMgrE.LoadOrderLocationTransaction(orderLocationTransactionId), inProcessLocationDetail, checkExcceed);
 }
        public void RecordOrderShipQty(OrderLocationTransaction orderLocationTransaction, InProcessLocationDetail inProcessLocationDetail, bool checkExcceed)
        {
            //orderLocationTransaction = this.orderLocationTransactionMgrE.LoadOrderLocationTransaction(orderLocationTransaction.Id);
            EntityPreference entityPreference = this.entityPreferenceMgrE.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_ALLOW_EXCEED_GI_GR);
            bool allowExceedGiGR = bool.Parse(entityPreference.Value); //企业属性,允许过量发货和收货

            OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
            OrderHead orderHead = orderDetail.OrderHead;
            decimal shipQty = inProcessLocationDetail.Qty * orderLocationTransaction.UnitQty;

            #region 是否过量发货判断
            //生产物料发货不检查过量选项
            if (orderLocationTransaction.OrderDetail.OrderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION
                && orderLocationTransaction.OrderDetail.OrderHead.SubType != BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_ADJ)
            {
                //检查AccumulateQty(已发数)不能大于等于OrderedQty(订单数)
                //if (!(orderHead.AllowExceed && allowExceedGiGR))
                //{
                //    if ((orderLocationTransaction.OrderedQty > 0 && orderLocationTransaction.AccumulateQty.HasValue && orderLocationTransaction.AccumulateQty.Value >= orderLocationTransaction.OrderedQty && shipQty > 0)
                //            || (orderLocationTransaction.OrderedQty < 0 && orderLocationTransaction.AccumulateQty.HasValue && orderLocationTransaction.AccumulateQty.Value <= orderLocationTransaction.OrderedQty && shipQty < 0))
                //    {
                //        throw new BusinessErrorException("Order.Error.ShipExcceed", orderHead.OrderNo, orderLocationTransaction.Item.Code);
                //    }
                //}

                if (!(orderHead.AllowExceed && allowExceedGiGR) && checkExcceed)   //不允许过量发货
                {
                    //检查AccumulateQty(已发数) + shipQty(本次发货数)不能大于OrderedQty(订单数)
                    orderLocationTransaction.AccumulateQty = orderLocationTransaction.AccumulateQty.HasValue ? orderLocationTransaction.AccumulateQty.Value : 0;
                    if ((orderLocationTransaction.OrderedQty > 0 && (orderLocationTransaction.AccumulateQty + shipQty > orderLocationTransaction.OrderedQty))
                        || (orderLocationTransaction.OrderedQty < 0 && (orderLocationTransaction.AccumulateQty + shipQty < orderLocationTransaction.OrderedQty)))
                    {
                        throw new BusinessErrorException("Order.Error.ShipExcceed", orderHead.OrderNo, orderLocationTransaction.Item.Code);
                    }
                }
            }
            #endregion

            #region 记录发货量
            if (orderLocationTransaction.BackFlushMethod == null ||
                orderLocationTransaction.BackFlushMethod == BusinessConstants.CODE_MASTER_BACKFLUSH_METHOD_VALUE_GOODS_RECEIVE)
            {
                if (!orderLocationTransaction.AccumulateQty.HasValue)
                {
                    orderLocationTransaction.AccumulateQty = 0;
                }
                //记录LocationTransaction的累计发货量
                orderLocationTransaction.AccumulateQty += shipQty;
                this.orderLocationTransactionMgrE.UpdateOrderLocationTransaction(orderLocationTransaction);

                //记录OrderDetail的累计发货量
                if (orderLocationTransaction.Item.Code == orderLocationTransaction.OrderDetail.Item.Code)
                {
                    //如果OrderLocationTransaction和OrderDetail上的Item一致,需要更新OrderDetail上的ShippedQty
                    if (!orderDetail.ShippedQty.HasValue)
                    {
                        orderDetail.ShippedQty = 0;
                    }

                    //OrderLocationTransaction和OrderDetail上的Item可能单位不一致,直接除以UnitQty就可以转换了
                    orderDetail.ShippedQty += (shipQty / orderLocationTransaction.UnitQty);
                    this.UpdateOrderDetail(orderDetail);
                }
            }
            #endregion
        }
 public string GenerateRMHuId(InProcessLocationDetail inProcessLocationDetail, string lotNo, decimal qty)
 {
     return GenerateRMHuId(inProcessLocationDetail.OrderLocationTransaction.OrderDetail, lotNo, qty);
 }
Beispiel #8
0
        public static bool IsInProcessLocationDetailMatchReceiptDetail(
            InProcessLocationDetail inProcessLocationDetail, ReceiptDetail receiptDetail)
        {
            if (receiptDetail.OrderLocationTransaction.OrderDetail.Id
                        == inProcessLocationDetail.OrderLocationTransaction.OrderDetail.Id)
            {
                if (inProcessLocationDetail.HuId != null && receiptDetail.HuId != null)
                {
                    if (receiptDetail.HuId == inProcessLocationDetail.HuId)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                //if (inProcessLocationDetail.HuId != null)
                //{
                //    //֧��Hu��һ��ҪHuIdƥ��
                //    if (receiptDetail.HuId == inProcessLocationDetail.HuId)
                //    {
                //        return true;
                //    }
                //}
                //else
                //{
                //    //��֧��Hu��ֱ����Ϊ��ͬ
                //    return true;
                //}

                return true;
            }

            return false;
        }
        public void CloseInProcessLocation(InProcessLocation inProcessLocation, User user, bool handleGap)
        {
            InProcessLocation oldInProcessLocation = this.LoadInProcessLocation(inProcessLocation.IpNo, true);

            if (oldInProcessLocation.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE)
            {
                throw new BusinessErrorException("InProcessLocation.Error.StatusErrorWhenClose", oldInProcessLocation.Status, inProcessLocation.IpNo);
            }

            oldInProcessLocation.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE;
            oldInProcessLocation.LastModifyDate = DateTime.Now;
            oldInProcessLocation.LastModifyUser = user;
            oldInProcessLocation.ReferenceOrderNo = inProcessLocation.ReferenceOrderNo;
            oldInProcessLocation.Disposition = inProcessLocation.Disposition;

            this.UpdateInProcessLocation(oldInProcessLocation);

            #region ���Ҳ���
            if (handleGap && oldInProcessLocation.OrderType != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
            {
                IList<InProcessLocationDetail> gapInProcessLocationDetailList = new List<InProcessLocationDetail>();
                foreach (InProcessLocationDetail inProcessLocationDetail in oldInProcessLocation.InProcessLocationDetails)
                {
                    if (!inProcessLocationDetail.ReceivedQty.HasValue || ((inProcessLocationDetail.Qty > 0) && (inProcessLocationDetail.Qty != inProcessLocationDetail.ReceivedQty)))
                    {
                        InProcessLocationDetail gapInProcessLocationDetail = new InProcessLocationDetail();
                        if (inProcessLocationDetail.ReceivedQty.HasValue)
                        {
                            gapInProcessLocationDetail.Qty = inProcessLocationDetail.ReceivedQty.Value - inProcessLocationDetail.Qty;
                        }
                        else
                        {
                            gapInProcessLocationDetail.Qty = 0 - inProcessLocationDetail.Qty;
                        }
                        gapInProcessLocationDetail.OrderLocationTransaction = inProcessLocationDetail.OrderLocationTransaction;
                        gapInProcessLocationDetail.LotNo = inProcessLocationDetail.LotNo;
                        gapInProcessLocationDetail.IsConsignment = inProcessLocationDetail.IsConsignment;
                        gapInProcessLocationDetail.PlannedBill = inProcessLocationDetail.PlannedBill;
                        gapInProcessLocationDetailList.Add(gapInProcessLocationDetail);
                    }
                }
                this.RecordInProcessLocationGap(gapInProcessLocationDetailList, oldInProcessLocation.GoodsReceiptGapTo, user);
            }
            #endregion
        }
Beispiel #10
0
        public IList<InventoryTransaction> InventoryOut(InProcessLocationDetail inProcessLocationDetail, User user)
        {
            OrderLocationTransaction orderLocationTransaction = inProcessLocationDetail.OrderLocationTransaction;
            OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
            OrderHead orderHead = orderDetail.OrderHead;

            if (inProcessLocationDetail.HuId != null && inProcessLocationDetail.HuId.Trim() != string.Empty
                && inProcessLocationDetail.OrderLocationTransaction.OrderDetail.OrderHead.SubType != BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_RTN)
            {
                #region �ж��Ƿ���Ҫ�¼�
                IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetHuLocationLotDetail(orderLocationTransaction.Location.Code, inProcessLocationDetail.HuId.Trim());
                if (locationLotDetailList != null && locationLotDetailList.Count > 0 && locationLotDetailList[0].StorageBin != null)
                {
                    //�¼�
                    this.InventoryPick(locationLotDetailList[0], user);
                }
                #endregion
            }

            #region ���ҳ����λ
            Location outLoc = null;
            if (orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
            {
                outLoc = orderLocationTransaction.Location;
            }
            else
            {
                if (inProcessLocationDetail.HuId != null && inProcessLocationDetail.HuId.Trim() != string.Empty
                    && orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_RWO)
                {
                    //������������������ȡ��λ
                    IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetHuLocationLotDetail(inProcessLocationDetail.HuId);
                    if (locationLotDetailList != null && locationLotDetailList.Count > 0)
                    {
                        LocationLotDetail locationLotDetail = locationLotDetailList[0];
                        outLoc = locationLotDetail.Location;
                    }
                    else
                    {
                        throw new BusinessErrorException("Hu.Error.NoInventory", inProcessLocationDetail.HuId);
                    }
                }
                else
                {
                    outLoc = orderLocationTransaction.Location;
                }
            }
            #endregion

            #region ���¿��
            IList<InventoryTransaction> inventoryTransactionList = RecordInventory(
                orderLocationTransaction.Item,
                outLoc,
                inProcessLocationDetail.HuId,
                inProcessLocationDetail.LotNo,
                (0 - inProcessLocationDetail.Qty * orderLocationTransaction.UnitQty),
                false,
                null,
                orderLocationTransaction.TransactionType,
                orderHead.ReferenceOrderNo,
                //true,
                user,
                false,
                false,//(orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION),
                null
                );
            #endregion

            #region ��������״̬�Ϳ�λ
            //ֻ����ͨ�Ķ����ż�¼���˻��͵������ÿ��ǣ���Ϊ�˻��͵��������ջ����������������ջ��ļ�¼�������˻�������
            if (orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML
                && inProcessLocationDetail.HuId != null && inProcessLocationDetail.HuId.Trim() != string.Empty
                && inProcessLocationDetail.Qty > 0)
            {
                Hu hu = this.huMgr.LoadHu(inProcessLocationDetail.HuId.Trim());
                if (orderDetail.DefaultLocationTo != null)
                {
                    hu.Location = orderDetail.DefaultLocationTo.Code;
                    //�����ѿ����գ���Ȼ�ջ�û���Ļ���ʾ�����Ŀ��
                    hu.StorageBin = null;
                }
                hu.Status = BusinessConstants.CODE_MASTER_HU_STATUS_VALUE_INPROCESS;
                hu.TransferFlag = orderDetail.OrderHead.IsMes;
                hu.IsMes = orderDetail.OrderHead.IsMes;
                this.huMgr.UpdateHu(hu);
            }
            #endregion

            #region ��¼�������
            foreach (InventoryTransaction inventoryTransaction in inventoryTransactionList)
            {
                this.locationTransactionMgr.RecordLocationTransaction(orderLocationTransaction, inventoryTransaction, inProcessLocationDetail.InProcessLocation, user);

                #region �˻����ϼ�
                if (inProcessLocationDetail.OrderLocationTransaction.OrderDetail.OrderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_RTN
                    && inProcessLocationDetail.ReturnPutAwaySorageBinCode != null && inProcessLocationDetail.ReturnPutAwaySorageBinCode.Trim() != string.Empty)
                {
                    LocationLotDetail locationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(inventoryTransaction.LocationLotDetailId);
                    locationLotDetail.NewStorageBin = this.storageBinMgr.LoadStorageBin(inProcessLocationDetail.ReturnPutAwaySorageBinCode);
                    inventoryTransaction.StorageBin = locationLotDetail.NewStorageBin;

                    InventoryPut(locationLotDetail, user);
                }
                #endregion
            }
            #endregion

            return inventoryTransactionList;
        }
        public IList<InProcessLocationDetail> SummarizeInProcessLocationDetails(IList<InProcessLocationDetail> inProcessLocationDetailList)
        {
            IList<InProcessLocationDetail> ipDetList = new List<InProcessLocationDetail>();
            if (inProcessLocationDetailList != null && inProcessLocationDetailList.Count > 0)
            {
                foreach (InProcessLocationDetail ipDetail in inProcessLocationDetailList)
                {
                    if (ipDetail.HuId == null)
                    {
                        //��֧��Hu,����Ҫ����
                        return inProcessLocationDetailList;
                    }

                    bool isExist = false;
                    foreach (InProcessLocationDetail ipDet in ipDetList)
                    {
                        //OrderLocationTransaction��ͬ�Ļ���
                        if (ipDetail.OrderLocationTransaction.Id == ipDet.OrderLocationTransaction.Id)
                        {
                            ipDet.Qty += ipDetail.Qty;
                            ipDet.AddHuInProcessLocationDetails(ipDetail);
                            isExist = true;
                            break;
                        }
                    }
                    if (!isExist)
                    {
                        InProcessLocationDetail inProcessLocationDetail = new InProcessLocationDetail();
                        CloneHelper.CopyProperty(ipDetail, inProcessLocationDetail, new string[] { "Id", "HuId" }, true);
                        inProcessLocationDetail.AddHuInProcessLocationDetails(ipDetail);
                        ipDetList.Add(inProcessLocationDetail);
                    }
                }
            }

            return ipDetList;
        }
        public void CreateInProcessLocationDetail(InProcessLocation inProcessLocation, OrderLocationTransaction outOrderLocationTransaction, IList<Hu> huList)
        {
            if (huList != null && huList.Count > 0)
            {
                foreach (Hu hu in huList)
                {
                    InProcessLocationDetail inProcessLocationDetail = new InProcessLocationDetail();
                    inProcessLocationDetail.InProcessLocation = inProcessLocation;
                    inProcessLocationDetail.OrderLocationTransaction = outOrderLocationTransaction;
                    inProcessLocationDetail.HuId = hu.HuId;
                    inProcessLocationDetail.LotNo = hu.LotNo;
                    inProcessLocationDetail.Qty = hu.Qty * hu.UnitQty / outOrderLocationTransaction.UnitQty;  //�ȳ�Hu.UnitQtyתΪ������λ���ڳ�outOrderLocationTransaction.UnitQtyתΪ������λ��

                    inProcessLocation.AddInProcessLocationDetail(inProcessLocationDetail);

                    this.CreateInProcessLocationDetail(inProcessLocationDetail);
                }
            }
        }
        public void StartOrder(string orderNo, User user)
        {
            OrderHead orderHead = this.orderHeadMgrE.CheckAndLoadOrderHead(orderNo);
            Flow flow = this.flowMgrE.LoadFlow(orderHead.Flow);

            //权限校验
            //if (!OrderHelper.CheckOrderOperationAuthrize(orderHead, user, BusinessConstants.ORDER_OPERATION_START_ORDER))
            //{
            //    throw new BusinessErrorException("Order.Error.NoStartPermission", orderHead.OrderNo);
            //}

            if (orderHead.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT)
            {
                #region 检查生产单最大上线数量
                if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION
                    && orderHead.Flow != null && flow.MaxOnlineQty > 0
                    && this.GetInPorcessWOCount(orderHead.Flow, user) >= flow.MaxOnlineQty)
                {
                    throw new BusinessErrorException("Order.Error.ExcceedMaxOnlineQty");
                }
                #endregion

                DateTime nowDate = DateTime.Now;
                orderHead.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS;
                orderHead.StartDate = nowDate;
                orderHead.StartUser = user;
                orderHead.LastModifyDate = nowDate;
                orderHead.LastModifyUser = user;

                this.orderHeadMgrE.UpdateOrderHead(orderHead);

                #region 判断自动PickList、Ship
                if (orderHead.IsAutoShip && orderHead.IsAutoReceive
                    && orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                {
                    if (orderHead.CompleteLatency.HasValue && orderHead.CompleteLatency.Value > 0)
                    {
                        //todo 收货延迟,记录到Quratz表中
                        throw new NotImplementedException("Complete Latency Not Implemented");
                    }
                    else
                    {
                        //立即收货
                        Receipt receipt = new Receipt();
                        foreach (OrderDetail orderDetail in orderHead.OrderDetails)
                        {
                            ReceiptDetail receiptDetail = new ReceiptDetail();
                            receiptDetail.OrderLocationTransaction = this.orderLocationTransactionMgrE.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_IN)[0];
                            receiptDetail.HuId = orderDetail.HuId;
                            receiptDetail.ReceivedQty = orderDetail.OrderedQty;
                            receiptDetail.Receipt = receipt;

                            #region 生产自动收货,找Out的OrderLocTrans,填充MaterialFulshBack
                            if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                            {
                                IList<OrderLocationTransaction> orderLocTransList = this.orderLocationTransactionMgrE.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_OUT);
                                foreach (OrderLocationTransaction orderLocTrans in orderLocTransList)
                                {
                                    MaterialFlushBack material = new MaterialFlushBack();
                                    material.OrderLocationTransaction = orderLocTrans;
                                    if (orderLocTrans.UnitQty != 0)
                                    {
                                        material.Qty = orderLocTrans.OrderedQty / orderLocTrans.UnitQty;
                                    }
                                    receiptDetail.AddMaterialFlushBack(material);
                                }
                            }
                            #endregion
                            receipt.AddReceiptDetail(receiptDetail);
                        }

                        ReceiveOrder(receipt, user);
                    }
                }
                else if (orderHead.IsAutoShip)
                {
                    if (orderHead.StartLatency.HasValue && orderHead.StartLatency.Value > 0)
                    {
                        //todo 上线延迟,记录到Quratz表中
                        throw new NotImplementedException("Start Latency Not Implemented");
                    }
                    else
                    {
                        //立即上线
                        IList<InProcessLocationDetail> inProcessLocationDetailList = new List<InProcessLocationDetail>();
                        foreach (OrderDetail orderDetail in orderHead.OrderDetails)
                        {
                            InProcessLocationDetail inProcessLocationDetail = new InProcessLocationDetail();
                            inProcessLocationDetail.OrderLocationTransaction = this.orderLocationTransactionMgrE.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_OUT)[0];
                            inProcessLocationDetail.Qty = orderDetail.OrderedQty;

                            inProcessLocationDetailList.Add(inProcessLocationDetail);
                        }

                        ShipOrder(inProcessLocationDetailList, user);
                    }
                }
                else if (orderHead.IsAutoCreatePickList
                    && orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML)  //过滤掉退货和调整
                {
                    IList<OrderLocationTransaction> orderLocationTransactionList = new List<OrderLocationTransaction>();
                    foreach (OrderDetail orderDetail in orderHead.OrderDetails)
                    {
                        IList<OrderLocationTransaction> outOrderLocationTransactionList = this.orderLocationTransactionMgrE.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_OUT);
                        foreach (OrderLocationTransaction orderLocationTransaction in outOrderLocationTransactionList)
                        {
                            orderLocationTransaction.CurrentShipQty = orderLocationTransaction.OrderedQty;
                        }
                        IListHelper.AddRange<OrderLocationTransaction>(orderLocationTransactionList, outOrderLocationTransactionList);
                    }

                    this.pickListMgrE.CreatePickList(orderLocationTransactionList, user);
                }
                #endregion
            }
            else
            {
                throw new BusinessErrorException("Order.Error.StatusErrorWhenStart", orderHead.Status, orderNo);
            }
        }
        public InProcessLocation ShipOrder(IList<OrderDetail> orderDetailList, User user)
        {
            InProcessLocation inProcessLocation = new InProcessLocation();
            foreach (OrderDetail orderDetail in orderDetailList)
            {
                InProcessLocationDetail inProcessLocationDetail = new InProcessLocationDetail();
                inProcessLocationDetail.OrderLocationTransaction = this.orderLocationTransactionMgrE.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_OUT)[0];
                inProcessLocationDetail.Qty = orderDetail.CurrentShipQty;
                inProcessLocationDetail.InProcessLocation = inProcessLocation;

                inProcessLocation.AddInProcessLocationDetail(inProcessLocationDetail);
            }

            return ShipOrder(inProcessLocation, user);
        }
        public IList<InventoryTransaction> InventoryOut(InProcessLocationDetail inProcessLocationDetail, User user)
        {
            OrderLocationTransaction orderLocationTransaction = inProcessLocationDetail.OrderLocationTransaction;
            OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
            OrderHead orderHead = orderDetail.OrderHead;
          
            if (inProcessLocationDetail.HuId != null && inProcessLocationDetail.HuId.Trim() != string.Empty
                && inProcessLocationDetail.OrderLocationTransaction.OrderDetail.OrderHead.SubType != BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_RTN)
            {
                #region 判断是否需要下架
                IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetHuLocationLotDetail(orderLocationTransaction.Location.Code, inProcessLocationDetail.HuId.Trim());
                if (locationLotDetailList != null && locationLotDetailList.Count > 0 && locationLotDetailList[0].StorageBin != null)
                {
                    //下架
                    this.InventoryPick(locationLotDetailList[0], user);
                }
                #endregion
            }

            #region 查找出库库位
            Location outLoc = null;
            if (orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
            {
                outLoc = orderLocationTransaction.Location;
            }
            else
            {
                if (inProcessLocationDetail.HuId != null && inProcessLocationDetail.HuId.Trim() != string.Empty
                    && orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_RWO)
                {
                    //生产返工,从条码上取库位
                    IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetHuLocationLotDetail(inProcessLocationDetail.HuId);
                    if (locationLotDetailList != null && locationLotDetailList.Count > 0)
                    {
                        LocationLotDetail locationLotDetail = locationLotDetailList[0];
                        outLoc = locationLotDetail.Location;
                    }
                    else
                    {
                        throw new BusinessErrorException("Hu.Error.NoInventory", inProcessLocationDetail.HuId);
                    }
                }
                else
                {
                    outLoc = orderLocationTransaction.Location;
                }
            }
            #endregion

            #region 更新库存
            IList<InventoryTransaction> inventoryTransactionList = RecordInventory(
                orderLocationTransaction.Item,
                outLoc,
                inProcessLocationDetail.HuId,
                inProcessLocationDetail.LotNo,
                (0 - inProcessLocationDetail.Qty * orderLocationTransaction.UnitQty),
                false,
                null,
                orderLocationTransaction.TransactionType,
                orderHead.ReferenceOrderNo,
                //true,
                user,
                false,
                (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                );
            #endregion

            #region 更新条码状态和库位
            //只有普通的订单才记录,退货和调整不用考虑,因为退货和调整先做收货在做发货,会冲掉收货的记录,发货退货不考虑
            if (orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML
                && inProcessLocationDetail.HuId != null && inProcessLocationDetail.HuId.Trim() != string.Empty
                && inProcessLocationDetail.Qty > 0)
            {
                Hu hu = this.huMgrE.LoadHu(inProcessLocationDetail.HuId.Trim());
                if (orderDetail.DefaultLocationTo != null)
                {
                    hu.Location = orderDetail.DefaultLocationTo.Code;
                }
                hu.Status = BusinessConstants.CODE_MASTER_HU_STATUS_VALUE_INPROCESS;
                this.huMgrE.UpdateHu(hu);
            }
            #endregion

            #region 记录库存事务
            foreach (InventoryTransaction inventoryTransaction in inventoryTransactionList)
            {
                this.locationTransactionMgrE.RecordLocationTransaction(orderLocationTransaction, inventoryTransaction, inProcessLocationDetail.InProcessLocation, user);

                #region 退货并上架
                if (inProcessLocationDetail.OrderLocationTransaction.OrderDetail.OrderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_RTN
                    && inProcessLocationDetail.ReturnPutAwaySorageBinCode != null && inProcessLocationDetail.ReturnPutAwaySorageBinCode.Trim() != string.Empty)
                {
                    LocationLotDetail locationLotDetail = this.locationLotDetailMgrE.LoadLocationLotDetail(inventoryTransaction.LocationLotDetailId);
                    locationLotDetail.NewStorageBin = this.storageBinMgrE.LoadStorageBin(inProcessLocationDetail.ReturnPutAwaySorageBinCode);
                    inventoryTransaction.StorageBin = locationLotDetail.NewStorageBin;

                    InventoryPut(locationLotDetail, user);
                }
                #endregion
            }
            #endregion

            return inventoryTransactionList;
        }
 public virtual void CreateInProcessLocationDetail(InProcessLocationDetail entity)
 {
     Create(entity);
 }
        public void TryCloseInProcessLocation(InProcessLocation inProcessLocation, User user)
        {
            InProcessLocation oldInProcessLocation = this.LoadInProcessLocation(inProcessLocation.IpNo, true);

            #region ���Ҳ���
            IList<InProcessLocationDetail> gapInProcessLocationDetailList = new List<InProcessLocationDetail>();
            bool allClose = true;
            if (oldInProcessLocation.InProcessLocationDetails != null && oldInProcessLocation.InProcessLocationDetails.Count > 0)
            {
                foreach (InProcessLocationDetail inProcessLocationDetail in oldInProcessLocation.InProcessLocationDetails)
                {
                    if (!inProcessLocationDetail.ReceivedQty.HasValue || Math.Abs(inProcessLocationDetail.Qty) > Math.Abs(inProcessLocationDetail.ReceivedQty.Value))
                    {
                        //�������IpDetail
                        allClose = false;
                        break;
                    }
                    else if (inProcessLocationDetail.ReceivedQty.HasValue && Math.Abs(inProcessLocationDetail.Qty) < Math.Abs(inProcessLocationDetail.ReceivedQty.Value))
                    {
                        //���գ���¼����
                        InProcessLocationDetail gapInProcessLocationDetail = new InProcessLocationDetail();

                        gapInProcessLocationDetail.Qty = inProcessLocationDetail.ReceivedQty.Value - inProcessLocationDetail.Qty;
                        gapInProcessLocationDetail.OrderLocationTransaction = inProcessLocationDetail.OrderLocationTransaction;
                        gapInProcessLocationDetail.LotNo = inProcessLocationDetail.LotNo;
                        gapInProcessLocationDetail.IsConsignment = inProcessLocationDetail.IsConsignment;
                        gapInProcessLocationDetail.PlannedBill = inProcessLocationDetail.PlannedBill;
                        gapInProcessLocationDetailList.Add(gapInProcessLocationDetail);
                    }
                }
            }

            if (allClose)
            {
                oldInProcessLocation.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE;
                oldInProcessLocation.LastModifyDate = DateTime.Now;
                oldInProcessLocation.LastModifyUser = user;
                oldInProcessLocation.ReferenceOrderNo = inProcessLocation.ReferenceOrderNo;
                oldInProcessLocation.Disposition = inProcessLocation.Disposition;

                this.UpdateInProcessLocation(oldInProcessLocation);
                this.RecordInProcessLocationGap(gapInProcessLocationDetailList, oldInProcessLocation.GoodsReceiptGapTo, user);
            }
            else
            {
                oldInProcessLocation.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS;
                oldInProcessLocation.LastModifyDate = DateTime.Now;
                oldInProcessLocation.LastModifyUser = user;
                oldInProcessLocation.ReferenceOrderNo = inProcessLocation.ReferenceOrderNo;
                oldInProcessLocation.Disposition = inProcessLocation.Disposition;

                this.UpdateInProcessLocation(oldInProcessLocation);
            }
            #endregion
        }
        public static bool IsInProcessLocationDetailMatchReceiptDetail(
            InProcessLocationDetail inProcessLocationDetail, ReceiptDetail receiptDetail)
        {
            if (receiptDetail.OrderLocationTransaction.OrderDetail.Id
                        == inProcessLocationDetail.OrderLocationTransaction.OrderDetail.Id)
            {
                if (inProcessLocationDetail.HuId != null && receiptDetail.HuId != null)
                {
                    if (receiptDetail.HuId == inProcessLocationDetail.HuId)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                //if (inProcessLocationDetail.HuId != null)
                //{
                //    //支持Hu,一定要HuId匹配
                //    if (receiptDetail.HuId == inProcessLocationDetail.HuId)
                //    {
                //        return true;
                //    }
                //}
                //else
                //{
                //    //不支持Hu,直接认为相同
                //    return true;
                //}

                return true;
            }

            return false;
        }
 public virtual void DeleteInProcessLocationDetail(InProcessLocationDetail entity)
 {
     entityDao.DeleteInProcessLocationDetail(entity);
 }
        public InProcessLocation ShipOrder(string pickListNo, User user)
        {
            PickList pickList = this.pickListMgrE.CheckAndLoadPickList(pickListNo);

            //订单关闭后,拣货单也应该能够发货
            if (pickList.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS
                && pickList.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_COMPLETE
                && pickList.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE)
            {
                throw new BusinessErrorException("Order.Error.PickUp.StatusErrorWhenShip", pickList.Status, pickList.PickListNo);
            }

            PickListHelper.CheckAuthrize(pickList, user);

            InProcessLocation inProcessLocation = new InProcessLocation();

            foreach (PickListDetail pickListDetail in pickList.PickListDetails)
            {
                OrderLocationTransaction orderLocationTransaction = pickListDetail.OrderLocationTransaction;

                foreach (PickListResult pickListResult in pickListDetail.PickListResults)
                {
                    InProcessLocationDetail inProcessLocationDetail = new InProcessLocationDetail();
                    inProcessLocationDetail.HuId = pickListResult.LocationLotDetail.Hu.HuId;
                    inProcessLocationDetail.LotNo = pickListResult.LocationLotDetail.LotNo;
                    inProcessLocationDetail.OrderLocationTransaction = orderLocationTransaction;
                    inProcessLocationDetail.Qty = pickListResult.Qty / orderLocationTransaction.UnitQty; //订单单位
                    inProcessLocationDetail.InProcessLocation = inProcessLocation;

                    inProcessLocation.AddInProcessLocationDetail(inProcessLocationDetail);
                }
            }

            inProcessLocation = ShipOrder(inProcessLocation, user, false);

            #region 关闭捡货单
            pickList.LastModifyDate = DateTime.Now;
            pickList.LastModifyUser = user;
            pickList.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE;

            this.pickListMgrE.UpdatePickList(pickList);
            #endregion

            return inProcessLocation;
        }
        public void RawMaterialBackflush(string prodLineCode, IDictionary<string, decimal> itemQtydic, User user)
        {
            Flow flow = this.flowMgrE.CheckAndLoadFlow(prodLineCode);
            DateTime dateTimeNow = DateTime.Now;

            IList<ProductLineInProcessLocationDetail> productLineInProcessLocationDetailList =
                this.GetProductLineInProcessLocationDetail(prodLineCode, BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE);

            IList<ProductLineInProcessLocationDetail> targetProductLineInProcessLocationDetailList = new List<ProductLineInProcessLocationDetail>();

            #region 根据剩余数量计算回冲零件数量,添加到待处理列表
            if (itemQtydic != null && itemQtydic.Count > 0)
            {
                foreach (string itemCode in itemQtydic.Keys)
                {
                    decimal remainQty = itemQtydic[itemCode];   //剩余投料量
                    decimal inQty = 0;                     //总投料量
                    IList<ProductLineInProcessLocationDetail> currentProductLineInProcessLocationDetailList = new List<ProductLineInProcessLocationDetail>();
                    foreach (ProductLineInProcessLocationDetail productLineInProcessLocationDetail in productLineInProcessLocationDetailList)
                    {
                        if (productLineInProcessLocationDetail.Item.Code == itemCode)
                        {
                            inQty += (productLineInProcessLocationDetail.Qty - productLineInProcessLocationDetail.BackflushQty);
                            currentProductLineInProcessLocationDetailList.Add(productLineInProcessLocationDetail);
                        }
                    }

                    if (remainQty > inQty)
                    {
                        throw new BusinessErrorException("MasterData.Production.Feed.Error.RemainQtyGtFeedQty", itemCode);
                    }

                    decimal backflushQty = inQty - remainQty;  //本次回冲量

                    #region 设定本次回冲数量
                    if (backflushQty > 0)
                    {
                        foreach (ProductLineInProcessLocationDetail productLineInProcessLocationDetail in currentProductLineInProcessLocationDetailList)
                        {
                            if (backflushQty - (productLineInProcessLocationDetail.Qty - productLineInProcessLocationDetail.BackflushQty) > 0)
                            {
                                productLineInProcessLocationDetail.CurrentBackflushQty = productLineInProcessLocationDetail.Qty - productLineInProcessLocationDetail.BackflushQty;
                                productLineInProcessLocationDetail.BackflushQty = productLineInProcessLocationDetail.Qty;
                                backflushQty -= productLineInProcessLocationDetail.Qty - productLineInProcessLocationDetail.BackflushQty;
                                targetProductLineInProcessLocationDetailList.Add(productLineInProcessLocationDetail);
                            }
                            else
                            {
                                productLineInProcessLocationDetail.CurrentBackflushQty = backflushQty;
                                productLineInProcessLocationDetail.BackflushQty += backflushQty;
                                backflushQty = 0;
                                targetProductLineInProcessLocationDetailList.Add(productLineInProcessLocationDetail);
                                break;
                            }
                        }
                    }
                    #endregion
                }
            }
            #endregion

            //为了多次回冲,注掉此处代码
            //#region 处理未填写剩余数量的投料,全部添加到待处理列表
            //foreach (ProductLineInProcessLocationDetail productLineInProcessLocationDetail in productLineInProcessLocationDetailList)
            //{
            //    bool isUsed = false;
            //    foreach (string itemCode in itemQtydic.Keys)
            //    {
            //        if (productLineInProcessLocationDetail.Item.Code == itemCode)
            //        {
            //            isUsed = true;
            //            break;
            //        }
            //    }

            //    //未填写剩余数量的全部回冲
            //    if (!isUsed)
            //    {
            //        productLineInProcessLocationDetail.CurrentBackflushQty = productLineInProcessLocationDetail.Qty - productLineInProcessLocationDetail.BackflushQty;
            //        productLineInProcessLocationDetail.BackflushQty = productLineInProcessLocationDetail.Qty;
            //        targetProductLineInProcessLocationDetailList.Add(productLineInProcessLocationDetail);
            //    }
            //}
            //#endregion

            if (targetProductLineInProcessLocationDetailList != null && targetProductLineInProcessLocationDetailList.Count > 0)
            {
                IList<OrderPlannedBackflush> orderPlannedBackflushList = this.orderPlannedBackflushMgrE.GetActiveOrderPlannedBackflush(prodLineCode);
                IDictionary<int, OrderPlannedBackflush> backFlushedorderPlannedDic = new Dictionary<int, OrderPlannedBackflush>();

                if (orderPlannedBackflushList == null || orderPlannedBackflushList.Count == 0)
                {
                    throw new BusinessErrorException("MasterData.Production.Feed.Error.NoWO", prodLineCode);
                }

                #region 物料回冲
                foreach (ProductLineInProcessLocationDetail productLineInProcessLocationDetail in targetProductLineInProcessLocationDetailList)
                {
                    #region 查找匹配的待回冲OrderLocationTransaction
                    IList<OrderPlannedBackflush> matchedOrderPlannedBackflushList = new List<OrderPlannedBackflush>();
                    decimal totalBaseQty = 0; //回冲分配基数
                    if (orderPlannedBackflushList != null && orderPlannedBackflushList.Count > 0)
                    {
                        foreach (OrderPlannedBackflush orderPlannedBackflush in orderPlannedBackflushList)
                        {
                            OrderLocationTransaction orderLocationTransaction = orderPlannedBackflush.OrderLocationTransaction;
                            if (productLineInProcessLocationDetail.Item.Code == orderLocationTransaction.Item.Code
                                && ((productLineInProcessLocationDetail.Operation.HasValue && productLineInProcessLocationDetail.Operation.Value == orderLocationTransaction.Operation)
                                || !productLineInProcessLocationDetail.Operation.HasValue))
                            {
                                matchedOrderPlannedBackflushList.Add(orderPlannedBackflush);
                                totalBaseQty += orderPlannedBackflush.PlannedQty;

                                if (!backFlushedorderPlannedDic.ContainsKey(orderPlannedBackflush.Id))
                                {
                                    backFlushedorderPlannedDic.Add(orderPlannedBackflush.Id, orderPlannedBackflush);
                                }
                            }
                        }
                    }
                    #endregion

                    #region 更新生产线上的物料
                    if (productLineInProcessLocationDetail.Qty == productLineInProcessLocationDetail.BackflushQty)
                    {
                        productLineInProcessLocationDetail.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE;
                    }
                    productLineInProcessLocationDetail.LastModifyDate = dateTimeNow;
                    productLineInProcessLocationDetail.LastModifyUser = user;

                    this.UpdateProductLineInProcessLocationDetail(productLineInProcessLocationDetail);

                    //记录库存事务
                    //this.locationTransactionMgrE.RecordLocationTransaction(productLineInProcessLocationDetail, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_TR, user, BusinessConstants.IO_TYPE_OUT);
                    //this.locationTransactionMgrE.RecordLocationTransaction(productLineInProcessLocationDetail, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT_TR, user, BusinessConstants.IO_TYPE_OUT);
                    #endregion

                    if (matchedOrderPlannedBackflushList.Count > 0)
                    {
                        #region 物料回冲
                        EntityPreference entityPreference = this.entityPreferenceMgrE.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_AMOUNT_DECIMAL_LENGTH);
                        int amountDecimalLength = int.Parse(entityPreference.Value);

                        decimal remainTobeBackflushQty = productLineInProcessLocationDetail.CurrentBackflushQty;  //剩余待回冲数量
                        decimal unitQty = Math.Round(remainTobeBackflushQty / totalBaseQty, amountDecimalLength);  //单位基数的回冲数量

                        for (int i = 0; i < matchedOrderPlannedBackflushList.Count; i++)
                        {
                            #region 更新匹配的OrderLocationTransaction
                            OrderPlannedBackflush matchedOrderPlannedBackflush = matchedOrderPlannedBackflushList[i];
                            OrderLocationTransaction matchedOrderLocationTransaction = matchedOrderPlannedBackflush.OrderLocationTransaction;

                            bool isLastestRecord = (i == (matchedOrderPlannedBackflushList.Count - 1));
                            decimal currentTotalBackflushQty = 0;

                            if (!matchedOrderLocationTransaction.AccumulateQty.HasValue)
                            {
                                matchedOrderLocationTransaction.AccumulateQty = 0;
                            }

                            if (!isLastestRecord)
                            {
                                decimal currentBackflushQty = matchedOrderPlannedBackflush.PlannedQty * unitQty;
                                currentTotalBackflushQty += currentBackflushQty;
                                matchedOrderLocationTransaction.AccumulateQty += currentBackflushQty;
                                remainTobeBackflushQty -= currentBackflushQty;
                            }
                            else
                            {
                                currentTotalBackflushQty += remainTobeBackflushQty;
                                matchedOrderLocationTransaction.AccumulateQty += remainTobeBackflushQty;
                                remainTobeBackflushQty = 0;
                            }

                            this.orderLocationTransactionMgrE.UpdateOrderLocationTransaction(matchedOrderLocationTransaction);
                            #endregion

                            #region 新增/更新AsnDetail
                            InProcessLocationDetail inProcessLocationDetail = null;
                            if (productLineInProcessLocationDetail.HuId == null || productLineInProcessLocationDetail.HuId.Trim() == string.Empty)
                            {
                                inProcessLocationDetail = this.inProcessLocationDetailMgrE.GetNoneHuAndIsConsignmentInProcessLocationDetail(matchedOrderPlannedBackflush.InProcessLocation, matchedOrderPlannedBackflush.OrderLocationTransaction);
                                if (inProcessLocationDetail != null)
                                {
                                    inProcessLocationDetail.Qty += currentTotalBackflushQty;

                                    this.inProcessLocationDetailMgrE.UpdateInProcessLocationDetail(inProcessLocationDetail);
                                }
                            }

                            if (inProcessLocationDetail == null)
                            {
                                inProcessLocationDetail = new InProcessLocationDetail();
                                inProcessLocationDetail.InProcessLocation = matchedOrderPlannedBackflush.InProcessLocation;
                                inProcessLocationDetail.OrderLocationTransaction = matchedOrderPlannedBackflush.OrderLocationTransaction;
                                inProcessLocationDetail.HuId = productLineInProcessLocationDetail.HuId;
                                inProcessLocationDetail.LotNo = productLineInProcessLocationDetail.LotNo;
                                inProcessLocationDetail.IsConsignment = productLineInProcessLocationDetail.IsConsignment;
                                inProcessLocationDetail.PlannedBill = productLineInProcessLocationDetail.PlannedBill;
                                inProcessLocationDetail.Qty = currentTotalBackflushQty;

                                this.inProcessLocationDetailMgrE.CreateInProcessLocationDetail(inProcessLocationDetail);

                                matchedOrderPlannedBackflush.InProcessLocation.AddInProcessLocationDetail(inProcessLocationDetail);
                            }
                            #endregion

                            #region 新增库存事务
                            this.locationTransactionMgrE.RecordWOBackflushLocationTransaction(
                                matchedOrderPlannedBackflush.OrderLocationTransaction, productLineInProcessLocationDetail.HuId,
                                productLineInProcessLocationDetail.LotNo, currentTotalBackflushQty,
                                matchedOrderPlannedBackflush.InProcessLocation.IpNo, user, productLineInProcessLocationDetail.LocationFrom);
                            #endregion
                        }
                        #endregion
                    }
                    else
                    {
                        #region 没有匹配的OrderLocationTransaction
                        //退回原库位
                        this.locationMgrE.InventoryIn(productLineInProcessLocationDetail, user);
                        #endregion
                    }
                }
                #endregion

                #region 关闭OrderPlannedBackflush
                foreach (OrderPlannedBackflush orderPlannedBackflush in backFlushedorderPlannedDic.Values)
                {
                    orderPlannedBackflush.IsActive = false;
                    this.orderPlannedBackflushMgrE.UpdateOrderPlannedBackflush(orderPlannedBackflush);
                }
                #endregion
            }
            else
            {
                throw new BusinessErrorException("MasterData.Production.Feed.Error.NoFeed", prodLineCode);
            }
        }
        public Receipt ReceiveOrder(Receipt receipt, User user, IList<WorkingHours> workingHoursList, bool createIp, bool isOddCreateHu)
        {
            #region 变量定义
            IDictionary<string, OrderHead> cachedOrderHead = new Dictionary<string, OrderHead>();  //缓存用到的OrderHead
            DateTime dateTimeNow = DateTime.Now;
            #endregion

            #region 判断全0收货
            if (receipt != null && receipt.ReceiptDetails != null && receipt.ReceiptDetails.Count > 0)
            {
                //判断全0收货
                IList<ReceiptDetail> nonZeroReceiptDetailList = new List<ReceiptDetail>();
                foreach (ReceiptDetail receiptDetail in receipt.ReceiptDetails)
                {
                    if (!receiptDetail.ReceivedQty.HasValue)
                    {
                        receiptDetail.ReceivedQty = 0;
                    }

                    if (!receiptDetail.RejectedQty.HasValue)
                    {
                        receiptDetail.RejectedQty = 0;
                    }


                    if (!receiptDetail.ScrapQty.HasValue)
                    {
                        receiptDetail.ScrapQty = 0;
                    }


                    if (receiptDetail.ReceivedQty.Value != 0
                        || receiptDetail.RejectedQty.Value != 0
                        || receiptDetail.ScrapQty.Value != 0)
                    {
                        nonZeroReceiptDetailList.Add(receiptDetail);
                    }
                }

                if (nonZeroReceiptDetailList.Count == 0)
                {
                    throw new BusinessErrorException("OrderDetail.Error.OrderDetailReceiveEmpty");
                }

                receipt.ReceiptDetails = nonZeroReceiptDetailList;
            }
            else
            {
                throw new BusinessErrorException("OrderDetail.Error.OrderDetailReceiveEmpty");
            }
            #endregion

            #region 为未发货就收货创建ASN
            if ((receipt.InProcessLocations == null || receipt.InProcessLocations.Count == 0)
                && createIp)
            {
                InProcessLocation inProcessLocation = new InProcessLocation();

                #region 循环收货列表,并添加到发货列表中
                foreach (ReceiptDetail receiptDetail in receipt.ReceiptDetails)
                {
                    OrderLocationTransaction orderLocationTransaction = receiptDetail.OrderLocationTransaction;
                    OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
                    OrderHead orderHead = orderDetail.OrderHead;

                    if (receiptDetail.MaterialFlushBack != null && receiptDetail.MaterialFlushBack.Count > 0)
                    {
                        #region 根据物料回冲创建ASN,只适应生产,其它情况没有测试
                        foreach (MaterialFlushBack materialFlushBack in receiptDetail.MaterialFlushBack)
                        {
                            InProcessLocationDetail inProcessLocationDetail = new InProcessLocationDetail();
                            inProcessLocationDetail.OrderLocationTransaction = this.orderLocationTransactionMgrE.LoadOrderLocationTransaction(materialFlushBack.OrderLocationTransaction.Id);
                            inProcessLocationDetail.HuId = materialFlushBack.HuId;
                            inProcessLocationDetail.LotNo = materialFlushBack.LotNo;
                            inProcessLocationDetail.Qty = materialFlushBack.Qty;
                            inProcessLocationDetail.InProcessLocation = inProcessLocation;

                            inProcessLocation.AddInProcessLocationDetail(inProcessLocationDetail);
                        }
                        #endregion
                    }
                    else
                    {
                        #region 根据out的OrderLocationTransaction自动创建ASN
                        IList<OrderLocationTransaction> orderLocationTransactionList =
                            this.orderLocationTransactionMgrE.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_OUT);

                        foreach (OrderLocationTransaction orderLocTrans in orderLocationTransactionList)
                        {
                            #region 直接Copy收货项至发货项
                            InProcessLocationDetail inProcessLocationDetail = new InProcessLocationDetail();
                            if (orderHead.IsShipScanHu)
                            {
                                //只有发货扫描条码才复制条码信息
                                inProcessLocationDetail.HuId = receiptDetail.HuId;
                                inProcessLocationDetail.LotNo = receiptDetail.LotNo;
                            }
                            inProcessLocationDetail.OrderLocationTransaction = orderLocTrans;
                            inProcessLocationDetail.Qty =
                                receiptDetail.ReceivedQty.Value + receiptDetail.RejectedQty.Value + receiptDetail.ScrapQty.Value;
                            inProcessLocationDetail.InProcessLocation = inProcessLocation;

                            inProcessLocation.AddInProcessLocationDetail(inProcessLocationDetail);
                            #endregion
                        }
                        #endregion
                    }
                }
                #endregion

                #region 发货
                DoShipOrder(inProcessLocation, user, true);

                receipt.AddInProcessLocation(inProcessLocation);
                #endregion
            }
            #endregion

            #region 更新订单信息
            EntityPreference entityPreference = this.entityPreferenceMgrE.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_NO_PRICE_LIST_RECEIPT);
            string taxCode = entityPreferenceMgrE.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_TAX_RATE).Value;
            foreach (ReceiptDetail receiptDetail in receipt.ReceiptDetails)
            {
                OrderLocationTransaction orderLocationTransaction = this.orderLocationTransactionMgrE.LoadOrderLocationTransaction(receiptDetail.OrderLocationTransaction.Id);
                receiptDetail.OrderLocationTransaction = orderLocationTransaction;
                OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
                OrderHead orderHead = orderDetail.OrderHead;

                #region 判断OrderHead状态并缓存
                if (!cachedOrderHead.ContainsKey(orderHead.OrderNo))
                {
                    //检查权限
                    //if (!OrderHelper.CheckOrderOperationAuthrize(orderHead, user, BusinessConstants.ORDER_OPERATION_RECEIVE_ORDER))
                    //{
                    //    throw new BusinessErrorException("Order.Error.NoReceivePermission", orderHead.OrderNo);
                    //}

                    //判断OrderHead状态,只要有ASN就都可以收货
                    if (!(orderHead.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS
                        || orderHead.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_COMPLETE
                        || orderHead.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE))
                    {
                        throw new BusinessErrorException("Order.Error.StatusErrorWhenReceive", orderHead.Status, orderHead.OrderNo);
                    }

                    //缓存OrderHead
                    cachedOrderHead.Add(orderHead.OrderNo, orderHead);
                }
                #endregion

                #region 整包装收货判断,快速的不考虑
                if (orderHead.FulfillUnitCount && orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML
                   && !(orderHead.IsAutoRelease && orderHead.IsAutoStart))
                {
                    if (receiptDetail.ReceivedQty % orderDetail.UnitCount != 0)
                    {
                        //不是整包装
                        throw new BusinessErrorException("Order.Error.NotFulfillUnitCountGrGi", orderDetail.Item.Code);
                    }
                }
                #endregion

                #region 是否过量收货判断
                if (orderDetail.OrderHead.SubType != BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_ADJ)
                {
                    EntityPreference allowExceedentityPreference = this.entityPreferenceMgrE.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_ALLOW_EXCEED_GI_GR);
                    bool allowExceedGiGR = bool.Parse(allowExceedentityPreference.Value); //企业属性,允许过量发货和收货


                    //检查Received(已收数)不能大于等于OrderedQty(订单数)
                    //if (!(orderHead.AllowExceed && allowExceedGiGR) && orderDetail.ReceivedQty.HasValue)
                    //{
                    //    if ((orderDetail.OrderedQty > 0 && orderDetail.ReceivedQty.Value >= orderDetail.OrderedQty)
                    //        || (orderDetail.OrderedQty < 0 && orderDetail.ReceivedQty.Value <= orderDetail.OrderedQty))
                    //    {
                    //        throw new BusinessErrorException("Order.Error.ReceiveExcceed", orderHead.OrderNo, orderDetail.Item.Code);
                    //    }
                    //}

                    if (!(orderHead.AllowExceed && allowExceedGiGR))   //不允许过量收货
                    {
                        //检查AccumulateQty(已收数) + CurrentReceiveQty(本次收货数)不能大于OrderedQty(订单数)
                        orderDetail.ReceivedQty = orderDetail.ReceivedQty.HasValue ? orderDetail.ReceivedQty.Value : 0;
                        if ((orderDetail.OrderedQty > 0 && orderDetail.ReceivedQty + receiptDetail.ReceivedQty > orderDetail.OrderedQty)
                            || (orderDetail.OrderedQty < 0 && orderDetail.ReceivedQty + receiptDetail.ReceivedQty < orderDetail.OrderedQty))
                        {
                            throw new BusinessErrorException("Order.Error.ReceiveExcceed", orderHead.OrderNo, orderDetail.Item.Code);
                        }
                    }
                }
                #endregion

                #region 采购收货是否有价格单判断
                if ((orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT
                    || orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_SUBCONCTRACTING)
                    && !bool.Parse(entityPreference.Value))
                {
                    if (orderDetail.UnitPrice == Decimal.Zero)
                    {
                        //重新查找一次价格
                        PriceListDetail priceListDetail = priceListDetailMgrE.GetLastestPriceListDetail(
                            orderDetail.DefaultPriceList,
                            orderDetail.Item,
                            orderHead.StartTime,
                            orderHead.Currency,
                            orderDetail.Uom);

                        if (priceListDetail != null)
                        {
                            orderDetail.UnitPrice = priceListDetail.UnitPrice;
                            orderDetail.IsProvisionalEstimate = priceListDetail.IsProvisionalEstimate;
                            orderDetail.IsIncludeTax = priceListDetail.IsIncludeTax;
                            orderDetail.TaxCode = taxCode;
                            //priceListDetail.TaxCode;
                        }
                        else
                        {
                            throw new BusinessErrorException("Order.Error.NoPriceListReceipt", orderDetail.Item.Code);
                        }
                    }
                }
                #endregion

                #region 计算PlannedAmount,用ReceiptDetail缓存本次收货产生的PlannedAmount金额,在创建PlannedBill时使用
                if (!orderDetail.ReceivedQty.HasValue)
                {
                    orderDetail.ReceivedQty = 0;
                }

                if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT
                    || orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_SUBCONCTRACTING
                    || orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION)
                {
                    CalculatePlannedAmount(orderDetail, receiptDetail, orderDetail.IncludeTaxTotalPrice);
                }
                #endregion

                #region 记录OrderDetail的累计收货量
                orderDetail.ReceivedQty += receiptDetail.ReceivedQty.Value;
                orderDetail.RejectedQty = receiptDetail.RejectedQty.Value + (orderDetail.RejectedQty == null ? 0 : orderDetail.RejectedQty);
                orderDetail.ScrapQty = receiptDetail.ScrapQty.Value + (orderDetail.ScrapQty == null ? 0 : orderDetail.ScrapQty);
                this.orderDetailMgrE.UpdateOrderDetail(orderDetail);
                #endregion

                #region 记录OrderLocationTransaction的累计收货量

                #region 成品
                if (!orderLocationTransaction.AccumulateQty.HasValue)
                {
                    orderLocationTransaction.AccumulateQty = 0;
                }
                orderLocationTransaction.AccumulateQty += receiptDetail.ReceivedQty.Value * orderLocationTransaction.UnitQty;
                #endregion

                #region 次品
                if (!orderLocationTransaction.AccumulateRejectQty.HasValue)
                {
                    orderLocationTransaction.AccumulateRejectQty = 0;
                }
                orderLocationTransaction.AccumulateRejectQty += receiptDetail.RejectedQty.Value * orderLocationTransaction.UnitQty;
                #endregion

                #region 废品
                if (!orderLocationTransaction.AccumulateScrapQty.HasValue)
                {
                    orderLocationTransaction.AccumulateScrapQty = 0;
                }
                orderLocationTransaction.AccumulateScrapQty += receiptDetail.ScrapQty.Value * orderLocationTransaction.UnitQty;
                #endregion

                this.orderLocationTransactionMgrE.UpdateOrderLocationTransaction(orderLocationTransaction);
                #endregion
            }
            #endregion

            #region 创建收货单
            this.receiptMgrE.CreateReceipt(receipt, user, isOddCreateHu);
            #endregion

            #region 记录工时
            if (workingHoursList != null)
            {
                foreach (WorkingHours workingHours in workingHoursList)
                {
                    workingHours.Receipt = receipt;
                    workingHours.LastModifyDate = DateTime.Now;
                    workingHours.LastModifyUser = user;
                    this.workingHoursMgrE.CreateWorkingHours(workingHours);
                }
            }
            #endregion

            #region 更新订单头信息
            foreach (OrderHead orderHead in cachedOrderHead.Values)
            {
                orderHead.LastModifyUser = user;
                orderHead.LastModifyDate = dateTimeNow;
                this.orderHeadMgrE.UpdateOrderHead(orderHead);
                if (!orderHead.AllowRepeatlyExceed)
                {
                    TryCompleteOrder(orderHead, user);
                }
            }
            #endregion

            #region 处理委外加工
            foreach (ReceiptDetail receiptDetail in receipt.ReceiptDetails)
            {
                OrderLocationTransaction orderLocationTransaction = receiptDetail.OrderLocationTransaction;
                OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
                OrderHead orderHead = orderDetail.OrderHead;
                Flow flow = this.flowMgrE.LoadFlow(orderHead.Flow);
                if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_SUBCONCTRACTING)
                {
                    Flow productionFlow = this.flowMgrE.LoadFlow(flow.ReferenceFlow, true);

                    OrderHead productionOrderHead = this.TransferFlow2Order(productionFlow, false);

                    foreach (FlowDetail productionFlowDetail in productionFlow.FlowDetails)
                    {
                        if (productionFlowDetail.DefaultLocationTo != null
                            && receiptDetail.OrderLocationTransaction.Location.Code   //目的库位相同
                            == productionFlowDetail.DefaultLocationTo.Code
                            && receiptDetail.OrderLocationTransaction.Item.Code == productionFlowDetail.Item.Code)
                        {
                            OrderDetail productionOrderDetail = this.orderDetailMgrE.TransferFlowDetail2OrderDetail(productionFlowDetail);

                            #region 合并相同的productionOrderDetail
                            bool findMatch = false;
                            if (productionOrderHead.OrderDetails != null && productionOrderHead.OrderDetails.Count > 0)
                            {
                                foreach (OrderDetail addProductionOrderDetail in productionOrderHead.OrderDetails)
                                {
                                    if (productionOrderDetail.Item.Code == addProductionOrderDetail.Item.Code
                                       && productionOrderDetail.Uom.Code == addProductionOrderDetail.Uom.Code
                                       && productionOrderDetail.UnitCount == addProductionOrderDetail.UnitCount
                                       && LocationHelper.IsLocationEqual(productionOrderDetail.DefaultLocationFrom, addProductionOrderDetail.DefaultLocationFrom)
                                       && LocationHelper.IsLocationEqual(productionOrderDetail.DefaultLocationTo, addProductionOrderDetail.DefaultLocationTo))
                                    {
                                        decimal addQty = receiptDetail.ReceivedQty.Value;
                                        if (addProductionOrderDetail.Uom.Code != orderDetail.Uom.Code)
                                        {
                                            addProductionOrderDetail.OrderedQty += this.uomConversionMgrE.ConvertUomQty(addProductionOrderDetail.Item, orderDetail.Uom, addQty, productionOrderDetail.Uom);
                                        }
                                        else
                                        {
                                            addProductionOrderDetail.OrderedQty += addQty;
                                        }
                                        findMatch = true;
                                    }
                                }
                            }
                            #endregion

                            if (!findMatch)
                            {
                                productionOrderDetail.OrderHead = productionOrderHead;
                                productionOrderDetail.OrderedQty = receiptDetail.ReceivedQty.Value;
                                if (productionOrderDetail.Uom.Code != orderDetail.Uom.Code)
                                {
                                    productionOrderDetail.OrderedQty = this.uomConversionMgrE.ConvertUomQty(productionOrderDetail.Item, orderDetail.Uom, receiptDetail.ReceivedQty.Value, productionOrderDetail.Uom);
                                }

                                productionOrderHead.AddOrderDetail(productionOrderDetail);
                            }
                        }
                    }

                    if (productionOrderHead.OrderDetails != null && productionOrderHead.OrderDetails.Count > 0)
                    {
                        productionOrderHead.IsAutoRelease = true;
                        productionOrderHead.IsAutoStart = true;
                        productionOrderHead.IsAutoShip = true;
                        productionOrderHead.IsAutoReceive = true;
                        productionOrderHead.StartLatency = 0;
                        productionOrderHead.CompleteLatency = 0;
                        productionOrderHead.StartTime = orderHead.StartTime;
                        productionOrderHead.WindowTime = orderHead.WindowTime;
                        productionOrderHead.ReferenceOrderNo = orderHead.OrderNo;
                        productionOrderHead.Priority = BusinessConstants.CODE_MASTER_ORDER_PRIORITY_VALUE_NORMAL;
                        productionOrderHead.IsSubcontract = true;

                        this.CreateOrder(productionOrderHead, user);
                    }
                }
            }
            #endregion

            #region 处理路线绑定
            foreach (OrderHead orderHead in cachedOrderHead.Values)
            {
                this.CreateBindingOrder(orderHead, user,
                    BusinessConstants.CODE_MASTER_BINDING_TYPE_VALUE_RECEIVE_ASYN,
                    BusinessConstants.CODE_MASTER_BINDING_TYPE_VALUE_RECEIVE_SYN);
            }
            #endregion

            return receipt;
        }
        public Receipt QuickReceiveOrder(Flow flow, IList<OrderDetail> orderDetailList, User user, string orderSubType, DateTime winTime, DateTime startTime, bool isUrgent, string referenceOrderNo, string externalOrderNo)
        {
            if (flow.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
            {
                throw new TechnicalException("QuickReceiveOrder not support Production");
            }

            #region 缓存上架信息
            IDictionary<string, string> huIdStorageBinDic = new Dictionary<string, string>();
            foreach (OrderDetail sourceOrderDetail in orderDetailList)
            {
                if (sourceOrderDetail.HuId != null && sourceOrderDetail.HuId.Trim() != string.Empty &&
                    sourceOrderDetail.PutAwayBinCode != null && sourceOrderDetail.PutAwayBinCode.Trim() != string.Empty)
                {
                    if (!huIdStorageBinDic.ContainsKey(sourceOrderDetail.HuId.Trim()))
                    {
                        huIdStorageBinDic.Add(sourceOrderDetail.HuId.Trim(), sourceOrderDetail.PutAwayBinCode.Trim());
                    }
                    else
                    {
                        if (huIdStorageBinDic[sourceOrderDetail.HuId.Trim()] != sourceOrderDetail.PutAwayBinCode.Trim())
                        {
                            throw new BusinessErrorException("Common.Business.Error.OneHuCannotInTwoBin");
                        }
                    }
                }
            }
            #endregion

            #region 初始化订单头
            OrderHead orderHead = this.TransferFlow2Order(flow, orderSubType);

            #region 从不合格品库位退货,收货扫描一定要设为False
            if (orderDetailList != null && orderDetailList.Count > 0)
            {
                //如果不是所有明细的目的库位都是Reject,可能有问题。
                if (orderSubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_RTN &&
                    orderDetailList[0].DefaultLocationTo != null &&
                    orderDetailList[0].DefaultLocationTo.Code == BusinessConstants.SYSTEM_LOCATION_REJECT)
                {
                    orderHead.IsReceiptScanHu = false;
                    orderHead.LocationTo = this.locationMgrE.GetRejectLocation();
                }
            }
            #endregion

            IList<OrderDetail> targetOrderDetailList = orderHead.OrderDetails;

            if (targetOrderDetailList == null)
            {
                targetOrderDetailList = new List<OrderDetail>();
            }

            orderHead.SubType = orderSubType;
            orderHead.WindowTime = winTime;
            orderHead.StartTime = startTime;
            orderHead.ReferenceOrderNo = referenceOrderNo;
            orderHead.ExternalOrderNo = externalOrderNo;
            if (isUrgent)
            {
                orderHead.Priority = BusinessConstants.CODE_MASTER_ORDER_PRIORITY_VALUE_URGENT;
            }
            else
            {
                orderHead.Priority = BusinessConstants.CODE_MASTER_ORDER_PRIORITY_VALUE_NORMAL;
            }

            orderHead.IsAutoRelease = true;
            orderHead.IsAutoStart = true;
            orderHead.IsAutoCreatePickList = false;
            orderHead.IsAutoShip = false;
            orderHead.IsAutoReceive = false;
            #endregion

            #region 合并OrderDetailList
            if (orderDetailList != null && orderDetailList.Count > 0)
            {
                IList<OrderDetail> newOrderDetailList = new List<OrderDetail>();
                foreach (OrderDetail sourceOrderDetail in orderDetailList)
                {
                    bool findMatch = false;

                    #region 在FlowDetail转换的OrderDetail里面查找匹配项
                    foreach (OrderDetail targetOrderDetail in targetOrderDetailList)
                    {
                        if (sourceOrderDetail.Item.Code == targetOrderDetail.Item.Code
                            && sourceOrderDetail.Uom.Code == targetOrderDetail.Uom.Code
                            && sourceOrderDetail.UnitCount == targetOrderDetail.UnitCount
                            && LocationHelper.IsLocationEqual(sourceOrderDetail.DefaultLocationFrom, targetOrderDetail.DefaultLocationFrom)
                            && LocationHelper.IsLocationEqual(sourceOrderDetail.DefaultLocationTo, targetOrderDetail.DefaultLocationTo))
                        {
                            targetOrderDetail.RequiredQty += sourceOrderDetail.OrderedQty;
                            targetOrderDetail.OrderedQty += sourceOrderDetail.OrderedQty;

                            findMatch = true;

                            break;
                        }
                    }
                    #endregion

                    if (!findMatch)
                    {
                        #region 没有找到匹配项,从新增匹配项中找
                        foreach (OrderDetail newOrderDetail in newOrderDetailList)
                        {
                            if (sourceOrderDetail.Item.Code == newOrderDetail.Item.Code
                            && sourceOrderDetail.Uom.Code == newOrderDetail.Uom.Code
                            && sourceOrderDetail.UnitCount == newOrderDetail.UnitCount
                            && LocationHelper.IsLocationEqual(sourceOrderDetail.DefaultLocationFrom, newOrderDetail.DefaultLocationFrom)
                            && LocationHelper.IsLocationEqual(sourceOrderDetail.DefaultLocationTo, newOrderDetail.DefaultLocationTo))
                            {
                                newOrderDetail.RequiredQty += sourceOrderDetail.OrderedQty;
                                newOrderDetail.OrderedQty += sourceOrderDetail.OrderedQty;

                                findMatch = true;

                                break;
                            }
                        }
                        #endregion

                        if (!findMatch)
                        {
                            #region 还没有找到匹配项,新增到newOrderDetailList中
                            OrderDetail clonedSourceOrderDetail = CloneHelper.DeepClone<OrderDetail>(sourceOrderDetail);
                            clonedSourceOrderDetail.OrderHead = orderHead;
                            newOrderDetailList.Add(clonedSourceOrderDetail);
                            #endregion
                        }
                    }
                }

                if (newOrderDetailList.Count > 0)
                {
                    #region 合并新增的OrderDetail
                    int seqInterval = int.Parse(this.entityPreferenceMgrE.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_SEQ_INTERVAL).Value);
                    int maxSeq = 0;
                    foreach (OrderDetail targetOrderDetail in targetOrderDetailList)
                    {
                        if (targetOrderDetail.Sequence > maxSeq)
                        {
                            maxSeq = targetOrderDetail.Sequence;
                        }
                    }

                    foreach (OrderDetail newOrderDetail in newOrderDetailList)
                    {
                        maxSeq += seqInterval;
                        newOrderDetail.Sequence = maxSeq;

                        orderHead.AddOrderDetail(newOrderDetail);
                    }
                    #endregion
                }
            }

            #endregion

            #region 创建订单
            this.CreateOrder(orderHead, user);
            #endregion

            #region 发货
            IList<InProcessLocationDetail> inProcessLocationDetailList = new List<InProcessLocationDetail>();
            foreach (OrderDetail sourceOrderDetail in orderDetailList)
            {
                foreach (OrderDetail targetOrderDetail in orderHead.OrderDetails)
                {
                    if (sourceOrderDetail.Item.Code == targetOrderDetail.Item.Code
                        && sourceOrderDetail.Uom.Code == targetOrderDetail.Uom.Code
                        && sourceOrderDetail.UnitCount == targetOrderDetail.UnitCount
                        && LocationHelper.IsLocationEqual(sourceOrderDetail.DefaultLocationFrom, targetOrderDetail.DefaultLocationFrom)
                        && LocationHelper.IsLocationEqual(sourceOrderDetail.DefaultLocationTo, targetOrderDetail.DefaultLocationTo))
                    {

                        if (orderSubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_ADJ
                            && sourceOrderDetail.HuId != null && sourceOrderDetail.HuId.Trim() != string.Empty)
                        {
                            #region 处理按条码的调整,去掉条码,只调整原库位数量
                            InProcessLocationDetail rtnInProcessLocationDetail = new InProcessLocationDetail();

                            rtnInProcessLocationDetail.OrderLocationTransaction = this.orderLocationTransactionMgrE.GetOrderLocationTransaction(targetOrderDetail.Id, BusinessConstants.IO_TYPE_OUT)[0];
                            Hu hu = this.huMgrE.CheckAndLoadHu(sourceOrderDetail.HuId);
                            rtnInProcessLocationDetail.LotNo = hu.LotNo;
                            rtnInProcessLocationDetail.Qty = 0 - hu.Qty;
                            inProcessLocationDetailList.Add(rtnInProcessLocationDetail);

                            InProcessLocationDetail adjInProcessLocationDetail = new InProcessLocationDetail();
                            adjInProcessLocationDetail.OrderLocationTransaction = rtnInProcessLocationDetail.OrderLocationTransaction;
                            adjInProcessLocationDetail.LotNo = hu.LotNo;
                            adjInProcessLocationDetail.Qty = sourceOrderDetail.OrderedQty + hu.Qty;
                            inProcessLocationDetailList.Add(adjInProcessLocationDetail);
                            #endregion
                        }
                        else
                        {
                            InProcessLocationDetail inProcessLocationDetail = new InProcessLocationDetail();

                            inProcessLocationDetail.OrderLocationTransaction = this.orderLocationTransactionMgrE.GetOrderLocationTransaction(targetOrderDetail.Id, BusinessConstants.IO_TYPE_OUT)[0];
                            inProcessLocationDetail.HuId = sourceOrderDetail.HuId;
                            if (inProcessLocationDetail.HuId != null && inProcessLocationDetail.HuId.Trim() != string.Empty)
                            {
                                Hu hu = this.huMgrE.CheckAndLoadHu(inProcessLocationDetail.HuId);
                                inProcessLocationDetail.LotNo = hu.LotNo;

                                //设置退货上架库格
                                if (orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_RTN)
                                {
                                    if (huIdStorageBinDic.ContainsKey(hu.HuId))
                                    {
                                        inProcessLocationDetail.ReturnPutAwaySorageBinCode = huIdStorageBinDic[hu.HuId];
                                    }
                                }
                            }
                            inProcessLocationDetail.Qty = sourceOrderDetail.OrderedQty;

                            inProcessLocationDetailList.Add(inProcessLocationDetail);

                            break;
                        }
                    }

                }
            }

            InProcessLocation inProcessLocation = this.ShipOrder(inProcessLocationDetailList, user);
            #endregion

            #region 为收货调整重新赋条码,增加目的库位的条码数量
            if (orderSubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_ADJ)
            {
                foreach (InProcessLocationDetail inProcessLocationDetail in inProcessLocation.InProcessLocationDetails)
                {
                    foreach (OrderDetail sourceOrderDetail in orderDetailList)
                    {
                        if (sourceOrderDetail.HuId != null && sourceOrderDetail.HuId.Trim() != string.Empty)
                        {
                            if (sourceOrderDetail.Item.Code == inProcessLocationDetail.OrderLocationTransaction.OrderDetail.Item.Code
                            && sourceOrderDetail.Uom.Code == inProcessLocationDetail.OrderLocationTransaction.OrderDetail.Uom.Code
                            && sourceOrderDetail.UnitCount == inProcessLocationDetail.OrderLocationTransaction.OrderDetail.UnitCount
                            && LocationHelper.IsLocationEqual(sourceOrderDetail.DefaultLocationFrom, inProcessLocationDetail.OrderLocationTransaction.OrderDetail.DefaultLocationFrom)
                            && LocationHelper.IsLocationEqual(sourceOrderDetail.DefaultLocationTo, inProcessLocationDetail.OrderLocationTransaction.OrderDetail.DefaultLocationTo))
                            {

                                Hu hu = this.huMgrE.CheckAndLoadHu(sourceOrderDetail.HuId);
                                inProcessLocationDetail.HuId = hu.HuId;
                                inProcessLocationDetail.LotNo = hu.LotNo;
                                break;
                            }
                        }
                    }
                }
            }
            #endregion

            #region 收货
            if (orderSubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML)
            {
                return ReceiveFromInProcessLocation(inProcessLocation, user, huIdStorageBinDic, externalOrderNo);
            }
            else
            {
                return ReceiveFromInProcessLocation(inProcessLocation, user, null, externalOrderNo);
            }
            #endregion
        }
    public string AdjustInProcessLocationTo()
    {

        try
        {
            InProcessLocation ip = TheInProcessLocationMgr.LoadInProcessLocation(this.IpNo, true);
            Receipt receipt = new Receipt();
            InProcessLocation nmlIp = CloneHelper.DeepClone(ip);
            IList<InProcessLocationDetail> nmlReceiptDetailList = new List<InProcessLocationDetail>();
            foreach (InProcessLocationDetail ipdet in ip.InProcessLocationDetails)
            {
                #region 对应的ipdet
                InProcessLocationDetail nmlInProcessLocationDetail = new InProcessLocationDetail();
                nmlInProcessLocationDetail.Qty = 0 - ipdet.Qty;
                nmlInProcessLocationDetail.OrderLocationTransaction = TheOrderLocationTransactionMgr.GetOrderLocationTransaction(ipdet.OrderLocationTransaction.OrderDetail, BusinessConstants.IO_TYPE_IN)[0];
                nmlInProcessLocationDetail.IsConsignment = ipdet.IsConsignment;
                nmlInProcessLocationDetail.PlannedBill = ipdet.PlannedBill;
                nmlReceiptDetailList.Add(nmlInProcessLocationDetail);
                #endregion

                #region 收货单明细
                ReceiptDetail receiptDetail = new ReceiptDetail();
                receiptDetail.Receipt = receipt;
                receiptDetail.ReceivedQty = nmlInProcessLocationDetail.Qty;
                receiptDetail.ShippedQty = nmlInProcessLocationDetail.Qty;
                receiptDetail.OrderLocationTransaction = nmlInProcessLocationDetail.OrderLocationTransaction;
                receiptDetail.IsConsignment = ipdet.IsConsignment;
                nmlInProcessLocationDetail.PlannedBill = ipdet.PlannedBill;

                OrderDetail orderDetail = receiptDetail.OrderLocationTransaction.OrderDetail;

                OrderHead orderHead = orderDetail.OrderHead;

                if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT)
                {
                    PriceListDetail priceListDetail = ThePriceListDetailMgr.GetLastestPriceListDetail(orderDetail.DefaultPriceList, orderDetail.Item, DateTime.Now, orderDetail.OrderHead.Currency);
                    if (priceListDetail == null)
                    {
                        throw new BusinessErrorException("Order.Error.NoPriceListReceipt", new string[] { orderDetail.Item.Code });
                    }
                    receiptDetail.PlannedAmount = priceListDetail.UnitPrice * (decimal)receiptDetail.ReceivedQty;
                }
                else if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION)
                {
                    PriceListDetail priceListDetail = ThePriceListDetailMgr.GetLastestPriceListDetail(orderDetail.DefaultPriceList, orderDetail.Item, DateTime.Now, orderDetail.OrderHead.Currency);
                    if (priceListDetail == null)
                    {
                        throw new BusinessErrorException("Order.Error.NoPriceListReceipt", new string[] { orderDetail.Item.Code });
                    }
                    receiptDetail.PlannedAmount = priceListDetail.UnitPrice * (decimal)receiptDetail.ReceivedQty;
                }

                receipt.AddReceiptDetail(receiptDetail);
                #endregion
            }


            nmlIp.InProcessLocationDetails = nmlReceiptDetailList;
            if (receipt.InProcessLocations == null)
            {
                receipt.InProcessLocations = new List<InProcessLocation>();
            }
            receipt.InProcessLocations.Add(nmlIp);

            TheReceiptMgr.CreateReceipt(receipt, this.CurrentUser);
            return receipt.ReceiptNo;
        }
        catch (BusinessErrorException ex)
        {
            throw (ex);
        }
    }
        public InProcessLocation ConvertOrderLocTransToInProcessLocation(IList<OrderLocationTransaction> orderLocTransList)
        {
            InProcessLocation inProcessLocation = new InProcessLocation();
            if (orderLocTransList != null && orderLocTransList.Count > 0)
            {
                inProcessLocation = inProcessLocationMgrE.GenerateInProcessLocation(orderLocTransList[0].OrderDetail.OrderHead);
                foreach (OrderLocationTransaction orderLocTrans in orderLocTransList)
                {
                    if (orderLocTrans.OrderDetail.RemainShippedQty > 0)
                    {
                        InProcessLocationDetail inProcessLocationDetail = new InProcessLocationDetail();
                        inProcessLocationDetail.OrderLocationTransaction = orderLocTrans;
                        inProcessLocationDetail.QtyToShip = orderLocTrans.OrderDetail.RemainShippedQty;
                        inProcessLocationDetail.Qty = inProcessLocationDetail.QtyToShip;
                        inProcessLocationDetail.InProcessLocation = inProcessLocation;

                        inProcessLocation.AddInProcessLocationDetail(inProcessLocationDetail);
                    }
                }
            }

            return inProcessLocation;
        }
 public virtual void UpdateInProcessLocationDetail(InProcessLocationDetail entity)
 {
     entityDao.UpdateInProcessLocationDetail(entity);
 }
        public InProcessLocation ConvertPickListToInProcessLocation(string pickListNo)
        {
            IList<InProcessLocationDetail> ipDetList = new List<InProcessLocationDetail>();
            IList<PickListResult> pickListResultList = pickListResultMgrE.GetPickListResult(pickListNo);
            if (pickListResultList != null && pickListResultList.Count > 0)
            {
                foreach (PickListResult pickListResult in pickListResultList)
                {
                    InProcessLocationDetail ipDet = new InProcessLocationDetail();
                    ipDet.OrderLocationTransaction = pickListResult.PickListDetail.OrderLocationTransaction;
                    ipDet.HuId = pickListResult.LocationLotDetail.Hu.HuId;
                    ipDet.LotNo = pickListResult.LocationLotDetail.LotNo;
                    ipDet.QtyToShip = pickListResult.Qty;//单位换算
                    ipDet.Qty = pickListResult.Qty;

                    ipDetList.Add(ipDet);
                }
            }

            InProcessLocation ip = inProcessLocationMgrE.GenerateInProcessLocation(ipDetList[0].OrderLocationTransaction.OrderDetail.OrderHead);
            ip.InProcessLocationDetails = ipDetList;

            return ip;
        }
Beispiel #28
0
        public IList<Hu> CreateHu(InProcessLocationDetail inProcessLocationDetail, User user)
        {
            if (inProcessLocationDetail.HuId != null)
            {
                throw new TechnicalException("HuId already exist.");
            }

            OrderLocationTransaction orderLocationTransaction = inProcessLocationDetail.OrderLocationTransaction;
            OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
            OrderHead orderHead = orderDetail.OrderHead;

            return CreateHu(orderLocationTransaction.Item, inProcessLocationDetail.Qty, inProcessLocationDetail.LotNo, orderDetail.Uom, orderDetail.UnitCount, orderDetail.HuLotSize,
                    orderHead.OrderNo, null, null, orderHead.PartyFrom, BusinessConstants.CODE_MASTER_ITEM_QUALITY_LEVEL_VALUE_1, user, inProcessLocationDetail, null, orderLocationTransaction.ItemVersion, null,orderDetail.CustomerItemCode);
        }
        public IList<InProcessLocationDetail> ConvertTransformerToInProcessLocationDetail(List<Transformer> transformerList, bool includeZero)
        {
            IList<InProcessLocationDetail> ipDetList = new List<InProcessLocationDetail>();
            InProcessLocationDetail ipDet = new InProcessLocationDetail();
            if (transformerList != null && transformerList.Count > 0)
            {
                foreach (Transformer transformer in transformerList)
                {
                    OrderLocationTransaction orderLocTrans = orderLocationTransactionMgrE.LoadOrderLocationTransaction(transformer.OrderLocTransId);
                    if (transformer.TransformerDetails != null && transformer.TransformerDetails.Count > 0)
                    {
                        foreach (TransformerDetail transformerDetail in transformer.TransformerDetails)
                        {
                            ipDet = new InProcessLocationDetail();
                            ipDet.OrderLocationTransaction = orderLocTrans;
                            ipDet.HuId = transformerDetail.HuId;
                            ipDet.LotNo = transformerDetail.LotNo;
                            ipDet.QtyToShip = transformerDetail.Qty;
                            ipDet.Qty = transformerDetail.CurrentQty;

                            if (ipDet.Qty != 0 || includeZero)
                                ipDetList.Add(ipDet);
                        }
                    }
                    else
                    {
                        ipDet = new InProcessLocationDetail();
                        ipDet.OrderLocationTransaction = orderLocTrans;
                        ipDet.QtyToShip = transformer.Qty;
                        ipDet.Qty = transformer.CurrentQty;

                        if (ipDet.Qty != 0 || includeZero)
                            ipDetList.Add(ipDet);
                    }
                }
            }

            return ipDetList;
        }
        public static TransformerDetail ConvertInProcessLocationDetailToTransformerDetail(InProcessLocationDetail inProcessLocationDetail)
        {
            TransformerDetail transformerDetail = ConvertOrderLocationTransactionToTransformerDetail(inProcessLocationDetail.OrderLocationTransaction);
            transformerDetail.HuId = inProcessLocationDetail.HuId;
            transformerDetail.LotNo = inProcessLocationDetail.LotNo;
            //transformerDetail.Qty = inProcessLocationDetail.QtyToShip;
            transformerDetail.Qty = inProcessLocationDetail.Qty;

            //多次收货加的
            decimal receivedQty = inProcessLocationDetail.ReceivedQty.HasValue ? (decimal)inProcessLocationDetail.ReceivedQty : 0;
            transformerDetail.CurrentQty = inProcessLocationDetail.Qty - receivedQty;

            return transformerDetail;
        }
        public void RecordOrderShipQty(OrderLocationTransaction orderLocationTransaction, InProcessLocationDetail inProcessLocationDetail, bool checkExcceed)
        {
            //orderLocationTransaction = this.orderLocationTransactionMgr.LoadOrderLocationTransaction(orderLocationTransaction.Id);
            EntityPreference entityPreference = this.entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_ALLOW_EXCEED_GI_GR);
            bool allowExceedGiGR = bool.Parse(entityPreference.Value); //��ҵ���ԣ���������������ջ�

            OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
            OrderHead orderHead = orderDetail.OrderHead;
            decimal shipQty = inProcessLocationDetail.Qty * orderLocationTransaction.UnitQty;

            #region �Ƿ���������ж�
            //�������Ϸ�����������ѡ��
            if (orderLocationTransaction.OrderDetail.OrderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION
                && orderLocationTransaction.OrderDetail.OrderHead.SubType != BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_ADJ)
            {
                //���AccumulateQty(�ѷ���)���ܴ��ڵ���OrderedQty(������)
                //if (!(orderHead.AllowExceed && allowExceedGiGR))
                //{
                //    if ((orderLocationTransaction.OrderedQty > 0 && orderLocationTransaction.AccumulateQty.HasValue && orderLocationTransaction.AccumulateQty.Value >= orderLocationTransaction.OrderedQty && shipQty > 0)
                //            || (orderLocationTransaction.OrderedQty < 0 && orderLocationTransaction.AccumulateQty.HasValue && orderLocationTransaction.AccumulateQty.Value <= orderLocationTransaction.OrderedQty && shipQty < 0))
                //    {
                //        throw new BusinessErrorException("Order.Error.ShipExcceed", orderHead.OrderNo, orderLocationTransaction.Item.Code);
                //    }
                //}

                if (!(orderHead.AllowExceed && allowExceedGiGR) && checkExcceed)   //�������������
                {
                    //���AccumulateQty(�ѷ���) + shipQty(���η�����)���ܴ���OrderedQty(������)
                    orderLocationTransaction.AccumulateQty = orderLocationTransaction.AccumulateQty.HasValue ? orderLocationTransaction.AccumulateQty.Value : 0;
                    if ((orderLocationTransaction.OrderedQty > 0 && (orderLocationTransaction.AccumulateQty + shipQty > orderLocationTransaction.OrderedQty))
                        || (orderLocationTransaction.OrderedQty < 0 && (orderLocationTransaction.AccumulateQty + shipQty < orderLocationTransaction.OrderedQty)))
                    {
                        throw new BusinessErrorException("Order.Error.ShipExcceed", orderHead.OrderNo, orderLocationTransaction.Item.Code);
                    }
                }
            }
            #endregion

            #region ��¼������
            if (orderLocationTransaction.BackFlushMethod == null ||
                orderLocationTransaction.BackFlushMethod == BusinessConstants.CODE_MASTER_BACKFLUSH_METHOD_VALUE_GOODS_RECEIVE)
            {
                if (!orderLocationTransaction.AccumulateQty.HasValue)
                {
                    orderLocationTransaction.AccumulateQty = 0;
                }
                //��¼LocationTransaction���ۼƷ�����
                orderLocationTransaction.AccumulateQty += shipQty;
                this.orderLocationTransactionMgr.UpdateOrderLocationTransaction(orderLocationTransaction);

                //��¼OrderDetail���ۼƷ�����
                if (orderLocationTransaction.Item.Code == orderLocationTransaction.OrderDetail.Item.Code)
                {
                    //���OrderLocationTransaction��OrderDetail�ϵ�Itemһ�£���Ҫ����OrderDetail�ϵ�ShippedQty
                    if (!orderDetail.ShippedQty.HasValue)
                    {
                        orderDetail.ShippedQty = 0;
                    }

                    //OrderLocationTransaction��OrderDetail�ϵ�Item���ܵ�λ��һ�£�ֱ�ӳ���UnitQty�Ϳ���ת����
                    orderDetail.ShippedQty += (shipQty / orderLocationTransaction.UnitQty);
                    this.UpdateOrderDetail(orderDetail);
                }
            }
            #endregion
        }