public virtual void ProcessSingleFile(string inboundDirectoryName, string inboundFileName)
        {
            log.Info("Start inbound file " + inboundFileName);
            FlatFileReader reader = new FlatFileReader(inboundFileName, Encoding.ASCII, "\t");

            try
            {
                OrderHead orderHead = null;
                OrderDetail orderDetail = null;
                string shiftCode = string.Empty;
                Hu hu = null;

                string[] fields = reader.ReadLine();
                while (fields != null)
                {
                    string prodLine = fields[0];
                    string itemCode = fields[1];
                    string huId = fields[2];
                    decimal qty = decimal.Parse(fields[3]);
                    string itemHuId = fields[4];
                    string onlineDate = fields[5];
                    string onlineTime = fields[6];
                    string offlineDate = fields[7];
                    string offlineTime = fields[8];
                    string customerCode = fields[9];
                    string customerLoc = fields[10];

                    if (orderHead == null)
                    {
                        #region 查找工单
                        shiftCode = BarcodeHelper.GetShiftCode(huId);

                        DetachedCriteria criteria = DetachedCriteria.For<OrderHead>();
                        criteria.CreateAlias("Flow", "f");
                        //criteria.CreateAlias("Shift", "s");

                        criteria.Add(Expression.Like("f.Code", prodLine, MatchMode.End));
                        criteria.Add(Expression.Eq("s.Code", shiftCode));
                        criteria.Add(Expression.Eq("Status", BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS));

                        criteria.AddOrder(Order.Asc("StartTime"));

                        IList<OrderHead> orderHeadList = this.criteriaMgrE.FindAll<OrderHead>(criteria);
                        #endregion

                        if (orderHeadList != null && orderHeadList.Count > 0)
                        {
                            foreach(OrderHead targetOrderHead in orderHeadList) 
                            {
                                orderHead = targetOrderHead;                               

                                #region 查找工单明细
                                IList<OrderDetail> orderDetailList = orderHead.OrderDetails;
                                foreach (OrderDetail targetOrderDetail in orderDetailList)
                                {
                                    if (targetOrderDetail.Item.Code == itemCode)
                                    {
                                        log.Info("Find match wo " + orderHead.OrderNo);
                                        orderDetail = targetOrderDetail;
                                        orderDetail.CurrentReceiveQty = qty;
                                        break;
                                    }
                                }                                
                                #endregion

                                if (orderDetail != null)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            throw new BusinessErrorException("No active wo find for prodline + " + prodLine + ", shift " + shiftCode);
                        }

                        if (orderDetail != null)
                        {
                            #region 创建外包装条码
                            if (this.huMgrE.LoadHu(huId) == null)
                            {
                                log.Info("Insert hu " + huId + " into database.");
                                hu = ResolveAndCreateHu(huId, orderDetail, qty);
                                orderDetail.HuId = hu.HuId;

                                Receipt receipt = new Receipt();
                                ReceiptDetail receiptDetail = new ReceiptDetail();
                                receiptDetail.OrderLocationTransaction = this.orderLocationTransactionMgrE.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_IN)[0];
                                receiptDetail.HuId = hu.HuId;
                                receiptDetail.ReceivedQty = qty;
                                receiptDetail.Receipt = receipt;

                                #region 找Out的OrderLocTrans,填充MaterialFulshBack
                                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 = qty;
                                    }
                                    receiptDetail.AddMaterialFlushBack(material);
                                }
                                #endregion
                                receipt.AddReceiptDetail(receiptDetail);

                                this.orderManager.ReceiveOrder(receipt, this.userMgrE.GetMonitorUser());
                            }
                            else
                            {
                                throw new BusinessErrorException("Hu " + huId + " already exist in database.");
                            }
                            #endregion
                        }
                        else
                        {
                            throw new BusinessErrorException("No item found for item code " + itemCode + " for prodline + " + prodLine + ", shift " + shiftCode);
                        }
                    }

                    #region 创建内包装条码
                    if (this.huMgrE.LoadHu(itemHuId) == null)
                    {
                        log.Info("Insert hu " + itemHuId + " into database.");
                        CreateItemHu(itemHuId, orderDetail, hu.LotNo, hu.ManufactureDate);
                    }
                    else
                    {
                        throw new BusinessErrorException("Hu " + itemHuId + " already exist in database.");
                    }
                    #endregion

                    fields = reader.ReadLine();
                }
            }
            finally
            {
                reader.Dispose();
            }
        }
예제 #2
0
        private Receipt BuildReceipt(OrderLocationTransaction orderLocationTransaction, IList<DssImportHistory> dssImportHistoryList)
        {
            if (orderLocationTransaction == null || dssImportHistoryList == null || dssImportHistoryList.Count == 0)
                return null;

            Receipt receipt = new Receipt();
            IList<OrderLocationTransaction> orderLocTransList = this.orderLocationTransactionMgr.GetOrderLocationTransaction(orderLocationTransaction.OrderDetail.Id, BusinessConstants.IO_TYPE_OUT);
            foreach (var dssImportHistory in dssImportHistoryList)
            {
                ReceiptDetail receiptDetail = new ReceiptDetail();
                receiptDetail.Receipt = receipt;
                receiptDetail.OrderLocationTransaction = orderLocationTransaction;
                receiptDetail.HuId = dssImportHistory.HuId;
                receiptDetail.ReceivedQty = dssImportHistory.Qty;

                #region 找Out的OrderLocTrans,填充MaterialFlushBack
                foreach (OrderLocationTransaction orderLocTrans in orderLocTransList)
                {
                    MaterialFlushBack material = new MaterialFlushBack();
                    material.OrderLocationTransaction = orderLocTrans;
                    if (orderLocTrans.UnitQty != 0)
                    {
                        material.Qty = dssImportHistory.Qty;
                    }
                    receiptDetail.AddMaterialFlushBack(material);
                }
                #endregion

                receipt.AddReceiptDetail(receiptDetail);
            }

            return receipt;
        }
예제 #3
0
        public Receipt ReceiveReuseOrder(OrderHead orderHead, User user, IList<Hu> huList)
        {
            foreach (OrderDetail orderDetail in orderHead.OrderDetails)
            {
                decimal qty = orderDetail.OrderedQty;
                foreach (Hu hu in huList)
                {
                    if (orderDetail.Item.Code == hu.Item.Code && orderDetail.Uom.Code == hu.Uom.Code)
                    {
                        qty = qty - hu.Qty;
                    }
                }
                if (qty != 0)
                {
                    throw new BusinessErrorException("OrderDetail.Item.Qty.NotMatch", orderDetail.Item.Code);
                }

            }

            IList<ReceiptDetail> receiptDetailList = new List<ReceiptDetail>();
            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.ScrapQty = orderDetail.OrderedQty;

                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.OrderDetail.Item.Code == orderLocTrans.Item.Code)
                        {
                            foreach (Hu hu in huList)
                            {
                                if (hu.Item.Code == orderLocTrans.Item.Code && hu.Uom.Code == orderLocTrans.OrderDetail.Uom.Code)
                                {
                                    material = new MaterialFlushBack();
                                    material.OrderLocationTransaction = orderLocTrans;
                                    material.HuId = hu.HuId;
                                    if (orderLocTrans.UnitQty != 0)
                                    {
                                        material.Qty = hu.Qty;
                                    }
                                    receiptDetail.AddMaterialFlushBack(material);
                                }
                            }
                        }
                        else
                        {
                            if (orderLocTrans.UnitQty != 0)
                            {
                                material.Qty = orderLocTrans.OrderedQty / orderLocTrans.UnitQty;
                            }
                            receiptDetail.AddMaterialFlushBack(material);
                        }
                    }
                }
                receiptDetailList.Add(receiptDetail);
            }


            return ReceiveOrder(receiptDetailList, user, null, null, null, true, false);
        }
예제 #4
0
        public Receipt ReceiveScrapOrder(OrderHead orderHead, User user)
        {
            IList<ReceiptDetail> receiptDetailList = new List<ReceiptDetail>();
            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.ScrapQty = orderDetail.OrderedQty;

                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);
                    }
                }
                receiptDetailList.Add(receiptDetail);
            }


            return ReceiveOrder(receiptDetailList, user, null, null, null, true, false);
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        public void DoReceiveWO(string huId, OrderDetail orderDetail, decimal qty)
        {
            #region 创建外包装条码 有创建状态的条码就不创建条码了
            Hu hu = new Hu();
            DetachedCriteria criteria = DetachedCriteria.For<Hu>();
            criteria.Add(Expression.Eq("HuId", huId));
            criteria.Add(Expression.Eq("Status", BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE));
            IList<Hu> huList = this.criteriaMgr.FindAll<Hu>(criteria);
            if (huList != null && huList.Count > 0)
            {
                hu = huList[0];
            }
            else
            {
                hu = ResolveAndCreateHu(huId, orderDetail, qty);
            }
            #endregion

            #region 工单收货
            orderDetail.HuId = hu.HuId;

            Receipt receipt = new Receipt();
            ReceiptDetail receiptDetail = new ReceiptDetail();
            receiptDetail.HuId = hu.HuId;
            receiptDetail.LotNo = hu.LotNo;
            receiptDetail.ReceivedQty = qty;
            receiptDetail.Receipt = receipt;

            #region 找Out的OrderLocTrans,填充MaterialFulshBack
            IList<OrderLocationTransaction> orderLocTransList = this.orderLocationTransactionMgr.GetOrderLocationTransaction(orderDetail.Id);
            foreach (OrderLocationTransaction orderLocTrans in orderLocTransList)
            {
                if (orderLocTrans.IOType == BusinessConstants.IO_TYPE_OUT)
                {
                    MaterialFlushBack material = new MaterialFlushBack();
                    material.OrderLocationTransaction = orderLocTrans;
                    if (orderLocTrans.UnitQty != 0)
                    {
                        material.Qty = qty;
                    }
                    receiptDetail.AddMaterialFlushBack(material);
                }
                else
                {
                    receiptDetail.OrderLocationTransaction = this.orderLocationTransactionMgr.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_IN)[0];
                }
            }
            #endregion
            receipt.AddReceiptDetail(receiptDetail);

            this.ReceiveOrder(receipt, this.userMgr.GetMonitorUser());
            #endregion
        }
        public virtual void DoReceiveOrder(string huId, OrderDetail orderDetail, decimal qty)
        {
            #region 创建外包装条码
            log.Info("Insert hu " + huId + " into database.");
            Hu hu = ResolveAndCreateHu(huId, orderDetail, qty);
            #endregion

            #region 工单收货
            orderDetail.HuId = hu.HuId;

            Receipt receipt = new Receipt();
            ReceiptDetail receiptDetail = new ReceiptDetail();
            receiptDetail.HuId = hu.HuId;
            receiptDetail.ReceivedQty = qty;
            receiptDetail.Receipt = receipt;

            #region 找Out的OrderLocTrans,填充MaterialFulshBack
            IList<OrderLocationTransaction> orderLocTransList = this.orderLocationTransactionMgrE.GetOrderLocationTransaction(orderDetail.Id);
            foreach (OrderLocationTransaction orderLocTrans in orderLocTransList)
            {
                if (orderLocTrans.IOType == BusinessConstants.IO_TYPE_OUT)
                {
                    MaterialFlushBack material = new MaterialFlushBack();
                    material.OrderLocationTransaction = orderLocTrans;
                    if (orderLocTrans.UnitQty != 0)
                    {
                        material.Qty = qty;
                    }
                    receiptDetail.AddMaterialFlushBack(material);
                }
                else
                {
                    receiptDetail.OrderLocationTransaction = this.orderLocationTransactionMgrE.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_IN)[0];
                }
            }
            #endregion
            receipt.AddReceiptDetail(receiptDetail);

            this.orderManager.ReceiveOrder(receipt, this.userMgrE.GetMonitorUser());
            #endregion
        }