{% extends "crm/business/list.html" %}
{% load i18n %}
{% load markup %}

{% block title %}{{ business }}{% endblock %}

{% block breadcrumb %}
    {{ block.super }}
    {% load breadcrumb_tags %}
    {% if business %}
        {% add_crumb business 'view_business' business.pk %}
    {% endif %}
{% endblock %}

{% block javascript %}
<script src="{{ MEDIA_URL }}js/jquery.autocomplete.js" type="text/javascript"></script>
<link rel="stylesheet" href="{{ MEDIA_URL }}css/jquery.autocomplete.css" type="text/css" media="screen" charset="utf-8">

{% endblock %}

{% block content %}
<h2>{{ business }}</h2>
<ul class='header-actions-left'>
{% if perms.crm.change_business %}
	<li><a href='{% url edit_business business_id=business.id %}?next={% url view_business business_id=business.id %}'>Edit</a></li>
{% endif %}
{# {% if perms.ledger.add_exchange %} #}
{#  {% for type in business.exchange_types %} #}
{#  <li><a href='{% url create_exchange exchange_type_slug=type.slug,business_id=business.id %}?next={% url view_business business_id=business.id %}'>{{ type.label }}</a></li> #}
{#  {% endfor %} #}
{# {% endif %} #}
</ul>

<div id='sidebar'>
	<h3>Contacts</h3>
	<ul class='people'>
	{% ifnotequal business.individual_relations.count 0 %}
	{% for contact in business.individual_relations.select_related %}
		<li>
			<a href='{% url view_person person_id=contact.id %}'>{{ contact.get_full_name }}</a>
			<a title="Edit {{ contact.get_full_name }}'s relationship to {{ business }}" href='{% url edit_business_relationship business_id=business.id,user_id=contact.id %}?next={% url view_business business_id=business.id %}'><img alt="Edit {{ contact.get_full_name }}'s relationship to {{ business }}" src='{{ FAMFAMFAM_URL }}pencil.png' /></a>
            <a title='Remove {{ contact.get_full_name }}' href='{% url associate_contact business_id=business.id,user_id=contact.id,action="remove" %}?next={% url view_business business_id=business.id %}'><img alt='Remove {{ contact.get_full_name }}' src='{{ FAMFAMFAM_URL }}delete.png' /></a>
		</li>
	{% endfor %}
	{% endifnotequal %}
    </ul>
	<form id="add-contact" action='{% url associate_contact business_id=business.id,action="add" %}?next={% url view_business business_id=business.id %}' method="post" accept-charset="utf-8">
		{% csrf_token %}
		<div class="field-wrapper">
		    {{ add_contact_form.contact }}
			<input type="submit" name="submit" value="Add" id="submit" />
		</div>
	</form>
</div>

<table class='vertical' id='business-profile'>
{% for location in business.locations.all %}
    {% for address in location.addresses.all %}
        <tr>
            <th>{{ location.type|capfirst }} Address:</th>
            <td>{{ address }}</td>
        </tr>
    {% endfor %}
    {% for phone in location.phones.all %}
        <tr>
            <th>{{ location.type|capfirst }} {{ phone.type|capfirst }}:</th>
            <td><a href='sip://1-{{ phone }}'>{{ phone }}</a></td>
        </tr>
    {% endfor %}
{% endfor %}
{% if business.description %}
    <tr>
        <th>Description:</th>
        <td>{{ business.description|textile }}</td>
    </tr>
{% endif %}
{% if business.notes %}
    <tr>
        <th>Notes:</th>
        <td>{{ business.notes|textile }}</td>
    </tr>
{% endif %}
</table>

{% ifequal business.business_projects.count 0 %}
	<p>No projects exist for this {% trans "business" %}.  <a href='{% url create_project business_id=business.id %}'>Create one now...</a></p>
{% else %}
	<h3>Projects</h3>
	<table class='businesses'>
		<tr>
			<th>Name</th>
			<th>Type</th>
			<th>Status</th>
			<th>Point Person</th>
			<th>Description</th>
		</tr>
		{% for project in business.business_projects.all %}
		<tr>
			<td><a href='{% url view_project business_id=business.id,project_id=project.id %}'>{{ project.name }}</a></td>
			<td>{{ project.type }}</td>
			<td>{{ project.status }}</td>
			<td>{{ project.point_person }}</td>
			<td>{{ project.description }}</td>
		</tr>
		{% endfor %}
	</table>
	<p>
		<a href='{% url create_project business_id=business.id %}'>New project for {{ business }}...</a>
	</p>
{% endifequal %}

{# {% include 'crm/business/_exchange_list.html' %} #}

{% endblock %}
