<div class="container">
	<div class="row">
		<div class="col-lg-12">
			<div class="card" style="background-color:#F1F5FB !important; ">
				<div class="card-header">
					<h3 class="card-title"> <?= $user->name ?> - Deposits </h3>
				</div>

				<?php
				$enc = json_decode($deposits);

				$total = 0;

				foreach ($enc->deposits as $key => $deposit) {
					if ($deposit->status == 1) {
						$total += $deposit->amount;
					}
				}

				$total -= $enc->costs;
				?>

				<div class="card-body" style="padding: 0">

					<div class="row" style="padding: 0">
						<div class="col-lg-4  stretch-card grid-margin">
							<div class="card border20 bg-gradient-warning card-img-holder text-black shadow">
								<div class="card-body">
									<img src="https://admin.work.mali-mart.com/app-assets/images/dashboard/circle.svg" class="card-img-absolute" alt="circle-image">
									<h4 class="font-weight-normal mb-3">Total Deposit Balance
										<i class="fa fa-mouse-pointer  fa-2x float-right"></i>
									</h4>
									<h1> <?= number_format($total, 2) ?> Tk </h1>
								</div>
							</div>
						</div>

						<div class="col-lg-4  stretch-card grid-margin">
							<div class="card border20 bg-gradient-warning card-img-holder text-black shadow">
								<div class="card-body">
									<img src="https://admin.work.mali-mart.com/app-assets/images/dashboard/circle.svg" class="card-img-absolute" alt="circle-image">
									<h4 class="font-weight-normal mb-3">Total Published Jobs
										<i class="fa fa-mouse-pointer  fa-2x float-right"></i>
									</h4>
									<h1> 0 </h1>
								</div>
							</div>
						</div>

						<div class="col-lg-4  stretch-card grid-margin">
							<div class="card border20 bg-gradient-warning card-img-holder text-black shadow">
								<div class="card-body">
									<img src="https://admin.work.mali-mart.com/app-assets/images/dashboard/circle.svg" class="card-img-absolute" alt="circle-image">
									<h4 class="font-weight-normal mb-3">Successful Jobs
										<i class="fa fa-mouse-pointer  fa-2x float-right"></i>
									</h4>
									<h1> 0 </h1>
								</div>
							</div>
						</div>

						<div class="col-lg-4  stretch-card grid-margin">
							<div class="card border20 bg-gradient-warning card-img-holder text-black shadow">
								<div class="card-body">
									<img src="https://admin.work.mali-mart.com/app-assets/images/dashboard/circle.svg" class="card-img-absolute" alt="circle-image">
									<h4 class="font-weight-normal mb-3">Ongoing jobs
										<i class="fa fa-mouse-pointer  fa-2x float-right"></i>
									</h4>
									<h1> 0 </h1>
								</div>
							</div>
						</div>

						<div class="col-lg-12">
							<hr>
						</div>

						<div class="col-lg-12" style="padding: 0">
							<div class="card" style="background-color:#F1F5FB !important; padding: 10px!important;">
								<div class="card-header">
									<h2 class="text-left">New Deposit </h2>

								</div>

								<div class="card-body" style="padding: 0">
									<br>
									<br>
									<div class="msgDiv"></div>
									<form action="https://myadmin.mali-mart.com/api/bid/deposit/<?= $user->id ?>" id="saveDeposit" method="post">
										<div class="row">
											<input type="hidden" name="merchant_id" value="<?= $user->id ?>">
											<input type="hidden" name="merchant_name" value="<?= $user->name ?>">
											<input type="hidden" name="merchant_code" value="<?= $user->own_refer_id ?>">


											<div class="col-lg-3">
												<div class="form-group">
													<label for="">bKash no</label>
													<input type="text" required name="bkash" class="form-control" placeholder="bKash no" />
												</div>
											</div>

											<div class="col-lg-3">
												<div class="form-group">
													<label for="">Trx ID</label>
													<input type="text" required name="trxId" class="form-control" placeholder="trxId" />
												</div>
											</div>
											<div class="col-lg-3">
												<div class="form-group">
													<label for="">Amount</label>
													<input type="text" required name="amount" class="form-control" placeholder="Ex. 5000 " />
												</div>
											</div>

											<div class="col-lg-3">
												<div class="form-group">
													<small style="height: 20px;background: #fff;width: 100%;display: block;"></small>
													<input type="submit" name="asdf" value="Save Deposit" class="btn btn-success" />
												</div>
											</div>
										</div>
									</form>

								</div>
							</div>
						</div>

						<div class="col-lg-6" style="padding: 0">
							<div class="card">
								<div class="card-header">
									<h3>Deposits Summary</h3>
								</div>
								<div class="card-body" style="padding: 0">
									<div class="table-responsive">
										<table class="table table-hover">
											<thead class="bg-warning">
												<tr>
													<th>SL</th>
													<th>bKash</th>
													<th>trxId</th>
													<th>Amount</th>
													<th>Status</th>
													<th>Date</th>
												</tr>
											</thead>

											<tbody>
												<?php
												foreach ($enc->deposits as $key => $deposit) : ?>
													<tr>
														<td><?= ($key + 1) ?></td>
														<td><?= $deposit->bkash ?></td>
														<td><?= $deposit->trxId ?></td>
														<td><?= $deposit->amount ?></td>
														<td><?= $deposit->status == 1 ? ' <p class="bg-success" style="padding: 5px 10px; border-radius: 5px;"> Success </p> ' :
																' <p class="bg-warning" style="padding: 5px 10px; border-radius: 5px;"> Pending. </p>' ?></td>
														<td><?= substr($deposit->created_at, 0, 10) ?></td>
													</tr>
												<?php endforeach;
												?>

											</tbody>
										</table>
									</div>
								</div>

							</div>
						</div>

						<!-- Job Payment summary start -->
						<div class="col-lg-6">
							<div class="card">
								<div class="card-header">
									<h3>Payment Summary</h3>
								</div>
								<div class="card-body" style="padding: 0">
									<div class="table-responsive">
										<table class="table table-hover">
											<thead class="bg-warning">
												<tr>
													<th>SL</th>
													<th>Invoice No</th>
													<th>Job</th>
													<th>Freelancer</th>
													<th>Amount</th>
													<th>Pay with</th>
													<th>Date</th>
												</tr>
											</thead>

											<tbody>
												<?php

												foreach ($enc->payments as $key => $payment) : ?>
													<tr>
														<td><?= ($key + 1) ?></td>
														<td><?= $payment->invoice_no ?></td>
														<td><?= $payment->title ?></td>
														<td><?= $payment->freelancer ?></td>
														<td><?= $payment->amount ?></td>
														<td><?= $payment->payWith ?></td>
														<td><?= $payment->created_at ?></td>

													</tr>
												<?php endforeach;
												?>

											</tbody>
										</table>
									</div>
								</div>

							</div>
						</div>
						<!-- Job Payment summary End -->

					</div>
				</div>
			</div>
		</div>
	</div>
</div>


<div class="container">
	<div class="row">

	</div>
</div>


<script>
	$("#saveDeposit").submit(function(e) {
		e.preventDefault();

		$.ajax({
			method: "post",
			url: $(this).attr('action'),
			data: $(this).serialize(),
			dataType: 'json',
			success: function(res) {
				if (res.status == 1) {

					var msg = '<div class="alert alert-danger fade in alert-dismissible" style="opacity: 1!important;">\n' +
						'    <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>\n' +
						'    <strong>Fake trxId!</strong> You just submitted fake trxId.\n' +
						'</div>';

					$(".msgDiv").append(msg);
				} else {
					location.reload();
				}
				console.log(res);
			}
		});
	});
</script>