<table class="table">
	<thead>
		<tr>
			<th scope="col">ID</th>
			<th scope="col">Image</th>
			<th scope="col">Name</th>
			<th scope="col" style="text-align: right;">Quantity</th><th scope="col" style="text-align: right;">Price</th>
			<th scope="col" style="text-align: right;">Dis%</th>
			<th scope="col" style="text-align: right;">Amount</th>
			<th scope="col" style="text-align: right;">X</th>
		</tr>
	</thead>
	<tbody style="padding: 0px;">
		<?php
		session_start();
		require_once 'db_connection.php'; 
		$user_id = $_SESSION['user_id'];
		$total_amount = 0; 

		$sql = "SELECT SUM(pro_qty) AS pro_qty , pro_dis,pro_price,proid,proname,cover  FROM mobiletemporarycart LEFT JOIN mobileproducts ON mobileproducts.prid=mobiletemporarycart.proid
		WHERE mobiletemporarycart.user_id='$user_id' AND mobiletemporarycart.orderid=0 GROUP BY  mobiletemporarycart.proid,mobiletemporarycart.pro_dis   ORDER BY mobiletemporarycart.tempid  DESC";

		$result = $conn->query($sql);
		$rowCount = 0;
		if ($result->num_rows > 0) {
			while($row = $result->fetch_assoc()) {
				$rowCount = $rowCount+1;
				$proid = $row["proid"];
				$proname = $row["proname"];
				$cover = $row["cover"];
				$pro_dis = $row["pro_dis"];
				$pro_price = $row["pro_price"];
				$pro_qty = $row["pro_qty"];

				$discounted_price = ($pro_price/100) * $pro_dis;
				$product_price2 = ($pro_price - $discounted_price)*$pro_qty;

				$total_amount = $total_amount + $product_price2;
				?>

				<tr>
					<th scope="row"><?php echo $rowCount; ?></th>
					<td><img width="30px" src="images/products/cover/<?php echo $cover; ?>" alt="img"></td>
					<td><?php echo $proname; ?></td>
					<td style="text-align: right;"><?php echo $pro_qty; ?></td>
					<td style="text-align: right;"><?php echo number_format((float)$pro_price,2); ?></td>
					<td style="text-align: right;"><?php echo $pro_dis; ?>%</td>
					<td style="text-align: right;"><?php echo number_format((float)$product_price2,2); ?></td>
					<td style="text-align: right;">
						<a class="confirm-text" href="javascript:void(0);"><img src="assets/img/icons/delete-2.svg" alt="img" onclick="deleteCartItem(<?php echo $proid; ?>,<?php echo $pro_dis; ?>);"></a>
					</td>
				</tr>
				<?php
			}
		}else{
			echo "Not found items..";
		}
		?>
	</tbody>
	<tfoot style="background:#198754;">
		<tr>
			<td colspan="6" style="font-weight:bold;text-align:left;font-size: 18px;color:#ffffff;">Sub Total </td>
			<td style="font-weight:bold;text-align:right;font-size: 18px;color:#ffffff;"><?php echo number_format((float)$total_amount,2); ?></td>
			<td colspan=""> </td>
		</tr>
	</tfoot>
</table>
<div class="row">
	<div class="col-md-12" style="display: none;"><span id="totalcost"><?php echo number_format((float)$total_amount,2); ?></span></div>
	<div class="col-md-12" style="text-align: right;padding-right: 90px; font-weight: bold;font-size: 22px;"><span id="totalwithdelicost"></span></div>
</div>

<div id="total_amount_view" style="display: none;"><?php echo $total_amount; ?></div>
<div class="row mt-3">

<div class="col-md-6">

		<a href="addcustomer.php" class="btn btn-block btn-outline-info active btn-md text-white" title="Add New Customer" onClick="JavaScript:return confirm('Are your sure change this add new customer ?');" target="_blank" style="font-weight:bold;margin-top:22px;width:100%;"><i class="fa fa-check-circle" data-bs-toggle="tooltip" title="" data-bs-original-title="fa fa-check-circle" aria-label="fa fa-check-circle"></i> Add Customer</a>				
		<br>
		
		<label style="font-weight:bold;color:#000000;">Select Customer</label>
		<select class="form-select" id="cusSelect2" onchange="setCustomerStatus(this.value);">
			<option value="0">Walk-in Customer</option>
			<option value="dc">Delivery Customer</option>
			<?php
			$cus2 = "SELECT * FROM mobilecustomers WHERE status=1";
			$result = $conn->query($cus2);
			if ($result->num_rows > 0) {
				while($row = $result->fetch_assoc()) {
					$coid = $row["coid"];
					echo $cname = $row["cname"];
					$cphone = $row["cphone"];
					echo '<option value="'.$coid.'">'.$cname.' | '.$cphone.'</option>';
				}
			}
			$conn->close();
			?>
		</select>

		<div class="col-md-12 mt-4 mb-5">
			<a href="javascript:void(0);" class="paymentmethod2" id="cash" onclick="selectPaymentOption('cash');" style="background:#0dcaf0;color:#ffffff;">
				<i class="fa fa-money-check-alt" data-bs-toggle="tooltip" title="" data-bs-original-title="fa fa-money-check-alt" aria-label="fa fa-money-check-alt" class="me-2" style="font-weight:bold;font-size:14px;"></i>
				Cash
			</a>
			<a href="javascript:void(0);" class="paymentmethod2" id="debit"  onclick="selectPaymentOption('debit');" style="background:#0dcaf0;color:#ffffff;">
				<i class="fa fa-credit-card" data-bs-toggle="tooltip" title="" data-bs-original-title="fa fa-credit-card" aria-label="fa fa-credit-card" class="me-2" style="font-weight:bold;font-size:14px;"></i>
				Debit
			</a>
			<a href="javascript:void(0);" class="paymentmethod2" id="credit"  onclick="selectPaymentOption('credit');" style="background:#0dcaf0;color:#ffffff;">
				<i class="fa fa-wallet" data-bs-toggle="tooltip" title="" data-bs-original-title="fa fa-wallet" aria-label="fa fa-wallet" class="me-2" style="font-weight:bold;font-size:14px;"></i>
				Credit
			</a>
			<div class="row mt-5" id="paytypeview" style="display: none;">cash</div>
		</div>
	<div class="mt-2" id="locationViewDiv" style="display: none;">
	<select class="form-select" id="shipping">
			<option value="free">Free Shipping</option>
		</select>
		</select>
		<div id="countryLoad">
			<select class="form-select" id="country">
			<option value="0">Select Country</option>
		</select>
		</div>
		<div id="cityLoad" class="mt-2">
			<select class="form-select" id="city">
			<option value="0">Select Country</option>
		</select>
		</div>
	</div>

	</div>
	<div class="col-md-6">
	<br>
<b style="font-weight:bold;color:#000000;">Delivery Cost</b>
<div id="deliveryCostview" style="font-size: 20px;background: black; color: #23ff23; text-align: center;padding: 5px 0px;font-weight: 600; margin-top: 1px;">0</div>

		<label style="font-weight:bold;color:#000000;">Cash Amount</label>
		<input type="number" class="form-control" id="cashamount" placeholder="Cash Amount" oninput="calBalance();">

		<div id="carddiv" style="display: none;">
		<label class="mt-1" style="font-weight:bold;color:#000000;">Card Number</label>
		<input type="text" class="form-control" id="cardno" placeholder="Card Number">
	</div>

<div id="chequediv" style="display: none;">
		<label class="mt-1" style="font-weight:bold;color:#000000;">Cheque Number</label>
		<input type="text" class="form-control" id="cheque" placeholder="Cheque Number">

		<label class="mt-1" style="font-weight:bold;color:#000000;">Due Date</label>
		<input type="date" class="form-control" id="duedate" placeholder="Due Date">
</div>

<div id="balanceview" style="font-size: 22px;background: black; color: #23ff23; text-align: center;padding: 5px 0px;font-weight:bold; margin-top: 1px;margin-bottom: 1px"></div>
		<button type="button" class="btn btn-success mt-2" style="width: 100%;" onclick="saveBill();" style="font-weight:bold;text-align:right;font-size: 18px;color:#ffffff;"><i class="fa fa-print" data-bs-toggle="tooltip" title="" data-bs-original-title="fa fa-print" aria-label="fa fa-print" style="font-weight:bold;font-size:18px;"></i> Make Bill</button>
	</div>
</div>


<div class="row">

</div>


<style type="text/css">
	.paymentmethod2{
		width: 32%;
		border: 1px solid #edf;
		border-radius: 5px;
		padding: 20px;
		margin: 2px;
	}

	.paymentmethod2:hover{
   background-color:#e3e3e3;
}
</style>



