<!--
Author      : Herpan / 22/7/2014 / view for Chart of Account list
Edited      : Ferry / 28-11-2014 / Show COA based On Company and Branch
Edited      : Fachri /  
Revisi      : Dhidhik, 28 Maret 2016 , dialog modal 
-->

<?php
	//---------Untuk privellege jika dia ada tombol save----------
	if($group_user->AddPrivillage == 1){
		$cek_autority_add 		= "";
	}
	else{
		$cek_autority_add 		= "disabled";
	}
	
	if($group_user->DeletePrivillage == 1){
		$cek_autority_delete 		= "";
	}
	else{
		$cek_autority_delete 		= "disabled";
	}
	
	if($group_user->EditPrivillage == 1){
		$cek_autority_edit 		= "";
	}
	else{
		$cek_autority_edit 		= "disabled";
	}
	//-------------end----------------------------
?>

<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'north',border:false" style="height:30px">
        <div style="padding:2px">
            <?php if(strpos($this->session->userdata('branch'),'HO')!==false){ ?>
                <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onClick="parent.tab_add('New Account','<?=$menu_link?>','icon-coa','add');" <?php echo $cek_autority_add;?>>New</a>
                <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'" id="edit-linkbutton" 
                    onclick="parent.tab_edit('Edit Account', '<?php echo $menu_link; ?>', 'icon-edit', 'edit', $('#grid').datagrid('getSelected').AccountNumber + '_' + $('#grid').datagrid('getSelected').BranchCode + '_' + $('#grid').datagrid('getSelected').BranchName);" <?php echo $cek_autority_edit;?>>Edit</a>						
                <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'" onclick="delete_coa_act();" id="suspend-linkbutton" <?php echo $cek_autority_delete;?>>Suspend</a>
            <?php } ?>

            <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick=" $('#grid').datagrid('reload');">Refresh</a>
            <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-print'" onClick="parent.tab_add('Print Chart Of Account', '<?php echo $menu_link; ?>', 'icon-coa', 'to_preview');">Print Preview</a>
            <!--<a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-excel'" onClick="modal_open('Import New Account','dlg_importfile')" <?php if($coa_num_rows > 0){ echo ' disabled="true"'; } ?>>Import from file</a>-->
       
			<?php if(strpos($this->session->userdata('branch'),'HO')!==false){ ?>
            <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-excel'" onClick="cek_data_gl()" >Import from file</a>
        
            <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onClick="cek_comp_gl();" <?php if($coa_num_rows<=0){ echo ' disabled="true"'; } ?> <?php echo $cek_autority_add;?>>Company G/L Account</a>
             <?php } ?>
            <!--<a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onClick="parent.tab_new('Company P/L Account', '<?php echo "list/coa/company_pl_account"; ?>','icon-company')"<?php if($coa_num_rows<=0){ echo ' disabled="true"'; } ?>>Company P/L Account</a>-->
            
            <span style="float:right">
                
            <?php if($HaveBranch == 1 and $BranchStatus == 0){ ?>
                <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onClick="parent.tab_add('New Bank Account','list/coa/add_branch/','icon-coa');" <?php echo $cek_autority_add;?>>Branch Bank Account</a>
                <!--<a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onClick="parent.tab_new('New P/L Account','list/coa/branch_pl_account/','icon-coa')">Branch P/L Account</a>-->
                    <!--<a href="#" id="edit-branch" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'" onClick="parent.tab_edit('Edit Account', '<?php echo $menu_link; ?>', 'icon-edit', 'edit_branch', $('#tt').datagrid('getSelected').AccountNumber)" disabled="true">Edit Branch Account</a>-->
            <?php } ?>
            </span>
        </div>
    </div>
    
    <div id="west-panel" data-options="region:'west',split:true,border:true" title="Filter" style="width:190px;background-color:#CCCCFF;">
        <div style="padding:5px">
            <table width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="283" align="left" colspan="2" style="padding-bottom:8px;">
                        <b>Find</b>
                    </td>
                </tr>

                <tr>
                    <td width="283" align="left" colspan="2">
                        <input id="txt_IDNumber"   name="txt_IDNumber"   placeholder="< Account No >" style="margin:2px 0px 3px;width:173px;height:20px;border:1px solid #CCC" >
                    </td>
                </tr>

                <tr>
                    <td width="283" align="left" colspan="2">
                        <input id="txt_Description" name="txt_Description" placeholder="< Account Name >" style="margin:2px 0px 3px;width:173px;height:20px;border:1px solid #CCC" >
                    </td>
                </tr>

                <tr>
                    <td colspan="2">
                        <div class="tr-divider"></div>
                    </td>
                </tr>

                <tr>
                    <td width="283" align="left" colspan="2" style="padding-bottom:8px;">
                        <b>Account Type</b>
                    </td>
                </tr>

                <tr>
                    <td width="283" align="left" colspan="2">
                        <select class="easyui-combogrid" name="account_type" id="account_type" style="width:175px;height:24px;" 
                            data-options="
                                panelWidth:270,
                                idField:'AccountSubTypeID',
                                textField:'AccountTypeName',
                                url:'<?php echo base_url(); ?>custom/get_data/accountsubtype_with_bsstatus',
                                columns:[[
                                    {field:'AccountTypeName',title:'Account Type Name',width:250}
                                ]]
                            ">
                        </select>
                    </td>
                </tr>
                
				<tr><td><div class="tr-divider"></div></td></tr>
                
                <!------------ copy company dari sini------------------------------------------------------------------------>
                <tr>
                    <td align="left" style="padding-bottom:8px;">
                        <b>by Company</b>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                      <select name="cmb_company" id="cmb_company" 
                        class="easyui-combobox" 
                        style="width:174px;"
                        data-options="
                            value:'<?php echo $this->session->userdata('company');?>',
                           
                            valueField:'CompanyCode',
                            textField:'CompanyName',
                            url:'<?php echo base_url(); ?>custom/get_data/company_find_master',
                            onSelect: function(rec){
                                var url = '<?php echo base_url(); ?>custom/get_data/branch_by_company_new/'+rec.CompanyCode;
                                    $('#cmb_branch').combobox('reload', url);
                                    $('#cmb_branch').combobox('setValue', '');
                                }
                        "editable="false"
                    >
                    
                    </select>
                    </td>
                </tr>
                <!------------end------------------------------------------------------------------------->
                
                <!-------copy branch dari sini------------------------------------------------------------------------>
                <tr>
                    <td align="left" style="padding-bottom:8px;">
                        <b>by Branch/Depo</b>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                       <select name="cmb_branch" id="cmb_branch" 
                            class="easyui-combobox" 
                            style="width:174px;"  
                            data-options="
                                value :'<?php echo $this->session->userdata('branch');?>',
                                valueField:'BranchCode', 
                                textField:'BranchName', 
                                url:'<?php echo base_url(); ?>custom/get_data/branch_by_company_new/<?php echo $this->session->userdata('company');?>'
                            " editable="false" 
                        >
                        
                        </select>
                    </td>
                </tr>
                <!---------end------------------------------------------------------------------------------>
            
                <!---------------ini separator---------------------->
                <tr><td><div class="tr-divider"></div></td></tr>
                <!----------------end--------------------------------->
                
                <!----------------------------------ini by status---------------------------------------------------------->
                <tr>
                    <td style="padding-bottom:8px;"><b>by Status</b></td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="0" style="margin-left:0px;"  /> Waiting For DP
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="1" style="margin-left:0px;"  /> On Progress
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="2" style="margin-left:0px;"  checked/> Finished
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="3" style="margin-left:0px;"  /> Suspended
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="4" style="margin-left:0px;"  /> Need App. Mgr.
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="5" style="margin-left:0px;"  /> Need App. Dir.
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="6" style="margin-left:0px;"  checked/> App. Dir &amp; Mgr
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="7" style="margin-left:0px;"  /> App. Limit
                    </td>
                </tr>
                
                 <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="9" style="margin-left:0px;" /> Cancel By Dir.
                    </td>
                </tr>
                <!------------------------------------------------------end-------------------------------------------------------------------------------------------->
                
                <!--copy dari sini untuk button reset dan search-->
                <tr>
                    <td height="38"><div style="float:right;"><a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onClick="location.reload();" >Reset</a> <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onClick="searching_data_transaksi();" >Search</a></div></td>
                </tr>
                <!--end-------------------------->               
            </table>
        </div>
    </div>
    
    <div data-options="region:'center',border:false,iconCls:'icon-ok'">
        <table id="grid" title="" iconCls="icon-save" rownumbers="true" pageSize="600" fitColumns="true" singleSelect="true" 
            data-options = "border:false,view:scrollview,autoRowheight:false" fit="true"
            url="<?php echo base_url(); ?>list/coa/ajax" 
        >  
            <thead>
                <tr>
                    <?php if($BranchStatus == 0){ ?>
                        <th field="AccountNumber" width="80" formatter="format_acc" sortable="true" data-options="align:'left',halign:'center'"><b>Account Number</b></th>
                        <th field="AccountNameShow" width="180" formatter="format_acc" sortable="true" data-options="align:'left',halign:'center'"><b>Account Name</b></th>
                    <?php } else {?>
                        <th field="AccountNumber" width="70" sortable="true" data-options="align:'left',halign:'center'"><b>Account Number</b></th>
                        <th field="AccountNameShow" width="180" sortable="true" data-options="align:'left',halign:'center'"><b>Account Name</b></th>
                    <?php }?> 

                    <th field="AccountTypeName" width="100" sortable="true" data-options="align:'left',halign:'center'" ><b>Sub Type</b></th>
                    <th field="AccTypeName" width="100" sortable="true" data-options="align:'left',halign:'center'" ><b>Account Type</b></th>
                    <th field="CurrentBalance" width="80" align="right" sortable="true" data-options="align:'right',halign:'center'" formatter="formatRp_bank"><b>Period Balance</b></th>
                    <th field="Status" width="40" align="center" sortable="true"><b>Auto Currency</b></th>
                    <th field="BranchStatus" width="110" sortable="true" data-options="align:'left',halign:'center'" hidden="true"><b>Branch Status</b></th>
                    <th field="BranchCode" width="110" sortable="true" data-options="align:'left',halign:'center'" hidden><b>Branch Code</b></th>
                    <th field="BranchName" width="110" sortable="true" data-options="align:'left',halign:'center'" hidden><b>Branch Name</b></th>
                    <th field="GLSaldoOpening" width="110" sortable="true" data-options="align:'right',halign:'center'" formatter="formatRp" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:1,required:true,disabled:false}}" hidden ><b>Opening Balance</b></th>
                    <th field="AccountBSStatus" width="110" sortable="true" data-options="align:'left',halign:'center'" hidden="true"><b>Account BSStatus</b></th>
                    <th field="AccountAutoStatus" width="110" sortable="true" data-options="align:'left',halign:'center'" hidden="true"><b>Account BSStatus</b></th>
                    <th field="AccountName" width="110" sortable="true" data-options="align:'left',halign:'center'" hidden="true"><b>Account Name</b></th>
                </tr>
            </thead>
        </table>
    </div>
</div>

<!--// Popup import file -->
<!--<div id="dlg_importfile" class="easyui-dialog" data-options="closed:true,width:'370',height:'150',modal:true" style="">
    <form id="data" method="post" enctype="multipart/form-data">
        <fieldset style="height:68px;padding-top:30px;">
            <input type="file" id="uploadfile" name="uploadfile" />
        </fieldset>
            <button>Upload</button>
    </form>
    
    <center><img src='<?php echo base_url();?>assets/custom/img/c_loader.gif' id='loading_img' alt='loadingImg' style='display:none;' /></center>
</div>-->
<!--================= Dialog Import =========================================-->
<div id="dialog-buttons-group-import" style="border:none;">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="save_import()">Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:jQuery('#dlg_importfile').dialog('close')">Cancel</a>
</div>

<div id="dlg_importfile" class="easyui-dialog" style="width:370px;height:150px;padding:10px 20px;" closed="true" buttons="#dialog-buttons-group-import" data-options="modal:true">
    <form id="data" method="post" enctype="multipart/form-data">
        <div class="fitem">
            <fieldset style="border:1px solid #CCC;">
                <legend>File Location</legend>
                <input type="file" name="uploadfile" id="uploadfile" style="width:100%">                    		
            </fieldset>	
        </div>
    </form>
</div>
<!--================= End Dialog Import =====================================-->
<script type="text/javascript">
    $(document).ready(function(){
		var status_privelage_delete = '<?php echo $group_user->DeletePrivillage;?>';
		var status_privelage_edit 	= '<?php echo $group_user->EditPrivillage;?>';
		
        $('#cbo_period_month').combobox('setValue', <?= date('m') ?>);
		
        $('#grid').datagrid({
            onDblClickRow:function(rowIndex, rowData){
                CompanyCode = '<?=$this->session->userdata('branch')?>';
                if(status_privelage_edit == 1){
					if(CompanyCode.indexOf('HO') !== -1){				  
						if(rowData.AccountTypeName == 'Bank'){
	//                        parent.tab_edit('Edit Branch Bank Account', '<?php echo $menu_link; ?>', 'icon-edit', 'edit_branch_bank_account', rowData.AccountNumber + '_' + rowData.BranchCode + '_' + rowData.BranchName);
							parent.tab_edit('Edit Branch Bank Account', '<?php echo $menu_link; ?>', 'icon-edit', 'edit', rowData.AccountNumber + '_' + rowData.BranchCode + '_' + rowData.BranchName);
						}
						else{
							parent.tab_edit('Edit Account', '<?php echo $menu_link; ?>', 'icon-edit', 'edit', rowData.AccountNumber + '_' + rowData.BranchCode + '_' + rowData.BranchName);
						}
					}
				}
            },
			onClickRow:function(index,value){
				if((value.Status !='App. Dir & Mgr') && (value.Status !='App. Limit') && (value.Status !='Finished') && (value.Status !='Need App. Dir.')){
					$('#suspend-linkbutton').linkbutton('disable');
				}else{
					if(status_privelage_delete == 1){
						$('#suspend-linkbutton').linkbutton('enable');
					}
					else{
						$('#suspend-linkbutton').linkbutton('disable');
					}
					
					if(status_privelage_edit == 1){
						$('#edit-linkbutton').linkbutton('enable');
					}
					else{
						$('#edit-linkbutton').linkbutton('disable');
					}
				}
			},
			
            onSelect:function(rowIndex, rowData){
                <?php if($HaveBranch == 1 and $BranchStatus == 0){ ?>            
                    if(rowData.AccountTypeName == 'Bank'){
                        $('#edit-branch').linkbutton('enable');
                    }
                    else{
                        $('#edit-branch').linkbutton('disable');
                    }
                <?php } ?>
            },

            rowStyler: function(index,row){
                if (row.AppLevel2Status == 0){
//                  return inline style	
                    return 'background-color:#FF6666;color:#fff;';
                }
            }
	});
	    
//	$("form#data").submit(function(){
//            var formData = new FormData($(this)[0]);		
////            $('#loading_img').show();
//
//            $.ajax({
//                url: 'coa/import',
//                type: 'POST',
//                data: formData,
//                async: false,			
//                success: function (result) {
//                    var result = eval('('+result+')');
//
//                    if (result.status==true){
//                        alert(result.message);									
//                    } 
//                    else {
//                        alert(result.message);					
//                    }	
//                },
//
//                cache: false,
//                contentType: false,
//                processData: false,
//            });
//        });
		
		//dtg_coa = $('#grid').datagrid('getRows');
		grid_navigation('COA','<?php echo $menu_link; ?>'); 
    });	   		
        
	function delete_coa(url, id) {
    url = base_url + url;
	var i               = $('#grid').datagrid('getSelected');
   	var detail          = JSON.stringify(i);
	
	var selectedrow     = $('#grid').datagrid('getSelected');
    var row_index       = $('#grid').datagrid('getRowIndex', selectedrow);
		
    $.messager.confirm('Confirm','Are you sure you want to remove this data ?', 
		
    function(r){
        	if (r){
            	$.post(url + '/delete',{id:id, detail:detail},function(result){
                	if (result.status==true){
                    	$.messager.alert('Success',result.message,'info',function(){						
							location.reload();							
						});
                	} 
                	else {
                    	$.messager.alert('Error',result.message,'error',function(){						
						//location.reload();							
						});
                	}
            	},'json');
        	}
    	});
	}

    //Fungsi untuk tampilan menjorok
    function format_acc(val,row){
	return '<span style="padding-left:'+row.AccountLevel+'em;">'+val+'</span>';	
    }
	
	function cek_data_gl(){
		var user_data = '<?php echo $this->session->userdata('username');?>';
		var user_data_20000 = '20000';
		var cek_data_gl = '<?php echo $cek_data_gl ?>';
		
		if(cek_data_gl == 1){
			if(user_data != user_data_20000){
				$.messager.alert('Warning','Maaf tidak bisa import untuk ke dua kalinya, silahkan hubungi Department IT','warning',function(){						
						//location.reload();							
				});
			}
			else{
				modal_open('Import New Account','dlg_importfile');
			}
		}
		else{
			modal_open('Import New Account','dlg_importfile');
		}
	}
	
	function cek_comp_gl(){
		var user_data = '<?php echo $this->session->userdata('username');?>';
		var user_data_20000 = '20000';
		
		if(user_data != user_data_20000){
			$.messager.alert('Warning','Maaf hanya user tertentu yang bisa akses halaman ini, silahkan hubungi Department IT','warning',function(){						
					//location.reload();							
			});
		}
		else{
			parent.tab_add('Company G/L Account', '<?php echo "list/coa/company_coa"; ?>','icon-company');
		}
	}
	
	function delete_coa_act(){
		
		var jobtitle_status = '<?php echo $this->session->userdata('jobtitle_status');?>';
		var user_data = '<?php echo $this->session->userdata('username');?>';
		var user_data_20000 = '20000';
		
		if((jobtitle_status == 1) || (jobtitle_status == 0) || (user_data == user_data_20000)){
			delete_coa('<?php echo $menu_link; ?>', $('#grid').datagrid('getSelected').AccountNumber);
		}
		else{
			$.messager.alert('Warning','Maaf hanya user tertentu yang bisa akses suspended coa, silahkan hubungi Department IT','warning',function(){						
					//location.reload();							
			});
		}
	}
        
    //============ DHIDHIK, 28 Maret 2016 ====================================//
    function save_import(){    
        var url = "<?php echo $menu_link ?>";
        import_data_coa(url,"form#data","dlg_importfile");
    }
    //============ END DHIDHIK, 28 Maret 2016 ================================//
    
</script>