示例#1
0
        private static IEnumerable <Payment> ConvertToPaymentModel(UpdateInvestmentRequest model)
        {
            var modelPayments = model.Payments.Select(p => new Payment
            {
                PaymentId        = p.PaymentId,
                EntityId_RemitTo = p.EntityId,
                Remitter         = new Entity {
                    EntityId = p.EntityId, FullName = p.Entidad
                },
                Amount = p.Inversion
            }
                                                      ).ToList();

            return(modelPayments);
        }
示例#2
0
        public JsonResult UpdateInvestments(UpdateInvestmentRequest model)
        {
            var transaction = TransactionService.FindTransactionById(model.TransactionId);
            var workingDate = DateTime.Now;
            var amount      = decimal.Zero;

            var modelPayments = ConvertToPaymentModel(model);

            var paymentsToUpdate = BuildInvestmentPaymentSets(modelPayments, transaction.Payments);

            foreach (var newPayment in paymentsToUpdate["new"])
            {
                var newEntity = new Entity
                {
                    FullName = newPayment.Remitter.FullName,
                    SourceId = 9
                };

                EntityService.CreateEntity(newEntity);

                var payment = new Payment
                {
                    CaseId           = model.CaseId,
                    CaseDetailId     = model.CaseDetailId,
                    TransactionId    = transaction.TransactionId,
                    CaseNumber       = model.CaseNumber,
                    ConceptId        = 2,
                    ClassId          = 3,
                    Amount           = newPayment.Amount,
                    EntityId_RemitTo = newEntity.EntityId,
                    Remitter         = newEntity,
                    ToDate           = transaction.TransactionDate,
                    TransactionNum   = transaction.TransactionId.ToString().PadLeft(9, '0'),
                    CheckBk          = 0,
                    StatusId         = 2,
                    IssueDate        = workingDate,
                    StatusChangeDate = workingDate
                };

                PaymentService.CreatePayment(payment);

                amount += payment.Amount.GetValueOrDefault(decimal.Zero);
            }

            foreach (var changedPayment in paymentsToUpdate["changed"])
            {
                if (changedPayment != null && changedPayment.EntityId_RemitTo == null)
                {
                    continue;
                }
                if (changedPayment == null)
                {
                    continue;
                }
                var existingEntity = EntityService.GetById(changedPayment.EntityId_RemitTo.Value);
                var payment        = PaymentService.FindPaymentById(changedPayment.PaymentId);

                if (changedPayment.Remitter != null)
                {
                    existingEntity.FullName = changedPayment.Remitter.FullName;
                }
                EntityService.ModifyEntity(existingEntity);

                payment.Amount = payment.Amount.GetValueOrDefault(decimal.Zero);
                PaymentService.ModifyPayment(payment);

                amount += payment.Amount.Value;
            }

            foreach (var removedPayment in paymentsToUpdate["removed"])
            {
                if (removedPayment == null)
                {
                    continue;
                }
                var transactionId = removedPayment.TransactionId;
                PaymentService.Delete(removedPayment.PaymentId);
                if (removedPayment.EntityId_RemitTo != null)
                {
                    EntityService.Delete(removedPayment.EntityId_RemitTo);
                }
                if (transactionId != null)
                {
                    TransactionService.Delete(transactionId.Value);
                }
            }

            transaction.TransactionAmount = amount;
            transaction.Comment           = model.Comment;

            TransactionService.ModifyTransaction(transaction);

            return(Json(new BasicDataTablesResult(new { Status = "OK" })));
        }