コード例 #1
0
        public IList<InventoryTransaction> BackflushVanProductMaterial(IList<BackflushInput> backflushInputList)
        {
            User currentUser = SecurityContextHolder.Get();
            DateTime dateTimeNow = DateTime.Now;

            IList<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();
            foreach (BackflushInput backflushInput in backflushInputList)
            {
                DateTime thisOfflineDate = backflushInput.EffectiveDate.HasValue ? backflushInput.EffectiveDate.Value : dateTimeNow;
                InventoryIO inventoryIO = new InventoryIO();

                inventoryIO.Location = backflushInput.Location;
                inventoryIO.Item = backflushInput.Item;
                //inventoryIO.HuId = 
                inventoryIO.Qty = -backflushInput.Qty;  //发货为负数
                //inventoryIO.LotNo = 
                inventoryIO.QualityType = CodeMaster.QualityType.Qualified; //回冲的物料一定是合格品,不能回冲不合格品物料
                inventoryIO.IsATP = true;
                inventoryIO.IsFreeze = false;                       //可能指定冻结的零件?
                //inventoryIO.IsCreatePlanBill = 
                //inventoryIO.IsConsignment = 
                //inventoryIO.PlanBill = 
                //inventoryIO.ActingBill = 
                inventoryIO.TransactionType = CodeMaster.TransactionType.ISS_WO;
                //inventoryIO.OccupyType = 
                //inventoryIO.OccupyReferenceNo = 
                inventoryIO.IsVoid = false;
                inventoryIO.EffectiveDate = thisOfflineDate;
                //inventoryIO.ManufactureParty = ;

                IList<InventoryTransaction> thisInventoryTransactionList = RecordInventory(inventoryIO);
                RecordLocationTransaction(backflushInput, thisOfflineDate, thisInventoryTransactionList, false);
                ((List<InventoryTransaction>)inventoryTransactionList).AddRange(thisInventoryTransactionList);

                #region 记录OrderBackflushDetail
                if (thisInventoryTransactionList != null && thisInventoryTransactionList.Count > 0)
                {
                    decimal backflushedQty = thisInventoryTransactionList.Sum(trans => trans.Qty) / backflushInput.UnitQty;
                    if (backflushedQty != 0)
                    {
                        OrderBackflushDetail orderBackflushDetail = new OrderBackflushDetail();
                        orderBackflushDetail.OrderNo = backflushInput.OrderNo;
                        orderBackflushDetail.OrderDetailId = backflushInput.OrderDetailId;
                        orderBackflushDetail.OrderDetailSequence = backflushInput.OrderDetailSequence;
                        if (backflushInput.OrderBomDetail != null)
                        {
                            orderBackflushDetail.OrderBomDetailId = backflushInput.OrderBomDetail.Id;
                            orderBackflushDetail.OrderBomDetailSequence = backflushInput.OrderBomDetail.Sequence;
                            orderBackflushDetail.Bom = backflushInput.OrderBomDetail.Bom;
                            orderBackflushDetail.ManufactureParty = backflushInput.OrderBomDetail.ManufactureParty;
                        }
                        orderBackflushDetail.ReceiptNo = backflushInput.ReceiptNo;
                        orderBackflushDetail.ReceiptDetailId = backflushInput.ReceiptDetailId;
                        orderBackflushDetail.ReceiptDetailSequence = backflushInput.ReceiptDetailSequence;
                        orderBackflushDetail.FGItem = backflushInput.FGItem;
                        orderBackflushDetail.Item = backflushInput.Item;
                        orderBackflushDetail.ItemDescription = backflushInput.ItemDescription;
                        orderBackflushDetail.ReferenceItemCode = backflushInput.ReferenceItemCode;
                        orderBackflushDetail.Uom = backflushInput.Uom;
                        orderBackflushDetail.BaseUom = backflushInput.BaseUom;
                        orderBackflushDetail.UnitQty = backflushInput.UnitQty;
                        orderBackflushDetail.TraceCode = backflushInput.TraceCode;
                        //orderBackflushDetail.HuId = backflushInput.HuId;
                        //LotNo = result.Key.LotNo,
                        orderBackflushDetail.Operation = backflushInput.Operation;
                        orderBackflushDetail.OpReference = backflushInput.OpReference;
                        orderBackflushDetail.BackflushedQty = backflushedQty;
                        //orderBackflushDetail.BackflushedRejectQty = 0;
                        //BackflushedScrapQty = input.BackflushedQty,
                        orderBackflushDetail.LocationFrom = backflushInput.Location;
                        orderBackflushDetail.ProductLine = backflushInput.ProductLine;
                        orderBackflushDetail.ProductLineFacility = backflushInput.ProductLineFacility;
                        //orderBackflushDetail.PlanBill = null;
                        orderBackflushDetail.EffectiveDate = thisOfflineDate;
                        orderBackflushDetail.CreateUserId = currentUser.Id;
                        orderBackflushDetail.CreateUserName = currentUser.FullName;
                        orderBackflushDetail.CreateDate = dateTimeNow;
                        orderBackflushDetail.IsVoid = false;

                        this.genericMgr.Create(orderBackflushDetail);
                    }
                }
                #endregion
            }

            return inventoryTransactionList;
        }
コード例 #2
0
        private Location TryLoadLocation(InventoryIO inventoryIO)
        {
            if (inventoryIO.CurrentLocation == null)
            {
                inventoryIO.CurrentLocation = genericMgr.FindById<Location>(inventoryIO.Location);
            }

            return inventoryIO.CurrentLocation;
        }
コード例 #3
0
        private ActingBill TryLoadActingBill(InventoryIO inventoryIO)
        {
            if (inventoryIO.CurrentActingBill == null)
            {
                inventoryIO.CurrentActingBill = genericMgr.FindById<ActingBill>(inventoryIO.ActingBill);
            }

            return inventoryIO.CurrentActingBill;
        }
コード例 #4
0
        private LocationLotDetail CreateNewLocationLotDetail(InventoryIO inventoryIO, IList<InventoryTransaction> inventoryTransactionList)
        {
            #region 是否允许负库存,占用不能出现负数库存,待验和不合格品不允许出现负库存
            if (inventoryIO.Qty < 0)
            {
                if (//inventoryIO.OccupyType != com.Sconit.CodeMaster.OccupyType.None || 
                    inventoryIO.QualityType != CodeMaster.QualityType.Qualified
                    || !TryLoadLocation(inventoryIO).AllowNegative)
                {
                    throw new BusinessException(Resources.INV.LocationLotDetail.Errors_NotEnoughInventory, inventoryIO.Item, inventoryIO.Location);
                }
            }
            #endregion

            #region 冲销时按指定PlanBill出库数量不足
            //只有冲销才会出现这种情况?
            if (inventoryIO.Qty < 0 && inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue)
            {
                throw new BusinessException(Resources.INV.LocationLotDetail.Errors_VoidFailNotEnoughSpecifyInventory, inventoryIO.Location, inventoryIO.Item);
            }
            #endregion

            //todo disabled的零件能不能做库存事务

            #region 虚零件和套件不能做库存事务不能做库存事务
            Item item = TryLoadItem(inventoryIO);
            if (item.IsVirtual)
            {
                throw new BusinessException(Resources.INV.LocationLotDetail.Errors_VirtualItemCannotProcessInventory, inventoryIO.Item);
            }

            if (item.IsKit)
            {
                throw new BusinessException(Resources.INV.LocationLotDetail.Errors_KitItemCannotProcessInventory, inventoryIO.Item);
            }
            #endregion

            #region 收货结算/入库结算/检验结算
            SettleBillTransaction billTransaction = null;
            if (inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue)
            {
                PlanBill pb = TryLoadPlanBill(inventoryIO);

                if (pb.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.ReceivingSettlement  //收货结算
                    || (pb.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.OnlineBilling && TryLoadLocation(inventoryIO).IsConsignment) //上线结算
                    || (pb.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.AfterInspection     //检验结算,检验合格收货事务或者让步使用收货事务
                    //&& inventoryIO.QualityType == com.Sconit.CodeMaster.QualityType.Qualified
                        && (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_INP_QDII
                        || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_INP_CCS))
                    || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_SO)   //销售退货收货立即结算
                {
                    if (inventoryIO.QualityType == CodeMaster.QualityType.Inspect)
                    {
                        throw new BusinessException("待验物料{0}不能结算。", inventoryIO.Item);
                    }
                    else if (inventoryIO.QualityType == CodeMaster.QualityType.Reject)
                    {
                        //throw new BusinessException("不合格物料{0}不能结算。", inventoryIO.Item);
                    }

                    pb.CurrentActingQty = inventoryIO.Qty / pb.UnitQty;
                    pb.CurrentLocation = inventoryIO.Location;
                    billTransaction = this.billMgr.SettleBill(pb, inventoryIO.EffectiveDate);

                    inventoryIO.IsConsignment = false;
                    //inventoryIO.PlanBill = null;
                }
            }
            #endregion

            #region 处理冲销寄售和结算信息
            if (billTransaction == null)
            {
                //已经做了结算不可能发生冲销
                billTransaction = VoidBill(inventoryIO);
            }
            #endregion

            #region 创建库存明细
            LocationLotDetail newLocationLotDetail = Mapper.Map<InventoryIO, LocationLotDetail>(inventoryIO);

            if (!string.IsNullOrWhiteSpace(newLocationLotDetail.HuId))
            {
                #region 更新条码首次入库日期
                Hu hu = inventoryIO.CurrentHu;
                if (hu == null)
                {
                    hu = this.genericMgr.FindById<Hu>(newLocationLotDetail.HuId);
                }

                if (!hu.FirstInventoryDate.HasValue)
                {
                    hu.FirstInventoryDate = DateTime.Now;
                    this.genericMgr.Update(hu);
                }
                #endregion
                //  huId = huId.ToUpper();
                //newLocationLotDetail.Hu = this.huMgrE.LoadHu(huId);

                ////库存数量和条码上的数量有差异,更新条码上的数量
                //if (newLocationLotDetail.Hu.Qty * newLocationLotDetail.Hu.UnitQty != qty)
                //{
                //    newLocationLotDetail.Hu.Qty = qty / newLocationLotDetail.Hu.UnitQty;
                //}
                //newLocationLotDetail.Hu.Location = location.Code;
                //newLocationLotDetail.Hu.Status = BusinessConstants.CODE_MASTER_HU_STATUS_VALUE_INVENTORY;

                //this.huMgrE.UpdateHu(newLocationLotDetail.Hu);

                if (newLocationLotDetail.Qty < 0)
                {
                    throw new TechnicalException("Barcode qty can't less than 0.");
                }
            }

            //入库

            LocationLotDetail mergeLocationLotDetail = null;
            if (string.IsNullOrWhiteSpace(newLocationLotDetail.HuId) && newLocationLotDetail.IsConsignment == false
                && newLocationLotDetail.IsFreeze == false && newLocationLotDetail.IsATP == true
                && newLocationLotDetail.OccupyType == CodeMaster.OccupyType.None)
            {
                #region 查找库存明细是否可以合并,有条码的不能合并(负库存,整数可用非寄售库存合并)
                mergeLocationLotDetail = this.genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetMergeInventory ?,?,?,?,?,?"
                    , new object[] { newLocationLotDetail.Location, newLocationLotDetail.Item, newLocationLotDetail.Qty,
                                     newLocationLotDetail.IsFreeze, newLocationLotDetail.IsATP, newLocationLotDetail.OccupyType}
                    , new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Decimal, 
                                    NHibernate.NHibernateUtil.Boolean,NHibernate.NHibernateUtil.Boolean, NHibernate.NHibernateUtil.Int16 }).FirstOrDefault();
                #endregion
            }

            if (mergeLocationLotDetail != null)
            {
                mergeLocationLotDetail.Qty += newLocationLotDetail.Qty;
                this.genericMgr.Update(mergeLocationLotDetail);
                //inventoryTransactionList.Add(CreateInventoryTransaction(inventoryIO, inventoryIO.Qty, mergeLocationLotDetail, billTransaction));
            }
            else
            {
                this.genericMgr.Create(newLocationLotDetail);
                //inventoryTransactionList.Add(CreateInventoryTransaction(inventoryIO, inventoryIO.Qty, newLocationLotDetail, billTransaction));
            }
            //this.genericMgr.Create(newLocationLotDetail);
            #endregion

            //inventoryTransactionList.Add(CreateInventoryTransaction(newLocationLotDetail, newLocationLotDetail.Qty, inventoryIO.IsCreatePlanBill, billTransaction));
            inventoryTransactionList.Add(CreateInventoryTransaction(inventoryIO, inventoryIO.Qty, newLocationLotDetail, billTransaction));

            return newLocationLotDetail;
        }
コード例 #5
0
        private InventoryTransaction CreateInventoryTransaction(InventoryIO inventoryIO, decimal qty, LocationLotDetail backFlushLocLotDet, SettleBillTransaction billTransaction)
        {
            InventoryTransaction inventoryTransaction = new InventoryTransaction();
            inventoryTransaction.LocationLotDetailId = backFlushLocLotDet.Id;
            inventoryTransaction.Location = inventoryIO.Location;
            inventoryTransaction.Bin = inventoryIO.Bin;
            inventoryTransaction.Item = inventoryIO.Item;
            inventoryTransaction.HuId = inventoryIO.HuId;
            inventoryTransaction.LotNo = inventoryIO.LotNo;
            inventoryTransaction.IsCreatePlanBill = inventoryIO.IsCreatePlanBill;
            inventoryTransaction.IsConsignment = inventoryIO.IsConsignment;
            inventoryTransaction.PlanBill = inventoryIO.PlanBill;
            if (inventoryIO.IsConsignment)
            {
                //寄售库存
                inventoryTransaction.PlanBillQty = qty;
            }
            if (billTransaction != null)   //发生了结算,记录结算数量
            {
                inventoryTransaction.BillTransactionId = billTransaction.Id;
                inventoryTransaction.IsConsignment = false;
                inventoryTransaction.ActingBill = billTransaction.ActingBill;
                inventoryTransaction.ActingBillQty = qty;             //基本单位
                inventoryTransaction.PlanBillQty = inventoryIO.Qty - qty;
            }
            inventoryTransaction.Qty = qty;
            inventoryTransaction.QualityType = inventoryIO.QualityType;
            inventoryTransaction.IsATP = inventoryIO.IsATP;
            inventoryTransaction.IsFreeze = inventoryIO.IsFreeze;
            inventoryTransaction.OccupyType = inventoryIO.OccupyType;
            inventoryTransaction.OccupyReferenceNo = inventoryIO.OccupyReferenceNo;

            return inventoryTransaction;
        }
コード例 #6
0
        public IList<InventoryTransaction> CancelInventoryExchange(IList<ItemExchange> itemExchangeList)
        {
            if (itemExchangeList != null && itemExchangeList.Count > 0)
            {

                foreach (ItemExchange itemExchange in itemExchangeList)
                {
                    if (!itemExchange.IsVoid)
                    {
                        itemExchange.IsVoid = true;
                        this.genericMgr.Update(itemExchange);
                    }
                    else
                    {
                        throw new BusinessException("库存物料替换已经冲销。");
                    }
                }

                List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();
                foreach (ItemExchange itemExchange in itemExchangeList)
                {
                    #region 入库冲销
                    InventoryIO inventoryIn = new InventoryIO();

                    inventoryIn.Location = itemExchange.LocationTo;
                    inventoryIn.Item = itemExchange.ItemTo;
                    inventoryIn.HuId = itemExchange.NewHu;
                    inventoryIn.Qty = -itemExchange.NewQty * itemExchange.NewUnitQty; ;
                    inventoryIn.LotNo = itemExchange.LotNo;
                    //inventoryIn.ManufactureParty = null;
                    inventoryIn.QualityType = itemExchange.QualityType;
                    inventoryIn.IsATP = itemExchange.QualityType == CodeMaster.QualityType.Qualified;
                    inventoryIn.IsFreeze = false;
                    inventoryIn.IsCreatePlanBill = false;
                    inventoryIn.IsConsignment = false;
                    inventoryIn.PlanBill = null;
                    inventoryIn.ActingBill = null;
                    //inventoryIn.TransactionType = CodeMaster.TransactionType.RCT_IIC_VOID;
                    inventoryIn.OccupyType = CodeMaster.OccupyType.None;
                    inventoryIn.OccupyReferenceNo = null;
                    inventoryIn.IsVoid = true;
                    inventoryIn.EffectiveDate = itemExchange.EffectiveDate;
                    //inventoryOut.ManufactureParty = ;

                    IList<InventoryTransaction> currentInventoryInTransactionList = RecordInventory(inventoryIn);

                    RecordLocationTransaction(itemExchange, currentInventoryInTransactionList, false, true);
                    inventoryTransactionList.AddRange(currentInventoryInTransactionList);
                    #endregion

                    #region 出库
                    InventoryIO inventoryOut = new InventoryIO();

                    inventoryOut.Location = itemExchange.LocationFrom;
                    inventoryOut.Item = itemExchange.ItemFrom;
                    inventoryOut.HuId = itemExchange.OldHu;
                    inventoryOut.Qty = itemExchange.Qty * itemExchange.UnitQty;
                    inventoryOut.LotNo = itemExchange.LotNo;
                    //inventoryOut.ManufactureParty = null;
                    inventoryOut.QualityType = itemExchange.QualityType;
                    inventoryOut.IsATP = itemExchange.QualityType == CodeMaster.QualityType.Qualified;
                    inventoryOut.IsFreeze = false;
                    inventoryOut.IsCreatePlanBill = false;
                    inventoryOut.IsConsignment = false;
                    inventoryOut.PlanBill = null;
                    inventoryOut.ActingBill = null;
                    //inventoryOut.TransactionType = CodeMaster.TransactionType.ISS_IIC_VOID;
                    inventoryOut.OccupyType = CodeMaster.OccupyType.None;
                    inventoryOut.OccupyReferenceNo = null;
                    inventoryOut.IsVoid = true;
                    inventoryOut.EffectiveDate = itemExchange.EffectiveDate;
                    //inventoryOut.ManufactureParty = itemExchange.ManufactureParty;

                    IList<InventoryTransaction> currentInventoryOutTransactionList = RecordInventory(inventoryOut);

                    RecordLocationTransaction(itemExchange, currentInventoryOutTransactionList, true, true);
                    inventoryTransactionList.AddRange(currentInventoryOutTransactionList);
                    #endregion
                }

                return inventoryTransactionList;
            }

            return null;
        }
コード例 #7
0
        private IList<InventoryTransaction> RecordInventory(InventoryIO inventoryIO)
        {
            #region 判断库存生效日期是否有效
            FinanceCalendar financeCalendar = financeCalendarMgr.GetNowEffectiveFinanceCalendar();
            //前开后闭
            if (financeCalendar.StartDate >= inventoryIO.EffectiveDate)
            {
                throw new BusinessException(string.Format("库存的生效日期{0}小于当前财政月的开始日期{1},不能进行库存操作。", inventoryIO.EffectiveDate, financeCalendar.StartDate));
            }
            #endregion

            IList<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();

            if (inventoryIO.LocationLotDetailId.HasValue)
            {
                #region 指定库存明细出库
                LocationLotDetail locationLotDetail = this.genericMgr.FindById<LocationLotDetail>(inventoryIO.LocationLotDetailId.Value);

                if (!string.IsNullOrWhiteSpace(locationLotDetail.HuId))
                {
                    throw new TechnicalException("条码库存不能指定库存明细出库。");
                }

                //记录被回冲的记录
                inventoryTransactionList.Add(CreateInventoryTransaction(locationLotDetail, -locationLotDetail.Qty, false, null));

                //更新库存数量
                //locationLotDetail.Qty += inventoryIO.Qty;
                locationLotDetail.Qty = 0;
                this.genericMgr.Update(locationLotDetail);
                #endregion
            }
            else if (!string.IsNullOrWhiteSpace(inventoryIO.HuId))
            {
                #region 有Hu
                //寄售/非寄售处理逻辑相同
                if (inventoryIO.Qty > 0)
                {
                    #region 入库数量 > 0
                    HuStatus huStatus = this.huMgr.GetHuStatus(inventoryIO.HuId);
                    if (huStatus.Status != CodeMaster.HuStatus.NA)
                    {
                        //if (huStatusList.Count > 1)
                        //{
                        //    throw new TechnicalException("HuId " + inventoryIO.HuId + "exist in two different location or ipdetail.");
                        //}

                        //HuStatus huStatus = huStatusList[0];

                        //同一个条码在所有库位中不能出现两次
                        if (huStatus.Status == CodeMaster.HuStatus.Location)
                        {
                            throw new BusinessException(Resources.INV.LocationLotDetail.Errors_HuIsAlreadyInLocation, inventoryIO.HuId, huStatus.Location);
                        }
                        else
                        {
                            throw new BusinessException("条码{0}是从库位{1}到库位{2}的在途库存,不能重复入库。", inventoryIO.HuId, huStatus.LocationFrom, huStatus.LocationTo);
                        }
                    }

                    inventoryIO.LotNo = huStatus.LotNo;
                    CreateNewLocationLotDetail(inventoryIO, inventoryTransactionList);
                    #endregion
                }
                else if (inventoryIO.Qty < 0)
                {
                    #region 入库数量 < 0 / 出库
                    LocationLotDetail locationLotDetail = this.GetHuLocationLotDetail(inventoryIO.HuId);

                    if (locationLotDetail == null)
                    {
                        //任意库位没有找到指定的HU
                        throw new BusinessException(Resources.INV.LocationLotDetail.Errors_HuNotInAnyLocation, inventoryIO.HuId);
                    }

                    if (locationLotDetail.Location != inventoryIO.Location)
                    {
                        //HU不在指定的库位
                        throw new BusinessException(Resources.INV.LocationLotDetail.Errors_HuNotInSpecifiedLocation, inventoryIO.HuId, inventoryIO.Location);
                    }

                    if (locationLotDetail.Qty + inventoryIO.Qty != 0)
                    {
                        //Hu中Item的数量不等于出库数
                        throw new BusinessException(Resources.INV.LocationLotDetail.Errors_HuQtyNotEqualShipQty, inventoryIO.HuId, locationLotDetail.Qty.ToString("0.###"), inventoryIO.Qty.ToString("0.###"));
                    }

                    #region 判断条码冻结
                    if (locationLotDetail.IsFreeze)
                    {
                        throw new BusinessException(Resources.INV.LocationLotDetail.Errors_HuFrozenCantShip, inventoryIO.HuId);
                    }
                    #endregion

                    #region 判断订单占用
                    BusinessException businessException = new BusinessException();
                    if (inventoryIO.OccupyType != locationLotDetail.OccupyType)
                    {
                        if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.None)
                        {
                            //要求订单没有被占用,实际被占用
                            CheckLocationLotDetailOccupied(locationLotDetail, businessException);
                        }
                        else if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.Inspect)
                        {
                            //检查是否被检验单占用
                            CheckLocationLotDetailOccupiedByInspectOrder(locationLotDetail, inventoryIO.OccupyReferenceNo, businessException);
                        }
                        else if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.Pick)
                        {
                            //检查是否被捡货单占用
                            CheckLocationLotDetailOccupiedByPickList(locationLotDetail, inventoryIO.OccupyReferenceNo, businessException);
                        }
                        else if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.Sequence)
                        {
                            //检查是否被排序单占用
                            CheckLocationLotDetailOccupiedBySequenceOrder(locationLotDetail, inventoryIO.OccupyReferenceNo, businessException);
                        }
                        else if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.MiscOrder)
                        {
                            //检查是否被计划出入库单占用
                            CheckLocationLotDetailOccupiedByMiscOrder(locationLotDetail, inventoryIO.OccupyReferenceNo, businessException);
                        }
                    }

                    if (businessException.HasMessage)
                    {
                        throw businessException;
                    }
                    #endregion

                    #region 处理寄售
                    SettleBillTransaction billTransaction = null;
                    if (locationLotDetail.IsConsignment && locationLotDetail.PlanBill.HasValue                 //是否有RCT类型的出库?
                        && (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_WO      //生产出库
                            || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SWO      //委外生产出库
                            || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_UNP  //计划外出库
                            || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_MIN  //投料 李秋云
                            || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SO   //销售出库
                        //|| inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_PO   //采购退库  采购退货出库出口库不需要处理寄售,在采购退货收货时处理
                            || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.CYC_CNT))    //盘亏
                    {
                        //寄售库存需要进行结算,对被回冲的库存进行负数结算
                        PlanBill pb = this.genericMgr.FindById<PlanBill>(locationLotDetail.PlanBill.Value);
                        //if (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_PO
                        //    && inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue)
                        //{
                        //    //采购退货,如果退的是寄售库存,和退货的PlanBill冲销
                        //    inventoryIO.IsCreatePlanBill = false;
                        //    inventoryIO.IsConsignment = false;
                        //    inventoryIO.PlanBill = null;

                        //    pb.CurrentVoidQty = inventoryIO.Qty;
                        //    this.billMgr.VoidPlanBill(pb);
                        //}
                        //else
                        //{
                        pb.CurrentActingQty = -inventoryIO.Qty / pb.UnitQty; //按负数结算
                        pb.CurrentLocation = locationLotDetail.Location;
                        pb.CurrentHuId = locationLotDetail.HuId;
                        billTransaction = this.billMgr.SettleBill(pb, inventoryIO.EffectiveDate);
                        //}
                    }
                    //else if (locationLotDetail.IsConsignment && locationLotDetail.PlanBill.HasValue
                    //   && (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_PO     //采购退货
                    //       || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SL))   //计划协议退货
                    //{
                    //    //退货,寄售库存需要取消寄售数量
                    //    PlanBill pb = this.genericMgr.FindById<PlanBill>(locationLotDetail.PlanBill.Value);
                    //    pb.CurrentVoidQty = -inventoryIO.Qty / pb.UnitQty;
                    //    this.billMgr.VoidPlanBill(pb);
                    //}
                    #endregion

                    #region 处理冲销寄售和结算信息
                    if (billTransaction == null)
                    {
                        billTransaction = VoidBill(inventoryIO);
                    }
                    #endregion

                    //记录被回冲的记录
                    inventoryTransactionList.Add(CreateInventoryTransaction(locationLotDetail, inventoryIO.Qty, inventoryIO.IsCreatePlanBill, billTransaction));

                    //更新库存数量
                    locationLotDetail.Qty += inventoryIO.Qty;
                    this.genericMgr.Update(locationLotDetail);
                    #endregion
                }
                #endregion
            }
            else
            {
                #region 没有Hu
                IList<LocationLotDetail> locationLotDetailList = null;
                if (inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue)
                {
                    #region 寄售处理。
                    if (inventoryIO.Qty > 0)
                    {
                        #region 入库数量 > 0

                        //如果是收货后检验或者收货结算,不回冲库存。
                        //if (!(needInspection
                        //    || plannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_RECEIVING_SETTLEMENT))
                        //{
                        //#region 回冲指定收货单号的寄售库存
                        //if (refOrderNo != null && refOrderNo.Trim() != string.Empty)
                        //{
                        //    IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetLocationLotDetail(location.Code, item.Code, true, false, BusinessConstants.MINUS_INVENTORY, false, refOrderNo, flushbackIgnoreHu);
                        //    BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                        //}
                        //#endregion

                        if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.None) //占用库存入库不能回冲负数库存
                        {
                            #region 回冲寄售库存
                            if (inventoryIO.Qty > 0)
                            {
                                //locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetMinusInventory", new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, true });
                                locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetMinusInventory",
                                    new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, true },
                                    new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Boolean });
                                //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectMinusInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, true });
                                BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                            }
                            #endregion

                            #region 回冲非寄售库存
                            if (inventoryIO.Qty > 0)
                            {
                                locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetMinusInventory", new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, false },
                                    new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Boolean });
                                //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectMinusInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, false });
                                BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                            }
                            #endregion
                        }
                        //}

                        #region 记录库存
                        if (inventoryIO.Qty > 0)
                        {
                            CreateNewLocationLotDetail(inventoryIO, inventoryTransactionList);
                        }
                        #endregion
                        #endregion
                    }
                    else if (inventoryIO.Qty < 0)
                    {
                        #region 入库数量 < 0,出库

                        //#region 回冲指定收货单号的寄售库存
                        //if (refOrderNo != null && refOrderNo.Trim() != string.Empty)
                        //{
                        //    IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetLocationLotDetail(location.Code, item.Code, true, false, BusinessConstants.PLUS_INVENTORY, false, refOrderNo, flushbackIgnoreHu);
                        //    BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                        //}
                        //#endregion
                        #region 非占用出库
                        if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.None)
                        {
                            if (inventoryIO.IsVoid)
                            {
                                #region 冲销
                                //入库时是寄售库存,冲销时出库的也应该是对应的寄售库存
                                locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetVoidInventory", new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.PlanBill.Value, inventoryIO.QualityType, inventoryIO.OccupyType },
                                    new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int32, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Int16 });
                                //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectVoidInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.PlanBill.Value, inventoryIO.QualityType, inventoryIO.OccupyType });
                                BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                #endregion
                            }
                            else
                            {
                                #region 非冲销
                                #region 回冲寄售库存
                                if (inventoryIO.Qty < 0)
                                {
                                    locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetVoidInventory", new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.PlanBill.Value, inventoryIO.QualityType, inventoryIO.OccupyType },
                                    new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int32, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Int16 });
                                    //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectPlusInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, true });
                                    BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                }
                                #endregion

                                //#region 回冲非寄售库存
                                //if (inventoryIO.Qty < 0)
                                //{
                                //    locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetPlusInventory", new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, false });
                                //    //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectPlusInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, false });
                                //    BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                //}
                                //#endregion
                                #endregion
                            }
                        }
                        #endregion

                        #region 占用出库
                        else
                        {
                            //指定Planbill出库
                            locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetVoidOccupyInventory", new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.PlanBill.Value, inventoryIO.QualityType, inventoryIO.OccupyType, inventoryIO.OccupyReferenceNo },
                                new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int32, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.String });
                            //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectVoidOccupyInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.PlanBill.Value, inventoryIO.QualityType, inventoryIO.OccupyType, inventoryIO.OccupyReferenceNo });
                            BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                        }
                        #endregion

                        #region 记录库存
                        if (inventoryIO.Qty < 0)
                        {
                            //指定Planbill库存不足
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(inventoryIO.PlanBill.Value);
                            throw new BusinessException(string.Format("供应商{0}的物料{1}在库位{2}中库存不足。", planBill.Party, inventoryIO.Item, inventoryIO.Location));
                            //CreateNewLocationLotDetail(inventoryIO, inventoryTransactionList);
                        }
                        #endregion
                        #endregion
                    }
                    #endregion
                }
                else
                {
                    #region 非寄售处理
                    if (inventoryIO.Qty > 0)
                    {
                        #region 入库数量 > 0

                        if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.None) //占用库存入库不能回冲负数库存
                        {
                            //收货后检验的不能回冲库存
                            //if (!needInspection)
                            //{
                            #region 回冲非寄售库存
                            locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetMinusInventory", new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, false },
                                new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Boolean });
                            //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectMinusInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, false });
                            BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                            #endregion
                            //}
                        }

                        #region 记录库存
                        if (inventoryIO.Qty > 0)
                        {
                            CreateNewLocationLotDetail(inventoryIO, inventoryTransactionList);
                        }
                        #endregion
                        #endregion
                    }
                    else if (inventoryIO.Qty < 0)
                    {
                        #region 入库数量 < 0

                        #region 非占用出库
                        if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.None)
                        {
                            if (!string.IsNullOrWhiteSpace(inventoryIO.ManufactureParty))
                            {
                                #region 指定供应商出库USP_Busi_GetManufacturePartyConsignmentInventory
                                locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetManufacturePartyConsignmentInventory",
                                    new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, true, inventoryIO.ManufactureParty },
                                new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Boolean, NHibernate.NHibernateUtil.String });
                                //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectManufacturePartyConsignmentInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, true, inventoryIO.ManufactureParty });
                                BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);

                                if (inventoryIO.Qty < 0)
                                {
                                    if (!TryLoadLocation(inventoryIO).AllowNegative)
                                    {
                                        throw new BusinessException("物料{0}在库位{1}中的供应商{2}寄售库存不足。", inventoryIO.Item, inventoryIO.Location, inventoryIO.ManufactureParty);
                                    }
                                }

                                //直接扣减为负库存
                                #endregion
                            }
                            else if (inventoryIO.IsVoid)
                            {
                                #region 冲销
                                //入库时是非寄售库存,冲销时出库的也应该是非寄售库存
                                //如果是入库结算的应该先冲销结算,再把寄售信息记录至IpLocationDet中。
                                locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetPlusInventory", new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, false },
                                    new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Boolean });
                                //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectPlusInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, false });
                                BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                #endregion
                            }
                            else
                            {
                                #region 回冲非寄售库存
                                if (inventoryIO.Qty < 0)
                                {
                                    locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetPlusInventory", new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, false },
                                    new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Boolean });
                                    //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectPlusInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, false });
                                    BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                }
                                #endregion

                                #region 回冲寄售库存
                                if (inventoryIO.Qty < 0 && inventoryIO.TransactionType != CodeMaster.TransactionType.ISS_IIC)  //物料库存替换不能冲寄售库存
                                {
                                    locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetPlusInventory", new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, true },
                                    new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Boolean });
                                    //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectPlusInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, true });
                                    BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                }
                                #endregion
                            }
                        }
                        #endregion

                        #region 占用出库
                        else
                        {
                            #region 回冲非寄售库存
                            if (inventoryIO.Qty < 0)
                            {
                                locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetOccupyInventory", new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, inventoryIO.OccupyReferenceNo, false },
                                    new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Boolean });
                                //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectOccupyInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, inventoryIO.OccupyReferenceNo });
                                BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                            }
                            #endregion

                            #region 回冲寄售库存
                            if (inventoryIO.Qty < 0)
                            {
                                locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetOccupyInventory", new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, inventoryIO.OccupyReferenceNo, true },
                                    new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Boolean });
                                //locationLotDetailList = genericMgr.FindAll<LocationLotDetail>(SelectOccupyInventoryStatement, new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, inventoryIO.OccupyReferenceNo });
                                BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                            }
                            #endregion
                        }
                        #endregion

                        #region 记录库存
                        //if (inputLocationLotDetail.Qty < 0 && flushToNegative)
                        if (inventoryIO.Qty < 0)
                        {
                            CreateNewLocationLotDetail(inventoryIO, inventoryTransactionList);
                        }
                        #endregion

                        #endregion
                    }
                    #endregion
                }
                #endregion
            }

            return inventoryTransactionList;
        }
コード例 #8
0
        public IList<InventoryTransaction> InventoryOut(IpDetail ipDetail, DateTime effectiveDate)
        {
            List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();
            com.Sconit.CodeMaster.TransactionType? transType = GetTransactionType(ipDetail);
            if (transType.HasValue)
            {
                foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs)
                {
                    InventoryIO inventoryIO = new InventoryIO();

                    inventoryIO.Location = ipDetail.LocationFrom;
                    inventoryIO.Item = ipDetail.Item;
                    inventoryIO.HuId = ipDetailInput.HuId;
                    inventoryIO.Qty = -ipDetailInput.ShipQty * ipDetail.UnitQty;  //转换为库存单位,发货为负数
                    inventoryIO.LotNo = ipDetailInput.LotNo;
                    inventoryIO.QualityType = ipDetail.QualityType;     //不合格品的ATP状态一定是false,合格品的状态一定是true,质检不采用ASN发货这里不可能出现
                    inventoryIO.IsATP = ipDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryIO.IsFreeze = false;                       //可能指定移库冻结的零件?
                    inventoryIO.IsCreatePlanBill = ipDetailInput.IsCreatePlanBill;
                    inventoryIO.IsConsignment = ipDetailInput.IsConsignment;
                    inventoryIO.PlanBill = ipDetailInput.PlanBill;
                    inventoryIO.ActingBill = ipDetailInput.ActingBill;
                    inventoryIO.TransactionType = transType.Value;
                    //if (ipDetail.CurrentOccupyType == com.Sconit.CodeMaster.OccupyType.Pick)
                    //{
                    //    //发货不能发捡货单占用的零件
                    //    throw new TechnicalException("Can't ship material occupied by picklist.");
                    //}
                    //else if (ipDetail.CurrentOccupyType == com.Sconit.CodeMaster.OccupyType.Inspect
                    //    && (transType.Value != com.Sconit.CodeMaster.TransactionType.ISS_TR
                    //    || transType.Value != com.Sconit.CodeMaster.TransactionType.ISS_TR_VOID))
                    //{
                    //    //检验、不合格品占用的零件只能做移库及移库冲销
                    //    throw new TechnicalException("Can't ship material occupied by inspect order.");
                    //}
                    inventoryIO.OccupyType = ipDetailInput.OccupyType;
                    inventoryIO.OccupyReferenceNo = ipDetailInput.OccupyReferenceNo;
                    inventoryIO.IsVoid = ipDetail.IsVoid;
                    inventoryIO.EffectiveDate = effectiveDate;
                    inventoryIO.ManufactureParty = ipDetailInput.ManufactureParty;

                    IList<InventoryTransaction> currentInventoryTransactionList = RecordInventory(inventoryIO);
                    #region 记录WMS发货单行号
                    foreach (InventoryTransaction currentInventoryTransaction in currentInventoryTransactionList)
                    {
                        currentInventoryTransaction.WMSIpSeq = ipDetailInput.WMSIpSeq;
                    }
                    #endregion
                    RecordLocationTransaction(ipDetail, ipDetailInput, effectiveDate, transType.Value, currentInventoryTransactionList);
                    inventoryTransactionList.AddRange(currentInventoryTransactionList);
                }
            }
            //else if (ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
            //    && ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
            //{
            //    #region 采购发货为供应商生成在途寄售物料
            //    foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs)
            //    {
            //        inventoryTransactionList = new List<InventoryTransaction>();

            //        InventoryTransaction inventoryTransaction = new InventoryTransaction();
            //        inventoryTransaction.Item = ipDetail.Item;
            //        inventoryTransaction.HuId = ipDetailInput.HuId;
            //        inventoryTransaction.LotNo = ipDetailInput.LotNo;
            //        inventoryTransaction.IsConsignment = true;
            //        inventoryTransaction.IsCreatePlanBill = true;
            //        PlanBill planBill = this.billMgr.CreatePlanBill(ipDetail, ipDetailInput, effectiveDate);
            //        inventoryTransaction.PlanBill = planBill.Id;
            //        inventoryTransaction.Qty = ipDetailInput.ShipQty;
            //        inventoryTransaction.QualityType = ipDetail.QualityType;
            //        inventoryTransaction.IsATP = ipDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
            //        inventoryTransaction.IsFreeze = false;
            //        inventoryTransaction.OccupyType = com.Sconit.CodeMaster.OccupyType.None;
            //        inventoryTransactionList.Add(inventoryTransaction);
            //    }
            //    #endregion
            //}
            else if (((ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement    //采购发货
                        || ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine        //计划协议
                        || ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.CustomerGoods)      //客供品发货
                        && ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                || (ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution
                && ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)//销售退货发货
                        || ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract   //委外
                        || ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Production     //生产
                )
            {
                #region 生成在途非寄售物料
                inventoryTransactionList = new List<InventoryTransaction>();
                foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs)
                {
                    InventoryTransaction inventoryTransaction = new InventoryTransaction();

                    inventoryTransaction.Item = ipDetail.Item;
                    inventoryTransaction.HuId = ipDetailInput.HuId;
                    inventoryTransaction.LotNo = ipDetailInput.LotNo;
                    inventoryTransaction.IsConsignment = false;
                    inventoryTransaction.IsCreatePlanBill = false;
                    inventoryTransaction.Qty = -ipDetailInput.ShipQty * ipDetail.UnitQty;  //转换为库存单位,出库位负数
                    inventoryTransaction.QualityType = ipDetail.QualityType;
                    inventoryTransaction.IsATP = ipDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryTransaction.IsFreeze = false;
                    inventoryTransaction.OccupyType = com.Sconit.CodeMaster.OccupyType.None;

                    inventoryTransactionList.Add(inventoryTransaction);
                }
                #endregion
            }
            else
            {
                throw new TechnicalException("未知情况,需要跟踪。");
            }

            return inventoryTransactionList;
        }
コード例 #9
0
        public IList<InventoryTransaction> CancelBackflushProductMaterial(IList<BackflushInput> backflushInputList, DateTime effectiveDate)
        {
            List<InventoryTransaction> totalInventoryTransactionList = new List<InventoryTransaction>();
            foreach (BackflushInput backflushInput in backflushInputList)
            {
                #region 收货回冲
                InventoryIO inventoryIO = new InventoryIO();

                //inventoryIO.Location = backflushInput.OrderBomDetail.Location;
                inventoryIO.Location = backflushInput.Location;
                inventoryIO.Item = backflushInput.Item;
                //inventoryIO.HuId = 
                //inventoryIO.LotNo = 
                inventoryIO.QualityType = CodeMaster.QualityType.Qualified; //回冲的物料一定是合格品,不能回冲不合格品物料
                inventoryIO.IsATP = true;
                inventoryIO.IsFreeze = false;                       //可能指定冻结的零件?
                //inventoryIO.IsCreatePlanBill = 
                //inventoryIO.IsConsignment = 
                //inventoryIO.PlanBill = 
                //inventoryIO.ActingBill = 
                if (backflushInput.OrderSubType == CodeMaster.OrderSubType.Return)
                {
                    //减少原材料库存
                    inventoryIO.Qty = -backflushInput.Qty * backflushInput.UnitQty;
                    if (backflushInput.OrderType == CodeMaster.OrderType.Production)
                    {
                        inventoryIO.TransactionType = CodeMaster.TransactionType.ISS_WO_RTN_VOID;
                    }
                    else if (backflushInput.OrderType == CodeMaster.OrderType.SubContract)
                    {
                        inventoryIO.TransactionType = CodeMaster.TransactionType.ISS_SWO_RTN_VOID;
                    }
                }
                else
                {
                    //增加原材料库存
                    inventoryIO.Qty = backflushInput.Qty * backflushInput.UnitQty;
                    if (backflushInput.OrderType == CodeMaster.OrderType.Production)
                    {
                        inventoryIO.TransactionType = CodeMaster.TransactionType.ISS_WO_VOID;
                    }
                    else if (backflushInput.OrderType == CodeMaster.OrderType.SubContract)
                    {
                        inventoryIO.TransactionType = CodeMaster.TransactionType.ISS_SWO_VOID;
                    }
                }
                //inventoryIO.OccupyType = 
                //inventoryIO.OccupyReferenceNo = 
                inventoryIO.IsVoid = true;
                inventoryIO.EffectiveDate = effectiveDate;
                //inventoryIO.ManufactureParty = ;

                IList<InventoryTransaction> thisInventoryTransactionList = RecordInventory(inventoryIO);
                RecordLocationTransaction(backflushInput, effectiveDate, thisInventoryTransactionList, true);
                totalInventoryTransactionList.AddRange(thisInventoryTransactionList);
                backflushInput.InventoryTransactionList = thisInventoryTransactionList;
                #endregion
            }

            return totalInventoryTransactionList;
        }
コード例 #10
0
        public IList<InventoryTransaction> ReturnProductRawMaterial(ReturnInput returnInput, DateTime effectiveDate)
        {
            #region 出生产线
            #region 查询生产线上物料
            IList<ProductLineLocationDetail> productLineLocationDetailList = null;
            if (returnInput.ProductLineLocationDetailId.HasValue)
            {
                string hql = "from ProductLineLocationDetail where Id = ? and IsClose = ? ";

                IList<object> para = new List<object>();
                para.Add(returnInput.ProductLineLocationDetailId.Value);
                para.Add(false);

                productLineLocationDetailList = this.genericMgr.FindAll<ProductLineLocationDetail>(hql, para.ToArray());

                if (productLineLocationDetailList != null && productLineLocationDetailList.Count > 0)
                {
                    OrderMaster orderMaster = this.genericMgr.FindById<OrderMaster>(productLineLocationDetailList[0].OrderNo);
                    FlowMaster flowMaster = this.genericMgr.FindById<FlowMaster>(productLineLocationDetailList[0].ProductLine);
                    Location location = this.genericMgr.FindById<Location>(productLineLocationDetailList[0].LocationFrom);
                    Item item = this.genericMgr.FindById<Item>(productLineLocationDetailList[0].Item);
                    returnInput.OrderNo = orderMaster.OrderNo;
                    returnInput.OrderType = orderMaster.Type;
                    returnInput.OrderSubType = orderMaster.SubType;
                    returnInput.TraceCode = productLineLocationDetailList[0].TraceCode;
                    returnInput.Item = productLineLocationDetailList[0].Item;
                    returnInput.Uom = item.Uom;
                    returnInput.BaseUom = item.Uom;
                    returnInput.UnitQty = 1;
                    returnInput.QualityType = productLineLocationDetailList[0].QualityType;
                    returnInput.HuId = productLineLocationDetailList[0].HuId;
                    returnInput.LotNo = productLineLocationDetailList[0].LotNo;
                    returnInput.CurrentProductLine = flowMaster;
                    returnInput.ProductLine = flowMaster.Code;
                    returnInput.CurrentLocationTo = location;
                }
            }
            else
            {
                string hql = "from ProductLineLocationDetail where ProductLine = ? and Item = ? and QualityType = ? and IsClose = ? ";
                IList<object> para = new List<object>();
                para.Add(returnInput.ProductLine);
                para.Add(returnInput.Item);
                para.Add(returnInput.QualityType);
                para.Add(false);

                if (!string.IsNullOrWhiteSpace(returnInput.ProductLineFacility))
                {
                    hql += " and ProductLineFacility = ?";
                    para.Add(returnInput.ProductLineFacility);
                }

                if (!string.IsNullOrWhiteSpace(returnInput.OrderNo))
                {
                    hql += " and OrderNo = ?";
                    para.Add(returnInput.OrderNo);

                    if (!string.IsNullOrWhiteSpace(returnInput.TraceCode))
                    {
                        hql += " and TraceCode = ?";
                        para.Add(returnInput.TraceCode);
                    }

                    if (returnInput.Operation.HasValue)
                    {
                        hql += " and Operation = ?";
                        para.Add(returnInput.Operation.Value);

                        if (!string.IsNullOrWhiteSpace(returnInput.OpReference))
                        {
                            hql += " and OpReference = ?";
                            para.Add(returnInput.OpReference);
                        }
                        else
                        {
                            //hql += " and OpReference is null";
                        }
                    }
                    else
                    {
                        //hql += " and Operation is null";
                    }
                }

                if (!string.IsNullOrWhiteSpace(returnInput.HuId))
                {
                    hql += " and HuId = ?";
                    para.Add(returnInput.HuId);
                }

                //hql += " order by CreateDate desc";  //
                productLineLocationDetailList = this.genericMgr.FindAll<ProductLineLocationDetail>(hql, para.ToArray());
            }
            #endregion

            #region 回冲生产线物料
            List<InventoryTransaction> issInventoryTransactionList = new List<InventoryTransaction>();
            decimal remainQty = returnInput.Qty * returnInput.UnitQty;  //转为库存单位
            if (productLineLocationDetailList != null && productLineLocationDetailList.Count > 0)
            {
                #region 循环扣减物料
                foreach (ProductLineLocationDetail productLineLocationDetail in productLineLocationDetailList)
                {
                    if (remainQty == 0)
                    {
                        break;
                    }

                    if (productLineLocationDetail.RemainBackFlushQty == 0)
                    {
                        continue;
                    }

                    InventoryTransaction inventoryTransaction = new InventoryTransaction();

                    if (productLineLocationDetail.RemainBackFlushQty >= remainQty)
                    {
                        productLineLocationDetail.VoidQty += remainQty;
                        inventoryTransaction.Qty = -remainQty;   //出库位负数
                        remainQty = 0;
                        if (productLineLocationDetail.RemainBackFlushQty == 0)
                        {
                            productLineLocationDetail.IsClose = true;
                        }
                    }
                    else
                    {
                        remainQty -= productLineLocationDetail.RemainBackFlushQty;
                        inventoryTransaction.Qty = -productLineLocationDetail.RemainBackFlushQty;   //出库位负数
                        productLineLocationDetail.VoidQty += productLineLocationDetail.RemainBackFlushQty;
                        productLineLocationDetail.IsClose = true;
                    }
                    inventoryTransaction.LocationLotDetailId = productLineLocationDetail.Id;
                    inventoryTransaction.Location = productLineLocationDetail.ProductLine;
                    inventoryTransaction.OrgLocation = productLineLocationDetail.LocationFrom;
                    inventoryTransaction.Bin = productLineLocationDetail.ProductLineFacility;
                    inventoryTransaction.Item = productLineLocationDetail.Item;
                    inventoryTransaction.HuId = productLineLocationDetail.HuId;
                    inventoryTransaction.LotNo = productLineLocationDetail.LotNo;
                    inventoryTransaction.IsCreatePlanBill = false;
                    inventoryTransaction.IsConsignment = productLineLocationDetail.IsConsignment;
                    inventoryTransaction.PlanBill = productLineLocationDetail.PlanBill;
                    if (inventoryTransaction.IsConsignment)
                    {
                        inventoryTransaction.PlanBillQty = inventoryTransaction.Qty;
                    }
                    inventoryTransaction.ActingBill = null;
                    inventoryTransaction.ActingBillQty = 0;
                    inventoryTransaction.QualityType = productLineLocationDetail.QualityType;
                    inventoryTransaction.IsATP = productLineLocationDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryTransaction.IsFreeze = false;
                    inventoryTransaction.OccupyType = com.Sconit.CodeMaster.OccupyType.None;

                    issInventoryTransactionList.Add(inventoryTransaction);
                    this.genericMgr.Update(productLineLocationDetail);
                }
                #endregion
            }

            if (remainQty > 0)
            {
                if (!string.IsNullOrWhiteSpace(returnInput.HuId))
                {
                    throw new BusinessException("退料条码{0}在生产线{1}上不存在或余额不足。", returnInput.HuId, returnInput.ProductLine);
                }
                else
                {
                    throw new BusinessException("退料零件{0}在生产线{1}上余额不足。", returnInput.Item, returnInput.ProductLine);

                }
            }
            #endregion

            #region 记录退生产线事务
            if (issInventoryTransactionList.Count == 0)
            {
                throw new TechnicalException("Return InventoryTransaction is empty.");
            }

            RecordLocationTransaction(returnInput, effectiveDate, issInventoryTransactionList, true);
            #endregion
            #endregion

            #region 入库位
            var groupedInventoryTransactionList = from trans in issInventoryTransactionList
                                                  group trans by new
                                                  {
                                                      LocationTo = !string.IsNullOrWhiteSpace(returnInput.LocationTo) ? returnInput.LocationTo : trans.OrgLocation,
                                                      IsConsignment = trans.IsConsignment,
                                                      PlanBill = trans.PlanBill
                                                  } into result
                                                  select new
                                                  {
                                                      LocationTo = result.Key.LocationTo,
                                                      IsConsignment = result.Key.IsConsignment,
                                                      PlanBill = result.Key.PlanBill,
                                                      //Qty = result.Sum(trans => -trans.Qty),
                                                      Qty = result.Sum(trans => trans.Qty),
                                                  };

            List<InventoryTransaction> rctInventoryTransactionList = new List<InventoryTransaction>();
            foreach (var trans in groupedInventoryTransactionList)
            {
                InventoryIO inventoryIO = new InventoryIO();

                inventoryIO.Location = trans.LocationTo;
                inventoryIO.Item = returnInput.Item;
                inventoryIO.HuId = returnInput.HuId;
                inventoryIO.LotNo = returnInput.LotNo;
                inventoryIO.Qty = -trans.Qty;    //入库为正数
                inventoryIO.QualityType = returnInput.QualityType;
                inventoryIO.IsATP = returnInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                inventoryIO.IsFreeze = false;
                inventoryIO.IsCreatePlanBill = false;
                inventoryIO.IsConsignment = trans.IsConsignment;
                inventoryIO.PlanBill = trans.PlanBill;
                inventoryIO.ActingBill = null;
                inventoryIO.TransactionType = com.Sconit.CodeMaster.TransactionType.RCT_MIN_RTN; //生产投料退库入库
                inventoryIO.OccupyType = com.Sconit.CodeMaster.OccupyType.None; //应该是非占用的零件才能投料
                //inventoryIO.OccupyReferenceNo = ipDetail.CurrentOccupyReferenceNo;
                inventoryIO.IsVoid = false;
                inventoryIO.EffectiveDate = effectiveDate;
                //inventoryIO.ManufactureParty = ;

                rctInventoryTransactionList.AddRange(RecordInventory(inventoryIO));
            }
            //记录出库事务
            RecordLocationTransaction(returnInput, effectiveDate, rctInventoryTransactionList, false);
            #endregion

            issInventoryTransactionList.AddRange(rctInventoryTransactionList);

            return issInventoryTransactionList;
        }
コード例 #11
0
        public IList<InventoryTransaction> BackflushProductMaterial(IList<BackflushInput> backflushInputList, DateTime effectiveDate)
        {
            List<InventoryTransaction> totalInventoryTransactionList = new List<InventoryTransaction>();
            foreach (BackflushInput backflushInput in backflushInputList)
            {
                if (backflushInput.OrderBomDetail != null)
                {
                    #region 指定OrderBomDetail
                    if (backflushInput.OrderBomDetail.BackFlushMethod == CodeMaster.BackFlushMethod.BackFlushOrder)
                    {
                        #region 只回冲在制品
                        IList<InventoryTransaction> thisInventoryTransactionList = BackflushProductLineLocationDetail(backflushInput, effectiveDate);
                        totalInventoryTransactionList.AddRange(thisInventoryTransactionList);
                        RecordLocationTransaction(backflushInput, effectiveDate, thisInventoryTransactionList, false);
                        backflushInput.InventoryTransactionList = thisInventoryTransactionList;
                        #endregion
                    }
                    else if (backflushInput.OrderBomDetail.BackFlushMethod == CodeMaster.BackFlushMethod.GoodsReceive)
                    {
                        #region 收货回冲
                        #region 先冲在制品
                        IList<InventoryTransaction> thisInventoryTransactionList = BackflushProductLineLocationDetail(backflushInput, effectiveDate);
                        #endregion

                        #region 再冲线旁物料
                        decimal backflushedQty = thisInventoryTransactionList.Sum(trans => trans.Qty);  //库存单位
                        decimal remainBackflushQty = backflushInput.Qty * backflushInput.UnitQty - backflushedQty;
                        if (remainBackflushQty != 0) //考虑到投料回冲可能出现负数,这里用!=
                        {
                            InventoryIO inventoryIO = new InventoryIO();

                            inventoryIO.Location = backflushInput.OrderBomDetail.Location;
                            inventoryIO.Item = backflushInput.Item;
                            inventoryIO.HuId = backflushInput.HuId;
                            inventoryIO.LotNo = backflushInput.LotNo;
                            inventoryIO.QualityType = CodeMaster.QualityType.Qualified; //回冲的物料一定是合格品,不能回冲不合格品物料
                            inventoryIO.IsATP = true;
                            inventoryIO.IsFreeze = false;                       //可能指定冻结的零件?
                            //inventoryIO.IsCreatePlanBill = 
                            //inventoryIO.IsConsignment = 
                            //inventoryIO.PlanBill = 
                            //inventoryIO.ActingBill = 
                            if (backflushInput.OrderSubType == CodeMaster.OrderSubType.Return)
                            {
                                inventoryIO.Qty = remainBackflushQty;  //为正数,增加原材料库存
                                if (backflushInput.OrderType == CodeMaster.OrderType.Production)
                                {
                                    inventoryIO.TransactionType = CodeMaster.TransactionType.ISS_WO_RTN;
                                }
                                else if (backflushInput.OrderType == CodeMaster.OrderType.SubContract)
                                {
                                    inventoryIO.TransactionType = CodeMaster.TransactionType.ISS_SWO_RTN;
                                }
                            }
                            else
                            {
                                inventoryIO.Qty = -remainBackflushQty;  //发货为负数
                                if (backflushInput.OrderType == CodeMaster.OrderType.Production)
                                {
                                    inventoryIO.TransactionType = CodeMaster.TransactionType.ISS_WO;
                                }
                                else if (backflushInput.OrderType == CodeMaster.OrderType.SubContract)
                                {
                                    inventoryIO.TransactionType = CodeMaster.TransactionType.ISS_SWO;
                                }
                            }

                            //inventoryIO.OccupyType = 
                            //inventoryIO.OccupyReferenceNo = 
                            inventoryIO.IsVoid = false;
                            inventoryIO.EffectiveDate = effectiveDate;
                            //inventoryIO.ManufactureParty = ;

                            ((List<InventoryTransaction>)thisInventoryTransactionList).AddRange(RecordInventory(inventoryIO));
                        }
                        #endregion

                        RecordLocationTransaction(backflushInput, effectiveDate, thisInventoryTransactionList, false);
                        totalInventoryTransactionList.AddRange(thisInventoryTransactionList);
                        backflushInput.InventoryTransactionList = thisInventoryTransactionList;
                        #endregion
                    }
                    else if (backflushInput.OrderBomDetail.BackFlushMethod == CodeMaster.BackFlushMethod.WeightAverage)
                    {
                        #region 加权平均回冲
                        PlanBackflush planBackflush = new PlanBackflush();

                        planBackflush.ProductLine = backflushInput.ProductLine;
                        planBackflush.ProductLineFacility = backflushInput.ProductLineFacility;
                        planBackflush.OrderNo = backflushInput.OrderNo;
                        planBackflush.OrderType = backflushInput.OrderType;
                        planBackflush.OrderSubType = backflushInput.OrderSubType;
                        planBackflush.OrderDetailSequence = backflushInput.OrderDetailSequence;
                        planBackflush.OrderDetailId = backflushInput.OrderDetailId;
                        planBackflush.OrderBomDetailId = backflushInput.OrderBomDetail.Id;
                        planBackflush.OrderBomDetailSequence = backflushInput.OrderBomDetail.Sequence;
                        planBackflush.ReceiptNo = backflushInput.ReceiptNo;
                        planBackflush.ReceiptDetailId = backflushInput.ReceiptDetailId;
                        planBackflush.ReceiptDetailSequence = backflushInput.ReceiptDetailSequence;
                        planBackflush.Bom = backflushInput.OrderBomDetail.Bom;
                        planBackflush.FGItem = backflushInput.FGItem;
                        planBackflush.Item = backflushInput.Item;
                        planBackflush.ItemDescription = backflushInput.OrderBomDetail.ItemDescription;
                        planBackflush.ReferenceItemCode = backflushInput.OrderBomDetail.ReferenceItemCode;
                        planBackflush.Uom = backflushInput.Uom;
                        planBackflush.BaseUom = backflushInput.BaseUom;
                        planBackflush.UnitQty = backflushInput.UnitQty;
                        planBackflush.ManufactureParty = backflushInput.OrderBomDetail.ManufactureParty;
                        planBackflush.Qty = backflushInput.Qty;
                        planBackflush.IsClose = false;
                        planBackflush.ReserveNo = backflushInput.OrderBomDetail.ReserveNo;
                        planBackflush.ReserveLine = backflushInput.OrderBomDetail.ReserveLine;
                        planBackflush.AUFNR = backflushInput.OrderBomDetail.AUFNR;
                        planBackflush.ICHARG = backflushInput.OrderBomDetail.ICHARG;
                        planBackflush.BWART = backflushInput.OrderBomDetail.BWART;

                        this.genericMgr.Create(planBackflush);
                        #endregion
                    }
                    #endregion
                }
                else
                {
                    #region 未指定OrderBomDetail,回冲所有ProductLineLocationDetail
                    IList<InventoryTransaction> thisInventoryTransactionList = BackflushProductLineLocationDetail(backflushInput, effectiveDate);
                    totalInventoryTransactionList.AddRange(thisInventoryTransactionList);
                    RecordLocationTransaction(backflushInput, effectiveDate, thisInventoryTransactionList, false);
                    backflushInput.InventoryTransactionList = thisInventoryTransactionList;
                    #endregion
                }
            }

            return totalInventoryTransactionList;
        }
コード例 #12
0
        public IList<InventoryTransaction> FeedProductRawMaterial(FeedInput feedInput, DateTime effectiveDate)
        {
            #region 出库位
            List<InventoryTransaction> issInventoryTransactionList = new List<InventoryTransaction>();
            InventoryIO inventoryIO = new InventoryIO();

            inventoryIO.Location = feedInput.LocationFrom;
            inventoryIO.Item = feedInput.Item;
            inventoryIO.HuId = feedInput.HuId;
            inventoryIO.Qty = -feedInput.Qty * feedInput.UnitQty;    //出库为负数,库存单位
            inventoryIO.LotNo = feedInput.LotNo;
            inventoryIO.QualityType = feedInput.QualityType;
            inventoryIO.IsATP = feedInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
            inventoryIO.IsFreeze = false;                       //可能指定移库冻结的零件?
            //inventoryIO.IsCreatePlanBill = ipDetailInput.IsCreatePlanBill;
            //inventoryIO.IsConsignment = ipDetailInput.IsConsignment;
            //inventoryIO.PlanBill = ipDetailInput.PlanBill;
            //inventoryIO.ActingBill = ipDetailInput.ActingBill;
            inventoryIO.TransactionType = com.Sconit.CodeMaster.TransactionType.ISS_MIN; //生产投料出库
            inventoryIO.OccupyType = com.Sconit.CodeMaster.OccupyType.None; //应该是非占用的零件才能投料
            //inventoryIO.OccupyReferenceNo = ipDetail.CurrentOccupyReferenceNo;
            inventoryIO.IsVoid = false;
            inventoryIO.EffectiveDate = effectiveDate;
            //inventoryIO.ManufactureParty = ;

            issInventoryTransactionList.AddRange(RecordInventory(inventoryIO));
            //记录出库事务
            RecordLocationTransaction(feedInput, effectiveDate, issInventoryTransactionList, true);
            #endregion

            #region 入生产线物料 by 李秋云 不记入库
            //var groupedInventoryTransactionList = from trans in issInventoryTransactionList
            //                                      group trans by new
            //                                      {
            //                                          IsConsignment = trans.IsConsignment,
            //                                          PlanBill = trans.PlanBill
            //                                      } into result
            //                                      select new
            //                                      {
            //                                          IsConsignment = result.Key.IsConsignment,
            //                                          PlanBill = result.Key.PlanBill,
            //                                          Qty = result.Sum(trans => -trans.Qty)
            //                                      };

            //IList<ProductLineLocationDetail> productLineLocationDetailList = new List<ProductLineLocationDetail>();
            //foreach (var trans in groupedInventoryTransactionList)
            //{
            //    ProductLineLocationDetail productLineLocationDetail = new ProductLineLocationDetail();

            //    productLineLocationDetail.ProductLine = feedInput.ProductLine;
            //    productLineLocationDetail.ProductLineFacility = feedInput.ProductLineFacility;
            //    productLineLocationDetail.OrderNo = feedInput.OrderNo;
            //    productLineLocationDetail.OrderDetailId = feedInput.OrderDetailId;
            //    productLineLocationDetail.TraceCode = feedInput.TraceCode;
            //    productLineLocationDetail.Operation = feedInput.Operation;
            //    productLineLocationDetail.OpReference = feedInput.OpReference;
            //    productLineLocationDetail.Item = feedInput.Item;
            //    productLineLocationDetail.ItemDescription = feedInput.CurrentItem.Description;
            //    productLineLocationDetail.ReferenceItemCode = feedInput.CurrentItem.ReferenceCode;
            //    productLineLocationDetail.HuId = feedInput.HuId;
            //    productLineLocationDetail.LotNo = feedInput.LotNo;
            //    productLineLocationDetail.IsConsignment = trans.IsConsignment;
            //    productLineLocationDetail.PlanBill = trans.PlanBill;
            //    productLineLocationDetail.Qty = trans.Qty; //库存单位
            //    productLineLocationDetail.BackFlushQty = 0;
            //    productLineLocationDetail.VoidQty = 0;
            //    productLineLocationDetail.LocationFrom = feedInput.LocationFrom;
            //    productLineLocationDetail.ReserveNo = feedInput.ReserveNo;       //预留号
            //    productLineLocationDetail.ReserveLine = feedInput.ReserveLine;   //行号
            //    productLineLocationDetail.AUFNR = feedInput.AUFNR;               //生产单号
            //    productLineLocationDetail.ICHARG = feedInput.ICHARG;             //生产批次
            //    productLineLocationDetail.BWART = feedInput.BWART;               //移动类型
            //    productLineLocationDetail.NotReport = feedInput.NotReport;       //不导出给SAP

            //    this.genericMgr.Create(productLineLocationDetail);

            //    productLineLocationDetailList.Add(productLineLocationDetail);
            //    //InventoryTransaction rctInventoryTransaction = Mapper.Map<InventoryTransaction, InventoryTransaction>(trans);
            //    //rctInventoryTransaction.ActingBillQty *= -1;
            //    //rctInventoryTransaction.Qty *= -1;

            //    //rctInventoryTransactionList.Add(rctInventoryTransaction);
            //}

            //List<InventoryTransaction> rctInventoryTransactionList = (from det in productLineLocationDetailList
            //                                                          select new InventoryTransaction
            //                                                          {
            //                                                              LocationLotDetailId = det.Id,
            //                                                              Location = det.ProductLine,
            //                                                              Bin = det.ProductLineFacility,
            //                                                              Item = det.Item,
            //                                                              HuId = det.HuId,
            //                                                              LotNo = det.LotNo,
            //                                                              Qty = det.Qty,
            //                                                              IsConsignment = det.IsConsignment,
            //                                                              PlanBill = det.PlanBill,
            //                                                              PlanBillQty = det.IsConsignment ? det.Qty : 0,
            //                                                              QualityType = det.QualityType,
            //                                                              IsATP = det.QualityType == com.Sconit.CodeMaster.QualityType.Qualified
            //                                                          }).ToList();
            ////记录入库事务 
            //RecordLocationTransaction(feedInput, effectiveDate, rctInventoryTransactionList, false);
            //issInventoryTransactionList.AddRange(rctInventoryTransactionList);
            #endregion

            return issInventoryTransactionList;
        }
コード例 #13
0
        private void CreateNewLocationLotDetail(InventoryIO inventoryIO, IList<InventoryTransaction> inventoryTransactionList, BillTransaction billTransaction)
        {
            #region 是否允许负库存,占用不能出现负数库存,待验和不合格品不允许出现负库存
            if (inventoryIO.Qty < 0)
            {
                //计划外出入库不允许负数库存
                if (inventoryIO.TransactionType == CodeMaster.TransactionType.ISS_UNP
                    || inventoryIO.TransactionType == CodeMaster.TransactionType.ISS_UNP_VOID
                    || inventoryIO.TransactionType == CodeMaster.TransactionType.RCT_UNP
                    || inventoryIO.TransactionType == CodeMaster.TransactionType.RCT_UNP_VOID)
                {
                    throw new BusinessException(Resources.INV.LocationLotDetail.Errors_NotEnoughInventory, inventoryIO.Item, inventoryIO.Location);
                }
                else
                {
                    if (inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue)
                    {
                        #region 寄售负库存
                        if (inventoryIO.QualityType != CodeMaster.QualityType.Qualified
                            || !TryLoadLocation(inventoryIO).AllowNegativeConsignment)
                        {
                            PlanBill pb = TryLoadPlanBill(inventoryIO);

                            throw new BusinessException("物料{0}在库位{1}中供应商{2}的寄售库存不足。", inventoryIO.Item, inventoryIO.Location, pb.Party);
                        }
                        #endregion
                    }
                    else
                    {
                        #region 非寄售负库存
                        if (//inventoryIO.OccupyType != com.Sconit.CodeMaster.OccupyType.None || 
                            inventoryIO.QualityType != CodeMaster.QualityType.Qualified
                            || !TryLoadLocation(inventoryIO).AllowNegative)
                        {
                            throw new BusinessException(Resources.INV.LocationLotDetail.Errors_NotEnoughInventory, inventoryIO.Item, inventoryIO.Location);
                        }
                        #endregion
                    }
                }
            }
            #endregion

            #region 冲销时按指定PlanBill出库数量不足
            //只有冲销才会出现这种情况?
            //if (inventoryIO.Qty < 0 && inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue)
            //{
            //    throw new BusinessException(Resources.INV.LocationLotDetail.Errors_VoidFailNotEnoughSpecifyInventory, inventoryIO.Location, inventoryIO.Item);
            //}
            #endregion

            //todo disabled的零件能不能做库存事务

            #region 虚零件和套件不能做库存事务不能做库存事务
            //Item item = TryLoadItem(inventoryIO);
            //if (item.IsVirtual)
            //{
            //    throw new BusinessException(Resources.INV.LocationLotDetail.Errors_VirtualItemCannotProcessInventory, inventoryIO.Item);
            //}

            //if (item.IsKit)
            //{
            //    throw new BusinessException(Resources.INV.LocationLotDetail.Errors_KitItemCannotProcessInventory, inventoryIO.Item);
            //}
            #endregion

            #region 收货结算/入库结算/检验结算
            //BillTransaction billTransaction = null;
            //if (inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue)
            //{
            //    PlanBill pb = TryLoadPlanBill(inventoryIO);

            //    if (pb.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.ReceivingSettlement  //收货结算
            //        || (pb.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.OnlineBilling && TryLoadLocation(inventoryIO).IsConsignment) //上线结算
            //        || (pb.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.AfterInspection     //检验结算,检验合格收货事务或者让步使用收货事务
            //        //&& inventoryIO.QualityType == com.Sconit.CodeMaster.QualityType.Qualified
            //            && (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_INP_QDII
            //            || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_INP_CCS))
            //        || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_SO)   //销售退货收货立即结算
            //    {
            //        if (inventoryIO.QualityType == CodeMaster.QualityType.Inspect)
            //        {
            //            throw new BusinessException("待验物料{0}不能结算。", inventoryIO.Item);
            //        }
            //        else if (inventoryIO.QualityType == CodeMaster.QualityType.Reject)
            //        {
            //            throw new BusinessException("不合格物料{0}不能结算。", inventoryIO.Item);
            //        }

            //        pb.CurrentActingQty = inventoryIO.Qty / pb.UnitQty;
            //        billTransaction = this.billMgr.SettleBill(pb, inventoryIO.EffectiveDate);

            //        inventoryIO.IsConsignment = false;
            //        //inventoryIO.PlanBill = null;
            //    }
            //}
            #endregion

            #region 处理冲销寄售和结算信息
            //if (billTransaction == null)
            //{
            //    //已经做了结算不可能发生冲销
            //    billTransaction = VoidBill(inventoryIO);
            //}
            #endregion

            #region 创建库存明细
            LocationLotDetail newLocationLotDetail = Mapper.Map<InventoryIO, LocationLotDetail>(inventoryIO);

            #region 记录寄售供应商
            if (inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue)
            {
                PlanBill pb = TryLoadPlanBill(inventoryIO);
                newLocationLotDetail.ConsignmentSupplier = pb.Party;
            }
            else
            {
                newLocationLotDetail.IsConsignment = false;
                newLocationLotDetail.PlanBill = null;
                newLocationLotDetail.ConsignmentSupplier = null;
            }
            #endregion

            #region 指定供应商负库存
            if (string.IsNullOrWhiteSpace(inventoryIO.HuId) && inventoryIO.Qty < 0
                && inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.None
                && !string.IsNullOrWhiteSpace(inventoryIO.ConsignmentSupplier))
            {
                newLocationLotDetail.ConsignmentSupplier = inventoryIO.ConsignmentSupplier;
                PlanBill negPlanBill = this.billMgr.LoadPlanBill(inventoryIO.Item, inventoryIO.Location, inventoryIO.ConsignmentSupplier, inventoryIO.EffectiveDate, false);
                inventoryIO.IsConsignment = true;
                newLocationLotDetail.IsConsignment = true;
                inventoryIO.PlanBill = negPlanBill.Id;
                newLocationLotDetail.PlanBill = negPlanBill.Id;
            }
            #endregion

            #region 冲销反结算
            if (billTransaction == null)
            {
                billTransaction = this.VoidBill(inventoryIO);

                if (billTransaction != null && inventoryIO.IsConsignment)    //发生了反结算,记录寄售库存
                {
                    newLocationLotDetail.IsConsignment = true;
                    newLocationLotDetail.PlanBill = billTransaction.PlanBill;
                    newLocationLotDetail.ConsignmentSupplier = billTransaction.Party;

                    #region 寄售负库存
                    if (inventoryIO.Qty < 0 && !TryLoadLocation(inventoryIO).AllowNegativeConsignment)
                    {
                        throw new BusinessException("物料{0}在库位{1}中供应商{2}的寄售库存不足。", inventoryIO.Item, inventoryIO.Location, billTransaction.Party);
                    }
                    #endregion
                }
            }
            #endregion

            if (!string.IsNullOrWhiteSpace(newLocationLotDetail.HuId))
            {
                #region 更新条码首次入库日期
                Hu hu = inventoryIO.CurrentHu;
                if (hu == null)
                {
                    hu = this.genericMgr.FindById<Hu>(newLocationLotDetail.HuId);
                }

                if (!hu.FirstInventoryDate.HasValue)
                {
                    hu.FirstInventoryDate = DateTime.Now;
                    this.genericMgr.Update(hu);
                }
                #endregion
                //  huId = huId.ToUpper();
                //newLocationLotDetail.Hu = this.huMgrE.LoadHu(huId);

                ////库存数量和条码上的数量有差异,更新条码上的数量
                //if (newLocationLotDetail.Hu.Qty * newLocationLotDetail.Hu.UnitQty != qty)
                //{
                //    newLocationLotDetail.Hu.Qty = qty / newLocationLotDetail.Hu.UnitQty;
                //}
                //newLocationLotDetail.Hu.Location = location.Code;
                //newLocationLotDetail.Hu.Status = BusinessConstants.CODE_MASTER_HU_STATUS_VALUE_INVENTORY;

                //this.huMgrE.UpdateHu(newLocationLotDetail.Hu);

                if (newLocationLotDetail.Qty < 0)
                {
                    throw new TechnicalException("Barcode qty can't less than 0.");
                }
            }

            //入库
            LocationLotDetail mergeLocationLotDetail = null;
            if (string.IsNullOrWhiteSpace(newLocationLotDetail.HuId) && TryLoadLocation(inventoryIO).MergeLocationLotDet)
            {
                //#region 查找库存明细是否可以合并,有条码的不能合并
                //mergeLocationLotDetail = this.genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetMergeInventory ?,?,?,?,?,?,?,?,?,?"
                //    , new object[] { newLocationLotDetail.Location, newLocationLotDetail.Item, newLocationLotDetail.Qty,
                //                    newLocationLotDetail.PlanBill, newLocationLotDetail.QualityType, newLocationLotDetail.IsFreeze,
                //                    newLocationLotDetail.IsATP, newLocationLotDetail.OccupyType, newLocationLotDetail.OccupyReferenceNo,
                //                    newLocationLotDetail.ConsignmentSupplier}
                //    , new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Decimal, 
                //                    NHibernate.NHibernateUtil.Int32, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Boolean,
                //                    NHibernate.NHibernateUtil.Boolean, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.String,
                //                    NHibernate.NHibernateUtil.String }).FirstOrDefault();
                //#endregion
            }

            if (mergeLocationLotDetail != null)
            {
                mergeLocationLotDetail.Qty += newLocationLotDetail.Qty;
                this.genericMgr.Update(mergeLocationLotDetail);
                inventoryTransactionList.Add(CreateInventoryTransaction(inventoryIO, inventoryIO.Qty, mergeLocationLotDetail, billTransaction));
            }
            else
            {
                if (!newLocationLotDetail.IsConsignment)
                {
                    newLocationLotDetail.PlanBill = null;
                    newLocationLotDetail.ConsignmentSupplier = null;
                }
                this.genericMgr.Create(newLocationLotDetail);
                inventoryTransactionList.Add(CreateInventoryTransaction(inventoryIO, inventoryIO.Qty, newLocationLotDetail, billTransaction));
            }
            #endregion
        }
コード例 #14
0
        private IList<InventoryTransaction> RecordInventory(InventoryIO inventoryIO)
        {
            #region 判断库存生效日期是否有效
            FinanceCalendar financeCalendar = financeCalendarMgr.GetNowEffectiveFinanceCalendar();
            //前开后闭
            if (financeCalendar.StartDate >= inventoryIO.EffectiveDate)
            {
                throw new BusinessException("库存的生效日期{0}大于当前财政月的开始日期{1},不能进行库存操作。");
            }
            #endregion

            IList<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();

            if (inventoryIO.LocationLotDetailId.HasValue)
            {
                #region 指定库存明细出库
                LocationLotDetail locationLotDetail = this.genericMgr.FindById<LocationLotDetail>(inventoryIO.LocationLotDetailId.Value);

                if (!string.IsNullOrWhiteSpace(locationLotDetail.HuId))
                {
                    throw new TechnicalException("条码库存不能指定库存明细出库。");
                }

                //记录被回冲的记录
                inventoryTransactionList.Add(CreateInventoryTransaction(locationLotDetail, -locationLotDetail.Qty, false, null));

                //更新库存数量
                //locationLotDetail.Qty += inventoryIO.Qty;
                locationLotDetail.Qty = 0;
                this.genericMgr.Update(locationLotDetail);
                #endregion
            }
            else if (!string.IsNullOrWhiteSpace(inventoryIO.HuId))
            {
                #region 有Hu
                //寄售/非寄售处理逻辑相同
                if (inventoryIO.Qty > 0)
                {
                    #region 入库数量 > 0
                    HuStatus huStatus = this.huMgr.GetHuStatus(inventoryIO.HuId);
                    if (huStatus.Status != CodeMaster.HuStatus.NA)
                    {
                        //if (huStatusList.Count > 1)
                        //{
                        //    throw new TechnicalException("HuId " + inventoryIO.HuId + "exist in two different location or ipdetail.");
                        //}

                        //HuStatus huStatus = huStatusList[0];

                        //同一个条码在所有库位中不能出现两次
                        if (huStatus.Status == CodeMaster.HuStatus.Location)
                        {
                            throw new BusinessException(Resources.INV.LocationLotDetail.Errors_HuIsAlreadyInLocation, inventoryIO.HuId, huStatus.Location);
                        }
                        else
                        {
                            throw new BusinessException("条码{0}是从库位{1}到库位{2}的在途库存,不能重复入库。", inventoryIO.HuId, huStatus.LocationFrom, huStatus.LocationTo);
                        }
                    }

                    inventoryIO.LotNo = huStatus.LotNo;
                    CreateNewLocationLotDetail(inventoryIO, inventoryTransactionList, null);
                    #endregion
                }
                else if (inventoryIO.Qty < 0)
                {
                    #region 入库数量 < 0 / 出库
                    LocationLotDetail locationLotDetail = this.GetHuLocationLotDetail(inventoryIO.HuId);

                    if (locationLotDetail == null)
                    {
                        //任意库位没有找到指定的HU
                        throw new BusinessException(Resources.INV.LocationLotDetail.Errors_HuNotInAnyLocation, inventoryIO.HuId);
                    }

                    if (locationLotDetail.Location != inventoryIO.Location)
                    {
                        //HU不在指定的库位
                        throw new BusinessException(Resources.INV.LocationLotDetail.Errors_HuNotInSpecifiedLocation, inventoryIO.HuId, inventoryIO.Location);
                    }

                    if (locationLotDetail.Qty + inventoryIO.Qty != 0)
                    {
                        //Hu中Item的数量不等于出库数
                        throw new BusinessException(Resources.INV.LocationLotDetail.Errors_HuQtyNotEqualShipQty, inventoryIO.HuId, locationLotDetail.Qty.ToString(), inventoryIO.Qty.ToString());
                    }

                    #region 判断条码冻结
                    if (locationLotDetail.IsFreeze)
                    {
                        throw new BusinessException(Resources.INV.LocationLotDetail.Errors_HuFrozenCantShip, inventoryIO.HuId);
                    }
                    #endregion

                    #region 判断订单占用
                    BusinessException businessException = new BusinessException();
                    if (inventoryIO.OccupyType != locationLotDetail.OccupyType)
                    {
                        if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.None)
                        {
                            //要求订单没有被占用,实际被占用
                            CheckLocationLotDetailOccupied(locationLotDetail, businessException);
                        }
                        else if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.Inspect)
                        {
                            //检查是否被检验单占用
                            CheckLocationLotDetailOccupiedByInspectOrder(locationLotDetail, inventoryIO.OccupyReferenceNo, businessException);
                        }
                        else if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.Pick)
                        {
                            //检查是否被捡货单占用
                            CheckLocationLotDetailOccupiedByPickList(locationLotDetail, inventoryIO.OccupyReferenceNo, businessException);
                        }
                        else if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.Sequence)
                        {
                            //检查是否被排序单占用
                            CheckLocationLotDetailOccupiedBySequenceOrder(locationLotDetail, inventoryIO.OccupyReferenceNo, businessException);
                        }
                        else if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.MiscOrder)
                        {
                            //检查是否被计划出入库单占用
                            CheckLocationLotDetailOccupiedByMiscOrder(locationLotDetail, inventoryIO.OccupyReferenceNo, businessException);
                        }
                    }

                    if (businessException.HasMessage)
                    {
                        throw businessException;
                    }
                    #endregion

                    #region 处理寄售
                    BillTransaction billTransaction = null;
                    if (locationLotDetail.IsConsignment && locationLotDetail.PlanBill.HasValue                 //是否有RCT类型的出库?
                        && (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_WO      //生产出库
                            || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SWO      //委外生产出库
                            || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_UNP  //计划外出库
                            || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SO   //销售出库
                            || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SO_IGI_VOID   //销售差异调整至发货方冲销
                        //|| inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_PO   //采购退库  采购退货出库出口库不需要处理寄售,在采购退货收货时处理
                            || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.CYC_CNT))    //盘亏
                    {
                        //寄售库存需要进行结算,对被回冲的库存进行负数结算
                        PlanBill pb = this.genericMgr.FindById<PlanBill>(locationLotDetail.PlanBill.Value);
                        //if (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_PO
                        //    && inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue)
                        //{
                        //    //采购退货,如果退的是寄售库存,和退货的PlanBill冲销
                        //    inventoryIO.IsCreatePlanBill = false;
                        //    inventoryIO.IsConsignment = false;
                        //    inventoryIO.PlanBill = null;

                        //    pb.CurrentVoidQty = inventoryIO.Qty;
                        //    this.billMgr.VoidPlanBill(pb);
                        //}
                        //else
                        //{
                        pb.CurrentActingQty = -inventoryIO.Qty / pb.UnitQty; //按负数结算
                        pb.CurrentLocation = locationLotDetail.Location;
                        pb.CurrentLocation = locationLotDetail.HuId;
                        billTransaction = this.billMgr.SettleBill(pb, inventoryIO.EffectiveDate);
                        pb.CurrentActingBill = billTransaction.ActingBill;
                        pb.CurrentBillTransaction = billTransaction.Id;
                        //}
                    }
                    //else if (locationLotDetail.IsConsignment && locationLotDetail.PlanBill.HasValue
                    //   && (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_PO     //采购退货
                    //       || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SL))   //计划协议退货
                    //{
                    //    //退货,寄售库存需要取消寄售数量
                    //    PlanBill pb = this.genericMgr.FindById<PlanBill>(locationLotDetail.PlanBill.Value);
                    //    pb.CurrentVoidQty = -inventoryIO.Qty / pb.UnitQty;
                    //    this.billMgr.VoidPlanBill(pb);
                    //}
                    #endregion

                    #region 处理冲销寄售和结算信息
                    if (billTransaction == null)
                    {
                        billTransaction = VoidBill(inventoryIO);
                    }
                    #endregion

                    //记录被回冲的记录
                    inventoryTransactionList.Add(CreateInventoryTransaction(locationLotDetail, inventoryIO.Qty, inventoryIO.IsCreatePlanBill, billTransaction));

                    //更新库存数量
                    locationLotDetail.Qty += inventoryIO.Qty;
                    this.genericMgr.Update(locationLotDetail);
                    #endregion
                }
                #endregion
            }
            else
            {
                #region 没有Hu
                IList<LocationLotDetail> locationLotDetailList = null;
                if (inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue)
                {
                    #region 寄售处理。
                    if (inventoryIO.Qty > 0)
                    {
                        #region 入库数量 > 0
                        BillTransaction billTransaction = null;
                        if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.None) //占用库存入库不能回冲负数库存
                        {
                            #region 收货结算/入库结算/检验结算
                            PlanBill pb = null;
                            if (inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue
                                && inventoryIO.TransactionType != CodeMaster.TransactionType.ISS_TR_VOID
                                && inventoryIO.TransactionType != CodeMaster.TransactionType.ISS_SL_VOID
                                && inventoryIO.TransactionType != CodeMaster.TransactionType.ISS_UNP_VOID
                                && inventoryIO.TransactionType != CodeMaster.TransactionType.RCT_UNP
                                //盘点、库存初始化、计划外入库指定供应商入库不用立即解算
                                && inventoryIO.TransactionType != CodeMaster.TransactionType.CYC_CNT
                                && inventoryIO.TransactionType != CodeMaster.TransactionType.LOC_INI
                                && inventoryIO.TransactionType != CodeMaster.TransactionType.RCT_UNP)  //
                            {
                                pb = TryLoadPlanBill(inventoryIO);

                                if (pb.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.ReceivingSettlement  //收货结算
                                    || (pb.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.OnlineBilling && TryLoadLocation(inventoryIO).IsConsignment) //上线结算
                                    || (pb.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.AfterInspection     //检验结算,检验合格收货事务或者让步使用收货事务
                                    //&& inventoryIO.QualityType == com.Sconit.CodeMaster.QualityType.Qualified
                                        && (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_INP_QDII
                                        || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_INP_CCS))
                                    || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_SO   //销售退货收货立即结算
                                    )
                                {
                                    if (inventoryIO.QualityType == CodeMaster.QualityType.Inspect)
                                    {
                                        throw new BusinessException("待验物料{0}不能结算。", inventoryIO.Item);
                                    }
                                    else if (inventoryIO.QualityType == CodeMaster.QualityType.Reject)
                                    {
                                        throw new BusinessException("不合格物料{0}不能结算。", inventoryIO.Item);
                                    }

                                    pb.CurrentActingQty = inventoryIO.Qty / pb.UnitQty;
                                    billTransaction = this.billMgr.SettleBill(pb, inventoryIO.EffectiveDate);
                                    pb.CurrentActingBill = billTransaction.ActingBill;
                                    pb.CurrentBillTransaction = billTransaction.Id;

                                    inventoryIO.IsConsignment = false;
                                    inventoryIO.PlanBill = null;
                                    inventoryIO.CurrentBillTransaction = billTransaction;
                                }

                                #region 回冲寄售负库存
                                if (inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue)
                                {
                                    if (inventoryIO.Qty > 0)
                                    {
                                        locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetMinusCSInventory ?,?,?,?,?",
                                            new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, pb.Party },
                                            new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int16, NHibernateUtil.Int16, NHibernateUtil.String }
                                        );
                                        BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                    }
                                }
                                #endregion


                                #region 回冲非寄售负库存
                                else
                                {
                                    if (inventoryIO.Qty > 0)
                                    {
                                        locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetMinusInventory ?,?,?,?",
                                            new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType },
                                            new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int16, NHibernateUtil.Int16 }
                                        );
                                        BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                    }
                                }
                                #endregion

                            }
                            #endregion

                            #region 寄售物料入库
                            else
                            {
                                #region 回冲寄售负库存
                                if (inventoryIO.Qty > 0)
                                {
                                    TryLoadPlanBill(inventoryIO);
                                    locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetMinusCSInventory ?,?,?,?,?",
                                        new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, inventoryIO.CurrentPlanBill.Party },
                                        new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int16, NHibernateUtil.Int16, NHibernateUtil.String });
                                    BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                }
                                #endregion
                            }
                            #endregion
                        }

                        #region 记录库存
                        if (inventoryIO.Qty > 0)
                        {
                            CreateNewLocationLotDetail(inventoryIO, inventoryTransactionList, billTransaction);
                        }
                        #endregion
                        #endregion
                    }
                    else if (inventoryIO.Qty < 0)
                    {
                        #region 入库数量 < 0,出库
                        #region 非占用出库
                        if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.None)
                        {
                            if (inventoryIO.IsVoid)
                            {
                                #region 冲销
                                //入库时是寄售库存,冲销时出库的也应该是对应的寄售库存
                                locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetVoidInventory ?,?,?,?,?",
                                    new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.PlanBill.Value, inventoryIO.QualityType, inventoryIO.OccupyType },
                                    new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int32, NHibernateUtil.Int16, NHibernateUtil.Int16 });
                                BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                #endregion
                            }
                            else
                            {
                                #region 非冲销
                                #region 回冲寄售库存
                                if (inventoryIO.Qty < 0)
                                {
                                    locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetVoidInventory ?,?,?,?,?",
                                        new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.PlanBill.Value, inventoryIO.QualityType, inventoryIO.OccupyType },
                                        new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int32, NHibernateUtil.Int16, NHibernateUtil.Int16 });
                                    BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                }
                                #endregion
                                #endregion
                            }
                        }
                        #endregion

                        #region 占用出库
                        else
                        {
                            //指定Planbill出库
                            locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetVoidOccupyInventory ?,?,?,?,?,?",
                                new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.PlanBill.Value, inventoryIO.QualityType, inventoryIO.OccupyType, inventoryIO.OccupyReferenceNo },
                                new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int32, NHibernateUtil.Int16, NHibernateUtil.Int16, NHibernateUtil.String });
                            BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                        }
                        #endregion

                        #region 记录库存
                        if (inventoryIO.Qty < 0)
                        {
                            CreateNewLocationLotDetail(inventoryIO, inventoryTransactionList, null);
                            //指定Planbill库存不足
                            //TryLoadPlanBill(inventoryIO);
                            //throw new BusinessException(string.Format("供应商{0}的物料{1}在库位{2}中库存不足。", inventoryIO.CurrentPlanBill.Party, inventoryIO.Item, inventoryIO.Location));
                            //CreateNewLocationLotDetail(inventoryIO, inventoryTransactionList);
                        }
                        #endregion
                        #endregion
                    }
                    #endregion
                }
                else
                {
                    #region 非寄售处理
                    if (inventoryIO.Qty > 0)
                    {
                        #region 入库数量 > 0

                        if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.None) //占用库存入库不能回冲负数库存
                        {
                            #region 回冲非寄售库存
                            locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetMinusInventory ?,?,?,?",
                                new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType },
                                new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int16, NHibernateUtil.Int16 });
                            BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                            #endregion
                        }

                        #region 记录库存
                        if (inventoryIO.Qty > 0)
                        {
                            CreateNewLocationLotDetail(inventoryIO, inventoryTransactionList, null);
                        }
                        #endregion
                        #endregion
                    }
                    else if (inventoryIO.Qty < 0)
                    {
                        #region 入库数量 < 0

                        #region 非占用出库
                        if (inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.None)
                        {
                            if (!string.IsNullOrWhiteSpace(inventoryIO.ConsignmentSupplier))
                            {
                                #region 指定供应商寄售出库
                                locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetPlusCSInventory ?,?,?,?,?",
                                    new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, inventoryIO.ConsignmentSupplier },
                                    new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int16, NHibernateUtil.Int16, NHibernateUtil.String });
                                BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);

                                //if (inventoryIO.Qty < 0)
                                //{
                                //    if (!TryLoadLocation(inventoryIO).AllowNegative)
                                //    {
                                //        throw new BusinessException("物料{0}在库位{1}中的供应商{2}寄售库存不足。", inventoryIO.Item, inventoryIO.Location, inventoryIO.ConsignmentSupplier);
                                //    }
                                //    else
                                //    {
                                //        //如果允许负库存,直接把自有物资扣减为负数库存,但是会记录CSSupplier,正数寄售库存勾兑时要和CSSupplier对应。
                                //    }
                                //}

                                #endregion
                            }
                            else if (inventoryIO.IsVoid)
                            {
                                #region 冲销
                                //入库时是非寄售库存,冲销时出库的也应该是非寄售库存
                                //如果是入库结算的应该先冲销结算,再把寄售信息记录至IpLocationDet中。
                                locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetPlusInventory ?,?,?,?,?",
                                    new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, false },
                                    new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int16, NHibernateUtil.Int16, NHibernateUtil.Boolean });
                                BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                #endregion
                            }
                            else
                            {
                                #region 回冲非寄售库存
                                if (inventoryIO.Qty < 0)
                                {
                                    locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetPlusInventory ?,?,?,?,?",
                                        new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, false },
                                        new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int16, NHibernateUtil.Int16, NHibernateUtil.Boolean });
                                    BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                }
                                #endregion

                                #region 回冲寄售库存
                                //if (inventoryIO.Qty < 0
                                //    && inventoryIO.TransactionType != CodeMaster.TransactionType.ISS_IIC  //物料库存替换不能冲寄售库存
                                //    && string.IsNullOrWhiteSpace(inventoryIO.WMSIpSeq)  //WMSIpSeq不为空,不能直接结算寄售库存
                                //    && inventoryIO.TransactionType != CodeMaster.TransactionType.ISS_UNP   //计划外出库没有指定供应商不能冲寄售库存   
                                //    && inventoryIO.TransactionType != CodeMaster.TransactionType.ISS_INP_CCS)   //让步使用没有指定供应商不能冲寄售库存   
                                //{
                                //    if (inventoryIO.TransactionType == CodeMaster.TransactionType.ISS_TR
                                //        && inventoryIO.QualityType == CodeMaster.QualityType.Reject)
                                //    {
                                //        //不合格品移库不指定供应商不能冲寄售库存
                                //    }
                                //    else
                                //    {
                                //        locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetPlusInventory ?,?,?,?,?", 
                                //            new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, true },
                                //            new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int16, NHibernateUtil.Int16, NHibernateUtil.Boolean });
                                //        BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                //    }
                                //}
                                #endregion
                            }
                        }
                        #endregion

                        #region 占用出库
                        else
                        {
                            if (!string.IsNullOrWhiteSpace(inventoryIO.ConsignmentSupplier))
                            {
                                #region 指定供应商寄售出库
                                locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetOccupyCSInventory ?,?,?,?,?,?",
                                        new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, inventoryIO.OccupyReferenceNo, inventoryIO.ConsignmentSupplier },
                                        new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int16, NHibernateUtil.Int16, NHibernateUtil.String, NHibernateUtil.String });
                                BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                #endregion
                            }
                            else
                            {
                                #region 回冲非寄售库存
                                if (inventoryIO.Qty < 0)
                                {
                                    locationLotDetailList = genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetOccupyInventory ?,?,?,?,?,?",
                                        new Object[] { inventoryIO.Location, inventoryIO.Item, inventoryIO.QualityType, inventoryIO.OccupyType, inventoryIO.OccupyReferenceNo, false },
                                        new IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.Int16, NHibernateUtil.Int16, NHibernateUtil.String, NHibernateUtil.Boolean });
                                    BackflushInventory(inventoryIO, locationLotDetailList, inventoryTransactionList);
                                }
                                #endregion
                            }
                        }
                        #endregion

                        #region 记录库存
                        //if (inputLocationLotDetail.Qty < 0 && flushToNegative)
                        if (inventoryIO.Qty < 0)
                        {
                            CreateNewLocationLotDetail(inventoryIO, inventoryTransactionList, null);
                        }
                        #endregion

                        #endregion
                    }
                    #endregion
                }
                #endregion
            }

            return inventoryTransactionList;
        }
コード例 #15
0
        public IList<InventoryTransaction> CancelInventoryOtherInOut(MiscOrderMaster miscOrderMaster, DateTime effectiveDate)
        {
            List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();

            foreach (MiscOrderDetail miscOrderDetail in miscOrderMaster.MiscOrderDetails)
            {
                List<InventoryTransaction> detailInventoryTransactionList = new List<InventoryTransaction>();

                foreach (MiscOrderLocationDetail miscOrderLocationDetail in miscOrderDetail.MiscOrderLocationDetails)
                {
                    InventoryIO inventoryIO = new InventoryIO();

                    inventoryIO.Location = !string.IsNullOrWhiteSpace(miscOrderDetail.Location) ? miscOrderDetail.Location : miscOrderMaster.Location;
                    inventoryIO.Item = miscOrderLocationDetail.Item;
                    inventoryIO.Qty = -miscOrderLocationDetail.Qty;
                    inventoryIO.HuId = miscOrderLocationDetail.HuId;
                    inventoryIO.LotNo = miscOrderLocationDetail.LotNo;
                    inventoryIO.QualityType = miscOrderLocationDetail.QualityType;
                    inventoryIO.IsATP = miscOrderLocationDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryIO.IsFreeze = miscOrderLocationDetail.IsFreeze;
                    inventoryIO.IsCreatePlanBill = miscOrderLocationDetail.IsCreatePlanBill;
                    //inventoryIO.IsConsignment = miscOrderLocationDetail.IsConsignment;
                    inventoryIO.IsConsignment = miscOrderLocationDetail.ActingBill.HasValue ? true : false; //解决寄售物资计划外出库冲销记录库存丢失寄售信息
                    inventoryIO.PlanBill = miscOrderLocationDetail.PlanBill;
                    inventoryIO.ActingBill = miscOrderLocationDetail.ActingBill;
                    inventoryIO.TransactionType = miscOrderMaster.Type == CodeMaster.MiscOrderType.GI ? CodeMaster.TransactionType.ISS_UNP_VOID : CodeMaster.TransactionType.RCT_UNP_VOID;
                    inventoryIO.OccupyType = miscOrderLocationDetail.OccupyType;
                    inventoryIO.OccupyReferenceNo = miscOrderLocationDetail.OccupyReferenceNo;
                    inventoryIO.IsVoid = true;
                    inventoryIO.EffectiveDate = effectiveDate;
                    //inventoryIO.ManufactureParty = ;

                    IList<InventoryTransaction> locationDetailInventoryTransactionList = RecordInventory(inventoryIO);
                    if (miscOrderMaster.IsScanHu)
                    {
                        RecordLocationTransaction(miscOrderMaster, miscOrderDetail, effectiveDate, locationDetailInventoryTransactionList, true);
                    }
                    detailInventoryTransactionList.AddRange(locationDetailInventoryTransactionList);
                }

                if (!miscOrderMaster.IsScanHu)
                {
                    RecordLocationTransaction(miscOrderMaster, miscOrderDetail, effectiveDate, detailInventoryTransactionList, true);
                }
                inventoryTransactionList.AddRange(detailInventoryTransactionList);
            }

            return inventoryTransactionList;
        }
コード例 #16
0
        public IList<InventoryTransaction> InventoryInspect(InspectMaster inspectMaster, DateTime effectiveDate)
        {
            if (inspectMaster.InspectDetails == null || inspectMaster.InspectDetails.Count == 0)
            {
                return null;
            }

            List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();

            foreach (InspectDetail inspectDetail in inspectMaster.InspectDetails.OrderByDescending(det => det.IsConsignment))
            {
                #region 检验出库
                InventoryIO inventoryOut = new InventoryIO();

                inventoryOut.Location = inspectDetail.LocationFrom;
                inventoryOut.Item = inspectDetail.Item;
                inventoryOut.HuId = inspectDetail.HuId;
                inventoryOut.Qty = -inspectDetail.InspectQty * inspectDetail.UnitQty;  //转换为库存单位,为负数
                inventoryOut.LotNo = inspectDetail.LotNo;
                //inventoryOut.ManufactureParty = null;
                inventoryOut.QualityType = com.Sconit.CodeMaster.QualityType.Qualified; //报验一定是合格品
                inventoryOut.IsATP = true;
                inventoryOut.IsFreeze = false;
                inventoryOut.IsCreatePlanBill = false;
                inventoryOut.IsConsignment = inspectDetail.IsConsignment;
                inventoryOut.PlanBill = inspectDetail.PlanBill;
                inventoryOut.ActingBill = null;
                inventoryOut.TransactionType = inspectMaster.IsATP ? CodeMaster.TransactionType.ISS_INP : CodeMaster.TransactionType.ISS_ISL;
                inventoryOut.OccupyType = CodeMaster.OccupyType.None;
                inventoryOut.OccupyReferenceNo = null;
                inventoryOut.IsVoid = false;
                inventoryOut.EffectiveDate = effectiveDate;
                inventoryOut.ManufactureParty = inspectDetail.ManufactureParty;

                IList<InventoryTransaction> currentInventoryOutTransactionList = RecordInventory(inventoryOut);

                RecordLocationTransaction(inspectDetail, inspectMaster, effectiveDate, currentInventoryOutTransactionList, true);
                inventoryTransactionList.AddRange(currentInventoryOutTransactionList);
                #endregion


                #region 检验入库
                foreach (InventoryTransaction currentInventoryOutTransaction in currentInventoryOutTransactionList)
                {
                    InventoryIO inventoryIn = new InventoryIO();

                    inventoryIn.Location = inspectDetail.LocationFrom;
                    inventoryIn.Item = inspectDetail.Item;
                    inventoryIn.HuId = inspectDetail.HuId;
                    inventoryIn.Qty = -currentInventoryOutTransaction.Qty;
                    inventoryIn.LotNo = inspectDetail.LotNo;
                    //inventoryIn.ManufactureParty = null;
                    inventoryIn.QualityType = com.Sconit.CodeMaster.QualityType.Inspect; //报验入库为待验状态
                    inventoryIn.IsATP = inspectMaster.IsATP; //使用报验单上的可用标记,如果是二次检验的为false
                    inventoryIn.IsFreeze = false;
                    inventoryIn.IsCreatePlanBill = false;
                    inventoryIn.IsConsignment = currentInventoryOutTransaction.IsConsignment;
                    inventoryIn.PlanBill = currentInventoryOutTransaction.PlanBill;
                    inventoryIn.ActingBill = null;
                    inventoryIn.TransactionType = inspectMaster.IsATP ? CodeMaster.TransactionType.RCT_INP : CodeMaster.TransactionType.RCT_ISL;
                    inventoryIn.OccupyType = CodeMaster.OccupyType.Inspect;
                    inventoryIn.OccupyReferenceNo = inspectMaster.InspectNo;
                    inventoryIn.IsVoid = false;
                    inventoryIn.EffectiveDate = effectiveDate;
                    //inventoryIO.ManufactureParty = ;

                    IList<InventoryTransaction> currentInventoryInTransactionList = RecordInventory(inventoryIn);

                    RecordLocationTransaction(inspectDetail, inspectMaster, effectiveDate, currentInventoryInTransactionList, false);
                    inventoryTransactionList.AddRange(currentInventoryInTransactionList);
                }
                #endregion
            }

            return inventoryTransactionList;
        }
コード例 #17
0
        public IList<InventoryTransaction> InventoryExchange(IList<ItemExchange> itemExchangeList)
        {
            if (itemExchangeList != null && itemExchangeList.Count > 0)
            {
                List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();
                foreach (ItemExchange itemExchange in itemExchangeList)
                {
                    this.genericMgr.Create(itemExchange);

                    #region 出库
                    InventoryIO inventoryOut = new InventoryIO();

                    inventoryOut.Location = itemExchange.LocationFrom;
                    inventoryOut.Item = itemExchange.ItemFrom;
                    //inventoryOut.HuId = itemExchange.HuId;
                    inventoryOut.Qty = -itemExchange.Qty * itemExchange.UnitQty;  //转换为库存单位,为负数
                    //inventoryOut.LotNo = concessionDetail.LotNo;
                    //inventoryOut.ManufactureParty = null;
                    inventoryOut.QualityType = itemExchange.QualityType;
                    inventoryOut.IsATP = itemExchange.QualityType == CodeMaster.QualityType.Qualified;
                    inventoryOut.IsFreeze = false;
                    inventoryOut.IsCreatePlanBill = false;
                    inventoryOut.IsConsignment = false;
                    inventoryOut.PlanBill = null;
                    inventoryOut.ActingBill = null;
                    //inventoryOut.TransactionType = CodeMaster.TransactionType.ISS_IIC;
                    inventoryOut.OccupyType = CodeMaster.OccupyType.None;
                    inventoryOut.OccupyReferenceNo = null;
                    inventoryOut.IsVoid = false;
                    inventoryOut.EffectiveDate = itemExchange.EffectiveDate;
                    //inventoryOut.ManufactureParty = itemExchange.ManufactureParty;
                    //OutQty,OutUom,OutBaseUom,OutUnitQty,InHu,OutHu,OrderType 
                    inventoryOut.HuId = itemExchange.OldHu;
                    inventoryOut.LotNo = itemExchange.LotNo;

                    IList<InventoryTransaction> currentInventoryOutTransactionList = RecordInventory(inventoryOut);

                    RecordLocationTransaction(itemExchange, currentInventoryOutTransactionList, true, false);
                    inventoryTransactionList.AddRange(currentInventoryOutTransactionList);
                    #endregion

                    #region 入库
                    InventoryIO inventoryIn = new InventoryIO();

                    //OutQty,OutUom,OutBaseUom,OutUnitQty,OrderType 
                    inventoryIn.Location = itemExchange.LocationTo;
                    inventoryIn.Item = itemExchange.ItemTo;
                    //inventoryIn.HuId = itemExchange.HuId;
                    inventoryIn.Qty = itemExchange.NewQty * itemExchange.NewUnitQty;  //转换为库存单位
                    //inventoryIn.LotNo = itemExchange.LotNo;
                    //inventoryIn.ManufactureParty = null;
                    inventoryIn.QualityType = itemExchange.QualityType;
                    inventoryIn.IsATP = itemExchange.QualityType == CodeMaster.QualityType.Qualified;
                    inventoryIn.IsFreeze = false;
                    inventoryIn.IsCreatePlanBill = false;
                    inventoryIn.IsConsignment = false;
                    inventoryIn.PlanBill = null;
                    inventoryIn.ActingBill = null;
                    //inventoryIn.TransactionType = CodeMaster.TransactionType.RCT_IIC;
                    inventoryIn.OccupyType = CodeMaster.OccupyType.None;
                    inventoryIn.OccupyReferenceNo = null;
                    inventoryIn.IsVoid = false;
                    inventoryIn.EffectiveDate = itemExchange.EffectiveDate;
                    //inventoryIn.ManufactureParty = ;
                    inventoryIn.HuId = itemExchange.NewHu;
                    inventoryIn.LotNo = itemExchange.LotNo;

                    IList<InventoryTransaction> currentInventoryInTransactionList = RecordInventory(inventoryIn);

                    RecordLocationTransaction(itemExchange, currentInventoryInTransactionList, false, false);
                    inventoryTransactionList.AddRange(currentInventoryInTransactionList);
                    #endregion
                }

                return inventoryTransactionList;
            }

            return null;
        }
コード例 #18
0
        public IList<InventoryTransaction> InspectJudge(InspectMaster inspectMaster, IList<InspectResult> inspectResultList, DateTime effectiveDate)
        {
            if (inspectResultList == null || inspectResultList.Count == 0)
            {
                return null;
            }

            List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();

            foreach (InspectResult inspectResult in inspectResultList)
            {
                #region 判定出库
                InventoryIO inventoryOut = new InventoryIO();

                inventoryOut.Location = inspectResult.CurrentLocation;
                inventoryOut.Item = inspectResult.Item;
                inventoryOut.HuId = inspectResult.HuId;
                inventoryOut.Qty = -inspectResult.JudgeQty * inspectResult.UnitQty;  //转换为库存单位,为负数
                inventoryOut.LotNo = inspectResult.LotNo;
                //inventoryOut.ManufactureParty = null;
                inventoryOut.QualityType = com.Sconit.CodeMaster.QualityType.Inspect; //判定一定是待验
                inventoryOut.IsATP = inspectMaster.IsATP;
                inventoryOut.IsFreeze = false;
                inventoryOut.IsCreatePlanBill = false;
                inventoryOut.IsConsignment = false;
                inventoryOut.PlanBill = null;
                inventoryOut.ActingBill = null;
                inventoryOut.TransactionType = inspectResult.JudgeResult == CodeMaster.JudgeResult.Qualified ? CodeMaster.TransactionType.ISS_INP_QDII : CodeMaster.TransactionType.ISS_INP_REJ;
                inventoryOut.OccupyType = CodeMaster.OccupyType.Inspect;
                inventoryOut.OccupyReferenceNo = inspectMaster.InspectNo;
                inventoryOut.IsVoid = false;
                inventoryOut.EffectiveDate = effectiveDate;
                inventoryOut.ManufactureParty = inspectResult.ManufactureParty;

                IList<InventoryTransaction> currentInventoryOutTransactionList = RecordInventory(inventoryOut);

                RecordLocationTransaction(inspectMaster, inspectResult, effectiveDate, currentInventoryOutTransactionList, true);
                inventoryTransactionList.AddRange(currentInventoryOutTransactionList);
                #endregion

                #region 判定入库
                foreach (InventoryTransaction currentInventoryOutTransaction in currentInventoryOutTransactionList)
                {
                    InventoryIO inventoryIn = new InventoryIO();

                    inventoryIn.Location = inspectResult.CurrentLocation;
                    inventoryIn.Item = inspectResult.Item;
                    inventoryIn.HuId = inspectResult.HuId;
                    //inventoryIn.Qty = inspectResult.JudgeQty * inspectResult.UnitQty;  //转换为库存单位
                    inventoryIn.Qty = -currentInventoryOutTransaction.Qty;  //转换为库存单位
                    inventoryIn.LotNo = inspectResult.LotNo;
                    //inventoryIn.ManufactureParty = null;
                    inventoryIn.QualityType = inspectResult.JudgeResult == CodeMaster.JudgeResult.Qualified
                        ? CodeMaster.QualityType.Qualified : CodeMaster.QualityType.Reject;  //判定合格为合格品,不合格为不合格品
                    inventoryIn.IsATP = inspectResult.JudgeResult == CodeMaster.JudgeResult.Qualified;  //合格为可用,不合格为不可用
                    inventoryIn.IsFreeze = false;
                    inventoryIn.IsCreatePlanBill = false;
                    inventoryIn.IsConsignment = currentInventoryOutTransaction.IsConsignment;
                    inventoryIn.PlanBill = currentInventoryOutTransaction.PlanBill;
                    inventoryIn.ActingBill = null;
                    inventoryIn.TransactionType = inspectResult.JudgeResult == CodeMaster.JudgeResult.Qualified
                        ? CodeMaster.TransactionType.RCT_INP_QDII : CodeMaster.TransactionType.RCT_INP_REJ;
                    inventoryIn.OccupyType = CodeMaster.OccupyType.None;   //判定完就不占用了
                    inventoryIn.OccupyReferenceNo = null;
                    inventoryIn.IsVoid = false;
                    inventoryIn.EffectiveDate = effectiveDate;
                    //inventoryIO.ManufactureParty = ;
                    inventoryIn.Bin = currentInventoryOutTransaction.Bin;//自动上架

                    IList<InventoryTransaction> currentInventoryInTransactionList = RecordInventory(inventoryIn);

                    RecordLocationTransaction(inspectMaster, inspectResult, effectiveDate, currentInventoryInTransactionList, false);
                    inventoryTransactionList.AddRange(currentInventoryInTransactionList);
                }
                #endregion
            }

            return inventoryTransactionList;
        }
コード例 #19
0
        public IList<InventoryTransaction> InventoryRePack(IList<InventoryRePack> inventoryRePackList, Boolean isCheckOccupy, DateTime effectiveDate)
        {
            IList<HuStatus> huStatusList = this.huMgr.GetHuStatus(inventoryRePackList.Select(i => i.HuId).ToList());

            #region 检验
            BusinessException businessException = new BusinessException();

            foreach (InventoryRePack inventoryRePack in inventoryRePackList)
            {
                HuStatus huStatus = huStatusList.Where(h => h.HuId == inventoryRePack.HuId).SingleOrDefault();

                if (huStatus == null)
                {
                    businessException.AddMessage("条码{0}不存在。", huStatus.HuId);
                }

                if (inventoryRePack.Type == CodeMaster.RePackType.Out)
                {
                    if (huStatus.Status == CodeMaster.HuStatus.Ip)
                    {
                        businessException.AddMessage("条码{0}为库位{1}至库位{2}的在途库存,不能翻箱。", huStatus.HuId, huStatus.LocationFrom, huStatus.LocationTo);
                    }

                    if (huStatus.Status == CodeMaster.HuStatus.NA)
                    {
                        businessException.AddMessage("条码{0}已经不在任何库位中,不能翻箱。", huStatus.HuId);
                    }

                    if (isCheckOccupy == true)
                    {
                        if (huStatus.OccupyType != CodeMaster.OccupyType.None)
                        {
                            businessException.AddMessage("条码{0}已经被占用,不能翻箱。", huStatus.HuId);
                        }
                    }
                }
                else
                {
                    if (huStatus.Status == CodeMaster.HuStatus.Location)
                    {
                        businessException.AddMessage("条码{0}已经在库位{1}中,不能翻箱。", huStatus.HuId, huStatus.Location);
                    }

                    if (huStatus.Status == CodeMaster.HuStatus.Ip)
                    {
                        businessException.AddMessage("条码{0}为库位{1}至库位{2}的在途库存,不能翻箱。", huStatus.HuId, huStatus.LocationFrom, huStatus.LocationTo);
                    }
                }
                inventoryRePack.Location = huStatus.Location;
                inventoryRePack.CurrentHu = huStatus;
            }

            if (inventoryRePackList.Where(i => i.Type == CodeMaster.RePackType.Out).Select(i => i.Location).Distinct().Count() > 1)
            {
                businessException.AddMessage("翻箱前条码的库位不一致。");
            }

            if (inventoryRePackList.Select(i => i.CurrentHu.Item).Distinct().Count() > 1)
            {
                businessException.AddMessage("翻箱前后的物料不一致。");
            }

            if (inventoryRePackList.Where(i => i.Type == CodeMaster.RePackType.Out).Sum(i => i.CurrentHu.Qty * i.CurrentHu.UnitQty)
                 != inventoryRePackList.Where(i => i.Type == CodeMaster.RePackType.In).Sum(i => i.CurrentHu.Qty * i.CurrentHu.UnitQty))
            {
                businessException.AddMessage("翻箱前的条码数量和翻箱后的条码数量不一致。");
            }

            if (businessException.HasMessage)
            {
                throw businessException;
            }
            #endregion

            #region 查找库位
            Location location = this.genericMgr.FindById<Location>(inventoryRePackList.Where(i => i.Type == CodeMaster.RePackType.Out).Select(i => i.Location).First());
            //IList<Location> locationList = BatchLoadLocations(inventoryRePackList.Where(i => i.Type == CodeMaster.RePackType.Out).Select(i => i.Location).ToList());
            #endregion

            #region 循环拆箱
            IList<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();

            #region 出库
            IList<InventoryTransaction> totalIssInventoryTransactionList = new List<InventoryTransaction>();
            foreach (InventoryRePack inventoryRePack in inventoryRePackList.Where(i => i.Type == CodeMaster.RePackType.Out))
            {
                inventoryRePack.CurrentLocation = location;

                InventoryIO inventoryOut = new InventoryIO();

                inventoryOut.Location = inventoryRePack.CurrentHu.Location;
                inventoryOut.Item = inventoryRePack.CurrentHu.Item;
                inventoryOut.HuId = inventoryRePack.CurrentHu.HuId;
                inventoryOut.Qty = -inventoryRePack.CurrentHu.Qty * inventoryRePack.CurrentHu.UnitQty;  //转换为库存单位
                inventoryOut.LotNo = inventoryRePack.CurrentHu.LotNo;
                inventoryOut.QualityType = inventoryRePack.CurrentHu.QualityType;
                inventoryOut.IsATP = inventoryRePack.CurrentHu.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                inventoryOut.IsFreeze = inventoryRePack.CurrentHu.IsFreeze;
                inventoryOut.IsCreatePlanBill = false;
                inventoryOut.IsConsignment = inventoryRePack.CurrentHu.IsConsignment;
                inventoryOut.PlanBill = inventoryRePack.CurrentHu.PlanBill;
                inventoryOut.ActingBill = null;
                inventoryOut.TransactionType = CodeMaster.TransactionType.ISS_REP;
                inventoryOut.OccupyType = inventoryRePack.CurrentHu.OccupyType;
                inventoryOut.OccupyReferenceNo = inventoryRePack.CurrentHu.OccupyReferenceNo;
                inventoryOut.IsVoid = false;
                inventoryOut.EffectiveDate = effectiveDate;
                //inventoryIO.ManufactureParty = ;

                IList<InventoryTransaction> issInventoryTransactionList = RecordInventory(inventoryOut);

                #region 如果翻箱的出库库存明细有寄售非寄售混杂或者有多条寄售信息,立即结算
                //寄售翻箱不能立即结算
                //TryManualSettleBill(totalIssInventoryTransactionList, effectiveDate);
                #endregion

                ((List<InventoryTransaction>)totalIssInventoryTransactionList).AddRange(issInventoryTransactionList);
                ((List<InventoryTransaction>)inventoryTransactionList).AddRange(issInventoryTransactionList);
                RecordLocationTransaction(inventoryRePack, effectiveDate, issInventoryTransactionList, true);
            }
            #endregion

            #region 入库
            foreach (InventoryRePack inventoryRePack in inventoryRePackList.Where(i => i.Type == CodeMaster.RePackType.In))
            {
                inventoryRePack.CurrentLocation = location;

                InventoryIO inventoryIn = new InventoryIO();

                inventoryIn.Location = location.Code;
                inventoryIn.Item = inventoryRePack.CurrentHu.Item;
                inventoryIn.HuId = inventoryRePack.CurrentHu.HuId;
                inventoryIn.LotNo = inventoryRePack.CurrentHu.LotNo;
                inventoryIn.Qty = inventoryRePack.CurrentHu.Qty * inventoryRePack.CurrentHu.UnitQty;  //转换为库存单位
                inventoryIn.QualityType = inventoryRePack.CurrentHu.QualityType;
                inventoryIn.IsATP = inventoryRePack.CurrentHu.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                inventoryIn.IsFreeze = inventoryRePack.CurrentHu.IsFreeze;
                inventoryIn.IsCreatePlanBill = false;
                inventoryIn.IsConsignment = totalIssInventoryTransactionList.Select(i => i.IsConsignment).First();
                inventoryIn.PlanBill = inventoryIn.IsConsignment ? totalIssInventoryTransactionList[0].PlanBill : null;
                inventoryIn.ActingBill = null;
                inventoryIn.TransactionType = CodeMaster.TransactionType.RCT_REP;
                inventoryIn.OccupyType = inventoryRePack.CurrentHu.OccupyType;
                inventoryIn.OccupyReferenceNo = inventoryRePack.CurrentHu.OccupyReferenceNo;
                inventoryIn.IsVoid = false;
                inventoryIn.EffectiveDate = effectiveDate;
                //inventoryIO.ManufactureParty = ;

                IList<InventoryTransaction> rctInventoryTransactionList = RecordInventory(inventoryIn);
                ((List<InventoryTransaction>)inventoryTransactionList).AddRange(rctInventoryTransactionList);
                RecordLocationTransaction(inventoryRePack, effectiveDate, rctInventoryTransactionList, false);
            }
            #endregion

            return inventoryTransactionList;
            #endregion
        }
コード例 #20
0
        public IList<InventoryTransaction> ConcessionToUse(ConcessionMaster consessionMaster, DateTime effectiveDate)
        {
            if (consessionMaster.ConcessionDetails != null && consessionMaster.ConcessionDetails.Count > 0)
            {
                List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();
                foreach (ConcessionDetail concessionDetail in consessionMaster.ConcessionDetails)
                {
                    #region 让步出库
                    InventoryIO inventoryOut = new InventoryIO();

                    inventoryOut.Location = concessionDetail.LocationFrom;
                    inventoryOut.Item = concessionDetail.Item;
                    inventoryOut.HuId = concessionDetail.HuId;
                    inventoryOut.Qty = -concessionDetail.Qty * concessionDetail.UnitQty;  //转换为库存单位,为负数
                    inventoryOut.LotNo = concessionDetail.LotNo;
                    inventoryOut.QualityType = com.Sconit.CodeMaster.QualityType.Reject; //让步使用一定是不合格品
                    inventoryOut.IsATP = false;
                    inventoryOut.IsFreeze = false;
                    inventoryOut.IsCreatePlanBill = false;
                    inventoryOut.IsConsignment = false;
                    inventoryOut.PlanBill = null;
                    inventoryOut.ActingBill = null;
                    inventoryOut.TransactionType = CodeMaster.TransactionType.ISS_INP_CCS;
                    inventoryOut.OccupyType = CodeMaster.OccupyType.None;
                    inventoryOut.OccupyReferenceNo = null;
                    inventoryOut.IsVoid = false;
                    inventoryOut.EffectiveDate = effectiveDate;
                    //inventoryIO.ManufactureParty = ;

                    IList<InventoryTransaction> currentInventoryOutTransactionList = RecordInventory(inventoryOut);

                    RecordLocationTransaction(consessionMaster, concessionDetail, effectiveDate, currentInventoryOutTransactionList, true);
                    inventoryTransactionList.AddRange(currentInventoryOutTransactionList);
                    #endregion

                    #region 让步入库
                    foreach (InventoryTransaction currentInventoryOutTransaction in currentInventoryOutTransactionList)
                    {
                        InventoryIO inventoryIn = new InventoryIO();

                        inventoryIn.Location = concessionDetail.LocationTo;
                        inventoryIn.Item = concessionDetail.Item;
                        inventoryIn.HuId = concessionDetail.HuId;
                        inventoryIn.Qty = -currentInventoryOutTransaction.Qty;
                        inventoryIn.LotNo = concessionDetail.LotNo;
                        inventoryIn.QualityType = CodeMaster.QualityType.Qualified;
                        inventoryIn.IsATP = true;
                        inventoryIn.IsFreeze = false;
                        inventoryIn.IsCreatePlanBill = false;
                        inventoryIn.IsConsignment = currentInventoryOutTransaction.IsConsignment;
                        inventoryIn.PlanBill = currentInventoryOutTransaction.PlanBill;
                        inventoryIn.ActingBill = null;
                        inventoryIn.TransactionType = CodeMaster.TransactionType.RCT_INP_CCS;
                        inventoryIn.OccupyType = CodeMaster.OccupyType.None;
                        inventoryIn.OccupyReferenceNo = null;
                        inventoryIn.IsVoid = false;
                        inventoryIn.EffectiveDate = effectiveDate;
                        //inventoryIO.ManufactureParty = ;

                        IList<InventoryTransaction> currentInventoryInTransactionList = RecordInventory(inventoryIn);

                        RecordLocationTransaction(consessionMaster, concessionDetail, effectiveDate, currentInventoryInTransactionList, false);
                        inventoryTransactionList.AddRange(currentInventoryInTransactionList);
                    }

                    #endregion
                }

                return inventoryTransactionList;
            }

            return null;
        }
コード例 #21
0
        private void BackflushInventory(InventoryIO inventoryIO, IList<LocationLotDetail> backFlushLocLotDetList, IList<InventoryTransaction> inventoryTransactionList)
        {
            Boolean isVoidedActBill = false;
            SettleBillTransaction voidBillTransaction = new SettleBillTransaction();
            if (backFlushLocLotDetList != null && backFlushLocLotDetList.Count > 0)
            {
                foreach (LocationLotDetail backFlushLocLotDet in backFlushLocLotDetList)
                {
                    #region 只有发生在按条码发货,按数量收货的情况,因为有些待回冲的库存已经被上一个条码冲掉,这里就不继续回冲了。
                    if (backFlushLocLotDet.Qty == 0)
                    {
                        continue;
                    }
                    #endregion

                    #region 判断是否满足回冲条件
                    if (inventoryIO.Qty == 0)
                    {
                        return;
                    }

                    PlanBill backFlushPlanBill = backFlushLocLotDet.IsConsignment && backFlushLocLotDet.PlanBill.HasValue ? this.genericMgr.FindById<PlanBill>(backFlushLocLotDet.PlanBill.Value) : null;
                    PlanBill inputPlanBill = inventoryIO.IsConsignment ? TryLoadPlanBill(inventoryIO) : null;

                    //如果被回冲和入库的都是寄售库存并且是同一个供应商,一定要回冲
                    if (backFlushLocLotDet.IsConsignment && inputPlanBill != null
                        && backFlushPlanBill.BillAddress == inputPlanBill.BillAddress)
                    {

                    }
                    else
                    {
                        //被回冲的寄售库存,和入库的寄售库存不是一个供应商,不能回冲
                        if (backFlushLocLotDet.IsConsignment && inputPlanBill != null
                            && backFlushPlanBill.BillAddress != inputPlanBill.BillAddress)
                        {
                            return;
                        }

                        //被回冲的寄售库存的结算方式是上线结算,判断是否当前事务类型是否是ISS-*,不满足不能回冲
                        //if (backFlushLocLotDet.IsConsignment
                        //    && backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_ONLINE_BILLING)
                        //{
                        //    if (!transType.StartsWith("ISS-"))
                        //    {
                        //        return;
                        //    }
                        //}

                        //被回冲的寄售库存的结算方式是下线结算,判断是否当前事务类型是否是ISS-*并且不等于ISS-TR,不满足不能回冲
                        //if (backFlushLocLotDet.IsConsignment
                        //   && backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_LINEAR_CLEARING)
                        //{
                        //    if (!(transType.StartsWith("ISS-") && transType != BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_TR))
                        //    {
                        //        return;
                        //    }
                        //}
                    }
                    #endregion

                    #region 回冲库存
                    decimal currentBFQty = 0; //本次回冲数
                    if (inventoryIO.Qty > 0)
                    {
                        if (backFlushLocLotDet.Qty + inventoryIO.Qty < 0)
                        {
                            //本次入库数 < 库存数量,全部回冲,回冲数量等于本次入库数
                            currentBFQty = inventoryIO.Qty;
                        }
                        else
                        {
                            //本次入库数 >= 库存数量,按负的库存数回冲
                            currentBFQty = 0 - backFlushLocLotDet.Qty;
                        }
                    }
                    else
                    {
                        if (backFlushLocLotDet.Qty + inventoryIO.Qty > 0)
                        {
                            //本次出库数 < 库存数量,全部回冲,回冲数量等于本次出库数
                            currentBFQty = inventoryIO.Qty;
                        }
                        else
                        {
                            //本次出库数 >= 库存数量,按正的库存数回冲
                            currentBFQty = 0 - backFlushLocLotDet.Qty;
                        }
                    }

                    //更新库存数量
                    backFlushLocLotDet.Qty += currentBFQty;
                    this.genericMgr.Update(backFlushLocLotDet);

                    #endregion

                    #region 结算
                    SettleBillTransaction billTransaction = null;

                    if (inventoryIO.Qty < 0 && inputPlanBill == null && backFlushLocLotDet.IsConsignment)
                    {
                        if (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SO            //销售出库
                                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_WO      //生产出库
                            //|| inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_MIN  //投料 李秋云
                                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SWO      //委外生产出库
                                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_UNP    //计划外出库
                                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.CYC_CNT)     //盘亏
                        //// (backFlushPlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_ONLINE_BILLING   //上线结算条件,发生移库出库事务才结算,可以避免收货检验时入检验库位就结算
                        ////&& (transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_TR
                        ////    || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_MATERIAL_IN)) 
                        ////|| 
                        //(backFlushPlanBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_LINEAR_CLEARING   //下线结算条件
                        //    && transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO)
                        ////|| (backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_INSPECTION         //检验结算条件,从检验库位出库,并且发生ISS-INP事务
                        ////    && backFlushLocLotDet.Location.Code == BusinessConstants.SYSTEM_LOCATION_INSPECT
                        ////        && transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_INP)
                        ////|| (backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_INSPECTION         //检验结算,从不合格品库位出库,立即结算
                        ////    && backFlushLocLotDet.Location.Code == BusinessConstants.SYSTEM_LOCATION_REJECT)
                        //|| transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_UNP                              //如果发生ISS_UNP或者CYC_CNT事务,强行结算
                        //|| transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_CYC_CNT
                        //|| transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_SO
                        //|| transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO
                        //|| transType.StartsWith(BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT))
                        {
                            //寄售库存需要进行结算,对被回冲的库存进行负数结算
                            backFlushPlanBill.CurrentActingQty = (0 - currentBFQty) / backFlushPlanBill.UnitQty; //按负数结算
                            backFlushPlanBill.CurrentLocation = backFlushLocLotDet.Location;
                            billTransaction = this.billMgr.SettleBill(backFlushPlanBill, inventoryIO.EffectiveDate);
                        }
                        //else if (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_PO      //采购退货
                        //        || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SL)     //计划协议退货
                        //{
                        //    //退货,寄售库存需要取消寄售数量
                        //    backFlushPlanBill.CurrentVoidQty = (0 - currentBFQty) / backFlushPlanBill.UnitQty; //按负数结算
                        //    this.billMgr.VoidPlanBill(backFlushPlanBill);
                        //}
                    }
                    else
                    {
                        //如果出库PlanBill和被回冲PlanBill的Id相同,即指定PlanBill出库,不发生回冲
                        if (!(backFlushLocLotDet.IsConsignment && backFlushLocLotDet.PlanBill == inputPlanBill.Id))
                        {
                            if (backFlushLocLotDet.IsConsignment)
                            {
                                //寄售库存需要进行结算,对被回冲的库存进行负数结算
                                backFlushPlanBill.CurrentActingQty = (0 - currentBFQty) / backFlushPlanBill.UnitQty; //按负数结算
                                backFlushPlanBill.CurrentLocation = backFlushLocLotDet.Location;
                                billTransaction = this.billMgr.SettleBill(backFlushPlanBill, inventoryIO.EffectiveDate);
                            }

                            if (inputPlanBill != null)
                            {
                                if (inventoryIO.QualityType == CodeMaster.QualityType.Inspect)
                                {
                                    throw new BusinessException("待验物料{0}不能结算。", inventoryIO.Item);
                                }
                                else if (inventoryIO.QualityType == CodeMaster.QualityType.Reject)
                                {
                                    //throw new BusinessException("不合格物料{0}不能结算。", inventoryIO.Item);
                                }

                                //对入库的库存进行结算
                                inputPlanBill.CurrentActingQty = currentBFQty / inputPlanBill.UnitQty;  //按正数结算
                                inputPlanBill.CurrentLocation = backFlushLocLotDet.Location;
                                billTransaction = this.billMgr.SettleBill(inputPlanBill, inventoryIO.EffectiveDate);
                            }
                        }
                    }
                    #endregion

                    #region 处理冲销寄售和结算信息
                    if (billTransaction == null)
                    {
                        if (isVoidedActBill == false)
                        {
                            billTransaction = VoidBill(inventoryIO);
                            isVoidedActBill = true;
                            voidBillTransaction = billTransaction;
                        }
                        else
                        {
                            billTransaction = voidBillTransaction;
                        }
                    }
                    #endregion

                    //记录被回冲的记录
                    if (inventoryIO.Qty > 0)
                    {
                        //回冲负数库存,按inventoryIO记录库存事务
                        inventoryTransactionList.Add(CreateInventoryTransaction(inventoryIO, currentBFQty, backFlushLocLotDet, billTransaction));
                    }
                    else
                    {
                        //回冲正数库存,按backFlushLocLotDet记录库存事务
                        //因为是出库,不可能有创建Planbill的情况
                        inventoryTransactionList.Add(CreateInventoryTransaction(backFlushLocLotDet, currentBFQty, false, billTransaction));
                    }

                    inventoryIO.Qty -= currentBFQty;
                }
            }
        }
コード例 #22
0
        public IList<InventoryTransaction> InventoryPack(IList<InventoryPack> inventoryPackList, DateTime effectiveDate)
        {
            IList<HuStatus> huStatusList = this.huMgr.GetHuStatus(inventoryPackList.Select(i => i.HuId).ToList());

            #region 检验
            BusinessException businessException = new BusinessException();
            foreach (InventoryPack inventoryPack in inventoryPackList)
            {
                HuStatus huStatus = huStatusList.Where(h => h.HuId == inventoryPack.HuId).SingleOrDefault();

                if (huStatus == null)
                {
                    businessException.AddMessage("条码{0}不存在。", huStatus.HuId);
                }

                if (huStatus.Status == CodeMaster.HuStatus.Location)
                {
                    businessException.AddMessage("条码{0}已经在库位{1}中,不能装箱。", huStatus.HuId, huStatus.Location);
                }

                if (huStatus.Status == CodeMaster.HuStatus.Ip)
                {
                    businessException.AddMessage("条码{0}为库位{1}至库位{2}的在途库存,不能装箱。", huStatus.HuId, huStatus.LocationFrom, huStatus.LocationTo);
                }

                if (inventoryPack.OccupyType != CodeMaster.OccupyType.None)
                {
                    businessException.AddMessage("零件{0}的库存已经被占用,不能装箱。", huStatus.Item);
                }

                inventoryPack.CurrentHu = huStatus;
            }

            if (businessException.HasMessage)
            {
                throw businessException;
            }
            #endregion

            #region 查找库位
            IList<Location> locationList = BatchLoadLocations(inventoryPackList.Select(i => i.Location).ToList());
            #endregion

            #region 循环装箱
            IList<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();
            foreach (InventoryPack inventoryPack in inventoryPackList)
            {
                inventoryPack.CurrentLocation = locationList.Where(l => l.Code == inventoryPack.Location).Single();

                #region 出库
                InventoryIO inventoryOut = new InventoryIO();
                IList<InventoryTransaction> issInventoryTransactionList = new List<InventoryTransaction>();

                if (inventoryPack.LocationLotDetailIdList != null && inventoryPack.LocationLotDetailIdList.Count > 0)
                {
                    #region 指定库存明细拆箱
                    foreach (int locationLotDetailId in inventoryPack.LocationLotDetailIdList)
                    {
                        inventoryOut.LocationLotDetailId = locationLotDetailId;
                        //inventoryOut.Qty = inventoryPack;  //转换为库存单位
                        inventoryOut.EffectiveDate = effectiveDate;

                        ((List<InventoryTransaction>)issInventoryTransactionList).AddRange(RecordInventory(inventoryOut));
                    }
                    #endregion
                }
                else
                {
                    inventoryOut.Location = inventoryPack.Location;
                    inventoryOut.Item = inventoryPack.CurrentHu.Item;
                    inventoryOut.HuId = null;
                    inventoryOut.Qty = -inventoryPack.CurrentHu.Qty * inventoryPack.CurrentHu.UnitQty;  //转换为库存单位
                    inventoryOut.LotNo = null;
                    inventoryOut.QualityType = inventoryPack.CurrentHu.QualityType;
                    inventoryOut.IsATP = inventoryPack.CurrentHu.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryOut.IsFreeze = false;
                    inventoryOut.IsCreatePlanBill = false;
                    inventoryOut.IsConsignment = false;
                    inventoryOut.PlanBill = null;
                    inventoryOut.ActingBill = null;
                    inventoryOut.TransactionType = CodeMaster.TransactionType.ISS_REP;
                    inventoryOut.OccupyType = inventoryPack.OccupyType;
                    inventoryOut.OccupyReferenceNo = inventoryPack.OccupyReferenceNo;
                    inventoryOut.IsVoid = false;
                    inventoryOut.EffectiveDate = effectiveDate;
                    //inventoryIO.ManufactureParty = ;

                    issInventoryTransactionList = RecordInventory(inventoryOut);
                }

                #region 如果翻箱的出库库存明细有寄售非寄售混杂或者有多条寄售信息,立即结算
                TryManualSettleBill(issInventoryTransactionList, effectiveDate);
                #endregion

                ((List<InventoryTransaction>)inventoryTransactionList).AddRange(issInventoryTransactionList);
                RecordLocationTransaction(inventoryPack, effectiveDate, issInventoryTransactionList, true);
                #endregion

                #region 入库
                InventoryIO inventoryIn = new InventoryIO();

                inventoryIn.Location = inventoryPack.Location;
                inventoryIn.Item = inventoryPack.CurrentHu.Item;
                inventoryIn.HuId = inventoryPack.CurrentHu.HuId;
                inventoryIn.LotNo = inventoryPack.CurrentHu.LotNo;
                inventoryIn.Qty = inventoryPack.CurrentHu.Qty * inventoryPack.CurrentHu.UnitQty;  //转换为库存单位
                inventoryIn.QualityType = inventoryPack.CurrentHu.QualityType;
                inventoryIn.IsATP = inventoryPack.CurrentHu.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                inventoryIn.IsFreeze = false;
                inventoryIn.IsCreatePlanBill = false;
                inventoryIn.IsConsignment = issInventoryTransactionList.Select(i => i.IsConsignment).First();
                inventoryIn.PlanBill = inventoryIn.IsConsignment ? issInventoryTransactionList[0].PlanBill : null;
                inventoryIn.ActingBill = null;
                inventoryIn.TransactionType = CodeMaster.TransactionType.RCT_REP;
                inventoryIn.OccupyType = inventoryPack.OccupyType;
                inventoryIn.OccupyReferenceNo = inventoryPack.OccupyReferenceNo;
                inventoryIn.IsVoid = false;
                inventoryIn.EffectiveDate = effectiveDate;
                //inventoryIO.ManufactureParty = ;

                IList<InventoryTransaction> rctInventoryTransactionList = RecordInventory(inventoryIn);
                RecordLocationTransaction(inventoryPack, effectiveDate, rctInventoryTransactionList, false);
                ((List<InventoryTransaction>)inventoryTransactionList).AddRange(issInventoryTransactionList);
                #endregion
            }

            return inventoryTransactionList;
            #endregion
        }
コード例 #23
0
        public IList<InventoryTransaction> InventoryIn(ReceiptDetail receiptDetail, DateTime effectiveDate)
        {
            List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();
            com.Sconit.CodeMaster.TransactionType? transType = GetTransactionType(receiptDetail);
            if (transType.HasValue)
            {
                #region 收货冲销,如果一个条码对应多条receiptDetailInput,需要先拆箱
                if (receiptDetail.IsVoid)
                {
                    var groupedHuIdList = from det in receiptDetail.ReceiptDetailInputs
                                          where !string.IsNullOrWhiteSpace(det.HuId)
                                          group det by det.HuId into gj
                                          select new
                                          {
                                              HuId = gj.Key,
                                              ReceiptDetailInputList = gj.ToList()
                                          };

                    if (groupedHuIdList != null && groupedHuIdList.Count() > 0)
                    {
                        //已知Bug,如果收货时不结算,两条不同的PlanBill生成条码会强制结算。但是在冲销时不会反结算。
                        #region 循环拆箱
                        foreach (var groupedHuId in groupedHuIdList.Where(g => g.ReceiptDetailInputList.Count() > 1))
                        {
                            InventoryUnPack inventoryUnPack = new InventoryUnPack();

                            inventoryUnPack.HuId = groupedHuId.HuId;
                            inventoryUnPack.CurrentHu = this.huMgr.GetHuStatus(groupedHuId.HuId);
                            IList<InventoryUnPack> inventoryUnPackList = new List<InventoryUnPack>();
                            inventoryUnPackList.Add(inventoryUnPack);
                            this.InventoryUnPack(inventoryUnPackList, effectiveDate);

                            foreach (ReceiptDetailInput receiptDetailInput in groupedHuId.ReceiptDetailInputList)
                            {
                                //把ReceiptDetailInput的HuId和LotNo至空,按数量出库。
                                receiptDetailInput.HuId = null;
                                receiptDetailInput.LotNo = null;
                                receiptDetailInput.IsConsignment = false;
                                receiptDetailInput.PlanBill = null;
                            }
                        }
                        #endregion

                        this.genericMgr.FlushSession();
                    }
                }
                #endregion

                foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                {
                    if (receiptDetailInput.ReceivedIpLocationDetailList != null && receiptDetailInput.ReceivedIpLocationDetailList.Count > 0)
                    {
                        List<InventoryTransaction> currentReceiptDetailInputInventoryTransactionList = new List<InventoryTransaction>();
                        #region 基于Ip收货,零件的寄售信息都在IpLocationDetail上面
                        foreach (IpLocationDetail receivedIpLocationDetail in receiptDetailInput.ReceivedIpLocationDetailList)
                        {
                            ReceiptDetailInput thisReceiptDetailInput = Mapper.Map<ReceiptDetailInput, ReceiptDetailInput>(receiptDetailInput);
                            thisReceiptDetailInput.ReceiveQty = (decimal)receivedIpLocationDetail.ReceivedQty / receiptDetail.UnitQty;
                            if (receiptDetail.CurrentIsReceiveScanHu && !string.IsNullOrWhiteSpace(receivedIpLocationDetail.HuId))
                            {
                                thisReceiptDetailInput.HuId = receivedIpLocationDetail.HuId;
                                thisReceiptDetailInput.LotNo = receivedIpLocationDetail.LotNo;
                            }

                            InventoryIO inventoryIO = new InventoryIO();

                            inventoryIO.Location = receiptDetail.LocationTo;
                            inventoryIO.Item = receiptDetail.Item;
                            if (receiptDetail.CurrentIsReceiveScanHu && receiptDetailInput.ReceivedIpLocationDetailList.Count == 1)
                            {
                                //如果收货扫描条码,并且只有一条发货库存明细,可以直接收为条码
                                //要用收货Input上指定的条码
                                inventoryIO.HuId = thisReceiptDetailInput.HuId;
                                inventoryIO.LotNo = thisReceiptDetailInput.LotNo;
                            }
                            inventoryIO.Qty = receivedIpLocationDetail.ReceivedQty;             //库存单位
                            inventoryIO.QualityType = receivedIpLocationDetail.QualityType;     //不合格品的ATP状态一定是false,合格品的状态一定是true,质检不采用ASN发货这里不可能出现
                            inventoryIO.IsATP = receivedIpLocationDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                            inventoryIO.IsFreeze = false;                       //可能指定移库冻结的零件?
                            inventoryIO.IsCreatePlanBill = receivedIpLocationDetail.IsCreatePlanBill;
                            inventoryIO.IsConsignment = receivedIpLocationDetail.IsConsignment;
                            inventoryIO.PlanBill = receivedIpLocationDetail.PlanBill;
                            inventoryIO.ActingBill = receivedIpLocationDetail.ActingBill;
                            inventoryIO.TransactionType = transType.Value;
                            //if (receivedIpLocationDetail.OccupyType == CodeMaster.OccupyType.Inspect)   //只有检验的收货要保留占用,其它收货不用保留
                            //{
                            inventoryIO.OccupyType = receivedIpLocationDetail.OccupyType;
                            inventoryIO.OccupyReferenceNo = receivedIpLocationDetail.OccupyReferenceNo;
                            //}
                            //inventoryIO.IsVoid = receiptDetail.IsVoid;
                            inventoryIO.EffectiveDate = effectiveDate;

                            #region 寄售处理
                            if (!receiptDetail.IsVoid &&
                                (((receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                                || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine)
                                && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                               || (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution
                                    && transType != CodeMaster.TransactionType.RCT_TR)  //差异调整至发货方,不用产生结算
                               || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract))
                            {
                                if (receivedIpLocationDetail.IsConsignment && receivedIpLocationDetail.PlanBill.HasValue)
                                {
                                    throw new TechnicalException("Can't create new planbill when receiptDetailInput aready has unsettled planbill.");
                                }
                                else
                                {
                                    #region 记录待结算
                                    PlanBill planBill = this.billMgr.CreatePlanBill(receiptDetail, thisReceiptDetailInput, effectiveDate);

                                    inventoryIO.IsConsignment = true;
                                    inventoryIO.IsCreatePlanBill = true;
                                    inventoryIO.PlanBill = planBill.Id;
                                    inventoryIO.CurrentPlanBill = planBill;

                                    thisReceiptDetailInput.IsConsignment = true;
                                    thisReceiptDetailInput.IsCreatePlanBill = true;
                                    thisReceiptDetailInput.PlanBill = planBill.Id;
                                    #endregion
                                }
                            }
                            #endregion

                            IList<InventoryTransaction> currentInventoryTransactionList = RecordInventory(inventoryIO);
                            #region 记录HuId,LotNo和WMS发货单行号
                            foreach (InventoryTransaction currentInventoryTransaction in currentInventoryTransactionList)
                            {
                                if (receiptDetail.CurrentIsReceiveScanHu && receiptDetailInput.ReceivedIpLocationDetailList.Count > 1
                                    && !string.IsNullOrWhiteSpace(receiptDetailInput.HuId))
                                {
                                    Hu hu = this.genericMgr.FindById<Hu>(receiptDetailInput.HuId);
                                    currentInventoryTransaction.HuId = hu.HuId;
                                    currentInventoryTransaction.LotNo = hu.LotNo;
                                }
                                currentInventoryTransaction.WMSRecSeq = receiptDetailInput.WMSRecSeq;
                            }
                            #endregion

                            RecordLocationTransaction(receiptDetail, thisReceiptDetailInput, effectiveDate, transType.Value, currentInventoryTransactionList);
                            inventoryTransactionList.AddRange(currentInventoryTransactionList);
                            currentReceiptDetailInputInventoryTransactionList.AddRange(currentInventoryTransactionList);
                        }

                        #region 收货扫描条码,需要装箱创建条码
                        if (receiptDetail.CurrentIsReceiveScanHu && receiptDetailInput.ReceivedIpLocationDetailList.Count > 1
                            && !string.IsNullOrWhiteSpace(receiptDetailInput.HuId))
                        {
                            #region 装箱
                            IList<InventoryPack> inventoryPackList = new List<InventoryPack>();
                            InventoryPack inventoryPack = new InventoryPack();
                            inventoryPack.Location = receiptDetail.LocationTo;
                            inventoryPack.HuId = receiptDetailInput.HuId;
                            inventoryPack.LocationLotDetailIdList = currentReceiptDetailInputInventoryTransactionList.Select(inv => inv.LocationLotDetailId).ToList();

                            inventoryPackList.Add(inventoryPack);
                            this.InventoryPack(inventoryPackList, effectiveDate);
                            #endregion
                        }
                        #endregion
                        #endregion
                    }
                    else
                    {
                        #region 基于ReceiptDetailInput收货
                        InventoryIO inventoryIO = new InventoryIO();

                        inventoryIO.Location = receiptDetail.LocationTo;
                        inventoryIO.Item = receiptDetail.Item;
                        inventoryIO.HuId = receiptDetailInput.HuId;
                        inventoryIO.LotNo = receiptDetailInput.LotNo;
                        inventoryIO.Qty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位
                        inventoryIO.QualityType = receiptDetailInput.QualityType;     //不合格品的ATP状态一定是false,合格品的状态一定是true,质检不采用ASN发货这里不可能出现
                        inventoryIO.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                        inventoryIO.IsFreeze = false;                       //可能指定移库冻结的零件?
                        inventoryIO.IsCreatePlanBill = receiptDetailInput.IsCreatePlanBill;
                        inventoryIO.IsConsignment = receiptDetailInput.IsConsignment;
                        inventoryIO.PlanBill = receiptDetailInput.PlanBill;
                        inventoryIO.ActingBill = receiptDetailInput.ActingBill;
                        inventoryIO.TransactionType = transType.Value;
                        inventoryIO.OccupyType = receiptDetailInput.OccupyType;
                        inventoryIO.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;
                        inventoryIO.IsVoid = receiptDetail.IsVoid;
                        inventoryIO.EffectiveDate = effectiveDate;
                        //inventoryIO.ManufactureParty = ;

                        #region 寄售处理
                        if (!receiptDetail.IsVoid &&
                            (((receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                            || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine)
                            && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                           || (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution
                                && transType != CodeMaster.TransactionType.RCT_TR)  //差异调整至发货方,不用产生结算
                           || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract))
                        {
                            if (receiptDetailInput.IsConsignment && receiptDetailInput.PlanBill.HasValue)
                            {
                                throw new TechnicalException("Can't create new planbill when receiptDetailInput aready has unsettled planbill.");
                            }

                            #region 记录待结算
                            PlanBill planBill = this.billMgr.CreatePlanBill(receiptDetail, receiptDetailInput, effectiveDate);

                            inventoryIO.IsConsignment = true;
                            inventoryIO.IsCreatePlanBill = true;
                            inventoryIO.PlanBill = planBill.Id;
                            inventoryIO.CurrentPlanBill = planBill;

                            receiptDetailInput.IsConsignment = true;
                            receiptDetailInput.IsCreatePlanBill = true;
                            receiptDetailInput.PlanBill = planBill.Id;
                            #endregion

                            #region 判断是否立即结算
                            //if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract)   //委外加工立即结算
                            //{
                            //    isBillSettle = true;
                            //}
                            //else if (receiptDetail.ReceivedQty < 0)  // 判断寄售负库存是否立即结算
                            //{
                            //    isBillSettle = true;
                            //}
                            //else if (string.IsNullOrWhiteSpace(receiptDetail.LocationTo) == null
                            //    && receiptDetail.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.ReceivingSettlement) //判断目的库位为空的立即结算,如销售收货结算
                            //{
                            //    isBillSettle = true;
                            //}

                            //if (isBillSettle)
                            //{
                            //    //结算
                            //    planBill.CurrentActingQty = planBill.PlanQty;
                            //    BillTransaction billTransaction = this.billMgr.SettleBill(planBill, effectiveDate);
                            //    inventoryIO.IsConsignment = false;
                            //    receiptDetailInput.IsConsignment = false;
                            //}
                            #endregion
                        }
                        #endregion

                        IList<InventoryTransaction> currentInventoryTransactionList = RecordInventory(inventoryIO);
                        #region 记录WMS发货单行号
                        foreach (InventoryTransaction currentInventoryTransaction in currentInventoryTransactionList)
                        {
                            currentInventoryTransaction.WMSRecSeq = receiptDetailInput.WMSRecSeq;
                        }
                        #endregion
                        RecordLocationTransaction(receiptDetail, receiptDetailInput, effectiveDate, transType.Value, currentInventoryTransactionList);
                        inventoryTransactionList.AddRange(currentInventoryTransactionList);
                        #endregion
                    }
                }

                return inventoryTransactionList;
            }
            else if ((receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                    || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine
                    || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract)
                  && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
            {
                #region 采购退货收货
                if (!receiptDetail.IsVoid)
                {
                    foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                    {
                        foreach (IpLocationDetail receivedIpLocationDetail in receiptDetailInput.ReceivedIpLocationDetailList)
                        {
                            InventoryTransaction inventoryTransaction = new InventoryTransaction();
                            inventoryTransaction.Item = receiptDetail.Item;
                            inventoryTransaction.HuId = receiptDetailInput.HuId;
                            inventoryTransaction.LotNo = receiptDetailInput.LotNo;
                            inventoryTransaction.IsConsignment = receivedIpLocationDetail.IsConsignment;
                            //inventoryTransaction.IsCreatePlanBill = receiptDetailInput.IsCreatePlanBill;
                            inventoryTransaction.PlanBill = receivedIpLocationDetail.PlanBill;
                            if (receivedIpLocationDetail.IsConsignment && receivedIpLocationDetail.PlanBill.HasValue)
                            {
                                inventoryTransaction.PlanBillQty = receivedIpLocationDetail.ReceivedQty;  //转换为库存单位
                            }
                            //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                            //inventoryTransaction.ActingBillQty = ;
                            inventoryTransaction.Qty = receivedIpLocationDetail.ReceivedQty;  //转换为库存单位,入库位正数
                            inventoryTransaction.QualityType = receiptDetailInput.QualityType;
                            inventoryTransaction.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                            inventoryTransaction.IsFreeze = false;
                            inventoryTransaction.OccupyType = receiptDetailInput.OccupyType;
                            inventoryTransaction.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;

                            #region 退货收货
                            if (receivedIpLocationDetail.IsConsignment && receivedIpLocationDetail.PlanBill.HasValue)
                            {
                                //如果寄售库存,冲销PlanBill。
                                PlanBill planBill = this.genericMgr.FindById<PlanBill>(receivedIpLocationDetail.PlanBill.Value);
                                planBill.CurrentVoidQty = receivedIpLocationDetail.ReceivedQty / receiptDetail.UnitQty;  //订单单位
                                this.billMgr.VoidPlanBill(planBill);

                                //inventoryTransaction.IsConsignment = false;
                                //inventoryTransaction.PlanBill = null;
                            }
                            else
                            {
                                //非寄售库存产生负数PlanBill,立即结算。
                                ReceiptDetailInput thisReceiptDetailInput = Mapper.Map<ReceiptDetailInput, ReceiptDetailInput>(receiptDetailInput);
                                thisReceiptDetailInput.ReceiveQty = receivedIpLocationDetail.ReceivedQty / receiptDetail.UnitQty;   //订单单位

                                PlanBill planBill = this.billMgr.CreatePlanBill(receiptDetail, thisReceiptDetailInput, effectiveDate);
                                planBill.CurrentActingQty = planBill.PlanQty;
                                planBill.CurrentLocation = inventoryTransaction.Location;
                                SettleBillTransaction billTransaction = this.billMgr.SettleBill(planBill, effectiveDate);

                                inventoryTransaction.IsConsignment = false;
                                inventoryTransaction.IsCreatePlanBill = true;
                                inventoryTransaction.PlanBill = planBill.Id;
                                inventoryTransaction.PlanBillQty = 0;
                                inventoryTransaction.ActingBill = billTransaction.ActingBill;
                                inventoryTransaction.ActingBillQty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;
                            }
                            #endregion

                            inventoryTransactionList.Add(inventoryTransaction);
                        }
                    }
                }
                #endregion

                #region 采购退货收货冲销
                else
                {
                    #region 采购退货收货冲销
                    foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails)
                    {
                        InventoryTransaction inventoryTransaction = new InventoryTransaction();
                        inventoryTransaction.Item = receiptDetail.Item;
                        inventoryTransaction.HuId = receiptLocationDetail.HuId;
                        inventoryTransaction.LotNo = receiptLocationDetail.LotNo;
                        inventoryTransaction.IsConsignment = receiptLocationDetail.IsConsignment;
                        //inventoryTransaction.IsCreatePlanBill = receiptDetailInput.IsCreatePlanBill;
                        inventoryTransaction.PlanBill = receiptLocationDetail.PlanBill;
                        if (receiptLocationDetail.IsConsignment && receiptLocationDetail.PlanBill.HasValue)
                        {
                            inventoryTransaction.PlanBillQty = receiptLocationDetail.Qty;  //转换为库存单位
                        }
                        //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                        //inventoryTransaction.ActingBillQty = ;
                        inventoryTransaction.Qty = receiptLocationDetail.Qty;  //转换为库存单位,入库位正数
                        inventoryTransaction.QualityType = receiptLocationDetail.QualityType;
                        inventoryTransaction.IsATP = receiptLocationDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                        inventoryTransaction.IsFreeze = false;
                        inventoryTransaction.OccupyType = receiptLocationDetail.OccupyType;
                        inventoryTransaction.OccupyReferenceNo = receiptLocationDetail.OccupyReferenceNo;

                        if (receiptLocationDetail.IsConsignment && receiptLocationDetail.PlanBill.HasValue)
                        {
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(receiptLocationDetail.PlanBill);
                            planBill.CurrentVoidQty = -receiptLocationDetail.Qty / receiptDetail.UnitQty;  //退货收货冲销,要反冲销PlanQty。转为订单单位
                            this.billMgr.VoidPlanBill(planBill);
                        }

                        if (receiptLocationDetail.ActingBill.HasValue)
                        {
                            ActingBill actingBill = this.genericMgr.FindById<ActingBill>(receiptLocationDetail.ActingBill);
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(receiptLocationDetail.PlanBill);
                            actingBill.CurrentVoidQty = -receiptLocationDetail.Qty / receiptDetail.UnitQty;   //转为订单单位
                            this.billMgr.VoidSettleBill(actingBill, planBill, receiptLocationDetail.IsCreatePlanBill);
                        }

                        inventoryTransactionList.Add(inventoryTransaction);
                    }
                    #endregion
                }
                #endregion

                return inventoryTransactionList;
            }
            else if ((receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                        || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine
                        || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract)
                    && receiptDetail.IpDetailType == CodeMaster.IpDetailType.Gap
                    && receiptDetail.IpGapAdjustOption == CodeMaster.IpGapAdjustOption.GI)
            {
                #region 差异收货调整至供应商
                foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                {
                    InventoryTransaction inventoryTransaction = new InventoryTransaction();
                    inventoryTransaction.Item = receiptDetail.Item;
                    inventoryTransaction.HuId = receiptDetailInput.HuId;
                    inventoryTransaction.LotNo = receiptDetailInput.LotNo;
                    inventoryTransaction.IsConsignment = false;
                    inventoryTransaction.IsCreatePlanBill = false;
                    //inventoryTransaction.PlanBill = receiptDetailInput.PlanBill;
                    //inventoryTransaction.PlanBillQty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位
                    //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                    //inventoryTransaction.ActingBillQty = ;
                    inventoryTransaction.Qty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位,入库位正数
                    inventoryTransaction.QualityType = receiptDetailInput.QualityType;
                    inventoryTransaction.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryTransaction.IsFreeze = false;
                    //inventoryTransaction.OccupyType = receiptDetailInput.OccupyType;
                    //inventoryTransaction.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;

                    inventoryTransactionList.Add(inventoryTransaction);
                }
                #endregion
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Production
                && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
            {
                #region 原材料回用
                foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                {
                    InventoryTransaction inventoryTransaction = new InventoryTransaction();
                    inventoryTransaction.Item = receiptDetail.Item;
                    inventoryTransaction.HuId = receiptDetailInput.HuId;
                    inventoryTransaction.LotNo = receiptDetailInput.LotNo;
                    inventoryTransaction.IsConsignment = false;
                    inventoryTransaction.IsCreatePlanBill = false;
                    //inventoryTransaction.PlanBill = receiptDetailInput.PlanBill;
                    //inventoryTransaction.PlanBillQty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位
                    //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                    //inventoryTransaction.ActingBillQty = ;
                    inventoryTransaction.Qty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位,入库位正数
                    inventoryTransaction.QualityType = receiptDetailInput.QualityType;
                    inventoryTransaction.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryTransaction.IsFreeze = false;
                    //inventoryTransaction.OccupyType = receiptDetailInput.OccupyType;
                    //inventoryTransaction.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;

                    inventoryTransactionList.Add(inventoryTransaction);
                }
                #endregion
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution
                  && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
            {
                #region 销售收货
                foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                {
                    InventoryTransaction inventoryTransaction = new InventoryTransaction();
                    inventoryTransaction.Item = receiptDetail.Item;
                    inventoryTransaction.HuId = receiptDetailInput.HuId;
                    inventoryTransaction.LotNo = receiptDetailInput.LotNo;
                    //inventoryTransaction.IsConsignment = receiptDetailInput.IsConsignment;
                    //inventoryTransaction.IsCreatePlanBill = receiptDetailInput.IsCreatePlanBill;
                    //inventoryTransaction.PlanBill = receiptDetailInput.PlanBill;
                    //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                    inventoryTransaction.Qty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位,入库位正数
                    inventoryTransaction.QualityType = receiptDetailInput.QualityType;
                    inventoryTransaction.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryTransaction.IsFreeze = false;
                    inventoryTransaction.OccupyType = receiptDetailInput.OccupyType;
                    inventoryTransaction.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;

                    if (!receiptDetail.IsVoid)
                    {
                        #region 收货
                        PlanBill planBill = this.billMgr.CreatePlanBill(receiptDetail, receiptDetailInput, effectiveDate);
                        inventoryTransaction.IsConsignment = true;
                        inventoryTransaction.IsCreatePlanBill = true;
                        inventoryTransaction.PlanBill = planBill.Id;

                        if (receiptDetail.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.ReceivingSettlement)
                        {
                            planBill.CurrentActingQty = planBill.PlanQty;
                            planBill.CurrentLocation = planBill.LocationFrom;
                            SettleBillTransaction billTransaction = this.billMgr.SettleBill(planBill, effectiveDate);

                            inventoryTransaction.IsConsignment = false;
                            inventoryTransaction.PlanBillQty = 0;
                            inventoryTransaction.ActingBill = billTransaction.ActingBill;
                            inventoryTransaction.ActingBillQty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;
                        }
                        #endregion
                    }
                    else
                    {
                        #region 收货冲销
                        if (receiptDetailInput.ActingBill.HasValue)
                        {
                            ActingBill actingBill = this.genericMgr.FindById<ActingBill>(receiptDetailInput.ActingBill);
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(receiptDetailInput.PlanBill);
                            actingBill.CurrentVoidQty = -receiptDetailInput.ReceiveQty;
                            this.billMgr.VoidSettleBill(actingBill, planBill, receiptDetailInput.IsCreatePlanBill);
                        }
                        else if (receiptDetailInput.IsCreatePlanBill)
                        {
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(receiptDetailInput.PlanBill);
                            planBill.CurrentVoidQty = -receiptDetailInput.ReceiveQty;
                            this.billMgr.VoidPlanBill(planBill);
                        }
                        #endregion
                    }

                    inventoryTransactionList.Add(inventoryTransaction);
                }
                #endregion
            }
            else
            {
                throw new TechnicalException("未知情况,需要跟踪。");
            }

            return inventoryTransactionList;
        }
コード例 #24
0
        public IList<InventoryTransaction> InventoryUnPack(IList<InventoryUnPack> inventoryUnPackList, DateTime effectiveDate)
        {
            IList<HuStatus> huStatusList = this.huMgr.GetHuStatus(inventoryUnPackList.Select(i => i.HuId).ToList());

            #region 检验
            BusinessException businessException = new BusinessException();
            foreach (InventoryUnPack inventoryUnPack in inventoryUnPackList)
            {
                HuStatus huStatus = huStatusList.Where(h => h.HuId == inventoryUnPack.HuId).SingleOrDefault();

                if (huStatus == null)
                {
                    businessException.AddMessage("条码{0}不存在。", huStatus.HuId);
                }

                if (huStatus.Status == CodeMaster.HuStatus.Ip)
                {
                    businessException.AddMessage("条码{0}为库位{1}至库位{2}的在途库存,不能拆箱。", huStatus.HuId, huStatus.LocationFrom, huStatus.LocationTo);
                }

                if (huStatus.Status == CodeMaster.HuStatus.NA)
                {
                    businessException.AddMessage("条码{0}已经不在任何库位中,不能拆箱。", huStatus.HuId);
                }

                if (huStatus.IsConsignment == true)
                {
                    int userId = SecurityContextHolder.Get().Id;
                    bool hasPermission = genericMgr.FindAll<UserPermissionView>(" from UserPermissionView as u where u.UserId=? and u.PermissionCode='Client_UnPackAllowCs' ", new object[] { userId }).Count == 0;
                    if (hasPermission)
                    {
                        businessException.AddMessage("寄售的条码{0}不能拆箱。", huStatus.HuId);
                    }
                }
                inventoryUnPack.CurrentHu = huStatus;
            }

            if (businessException.HasMessage)
            {
                throw businessException;
            }
            #endregion

            #region 循环拆箱
            IList<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();
            foreach (InventoryUnPack inventoryUnPack in inventoryUnPackList)
            {
                #region 出库
                InventoryIO inventoryOut = new InventoryIO();

                inventoryOut.Location = inventoryUnPack.CurrentHu.Location;
                inventoryOut.Item = inventoryUnPack.CurrentHu.Item;
                inventoryOut.HuId = inventoryUnPack.CurrentHu.HuId;
                inventoryOut.Qty = -inventoryUnPack.CurrentHu.Qty * inventoryUnPack.CurrentHu.UnitQty;  //转换为库存单位
                inventoryOut.LotNo = inventoryUnPack.CurrentHu.LotNo;
                inventoryOut.QualityType = inventoryUnPack.CurrentHu.QualityType;
                inventoryOut.IsATP = inventoryUnPack.CurrentHu.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                inventoryOut.IsFreeze = inventoryUnPack.CurrentHu.IsFreeze;
                inventoryOut.IsCreatePlanBill = false;
                inventoryOut.IsConsignment = inventoryUnPack.CurrentHu.IsConsignment;
                inventoryOut.PlanBill = inventoryUnPack.CurrentHu.PlanBill;
                inventoryOut.ActingBill = null;
                inventoryOut.TransactionType = CodeMaster.TransactionType.ISS_REP;
                inventoryOut.OccupyType = inventoryUnPack.CurrentHu.OccupyType;
                inventoryOut.OccupyReferenceNo = inventoryUnPack.CurrentHu.OccupyReferenceNo;
                inventoryOut.IsVoid = false;
                inventoryOut.EffectiveDate = effectiveDate;
                //inventoryIO.ManufactureParty = ;

                IList<InventoryTransaction> issInventoryTransactionList = RecordInventory(inventoryOut);
                ((List<InventoryTransaction>)inventoryTransactionList).AddRange(issInventoryTransactionList);
                RecordLocationTransaction(inventoryUnPack, effectiveDate, issInventoryTransactionList, true);
                #endregion

                #region 入库
                InventoryIO inventoryIn = new InventoryIO();

                inventoryIn.Location = inventoryUnPack.CurrentHu.Location;
                inventoryIn.Item = inventoryUnPack.CurrentHu.Item;
                inventoryIn.HuId = null;
                inventoryIn.LotNo = null;
                inventoryIn.Qty = inventoryUnPack.CurrentHu.Qty * inventoryUnPack.CurrentHu.UnitQty;  //转换为库存单位
                inventoryIn.QualityType = inventoryUnPack.CurrentHu.QualityType;
                inventoryIn.IsATP = inventoryUnPack.CurrentHu.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                inventoryIn.IsFreeze = inventoryUnPack.CurrentHu.IsFreeze;
                inventoryIn.IsCreatePlanBill = false;
                inventoryIn.IsConsignment = inventoryUnPack.CurrentHu.IsConsignment;
                inventoryIn.PlanBill = inventoryUnPack.CurrentHu.PlanBill;
                inventoryIn.ActingBill = null;
                inventoryIn.TransactionType = CodeMaster.TransactionType.RCT_REP;
                inventoryIn.OccupyType = inventoryUnPack.CurrentHu.OccupyType;
                inventoryIn.OccupyReferenceNo = inventoryUnPack.CurrentHu.OccupyReferenceNo;
                inventoryIn.IsVoid = false;
                inventoryIn.EffectiveDate = effectiveDate;
                //inventoryIO.ManufactureParty = ;

                IList<InventoryTransaction> rctInventoryTransactionList = RecordInventory(inventoryIn);
                RecordLocationTransaction(inventoryUnPack, effectiveDate, rctInventoryTransactionList, false);
                ((List<InventoryTransaction>)inventoryTransactionList).AddRange(issInventoryTransactionList);
                #endregion
            }

            return inventoryTransactionList;
            #endregion
        }
コード例 #25
0
        private SettleBillTransaction VoidBill(InventoryIO inventoryIO)
        {
            #region 处理冲销寄售和结算

            //只有收货单冲销才会发生冲销寄售和结算问题,也就是只有RCT事务才有,ISS没有。
            if (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_PO_VOID  //采购收货冲销
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_SL_VOID  //计划协议收货冲销
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_SO_VOID //销售收货冲销
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_TR_VOID //移库收货冲销
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_TR_RTN_VOID //移库退货收货冲销
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_STR_VOID //委外移库收货冲销
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_STR_RTN_VOID //委外移库退货收货冲销
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_UNP_VOID   //计划外出库冲销
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_UNP_VOID  //计划外入库冲销   //入的都是非寄售物品,不存在冲销的问题 //现在支持入库寄售库存
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_WO_VOID  //生产收货冲销
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.CYC_CNT_VOID //盘盈冲销出库,出负数;盘亏冲销入库,入正数          
                //inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_PO_VOID //采购退货冲销入库 //因为采购退货
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SO_VOID  //销售冲销入库
                //|| inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_TR_VOID  //移库冲销入库
                //|| inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_TR_RTN_VOID //移库退货冲销入库
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_WO_BF_VOID   //投料冲销入库             //下线结算的东西要冲销回来
                || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_WO_VOID      //生产投料冲销入库
                )
            {
                SettleBillTransaction billTransaction = null;
                if (inventoryIO.ActingBill.HasValue)
                {
                    ActingBill actingBill = TryLoadActingBill(inventoryIO);
                    PlanBill planbill = inventoryIO.PlanBill.HasValue ? TryLoadPlanBill(inventoryIO) : null;
                    if (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SO_VOID)
                    {
                        actingBill.CurrentVoidQty = inventoryIO.Qty / actingBill.UnitQty;
                    }
                    else
                    {
                        actingBill.CurrentVoidQty = -inventoryIO.Qty / actingBill.UnitQty;   //转为订单单位
                    }
                    inventoryIO.CurrentPlanBill.CurrentLocation = inventoryIO.Location;
                    billTransaction = this.billMgr.VoidSettleBill(actingBill, planbill, inventoryIO.IsCreatePlanBill);
                    //inventoryIO.ActingBill = null;

                    if (inventoryIO.IsCreatePlanBill)
                    {
                        inventoryIO.PlanBill = null;
                        inventoryIO.IsConsignment = false;
                        inventoryIO.IsCreatePlanBill = false;
                    }
                }
                else if (inventoryIO.IsCreatePlanBill)
                {
                    PlanBill planBill = TryLoadPlanBill(inventoryIO);
                    planBill.CurrentVoidQty = -inventoryIO.Qty / planBill.UnitQty;   //转为订单单位
                    this.billMgr.VoidPlanBill(planBill);
                    inventoryIO.PlanBill = null;
                    inventoryIO.IsConsignment = false;
                    inventoryIO.IsCreatePlanBill = false;
                }

                return billTransaction;
            }

            return null;
            #endregion
        }
コード例 #26
0
        public IList<InventoryTransaction> StockTakeAdjust(StockTakeMaster stockTakeMaster, IList<StockTakeResult> stockTakeResultList, DateTime effectiveDate)
        {
            List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();

            if (stockTakeResultList != null && stockTakeResultList.Count > 0)
            {
                foreach (StockTakeResult stockTakeResult in stockTakeResultList)
                {
                    if (stockTakeResult.DifferenceQty == 0)
                    {
                        continue;
                    }
                    if (stockTakeResult.QualityType == CodeMaster.QualityType.Inspect
                        || stockTakeResult.QualityType == CodeMaster.QualityType.Reject)
                    {
                        //待验的库存不能调整。
                        throw new TechnicalException("Can't adjust inspect/reject inventory.");
                    }
                    InventoryIO inventoryIO = new InventoryIO();
                    inventoryIO.Location = stockTakeResult.Location;
                    inventoryIO.Bin = stockTakeResult.Bin;
                    inventoryIO.Item = stockTakeResult.Item;
                    inventoryIO.HuId = stockTakeResult.HuId;
                    inventoryIO.LotNo = stockTakeResult.LotNo;
                    inventoryIO.Qty = stockTakeResult.DifferenceQty;  //盘亏为负数,出库。盘盈为正数,入库。
                    inventoryIO.QualityType = stockTakeResult.QualityType;
                    inventoryIO.IsATP = stockTakeResult.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryIO.IsFreeze = false;
                    inventoryIO.IsCreatePlanBill = false;
                    inventoryIO.IsConsignment = false;
                    inventoryIO.PlanBill = null;
                    inventoryIO.ActingBill = null;
                    inventoryIO.TransactionType = CodeMaster.TransactionType.CYC_CNT;
                    inventoryIO.OccupyType = CodeMaster.OccupyType.None;
                    inventoryIO.OccupyReferenceNo = null;
                    inventoryIO.IsVoid = false;
                    inventoryIO.EffectiveDate = effectiveDate;
                    //inventoryIO.ManufactureParty = ;

                    IList<InventoryTransaction> currentInventoryTransactionList = RecordInventory(inventoryIO);
                    RecordLocationTransaction(stockTakeMaster, stockTakeResult, effectiveDate, currentInventoryTransactionList);
                    inventoryTransactionList.AddRange(currentInventoryTransactionList);
                }
            }

            return inventoryTransactionList;
        }
コード例 #27
0
        private PlanBill TryLoadPlanBill(InventoryIO inventoryIO)
        {
            if (inventoryIO.CurrentPlanBill == null)
            {
                inventoryIO.CurrentPlanBill = genericMgr.FindById<PlanBill>(inventoryIO.PlanBill);
            }

            return inventoryIO.CurrentPlanBill;
        }
コード例 #28
0
        public IList<InventoryTransaction> InventoryOtherInOut(MiscOrderMaster miscOrderMaster, MiscOrderDetail miscOrderDetail, DateTime effectiveDate)
        {
            List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();

            #region 出库
            if (miscOrderMaster.IsScanHu)
            {
                #region 条码
                foreach (MiscOrderLocationDetail miscOrderLocationDetail in miscOrderDetail.MiscOrderLocationDetails)
                {
                    if (miscOrderMaster.Type == CodeMaster.MiscOrderType.GR && miscOrderMaster.IsCs
                        && !string.IsNullOrWhiteSpace(miscOrderDetail.ManufactureParty))
                    {
                        PlanBill planBill = this.billMgr.CreatePlanBill(miscOrderMaster, miscOrderDetail, miscOrderLocationDetail, effectiveDate);

                        miscOrderLocationDetail.IsCreatePlanBill = true;
                        miscOrderLocationDetail.IsConsignment = true;
                        miscOrderLocationDetail.PlanBill = planBill.Id;
                    }

                    InventoryIO inventoryIO = new InventoryIO();

                    inventoryIO.Location = !string.IsNullOrWhiteSpace(miscOrderDetail.Location) ? miscOrderDetail.Location : miscOrderMaster.Location;
                    inventoryIO.Item = miscOrderLocationDetail.Item;
                    inventoryIO.HuId = miscOrderLocationDetail.HuId;
                    inventoryIO.Qty = miscOrderMaster.Type == CodeMaster.MiscOrderType.GI ? -miscOrderLocationDetail.Qty : miscOrderLocationDetail.Qty; //出库为负数
                    inventoryIO.LotNo = miscOrderLocationDetail.LotNo;
                    inventoryIO.QualityType = miscOrderLocationDetail.QualityType;
                    inventoryIO.IsATP = miscOrderLocationDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryIO.IsFreeze = miscOrderLocationDetail.IsFreeze;
                    inventoryIO.IsCreatePlanBill = miscOrderLocationDetail.IsCreatePlanBill;
                    inventoryIO.IsConsignment = miscOrderLocationDetail.IsConsignment;
                    inventoryIO.PlanBill = miscOrderLocationDetail.PlanBill;
                    inventoryIO.ActingBill = miscOrderLocationDetail.ActingBill;
                    inventoryIO.TransactionType = miscOrderMaster.Type == CodeMaster.MiscOrderType.GI ? CodeMaster.TransactionType.ISS_UNP : CodeMaster.TransactionType.RCT_UNP;
                    inventoryIO.OccupyType = miscOrderLocationDetail.OccupyType;
                    inventoryIO.OccupyReferenceNo = miscOrderLocationDetail.OccupyReferenceNo;
                    inventoryIO.IsVoid = false;
                    inventoryIO.EffectiveDate = effectiveDate;
                    //inventoryIO.ManufactureParty = ;

                    IList<InventoryTransaction> currentInventoryTransactionList = RecordInventory(inventoryIO);
                    RecordLocationTransaction(miscOrderMaster, miscOrderDetail, effectiveDate, currentInventoryTransactionList, false);
                    inventoryTransactionList.AddRange(currentInventoryTransactionList);
                }
                #endregion
            }
            else
            {
                #region 数量
                PlanBill planBill = null;
                if (miscOrderMaster.Type == CodeMaster.MiscOrderType.GR
                       && !string.IsNullOrWhiteSpace(miscOrderDetail.ManufactureParty))
                {
                    planBill = this.billMgr.CreatePlanBill(miscOrderMaster, miscOrderDetail, null, effectiveDate);
                }

                InventoryIO inventoryIO = new InventoryIO();

                inventoryIO.Location = !string.IsNullOrWhiteSpace(miscOrderDetail.Location) ? miscOrderDetail.Location : miscOrderMaster.Location;
                inventoryIO.Item = miscOrderDetail.Item;
                //inventoryIO.HuId = miscOrderDetail.HuId;
                inventoryIO.Qty = (miscOrderMaster.Type == CodeMaster.MiscOrderType.GI ? -miscOrderDetail.Qty : miscOrderDetail.Qty) * miscOrderDetail.UnitQty; //出库为负数,同时转为库存单位
                //inventoryIO.LotNo = miscOrderLocationDetail.LotNo;
                inventoryIO.QualityType = miscOrderMaster.QualityType;
                inventoryIO.IsATP = miscOrderMaster.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                inventoryIO.IsFreeze = false;
                inventoryIO.IsCreatePlanBill = planBill != null;
                inventoryIO.IsConsignment = planBill != null;
                inventoryIO.PlanBill = planBill != null ? (int?)planBill.Id : null;
                //inventoryIO.ActingBill = miscOrderLocationDetail.ActingBill;
                inventoryIO.TransactionType = miscOrderMaster.Type == CodeMaster.MiscOrderType.GI ? CodeMaster.TransactionType.ISS_UNP : CodeMaster.TransactionType.RCT_UNP;
                //inventoryIO.OccupyType = miscOrderLocationDetail.OccupyType;
                //inventoryIO.OccupyReferenceNo = miscOrderLocationDetail.OccupyReferenceNo;
                inventoryIO.IsVoid = false;
                inventoryIO.EffectiveDate = effectiveDate;
                inventoryIO.ManufactureParty = miscOrderDetail.ManufactureParty;

                IList<InventoryTransaction> currentInventoryTransactionList = RecordInventory(inventoryIO);
                RecordLocationTransaction(miscOrderMaster, miscOrderDetail, effectiveDate, currentInventoryTransactionList, false);
                inventoryTransactionList.AddRange(currentInventoryTransactionList);
                #endregion
            }
            #endregion
            return inventoryTransactionList;
        }
コード例 #29
0
        private Item TryLoadItem(InventoryIO inventoryIO)
        {
            if (inventoryIO.CurrentItem == null)
            {
                inventoryIO.CurrentItem = genericMgr.FindById<Item>(inventoryIO.Item);
            }

            return inventoryIO.CurrentItem;
        }
コード例 #30
0
        public IList<InventoryTransaction> CancelInventoryOtherInOut(MiscOrderMaster miscOrderMaster, DateTime effectiveDate)
        {
            List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();

            foreach (MiscOrderDetail miscOrderDetail in miscOrderMaster.MiscOrderDetails)
            {
                List<InventoryTransaction> detailInventoryTransactionList = new List<InventoryTransaction>();

                foreach (MiscOrderLocationDetail miscOrderLocationDetail in miscOrderDetail.MiscOrderLocationDetails)
                {
                    //PlanBill planBill = null;
                    InventoryIO inventoryIO = new InventoryIO();

                    inventoryIO.Location = !string.IsNullOrWhiteSpace(miscOrderDetail.Location) ? miscOrderDetail.Location : miscOrderMaster.Location;
                    inventoryIO.Item = miscOrderLocationDetail.Item;
                    inventoryIO.Qty = -miscOrderLocationDetail.Qty;
                    inventoryIO.HuId = miscOrderLocationDetail.HuId;
                    inventoryIO.LotNo = miscOrderLocationDetail.LotNo;
                    inventoryIO.QualityType = miscOrderLocationDetail.QualityType;
                    inventoryIO.IsATP = miscOrderLocationDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryIO.IsFreeze = miscOrderLocationDetail.IsFreeze;
                    inventoryIO.IsCreatePlanBill = miscOrderLocationDetail.IsCreatePlanBill;
                    inventoryIO.IsConsignment = miscOrderLocationDetail.IsConsignment;
                    //inventoryIO.IsConsignment = miscOrderLocationDetail.ActingBill.HasValue ? true : false; //解决寄售物资计划外出库冲销记录库存丢失寄售信息
                    inventoryIO.PlanBill = miscOrderLocationDetail.PlanBill;
                    inventoryIO.ActingBill = miscOrderLocationDetail.ActingBill;
                    inventoryIO.TransactionType = miscOrderMaster.MoveType == "992" ? CodeMaster.TransactionType.LOC_INI_VOID : (miscOrderMaster.Type == CodeMaster.MiscOrderType.GI ? CodeMaster.TransactionType.ISS_UNP_VOID : CodeMaster.TransactionType.RCT_UNP_VOID);
                    inventoryIO.OccupyType = miscOrderLocationDetail.OccupyType;
                    inventoryIO.OccupyReferenceNo = miscOrderLocationDetail.OccupyReferenceNo;
                    inventoryIO.IsVoid = true;
                    inventoryIO.EffectiveDate = effectiveDate;
                    inventoryIO.ConsignmentSupplier = miscOrderLocationDetail.ConsignmentSupplier;

                    if (inventoryIO.TransactionType == CodeMaster.TransactionType.ISS_UNP_VOID
                        && miscOrderLocationDetail.IsConsignment && miscOrderLocationDetail.PlanBill.HasValue)
                    {
                        PlanBill planBill = this.genericMgr.FindById<PlanBill>(miscOrderLocationDetail.PlanBill.Value);
                        planBill.CurrentCancelVoidQty = -miscOrderLocationDetail.Qty / planBill.UnitQty;
                        this.billMgr.CancelVoidPlanBill(planBill);
                    }

                    IList<InventoryTransaction> locationDetailInventoryTransactionList = RecordInventory(inventoryIO);
                    if (miscOrderMaster.IsScanHu)
                    {
                        RecordLocationTransaction(miscOrderMaster, miscOrderDetail, effectiveDate, locationDetailInventoryTransactionList, true);
                    }
                    detailInventoryTransactionList.AddRange(locationDetailInventoryTransactionList);
                }

                if (!miscOrderMaster.IsScanHu)
                {
                    RecordLocationTransaction(miscOrderMaster, miscOrderDetail, effectiveDate, detailInventoryTransactionList, true);
                }
                inventoryTransactionList.AddRange(detailInventoryTransactionList);
            }

            return inventoryTransactionList;
        }