<!--
Author 		  	: Fachri
Last update   	: 08/12/2014
Desc          	: view for export import transaction
Revision		: 1) Hasan | 03/02/2015 | Design UI
-->
<script type="text/javascript" src="<?=base_url()?>assets/plugins/jquery-easyui-1.3.6/plugins/datagrid-scrollview.js"></script>

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',border:false" style="height:30px">
        <div style="padding:2px">
        
           <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-journal" plain="true"  id="btn_journal" 
                onclick="to_journal();">Journal
            </a>						
            <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onClick="$('#tt').datagrid('reload')">Refresh</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">
                <tr>
                    <td width="190" align="left" style="padding-bottom:8px;">
                        <b>Find</b>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <input id="txt_IDNumber" name="txt_IDNumber" placeholder="< Source Number >" style="margin:2px 0px 3px;width:172px;height:22px;border:1px solid #CCC;">
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <input id="txt_Description" name="txt_Description" placeholder="< Desc >" style="margin:2px 0px 3px;width:172px;height:22px;border:1px solid #CCC;">
                    </td>
                </tr>
               
				
				<!--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'">
        
    <!--<p><b><?=base_url()?>file/import_transaction/detail/<?php echo $detail->ImportTransID;?>/<?php echo $detail->TransType;?></b></p>-->
        <table id="tt" class="easyui-datagrid" 
            url="<?=base_url()?>file/import_transaction/detail/<?php echo $detail->ImportTransID;?>/<?php echo $detail->TransType;?>" title="" 
            iconCls="icon-save" rowNumbers="true" 
            pageSize="50" 
            singleSelect="true" 
            style="width:auto;height:560%;" 
            data-options = "border:false,view:scrollview,autoRowheight:false"
        >
            <thead>
            <tr>
                <th width="95" halign="center" align="left" field="ImportTransID" hidden>Source Number</th>
				<?php
					if($detail->TransType == "Item"){
				?>
                	<th width="250" halign="center" align="left" field="SourceNumber">Item Code</th>
                	<th width="255" halign="center" align="left" field="ItemDesc">Item Desc</th>
                <?php
					}
					else if($detail->TransType == "Customer"){
				?>
                	<th width="170" halign="center" align="left" field="SourceNumber">Customer Code</th>
                	<th width="170" halign="center" align="left" field="CustomerName">Customer Name</th>
				<?php		
					}
					else if($detail->TransType == "Vendors"){
				?>
                	<th width="170" halign="center" align="left" field="SourceNumber">Vendor Code</th>
                	<th width="170" halign="center" align="left" field="VendorName">Vendor Name</th>
				<?php	
					}
					else if($detail->TransType == "Asset"){
				?>
                	<th width="170" halign="center" align="left" field="SourceNumber">Asset Code</th>
                	<th width="170" halign="center" align="left" field="ItemDesc">Asset Name</th>
                    <th width="170" halign="center" align="left" field="BranchCode">Branch Code</th>
				<?php
					}
					else if($detail->TransType == "Inventories"){
				?>
                	<th width="350" halign="center" align="left" field="SourceNumber">Item Code</th>
                	<th width="350" halign="center" align="left" field="ItemDesc">Item Name</th>
                    <th width="170" halign="center" align="left" field="BranchCode">Branch Code</th>
				<?php		
					}
					else if($detail->TransType == "PR"){
				?>
                	<th width="350" halign="center" align="left" field="SourceNumber">Source Number</th>
                    <th width="170" halign="center" align="left" field="BranchCode">Branch Code</th>
                <?php
					}
					if($detail->TransType == "Item_Expense"){
				?>
                	<th width="250" halign="center" align="left" field="SourceNumber">Item Desc</th>
                	<th width="255" halign="center" align="left" field="SvcDetailUnit">Item Unit</th>
                <?php
					}else if($detail->TransType == "Ar_Transaction"){
				?>
                	<th width="350" halign="center" align="left" field="SourceNumber">Source Number</th>
                    <th width="170" halign="center" align="left" field="BranchCode">Branch Code</th>
                <?php
					}else if($detail->TransType == "Ap_Transaction"){
				?>
                <th width="350" halign="center" align="left" field="SourceNumber">Source Number</th>
                <th width="170" halign="center" align="left" field="BranchCode">Branch Code</th>
                <?php
					}else if($detail->TransType == "RI"){
				?>   
                <th width="350" halign="center" align="left" field="SourceNumber">Source Number</th>
                <th width="170" halign="center" align="left" field="BranchCode">Branch Code</th> 
                <?php
					}
				?>
                <th width="150" halign="center" align="center" field="SourceDate" formatter="formatDate">Source Date</th>
                <th width="150" halign="center" align="center" field="TransType">Trans Type</th>
                <th width="150" halign="center" align="center" field="ImportNumber">Import Id</th>
                <th width="130" halign="center" align="center" field="LastUser">Last User</th>
                <th width="150" halign="center" align="center" field="ItemCategoryID" hidden='true'>Item Category ID</th>
            </tr>
            </thead>
        </table>
    </div>
</div>

<!-- Dialog Button -->
<div id="dialog-buttons-group" style="border:none;">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" id="ok_button" onclick="save_import();">Simpan</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" id="close_button" onClick="close_dialog();">Batal</a>
</div>

<script type="text/javascript">
$(document).ready(function(){
	$('#tt').datagrid({
        onDblClickRow:function(){	
		var selected = $('#tt').datagrid('getSelected');
			
			//parent.tab_edit('Edit Customer', 'file/edit_import/', 'icon-edit', 'edit', selected.ImportTransID);
			
			//if(selected.TransType == "Item"){
//				parent.tab_edit('Edit Item', 'list/items/', 'icon-edit', 'edit', selected.SourceNumber);
//			}
//			else if(selected.TransType == "Customer"){
//				parent.tab_edit('Edit Customer', 'list/customers/', 'icon-edit', 'edit', selected.SourceNumber);
//			}
//			else if(selected.TransType == "Vendors"){
//				parent.tab_edit('Edit Vendor', 'list/vendors/', 'icon-edit', 'edit', selected.SourceNumber);
//			}
		
		}
    });
});

function to_journal(){
    //var qtyRow = qtyRowDatagrid("tt");
    $("#tt").datagrid('selectRow', 0);
    
	trans_type = '<?php echo $detail->TransType;?>';
	var selected = $('#tt').datagrid('getSelected');
	if(selected.TransType == 'Inventories'){
		parent.tab_add('Preview Journal <?=$menu_label?>', '<?php echo $menu_link; ?>', 'icon-print', 'to_print_journal_inventori/'+selected.BranchCode+'/'+selected.ImportTransID+'/'+selected.ItemCategoryID);
	}
	else if(selected.TransType == 'Asset'){
		parent.tab_add('Preview Journal <?=$menu_label?>', '<?php echo $menu_link; ?>', 'icon-print', 'to_print_journal/'+selected.BranchCode+'/'+selected.ImportTransID+'/'+selected.ItemCategoryID);
	}
	else{
		$('#btn_journal').linkbutton('disable');
	}
	
}

function save_import() {
	var type_transaction = $('#rdo_transaction_type:checked').val();
	$('#transaction_type').val(type_transaction); 
	$('#loading_img').show();
	$('#id_span').show();
	//$('#close_button').linkbutton('disable', true);
	$('#ok_button').linkbutton('disable', true);
	import_data('<?php echo $menu_link ?>/insert','#form_import_transaction','dialog-import');
} 

function close_dialog(){
	location.reload();
	modal_close('dialog-import');
}

function modal_open_imp(title, divid){
	 $('#'+divid).dialog('open').dialog('setTitle',title);
}


</script>