<!---- 
    Author 	: Ferry / Tanggal     : 05-12-2014	
-->

<div class="easyui-layout" data-options="fit:true,border:false">
    <form id="fm_branch_pl_coa" name="fm_branch_pl_coa" method="post" action="">

        <!-- top view-->
        <div id="form-header" data-options="region:'north',border:false" >
            <div id="form-header-wrapper">
                <table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
                    <tr>
                        <td align="left" valign="middle">					
                        </td>							

                        <td height="25" align="right" valign="middle">								
                            <span class="form-title">
                                Branch P/L Account
                            </span>
                        </td>
                    </tr>
                </table>		     	
            </div>			
        </div>
        <!-- end top view -->

        <!-- center view -->
        <div id="form-body" data-options="region:'center',border:false">
            <div id="form-wrapper" class="easyui-panel" style="width:1180%;height:300px;padding:5px;">
                <div class="easyui-layout" fit="true">					
                    <div data-options="region:'south',split:true,collapsible:false" style="height:136px;">
                        <table id="dtg_branch" title="List Of Branch" class="easyui-datagrid" style="width:auto"
                            url="<?php echo base_url()?>custom/get_data/branch_active_by_company"
                            idField="BranchCode"
                            toolbar="#toolbar">

                            <thead>
                                <tr>
                                    <th field="ck" checkbox="true"></th>
                                    <th width="150" align="left" halign="center" field="BranchCode"><b>Branch Code</b></th>
                                    <th width="970" align="left" halign="center" field="BranchName"><b>Branch Name</b></th>																		
                                </tr>
                            </thead>
                        </table>
                    </div>
                    
                    <div data-options="region:'west',split:true,collapsible:false" style="width:1173px;">
                        <table id="dtg_pl_account" class="easyui-datagrid" title="List Of G/L Account" rownumbers="true"
                            url="<?php echo base_url(); ?>list/coa/ajax_branch_pl_account"                                
                            data-options="border:false,singleSelect:false,fit:false,fitColumns:true, 
                            idField:'AccountNumber',
                            onLoadSuccess:function() {
                                var rows = $(this).datagrid('getRows');
                                for(var i=0; i<rows.length; i++){
                                    if(rows[i]['PLStatus'] == 1){
                                        $(this).datagrid('checkRow',i);
                                    }
                                    else{
                                        $(this).datagrid('uncheckRow',i);
                                    }
                                }    
                            }"
                            >
                            
                            <thead>
                                <tr>
                                    <!--<th field="status" editor="{type:'id_field',options:{readonly:true}}"></th>-->
                                    <!--<th field="AccountNumber" width="90" formatter="format_acc" sortable="true"><b>Account No</b></th>-->
                                    <th field="PLStatus" width="60" align="center" checkbox="true" title="Clear"></th>
                                    <th data-options="field:'AccountNumber'" formatter="format_acc" width="100" halign="center"><b>Account Number</b></th>
                                    <th data-options="field:'AccountName'" formatter="format_acc" width="350" halign="center"><b>Account Name</b></th>
                                    <!--<th data-options="field:'AccountTypeName'" width="150" halign="center"><b>Account Type</b></th>-->
                                    <th data-options="field:'AccountTypeName'" width="250" halign="center"><b>Account Type</b></th>
                                    <th data-options="field:'Status'" width="60" align="center" halign="center"><b>Status</b></th>
                                    <th data-options="field:'AccountChild'" width="150" halign="center" hidden="true"><b>Account Child</b></th>
                                    <th data-options="field:'AppLevel1Status'" width="150" halign="center" hidden="true"><b>App. Mgr</b></th>
                                    <th data-options="field:'AppLevel2Status'" width="150" halign="center" hidden="true"><b>App. Dir</b></th>
                                </tr>
                            </thead>
                        </table>					
                    </div>
                </div>						          
            </div>	

            <div id="form-footer">
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-help" onclick="" plain="true">Help</a>
                <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-save" onclick="save_branch_pl_coa('list/coa');">Save</a>					  
                <a href="javascript:void(0)" class="easyui-linkbutton  form-button" iconCls="icon-cancel" onclick="load_branch_pl_coa('list/coa');">Cancel</a>						
            </div>
        </div>
        <!-- end center view -->	
    </form>	
</div>

<script>
    $(document).ready(function(){
        $('#dtg_pl_account').datagrid({            
            rowStyler: function(index, row){
                if (row.AppLevel1Status==0 || row.AppLevel2Status==0){
                    return 'background-color:#FF6666;color:#fff;'; 
                }
            }				
        });
			
    });

    //Fungsi untuk tampilan menjorok
    function format_acc(val,row){
        return '<span style="padding-left:'+row.AccountLevel+'em;">'+val+'</span>';	
    }
	        
//        Edit Record on Click
	/*$(document).ready( function(){
		$("#selected_coa").datagrid({
			onClickRow:function(rowIndex){
				var row = $("#selected_coa").datagrid("getSelected");
			}
		})
	});*/

    function save_branch_pl_coa(url) {        
        url = base_url + url + '/insert_branch_pl_account';
        
        var selected_pl_account = JSON.stringify($('#dtg_pl_account').datagrid('getChecked'));
        var selected_branch     = JSON.stringify($('#dtg_branch').datagrid('getChecked'));
        
        $.messager.confirm('Warning :','Pastikan Branch yang dipilih sudah benar...!!',  
            function(r){
                if (r){
                    $.post(url, {selected_pl_account:selected_pl_account, selected_branch:selected_branch}, function(result){
                        if (result.status==true){
			    $.messager.alert('Success',result.message,'info',function(){});				
                        } 
                        else {
			    $.messager.alert('Error',result.message,'error',function(){});				
                        }
                    },'json');
                }
            }
        );
    }

    function load_branch_pl_coa(url) {        
        url = base_url + url + '/branch_pl_account';

        $.messager.confirm('Warning :','Anda Yakin, akan membatalkan semua transaksi...?',  
            function(r){
                if (r){
                    $.post(url);
                }
            }
        );
    }
</script>