<!-- EasyUI CSS -->
<link href="<?php echo base_url() . "assets/" ?>easyui/themes/bootstrap/easyui.css" rel="stylesheet">
<link href="<?php echo base_url() . "assets/" ?>easyui/themes/icon.css" rel="stylesheet">

	<div class="row">
		<div id="table-content" class="col-lg-12">
			<table id="tbl">
				<table id="tbl">
				<div id="tb" style="padding:3px;height:auto;">
					<div style="margin-bottom:0px; max-width:100px;">												
						<?php echo @$create; ?>
					</div>
				</div>
			</table>
			</table>
		</div>
	</div>

	<div class="row">
		<div class="extra-footer col-lg-12" style="height:25px;"></div>
		<div class="col-lg-12 page-footer-table"></div>
		<!-- only space 
		-->
	</div>

<script>

	var tbl, setup; // setup is flag
    $(document).ready(function () {
		setup = 0;
		tbl = $('#tbl').datagrid({width: '100%'});
        // toolbar action
		var toolbarCostum = $('#tb');	
		// handle when direct update or create
		tbl.datagrid(gridConfigGeneralNoRowNumFixHeight);
		tbl.datagrid({
			pageNumber: '<?php echo $pnumber?>',
			pageSize: '<?php echo $psize?>',
		});
        tbl.datagrid({
            url: '<?php echo site_url('/') . $controller . '/load_data'; ?>',
            title: "List Uang Masuk",
            toolbar: toolbarCostum,
            onLoadSuccess: loadAction, 
			frozenColumns:[[
				{field: 'options', title: 'ACTION', width: 100, halign: 'center', align: 'center', formatter: formatButton},
				{field: 'no', title: 'No Transaksi', width: 200, sortable: 'true', halign: 'center', align: 'center'},				
			]],	
            columns: [[ 
					{field: 'tanggaltransaksi', title: 'Tanggal Transaksi', width: 130, sortable: 'true', halign: 'center', align: 'center'},
					{field: 'diserahkan', title: 'Diserahkan Oleh', width: 130, sortable: 'true', halign: 'center', align: 'center'},
					{field: 'diterima', title: 'Diterima Oleh', width: 130, sortable: 'true', halign: 'center', align: 'center'},
					{field: 'besarnya', title: 'Total Transaksi', width: 130, sortable: 'true', halign: 'center', align: 'center'},
					{field: 'Keterangan', title: 'Keterangan', width: 130, sortable: 'true', halign: 'center', align: 'center'},
					{field: 'tanggalinput', title: 'Tanggal Input', width: 130, sortable: 'true', halign: 'center', align: 'center'},
					{field: 'status', title: 'Cetak Status', width: 130, sortable: 'true', halign: 'center', align: 'center'},
                    {field: 'created_by', title: 'Created By', width: 100, sortable: 'true', halign: 'center', align: 'center'},
                    {field: 'created_date', title: 'Created Date', width: 150, sortable: 'true', halign: 'center', align: 'center'},                    
                ]]
        });
    });
	
	function loadAction() {
		
		// fix asyn setup and multiple setup
		if (setup == 0){
			tbl.datagrid('enableFilter',
				 [ {
					field: 'created_date',
					type: 'datebox',
					options: {formatter: myFormatter, parser: myParser},
					op: ['equal', 'less', 'greater']
				},{
					field: 'tanggaltransaksi',
					type: 'datebox',
					options: {formatter: myFormatter, parser: myParser},
					op: ['equal', 'less', 'greater']
				},{
					field: 'tanggalinput',
					type: 'datebox',
					options: {formatter: myFormatter, parser: myParser},
					op: ['equal', 'less', 'greater']
				}] 
			);  
			// remove filter option
			$("input[name='options']").remove();
			setup = 1;
		}
		// fix
		//resizeContentDOMFit();
		// filter
		tbl.datagrid('resize', 'fixRowHeight');
	}
	
	 // format date
    function myFormatter(date) {
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
    }

    // required
    function myParser(s) {
        if (!s)
            return new Date();
        var ss = (s.split('-'));
        var y = parseInt(ss[0], 10);
        var m = parseInt(ss[1], 10);
        var d = parseInt(ss[2], 10);
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
            return new Date(y, m - 1, d);
        } else {
            return new Date();
        }
    }

	
	 // inline editor on row
    //load edit view	
	function edit_view(no_trans) {
		//alert(no_trans); die();
		window.location.href = "<?php echo '#'.$controller.'/form/'; ?>"+no_trans;
	}
	
	function create_view() {
		//alert(no_trans); die();
		window.location.href = "<?php echo '#'.$controller.'/form/'; ?>";
	}
	
	function delete_data(id) {
		
		var alertmsg = 'Delete Data Ini ?';
		if (confirm(alertmsg)) {
			
			
			/* $.post("adm_tahun_ajaran/change_tahun_ajaran", {row_id: row_id}, function () {
                  //window.location.href = '#adm_tahun_ajaran/';
                    //window.location.reload();
                }, 'json'); */
				
			$.ajax({
			url:"<?php echo site_url('/').$controller; ?>/delete",
			type: "POST",
			dataType:"json",
			data:"id_daftar="+id_daftar,
			success : function(msg){			
				container = $('#content');
				var url = location.hash.replace(/^#/, '');
				loadURL(url + location.search, container);
			},
			error :function(msg){
				$("#content").html("<span class='label label-important'> Error </span>");			
				$("#loading_anim").hide();
			}
			}); 
			
		}
	}	
	
	
	
	// inline editor on row
    function formatButton(val, row, index) {
      
		
		var status = row.status;
		var id = row.Id;
		
				
		if (status == 'CETAK') {
			//var cetakFaktur = '';
			var cetakFaktur = '<?php echo @$cetakFaktur; ?>';
		} else {
			var cetakFaktur = '<?php echo @$cetakFaktur; ?>';
		}
		return cetakFaktur;
		
    }

	function cetakFaktur(noFaktur) {
		var urlFaktur = '<?php echo base_url(); ?>index.php/trans_uang_masuk/printFaktur?faktur='+noFaktur;
		// redirect
		console.log(urlFaktur);
		//window.location = urlExport;
		window.open(urlFaktur,'_blank');
	}	
	
	
</script>