<script type="text/javascript">
$(document).ready(function() {
    /* Build the DataTable with third column using our custom sort functions */
    $('select').select2();
   /* var oTable = $("#test").dataTable( {
        "iDisplayLength": 10,
		 "aLengthMenu": [5,10,25,50,100],
		 "asSorting": [ "asc"], "aTargets": [ 1 ],
		 "sPaginationType": "full_numbers", "aoColumns": [ { 
		 	"bSortable": false }, 
			null, 
//			null, 
			null, { 
			"bSortable": false } ]});
     oTable.fnSort( [ [1,'asc'] ] );
    $("table.editable").on("click",".remove",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text(); 
        $("#row_delete").dialog("open");
    });
    $("table.editable").on("click",".edit",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text(); 
        $("#row_edit").dialog("open");
    });
    $("#row_edit").dialog({
        autoOpen: false,
        resizable: false,        
        modal: true,
        buttons: {
            "Continue...": function() {
				window.location.href = "chartOfAcct?id=" + ID;		
                $(this).dialog("close");
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });    
    
   */
    
    function remove_row(row){
        row.remove();
 		$.ajax({
  			type: "POST",
  			url: "companyFinancialCalendar",
			data:"ID="+ID,
  			success: function(){
				alert('Row has been deleted...');
			},
		});       // Here your ajax action after delete confirmed
    }
    $("#row_delete").dialog({
        autoOpen: false,
        resizable: false,        
        modal: true,

        buttons: {
            "Delete": function() {
				window.location.href = "acctCodeDelete?ID=" + ID;		
                remove_row(rRow);
                $(this).dialog("close");
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });    
}); 


 function refrechConbo(){
        $('#listTableChartOfAcct tbody').empty();
         $.ajax({
             type: "POST",
             url: "<?php echo base_url() ?>setting/getTypeOfBusinessByIndustry",
             data: "id=" + $("#indusID").val(),
             success: function(data) {
                 $('#BuzTypeID').empty();
                   var opt = '' +
                         '<option></option>';
                 var resul = eval("(" + data + ")");
                 var n = resul.records.length;
                 var i = 0;
               
                 for (i = 0; i < n; i++)
                     opt = opt + '<option value="' + resul.records[i].ID + '">' + resul.records[i].name + '</option>';
                 
                 $('#BuzTypeID').append(opt);
             },
         });
     }
     
     
     function refreshChartOfAcctList(){
        $.ajax({
             type: "POST",
             url: "<?php echo base_url() ?>setting/loadCharOfAcct",
             data: "buzID=" + $("#BuzTypeID").val(),
             success: function(data) {
                 $('#listTableChartOfAcct tbody').empty();
                   var tbody = "";
                 var resul = eval("(" + data + ")");
                 var n = resul.records.length;
                 var i = 0;
               
                 for (i = 0; i < n; i++){
                     tbody = tbody + '<tr><td>' + (i+1) + '</td><td>' +   resul.records[i].acctCode + '</td> <td>' +  resul.records[i].acctName + '</td></tr>'
                     
                 }
                 $('#listTableChartOfAcct tbody').append(tbody);
             },
         });
     }

</script>



<div id="content">                        
<div class="wrap">
<div class="head">
	<div class="info">
		<h1><?php echo $companyName; //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 $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
                <li><a href="#"><?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 --> 
<!--industry-->
        <div class="content">
            <div class="wrap">                    
                <div class="row-fluid">
                    <div class="span12">
                        <div class="block">
                        <?php echo form_open('setting/createCompanyChartofAccount',array("id"=>"chartofaccount")); ?>
                            <div class="head">
                                <h2><?php echo $this->lang->line('title').' '.$companyName; ?></h2>
                            </div><!-- head -->
							<div class="content np">   
                                                 <?php 
                                        if($listOfChartAcct==FALSE){
                                            
                                        ?>
                                <div class="controls-row"><!-- Row 4-->
                                    <div class="span6 tac">
                                    	<input type="hidden" name="companyID" value="<?php echo $companyID; ?>" />
                                    	<div class="span6 tar"><?php echo form_label($this->lang->line('industry_classification'));?></div>
                                      
                                            <?php
												$preselcat = '';
												$options[] = '--Please Select--';
												foreach($industryInfo as $row){
													$options[$row->indusID] = $row->indusName;
												}
												$js='class="input-medium indusList" id="indusID" onchange="refrechConbo()"';
												echo form_dropdown('indusList', $options, $preselcat, $js);
											?>     
                                        
                                    </div>
                                    <div class="span6 tac">
                                    	<div class="span6 tar"><?php echo form_label($this->lang->line('type_of_business'));?></div>
                                       
                                            <?php
												$preselcat = '';
												unset($options);
												$options = array();
												$options[] = '--Please Select--';
												foreach($industryInfo as $row){
													$options[$row->bizID] = $row->bizName;
													$optionClass[$row->bizID] = 'buzTypeItm indus'.$row->indusID;
												}
												$js='class="input-medium buzTypeList" onchange="refreshChartOfAcctList()" id="BuzTypeID"';
												echo form_dropdown('businessTypeID', $options, $preselcat, $js, $optionClass);
											?>     
                                       
                                    </div>
                                </div><!-- End Row 4-->
                                
                                <div class="footer">
                                <div class="side fr">
                                    <div class="btn-group">
                                        <?php 
                                            $data = array(
                                                        'name'=>'addprice', 
                                                        'class'=>'btn btn-warning',
                                                        'id'=>'adItmPrice'
                                                    );
                                            echo form_submit($data,$this->lang->line('save'));
                                            ?>
                                    </div>
                                </div>
                            </div>
                                        <?php }else{ ?>
                                <div class="controls-row"><!-- Row 4-->
                                    <div class="span6 tac">
                                    	<input type="hidden" name="companyID" value="<?php echo $companyID; ?>" />
                                    	<div class="span6 tar"><?php echo form_label($this->lang->line('industry_classification'));?></div>
                                      
                                        <input value="<?php if(isset($buzType)) if($buzType) echo $buzType ["industry"]; ?>" class="input-medium buzTypeList" type="text" readonly /> 
                                        
                                    </div>
                                    <div class="span6 tac">
                                    	<div class="span6 tar"><?php echo form_label($this->lang->line('type_of_business'));?></div>
                                       
                                            <input  value="<?php if(isset($buzType)) if($buzType) echo $buzType ["bizName"]; ?>" class="input-medium buzTypeList" type="text" readonly /> 
                                       
                                    </div>
                                </div><!-- End Row 4-->
                                        <?php } ?>
                            </div><!-- content -->
                    		
                    	</div>
                    </div>
                </div>
			</div>
		</div>
<!--industry--->
<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('titlelist') ?></h2>
                    	<ul class="buttons">
                    		<li><!--a href="<?php echo base_url(); ?>glsetting/chartOfAcct" title="<?php echo $this->lang->line('addnew') ?>"><span class="i-plus-2"></span></a--></li>
                        </ul>                                       
                </div>
            	<div class="content np table-sorting">
            	<table cellpadding="0" cellspacing="0" width="100%" id="listTableChartOfAcct" class="editable">
                	<thead>
                    <tr>
            			<th style="display:none"></th>
            			<th class="tac">#</th>
						<th class="tac"><?php echo $this->lang->line('acctNo');?></th>
            			<th><?php echo $this->lang->line('acctName');?></th>       
                		<!--th width="55" class="tac"><?php echo $this->lang->line('action');?></th-->
            		</tr>
        			</thead>
       				 <tbody>
                                     <?php 
                                        if($listOfChartAcct){
                                            $i=0;
                                            foreach($listOfChartAcct as $row){
                                             ?>
                                     
                                     <tr>
                                         <td><?php echo ++$i; ?></td>
                                         <td><?php echo substr($row->acctCode,0,5).'-'.substr($row->acctCode,5,3).'-'.substr($row->acctCode,8.2); ?></td>
                                         <td><?php echo $row->acctName ?></td>
                                     </tr>
                                     <?php
                                            }
                                        }
                                     ?>
                                </tbody>
			</table>                                         
			</div>

<div class="dialog" id="row_delete" style="display: none;" title="Delete?">
    <p><?php echo $this->lang->line('message1');?></p>
</div>   
<div class="dialog" id="row_edit" style="display: none;" title="Edit ?">
    <p><?php echo $this->lang->line('message2');?></p>
</div>  

