Exemplo n.º 1
0
        public IList<ShiftPlanSchedule> ReadPSModelFromXls(Stream inputStream, User user, string regionCode, string flowCode, DateTime date, string shiftCode)
        {
            IList<ShiftPlanSchedule> spsList = new List<ShiftPlanSchedule>();
            Shift shift = shiftMgr.LoadShift(shiftCode);

            if (inputStream.Length == 0)
                throw new BusinessErrorException("Import.Stream.Empty");

            if (shift == null)
                throw new BusinessErrorException("Import.PSModel.ShiftNotExist");

            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);

            Sheet sheet = workbook.GetSheetAt(0);
            IEnumerator rows = sheet.GetRowEnumerator();

            ImportHelper.JumpRows(rows, 4);
            int colIndex = this.GetPlanColumnIndexToRead((HSSFRow)rows.Current, shift.ShiftName, date);

            if (colIndex < 0)
                throw new BusinessErrorException("Import.PSModel.Shift.Not.Exist", shift.ShiftName);

            ImportHelper.JumpRows(rows, 2);

            while (rows.MoveNext())
            {
                Row row = (HSSFRow)rows.Current;
                if (!this.CheckValidDataRow(row, 1, 4))
                {
                    break;//边界
                }

                //string regCode=row.GetCell(
                string fCode = string.Empty;
                string itemCode = string.Empty;
                int seq = 0;
                decimal planQty = 0;
                Cell cell = null;

                #region 读取生产线
                fCode = row.GetCell(1).StringCellValue;
                if (fCode.Trim() == string.Empty)
                    throw new BusinessErrorException("Import.PSModel.Empty.Error.Flow", (row.RowNum + 1).ToString());

                if (flowCode != null && flowCode.Trim() != string.Empty)
                {
                    if (fCode.Trim().ToUpper() != flowCode.Trim().ToUpper())
                        continue;//生产线过滤
                }
                #endregion

                #region 读取序号
                try
                {
                    string seqStr = row.GetCell(2).StringCellValue;
                    seq = row.GetCell(2).StringCellValue.Trim() != string.Empty ? int.Parse(row.GetCell(2).StringCellValue) : 0;
                }
                catch
                {
                    throw new BusinessErrorException("Import.PSModel.Read.Error.Seq", (row.RowNum + 1).ToString());
                }
                #endregion

                #region 读取成品代码
                try
                {
                    itemCode = row.GetCell(3).StringCellValue;
                    if (itemCode == string.Empty)
                        throw new BusinessErrorException("Import.PSModel.Empty.Error.ItemCode", (row.RowNum + 1).ToString());
                }
                catch
                {
                    throw new BusinessErrorException("Import.PSModel.Read.Error.ItemCode", (row.RowNum + 1).ToString());
                }
                #endregion

                #region 读取计划量
                try
                {
                    cell = row.GetCell(colIndex);
                    if (cell == null || cell.CellType == NPOI.SS.UserModel.CellType.BLANK)
                        continue;

                    planQty = Convert.ToDecimal(row.GetCell(colIndex).NumericCellValue);
                }
                catch
                {
                    throw new BusinessErrorException("Import.PSModel.Read.Error.PlanQty", (row.RowNum + 1).ToString());
                }
                #endregion

                FlowDetail flowDetail = flowDetailMgr.LoadFlowDetail(fCode, itemCode, seq);
                if (flowDetail == null)
                    throw new BusinessErrorException("Import.PSModel.FlowDetail.Not.Exist", (row.RowNum + 1).ToString());

                //区域权限过滤
                if (regionCode != null && regionCode.Trim() != string.Empty)
                {
                    if (regionCode.Trim().ToUpper() != flowDetail.Flow.PartyTo.Code.ToUpper())
                        continue;
                }
                if (!user.HasPermission(flowDetail.Flow.PartyTo.Code))
                    continue;

                ShiftPlanSchedule sps = new ShiftPlanSchedule();
                sps.FlowDetail = flowDetail;
                sps.ReqDate = date;
                sps.Shift = shift;
                sps.PlanQty = planQty;
                sps.LastModifyUser = user;
                sps.LastModifyDate = DateTime.Now;
                spsList.Add(sps);
            }

            if (spsList.Count == 0)
                throw new BusinessErrorException("Import.Result.Error.ImportNothing");

            return spsList;
        }
 public LocationLotDetail CheckLoadHuLocationLotDetail(string huId, User user, string locationCode)
 {
     IList<LocationLotDetail> locationLotDetailList = this.GetHuLocationLotDetail(locationCode, huId);
     if (locationLotDetailList == null || locationLotDetailList.Count == 0)
     {
         throw new BusinessErrorException("Common.Business.Error.HuNoInventory", locationCode, huId);
     }
     else if (locationLotDetailList.Count > 1)
     {
         throw new BusinessErrorException("Common.Business.Error.FindMultiHu", locationCode, huId);
     }
     else
     {
         if (user != null)
         {
             string regionCode = locationLotDetailList[0].Location.Region.Code;
             if (!user.HasPermission(regionCode))
             {
                 throw new BusinessErrorException("Common.Business.Error.NoPermission");
             }
         }
         return locationLotDetailList[0];
     }
 }
Exemplo n.º 3
0
        public IList<CycleCountDetail> ReadCycleCountFromXls(Stream inputStream, User user, CycleCount cycleCount)
        {
            if (inputStream.Length == 0)
                throw new BusinessErrorException("Import.Stream.Empty");

            //区域权限过滤
            if (!user.HasPermission(cycleCount.Location.Region.Code))
            {
                throw new BusinessErrorException("Common.Business.Error.NoPartyPermission", cycleCount.Location.Region.Code);
            }

            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);

            Sheet sheet = workbook.GetSheetAt(0);
            IEnumerator rows = sheet.GetRowEnumerator();

            ImportHelper.JumpRows(rows, 11);

            #region 列定义
            int colItem = 1;//物料代码
            int colUom = 3;//单位
            int colQty = 4;//数量
            int colHu = 5;//条码
            int colBin = 6;//库格
            #endregion

            IList<CycleCountDetail> cycleCountDetailList = new List<CycleCountDetail>();
            while (rows.MoveNext())
            {
                Row row = (HSSFRow)rows.Current;
                if (!this.CheckValidDataRow(row, 1, 7))
                {
                    break;//边界
                }

                if (row.GetCell(colHu) == null)
                {
                    string itemCode = string.Empty;
                    decimal qty = 0;
                    string uomCode = string.Empty;

                    #region 读取数据
                    #region 读取物料代码
                    itemCode = row.GetCell(colItem) != null ? row.GetCell(colItem).StringCellValue : string.Empty;
                    if (itemCode == null || itemCode.Trim() == string.Empty)
                        this.ThrowCommonError(row.RowNum, colItem, row.GetCell(colItem));

                    var i = (
                        from c in cycleCountDetailList
                        where c.HuId == null && c.Item.Code.Trim().ToUpper() == itemCode.Trim().ToUpper()
                        select c).Count();

                    if (i > 0)
                        throw new BusinessErrorException("Import.Business.Error.Duplicate", itemCode, (row.RowNum + 1).ToString(), (colItem + 1).ToString());
                    #endregion

                    #region 读取数量
                    try
                    {
                        qty = Convert.ToDecimal(row.GetCell(colQty).NumericCellValue);
                    }
                    catch
                    {
                        this.ThrowCommonError(row.RowNum, colQty, row.GetCell(colQty));
                    }
                    #endregion

                    #region 读取单位
                    uomCode = row.GetCell(colUom) != null ? row.GetCell(colUom).StringCellValue : string.Empty;
                    if (uomCode == null || uomCode.Trim() == string.Empty)
                        throw new BusinessErrorException("Import.Read.Error.Empty", (row.RowNum + 1).ToString(), colUom.ToString());
                    #endregion
                    #endregion

                    #region 填充数据
                    Item item = itemMgr.CheckAndLoadItem(itemCode);
                    Uom uom = uomMgr.CheckAndLoadUom(uomCode);
                    //单位换算
                    if (item.Uom.Code.Trim().ToUpper() != uom.Code.Trim().ToUpper())
                    {
                        qty = uomConversionMgr.ConvertUomQty(item, uom, qty, item.Uom);
                    }

                    CycleCountDetail cycleCountDetail = new CycleCountDetail();
                    cycleCountDetail.CycleCount = cycleCount;
                    cycleCountDetail.Item = item;
                    cycleCountDetail.Qty = qty; cycleCountDetailList.Add(cycleCountDetail);
                    #endregion
                }
                else
                {
                    string huId = string.Empty;
                    string binCode = string.Empty;

                    #region 读取数据
                    #region 读取条码
                    huId = row.GetCell(colHu) != null ? row.GetCell(colHu).StringCellValue : string.Empty;
                    if (huId == null || huId.Trim() == string.Empty)
                        throw new BusinessErrorException("Import.Read.Error.Empty", (row.RowNum + 1).ToString(), colHu.ToString());

                    var i = (
                        from c in cycleCountDetailList
                        where c.HuId != null && c.HuId.Trim().ToUpper() == huId.Trim().ToUpper()
                        select c).Count();

                    if (i > 0)
                        throw new BusinessErrorException("Import.Business.Error.Duplicate", huId, (row.RowNum + 1).ToString(), colHu.ToString());
                    #endregion

                    #region 读取库格
                    binCode = row.GetCell(colBin) != null ? row.GetCell(colBin).StringCellValue : null;
                    if (cycleCount.PhyCntGroupBy == BusinessConstants.CODE_MASTER_PHYCNT_GROUPBY_BIN
                        && (binCode == null || binCode == string.Empty))
                    {
                        throw new BusinessErrorException("Import.Read.Error.Empty", (row.RowNum + 1).ToString(), colBin.ToString());
                    }
                    #endregion
                    #endregion

                    #region 填充数据
                    Hu hu = huMgr.CheckAndLoadHu(huId);
                    StorageBin bin = null;
                    if (binCode != null && binCode.Trim() != string.Empty)
                    {
                        bin = storageBinMgr.CheckAndLoadStorageBin(binCode);
                    }

                    CycleCountDetail cycleCountDetail = new CycleCountDetail();
                    cycleCountDetail.CycleCount = cycleCount;
                    cycleCountDetail.Item = hu.Item;
                    cycleCountDetail.Qty = hu.Qty * hu.UnitQty;
                    cycleCountDetail.HuId = hu.HuId;
                    cycleCountDetail.LotNo = hu.LotNo;
                    cycleCountDetail.StorageBin = bin != null ? bin.Code : null;
                    cycleCountDetailList.Add(cycleCountDetail);
                    #endregion
                }
            }

            if (cycleCountDetailList.Count == 0)
                throw new BusinessErrorException("Import.Result.Error.ImportNothing");

            return cycleCountDetailList;
        }
Exemplo n.º 4
0
        public IList<FlowPlan> ReadShipScheduleYFKFromXls(Stream inputStream, User user, string planType, string partyCode, string timePeriodType, DateTime date)
        {
            IList<FlowPlan> flowPlanList = new List<FlowPlan>();
            if (inputStream.Length == 0)
                throw new BusinessErrorException("Import.Stream.Empty");

            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);

            Sheet sheet = workbook.GetSheetAt(0);
            IEnumerator rows = sheet.GetRowEnumerator();

            ImportHelper.JumpRows(rows, 8);
            int colIndex = this.GetColumnIndexToRead_ShipScheduleYFK((HSSFRow)rows.Current, date);

            if (colIndex < 0)
                throw new BusinessErrorException("Import.MRP.DateNotExist", date.ToShortDateString());

            #region 列定义
            int colFlow = 1;//Flow
            int colUC = 6;//单包装
            #endregion

            while (rows.MoveNext())
            {
                Row row = (HSSFRow)rows.Current;
                if (!this.CheckValidDataRow(row, 1, 6))
                {
                    break;//边界
                }

                //string regCode=row.GetCell(
                string flowCode = string.Empty;
                string itemCode = string.Empty;
                decimal UC = 1;
                decimal planQty = 0;
                string refOrderNo = string.Empty;
                #region 读取客户代码
                //try
                //{
                //    pCode = row.GetCell(1).StringCellValue;
                //    if (pCode.Trim() == string.Empty)
                //        throw new BusinessErrorException("Import.MRP.Empty.Error.Customer", (row.RowNum + 1).ToString());

                //    if (partyCode != null && partyCode.Trim() != string.Empty)
                //    {
                //        if (pCode.Trim().ToUpper() != partyCode.Trim().ToUpper())
                //            continue;//客户过滤
                //    }
                //}
                //catch
                //{
                //    throw new BusinessErrorException("Import.MRP.Read.Error.Customer", (row.RowNum + 1).ToString());
                //}
                #endregion

                #region 读取参考订单号
                try
                {
                    refOrderNo = row.GetCell(3).StringCellValue;
                }
                catch { throw new BusinessErrorException("Import.MRP.Read.Error.RefOrderNo", (row.RowNum + 1).ToString()); }

                #endregion

                #region 读取Flow
                try
                {
                    flowCode = row.GetCell(colFlow).StringCellValue;
                    if (flowCode.Trim() == string.Empty)
                        continue;
                }
                catch
                {
                    this.ThrowCommonError(row, colIndex);
                }
                #endregion

                #region 读取成品代码
                try
                {
                    itemCode = row.GetCell(4).StringCellValue;
                    if (itemCode == string.Empty)
                        throw new BusinessErrorException("Import.PSModel.Empty.Error.ItemCode", (row.RowNum + 1).ToString());
                }
                catch
                {
                    throw new BusinessErrorException("Import.PSModel.Read.Error.ItemCode", (row.RowNum + 1).ToString());
                }
                #endregion

                #region 读取单包装
                try
                {
                    UC = Convert.ToDecimal(row.GetCell(colUC).NumericCellValue);
                }
                catch
                {
                    this.ThrowCommonError(row.RowNum, colUC, row.GetCell(colUC));
                }
                #endregion

                #region 读取计划量
                try
                {
                    planQty = Convert.ToDecimal(row.GetCell(colIndex).NumericCellValue);
                }
                catch
                {
                    throw new BusinessErrorException("Import.PSModel.Read.Error.PlanQty", (row.RowNum + 1).ToString());
                }
                #endregion

                FlowDetail flowDetail = this.LoadFlowDetailByFlow(flowCode, itemCode, UC);
                if (flowDetail == null)
                    throw new BusinessErrorException("Import.MRP.Distribution.FlowDetail.Not.Exist", (row.RowNum + 1).ToString());

                if (partyCode != null && partyCode.Trim() != string.Empty)
                {
                    if (!StringHelper.Eq(flowCode, partyCode))
                        continue;//客户过滤
                }

                //区域过滤
                if (partyCode != null && partyCode.Trim() != string.Empty)
                {
                    if (!StringHelper.Eq(partyCode, flowDetail.Flow.PartyTo.Code))
                        continue;//客户过滤
                }
                //区域权限过滤
                if (!user.HasPermission(flowDetail.Flow.PartyFrom.Code) && !user.HasPermission(flowDetail.Flow.PartyTo.Code))
                    continue;

                FlowPlan flowPlan = new FlowPlan();
                flowPlan.FlowDetail = flowDetail;
                flowPlan.TimePeriodType = timePeriodType;
                flowPlan.ReqDate = date;
                flowPlan.PlanQty = planQty;
                flowPlan.RefOrderNo = refOrderNo;
                flowPlanList.Add(flowPlan);
            }

            if (flowPlanList.Count == 0)
                throw new BusinessErrorException("Import.Result.Error.ImportNothing");

            return flowPlanList;
        }
Exemplo n.º 5
0
        private Repack CreateRepack(IList<RepackDetail> repackDetailList, string type, User user)
        {
            IList<RepackDetail> inRepackDetailList = new List<RepackDetail>();
            IList<RepackDetail> outRepackDetailList = new List<RepackDetail>();

            #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);
                        }
                        else
                        {
                            throw new TechnicalException("Invalid IO Type:" + repackDetail.IOType);
                        }
                    }
                }

                if (inRepackDetailList.Count == 0 || outRepackDetailList.Count == 0)
                {
                    throw new BusinessErrorException("MasterData.Inventory.Repack.Error.RepackDetailEmpty");
                }
            }
            else
            {
                throw new BusinessErrorException("MasterData.Inventory.Repack.Error.RepackDetailEmpty");
            }
            #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.locationLotDetailMgrE.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(entityPreferenceMgrE.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.numberControlMgrE.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.locationMgrE.InventoryRepackIn(inRepackDetail, user);

                this.repackDetailMgrE.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.locationMgrE.InventoryRepackOut(outRepackDetail, location, plannedBillId, user);
                outRepackDetail.LocationLotDetail = this.locationLotDetailMgrE.LoadLocationLotDetail(inventoryTransaction.LocationLotDetailId);

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

            return repack;
        }
Exemplo n.º 6
0
        public Resolver AnalyzeBarcode(string barcode, User user, string moduleType)
        {
            Resolver resolver = new Resolver();
            resolver.ModuleType = moduleType;
            resolver.UserCode = user.Code;

            if (barcode == null || barcode.Trim() == string.Empty)
            {
                return resolver;
            }
            //Order
            if (barcode.StartsWith(BusinessConstants.CODE_PREFIX_ORDER))
            {
                resolver.BarcodeHead = BusinessConstants.CODE_PREFIX_ORDER;
                resolver.Code = barcode;
                OrderHead orderHead = orderHeadMgr.CheckAndLoadOrderHead(resolver.Code);
                Flow flow = this.flowMgr.LoadFlow(orderHead.Flow);

                #region CopyProperty from OrderHead
                resolver.Description = flow.Description;
                resolver.NeedPrintAsn = orderHead.NeedPrintAsn;
                resolver.NeedPrintReceipt = orderHead.NeedPrintReceipt;
                resolver.AllowExceed = orderHead.AllowExceed;
                resolver.OrderType = orderHead.Type;
                resolver.AntiResolveHu = orderHead.AntiResolveHu;
                if (moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_SHIP)
                {
                    resolver.IsScanHu = orderHead.IsShipScanHu;
                }
                else if (moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_RECEIVE)
                {
                    resolver.IsScanHu = orderHead.IsReceiptScanHu;
                }
                else
                {
                    resolver.IsScanHu = orderHead.IsShipScanHu || orderHead.IsReceiptScanHu;
                }
                #endregion

                #region 校验
                //校验权限
                if (!user.HasPermission(orderHead.PartyFrom.Code)
                 || !user.HasPermission(orderHead.PartyTo.Code))
                {
                    throw new BusinessErrorException("Common.Business.Error.NoPermission");
                }

                #region 校验状态:Status
                if (moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_SHIP
                    || moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_RECEIVE
                    || moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_OFFLINE)
                {
                    if (orderHead.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS)
                    {
                        throw new BusinessErrorException("Common.Business.Error.StatusError", orderHead.OrderNo, orderHead.Status);
                    }
                }
                else if (moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_ONLINE)
                {
                    if (orderHead.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT)
                    {
                        throw new BusinessErrorException("Common.Business.Error.StatusError", orderHead.OrderNo, orderHead.Status);
                    }
                }
                #endregion

                #region 校验类型:Type
                if (moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_OFFLINE
                    || moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_ONLINE)
                {
                    if (orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                    {
                        throw new BusinessErrorException("Order.Error.OrderOfflineIsNotProduction", orderHead.OrderNo, orderHead.Type);
                    }
                }
                else if (moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_SHIP)
                {
                    if (orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT
                        && orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION
                        && orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_TRANSFER)
                    {
                        throw new BusinessErrorException("Order.Error.OrderShipIsNotProduction", orderHead.OrderNo, orderHead.Type);
                    }
                }
                else if (moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_RECEIVE)
                {
                    if (orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_CUSTOMERGOODS
                    && orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT
                    && orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_TRANSFER)
                    {
                        throw new BusinessErrorException("Order.Error.OrderReceiveIsNotProduction", orderHead.OrderNo, orderHead.Type);
                    }
                }
                #endregion

                #endregion
            }
            //PickList
            else if (barcode.StartsWith(BusinessConstants.CODE_PREFIX_PICKLIST))
            {
                resolver.BarcodeHead = BusinessConstants.CODE_PREFIX_PICKLIST;
                resolver.Code = barcode;
                PickList pickList = pickListMgr.CheckAndLoadPickList(resolver.Code);
                resolver.PickBy = pickList.PickBy;
                //resolver.IsDetailContainHu = true;
                resolver.IsScanHu = true;//目前只有支持Hu才支持拣货
                resolver.OrderType = pickList.OrderType;

                #region 校验
                //校验权限
                if (!user.HasPermission(pickList.PartyFrom.Code)
                || !user.HasPermission(pickList.PartyTo.Code))
                {
                    throw new BusinessErrorException("Common.Business.Error.NoPermission");
                }

                if (moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_SHIP)
                {
                    //校验状态
                    if (pickList.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT
                        && moduleType != BusinessConstants.TRANSFORMER_MODULE_TYPE_PICKLIST)
                    {
                        throw new BusinessErrorException("Common.Business.Error.StatusError", pickList.PickListNo, pickList.Status);
                    }
                    if (pickList.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE
                        && moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_PICKLIST)
                    {
                        throw new BusinessErrorException("Common.Business.Error.StatusError", pickList.PickListNo, pickList.Status);
                    }
                }
                #endregion
            }
            //ASN
            else if (barcode.StartsWith(BusinessConstants.CODE_PREFIX_ASN))
            {
                resolver.BarcodeHead = BusinessConstants.CODE_PREFIX_ASN;
                resolver.Code = barcode;
                InProcessLocation inProcessLocation = inProcessLocationMgr.CheckAndLoadInProcessLocation(resolver.Code);
                #region CopyProperty from ASN
                //resolver.IsDetailContainHu = inProcessLocation.IsDetailContainHu;
                resolver.IsScanHu = inProcessLocation.IsReceiptScanHu;
                //resolver.NeedPrintReceipt=inProcessLocation.
                resolver.PickBy = inProcessLocation.IsDetailContainHu ? BusinessConstants.CODE_MASTER_PICKBY_HU : BusinessConstants.CODE_MASTER_PICKBY_ITEM;
                //resolver.PickBy = inProcessLocation.IsReceiptScanHu ? BusinessConstants.CODE_MASTER_PICKBY_HU : BusinessConstants.CODE_MASTER_PICKBY_ITEM;
                resolver.OrderType = inProcessLocation.OrderType;
                //resolver.AntiResolveHu =
                #endregion

                #region 校验
                //校验权限
                if (!user.HasPermission(inProcessLocation.PartyFrom.Code)
                    || !user.HasPermission(inProcessLocation.PartyTo.Code))
                {
                    throw new BusinessErrorException("Common.Business.Error.NoPermission");
                }

                if (moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_RECEIVE)
                {
                    //校验状态
                    if (inProcessLocation.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE)
                    {
                        throw new BusinessErrorException("Common.Business.Error.StatusError", inProcessLocation.IpNo, inProcessLocation.Status);
                    }
                }
                #endregion
            }

            #region 检验 Inspect
            else if (barcode.StartsWith(BusinessConstants.CODE_PREFIX_INSPECTION))
            {
                resolver.BarcodeHead = BusinessConstants.CODE_PREFIX_INSPECTION;
                resolver.Code = barcode;
                InspectOrder inspectOrder = inspectOrderMgr.CheckAndLoadInspectOrder(resolver.Code);
                resolver.IsScanHu = inspectOrder.IsDetailHasHu;
                if (resolver.IsScanHu)
                {
                    resolver.PickBy = BusinessConstants.CODE_MASTER_PICKBY_HU;
                }
                else
                {
                    resolver.PickBy = BusinessConstants.CODE_MASTER_PICKBY_ITEM;
                }
                //if (inspectOrder.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE)
                //{
                //    throw new BusinessErrorException("InspectOrder.Error.StatusIsNotValid", inspectOrder.Status);
                //}
            }
            #endregion
            //Special,"$"
            else if (barcode.StartsWith(BusinessConstants.BARCODE_SPECIAL_MARK))
            {
                if (barcode.Length > 1)
                {
                    resolver.BarcodeHead = barcode.Substring(1, 1);
                }
                if (barcode.Length > 2)
                {
                    resolver.Code = barcode.Substring(2, barcode.Length - 2);
                }

                //Bin
                if (resolver.BarcodeHead == BusinessConstants.BARCODE_HEAD_BIN)
                {
                    if (resolver.Code == null || resolver.Code == string.Empty)
                    {
                        return resolver;
                    }
                    StorageBin storageBin = storageBinMgr.CheckAndLoadStorageBin(resolver.Code);
                    resolver.Description = storageBin.Description;
                    resolver.BinCode = resolver.Code;

                    #region 校验
                    if (!storageBin.IsActive)
                    {
                        throw new BusinessErrorException("Common.Business.Error.EntityInActive", storageBin.Code);
                    }

                    if (!user.HasPermission(storageBin.Area.Location.Region.Code))
                    {
                        throw new BusinessErrorException("Common.Business.Error.NoPermission");
                    }
                    #endregion
                }
                //Flow
                else if (resolver.CodePrefix == BusinessConstants.BARCODE_HEAD_FLOW)
                {
                    Flow flow = flowMgr.CheckAndLoadFlow(resolver.Code);
                    resolver.Description = flow.Description;
                    resolver.IsScanHu = flow.IsShipScanHu || flow.IsReceiptScanHu;
                    resolver.OrderType = flow.Type;
                    resolver.AllowCreateDetail = flow.AllowCreateDetail;

                    #region 校验
                    if (!flow.IsActive)
                    {
                        throw new BusinessErrorException("Common.Business.Error.EntityInActive", flow.Code);
                    }

                    if (!user.HasPermission(flow.PartyFrom.Code)
                    || !user.HasPermission(flow.PartyTo.Code))
                    {
                        throw new BusinessErrorException("Common.Business.Error.NoPermission");
                    }

                    if (flow.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_TRANSFER
                        && moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_TRANSFER)
                    {
                        throw new BusinessErrorException("Flow.Error.FlowTypeIsNotTransfer", flow.Type);
                    }
                    else if (flow.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT
                        && moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_RECEIVERETURN)
                    {
                        throw new BusinessErrorException("Flow.ReceiveReturn.Error.FlowTypeIsNotProcurement", flow.Type);
                    }
                    else if (flow.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION
                        && moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_SHIPRETURN)
                    {
                        throw new BusinessErrorException("Flow.ShipReturn.Error.FlowTypeIsNotDistribution", flow.Type);
                    }
                    else if (flow.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION
                        && (moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_FLUSHBACK ||
                        moduleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_MATERIALIN))
                    {
                        throw new BusinessErrorException("Flow.ShipReturn.Error.FlowTypeIsNotDistribution", flow.Type);
                    }
                    #endregion
                }
                //Command
                else if (resolver.BarcodeHead == BusinessConstants.BARCODE_HEAD_OK
                    || resolver.BarcodeHead == BusinessConstants.BARCODE_HEAD_CANCEL)
                {
                    resolver.Command = resolver.BarcodeHead;
                }
            }
            else
            {
                resolver.BarcodeHead = BusinessConstants.BARCODE_HEAD_DEFAULT;
                resolver.Code = barcode;
            }
            return resolver;
        }
Exemplo n.º 7
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;
        }