예제 #1
0
        /// <summary>
        /// 移库调拨申请
        /// </summary>
        /// <param name="User"></param>
        /// <param name="DeliveryInfo">移库单信息</param>
        /// <param name="ErrorInfo">出错消息</param>
        /// <returns></returns>
        public static int TransWithVehicle(UserInfo User, Delivery DeliveryInfo, out string ErrorInfo)
        {
            ErrorInfo = "";
            LogWriter.WriteLog("PBMIFService.TransWithVehicle:UserName="******",DeliveryInfo=" + JsonConvert.SerializeObject(DeliveryInfo));

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

            if (DeliveryInfo.Classify != 5 && DeliveryInfo.Classify != 6)
            {
                ErrorInfo = "单据类别无效";
                return -1;
            }

            #region 根据车辆设置调入或调出车仓库
            //如果有送货车辆,默认出货仓库为该车辆所关联仓库
            if (DeliveryInfo.DeliveryVehicle != 0)
            {
                CM_Vehicle v = new CM_VehicleBLL(DeliveryInfo.DeliveryVehicle).Model;
                if (v == null) { ErrorInfo = "送货车辆无效!"; return -1; }

                if (DeliveryInfo.Classify == 5)
                {
                    //车销移库
                    DeliveryInfo.ClientWareHouse = v.RelateWareHouse;
                }
                else if (DeliveryInfo.Classify == 6)
                {
                    //车销退库
                    DeliveryInfo.SupplierWareHouse = v.RelateWareHouse;
                }
            }
            #endregion

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

            #region 必填字段校验
            if (DeliveryInfo.Supplier == 0 && DeliveryInfo.SupplierWareHouse != 0)
            {
                DeliveryInfo.Supplier = new CM_WareHouseBLL(DeliveryInfo.SupplierWareHouse).Model.Client;
            }
            if (DeliveryInfo.Supplier == 0) { ErrorInfo = "无效的客户!"; return -2; }
            if (DeliveryInfo.SupplierWareHouse == 0) { ErrorInfo = "无效的调出仓库!"; return -2; }
            if (DeliveryInfo.Client == 0) { DeliveryInfo.Client = DeliveryInfo.Supplier; }
            if (DeliveryInfo.ClientWareHouse == 0) { ErrorInfo = "无效的调入仓库!"; return -2; }
            if (DeliveryInfo.Items == null || DeliveryInfo.Items.Count == 0) { ErrorInfo = "无调拨产品明细!"; return -10; }
            #endregion

            PBM_DeliveryBLL bll = new PBM_DeliveryBLL();

            #region 保存发货单头信息
            bll.Model.SheetCode = "";
            bll.Model.Supplier = DeliveryInfo.Supplier;
            bll.Model.SupplierWareHouse = DeliveryInfo.SupplierWareHouse;
            bll.Model.Client = DeliveryInfo.Client;
            bll.Model.ClientWareHouse = DeliveryInfo.ClientWareHouse;
            bll.Model.Classify = DeliveryInfo.Classify;              //5:车销移库 6:车销退库
            bll.Model.SalesMan = User.StaffID;
            bll.Model.PrepareMode = 1;           //1:快捷模式
            bll.Model.State = 1;                 //默认制单状态
            bll.Model.DeliveryVehicle = DeliveryInfo.DeliveryVehicle;
            bll.Model.Remark = DeliveryInfo.Remark;
            bll.Model.ApproveFlag = 2;
            bll.Model.InsertStaff = User.StaffID;
            #endregion

            #region 循环处理每个发货单明细
            foreach (Delivery.DeliveryDetail item in DeliveryInfo.Items)
            {
                if (item.Product == 0) continue;
                if (item.DeliveryQuantity <= 0 && item.SignInQuantity <= 0) continue;

                string lotnumber = item.LotNumber.Trim();
                int quantity = item.DeliveryQuantity <= 0 ? item.SignInQuantity : item.DeliveryQuantity;

                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; }

                //判断库存是否够销售
                int inv_quantity = INV_InventoryBLL.GetProductQuantity(bll.Model.SupplierWareHouse, item.Product, lotnumber);
                if (quantity > inv_quantity)
                {
                    ErrorInfo = "产品[" + productbll.Model.FullName + "]库存不足,当前库存:" + inv_quantity.ToString();
                    return -11;
                }

                #region 新增库存明细
                PBM_DeliveryDetail d = new PBM_DeliveryDetail();

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

                d.Price = extinfo.SalesPrice;       //默认销售价
                d.DiscountRate = 1;

                d.ConvertFactor = productbll.Model.ConvertFactor == 0 ? 1 : productbll.Model.ConvertFactor;
                d.DeliveryQuantity = quantity;
                d.SignInQuantity = d.DeliveryQuantity;
                d.Remark = item.Remark;

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

            //计算折扣金额
            bll.Model.DiscountAmount = 0;
            bll.Model.WipeAmount = 0;

            //计算实际销售金额
            bll.Model.ActAmount = Math.Round(bll.Items.Sum(p => Math.Round(p.Price * p.ConvertFactor, 2) * p.SignInQuantity / p.ConvertFactor), 2);

            int ret = bll.Add();
            if (ret <= 0) { ErrorInfo = "销售单保存失败!"; return ret; }
            return ret;
        }
예제 #2
0
        /// <summary>
        /// 提交销售单,并输出提交后的订单信息
        /// </summary>
        /// <param name="User"></param>
        /// <param name="DeliveryID">销售单ID</param>
        /// <param name="DeliveryInfo">输出:销售单结构</param>
        /// <param name="ErrorInfo">输出:出错信息</param>
        /// <returns>0:成功 小于0:失败</returns>
        public static int SaleOut_Submit(UserInfo User, int DeliveryID, out Delivery DeliveryInfo, out string ErrorInfo)
        {
            ErrorInfo = "";
            DeliveryInfo = null;
            LogWriter.WriteLog("PBMIFService.SaleOut_Submit:UserName="******",DeliveryID=" + DeliveryID.ToString());

            if (DeliveryID <= 0) { ErrorInfo = "销售单ID无效"; return -1; }

            PBM_DeliveryBLL bll = new PBM_DeliveryBLL(DeliveryID);
            if (bll.Model == null) { ErrorInfo = "销售单ID无效"; return -1; }
            if (bll.Model.State > 3 || bll.Model.ApproveFlag == 1) { ErrorInfo = "销售单状态无效"; return -1; }

            if (User.OwnerType == 3 && bll.Model.Supplier != User.ClientID) { ErrorInfo = "不可提交该销售单"; return -2; }

            int ret = bll.Approve();
            if (ret < 0) { ErrorInfo = "销售单提交失败!"; return -1; }

            DeliveryInfo = new Delivery(bll.Model.ID);
            return 0;
        }
예제 #3
0
        /// <summary>
        /// 验证销售单,当在执行预售送货时,或在收款单变更了销售单明细时,需要调用此接口更新销售单
        /// </summary>
        /// <param name="User"></param>
        /// <param name="DeliveryInfo"></param>
        /// <param name="ErrorInfo"></param>
        /// <returns></returns>
        public static int SaleOut_Update(UserInfo User, Delivery DeliveryInfo, out string ErrorInfo)
        {
            ErrorInfo = "";
            LogWriter.WriteLog("PBMIFService.SaleOut_Update:UserName="******",DeliveryInfo=" + JsonConvert.SerializeObject(DeliveryInfo));

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

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

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

            //如果有送货车辆,默认出货仓库为该车辆所关联仓库
            if (DeliveryInfo.DeliveryVehicle != 0 && DeliveryInfo.SupplierWareHouse == 0)
            {
                CM_Vehicle v = new CM_VehicleBLL(DeliveryInfo.DeliveryVehicle).Model;
                if (v == null) { ErrorInfo = "送货车辆无效!"; return -1; }

                DeliveryInfo.SupplierWareHouse = v.RelateWareHouse;
            }

            //默认业务人员为当前员工
            if (DeliveryInfo.SalesMan == 0) DeliveryInfo.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 (DeliveryInfo.SupplierWareHouse == 0) { ErrorInfo = "无效的供货仓库!"; return -2; }
            if (DeliveryInfo.Items == null || DeliveryInfo.Items.Count == 0) { ErrorInfo = "无销售产品明细!"; return -10; }
            #endregion

            #region 保存销售单头信息
            bll.Model.SalesMan = DeliveryInfo.SalesMan;
            bll.Model.DeliveryVehicle = DeliveryInfo.DeliveryVehicle;
            bll.Model.SupplierWareHouse = DeliveryInfo.SupplierWareHouse;
            bll.Model.WipeAmount = DeliveryInfo.WipeAmount;

            bll.Model.WorkList = DeliveryInfo.WorkList;
            bll.Model.Remark = DeliveryInfo.Remark;
            #endregion

            #region 循环处理每个订单明细
            foreach (Delivery.DeliveryDetail item in DeliveryInfo.Items)
            {
                if (item.Product == 0) continue;
                if (item.DeliveryQuantity <= 0 && item.SignInQuantity <= 0)
                {
                    if (item.DetailID == 0)
                        continue;
                    else
                        bll.DeleteDetail(item.DetailID);
                }

                string lotnumber = item.LotNumber.Trim();

                int quantity = 0;
                if (bll.Model.State == 1)
                    quantity = item.DeliveryQuantity == 0 ? item.SignInQuantity : item.DeliveryQuantity;
                else
                    quantity = item.SignInQuantity;

                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 (bll.Model.Classify != 2)
                {
                    //不为退货单时,判断车库存是否够销售
                    int inv_quantity = INV_InventoryBLL.GetProductQuantity(bll.Model.SupplierWareHouse, item.Product, lotnumber);
                    if (quantity > inv_quantity)
                    {
                        ErrorInfo = "产品[" + productbll.Model.FullName + "]库存不足,当前库存:" + inv_quantity.ToString();
                        return -11;
                    }
                }

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

                    if (bll.Model.State == 1) d.DeliveryQuantity = quantity;
                    d.SignInQuantity = item.SignInQuantity;
                    d.LotNumber = lotnumber;
                    d.Remark = item.Remark;
                    bll.UpdateDetail(d);
                }
                else
                {
                    #region 新增商品明细品项
                    PBM_DeliveryDetail d = new PBM_DeliveryDetail();

                    d.Product = item.Product;
                    d.LotNumber = lotnumber;
                    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.ConvertFactor = productbll.Model.ConvertFactor == 0 ? 1 : productbll.Model.ConvertFactor;
                    d.DeliveryQuantity = item.DeliveryQuantity;
                    d.SignInQuantity = d.DeliveryQuantity;
                    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.SignInQuantity / 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.SignInQuantity / p.ConvertFactor)
                - bll.Model.WipeAmount, 2);

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

            return 0;
        }
예제 #4
0
        /// <summary>
        /// 新增销售发货单
        /// </summary>
        /// <param name="User"></param>
        /// <param name="DeliveryInfo">发货单信息</param>
        /// <param name="ErrorInfo">出错消息</param>
        /// <returns></returns>
        public static int SaleOut_Add(UserInfo User, Delivery DeliveryInfo, out string ErrorInfo)
        {
            ErrorInfo = "";
            LogWriter.WriteLog("PBMIFService.SaleOut_Add:UserName="******",DeliveryInfo=" + JsonConvert.SerializeObject(DeliveryInfo));

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

            //如果有送货车辆,默认出货仓库为该车辆所关联仓库
            if (DeliveryInfo.DeliveryVehicle != 0 && DeliveryInfo.SupplierWareHouse == 0)
            {
                CM_Vehicle v = new CM_VehicleBLL(DeliveryInfo.DeliveryVehicle).Model;
                if (v == null) { ErrorInfo = "送货车辆无效!"; return -1; }

                DeliveryInfo.SupplierWareHouse = v.RelateWareHouse;
            }

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

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

            PBM_DeliveryBLL bll = new PBM_DeliveryBLL();

            #region 保存销售单头信息
            bll.Model.SheetCode = "";
            bll.Model.Supplier = DeliveryInfo.Supplier;
            bll.Model.SupplierWareHouse = DeliveryInfo.SupplierWareHouse;
            bll.Model.Client = DeliveryInfo.Client;
            bll.Model.SalesMan = DeliveryInfo.SalesMan;
            bll.Model.Classify = (DeliveryInfo.Classify == 0 ? 1 : DeliveryInfo.Classify);              //默认销售单
            bll.Model.PrepareMode = (DeliveryInfo.PrepareMode == 0 ? 2 : DeliveryInfo.PrepareMode);     //默认车销模式
            bll.Model.State = 1;        //默认制单状态
            bll.Model.StandardPrice = DeliveryInfo.StandardPrice;
            bll.Model.OrderId = DeliveryInfo.OrderID;
            bll.Model.WipeAmount = DeliveryInfo.WipeAmount;
            bll.Model.DeliveryVehicle = DeliveryInfo.DeliveryVehicle;
            bll.Model.WorkList = DeliveryInfo.WorkList;
            bll.Model.Remark = DeliveryInfo.Remark;
            bll.Model.ApproveFlag = 2;
            bll.Model.InsertStaff = User.StaffID;
            #endregion

            #region 循环处理每个订单明细
            foreach (Delivery.DeliveryDetail item in DeliveryInfo.Items)
            {
                if (item.Product == 0) continue;
                if (item.DeliveryQuantity <= 0 && item.SignInQuantity <= 0) continue;

                string lotnumber = item.LotNumber.Trim();
                int deliveryquantity = item.DeliveryQuantity <= 0 ? item.SignInQuantity : item.DeliveryQuantity;

                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 (bll.Model.Classify != 2)
                {
                    //不为退货单时,判断车库存是否够销售
                    int inv_quantity = INV_InventoryBLL.GetProductQuantity(bll.Model.SupplierWareHouse, item.Product, lotnumber);
                    if (deliveryquantity > inv_quantity)
                    {
                        ErrorInfo = "产品[" + productbll.Model.FullName + "]库存不足,当前库存:" + inv_quantity.ToString();
                        return -11;
                    }
                }

                #region 新增销售明细
                PBM_DeliveryDetail d = new PBM_DeliveryDetail();

                d.Product = item.Product;
                d.LotNumber = lotnumber;
                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.DeliveryQuantity = deliveryquantity;
                d.SignInQuantity = d.DeliveryQuantity;
                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.DeliveryQuantity / 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.SignInQuantity / p.ConvertFactor)
                - bll.Model.WipeAmount, 2);

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

            #region 销售单直接完成
            if (DeliveryInfo.State == 4 && DeliveryInfo.PayInfos != null && DeliveryInfo.PayInfos.Count > 0)
            {
                LogWriter.WriteLog("PBMIFService.SaleOut_Add:UserName="******",DeliveryID=" + deliveryid.ToString() + ",Auto submit order!");
                int ret = SaleOut_Confirm(User, deliveryid, DeliveryInfo.WipeAmount, DeliveryInfo.PayInfos, out ErrorInfo);
                if (ret < 0)
                {
                    LogWriter.WriteLog("PBMIFService.SaleOut_Add:UserName="******",DeliveryID=" + deliveryid.ToString() +
                        ",Auto confirm failed!ErrorInfo=" + ErrorInfo);
                    return ret;
                }
            }
            #endregion

            return deliveryid;
        }