Ejemplo n.º 1
0
        public async Task <IActionResult> DeletePaymentUse(int paymentUseId, [FromBody] DeletePaymentUseRequestDto requestDto)
        {
            if (!ModelState.IsValid)
            {
                throw new ValidationException("Model is not valid.");
            }

            await Executor.GetCommand <DeletePaymentUseCommand>()
            .Process(c => c.ExecuteAsync(paymentUseId, requestDto));

            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task ExecuteAsync(int paymentInvoiceId, DeleteChargedPaymentInvoiceDto requestDto)
        {
            //Удалить Payment Invoice
            var paymentInvoiceItem = await _executor.GetHandler <GetPaymentInvoiceByIdQuery>().Process(h =>
                                                                                                       h.ExecuteAsync(paymentInvoiceId));

            var user = _executor.GetQuery <GetUserByIdQuery>()
                       .Process(q => q.Execute(NiisAmbientContext.Current.User.Identity.UserId));

            var deletionDate = DateTimeOffset.Now;

            paymentInvoiceItem.IsDeleted   = true;
            paymentInvoiceItem.DeletedDate = deletionDate;
            paymentInvoiceItem.ReasonOfDeletingChargedPaymentInvoice            = requestDto.DeletionReason;
            paymentInvoiceItem.DateOfDeletingChargedPaymentInvoice              = deletionDate;
            paymentInvoiceItem.EmployeeAndPositonWhoDeleteChargedPaymentInvoice = $"{user.NameRu} {user.Position?.NameRu}";

            paymentInvoiceItem.Status = Uow.GetRepository <DicPaymentStatus>()
                                        .AsQueryable()
                                        .FirstOrDefault(q => q.Code == DicPaymentStatusCodes.Notpaid);
            paymentInvoiceItem.DateComplete   = null;
            paymentInvoiceItem.WriteOffUser   = null;
            paymentInvoiceItem.WriteOffUserId = null;

            _executor.GetCommand <UpdatePaymentInvoiceCommand>()
            .Process(c => c.Execute(paymentInvoiceItem));

            //Удалить все Payment Use
            var paymentUseRequestDto = new DeletePaymentUseRequestDto();

            paymentUseRequestDto.DeletionReason = requestDto.DeletionReason;
            foreach (var pu in paymentInvoiceItem.PaymentUses)
            {
                await _executor.GetCommand <DeletePaymentUseCommand>()
                .Process(c => c.ExecuteAsync(pu.Id, paymentUseRequestDto));
            }

            var ownerType = (Owner.Type)Enum.ToObject(typeof(Owner.Type), requestDto.OwnerType);

            //експорт в 1С
            var isExportedTo1C = await _executor.GetHandler <ExportPaymentTo1CHandler>().Process(r => r.ExecuteAsync(ownerType,
                                                                                                                     paymentInvoiceId, PaymentInvoiveChangeFlag.PaymentInvoiceChargedDateIsDeleted, DicPaymentStatusCodes.Charged));
        }
Ejemplo n.º 3
0
        public async Task ExecuteAsync(int paymentUseId, DeletePaymentUseRequestDto requestDto)
        {
            var paymentUse = await _executor.GetQuery <GetPaymentUseByIdQuery>()
                             .Process(q => q.ExecuteAsync(paymentUseId));

            if (paymentUse.PaymentInvoice.DateComplete != null)
            {
                throw new ValidationException("Cannot delete Charged PaymentUse.");
            }

            var user = _executor.GetQuery <GetUserByIdQuery>()
                       .Process(q => q.Execute(NiisAmbientContext.Current.User.Identity.UserId));

            var deletionDate = DateTimeOffset.Now;

            paymentUse.IsDeleted   = true;
            paymentUse.DeletedDate = deletionDate;
            paymentUse.DeletionClearedPaymentReason       = requestDto.DeletionReason;
            paymentUse.DeletionClearedPaymentDate         = deletionDate;
            paymentUse.DeletionClearedPaymentEmployeeName = $"{user.NameRu} {user.Position?.NameRu}";

            _executor.GetCommand <UpdatePaymentUseCommand>()
            .Process(c => c.Execute(paymentUse));

            var paymentInvoice = paymentUse.PaymentInvoice;

            paymentInvoice.Status = Uow.GetRepository <DicPaymentStatus>()
                                    .AsQueryable()
                                    .FirstOrDefault(q => q.Code == DicPaymentStatusCodes.Notpaid);
            paymentInvoice.DateFact       = null;
            paymentInvoice.WhoBoundUserId = null;

            _executor.GetCommand <UpdatePaymentInvoiceCommand>()
            .Process(c => c.Execute(paymentInvoice));

            _executor.GetCommand <UpdatePaymentStatusCommand>()
            .Process(c => c.Execute(paymentUse.PaymentId.Value));
        }