<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class branchAjax extends CI_Controller {
	function __construct()
	{
		parent::__construct();
		$this->load->model('branch/cabang_model', '', TRUE);
	}

	function reloadTable($prnumb){
		$data_op = $this->cabang_model->get_all_op($prnumb,date('Y'));?>
		<table width="1195" border="1">
			<tr>
			  <th width="34"><div align="center">No.</div></th>
			  <th width="115"><div align="center">PR Number</div></th>
			  <th width="112"><div align="center">Quantity</div></th>
			  <th width="86"><div align="center">PR Price</div></th>
			  <th width="138"><div align="center">Volume</div></th>
			  <th width="100"><div align="center">Purchase Price</div></th>
			  <th width="123"><div align="center">Fee Payment</div></th>
			  <th width="122"><div align="center">Freight</div></th>
			  <th width="89"><div align="center">Others</div></th>
			  <th width="89">Average</th>
			  <th width="117"><div align="center">Action</div></th>
			</tr>
	  <?php $i=1; 
			$vol = 0; 
			$pur = 0; 
			$fee = 0; 
			$freight = 0; 
			$other = 0; 
			$total = 0;
			$av = 0;
			if(isset($data_op)){
	foreach ($data_op->result() as $row){ 
	$vol +=$row->vol;
	$pur +=$row->pur;
	$fee +=$row->fee;
	$freight +=$row->freight;
	$other +=$row->other;
	$total +=$row->total;
	$average = ($pur + $fee + $freight + $other) / $vol;
	//$av += $average; 
	?>
    <tr>
      <td><?php echo $i;?></td>
      <td><?php echo $row->prnumb;?></td>
      <td><?php echo $row->quantity;?></td>
      <td><?php echo $row->total;?></td>
      <td><?php echo $row->vol;?></td>
      <td><?php echo $row->pur;?></td>
      <td><?php echo $row->fee;?></td>
      <td><?php echo $row->freight;?></td>
      <td><?php echo $row->other;?></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <?php $i++;}?>
    <tr>
      <td colspan="4">TOTAL</td>
      <td><?php echo $vol;?></td>
      <td><?php echo $pur;?></td>
      <td><?php echo $fee;?></td>
      <td><?php echo $freight;?></td>
      <td><?php echo $other;?></td>
      <td><?php echo ceil($average);?></td>
      <td><input type="submit" name="button5" id="button5" value="Closed" class="button" /></td>
    </tr>
	<?php } ?>
  </table>
  <input name="totvol" type="hidden" id="totvol" size="20" maxlength="50" value="<?php echo $vol;?>"  />
  <input name="average" type="hidden" id="average" size="20" maxlength="50" value="<?php echo $average;?>"  />
   <input name="nopr" type="hidden" id="nopr" size="20" maxlength="50" value="<?php echo $row->prnumb; ?>"  />
	<?php }
}