<!--
Author      : Tagor / Tanggal : 15/09/2014
Revision    : Ferry / Tanggal : 01/01/2015
-->
	
	<?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----------------------------
	?>	
<!--<script type="text/javascript" src="<?=base_url()?>assets/custom/js/shortkeys/keys.js"></script> 	
<script type="text/javascript" src="<?=base_url()?>assets/custom/js/shortkeys/shortkeys_branchinfo.js"></script> -->
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'north',border:false" style="height:30px" id="button-top">
        <div style="padding:2px">
            <?php //if($this->session->userdata('branch_status') == 0){ ?>
<!--            <a href="#" class="easyui-linkbutton btnNew" id="new-linkbutton" data-options="plain:true,iconCls:'icon-add'" onClick="parent.tab_add('New Branch Info','<?=$menu_link?>','icon-add','add');" <?php echo $cek_autority_add;?>>New</a>
            <a href="#" class="easyui-linkbutton" id="edit-linkbutton" data-options="plain:true,iconCls:'icon-edit'" onclick="parent.tab_edit('Edit Branch Info', '<?=$menu_link?>', 'icon-edit', 'edit', $('#grid').datagrid('getSelected').BranchCode);" <?php echo $cek_autority_edit;?>>Edit</a>
            <a href="#" class="easyui-linkbutton" id="suspend-linkbutton" data-options="plain:true,iconCls:'icon-remove'" onclick="delete_branch();" <?php echo $cek_autority_delete;?>>Suspend</a>-->
            <?php //}?>
<!--            <a href="#" class="easyui-linkbutton" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="$('#grid').datagrid('reload');">Refresh</a>
            <a href="#" class="easyui-linkbutton" id="preview-linkbutton" data-options="plain:true,iconCls:'icon-print'" onClick="parent.tab_print_list('Print Branch', '<?=$menu_link?>', 'icon-edit', 'to_preview', $('#cmb_company').combobox('getValue'),$('#cmb_branch').combobox('getValue'))">Print Preview</a>-->
        </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">
      	<form class="form-filter">
        <table width="100%" cellpadding="0" cellspacing="0" id="tab_transstatus">
            <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_Name" name="txt_Name" placeholder="< Branch Name >" style="margin:2px 0px 3px;width:172px;height:20px;border:1px solid #ccc" />
                </td>
            </tr>

            <tr>
                <td width="283" align="left" colspan="2">
                    <input id="txt_Addres" name="txt_Addres" placeholder="< Branch Addres >" style="margin:2px 0px 3px;width:172px;height:20px;border:1px solid #ccc"  />
                </td>
            </tr>

            <!--ini separator--------------------------------------------->
            <tr><td colspan="2"><div class="tr-divider"></div></td></tr>
            <!--end-------------------------------------------------------->
            
            <!-------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>
            <!------------sampai sini-------------------------------------------------------------------------------->
                
            <!-------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>
            
        	<!--ini separator--------------------------------------------->
            <tr><td colspan="2"><div class="tr-divider"></div></td></tr>
            <!--end-------------------------------------------------------->
             
           <!--copy dari sini untuk by status--------------------------------------------->
<!--			<tr>
				<td width="283" align="left" colspan="2">
					<input type="checkbox" name="chk_TransStatus" value="1" style="margin-left:0px;" checked /> Active
				</td>
			</tr>

			<tr>
				<td width="283" align="left" colspan="2">
					<input type="checkbox" name="chk_TransStatus" value="3" style="margin-left:0px;"/> Suspended
				</td>
			</tr>
			<tr>
				<td width="283" align="left" colspan="2">
				  <input type="checkbox" name="chk_TransStatus" value="4" style="margin-left:0px;"  /> Need App. Mgr
				</td>
			</tr>
			<tr>
				<td width="283" align="left" colspan="2">
				  <input type="checkbox" name="chk_TransStatus" value="5" style="margin-left:0px;"  /> Need App. Dir
				</td>
			</tr>
			<tr>
				<td width="283" align="left" colspan="2">
					<input type="checkbox" name="chk_TransStatus" value="6" style="margin-left:0px;" /> App. Dir & Mgr
				</td>
			</tr>-->
			<!------------end-------------------------------------------------------------------------------->
            
            <!--ini separator--------------------------------------------->
            <!--<tr><td colspan="2"><div class="tr-divider"></div></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();" >Search</a></div></td>
            </tr>-->
            <!--end-------------------------->
          </table>
          </form>
        </div>
    </div>
    
    <div data-options="region:'center',border:false,iconCls:'icon-ok'">
        <table id="grid"
        	title="" iconCls="icon-edit" 
            singleSelect="true" rowNumbers="true" 
            pageSize="150" 
            fitColumns="true" remoteSort="false" 
            url="<?=base_url($menu_link.'/ajax')?>" 
            style="width:auto;height:560px" 
            data-options = "border:false,view:scrollview,autoRowheight:false"
        > 
            <thead>
                <tr>
                    <th width="150" align="left"   halign="center" field="CompanyName" sortable="true">Company</th>
                    <th width="120" align="left"   halign="center" field="TransNumber" sortable="true">Branch Code</th>
                    <th width="150" align="left"   halign="center" field="BranchName"  sortable="true">Name</th>
                    <th width="205" align="left"   halign="center" field="BranchAddress">Address</th>
                    <th width="100"  align="left"   halign="center" field="CityName" sortable="true">City</th>
                    <th width="110"  align="left"   halign="center" field="StateName">State</th>
                    <th width="80"  align="center" halign="center" field="TransStatus" sortable="true" hidden="true">Status</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

<script type="text/javascript">
    
    $(document).ready(function(){
        //========== list menu sisi kiri =====================================//        
    	var status_privelage_delete = '<?php echo $group_user->DeletePrivillage;?>';
    	var status_privelage_edit 	= '<?php echo $group_user->EditPrivillage;?>';
        var status_privelage_add    = '<?= $group_user->AddPrivillage;?>';

        list_master_datagrid('Branch','<?=$menu_link;?>','Branch Info',status_privelage_edit,status_privelage_delete,status_privelage_add);
        //========== end list menu sisi kiri =====================================//
    });
	
	/*
		jangan lupa ini ditaro dibawah di setaip list untuk search
		taro di luar documen ready jangan didalam doc ready
		jangan lupa hapus fungsi on key up di setiap find
		jangan lupa cek id gridnya
		created by : fachri 
	*/
	function searching_data(){
		if($('#cmb_branch').combobox('getValue') == ""){
			$.messager.alert('Info','Branch tidak boleh kosong, silahkan pilih');
		}
		else{
			var txt_Name 		= $('#txt_Name').val();
			var txt_Addres 		= $('#txt_Addres').val();
			
			var cmb_branch 		= $('#cmb_branch').combobox('getValue');
			var chk_status = new Array();
			$.each($('input[name="chk_TransStatus"]:checked'),function(){
				chk_status.push($(this).val());
			});
			
			$('#grid').datagrid('load',{
				TransNumber 	: cmb_branch,
				BranchName 	: txt_Name,
				TransStatus : chk_status,
				BranchAddress : txt_Addres
			});
		}
	}
	//------------------end--------------------------------------
	
    function update_status(){
	var BranchCode 	= $('#grid').datagrid('getSelected').TransNumber;
	var status 	= $('#grid').datagrid('getSelected').TransStatus;

	$.ajax({
            type        : "POST",
            url         : "branch_info/get_status_transaksi",
            data        : {'number':BranchCode},
            dataType    : "json",
		
            success     : function(msg){
                var status_numb = msg.trans_status;
                var balance1 = msg.balance;

                if(status_numb == 2 || status_numb == 4 || status_numb == 5 || status_numb == 6){
                    $.messager.alert('Info','Status "'+ status +'" tidak bisa disuspend');
                    return false;
                }
                else if(status_numb == 3){
                    $.messager.alert('Info','Status sudah "Suspend" / "Cancel"');
                    return false;
                }
                else if(balance1 != 0){
                    $.messager.alert('Info','Branch memiliki outstanding, tidak bisa disuspend');
                    return false;
                }
                else{
                    suspend_data('<?php echo $menu_link; ?>','#grid',BranchCode);
                }
            }
	});

	return false;
    }
	
	function delete_branch(){
		
		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 == 0) || (user_data == user_data_20000)){
			suspend_data_new('L', 1, '<?=$menu_link?>', $('#grid').datagrid('getSelected').BranchCode, '#grid');
		}
		else{
			$.messager.alert('Warning','Maaf hanya user tertentu yang bisa akses suspended branch, silahkan hubungi Department IT','warning',function(){						
					//location.reload();							
			});
		}
	}
</script>