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

{if strlen($QUOTATION_ERR)}<p>{$QUOTATION_ERR}</p>{/if}

<form action="{$FORM_ACTION}" method="post" name="f">
<input type="hidden" name="action" value="{$smarty.const.ACTION_QUOTATION_MAKEIT}">

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

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

function setAction(num)
{
document.f.action.value=num;
document.f.submit();
}

var curr_elem_num = null;

</script>
{/literal}

<table class="stdtable" cellspacing="0">
  <caption><em>{t}Create quotation{/t}</em></caption>
  <tr>
    <td class="label"> {t}Quotation nr.{/t}: </td>
    <td>
      <input type="text" class="tinput" name="quot_number" value="{$quotInfo.quot_number|wash}" size="10" maxlength="10">
       <span class="label">{t}Quotation date{/t}:</span>
      <input type="text" class="tinput format-y-m-d divider-dash no-transparency" name="quot_date" value="{$quotInfo.quot_date|wash}" size="10" maxlength="10" id="rdate">
      <span class="label">{t}Term of payment{/t}:</span> <input type="text" class="tinput" name="quot_payterm" id="payterm" value="{$quotInfo.quot_payterm|wash}" size="30" maxlength="30">
    </td>
  </tr>
  <tr>
    <td class="label"> {t}Recipient (company){/t}: </td>
    <td>
      <select name="cpn_id" id="cpn" onchange="companyChanged()">
        {html_options options=$select_cpn selected=$quotInfo.cpn_id}
      </select>

      <span class="label">{t}Contact person{/t}:</span>
      <select name="pe_id_recipient" id="pe_id_recipient">
        {html_options options=$persons selected=$quotInfo.pe_id_recipient}
      </select>

    </td>
  </tr>
  <tr>
    <td class="label"> {t}Quotation type{/t}: </td>
    <td>
      <select name="bmt_id">
        {html_options options=$select_bmt selected=$quotInfo.bmt_id}
      </select>
      <span class="label">{t}Currency{/t}:</span>
      <select name="curr_id">
        {html_options options=$select_curr selected=$quotInfo.curr_id}
      </select>
    </td>
  </tr>
</table>

<table class="stdtable" id="tbllineitems" cellspacing="0">
  <caption><em>{t}Line items{/t}</em></caption>
  <tr>
    <th> {t}Product code{/t} </th>
    <th> {t}Description{/t} </th>
    <th> {t}Qty./Hours{/t} </th>
    <th> {t}Unit price net{/t} </th>
    <th> {t}Net price{/t} </th>
    <th> {t}Delete{/t} </th>
  </tr>
  {section name=lit loop=$quotInfo.lineitems}
  <tr class="{cycle values="odd,even"}">
    <td>
      <input type="text" class="tinput" name="lit_prodcode[]" value="{$quotInfo.lineitems[lit].lit_prodcode|wash}" size="18" maxlength="18" id="prodcode{$smarty.section.lit.index}" onblur="getProdInfo('{$smarty.section.lit.index}')">
      {if (!strlen($quotInfo.lineitems[lit].lit_prodcode))}
      <a href="#" onclick="getProductCatalog({$smarty.section.lit.index})"><img src="img/phpaga/catalog.png" width="16" height="16"></a>
      {/if}
    </td>
    <td> <textarea name="lit_desc[]" cols="60" rows="2" wrap="virtual" id="prodname{$smarty.section.lit.index}">{$quotInfo.lineitems[lit].lit_desc|wash}</textarea> </td>
    <td> <input type="text" class="tinput number" name="lit_qty[]" value="{$quotInfo.lineitems[lit].lit_qty|wash}" size="10" maxlength="10" id="prodqty{$smarty.section.lit.index}" onblur="calcLineItemPrice('{$smarty.section.lit.index}');"> </td>
    <td class="number">
      <span id="unitnetpricetxt{$smarty.section.lit.index}">{$quotInfo.lineitems[lit].lit_unitnetprice|wash|phpaga_formatamount|default:"&nbsp;"}</span>
      <input type="hidden" name="lit_unitnetprice[]" value="{$quotInfo.lineitems[lit].lit_unitnetprice}" size="15" id="unitnetprice{$smarty.section.lit.index}">
    </td>
    <td> <input type="text" class="tinput number" name="lit_netprice[]" value="{$quotInfo.lineitems[lit].lit_netprice|wash}" size="15" maxlength="15" id="prodprice{$smarty.section.lit.index}"> </td>
    <td> <a href="#" onclick="delLineItem(this.parentNode.parentNode.rowIndex)"><img src="img/phpaga/delete.png" width="16" height="16"></a> </td>
  </tr>
  {/section}
</table>

<div class="buttons">
  <input type="button" name="add" onclick="addLineItem();" value="{t}Add line item{/t}" />
  <input type="button" name="recalc" onclick="setAction({$smarty.const.ACTION_BILL_RECALC});" value="{t}Re-calculate{/t}" />
  <input type="button" name="create" onclick="setAction({$smarty.const.ACTION_QUOTATION_MAKEIT});" value="{t}Create quotation{/t}" />
</div>

<div class="dcaption"><em>{t}Preview{/t} <span>{t}(select Re-calculate to refresh){/t}</span></em>&nbsp;</div>

{if (is_array($quot_details) && (count($quot_details) > 0))}
<table class="stdtable billdetailstable wauto" cellspacing="0">
  {section name=details loop=$quot_details}
  <tr>
    {if $quot_details[details].text eq ""}
    <td class="btext">&nbsp;</td>
    {else}
    <td class="bdesc"> {$quot_details[details].text|wash} </td>
    {/if}
    {if $quot_details[details].amount eq ""}
    <td class="bamount">&nbsp;</td>
    {else}
    <td class="bnumber"> {$quot_details[details].amount} </td>
    {/if}
  </tr>
  {/section}
</table>
{/if}
</form>

<div id="prodselectbox">
  <input type="hidden" id="prodselectdest" name="prodselectdest" value="">
  <table class="stdtable prodselect" cellspacing="0">
    <caption><em>{t}Products{/t}</em>
      <a class="ptr" onclick="hideElement('prodselectbox');"><img src="img/phpaga/close.png" alt="X" title="{t}Close{/t}"></a>
    </caption>
    <tr>
      <th> {t}Product code{/t} </th>
      <th> {t}Name{/t} </th>
      <th> {t}Price{/t} </th>
      <th> {t}Stock{/t} </th>
      <th> {t}Category{/t} </th>
    </tr>
    {section name=pr loop=$products}
    <tr class="{cycle values="odd,even"} pointer" onclick="selectProduct('{$products[pr].prod_code|wash}');">
      <td> {$products[pr].prod_code|wash|default:"&nbsp;"} </td>
      <td> {$products[pr].prod_name|wash|default:"&nbsp;"} </td>
      <td class="number"> {$products[pr].prod_price|wash|phpaga_formatamount|default:"&nbsp;"} </td>
      <td class="number"> {$products[pr].prod_stock|wash|default:"&nbsp;"} </td>
      <td> {$products[pr].prcat_title|wash|default:"&nbsp;"} </td>
    </tr>
    {/section}
  </table>
</div>

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