<!---- 
Author 		 : Tagor
Created Date : 06/10/2014	
Revision 	 : 1) Hasan | 11/02/2015 | Design UI
-->

<?php
$disable_add	= '';
$disable_edit	= '';
$disable_delete	= '';
// -Later use
//if(strpos($available_action, 'A') === false)
//	$disable_add	= 'disabled';
//if(strpos($available_action, 'E') === false)
//	$disable_edit	= 'disabled';
//if(strpos($available_action, 'D') === false)
//	$disable_delete	= 'disabled';
?>

<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'north',border:false" style="padding:2px;">
        <a href="#" class="easyui-linkbutton" id="new-linkbutton" data-options="plain:true,iconCls:'icon-add'" onClick="parent.tab_new('New Payment','<?=$menu_link?>/add','icon-add')">New</a>	
        <a href="#" class="easyui-linkbutton" id="edit-linkbutton" data-options="plain:true,iconCls:'icon-edit'" onclick="parent.tab_edit('Edit Payment', '<?=$menu_link?>', 'icon-edit', 'edit', $('#grid').datagrid('getSelected').CPayNumber)">Edit</a>
        <!--<a href="#" class="easyui-linkbutton" id="suspend-linkbutton" data-options="plain:true,iconCls:'icon-remove'" onclick="suspend_data_new('L',1,'<?=$menu_link?>',$('#grid').datagrid('getSelected').CPayNumber,'#grid')">Suspend</a>-->
        <a href="#" class="easyui-linkbutton" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="refresh_datagrid('#grid')">Refresh</a>
        <a href="#" class="easyui-linkbutton" id="preview-linkbutton" data-options="plain:true,iconCls:'icon-print'" onClick="parent.tab_add('Print Payment', '<?=$menu_link?>', 'icon-print', 'to_preview')">Print Preview</a>
    </div>
    
    <div id="west-panel" data-options="region:'west',split:true,border:true" title="Filter" style="width:190px;background-color:#CCCCFF;padding:5px;">
        <table width="100%" cellpadding="0" cellspacing="0">
        <tr>
            <td style="padding-bottom:8px;"><b>Find</b></td>
        </tr>
        <tr>
            <td >
                <input id="txt_IDNumber" name="txt_IDNumber"  placeholder="< Payment No. >" style="margin:2px 0px 3px;width:100%;height:18px;border:1px solid #CCC;" onkeyup="search_data()">
            </td>
        </tr>
        <tr>
            <td >
                <input id="txt_Description"  name="txt_Description" placeholder="< Description >" style="margin:2px 0px 3px;width:100%;height:18px;border:1px solid #CCC;" onkeyup="search_data()">
            </td>
        </tr>
        <tr><td><div class="tr-divider"></div></td></tr>
        <tr>
            <td style="padding-bottom:8px;">
                <b>Date</b>
                <input type="checkbox" name="chk_ByDate" value="1" id="chk_ByDate" style="float:right;" />
            </td>
        </tr>
        <tr>
            <td>
                From
            	<span style="float:right">
                	<input name="txt_DateFrom" id="txt_DateFrom" type="text" class="easyui-datebox filter_date" style="width:100px;height:22px;" onSelect="search_data()" editable="false" />
            	</span>
            </td>
        </tr>
        <tr>
            <td>
                To
				<span style="float:right">
                	<input name="txt_DateTo" id="txt_DateTo" type="text" class="easyui-datebox filter_date" style="width:100px;height:22px;" onSelect="search_data()" editable="false" />
            	</span>
            </td>
        </tr>
        <tr><td><div class="tr-divider"></div></td></tr>
        <tr>
            <td style="padding-bottom:8px;"><b>by Status</b></td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="TransStatus[]" id="TransStatus" value="0" onclick="search_data()" style="margin-left:0px;" /> Waiting
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="TransStatus[]" id="TransStatus" value="1" onclick="search_data()" style="margin-left:0px;" /> On Progress
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="TransStatus[]" id="TransStatus" value="2" onclick="search_data()" style="margin-left:0px;" /> Finished
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="TransStatus[]" id="TransStatus" value="3" onclick="search_data()" style="margin-left:0px;" /> Cancel
            </td>
        </tr>
        </table>
    </div>
    
    <div data-options="region:'center',border:false,iconCls:'icon-ok'">
        <table id="tt" class="easyui-datagrid" 
            url="<?php echo site_url('list/payment_lebih/ajax'); ?>" 
            singleSelect="true" rowNumbers="true" 
            pagination="true" pageSize="20" 
            remoteSort="false" fit="true" 
        >
            <thead>
            <tr>
                <th field="CPayNumber" width="150" align="left" halign="center" sortable="true">Payment No.</th>
                <th field="CPayDate" width="80" align="center" halign="center" sortable="true" formatter="formatDate">Date</th>
                <th field="CPayTotalAmount" width="110" align="right" halign="center" sortable="true" formatter="formatRp">Amount</th>
                <th field="CPayDesc" width="470" align="left" halign="center" sortable="true">Description</th>
                <th field="TransStatus" width="120" align="center" halign="center" sortable="true">Status</th>
            </tr>
            </thead>
        </table>
    </div>
</div>

<script type="text/javascript">
$(document).ready(function(){
	$('.filter_date').datebox({
		onSelect: function(date){
			search_data();
		}
	});	
	
	$('#chk_ByDate').click(function(){
		if( $(this).is(':checked') ){
			$('#txt_DateFrom').datebox('enable', true);
			$('#txt_DateTo').datebox('enable', true);
			$('#txt_DateFrom').datebox('setValue', '<?=date('01-m-Y')?>');
			$('#txt_DateTo').datebox('setValue', 'today');
		}
		else{
			$('#txt_DateFrom').datebox('disable', true);
			$('#txt_DateTo').datebox('disable', true);
			$('#txt_DateFrom').datebox('setValue', '');
			$('#txt_DateTo').datebox('setValue', '');
		}
		search_data();
	});
	
	$('#grid').datagrid({
		onDblClickRow:function(){
			parent.tab_edit('Edit Payment', '<?=$menu_link?>', 'icon-edit', 'edit', $('#grid').datagrid('getSelected').CPayNumber);
		},
		onClickRow:function(index,value){
			if(value.Status=='Cancel'){
				$('#suspend-linkbutton').linkbutton('disable');
				$('#edit-linkbutton').linkbutton('disable');
			}else{
				$('#suspend-linkbutton').linkbutton('enable');
				$('#edit-linkbutton').linkbutton('enable');
			}
		}
	});
	
	$(function(){
		$('#grid').datagrid({loadFilter:pagerFilter}).datagrid('loadData');
	});
});

function update_status(){
	var trans_number = $('#tt').datagrid('getSelected').CPayNumber;
	var status = $('#tt').datagrid('getSelected').TransStatus;
	$.ajax({
		type : "POST",
		url : "payment/get_status_transaki",
		data : {'number':trans_number},
		dataType : "json",
		success : function(msg){
			var status_code = msg.number_cash;
			if(status_code == 2 || status_code == 4 || status_code == 5 || status_code == 6){
				$.messager.alert('Info','Status '+ status +' sudah tidak bisa disuspend');
				return false;
			}
			else if(status_code == 3){
				$.messager.alert('Info','Status sudah Suspend / Cancel');
				return false;
			}
			else{
				suspend_data('<?=$menu_link?>','#tt',trans_number);
			}
		}
	});
	return false;
}

function pagerFilter(data){
	if (typeof data.length == 'number' && typeof data.splice == 'function'){	// is array
		data = {
			total: data.length,
			rows: data
		}
	}
	var tt = $(this);
	var opts = tt.datagrid('options');
	var pager = tt.datagrid('getPager');
	pager.pagination({
		onSelectPage:function(pageNum, pageSize){
			opts.pageNumber = pageNum;
			opts.pageSize = pageSize;
			pager.pagination('refresh',{
				pageNumber:pageNum,
				pageSize:pageSize
			});
			tt.datagrid('loadData',data);
		}
	});
	if (!data.originalRows){
		data.originalRows = (data.rows);
	}
	var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
	var end = start + parseInt(opts.pageSize);
	data.rows = (data.originalRows.slice(start, end));
	return data;
}
</script>