<?php include('../config/setup.php'); ?>
<?php 
session_start();
    date_default_timezone_set('Asia/Kolkata');
    // order_master approve update query starts
    if(isset($_POST['change_ven'])){
        $vendor_id = $_POST['vendor_id'];
        $vendor_name = $_POST['vendor_name'];
        $vendor_email = $_POST['vendor_email'];
        $vendor_mobile = $_POST['vendor_mobile'];

        $sql = "SELECT * FROM master_login WHERE Master_Type = 2 AND Master_Active_Status = 1 ORDER BY Master_id DESC " ;
        $sub_sql = "UPDATE master_login SET vendor_name = '$vendor_name' ,vendor_email = '$vendor_email' , vendor_mobile = '$vendor_mobile' WHERE vendor_id = '$vendor_id' " ;
        if($config->query($sub_sql) === TRUE){
            $sql = "UPDATE v_profile SET v_name = '$vendor_name' WHERE vendor_id = '$vendor_id' " ;
            if($config->query($sql) === TRUE){
                $_SESSION['status'] = "Updated Successfully";
    		    $_SESSION['alert'] = "success";
            }else {
                $_SESSION['status'] = "Failed";
    		    $_SESSION['alert'] = "error";
            }
        }

    }
    // order_master approve update query ends
    
    // order_master reject update query starts
    if(isset($_POST['block'])){
        $vendor_id = $_POST['vendor_id'];

        $sql = "UPDATE master_login SET Master_Active_Status = 0 WHERE Master_id = '$vendor_id' " ;
        if($config->query($sql) === TRUE){
            $_SESSION['status'] = "Blocked";
		    $_SESSION['alert'] = "success";
        } else {
            $_SESSION['status'] = "Failed";
		    $_SESSION['alert'] = "error";
        }
    }
    // order_master reject update query ends

        if(isset($_POST['add-Funds'])){
    	 $vendor_id = $_POST['vendor_id'];
    	 $amount = $_POST['total_amount'];
    	 // print_r($vendor_id);exit;
    	 $c_amount = $_POST['c_amount'];
    	 $t_amount=($amount+$c_amount);
        $sql = "UPDATE ewallet_master SET total_amount = '$t_amount' WHERE vendor_id = '$vendor_id' " ;
        if($config->query($sql) === TRUE){
            $_SESSION['status'] = "Updated";
		    $_SESSION['alert'] = "success";
        } else {
            $_SESSION['status'] = "Failed";
		    $_SESSION['alert'] = "error";
        }

    }


?>

<?php include "head.php" ?>
	<div class="wrapper">
		<div class="main-header">
			<!-- Logo Header -->
			<?php include('logo.php'); ?>
			<!-- End Logo Header -->

			<!-- Navbar Header -->
			<?php include('topbar.php'); ?>
			<!-- End Navbar -->
		</div>
		<!-- Sidebar -->
		<?php include('sidebar.php'); ?>


		<div class="main-panel">
			<div class="content">
				<div class="page-inner">
					<div class="page-header d-flex justify-content-between">
						<h4 class="page-title">Add / Edit Vendor</h4>
					</div>
					<div class="row">
						<div class="col-md-12">
							<div class="card">
								<div class="card-body">
									<div class="table-responsive">
										<table id="basic-datatables" class="display table table-striped table-hover">
											<thead>
												<tr>
													<th>S.No</th>
													<th>Name</th>
													<th>Mobile Number</th>
													<th>Email Id</th>
													<th>Status</th>
													<th>Action</th>
												</tr>
											</thead>
											<tbody>
											    <?php
											        $sno = 1;
											        $sql = "SELECT * FROM master_login WHERE Master_Type = 2 AND Master_Active_Status = 1 ORDER BY Master_id DESC " ;
											        $res = $config->query($sql);
											        while($row = $res->fetch_assoc()){
											            $status = $row['Master_Active_Status'];

											             $mas_id= $row['Master_id'];
											             $sql1 = "SELECT * FROM ewallet_master WHERE vendor_id ='$mas_id' " ;
											             $res1 = $config->query($sql1);
											              $pla_res1 = $res1->fetch_assoc();
											    ?>
											    <tr>
											        <td><?= $sno ?></td>
											        <td><?= $row['Master_Name'] ?></td>
											        <td><?= $row['Master_phone'] ?></td>
											        <td><?= $row['Master_Username'] ?></td>
											        <!--<td><?#= $row['Master_Password'] ?></td>-->
											        <td>
											        <?php 
                								        if($status == 1){
                								            $cur_stauts = "Active";
                								            $btn = "success";
                								        }else{
                								            $cur_stauts = "In-Active";
                								            $btn = "danger";
                								        }
                								    ?>
											            <a class="btn btn-<?= $btn ?> text-white" ><?= $cur_stauts; ?></a>
											        </td>
											        <td>
											            <a href="#" class="btn btn-primary" data-toggle="modal" data-target="#vendor<?= $sno; ?>"> <i class="fas fa-pencil-alt"></i>  </a>
											              <a href="#" class="btn btn-info" data-toggle="modal" data-target="#wallet<?= $sno; ?>"> <i class="fas fa-plus"></i>  </a>
											            
											        </td>
											        
											    </tr>
											    <div class="modal fade" id="wallet<?= $sno; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                    				<div class="modal-dialog" role="document">
                                    					<div class="modal-content">
                                    						<div class="modal-header bg-info">
                                    							<h5 class="modal-title" id="exampleModalLabel">Add Funds</h5>
                                    							<button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
                                    								<span aria-hidden="true">&times;</span>
                                    							</button>
                                    						</div>
                                    						<div class="modal-body">
                                    							<form method="post">
                                    								<div class="form-group">
                                    									<label for="user_name">Current Amount</label>
                                    									<input type="hidden"  id="user_id" name="vendor_id" value="<?= $row['Master_id']; ?>" >
                                    									<input type="text" class="form-control" id="user_name" name="c_amount" value="<?= $pla_res1['total_amount']; ?>" readonly>
                                    								</div>
                                    							
                                    								<div class="form-group">
                                    									<label for="user_mobile">Add Funds</label>
                                    									<input type="number" class="form-control" id="user_mobile" name="total_amount" value="" >
                                    								</div>
                                    								<div class="form-group d-flex" style="column-gap:10px;">
                                    									<button class="btn btn-success btn-lg btn-block" type="submit" name="add-Funds"><i class="fas fa-check-circle"></i> Add</button>
        																<button class="btn btn-danger btn-lg btn-block" type="button" data-dismiss="modal"><i class="fas fa-times-circle"></i> Cancel</button>                                    									
                                    								</div>
                                    							</form>
                                    						</div>
                                    					</div>
                                    				</div>
                                    			</div>
											    <!-- Modal -->
                                    			<div class="modal fade" id="vendor<?= $sno; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                    				<div class="modal-dialog" role="document">
                                    					<div class="modal-content">
                                    						<div class="modal-header bg-info">
                                    							<h5 class="modal-title" id="exampleModalLabel">Edit</h5>
                                    							<button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
                                    								<span aria-hidden="true">&times;</span>
                                    							</button>
                                    						</div>
                                    						<div class="modal-body">
                                    							<form method="post">
                                    								<div class="form-group">
                                    									<label for="vendor_name">Name</label>
                                    									<input type="hidden"  id="vendor_id" name="vendor_id" value="<?= $row['Master_id']; ?>" >
                                    									<input type="text" class="form-control" id="vendor_name" name="vendor_name" value="<?= $row['Master_Name']; ?>" readonly>
                                    								</div>
                                    								<div class="form-group">
                                    									<label for="vendor_email">Email</label>
                                    									<input type="text" class="form-control" id="vendor_email" name="vendor_email" value="<?= $row['Master_Username']; ?>" readonly>
                                    								</div>
                                    								<div class="form-group">
                                    									<label for="vendor_mobile">Mobile Number</label>
                                    									<input type="number" class="form-control" id="vendor_mobile" name="vendor_mobile" value="<?= $row['Master_phone']; ?>" readonly>
                                    								</div>
                                    								<div class="form-group d-flex" style="column-gap:10px;">
                                    									<button class="btn btn-success btn-lg btn-block" type="submit" name="block"><i class="fas fa-check-circle"></i> Block</button>
        																<button class="btn btn-danger btn-lg btn-block" type="button" data-dismiss="modal"><i class="fas fa-times-circle"></i> Cancel</button>                                    									
                                    								</div>
                                    							</form>
                                    						</div>
                                    					</div>
                                    				</div>
                                    			</div>
											    <?php $sno++; } ?>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>




			<?php include('footer.php'); ?>
		</div>
		<!-- End Custom template -->
	</div>
	<!--   Core JS Files   -->
	<style>
	    .badge{
            border-radius: 50px;
            margin-left: auto;
            line-height: 1;
            padding: 6px 10px;
            vertical-align: middle;
            font-weight: 800;
            font-size: 15px;
            border: unset; 
        }
        .btn-block+.btn-block{
            margin-top: unset;
        }
	</style>
	<script src="../assets/js/core/jquery.3.2.1.min.js"></script>
	<script src="../assets/js/core/popper.min.js"></script>
	<script src="../assets/js/core/bootstrap.min.js"></script>
	<!-- jQuery UI -->
	<script src="../assets/js/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
	<script src="../assets/js/plugin/jquery-ui-touch-punch/jquery.ui.touch-punch.min.js"></script>

	<!-- jQuery Scrollbar -->
	<script src="../assets/js/plugin/jquery-scrollbar/jquery.scrollbar.min.js"></script>
	<!-- Datatables -->
	<script src="../assets/js/plugin/datatables/datatables.min.js"></script>
	<!-- Atlantis JS -->
	<script src="../assets/js/atlantis.min.js"></script>
	<!-- Atlantis DEMO methods, don't include it in your project! -->
	<script src="../assets/js/setting-demo2.js"></script>
	<script>
		$(document).ready(function() {
			$('#basic-datatables').DataTable({});
		});
	</script>
</body>

</html>