<!---- 
    Author 	: Herpan
    Tanggal : 12-08-2014	
    Revisi 	:
-->
<?php
//---------Untuk privellege jika dia ada tombol save,suspen,jurnal----------
	if($group_user->SavePrivillage == 1){
		$cek_autority_save  = "";
	}
	else{
		$cek_autority_save 	= "disabled";
	}
	
	if($group_user->JournalPrivillage == 1){
		$cek_autority_journal  = "";
	}
	else{
		$cek_autority_journal 	= "disabled";
	}
	
	if($group_user->DeletePrivillage == 1){
		$cek_autority_delete  = "";
	}
	else{
		$cek_autority_delete 	= "disabled";
	}

	if($group_user->ReversePrivillage == 1){
        $cek_autority_reverse  = "";
    }
    else{
        $cek_autority_reverse    = "display:none";
    }
//-------------end----------------------------
$trans_status = "";
	foreach($payment as $row):
		$trans_status = $row->status;
?>

<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">
							
							<input type="checkbox" class="easyui-checkbox" name="chk_suspended" id="chk_suspended" style="margin-top:0px;margin-right:1px;" onClick="suspend(1)" <?=(!in_array($row->status,array(5,6))) ? 'disabled' : ''?> <?=(in_array($row->status,array(3,9))) ? 'checked' : ''?> <?= $cek_autority_delete;?>/>
                    		<span style="display:inline-block;margin-top:2px;<?=(($row->status==3)?'color:gray;':'color:black')?>">Suspend</span>
							<a href="#" class="easyui-linkbutton" iconCls="icon-journal" plain="true" onclick="show_journal()" <?= $cek_autority_journal;?>>Journal</a>
                    		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="location.reload()">Refresh</a>
						</td>
						<td align="center" width="40%"><span id="approval_information">
		                <?php
		                if($row->status == 5){
		                    echo get_status_approval_header($row->status);
		                }
		                ?>
		                </span></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">
    <?php if($row->status==2){ ?>
        <div class="blanket"></div>
        <div class="paid-box"><b>Paid</b></div>
    <?php }else if($row->status==3){ ?>
    	 <div class="blanket"></div>
         <div class="suspend-box"><b>Suspended</b></div>
	<?php
	}
	?>
		<div id="form-wrapper" class="easyui-panel"  style="width:1180%;height:548px;padding:5px;" fit='true'>
			
			<form id="fm_payment_afiliasi" name="fm_payment_afiliasi" method="post">
				
                <table cellpadding="0" cellspacing="3" width="100%" height="100%" border="0">
					<tr>
						<td valign="middle" height="22" width="70" align="left">
							<b><label>Payment for</label></b>
						</td>
						<td width="10"><b>:</b></td>
						<td valign="top" align="left"  width="800">
							<input name="txt_payment_for" id="txt_payment_for" type="text" value="<?= $row->ADebtNumber;?>" style="width:402px;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="100" align="center" valign="middle" bgcolor="#333399"><span style="color: #fff">Payment Afiliasi No.</span></td>
												<td width="100" 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="text" name="payment_afiliasi_no" id="payment_afiliasi_no" class="easyui-validatebox" style="width:200px;background-color:#E3E2E2;"  required="required"
														value="<?= $row->AInsNumber;?>" readonly />
												</td>
												<td align="right" valign="top">
													<input name="txt_payment_afiliasi_date" id="txt_payment_afiliasi_date" type="text" class="easyui-datebox" value="<?= convert_to_dmy($row->AInsDate);?>" style="width:125px;height:20px" required="required" readonly/>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td valign="top" height="22" width="70" align="left">
							<b><label>Transfer From</label></b>

						</td>
						<td width="10"><b>:</b></td>
						<td valign="top" align="left"  width="800">
							<select name="cmb_fromcompany" id="cmb_fromcompany" class="easyui-combobox" editable="false" style="width:200px;" required="true"   
									readonly data-options="
										value:'<?= $row->FromCompCode;?>',
										valueField:'CompanyCode',
										textField:'CompanyName',
										url:'<?= base_url().$menu_link; ?>/get_company/<?= $row->FromCompCode;?>'
									">
							</select>
							<select name="cmb_bankfrom" id="cmb_bankfrom" editable='true' class="combo-grid"  style="width:200px;" required="true" <?php if($trans_status == 3 || $trans_status == 2 || $trans_status == 1) {echo "disabled";}?>
									data-options="
										value:'<?= $row->AccountBankFrom;?>',
										panelWidth:199,
                                        idField: 'AccountNumber',
                                        textField: 'AccountName',
                                        method : 'get',
                                       	url:'<?= base_url().$menu_link; ?>/get_bank/<?= $row->FromCompCode;?>',
                                        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,
                                        onSelect:function(){
											$('.app-button').linkbutton('disable');
										}
									">
							</select>
						</td>
					</tr>
					<tr>
						<td valign="top" height="22" align="left">
							<b><label>Transfer To</label></b>
						</td>
						<td width="10"><b>:</b></td>
						<td valign="top" align="left">
							<select name="cmb_tocompany" id="cmb_tocompany" class="easyui-combobox" editable="false" style="width:200px;" required="true"
								readonly data-options="
									value:'<?= $row->ToCompCode;?>',
									valueField:'CompanyCode',
									textField:'CompanyName',
									url:'<?= base_url().$menu_link; ?>/get_company/<?= $row->ToCompCode;?>'
								">
							</select>
							<select name="cmb_bankto" id="cmb_bankto" editable='true' class="combo-grid"  style="width:200px;" required="true" <?php if($trans_status == 3 || $trans_status == 2 || $trans_status == 1) {echo "disabled";}?>
								data-options="
										value:'<?= $row->AccountBankTo;?>',
										panelWidth:199,
                                        idField: 'AccountNumber',
                                        textField: 'AccountName',
                                        method : 'get',
                                       	url:'<?= base_url().$menu_link; ?>/get_bank/<?= $row->ToCompCode;?>',
                                        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,
                                        onSelect:function(rowIndex,rowData){
											$('.app-button').linkbutton('disable');
											
                                            get_bank_balance(rowData.AccountNumber,rowData.CurrencyCode);
										}
								">
							</select>
						</td>
					</tr>
					<tr>
						<td valign="middle" height="22" align="left">
							<b><label><?php echo label_grid('check_no');?></label></b>
						</td>
						<td width="10"><b>:</b></td>
						<td valign="top" align="left">
							<input name="txt_cheque_no" id="txt_cheque_no" type="text" style="width:402px" value="<?= $row->ChequeNumber;?>" <?php if($trans_status == 3 || $trans_status == 2 || $trans_status == 1) {echo "disabled";}?>/>
						</td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>
					<!--<tr>
						<td valign="middle" height="22" align="left">
							Date
						</td>
						<td valign="top" align="left">
							<input name="txt_cheque_date" id="txt_cheque_date" type="text" class="easyui-datebox" style="width:100px;height:20px;" 
							value="<?= convert_to_dmy($row->ChequeDate);?>" <?php if($trans_status == 3 || $trans_status == 2 || $trans_status == 1) {echo "disabled";}?>/>
						</td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>-->
					<tr>
						<td valign="top" height="51" align="left">
							<b><label>Memo</label></b>
						</td>
						<td width="10" valign="top"><b>:</b></td>
						<td valign="top" align="left">
							<textarea class="textbox" style="resize:none;" name="txa_memo" id="txa_memo" cols="55" rows="3" <?php if($trans_status == 3 || $trans_status == 2 || $trans_status == 1) {echo "disabled";}?>><?=  $row->APayDesc;?></textarea>
						</td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>
					<tr>
						<td height="22" valign="top" align="left"><b><label>Amount</label></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" style="width:402px;background-color:#E3E2E2;text-align:right"
									 value="<?= $row->APayAmount;?>" readonly data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.',disabled:true"/>
							
          					<input type="hidden" id="detail" name="detail" />
          					<input type="hidden" id="link_id" name="link_id" value="<?= $row->LinkNumber;?>"/>
							<input type="hidden" id="loan_payment" name="loan_payment" value="<?= $row->LoanPayment;?>"/>
							<input type="hidden" id="payment_balance" name="payment_balance" value="<?= $row->PaymentBalance;?>"/>
                            <input type="hidden" id="payment_period" name="payment_period" value="<?= $row->PaymentPeriod;?>"/>
							<input type="hidden" id="payment_perperiod" name="payment_perperiod" value="<?= $row->PaymentPerPeriod;?>"/>
							<input type="hidden" id="new_row" name="new_row" value="1"/>

                        </td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>
					<tr height="20" style="display:none">
                        <td valign="top" height="22" 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:402px" readonly />
                        </td>
                    </tr>						
				</table>
				<input type="hidden" name="exsist_trans_status" id="exsist_trans_status" value="<?= $trans_status?>" />
				<input type="hidden" name="code_appdir" id="code_appdir" />
				<input type="hidden" name="copy_suspend" id="copy_suspend" />
				
				<table id="dtg_payment_history" class="easyui-<?=(in_array($row->status,array(0,1,2,4)))?'datagrid':'edatagrid'?>" title="Payment History"  idField="id" rownumbers="true" fitColumns="true" 
						singleSelect="true" style="height:293px;" url="<?= base_url().$menu_link;?>/payment_detail/<?= $row->ADebtNumber;?>/<?= $row->PaymentPeriod;?>/<?= $row->status;?>/<?= $row->AInsNumber;?>"
						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',pay_perperiod);
										$('#payment_period').val(pay_period);
										$('#payment_balance').val(payment_balance);
										$('#payment_perperiod').val(pay_perperiod);
										$('#new_row').val(1);
										$('#dtg_payment_history').datagrid('reload');
									});
								 }
							}
						"
						>
					<thead>
						<tr>
							<th data-options="field:'LoanPayment',width:100,halign:'center',align:'right'" formatter="formatRp">Loan Payment</th>
							<th data-options="field:'PaymentPeriod',width:100,halign:'center',align:'center'" hidden>Payment Period</th>
							<th data-options="field:'PaymentPerPeriod',width:100,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'" formatter="formatRp">Payment Balance</th>
                            <th data-options="field:'AInsNumber',width:100,halign:'center',align:'right'" hidden='true'>AInsNumber</th>
						</tr>
					</thead>
				</table>
			</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 app-button app-approval" iconCls="icon-ok" onclick="app_dir()" <?= (($this->session->userdata("jobtitle_status") != 0 || !in_array($row->status, array(5,6))) || (date('Y-m-d') < date('Y-m-d', strtotime($row->AInsDate))))?'disabled':'' ?>>App. Dir</a>
                     <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-reload" onclick="app_reverse()" <?=(in_array($row->status,array(1,2,9)))?'':'disabled'?> style="<?= $cek_autority_reverse;?>" >Reverse</a>
                     <a href="javascript:void(0)" class="easyui-linkbutton form-button save-button" iconCls="icon-save" onclick="update_payment_afiliasi()" <?=(in_array($row->status,array(0,1,2,3)))?'disabled':''?> <?= $cek_autority_save;?>>Save</a> 								
                     <!-- <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="parent.tab_edit('Print Payment Afiliasi', '<?=$menu_link?>', 'icon-print', 'to_preview_by_payment_number','<?= $row->AInsNumber;?>')">Preview & Print</a>  -->  
                     <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="parent.tab_edit('Print Payment Afiliasi', '<?=$menu_link?>', 'icon-print', 'to_print_detail','<?= $row->AInsNumber;?>');" <?=(in_array($row->status,array(4,5,6,1,2,3,9)))?'':'disabled'?>>Preview & Print</a>
                     <!-- <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="<?=($this->session->userdata('jobtitle_status')==0)?'suspend(2)':'parent.tab_close(\'tt\')'?>" <?=(in_array($trans_status,array(3,9)) || $row->AppLevel2Status==1)?'disabled':''?>>Cancel</a> -->	
                	 <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="<?=($this->session->userdata('jobtitle_status')==0)?'suspend(2)':'parent.tab_close(\'tt\')'?>" <?=(!in_array($row->status,array(0,5,6)))?'disabled':''?>><?=($this->session->userdata('jobtitle_status')==0)?'Cancel':'Close'?></a>	
                </td>
             </tr>
        </table>				
    </div>
</div>

<script type="text/javascript">

/*========== variabel untuk menampung default value grid edit =============================*/
var pay_period 		= '<?= $row->PaymentPeriod;?>';
var pay_perperiod 	= '<?= $row->PaymentPerPeriod;?>';
var pay_balance 	= '<?= $row->PaymentBalance;?>';
var loy_payment 	= '<?= $row->LoanPayment;?>';
var n_row 			= 1; 

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

$(document).ready(function(){
	
	$('#txt_cheque_date').datebox('setValue', '<?= date("d-m-Y", strtotime($row->ChequeDate));?>');
	$('#txt_payment_afiliasi_date').datebox('setValue', '<?= date("d-m-Y", strtotime($row->AInsDate));?>');

	$('#chk_suspend').click(function(){
		if($(this).is(':checked')){
			$('#copy_suspend').val('1');
		}
		else{
			$('#copy_suspend').val('');
		}
	});

	var AccountBankTo = '<?= $row->AccountBankTo;?>';
	
    get_bank_balance(AccountBankTo,'IDR');

    $('#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);
				
			}
		}
    });
	
    $('#txt_payment_for').on('click',function(){
    	var ADebtNumber = $(this).val();
    	parent.tab_edit('Edit Piutang Afiliasi', 'list/piutang_afiliasi', 'icon-edit', 'edit', ADebtNumber);
    }).on('mouseover',function(){
    	$(this).css({"color":"blue","text-decoration":"underline","cursor":"pointer"});
    }).on('mouseout',function(){
    	$(this).css({"color":"#545454","text-decoration":"none"});
    });

});

	
	function update_payment_afiliasi(){

		$('#dtg_payment_history').edatagrid('saveRow');	
		var row_payment 	= $('#dtg_payment_history').datagrid('getRows');

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

		$.each(row_payment, function( index,value) {
	        total_payment 	+= parseFloat(value.PaymentPerPeriod);
  
    	});
		
		if(payment_perperiod > loan_payment){
			$.messager.alert('Unseccessfull','Pembayaran melebihi sisa nilai pinjaman','error',function(){
				$('#txt_amount').numberbox('setValue',pay_perperiod);
				$('#payment_period').val(pay_period);
				$('#payment_balance').val(payment_balance);
				$('#payment_perperiod').val(pay_perperiod);
				$('#new_row').val(1);
				$('#dtg_payment_history').datagrid('reload');
			});

		}else{

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

			if(amount > 0){

				var login_as        = "<?= $this->session->userdata('username');?>";
				var created_by      = "<?= $row->CreatedBy;?>";
				var depart_by       = "<?= $row->DepartmentCode;?>";
			    var depart_ses      = "<?= $this->session->userdata('department');?>";
			    var jobtitle_status = "<?= $this->session->userdata('jobtitle_status');?>";

				var no_transaksi    = $('#payment_afiliasi_no').val();
			    var status          = '<?= $row->status;?>';
			    

			    checking_update(no_transaksi,status,function(check){
			        
			        if(check.status == true){

			            $('#dtg_payment_history').edatagrid('saveRow');
						var i=$('#dtg_payment_history').datagrid('getRows');
						var detail = JSON.stringify(i);
						$("#detail").val(detail);
						edit_data('<?=$menu_link?>','#fm_payment_afiliasi',created_by,login_as,depart_by,depart_ses,jobtitle_status);

			        }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',pay_perperiod);
					$('#payment_period').val(pay_period);
					$('#payment_balance').val(payment_balance);
					$('#payment_perperiod').val(pay_perperiod);
					$('#new_row').val(1);
					$('#dtg_payment_history').datagrid('reload');
				});

			}
		}
		
	}
	
	function app_dir(){

		$('#dtg_payment_history').edatagrid('saveRow');	
		var row_payment 	= $('#dtg_payment_history').datagrid('getRows');

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

		$.each(row_payment, function( index,value) {
	        total_payment 	+= parseFloat(value.PaymentPerPeriod);
  
    	});
		
		if(payment_perperiod > loan_payment){
			$.messager.alert('Unseccessfull','Pembayaran melebihi sisa nilai pinjaman','error',function(){
				$('#txt_amount').numberbox('setValue',pay_perperiod);
				$('#payment_period').val(pay_period);
				$('#payment_balance').val(payment_balance);
				$('#payment_perperiod').val(pay_perperiod);
				$('#new_row').val(1);
				$('#dtg_payment_history').datagrid('reload');
			});
		}else{
			
			var payment_afiliasi_no   	= $('#payment_afiliasi_no').val();
			
			checking_approval(payment_afiliasi_no,function(check){
				if(check.status == false){
					$('#code_appdir').val('5');
	            	approved_dir('<?=$menu_link?>','#fm_payment_afiliasi');
				}else{
					$.messager.alert('Unseccessfull',check.message,'error',function(){
						location.reload();
					});
				}
			});
		       
		}
	}

	function app_reverse(){

		var no_transaksi    = $('#payment_afiliasi_no').val();

	    checking_reverse(no_transaksi,function(check){
	        
	        if(check.status == true){

	           	var LinkNumber = $('#link_id').val();
				var no_afiliasi_piutang = $('#txt_payment_for').val();
		    	reversed_data('F','<?=$menu_link?>', LinkNumber + ',' + no_afiliasi_piutang, 'Payment Afiliasi');

	        }else{
	           $.messager.alert('Unseccessfull',check.message,'error',function(){
	                location.reload();
	            });
	        }
	    });
	}
	
	function get_datatogrid(){
		var id_afilasi = $('#id_afiliasi').val();
		$('#dtg_payment_history').datagrid('reload','<?= base_url()?>list/payment_afiliasi/gridbyafiliasiID'+id_afilasi);
	}
	
	function show_journal(){
		var id			= $('#payment_afiliasi_no').val();
		parent.tab_edit('Journal Payment Afiliasi', '<?=$menu_link?>', 'icon-journal', 'to_journal', id);
	}
	
	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',pay_perperiod);
				$('#payment_period').val(pay_period);
				$('#payment_balance').val(payment_balance);
				$('#payment_perperiod').val(pay_perperiod);
				$('#new_row').val(1);
				$('#dtg_payment_history').datagrid('reload');
			});
	    }
	}
	
	function suspend(type){

		var no_transaksi    = $('#payment_afiliasi_no').val();

	    checking_suspend(no_transaksi,function(check){
	        
	        if(check.status == true){
	          	suspend_data_new('F',type,'<?= $menu_link;?>',$('#link_id').val(),'Payments Afiliasi');
	        }else{
	            $.messager.alert('Unseccessfull',check.message,'error',function(){
	                location.reload();
	            });
	        }
	    });
	}
</script>
<?php endforeach;?>