<?php 
	include("../config/defines.php"); 
	if(!isset($_SESSION["user_id"])){ echo "<script>window.location.href = '../login';</script>"; }
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta name="viewport" content="width=device-width"/>
        <meta charSet="utf-8"/>
        <title>Deposit| <?php echo $company_name; ?></title>
        <?php include($AaliLINK_IN."/functions/html/css.php"); ?>
    </head>
    <body>
        <?php include($AaliLINK_IN."/functions/html/header.php"); ?>
        
      
<div class="section-body">   
    <div class="row mb-2 p-3">
      	<div class="col-md-4">
        	<div class="card shadow-lg">
             	<div class="card-body">
                  <h3 class="text-center py-1">Deposit</h3>
<?php if(isset($_POST["btn_deposit"])){ if($_POST["date"]=="" || $_POST["slip_id"]=="" || $_POST["amount"]=="" || $_POST["gateway"]=="0" || $_FILES["slip"]==""){
            echo "<div class='alert alert-warning alert-block'>Fill in all the fields..!</div>";
        }else{
            $valid_extensions = array('jpeg', 'jpg', 'png', 'gif', 'bmp'); 
            $user_image = '../cms/uploads/deposits/'; 
            $img = $_FILES['slip']['name'];
            $tmp = $_FILES['slip']['tmp_name'];
            $ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));
            $final_image = rand(1000,1000000).$img;
            if(in_array($ext, $valid_extensions)){ 
                $user_image = $user_image.strtolower($final_image); 
                if(move_uploaded_file($tmp,$user_image)){
                    $ded=0; $amt=0;
                    $date = date("Y-m-d H:i:s");
                    
                    $queryu = mysqli_query($conn,"INSERT INTO aalierp_deposit (dep_date,slip_id,user_id,dep_amount,dep_way,dep_slip,dep_reason,dep_status,created_by) VALUES 
                    ('".$_POST["date"]."','".$_POST["slip_id"]."','".$_SESSION["user_id"]."','".$_POST["amount"]."','".$_POST["gateway"]."','".$user_image."','".$_POST["product"]."','Pending','".$user_name."')");
                    if($queryu){
                        echo "<script>window.location.href='https://d101sale.com/profile';</script>";
                    }
                }
            }
        }
    }
?>
<?php $view_rate = mysqli_query($conn, "SELECT * FROM aalierp_rate WHERE rate_for='Deposit' ORDER BY rate_id DESC LIMIT 1"); $re = mysqli_fetch_assoc($view_rate); ?>
                	
                    <form method="POST" enctype="multipart/form-data" onsubmit="return confirm('Kindly check all detail for deposit?');">
                    	<label>Deposit Date:</label>
                        <input type="date" name="date" class="form-control mb-1" />
                        <label>Slip Transaction ID:</label>
                        <input type="text" name="slip_id" placeholder="Transaction ID" class="form-control mb-1" />
                        <label>Gateway:</label>
                        <select class="form-control mb-1" name="gateway">
                        	<option value="0">Select Gateway</option>
<?php 
    $gvi = mysqli_query($conn,"SELECT * FROM aalierp_gateway WHERE gate_type='Deposit'"); while($gro = mysqli_fetch_array($gvi)){ ?>
                            <option value="<?php echo $gro["gate_id"]; ?>"><?php echo $gro["gate_name"]; ?></option>
<?php } ?>
                    	</select>
                        <label>For Product:</label>
                        <select class="form-control mb-1" name="product">
                        	<option value="0">Select Product</option>
<?php 
    $produ = mysqli_query($conn,"SELECT * FROM aalierp_product"); while($pro = mysqli_fetch_array($produ)){ ?>
                            <option value="<?php echo $pro["product_name"]; ?>"><?php echo $pro["product_name"]; ?></option>
<?php } ?>
                    	</select>
                        <label>Deposit:</label>
                        <input type="text" name="amount" placeholder="Enter amount" class="form-control mb-1" />
                        <label>Upload Deposit Slip:</label>
                        <input type="file" class="form-control mb-2" name="slip" />
                        <input type="submit" name="btn_deposit" class="btn btn-info btn-block" value="Add Deposit" />
                 	</form>
                </div>
        	</div>
       	</div>
        <div class="col-md-8">
            <div class="row">
<?php $view_pay = mysqli_query($conn,"SELECT * FROM aalierp_gateway WHERE gate_type='Deposit'"); while($rr = mysqli_fetch_array($view_pay)){ ?>
        
                <div class="col-md-6">
                    <div class="card">
                        <div class="card-body card-type-3">
                            <div class="row">
                                <div class="col">
                                    <h5 class="text-muted mb-0">Gateway: <?php echo $rr["gate_title"]; ?></h5>
                                    <p>Copy Address:</p>
                                    <div class="form-group">
                                        <div class="input-group mt-2" style="height: 30px;">
                                            <input type="text" value="<?php echo $rr["gate_acc"]; ?>" id="myAddress" class="form-control" disabled>
                                            <div class="input-group-append">
                                                <button class="btn btn-primary" onclick="myFunction();" type="button"><i class="fa fa-copy"></i></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>   
        <?php } ?>
            </div>

        	<table class="table table-striped table-block table-sm">
            	<thead>
                	<tr><th colspan="2" class="text-center"><h4>Deposit Detail [Total Amount Deposit: <b class="deposit"></b>]</h4></th></tr>
               	</thead>
                <tbody>
<?php 
    $viewdep = mysqli_query($conn,"SELECT * FROM aalierp_deposit WHERE user_id='".$_SESSION["user_id"]."'");   
    $n=1; while($dow = mysqli_fetch_array($viewdep)){ ?>
                 	<tr>
                    	<td>Recharge<br><?php echo $dow["dep_date"]; ?></td>
                        <td class="text-right"><?php echo $cur."".$dow["dep_amount"]; ?><br><span class="text-success"><?php echo $dow["dep_status"]; ?></span></td>
                	</tr>
<?php } ?>
           		</tbody>
          	</table>
      	</div>
    </div>

</div>
        
        
        
        <?php include($AaliLINK_IN."/functions/html/footer.php"); ?>
        <script>
            function myFunction() {
                var copyText = document.getElementById("myAddress");
                copyText.select();
                copyText.setSelectionRange(0, 99999); 
                navigator.clipboard.writeText(copyText.value);
                alert("Address Copied: " + copyText.value);
            }
        </script>
        <?php include($AaliLINK_IN."/functions/html/js.php"); ?>
    </body>
</html>