<?php

$total = 0;
$allJobs = null;
if ($jobs) {
	$allJobs = json_decode($jobs);
	foreach ($allJobs as $key => $earn) {
		$total += $earn->amount;
	}
}
?>


<div class="container">
	<div class="row">
		<div class="col-lg-12">
			<div class="card" style="background: none !important">
				<div class="card-header">
					<h3 class="card-title"> <?= $user->name ?> - All Jobs </h3>
				</div>

				<div class="card-body" style="padding: 0">
					<br>
					<br>
					<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 Job Earn
										<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">Successful Jobs
										<i class="fa fa-mouse-pointer  fa-2x float-right"></i>
									</h4>
									<h1> <?= $allJobs ? count($allJobs) : 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>

						<!-- Job Payment summary start -->
						<div class="col-lg-12">
							<div class="card">
								<div class="card-header">
									<h3>Earn 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
												if ($allJobs != null) {
													foreach ($allJobs as $key => $payment) : ?>
														<tr>
															<td><?= ($key + 1) ?></td>
															<td><?= $payment->invoice_no ?></td>
															<td><?= $payment->title ?></td>
															<td><?= $user->name ?></td>
															<td><?= number_format($payment->amount, 2)  ?></td>
															<td><?= $payment->paywith ?></td>
															<td><?= substr($payment->date, 0, 10) ?></td>

														</tr>
													<?php
													endforeach;
												} else {
													?>
													<tr>
														<td colspan="7" class="text-center">No record found</td>
													</tr>
												<?php
												}
												?>
											</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>