<?php 

function reject_payment_cb() {
	$post = new post;
	if(!isset($_GET['id'])) return_method();
	$payment_meta = $post->get_post_meta($_GET['id']);
	$invoice = new pm_invoice($payment_meta['user_id']);
	$invoice->set_invoice_by_number($payment_meta['in_ref']);
	?>
    <div class="row">
	<div class="col-md-6">
	    <div class="panel panel-custom">
	        <div class="panel-heading">
	            <strong class="panel-title">Payment Details</strong>
	        </div>
	        <div class="panel-body">
                
            	<table class="table table-bordered">
            		<tbody>
            			<tr>
            				<td>Name</td>
            				<td><?php echo get_fullname($payment_meta['user_id']) ?></td>
            			</tr>
            			<tr>
            				<td>Description</td>
            				<td><?php echo $invoice->description(); ?></td>
            			</tr>
            			<tr>
            				<td>Amount</td>
            				<td><?php echo toMoney($payment_meta['amount']); ?></td>
            			</tr>
            			<tr>
            				<td>Attachment(s)</td>
            				<td>
            					<?php 
            						$files = get_library_files("pop-".$payment_meta['in_ref'], $payment_meta['user_id']);
									echo "<ul style=\"padding: 0px;\">";
									if(isset($files['files']) && _count($files['files']) && is_array($files['files'])) {
										foreach ($files['files'] as $url => $file_meta) {
											echo "<li style=\"display: block;\"><a href=\"".$url."\" target=\"_blank\">".$file_meta['title']."</a></li>";
										}
									}
									echo "</ul>";
            					 ?>
            				</td>
            			</tr>
            			<tr>
            				<td>Date</td>
            				<td><?php echo date(_DATE_FORMAT_, $payment_meta['posted_on']) ?></td>
            			</tr>
            		</tbody>
            	</table>
            	<form id="reject_payment_form" method="post" action="contents/plugins/payment_module/ajax.php" data-clearform=1 data-callback="disable" data-callbackid="#submit-pm_reject_payment" data-dontcallbackonload=1>
					<input type="hidden" name="id" value="<?php echo $payment_meta['id'] ?>">
					<input type="hidden" name="user_id" value="<?php echo $payment_meta['user_id'] ?>">
					<input type="hidden" name="in_ref" value="<?php echo $payment_meta['in_ref'] ?>">
					<?php 
						textarea(['label' => 'Reason', 'id' => 'reason', 'required' => 'required']);
						submit_btn('pm_reject_payment', 'Submit');
					 ?>
				</form>
	        </div>
	    </div>
    </div>
    </div>
    <?php
    global $post_meta;
    add_page_javascript('app/assets/js/page-scripts/js-functions.js');
    add_page_javascript('app/assets/js/page-scripts/submit.js');
}