<?php
header("Content-Type: text/html;charset=utf-8");
error_reporting(0);
$path="../../";
if($_POST){
	if($_POST["xls"]<>""){
		header('Content-Encoding: UTF-8');
		$file="".$_GET["ne"]."_".date("dmyHis").".xls";
		header("Content-type: application/vnd.ms-excel");
		header("Content-Disposition: attachment; filename=".$file."");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo "\xEF\xBB\xBF"; //UTF-8 BOM
		echo $out;
	}
	include "../".$_GET["path"]."".$_GET["ne"].".php";
}else{
//include("../public/log.php");
include("../../map.php");
include("../../scripts.php");
?>
<style>
	.modern-card { border: none; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); margin-bottom: 24px; overflow: hidden; background: #fff; }
	.modern-card .card-header { background: #f8f9fa; border-bottom: 1px solid #edf2f9; padding: 16px 20px; }
	.modern-card .card-title { font-size: 1.1rem; font-weight: 600; color: #1e293b; margin: 0; }
	.modern-card .card-body { padding: 24px; }
	.modern-card .card-footer { background: #fdfdfe; border-top: 1px solid #edf2f9; padding: 12px 20px; font-size: 0.85rem; color: #64748b; }
	.modern-form-group { margin-bottom: 1rem; }
	.modern-form-control { border-radius: 8px; border: 1px solid #cbd5e1; padding: 10px 14px; box-shadow: none; transition: all 0.2s; width: 100%; }
	.modern-form-control:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); outline: none; }
	.modern-btn { border-radius: 8px; font-weight: 600; padding: 10px 20px; transition: all 0.2s; border: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; width: 100%; }
	.modern-btn-warning { background-color: #f59e0b; color: #fff; }
	.modern-btn-warning:hover { background-color: #d97706; color: #fff; transform: translateY(-1px); }
	.xls-checkbox-wrapper { display: flex; align-items: center; height: 100%; min-height: 44px; gap: 8px; padding: 0 10px; border: 1px solid #e2e8f0; border-radius: 8px; background: #f8fafc; cursor: pointer; }
	.xls-checkbox-wrapper input { width: 18px; height: 18px; margin: 0; cursor: pointer; }
	.modern-row { display: flex; flex-wrap: wrap; margin-left: -10px; margin-right: -10px; }
	.modern-col { padding-left: 10px; padding-right: 10px; margin-bottom: 16px; box-sizing: border-box; }
	.col-12 { width: 100%; } .col-9 { width: 75%; } .col-6 { width: 50%; } .col-3 { width: 25%; } .col-2 { width: 16.666%; }
	@media (max-width: 768px) { .col-6, .col-3, .col-9, .col-2 { width: 100%; } }
</style>

<div class="container-fluid" style="padding: 24px; max-width: 1200px; margin: 0 auto;">
<?php if($_GET["ne"]=="report_clients"){?>
	
	<!-- Genel Rapor -->
	<div class="modern-card">
		<div class="card-header"><h3 class="card-title"><i class="fa fa-chart-bar" style="color: #3b82f6; margin-right: 8px;"></i> Genel Rapor</h3></div>
		<div class="card-body">
			<form action="?ne=<?php echo $_GET["ne"];?>&path=<?php echo $_GET["path"];?>" method="post">
				<div class="modern-row">
					<div class="modern-col col-6">
						<input type="text" class="modern-form-control" name="q" placeholder="Aranan kelime veya başlık...">
					</div>
					<div class="modern-col col-3">
						<input type="date" class="modern-form-control" name="ts1" value="<?php echo date("Y-m-d")?>">
					</div>
					<div class="modern-col col-3">
						<input type="date" class="modern-form-control" name="ts2" value="<?php echo date("Y-m-d")?>">
					</div>
					<div class="modern-col col-6">
						<select size=1 name="s2" class="modern-form-control">
							<option value=""><?php echo translate("Tümü")?></option>
							<?php $sqlc=mysqli_query($conn, "select * from kategoriler where ne='kkategori' order by sira asc"); while($rsc=mysqli_fetch_assoc($sqlc)){?>
							<option value="<?php echo $rsc["Cat_ID"];?>" <?php if($rsc["Cat_ID"]==$rsu["s2"]){?>Selected<?php }?> title="<?php echo $rsc["Cat_".$_SESSION["lang"].""];?>" alt="<?php echo $rsc["Cat_".$_SESSION["lang"].""];?>" style="color:#6699FF">[<?php echo $rsc["Cat_ID"];?>] <?php echo $rsc["Cat_".$_SESSION["lang"].""];?></option>
							<?php }?>
						</select>
					</div>
					<div class="modern-col col-3">
						<label class="xls-checkbox-wrapper">
							<input id="xls" type="checkbox" name="xls" value="true">
							<span style="font-weight: 500; color: #475569;"><i class="fa fa-file-excel" style="color:#10b981;"></i> <?php echo translate("xls Export")?></span>
						</label>
					</div>
					<div class="modern-col col-3">
						<button type="submit" class="modern-btn modern-btn-warning"><i class="fa fa-filter" style="margin-right:8px;"></i> <?php echo translate("Filtrele")?></button>
					</div>
				</div>
			</form>
		</div>
		<div class="card-footer"><i class="fa fa-info-circle"></i> Genel Alacak, Borç, Geciken</div>
	</div>

	<!-- Günlük Rapor -->
	<div class="modern-card">
		<div class="card-header"><h3 class="card-title"><i class="fa fa-calendar-day" style="color: #f59e0b; margin-right: 8px;"></i> Günlük Rapor (Beta)</h3></div>
		<div class="card-body">
			<form action="?ne=<?php echo $_GET["ne"];?>_daily&path=<?php echo $_GET["path"];?>" method="post">
				<div class="modern-row">
					<div class="modern-col col-6">
						<input type="text" class="modern-form-control" name="q" placeholder="Aranan...">
					</div>
					<div class="modern-col col-3">
						<input type="date" class="modern-form-control" name="ts1" value="<?php echo date("Y-m-d")?>">
					</div>
					<div class="modern-col col-3">
						<input type="date" class="modern-form-control" name="ts2" value="<?php echo date("Y-m-d")?>">
					</div>
					
					<div class="modern-col col-3" style="display:flex; gap: 10px;">
						<label class="xls-checkbox-wrapper" style="flex:1;">
							<input type="radio" name="type" value="alacak" checked>
							<span style="font-size:14px; font-weight:500;"><?php echo translate("Alacak")?></span>
						</label>
						<label class="xls-checkbox-wrapper" style="flex:1;">
							<input type="radio" name="type" value="tahsilat">
							<span style="font-size:14px; font-weight:500;"><?php echo translate("Tahsilat")?></span>
						</label>
					</div>
					
					<div class="modern-col col-3">
						<select size=1 name="s2" class="modern-form-control">
							<option value=""><?php echo translate("Tümü")?></option>
							<?php $sqlc=mysqli_query($conn, "select * from kategoriler where ne='kkategori' order by sira asc"); while($rsc=mysqli_fetch_assoc($sqlc)){?>
							<option value="<?php echo $rsc["Cat_ID"];?>" <?php if($rsc["Cat_ID"]==$rsu["s2"]){?>Selected<?php }?> title="<?php echo $rsc["Cat_".$_SESSION["lang"].""];?>" alt="<?php echo $rsc["Cat_".$_SESSION["lang"].""];?>" style="color:#6699FF">[<?php echo $rsc["Cat_ID"];?>] <?php echo $rsc["Cat_".$_SESSION["lang"].""];?></option>
							<?php }?>
						</select>
					</div>
					<div class="modern-col col-3">
						<label class="xls-checkbox-wrapper">
							<input type="checkbox" name="xls" value="true">
							<span style="font-weight: 500; color: #475569;"><i class="fa fa-file-excel" style="color:#10b981;"></i> <?php echo translate("xls Export")?></span>
						</label>
					</div>
					<div class="modern-col col-3">
						<button type="submit" class="modern-btn modern-btn-warning"><i class="fa fa-filter" style="margin-right:8px;"></i> <?php echo translate("Filtrele")?></button>
					</div>
				</div>
			</form>
		</div>
		<div class="card-footer"><i class="fa fa-info-circle"></i> Belirtilen tarih aralığından belirtilen gün kadar alacak izleme</div>
	</div>

	<!-- Aylık Rapor -->
	<div class="modern-card">
		<div class="card-header"><h3 class="card-title"><i class="fa fa-calendar-alt" style="color: #10b981; margin-right: 8px;"></i> Aylık Rapor (Beta)</h3></div>
		<div class="card-body">
			<form action="?ne=<?php echo $_GET["ne"];?>_monthly&path=<?php echo $_GET["path"];?>" method="post">
				<div class="modern-row">
					<div class="modern-col col-9">
						<input type="text" class="modern-form-control" name="q" placeholder="Aranan...">
					</div>
					<div class="modern-col col-3">
						<input type="number" name="year" class="modern-form-control" style="background-color: #f8fafc;" placeholder="Yıl" value="<?php echo date('Y')?>">
					</div>
					<div class="modern-col col-3" style="display:flex; gap: 10px;">
						<label class="xls-checkbox-wrapper" style="flex:1;">
							<input type="radio" name="type" value="alacak" checked>
							<span style="font-size:14px; font-weight:500;"><?php echo translate("Alacak")?></span>
						</label>
						<label class="xls-checkbox-wrapper" style="flex:1;">
							<input type="radio" name="type" value="tahsilat">
							<span style="font-size:14px; font-weight:500;"><?php echo translate("Tahsilat")?></span>
						</label>
					</div>
					<div class="modern-col col-3">
						<select size=1 name="s2" class="modern-form-control">
							<option value=""><?php echo translate("Tümü")?></option>
							<?php $sqlc=mysqli_query($conn, "select * from kategoriler where ne='kkategori' order by sira asc"); while($rsc=mysqli_fetch_assoc($sqlc)){?>
							<option value="<?php echo $rsc["Cat_ID"];?>" <?php if($rsc["Cat_ID"]==$rsu["s2"]){?>Selected<?php }?> title="<?php echo $rsc["Cat_".$_SESSION["lang"].""];?>" alt="<?php echo $rsc["Cat_".$_SESSION["lang"].""];?>" style="color:#6699FF">[<?php echo $rsc["Cat_ID"];?>] <?php echo $rsc["Cat_".$_SESSION["lang"].""];?></option>
							<?php }?>
						</select>
					</div>
					<div class="modern-col col-3">
						<label class="xls-checkbox-wrapper">
							<input type="checkbox" name="xls" value="true">
							<span style="font-weight: 500; color: #475569;"><i class="fa fa-file-excel" style="color:#10b981;"></i> <?php echo translate("xls Export")?></span>
						</label>
					</div>
					<div class="modern-col col-3">
						<button type="submit" class="modern-btn modern-btn-warning"><i class="fa fa-filter" style="margin-right:8px;"></i> <?php echo translate("Filtrele")?></button>
					</div>
				</div>
			</form>
		</div>
		<div class="card-footer"><i class="fa fa-info-circle"></i> Aylık bazda alacak izleme</div>
	</div>

<?php }else{?>
	<!-- Genel Rapor (Others) -->
	<div class="modern-card" style="margin-top: 5%;">
		<div class="card-header"><h3 class="card-title"><i class="fa fa-chart-line" style="color: #6366f1; margin-right: 8px;"></i> Genel Rapor</h3></div>
		<div class="card-body">
			<form action="?ne=<?php echo $_GET["ne"];?>&path=<?php echo $_GET["path"];?>" method="post">
				<div class="modern-row">
					<div class="modern-col col-12">
						<input type="text" class="modern-form-control" name="q" placeholder="Aranan...">
					</div>
					<div class="modern-col col-6">
						<input type="date" class="modern-form-control" name="ts1" value="<?php echo date("Y-m-d")?>">
					</div>
					<div class="modern-col col-6">
						<input type="date" class="modern-form-control" name="ts2" value="<?php echo date("Y-m-d")?>">
					</div>

					<?php if($_GET["ne"]<>"report_ecommerces"){?>
					<div class="modern-col col-6">
						<select size=1 name="s9" class="modern-form-control">
							<option value=""><?php echo translate("Tümü")?></option>
							<?php $sqlc=mysqli_query($conn, "select * from kategoriler where ne='ukategori' order by sira asc"); while($rsc=mysqli_fetch_assoc($sqlc)){?>
							<option value="<?php echo $rsc["Cat_ID"];?>" <?php if($rsc["Cat_ID"]==$rsu["s9"]){?>Selected<?php }?> title="<?php echo $rsc["Cat_".$_SESSION["lang"].""];?>" alt="<?php echo $rsc["Cat_".$_SESSION["lang"].""];?>" style="color:#6699FF">[<?php echo $rsc["Cat_ID"];?>] <?php echo $rsc["Cat_".$_SESSION["lang"].""];?></option>
							<?php }?>
						</select>
					</div>
					<?php }?>

					<?php if($_GET["ne"]=="report_ecommerces"){?>
					<div class="modern-col col-3">
						<select size=1 name="type" class="modern-form-control">
							<option value="orders"><?php echo translate("Sadece Siparişler")?></option>
							<option value="order_items"><?php echo translate("Sadece Ürünler")?></option>
							<option value="orders_and_items"><?php echo translate("Sipariş ve Ürünler")?></option>
						</select>
					</div>
					<div class="modern-col col-3">
						<select size=1 name="odeme" class="modern-form-control">
							<option value="PayTr"><?php echo translate("PayTr")?></option>
							<option value="Havale"><?php echo translate("Havale")?></option>
							<option value="Pos"><?php echo translate("Pos")?></option>
						</select>
					</div>
					<?php }?>

					<div class="modern-col <?php echo ($_GET["ne"]=="report_ecommerces") ? 'col-6' : 'col-6'; ?>" style="display:flex; gap: 16px;">
						<label class="xls-checkbox-wrapper" style="flex:1;">
							<input type="checkbox" name="xls" value="true">
							<span style="font-weight: 500; color: #475569;"><i class="fa fa-file-excel" style="color:#10b981;"></i> <?php echo translate("xls Export")?></span>
						</label>
						<button type="submit" class="modern-btn modern-btn-warning" style="flex:1;"><i class="fa fa-filter" style="margin-right:8px;"></i> <?php echo translate("Filtrele")?></button>
					</div>
				</div>
			</form>
		</div>
	</div>
<?php }?>
</div>
<?php }?>