<!--
Author 		  : Tagor
Last update   : 07/08/2014
Revisi        : Fachri
-->

	
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'north',border:false" style="height:30px">
        <div style="padding:2px">
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add_row_pop_up();">New</a>
            <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onClick="$('#grid').datagrid('reload')">Refresh</a>
        </div>
    </div>
	
	 <div 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 style="padding-bottom:8px;">
                    <b>Find</b>
                </td>
            </tr>
            <tr>
                <td>
                    <input id="txt_IDNumber" name="txt_IDNumber"  placeholder="< Tranasction. No. >" style="margin:2px 0px 3px;width:172px;height:22px;border:1px solid #CCC">
                </td>
            </tr>
            <tr>
                <td>
                    <input id="txt_Description" name="txt_Description"  placeholder="< Item Description >" style="margin:2px 0px 3px;width:172px;height:22px;border:1px solid #CCC">
                </td>
            </tr>
            <tr><td><div class="tr-divider"></div></td></tr>
            
            <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>
            
            </table>
            </form>
        </div>
    </div>
	
	<div data-options="region:'center',border:false,iconCls:'icon-ok'">
		<!-- gaya table baru di grid -->
        
		<form id="fm_recur" name="fm_recur" method="post">
		<table id="grid" class="easyui-datagrid"
        	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" 
            toolbar="#tb_dg_recur" 
            data-options = "border:false,view:scrollview,autoRowheight:false"
        > 
            <thead>
            <tr>
                <!--<th width="170" halign="center" align="left" field="SourceNumber">Source No</th>-->
                <th width="190"  halign='center' field="NoTransaction" 		data-options="align:'center'" >No Transaction</th>
                <th width="110"  halign='center' field="DateTransaction" 	data-options="align:'center'"  formatter="formatDate">Transaction Date</th>
                <th width="250"  halign='center' field="ItemName" 			data-options="align:'center'" >Item Name</th>
                <th width="150"  halign='center' field="TotalInvoice" 		data-options="align:'center'" formatter="formatRp">Total Invoice</th>
                <th width="150"  halign='center' field="CurrencyRate" 		data-options="align:'center'" formatter="formatRp">Currency Rate</th>
                <th width="100"  halign='center' field="PeriodUsed" 		data-options="align:'center'" >Period Used</th>
                <th width="150"  halign='center' field="TotalOwing" 		data-options="align:'center'" formatter="formatRp">Amount Reccur</th>
                <th width="100"  halign='center' field="Length" 			data-options="align:'center'" hidden>Length</th>
            </tr>
            </thead>
        </table>
        </form>
	</div>
</div>
<div id="dialog-item" class="easyui-dialog" closed="true" data-options="modal:true, iconCls:'icon-save'" buttons="#dialog-buttons" style="width:860px;height:485px;top:27px;background-color:#F8F8F8;padding:5px;">


    <form id="form_import_recur" name="form_import_recur" method="post" novalidate>
        <input type="hidden" id="txt_category" name="txt_category" />
		<input type="hidden" id="txt_net_due" name="txt_net_due" />
        <input type="hidden" id="txt_vendro_addres" name="txt_vendro_addres" />
        <input type="hidden" id="txt_terms" name="txt_terms" />
        
        
        <div id="tab_purchase_req" class="easyui-tabs" style="width:835px;height:435px; background-color:#F8F8F8;" data-options="fit:true,plain:true">
            <div title="Form Input Adv" style="padding:10px">
                <table width="100%" height="343">
                    <tr>
                    	<td width="115" height="76"><b>No Transaction</b></td>
                    	<td width="9"><b>:</b></td>
    
                    	<td width="268">
                       		<input type="text" style="width:250px;height:20px" name="txt_transaction_no" id="txt_transaction_no" class="easyui-validatebox" required/>
                    	</td>
                        <td width="140">
                       		<b>Transaction Date</b>
                    	</td>
                        <td width="5"><b>:</b></td>
                        <td width="250">
                       		<input name="txt_date" id="txt_date" type="text" value="<?php echo $date_now;?>" class="easyui-datebox validBackward" style="width:250px;height:20px"" required editable="false" />
                            
                    	</td>
                	</tr>
                    <tr>
                    	<td width="115" height="51" valign="top"><b>Item Name</b></td>
                    	<td valign="top"><b>:</b></td>
    
                    	<td valign="top">
                       		<select name="cmb_ItemCode" id="cmb_ItemCode" class="easyui-combobox" style="width:250px;" editable="true" required
                                    data-options="
                                    valueField:'AdvDetailName',
                                    textField:'AdvDetailDesc',
                                    url:'<?php echo base_url(); ?>file/import_recur/get_data_adv',
                                   	onSelect: function(rec){
                                        $('#txt_category').val(rec.AdvCategoryID);
                                        $('#txt_net_due').val(rec.AdvNetDueIn);
                                    }
                                    ">
                            </select>
                    	</td>
                        <td width="140" valign="top">
                       		<b>Vendor</b>
                    	</td>
                        <td width="5"  valign="top"><b>:</b></td>
                        <td width="250"  valign="top">
                            <select class="easyui-combogrid" name="cbg_vendor" id="cbg_vendor" style="width:252px;height:22px;" required 
                                data-options="
                                    panelWidth:400,
                                    idField: 'VendorCode',
                                    textField: 'VendorName',
                                    url: '<?=base_url()?>custom/get_data/vendor_new_by_branch',
                                    method: 'get',
                                    columns: [[
                                        {field:'VendorCode',title:'Vendor No',width:100,halign:'center'},
                                        {field:'VendorName',title:'Vendor Name',width:161}
                                    ]],
                                    fitColumns: true
                                ">
                            </select>
                    	</td>
                	</tr>
                    <tr>
                    	<td width="115" valign="top"><b>Total Invoice</b></td>
                    	<td valign="top"><b>:</b></td>
    
                    	<td colspan="6" valign="top">
                       		 <input type="text" style="width:250px;height:20px" name="txt_total_invoice" id="txt_total_invoice" class="easyui-numberbox" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" value="0" required/>
                    	</td>
                	</tr>
                    <tr>
                    	<td width="140" valign="top">
                       		<b>Currency Code</b>
                    	</td>
                        <td width="5" valign="top"><b>:</b></td>
                        <td width="250" valign="top">
                       		<input type="text" style="width:250px;height:20px" name="cmb_currency" id="cmb_currency" required readonly="readonly"/>
                    	</td>
                        <td width="115" valign="top"><b>Currency Rate</b></td>
                    	<td valign="top"><b>:</b></td>
    
                    	<td valign="top">
                       		<input type="text" style="width:250px;height:20px" name="txt_currencyrate" id="txt_currencyrate" class="easyui-numberbox" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" value="1" readonly required/>
                    	</td>
                        
                	</tr>
                    
                   
                    <tr>
                    	<td width="115" valign="top"><b>Period Used</b></td>
                    	<td valign="top"><b>:</b></td>
    
                    	<td colspan="6" valign="top">
                       		<input type="text" style="width:250px;height:20px" name="txt_periodeuse" id="txt_periodeuse" class="easyui-numberbox" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" value="0" required/>
                    	</td>
                	</tr>
            	</table>
                <div style="border:none; margin-top:10px; float:right;">
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_recur();">&nbsp; Save &nbsp; &nbsp;</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-item');">Cancel</a>
                </div>
          </div>
        </div>

    </form>
</div>


<script type="text/javascript">
var LoopIndexGrid   = 0;

$(document).ready(function(){
	$('#grid').datagrid({
            onDblClickRow:function(rowIndex, rowData){
				parent.tab_edit('Edit Purchase Invoice', 'list/purchases_invoice', 'icon-edit', 'edit', rowData.NoTransaction);
			}
	});
	
	$('#cbg_vendor').combogrid({
		onSelect:function(rowIndex, rowData){
			$('#txt_currencyrate').numberbox('setValue', rowData.CurrencyRate);
			$('#cmb_currency').val(rowData.CurrencyCode);
			$('#txt_vendro_addres').val(rowData.VendorAddress);
			$('#txt_terms').val(rowData.TermsPaymentID);
			
			
			if(rowData.CurrencyCode == 'IDR' ){
				$('#txt_currencyrate').prop('readonly', true);
			}
			else{
				$('#txt_currencyrate').prop('readonly', false);
			}
		}
	});	
	grid_navigation('Import_Recur','<?php echo $menu_link; ?>'); 
});

function add_row_pop_up(){
	modal_open('Adv Payment','dialog-item');
}

function choose_recur(){
	$.messager.confirm('Confirm', 'Pastikan semua data sudah benar, jika sudah di import, transaksi tidak bisa dirubah kembali',
        function (r) {
            if (r) {
				if($('#txt_total_invoice').numberbox('getValue') == 0){
					$.messager.alert('Info','Transaksi gagal di import Total Invoice tidak boleh kosong','info',function(){					
						//location.reload();							
					});
				}
				else if($('#txt_currencyrate').numberbox('getValue') == 0){
					$.messager.alert('Info','Transaksi gagal di import Currency Rate tidak boleh kosong(0) silahkan isi dengan angka 1','info',function(){					
						//location.reload();							
					});
				}
				else{
					save_transaction('<?php echo $menu_link?>','#form_import_recur');
				}   
        }
    });
}

function searching_data(){
		var txt_no 		= $('#txt_IDNumber').val();
		var txt_desc 	= $('#txt_Description').val();
		
		
		
		$('#grid').datagrid('load',{
			NoTransaction 	: txt_no,
			ItemName 	: txt_desc
		});	
}
</script>