<!-- BEGIN {$smarty.template} -->

{include file="delete_company.tpl.js"}
{literal}
<script type="text/javascript">
    $(document).ready(function() {
        var ocplot = null;

        $.getJSON("data_service.php?req=opcat&cpn_id={/literal}{$cpnInfo.cpn_id}{literal}", 
            function(data){  ocplot = get_opcat_plot('cpnopcat', data); }
        );

        $("#tab_container").tabs();
        $('#tab_container').bind('tabsshow', function(event, ui) {
            if (ui.panel.id == "company-task-categories")
                ocplot.replot();
        });
    });
</script>
{/literal}

<h2>{t}Company{/t}: {$cpnInfo.cpn_name|wash}</h2>
{if ($perm_companies) || ($cpnInfo.pe_id == $smarty.session.auth_user.pe_id)}
<ul class="actions">
    <li><a href="edit_company.php?id={$cpnInfo.cpn_id}">{t}Edit{/t}</a></li>
    <li><a class="ptr" onclick="confirm_delete_company({$cpnInfo.cpn_id}, '{$cpnInfo.cpn_name|phpaga_popup_sanitizestr}');">{t}Delete{/t}</a></li>
</ul>
<div class="spacer"> </div>
{/if}

<div id="tab_container">
    <ul class="tab_items">
        <li><a href="#company-details" rel="company-details">{t}Company{/t}</a></li>
        {if (isset($opcats) && (count($opcats) > 0))}
        <li><a href="#company-task-categories" rel="company-task-categories">{t}Task categories{/t}</a></li>
        {/if}
        {if (isset($cpnInfo.projects) && is_array($cpnInfo.projects) && (count($cpnInfo.projects) > 0))}
        <li><a href="#company-projects" rel="company-projects">{t}Projects{/t}</a></li>
        {/if}
        {if ($perm_financial && isset($cpnInfo.bills) && is_array($cpnInfo.bills) && count($cpnInfo.bills))}
        <li><a href="#company-invoices" rel="company-invoices">{t}Invoices{/t}</a></li>
        {/if}
        {if ($perm_financial && isset($cpnInfo.quotations) && is_array($cpnInfo.quotations) && (count($cpnInfo.quotations) > 0))}
        <li><a href="#company-quotations" rel="company-quotations">{t}Quotations{/t}</a></li>
        {/if}
        {if (isset($persons) && is_array($persons) && (count($persons) > 0))}
        <li><a href="#company-employees" rel="company-employees">{t}Employees{/t}</a></li>
        {/if}
    </ul>

    <div id="company-details" class="tab_content">
        <table class="detail" cellspacing="0">
            <caption><em>{$cpnInfo.cpn_name|wash}</em> </caption>
            <tr>
                <th>{t}Address{/t}: </th>
                <td> {$cpnInfo.cpn_address|wash|default:"&nbsp;"} </td>
            </tr>
            <tr>
                <th>{t}Address 2{/t}: </th>
                <td> {$cpnInfo.cpn_address2|wash|default:"&nbsp;"} </td>
            </tr>
            <tr>
                <th>{t}Location{/t}: </th>
                <td> {$cpnInfo.full_location|wash|default:"&nbsp;"} </td>
            </tr>
            <tr>
                <th>{t}Country{/t}: </th>
                <td> <img src="img/flags/{$cpnInfo.ctr_code|strtolower|wash}.png" alt="{$cpnInfo.ctr_name|wash|default:"&nbsp;"}" title="{$cpnInfo.ctr_name|wash|default:"&nbsp;"}" /> {$cpnInfo.ctr_name|wash|default:"&nbsp;"} </td>
            </tr>
            <tr>
                <th>{t}Category{/t}: </th>
                <td> {$cpnInfo.ccat_title|wash|default:"&nbsp;"} </td>
            </tr>
            <tr>
                <th>{t}Tax number{/t}: </th>
                <td> {$cpnInfo.cpn_taxnr|wash|default:"&nbsp;"} </td>
            </tr>
            <tr>
                <th> {t}Default term of payment{/t}: </th>
                <td> {$cpnInfo.cpn_defaultpayterm|wash|default:"&nbsp;"} </td>
            </tr>
            <tr>
                <th>{t}Phone{/t}: </th>
                <td> {$cpnInfo.cpn_phone|wash|default:"&nbsp;"} </td>
            </tr>
            <tr>
                <th>{t}Fax{/t}: </th>
                <td> {$cpnInfo.cpn_fax|wash|default:"&nbsp;"} </td>
            </tr>
            <tr>
                <th>{t}Url{/t}: </th>
                <td> {if strlen($cpnInfo.cpn_url)}{$cpnInfo.cpn_url|wash|phpaga_urlmodifier}{else}&nbsp;{/if} </td>
            </tr>
            <tr>
                <th>{t}Email{/t}: </th>
                <td> {if strlen($cpnInfo.cpn_email)}<a href="mailto:{$cpnInfo.cpn_email|wash}">{$cpnInfo.cpn_email|wash}</a>{else}&nbsp;{/if} </td>
            </tr>
            <tr>
                <td class="recinfo"> {t}Record owner{/t}: </td>
                <td class="recinfo"> {$cpnInfo.owner_pe_person|wash|default:"&nbsp;"} </td>
            </tr>
        </table>
    </div>

    {if (isset($opcats) && (count($opcats) > 0))}
    <div id="company-task-categories" class="tab_content">
        <div class="dcaption"><em>{t}Task categories{/t}</em>&nbsp;</div>

        <div class="floatcontainer">

            <div id="cpnopcat" class="opcatchart flleft"></div>

            <table class="flleft"  cellspacing="0">
                <caption><em>{t}Per project{/t}</em> </caption>
                <tr class="r">
                    <th>&nbsp;</th>
                    {foreach item=prj from=$opcats.projects}
                    <th> <a href="project.php?id={$prj.prj_id}">{$prj.prj_title|wash}</a></th>
                    {/foreach}
                    <th>{t}Total{/t}</th>
                </tr>
                {foreach key=opckey item=opc from=$opcats.opcats}
                <tr>
                    <td> {$opc.opcat_title|wash} </td>
                    {foreach item=row from=$opcats.rows[$opckey]}
                    <td class="time"> {if strlen($row.opcat_duration)}{$row.opcat_duration|phpaga_minutes2duration}{else}&nbsp;{/if} </td>
                    {/foreach}
                    <td class="time"> {$opc.duration|phpaga_minutes2duration} </td>
                </tr>
                {/foreach}
                <tr class="summary">
                    <td>&nbsp;</td>
                    {foreach item=prj from=$opcats.projects}
                    <td class="time">{$prj.duration|phpaga_minutes2duration}</td>
                    {/foreach}
                    <td class="time">{$TOTAL_DURATION_PRJ|phpaga_minutes2duration}</td>
                </tr>
            </table>
        </div>
        <div class="spacer"></div>
    </div>
    {/if}

    {if (isset($cpnInfo.projects) && is_array($cpnInfo.projects) && (count($cpnInfo.projects) > 0))}
    <div id="company-projects" class="tab_content">
        <table cellspacing="0">
            <caption><em>{t}Projects{/t}</em></caption>
            <thead>
                <tr>
                    <th> {t}Title{/t} </th>
                    <th> {t}Status{/t} </th>
                    <th> {t}Start date{/t} </th>
                    <th> {t}Projected end{/t} </th>
                    <th> {t}End date{/t} </th>
                    <th> {t}Category{/t} </th>
                    <th> {t}Hours{/t} </th>
                    <th> {t}Actions{/t} </th>
                </tr>
            </thead>
            <tbody>
                {section name=prjs loop=$cpnInfo.projects}
                <tr>
                    <td> <a href="project.php?id={$cpnInfo.projects[prjs].prj_id}">{$cpnInfo.projects[prjs].prj_title|wash}</a> </td>
                    <td> {$cpnInfo.projects[prjs].prjstat_title|wash} </td>
                    <td class="time"> {$cpnInfo.projects[prjs].prj_startdate|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
                    <td class="time"> {if strlen($cpnInfo.projects[prjs].prj_estimatedend)}<span{if (($cpnInfo.projects[prjs].prj_status != 2) && phpaga_dategreater($cpnInfo.projects[prjs].prj_estimatedend, $cpnInfo.projects[prjs].prj_enddate))} class="overdue"{/if}>
                            {$cpnInfo.projects[prjs].prj_estimatedend|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}</span>{else}&nbsp;{/if}
                    </td>
                    <td class="time"> {if strlen($cpnInfo.projects[prjs].prj_enddate)}{$cpnInfo.projects[prjs].prj_enddate|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}{else}&nbsp;{/if} </td>
                    <td> {$cpnInfo.projects[prjs].prjcat_title|wash} </td>
                    <td class="time"> {$cpnInfo.projects[prjs].prj_duration|phpaga_minutes2duration} </td>
                    <td class="actions"> {strip}
                        <a href="project.php?id={$cpnInfo.projects[prjs].prj_id}"><img src="img/phpaga/view.png" height="16" width="16" border="0" alt="{t}View{/t}" title="{t}View{/t}"></a>
                        <a href="edit_project.php?prj_id={$cpnInfo.projects[prjs].prj_id}"><img src="img/phpaga/edit.png" height="16" width="16" border="0" alt="{t}Edit{/t}" title="{t}Edit{/t}"></a>
                        <a href="add_operation.php?prj_id={$cpnInfo.projects[prjs].prj_id}"><img src="img/phpaga/task_add.png" height="16" width="16" border="0" alt="{t}Add task{/t}" title="{t}Add task{/t}"></a>
                        {/strip}
                    </td>
                </tr>
                {/section}
            </tbody>
        </table>
    </div>
    {/if}

    {if ($perm_financial)}
    <div id="company-invoices" class="tab_content">
        {if (isset($cpnInfo.billing_summary.issued) && is_array($cpnInfo.billing_summary.issued) && count($cpnInfo.billing_summary.issued)) || (isset($cpnInfo.billing_summary.outstanding) && is_array($cpnInfo.billing_summary.outstanding) && count($cpnInfo.billing_summary.outstanding))}
        <table cellspacing="0">
            <caption><em>{t}Overall{/t}</em></caption>
            <thead>
                <tr>
                    <th> {t}Status{/t}</th>
                    <th> {t}Nr. of invoices{/t} </th>
                    <th> {t}Time frame{/t} </th>
                    <th> {t}Total amount{/t} </th>
                    <th> {t}Currency{/t} </th>
                </tr>
            </thead>
            <tbody>
                {section name=isum loop=$cpnInfo.billing_summary.issued}
                <tr>
                    <td>{t}issued{/t}</td>
                    <td class="number"> {$cpnInfo.billing_summary.issued[isum].count|default:"&nbsp;"} </td>
                    <td class="number"> {$cpnInfo.billing_summary.issued[isum].min_date|wash|default:"&nbsp;"} - {$cpnInfo.billing_summary.issued[isum].max_date|default:"&nbsp;"}</td>
                    <td class="number"> {$cpnInfo.billing_summary.issued[isum].amount|phpaga_formatamount|default:"&nbsp;"} </td>
                    <td class="last"> {$cpnInfo.billing_summary.issued[isum].curr_name|wash|default:"&nbsp;"} </td>
                </tr>
                {/section}
                {section name=isum loop=$cpnInfo.billing_summary.outstanding}
                <tr>
                    <td>{t}outstanding{/t}</td>
                    <td class="number"> {$cpnInfo.billing_summary.outstanding[isum].count|default:"&nbsp;"} </td>
                    <td class="number"> {$cpnInfo.billing_summary.outstanding[isum].min_date|wash|default:"&nbsp;"} - {$cpnInfo.billing_summary.outstanding[isum].max_date|default:"&nbsp;"}</td>
                    <td class="number"> {$cpnInfo.billing_summary.outstanding[isum].amount|phpaga_formatamount|default:"&nbsp;"} </td>
                    <td class="last"> {$cpnInfo.billing_summary.outstanding[isum].curr_name|wash|default:"&nbsp;"} </td>
                </tr>
                {/section}
            </tbody>
        </table>
        {/if}

        {if ($perm_financial && isset($cpnInfo.bills) && is_array($cpnInfo.bills) && (count($cpnInfo.bills) > 0))}
        <table cellspacing="0">
            <caption><em>{t}Invoices{/t}</em></caption>
            <thead>
                <tr>
                    <th> {t}Invoice nr.{/t} </th>
                    <th> {t}Invoice date{/t} </th>
                    <th> {t}Amount{/t} </th>
                    <th> {t}Currency{/t} </th>
                    <th> {t}Date paid{/t} </th>
                </tr>
            </thead>
            <tbody>
                {section name=inv loop=$cpnInfo.bills}
                <tr>
                    <td class="number"> <a href="bill.php?id={$cpnInfo.bills[inv].bill_id}">{$cpnInfo.bills[inv].bill_number|wash}</a> </td>
                    <td class="time"> <a href="bill.php?id={$cpnInfo.bills[inv].bill_id}">{$cpnInfo.bills[inv].bill_date|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}</a> </td>
                    <td class="number"> {$cpnInfo.bills[inv].bill_endsum|phpaga_formatamount|default:"&nbsp;"} </td>
                    <td> {$cpnInfo.bills[inv].curr_name|wash|default:"&nbsp;"} </td>
                    <td class="time last"> {$cpnInfo.bills[inv].bill_paydate|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
                </tr>
                {/section}
            </tbody>
        </table>
        {/if}
        {/if}
    </div>

    {if ($perm_financial && isset($cpnInfo.quotations) && is_array($cpnInfo.quotations) && (count($cpnInfo.quotations) > 0))}
    <div id="company-quotations" class="tab_content">

        <table cellspacing="0">
            <caption><em>{t}Quotations{/t}</em></caption>
            <thead>
                <tr>
                    <th> {t}Quotation nr.{/t} </th>
                    <th> {t}Quotation date{/t} </th>
                    <th> {t}Amount{/t} </th>
                    <th> {t}Currency{/t} </th>
                </tr>
            </thead>
            <tbody>
                {section name=quot loop=$cpnInfo.quotations}
                <tr>
                    <td class="number"> <a href="quotation.php?id={$cpnInfo.quotations[quot].quot_id}">{$cpnInfo.quotations[quot].quot_number|wash}</a> </td>
                    <td class="time"> <a href="quotation.php?id={$cpnInfo.quotations[quot].quot_id}">{$cpnInfo.quotations[quot].quot_date|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}</a> </td>
                    <td class="number"> {$cpnInfo.quotations[quot].quot_endsum|phpaga_formatamount|default:"&nbsp;"} </td>
                    <td class="last"> {$cpnInfo.quotations[quot].curr_name|wash|default:"&nbsp;"}  </td>
                </tr>
                {/section}
            </tbody>
        </table>
    </div>
    {/if}

    {if (isset($persons) && is_array($persons) && (count($persons) > 0))}
    <div id="company-employees" class="tab_content">
        <table cellspacing="0">
            <caption><em>{t}Employees{/t}</em></caption>
            <thead>
                <tr>
                    <th> {t}Name{/t} </th>
                    <th> {t}Address{/t} </th>
                    <th> {t}City{/t} </th>
                    <th> {t}Country{/t} </th>
                    <th>{t}Work phone{/t}: </th>
                    <th> {t}Email{/t} </th>
                </tr>
            </thead>
            <tbody>
                {section name=idx loop=$persons}
                <tr>
                    <td> <a href="person.php?id={$persons[idx].pe_id}">{$persons[idx].pe_person|wash}</a> </td>
                    <td> {$persons[idx].pe_address|wash|default:"&nbsp;"} </td>
                    <td> {$persons[idx].pe_location|wash|default:"&nbsp;"} </td>
                    <td> {$persons[idx].ctr_name|wash|default:"&nbsp;"} </td>
                    <td> {$persons[idx].pe_phonework|wash|default:"&nbsp;"} </td>
                    <td class="last"> {if (isset($persons[idx].pe_email) && strlen($persons[idx].pe_email))}<a href="mailto:{$persons[idx].pe_email|wash}">{$persons[idx].pe_email|wash}{else}&nbsp;{/if}</a> </td>
                </tr>
                {/section}
            </tbody>
        </table>
    </div>
    {/if}
</div>

<!-- END {$smarty.template} -->
