Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        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.criteriaMgr.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.huMgr.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.orderLocationTransactionMgr.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_IN)[0];
                                receiptDetail.HuId        = hu.HuId;
                                receiptDetail.ReceivedQty = qty;
                                receiptDetail.Receipt     = receipt;
                                receiptDetail.LotNo       = hu.LotNo;

                                #region 找Out的OrderLocTrans,填充MaterialFulshBack
                                IList <OrderLocationTransaction> orderLocTransList = this.orderLocationTransactionMgr.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.userMgr.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.huMgr.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();
            }
        }