Exemplo n.º 1
0
        /// <summary>
        /// 接收申请单
        /// </summary>
        /// <param name="request">申请单信息</param>
        /// <returns>申请单信息</returns>
        public virtual RMARequestInfo Receive(RMARequestInfo request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request is required!");
            }
            if (!request.SysNo.HasValue)
            {
                throw new ArgumentNullException("request.SysNo is required!");
            }

            RMARequestInfo original = LoadWithRegistersBySysNo(request.SysNo.Value);

            request.VerifyReceive(original);

            original.ReceiveWarehouse = request.ReceiveWarehouse;
            original.ReceiveTime      = DateTime.Now;
            original.ReceiveUserSysNo = ServiceContext.Current.UserSysNo;
            //获取UI上需要的接收人名称
            original.ReceiveUserName  = ExternalDomainBroker.GetUserInfoBySysNo(original.ReceiveUserSysNo.Value);
            original.IsViaPostOffice  = request.IsViaPostOffice;
            original.PostageToPoint   = request.PostageToPoint;
            original.Status           = RMARequestStatus.Handling;
            original.CustomerSendTime = request.CustomerSendTime;
            original.ShipViaCode      = request.ShipViaCode;
            original.IsRejectRMA      = request.IsRejectRMA;
            original.TrackingNumber   = request.TrackingNumber;
            original.Phone            = request.Phone;
            original.Contact          = request.Contact;
            original.Address          = request.Address;
            original.ETakeDate        = request.ETakeDate;
            original.AreaSysNo        = request.AreaSysNo;
            original.Memo             = request.Memo;
            original.Note             = request.Note;
            original.IsReceiveMsg     = request.IsReceiveMsg;

            request.ReturnPoint = request.PostageToPoint;

            // data format:
            // { RegisterSysNo: [ HaveInvoice, IsFullAccessory, IsFullPackage ] }
            Dictionary <int, bool?[]> dic = new Dictionary <int, bool?[]>();

            request.Registers.ForEach(reg =>
            {
                dic.Add(
                    reg.BasicInfo.SysNo.Value,
                    new bool?[] { reg.BasicInfo.IsHaveInvoice, reg.BasicInfo.IsFullAccessory, reg.BasicInfo.IsFullPackage }
                    );
            });

            Dictionary <int, decimal> costs = GetSOItemsCost(request.SysNo.Value);
            bool isWithin7Days = IsWithin7Days(request.SOSysNo.Value, request.CustomerSendTime.Value);

            original.Registers.ForEach(reg =>
            {
                reg.BasicInfo.OwnBy             = RMAOwnBy.Customer;
                reg.BasicInfo.Location          = RMALocation.Self;
                reg.BasicInfo.LocationWarehouse = request.ReceiveWarehouse;
                reg.BasicInfo.OwnByWarehouse    = ((int)RMAOwnBy.Origin).ToString();
                reg.BasicInfo.Cost            = costs[reg.BasicInfo.ProductSysNo.Value];
                reg.BasicInfo.IsWithin7Days   = isWithin7Days;
                reg.BasicInfo.Status          = request.Status;
                reg.BasicInfo.IsHaveInvoice   = dic[reg.BasicInfo.SysNo.Value][0];
                reg.BasicInfo.IsFullAccessory = dic[reg.BasicInfo.SysNo.Value][1];
                reg.BasicInfo.IsFullPackage   = dic[reg.BasicInfo.SysNo.Value][2];
            });

            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                UpdateWithRegisters(original);

                UpdateInventory(original.Registers, true);

                scope.Complete();
            }

            var customer = ExternalDomainBroker.GetCustomerInfo(request.CustomerSysNo.Value);

            //SendEmail(customer.BasicInfo.Email, request.RequestID);

            ExternalDomainBroker.CreateOperationLog("RMA_Request_Recieve", BizLogType.RMA_Request_Receive, request.SysNo.Value, original.CompanyCode);

            return(original);
        }