Exemplo n.º 1
0
        IList <IWHTransLine> IWHTransHead.GetLines(ISession session)
        {
            IList <ReturnLine> lines = session.CreateEntityQuery <ReturnLine>()
                                       .Where(Exp.Eq("OrderNumber", this.OrderNumber))
                                       .OrderBy("SKUID").OrderBy("RefOrderLineID")
                                       .List <ReturnLine>();

            this._lines = lines;
            IList <IWHTransLine> whLines = new List <IWHTransLine>(lines.Count);

            foreach (ReturnLine line in lines)
            {
                if (this.OrderTypeCode != ReturnHead.ORDER_TYPE_EXCHANGE_RTN)
                {
                    line.LocationCode = this.LocationCode;
                }
                else
                {
                    WHArea area = WHArea.Retrieve(session, line.AreaCode);
                    line.LocationCode = area.LocationCode;
                }
                whLines.Add(line);
            }
            return(whLines);
        }
Exemplo n.º 2
0
        private static WHTransLine BuildTransLine(ISession session, TransItemWrapper wrapper, IWHTransHead transHead, int commitDate, int commitTime, ref int lineNumber, OrderTransDef orderTransDef)
        {
            WHArea area = null;

            WHTransLine line = new WHTransLine();

            line.LineNumber          = lineNumber++;
            line.SKUID               = wrapper.SKUID;
            line.TransDate           = commitDate;
            line.TransTime           = commitTime;
            line.UnitID              = wrapper.UnitID;
            line.CurrencyCode        = wrapper.CurrencyCode;
            line.RefOrderType        = transHead.OrderTypeCode;
            line.RefOrderNumber      = transHead.OrderNumber;
            line.RefOrderLine        = wrapper.LineNumber;
            line.OriginalOrderType   = transHead.OriginalOrderType;
            line.OriginalOrderNumber = transHead.OrginalOrderNumber;
            line.OriginalOrderLine   = wrapper.OriginalOrderLine;
            line.TaxValue            = wrapper.TaxValue;
            line.StockDetailID       = wrapper.StockDetailID;
            ItemSpec itemSpec = ItemSpec.Retrieve(session, line.SKUID);

            line.AvgMoveCost = itemSpec.AvgMoveCost;

            //TODO: 目前只支持的配置实现方式有限

            //交易类型
            if (orderTransDef.StepType == TransStepType.Single)
            {
                if (orderTransDef.TransTypeFrom == TransTypeFrom.ConfigValue)
                {
                    line.TransTypeCode = orderTransDef.TransTypeCode;
                }
                else if (orderTransDef.TransTypeFrom == TransTypeFrom.InterfaceValue)
                {
                    line.TransTypeCode = wrapper.TransTypeCode;
                }
                else
                {
                    throw new Exception(string.Format("WHTransaction: TransTypeFrom {0} not supported", (int)orderTransDef.TransTypeFrom));
                }
            }
            else if (orderTransDef.StepType == TransStepType.MultiSelect)
            {
                if (orderTransDef.TransTypeFrom == TransTypeFrom.InterfaceValue)
                {
                    line.TransTypeCode = wrapper.TransTypeCode;
                }
                else
                {
                    throw new Exception(string.Format("WHTransaction: TransTypeFrom {0} not supported by TransStepType.MultiSelect", (int)orderTransDef.TransTypeFrom));
                }
            }
            //交易数量
            if (orderTransDef.TransQtyFrom == TransQtyFrom.QualifiedQty)
            {
                line.TransQty = wrapper.QualifiedQty;
            }
            else if (orderTransDef.TransQtyFrom == TransQtyFrom.UnQualifiedQty)
            {
                line.TransQty = wrapper.UnQualifiedQty;
            }
            else
            {
                throw new Exception(string.Format("WHTransaction: TransQtyFrom {0} not supported", (int)orderTransDef.TransQtyFrom));
            }
            //交易仓库信息。LocationCode, AreaCode必须有,SectionCode可以有可以没有
            if (orderTransDef.TransLocationFrom == TransLocationFrom.ConfigValue)
            {
                //从(交易-仓库配置)中取库房区域、货架信息
                //不会从(产品-默认存储位置)读取,因为出入库单据如果用到(产品-默认存储位置),需要在界面提供选择,因此仓库获取类型变为TransLocationFrom.InterfaceValue
                IList <WHAreaCfg> areaCfg = WHAreaCfg.Retrieve(session, line.TransTypeCode);
                if (areaCfg == null || areaCfg.Count <= 0)
                {
                    throw new Exception(string.Format("WHTransaction: area cfg does not exists for transaction type {0}", line.TransTypeCode));
                }
                area = WHArea.Retrieve(session, areaCfg[0].AreaCode);
                if (area == null)
                {
                    throw new Exception(string.Format("WHTransaction: area {0} does not exist", areaCfg[0].AreaCode));
                }
                line.LocationCode = area.LocationCode;
                line.AreaCode     = area.AreaCode;
            }
            else if (orderTransDef.TransLocationFrom == TransLocationFrom.InterfaceValue)
            {
                if (string.IsNullOrEmpty(wrapper.LocationCode) || wrapper.LocationCode.Trim().Length <= 0 ||
                    string.IsNullOrEmpty(wrapper.AreaCode) || wrapper.AreaCode.Trim().Length <= 0)
                {
                    throw new Exception(string.Format("WHTransaction: LocationCode or AreaCode is empty in transaction order line {0}", wrapper.LineNumber));
                }
                line.LocationCode = wrapper.LocationCode;
                line.AreaCode     = wrapper.AreaCode;
                line.SectionCode  = wrapper.SectionCode;
            }
            else
            {
                throw new Exception(string.Format("WHTransaction: TransLocationFrom {0} not supported", (int)orderTransDef.TransLocationFrom));
            }

            area = WHArea.Retrieve(session, line.AreaCode);
            if (area == null)
            {
                throw new Exception(string.Format("WHTransaction: invalidate AreaCode {0}", line.AreaCode));
            }
            //如果库位被锁定(例如正在进行盘点作业)则不允许交易
            if (area.IsLocked && orderTransDef.TransTypeCode != "301") //盘点的交易类型为301
            {
                throw new Exception("库位" + area.AreaCode + "-" + area.Name + "正在盘点,无法执行出入库操作");
            }
            line.IsScrap     = area.IsScrap;
            line.IsQC        = area.IsQC;
            line.IsNonFormal = area.IsNonFormal;

            TransTypeDef transTypeDef = TransTypeDef.Retrieve(session, orderTransDef.TransTypeCode);

            if (transTypeDef == null)
            {
                throw new Exception(string.Format("WHTransaction: invalidate transaction type code {0}", orderTransDef.TransTypeCode));
            }
            line.TransQty = line.TransQty * ((int)transTypeDef.TransProperty);
            //交易描述
            line.TransReason = transTypeDef.TransDefText;
            if (!string.IsNullOrEmpty(transTypeDef.TransDefDesc) && transTypeDef.TransDefDesc.Trim().Length > 0)
            {
                line.TransReason = line.TransReason + " - " + transTypeDef.TransDefDesc;
            }
            //交易价格
            if (transTypeDef.PriceSourceType == TransTypePriceSource.FromSourceOrder)
            {
                line.TransPrice = wrapper.Price;
            }
            else if (transTypeDef.PriceSourceType == TransTypePriceSource.FromMovAvgCost)
            {
                line.TransPrice = itemSpec.AvgMoveCost;
            }
            else if (transTypeDef.PriceSourceType == TransTypePriceSource.FromAreaCfg)
            {
                if (!area.UseFixCost || area.CostFixValue < 0M)
                {
                    throw new Exception(string.Format("WHTransaction: TransTypePriceSource is FromAreaCfg, but it does not exists in AreaCode {0}", area.AreaCode));
                }
                line.TransPrice = area.CostFixValue;
            }
            line.TransPrice = line.TransPrice * area.CostTransRate - area.FixedComsumeValue;
            if (line.TransPrice < 0M)
            {
                line.TransPrice = 0M;
            }

            //if ((line.TransTypeCode == "101" || line.TransTypeCode == "301") && itemSpec.EnableOS)
            //{
            //    itemSpec.EnableOS = false;
            //    itemSpec.Update(session, "EnableOS");
            //}

            log.DebugFormat("trans line built: trans type:{0}, qty={1}, area={2}, section={3}, price={4}", line.TransTypeCode, line.TransQty, line.AreaCode, line.SectionCode, line.TransPrice);
            return(line);
        }
Exemplo n.º 3
0
        public int UpdateLines(ISession session, IList <RCVLine> linesValue)
        {
            if (linesValue == null || linesValue.Count <= 0)
            {
                return(0);
            }

            #region 检查
            IList <RCVLine>           lines = new List <RCVLine>(linesValue.Count);
            bool                      error = false, errorHead = false;
            System.Text.StringBuilder builder    = new System.Text.StringBuilder();
            bool                      hasSection = false;
            foreach (RCVLine lv in linesValue)
            {
                errorHead = false;
                //收货数量是否有效
                if (lv.RCVTotalQty <= 0M)
                {
                    error = true;
                    if (!errorHead)
                    {
                        builder.Append("行号").Append(lv.LineNumber).Append(": ");
                    }
                    errorHead = true;
                    builder.Append("收货数量小于0; ");
                    continue;
                }
                RCVLine l = RCVLine.Retrieve(session, lv.OrderNumber, lv.LineNumber);
                //可以不填写货架,但如果填写了,则检查货架有效性
                WHSection section = null;
                hasSection = false;
                //库位、货架容量检查
                WHArea area = WHArea.Retrieve(session, l.AreaCode);
                if (!string.IsNullOrEmpty(l.SectionCode) && l.SectionCode.Trim().Length > 0)
                {
                    hasSection = true;
                    section    = WHSection.Retrieve(session, l.AreaCode, l.SectionCode);
                }
                decimal capacityFree = 0M;
                //取库位、货架容量
                if (hasSection)
                {
                    capacityFree = section.SectionCapacity;
                }
                else
                {
                    capacityFree = area.AreaCapacity;
                }
                //库位容量扣减当前已存放量
                if (hasSection)
                {
                    capacityFree = capacityFree - Cast.Decimal(session.CreateObjectQuery(@"
select sum(StockQty) from StockDetail 
where AreaCode=?area and SectionCode=?section")
                                                               .Attach(typeof(StockDetail))
                                                               .SetValue("?area", area.AreaCode, "AreaCode")
                                                               .SetValue("?section", section.SectionCode, "SectionCode")
                                                               .Scalar(), 0M);
                }
                else
                {
                    capacityFree = capacityFree - Cast.Decimal(session.CreateObjectQuery(@"select sum(StockQty) from StockDetail where AreaCode=?area")
                                                               .Attach(typeof(StockDetail))
                                                               .SetValue("?area", area.AreaCode, "AreaCode")
                                                               .Scalar(), 0M);
                }
                //剩余容量和本次入库量比较
                if (capacityFree < lv.QualifiedQty)
                {
                    builder.Append("行号").Append(lv.LineNumber).Append(": ");
                    error = true;
                    builder.Append("入库量").Append(lv.QualifiedQty).Append("大于剩余容量").Append(capacityFree);
                }
                if (!error)
                {
                    lines.Add(l);
                }
            }
            if (error)
            {
                throw new Exception(builder.ToString());
            }
            #endregion

            int       count     = 0;
            DbSession dbsession = session.DbSession as DbSession;
            session.BeginTransaction();
            for (int i = 0; i < lines.Count; i++)
            {
                RCVLine line   = lines[i];
                POLine  poLine = null;
                if (!string.IsNullOrEmpty(this._refOrderNumber) && this._refOrderNumber.Trim().Length > 0 &&
                    !string.IsNullOrEmpty(line.RefOrderLine) && line.RefOrderLine.Trim().Length > 0)
                {
                    poLine = POLine.Retrieve(session, this._refOrderNumber, line.RefOrderLine);
                }
                if (poLine != null)
                {
                    IDbCommand cmd = dbsession.CreateStoredProcCommand("F_PUR_RCV_TOLERANCE_RATIO", new object[] { 0, poLine.OrderNumber });
                    dbsession.ExecuteNonQuery(cmd);
                    IDbDataParameter p      = cmd.Parameters[0] as IDbDataParameter;
                    decimal          ration = Cast.Decimal(p.Value);
                    if (poLine.PurchaseQty * (1 + ration) - poLine.ReceiveQty - poLine.UnfinishedReceiveQty - linesValue[i].QualifiedQty + line.QualifiedQty < 0)
                    {
                        error = true;
                        builder.Append("行号").Append(line.LineNumber).Append("收货数量").Append(linesValue[i].QualifiedQty)
                        .Append("超过PO最大可收货数量").Append(Math.Floor(poLine.PurchaseQty * (1 + ration)) - poLine.ReceiveQty - poLine.UnfinishedReceiveQty + line.QualifiedQty);
                        break;
                    }
                    poLine.UnfinishedReceiveQtyChange(session, linesValue[i].QualifiedQty - line.QualifiedQty);
                }
                line.RCVTotalQty  = linesValue[i].RCVTotalQty;
                line.QualifiedQty = linesValue[i].QualifiedQty;
                line.Update(session, "RCVTotalQty", "QualifiedQty");

                count++;
            }
            if (error)
            {
                session.Rollback();
                throw new Exception(builder.ToString());
            }
            else
            {
                session.Commit();
            }

            return(count);
        }