Exemplo n.º 1
0
        public void Close(DeliveryClose request)
        {
            var delivery = GetById(request.Id);

            if (delivery.IsClosed || delivery.IsDeleted)
            {
                throw new InvalidOperationException();
            }

            delivery.Close();
            foreach (var deliveryPayment in request.Payments)
            {
                var invoice = delivery.Invoices.First(x => x.Id == deliveryPayment.InvoiceId);
                if (invoice.PaymentMethod == PaymentMethod.Cash)
                {
                    continue;
                }

                var customer = invoice.Person;
                var payment  = new Payment
                {
                    ReferencedDocument   = invoice,
                    ReferencedDocumentId = invoice.Id,
                    CustomerName         = invoice.CustomerName,
                    Total    = deliveryPayment.Total,
                    Number   = _numberSequenceService.NextForPayment(),
                    Person   = customer,
                    PersonId = customer.Id
                };
                customer.Accept(payment);
                _paymentRepository.Add(payment);
            }
        }
Exemplo n.º 2
0
        private void CreateCancellingPayment(Invoice invoice, Customer customer)
        {
            var number  = _documentNumberGenerator.NextForPayment();
            var payment = invoice.CreateCancellingPayment(number);

            customer.Accept(payment);

            _paymentRepository.Add(payment);
        }
Exemplo n.º 3
0
        public void Create(CreatePayment request)
        {
            var customer = _customerRepository.Get(request.PersonId);

            if (customer == null)
            {
                throw new NotFoundException();
            }

            var number  = _numberSequenceService.NextForPayment();
            var payment = new Payment()
            {
                Total       = -request.Total,
                PersonId    = request.PersonId,
                Person      = customer,
                Description = request.Description,
                Number      = number
            };

            customer.Accept(payment);
            _paymentRepository.Add(payment);
        }