Package pl.com.bottega.ecommerce.sales.application.internal.bookkeeping

Source Code of pl.com.bottega.ecommerce.sales.application.internal.bookkeeping.BookKeepingListener

/*
* Copyright 2011-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pl.com.bottega.ecommerce.sales.application.internal.bookkeeping;

import javax.inject.Inject;

import pl.com.bottega.ddd.annotations.event.EventListener;
import pl.com.bottega.ddd.annotations.event.EventListeners;
import pl.com.bottega.ecommerce.canonicalmodel.events.OrderSubmittedEvent;
import pl.com.bottega.ecommerce.sales.domain.client.Client;
import pl.com.bottega.ecommerce.sales.domain.client.ClientRepository;
import pl.com.bottega.ecommerce.sales.domain.invoicing.BookKeeper;
import pl.com.bottega.ecommerce.sales.domain.invoicing.Invoice;
import pl.com.bottega.ecommerce.sales.domain.invoicing.InvoiceRepository;
import pl.com.bottega.ecommerce.sales.domain.invoicing.InvoiceRequest;
import pl.com.bottega.ecommerce.sales.domain.invoicing.InvoiceRequestFactory;
import pl.com.bottega.ecommerce.sales.domain.invoicing.TaxAdvisor;
import pl.com.bottega.ecommerce.sales.domain.purchase.Purchase;
import pl.com.bottega.ecommerce.sales.domain.purchase.PurchaseRepository;

@EventListeners
public class BookKeepingListener {

  @Inject
  private BookKeeper bookKeeper;
 
  @Inject
  private PurchaseRepository purchaseRepository;
 
  @Inject
  private InvoiceRepository invoiceRepository;
 
  @Inject
  private TaxAdvisor taxAdvisor;
 
  @Inject
  private ClientRepository clientRepository;
 
  @Inject
  private InvoiceRequestFactory invoiceRequestFactory;
 
  @EventListener
  public void handle(OrderSubmittedEvent event){
    Purchase purchase = purchaseRepository.load(event.getOrderId());
   
    Client client = clientRepository.load(purchase.getClientData().getAggregateId());
    InvoiceRequest request  = invoiceRequestFactory.create(client, purchase);
    Invoice invoice = bookKeeper.issuance(request, taxAdvisor.suggestBestTax(client));
   
    invoiceRepository.save(invoice);
  }
}
TOP

Related Classes of pl.com.bottega.ecommerce.sales.application.internal.bookkeeping.BookKeepingListener

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.