<?php
include "config/init.php";
include "template/header.php";
//Main Header
include "template/main-header.php";
//Left side column. contains the logo and sidebar -->
include "template/main-sidebar.php";
if($_SESSION['role'] != 'SYSTEMADMIN'){
    header("location:index.php");
    die();
}

/**
$total_sent1 ="0.00";
$num_sent1 =0;
$total_received1 ="0.00";
$country_bal1  ="0.00";
$num_received1 =0;
$total_commission1 ="0.00";
$total_pg_commission1 ="0.00";
$total_fees1 ="0.00";
$total_unredeemed_tokens1 ="0.00";
 */
if(isset($_POST['RECONCILE-1'])){
    if(!empty($_POST['sender'])){

        //$result ="TEST ".$_POST['sender'];
		

        $name = get_customer_by_id($dbc,$_POST['sender'])['fullName'];
        $pnum = get_customer_by_id($dbc,$_POST['sender'])['phoneNum'];
		$countryCode = get_customer_by_id($dbc,$_POST['sender'])['countryCode'];
		
		$cus_acc = get_cus_account_info_by_customerID($dbc,$_POST['sender'],$countryCode);

        $total_credit =  moneyFormat2($cus_acc['credit']);
        $total_debit =  moneyFormat2($cus_acc['debit']);
        $total_balance =  moneyFormat2($cus_acc['balance']);
		$sender = trim($_POST['sender']);

        
	$total_fees1 = get_main_transaction_by_customer_fees_all_special($dbc,$sender,"gb");
	$total_fees1 = $total_fees;
	$total_received1 =  get_main_transaction_by_customer_received_all_special($dbc,$sender,"gb");
    $total_sent1 =  get_main_transaction_by_customer_sent_all_special($dbc,$sender,"gb");
    $country_bal1 = $total_received1 - $total_sent1;

	
	                            /**
                                $reff = isset($_GET["ref"])? $_GET["ref"] : "xxx";//sendersAmount recipientAmount
                                $query1 = "SELECT sum(sendersAmount) as sender_lr FROM maintransaction_tbl WHERE senderID = '$reff' && senderCountryCode ='lr' && transactionStatus='COMPLETED'";
                                $query2 = "SELECT sum(sendersAmount) as sender_lr1 FROM maintransaction_tbl WHERE senderID = '$reff' && senderCountryCode ='lr1' && transactionStatus='COMPLETED'";
                                $query3 = "SELECT sum(recipientAmount) as receiver_lr FROM maintransaction_tbl WHERE recipientID = '$reff' && recipientCountryCode ='lr' && transactionStatus='COMPLETED'";
                                $query4 = "SELECT sum(recipientAmount) as receiver_lr1 FROM maintransaction_tbl WHERE recipientID = '$reff' && recipientCountryCode ='lr1' && transactionStatus='COMPLETED'";
                                $q1 = mysqli_query($dbc,$query1);
                                $q2 = mysqli_query($dbc,$query2);
                                $q3 = mysqli_query($dbc,$query3);
                                $q4 = mysqli_query($dbc,$query4);

                                while( $row1=mysqli_fetch_array($q1) ) {  
                                $total_sent_lr = moneyFormat2($row1['sender_lr'] + $fees_lr);
                                }
                                while( $row2=mysqli_fetch_array($q2) ) {  
                                $total_sent_lr1 = moneyFormat2($row2['sender_lr1'] + $fees_lr1);
                                }
                                while( $row3=mysqli_fetch_array($q3) ) {  
                                $total_received_lr = moneyFormat2($row3['receiver_lr']);
                                }
                                while( $row4=mysqli_fetch_array($q4) ) {  
                                $total_received_lr1 = moneyFormat2($row4['receiver_lr1']);
                                }
                                **/
                                



    }



}



?>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">

        <h1>
            Customer Reconciliation
        </h1>

        <?php ?>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-3">
                <div class="box box-primary">
                    <div class="box-header with-border">Find Customer</div>
                    <div class="box-body">
                        <form role="form" method="post">

                            <div class="form-group">
                                <label for="findCustomer">Find Customer</label>
                                <select class="form-control" required name="sender" id="findCustomer">
                                    <option value="">Find Customer</option>
                                </select>
                            </div>

                            <div class="form-group">
                                <button type="submit" name="RECONCILE-1" class="btn btn-primary">Submit</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

            <div class="col-md-9">
                <div class="row">
                    <div class="col-md-12">
                        <div class="small-box bg-aqua">
                            <div class="inner">
                                <h4><b>Actual Transactions Summary <?=!isset($_POST['sender'])?" ":" For ".$name."(".$pnum.")"?></b></h4>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3><?=!isset($total_sent1)?"0.00":$total_sent1;?></h3>
                                <p><b>Total Sent</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>
                    <div class="col-md-4">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3><?=!isset($total_received1)?"0.00":$total_received1;?></h3>
                                <p>Total Received</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>

                    <div class="col-md-4">
                        <div class="small-box bg-blue">
                            <div class="inner">
                                <h3><?=!isset($country_bal1)?"0.00":$country_bal1;?></h3>
                                <p>Account Balance</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3><?=!isset($total_fees1)?"0.00":$total_fees1;?></h3>
                                <p>Total Fees</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>

                    <div class="col-md-4">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3><?=!isset($total_commission1)?"0.00":$total_commission1?></h3>
                                <p>Agent Commissions</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>

                    <div class="col-md-4">
                        <div class="small-box bg-green">
                            <div class="inner">
                                <h3><?=!isset($total_pg_commission1)?"0.00":$total_pg_commission1;?></h3>
                                <p>Diamond-Pay Commission</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3><?=!isset($num_sent1)?"0":$num_sent1;?></h3>
                                <p>Sent Transactions #</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>

                    <div class="col-md-4">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3><?=!isset($num_received1)?"0":$num_received1;?></h3>
                                <p>Received Transactions #</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>

                    <div class="col-md-4">
                        <div class="small-box bg-red">
                            <div class="inner">
                                <h3><?=!isset($total_unredeemed_tokens1)?"0.00":$total_unredeemed_tokens1;?></h3>
                                <p>Unredeemed Tokens</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>
                </div>


                <div class="row">
                    <div class="col-md-12">
                        <div class="small-box bg-aqua-gradient">
                            <div class="inner">
                                <h4><b>System Transactions Summary <?=!isset($_POST['sender'])?" ":" For ".$name."(".$pnum.")"?></b></h4>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-4">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3><?=!isset($total_debit)?"0.00":$total_debit;?></h3>
                                <p><b>Total Sent</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>
                    <div class="col-md-4">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3><?=!isset($total_credit)?"0.00":$total_credit;?></h3>
                                <p>Total Received</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>

                    <div class="col-md-4">
                        <div class="small-box bg-blue">
                            <div class="inner">
                                <h3><?=!isset($total_balance)?"0.00":$total_balance;?></h3>
                                <p>Account Balance</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3><?=!isset($total_fees1)?"0.00":$total_fees1;?></h3>
                                <p>Total Fees</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>

                    <div class="col-md-4">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3><?=!isset($total_commission1)?"0.00":$total_commission1?></h3>
                                <p>Agent Commissions</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>

                    <div class="col-md-4">
                        <div class="small-box bg-green">
                            <div class="inner">
                                <h3><?=!isset($total_pg_commission1)?"0.00":$total_pg_commission1;?></h3>
                                <p>Diamond-Pay Commission</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3><?=!isset($num_sent1)?"0":$num_sent1;?></h3>
                                <p>Sent Transactions #</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>

                    <div class="col-md-4">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3><?=!isset($num_received1)?"0":$num_received1;?></h3>
                                <p>Received Transactions #</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>

                    <div class="col-md-4">
                        <div class="small-box bg-red">
                            <div class="inner">
                                <h3><?=!isset($total_unredeemed_tokens1)?"0.00":$total_unredeemed_tokens1;?></h3>
                                <p>Unredeemed Tokens</p>
                            </div>
                            <div class="icon">
                                <i class="fa fa-money"></i>
                            </div>
                        </div>

                    </div>
                </div>

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

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


