Ejemplo n.º 1
0
        /// <summary>
        /// 更新预售订单
        /// </summary>
        /// <param name="User"></param>
        /// <param name="OrderInfo"></param>
        /// <param name="ErrorInfo"></param>
        /// <returns></returns>
        public static int Order_Update(UserInfo User, Order OrderInfo, out string ErrorInfo)
        {
            ErrorInfo = "";
            LogWriter.WriteLog("PBMIFService.Order_Update:UserName="******",OrderInfo=" + JsonConvert.SerializeObject(OrderInfo));

            if (OrderInfo.ID == 0) { ErrorInfo = "销售订单不存在,请先新增销售订单!"; return -1; }

            PBM_OrderBLL bll = new PBM_OrderBLL(OrderInfo.ID);
            if (bll.Model == null) { ErrorInfo = "订货单不存在,请先新增订货单!"; return -1; }
            if (bll.Model.State > 1 || bll.Model.ApproveFlag == 1) { ErrorInfo = "订货单状态不允许执行此操作!"; return -1; }

            if (bll.Model.Supplier == 0) bll.Model.Supplier = OrderInfo.Supplier;
            if (bll.Model.Client == 0) bll.Model.Client = OrderInfo.Client;

            //默认业务人员为当前员工
            if (OrderInfo.SalesMan == 0) OrderInfo.SalesMan = User.StaffID;

            #region 必填字段校验
            if (bll.Model.Supplier == 0) { ErrorInfo = "无效的供货客户!"; return -2; }
            if (User.OwnerType == 3 && bll.Model.Supplier != User.ClientID) { ErrorInfo = "无效的供货客户!"; return -2; }
            if (bll.Model.Client == 0) { ErrorInfo = "无效的购买客户!"; return -2; }

            if (OrderInfo.Items == null || OrderInfo.Items.Count == 0) { ErrorInfo = "无订货产品明细!"; return -10; }
            #endregion

            #region 保存订货单头信息
            bll.Model.SalesMan = OrderInfo.SalesMan;
            bll.Model.WipeAmount = OrderInfo.WipeAmount;
            bll.Model.ArriveTime = OrderInfo.ArriveTime < DateTime.Today ? DateTime.Today.AddDays(1) : OrderInfo.ArriveTime;
            bll.Model.WorkList = OrderInfo.WorkList;
            bll.Model.Remark = OrderInfo.Remark;
            #endregion

            #region 循环处理每个订单明细
            foreach (Order.OrderDetail item in OrderInfo.Items)
            {
                if (item.Product == 0) continue;
                if (item.BookQuantity <= 0 && item.ConfirmQuantity <= 0)
                {
                    if (item.DetailID == 0)
                        continue;
                    else
                        bll.DeleteDetail(item.DetailID);
                }

                int quantity = item.BookQuantity == 0 ? item.ConfirmQuantity : item.BookQuantity;

                string remark = item.Remark;

                PDT_ProductBLL productbll = new PDT_ProductBLL(item.Product);
                if (productbll.Model == null) { ErrorInfo = "无效产品项,产品ID:" + item.Product; return -11; }
                PDT_ProductExtInfo extinfo = productbll.GetProductExtInfo(bll.Model.Supplier);
                if (productbll.Model == null) { ErrorInfo = "产品不在销售商的经营目录中," + productbll.Model.FullName; return -11; }

                if (item.DetailID > 0)
                {
                    PBM_OrderDetail d = bll.GetDetailModel(item.DetailID);

                    d.ConvertFactor = productbll.Model.ConvertFactor == 0 ? 1 : productbll.Model.ConvertFactor;
                    d.BookQuantity = quantity;
                    d.ConfirmQuantity = quantity;
                    d.Remark = item.Remark;
                    bll.UpdateDetail(d);
                }
                else
                {
                    #region 新增商品明细品项
                    PBM_OrderDetail d = new PBM_OrderDetail();

                    d.Product = item.Product;
                    d.SalesMode = item.SalesMode == 0 ? 1 : item.SalesMode;     //默认为“销售”

                    d.Price = PDT_StandardPriceBLL.GetSalePrice(bll.Model.Client, bll.Model.Supplier, d.Product);
                    if (d.SalesMode == 1)
                        d.DiscountRate = (item.DiscountRate <= 0 || item.DiscountRate > 1) ? 1 : item.DiscountRate;
                    else
                        d.DiscountRate = 0;

                    d.BookQuantity = quantity;
                    d.ConfirmQuantity = d.BookQuantity;
                    d.Remark = item.Remark;

                    bll.AddDetail(d);
                    #endregion
                }
            }
            #endregion

            //计算折扣金额
            bll.Model.DiscountAmount = bll.Items.Sum(p => (1 - p.DiscountRate) *
                Math.Round(p.Price * p.ConvertFactor, 2) * p.ConfirmQuantity / p.ConvertFactor);

            //计算实际销售金额
            bll.Model.ActAmount = Math.Round((bll.Model.Classify == 2 ? -1 : 1) *
                bll.Items.Sum(p => p.DiscountRate * Math.Round(p.Price * p.ConvertFactor, 2) * p.ConfirmQuantity / p.ConvertFactor)
                - bll.Model.WipeAmount, 2);

            int ret = bll.Update();
            if (ret < 0) { ErrorInfo = "订货单保存失败!"; return ret; }

            return 0;
        }
    protected void bt_AddDetail_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] == 0) return;
        PBM_OrderBLL _bll = new PBM_OrderBLL((int)ViewState["ID"]);

        if (ViewState["Details"] == null) return;
        ListTable<PBM_OrderDetail> Details = (ListTable<PBM_OrderDetail>)ViewState["Details"];

        int product = 0;
        int.TryParse(select_Product.SelectValue, out product);
        //int.TryParse(RadComboBox1.SelectedValue, out product);
        if (product != 0)
        {
            PDT_ProductBLL productbll = new PDT_ProductBLL(product, true);
            if (productbll.Model == null) return;
            if (productbll.Model.ConvertFactor == 0)
            {
                productbll.Model.ConvertFactor = 1;
                productbll.Update();
            }

            int quantity = 0;
            decimal price = 0;

            int.TryParse(tbx_Quantity.Text, out quantity);
            decimal.TryParse(tbx_Price.Text, out price);

            if (ddl_Unit.SelectedValue == "T")
            {
                //整件单位
                quantity = quantity * productbll.Model.ConvertFactor;
                price = price / productbll.Model.ConvertFactor;
            }

            if (quantity == 0)
            {
                MessageBox.Show(this, "请填写数量!");
                return;
            }

            PBM_OrderDetail d = null;

            if (ViewState["SelectedDetail"] != null)
            {
                d = (PBM_OrderDetail)ViewState["SelectedDetail"];
            }
            else
            {
                d = new PBM_OrderDetail();
                d.OrderID = (int)ViewState["ID"];

                if (Details.GetListItem().Count == 0)
                    d.ID = 1;
                else
                    d.ID = Details.GetListItem().Max(p => p.ID) + 1;
            }

            d.Product = product;
            d.Price = price;                    //实际销售价
            d.DiscountRate = 1;                 //默认全价
            d.ConvertFactor = productbll.Model.ConvertFactor;
            d.BookQuantity = quantity;
            d.ConfirmQuantity = quantity;
            d.DeliveredQuantity = 0;
            d.SalesMode = int.Parse(ddl_SalesMode.SelectedValue);
            if (d.SalesMode == 2)
            { d.Price = 0; }

            if (ViewState["SelectedDetail"] != null)
            {
                Details.Update(d);
                ViewState["SelectedDetail"] = null;
                bt_AddDetail.Text = "新 增";
                gv_List.SelectedIndex = -1;
            }
            else
            {
                Details.Add(d);
            }

            tbx_Quantity.Text = "0";

            BindGrid();
        }
    }
Ejemplo n.º 3
0
        /// <summary>
        /// 新增预售订单
        /// </summary>
        /// <param name="User"></param>
        /// <param name="OrderInfo">发货单信息</param>
        /// <param name="ErrorInfo">出错消息</param>
        /// <returns></returns>
        public static int Order_Add(UserInfo User, Order OrderInfo, out string ErrorInfo)
        {
            ErrorInfo = "";
            LogWriter.WriteLog("PBMIFService.Order_Add:UserName="******",OrderInfo=" + JsonConvert.SerializeObject(OrderInfo));

            //经销商级人员,供货商只能是自己所属的经销商
            if (User.OwnerType == 3) OrderInfo.Supplier = User.ClientID;

            //默认业务人员为当前员工
            if (OrderInfo.SalesMan == 0) OrderInfo.SalesMan = User.StaffID;

            #region 必填字段校验
            if (OrderInfo.Supplier == 0) { ErrorInfo = "无效的供货客户!"; return -2; }
            if (OrderInfo.Client == 0) { ErrorInfo = "无效的购买客户!"; return -2; }
            if (OrderInfo.Items == null || OrderInfo.Items.Count == 0) { ErrorInfo = "无销售产品明细!"; return -10; }
            #endregion

            PBM_OrderBLL bll = new PBM_OrderBLL();

            #region 保存销售单头信息
            bll.Model.SheetCode = "";
            bll.Model.Supplier = OrderInfo.Supplier;
            bll.Model.Client = OrderInfo.Client;
            bll.Model.SalesMan = OrderInfo.SalesMan;
            bll.Model.Classify = (OrderInfo.Classify == 0 ? 1 : OrderInfo.Classify);              //默认销售单
            bll.Model.State = 1;        //默认制单状态
            bll.Model.StandardPrice = OrderInfo.StandardPrice;

            bll.Model.WipeAmount = OrderInfo.WipeAmount;
            bll.Model.ArriveTime = OrderInfo.ArriveTime < DateTime.Today ? DateTime.Today.AddDays(1) : OrderInfo.ArriveTime;
            bll.Model.WorkList = OrderInfo.WorkList;
            bll.Model.Remark = OrderInfo.Remark;
            bll.Model.ApproveFlag = 2;
            bll.Model.InsertStaff = User.StaffID;

            //订单来源
            bll.Model["OrderSource"] = OrderInfo.OrderSource > 0 ? OrderInfo.OrderSource.ToString() : "2";

            #endregion

            #region 循环处理每个订单明细
            foreach (Order.OrderDetail item in OrderInfo.Items)
            {
                if (item.Product == 0) continue;
                if (item.BookQuantity <= 0 && item.ConfirmQuantity <= 0) continue;

                int bookquantity = item.BookQuantity <= 0 ? item.ConfirmQuantity : item.BookQuantity;

                PDT_ProductBLL productbll = new PDT_ProductBLL(item.Product);
                if (productbll.Model == null) { ErrorInfo = "无效产品项,产品ID:" + item.Product; return -11; }
                PDT_ProductExtInfo extinfo = productbll.GetProductExtInfo(bll.Model.Supplier);
                if (productbll.Model == null) { ErrorInfo = "产品不在销售商的经营目录中," + productbll.Model.FullName; return -11; }

                #region 新增商品明细
                PBM_OrderDetail d = new PBM_OrderDetail();

                d.Product = item.Product;
                d.SalesMode = item.SalesMode == 0 ? 1 : item.SalesMode;     //默认为“销售”

                if (item.Price > 0)
                    d.Price = item.Price;
                else
                    d.Price = PDT_StandardPriceBLL.GetSalePrice(bll.Model.Client, bll.Model.Supplier, d.Product);       //默认销售价

                if (d.SalesMode == 1)
                    d.DiscountRate = (item.DiscountRate <= 0 || item.DiscountRate > 1) ? 1 : item.DiscountRate;
                else
                    d.DiscountRate = 0;     //非销售时,0折销售

                d.ConvertFactor = productbll.Model.ConvertFactor == 0 ? 1 : productbll.Model.ConvertFactor;
                d.BookQuantity = bookquantity;
                d.ConfirmQuantity = d.BookQuantity;
                d.Remark = item.Remark;

                bll.Items.Add(d);
                #endregion
            }
            #endregion

            //计算折扣金额
            bll.Model.DiscountAmount = bll.Items.Sum(p => (1 - p.DiscountRate) *
                Math.Round(p.Price * p.ConvertFactor, 2) * p.ConfirmQuantity / p.ConvertFactor);

            //计算实际销售金额
            bll.Model.ActAmount = Math.Round((bll.Model.Classify == 2 ? -1 : 1) *
                bll.Items.Sum(p => p.DiscountRate * Math.Round(p.Price * p.ConvertFactor, 2) * p.ConfirmQuantity / p.ConvertFactor)
                - bll.Model.WipeAmount, 2);

            int orderid = bll.Add();
            if (orderid <= 0) { ErrorInfo = "销售订单保存失败!"; return orderid; }

            #region 判断订单是否直接提交
            if (OrderInfo.State == 2)
            {
                LogWriter.WriteLog("PBMIFService.Order_Add:UserName="******",OrderID=" + orderid.ToString() + ",Auto submit order!");
                Order OutOrderInfo;
                if (OrderInfo.PayInfos == null) OrderInfo.PayInfos = new List<Order.OrderPayInfo>();
                int ret = Order_Submit(User, orderid, OrderInfo.WipeAmount, OrderInfo.PayInfos, out OutOrderInfo, out ErrorInfo);
                if (ret < 0)
                {
                    LogWriter.WriteLog("PBMIFService.Order_Add:UserName="******",OrderID=" + orderid.ToString() +
                        ",Auto submit failed!ErrorInfo=" + ErrorInfo);
                    return ret;
                }
            }
            #endregion

            return orderid;
        }
Ejemplo n.º 4
0
            public OrderDetail(PBM_OrderDetail m)
            {
                DetailID = m.ID;
                Product = m.Product;
                Price = m.Price;
                DiscountRate = m.DiscountRate;
                BookQuantity = m.BookQuantity;
                ConfirmQuantity = m.ConfirmQuantity;
                DeliveredQuantity = m.DeliveredQuantity;
                Remark = m.Remark;

                PDT_Product p = new PDT_ProductBLL(Product).Model;
                if (p == null) return;

                ProductName = p.ShortName;

                if (p.ConvertFactor == 0) p.ConvertFactor = 1;
                ConvertFactor = p.ConvertFactor;

                if (p.Category > 0)
                {
                    CategoryName = PDT_CategoryBLL.GetFullCategoryName(p.Category);
                }

                #region 获取字典表名称
                try
                {
                    if (m.SalesMode > 0)
                    {
                        Dictionary_Data dic = DictionaryBLL.GetDicCollections("PBM_SalseMode")[m.SalesMode.ToString()];
                        if (dic != null) SalesModeName = dic.Name;
                    }
                    if (p.TrafficPackaging > 0)
                    {
                        PackingName_T = DictionaryBLL.GetDicCollections("PDT_Packaging")[p.TrafficPackaging.ToString()].ToString();
                    }
                    if (p.Packaging > 0)
                    {
                        PackingName_P = DictionaryBLL.GetDicCollections("PDT_Packaging")[p.Packaging.ToString()].ToString();
                    }
                }
                catch (System.Exception err)
                {
                    LogWriter.WriteLog("MCSFramework.WSI.OrderDetail", err);
                }
                #endregion
            }