private Hu CreateItemHu(string barCode, OrderDetail orderDetail, string lotNo, DateTime manufactureDate)
        {
            Item    item = orderDetail.Item;
            decimal qty  = 1;

            Hu hu = new Hu();

            hu.HuId = barCode;
            hu.Item = item;
            hu.Uom  = orderDetail.Uom;  //用Flow单位
            #region 单位用量
            if (item.Uom.Code != orderDetail.Uom.Code)
            {
                hu.UnitQty = this.uomConversionMgr.ConvertUomQty(item, orderDetail.Uom, 1, item.Uom);   //单位用量
            }
            else
            {
                hu.UnitQty = 1;
            }
            #endregion
            hu.QualityLevel     = BusinessConstants.CODE_MASTER_ITEM_QUALITY_LEVEL_VALUE_1;
            hu.Qty              = qty;
            hu.UnitCount        = 1;
            hu.LotNo            = lotNo;
            hu.LotSize          = 1;
            hu.ManufactureDate  = manufactureDate;
            hu.ManufactureParty = orderDetail.OrderHead.PartyFrom;
            hu.CreateUser       = this.userMgr.GetMonitorUser();
            hu.CreateDate       = DateTime.Now;
            hu.Status           = BusinessConstants.CODE_MASTER_HU_STATUS_VALUE_CREATE;

            this.huMgr.CreateHu(hu);

            return(hu);
        }
Esempio n. 2
0
    public IList <Hu> GetHuList()
    {
        IList <Hu> huList = new List <Hu>();

        if (GV_List.Rows.Count > 0)
        {
            foreach (GridViewRow gvr in GV_List.Rows)
            {
                Label   lblHuId  = (Label)gvr.FindControl("lblHuId");
                Label   lblLotNo = (Label)gvr.FindControl("lblLotNo");
                TextBox tbQty    = (TextBox)gvr.FindControl("tbQty");

                Hu hu = new Hu();
                hu.HuId  = lblHuId.Text;
                hu.LotNo = lblLotNo.Text;
                hu.Qty   = tbQty.Text.Trim() != string.Empty ? decimal.Parse(tbQty.Text.Trim()) : 0;

                if (hu.Qty != 0)
                {
                    huList.Add(hu);
                }
            }
        }
        return(huList);
    }
Esempio n. 3
0
        public IList <Hu> CloneHu(string huId, decimal uintCount, int count, User user)
        {
            IList <Hu> huList      = new List <Hu>();
            Hu         oldHu       = this.LoadHu(huId);
            DateTime   dateTimeNow = DateTime.Now;

            int i = 0;

            while (i < count)
            {
                Hu huTemplate = CloneHelper.DeepClone <Hu>(oldHu);
                huTemplate.LotSize   = uintCount;
                huTemplate.UnitCount = uintCount;
                huTemplate.Qty       = uintCount;
                #region 百利得定制条码生成规则,如果是以零件号开头的为原材料条码,不是以零件号开头的为成品条码
                if (oldHu.HuId.StartsWith(oldHu.Item.Code))
                {
                    huTemplate.HuId = this.numberControlMgr.CloneRMHuId(oldHu.HuId, uintCount);
                }
                else
                {
                    huTemplate.HuId = this.numberControlMgr.CloneFGHuId(oldHu.HuId);
                }
                #endregion
                huTemplate.CreateDate = dateTimeNow;
                huTemplate.CreateUser = user;
                huTemplate.Status     = BusinessConstants.CODE_MASTER_HU_STATUS_VALUE_CREATE;

                this.CreateHu(huTemplate);
                huList.Add(huTemplate);
                i++;
            }

            return(huList);
        }
Esempio n. 4
0
        protected override void ExecuteSubmit(Resolver resolver)
        {
            IList <Hu> huList = new List <Hu>();

            if (resolver.Transformers != null)
            {
                foreach (Transformer transformer in resolver.Transformers)
                {
                    if (transformer.TransformerDetails != null)
                    {
                        foreach (TransformerDetail transformerDetail in transformer.TransformerDetails)
                        {
                            Hu hu = huMgr.LoadHu(transformerDetail.HuId);
                            huList.Add(hu);
                        }
                    }
                }
            }
            if (huList.Count > 0)
            {
                orderMgr.CreateOrder(resolver.Code, resolver.UserCode, huList);
                resolver.Result       = languageMgr.TranslateMessage("Order.Reuse.Successfully", resolver.UserCode);
                resolver.Transformers = null;
                resolver.Command      = BusinessConstants.CS_BIND_VALUE_TRANSFORMER;
            }
            else
            {
                throw new BusinessErrorException("Common.Business.Error.OprationFailed");
            }
        }
Esempio n. 5
0
        protected override void SetDetail(Resolver resolver)
        {
            List <string> flowTypes = new List <string>();

            flowTypes.Add(BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION);
            bool isHaslocationLotDetail = locationLotDetailMgr.CheckHuLocationExist(resolver.Input);

            if (!isHaslocationLotDetail)
            {
                throw new BusinessErrorException("Hu.Error.NoInventory", resolver.Input);
            }
            Hu       hu       = huMgr.CheckAndLoadHu(resolver.Input);
            FlowView flowView = null;

            //如果是扫描Bin,根据Hu和Bin匹配出flow
            if (resolver.CodePrefix == null || resolver.CodePrefix.Trim() == string.Empty)
            {
                //确定flow和flowView
                flowView = flowMgr.CheckAndLoadFlowView(null, resolver.UserCode, string.Empty, null, hu, flowTypes);
                setBaseMgr.FillResolverByFlow(resolver, flowView.Flow);
            }
            //如果已经确定了Flow
            else
            {
                //根据Flow和Hu匹配出flowView
                flowView = flowMgr.CheckAndLoadFlowView(resolver.Code, null, null, null, hu, flowTypes);
            }
            setDetailMgr.MatchHuByFlowView(resolver, flowView, hu);
        }
Esempio n. 6
0
    public void PrintCallBack()
    {
        if (this.GV_List.Rows != null && this.GV_List.Rows.Count > 0)
        {
            IList <Hu> huList = new List <Hu>();

            foreach (GridViewRow row in this.GV_List.Rows)
            {
                CheckBox checkBoxGroup = row.FindControl("CheckBoxGroup") as CheckBox;
                if (checkBoxGroup.Checked)
                {
                    HiddenField hfHuId = row.FindControl("hfHuId") as HiddenField;

                    Hu hu = TheHuMgr.LoadHu(hfHuId.Value);
                    huList.Add(hu);
                }
            }

            this.PrintEvent(huList, null);

            return;
        }

        this.PrintEvent(null, null);
    }
Esempio n. 7
0
        protected override void SetDetail(Resolver resolver)
        {
            Hu hu = huMgr.CheckAndLoadHu(resolver.Input);

            if (this.locationMgr.IsHuOcuppyByPickList(resolver.Input))
            {
                throw new BusinessErrorException("Order.Error.PickUp.HuOcuppied", resolver.Input);
            }
            if (resolver.BinCode == string.Empty || resolver.BinCode == null)
            {
                throw new BusinessErrorException("Warehouse.PutAway.PlzScanBin");
            }
            if (hu.StorageBin != null && hu.StorageBin.Trim() != string.Empty && hu.StorageBin == resolver.BinCode)
            {
                throw new BusinessErrorException("Warehouse.PutAway.AlreadyInThisBin");
            }
            //校验Bin
            StorageBin        bin = storageBinMgr.CheckAndLoadStorageBin(resolver.BinCode);
            LocationLotDetail locationLotDetail = locationLotDetailMgr.CheckLoadHuLocationLotDetail(resolver.Input, string.Empty, bin.Area.Location.Code);

            locationLotDetail.NewStorageBin = bin;
            TransformerDetail transformerDetail = TransformerHelper.ConvertLocationLotDetailToTransformerDetail(locationLotDetail, true);

            resolver.AddTransformerDetail(transformerDetail);
        }
Esempio n. 8
0
    public void HuInput(Hu newHu)
    {
        IList <Hu> huList = this.GetHuList();

        huList.Add(newHu);

        this.GV_List.DataSource = huList;
        this.GV_List.DataBind();
    }
Esempio n. 9
0
        public Hu CheckAndLoadHu(string huId)
        {
            Hu hu = this.LoadHu(huId);

            if (hu == null)
            {
                throw new BusinessErrorException("Hu.Error.HuIdNotExist", huId);
            }

            return(hu);
        }
Esempio n. 10
0
        protected override void ExecutePrint(Resolver resolver)
        {
            IList <Hu> huList = new List <Hu>();
            Hu         hu     = huMgr.CheckAndLoadHu(resolver.Code);

            huList.Add(hu);

            IList <object> huDetailObj = new List <object>();

            huDetailObj.Add(huList);
            resolver.PrintUrl = reportMgr.WriteToFile("BarCode.xls", huDetailObj, "BarCode.xls");
        }
        private IList <Hu> ResolveAndCreateHu(IList <DssImportHistory> dssImportHistoryList, OrderDetail orderDetail)
        {
            IList <Hu> huList = new List <Hu>();

            if (dssImportHistoryList != null && dssImportHistoryList.Count > 0)
            {
                foreach (var dssImportHistory in dssImportHistoryList)
                {
                    Hu hu = this.ResolveAndCreateHu(dssImportHistory.HuId, orderDetail, dssImportHistory.Qty);
                    huList.Add(hu);
                }
            }
            return(huList);
        }
Esempio n. 12
0
    private void HuScan(string huId)
    {
        Hu hu = TheHuMgr.LoadHu(huId);

        if (hu != null)
        {
            this.HuScan(hu);
        }
        else
        {
            ShowErrorMessage("Hu.Not.Exist");
            this.InitialHuScan();
            return;
        }
    }
Esempio n. 13
0
        public string Print(string huId, string huTemplate)
        {
            Hu hu = base.genericMgr.FindById <Hu>(huId);
            IList <PrintHu> huList = new List <PrintHu>();

            PrintHu printHu = Mapper.Map <Hu, PrintHu>(hu);

            printHu.ManufacturePartyDescription = base.genericMgr.FindById <Supplier>(hu.ManufactureParty).Name;
            huList.Add(printHu);
            IList <object> data = new List <object>();

            data.Add(huList);
            data.Add(CurrentUser.FullName);
            return(reportGen.WriteToFile(huTemplate, data));
        }
Esempio n. 14
0
        private void ProcessOrderLocationTransactionIn(MesScmsTableIndex mesScmsTableIndex)
        {
            #region 物料消耗
            IList <MesScmsStationBox> stationBoxList = mesScmsStationBoxMgr.GetUpdateMesScmsStationBox();

            if (stationBoxList != null && stationBoxList.Count > 0)
            {
                foreach (MesScmsStationBox stationBox in stationBoxList)
                {
                    try
                    {
                        Hu hu = huMgr.CheckAndLoadHu(stationBox.HuId);
                        OrderLocationTransaction olt = orderLocationTransactionMgr.GetOrderLocationTransaction(stationBox.OrderNo, stationBox.TagNo, hu.Item.Code);
                        if (olt == null)
                        {
                            //没找到,算传错了,记错误日志,更新标记
                            log.Error(stationBox.Id + " not found match order");
                        }
                        else
                        {
                            //货架上没有了,跳过
                            if (olt.Cartons == 0)
                            {
                                log.Error(stationBox.Id + "," + hu.Item.Code + "," + "current carton zero");
                            }
                            else
                            {
                                olt.Cartons = olt.Cartons - 1;
                                this.orderLocationTransactionMgr.UpdateOrderLocationTransaction(olt);

                                hu.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE;
                                huMgr.UpdateHu(hu);
                            }
                        }
                        mesScmsStationBoxMgr.Complete(stationBox);
                    }
                    catch (Exception e)
                    {
                        this.CleanSession();
                        log.Error(stationBox.Id + " complete exception", e);
                        continue;
                    }
                }
            }
            #endregion

            mesScmsTableIndexMgr.Complete(mesScmsTableIndex);
        }
Esempio n. 15
0
        /// <summary>
        /// 仅校验投料的物料号,库位是否一致,不校验单位单包装等信息
        /// todo:不允许投入的又有数量又有Hu //可以前台控制
        /// </summary>
        /// <param name="resolver"></param>
        protected override void SetDetail(Resolver resolver)
        {
            if (resolver.CodePrefix == string.Empty)
            {
                throw new BusinessErrorException("Common.Business.Error.ScanProductLineFirst");
            }
            LocationLotDetail locationLotDetail = locationLotDetailMgr.CheckLoadHuLocationLotDetail(resolver.Input, resolver.UserCode);
            TransformerDetail transformerDetail = TransformerHelper.ConvertLocationLotDetailToTransformerDetail(locationLotDetail, false);
            var query = resolver.Transformers.Where
                            (t => (t.ItemCode == transformerDetail.ItemCode && t.LocationCode == transformerDetail.LocationCode));

            if (query.Count() < 1)
            {
                throw new BusinessErrorException("Warehouse.HuMatch.NotMatch", transformerDetail.HuId);
            }

            #region 先进先出校验
            Flow flow = flowMgr.CheckAndLoadFlow(resolver.Code);
            if (flow.IsGoodsReceiveFIFO)
            {
                Hu             hu       = huMgr.CheckAndLoadHu(resolver.Input);
                IList <string> huIdList = new List <string>();
                if (resolver.Transformers != null && resolver.Transformers.Count > 0)
                {
                    foreach (Transformer transformer in resolver.Transformers)
                    {
                        if (transformer.TransformerDetails != null && transformer.TransformerDetails.Count > 0)
                        {
                            foreach (TransformerDetail det in transformer.TransformerDetails)
                            {
                                if (det.CurrentQty != decimal.Zero)
                                {
                                    huIdList.Add(det.HuId);
                                }
                            }
                        }
                    }
                }
                string maxLot = setDetailMgr.CheckFIFO(hu, huIdList);
                if (maxLot != string.Empty && maxLot != null)
                {
                    throw new BusinessErrorException("FIFO.ERROR", hu.HuId, maxLot);
                }
            }
            #endregion

            resolver.AddTransformerDetail(transformerDetail);
        }
        private void writeContent(string userName, int pageIndex, int num, Hu hu)
        {
            if (hu.PrintCount > 1)
            {
                this.SetRowCell(pageIndex, 1, 4, "(R)", num);
            }
            hu.PrintCount += 1;


            //hu id内容
            string barCode = Utility.BarcodeHelper.GetBarcodeStr(hu.HuId, this.barCodeFontName);

            this.SetRowCell(pageIndex, 0, 0, barCode, num);
            //hu id内容
            this.SetRowCell(pageIndex, 1, 0, hu.HuId, num);
            //PRINTED DATE:内容
            this.SetRowCell(pageIndex, 2, 3, DateTime.Now.ToString("MM/dd/yy"), num);
        }
Esempio n. 17
0
        public static TransformerDetail ConvertHuToTransformerDetail(Hu hu)
        {
            TransformerDetail transformerDetail = new TransformerDetail();

            transformerDetail.ItemCode        = hu.Item.Code;
            transformerDetail.ItemDescription = hu.Item.Description;
            transformerDetail.UomCode         = hu.Uom.Code;
            transformerDetail.UnitCount       = hu.UnitCount;
            transformerDetail.HuId            = hu.HuId;
            transformerDetail.LotNo           = hu.LotNo;
            transformerDetail.Qty             = hu.Qty;
            transformerDetail.CurrentQty      = hu.Qty;
            transformerDetail.Status          = hu.Status;
            transformerDetail.LocationCode    = hu.Location == null ? string.Empty : hu.Location;
            transformerDetail.StorageBinCode  = hu.StorageBin == null ? string.Empty : hu.StorageBin;

            return(transformerDetail);
        }
Esempio n. 18
0
        public List <AppData> HuellasTemplate()
        {
            List <AppData> TemLis = new List <AppData>();
            DataTable      DT     = objDato.TodasHuellas();

            foreach (DataRow Row in DT.Rows)
            {
                string[] Hu;
                Hu = Convert.ToString(Row[1]).Split('-');
                Hu = Hu.Take(Hu.Length - 1).ToArray();
                byte[]        Hub = Array.ConvertAll(Hu, byte.Parse);
                Stream        D   = new MemoryStream(Hub);
                DPFP.Template Tem = new DPFP.Template(D);
                TemLis.Add(new AppData {
                    Template = Tem, IDCliente = Convert.ToInt32(Row[0])
                });
            }
            return(TemLis);
        }
Esempio n. 19
0
    private void HuInput(string huId)
    {
        try
        {
            if (MiscOrder.MiscOrderDetails != null)
            {
                foreach (MiscOrderDetail miscOrderDetail in MiscOrder.MiscOrderDetails)
                {
                    if (miscOrderDetail.HuId == huId)
                    {
                        ShowErrorMessage("MasterData.MiscOrder.Location.Exists");
                    }
                }
            }
            if (this.ModuleType != BusinessConstants.CODE_MASTER_MISC_ORDER_TYPE_VALUE_GR)
            {
                if (this.tbMiscOrderLocation.Text.Trim() == string.Empty)
                {
                    ShowErrorMessage("MasterData.MiscOrder.Location.Empty");
                    return;
                }
                IList <LocationLotDetail> locationLotDetailList = TheLocationLotDetailMgr.GetHuLocationLotDetail(this.tbMiscOrderLocation.Text.Trim(), huId);
                if (locationLotDetailList.Count == 0)
                {
                    ShowErrorMessage("MasterData.MiscOrder.Location.NotExists.Hu", huId);
                }
            }
            Hu hu = TheHuMgr.LoadHu(huId);
            MiscOrderDetail newMiscOrderDetail = new MiscOrderDetail();
            newMiscOrderDetail.HuId  = huId;
            newMiscOrderDetail.Item  = hu.Item;
            newMiscOrderDetail.LotNo = hu.LotNo;
            newMiscOrderDetail.Qty   = hu.Qty * hu.UnitQty;
            MiscOrder.AddMiscOrderDetail(newMiscOrderDetail);

            BindMiscOrderDetails();
        }
        catch (BusinessErrorException ex)
        {
            ShowErrorMessage(ex);
        }
    }
Esempio n. 20
0
    protected void tbHuId_TextChanged(object sender, EventArgs e)
    {
        this.lblMessage.Text = string.Empty;

        TextBox    _editControl = (TextBox)sender;
        string     huId         = _editControl.Text.Trim().ToUpper();
        IList <Hu> huList       = this.GetHuList();
        Hu         hu           = TheHuMgr.LoadHu(huId);

        if (hu != null && huList.IndexOf(hu) < 0)
        {
            huList.Add(hu);
        }
        else
        {
            this.lblMessage.Text = Resources.Language.MasterDataHuNotExist + " (" + huId + ")";
        }

        this.InitialHuIdInput(huList);
    }
Esempio n. 21
0
        public DPFP.Template RegresarHuellaTemp()
        {
            string[] Hu;
            objDato.IDUsuario = IDUsuario;
            Hu = objDato.VeriHuella().Split('-');
            Hu = Hu.Take(Hu.Length - 1).ToArray();

            byte[] Hub = Array.ConvertAll(Hu, byte.Parse);

            /*int cont = 0;
             * foreach (string H in Hu)
             * {
             *  Hub[cont] = Convert.ToByte(H);
             *  cont++;
             * }*/
            Stream D = new MemoryStream(Hub);

            DPFP.Template Tem = new DPFP.Template(D);
            return(Tem);
        }
Esempio n. 22
0
 protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         PickListDetail         pickListDetail     = (PickListDetail)e.Row.DataItem;
         Hu_HuInput             ucHuInput          = (Hu_HuInput)e.Row.FindControl("ucHuInput");
         TextBox                tbShipQty          = (TextBox)e.Row.FindControl("tbShipQty");
         IList <PickListResult> pickListResultList = ThePickListResultMgr.GetPickListResult(pickListDetail);
         if (pickListResultList != null && pickListResultList.Count > 0)
         {
             foreach (PickListResult pickListResult in pickListResultList)
             {
                 string huId  = pickListResult.LocationLotDetail.Hu.HuId;
                 Hu     newHu = TheHuMgr.LoadHu(huId);
                 newHu.Qty = pickListResult.Qty;
                 ucHuInput.HuInput(newHu);
                 tbShipQty.Text = ucHuInput.SumQty().ToString("F2");
             }
         }
     }
 }
Esempio n. 23
0
    private IList <Hu> GetHuList()
    {
        IList <Hu> huList = new List <Hu>();

        foreach (GridViewRow gvr in GV_List.Rows)
        {
            Label _displayControl = (Label)gvr.FindControl("lblHuId");

            string huId = string.Empty;
            if (_displayControl.Visible)
            {
                huId = _displayControl.Text.Trim();
                Hu hu = TheHuMgr.LoadHu(huId);
                if (hu != null)
                {
                    huList.Add(hu);
                }
            }
        }

        return(huList);
    }
        private Hu ResolveAndCreateHu(string barCode, OrderDetail orderDetail, decimal qty)
        {
            string[] splitedBarcode  = BarcodeHelper.SplitFGBarcode(barCode);
            Item     item            = orderDetail.Item;
            string   lotNo           = splitedBarcode[2];
            DateTime manufactureDate = LotNoHelper.ResolveLotNo(lotNo);


            Hu hu = new Hu();

            hu.HuId = barCode;
            hu.Item = item;
            hu.Uom  = orderDetail.Uom;  //用Flow单位
            #region 单位用量
            if (item.Uom.Code != orderDetail.Uom.Code)
            {
                hu.UnitQty = this.uomConversionMgr.ConvertUomQty(item, orderDetail.Uom, 1, item.Uom);   //单位用量
            }
            else
            {
                hu.UnitQty = 1;
            }
            #endregion
            hu.QualityLevel     = BusinessConstants.CODE_MASTER_ITEM_QUALITY_LEVEL_VALUE_1;
            hu.Qty              = qty;
            hu.UnitCount        = orderDetail.UnitCount;
            hu.LotNo            = lotNo;
            hu.LotSize          = qty;
            hu.ManufactureDate  = manufactureDate;
            hu.ManufactureParty = orderDetail.OrderHead.PartyFrom;
            hu.CreateUser       = this.userMgr.GetMonitorUser();
            hu.CreateDate       = DateTime.Now;
            hu.Status           = BusinessConstants.CODE_MASTER_HU_STATUS_VALUE_CREATE;

            this.huMgr.CreateHu(hu);
            this.numberControlMgr.ReverseUpdateHuId(barCode);

            return(hu);
        }
Esempio n. 25
0
        public void CreateReceipt(Receipt receipt, User user, bool isOddCreateHu)
        {
            log.Debug("Start create receipt");
            #region 查找所有的发货项,收货单打印模板,收货差异处理选项
            string      orderType       = null;
            Party       partyFrom       = null;
            Party       partyTo         = null;
            ShipAddress shipFrom        = null;
            ShipAddress shipTo          = null;
            string      dockDescription = null;
            string      receiptTemplate = null;
            string      huTemplate      = null;
            string      grGapTo         = null;
            IList <InProcessLocationDetail> inProcessLocationDetailList = new List <InProcessLocationDetail>();
            if (receipt.InProcessLocations != null && receipt.InProcessLocations.Count > 0)
            {
                foreach (InProcessLocation inProcessLocation in receipt.InProcessLocations)
                {
                    InProcessLocation currentIp = inProcessLocationMgr.LoadInProcessLocation(inProcessLocation.IpNo);
                    if (currentIp.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE)
                    {
                        throw new BusinessErrorException("InProcessLocation.Error.StatusErrorWhenReceive", currentIp.Status, currentIp.IpNo);
                    }

                    if (orderType == null)
                    {
                        orderType = inProcessLocation.OrderType;
                    }

                    //判断OrderHead的PartyFrom是否一致
                    if (partyFrom == null)
                    {
                        partyFrom = inProcessLocation.PartyFrom;
                    }
                    else if (inProcessLocation.PartyFrom.Code != partyFrom.Code)
                    {
                        throw new BusinessErrorException("Order.Error.ReceiveOrder.PartyFromNotEqual");
                    }

                    //判断OrderHead的PartyFrom是否一致
                    if (partyTo == null)
                    {
                        partyTo = inProcessLocation.PartyTo;
                    }
                    else if (inProcessLocation.PartyTo.Code != partyTo.Code)
                    {
                        throw new BusinessErrorException("Order.Error.ReceiveOrder.PartyToNotEqual");
                    }

                    //判断OrderHead的ShipFrom是否一致
                    if (shipFrom == null)
                    {
                        shipFrom = inProcessLocation.ShipFrom;
                    }
                    else if (!AddressHelper.IsAddressEqual(inProcessLocation.ShipFrom, shipFrom))
                    {
                        throw new BusinessErrorException("Order.Error.ReceiveOrder.ShipFromNotEqual");
                    }

                    //判断OrderHead的ShipTo是否一致
                    if (shipTo == null)
                    {
                        shipTo = inProcessLocation.ShipTo;
                    }
                    else if (!AddressHelper.IsAddressEqual(inProcessLocation.ShipTo, shipTo))
                    {
                        throw new BusinessErrorException("Order.Error.ReceiveOrder.ShipToNotEqual");
                    }

                    if (dockDescription == null)
                    {
                        dockDescription = inProcessLocation.DockDescription;
                    }
                    else if (inProcessLocation.DockDescription != dockDescription)
                    {
                        throw new BusinessErrorException("Order.Error.ReceiveOrder.DockDescriptionNotEqual");
                    }

                    //判断收货单打印模板是否一致
                    if (receiptTemplate == null)
                    {
                        receiptTemplate = inProcessLocation.ReceiptTemplate;
                    }
                    else
                    {
                        if (inProcessLocation.ReceiptTemplate != null && inProcessLocation.ReceiptTemplate != receiptTemplate)
                        {
                            throw new BusinessErrorException("Order.Error.ReceiveOrder.ReceiptTemplateNotEqual");
                        }
                    }

                    //判断条码打印模板是否一致
                    if (huTemplate == null)
                    {
                        huTemplate = inProcessLocation.HuTemplate;
                    }
                    else
                    {
                        if (inProcessLocation.HuTemplate != null && inProcessLocation.HuTemplate != huTemplate)
                        {
                            throw new BusinessErrorException("Order.Error.ReceiveOrder.HuTemplateNotEqual");
                        }
                    }

                    #region 查找收货差异处理选项
                    if (grGapTo == null)
                    {
                        grGapTo = inProcessLocation.GoodsReceiptGapTo;
                    }
                    else
                    {
                        if (inProcessLocation.GoodsReceiptGapTo != null && inProcessLocation.GoodsReceiptGapTo != grGapTo)
                        {
                            throw new BusinessErrorException("Order.Error.ReceiveOrder.GoodsReceiptGapToNotEqual");
                        }
                    }
                    #endregion

                    IListHelper.AddRange <InProcessLocationDetail>(
                        inProcessLocationDetailList, this.inProcessLocationDetailMgr.GetInProcessLocationDetail(inProcessLocation));
                }
            }
            #endregion

            IList <ReceiptDetail> targetReceiptDetailList = receipt.ReceiptDetails;
            receipt.ReceiptDetails = null;   //清空Asn明细,稍后填充

            #region 创建收货单Head
            receipt.ReceiptNo       = numberControlMgr.GenerateNumber(BusinessConstants.CODE_PREFIX_RECEIPT);
            receipt.OrderType       = orderType;
            receipt.CreateDate      = DateTime.Now;
            receipt.CreateUser      = user;
            receipt.PartyFrom       = partyFrom;
            receipt.PartyTo         = partyTo;
            receipt.ShipFrom        = shipFrom;
            receipt.ShipTo          = shipTo;
            receipt.DockDescription = dockDescription;
            receipt.ReceiptTemplate = receiptTemplate;
            receipt.IsPrinted       = false;
            receipt.NeedPrint       = false;
            if (receipt.InProcessLocations != null && receipt.InProcessLocations.Count > 0)
            {
                foreach (InProcessLocation inProcessLocation in receipt.InProcessLocations)
                {
                    if (inProcessLocation.NeedPrintReceipt)
                    {
                        receipt.NeedPrint = true;
                        break;
                    }
                }
            }

            this.CreateReceipt(receipt);
            log.Debug("Create receipt " + receipt.ReceiptNo + " head successful");
            #endregion

            #region HU处理/入库操作/创建收货明细
            log.Debug("Start create receipt detail");
            IList <LocationLotDetail> inspectLocationLotDetailList = new List <LocationLotDetail>();
            foreach (ReceiptDetail receiptDetail in targetReceiptDetailList)
            {
                OrderLocationTransaction orderLocationTransaction = receiptDetail.OrderLocationTransaction;
                OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
                OrderHead   orderHead   = orderDetail.OrderHead;

                if (orderHead.CreateHuOption == BusinessConstants.CODE_MASTER_CREATE_HU_OPTION_VALUE_GR &&
                    receiptDetail.HuId == null)         //如果订单设置为收货时创建Hu,但是收货时已经扫描过Hu了,按已扫描处理
                {
                    #region 收货时创建Hu
                    log.Debug("Create receipt detail with generate barcode.");
                    #region 生产本次收货+剩余零头生成Hu
                    decimal oddQty = 0;

                    if (!isOddCreateHu && orderDetail.HuLotSize.HasValue &&
                        orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)    //只有生产支持零头
                    {
                        #region 查找剩余零头 + 本次收货数是否能够生成Hu
                        Hu oddHu = this.CreateHuFromOdd(receiptDetail, user);
                        if (oddHu != null)
                        {
                            log.Debug("Generate barcode using odd qty.");
                            //如果零头生成了Hu,本次收货数会扣减
                            #region 创建Hu
                            IList <Hu> oddHuList = new List <Hu>();
                            oddHuList.Add(oddHu);
                            IList <ReceiptDetail> oddReceiptDetailList = this.receiptDetailMgr.CreateReceiptDetail(receipt, orderLocationTransaction, oddHuList);
                            log.Debug("Generate odd barcode successful.");
                            #endregion

                            #region 入库
                            IList <InventoryTransaction> inventoryTransactionList = this.locationMgr.InventoryIn(oddReceiptDetailList[0], user, receiptDetail.PutAwayBinCode);
                            log.Debug("odd Inventory in successful.");
                            #endregion

                            #region 是否检验
                            if (orderDetail.NeedInspection && orderHead.NeedInspection && orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML)
                            {
                                foreach (InventoryTransaction inventoryTransaction in inventoryTransactionList)
                                {
                                    LocationLotDetail locationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(inventoryTransaction.LocationLotDetailId);
                                    locationLotDetail.CurrentInspectQty = locationLotDetail.Qty;
                                    inspectLocationLotDetailList.Add(locationLotDetail);
                                }
                            }
                            #endregion
                        }
                        #endregion

                        oddQty = receiptDetail.ReceivedQty.HasValue && orderDetail.HuLotSize.HasValue ?
                                 receiptDetail.ReceivedQty.Value % orderDetail.HuLotSize.Value : 0; //收货零头数
                        log.Debug("Receive odd qty is " + oddQty);

                        receiptDetail.ReceivedQty = receiptDetail.ReceivedQty.Value - oddQty; //收货数量凑整
                    }
                    #endregion

                    #region 满包装/零头创建Hu处理
                    if (receiptDetail.ReceivedQty.HasValue ||
                        receiptDetail.RejectedQty.HasValue ||
                        receiptDetail.ScrapQty.HasValue)
                    {
                        //创建Hu
                        IList <Hu> huList = this.huMgr.CreateHu(receiptDetail, user);
                        log.Debug("Create barcode successful.");

                        //创建收货项
                        IList <ReceiptDetail> receiptDetailList = this.receiptDetailMgr.CreateReceiptDetail(receipt, orderLocationTransaction, huList);
                        log.Debug("Create receipt detail successful.");

                        #region 如果还有次品或者废品收货,添加到收货列表
                        if ((receiptDetail.RejectedQty.HasValue && receiptDetail.RejectedQty > 0) ||
                            (receiptDetail.ScrapQty.HasValue && receiptDetail.ScrapQty > 0))
                        {
                            ReceiptDetail rejAndScrapReceiptDetail = new ReceiptDetail();
                            CloneHelper.CopyProperty(receiptDetail, rejAndScrapReceiptDetail);
                            rejAndScrapReceiptDetail.ReceivedQty    = null;
                            rejAndScrapReceiptDetail.PutAwayBinCode = null;
                            rejAndScrapReceiptDetail.Receipt        = receipt;

                            this.receiptDetailMgr.CreateReceiptDetail(rejAndScrapReceiptDetail);

                            receiptDetailList.Add(rejAndScrapReceiptDetail);
                            receipt.AddReceiptDetail(rejAndScrapReceiptDetail);
                        }
                        #endregion

                        foreach (ReceiptDetail huReceiptDetail in receiptDetailList)
                        {
                            #region 匹配ReceiptDetail和InProcessLocationDetail,Copy相关信息
                            if (orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                            {
                                IList <InProcessLocationDetail> matchInProcessLocationDetailList = OrderHelper.FindMatchInProcessLocationDetail(receiptDetail, inProcessLocationDetailList);
                                if (matchInProcessLocationDetailList != null && matchInProcessLocationDetailList.Count > 0)
                                {
                                    if (matchInProcessLocationDetailList.Count > 1)
                                    {
                                        //只有当ASN中包含条码,按数量收货,并收货后创建条码才有可能发生这种情况。
                                        //变态才这么干。
                                        log.Error("只有当ASN中包含条码,按数量收货,并收货后创建条码才有可能发生这种情况。");
                                        throw new BusinessErrorException("你是变态才这么设置。");
                                    }

                                    //如果找到匹配项,只可能有一个
                                    huReceiptDetail.PlannedBill   = matchInProcessLocationDetailList[0].PlannedBill;
                                    huReceiptDetail.IsConsignment = matchInProcessLocationDetailList[0].IsConsignment;
                                    huReceiptDetail.ShippedQty    = matchInProcessLocationDetailList[0].Qty;

                                    this.receiptDetailMgr.UpdateReceiptDetail(huReceiptDetail);
                                }

                                //收货创建HU,分配PlannedAmount,todo:考虑余数
                                huReceiptDetail.PlannedAmount = receiptDetail.PlannedAmount / receiptDetail.ReceivedQty.Value * huReceiptDetail.ReceivedQty.Value;
                            }
                            #endregion

                            #region 入库
                            IList <InventoryTransaction> inventoryTransactionList = this.locationMgr.InventoryIn(huReceiptDetail, user, receiptDetail.PutAwayBinCode);
                            log.Debug("Inventory in successful.");
                            #endregion

                            #region 是否检验
                            if (orderDetail.NeedInspection &&
                                orderHead.NeedInspection &&
                                orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML &&
                                huReceiptDetail.ReceivedQty.HasValue &&
                                huReceiptDetail.ReceivedQty > 0)
                            {
                                foreach (InventoryTransaction inventoryTransaction in inventoryTransactionList)
                                {
                                    if (inventoryTransaction.Location.Code != BusinessConstants.SYSTEM_LOCATION_REJECT)
                                    {
                                        LocationLotDetail locationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(inventoryTransaction.LocationLotDetailId);
                                        locationLotDetail.CurrentInspectQty = inventoryTransaction.Qty;
                                        inspectLocationLotDetailList.Add(locationLotDetail);
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion

                    #region 生产剩余零头处理
                    if (oddQty > 0)
                    {
                        log.Debug("Start handle odd qty.");
                        ReceiptDetail oddReceiptDetail = new ReceiptDetail();
                        CloneHelper.CopyProperty(receiptDetail, oddReceiptDetail);

                        oddReceiptDetail.ReceivedQty = oddQty;
                        oddReceiptDetail.RejectedQty = 0;
                        oddReceiptDetail.ScrapQty    = 0;

                        #region 零头入库
                        oddReceiptDetail.Receipt = receipt;
                        IList <InventoryTransaction> inventoryTransactionList = this.locationMgr.InventoryIn(oddReceiptDetail, user, receiptDetail.PutAwayBinCode);
                        #endregion

                        #region 零头创建收货明细
                        this.receiptDetailMgr.CreateReceiptDetail(oddReceiptDetail);
                        receipt.AddReceiptDetail(oddReceiptDetail);
                        #endregion

                        #region 创建HuOdd
                        LocationLotDetail locationLotDetail = locationLotDetailMgr.LoadLocationLotDetail(inventoryTransactionList[0].LocationLotDetailId);
                        this.huOddMgr.CreateHuOdd(oddReceiptDetail, locationLotDetail, user);
                        #endregion
                        log.Debug("End handle odd qty.");
                    }
                    #endregion

                    #endregion
                }
                else
                {
                    #region 收货时不创建Hu
                    log.Debug("Create receipt detail with no generate barcode.");

                    #region 更新Hu上的OrderNo、ReceiptNo和AntiResloveHu
                    if (receiptDetail.HuId != null && receiptDetail.HuId.Trim() != string.Empty)
                    {
                        Hu   hu        = this.huMgr.LoadHu(receiptDetail.HuId);
                        bool isUpdated = false;

                        if (hu.OrderNo == null || hu.ReceiptNo == null)
                        {
                            if (hu.OrderNo == null)
                            {
                                log.Debug("Update hu OrderNo " + orderHead.OrderNo + ".");
                                hu.OrderNo = orderHead.OrderNo;
                            }

                            if (hu.ReceiptNo == null)
                            {
                                log.Debug("Update hu ReceiptNo " + receipt.ReceiptNo + ".");
                                hu.ReceiptNo = receipt.ReceiptNo;
                            }

                            isUpdated = true;
                        }

                        if (hu.AntiResolveHu == null &&
                            orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT)
                        {
                            hu.AntiResolveHu = orderHead.AntiResolveHu;
                            isUpdated        = true;
                        }

                        if (isUpdated)
                        {
                            this.huMgr.UpdateHu(hu);
                        }
                    }
                    #endregion

                    IList <ReceiptDetail> noCreateHuReceiptDetailList = new List <ReceiptDetail>();

                    #region 匹配ReceiptDetail和InProcessLocationDetail,Copy相关信息
                    log.Debug("Start match ReceiptDetail and InProcessLocationDetail.");
                    if (orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION &&
                        orderHead.SubType != BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_ADJ)     //收货调整已经匹配过InProcessLocationDetail,不需要在匹配
                    {
                        IList <InProcessLocationDetail> matchInProcessLocationDetailList = OrderHelper.FindMatchInProcessLocationDetail(receiptDetail, inProcessLocationDetailList);
                        log.Debug("Find matched InProcessLocationDetailList, count = " + matchInProcessLocationDetailList != null ? matchInProcessLocationDetailList.Count : 0);

                        if (matchInProcessLocationDetailList != null && matchInProcessLocationDetailList.Count == 1)
                        {
                            //一次收货对应一次发货。
                            log.Debug("one ipdet vs one receiptdet.");
                            receiptDetail.PlannedBill   = matchInProcessLocationDetailList[0].PlannedBill;
                            receiptDetail.IsConsignment = matchInProcessLocationDetailList[0].IsConsignment;
                            if (matchInProcessLocationDetailList[0].InProcessLocation.Type == BusinessConstants.CODE_MASTER_INPROCESS_LOCATION_TYPE_VALUE_GAP)
                            {
                                receiptDetail.ShippedQty = 0 - matchInProcessLocationDetailList[0].Qty;
                            }
                            else
                            {
                                receiptDetail.ShippedQty = matchInProcessLocationDetailList[0].Qty;
                            }
                            receiptDetail.ReceivedInProcessLocationDetail = matchInProcessLocationDetailList[0];
                            noCreateHuReceiptDetailList.Add(receiptDetail);
                        }
                        else if (matchInProcessLocationDetailList != null && matchInProcessLocationDetailList.Count > 1)
                        {
                            //一次收货对应多次发货。
                            //如:发货按条码,收货按数量。
                            log.Debug("multi ipdet vs one receiptdet.");
                            decimal totalRecQty = receiptDetail.ReceivedQty.Value;
                            InProcessLocationDetail lastInProcessLocationDetail = null;
                            log.Debug("Start Fetch matched InProcessLocationDetailList.");
                            foreach (InProcessLocationDetail inProcessLocationDetail in matchInProcessLocationDetailList)
                            {
                                lastInProcessLocationDetail = inProcessLocationDetail; //记录最后一次发货项,供没有对应发货的收货项使用

                                if (inProcessLocationDetail.ReceivedQty.HasValue && Math.Abs(inProcessLocationDetail.ReceivedQty.Value) >= Math.Abs(inProcessLocationDetail.Qty))
                                {
                                    continue;
                                }

                                if (Math.Abs(totalRecQty) > 0)
                                {
                                    log.Debug("Start cloned ReceiptDetail.");
                                    ReceiptDetail clonedReceiptDetail = new ReceiptDetail();
                                    CloneHelper.CopyProperty(receiptDetail, clonedReceiptDetail);
                                    log.Debug("End cloned ReceiptDetail.");

                                    clonedReceiptDetail.PlannedBill   = inProcessLocationDetail.PlannedBill;
                                    clonedReceiptDetail.IsConsignment = inProcessLocationDetail.IsConsignment;

                                    #region
                                    if (matchInProcessLocationDetailList[0].InProcessLocation.Type == BusinessConstants.CODE_MASTER_INPROCESS_LOCATION_TYPE_VALUE_GAP)
                                    {
                                        inProcessLocationDetail.Qty = 0 - inProcessLocationDetail.Qty;
                                    }
                                    #endregion

                                    if (Math.Abs(totalRecQty) > Math.Abs(inProcessLocationDetail.Qty - (inProcessLocationDetail.ReceivedQty.HasValue ? inProcessLocationDetail.ReceivedQty.Value : decimal.Zero)))
                                    {
                                        clonedReceiptDetail.ReceivedQty = inProcessLocationDetail.Qty - (inProcessLocationDetail.ReceivedQty.HasValue ? inProcessLocationDetail.ReceivedQty.Value : decimal.Zero);
                                        clonedReceiptDetail.ShippedQty  = inProcessLocationDetail.Qty - (inProcessLocationDetail.ReceivedQty.HasValue ? inProcessLocationDetail.ReceivedQty.Value : decimal.Zero);
                                        totalRecQty -= inProcessLocationDetail.Qty - (inProcessLocationDetail.ReceivedQty.HasValue ? inProcessLocationDetail.ReceivedQty.Value : decimal.Zero);
                                    }
                                    else
                                    {
                                        clonedReceiptDetail.ReceivedQty = totalRecQty;
                                        clonedReceiptDetail.ShippedQty  = totalRecQty;
                                        totalRecQty = 0;
                                    }

                                    //因为去掉了数量,记录已经匹配的发货项,避免差异处理的时候匹配多条而产生差异。
                                    clonedReceiptDetail.ReceivedInProcessLocationDetail = inProcessLocationDetail;

                                    noCreateHuReceiptDetailList.Add(clonedReceiptDetail);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            log.Debug("End Fetch matched InProcessLocationDetailList.");

                            //超收,没有找到对应的发货项,只记录收货数,发货数记0
                            if (Math.Abs(totalRecQty) > 0)
                            {
                                ReceiptDetail clonedReceiptDetail = new ReceiptDetail();
                                CloneHelper.CopyProperty(receiptDetail, clonedReceiptDetail);

                                clonedReceiptDetail.ShippedQty  = 0;
                                clonedReceiptDetail.ReceivedQty = totalRecQty;
                                clonedReceiptDetail.ReceivedInProcessLocationDetail = lastInProcessLocationDetail;

                                noCreateHuReceiptDetailList.Add(clonedReceiptDetail);
                            }
                        }
                        else
                        {
                            noCreateHuReceiptDetailList.Add(receiptDetail);
                        }
                    }
                    else
                    {
                        noCreateHuReceiptDetailList.Add(receiptDetail);
                    }
                    log.Debug("End match ReceiptDetail and InProcessLocationDetail.");
                    #endregion

                    foreach (ReceiptDetail noCreateHuReceiptDetail in noCreateHuReceiptDetailList)
                    {
                        noCreateHuReceiptDetail.Receipt = receipt;

                        if (noCreateHuReceiptDetail.ReceivedQty != 0)
                        {
                            #region 入库
                            log.Debug("Start Inventory In.");
                            IList <InventoryTransaction> inventoryTransactionList = this.locationMgr.InventoryIn(noCreateHuReceiptDetail, user, noCreateHuReceiptDetail.PutAwayBinCode);
                            log.Debug("End Inventory In.");
                            #endregion

                            #region 是否检验
                            if (orderDetail.NeedInspection && orderHead.NeedInspection && inventoryTransactionList != null && inventoryTransactionList.Count > 0 &&
                                orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML)
                            {
                                foreach (InventoryTransaction inventoryTransaction in inventoryTransactionList)
                                {
                                    if (inventoryTransaction.Location.Code != BusinessConstants.SYSTEM_LOCATION_REJECT)
                                    {
                                        LocationLotDetail locationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(inventoryTransaction.LocationLotDetailId);
                                        locationLotDetail.CurrentInspectQty = inventoryTransaction.Qty;
                                        inspectLocationLotDetailList.Add(locationLotDetail);
                                    }
                                }
                            }
                            #endregion
                        }

                        #region 创建收货明细
                        log.Debug("Start Create Receipt Detail.");
                        this.receiptDetailMgr.CreateReceiptDetail(noCreateHuReceiptDetail);
                        receipt.AddReceiptDetail(noCreateHuReceiptDetail);
                        log.Debug("End Create Receipt Detail.");
                        #endregion
                    }

                    #endregion
                }
            }
            #endregion

            #region 检验
            if (inspectLocationLotDetailList.Count > 0)
            {
                //对于没有Hu的,如果收货时已经回冲了负数库存,也就是库存数量和待检验数量不一致可能会有问题
                //增加ipno,receiptno,isseperated字段
                this.inspectOrderMgr.CreateInspectOrder(inspectLocationLotDetailList, user, receipt.InProcessLocations[0].IpNo, receipt.ReceiptNo, false);
            }
            #endregion

            //#region 匹配收货发货项,查找差异
            //IList<InProcessLocationDetail> gapInProcessLocationDetailList = new List<InProcessLocationDetail>();

            //#region 发货项不匹配
            //foreach (InProcessLocationDetail inProcessLocationDetail in inProcessLocationDetailList)
            //{
            //    if (inProcessLocationDetail.OrderLocationTransaction.OrderDetail.OrderHead.Type
            //        != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)   //生产暂时不支持差异
            //    {
            //        decimal receivedQty = 0;  //发货项的累计收货数

            //        //一条发货项可能对应多条收货项
            //        foreach (ReceiptDetail receiptDetail in receipt.ReceiptDetails)
            //        {
            //            //匹配收货项和发货项
            //            if (receiptDetail.ReceivedInProcessLocationDetail != null)
            //            {
            //                //对于已经匹配的,直接按发货项匹配
            //                if (receiptDetail.ReceivedInProcessLocationDetail.Id == inProcessLocationDetail.Id)
            //                {
            //                    if (receiptDetail.ReceivedQty.HasValue)
            //                    {
            //                        receivedQty += receiptDetail.ReceivedQty.Value;
            //                    }
            //                }
            //            }
            //            else if (OrderHelper.IsInProcessLocationDetailMatchReceiptDetail(
            //                inProcessLocationDetail, receiptDetail))
            //            {
            //                if (receiptDetail.ReceivedQty.HasValue)
            //                {
            //                    receivedQty += receiptDetail.ReceivedQty.Value;
            //                }
            //            }
            //        }

            //        if (receivedQty != inProcessLocationDetail.Qty)
            //        {
            //            #region 收货数量和发货数量不匹配,记录差异
            //            InProcessLocationDetail gapInProcessLocationDetail = new InProcessLocationDetail();
            //            gapInProcessLocationDetail.Qty = receivedQty - inProcessLocationDetail.Qty;
            //            gapInProcessLocationDetail.OrderLocationTransaction = inProcessLocationDetail.OrderLocationTransaction;
            //            //gapInProcessLocationDetail.HuId = inProcessLocationDetail.HuId;
            //            gapInProcessLocationDetail.LotNo = inProcessLocationDetail.LotNo;
            //            gapInProcessLocationDetail.IsConsignment = inProcessLocationDetail.IsConsignment;
            //            gapInProcessLocationDetail.PlannedBill = inProcessLocationDetail.PlannedBill;

            //            gapInProcessLocationDetailList.Add(gapInProcessLocationDetail);
            //            #endregion
            //        }
            //    }
            //}
            //#endregion

            //#region 收货项不匹配
            //foreach (ReceiptDetail receiptDetail in receipt.ReceiptDetails)
            //{
            //    if (receiptDetail.OrderLocationTransaction.OrderDetail.OrderHead.Type
            //        != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)   //生产暂时不支持差异
            //    {
            //        IList<InProcessLocationDetail> matchInProcessLocationDetailList = OrderHelper.FindMatchInProcessLocationDetail(receiptDetail, inProcessLocationDetailList);

            //        if (matchInProcessLocationDetailList == null || matchInProcessLocationDetailList.Count == 0)
            //        {
            //            OrderLocationTransaction outOrderLocationTransaction =
            //                this.orderLocationTransactionMgr.GetOrderLocationTransaction(receiptDetail.OrderLocationTransaction.OrderDetail, BusinessConstants.IO_TYPE_OUT)[0];
            //            #region 没有找到和收货项对应的发货项
            //            InProcessLocationDetail gapInProcessLocationDetail = new InProcessLocationDetail();
            //            gapInProcessLocationDetail.Qty = receiptDetail.ReceivedQty.Value;
            //            gapInProcessLocationDetail.OrderLocationTransaction = outOrderLocationTransaction;
            //            //gapInProcessLocationDetail.HuId = receiptDetail.HuId;
            //            gapInProcessLocationDetail.LotNo = receiptDetail.LotNo;
            //            gapInProcessLocationDetail.IsConsignment = receiptDetail.IsConsignment;
            //            gapInProcessLocationDetail.PlannedBill = receiptDetail.PlannedBill;

            //            gapInProcessLocationDetailList.Add(gapInProcessLocationDetail);
            //            #endregion
            //        }
            //    }
            //}
            //#endregion
            //#endregion

            #region 关闭InProcessLocation
            if (receipt.InProcessLocations != null && receipt.InProcessLocations.Count > 0)
            {
                foreach (InProcessLocation inProcessLocation in receipt.InProcessLocations)
                {
                    if (inProcessLocation.IsAsnUniqueReceipt)
                    {
                        //不支持多次收货直接关闭
                        this.inProcessLocationMgr.CloseInProcessLocation(inProcessLocation, user);
                    }
                    else
                    {
                        this.inProcessLocationMgr.TryCloseInProcessLocation(inProcessLocation, user);
                    }

                    //transportationOrderMgr.TryCompleteTransportationOrder(inProcessLocation, user);
                }
            }
            #endregion
        }
Esempio n. 26
0
        private void writeContent(string companyCode, string userName, int pageIndex, int num, Hu hu)
        {
            if (hu.PrintCount > 1)
            {
                this.SetRowCell(pageIndex, 1, 3, "(R)", num);
            }
            hu.PrintCount += 1;

            if (hu.Item.Type.Equals("M")) //成品
            {
                //YFKSS
                this.SetMergedRegion(pageIndex, 1, 4, 9, 4, num);
                Cell cell = this.GetCell(this.GetRowIndexAbsolute(pageIndex, getRowIndex(1, num)), getColumnIndex(4, num));

                //cell.CellStyle = workbook.CreateCellStyle();
                //cell.CellStyle.CloneStyleFrom(cellStyle);
                cell.CellStyle = this.cellStyle1;
                this.SetRowCell(pageIndex, 1, 4, companyCode, num);

                /*
                 * Bitmap bitmap = Barcode_Writer.Code128.Instance.Generate("12314325346457567");
                 * MemoryStream ms = new MemoryStream();
                 * bitmap.Save(ms, ImageFormat.Jpeg);
                 * ms.Flush();
                 * byte[] bData = ms.GetBuffer();
                 * ms.Close();
                 *
                 * int pictureIdx = this.workbook.AddPicture(bData, HSSFWorkbook.PICTURE_TYPE_JPEG);
                 *
                 * HSSFPatriarch patriarch = this.sheet.CreateDrawingPatriarch();
                 * //add a picture
                 * HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 70, 100, this.getColumnIndex(0, num), this.getRowIndex(0, num), this.getColumnIndex(0, num), this.getRowIndex(0, num));
                 * HSSFPicture pict = patriarch.CreatePicture(anchor, pictureIdx);
                 */
                //hu id内容
                string barCode = Utility.BarcodeHelper.GetBarcodeStr(hu.HuId, this.barCodeFontName);
                this.SetRowCell(pageIndex, 0, 0, barCode, num);
                //hu id内容
                this.SetRowCell(pageIndex, 1, 0, hu.HuId, num);
                //PART NO.内容
                this.SetRowCell(pageIndex, 3, 0, hu.Item.Code, num);
                //批号LotNo
                this.SetRowCell(pageIndex, 5, 0, hu.LotNo, num);
                //SHIFT
                this.SetRowCell(pageIndex, 4, 2, "SHIFT", num);
                //SHIFT内容
                this.SetRowCell(pageIndex, 5, 2, Utility.BarcodeHelper.GetShiftCode(hu.HuId), num);
                //QUANTITY.
                this.SetRowCell(pageIndex, 4, 3, "QUANTITY.", num);
                //QUANTITY内容
                this.SetRowCell(pageIndex, 5, 3, hu.Qty.ToString("0.########"), num);
                //CUSTPART
                this.SetRowCell(pageIndex, 6, 0, "CUSTPART", num);
                //CUSTPART内容
                this.SetRowCell(pageIndex, 7, 0, hu.CustomerItemCode, num);
                //WO DATE
                this.SetRowCell(pageIndex, 6, 3, "WO DATE", num);
                //WO DATE内容
                this.SetRowCell(pageIndex, 7, 3, hu.ManufactureDate.ToString("MM/dd/yy"), num);
                //DESCRIPTION
                this.SetRowCell(pageIndex, 8, 0, "DESCRIPTION.", num);
                //DESCRIPTION内容
                this.SetRowCell(pageIndex, 9, 0, hu.Item.Description, num);
                //PRINTED DATE:内容
                this.SetRowCell(pageIndex, 10, 1, DateTime.Now.ToString("MM/dd/yy"), num);
                //print name 内容
                this.SetRowCell(pageIndex, 10, 3, userName, num);
            }
            else if (hu.Item.Type.Equals("P")) //原材料
            {
                //画方框
                Cell cell1 = this.GetCell(this.GetRowIndexAbsolute(pageIndex, getRowIndex(2, num)), getColumnIndex(4, num));

                //cell1.CellStyle = workbook.CreateCellStyle();
                //cell1.CellStyle.CloneStyleFrom(cellStyle1);
                cell1.CellStyle = this.cellStyle2;

                Cell cell2 = this.GetCell(this.GetRowIndexAbsolute(pageIndex, getRowIndex(3, num)), getColumnIndex(4, num));

                //cell2.CellStyle = workbook.CreateCellStyle();
                //cell2.CellStyle.CloneStyleFrom(cellStyle2);
                cell2.CellStyle = this.cellStyle3;

                //hu id内容
                string barCode = Utility.BarcodeHelper.GetBarcodeStr(hu.HuId, this.barCodeFontName);
                this.SetRowCell(pageIndex, 0, 0, barCode, num);
                //hu id内容
                this.SetRowCell(pageIndex, 1, 0, hu.HuId, num);
                //PART NO.内容
                this.SetRowCell(pageIndex, 3, 0, hu.Item.Code, num);
                //批号LotNo
                this.SetRowCell(pageIndex, 5, 0, hu.LotNo, num);
                //QUANTITY.
                this.SetRowCell(pageIndex, 4, 2, "QUANTITY.", num);
                //QUANTITY.
                this.SetRowCell(pageIndex, 5, 2, hu.Qty.ToString("0.########"), num);
                //DESCRIPTION
                this.SetRowCell(pageIndex, 6, 0, "DESCRIPTION.", num);
                //DESCRIPTION内容
                this.SetRowCell(pageIndex, 7, 0, hu.Item.Description, num);
                //SUPPLIER
                this.SetRowCell(pageIndex, 8, 0, "SUPPLIER.", num);
                //SUPPLIER内容
                this.SetRowCell(pageIndex, 9, 0, hu.ManufactureParty == null ? string.Empty : hu.ManufactureParty.Name, num);
                //PRINTED DATE:内容
                this.SetRowCell(pageIndex, 10, 1, DateTime.Now.ToString("MM/dd/yy"), num);
                //print name 内容
                this.SetRowCell(pageIndex, 10, 3, userName, num);
            }
        }
Esempio n. 27
0
    private void HuScan(Hu hu)
    {
        if (hu == null)
        {
            this.lblMessage.Text = Resources.Language.MasterDataHuNotExist;
            return;
        }
        else
        {
            if (TheOrder.OrderDetails != null)
            {
                foreach (OrderDetail orderDetail in TheOrder.OrderDetails)
                {
                    if (orderDetail.HuId == hu.HuId)
                    {
                        this.lblMessage.Text = Resources.Language.MasterDataHuExist;
                        return;
                    }
                }
            }
            Flow flow = this.TheFlowMgr.LoadFlow(TheOrder.Flow);
            if (flow != null && !flow.AllowCreateDetail)
            {
                bool isMatch = false;
                if (TheOrder.OrderDetails != null)
                {
                    foreach (OrderDetail orderDetail in TheOrder.OrderDetails)
                    {
                        if (orderDetail.Item.Code == hu.Item.Code && orderDetail.Uom.Code == hu.Uom.Code)
                        {
                            if (!orderDetail.OrderHead.FulfillUnitCount || orderDetail.UnitCount == hu.UnitCount)
                            {
                                if (orderDetail.HuId != string.Empty && orderDetail.HuId != null)
                                {
                                    OrderDetail newOrderDetail = new OrderDetail();
                                    newOrderDetail.IsScanHu = true;
                                    int seqInterval = int.Parse(TheEntityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_SEQ_INTERVAL).Value);

                                    int seq = int.Parse(TheEntityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_SEQ_INTERVAL).Value);
                                    if (this.TheOrder.OrderDetails == null || this.TheOrder.OrderDetails.Count == 0)
                                    {
                                        newOrderDetail.Sequence = seqInterval;
                                    }
                                    else
                                    {
                                        newOrderDetail.Sequence = this.TheOrder.OrderDetails.Last <OrderDetail>().Sequence + seqInterval;
                                    }
                                    newOrderDetail.Item  = orderDetail.Item;
                                    newOrderDetail.Uom   = orderDetail.Uom;
                                    newOrderDetail.HuId  = hu.HuId;
                                    newOrderDetail.HuQty = hu.Qty;
                                    if ((this.ModuleType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION && this.ModuleSubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_ADJ) ||
                                        this.ModuleSubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_RTN)
                                    {
                                        newOrderDetail.OrderedQty = -hu.Qty;
                                    }
                                    else
                                    {
                                        newOrderDetail.OrderedQty = hu.Qty;
                                    }
                                    newOrderDetail.LocationFrom = orderDetail.LocationFrom;
                                    if (this.IsReject)
                                    {
                                        newOrderDetail.LocationTo = TheLocationMgr.GetRejectLocation();
                                    }
                                    else
                                    {
                                        newOrderDetail.LocationTo = orderDetail.LocationTo;
                                    }
                                    newOrderDetail.ReferenceItemCode = orderDetail.ReferenceItemCode;
                                    newOrderDetail.UnitCount         = orderDetail.UnitCount;
                                    newOrderDetail.PackageType       = orderDetail.PackageType;
                                    newOrderDetail.OrderHead         = orderDetail.OrderHead;
                                    newOrderDetail.IsScanHu          = true;
                                    TheOrder.AddOrderDetail(newOrderDetail);
                                }

                                else
                                {
                                    orderDetail.IsScanHu = true;
                                    orderDetail.HuId     = hu.HuId;
                                    orderDetail.HuQty    = hu.Qty;
                                    if ((this.ModuleType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION && this.ModuleSubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_ADJ) ||
                                        this.ModuleSubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_RTN)
                                    {
                                        orderDetail.OrderedQty = -hu.Qty;
                                    }
                                    else
                                    {
                                        orderDetail.OrderedQty = hu.Qty;
                                    }
                                    if (this.IsReject)
                                    {
                                        orderDetail.LocationTo = TheLocationMgr.GetRejectLocation();
                                    }
                                }
                                isMatch = true;
                                break;
                            }
                        }
                    }
                }
                if (!isMatch)
                {
                    this.lblMessage.Text = Resources.Language.MasterDataFlowNotExistHuItem;
                    return;
                }
            }
            else
            {
                OrderDetail newOrderDetail = new OrderDetail();
                newOrderDetail.IsScanHu = true;
                int seqInterval = int.Parse(TheEntityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_SEQ_INTERVAL).Value);

                int seq = int.Parse(TheEntityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_SEQ_INTERVAL).Value);
                if (this.TheOrder.OrderDetails == null || this.TheOrder.OrderDetails.Count == 0)
                {
                    newOrderDetail.Sequence = seqInterval;
                }
                else
                {
                    newOrderDetail.Sequence = this.TheOrder.OrderDetails.Last <OrderDetail>().Sequence + seqInterval;
                }
                newOrderDetail.Item  = hu.Item;
                newOrderDetail.Uom   = hu.Uom;
                newOrderDetail.HuId  = hu.HuId;
                newOrderDetail.HuQty = hu.Qty;
                if ((this.ModuleType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION && this.ModuleSubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_ADJ) ||
                    this.ModuleSubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_RTN)
                {
                    newOrderDetail.OrderedQty = -hu.Qty;
                }
                else
                {
                    newOrderDetail.OrderedQty = hu.Qty;
                }
                if (this.IsReject)
                {
                    newOrderDetail.LocationFrom = TheLocationMgr.GetRejectLocation();
                }
                else
                {
                    newOrderDetail.LocationFrom = TheOrder.LocationFrom;
                }
                newOrderDetail.LocationTo = TheOrder.LocationTo;
                newOrderDetail.UnitCount  = hu.UnitCount;
                TheOrder.AddOrderDetail(newOrderDetail);
            }

            IList <OrderDetail> orderDetailList = new List <OrderDetail>();
            foreach (OrderDetail od in TheOrder.OrderDetails)
            {
                if (od.IsScanHu)
                {
                    orderDetailList.Add(od);
                }
            }

            this.GV_List.DataSource = orderDetailList;
            this.GV_List.DataBind();
            InitialHuScan();
        }
    }
Esempio n. 28
0
    private void HuScan(string huId)
    {
        Hu hu = TheHuMgr.LoadHu(huId);

        HuScan(hu);
    }
Esempio n. 29
0
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        try
        {
            IList<TransformerDetail> transformerDetailList = this.ucList.PopulateTransformerDetailList();
            IList<OrderDetail> orderDetailList = new List<OrderDetail>();
            string currentFlow = string.Empty;

            foreach (TransformerDetail transformerDetail in transformerDetailList)
            {
                if (transformerDetail.CurrentQty != transformerDetail.AdjustQty)
                {
                    OrderLocationTransaction orderLocTrans = TheOrderLocationTransactionMgr.LoadOrderLocationTransaction(transformerDetail.OrderLocTransId);
                    if (currentFlow == string.Empty)
                    {
                        currentFlow = orderLocTrans.OrderDetail.OrderHead.Flow;
                    }
                    OrderDetail orderDetail = new OrderDetail();
                    orderDetail.Item = TheItemMgr.LoadItem(transformerDetail.ItemCode);
                    orderDetail.Uom = TheUomMgr.LoadUom(transformerDetail.UomCode);
                    if (transformerDetail.HuId != null && transformerDetail.HuId.Trim() != string.Empty)
                    {
                        Hu hu = this.TheHuMgr.CheckAndLoadHu(transformerDetail.HuId.Trim());
                        orderDetail.OrderedQty = transformerDetail.AdjustQty - hu.Qty;
                    }
                    else
                    {
                        orderDetail.OrderedQty = transformerDetail.AdjustQty - transformerDetail.CurrentQty;
                    }
                    orderDetail.UnitCount = transformerDetail.UnitCount;
                    orderDetail.HuId = transformerDetail.HuId;
                    orderDetail.HuLotNo = transformerDetail.LotNo;
                    if (transformerDetail.LocationFromCode != null)
                    {
                        orderDetail.LocationFrom = TheLocationMgr.LoadLocation(transformerDetail.LocationFromCode);
                    }
                    if (transformerDetail.LocationToCode != null)
                    {
                        orderDetail.LocationTo = TheLocationMgr.LoadLocation(transformerDetail.LocationToCode);

                    }

                    orderDetailList.Add(orderDetail);
                }
            }
            if (orderDetailList.Count > 0)
            {
                Receipt receipt = TheOrderMgr.QuickReceiveOrder(currentFlow, orderDetailList, this.CurrentUser.Code, BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_ADJ, DateTime.Now, DateTime.Now, false, this.ReceiptNo, null);
                this.Visible = false;
                ShowSuccessMessage("MasterData.Receipt.Adjust.Successfully", this.ReceiptNo);
                if (AdjustEvent != null)
                {
                    AdjustEvent(receipt.ReceiptNo, e);
                }
            }
            else
            {
                ShowSuccessMessage("MasterData.Receipt.NoDetail.Adjust", this.ReceiptNo);
            }
        }
        catch (BusinessErrorException ex)
        {
            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.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();
            }
        }