void ribi::imcw::company::buy_click_card(
  person& customer,
  balance& account_euros,
  bank& the_bank,
  calendar& the_calendar
)
{
  assert(customer.has_account(account_euros));
  #ifndef NDEBUG
  const auto before = account_euros.get_value();
  #endif
  the_bank.transfer(
    account_euros,
    money(click_card::cost_inc_vat_euros),
    m_balance_undistributed,
    the_calendar.get_today()
  );

  #ifndef NDEBUG
  const auto after = account_euros.get_value();
  assert(after < before);
  #endif

  //ClickCard will be valid the first day of the next month
  click_card c(
    the_calendar.get_today() //Purchase date
  );
  customer.add_click_card(c);
}
void ribi::imcw::company::buy_winner_package(
  person& customer,
  const winner_package_name name,
  balance& account_euros,
  bank& the_bank,
  const boost::gregorian::date& the_day
)
{
  if (customer.has_valid_click_card(the_day))
  {
    std::stringstream s;
    s << __func__
      << "Cannot buy a WinnerPackage when customer already has a ClickCard";
    throw std::logic_error(s.str());
  }
  assert(!is_customer(customer));
  assert(customer.has_account(account_euros));

  #ifndef NDEBUG
  const auto account_before = account_euros.get_value();
  const auto n_customers_before = m_customers.size();
  #endif // NDEBUG

  const winner_package p(name);
  const int n_winners = p.get_n_winners();

  //Buy ClickCard
  {
    the_bank.transfer(
      account_euros,
      money(click_card::cost_inc_vat_euros),
      m_balance_undistributed,
      the_day
    );
    click_card c(the_day);
    assert(!c.is_valid(the_day)); //Not valid yet
    customer.add_click_card(c);
  }
  assert(!customer.has_valid_click_card(the_day)); //Not valid yet

  //ClickCard makes person a customer
  m_customers.push_back(customer);

  //Winners
  for (int i=0; i!=n_winners; ++i)
  {
    buy_winner(customer,account_euros,the_bank,the_day);
  }
  assert(customer.get_n_winners() == n_winners);

  #ifndef NDEBUG
  const auto account_after = account_euros.get_value();
  assert(account_after < account_before);
  const auto n_customers_after = m_customers.size();
  assert(n_customers_after == n_customers_before + 1);
  #endif // NDEBUG

}