<?php require admin_view('static/header') ?>

<div class="container-fluid">
	<style>
		.provider-value {
			color: #b72b2b !important
	</style>
	<div class="row">

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

			<a href="<?= admin_url('orders') ?>" class="btn btn-default">Tüm Siparişler <span class="label label-default"><?= $allOrders ?></span></a>

			<a href="<?= admin_url('orders/pending') ?>" class="btn btn-default">Beklemede <span class="label label-default"><?= $pendingOrders ?></span></a>

			<a href="<?= admin_url('orders/processing') ?>" class="btn btn-default">İşlemde <span class="label label-primary"><?= $processingOrders ?></span></a>

			<a href="<?= admin_url('orders/inprogress') ?>" class="btn btn-default">Yükleniyor <span class="label label-primary"><?= $inprogressOrders ?></span></a>

			<a href="<?= admin_url('orders/completed') ?>" class="btn btn-default">Tamamlandı <span class="label label-success"><?= $completedOrders ?></span></a>

			<a href="<?= admin_url('orders/partial') ?>" class="btn btn-default">Kısmi Tamamlandı <span class="label label-warning"><?= $partialOrders ?></span></a>

			<a href="<?= admin_url('orders/canceled') ?>" class="btn btn-default">İptal Edildi <span class="label label-danger"><?= $canceledOrders ?></span></a>

			<a href="<?= admin_url('orders/failed') ?>" class="btn btn-default">Fail <span class="label label-danger"><?= $failedOrders ?></span></a>



			<?php if ($page_order_status == "failed") : ?>

				<div class="panel panel-default" style="margin-top:20px;margin-bottom:0;border-bottom-left-radius: 0;border-bottom-right-radius: 0;">

					<div class="panel-body">

						<small><b>Seçili Siparişleri:</b></small>

						<button onclick="order_multiple_cancel();" class="btn btn-default btn-xs">İptal ve İade Et</button>

						<button onclick="toplusec();" class="btn btn-default btn-xs pull-right">Tüm Siparişleri Seç</button>

					</div>

				</div>

				<div class="panel panel-default" style="border-radius:0;margin:0;">

					<table class="table order-table table-grey" style="margin-bottom:0;">

						<thead>

							<tr>

								<th></th>

								<th data-field="id">Sipariş ID</th>

								<th>Kullanıcı adı</th>

								<th>Ücret</th>

								<th style="width:10%;">Link</th>

								<th>Başlangıç</th>

								<th>Miktar</th>

								<th style="width:20%;">Servis</th>

								<th>Sipariş Durumu</th>

								<th>Kalan</th>

								<th>Sipariş Tarihi</th>

								<th></th>

							</tr>

						</thead>

						<tbody>

							<?php $i = 0; ?>

							<?php foreach ($orders as $order) : ?>

								<tr>

									<td>

										<input <?php if ($order['order_status'] == 'Completed' || $order['order_status'] == 'Canceled') : ?> disabled="" <?php endif; ?> type="checkbox" id="checkbox<?= $i; ?>" name="checkbox<?= $order["order_id"]; ?>" value='<?= $order["order_id"] ?>'>

									</td>

									<td class="p-l">

										<?= $order["order_id"]; ?>

									</td>

									<td><?= ($order["user_username"] != null) ? $order["user_username"] : "Silinmiş"; ?></td>

									<td class="service-block__minorder">

										<div><?= $order["order_amount"]; ?></div>

									</td>

									<td style="width:10%;"><?= $order["order_link"]; ?></td>

									<td><?= $order["order_start_count"]; ?></td>

									<td><?= $order["order_quantity"]; ?></td>

									<td style="width:20%;"> <span class="label-id"><?= ($order["service_id"] != null) ? $order["service_id"] : "0"; ?></span><?= ($order["service_name"] != null) ? $order["service_name"] : "Silinmiş"; ?></td>

									<td>

										Fail

									</td>

									<td><?= $order["order_remains"]; ?></td>

									<td class="nowrap"><?= str_date(date("y-m-d H:i:s", $order["order_date"])) ?></td>

									<td>

										<div class="dropdown pull-right">

											<button class="btn btn-xs btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">İşlemler<span class="caret"></span></button>

											<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">

												<li><a href="#" data-toggle="modal" data-toggle="modal" data-target="#modalDefault" data-action="get_order" data-id="<?= $order["order_id"]; ?>">Sipariş Detayları</a></li>

												<li role="separator" class="divider"></li>

												<li class="dropdown-header">Sipariş İşlemleri</li>

												<li><a href="#" onclick="send_order(<?= $order["order_id"]; ?>)">Siparişi Gönder</a></li>

												<li><a href="#" onclick="cancel_order(<?= $order["order_id"]; ?>)">Siparişi İptal Et</a></li>

										
												<li class="dropdown-header">Sipariş Durumunu Güncelle</li>
                                                <?php if ($order['is_failed'] == 0) : ?>
												<?php if ($order['order_status'] == "Pending" || $order['order_status'] == "Completed" || $order['order_status'] == "Processing" || $order['order_status'] == "Partial" || $order['order_status'] == "In progress") : ?>
                                                    
													<li><a href="#" onclick="update_order_status('<?= $order["order_id"]; ?>', 'Canceled')">İptal</a></li>

												<?php endif; ?>
                                                <?php endif; ?>
												<?php if ($order['order_status'] == "Pending" || $order['order_status'] == "Processing" || $order['order_status'] == "In progress") : ?>

													<li><a href="#" onclick="update_order_status('<?= $order["order_id"]; ?>', 'Completed')">Tamamlandı</a></li>

												<?php endif; ?>

												<?php if ($order['order_status'] == "Pending" || $order['order_status'] == "Processing") : ?>

													<li><a href="#" onclick="update_order_status('<?= $order["order_id"]; ?>', 'In progress')">Yükleniyor</a></li>

												<?php endif; ?>




											</ul>

										</div>

									</td>

								</tr>

								<?php $i++; ?>

							<?php endforeach; ?>

							<input type="hidden" id="totalcheckbox" name="totalcheckbox" value="<?= $i ?>">

						</tbody>

					</table>

				</div>

			<?php else : ?>

				<div class="pull-right">

					<form class="form-inline" action="" method="get">

						<div class="input-group">

							<input type="text" name="search" class="form-control" value="" placeholder="Sipariş ara...">

							<span class="input-group-btn">

								<select class="form-control" style="border-radius:0;" name="search_type">

									<option value="id">Sipariş ID</option>

									<option value="link">Bağlantı</option>

									<option value="username">Kullanıcı Adı</option>

								</select>

								<button type="submit" class="btn btn-default"><span class="fa fa-search" aria-hidden="true"></span></button>

							</span>

						</div>

					</form>

				</div>

				<div class="panel panel-default" style="margin-top:20px;margin-bottom:0;border-bottom-left-radius: 0;border-bottom-right-radius: 0;">

					<div class="panel-body">

						<small><b>Seçili Siparişleri:</b></small>

						<button onclick="order_multiple_cancel();" class="btn btn-default btn-xs">İptal ve İade Et</button>

						<button onclick="toplusec();" class="btn btn-default btn-xs pull-right">Tüm Siparişleri Seç</button>

					</div>

				</div>

				<div class="panel panel-default" style="border-radius:0;margin:0;">

					<table class="table order-table table-grey" style="margin-bottom:0;">

						<thead>

							<tr>

								<th></th>

								<th>Sipariş ID</th>

								<th>Kullanıcı adı</th>

								<th>Ücret</th>

								<th style="width:10%;">Link</th>

								<th>Başlangıç</th>

								<th>Miktar</th>

								<th style="width:20%;">Servis</th>

								<th>Sipariş Durumu</th>

								<th>Kalan</th>

								<th>Sipariş Tarihi</th>

								<th></th>

							</tr>

						</thead>

						<tbody>

							<?php $i = 0; ?>


							<?php foreach ($orders as $order) :

								if ($order['api_id'] != NULL) {
									$apis = $db->from('apis')->where('api_id', $order['api_id'])->first();
								}

							?>



								<tr>

									<td>

										<input <?php if ($order['order_status'] == 'Completed' || $order['order_status'] == 'Canceled') : ?> disabled="" <?php endif; ?> type="checkbox" id="checkbox<?= $i; ?>" name="checkbox<?= $order["order_id"]; ?>" value='<?= $order["order_id"] ?>'>

									</td>

									<td class="p-l">

										<?= $order["order_id"]; ?>

										<div class="provider-value"><?= $order["api_order_id"] ?></div>


									</td>

									<td><?= ($order["user_username"] != null) ? $order["user_username"] : "Silinmiş"; ?></td>

									<td class="service-block__minorder">

										<div style="background: #dc123c;text-align: center;color: white;font-weight: bold;border-radius: 4px;"><?= $order["order_amount"]; ?>{CURRENCY_SYMBOL}</div>

										<div class="provider-value"><?= $order["api_order_currency"] . $order["api_order_amount"]; ?></div>

									</td>

									<td style="width:10%;"><?= $order["order_link"]; ?></td>

									<td><?= $order["order_start_count"]; ?></td>

									<td><?= $order["order_quantity"]; ?></td>

									<td style="width:20%;">
										<span class="label-id"><?= ($order["service_id"] != null) ? $order["service_id"] : "0"; ?></span><?= ($order["service_name"] != null) ? $order["service_name"] : "Silinmiş"; ?>
										<br>
										<span style="color:#b72b2b"><?php if ($apis) echo $apis['api_url']; ?></span>
									</td>

									<td>

										<?php foreach ($status_list as $en => $tr) : ?>

											<?php if ($en == $order["order_status"]) : ?>

												<?= $tr; ?>

											<?php endif; ?>

										<?php endforeach; ?>

										</select>

									</td>

									<td><?= $order["order_remains"]; ?></td>

									<td class="nowrap"><?= str_date(date("y-m-d H:i:s", $order["order_date"])) ?></td>

									<td>

										<div class="dropdown pull-right">

											<button class="btn btn-xs btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">İşlemler<span class="caret"></span></button>

											<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">

												<li><a href="#" data-toggle="modal" data-toggle="modal" data-target="#modalDefault" data-action="get_order" data-id="<?= $order["order_id"]; ?>">Sipariş Detayları</a></li>

												<?php if ($order['order_status'] !== 'Partial' || $order['order_status'] !== 'Canceled') : ?>

													<li><a href="#" onclick="update_order_status('<?= $order["order_id"]; ?>', 'Partial')">Gitmeyen Miktar Ayarla</a></li>

												<?php endif; ?>

												<?php if ($order['api_id'] == null) : ?>

													<li><a href="#" onclick="update_order_count('<?= $order["order_id"]; ?>')">Başlangıç Sayısı Ayarla</a></li>

												<?php endif; ?>

												<li role="separator" class="divider"></li>

												<li class="dropdown-header">Sipariş Durumunu Güncelle</li>

												<?php if ($order['order_status'] == "Pending" || $order['order_status'] == "Completed" || $order['order_status'] == "Processing" || $order['order_status'] == "Partial" || $order['order_status'] == "In progress") : ?>

													<li><a href="#" onclick="update_order_status('<?= $order["order_id"]; ?>', 'Canceled')">İptal</a></li>

												<?php endif; ?>

												<?php if ($order['order_status'] == "Pending" || $order['order_status'] == "Processing" || $order['order_status'] == "In progress"  || $order['order_status'] == "Canceled") : ?>

													<li><a href="#" onclick="update_order_status('<?= $order["order_id"]; ?>', 'Completed')">Tamamlandı</a></li>

												<?php endif; ?>

												<?php if ($order['order_status'] == "Pending" || $order['order_status'] == "Processing" || $order['order_status'] == "Canceled") : ?>

													<li><a href="#" onclick="update_order_status('<?= $order["order_id"]; ?>', 'In progress')">Yükleniyor</a></li>

												<?php endif; ?>

											</ul>

										</div>

									</td>

								</tr>

								<?php $i++; ?>

							<?php endforeach; ?>

						</tbody>

					</table>

					<input type="hidden" id="totalcheckbox" name="totalcheckbox" value="<?= $i ?>">

				</div>

				<?php if ($i > 0) : ?>
					<?php if ($page_order_status) : ?>


						<ul class="pagination">

							<?= $db->showPagination(admin_url('orders/' . $page_order_status . '?' . $pageParam . '=[page]')); ?>

						</ul>

					<?php else : ?>

						<ul class="pagination">

							<?= $db->showPagination(admin_url(route(1) . '?' . $pageParam . '=[page]')); ?>

						</ul>

					<?php endif; ?>

				<?php endif; ?>
			<?php endif; ?>

		</div>



	</div>



</div>

<?php require admin_view('static/footer') ?>