Esempio n. 1
0
        private void CheckWHSettings(ISession session, IList <ReturnLine> toCheck)
        {
            StringBuilder errmsg = new StringBuilder();

            //检查
            foreach (ReturnLine line in toCheck)
            {
                if (string.IsNullOrEmpty(line.AreaCode) || line.AreaCode.Trim().Length <= 0)
                {
                    errmsg.Append("行").Append(line.LineNumber).Append("库位为空; ");
                    continue;
                }
                if (!string.IsNullOrEmpty(line.SectionCode) && line.SectionCode.Trim().Length > 0)
                {
                    WHSection section = WHSection.Retrieve(session, line.AreaCode, line.SectionCode);
                    if (section == null)
                    {
                        errmsg.Append("行").Append(line.LineNumber)
                        .Append("货架").Append(line.SectionCode).Append("(").Append(line.AreaCode).Append(")不存在; ");
                        continue;
                    }
                }
            }
            if (errmsg.Length > 0)
            {
                throw new Exception(errmsg.ToString());
            }
        }
Esempio n. 2
0
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName == "Save")
        {
            #region 保存
            using (ISession session = new Session())
            {
                IList <StockInLine>       linesToSave = new List <StockInLine>();
                System.Text.StringBuilder error       = new System.Text.StringBuilder();
                foreach (RepeaterItem item in this.repeatControl.Items)
                {
                    HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                    TextBox           text;
                    StockInLine       line = StockInLine.Retrieve(session, this.OrderNumber, chk.Value);
                    text             = item.FindControl("txtQty") as TextBox;
                    line.Quantity    = Cast.Decimal(text.Text.Trim());
                    text             = item.FindControl("txtSec") as TextBox;
                    line.SectionCode = text.Text.Trim();
                    DropDownList drp = item.FindControl("drpArea") as DropDownList;
                    line.AreaCode = drp.SelectedValue;

                    if (string.IsNullOrEmpty(line.AreaCode) || line.AreaCode.Trim().Length <= 0)
                    {
                        error.Append(chk.Attributes["sku"]).Append("未选择库位;");
                    }
                    else if (!string.IsNullOrEmpty(line.SectionCode) && line.SectionCode.Trim().Length > 0)
                    {
                        WHSection section = WHSection.Retrieve(session, line.AreaCode, line.SectionCode);
                        if (section == null)
                        {
                            error.Append(chk.Attributes["sku"])
                            .Append("库位").Append(line.AreaCode).Append("中不存在货架").Append(line.SectionCode).Append(";");
                        }
                    }

                    linesToSave.Add(line);
                }
                if (error.Length > 0)
                {
                    WebUtil.ShowError(this, error.ToString());
                    return;
                }

                try
                {
                    //检查
                    StockInHead head = StockInHead.Retrieve(session, this.OrderNumber);
                    if (head == null)
                    {
                        return;
                    }
                    session.BeginTransaction();
                    head.CreateOrUpdateLines(session, linesToSave);
                    session.Commit();
                    WebUtil.ShowMsg(this, "保存成功");
                }
                catch (Exception er)
                {
                    session.Rollback();
                    WebUtil.ShowError(this, er);
                }
            }
            #endregion
        }
        else if (e.CommandName == "Delete")
        {
            #region  除
            using (ISession session = new Session())
            {
                try
                {
                    session.BeginTransaction();
                    foreach (RepeaterItem item in this.repeatControl.Items)
                    {
                        HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                        if (chk.Checked)
                        {
                            StockInLine line = StockInLine.Retrieve(session, this.OrderNumber, chk.Value.Trim());
                            if (line != null)
                            {
                                line.Delete(session);
                            }
                        }
                    }
                    session.Commit();
                    this.QueryAndBindData(session, null);
                    WebUtil.ShowMsg(this, "选择的明细已经删除");
                }
                catch (Exception er)
                {
                    session.Rollback();
                    WebUtil.ShowError(this, er);
                }
            }
            #endregion
        }
        else if (e.CommandName == "Release")
        {
            #region 发布
            using (ISession session = new Session())
            {
                try
                {
                    StockInHead head = StockInHead.Retrieve(session, this.OrderNumber);
                    session.BeginTransaction();
                    head.Release(session);
                    session.Commit();
                    WebUtil.ShowMsg(this, "发布成功");
                    this.QueryAndBindData(session, head);
                    this.SetView(head);
                }
                catch (Exception er)
                {
                    session.Rollback();
                    WebUtil.ShowError(this, er);
                }
            }
            #endregion
        }
        else if (e.CommandName == "Close")
        {
            #region 关闭
            using (ISession session = new Session())
            {
                try
                {
                    StockInHead head = StockInHead.Retrieve(session, this.OrderNumber);
                    if (head == null)
                    {
                        return;
                    }
                    session.BeginTransaction();
                    head.Close(session);
                    session.Commit();
                    WebUtil.ShowMsg(this, "产品入库单" + head.OrderNumber + "已经完成");
                    this.QueryAndBindData(session, head);
                    this.SetView(head);
                }
                catch (Exception er)
                {
                    session.Rollback();
                    WebUtil.ShowError(this, er);
                }
            }
            #endregion
        }
        else if (e.CommandName == "Add")
        {
            #region 添加明细
            using (ISession session = new Session())
            {
                ItemSpec sku = ItemSpec.Retrieve(session, this.txtSku.Text.Trim().ToUpper());
                if (sku == null)
                {
                    WebUtil.ShowError(this, "SKU: " + this.txtSku.Text.Trim() + "不存在");
                    return;
                }
                StockInHead head = StockInHead.Retrieve(session, this.OrderNumber);
                StockInLine line = new StockInLine();
                line.OrderNumber   = this.OrderNumber;
                line.LocationCode  = head.LocationCode;
                line.LineNumber    = head.NextLineNumber();
                line.AreaCode      = "";
                line.SectionCode   = "";
                line.Price         = sku.AvgMoveCost;
                line.Quantity      = 0M;
                line.RefQuantity   = 0M;
                line.SKUID         = sku.SKUID;
                line.StockDetailID = 0;
                line.UnitID        = 0;

                bool isError = false;
                try
                {
                    session.BeginTransaction();
                    line.Create(session);
                    head.Update(session, "CurrentLineNumber");
                    session.Commit();
                }
                catch (Exception er)
                {
                    session.Rollback();
                    WebUtil.ShowError(this, er);
                    isError = true;
                }

                if (!isError)
                {
                    this.txtSku.Text = "";
                    this.QueryAndBindData(session, head);
                    this.SetView(head);
                }
            }
            #endregion
        }
    }
Esempio n. 3
0
        public void UpdateLines(ISession session, IList <StockInLine> lines2Save)
        {
            if (lines2Save == null || lines2Save.Count <= 0)
            {
                return;
            }

            #region 检查
            if (this._status != StockInStatus.New)
            {
                throw new Exception("单据不是新建状态,无法更新");
            }

            IList <StockInLine> lines = new List <StockInLine>(lines2Save.Count);
            bool error = false, errorHead = false;
            System.Text.StringBuilder builder = new System.Text.StringBuilder();
            foreach (StockInLine item in lines2Save)
            {
                errorHead = false;
                if (item.Quantity <= 0M)
                {
                    error = true;
                    if (!errorHead)
                    {
                        builder.Append("行号").Append(item.LineNumber).Append(": ");
                    }
                    errorHead = true;
                    builder.Append("数量无效; ");
                }
                if (this._orderTypeCode == StockInHead.ORD_TYPE_ASSIST_IN)
                {
                    if (string.IsNullOrEmpty(item.AreaCode) || item.AreaCode.Trim().Length <= 0)
                    {
                        error = true;
                        if (!errorHead)
                        {
                            builder.Append("行号").Append(item.LineNumber).Append(": ");
                        }
                        errorHead = true;
                        builder.Append("仓库为空; ");
                    }
                    if (!string.IsNullOrEmpty(item.SectionCode) && item.SectionCode.Trim().Length > 0)
                    {
                        WHSection section = WHSection.Retrieve(session, item.AreaCode, item.SectionCode);
                        if (section == null)
                        {
                            error = true;
                            if (!errorHead)
                            {
                                builder.Append("行号").Append(item.LineNumber).Append(": ");
                            }
                            errorHead = true;
                            builder.Append("货架{").Append(item.AreaCode).Append("-").Append(item.SectionCode).Append("}不存在; ");
                        }
                    }
                }
                else if (this._orderTypeCode == StockInHead.ORD_TYPE_ASSIST_OUT)
                {
                    if (item.Quantity > item.RefQuantity)
                    {
                        error = true;
                        if (!errorHead)
                        {
                            builder.Append("行号").Append(item.LineNumber).Append(": ");
                        }
                        errorHead = true;
                        builder.Append("领用数量大于库存数量; ");
                    }
                }
                if (!error)
                {
                    lines.Add(StockInLine.Retrieve(session, item.OrderNumber, item.LineNumber));
                }
            }
            if (error)
            {
                throw new Exception(builder.ToString());
            }
            #endregion

            for (int i = 0; i < lines.Count; i++)
            {
                StockInLine line = lines[i];
                if (this._orderTypeCode == StockInHead.ORD_TYPE_ASSIST_IN)
                {
                    line.AreaCode    = lines2Save[i].AreaCode;
                    line.SectionCode = lines2Save[i].SectionCode;
                    line.Quantity    = lines2Save[i].Quantity;
                    line.Price       = lines2Save[i].Price;
                    line.Update(session, "AreaCode", "SectionCode", "Quantity", "Price");
                }
                else
                {
                    line.Quantity = lines2Save[i].Quantity;
                    line.Update(session, "Quantity");
                }
            }
        }
        public void AddLines(ISession session, IList <WHTransferLine> lines)
        {
            if (this.Status != WHTransferStatus.New)
            {
                log.WarnFormat("status of transfer order {0} is not New, lines can't be added", this.OrderNumber);
                throw new Exception(string.Format("移库单{0}不是新建状态,无法添加明细", this.OrderNumber));
            }
            //检查
            System.Text.StringBuilder builder = new System.Text.StringBuilder();
            bool     msghead = false;
            ItemSpec sku     = null;;

            foreach (WHTransferLine line in lines)
            {
                msghead = false;
                sku     = null;
                StockDetail sto = StockDetail.Retrieve(session, line.FromStockID);
                if (sto == null)
                {
                    log.ErrorFormat("detail stock ID {0} not exists", line.FromStockID);
                    throw new Exception(string.Format("库存明细ID {0}不存在", line.FromStockID));
                }

                line.OrderNumber  = this.OrderNumber;
                line.LineNumber   = this.NextLineNumber();
                line.SKUID        = sto.SKUID;
                line.FromLocation = Cast.String(this.FromLocation, "").Trim().ToUpper();
                line.ToLocation   = Cast.String(this.ToLocation, "").Trim().ToUpper();
                line.FromArea     = Cast.String(sto.AreaCode).Trim().ToUpper();
                line.FromSection  = Cast.String(sto.SectionCode).Trim().ToUpper();
                line.UnitID       = 0;
                bool isAreaEmpty = false;
                if (string.IsNullOrEmpty(line.ToArea) || line.ToArea.Trim().Length <= 0)
                {
                    if (!msghead)
                    {
                        if (sku == null)
                        {
                            sku = ItemSpec.Retrieve(session, sto.SKUID);
                        }
                        builder.Append(sku.BarCode).Append(":");
                    }
                    builder.Append("移入库位为空;");
                    isAreaEmpty = true;
                }
                else if (!string.IsNullOrEmpty(line.ToSection) && line.ToSection.Trim().Length > 0)
                {
                    WHSection section = WHSection.Retrieve(session, line.ToArea, line.ToSection);
                    if (section == null)
                    {
                        if (!msghead)
                        {
                            if (sku == null)
                            {
                                sku = ItemSpec.Retrieve(session, sto.SKUID);
                            }
                            builder.Append(sku.BarCode).Append(":");
                        }
                        builder.Append("移入库位").Append(line.ToArea).Append("中不存在货架").Append(line.ToSection).Append(";");
                    }
                }
                if (!isAreaEmpty && line.FromArea == Cast.String(line.ToArea).Trim().ToUpper() && line.FromSection == Cast.String(line.ToSection, "").Trim().ToUpper())
                {
                    if (sku == null)
                    {
                        sku = ItemSpec.Retrieve(session, sto.SKUID);
                    }
                    builder.Append(sku.BarCode).Append(":");
                    builder.Append("来源库位-货架与移入库位-货架一样;");
                }
            }

            if (builder.Length > 0)
            {
                log.Warn(builder.ToString());
                throw new Exception(builder.ToString());
            }

            foreach (WHTransferLine line in lines)
            {
                line.Create(session);
            }
            this.Update(session, "CurrentLineNumber");
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public SimpleJson AddLine(ISession session, string poLineNumber, string areaCode, string sectionCode, decimal qty)
        {
            //检查
            if (string.IsNullOrEmpty(poLineNumber) || poLineNumber.Trim().Length <= 0)
            {
                return(new SimpleJson().HandleError("PO行为空"));
            }
            if (string.IsNullOrEmpty(areaCode) || areaCode.Trim().Length <= 0)
            {
                return(new SimpleJson().HandleError("库位为空"));
            }
            if (!string.IsNullOrEmpty(sectionCode) && sectionCode.Trim().Length > 0)
            {
                WHSection section = WHSection.Retrieve(session, areaCode, sectionCode);
                if (session == null)
                {
                    return(new SimpleJson()
                           .HandleError("库位" + areaCode.Trim().ToUpper() + "中的货架" + sectionCode.Trim().ToUpper() + "不存在"));
                }
            }
            if (qty <= 0)
            {
                return(new SimpleJson().HandleError("收货数量" + qty.ToString() + "小于0"));
            }
            POLine poLine = POLine.Retrieve(session, this.RefOrderNumber, poLineNumber);

            if (poLine == null)
            {
                return(new SimpleJson().HandleError("PO " + this.RefOrderNumber + "中不存在" + poLineNumber + "的行"));
            }
            if (poLine.ReceivableQty() <= 0M)
            {
                return(new SimpleJson().HandleError("订单" + this.RefOrderNumber + "行" + poLineNumber + "可收货数量为0"));
            }
            if (!poLine.UnfinishedReceiveQtyChange(session, qty))
            {
                return(new SimpleJson().HandleError("无法更新订单" + this.RefOrderNumber + "行" + poLineNumber + "的待入库数量"));
            }

            RCVLine line = new RCVLine();

            line.OrderNumber    = this.OrderNumber;
            line.LineNumber     = this.NextLineNumber();
            line.TransTypeCode  = " ";
            line.LocationCode   = this.LocationCode;
            line.AreaCode       = areaCode.Trim().ToUpper();
            line.SectionCode    = string.IsNullOrEmpty(sectionCode) ? " " : sectionCode.Trim().ToUpper();
            line.SKUID          = poLine.SKUID;
            line.UnitID         = poLine.UnitID;
            line.RefQty         = poLine.ReceivableQty();
            line.RCVTotalQty    = qty;
            line.QualifiedQty   = qty;
            line.UnQualifiedQty = 0M;
            line.RefOrderLine   = line.OriginalOrderLine = poLine.LineNumber;
            line.TaxValue       = 0M; // poLine.TaxValue;  系统默认进项税不可以退税抵扣,所以交易税率设置为0,需财务手工确定可以抵扣的进项税率
            line.Price          = poLine.Price;
            line.Create(session);

            this.Update(session, "CurrentLineNumber");

            return(new SimpleJson());
        }