<!-- 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">
  <tr>
    <td class="header" colspan="2"> {t}Create quotation{/t} </td>
  </tr>

  <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" name="quot_date" value="{$quotInfo.quot_date|wash}" size="10" maxlength="10" id="rdate">
      <input type="image" src="img/phpaga/cal.png" id="btn_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="javscript:getPayTerm()">
        {html_options options=$select_cpn selected=$quotInfo.cpn_id}
      </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>

  <tr>
    <td class="section" colspan="2"> {t}Line items{/t} </td>
  </tr>
  <tr>
    <td colspan="2">

      <table class="substdtable" id="tbllineitems" cellspacing="0">
        <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>
    <td>
  </tr>

  <tr>
    <td colspan="2">
      <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>
    </td>
  </tr>

  <tr>
    <td class="section" colspan="2">{t}Preview (select Re-calculate to refresh){/t}: </td>
  </tr>
{if (is_array($quot_details) && (count($quot_details) > 0))}
    <tr>
    <td colspan="2">
      <table class="billdetailstable" cellspacing="0" align="center">
	{section name=details loop=$quot_details}
	<tr>
	  {if $quot_details[details].text eq ""}
	  <td nowrap class="btext">&nbsp;</td>
	  {else}
	  <td class="bdesc"> {$quot_details[details].text|wash} </td>
	  {/if}
	  {if $quot_details[details].amount eq ""}
	  <td nowrap class="bamount">&nbsp;</td>
	  {else}
	  <td class="bnumber"> {$quot_details[details].amount} </td>
	  {/if}
	</tr>
	{/section}
      </table>
    </td>
  </tr>
{/if}

</table>
</form>

<div id="prodselectbox">
  <input type="hidden" id="prodselectdest" name="prodselectdest" value="">
  <table class="stdtable prodselect" cellspacing="0">
    <tr>
      <td class="header" colspan="3"> {t}Products{/t} </td>
      <td class="headeraction" colspan="3"> [ <a class="ptr" onclick="hideElement('prodselectbox');">X</a> ] </td>
    </tr>
    <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>

{literal}
<script type="text/javascript">
    Calendar.setup({
        inputField     :    "rdate",                     // id of the input field
        ifFormat       :    "%Y-%m-%d",       // format of the input field
        showsTime      :    false,                      // will display a time selector
        button         :    "btn_rdate",                 // trigger for the calendar (button ID)
        singleClick    :    true,                     // double-click mode
        showOthers     :    true                       // show overlapping months
    });
  </script>
  {/literal}

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