{extends file="./main.tpl"}
{block name=head}
<script type="text/javascript">
function getAmt(amountObj)
{
  var row      = $(amountObj).parents('.itemRow'); 
  var kg       = row.find('.kg').val() != '' ? row.find('.kg').val() : 0;
  var rate     = $('.rate').val() != '' ? $('.rate').val() : 0;
  var kgrs     = row.find('.kgrs').val() != '' ? row.find('.kgrs').val() : 0;
  var totalAmt = row.find('.totalAmt').val() != '' ? row.find('.totalAmt').val() : 0;
  var dd   	   = 0;
  var aa       =  parseFloat(kg) * parseFloat(rate);
  row.find('.kgrs').val(aa.toFixed(2));
  
  if(kg > 0  && totalAmt < 0)
  {
	  var xx = Math.abs(totalAmt);
	  dd =  parseFloat(kgrs) - parseFloat(xx);
	  row.find('.finalAmt').val(dd.toFixed(2));
  }
  else if(kg < 0  && totalAmt > 0)
  {
	  var xx = Math.abs(kgrs);
	  dd =  parseFloat(xx) - parseFloat(totalAmt);
	  row.find('.finalAmt').val(dd.toFixed(2));
  }
  else
  {
    var xx = Math.abs(kgrs);
    var yy = Math.abs(totalAmt);
    dd =  parseFloat(xx) + parseFloat(totalAmt);
	row.find('.finalAmt').val(dd.toFixed(2));
  }
  
  
}
</script>
{/block}
{block name=body}
<form action="summary.php" method="POST">
<table align="center" border="2" width="70%"> 
	<h2 align="center">Client Summary</h2>
<thead>
<center>
  <input type="text" class="rate" placeholder="Enter Rate" onBlur="getAmt();">
</center>
	<tr>
		<th class="table1">Party Name</th>
		<th class="table1">Fine</th>
		<th class="table1">Amount</th>
		<th class="table1">Silver Rs</th>
		<th class="table1">Final Amount</th>
    </tr>
</thead>
</tbody>
{foreach from=$pendingArray item=onerow}
  <tr class="itemRow">
	<input type="hidden" name="partyId" value="{$onerow.partyId}">
  	<td class="table1" align="center">{$onerow.partyName}</td>
    <td class="table1" align="center">
		<input type="text" class="kg" value="{$onerow.kg|string_format:"%.3f"}" style="width:100px;" onBlur="getAmt(this);"">
	</td>
	<td class="table1" align="center"> 
	  <input type="text" value="{$onerow.totalAmt|string_format:"%.3f"}" class="totalAmt">
	</td>
	<td class="table1" align="center">
		<input type="text" class="kgrs" style="width:100px;" onBlur="getAmt(this);" readonly>
	</td>
	<td class="table1" align="center">
		<input type="text" class="finalAmt" style="width:100px;" onBlur="getAmt(this);">
	</td>
		

  </tr>
{/foreach}
</tbody>
</table>
<br><br><br>
<table align="center" border="1" width="30%">
  <tr>
    <td>Final Weight :- {$kg|string_format:"%.3f"}</td>
  </tr>
  <tr>
     <td>Total Amount :- {$totalAmt|string_format:"%.3f"}</td>
  </tr>
  
</table>
</form>
{/block}