Пример #1
0
 public POHead SavePOHead()
 {
     using (ISession session = new Session())
     {
         try
         {
             POHead poHead = null;
             if (this.IsNew)
             {
                 //新增
                 poHead = new POHead();
                 poHead.OrderNumber = ERPUtil.NextOrderNumber(POHead.ORDER_TYPE);
                 this.txtOrderNumber.Text = poHead.OrderNumber;
                 poHead.CompanyID = -1;
                 poHead.LocationCode = this.drpLocationCode.SelectedValue;
                 poHead.PurchGroupCode = this.drpPurchGroupCode.SelectedValue;
                 poHead.VendorID = Cast.Int(this.drpVendorID.SelectedValue, 0);
                 poHead.Status = POStatus.New;
                 poHead.TaxAmt = 0M;
                 poHead.TaxExclusiveAmt = 0M;
                 poHead.TaxInclusiveAmt = 0M;
                 poHead.ShippingAddress = this.txtShippingAddress.Text.Trim();
                 poHead.CreateUser = Magic.Security.SecuritySession.CurrentUser.UserId;
                 poHead.CreateTime = DateTime.Now;
                 poHead.ApproveResult = ApproveStatus.UnApprove;
                 poHead.ApproveTime = new DateTime(1900, 1, 1);
                 poHead.ApproveUser = 0;
                 poHead.ApproveNote = " ";
                 poHead.CurrentLineNumber = "0000";
                 poHead.Note = this.txtNote.Text.Trim();
                 poHead.DefaultPlanDate = Cast.DateTime(this.txtDemandDate.Text, DateTime.Now);
                 poHead.Create(session);
                 WebUtil.ShowMsg(this, "采购订单保存成功", "操作成功");
                 return poHead;
             }
             else
             {
                 //编辑
                 poHead = POHead.Retrieve(session, this.txtOrderNumber.Text.Trim());
                 poHead.LocationCode = this.drpLocationCode.SelectedValue;
                 poHead.PurchGroupCode = this.drpPurchGroupCode.SelectedValue;
                 poHead.VendorID = Cast.Int(this.drpVendorID.SelectedValue, 0);
                 poHead.ShippingAddress = this.txtShippingAddress.Text.Trim();
                 poHead.Note = this.txtNote.Text.Trim();
                 poHead.DefaultPlanDate = Cast.DateTime(this.txtDemandDate.Text, poHead.DefaultPlanDate);
                 poHead.Update(session, "PurchGroupCode", "LocationCode", "VendorID", "ShippingAddress", "Note", "DefaultPlanDate");
                 WebUtil.ShowMsg(this, "采购订单保存成功", "操作成功");
                 return poHead;
             }
         }
         catch (Exception ex)
         {
             //throw;
             logger.Info("保存POHead", ex);
             WebUtil.ShowMsg(this, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员");
         }
         return null;
     }
 }
Пример #2
0
        /// <summary>
        /// 添加收货明细,引用指定采购订单的所有可收货明细
        /// </summary>
        /// <param name="session"></param>
        /// <param name="poNumber"></param>
        /// <returns></returns>
        public int AddLinesFromRefOrder(ISession session)
        {
            int count = 0;

            switch (this._orderTypeCode)
            {
            case RCVHead.ORD_TYPE_PUR:
                foreach (POLine poLine in POHead.ReceivableLines(session, this._refOrderNumber))
                {
                    if (this.AddLine(session, poLine))
                    {
                        count++;
                    }
                }
                break;
            }
            return(count);
        }
Пример #3
0
        public static RCVHead CreatePurchaseRCV(ISession session, int userId, string poNumber, string note)
        {
            RCVHead head = new RCVHead();

            head._refOrderType   = head._originalOrderType = POHead.ORDER_TYPE;
            head._refOrderNumber = head._orginalOrderNumber = poNumber.Trim().ToUpper();
            #region 检查
            //暂时不允许采购收货,但不引用采购订单的方式
            if (string.IsNullOrEmpty(head._refOrderNumber))
            {
                throw new Exception("采购订单为空");
            }
            POHead po = POHead.Retrieve(session, head._refOrderNumber);
            if (po == null)
            {
                throw new Exception(string.Format("采购订单{0}不存在", head._refOrderNumber));
            }
            if (po.Status != POStatus.Release)
            {
                throw new Exception(string.Format("采购订单{0}不是发布状态,不可以进行收货作业", head._refOrderNumber));
            }
            if (po.ApproveResult != ApproveStatus.Approve)
            {
                throw new Exception(string.Format("采购订单{0}还没有完成签核,不可以进行收货作业", head._refOrderNumber));
            }
            #endregion
            head._orderTypeCode = RCVHead.ORD_TYPE_PUR;
            head._orderNumber   = ERPUtil.NextOrderNumber(head._orderTypeCode);
            head._objectID      = po.VendorID;
            head._locationCode  = po.LocationCode;
            head._createUser    = userId;
            head._note          = note.Trim();
            EntityManager.Create(session, head);

            return(head);
        }
Пример #4
0
 private void SetView(POHead po)
 {
     if (this.IsNew)
     {
         this.cmdDetail.Visible = false;
         this.cmdPaid.Visible = false;
     }
     else
     {
         this.cmdDetail.Visible = true;
         this.cmdPaid.Visible = false;
         if (po != null && !po.HasPaid)
             this.cmdPaid.Visible = true;
         this.cmdDetail["Detail"].NavigateUrl = "POLineManage.aspx?OrderNum=" + this.OrderNumber + "&return=" + Microsoft.JScript.GlobalObject.escape(WebUtil.Param("return"));
     }
     this.cmdReturn["Return"].NavigateUrl = WebUtil.Param("return");
 }
Пример #5
0
 void RetrievePOHeadData(POHead po, string poNumber)
 {
     string orderNumber = poNumber;
     if (!string.IsNullOrEmpty(orderNumber))
     {
         if (po != null)
         {
             this.txtOrderNumber.Text = po.OrderNumber;
             this.drpPurchGroupCode.SelectedValue = po.PurchGroupCode;
             this.drpLocationCode.SelectedValue = po.LocationCode;
             this.drpVendorID.SelectedValue = po.VendorID.ToString();
             this.txtShippingAddress.Text = po.ShippingAddress;
             this.txtNote.Text = po.Note;
             this.hidStatus.Value = po.Status.ToString();
             this.txtDemandDate.Text = po.DefaultPlanDate.ToString("yyyy-MM-dd");
             this.lblPaid.Text = po.HasPaid ? "是" : "否";
             if (po.Status != POStatus.New)
             {
                 WebUtil.DisableControl(this.drpPurchGroupCode);
                 WebUtil.DisableControl(this.drpLocationCode);
                 WebUtil.DisableControl(this.drpVendorID);
                 WebUtil.DisableControl(this.txtShippingAddress);
                 WebUtil.DisableControl(this.txtNote);
                 WebUtil.DisableControl(this.txtDemandDate);
                 this.cmdSave.Visible = false;
             }
         }
     }
 }
Пример #6
0
    private void UpdatePOLineAndPoHead(ISession session, POHead head)
    {
        //POLine 统计
        IList<POLine> lines = session.CreateEntityQuery<POLine>()
            .Where(Exp.Eq("OrderNumber", this.OrderNumber))
            .And(Exp.NEq("LineStatus", POLineStatus.Cancel))
            .List<POLine>();
        decimal totalTaxInclusiveAmt = 0M; //, totalTaxAmt = 0M, totalTaxExlusiveAmt = 0M;
        foreach (POLine line in lines)
        {
            totalTaxInclusiveAmt += line.TaxInclusiveAmt;
            //totalTaxAmt += line.TaxAmt;
            //totalTaxExlusiveAmt += line.TaxExlusiveAmt;
        }

        //更新主表 TaxInclusiveAmt TaxAmt TaxExlusiveAmt
        head.TaxInclusiveAmt = totalTaxInclusiveAmt;
        //head.TaxAmt = totalTaxAmt;
        //head.TaxExclusiveAmt = totalTaxExlusiveAmt;
        head.Update(session, "TaxInclusiveAmt");
    }
Пример #7
0
 private void SetView(ISession session, POHead head)
 {
     POStatus status = head == null ? POStatus.Close : head.Status;
     this.hidStatus.Value = status.ToString();
     //按钮屏蔽判断  新建 1  发布 2 已完成3
     //新增 cmdSelectItem  保存cmdSave1 取消cmdCancel1 返回cmdReturn1
     switch (status)
     {
         case POStatus.New:
             this.cmdSelectItem1.Visible = true;
             this.cmdSelectItem2.Visible = true;
             this.cmdSave1.Visible = true;
             this.cmdSave2.Visible = true;
             this.cmdDelete1.Visible = true;
             this.cmdDelete2.Visible = true;
             this.cmdCancel1.Visible = false;
             this.cmdCancel2.Visible = false;
             this.cmdRelease1.Visible = true;
             this.cmdRelease2.Visible = true;
             this.cmdClose1.Visible = false;
             this.cmdClose2.Visible = false;
             this.divQuickAdd1.Visible = true;
             this.divQuickAdd2.Visible = true;
             break;
         case POStatus.Release:
             this.cmdSelectItem1.Visible = false;
             this.cmdSelectItem2.Visible = false;
             this.cmdSave1.Visible = false;
             this.cmdSave2.Visible = false;
             this.cmdDelete1.Visible = false;
             this.cmdDelete2.Visible = false;
             this.cmdRelease1.Visible = false;
             this.cmdRelease2.Visible = false;
             this.cmdCancel1.Visible = true;
             this.cmdCancel2.Visible = true;
             if (head.ApproveResult == ApproveStatus.UnApprove)
             {
                 this.cmdClose1.Visible = false;
                 this.cmdClose2.Visible = false;
             }
             else
             {
                 this.cmdClose1.Visible = true;
                 this.cmdClose2.Visible = true;
             }
             this.divQuickAdd1.Visible = false;
             this.divQuickAdd2.Visible = false;
             this.SetReadonly();
             break;
         case POStatus.Close:
             this.cmdSelectItem1.Visible = false;
             this.cmdSelectItem2.Visible = false;
             this.cmdSave1.Visible = false;
             this.cmdSave2.Visible = false;
             this.cmdDelete1.Visible = false;
             this.cmdDelete2.Visible = false;
             this.cmdRelease1.Visible = false;
             this.cmdRelease2.Visible = false;
             this.cmdCancel1.Visible = false;
             this.cmdCancel2.Visible = false;
             this.cmdClose1.Visible = false;
             this.cmdClose2.Visible = false;
             this.divQuickAdd1.Visible = false;
             this.divQuickAdd2.Visible = false;
             this.SetReadonly();
             break;
     }
 }
Пример #8
0
 private void SetQuickAdd(ISession session, POHead head)
 {
     this.txtDemandDate.Value = head.DefaultPlanDate.ToString("yyyy-MM-dd");
 }
Пример #9
0
    private void BindPOLine(ISession session, POHead poHead)
    {
        //显示POHead内容
        if (poHead != null)
        {
            this.LabOrderNumber.Text = poHead.OrderNumber;
            //供应商
            Vendor vendor = Vendor.Retrieve(session, poHead.VendorID);
            if (vendor != null)
                this.LabVendorID.Text = vendor.ShortName;
            //采购组
            this.LabPurchGroupCode.Text = poHead.PurchGroupCode;
            this.LabTaxInclusiveAmt.Text = RenderUtil.FormatNumber(poHead.TaxInclusiveAmt, "#0.#0");
        }

        //POLine.SKUID=ItemSpec.SKUID  ItemSpec.ItemID=ItemMaster.ItemID
        //货号ItemMaster.ItemCode  商品名称ItemMaster.ItemName
        //颜色ItemSpec.ColorCode  尺码  ItemSpec.SizeCode
        ObjectQuery query = session.CreateObjectQuery(@"
        select m.ItemCode as ItemCode,m.ItemName as ItemName,s.ColorCode as ColorCode,s.SizeCode as SizeCode
        ,p.LineNumber as LineNumber,p.LineStatus as LineStatus,p.PurchaseQty as PurchaseQty,p.PlanDate as PlanDate,p.Price as Price,p.OrderNumber as OrderNumber
        ,p.TaxInclusiveAmt as TaxInclusiveAmt,p.TaxValue as TaxValue,p.TaxAmt as TaxAmt,p.TaxID as TaxID
        from POLine p
        inner join ItemSpec s on p.SKUID=s.SKUID
        inner join ItemMaster m on s.ItemID=m.ItemID
        WHERE p.OrderNumber=?
        order by p.LineNumber")
            .Attach(typeof(POLine)).Attach(typeof(ItemSpec)).Attach(typeof(ItemMaster))
            .SetValue(0, this.OrderNumber, "p.OrderNumber");
        DataSet ds = query.DataSet();
        this.rptPL.DataSource = ds;
        this.rptPL.DataBind();

        int number = 0;
        foreach (DataRow row in ds.Tables[0].Rows)
            number += Cast.Int(row["PurchaseQty"]);
        this.lblTotalQty.Text = number.ToString();
    }
Пример #10
0
        public bool ReceiveFinish(ISession session, decimal rcvQty, decimal iqcQty)
        {
            //使用DbSession,避免并发冲突
            if (rcvQty == 0M && iqcQty == 0M)
            {
                return(true);
            }
            if (this._lineStatus != POLineStatus.Open)
            {
                throw new Exception(string.Format("订单行({0}-{1})不是Open状态,无法进行收货", this._orderNumber, this._lineNumber));
            }
            DbSession dbSession = session.DbSession as DbSession;

            System.Text.StringBuilder builder = new System.Text.StringBuilder();
            builder.Append("update ")
            .Append(EntityManager.GetEntityMapping(typeof(POLine)).TableName)
            .Append(" set ")
            .Append(EntityManager.GetPropMapping(typeof(POLine), "UnfinishedReceiveQty").ColumnName)
            .Append("=")
            .Append(EntityManager.GetPropMapping(typeof(POLine), "UnfinishedReceiveQty").ColumnName)
            .Append("-:qty1,")
            .Append(EntityManager.GetPropMapping(typeof(POLine), "IQCQty").ColumnName)
            .Append("=")
            .Append(EntityManager.GetPropMapping(typeof(POLine), "IQCQty").ColumnName)
            .Append("+:qty2,")
            .Append(EntityManager.GetPropMapping(typeof(POLine), "ReceiveQty").ColumnName)
            .Append("=")
            .Append(EntityManager.GetPropMapping(typeof(POLine), "ReceiveQty").ColumnName)
            .Append("+:qty3 where ")
            .Append(EntityManager.GetPropMapping(typeof(POLine), "OrderNumber").ColumnName)
            .Append("=:ordNum and ")
            .Append(EntityManager.GetPropMapping(typeof(POLine), "LineNumber").ColumnName)
            .Append("=:lineNum");
            IDbCommand command = dbSession.CreateSqlStringCommand(builder.ToString());

            dbSession.AddParameter(command, ":qty1", EntityManager.GetPropMapping(typeof(POLine), "UnfinishedReceiveQty").DbTypeInfo, iqcQty);
            dbSession.AddParameter(command, ":qty2", EntityManager.GetPropMapping(typeof(POLine), "IQCQty").DbTypeInfo, iqcQty);
            dbSession.AddParameter(command, ":qty3", EntityManager.GetPropMapping(typeof(POLine), "ReceiveQty").DbTypeInfo, rcvQty);
            dbSession.AddParameter(command, ":ordNum", EntityManager.GetPropMapping(typeof(POLine), "OrderNumber").DbTypeInfo, this._orderNumber);
            dbSession.AddParameter(command, ":lineNum", EntityManager.GetPropMapping(typeof(POLine), "LineNumber").DbTypeInfo, this._lineNumber);
            bool result = dbSession.ExecuteNonQuery(command) > 0;

            //尝试自动关闭PO行,PO
            if (this._receiveQty + rcvQty >= this._purchaseQty)
            {
                //收货数量大于等于采购数量,自动关闭PO行
                //TODO: 是否采用参数配置这个动作
                this._lineStatus = POLineStatus.Close;
                this.Update(session, "LineStatus");
                //所有PO行状态为关闭或取消,则自动关闭PO
                if (session.CreateEntityQuery <POLine>()
                    .Where(Exp.Eq("OrderNumber", this._orderNumber) & Exp.Eq("LineStatus", POLineStatus.Open))
                    .Count() <= 0)
                {
                    POHead head = POHead.Retrieve(session, this._orderNumber);
                    if (head != null)
                    {
                        head.Status = POStatus.Close;
                        head.Update(session, "Status");
                    }
                }
            }

            return(true);
        }