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

{include file="delete_company.tpl.js"}

<table class="stdtable" cellspacing="0">

  <caption><em>{t}Company{/t}: {$cpnInfo.cpn_name|wash}</em>
    {if ($perm_companies) || ($cpnInfo.pe_id == $smarty.session.auth_user.pe_id)}
    [ <a class="ptr" onclick="confirm_delete_company({$cpnInfo.cpn_id}, '{$cpnInfo.cpn_name|phpaga_popup_sanitizestr}');">{t}Delete{/t}</a>
    | <a href="edit_company.php?id={$cpnInfo.cpn_id}">{t}Edit{/t}</a> ]
    {else}
    &nbsp;
    {/if}
  </caption>

  <tr>
    <td class="label">{t}Company{/t}: </td>
    <td class="data"> {$cpnInfo.cpn_name|wash|default:"&nbsp;"} </td>
  </tr>
  <tr>
    <td class="label">{t}Address{/t}: </td>
    <td class="data"> {$cpnInfo.cpn_address|wash|default:"&nbsp;"} </td>
  </tr>
  <tr>
    <td class="label">{t}Address 2{/t}: </td>
    <td class="data"> {$cpnInfo.cpn_address2|wash|default:"&nbsp;"} </td>
  </tr>
  <tr>
    <td class="label">{t}Location{/t}: </td>
    <td class="data"> {$cpnInfo.full_location|wash|default:"&nbsp;"} </td>
  </tr>
  <tr>
    <td class="label">{t}Country{/t}: </td>
    <td class="data"> <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>
    <td class="label">{t}Category{/t}: </td>
    <td class="data"> {$cpnInfo.ccat_title|wash|default:"&nbsp;"} </td>
  </tr>
  <tr>
    <td class="label">{t}Tax number{/t}: </td>
    <td class="data"> {$cpnInfo.cpn_taxnr|wash|default:"&nbsp;"} </td>
  </tr>
  <tr>
    <td class="label"> {t}Default term of payment{/t}: </td>
    <td class="data"> {$cpnInfo.cpn_defaultpayterm|wash|default:"&nbsp;"} </td>
  </tr>
  <tr>
    <td class="label">{t}Phone{/t}: </td>
    <td class="data"> {$cpnInfo.cpn_phone|wash|default:"&nbsp;"} </td>
  </tr>
  <tr>
    <td class="label">{t}Fax{/t}: </td>
    <td class="data"> {$cpnInfo.cpn_fax|wash|default:"&nbsp;"} </td>
  </tr>
  <tr>
    <td class="label">{t}Url{/t}: </td>
    <td class="data"> {if strlen($cpnInfo.cpn_url)}{$cpnInfo.cpn_url|wash|phpaga_urlmodifier}{else}&nbsp;{/if} </td>
  </tr>
  <tr>
    <td class="label">{t}Email{/t}: </td>
    <td class="data"> {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="label recinfo"> {t}Record owner{/t}: </td>
    <td class="data recinfo"> {$cpnInfo.owner_pe_person|wash|default:"&nbsp;"} </td>
  </tr>
</table>

{if ($opcatresult && isset($opcats) && (count($opcats) > 0))}
{if ($opcat_byproject == 0)}
<div class="dcaption"><em>{t}Task categories{/t}</em>
  [ <a href="company.php?id={$cpnInfo.cpn_id}&amp;detail={$smarty.const.PHPAGA_OPCGRP_PROJECT}">{t}Details{/t}</a> ]</div>

<div class="floatcontainer">

    <table class="stdtable w20 flleft" cellspacing="0">
      {section name=opcdet loop=$opcats}
      <tr>
        <td class="label">{$opcats[opcdet].opcat_title|wash}:&nbsp;</td>
        <td class="data number">&nbsp;{$opcats[opcdet].opcat_duration|phpaga_minutes2duration}&nbsp;</td>
      </tr>
      {/section}
      <tr class="summary">
        <td class="label">{t}Total duration{/t}: </td>
        <td class="data number"> {$TOTAL_DURATION|phpaga_minutes2duration} </td>
      </tr>
    </table>

    <div class="flleft">
      <object type="image/svg+xml" data="opcat_graph.php?cpn_id={$cpnInfo.cpn_id}" height="{$smarty.const.PHPAGA_GRAPH_HEIGHT}" width="{$smarty.const.PHPAGA_GRAPH_WIDTH}">
        You need a browser capeable of SVG to display this image.
        You can find the Adobe SVG Viewer here:
        <a href="http://www.adobe.com/svg/viewer/install/main.html">http://www.adobe.com/svg/viewer/install/main.html</a>
      </object>
    </div>

</div>
<div class="spacer"></div>
{else}
<table class="stdtable" cellspacing="0">
  <caption><em>{t}Task categories{/t}</em>
    [ <a href="company.php?id={$cpnInfo.cpn_id}&amp;detail=0">{t}Overall{/t}</a> ]
  </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 class="{cycle values="odd,even"}">
    <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|phpaga_minutes2duration}</td>
  </tr>
</table>
{/if}
{/if}

{if (isset($cpnInfo.projects) && is_array($cpnInfo.projects) && (count($cpnInfo.projects) > 0))}
<table class="stdtable" cellspacing="0">
  <caption><em>{t}Projects{/t}</em></caption>
  <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>
  {section name=prjs loop=$cpnInfo.projects}
  <tr class="{cycle values="odd,even"}">
    <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}
</table>
{/if}

{if (isset($cpnInfo.billing_summary) && is_array($cpnInfo.billing_summary))}
{if (isset($cpnInfo.billing_summary.issued) && is_array($cpnInfo.billing_summary.issued) && (count(($cpnInfo.billing_summary.issued)) > 0))}
<table class="stdtable" cellspacing="0">
  <caption><em>{t}Invoices issued{/t}</em></caption>
  <tr>
    <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>
  {section name=isum loop=$cpnInfo.billing_summary.issued}
  <tr class="{cycle values="odd,even"}">
    <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}
</table>
{/if}
{if (isset($cpnInfo.billing_summary.outstanding) && is_array($cpnInfo.billing_summary.outstanding) && (count(($cpnInfo.billing_summary.outstanding)) > 0))}
<table class="stdtable" cellspacing="0">
  <caption><em>{t}Outstanding invoices{/t}</em></caption>
  <tr>
    <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>
  {section name=isum loop=$cpnInfo.billing_summary.outstanding}
  <tr class="{cycle values="odd,even"}">
    <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}
</table>
{/if}
{/if}

{if (isset($cpnInfo.bills) && is_array($cpnInfo.bills) && (count($cpnInfo.bills) > 0))}
<table class="stdtable" cellspacing="0">
  <caption><em>{t}Invoices{/t}</em></caption>
  <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>
  {section name=inv loop=$cpnInfo.bills}
  <tr class="{cycle values="odd,even"}">
    <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}
</table>
{/if}

{if (isset($cpnInfo.quotations) && is_array($cpnInfo.quotations) && (count($cpnInfo.quotations) > 0))}
<table class="stdtable" cellspacing="0">
  <caption><em>{t}Quotations{/t}</em></caption>
  <tr>
    <th> {t}Quotation nr.{/t} </th>
    <th> {t}Quotation date{/t} </th>
    <th> {t}Amount{/t} </th>
    <th> {t}Currency{/t} </th>
  </tr>
  {section name=quot loop=$cpnInfo.quotations}
  <tr class="{cycle values="odd,even"}">
    <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}
</table>
{/if}

{if (isset($persons) && is_array($persons) && (count($persons) > 0))}
<table class="stdtable" cellspacing="0">
  <caption><em>{t}Employees{/t}</em></caption>
  <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>
  {section name=idx loop=$persons}
  <tr class="{cycle values="odd,even"}">
    <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}
</table>
{/if}

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