Exemplo n.º 1
0
        public void AddMaterialFlushBack(MaterialFlushBack materialFlushBack)
        {
            if (this._materialFlushBack == null)
            {
                this._materialFlushBack = new List<MaterialFlushBack>();
            }

            this._materialFlushBack.Add(materialFlushBack);
        }
        public IList<MaterialFlushBack> AssignMaterialFlushBack(MaterialFlushBack sourceMaterialFlushBack, IList<OrderLocationTransaction> inOrderLocationTransactionList)
        {
            Hu hu = null;
            if (sourceMaterialFlushBack.HuId != null && sourceMaterialFlushBack.HuId.Trim() != string.Empty)
            {
                hu = this.huMgr.CheckAndLoadHu(sourceMaterialFlushBack.HuId);
            }

            IList<MaterialFlushBack> materialFlushBackList = new List<MaterialFlushBack>();
            decimal theoryTotalQty = 0;  //理论消耗量
            if (inOrderLocationTransactionList != null && inOrderLocationTransactionList.Count > 0)
            {
                foreach (OrderLocationTransaction inOrderLocationTransaction in inOrderLocationTransactionList)
                {
                    IList<OrderLocationTransaction> orderLocationTransactionList = this.orderLocationTransactionMgr.GetOrderLocationTransaction(inOrderLocationTransaction.OrderDetail.Id, BusinessConstants.IO_TYPE_OUT);
                    if (orderLocationTransactionList != null && orderLocationTransactionList.Count > 0)
                    {
                        foreach (OrderLocationTransaction orderLocationTransaction in orderLocationTransactionList)
                        {
                            if (orderLocationTransaction.Item.Code == sourceMaterialFlushBack.RawMaterial.Code)
                            {
                                if (sourceMaterialFlushBack.Operation == 0
                                    || orderLocationTransaction.Operation == sourceMaterialFlushBack.Operation)
                                {
                                    if ((hu == null)   //按数量分配
                                        || (hu != null && (hu.Version == null || hu.Version.Trim() == string.Empty)) //按条码分配
                                        || (hu != null && hu.Version != null && hu.Version.Trim() != string.Empty && hu.Version == orderLocationTransaction.ItemVersion))  //按条码和工程状态分配
                                    {
                                        MaterialFlushBack materialFlushBack = new MaterialFlushBack();
                                        materialFlushBack.OrderDetail = inOrderLocationTransaction.OrderDetail;
                                        materialFlushBack.OrderLocationTransaction = orderLocationTransaction;
                                        materialFlushBack.Operation = orderLocationTransaction.Operation;
                                        materialFlushBack.RawMaterial = orderLocationTransaction.Item;
                                        materialFlushBack.Uom = orderLocationTransaction.OrderDetail.Uom;
                                        materialFlushBack.HuId = sourceMaterialFlushBack.HuId;
                                        if (inOrderLocationTransaction.OrderDetail.OrderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                                        {
                                            materialFlushBack.Qty = inOrderLocationTransaction.CurrentReceiveQty * orderLocationTransaction.UnitQty;
                                        }
                                        else
                                        {
                                            //生产,废品和次品都消耗原材料
                                            materialFlushBack.Qty =
                                                (inOrderLocationTransaction.CurrentReceiveQty + inOrderLocationTransaction.CurrentRejectQty + inOrderLocationTransaction.CurrentScrapQty)
                                                    * orderLocationTransaction.UnitQty;
                                        }
                                        theoryTotalQty += materialFlushBack.Qty;

                                        materialFlushBackList.Add(materialFlushBack);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            int FlushBackListCount = materialFlushBackList.Count;

            if (FlushBackListCount == 0)
            {
                throw new BusinessErrorException("Order.Error.ReceiveOrder.AssignMaterial", sourceMaterialFlushBack.RawMaterial.Code);
            }

            EntityPreference entityPreference = entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_AMOUNT_DECIMAL_LENGTH);
            int decimalLength = int.Parse(entityPreference.Value);

            decimal remainFlushBack = sourceMaterialFlushBack.Qty;
            for (int i = 0; i < FlushBackListCount; i++)
            {
                //分配的消耗量等于实际的总消耗量 / 理论总消耗量 * 单个物料的消耗量,最后一条用减法处理
                if (i < FlushBackListCount - 1)
                {
                    materialFlushBackList[i].Qty = Math.Round(sourceMaterialFlushBack.Qty / theoryTotalQty * materialFlushBackList[i].Qty, decimalLength, MidpointRounding.AwayFromZero); ;
                    remainFlushBack = remainFlushBack - materialFlushBackList[i].Qty;
                }
                else
                {
                    materialFlushBackList[i].Qty = remainFlushBack;
                }
            }
            //foreach(MaterialFlushBack materialFlushBack in materialFlushBackList)
            //{

            //    materialFlushBack.Qty = sourceMaterialFlushBack.Qty / theoryTotalQty * materialFlushBack.Qty;
            //}

            return materialFlushBackList;
        }
        public IList<MaterialFlushBack> AssignMaterialFlushBack(MaterialFlushBack sourceMaterialFlushBack, IList<OrderDetail> orderDetailList)
        {
            if (orderDetailList != null && orderDetailList.Count > 0)
            {
                IList<OrderLocationTransaction> targetInOrderLocationTransactionList = new List<OrderLocationTransaction>();

                foreach (OrderDetail orderDetail in orderDetailList)
                {
                    IList<OrderLocationTransaction> inOrderLocationTransactionList = this.orderLocationTransactionMgr.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_IN);

                    //入库(in)的OrderLocationTransaction只可能有一个
                    inOrderLocationTransactionList[0].CurrentReceiveQty = orderDetail.CurrentReceiveQty;
                    inOrderLocationTransactionList[0].CurrentRejectQty = orderDetail.CurrentRejectQty;
                    inOrderLocationTransactionList[0].CurrentScrapQty = orderDetail.CurrentScrapQty;

                    targetInOrderLocationTransactionList.Add(inOrderLocationTransactionList[0]);
                }

                return AssignMaterialFlushBack(sourceMaterialFlushBack, targetInOrderLocationTransactionList);
            }

            return null;
        }
Exemplo n.º 4
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.º 5
0
    private void ReceiveRender(object sender, EventArgs e)
    {
        bool isOddCreateHu = (bool)sender;

        IList<ReceiptDetail> receiptDetailList = this.ucDetailList.PopulateReceiptDetailList();
        bool isReceiptOneItem = bool.Parse(TheEntityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_IS_RECEIPT_ONE_ITEM).Value);
        if (this.ModuleType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION && this.ModuleSubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_ADJ && isReceiptOneItem && receiptDetailList.Count > 1)
        {
            ShowErrorMessage("MasterData.Receipt.One.Item");
            return;
        }
        IList<OrderLocationTransaction> inLocTransList = new List<OrderLocationTransaction>();

        foreach (ReceiptDetail receiptDetail in receiptDetailList)
        {
            OrderLocationTransaction ol = receiptDetail.OrderLocationTransaction;
            ol.CurrentReceiveQty = ol.UnitQty * (receiptDetail.ReceivedQty.HasValue ? (decimal)receiptDetail.ReceivedQty : 0);
            ol.CurrentRejectQty = ol.UnitQty * (receiptDetail.RejectedQty.HasValue ? (decimal)receiptDetail.RejectedQty : 0);
            ol.CurrentScrapQty = ol.UnitQty * (receiptDetail.ScrapQty.HasValue ? (decimal)receiptDetail.ScrapQty : 0);
            inLocTransList.Add(ol);
        }

        IList<OrderLocationTransaction> orderLocTransList = this.ucInLocTransList.InLocTransList;  //投入原材料List
        IList<OrderLocationTransaction> outLocTransList = new List<OrderLocationTransaction>();     //非零原材料List
        IList<OrderLocationTransaction> rwoLocTransList = new List<OrderLocationTransaction>();    //返工成品List

        foreach (OrderLocationTransaction inLocTrans in this.ucInLocTransList.InLocTransList)
        {
            if (inLocTrans.BomDetail == null)
            {
                rwoLocTransList.Add(inLocTrans);
            }
            else if (inLocTrans.CurrentReceiveQty != 0)
            {
                outLocTransList.Add(inLocTrans);
            }
        }

        try
        {

            #region 正常生产收货
            if (outLocTransList.Count > 0)
            {
                foreach (ReceiptDetail receiptDetail in receiptDetailList)
                {
                    foreach (OrderLocationTransaction orderLocationTransaction in outLocTransList)
                    {
                        MaterialFlushBack materialFlushBack = new MaterialFlushBack();
                        materialFlushBack.RawMaterial = orderLocationTransaction.Item;
                        materialFlushBack.Uom = orderLocationTransaction.OrderDetail.Uom;
                        materialFlushBack.Operation = orderLocationTransaction.Operation;
                        materialFlushBack.Qty = orderLocationTransaction.CurrentReceiveQty;
                        IList<MaterialFlushBack> materialFlushBackList = TheMaterialFlushBackMgr.AssignMaterialFlushBack(materialFlushBack, inLocTransList);
                        foreach (MaterialFlushBack m in materialFlushBackList)
                        {
                            if (m.OrderLocationTransaction.OrderDetail.Id == receiptDetail.OrderLocationTransaction.OrderDetail.Id)
                            {
                                if (m.OrderLocationTransaction.UnitQty != 0)
                                {
                                    m.Qty = m.Qty / m.OrderLocationTransaction.UnitQty;
                                }
                                materialFlushBack = m;
                                receiptDetail.AddMaterialFlushBack(materialFlushBack);
                                break;
                            }
                        }
                    }
                }
            }
            #endregion

            #region 新品收货
            if (this.IsNewItem)
            {
                IList<TransformerDetail> transformerDetailList = this.ucNewItemInLocTransList.NewItemInLocTransList; //新品原材料List
                if (transformerDetailList.Count > 0)
                {
                    foreach (ReceiptDetail receiptDetail in receiptDetailList)
                    {
                        foreach (TransformerDetail transformerDetail in transformerDetailList)
                        {

                            MaterialFlushBack materialFlushBack = new MaterialFlushBack();
                            LocationLotDetail newItemLocationLotDetail = TheLocationLotDetailMgr.LoadLocationLotDetail(transformerDetail.LocationLotDetId);
                            materialFlushBack.RawMaterial = newItemLocationLotDetail.Item;
                            materialFlushBack.Uom = newItemLocationLotDetail.Hu.Uom;
                            materialFlushBack.Qty = newItemLocationLotDetail.Qty;
                            materialFlushBack.HuId = newItemLocationLotDetail.Hu.HuId;

                            IList<MaterialFlushBack> materialFlushBackList = TheMaterialFlushBackMgr.AssignMaterialFlushBack(materialFlushBack, inLocTransList);
                            foreach (MaterialFlushBack m in materialFlushBackList)
                            {
                                if (m.OrderLocationTransaction.OrderDetail.Id == receiptDetail.OrderLocationTransaction.OrderDetail.Id)
                                {
                                    if (m.OrderLocationTransaction.UnitQty != 0)
                                    {
                                        m.Qty = m.Qty / m.OrderLocationTransaction.UnitQty;
                                    }
                                    materialFlushBack = m;
                                    receiptDetail.AddMaterialFlushBack(materialFlushBack);
                                    break;
                                }
                            }

                        }
                    }
                }
            }
            #endregion

            #region 返工收货
            if (rwoLocTransList.Count > 0)
            {
                foreach (OrderLocationTransaction rwoOrderLocTran in rwoLocTransList)
                {
                    foreach (ReceiptDetail receiptDetail in receiptDetailList)
                    {

                        if (receiptDetail.OrderLocationTransaction.Item.Code == rwoOrderLocTran.Item.Code)
                        {
                            MaterialFlushBack materialFlushBack = new MaterialFlushBack();
                            materialFlushBack.RawMaterial = rwoOrderLocTran.Item;
                            materialFlushBack.Uom = rwoOrderLocTran.OrderDetail.Uom;
                            materialFlushBack.Operation = rwoOrderLocTran.Operation;
                            materialFlushBack.Qty = rwoOrderLocTran.CurrentReceiveQty;
                            IList<MaterialFlushBack> materialFlushBackList = TheMaterialFlushBackMgr.AssignMaterialFlushBack(materialFlushBack, inLocTransList);
                            foreach (MaterialFlushBack m in materialFlushBackList)
                            {
                                if (m.OrderLocationTransaction.OrderDetail.Id == receiptDetail.OrderLocationTransaction.OrderDetail.Id)
                                {
                                    if (m.OrderLocationTransaction.UnitQty != 0)
                                    {
                                        m.Qty = m.Qty / m.OrderLocationTransaction.UnitQty;
                                    }
                                    materialFlushBack = m;
                                    receiptDetail.AddMaterialFlushBack(materialFlushBack);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            Receipt receipt = TheOrderMgr.ReceiveOrder(receiptDetailList, this.CurrentUser, null, null, null, true, isOddCreateHu);
            OrderHead orderHead = TheOrderHeadMgr.LoadOrderHead(this.OrderNo);

            if (RefreshListEvent != null)
            {
                this.RefreshListEvent(new object[] { receipt.ReceiptNo, orderHead.NeedPrintReceipt }, e);
            }

        }
        catch (BusinessErrorException ex)
        {
            this.ShowErrorMessage(ex);
        }
    }
        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();
            }
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
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
        }