Exemplo n.º 1
0
        /// <summary>
        /// 添加收货明细,引用POLine信息
        /// </summary>
        /// <param name="session"></param>
        /// <param name="poLine"></param>
        /// <returns></returns>
        public bool AddLine(ISession session, POLine poLine)
        {
            if (poLine.ReceivableQty() <= 0M)
            {
                return(false);
            }
            if (!poLine.UnfinishedReceiveQtyChange(session, poLine.ReceivableQty()))
            {
                return(false);
            }

            RCVLine line = new RCVLine();

            line.OrderNumber    = this.OrderNumber;
            line.LineNumber     = this.NextLineNumber();
            line.TransTypeCode  = " ";
            line.LocationCode   = this.LocationCode;
            line.SKUID          = poLine.SKUID;
            line.UnitID         = poLine.UnitID;
            line.RefQty         = poLine.ReceivableQty();
            line.RCVTotalQty    = poLine.ReceivableQty();
            line.QualifiedQty   = poLine.ReceivableQty();
            line.UnQualifiedQty = 0M;
            line.RefOrderLine   = line.OriginalOrderLine = poLine.LineNumber;
            line.TaxValue       = 0M; // poLine.TaxValue; 系统默认进项税不可以退税抵扣,所以交易税率设置为0,需财务手工确定可以抵扣的进项税率
            line.Price          = poLine.Price;
            return(line.Create(session));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 删除收货单指定明细
        /// </summary>
        /// <param name="session"></param>
        /// <param name="lienesToDelete"></param>
        /// <returns></returns>
        public int DeleteLines(ISession session, IList <RCVLine> lienesToDelete)
        {
            if (lienesToDelete == null || lienesToDelete.Count <= 0)
            {
                return(0);
            }
            if (this._status != ReceiveStatus.New)
            {
                throw new Exception("收货单不是新建状态,无法删除明细");
            }

            int count = 0;

            foreach (RCVLine ltd in lienesToDelete)
            {
                if (this._orderTypeCode == RCVHead.ORD_TYPE_PUR)
                {   //采购收货,删除明细时需要恢复采购订单的冗余字段值
                    POLine poLine = null;
                    if (!string.IsNullOrEmpty(this._refOrderNumber) && this._refOrderNumber.Trim().Length > 0 &&
                        !string.IsNullOrEmpty(ltd.RefOrderLine) && ltd.RefOrderLine.Trim().Length > 0)
                    {
                        poLine = POLine.Retrieve(session, this._refOrderNumber, ltd.RefOrderLine);
                    }
                    if (poLine != null)
                    {
                        poLine.UnfinishedReceiveQtyChange(session, -ltd.QualifiedQty);
                    }
                }
                ltd.Delete(session);

                count++;
            }

            return(count);
        }
Exemplo n.º 3
0
        public void AddLine(ISession session, string po, string poLine, string area, string section, decimal qty)
        {
            if (this.Status != POReturnStatus.New)
            {
                throw new Exception("采购退货单不是新建状态,无法添加明细");
            }
            POLine line = POLine.Retrieve(session, po, poLine);

            if (line == null)
            {
                throw new Exception(po + "行" + poLine + "不存在");
            }
            if (line.ReceiveQty < qty)
            {
                throw new Exception(po + "行" + poLine + "退货数量" + qty.ToString() + "大于收货数量" + line.ReceiveQty.ToString());
            }
            StockDetail sto = StockDetail.Retrieve(session, line.SKUID, this.LocationCode, area, section);

            if (sto == null)
            {
                throw new Exception(po + "行" + poLine + "库存明细(" + area + "," + section + ")不存在");
            }
            if (sto.StockQty < qty)
            {
                throw new Exception(po + "行" + poLine + "退货数量" + qty.ToString() + "大于库存量" + sto.StockQty.ToString());
            }

            DbSession  dbsession = session.DbSession as DbSession;
            IDbCommand cmd       = dbsession.CreateSqlStringCommand("Select Sum(a.rtn_qty) From ord_pur_rtn_line a Where a.po_num=:po And a.po_line=:poline");

            dbsession.AddParameter(cmd, ":po", DbTypeInfo.AnsiString(16), po);
            dbsession.AddParameter(cmd, ":poline", DbTypeInfo.AnsiString(4), poLine);
            decimal returnedQty = Cast.Decimal(dbsession.ExecuteScalar(cmd));

            if (returnedQty + qty > line.ReceiveQty)
            {
                throw new Exception(po + "行" + poLine + ",已退货数量" + returnedQty.ToString() + "本次退货数量" + qty.ToString() + "大于收货数量" + line.ReceiveQty.ToString());
            }

            POReturnLine rtnLine = new POReturnLine();

            rtnLine.OrderNumber   = this.OrderNumber;
            rtnLine.LineNumber    = this.NextLineNumber();
            rtnLine.PONumber      = po;
            rtnLine.POLine        = poLine;
            rtnLine.SKUID         = line.SKUID;
            rtnLine.Price         = line.Price;
            rtnLine.Quantity      = qty;
            rtnLine.TaxValue      = line.TaxValue;
            rtnLine.StockDetailID = sto.StockDetailID;
            rtnLine.Create(session);
        }
Exemplo n.º 4
0
        public void Close(ISession session, bool throwException)
        {
            if (this._status != ReceiveStatus.Open)
            {
                log.ErrorFormat("收货单{0}不是待发货状态,无法执行关闭操作", this._orderNumber);
                if (throwException)
                {
                    throw new Exception(string.Format("收货单{0}不是待发货状态,无法执行关闭操作", this._orderNumber));
                }
                return;
            }

            //签核完成后会调用这个方法,尝试将收货单自动关闭,如果这个方法发生异常,签核处理正常完成,需要手工来关闭这个单据
            //签核完成的关闭动作将新开一个session来完成,确保关闭时的异常不会影响签核操作的结束;手工关闭时由界面开session来执行这个方法
            try
            {
                //库存交易
                ERPUtil.CommitWHTrans(session, this);
                //更新PO行的冗余字段值
                if (this._orderTypeCode == RCVHead.ORD_TYPE_PUR &&
                    !string.IsNullOrEmpty(this._refOrderNumber) && this._refOrderNumber.Trim().Length > 0)
                {
                    IList <RCVLine> rcvLines = session.CreateEntityQuery <RCVLine>()
                                               .Where(Exp.Eq("OrderNumber", this._orderNumber))
                                               .OrderBy("LineNumber")
                                               .List <RCVLine>();
                    foreach (RCVLine rcv in rcvLines)
                    {
                        if (!string.IsNullOrEmpty(rcv.RefOrderLine) && rcv.RefOrderLine.Trim().Length > 0)
                        {
                            POLine poLine = POLine.Retrieve(session, this._refOrderNumber, rcv.RefOrderLine);
                            if (poLine != null)
                            {
                                poLine.ReceiveFinish(session, rcv.RCVTotalQty, rcv.QualifiedQty);
                            }
                        }
                    }
                }
                //更新本身状态
                this._status = ReceiveStatus.Close;
                this.Update(session, "Status");
            }
            catch (Exception er)
            {
                log.Error(string.Format("收货单{0}关闭时发生异常", this._orderNumber), er);
                if (throwException)
                {
                    throw er;
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// ����ջ���ϸ������POLine��Ϣ
        /// </summary>
        /// <param name="session"></param>
        /// <param name="poLine"></param>
        /// <returns></returns>
        public bool AddLine(ISession session, POLine poLine)
        {
            if (poLine.ReceivableQty() <= 0M) return false;
            if (!poLine.UnfinishedReceiveQtyChange(session, poLine.ReceivableQty())) return false;

            RCVLine line = new RCVLine();
            line.OrderNumber = this.OrderNumber;
            line.LineNumber = this.NextLineNumber();
            line.TransTypeCode = " ";
            line.LocationCode = this.LocationCode;
            line.SKUID = poLine.SKUID;
            line.UnitID = poLine.UnitID;
            line.RefQty = poLine.ReceivableQty();
            line.RCVTotalQty = poLine.ReceivableQty();
            line.QualifiedQty = poLine.ReceivableQty();
            line.UnQualifiedQty = 0M;
            line.RefOrderLine = line.OriginalOrderLine = poLine.LineNumber;
            line.TaxValue = 0M;  // poLine.TaxValue; ϵͳĬ�Ͻ���˰��������˰�ֿۣ����Խ���˰������Ϊ0��������ֹ�ȷ�����Եֿ۵Ľ���˰��
            line.Price = poLine.Price;
            return line.Create(session);
        }
Exemplo n.º 6
0
    protected void cmdProduct_Click(object sender, EventArgs e)
    {
        if (this.txtSkuId.Value.Trim().Length <= 0) return;

        bool added = false;
        using (_session = new Session())
        {
            string[] idArray = this.txtSkuId.Value.Trim().Trim(';').Split(';');
            try
            {
                POHead head = POHead.Retrieve(_session, this.OrderNumber);
                if (head == null || head.Status != POStatus.New) return;

                _session.BeginTransaction();
                foreach (string s in idArray)
                {
                    POLine poLine = new POLine();
                    poLine.OrderNumber = this.OrderNumber;
                    poLine.SKUID = Cast.Int(s, 0);
                    if (poLine.SKUID <= 0) continue;
                    poLine.LineNumber = head.NextLineNumber();
                    poLine.LineStatus = POLineStatus.Open;
                    poLine.PurchaseQty = 0M;
                    poLine.Price = 0M;
                    //Vendor vendor = null;
                    //if (head.VendorID > 0) vendor = Vendor.Retrieve(_session, head.VendorID);
                    //if (vendor != null)
                    //{
                    //    poLine.TaxID = vendor.TaxID;
                    //    poLine.TaxValue = vendor.Tax;
                    //}
                    //else
                    //{
                    //    poLine.TaxID = 0;
                    //    poLine.TaxValue = 0M;
                    //}
                    poLine.TaxID = 0;
                    poLine.TaxValue = 0M;
                    poLine.TaxInclusiveAmt = 0M;
                    poLine.TaxAmt = 0M;
                    poLine.TaxExlusiveAmt = 0M;
                    poLine.PlanDate = head.DefaultPlanDate;
                    poLine.ActualDate = new DateTime(1900, 1, 1);
                    poLine.ReceiveQty = 0M;
                    poLine.IQCQty = 0M;
                    poLine.UnfinishedReceiveQty = 0M;
                    poLine.ModifyUser = SecuritySession.CurrentUser.UserId;
                    poLine.ModifyTime = DateTime.Now;
                    poLine.UnitID = 0;

                    poLine.Create(_session);
                    added = true;
                }
                head.Update(_session, "CurrentLineNumber");
                _session.Commit();
                if (added)
                {
                    BindPOLine(_session, head);
                    WebUtil.ShowMsg(this, "订单明细保存成功", "操作成功");
                }
            }
            catch (Exception ex)
            {
                _session.Rollback();
                logger.Info("保存POLine", ex);
                WebUtil.ShowError(this, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员");
            }
        }
    }
Exemplo n.º 7
0
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName == "Save")
        {
            #region 保存
            //txtPurchaseQty txtPlanDate txtPrice
            bool updated = false;
            using (_session = new Session())
            {
                POHead head = POHead.Retrieve(_session, this.OrderNumber);
                if (head == null || head.Status != POStatus.New) return;

                _session.BeginTransaction();
                try
                {
                    foreach (RepeaterItem item in this.rptPL.Items)
                    {
                        HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                        if (!string.IsNullOrEmpty(chk.Value))
                        {
                            HtmlInputText txtPurchaseQty = item.FindControl("txtPurchaseQty") as HtmlInputText;
                            HtmlInputText txtPlanDate = item.FindControl("txtPlanDate") as HtmlInputText;
                            HtmlInputText txtPrice = item.FindControl("txtPrice") as HtmlInputText;
                            POLine poLine = POLine.Retrieve(_session, this.OrderNumber, chk.Value);
                            if (poLine == null || poLine.LineStatus != POLineStatus.Open) continue;

                            poLine.PurchaseQty = Cast.Decimal(txtPurchaseQty.Value, poLine.PurchaseQty);
                            poLine.PlanDate = Cast.DateTime(txtPlanDate.Value, poLine.PlanDate);
                            poLine.Price = Cast.Decimal(txtPrice.Value, poLine.Price);
                            poLine.TaxID = 0;
                            poLine.TaxValue = 0M;
                            //含税额(含税采购成本)  TaxInclusiveAmt 含税额 = 数量*单价
                            poLine.TaxInclusiveAmt = poLine.PurchaseQty * poLine.Price;
                            //不含税额(采购成本) TaxExlusiveAmt 含税额-税额
                            poLine.TaxExlusiveAmt = 0M; // poLine.TaxInclusiveAmt / (1 + poLine.TaxValue);
                            //税额    TaxAmt  税额 = 不含税额*税率
                            poLine.TaxAmt = 0M; //poLine.TaxExlusiveAmt * poLine.TaxValue;
                            poLine.Update(_session, "PurchaseQty", "TaxID", "TaxValue", "PlanDate", "Price", "TaxInclusiveAmt");
                            updated = true;
                        }
                    }
                    //更新统计信息
                    if (updated)
                        UpdatePOLineAndPoHead(_session, head);
                    _session.Commit();
                    if (updated)
                    {
                        BindPOLine(_session, head);
                        WebUtil.ShowMsg(this, "采购订单明细保存成功", "操作成功");
                    }
                }
                catch (Exception ex)
                {
                    _session.Rollback();
                    WebUtil.ShowError(this, ex);
                }
            }
            #endregion
        }
        else if (e.CommandName == "Cancel")
        {
            #region 取消明细
            bool updated = false;
            using (_session = new Session())
            {
                POHead head = POHead.Retrieve(_session, this.OrderNumber);
                if (head.Status != POStatus.Release)
                    return;

                _session.BeginTransaction();
                try
                {
                    foreach (RepeaterItem item in this.rptPL.Items)
                    {
                        HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                        if (chk != null && chk.Checked && !string.IsNullOrEmpty(chk.Value))
                        {
                            POLine poLine = POLine.Retrieve(_session, this.OrderNumber, chk.Value);
                            if (poLine == null || poLine.LineStatus != POLineStatus.Open) continue;
                            poLine.LineStatus = POLineStatus.Cancel;
                            poLine.ModifyUser = Magic.Security.SecuritySession.CurrentUser.UserId;
                            poLine.ModifyTime = DateTime.Now;
                            poLine.Update(_session, "LineStatus", "ModifyUser", "ModifyTime");
                            updated = true;
                        }
                    }
                    //再次统计 POLine
                    if (updated)
                        UpdatePOLineAndPoHead(_session, head);
                    _session.Commit();

                    if (updated)
                    {
                        BindPOLine(_session, head);
                        WebUtil.ShowMsg(this, "选择的明细已经取消", "操作成功");
                    }
                }
                catch (Exception ex)
                {
                    _session.Rollback();
                    WebUtil.ShowError(this, ex);
                }
            }
            #endregion
        }
        else if (e.CommandName == "Delete")
        {
            #region 删除明细
            bool deleted = false;
            using (_session = new Session())
            {
                POHead head = POHead.Retrieve(_session, this.OrderNumber);
                if (head == null || head.Status != POStatus.New) return;

                _session.BeginTransaction();
                try
                {
                    foreach (RepeaterItem item in this.rptPL.Items)
                    {
                        HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                        if (chk != null && chk.Checked && !string.IsNullOrEmpty(chk.Value))
                        {
                            POLine line = POLine.Retrieve(_session, this.OrderNumber, chk.Value);
                            if (line.LineStatus != POLineStatus.Open) continue;
                            line.Delete(_session);
                            deleted = true;
                        }
                    }
                    //再次统计 POLine
                    if (deleted)
                        UpdatePOLineAndPoHead(_session, head);
                    _session.Commit();

                    if (deleted)
                    {
                        BindPOLine(_session, head);
                        WebUtil.ShowMsg(this, "选择的明细已经删除", "操作成功");
                    }
                }
                catch (Exception ex)
                {
                    _session.Rollback();
                    WebUtil.ShowError(this, ex);
                }
            }
            #endregion
        }
        else if (e.CommandName == "Release" || e.CommandName == "Close")
        {
            #region 发布,关闭
            using (_session = new Session())
            {
                try
                {
                    POHead head = POHead.Retrieve(_session, this.OrderNumber);
                    _session.BeginTransaction();
                    if (e.CommandName == "Release")
                        head.Release(_session);
                    else
                        head.Close(_session);
                    _session.Commit();

                    BindPOLine(_session, head);
                    this.SetView(_session, head);
                    WebUtil.ShowMsg(this, "订单已经" + (e.CommandName == "Release" ? "发布" : "关闭"), "操作成功");
                }
                catch (Exception er)
                {
                    _session.Rollback();
                    WebUtil.ShowError(this, er);
                }
            }
            #endregion
        }
        else if (e.CommandName == "QuickAdd")
        {
            #region 快速添加
            using (_session = new Session())
            {
                //检查
                string itemCode = this.txtItemCode.Value.Trim();
                string color = this.txtColorCode.Value.Trim().ToUpper();
                string size = this.txtSizeCode.Value.Trim().ToUpper();
                decimal qty = Cast.Decimal(this.txtPurchaseQty.Value.Trim(), 0M);
                decimal price = Cast.Decimal(this.txtPrice.Value.Trim(), 0M);
                DateTime date = Cast.DateTime(this.txtDemandDate.Value.Trim(), new DateTime(1900, 1, 1));

                if (qty <= 0M)
                {
                    this.txtAlertMsg.InnerText = string.Format("采购数量{0}不是有效的数字", this.txtPurchaseQty.Value.Trim());
                    return;
                }
                if (price <= 0M)
                {
                    this.txtAlertMsg.InnerText = string.Format("单价{0}不是有效的数字", this.txtPrice.Value.Trim());
                    return;
                }
                if (date <= new DateTime(1900, 1, 1))
                {
                    this.txtAlertMsg.InnerText = string.Format("无效的需求日期{0}", this.txtDemandDate.Value.Trim());
                    return;
                }

                IList<ItemMaster> masters = _session.CreateEntityQuery<ItemMaster>()
                    .Where(Exp.Eq("ItemCode", itemCode)).List<ItemMaster>();
                if (masters == null || masters.Count <= 0)
                {
                    this.txtAlertMsg.InnerText = string.Format("货号{0}不存在", itemCode);
                    return;
                }
                ItemColor objColor = ItemColor.Retrieve(_session, color);
                if (objColor == null)
                {
                    this.txtAlertMsg.InnerText = string.Format("颜色代码{0}不存在", color);
                    return;
                }
                IList<ItemSpec> skus = _session.CreateEntityQuery<ItemSpec>()
                    .Where(Exp.Eq("ItemID", masters[0].ItemID) & Exp.Eq("ColorCode", objColor.ColorCode) & Exp.Eq("SizeCode", size))
                    .List<ItemSpec>();
                if (skus == null || skus.Count <= 0)
                {
                    this.txtAlertMsg.InnerText = string.Format("不存在货号:{0} 颜色:{1} 尺码:{2}的SKU", itemCode, color, size);
                    return;
                }
                ItemSize objSize = ItemSize.Retrieve(_session, size, masters[0].CategoryID);
                if (objSize == null)
                {
                    this.txtAlertMsg.InnerText = string.Format("尺码{0}不存在", size);
                    return;
                }

                //添加操作
                POHead head = POHead.Retrieve(_session, this.OrderNumber);
                POLine line = new POLine();
                line.OrderNumber = this.OrderNumber;
                line.LineNumber = head.NextLineNumber();
                line.LineStatus = POLineStatus.Open;
                line.SKUID = skus[0].SKUID;
                line.PurchaseQty = qty;
                line.Price = price;
                line.TaxID = 0;
                line.TaxValue = 0M;
                line.TaxInclusiveAmt = line.PurchaseQty * line.Price;
                line.TaxExlusiveAmt = 0M; // line.TaxInclusiveAmt / (1 + line.TaxValue);
                line.TaxAmt = 0M; //line.TaxExlusiveAmt * line.TaxValue;
                line.PlanDate = date;
                line.ActualDate = new DateTime(1900, 1, 1);
                line.ReceiveQty = 0M;
                line.IQCQty = 0M;
                line.UnfinishedReceiveQty = 0M;
                line.ModifyUser = SecuritySession.CurrentUser.UserId;
                line.ModifyTime = DateTime.Now;
                line.UnitID = 0;

                try
                {
                    _session.BeginTransaction();
                    line.Create(_session);
                    head.Update(_session, "CurrentLineNumber");
                    this.UpdatePOLineAndPoHead(_session, head);
                    _session.Commit();
                    BindPOLine(_session, head);
                    this.txtAlertMsg.InnerText = "添加成功,订单行号为" + line.LineNumber;
                    this.txtPurchaseQty.Value = "";
                }
                catch (Exception er)
                {
                    _session.Rollback();
                    WebUtil.ShowError(this, er);
                }
            }
            #endregion
        }
    }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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());
        }