Exemplo n.º 1
0
        public async Task <SalesInvoice> CreateInvoiceAsync(DateTimeOffset dueDate, Guid?invoiceNoteId, List <SalesInvoiceItem> invoiceItems,
                                                            Guid?customerId, Guid?salesOrderId)
        {
            NumberSequence numberSequence = await _numberSequenceRepository.GetSingleBySpecificationAsync(new NumberSequenceSpecification(typeof(SalesInvoice).Name));

            int invoiceCount = await _salesInvoiceRepository.CountAllAsync();

            string invoiceNumber = numberSequence.GenerateSequence(invoiceCount);

            Address  billingAddress;
            Customer customer = await _customerRepository.GetSingleBySpecificationAsync(new CustomerSpecification(customerId.Value));

            billingAddress = customer.BillingAddress;

            string invoiceNotes = string.Empty;

            if (invoiceNoteId.HasValue)
            {
                SalesInvoiceNote salesInvoiceNote = await _salesInvoiceNoteRepository.GetByIdAsync(invoiceNoteId.Value);

                invoiceNotes = salesInvoiceNote?.Description;
            }

            SalesInvoice invoice = new(invoiceNumber, dueDate, invoiceNotes, customerId, salesOrderId, billingAddress, invoiceItems);

            invoice = await _salesInvoiceRepository.AddAsync(invoice);

            return(invoice);
        }
Exemplo n.º 2
0
        public async Task <SalesOrder> CreateSalesOrderAsync(Guid?customerId, Guid?quotationId)
        {
            string         salesOrderName = typeof(SalesOrder).Name;
            NumberSequence numberSequence = await _numberSequenceRepository.GetSingleBySpecificationAsync(new NumberSequenceSpecification(salesOrderName));

            int salesOrderCount = await _salesOrderRepository.CountAllAsync();

            string salesOrderNumber = numberSequence.GenerateSequence(salesOrderCount);

            Address shipToAddress = null;

            if (customerId.HasValue)
            {
                Customer customer = await _customerRepository.GetByIdAsync(customerId.Value);

                shipToAddress = customer.BillingAddress;
            }

            if (shipToAddress == null)
            {
                throw new Exception("Shipping address cannot be null.");
            }

            SalesOrder salesOrder = new SalesOrder(salesOrderNumber, customerId, quotationId, shipToAddress);

            salesOrder = await _salesOrderRepository.AddAsync(salesOrder);

            return(salesOrder);
        }
Exemplo n.º 3
0
        public async Task ConvertToSalesOrderAsync(Guid quotationId)
        {
            Quotation quotation = await _quotationRepository.GetSingleBySpecificationAsync(new QuotationSpecification(quotationId));

            Address  shipToAddress;
            Customer customer = await _customerRepository.GetSingleBySpecificationAsync(new CustomerSpecification(quotation.CustomerId.Value));

            shipToAddress = customer.BillingAddress;

            List <SalesOrderItem> salesOrderItems = quotation.QuotationItems.Select(quotationItem =>
            {
                ItemOrdered itemOrdered       = new(quotationItem.ItemQuoted.ItemId, quotationItem.ItemQuoted.ItemName, quotationItem.ItemQuoted.ItemDescription);
                SalesOrderItem salesOrderItem = new(itemOrdered, quotationItem.UnitPrice, quotationItem.Units);
                return(salesOrderItem);
            }).ToList();

            NumberSequence numberSequence = await _numberSequenceRepository.GetSingleBySpecificationAsync(new NumberSequenceSpecification(typeof(SalesOrder).Name));

            int salesOrderCount = await _salesOrderRepository.CountAllAsync();

            string salesOrderNumber = numberSequence.GenerateSequence(salesOrderCount);

            SalesOrder salesOrder = new(salesOrderNumber, quotation.CustomerId, quotationId, shipToAddress, salesOrderItems);

            await _salesOrderRepository.AddAsync(salesOrder);
        }
Exemplo n.º 4
0
        public async Task ConvertToInvoiceAsync(Guid salesOrderId)
        {
            SalesOrder salesOrder = await _salesOrderRepository.GetSingleBySpecificationAsync(new SalesOrderSpecification(salesOrderId));

            Address  billingAddress;
            Customer customer = await _customerRepository.GetSingleBySpecificationAsync(new CustomerSpecification(salesOrder.CustomerId.Value));

            billingAddress = customer.BillingAddress;

            List <SalesInvoiceItem> invoiceLines = salesOrder.SalesOrderItems.Select(salesOrderLine =>
            {
                InvoicedItem invoicedItem    = new (salesOrderLine.ItemOrdered.ItemId, salesOrderLine.ItemOrdered.ItemName, salesOrderLine.ItemOrdered.ItemDescription);
                SalesInvoiceItem invoiceLine = new(invoicedItem, salesOrderLine.UnitPrice, salesOrderLine.Units, null);
                return(invoiceLine);
            }).ToList();

            NumberSequence numberSequence = await _numberSequenceRepository.GetSingleBySpecificationAsync(new NumberSequenceSpecification(typeof(SalesInvoice).Name));

            int invoiceCount = await _salesInvoiceRepository.CountAllAsync();

            string invoiceNumber = numberSequence.GenerateSequence(invoiceCount);

            SalesInvoiceNote invoiceNote = await _salesInvoiceNoteRepository.GetSingleBySpecificationAsync(new SalesInvoiceNoteSpecification());

            SalesInvoice invoice = new SalesInvoice(invoiceNumber, DateTime.Now, invoiceNote?.Description, salesOrder.CustomerId, salesOrderId, billingAddress, invoiceLines);

            await _salesInvoiceRepository.AddAsync(invoice);
        }
Exemplo n.º 5
0
        public async Task <Quotation> CreateQuotationAsync(DateTimeOffset quotationDate, DateTimeOffset validUntil, Guid?customerId)
        {
            NumberSequence numberSequence = await _numberSequenceRepository.GetSingleBySpecificationAsync(new NumberSequenceSpecification(typeof(Quotation).Name));

            int quotationCount = await _quotationRepository.CountAllAsync();

            string quotationNumber = numberSequence.GenerateSequence(quotationCount);

            Quotation quotation = new Quotation(quotationNumber, quotationDate, validUntil, customerId);

            quotation = await _quotationRepository.AddAsync(quotation);

            return(quotation);
        }