<script type="text/javascript">

  //Date picker
	$(function() {
		 
		$( "#txt_postdate" ).datepicker({
			changeMonth: true,
			changeYear: true
		});
		$( "#txt_postdate" ).datepicker( "option", "dateFormat", "dd.mm.yy");
		$( "#txt_postdate" ).datepicker( "setDate", "<?php echo date('d.m.Y'); ?>" );
		
	});

</script>
<?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);
		$this->load->model('branch/branch_model', '', TRUE);
	}


	function reloadTable($prnumb){
		$data_op = $this->cabang_model->get_all_op($prnumb,date('Y'));?>
		<table width="541" border="1">
			<tr>
			  <th colspan="5">PR Numb : <?php echo $prnumb;?></th>
		  </tr>
			<tr>
			  <th colspan="5">Posting Date : 
		      <input name="txt_postdate" type="text" id="txt_postdate" size="10" value="<?php echo date('d.m.Y'); ?>"  maxlength="10" /></th>
		  </tr>
			<tr>
			  <th width="34"><div align="center">No.</div></th>
			  <th width="115"><div align="center">Purchase Price</div></th>
			  <th width="112"><div align="center">Volume</div></th>
			  <th width="123"><div align="center">Others Payment</div></th>
			  <th width="123"><input type="submit" name="button5" id="button5" value="Closed" class="button" /></th>
		    </tr>
	  <?php $i=1; 
			$vol = 0; 
			$pur = 0; 
			$fee = 0; 
			
			$total = 0;
			$av = 0;
			if(isset($data_op))
			{
	foreach ($data_op->result() as $row){ 
	$vol +=$row->vol;
	$pur +=$row->pur;
	$fee +=$row->fee;
	
	$total +=$row->total;
	
	$average = ceil(($pur + $fee ) / $vol);
	//$av += $average; 
	?>
    <tr>
      <td><?php echo $i;?></td>
      <td><div align="right"><?php echo $this->fungsi->format_idr(($row->pur));?></div></td>
      <td><div align="right"><?php echo number_format ($row->vol);?></div></td>
      <td><div align="right"><?php echo $this->fungsi->format_idr(($row->fee));?></div></td>
      <td>&nbsp;</td>
      </tr>
    <?php $i++;}?>
    <tr>
      <td>TOTAL</td>
      <td><div align="right"><?php echo $this->fungsi->format_idr(($pur));?></div></td>
      <td><div align="right"><?php echo number_format ($vol);?></div></td>
      <td><div align="right"><?php echo $this->fungsi->format_idr(($fee));?></div></td>
      <th>Average : <?php echo $this->fungsi->format_idr($average);?></th>
      </tr>
	<?php } ?>
  </table>
<input name="totvol" type="hidden" id="totvol" size="20" maxlength="50" value="<?php echo $vol;?>"  />
<input name="totpur" type="hidden" id="totpur" size="20" maxlength="50" value="<?php echo $pur;?>"  />
<input name="totfee" type="hidden" id="totfee" size="20" maxlength="50" value="<?php echo $fee;?>"  />
  <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; ?>"  />
   <input name="year" type="hidden" id="year" size="20" maxlength="50" value="<?php echo $row->year; ?>"  />
	<?php
	$data_po =  $this->branch_model->get_po_byprno($row->prnumb, $row->year);
	foreach ($data_po->result() as $row_po);
	echo 'No. PO :'.$row_po->ebeln;
	//echo $row_po->disc;
	?>
    <input name="txt_po" type="hidden" id="txt_po" value="<?php echo $row_po->ebeln; ?>"  />
    <?php
	 }
}