<!---- 
    Author 	: Herpan
    Tanggal : 12-08-2014	
    Revisi 	:
-->
<?php
//---------Untuk privellege jika dia ada tombol save----------
	if($group_user->SavePrivillage == 1){
		$cek_autority_save  = "";
	}
	else{
		$cek_autority_save 	= "disabled";
	}
//-------------end----------------------------
?>
<div class="easyui-layout" data-options="fit:true,border:false">
	<!-- top view-->
	<div id="form-header" data-options="region:'north',border:false" >
		 <div id="form-header-wrapper">
				<table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
					<tr>
						<td align="left" valign="middle">
							<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="location.reload()">Refresh</a>
							<a href="#" class="easyui-linkbutton" iconCls="icon-document" plain="true" onclick="parent.tab_add('New Payment Afiliasi','<?=$menu_link?>','icon-add','add')">New</a>
						</td>							
						<td height="25" align="right" valign="middle">								
							<span class="form-title"><?=$menu_label?></span>
						</td>
					</tr>
				</table>		     	
		 </div>			
	</div>
	<!-- end top view -->	
	<!-- center view -->
	<div id="form-body" data-options="region:'center',border:false">
		<div id="form-wrapper" class="easyui-panel"  style="width:1180px;height:526px;padding:5px;" fit='true'>
			<form id="fm_payment_afiliasi" name="fm_payment_afiliasi" method="post">
            <input type="hidden" name="txt_status_new" id="txt_status_new" />
                <table cellpadding="0" cellspacing="3" width="100%" height="100%" border="0">
					<tr>
						<td valign="middle" height="22" width="120" align="left"><b>Payment for</b></td>
                        <td><b>:</b></td>
						<td valign="top" align="left" width="800">
							<input name="txt_payment_for" id="txt_payment_for" type="text" style="width:246px;background-color:#E3E2E2;" readonly />
							<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-sales" onClick="modal_open('List Piutang','dialog_piutang_list')" style="width:110px;" plain="true">List Piutang</a>
						</td>
						
						<td align="left" valign="middle">&nbsp;</td>
						<td rowspan="6" align="left" valign="top">
							<table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
								<tr>
									<td align="right" valign="top">
										<table cellpadding="0" cellspacing="1" width="100%" border="0">
											<tr>
												<td height="20">&nbsp;</td>
												<!-- <td width="190" align="center" valign="middle" bgcolor="#333399"><span style="color: #fff">Payment Afiliasi No.</span></td> -->
												<td width="122" align="center" valign="middle" bgcolor="#333399"><span style="color:#fff;">Payment Afiliasi Date</span></td>
											</tr>
											<tr>
												<td>&nbsp;</td>
												<!-- <td height="20" align="left" valign="top"> -->
													<input type="hidden" name="payment_afiliasi_no" id="payment_afiliasi_no" class="easyui-validatebox" style="width:190px;background-color:#E3E2E2;text-align:center;" required readonly />
												<!-- </td> -->
												<td align="right" valign="top"><input name="txt_payment_afiliasi_date" id="txt_payment_afiliasi_date" type="text" class="easyui-datebox validBackward" style="width:122px;height:20px" required editable="false" value='<?= $date_now;?>'/></td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td valign="top" height="22" width="70" align="left"><b>Transfer From</b></td>
                        <td><b>:</b></td>
						<td valign="top" align="left"  width="800">
							<select name="cmb_fromcompany" id="cmb_fromcompany" class="easyui-combobox" editable="false" style="width:180px;" required="true" 
									data-options="
										valueField:'CompanyCode',
										textField:'CompanyName'
									">
							</select>
							<select name="cmb_bankfrom" id="cmb_bankfrom" editable='true' class="combo-grid"  
									 style="width:180px;" required="true" 
									data-options="
										panelWidth:199,
                                        idField: 'AccountNumber',
                                        textField: 'AccountName',
                                        method : 'get',
                                        url:'',
                                        columns: [[
                                            {field:'AccountNumber',title:'Account Number',width:110,halign:'center',hidden:true}, 
                                            {field:'AccountName',title:'Bank Name',width:190,halign:'center'}, 
                                            {field:'CurrencyCode',title:'Bank Currency',width:80,halign:'center',align:'center'}
                                        ]],
                                        fitColumns: true,
                                        onLoadSuccess:function(data){
                                        	var total_data = data.rows.length;
                                        	if(total_data > 0){
                                        		$('#cmb_bankfrom').combogrid('setValue',data.rows[0]['AccountNumber']);
                                        	}
                                        }
										
									">
							</select>
						</td>
					</tr>
					<tr>
						<td valign="top" height="22" align="left"><b>Transfer To</b></td>
                        <td><b>:</b></td>
						<td valign="top" align="left">
							<select name="cmb_tocompany" id="cmb_tocompany" class="easyui-combobox" editable="false" style="width:180px;" required="true"
								data-options="
									valueField:'CompanyCode',
									textField:'CompanyName'
								">
							</select>
							<select name="cmb_bankto" id="cmb_bankto" editable='true' class="combo-grid"  
									 style="width:180px;" required="true" 
									data-options="
										panelWidth:199,
                                        idField: 'AccountNumber',
                                        textField: 'AccountName',
                                        method : 'get',
                                        url:'',
                                        columns: [[
                                            {field:'AccountNumber',title:'Account Number',width:110,halign:'center',hidden:true}, 
                                            {field:'AccountName',title:'Bank Name',width:190,halign:'center'}, 
                                            {field:'CurrencyCode',title:'Bank Currency',width:80,halign:'center',align:'center'}
                                        ]],
                                        fitColumns: true,
                                        onLoadSuccess:function(data){
                                        	var total_data = data.rows.length;
                                        	if(total_data > 0){
                                        		$('#cmb_bankto').combogrid('setValue',data.rows[0]['AccountNumber']);
                                        	}
                                        },
										onSelect:function(rowIndex,rowData){
                                        	
                                            get_bank_balance(rowData.AccountNumber,rowData.CurrencyCode);
										}
									">
							</select>
						</td>
					</tr>
					<tr>
						<td valign="middle" height="22" align="left"><b><?php echo label_grid('check_no');?></b></td>
                        <td><b>:</b></td>
						<td valign="top" align="left">
							<input name="txt_cheque_no" id="txt_cheque_no" type="text" style="width:362px" />
						</td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>
					<!--<tr>
						<td valign="middle" height="22" align="left"><b>Date</b></td>
                        <td><b>:</b></td>
						<td valign="top" align="left">
							<input name="txt_cheque_date" id="txt_cheque_date" type="text" value="<?= $date_now;?>" class="easyui-datebox" style="width:180px;height:20px;" editable="false"/>
						</td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>-->
					<tr>
						<td valign="top" height="51" align="left" style="padding-top:4px;"><b>Memo</b></td>
                        <td valign="top" style="padding-top:4px;"><b>:</b></td>
						<td valign="top" align="left">
							<textarea class="textbox" name="txa_memo" id="txa_memo" rows="4" style="width:362px;resize:none;white-space:normal;"></textarea>
						</td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>
					<tr>
						<td height="22" valign="top" align="left"><b>Amount</b></td>
                        <td width="10"><b>:</b></td>
						<td valign="top" height="22" align="left">
							<input name="txt_amount" id="txt_amount" type="text" class="easyui-numberbox" data-options="precision:2,decimalSeparator:',',groupSeparator:'.',disabled:true" autoComplete="off" style="width:362px;" required="required" />
							<!-- <input type="hidden" id="txt_amount_hidden" name="txt_amount_hidden" /> -->
							<input type="hidden" id="detail" name="detail" />
							<input type="hidden" id="loan_payment" name="loan_payment" />
							<input type="hidden" id="payment_balance" name="payment_balance" />
                            <input type="hidden" id="payment_period" name="payment_period"/>
							<input type="hidden" id="payment_perperiod" name="payment_perperiod" />
							<input type="hidden" id="new_row" name="new_row" />
							<!-- <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-calculator',size:'small'" id="calc_validate" onClick="get_amount_from_grid()"></a> -->
						</td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>
					<tr height="20" style="display:none">
                        <td width="150" align="left"><b>Bank Balance (<span class='bank_balance_currency'></span>)</b></td>
                        <td width="10"><b>:</b></td>
                        <td >
                            <input name="txt_bank_balance" id="txt_bank_balance" type="text" class="easyui-numberbox" data-options="precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" style="text-align:right;width:362px" readonly />
                        </td>
                    </tr>					
				</table>
                
                <!-- Item Grid -->
                <div class="easyui-tabs" data-options="tabHeight:18" style="margin:5px 0px;">
                    <div title="Item">
                        <table toolbar="#tb_dtg_payment_afiliasi" id="dtg_payment_history" 
                        class="easyui-edatagrid" title="Payment History" idField="id" rownumbers="true" fitColumns="true" singleSelect="true" style="height:250px;"
                        data-options = "
                        	onBeginEdit:function(rowIndex){
								save_button_begendedit('<?=$group_user->SavePrivillage;?>');

								editors = $('#dtg_payment_history').datagrid('getEditors',rowIndex);
								var e1	= $(editors[0].target);
					           
								e1.numberbox({
									onChange:function(){
										value1 = 0;
										value2 = e1.numberbox('getValue');
					                    
										dg_item = $('#dtg_payment_history').datagrid('getRows');

										var new_index = dg_item.length;

										$.each(dg_item,function(index,value){
											if(rowIndex == 0){
												value1 = value.LoanPayment;
												
											}
											else if(index==(rowIndex-1)){
												value1 = value.PaymentBalance;
											}
											
											if(index==rowIndex){
												value3 = value1-value2;
												value.PaymentBalance = value3;
											}
										});
									}
								});
							},
							onEndEdit:function(){
								save_button_endedit('<?=$group_user->SavePrivillage;?>');
							},
							onClickRow:function(){
								 var selected_data=$('#dtg_payment_history').datagrid('getSelected');
								 var no_paymen = $('#payment_afiliasi_no').val();
								 if(selected_data.AInsNumber != no_paymen){
									 $.messager.alert('Unseccessfull','Data tidak sama dengan Nomor payment afiliasi','error',function(){	
									 	$('#txt_amount').numberbox('setValue',0);
										$('#payment_period').val(0);
										$('#payment_balance').val(0);
										$('#payment_perperiod').val(0);
										$('#new_row').val(0);
										$('#dtg_payment_history').datagrid('reload'); 
									});
								 }
							}
                        "
                        >
                            <thead>
                                <tr>
                                    <th data-options="field:'LoanPayment',width:100,halign:'center',align:'right',required:true" formatter="formatRp" >Loan Payment</th>
                                    <th data-options="field:'PaymentPeriod',halign:'center',align:'right',required:true" hidden="true">Payment Period</th>
                                    <th data-options="field:'PaymentPerPeriod',width:0,halign:'center',align:'right',editor:{type:'numberbox',options:{precision:2,decimalSeparator:',',required:true,min:0}}" formatter="formatRp">Payment Per Period</th>
                                    <th data-options="field:'PaymentBalance',width:100,halign:'center',align:'right',required:true" formatter="formatRp" >Payment Balance</th>
                                    <th data-options="field:'AInsNumber',halign:'center',align:'right',editor:{type:'text',options:{disabled:true}}" hidden="true">Payment No</th>
                                </tr>
                            </thead>
                        </table>
                        
                        <div id="tb_dtg_payment_afiliasi">
                            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addNewRow()">New</a>								
                        </div>
                    </div>
                </div>
                <!-- End of item grid -->
            </form>
		</div>
	</div>
    <div id="form-footer" data-options="region:'south',border:false">
        <table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
             <tr>
               <td align="left">
               </td>
                <td align="right">                              
                      <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-help" onclick="" plain="true">Help</a>
                     <a href="javascript:void(0)" class="easyui-linkbutton form-button save-button" iconCls="icon-save" onclick="save_me()" <?= $cek_autority_save;?>>Save</a>
                     <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="parent.tab_close('tt')">Cancel</a>
                </td>
             </tr>
        </table>				
    </div>	
</div>
<!-- Dialog piutang List -->
<div id="dialog_piutang_list" class="easyui-dialog" style="width:900px;background-color:#F8F8F8;height:550px;padding: 0 0px 0 0px" closed="true" 
	data-options="modal:true,fitColumns:true" buttons="#dialog-buttons">
	<table id="tb_piutang_list"  
        url="<?= base_url().$menu_link;?>/list_piutangafiliasi"
        idField="ADebtNumber" singleSelect="true"
        fitColumns="true" fit="true"
    >
		<thead>
			<tr>
				<th colspan="2"><b>Dari</b></th>
				<th colspan="2"><b>Ke</b></th>
				<th rowspan="2" field="BalanceAmount" width="135" align="center" formatter="formatRp"><b>OutStanding</b></th>				
				<th rowspan="2" field="ADebtAmount" width="135" align="center" formatter="formatRp"><b>Amount</b></th>
                <th rowspan="2" field="IsLock" width="50" align="center"><b>Status</b></th>
			</tr>
			<tr>
				<th field="CompFrom" width="120" align="center"><b>Perusahaan</b></th>
				<th field="BankFrom" width="120" align="center"><b>Bank</b></th>
				<th field="CompTo" width="120"  align="center"><b>Perusahaan</b></th>
				<th field="BankTo" width="120"  align="center"><b>Bank</b></th>
			</tr>
		</thead>
	</table>
	<div id="dialog-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="get_piutang(false)">OK</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog_piutang_list')">Cancel</a>
	</div>
</div>


<script type="text/javascript">

var SavePrivillage  = '<?=$group_user->SavePrivillage;?>';

$(document).ready(function(){
	
	$('#payment_afiliasi_no').val('<?= $payment_afiliasi_number; ?>');
	
	$('#txt_payment_afiliasi_date').datebox({
		onChange:function(){
			url             = base_url + '<?php $menu_link; ?>/get_payment_afiliasi_number';                
			var Payment_af_date   = $('#txt_payment_afiliasi_date').datebox('getValue');
			
			$.post(url, {Payment_af_date:Payment_af_date}, function(result){
				if (result.status === true){
					$('#payment_afiliasi_no').val(result.number);
				} 
			},'json');
		}
	});

	$('#fm_payment_afiliasi').click(function(){
		var new_row = $('#new_row').val();

		if(new_row == 1){
			get_amount_from_grid();
			var rownumbers = $('.datagrid-cell-rownumber').length;
			for(var x = 0; x < rownumbers; x++){
				$('.datagrid-cell-rownumber').eq(x).html(x+1);
				
			}
		}
    });

    var no_piutang = '<?= $no_piutang;?>';

    $('#tb_piutang_list').datagrid({
    	rowStyler: function(index,row){
				if (row.IsLock=='Locked'){					
					return 'background-color:#FF6666;color:#fff;';
				}					
			},
			onLoadSuccess:function(data){
				if(no_piutang !=''){
				    var ind_piutang = findWithAttr(data.rows,'ADebtNumber',no_piutang);
				    $('#tb_piutang_list').datagrid('selectRow',ind_piutang);
				    if(data.rows[ind_piutang]['IsLock']!='Locked'){
				    	get_piutang(true);
				    }
				}
			}
    });

    $('#txt_payment_for').on('mouseover',function(){
    	$(this).css({'color':'blue','font-weight':'bold','cursor':'pointer'});
    }).on('mouseout',function(){
    	$(this).css({'color':'#545454','font-weight':'normal'});
    }).on('click',function(){
    	var TransNumber = $(this).val();
    	parent.tab_edit('Edit Piutang Afiliasi','list/piutang_afiliasi', 'icon-edit', 'edit',TransNumber);
    });

});
	
function get_piutang(val){

	var rows = $('#tb_piutang_list').datagrid('getSelected');
	if(rows.IsLock=='Locked'){
		$.messager.alert('Info','Tidak bisa memilih Transaksi yang di-Lock');
	}
	else{

		var piutang_no 	= rows.ADebtNumber;
		var comp_from	= rows.CompFromCode;
		var comp_to		= rows.CompToCode;	
		var bank_from	= rows.BankFromCode;
		var bank_to		= rows.BankToCode;
		var cheque_no	= rows.ChequeNumber;
		var cheque_stat	= rows.CqTermStatus;
		var cheque_date	= rows.ChequeDate;
		var description	= rows.ADebtDesc;
		var amount		= rows.ADebtAmount;
		var OutStanding = rows.BalanceAmount;
		
		var no_trans 	= piutang_no.replace(/\//g,".");
		
		var url_comp_from 	= '<?= base_url().$menu_link; ?>/get_company/'+comp_to;
		$('#cmb_fromcompany').combobox('reload', url_comp_from);
		$('#cmb_fromcompany').combobox('setValue', comp_to);
		var url_bank_from 	= '<?= base_url().$menu_link; ?>/get_bank/'+comp_to;
		$('#cmb_bankfrom').combogrid('grid').datagrid('loadData', {'total':0,'rows':[]});
		$('#cmb_bankfrom').combogrid('grid').datagrid({
			url:url_bank_from,
		});
		
		var url_comp_to 	= '<?= base_url().$menu_link; ?>/get_company/'+comp_from;
		$('#cmb_tocompany').combobox('reload', url_comp_to);
		$('#cmb_tocompany').combobox('setValue', comp_from);
		var url_bank_to 	= '<?= base_url().$menu_link; ?>/get_bank/'+comp_from;
		$('#cmb_bankto').combogrid('grid').datagrid('loadData', {'total':0,'rows':[]});
		$('#cmb_bankto').combogrid('grid').datagrid({
			url:url_bank_to,
		});
		
		$('#dtg_payment_history').datagrid({
			url:'<?= base_url().$menu_link; ?>/grid_bypiutang_no/' + no_trans,
			onLoadSuccess:function(data){
				var period 			= parseInt(data.rows.length) + 1;
				var no_paymen 		= $('#payment_afiliasi_no').val();
				if(val==true){
					$('#dtg_payment_history').datagrid('appendRow',{
						LoanPayment 		: amount,
						PaymentPeriod 		: period,
						PaymentPerPeriod 	: OutStanding,
						PaymentBalance 		: 0,
						AInsNumber			: no_paymen
					});

					$('#new_row').val(1);
					$('#loan_payment').val(amount);
		
					$('#txt_payment_for').val(piutang_no);
				   	$('#txa_memo').html(description);

				   	$('#txt_amount').numberbox('setValue',OutStanding);
					$('#payment_period').val(period);
					$('#payment_balance').val(0);
					$('#payment_perperiod').val(OutStanding);
				}else{

					$('#loan_payment').val(amount);
		
					$('#txt_payment_for').val(piutang_no);
				   	$('#txa_memo').html(description);

				   	$('#txt_amount').numberbox('setValue',0);
					$('#payment_period').val(0);
					$('#payment_balance').val(0);
					$('#payment_perperiod').val(0);
					$('#new_row').val(0);
				}
			}
		});

		modal_close('dialog_piutang_list');
	}
}

function addNewRow(){

	/*============ jika new row val == 1 berarti sudah ada row baru yang ditambahkan, jika 0 belum ada ===================*/
	var new_row = $('#new_row').val();

	if(new_row == 0 || new_row == ''){

		/*================== hitung jumlah row di table payment history -==================*/
		var row_payment 	= $('#dtg_payment_history').datagrid('getRows');
		var count_row 		= row_payment.length;

		/*================ count_row di jadikan sebagai index baru untuk datagrid payment history =======================*/
		/*================ perhiutngan sebenarnya new_index = (count_row - 1) + 1 =======================================*/

		//var new_index 		= count_row;

		var loan_payment 	= $('#loan_payment').val();
		var no_paymen 		= $('#payment_afiliasi_no').val();

		/*========================= untuk payment period valuenya = count_row + 1 ================================*/
		var period 			= count_row + 1;

		/*======================== tambahkan 1 row ke datagrid payment history ===============================*/
		$('#dtg_payment_history').datagrid('appendRow',{
			LoanPayment 		: loan_payment,
			PaymentPeriod 		: period,
			PaymentPerPeriod 	: 0,
			PaymentBalance 		: 0,
			AInsNumber			: no_paymen
		});

		$('#new_row').val(1);
	}
	
}
	
function get_amount_from_grid(){

	/*===================== save row & get all rows =======================*/
	$('#dtg_payment_history').edatagrid('saveRow');	
	var row_payment 	= $('#dtg_payment_history').datagrid('getRows');
	var count_row 		= row_payment.length;

	var total_payment  	= 0;
	var loan_payment 	= parseFloat($('#loan_payment').val());

	/*============== looing item datagrid payment history ===================*/
	$.each(row_payment, function( index,value) {
        total_payment 	+= parseFloat(value.PaymentPerPeriod);

        /*================== get payment history terakhir ========================*/
        if( (index+1) == count_row ){
        	$('#payment_balance').val(value.PaymentBalance);
			$('#payment_perperiod').val(value.PaymentPerPeriod);
			$('#payment_period').val(value.PaymentPeriod);
			$('#txt_amount').numberbox('setValue',value.PaymentPerPeriod);
        }
    });

    if(loan_payment < total_payment){
    	$.messager.alert('Unseccessfull','Pembayaran melebihi sisa nilai pinjaman','error',function(){
			$('#txt_amount').numberbox('setValue',0);
			$('#payment_period').val(0);
			$('#payment_balance').val(0);
			$('#payment_perperiod').val(0);
			$('#new_row').val(0);
			$('#dtg_payment_history').datagrid('reload'); 
		});
    }

}


//======== SAVE ========
function save_me(){

	var new_row 		= $('#new_row').val();

	if(new_row > 0){

		/*===================== save row & get all rows =======================*/
		$('#dtg_payment_history').edatagrid('saveRow');	
		var row_payment 	= $('#dtg_payment_history').datagrid('getRows');

		var total_payment  	= 0;
		var loan_payment 	= parseFloat($('#loan_payment').val());

		/*============== looing item datagrid payment history ===================*/
		$.each(row_payment, function( index,value) {
	        total_payment 	+= parseFloat(value.PaymentPerPeriod);
	    });

	    if(loan_payment < total_payment){
	    	$.messager.alert('Unseccessfull','Pembayaran melebihi sisa nilai pinjaman','error',function(){
				$('#txt_amount').numberbox('setValue',0);
				$('#payment_period').val(0);
				$('#payment_balance').val(0);
				$('#payment_perperiod').val(0);
				$('#new_row').val(0);
				$('#dtg_payment_history').datagrid('reload'); 
			});
	    }else{

	    	var amount 			= parseFloat($('#txt_amount').numberbox('getValue'));

	    	if(amount > 0){
		    	var AdebtNumber   	= $('#txt_payment_for').val();
				var payment_period 	= $('#payment_period').val();

				checking_payment_save(AdebtNumber,payment_period,'AIns',function(check){
					
					if(check.status == false){
						save_transaction('<?= $menu_link?>','#fm_payment_afiliasi');
					}else{
						$.messager.alert('Unseccessfull',check.message,'error',function(){
							location.reload();
						});
					}
				});
			}else{
				$.messager.alert('Unseccessfull','Payment amount belum di input.','error',function(){
					$('#txt_amount').numberbox('setValue',0);
					$('#payment_period').val(0);
					$('#payment_balance').val(0);
					$('#payment_perperiod').val(0);
					$('#new_row').val(0);
					$('#dtg_payment_history').datagrid('reload'); 
				});
			}
	    }
		
	}else{
		$.messager.alert('Unseccessfull','Belum ada transaksi payment.','error',function(){
			$('#txt_amount').numberbox('setValue',0);
			$('#payment_period').val(0);
			$('#payment_balance').val(0);
			$('#payment_perperiod').val(0);
			$('#new_row').val(0);
			$('#dtg_payment_history').datagrid('reload');
		});
	}
}
//======= END SAVE ===========
</script>