<script type="text/javascript">
$(document).ready(function() {   
	$('select').select2();

	$.each($(".select2-container"), function (i, n) {
        $(n).next().show().fadeTo(0,0).height("0px").css("left", "auto"); // make the original select visible for validation engine and hidden for us
        $(n).prepend($(n).next());
        $(n).delay(500).queue(function () {
            $(this).removeClass("validate[required]"); //remove the class name from select2 container(div), so that validation engine dose not validate it
            $(this).dequeue();
        });
    });	
	//Datepicker
   jQuery('.datepicker2').datepicker({
			dateFormat : 'dd-mm-yy',
			changeMonth : true,
			changeYear : true
			});

   //Data table configurations
   var oTable = $("#test").dataTable({
	   	"iDisplayLength": 10,
		"aLengthMenu": [5,10,25,50,100],
		"sPaginationType": "full_numbers",
		"aoColumns": [	{"bSortable": false },
						{"bSortable": false },
					<?php foreach($tbHdr as $v): ?>
						null,
					<?php endforeach; ?>
						{"bSortable": false }
					] 
	});
	oTable.fnSort( [ [1,'asc'] ] );
   
	//Location transfer detail 
	$('.detail').live('click',function(){
		var row = $(this).parents('tr');
		var itemCode = $(row).find('td:nth-child(3)').html();
		itemCode = itemCode.split(']');
		itemCode = itemCode[0].split('[');
		itemCode = itemCode[1].replace(/\s+/g, '-');
		window.location = "<?php echo base_url() ?>inventory/rptSubtotalDetail/"+$(row).find('.ID').text()+"/<?php  echo $locID; ?>";
	});
	
}); 

function changeList(){
	var locID = $('#location').val();
	var urls = "<?php echo base_url();?>inventory/rptbylocation/"+locID;
		window.location = urls;
} 

 
</script>

<div id="content">                        
<div class="wrap">
<div class="head">
	<div class="info">
        <h1><?php echo element('compName', $this->session->userdata('logged_in')) ?> [ 
            <?php echo element('compNo', $this->session->userdata('logged_in')) ?> ]</h1>
        <ul class="breadcrumb">
            <li><a href='<?php echo base_url(); ?>'><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
            <li><a href="<?php echo base_url(); ?>/locationtransfer"><?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
            <li class="active"><?php echo $this->lang->line('title') ?></li>
        </ul>
	</div>
	<div class="search">
		<form action="<?php echo base_url() ?>admin/search" method="post">
			<input name="search_text" type="text" placeholder="search..."/>                                
            <button type="submit"><span class="i-magnifier"></span></button>
		</form>
	</div>                        
</div><!-- head --> 
<div class="content">
	<div class="wrap">        
        <div class="content">
            <div class="wrap">   
                
                <div class="row-fluid">
                    <div class="span12">
                        <div class="block">
                        	<div class="head">
                            	<h2><?php echo $this->lang->line('selectLoc') ?></h2>
                            </div>
                            <div class="content">
                				<div class="controls-row"><!-- Row 4-->
                                    <div class="span6 tac">
                                    	<div class="span5 tar"><?php echo form_label($this->lang->line('selectLoc'));?></div>
                                        <div class="span6">
                                            <?php
                                                $preselcat = $locID?$locID:'';
												$options[''] = 'All';
                                                if(!empty($location)){
	                                                foreach($location as $row){
	                                                    $options[$row->fldid] = $row->code;
	                                                }
                                                }
                                                $js='onChange="changeList()" id="location" class="span10"';
                                                echo form_dropdown('location', $options, $preselcat, $js);
                                            ?>
                                        </div>
                                	</div>                                   
                                </div><!-- End Row 4-->
                            </div>
                            <div class="footer"></div>
                        </div>
                        <div class="block">                            
                            <div class="head">
                                <h2><?php echo $this->lang->line('title') ?></h2>
                            	<ul class="buttons">
                                     <li><a href="<?php echo base_url()?>inventory/rptbylocationprint/<?php echo $locID; ?>" name="updatePosting" onclick=""><?php echo $this->lang->line('print') ?></a></li>
                                </ul>
                            </div><!-- head -->
                            <div class="content np table-sorting">
                                <table cellpadding="0" cellspacing="0" width="100%" id="test" class="editable">
                                    <thead>
                                    <tr>
                                    	<th style="display:none;">&nbsp;</th>
                                    	<th class="tac">#</th>
                                    <?php 
									foreach($tbHdr as $row): 	
										if(in_array($row,$alignRight)):
									?>
                                        <th class="tar"><?php echo $this->lang->line($row); ?></th>
                                    <?php 
										else:
									?>
                                    	<th class="tac"><?php echo $this->lang->line($row); ?></th>
                                    <?php 
										endif;
									endforeach; ?>
										<th width="55" class="tac"><?php echo $this->lang->line('action');?></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php $bil = 0; 
                                    if(isset($datatbls) && !empty($datatbls)):
                                        foreach($datatbls as $item):
                                        $bil++?>
                                        <tr class="itemList">
                                        	<td class="ID" style="display:none"><?php echo $item->itemID; ?></td>
                                            <td class="tac"><?php echo $bil; ?></td>
										<?php 
										foreach($tbHdr as $row): 
											if(in_array($row,$alignRight)):
										?>
                                            <td class="tar span2"><?php echo $item->$row; ?></td>
                                        <?php 
											else:
										?>
                                        	<td class="tac span2"><?php echo $item->$row; ?></td>
                                        <?php 
											endif;
										endforeach; ?> 
                                        	<td class="tac"><?php
												$attr = 'class="btn btn-mini btn-primary detail" title="'.$this->lang->line("Show Detail").'"';
												echo form_button('edit','<span class="i-pen">',$attr); ?>
											</td>
                                        
                                        </tr>
                                        <?php 
                                        endforeach;
                                    endif;?>
                                    </tbody>         
                                </table>
                            </div><!-- content -->                              
                        </div><!-- block -->
                    </div><!-- span12 -->
                </div><!-- row-fluid -->	
            </div><!-- wrap -->
        </div><!-- content -->
	</div>
</div>
