<?php include "config/init.php"?>

<?php include "template/header.php"?>

    <!-- Main Header  -->
    <?php include "template/main-header.php"?>

    <!-- Left side column. contains the logo and sidebar -->
    <?php include "template/main-sidebar.php"?>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1 style="color:red">
                Failed Transactions
            

            </h1>
            <ol class="breadcrumb">
                <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Customer</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
			
			<?php
			if(empty($_GET["ref"]) && !isset($_GET["ref"])){
			?>

            <div class="row">
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <!-- List of All Payout -->
                        <div class="panel-heading" style="color:red">This is a list of Failed Transactions</div>
                        <div class="panel-body">
                            <table class="table table-striped" id="failed-transactions">
                                <thead>
                                <tr>
                                    <th>DateTime</th>
                                    <th>transaction ID</th>
                                    <th>Transaction Type</th>
                                    <th>Sender Name</th>
                                    <th>Recipient Name</th>
                                    <th>senderAmount</th>
                                    <th>RecipientAmount</th>
                                    <th>Exchange Rate</th>
                                    <th>Tnx Reference</th>
                                    <th>Fee</th>
                                    <th>Status</th>
                                    <th>Device</th>
									<th>View</th>
									<th>Action</th>
                                </tr>
                                </thead>
                            </table>
                            <hr>
                        </div>
                    </div>
                </div>
            </div>
			
			<?php
			}else{
			
			//echo $net_comm;
			$trnx_data = get_main_transaction_by_transaction_uid($dbc,$_GET["ref"]);
			$type = $trnx_data["transactionTypes"];
			
			$cus = get_customer_by_id($dbc,$trnx_data["senderID"]);
			$sender = $cus["fullName"];
			
			
			$data = array();
			
			if($type=="MT-BANK"){
				
			$data['sender']= $sender;
			$data['account_number']= $trnx_data["remitRecipientBankAccount"];
			$data['account_bank']= $trnx_data["remitRecipientBankName"];
			$data['amount']= $trnx_data["recipientAmount"];
			$data['transaction_id']= $trnx_data["transaction_uid"];
			
			$result_bank = api_BankTransfer_Autocomplete($data);
			
			if($result_bank["statusCode"]==200 || $result_bank["statusCode"]=="200"){
			update_main_transaction_status_with_txnID($dbc,$trnx_data["transaction_uid"],"COMPLETED");
			$result = "<p class='alert alert-success'>Transaction successfully completed --BANK--</p>";	
			}else{
			$result = "<p class='alert alert-danger'>Transaction completion failed</p>";		
			}
			
			}elseif($type=="MT-MOMO"){
				
			$data['sender']= $sender;
			$data['momoNumber']= $trnx_data["remitRecipientMomoNumber"];
			$data['channel']= $trnx_data["remitRecipientChannel"];
			$data['amount']= $trnx_data["recipientAmount"];
			$data['transaction_id']= $trnx_data["transaction_uid"];
			
			$result_momo = api_MomoPush_Autocomplete($data);
			
			if($result_momo["statusCode"]==200 || $result_momo["statusCode"]=="200"){
			update_main_transaction_status_with_txnID($dbc,$trnx_data["transaction_uid"],"COMPLETED");
			$result = "<p class='alert alert-success'>Transaction successfully completed --BANK--</p>";	
			}else{
			$result = "<p class='alert alert-danger'>Transaction completion failed</p>";		
			}
			
			}elseif($type=="MT-AIRTIME"){
				
			$data['sender']= $sender;
			$data['amount']= $trnx_data["recipientAmount"];
			$data['phoneNumber']= $trnx_data["airtimeNumber"];
			$data['channel']= $trnx_data["airtimeChannel"];
			$data['transaction_id']= $trnx_data["transaction_uid"];
			
			$result_airtime = api_buy_airtime_Autocomplete($data);
			
			if($result_airtime["statusCode"]==200 || $result_airtime["statusCode"]=="200"){
			update_main_transaction_status_with_txnID($dbc,$trnx_data["transaction_uid"],"COMPLETED");
			$result = "<p class='alert alert-success'>Transaction successfully completed --BANK--</p>";	
			}else{
			$result = "<p class='alert alert-danger'>Transaction completion failed</p>";		
			}
			
			}else{
			$result = "<p class='alert alert-danger'>Transactions Unavailable</p>";	
			}
				
			if(isset($result)){echo $result; }
			//var_dump($trnx_data["transactionTypes"]);
    
			?>
			
			<?php
			}
			?>

        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

<?php include "template/footer.php"?>


