Exemplo n.º 1
0
 public override async Task ApplyAsync(PaymentUse paymentUse)
 {
     await ApplyStageAsync(
         _logicMap.TryGetValue(paymentUse.PaymentInvoice.Tariff.Code, out var logic)
         ?logic.Invoke(paymentUse.PaymentInvoice.Request)
         : null, paymentUse.PaymentInvoice.Request);
 }
Exemplo n.º 2
0
        public void Execute(BoundPaymentDto boundPaymentDto)
        {
            var payment        = GetPayment(boundPaymentDto.PaymentId);
            var paymentInvoice = GetPaymentInvoice(boundPaymentDto.PaymentInvoiceId);
            var currentUser    = this.GetCurrentUser();

            var paymentUse = new PaymentUse
            {
                Payment        = payment,
                PaymentInvoice = paymentInvoice,
                Request        = paymentInvoice.Request,
                ProtectionDoc  = paymentInvoice.ProtectionDoc,
                Contract       = paymentInvoice.Contract,
                Amount         = boundPaymentDto.Amount,
                Description    = boundPaymentDto.Description,
                DateCreate     = DateTimeOffset.Now,
                EmployeeCheckoutPaymentName = currentUser.NameRu
            };

            payment.PaymentUseAmmountSumm = payment.PaymentUses.Sum(x => x.Amount) + paymentUse.Amount;
            Uow.GetRepository <Payment>().Update(paymentUse.Payment);

            Uow.GetRepository <PaymentUse>().Create(paymentUse);
            Uow.SaveChanges();
        }
Exemplo n.º 3
0
        public void Execute(PaymentUse paymentUse)
        {
            var paymentUseRepository = Uow.GetRepository <PaymentUse>();

            paymentUseRepository.Update(paymentUse);
            Uow.SaveChanges();
        }
Exemplo n.º 4
0
        private PaymentUse CreatePaymenUse(WtPlPaymentUse oldPayment)
        {
            try
            {
                var paymentUse = new PaymentUse
                {
                    Amount           = oldPayment.Amount,
                    DateCreate       = new DateTimeOffset(oldPayment.DateCreate.GetValueOrDefault(DateTime.Now)),
                    DateUpdate       = new DateTimeOffset(oldPayment.DateCreate.GetValueOrDefault(DateTime.Now)),
                    Description      = oldPayment.Dsc,
                    ExternalId       = oldPayment.Id,
                    PaymentId        = GetObjectId <Payment>(oldPayment.PaymentId),
                    PaymentInvoiceId = GetObjectId <PaymentInvoice>(oldPayment.FixId),
                    Timestamp        = BitConverter.GetBytes(DateTime.Now.Ticks),
                    BlockedAmount    = 0,
                    ReturnedAmount   = 0,
                    IsDeleted        = false
                };

                return(paymentUse);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        public int Execute(PaymentUse paymentUse)
        {
            var repo = Uow.GetRepository <PaymentUse>();

            repo.Create(paymentUse);
            Uow.SaveChanges();

            return(paymentUse.Id);
        }
Exemplo n.º 6
0
        private void FillPaymentUseEditInfo(PaymentUse paymentUse, EditPaymentUseRequestDto requestDto)
        {
            var user = _executor.GetQuery <GetUserByIdQuery>()
                       .Process(q => q.Execute(NiisAmbientContext.Current.User.Identity.UserId));

            paymentUse.EditClearedPaymentDate         = DateTimeOffset.Now;
            paymentUse.EditClearedPaymentEmployeeName = $"{user.NameRu} {user.Position?.NameRu}";
            paymentUse.EditClearedPaymentReason       = requestDto.EditReason;
        }
Exemplo n.º 7
0
        public void Execute(Owner.Type ownerType, PaymentUse paymentUse, bool force)
        {
            Executor.CommandChain()
            .AddCommand <CreditPaymentInvoiceCommand>(c => c.Execute(ownerType, paymentUse, force))
            .AddCommand <CreatePaymentUseCommand>(c => c.Execute(paymentUse))
            .ExecuteAllWithTransaction();

            Executor.GetCommand <UpdatePaymentStatusCommand>()
            .Process(c => c.Execute(paymentUse.PaymentId.Value));
        }
Exemplo n.º 8
0
        private bool IsPaymentInForeignCurrency(PaymentUse paymentUse)
        {
            if (paymentUse.PaymentId == null)
            {
                return(false);
            }

            var payment = _executor.GetQuery <GetPaymentByIdQuery>()
                          .Process(q => q.ExecuteAsync(paymentUse.PaymentId.Value)).Result;

            return(payment != null && payment.IsForeignCurrency);
        }
Exemplo n.º 9
0
        public int ExecuteSystem(PaymentUse paymentUse)
        {
            if (paymentUse.PaymentInvoiceId != null)
            {
                var paymentInvoice = _executor.GetQuery <GetPaymentInvoiceByIdQuery>()
                                     .Process(q => q.ExecuteAsync(paymentUse.PaymentInvoiceId.Value)).Result;

                paymentUse.RequestId       = paymentInvoice.Request?.Id;
                paymentUse.ProtectionDocId = paymentInvoice.ProtectionDoc?.Id;
                paymentUse.ContractId      = paymentInvoice.Contract?.Id;
            }

            paymentUse.DateOfPayment = DateTimeOffset.Now;
            paymentUse.EmployeeCheckoutPaymentName = "Автоимпорт";
            var paymentUseRepository = Uow.GetRepository <PaymentUse>();

            paymentUseRepository.Create(paymentUse);
            Uow.SaveChanges();
            return(paymentUse.Id);
        }
Exemplo n.º 10
0
        public int Execute(PaymentUse paymentUse)
        {
            if (paymentUse.PaymentInvoiceId != null)
            {
                var paymentInvoice = _executor.GetQuery <GetPaymentInvoiceByIdQuery>()
                                     .Process(q => q.ExecuteAsync(paymentUse.PaymentInvoiceId.Value)).Result;

                paymentUse.RequestId       = paymentInvoice.Request?.Id;
                paymentUse.ProtectionDocId = paymentInvoice.ProtectionDoc?.Id;
                paymentUse.ContractId      = paymentInvoice.Contract?.Id;
            }

            paymentUse.DateOfPayment = DateTimeOffset.Now;
            paymentUse.EmployeeCheckoutPaymentName = Uow.GetRepository <ApplicationUser>().GetById(NiisAmbientContext.Current.User.Identity.UserId)?.NameRu;
            var paymentUseRepository = Uow.GetRepository <PaymentUse>();

            paymentUseRepository.Create(paymentUse);
            Uow.SaveChanges();
            return(paymentUse.Id);
        }
Exemplo n.º 11
0
 public abstract Task ApplyAsync(PaymentUse paymentUse);
Exemplo n.º 12
0
        public void Execute(Owner.Type ownerType, PaymentUse paymentUse, bool force)
        {
            if (!paymentUse.PaymentInvoiceId.HasValue)
            {
                return;
            }

            var paymentInvoice = _executor.GetQuery <GetPaymentInvoiceByIdQuery>()
                                 .Process(q => q.ExecuteAsync(paymentUse.PaymentInvoiceId.Value)).Result;

            if (paymentInvoice == null)
            {
                return;
            }

            PaymentInvoiceDto paymentInvoiceDto;

            switch (ownerType)
            {
            case Owner.Type.Request:
                if (!paymentInvoice.RequestId.HasValue)
                {
                    throw new ArgumentNullException(nameof(paymentInvoice.RequestId));
                }

                var request = _executor.GetQuery <GetRequestByIdQuery>()
                              .Process(q => q.ExecuteAsync(paymentInvoice.RequestId.Value)).Result;
                paymentInvoiceDto = _mapper.Map <PaymentInvoice, PaymentInvoiceDto>(paymentInvoice,
                                                                                    opt => opt.Items["RequestCustomers"] = request.RequestCustomers);
                break;

            case Owner.Type.Contract:
                if (!paymentInvoice.ContractId.HasValue)
                {
                    throw new ArgumentNullException(nameof(paymentInvoice.ContractId));
                }

                var contract = _executor.GetQuery <GetContractByIdQuery>()
                               .Process(q => q.ExecuteAsync(paymentInvoice.ContractId.Value)).Result;
                paymentInvoiceDto = _mapper.Map <PaymentInvoice, PaymentInvoiceDto>(paymentInvoice,
                                                                                    opt => opt.Items["ContractCustomers"] = contract.ContractCustomers);
                break;

            case Owner.Type.ProtectionDoc:
                if (!paymentInvoice.ProtectionDocId.HasValue)
                {
                    throw new ArgumentNullException(nameof(paymentInvoice.ProtectionDocId));
                }

                var protectionDoc = _executor.GetQuery <GetProtectionDocByIdQuery>()
                                    .Process(q => q.ExecuteAsync(paymentInvoice.ProtectionDocId.Value)).Result;
                paymentInvoiceDto = _mapper.Map <PaymentInvoice, PaymentInvoiceDto>(paymentInvoice,
                                                                                    opt => opt.Items["ProtectionDocCustomers"] = protectionDoc.ProtectionDocCustomers);
                break;

            default:
                throw new ApplicationException(string.Empty,
                                               new ArgumentException($"{nameof(ownerType)}: {ownerType}"));
            }

            if (decimal.Round(paymentInvoiceDto.Remainder, 2) < decimal.Round(paymentUse.Amount, 2))
            {
                throw new OptimisticConcurrencyException("Using amount is bigger than remainder!");
            }

            var paymentRepository = Uow.GetRepository <Payment>();
            var payment           = paymentRepository
                                    .AsQueryable()
                                    .Include(p => p.PaymentUses)
                                    .First(p => p.Id == paymentUse.PaymentId.Value);

            var paymentDto = _mapper.Map <Payment, PaymentDto>(payment);

            if (decimal.Round(paymentDto.RemainderAmount, 2) < decimal.Round(paymentUse.Amount, 2))
            {
                throw new OptimisticConcurrencyException("Using amount is bigger than payment remainder!");
            }

            if (decimal.Round(paymentInvoiceDto.Remainder, 2) == decimal.Round(paymentUse.Amount, 2) || force && IsPaymentInForeignCurrency(paymentUse))
            {
                paymentInvoice.Status = Uow.GetRepository <DicPaymentStatus>().AsQueryable()
                                        .FirstOrDefault(q => q.Code == DicPaymentStatusCodes.Credited);
                paymentInvoice.DateFact       = DateTimeOffset.Now;
                paymentInvoice.WhoBoundUserId = NiisAmbientContext.Current.User.Identity.UserId;

                var paymentInvoiceRepository = Uow.GetRepository <PaymentInvoice>();
                paymentInvoiceRepository.Update(paymentInvoice);
                Uow.SaveChanges();
            }
        }