Пример #1
0
        /// <summary>
        /// 创建借货单
        /// </summary>
        /// <param name="model">借货单实体</param>
        /// <returns>受影响的行</returns>
        /// <remarks>2013-07-09 周唐炬 创建</remarks>
        public int CreateWhProductLend(WhProductLend model)
        {
            var price = decimal.Zero;
            var id    = IProductLendDao.Instance.CreateWhProductLend(model);

            if (id <= 0)
            {
                throw new HytException("创建借货单异常!");
            }
            CreateProductLendItem(id, model.DeliveryUserSysNo, model.CreatedBy, model.ItemList, ref price);
            //检查前台传入价格是否跟后台计算数据一致
            if (model.Amount != price)
            {
                model.Amount = price;
                UpdateWhProductLend(model);
            }
            //配送员借货额度结算
            DeliveryCreditCalculate(model.DeliveryUserSysNo, model.WarehouseSysNo, model.Amount, id);

            var borrowInfos = (from item in model.ItemList
                               let product = PdProductBo.Instance.GetProduct(item.ProductSysNo)                        //商品
                                             let warehouse = WhWarehouseBo.Instance.GetWarehouse(model.WarehouseSysNo) //仓库
                                                             where product != null && warehouse != null
                                                             select new BorrowInfo()
            {
                ErpCode = product.ErpCode,
                Quantity = item.LendQuantity,
                WarehouseNumber = warehouse.ErpCode,
                Amount = model.Amount,
                Remark = item.Remarks,
                WarehouseSysNo = model.WarehouseSysNo
            }).ToList();

            var syUser = SyUserBo.Instance.GetSyUser(model.DeliveryUserSysNo);
            var client = EasProviderFactory.CreateProvider();

            //销售出库接口的摘要格式:JC[Hyt借货单系统编号]-[借货员姓名]
            client.Borrow(borrowInfos, string.Format("JC[{0}]-[{1}]", id, syUser != null ? syUser.UserName : model.DeliveryUserSysNo.ToString()), id.ToString());

            return(id);
        }
Пример #2
0
        /// <summary>
        /// 补单
        /// </summary>
        /// <param name="model">补单实体</param>
        /// <param name="user">当前用户实体</param>
        /// <returns>true:成功,失败抛出异常</returns>
        /// <remarks>2013-07-16 黄伟 创建</remarks>
        /// <remarks>2013-11-15 周唐炬 加入商品借货、EAS业务、恢复配送员信用</remarks>
        private Result CreateOrder(ParaLogisticsControllerAdditionalOrders model, SyUser user)
        {
            var result = new Result {
                Status = false, StatusCode = -1, Message = "补单失败!"
            };
            var so          = new SoOrder();
            var currentTime = DateTime.Now;
            var client      = EasProviderFactory.CreateProvider();  //EAS Provider

            var borrowInfoGroupList = new List <BorrowInfoGroup>(); //EAS还货数据
            var saleInfoGroupList   = new List <SaleInfoGroup>();   //EAS出库分组数据
            var deliveryUser        = SyUserBo.Instance.GetSyUser(model.DeliverymanSysNo);

            #region 补单实体数据
            //保存收货地址
            var address          = model.ReceiveAddress;
            var soReceiveAddress = new SoReceiveAddress
            {
                AreaSysNo         = address.AreaSysNo,
                MobilePhoneNumber = address.MobilePhoneNumber,
                Name          = address.Name,
                PhoneNumber   = address.PhoneNumber,
                StreetAddress = address.Address,
                ZipCode       = address.ZipCode
            };
            //创建收货地址
            ISoReceiveAddressDao.Instance.InsertEntity(soReceiveAddress);

            so.ReceiveAddressSysNo = soReceiveAddress.SysNo;
            so.CustomerSysNo       = model.UserSysNo;
            so.LevelSysNo          = model.LevelSysNo;

            var deliveryType = GetDelTypeByNameLike("普通百城当日"); //普通百城当日
            so.DeliveryTypeSysNo = deliveryType.SysNo;
            so.Remarks           = so.DeliveryRemarks = "补单";
            so.DeliveryTime      = deliveryType.DeliveryTime; //全天

            so.PayTypeSysNo          = model.PaymentTypeSysNo;
            so.DefaultWarehouseSysNo = model.WarehouseSysNo;
            so.CreateDate            = currentTime;
            so.LastUpdateBy          = user.SysNo;
            so.LastUpdateDate        = currentTime;
            so.OrderCreatorSysNo     = user.SysNo;
            //order status related
            so.OrderSource      = (int)OrderStatus.销售单来源.业务员补单;
            so.OrderSourceSysNo = model.DeliverymanSysNo;
            so.PayStatus        = (int)OrderStatus.销售单支付状态.已支付;
            so.SalesSysNo       = 0;
            so.SalesType        = (int)OrderStatus.销售方式.普通订单;
            so.Status           = (int)OrderStatus.销售单状态.已完成;
            so.OnlineStatus     = Constant.OlineStatusType.已发货;

            //创建订单主表
            ISoOrderDao.Instance.InsertEntity(so);
            so = SoOrderBo.Instance.GetEntity(so.SysNo);
            var lstSoOrderItem = new List <SoOrderItem>();
            var soItems        = model.OrderInformations;
            #endregion

            //该商品配送员等级价总金额
            var deliveryPrice = decimal.Zero;

            foreach (var item in soItems)
            {
                var originalPrice = SoOrderBo.Instance.GetOriginalPrice(model.UserSysNo, item.ProductSysNo);
                var soItem        = new SoOrderItem()
                {
                    OrderSysNo           = so.SysNo,
                    OriginalPrice        = originalPrice,
                    ProductName          = item.ProductName,
                    ProductSysNo         = item.ProductSysNo,
                    TransactionSysNo     = so.TransactionSysNo,
                    Quantity             = item.ProductOrderNumber,
                    SalesAmount          = originalPrice * item.ProductOrderNumber,
                    RealStockOutQuantity = item.ProductOrderNumber,
                    ProductSalesType     = (int)CustomerStatus.商品销售类型.普通,
                    SalesUnitPrice       = originalPrice
                };
                so.OrderAmount += originalPrice * item.ProductOrderNumber;
                //创建订单明细
                soItem.SysNo = ISoOrderItemDao.Instance.Insert(soItem);
                lstSoOrderItem.Add(soItem);

                #region 计算商品配送员进货价
                var productLendItem = IProductLendDao.Instance.GetWhProductLendItemInfo(new ParaWhProductLendItemFilter()
                {
                    DeliveryUserSysNo = model.DeliverymanSysNo,
                    ProductSysNo      = item.ProductSysNo,
                    PriceSource       = ProductStatus.产品价格来源.配送员进货价.GetHashCode()
                });
                if (productLendItem != null)
                {
                    deliveryPrice += item.ProductOrderNumber * productLendItem.Price;
                }
                #endregion

                #region 修改借货数量
                //配送员补单的时候,eas 要做还货,然后再做销售出库
                //(即补单完成后,要先调用还货接口、再调用销售出库接口)
                ProductReturn(model.DeliverymanSysNo, item, user.SysNo);

                #endregion

                #region EAS业务数据

                var product = PdProductBo.Instance.GetProduct(item.ProductSysNo);
                if (product == null)
                {
                    continue;
                }
                //重新获取到包含信用等级价格的借货明细
                var productLend = IProductLendDao.Instance.GetWhProductLendItemInfo(new ParaWhProductLendItemFilter()
                {
                    ProductSysNo      = product.SysNo,
                    DeliveryUserSysNo = model.DeliverymanSysNo,
                    PriceSource       = ProductStatus.产品价格来源.配送员进货价.GetHashCode()
                });
                var    warehouse        = WhWarehouseBo.Instance.GetWarehouse(model.WarehouseSysNo);
                var    warehouseErpCode = string.Empty;
                string organizationCode = string.Empty;//组织机构代码
                if (warehouse != null)
                {
                    warehouseErpCode = warehouse.ErpCode;
                    var oraganization = OrganizationBo.Instance.GetOrganization(warehouse.SysNo);
                    if (oraganization != null)
                    {
                        organizationCode = oraganization.Code;
                    }
                }
                if (productLend == null)
                {
                    continue;
                }

                #region EAS还货数据

                var borrowInfoGroup = borrowInfoGroupList.SingleOrDefault(x => x.ProductLendSysNo == productLend.ProductLendSysNo) ?? new BorrowInfoGroup()
                {
                    ProductLendSysNo = productLend.ProductLendSysNo
                };
                var borrowInfo = new BorrowInfo()
                {
                    ErpCode         = product.ErpCode,
                    Quantity        = item.ProductOrderNumber,
                    WarehouseNumber = warehouseErpCode,
                    Amount          = productLend.Price,
                    Remark          = string.Empty,
                    WarehouseSysNo  = model.WarehouseSysNo
                };
                //入库单
                var stockin = IInStockDao.Instance.GetStockInBySource(WarehouseStatus.入库单据类型.借货单.GetHashCode(), productLend.SysNo);
                if (stockin != null)
                {
                    borrowInfoGroup.StockInSysno = stockin.SysNo;
                }
                borrowInfoGroup.BorrowInfoList.Add(borrowInfo);
                //添加到GroupList中
                if (borrowInfoGroupList.All(x => x.ProductLendSysNo != productLend.ProductLendSysNo))
                {
                    borrowInfoGroupList.Add(borrowInfoGroup);
                }
                #endregion

                #region EAS销售出库数据

                //根据借货单编号查询分组数据中的SaleInfo信息
                var saleInfoGroup = saleInfoGroupList.SingleOrDefault(x => x.ProductLendSysNo == productLend.ProductLendSysNo) ?? new SaleInfoGroup()
                {
                    ProductLendSysNo = productLend.ProductLendSysNo
                };
                var saleInfo = new SaleInfo()
                {
                    ErpCode          = product.ErpCode,
                    Quantity         = item.ProductOrderNumber,
                    WarehouseNumber  = warehouseErpCode,
                    WarehouseSysNo   = model.WarehouseSysNo,
                    OrganizationCode = organizationCode,
                    Amount           = originalPrice,
                    //销售出库接口的备注格式:JC[Hyt借货单系统编号]-[借货员姓名]-XS[Hyt订单号]
                    Remark = string.Format("JC[{0}]-[{1}]-XS[{2}],配送方式:百城当日达(补单)", saleInfoGroup.ProductLendSysNo, deliveryUser != null ? deliveryUser.UserName : model.DeliverymanSysNo.ToString(CultureInfo.InvariantCulture), so.SysNo)
                };
                saleInfoGroup.SaleInfoList.Add(saleInfo);
                //添加到Groups中
                if (saleInfoGroupList.All(x => x.ProductLendSysNo != productLend.ProductLendSysNo))
                {
                    saleInfoGroupList.Add(saleInfoGroup);
                }
                #endregion

                #endregion
            }
            #region 恢复配送员信用

            if (deliveryPrice > decimal.Zero)
            {
                DeliveryUserCreditBo.Instance.UpdateRemaining(model.WarehouseSysNo, model.DeliverymanSysNo, 0, deliveryPrice, "补单,单号:" + so.SysNo);
            }
            #endregion

            #region 更新订单、创建收款单、加入订单池、创建配送单配送在途
            //从接口调用金额计算
            so.CashPay = ISoOrderItemDao.Instance.SynchronousOrderAmount(so.SysNo);//同步订单价格
            //so.CashPay = so.OrderAmount; //订单现金支付金额

            //更新订单金额
            so.ProductAmount = so.OrderAmount;

            SoOrderBo.Instance.UpdateOrder(so); //更新订单 余勇修改为调用业务层方法 ISoOrderDao.Instance.Update(so);

            //创建订单收款单
            FnReceiptVoucherBo.Instance.CreateReceiptVoucherByOrder(so);
            SoOrderBo.Instance.WriteSoTransactionLog(so.TransactionSysNo
                                                     , string.Format(Constant.ORDER_TRANSACTIONLOG_CREATE, so.SysNo)
                                                     , user.UserName);
            //补单不用加入订单池
            //创建出库单已签收
            var stockOut = CreateOutStock(lstSoOrderItem, model.WarehouseSysNo, user);

            //配送方式
            var delivertType = DeliveryTypeBo.Instance.GetDeliveryType(so.DeliveryTypeSysNo);

            //创建配送单配送在途
            LgDeliveryBo.Instance.CreateLgDelivery(model.WarehouseSysNo, model.DeliverymanSysNo, delivertType,
                                                   user.SysNo, new List <LgDeliveryItem> {
                new LgDeliveryItem
                {
                    NoteType  = (int)LogisticsStatus.配送单据类型.出库单,
                    NoteSysNo = stockOut.SysNo,
                    ExpressNo = ""
                }
            }, true);

            #endregion

            #region EAS还货
            if (borrowInfoGroupList.Any())
            {
                //摘要:JC[Hyt借出编号]-[借货员姓名]-RK[Hyt入库编号]
                //(如果还货的商品在不同 借货单中,就以借货单明细分开调用)
                borrowInfoGroupList.ForEach(x =>
                {
                    if (x.BorrowInfoList.Count > 0)
                    {
                        client.Return(x.BorrowInfoList, string.Format("JC[{0}]-[{1}]-RK[{2}]", x.ProductLendSysNo,
                                                                      deliveryUser != null ? deliveryUser.UserName : model.DeliverymanSysNo.ToString(),
                                                                      x.StockInSysno), x.ProductLendSysNo.ToString());
                    }
                });
            }
            #endregion

            #region EAS出库
            if (saleInfoGroupList.Any())
            {
                saleInfoGroupList.ForEach(x =>
                {
                    if (x.SaleInfoList.Count > 0)
                    {
                        client.SaleOutStock(x.SaleInfoList, Extra.Erp.Model.EasConstant.HytCustomer, so.SysNo.ToString(), so.TransactionSysNo);
                    }
                });
            }
            #endregion

            //新增会员明细 2014-1-17 黄志勇 添加
            LgSettlementBo.Instance.WriteShopNewCustomerDetail(so.CustomerSysNo, stockOut.StockOutAmount);

            result.Status     = true;
            result.StatusCode = so.SysNo;
            result.Message    = "补单成功!";
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 借货还货EAS事务(其他出库单)
        /// </summary>
        /// <param name="model">入库实体</param>
        /// <remarks>2013-11-21 周唐炬 创建</remarks>
        private static void BorrowInfoTranslations(WhStockIn model)
        {
            List <BorrowInfo> borrowInfoList = null;

            if (model.ItemList != null && model.ItemList.Any())
            {
                borrowInfoList = new List <BorrowInfo>();
                //仓库
                var warehouse        = WhWarehouseBo.Instance.GetWarehouse(model.WarehouseSysNo);
                var warehouseErpCode = string.Empty;
                if (warehouse != null)
                {
                    warehouseErpCode = warehouse.ErpCode;
                }
                model.ItemList.ForEach(x =>
                {
                    #region 入库数写入仓库库存
                    var stock           = new PdProductStock();
                    stock.StockQuantity = x.RealStockInQuantity;
                    BLL.Warehouse.PdProductStockBo.Instance.SaveProductStock(stock, BLL.Authentication.AdminAuthenticationBo.Instance.Current.Base.SysNo);

                    ///添加调拨入库记录
                    WhWarehouseChangeLog log = new WhWarehouseChangeLog()
                    {
                        WareSysNo      = stock.WarehouseSysNo,
                        ProSysNo       = x.ProductSysNo,
                        ChageDate      = model.CreatedDate,
                        CreateDate     = DateTime.Now,
                        ChangeQuantity = Convert.ToInt32(x.RealStockInQuantity),
                        BusinessTypes  = "借货入库",
                        LogData        = "入库单号:" + model.TransactionSysNo
                    };
                    WhWarehouseChangeLogBo.Instance.CreateMod(log);
                    #endregion

                    var product = PdProductBo.Instance.GetProduct(x.ProductSysNo);
                    if (product == null)
                    {
                        return;
                    }
                    var price = decimal.Zero;

                    //借货单商品
                    var item = IProductLendDao.Instance.GetWhProductLendItemInfo(new ParaWhProductLendItemFilter()
                    {
                        ProductLendSysNo = model.SourceSysNO,
                        ProductSysNo     = x.ProductSysNo,
                        PriceSource      = (int)ProductStatus.产品价格来源.配送员进货价
                    });
                    if (item != null)
                    {
                        price = item.Price;
                    }

                    var borrowInfo = new BorrowInfo()
                    {
                        ErpCode         = product.ErpCode,
                        Quantity        = x.RealStockInQuantity,
                        WarehouseNumber = warehouseErpCode,
                        WarehouseSysNo  = model.WarehouseSysNo,
                        Amount          = price,
                        Remark          = model.Remarks
                    };
                    borrowInfoList.Add(borrowInfo);
                });
            }

            //获取摘要
            var userName    = string.Empty;
            var productLend = ProductLendBo.Instance.GetWhProductLend(model.SourceSysNO);
            if (productLend != null)
            {
                var syUser = SyUserBo.Instance.GetSyUser(productLend.DeliveryUserSysNo);
                if (syUser != null)
                {
                    userName = syUser.UserName;
                }
            }
            var description = string.Format("JC[{0}]-[{1}]-RK[{2}]", model.SourceSysNO, userName, model.SysNo);
            //借货调用借货入库,对应Eas其他出库单
            var client = EasProviderFactory.CreateProvider();
            client.Return(borrowInfoList, description, model.SourceSysNO.ToString());
        }