Exemplo n.º 1
0
        public static TransformerDetail ConvertRepackDetailToTransformerDetail(RepackDetail repackDetail)
        {
            TransformerDetail transformerDetail = new TransformerDetail();
            if (repackDetail.LocationLotDetail.Hu != null)
            {
                transformerDetail = ConvertHuToTransformerDetail(repackDetail.LocationLotDetail.Hu);
                transformerDetail.Qty = repackDetail.Qty / repackDetail.LocationLotDetail.Hu.UnitQty;
                transformerDetail.CurrentQty = transformerDetail.Qty;
            }
            else
            {
                transformerDetail.ItemCode = repackDetail.LocationLotDetail.Item.Code;
                transformerDetail.ItemDescription = repackDetail.LocationLotDetail.Item.Description;

                transformerDetail.UomCode = repackDetail.LocationLotDetail.Item.Uom.Code;
                transformerDetail.UnitCount = repackDetail.LocationLotDetail.Item.UnitCount;

                transformerDetail.Qty = repackDetail.Qty;
                transformerDetail.CurrentQty = repackDetail.Qty;
            }

            transformerDetail.LocationLotDetId = repackDetail.LocationLotDetail.Id;
            transformerDetail.LocationCode = repackDetail.LocationLotDetail.Location.Code;
            transformerDetail.StorageBinCode = repackDetail.StorageBinCode;
            transformerDetail.IOType = repackDetail.IOType;

            return transformerDetail;
        }
Exemplo n.º 2
0
        private void CreateRepack(Resolver resolver)
        {
            string[] huIdArr = resolver.Input.Split(',');
            List<ReceiptNote> receiptNotes = new List<ReceiptNote>();

            foreach (string huId in huIdArr)
            {
                try
                {
                    IList<RepackDetail> repackDetailList = new List<RepackDetail>();
                    LocationLotDetail locationLotDetail = locationLotDetailMgr.CheckLoadHuLocationLotDetail(huId);
                    RepackDetail inRepackDetail = new RepackDetail();
                    inRepackDetail.LocationLotDetail = locationLotDetail;
                    inRepackDetail.Hu = locationLotDetail.Hu;
                    inRepackDetail.IOType = BusinessConstants.IO_TYPE_IN;
                    inRepackDetail.Qty = inRepackDetail.Hu.Qty * inRepackDetail.Hu.UnitQty;
                    repackDetailList.Add(inRepackDetail);

                    RepackDetail outRepackDetail = new RepackDetail();
                    outRepackDetail.itemCode = inRepackDetail.Hu.Item.Code;
                    outRepackDetail.IOType = BusinessConstants.IO_TYPE_OUT;
                    outRepackDetail.Qty = inRepackDetail.Qty;
                    repackDetailList.Add(outRepackDetail);

                    Repack repack = repackMgr.CreateDevanning(repackDetailList, userMgr.CheckAndLoadUser(resolver.UserCode));

                    ReceiptNote receiptNote = Repack2ReceiptNote(repack);
                    receiptNotes.Add(receiptNote);
                }

                catch (Exception ex)
                {
                    continue;
                }
            }
            if (resolver.ReceiptNotes == null)
            {
                resolver.ReceiptNotes = receiptNotes;
            }
            else
            {
                IListHelper.AddRange<ReceiptNote>(resolver.ReceiptNotes, receiptNotes);
            }
        }
    protected void btnRepack_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.RepackType == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_REPACK)
            {
                if (this.IsQty)
                {
                    if (this.tbLocation.Text.Trim() == string.Empty)
                    {
                        ShowErrorMessage("MasterData.Inventory.Repack.Location.Empty");
                        return;
                    }

                    if (this.OutTransformerDetailList == null || this.OutTransformerDetailList.Count == 0)
                    {
                        ShowErrorMessage("MasterData.Inventory.Repack.Error.RepackDetailEmpty");
                        return;
                    }
                    
                    IList<RepackDetail> repackDetailList = new List<RepackDetail>();
                    decimal totalqty = 0;

                   

                    foreach (TransformerDetail transformerDetail in OutTransformerDetailList)
                    {
                        RepackDetail outRepackDetail = new RepackDetail();

                        outRepackDetail.IOType = BusinessConstants.IO_TYPE_OUT;

                        outRepackDetail.Hu = TheHuMgr.LoadHu(transformerDetail.HuId);
                        outRepackDetail.Qty = outRepackDetail.Hu.Qty * outRepackDetail.Hu.UnitQty;
                        totalqty += outRepackDetail.Qty;
                        repackDetailList.Add(outRepackDetail);

                        if (repackDetailList.Count>0)
                        {
                           
                            IList<LocationLotDetail> locationLotDetailList = TheLocationLotDetailMgr.GetLocationLotDetail(this.tbLocation.Text.Trim(), repackDetailList[0].Hu.Item.Code, false, false, BusinessConstants.PLUS_INVENTORY, null, false);
                            if (locationLotDetailList == null || locationLotDetailList.Count == 0)
                            {
                                ShowErrorMessage("MasterData.Inventory.Repack.LocationLotDetail.Empty");
                                return;
                            }

                            foreach (LocationLotDetail locationLotDetail in locationLotDetailList)
                            {
                                RepackDetail inRepackDetail = new RepackDetail();
                                inRepackDetail.LocationLotDetail = locationLotDetail;
                                inRepackDetail.IOType = BusinessConstants.IO_TYPE_IN;
                                repackDetailList.Add(inRepackDetail);
                                if (locationLotDetail.Qty < totalqty)
                                {
                                   
                                    inRepackDetail.Qty = locationLotDetail.Qty;
                                    totalqty -= inRepackDetail.Qty;
                                }
                                else
                                {
                                    inRepackDetail.Qty = totalqty;
                                    break;
                                }
                            }
                        }

                    }
                    Repack repack = TheRepackMgr.CreateRepack(repackDetailList, this.CurrentUser);

                    if (this.IsQty)
                    {
                        RepackEvent(repack.RepackNo, e);
                    }

                }
                else
                {
                    ExecuteSubmit();
                }
            }
            else if (this.RepackType == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_DEVANNING)
            {
                UpdateOutTransformer();
                ExecuteSubmit();
            }
            if (RepackEvent != null && !this.IsQty)
            {
                RepackEvent(this.CacheResolver.Result, e);

            }
        }
        catch (BusinessErrorException ex)
        {
            ShowErrorMessage(ex);
        }

    }
    protected void btnRepack_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.RepackType == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_REPACK)
            {
                if (this.IsQty)
                {
                    if (this.tbLocation.Text.Trim() == string.Empty)
                    {
                        ShowErrorMessage("MasterData.Inventory.Repack.Location.Empty");
                        return;
                    }

                    if (this.OutTransformerDetailList == null || this.OutTransformerDetailList.Count == 0)
                    {
                        ShowErrorMessage("MasterData.Inventory.Repack.Error.RepackDetailEmpty");
                        return;
                    }

                    IList<RepackDetail> repackDetailList = new List<RepackDetail>();

                    IDictionary<string, decimal> ItemDic = new Dictionary<string, decimal>();

                    foreach (TransformerDetail transformerDetail in OutTransformerDetailList)
                    {
                        RepackDetail outRepackDetail = new RepackDetail();

                        outRepackDetail.IOType = BusinessConstants.IO_TYPE_OUT;

                        outRepackDetail.Hu = TheHuMgr.LoadHu(transformerDetail.HuId);
                        outRepackDetail.Qty = outRepackDetail.Hu.Qty * outRepackDetail.Hu.UnitQty;

                        if (ItemDic.ContainsKey(outRepackDetail.Hu.Item.Code))
                        {
                            ItemDic[outRepackDetail.Hu.Item.Code] += outRepackDetail.Qty;
                        }
                        else
                        {
                            ItemDic.Add(outRepackDetail.Hu.Item.Code, outRepackDetail.Qty);
                        }
                        repackDetailList.Add(outRepackDetail);

                    }
                    if (repackDetailList.Count > 0)
                    {
                        foreach (string item in ItemDic.Keys)
                        {
                            IList<LocationLotDetail> locationLotDetailList = TheLocationLotDetailMgr.GetLocationLotDetail(this.tbLocation.Text.Trim(), item, false, false, BusinessConstants.PLUS_INVENTORY, null, false);
                            if (locationLotDetailList == null || locationLotDetailList.Count == 0)
                            {
                                ShowErrorMessage("MasterData.Inventory.Repack.LocationLotDetail.Empty");
                                return;
                            }

                            decimal locQty = (from l in locationLotDetailList select l.Qty).Sum();
                            decimal outQty = ItemDic[item];
                            if (outQty > locQty)
                            {
                                ShowErrorMessage("MasterData.Inventory.LocationLotDetail.LessThanHuQty",item, locQty.ToString("0.########"), outQty.ToString("0.########"));
                                return;
                            }

                            foreach (LocationLotDetail locationLotDetail in locationLotDetailList)
                            {
                                RepackDetail inRepackDetail = new RepackDetail();
                                inRepackDetail.LocationLotDetail = locationLotDetail;
                                inRepackDetail.IOType = BusinessConstants.IO_TYPE_IN;
                                repackDetailList.Add(inRepackDetail);
                                if (locationLotDetail.Qty < outQty)
                                {

                                    inRepackDetail.Qty = locationLotDetail.Qty;
                                    outQty -= inRepackDetail.Qty;
                                }
                                else
                                {
                                    inRepackDetail.Qty = outQty;
                                    break;
                                }
                            }
                        }
                    }

                    Repack repack = TheRepackMgr.CreateRepack(repackDetailList, this.CurrentUser);

                    if (this.IsQty)
                    {
                        RepackEvent(repack.RepackNo, e);
                    }

                }
                else
                {
                    ExecuteSubmit();
                    Repack repack = TheRepackMgr.LoadRepack(this.CacheResolver.Code, true);
                    IList<Hu> huList = new List<Hu>();
                    foreach (RepackDetail repackDet in repack.RepackDetails)
                    {
                        if (repackDet.IOType == BusinessConstants.IO_TYPE_OUT && repackDet.LocationLotDetail.Hu != null
                            && repackDet.LocationLotDetail.Hu.PrintCount == 0)
                        {
                            huList.Add(repackDet.LocationLotDetail.Hu);
                        }
                    }

                    if (huList.Count > 0)
                    {
                        IList<object> huDetailObj = new List<object>();

                        huDetailObj.Add(huList);
                        huDetailObj.Add(CurrentUser.Code);
                        string huTemplate = TheEntityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_DEFAULT_HU_TEMPLATE).Value;
                        if (huTemplate != null && huTemplate.Length > 0)
                        {
                            string barCodeUrl = TheReportMgr.WriteToFile(huTemplate, huDetailObj, "BarCode.xls");
                            Page.ClientScript.RegisterStartupScript(GetType(), "method", " <script language='javascript' type='text/javascript'>PrintOrder('" + barCodeUrl + "'); </script>");

                        }

                    }
                }
            }
            else if (this.RepackType == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_DEVANNING)
            {
                UpdateOutTransformer();
                ExecuteSubmit();
            }
            if (RepackEvent != null && !this.IsQty)
            {
                RepackEvent(this.CacheResolver.Code, e);

            }
        }
        catch (BusinessErrorException ex)
        {
            ShowErrorMessage(ex);
        }
    }
Exemplo n.º 5
0
        public void InventoryRepackIn(RepackDetail repackDetail, User user)
        {
            LocationLotDetail oldLocationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(repackDetail.LocationLotDetail.Id);

            if (oldLocationLotDetail.Qty == 0)
            {
                throw new BusinessErrorException("MasterData.Inventory.Repack.Error.ZeroInRepackDetailQty", oldLocationLotDetail.Hu.HuId);
            }
            else if (repackDetail.Qty > oldLocationLotDetail.Qty)
            {
                throw new BusinessErrorException("MasterData.Inventory.Repack.Error.LocationQtyLessThanInRepackDetailQty", oldLocationLotDetail.Hu.HuId);
            }

            #region �¼�
            if (oldLocationLotDetail.StorageBin != null)
            {
                this.InventoryPick(oldLocationLotDetail, user);
            }
            #endregion

            #region ���㣬ֻ�з�����������
            if (oldLocationLotDetail.IsConsignment == true
                && oldLocationLotDetail.PlannedBill.HasValue
                && repackDetail.Repack.Type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_REPACK)
            {
                PlannedBill pb = this.plannedBillMgr.LoadPlannedBill(oldLocationLotDetail.PlannedBill.Value);
                pb.CurrentActingQty = repackDetail.Qty / pb.UnitQty;
                this.billMgr.CreateActingBill(pb, user);
            }
            #endregion

            #region ����
            oldLocationLotDetail.Qty -= repackDetail.Qty;
            this.locationLotDetailMgr.UpdateLocationLotDetail(oldLocationLotDetail);
            #endregion

            #region Hu�ر�
            if (oldLocationLotDetail.Hu != null)
            {
                Hu hu = this.huMgr.LoadHu(oldLocationLotDetail.Hu.HuId);
                hu.Location = null;
                hu.Status = BusinessConstants.CODE_MASTER_HU_STATUS_VALUE_CLOSE;

                this.huMgr.UpdateHu(hu);
            }
            #endregion

            #region ��¼��������
            InventoryTransaction inventoryOutTransaction = InventoryTransactionHelper.CreateInventoryTransaction(oldLocationLotDetail, 0 - repackDetail.Qty, false);
            this.locationTransactionMgr.RecordLocationTransaction(inventoryOutTransaction, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_REPACK, user);
            #endregion
        }
Exemplo n.º 6
0
        public InventoryTransaction InventoryRepackOut(RepackDetail repackDetail, Location location, int? plannedBillId, User user)
        {
            #region ����Hu�ϵ�OrderNo
            Hu hu = null;
            if (repackDetail.Hu != null)
            {
                hu = this.huMgr.CheckAndLoadHu(repackDetail.Hu.HuId);

                if (repackDetail.Repack.Type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_REPACK)
                {
                    if (hu.OrderNo != null)
                    {
                        throw new BusinessErrorException("MasterData.Inventory.Repack.Error.OrderNoIsNotEmpty", hu.HuId);
                    }
                    else
                    {
                        hu.OrderNo = repackDetail.Repack.RepackNo;
                        this.huMgr.UpdateHu(hu);
                    }
                }
            }
            #endregion

            #region ���
            PlannedBill plannedBill = plannedBillId.HasValue ? this.plannedBillMgr.LoadPlannedBill(plannedBillId.Value) : null;
            IList<InventoryTransaction> inventoryTransactionList = RecordInventory(
                hu != null ? hu.Item : this.itemMgr.CheckAndLoadItem(repackDetail.itemCode),
                location,
                hu != null ? hu.HuId : null,
                hu != null ? hu.LotNo : null,
                repackDetail.Qty,     //��浥λ
                plannedBill != null,
                plannedBill,
                BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT_REPACK,
                null,
                //true,
                user,
                false,
                false,
                null
                );
            #endregion

            #region ��¼��������
            LocationLotDetail inLocationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(inventoryTransactionList[0].LocationLotDetailId);

            InventoryTransaction inventoryInTransaction = InventoryTransactionHelper.CreateInventoryTransaction(inLocationLotDetail, repackDetail.Qty, false);
            this.locationTransactionMgr.RecordLocationTransaction(inventoryInTransaction, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT_REPACK, user);
            #endregion

            #region �ϼ�
            if (hu != null && repackDetail.StorageBinCode != null && repackDetail.StorageBinCode != string.Empty)
            {
                inLocationLotDetail.NewStorageBin = this.storageBinMgr.CheckAndLoadStorageBin(repackDetail.StorageBinCode);
                this.InventoryPut(inLocationLotDetail, user);
            }
            #endregion

            return inventoryInTransaction;
        }
 public virtual void UpdateRepackDetail(RepackDetail entity)
 {
     Update(entity);
 }
 public virtual void DeleteRepackDetail(RepackDetail entity)
 {
     Delete(entity);
 }
Exemplo n.º 9
0
        public IList<RepackDetail> ConvertTransformerListToRepackDetail(IList<Transformer> transformerList)
        {
            IList<RepackDetail> repackDetailList = new List<RepackDetail>();

            if (transformerList != null && transformerList.Count == 2)
            {
                foreach (Transformer transformer in transformerList)
                {
                    if (transformer.TransformerDetails != null)
                    {
                        foreach (TransformerDetail transformerDetail in transformer.TransformerDetails)
                        {
                            RepackDetail repackDetail = new RepackDetail();
                            repackDetail.IOType = transformerDetail.IOType;

                            if (transformerDetail.HuId != string.Empty)
                            {
                                repackDetail.Hu = huMgr.LoadHu(transformerDetail.HuId);
                                repackDetail.Qty = repackDetail.Hu.Qty * repackDetail.Hu.UnitQty;
                            }
                            else
                            {
                                repackDetail.Qty = transformerDetail.Qty;
                                repackDetail.itemCode = transformerDetail.ItemCode;
                            }
                            if (transformerDetail.LocationLotDetId != 0)
                            {
                                repackDetail.LocationLotDetail = locationLotDetailMgr.LoadLocationLotDetail(transformerDetail.LocationLotDetId);
                            }
                            repackDetailList.Add(repackDetail);
                        }
                    }
                }
            }
            return repackDetailList;
        }
 public virtual void CreateRepackDetail(RepackDetail entity)
 {
     Create(entity);
 }
 public virtual void DeleteRepackDetail(RepackDetail entity)
 {
     entityDao.DeleteRepackDetail(entity);
 }
 public virtual void UpdateRepackDetail(RepackDetail entity)
 {
     entityDao.UpdateRepackDetail(entity);
 }
 public virtual void CreateRepackDetail(RepackDetail entity)
 {
     entityDao.CreateRepackDetail(entity);
 }
Exemplo n.º 14
0
        public void MatchRepack(Resolver resolver)
        {
            string huId = resolver.Input;
            if (huId == string.Empty)
            {
                throw new BusinessErrorException("Common.Business.Hu.NotExist");
            }

            //为了转成统一对象,只能写死,第一个为投入,第二个为产出
            #region 翻箱前
            if (resolver.IOType == BusinessConstants.IO_TYPE_IN)
            {
                if (resolver.Transformers != null && resolver.Transformers.Count == 2)
                {
                    Transformer inTransformer = resolver.Transformers[0];
                    if (inTransformer == null)
                    {
                        inTransformer = new Transformer();
                    }
                    if (inTransformer.TransformerDetails == null)
                    {
                        inTransformer.TransformerDetails = new List<TransformerDetail>();
                    }

                    if (resolver.Transformers[1] == null)
                    {
                        resolver.Transformers[1] = new Transformer();
                    }
                    if (resolver.Transformers[1].TransformerDetails == null)
                    {
                        resolver.Transformers[1].TransformerDetails = new List<TransformerDetail>();
                    }

                    #region 拆箱输入只能一条
                    if (resolver.ModuleType == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_DEVANNING)
                    {
                        if (inTransformer.TransformerDetails.Count > 0)
                        {
                            throw new BusinessErrorException("MasterData.Inventory.Repack.Devanning.MoreThanOneInput");
                        }
                    }
                    #endregion

                    //校验重复扫描
                    if (inTransformer.TransformerDetails != null && inTransformer.TransformerDetails.Count > 0)
                    {
                        foreach (TransformerDetail inTransformDetail in inTransformer.TransformerDetails)
                        {
                            if (inTransformDetail.HuId == huId)
                            {
                                throw new BusinessErrorException("Repack.Error.HuReScan", huId);
                            }
                        }
                    }
                    LocationLotDetail locationLotDetail = locationLotDetailMgr.CheckLoadHuLocationLotDetail(huId, resolver.UserCode);
                    if (inTransformer.LocationFromCode == null || inTransformer.LocationFromCode == string.Empty)
                    {
                        inTransformer.LocationFromCode = locationLotDetail.Location.Code;
                    }
                    if (locationLotDetail.Location.Code != inTransformer.LocationFromCode)
                    {
                        throw new BusinessErrorException("Repack.Error.Location.NotEqual");
                    }
                    //翻箱 拆箱 不允许操作不合格品
                    if (locationLotDetail.Location.Code == "Inspect")
                    {
                        throw new BusinessErrorException("Repack.Error.Location.Inspect",huId);
                    }
                    RepackDetail repackDetail = new RepackDetail();
                    repackDetail.LocationLotDetail = locationLotDetail;
                    repackDetail.Hu = locationLotDetail.Hu;
                    repackDetail.IOType = BusinessConstants.IO_TYPE_IN;
                    repackDetail.Qty = repackDetail.Hu.Qty * repackDetail.Hu.UnitQty;
                    inTransformer.AddTransformerDetail(TransformerHelper.ConvertRepackDetailToTransformerDetail(repackDetail));
                    resolver.Transformers[0] = inTransformer;
                    if (resolver.ModuleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_DEVANNING)
                    {
                        resolver.AntiResolveHu = locationLotDetail.Hu.AntiResolveHu;
                        resolver.IOType = BusinessConstants.IO_TYPE_OUT;
                        resolver.BinCode = locationLotDetail.StorageBin == null ? string.Empty : locationLotDetail.StorageBin.Code;
                    }
                }
            }
            #endregion

            #region 翻箱后
            else if (resolver.IOType == BusinessConstants.IO_TYPE_OUT)
            {
                if (resolver.Transformers != null && resolver.Transformers.Count == 2)
                {
                    Transformer outTransformer = resolver.Transformers[1];
                    Transformer inTransformer = resolver.Transformers[0];
                    if (outTransformer == null)
                    {
                        outTransformer = new Transformer();
                    }
                    if (outTransformer.TransformerDetails == null)
                    {
                        outTransformer.TransformerDetails = new List<TransformerDetail>();
                    }

                    #region 拆箱必须先扫描输入
                    if (resolver.ModuleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_DEVANNING)
                    {
                        if (inTransformer.TransformerDetails.Count == 0)
                        {
                            throw new BusinessErrorException("Devanning.Error.Input.Empty");
                        }
                    }
                    #endregion

                    #region 校验重复扫描
                    if (outTransformer.TransformerDetails != null && outTransformer.TransformerDetails.Count > 0)
                    {
                        foreach (TransformerDetail inTransformDetail in outTransformer.TransformerDetails)
                        {
                            if (inTransformDetail.HuId == huId)
                            {
                                throw new BusinessErrorException("Repack.Error.HuReScan", huId);
                            }
                        }
                    }
                    #endregion

                    #region 根据投入的反向解析hu选项来判断产出
                    Hu hu = null;
                    if (resolver.ModuleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_DEVANNING)  //只有拆箱支持解析条码
                    {
                        TransformerDetail inTransformerDetail = inTransformer.TransformerDetails[0];
                        Hu inputHu = huMgr.LoadHu(inTransformerDetail.HuId);

                        hu = this.ResolveHu(resolver.AntiResolveHu, huId, inputHu.Uom, inputHu.ManufactureParty);
                    }
                    else if (resolver.ModuleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_REPACK)
                    {
                        hu = huMgr.CheckAndLoadHu(huId);
                    }
                    #endregion
                    TransformerDetail transformerDetail = TransformerHelper.ConvertHuToTransformerDetail(hu);
                    transformerDetail.IOType = resolver.IOType;

                    outTransformer.AddTransformerDetail(transformerDetail);
                    resolver.Transformers[1] = outTransformer;
                }
            }
            #endregion

            resolver.Command = BusinessConstants.CS_BIND_VALUE_TRANSFORMERDETAIL;
            // return transformerList;
        }
Exemplo n.º 15
0
        private Repack CreateRepack(IList<RepackDetail> repackDetailList, string type, User user)
        {
            IList<RepackDetail> inRepackDetailList = new List<RepackDetail>();
            IList<RepackDetail> outRepackDetailList = new List<RepackDetail>();
            bool hasHu = false;
            #region �ж�RepackDetailList�Ƿ�Ϊ��
            if (repackDetailList != null && repackDetailList.Count > 0)
            {
                foreach (RepackDetail repackDetail in repackDetailList)
                {
                    if (repackDetail.Qty != 0)
                    {
                        if (repackDetail.IOType == BusinessConstants.IO_TYPE_IN)
                        {
                            inRepackDetailList.Add(repackDetail);
                        }
                        else if (repackDetail.IOType == BusinessConstants.IO_TYPE_OUT)
                        {
                            outRepackDetailList.Add(repackDetail);
                            if (!hasHu && repackDetail.Hu != null)
                            {
                                hasHu = true;
                            }
                        }
                        else
                        {
                            throw new TechnicalException("Invalid IO Type:" + repackDetail.IOType);
                        }
                    }
                }

                #region ��������û����������������ϲ�,����һ��������
                if (outRepackDetailList.Count == 0 && type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_REPACK)
                {
                    Hu inHu = inRepackDetailList[0].Hu;
                    Hu outHu = new Hu();
                    CloneHelper.CopyProperty(inHu, outHu);
                    outHu.OrderNo = null;
                    outHu.ReceiptNo = null;
                    outHu.Location = null;
                    outHu.StorageBin = null;
                    outHu.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE;

                    string repackShift = entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_REPACK_SHIFT).Value;

                    string prefix = inHu.HuId.Substring(0, inHu.HuId.Length - 4) + repackShift;
                    outHu.HuId =numberControlMgr.GenerateNumber(prefix, 3);
                    outHu.Qty = (from l in inRepackDetailList select l.Qty).Sum();
                    outHu.UnitCount = outHu.Qty;
                    outHu.LotSize = outHu.UnitCount;
                    outHu.PrintCount = 0;
                    huMgr.CreateHu(outHu);

                    RepackDetail outRepackDetail = new RepackDetail();
                    outRepackDetail.Hu = outHu;
                    outRepackDetail.IOType = BusinessConstants.IO_TYPE_OUT;
                    outRepackDetail.Qty = outHu.Qty;
                    outRepackDetail.itemCode = outHu.Item.Code;
                    outRepackDetailList.Add(outRepackDetail);
                }
                #endregion

                if (inRepackDetailList.Count == 0 || outRepackDetailList.Count == 0)
                {
                    throw new BusinessErrorException("MasterData.Inventory.Repack.Error.RepackDetailEmpty");
                }
                if (hasHu && type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_DEVANNING && outRepackDetailList.Count < 2)
                {
                    throw new BusinessErrorException("MasterData.Inventory.Devanning.Error.DevanningDetailLessThanTwo");
                }
            }
            else
            {
                throw new BusinessErrorException("MasterData.Inventory.Repack.Error.RepackDetailEmpty");
            }
            #endregion

            #region �ж��Ƿ񱻼��
            foreach (RepackDetail inRepackDetail in inRepackDetailList)
            {
                if (inRepackDetail.LocationLotDetail.Hu != null && this.locationMgr.IsHuOcuppyByPickList(inRepackDetail.LocationLotDetail.Hu.HuId))
                {
                    throw new BusinessErrorException("MasterData.Inventory.Repack.Error.HuOccupied", inRepackDetail.Hu.HuId);
                }
            }
            #endregion

            #region �жϷ���������Ƿ�Ϊ������
            foreach (RepackDetail outRepackDetail in outRepackDetailList)
            {
                if (outRepackDetail.Hu != null && outRepackDetail.Hu.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE)
                {
                    throw new BusinessErrorException("MasterData.Inventory.Repack.Error.HuStatusNotCreate", outRepackDetail.Hu.HuId);
                }
            }
            #endregion

            #region ���In��Out��ϸ�����Ƿ�ƥ��
            IDictionary<string, decimal> inItemQtyDic = new Dictionary<string, decimal>();
            Location location = null;

            #region �ռ�In����
            foreach (RepackDetail inRepackDetail in inRepackDetailList)
            {
                LocationLotDetail inLocationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(inRepackDetail.LocationLotDetail.Id);

                if (location == null)
                {
                    location = inLocationLotDetail.Location;

                    if (!user.HasPermission(inLocationLotDetail.Location.Region.Code))
                    {
                        throw new BusinessErrorException("MasterData.Inventory.Repack.Error.NoPermission", location.Code);
                    }
                }
                else if (location.Code != inLocationLotDetail.Location.Code)
                {
                    throw new BusinessErrorException("MasterData.Inventory.Repack.Error.InRepackDetailLocationNotEqual");
                }

                if (inItemQtyDic.ContainsKey(inLocationLotDetail.Item.Code))
                {
                    inItemQtyDic[inLocationLotDetail.Item.Code] += inRepackDetail.Qty;
                }
                else
                {
                    inItemQtyDic.Add(inLocationLotDetail.Item.Code, inRepackDetail.Qty);
                }
            }
            #endregion

            #region �ռ�Out����
            IDictionary<string, decimal> outItemQtyDic = new Dictionary<string, decimal>();

            foreach (RepackDetail outRepackDetail in outRepackDetailList)
            {
                if (type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_REPACK)
                {
                    if (outRepackDetail.Hu == null)
                    {
                        throw new BusinessErrorException("MasterData.Inventory.Repack.Error.HuIdIsEmpty");
                    }
                    else
                    {
                        if (outItemQtyDic.ContainsKey(outRepackDetail.Hu.Item.Code))
                        {
                            outItemQtyDic[outRepackDetail.Hu.Item.Code] += outRepackDetail.Qty;
                        }
                        else
                        {
                            outItemQtyDic.Add(outRepackDetail.Hu.Item.Code, outRepackDetail.Qty);
                        }
                    }
                }
                else if (type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_DEVANNING)
                {
                    string itemCode = outRepackDetail.Hu != null ? outRepackDetail.Hu.Item.Code : outRepackDetail.itemCode;

                    if (itemCode == null)
                    {
                        throw new TechnicalException("ItemCode not specified.");
                    }

                    if (outItemQtyDic.ContainsKey(itemCode))
                    {
                        outItemQtyDic[itemCode] += outRepackDetail.Qty;
                    }
                    else
                    {
                        outItemQtyDic.Add(itemCode, outRepackDetail.Qty);
                    }
                }
                else
                {
                    throw new TechnicalException("Repack type: " + type + " is not valided.");
                }
            }
            #endregion

            #region �Ƚ�
            if (inItemQtyDic.Count != outItemQtyDic.Count)
            {
                throw new BusinessErrorException("MasterData.Inventory.Repack.Error.InOutQtyNotMatch");
            }

            foreach (string itemCode in inItemQtyDic.Keys)
            {
                if (outItemQtyDic.ContainsKey(itemCode))
                {
                    decimal inQty = inItemQtyDic[itemCode];
                    decimal outQty = outItemQtyDic[itemCode];

                    //�Ƿ��Զ�����ʣ�������ļ�¼
                    bool autoCreate = bool.Parse(entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_AUTO_CREATE_WHEN_DEAVING).Value);

                    #region �������ʣ�������õ�ʣ������������
                    if (autoCreate && type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_DEVANNING && inQty > outQty)
                    {
                        RepackDetail remainRepackDetail = CloneHelper.DeepClone(inRepackDetailList[0]);
                        remainRepackDetail.Qty = inQty - outQty;
                        remainRepackDetail.IOType = BusinessConstants.IO_TYPE_OUT;
                        outRepackDetailList.Add(remainRepackDetail);
                    }
                    #endregion

                    else if (inQty != outQty)
                    {
                        throw new BusinessErrorException("MasterData.Inventory.Repack.Error.InOutQtyNotMatch");
                    }
                }
                else
                {
                    throw new BusinessErrorException("MasterData.Inventory.Repack.Error.InOutItemNotMatch", itemCode);
                }
            }
            #endregion
            #endregion

            #region �������䵥ͷ
            Repack repack = new Repack();
            repack.RepackNo = this.numberControlMgr.GenerateNumber(BusinessConstants.CODE_PREFIX_REPACK);
            repack.CreateDate = DateTime.Now;
            repack.CreateUser = user;
            repack.Type = type;

            this.CreateRepack(repack);
            #endregion

            #region �������䵥��ϸ
            Int32? plannedBillId = null;  //���䴫��PlannedBill
            foreach (RepackDetail inRepackDetail in inRepackDetailList)
            {
                //����
                inRepackDetail.Repack = repack;
                this.locationMgr.InventoryRepackIn(inRepackDetail, user);

                this.repackDetailMgr.CreateRepackDetail(inRepackDetail);

                if (repack.Type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_DEVANNING)
                {
                    plannedBillId = inRepackDetail.LocationLotDetail.IsConsignment ? inRepackDetail.LocationLotDetail.PlannedBill : null;
                }
            }

            foreach (RepackDetail outRepackDetail in outRepackDetailList)
            {
                //���
                outRepackDetail.Repack = repack;
                InventoryTransaction inventoryTransaction = this.locationMgr.InventoryRepackOut(outRepackDetail, location, plannedBillId, user);
                outRepackDetail.LocationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(inventoryTransaction.LocationLotDetailId);

                this.repackDetailMgr.CreateRepackDetail(outRepackDetail);
            }
            #endregion

            return repack;
        }