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

<script type="text/javascript" src="js/tasks.js"></script>
<script type="text/javascript" src="js/material.js"></script>

{literal}
<script type="text/javascript">

function confirm_delete(bill_id)
{
if (window.confirm('{/literal}{t}Are you sure you want to delete this invoice?{/t} {$billInfo.bill_number}/{$billInfo.bill_date}  ({$billInfo.bill_endsum|phpaga_formatamount} {$billInfo.curr_name}){literal}')) {
location.href = 'bill.php?id='+bill_id+'&action={/literal}{$smarty.const.ACTION_DELETE}{literal}';
}
}

</script>
{/literal}

<div id="opdetails"> </div>
<div id="matdetails"> </div>
<form action="bill_pdf.php" method="get" onsubmit="hideElement('printbill');">
<input type="hidden" name="id" value="{$billInfo.bill_id}">
{include file="bill_print.tpl.html"}
</form>

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

  <caption><em>{t}Invoice{/t} {$billInfo.bill_number|wash}/{$billInfo.bill_date|wash}{if strlen($billInfo.rbill_id)} <span>(recurring invoice <a href="recurrbills.php?id={$billInfo.rbill_id|wash}">#{$billInfo.rbill_id|wash}</a>)</span>{/if}</em>
    [ {if ($perm_invoices && ($billInfo.bill_paydate eq ""))}<a class="ptr" onclick="confirm_delete({$billInfo.bill_id});">{t}Delete{/t}</a> |{/if}
    {if $perm_invoices}<a href="add_bill.php?id={$billInfo.bill_id}&amp;action={$smarty.const.ACTION_CLONE}">{t}Clone{/t}</a> |{/if}
    <a class="ptr" onclick="showElement('printbill');">{t}Export PDF{/t}</a>
    {if ($perm_invoices && ($billInfo.bill_paydate eq ""))}
    | <a href="bill_paid.php?id={$billInfo.bill_id}">{t}Set payment date{/t}</a>
    {/if}
    ]
  </caption>

  <tr>
    <td class="label">{t}Invoice nr.{/t}: </td>
    <td class="data"> {$billInfo.bill_number|wash} </td>
    <td class="label"> {t}Invoice date{/t}: </td>
    <td class="data"> {$billInfo.bill_date|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
  </tr>
  <tr>
    <td class="label">{t}Company{/t}: </td>
    <td class="data">{$billInfo.cpn_name|wash}</td>
    <td class="label"> {t}Date due{/t}: </td>
    {if strlen($billInfo.bill_date_due)}
    <td class="data{if $billInfo.bill_overdue} warn{/if}"> {$billInfo.bill_date_due|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
    {else}
    <td class="data recinfo"> {t}not set{/t} </td>
    {/if}
  </tr>
  <tr>
    <td class="label"> {t}Contact person{/t}: </td>
    <td class="data"> {$billInfo.bill_person_recipient|wash|default:"&nbsp;"} </td>
    <td class="label"> {t}Date paid{/t}: </td>
    {if $billInfo.bill_paydate eq ""}
    <td class="data recinfo"> {t}not paid{/t} </td>
    {else}
    <td class="data"> {$billInfo.bill_paydate|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
    {/if}
  </tr>
  <tr>
    <td class="label"> {t}Invoice type{/t}: </td>
    <td class="data"> {$billInfo.bmt_description|wash} </td>
    <td class="label"> {t}Term of payment{/t}: </td>
    <td class="data"> {$billInfo.bill_payterm|wash|default:"&nbsp;"} </td>
  </tr>

  <tr>
    <td class="label">{t}Details{/t}: </td>
    <td class="desc" colspan="3">
      <table class="billdetailstable" cellspacing="0">
        {section name=details loop=$billInfo.bill_details}
        <tr>
          {if $billInfo.bill_details[details].text eq ""}
          <td class="btext">&nbsp;</td>
          {else}
          <td class="bdesc"> {$billInfo.bill_details[details].text|wash} </td>
          {/if}
          {if $billInfo.bill_details[details].amount eq ""}
          <td class="bamount">&nbsp;</td>
          {else}
          <td class="bnumber"> {$billInfo.bill_details[details].amount} </td>
          {/if}
        </tr>
        {/section}
      </table>
    </td>
  </tr>
</table>

<table class="stdtable" cellspacing="0">
  <caption><em>{t}Line items{/t}</em></caption>
  <tr>
    <th> {t}Product code{/t} </th>
    <th> {t}Description{/t} </th>
    <th class="time"> {t}Qty./Hours{/t} </th>
    <th class="number"> {t}Net price{/t} </th>
  </tr>
  {section name=lit loop=$billInfo.lineitems}
  <tr class="{cycle values="odd,even"}">
    <td>
      {$billInfo.lineitems[lit].lit_prodcode|wash|default:"&nbsp;"}
      {if strlen($billInfo.lineitems[lit].op_id)}
      {if strlen($billInfo.lineitems[lit].lit_prodcode)}<br />{/if}
      {if (is_numeric($billInfo.lineitems[lit].op_id) && ($billInfo.lineitems[lit].op_id > 0))}
      <a class="ptr" onclick="viewTaskDetails({$billInfo.lineitems[lit].op_id}, 'vimgb')"><img id="vimgb{$billInfo.lineitems[lit].op_id}" src="img/phpaga/view.png" height="16" width="16" border="0" alt="{t}View{/t}" title="{t}Associated task{/t}"></a>
      {else}
      {t}Multiple tasks are associated with this line item{/t}
      {/if}
      {/if}
      {if strlen($billInfo.lineitems[lit].mat_id)}<br />
      <a class="ptr" onclick="viewMaterialDetails({$billInfo.lineitems[lit].mat_id}, 'vimgc')"><img id="vimgc{$billInfo.lineitems[lit].mat_id}" src="img/phpaga/view.png" height="16" width="16" border="0" alt="{t}View{/t}" title="{t}Associated material{/t}"></a>
      {/if}
    </td>
    <td class="datawrap"> {$billInfo.lineitems[lit].lit_desc|wash|nl2br} </td>
    <td class="number"> {$billInfo.lineitems[lit].lit_qty|wash|default:"&nbsp;"} </td>
    <td class="number lr"> {$billInfo.lineitems[lit].lit_netprice|wash|phpaga_formatamount|default:"&nbsp;"} </td>
  </tr>
  {/section}
</table>

{if count($billInfo.expenses)}
<table class="stdtable" id="tblexpenses" cellspacing="0">
  <caption><em>{t}Expenses{/t}</em></caption>
  <tr>
    <th> {t}Project{/t} </th>
    <th> {t}Date{/t} </th>
    <th> {t}Description{/t} </th>
    <th class="number"> {t}Cost{/t} </th>
    <th> {t}Currency{/t} </th>
    <th> {t}Person{/t} </th>
  </tr>
  {section name=exp loop=$billInfo.expenses}
  <tr class="{cycle values="odd,even"}">
    <td> {$billInfo.expenses[exp].prj_title|wash} </td>
    <td> {$billInfo.expenses[exp].exp_date|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
    <td> {$billInfo.expenses[exp].exp_desc|wash} </td>
    <td class="number"> {$billInfo.expenses[exp].exp_sum|phpaga_formatamount} </td>
    <td> {$billInfo.expenses[exp].curr_name|wash} </td>
    <td> <a href="person.php?id={$billInfo.expenses[exp].pe_id}">{$billInfo.expenses[exp].pe_person}</a> </td>
  </tr>
  {/section}
</table>
{/if}

{if isset($billInfo.operations.oprows) && is_array($billInfo.operations.oprows) && count($billInfo.operations.oprows) > 0}
<table class="stdtable" cellspacing="0">
  <caption><em>{t}Associated tasks{/t}</em></caption>
  <tr>
    <th> {t}Project{/t} </th>
    <th> {t}Task{/t} </th>
    <th class="time"> {t}Date{/t} </th>
    <th> {t}Person{/t} </th>
    <th> {t}Category{/t} </th>
    <th class="time"> {t}Hours{/t} </th>
    <th> {t}Actions{/t} </th>
  </tr>
  {section name=operations loop=$billInfo.operations.oprows}
  <tr class="{cycle values="odd,even"}">
    <td> <a href="project.php?id={$billInfo.operations.oprows[operations].prj_id}">{$billInfo.operations.oprows[operations].prj_title|wash}</a> </td>
    <td {if ((strlen($billInfo.operations.oprows[operations].op_desc) > $smarty.const.PHPAGA_SHOWOPDESCLENGHT))} onmouseover="return escape('{$billInfo.operations.oprows[operations].op_desc|phpaga_popup_sanitizestr}')"{/if}>
      {$billInfo.operations.oprows[operations].op_desc|wash|trnc:$smarty.const.PHPAGA_SHOWOPDESCLENGHT:"...":true}
    </td>
    <td class="time"> {$billInfo.operations.oprows[operations].op_startdate|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
    <td> <a href="person.php?id={$billInfo.operations.oprows[operations].pe_id}">{$billInfo.operations.oprows[operations].op_person|wash}</a> </td>
    <td> {$billInfo.operations.oprows[operations].opcat_title|wash} </td>
    <td class="time"> {$billInfo.operations.oprows[operations].duration} </td>
    <td class="actions"> <a class="ptr" onclick="viewTaskDetails({$billInfo.operations.oprows[operations].op_id}, 'vim')"><img id="vim{$billInfo.operations.oprows[operations].op_id}" src="img/phpaga/view.png" height="16" width="16" border="0" alt="{t}View{/t}" title="{t}View{/t}"></a> </td>
  </tr>
  {/section}
  <tr>
    <td class="time" colspan="5"> {t}Total duration{/t}: </td>
    <td class="time"> {$billInfo.operations.duration} </td>
    <td> &nbsp; </td>
  </tr>
</table>
{/if}

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