<?php
session_start();
include 'include/db.php';
include 'include/constant.php';
include 'include/functions.php';
include 'get_user_info.php';
/*
Handle all ajax request
*/

//  Admin payout manage
if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'admin_payout_manage') {
?>
	<thead>
		<tr>
			<th> </th>
			<th> Transaction id </th>
			<th> User Id </th>
			<th>Amount</th>
			<th> Fees amount </th>
			<th>Payout type</th>
			<th> Accept status </th>
			<th> Bank Details </th>
			<th> Declined message </th>
			<th>Payout request date</th>
			<th>Accept/Decline date</th>
		</tr>
	</thead>
	<tbody>
		<?php
		$qry = "select * from payout inner join payout_details on payout.payout_id=payout_details.payout_details_type 
		LEFT JOIN  bank_details BD ON BD.user_unique_id = payout_details.payout_user_id  WHERE 1=1 ";
		if (isset($_REQUEST['status']) && $_REQUEST['status'] != '') {
			$qry .= " AND payout_accept_status = '" . (int)$_REQUEST['status'] . "' ";
		}
		$qry .= " ORDER BY payout_details_id DESC";
		$connection1 = mysqli_query($conn, $qry);
		if (mysqli_num_rows($connection1) > 0) {
			$count = 1;
			while ($rows = mysqli_fetch_array($connection1)) {
		?>
				<tr>
					<td><?php //echo $count++;
						?> <input type="checkbox" class="payout_user" value="<?php echo isset($rows['payout_details_id']) ? $rows['payout_details_id'] : '' ?>" <?php echo $rows['payout_accept_status'] != 2 ? 'disabled readonly' : '' ?>></td>
					<td> <?php echo $rows['payout_transaction_id']; ?> </td>
					<td> <?php echo $rows['payout_user_id']; ?> </td>
					<td><?php echo $rows['payout_amount'] ?></td>
					<td><?php echo $rows['fee_amount'] ?></td>
					<td><?php echo $rows['payout_type']; ?></td>
					<td>
						<?php
						if ($rows['payout_accept_status'] == 2) {
							echo '<span style="background-color:yellow"> Pending  </span>';
						} else if ($rows['payout_accept_status'] == 1) {
							echo '<span style="color:green"> Successfully </span>';
						} else if ($rows['payout_accept_status'] == 3) {
							echo '<span style="color:red"> Declined </span>';
						}

						?>
					</td>
					<td style="min-width: 120px">
						<b> A/C </b> - <?php echo isset($rows['ac']) && $rows['ac'] != '' ? $rows['ac'] : 'N/A' ?> <br>
						<b> Aadhaar - </b><?php echo isset($rows['adhar']) && $rows['adhar'] != '' ? $rows['adhar'] : 'N/A' ?> <br>
						<b> Pancard - </b><?php echo isset($rows['pan']) && $rows['pan'] != '' ? $rows['pan'] : 'N/A' ?> <br>
						<b> IFSC - </b> <?php echo isset($rows['ifsc']) && $rows['ifsc'] != '' ? $rows['ifsc'] : 'N/A' ?> <br>
						<b> A/C Holder - </b> <?php echo isset($rows['holder_name']) && $rows['holder_name'] != '' ? $rows['holder_name'] : 'N/A' ?> <br>
						<b>Nominee - </b><?php echo isset($rows['nominee']) && $rows['nominee'] != '' ? $rows['nominee'] : 'N/A' ?>
					</td>
					<td><textarea rows="4"><?php echo $rows['payout_decline_msg']; ?></textarea></td>
					<td>
						<?php
						$date = explode(' ', $rows['payout_request_date']);
						echo $date['0'] . ' &nbsp' . $date['1'];
						?>
					</td>
					<td>
						<?php
						$date = explode(' ', $rows['payout_accept_date']);
						if ($rows['payout_accept_date'] != '') {
							echo $date['0'] . ' &nbsp' . $date['1'];
						} else {
							echo '0000-00-00 &nbsp 00:00:00';
						}
						?>
					</td>

				</tr>
		<?php
			}
		}
		echo '</tbody>';
	}


	//  admin payout declined
	if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'admin_decline_payout') {
		$return = '';
		$sql = "SELECT payout_user_id, payout_amount, fee_amount FROM  payout_details WHERE payout_details_id = '" . $_REQUEST['payout_id'] . "'";
		$con = mysqli_query($conn, $sql);
		if (mysqli_num_rows($con) > 0) {
			$row = mysqli_fetch_assoc($con);
			$total_amount = $row['payout_amount'] + $row['fee_amount'];

			$upd = "UPDATE payout_details SET payout_accept_status = '3',payout_decline_msg = '" . trim($_REQUEST['declined_msg']) . "',payout_accept_date = '$today_date' WHERE payout_details_id = '" . $_REQUEST['payout_id'] . "' ";
			mysqli_query($conn, $upd);

			/*  Admin return payout amount to user  */
			wallet($wallet = array('sender_id' => ADMIN_ID, 'receiver_id' =>  $row['payout_user_id'], 'amount' => $total_amount));

			$wallet_arr = array(
				'sender_id'			=>	ADMIN_ID,
				'receiver_id'		=>	$row['payout_user_id'],
				'amount'			=>	$total_amount,
				'respective_user'	=>	null,
				'transaction_type'	=>	3,  //  Purchase product
				'remarks'			=>  'Payout refund money due to payout declined',
				'status'			=>	1,
				'transaction_id'	=>  get_unique_id('t')
			);
			add_wallet_history($wallet_arr);
			$return = 1;
		}
		echo $return;
	}

	// Payout accept
	if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'admin_accept_payout') {
		$payout_ids = isset($_REQUEST['payout_ids']) && !empty($_REQUEST['payout_ids']) ? $_REQUEST['payout_ids'] : null;
		$return = '';

		if ($payout_ids != null) {
			$payout_concat_ids = "'" . implode("','", $payout_ids) . "'";
			$upd = "UPDATE payout_details SET payout_accept_status = '1', payout_accept_date = '$today_date' WHERE payout_details_id IN ($payout_concat_ids) ";
			mysqli_query($conn, $upd);
			$return = 1;
		}
		echo $return;
	}



	//  Admin KYC manage
	if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'admin_kyc_manage') {
		?>
		<thead>
			<tr>
				<th> Sr. </th>
				<th> User Id </th>
				<th> User Informations </th>
				<th> Bank Details </th>
				<th>Action</th>
			</tr>
		</thead>
	<tbody>
		<?php
		$qry = "select * FROM registration AS R LEFT JOIN  bank_details AS B ON B.user_unique_id = R.unique_user_id WHERE R.unique_user_id != '" . ADMIN_ID . "' ";
		if (isset($_REQUEST['status']) && $_REQUEST['status'] != '') {
			$qry .= " AND R.is_kyc_accepted = '" . (int)$_REQUEST['status'] . "' ";
		}
		//$qry.=" ORDER BY payout_details_id DESC";
		$connection1 = mysqli_query($conn, $qry);
		if (mysqli_num_rows($connection1) > 0) {
			$count = 1;
			while ($rows = mysqli_fetch_array($connection1)) {
		?>
				<tr>
					<td><?php echo $count++; ?> </td>
					<td> <?php echo $rows['unique_user_id']; ?> </td>
					<td>
						<?php echo isset($rows['user_name']) && $rows['user_name'] != '' ? 'Name - ' . $rows['user_name'] . '<br>' : ''; ?>
						Address - <?php echo $rows['user_address'] ?> <br>
						Email - <?php echo isset($rows['user_email']) && $rows['user_email'] != '' ? $rows['user_email'] : 'N/A' ?> <br>
						Mobile - <?php echo isset($rows['user_mobile']) && $rows['user_mobile'] != '' ? $rows['user_mobile'] : 'N/A'; ?> <br>
						Purchase status -
						<?php
						if ($rows['active_deactive'] == 1) {
							echo '<span style="color:green"> Active </span>';
						} else {
							echo '<span style="color:red"> Deactive </span>';
						}

						?>
					</td>
					<td style="min-width: 120px">
						<b> A/C </b> - <?php echo isset($rows['ac']) && $rows['ac'] != '' ? $rows['ac'] : 'N/A' ?> <br>
						<b> Aadhaar - </b><?php echo isset($rows['adhar']) && $rows['adhar'] != '' ? $rows['adhar'] : 'N/A' ?> <br>
						<b> Pancard - </b><?php echo isset($rows['pan']) && $rows['pan'] != '' ? $rows['pan'] : 'N/A' ?> <br>
						<b> IFSC - </b> <?php echo isset($rows['ifsc']) && $rows['ifsc'] != '' ? $rows['ifsc'] : 'N/A' ?> <br>
						<b> A/C Holder - </b> <?php echo isset($rows['holder_name']) && $rows['holder_name'] != '' ? $rows['holder_name'] : 'N/A' ?> <br>
						<b>Nominee - </b><?php echo isset($rows['nominee']) && $rows['nominee'] != '' ? $rows['nominee'] : 'N/A' ?>
					</td>
					<td>
						<?php
						if (isset($rows['is_kyc_accepted']) && $rows['is_kyc_accepted'] == 1) {
							echo '<button class="btn btn-success"> KYC Accepted </button>';
						} else {
							echo '<button class="btn btn-primary accept_kyc" data-id="' . $rows['unique_user_id'] . '"> Accept KYC </button>';
						}
						?>
					</td>

				</tr>
		<?php
			}
		}
		echo '</tbody>';
	}


	//  KYC accept
	if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'admin_accept_kyc') {
		$user_id = isset($_REQUEST['user_id']) && !empty($_REQUEST['user_id']) ? $_REQUEST['user_id'] : null;
		$return = '';

		if ($user_id != null) {
			$upd = "UPDATE registration SET is_kyc_accepted = '1' WHERE unique_user_id ='$user_id' ";
			mysqli_query($conn, $upd);
			$return = 1;
		}
		echo $return;
	}


	//  Product dispat manage
	if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'product_dispatch_manage') {
		?>
		<thead>
			<tr>
				<?php
				if (isset($got_unique_id) && strtoupper($got_unique_id) == ADMIN_ID) {
					echo '<th> </th>';
				}
				?>
				<th> User Id </th>
				<th> Name </th>
				<th>Product</th>
				<th> Total Amount </th>
				<th>Purchase type</th>
				<th> Mailing Address </th>
				<th> Remarks </th>
				<th> Purchase Date </th>
				<th> Dispatch Date </th>
			</tr>
		</thead>
	<tbody>
		<?php
		$qry = "SELECT PP.*,R.user_name, P.product_name  FROM product_purchase AS PP 
		 LEFT JOIN registration AS R ON R.unique_user_id = PP.purchase_user_id
		 LEFT JOIN product AS P ON P.product_id = PP.purchase_product_id WHERE 1=1 ";
		if (isset($_REQUEST['status']) && $_REQUEST['status'] != '') {
			$qry .= " AND PP.status = '" . $_REQUEST['status'] . "' ";
		}
		if (isset($got_unique_id) && strtoupper($got_unique_id) != ADMIN_ID) {
			$qry .= " AND LOWER(PP.purchase_user_id) = '" . strtoupper($got_unique_id) . "' ";
		}
		$qry .= " GROUP BY(purchase_id) ORDER BY purchase_date DESC";

		$connection1 = mysqli_query($conn, $qry);

		if (mysqli_num_rows($connection1) > 0) {
			$count = 1;
			while ($rows = mysqli_fetch_array($connection1)) {
				$mailing_address = json_decode($rows['mailing_address'], true)

		?>
				<tr>
					<?php
					if (isset($got_unique_id) && strtoupper($got_unique_id) == ADMIN_ID) {
					?>
						<td><?php //echo $count++;
							?> <input type="checkbox" class="purchase-id" value="<?php echo isset($rows['purchase_id']) ? $rows['purchase_id'] : '' ?>" <?php echo $rows['status'] != 2 ? 'disabled readonly' : '' ?>></td>
					<?php
					}
					?>

					<td> <?php echo $rows['purchase_user_id']; ?> </td>
					<td> <?php echo $rows['user_name']; ?> </td>
					<td> <?php echo $rows['product_name']; ?> </td>
					<td><?php echo $rows['purchase_product_price'] + $rows['tax_amount'] ?></td>
					<td><?php echo isset($mailing_address['purchase_by']) ? $mailing_address['purchase_by'] : '' ?></td>
					<td style="min-width: 150px">
						<b> Name </b> - <?php echo isset($mailing_address['name']) && $mailing_address['name'] != '' ? $mailing_address['name'] : 'N/A' ?> <br>
						<b> C/O - </b><?php echo isset($mailing_address['co']) && $mailing_address['co'] != '' ? $mailing_address['co'] : 'N/A' ?> <br>
						<b> Address - </b><?php echo isset($mailing_address['address']) && $mailing_address['address'] != '' ? $mailing_address['address'] : 'N/A' ?> <br>
						<b> Landmark - </b><?php echo isset($mailing_address['m_landmark']) && $mailing_address['m_landmark'] != '' ? $mailing_address['m_landmark'] : 'N/A' ?> <br>
						<b> Pincode - </b> <?php echo isset($mailing_address['pincode']) && $mailing_address['pincode'] != '' ? $mailing_address['pincode'] : 'N/A' ?> <br>
						<b>Phone - </b> <?php echo isset($mailing_address['mobile']) && $mailing_address['mobile'] != '' ? $mailing_address['mobile'] : 'N/A' ?> <br>
					</td>
					<td><textarea rows="5"><?php echo isset($mailing_address['remarks']) && $mailing_address['remarks'] != '' ? $mailing_address['remarks'] : '' ?></textarea> </td>
					<td> <?php echo $rows['purchase_date']; ?> </td>
					<td> <?php echo $rows['dispatch_date']; ?> </td>
				</tr>
		<?php
			}
		}
		echo '</tbody>';
	}


	// product dispatch
	if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'product_purchase_dispatched') {
		$purchase_ids = isset($_REQUEST['purchase_ids']) && !empty($_REQUEST['purchase_ids']) ? $_REQUEST['purchase_ids'] : null;
		$return = '';

		if ($purchase_ids != null) {
			$purchase_concat_ids = "'" . implode("','", $purchase_ids) . "'";
			$upd = "UPDATE  product_purchase SET status = '1', dispatch_date = '$today_date' WHERE purchase_id IN ($purchase_concat_ids) ";
			mysqli_query($conn, $upd);
			$return = 1;
		}
		echo $return;
	}

	// User affiliate submit
	if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'user_affiliate_submit') {
		if (isset($_SESSION['affiliate_security']) && $_SESSION['affiliate_security'] == $_REQUEST['affiliate_security'] && isset($got_unique_id) && $got_unique_id != '') {
			$product_name = isset($_REQUEST['product_name']) ? mysqli_real_escape_string($conn, ucfirst(trim($_REQUEST['product_name']))) : '';
			$product_order_id = isset($_REQUEST['product_order_id']) ? mysqli_real_escape_string($conn, trim($_REQUEST['product_order_id'])) : '';

			$sql = "INSERT INTO affiliate(user_id, product_name, order_id) VALUES('$got_unique_id', '$product_name', '$product_order_id')";
			$con = mysqli_query($conn, $sql);
			if ($con) {
				echo 1;
			} else {
				echo 2;
			}
		} else {
			echo 2;
		}
	}


	//  Admin payout manage
	if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'affiliate_hostory') {
		?>
		<thead>
			<tr>
				<th> Sr.no</th>
				<?php
				if (strtoupper($got_unique_id) == ADMIN_ID) {
					echo '<th> User Id </th>';
				}
				?>
				<th> Affiliate Product Name </th>
				<th> Affiliate Product Order Id </th>
				<th>Status</th>
				<th>Remarks</th>
				<th>Last Update</th>
				<?php
				if (strtoupper($got_unique_id) == ADMIN_ID) {
					echo '<th> Action </th>';
				}
				?>
			</tr>
		</thead>
	<tbody>
		<?php
		$qry = "select * from affiliate WHERE 1=1 ";
		if (isset($_REQUEST['status']) && $_REQUEST['status'] != '') {
			$qry .= " AND status = '" . (int)$_REQUEST['status'] . "' ";
		}
		if (isset($got_unique_id) && strtoupper($got_unique_id) != ADMIN_ID) {
			$qry .= " AND LOWER(user_id) = '" . strtolower($got_unique_id) . "' ";
		}
		$qry .= " ORDER BY last_update DESC";
		$connection1 = mysqli_query($conn, $qry);
		if (mysqli_num_rows($connection1) > 0) {
			$count = 1;
			while ($rows = mysqli_fetch_array($connection1)) {
		?>
				<tr>
					<td>
						<?php echo $count++; ?>
						<?php if (isset($got_unique_id) && strtoupper($got_unique_id) == ADMIN_ID) : ?>
							<input type="checkbox" class="affiliate-checkbox" value="<?php echo isset($rows['id']) ? $rows['id'] : '' ?>" <?php echo $rows['status'] != 2 ? 'disabled readonly' : '' ?>>
						<?php endif; ?>
					</td>
					<?php
					if (strtoupper($got_unique_id) == ADMIN_ID) {
						echo '<td>' . $rows["user_id"] . '</td>';
					}
					?>
					<td> <?php echo ucfirst(strtolower($rows['product_name'])); ?> </td>
					<td><?php echo $rows['order_id'] ?></td>
					<td>
						<?php
						if ($rows['status'] == 2) {
							echo '<span style="background-color:yellow"> Pending  </span>';
						} else if ($rows['status'] == 1) {
							echo '<span style="color:green"> Successfully </span>';
						} else if ($rows['status'] == 3) {
							echo '<span style="color:red"> Declined </span>';
						}
						?>
					</td>
					<td><textarea rows="3"><?php echo $rows['remarks'] ?></textarea></td>
					<td><?php echo $rows['last_update']; ?></td>
					<?php
					if (strtoupper($got_unique_id) == ADMIN_ID) {
						echo '<td>';
						if ($rows['status'] == 1) {
							echo '<button class="btn btn-success">  Paid & Accepted </button>';
						} else if ($rows['status'] == 3) {
							echo '<button class="btn btn-danger">  Declined </button>';
						} else {
							echo '<a href="money_send.php?id=' . $rows['user_id'] . '&affiliate=' . $rows['id'] . '  "><button class="btn btn-primary">  Pay & Accept </button></a>';
						}
						echo '</td>';
					?>
					<?php
					}
					?>

				</tr>
		<?php
			}
		}
		echo '</tbody>';
	}


	//  Admin affiliate income
	if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'affiliate_income_hostory') {
		?>
		<thead>
			<tr>
				<th> Sr.no</th>
				<th> Transfer to/by </th>
				<th> Affiliate Product Name </th>
				<th> Affiliate Product Order Id </th>
				<th>Amount</th>
				<th>Credit/Debit</th>
				<th>Remarks</th>
				<th>Date</th>
			</tr>
		</thead>
	<tbody>
		<?php
		$qry = "SELECT * FROM wallet_new AS W 
		INNER JOIN affiliate AS A ON W.affiliate_id = A.id  
		WHERE (affiliate_id != 0 || affiliate_id IS NOT NULL) AND (LOWER(W.sender_id) = '" . strtolower($got_unique_id) . "' || LOWER(W.receiver_id) = '" . strtolower($got_unique_id) . "' ) ";
		$qry .= " ORDER BY W.id DESC ";
		$connection1 = mysqli_query($conn, $qry);
		if (mysqli_num_rows($connection1) > 0) {
			$count = 1;
			$arr = array();
			while ($rows = mysqli_fetch_assoc($connection1)) {
		?>
				<tr>
					<td>
						<?php echo $count++; ?>
					</td>
					<td>
						<?php
						if (strtolower($rows['receiver_id']) == strtolower($got_unique_id))
							echo strtoupper($rows['sender_id']) == ADMIN_ID ? 'Admin' : $rows['sender_id'];
						else
							echo strtoupper($rows['receiver_id']) == ADMIN_ID ? 'Admin' : $rows['receiver_id'];
						?>
					</td>
					<td> <?php echo $rows['product_name']; ?> </td>
					<td><?php echo $rows['order_id'] ?></td>
					<td><?php echo isset($rows['amount']) && $rows['amount'] != '' ? 'Rs.' . $rows['amount'] : 'Rs. 0' ?></td>
					<td>
						<?php
						if (strtolower($rows['receiver_id']) == strtolower($got_unique_id))
							echo "<span style='color:green;font-weight:bolder'> Credited </span>";
						else
							echo "<span style='color:red;font-weight:bolder'> Debited </span>";
						?>
					</td>
					<td><textarea rows="3"><?php echo $rows['remarks'] ?></textarea></td>
					<td><?php echo $rows['transaction_date']; ?></td>

				</tr>
		<?php
			}
		}
		echo '</tbody>';
	}


	//  admin affiliate declined
	if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'admin_decline_affiliate') {
		$upd = "UPDATE affiliate SET status = '3',remarks = '" . trim($_REQUEST['declined_msg']) . "',last_update = '$today_date' WHERE id = '" . $_REQUEST['affiliate_id'] . "' ";
		$con = mysqli_query($conn, $upd);
		if ($con) {
			echo 1;
		}
	}



	//  Rewards report
	if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'rewards_report') {
		?>
		<thead>
			<tr>
				<th> Sr.no </th>
				<?php
				if (strtolower($got_unique_id) == strtolower(ADMIN_ID)) :
				?>
					<th> User Id </th>
				<?php endif; ?>
				<th>Reward</th>
				<th>Date</th>
			</tr>
		</thead>
	<tbody>
		<?php
		// reward_type = 4  -- special tree structure reward bonus
		$qr1 = "SELECT  * from rewards WHERE reward_type = 3 || reward_type = 4 ";
		if (strtolower($got_unique_id) != strtolower(ADMIN_ID)) {
			$qr1 .= " AND LOWER(user_id) = '" . strtolower($got_unique_id) . "' ";
		}
		if (isset($_REQUEST['from_date']) && $_REQUEST['from_date'] != '') {
			$qr1 .= " AND DATE(reward_date) >= '" . $_REQUEST['from_date'] . "' ";
		}
		if (isset($_REQUEST['to_date']) && $_REQUEST['to_date'] != '') {
			$qr1 .= " AND DATE(reward_date) <= '" . $_REQUEST['to_date'] . "' ";
		}
		if (isset($_REQUEST['status']) && $_REQUEST['status'] != '') {
			$qr1 .= " AND reward = '" . (int)$_REQUEST['status'] . "' ";
		}
		$qr1 .= " ORDER BY id DESC";

		$con1 = mysqli_query($conn, $qr1);
		if (mysqli_num_rows($con1) > 0) {
			$count = 1;
			while ($ro = mysqli_fetch_array($con1)) {
		?>
				<tr>
					<td> <?php echo $count++; ?> </td>
					<?php
					if (strtolower($got_unique_id) == strtolower(ADMIN_ID)) {
					?>
						<td> <?php echo $ro['user_id']; ?></td>
					<?php
					}
					?>
					<td>
						<textarea rows="4"><?php echo $ro['reward_desc']; ?></textarea>
					</td>
					<td> <?php echo isset($ro['reward_date']) && $ro['reward_date'] != '' ? date('d-m-Y H:i:s', strtotime($ro['reward_date'])) : "null"; ?> </td>
			<?php

			}
		}
			?>
	</tbody>

<?php
	}
	// Wallet report
	if (isset($_REQUEST['resource']) && $_REQUEST['resource'] == 'wallet_report') {
		if(!isset($_REQUEST['id'])){
?>
	<thead>
		<tr>
			<th>Sr.no</th>
			<!--<th> Transaction id </th>-->
			<th>Transaction Type</th>
			<th>Amount(Rs.)</th>
			<th>Transfer by/to</th>
			<th>Date</th>
			<th> Debit/Credit </th>

		</tr>
	</thead>
	<tbody>
		<?php
		}
		$wallet_query = "select * from wallet_new  where (LOWER(sender_id) ='" . strtolower(trim($got_unique_id)) . "' || receiver_id = '" . strtolower(trim($got_unique_id)) . "') AND transaction_type != 5 ";
		if (isset($_REQUEST['from_date']) && $_REQUEST['from_date'] != '') {
			$wallet_query .= " AND DATE(transaction_date) >= '" . $_REQUEST['from_date'] . "' ";
		}
		if (isset($_REQUEST['to_date']) && $_REQUEST['to_date'] != '') {
			$wallet_query .= " AND DATE(transaction_date) <= '" . $_REQUEST['to_date'] . "' ";
		}
		if (isset($_REQUEST['id']) ) {
			$wallet_query .= " AND id = '" . $_REQUEST['id'] . "' ";
		}
		$wallet_query .= " ORDER BY id DESC";
		$wallet_res = mysqli_query($conn, $wallet_query);
		$count_wallet = mysqli_num_rows($wallet_res);
		if ($count_wallet > 0) {
			$count = 1;
			while ($rows = mysqli_fetch_array($wallet_res)) {
				if(!isset($_REQUEST['id'])){
		?>
				<tr>
					<td>
						<?php echo $count++; ?>
						<a href="javascript:void(0)" data-toggle="modal" id="wallet<?php echo $rows['id']; ?>" class="wallet_class"  data-target="#wallet_details<?php echo $count ?>"> <i class="fa fa-eye" aria-hidden="true"></i> </a>
					</td>
					<!--<td><?php echo $rows['transaction_id']; ?></td>-->
					<td> <?php
							if ($rows['transaction_type'] == 1) {
								echo "Wallet Transfer";
							} else if ($rows['transaction_type'] == 2) {
								echo "Product purchase";
							} else if ($rows['transaction_type'] == 3) {
								echo "Payout Request";
							} else if ($rows['transaction_type'] == 4) {
								echo "Purchasing commission";
							}
							?>
					</td>
					<td><?php echo $rows['amount']; ?></td>
					<td>
						<?php
						if (strtolower($rows['receiver_id']) == strtolower($got_unique_id))
							echo strtoupper($rows['sender_id']) == ADMIN_ID ? 'Admin' : $rows['sender_id'];
						else
							echo strtoupper($rows['receiver_id']) == ADMIN_ID ? 'Admin' : $rows['receiver_id'];
						?>
					</td>
					<td>
						<?php
						$date = explode(' ', $rows['transaction_date']);
						echo $date['0'];
						?>
					</td>
					<td>
						<?php
						if (strtolower($rows['receiver_id']) == strtolower($got_unique_id))
							echo "<span style='color:green;font-weight:bolder'> Credited </span>";
						else
							echo "<span style='color:red;font-weight:bolder'> Debited </span>";
						?>
					</td>
				</tr>
				<!-----  show some details  ---->
				<?php
				}
				if (isset($_REQUEST['id']) && $_REQUEST['id'] != '') {
				?>
					<!----append modal content to the transaction modal detail----->
							<div class="row">
								<div class="col-sm-3 col-md-offset-2">
									Transfer by/to -
								</div>
								<div class="col-sm-7">
									<?php
									if (strtolower($rows['receiver_id']) == strtolower($got_unique_id))
										echo $rows['sender_id'] == ADMIN_ID ? 'Admin [' . $rows['sender_id'] . ']' : $rows['sender_id'];
									else
										echo $rows['receiver_id'] == ADMIN_ID ? 'Admin [' . $rows['receiver_id'] . ']' : $rows['receiver_id'];
									?>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3 col-md-offset-2">
									Transaction Type -
								</div>
								<div class="col-sm-7">
									<?php
									if ($rows['transaction_type'] == 1) {
										echo "Wallet Transfer";
									} else if ($rows['transaction_type'] == 2) {
										echo "Product purchase";
									} else if ($rows['transaction_type'] == 3) {
										echo "Payout Request";
									} else if ($rows['transaction_type'] == 4) {
										echo "Purchasing commission";
									}
									?>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3 col-md-offset-2">
									Transaction id -
								</div>
								<div class="col-sm-7">
									<?php echo $rows['transaction_id']; ?>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3 col-md-offset-2">
									Amount -
								</div>
								<div class="col-sm-7">
									<?php echo 'Rs. ' . $rows['amount']; ?>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3 col-md-offset-2">
									Debit/Credit -
								</div>
								<div class="col-sm-7">
									<?php
									if (strtolower($rows['receiver_id']) == strtolower($got_unique_id))
										echo "<span style='color:green;font-weight:bolder'> Credited </span>";
									else
										echo "<span style='color:red;font-weight:bolder'> Debited </span>";
									?>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3 col-md-offset-2">
									Date -
								</div>
								<div class="col-sm-7">
									<?php
									$date = explode(' ', $rows['transaction_date']);
									echo $date['0'] . ' ' . $date['1'];
									?>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3 col-md-offset-2">
									Status -
								</div>
								<div class="col-sm-7">
									<?php
									if (isset($rows['status'])) {
										if ($rows['status'] == 1)
											echo "<span style='color:green;font-weight:bolder'> Successful</span>";
										else if ($rows['status'] == 2)
											echo "<span style='color:orange;font-weight:bolder'> Pending</span>";
										else
											echo "<span style='color:red;font-weight:bolder'> Failed</span>";
									}
									?>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-3 col-md-offset-2">
									Note -
								</div>
								<div class="col-sm-7">
									<?php
									echo $rows['remarks'];
									?>
								</div>
								</div>
					<!----append modal content to the transaction modal detail----->
				<?php
				}
				?>


		<?php
			}
		}
		?>
	</tbody>

<?php
	}
?>