<?php //print_r($supplier); exit(); ?>
<script type="text/javascript">
	$(document).ready(function(){
		//Data table configurations
	   	var oTable = $("#test").dataTable({
			"iDisplayLength": 10,
			"aLengthMenu": [5,10,25,50,100],
			"sPaginationType": "full_numbers",
			"aoColumns": [	{"bSortable": false},
							{"bSortable": false},
							null,
							null,
							null,
							{"bSortable": false}
						] 
		});
		oTable.fnSort( [ [1,'asc'] ] );
		//Data table configurations end
		
		$("table .checkall1").live("click", "checkall1",function(){           
			$(oTable.fnGetNodes()).find(':checkbox').prop('checked', this.checked);
		});
		
		
		//Popup alert for editing
		$("table.editable").on("click",".edit",function(){
			//rRow = $(this).parents("tr");
			ID = $(this).parents('tr').find('.itemList').text(); 
			$("#row_edit").dialog("open");
		});
		
		$("#row_edit").dialog({
			autoOpen: false,
			resizable: false,        
			modal: true,
			buttons: {
				"Continue...": function() {
					window.location.href = "<?php echo base_url();?>itemcountadjust/edit/" + ID;		
					$(this).dialog("close");
				},
				Cancel: function() {
					$(this).dialog("close");
				}
			}
		});
		
		//Confirm adjust transaction
		//Confirm transection
		$('.confirm').live('click',function(){
			var transferList = '';
			$('.itemList').each(function(){
				if($(this).parent('tr').find('input:checked').attr('checked') == 'checked'){
					if(transferList == '')	transferList += $(this).text();
					else					transferList += ','+$(this).text();
				}
			}); 
			
			jQuery.ajax({
				url: "<?php echo base_url(); ?>itemcountadjust/confirmAdjust/",
				async: false,
				type: "POST",
				data: 'adjstID='+transferList,
				dataType: "html",
				success: function(data) {
					if(data == 'Success'){
						//location.reload();	
					}	
				}
			});
		});
		
	});
	
	function  calVariance(obj,nCont){
		var qty = parseInt(obj.find('#quantity').text());
		var perItemPrice = parseFloat(obj.find('#costQty').text().replace(',',''))/qty;
		var countPrice = perItemPrice*nCont;
		var costVariance = (qty*perItemPrice)-countPrice;
		var itemId = obj.find('.itemList').text();
		
		//Changeing HTML DOM values
		obj.find('#variance').text(qty - nCont).animate({backgroundColor:'#f89406',color:'#fff'});
		obj.find('#varCost').text(parseFloat(countPrice, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,")).animate({backgroundColor:'#f89406',color:'#fff'});
		obj.find('#costVar').text(parseFloat(costVariance, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString()).animate({backgroundColor:'#f89406',color:'#fff'});
	}
</script>

<div id="content">                        
    <div class="wrap">
    	<!--Header start here-->
		<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() . "home" ?>"><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
                    <li><a href="<?php echo base_url() . "inventoryControl" ?>"><?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                    <li class="active"><?php echo $this->lang->line('titlelist') ?></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>
        <!--Header end here-->
        
        <!--Alert Message start-->
        <?php 	
			$message = $this->session->flashdata('msg');
			$alert = $this->session->flashdata('danger-msg');
			if(isset($message) && $message != ''): ?>
            <div class="content alertbox">                                                
                <div class="row-fluid">
                    <div class="span12">        
                        <div class="alert alert-success">            
                            <strong>Success! </strong><?php echo $message;?>
                        </div>       
                    </div>
                </div>
            </div>
        <?php	
			elseif(isset($alert) && $alert != ''): ?>
            <div class="content alertbox">                                                
                <div class="row-fluid">
                    <div class="span12">        
                        <div class="alert alert-error">            
                            <strong>Deleted! </strong><?php echo $alert;?>
                        </div>       
                    </div>
                </div>
            </div>
		<?php endif; ?>
        <!--Alert Message end-->
        
        <!--Main content start here-->
        <div class="content">
            <div class="wrap">                    
                <div class="row-fluid">
                    <div class="span12">
                    	<?php if(!empty($location)): ?>
                        <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[''] = '--Select Location--';
                                                foreach($location as $row){
                                                    $options[$row->fldid] = $row->code;
                                                }
                                                $js=' class="input-medium location"';
                                                echo form_dropdown('location', $options, $preselcat, $js);
                                            ?>
                                        </div>
                                	</div>
                                    <div class="span6 tac">
                                    	<div class="span4"><?php echo $this->lang->line('fromNo') ?></div>
                                        <div class="span8">
                                            <?php
                                            $data = array(
                                                'value'=>$formNo,
                                                'name'=>'formNo',
                                                'id'=>'formNo',
                                                'style'=>'color: red;',
                                                'class'=>'input-small',); 
                                            echo form_input($data, set_value($formNo));
                                            ?>
                                            <?php
                                            $data = array(
                                                'value'=>"0000",
                                                'name'=>'formID',
                                                'id'=>'formID',
                                                'style'=>'',
                                                'disabled'=>'disabled',
                                                'placeholder'=>'0000',
                                                'class'=>'input-small validate[required]',); 
                                            echo form_input($data);
                                            ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="footer"></div>
                        </div>
                        <?php endif; ?>
                        
                        <div class="block">
                            <div class="head">
                                <h2><?php echo $this->lang->line('titlelist'); ?></h2>
                                <!--<ul class="buttons">
                                    <li><a href="" class="" title="New"><span class="i-plus-2"></span></a></li>
                                </ul>-->                                        
                            </div>
                            <div class="content np table-sorting">
                                <table cellpadding="0" cellspacing="0" width="100%" id="test" class="editable">
                                    <thead>
                                    <tr>
                                        <th style="display:none"></th>
                                        <th>#</th>
                                        <th><?php echo $this->lang->line('formNo') ?></th>
                                        <th><?php echo $this->lang->line('location') ?></th>
                                        <th><?php echo $this->lang->line('adjstDate') ?></th>                       
                        				<th class="tac"><input type="checkbox" id="checkall1" class="checkall1"/></th>
                                    </tr>
                                    </thead>
                                     <tbody>
										<?php 
										
                        				if(!empty($datatbls)):
										$bil = 0;
										$i = 1;
                                        foreach($datatbls as $datatbl):
                                        $bil++?>
                                        <tr>
                                            <td id="" class="ID itemList" style="display:none"><?php echo $datatbl->ID; ?></td>            
                                            <td id="serial" class="no-edit"><?php echo $i++; ?></td>                                                          
                                            <td id="fromNo" class="no-edit"><a href="javascript:" class="edit"><?php echo $datatbl->formNo; ?></a></td>
                                            <td id="location" class="no-edit"><?php echo $datatbl->code; ?></td>
                                            <td id="adjstDate" class="no-edit"><?php echo $datatbl->adjustmentDate; ?></td>
					                    	<td class="tac"><input type="checkbox" class="checkbox" id="checkbox"/></td>
                                        </tr>
                                        <?php endforeach; 
										endif;
										?>
                                    </tbody>
                                </table>                                         
                        	</div>
                            <div class="footer">
                                <div class="side fr">
                                    <div class="btn-group">
                                        <?php 
                                            $data = array(
                                                    'name'=>'postcrdtn', 
                                                    'class'=>'btn-form btn-warning-form confirm');
                                            echo form_submit($data,$this->lang->line('confirmAdjust'));
                                            ?>
                                    </div>
                                </div>
                            </div>
                        </div>                                     
                    </div>
                </div>                                
            </div>
        </div>
        
	</div>
</div>
<div class="dialog" id="row_delete" style="display: none;" title="Are you sure to Delete?">
    <p><?php echo $this->lang->line('message1') ?></p>
</div>   
<div class="dialog" id="row_edit" style="display: none;" title="Are you sure to Edit ?">
    <p><?php echo $this->lang->line('message2') ?></p>
</div>

