<!-- 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">
  <tr>
    <td class="header" colspan="2"> {t}Invoice{/t} {$billInfo.bill_number|wash}/{$billInfo.bill_date|wash}  </td>
    <td class="headeraction" colspan="2"> [ {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}
      ]
    </td>
  </tr>
  <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}Term of payment{/t}: </td>
    <td class="data"> {$billInfo.bill_payterm|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 colspan="3" class="data"> {$billInfo.bmt_description|wash} </td>
  </tr>
  <tr>
    <td class="label">{t}Company{/t}: </td>
    <td colspan="3" class="data">{$billInfo.cpn_name|wash}</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 nowrap class="btext">&nbsp;</td>
          {else}
          <td class="bdesc"> {$billInfo.bill_details[details].text|wash} </td>
          {/if}
          {if $billInfo.bill_details[details].amount eq ""}
          <td nowrap class="bamount">&nbsp;</td>
          {else}
          <td class="bnumber"> {$billInfo.bill_details[details].amount} </td>
          {/if}
        </tr>
        {/section}
      </table>
    </td>
  </tr>
  <tr>
    <td colspan="4" class="section">{t}Line items{/t} </td>
  </tr>
  <tr>
    <td colspan="4">
      <table class="substdtable" cellspacing="0" width="100%">
        <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>
    </td>
  </tr>
</table>

{if isset($billInfo.operations.oprows) && is_array($billInfo.operations.oprows) && count($billInfo.operations.oprows) > 0}

<table class="stdtable" cellspacing="0">
  <tr>
    <td class="header" colspan="7"> {t}Associated tasks{/t} </td>
  </tr>
  <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|truncate:$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} -->
