This commit is contained in:
ns77@siliconpin.com
2025-09-03 14:04:44 +00:00
parent 10881c6a5b
commit 533d1b572d
12 changed files with 410 additions and 218 deletions

View File

@@ -1,120 +1,118 @@
<div class="container">
<table>
<!-- <tr>
<td>
<form>
<input type="date" name="tday">
<input type="submit" class="btn-info" value="Daily Report">
</form>
</td>
<td>
<form>
<input type="date" name="tmonth">
<input type="submit" class="btn-info" value="Monthly Report">
</form>
</td>
</tr> -->
<tr><td>.</td><td>.</td></tr>
<tr>
<td colspan="2">
<form method="post">
<select name="Agent">
<option value=""> Select Agent </option>
<?php
$users = glob(APP_DIR.'/CONTENT/ROOT_URI/Admin/users/*');
$user_arr = array();
for($i = 0; $i < count($users); $i++) {
$new_user = explode('/', $users[$i]);
$new_user = end($new_user);
echo '<option value="'.$new_user.'">'.$new_user.'</option>';
// $user_arr[$i] = $new_user;
}
?>
</select>
<label for="">From </label><input type="date" name="dFrom">
<label for="">To </label><input type="date" name="dTo">
<input type="submit" class="btn-info" value="Report">
</form>
</td>
</tr>
</table>
</div>
<?php
function report_view($type,$dt) {
$dateFrom=$dt;
if($type!="month" || $type!="day") {
$dateFrom= strtotime($dt); $dateFrom = date("Y-m-d", $dateFrom);
$dateTo= strtotime('+1 day', strtotime($type)); $dateTo = date("Y-m-d", $dateTo);
}
//$dateFrom=$dt;
else{
if($type=="month") {$dateFrom= strtotime('-1 day', strtotime($dt)); $dateFrom = date("Y-m-d", $dateFrom);}
$dateTo = strtotime('+1 '.$type, strtotime($dt));
$dateTo = date("Y-m-d", $dateTo);
}
echo '<div class="container"> <h3>'.$dateFrom." -> ".$dateTo."(Up to)</h3> </div>";
$conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
$totalAmount=0;
$agent="";if(isset($_POST['Agent'])) $agent=$_POST['Agent']; else $agent=$_SESSION['EMAIL'];
echo '
<div class="container" style="margin-top: 70px;">
<h5>VIEW REPORT:::::::: </h5><hr>
</div>
<div class="container">
<table class="table table-striped table-bordered table-hover table-responsive">
<tr>
<th>Transaction ID</th>
<th>Time</th>
<th>AC No</th>
<th>Name</th>
<th>Amount</th>
<th>commission</th>
</tr>';
$sql = "SELECT * FROM `".$GLOBALS['arif_tran']."` INNER JOIN `".$GLOBALS['arif_ac']."` ON `".$GLOBALS['arif_tran']."`.`AT_ACID`=`".$GLOBALS['arif_ac']."`.`AA_ACNO` WHERE `AT_TIMESTAMP` BETWEEN '".$dateFrom." 00:00:00.000000' AND '".$dateTo." 00:00:00.000000'
AND `AA_AGENT`= '".$agent."' ORDER BY `AT_ID` DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
//$ID=$row["GC_ID"];
// $tt=$row["AT_ID"]-10;
echo "
<tr>
<td>".$row["AT_ID"]. "</td>
<td>".$row["AT_TIMESTAMP"]. "</td>
<td>".$row["AT_ACID"]. "</td>
<td>".$row["AA_NAME"]. "</td>
<td>".$row["AT_AMOUNT"]. "</td>
<td>".$row["AT_AMOUNT"]/100*2.5 . "</td>
</tr>";$totalAmount+=$row["AT_AMOUNT"];
}
} else {
echo "0 results";
}
$conn->close();
echo '
</table>
<hr> <h2> Total Transaction amount : '.$totalAmount.'</h2>
<hr> <h2> Total Commission amount : '.$totalAmount/100*2.5 .'</h2>
</div>
';
}
if(isset($_POST['tday']) && $_POST['tday']!="") report_view('day',$_POST['tday']);
if(isset($_POST['tmonth']) && $_POST['tmonth']!="") report_view('month',$_POST['tmonth']);
if(isset($_POST['dFrom']) && $_POST['dTo']!="") report_view($_POST['dTo'],$_POST['dFrom']);
//if(isset($_GET['Type']) && $_GET['Type']=="Loan") view_list_ac('Loan');
// if(isset($_GET['Type']) && $_GET['Type']=="Recurring") view_list_ac('Recurring');
// if(isset($_GET['Type']) && $_GET['Type']=="FD") view_list_ac('FD');
// ---- Default date range ----
$today = date("Y-m-d"); // Today date
$monthStart = date("Y-m-01"); // first date of each month
$dFrom = $_GET['dFrom'] ?? $monthStart;
$dTo = $_GET['dTo'] ?? $today;
?>
<div class="container mt-4">
<div class="card shadow-lg p-4 rounded-3">
<h4 class="mb-3">Commission Report</h4>
<form method="get" class="row g-3">
<div class="col-md-3">
<label class="form-label">From</label>
<input value="<?= $dFrom ?>" type="date" name="dFrom" class="form-control" required>
</div>
<div class="col-md-3">
<label class="form-label">To</label>
<input value="<?= $dTo ?>" type="date" name="dTo" class="form-control" required>
</div>
<div class="col-md-3 d-flex align-items-end" style="margin-top: 25px;">
<button type="submit" class="btn btn-info w-100">Generate Report</button>
</div>
</form>
</div>
</div>
<?php
function commission_report($dateFrom, $dateTo) {
echo '<div class="container mt-4">
<div class="alert alert-primary shadow-sm">
<h5 class="mb-0">Commission Report: '.$dateFrom." → ".$dateTo.'</h5>
</div>
</div>';
$conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
// ---- Login user type check ----
$loginType = $_SESSION['type'] ?? ''; // login session-এ type আছে
$loginId = $_SESSION['user_id']; // login user_id
// ---- Base Query ----
$sql = "SELECT u.user_id, u.user_name, u.comi_rate, COALESCE(SUM(t.AT_AMOUNT),0) as total_amount FROM `".$GLOBALS['arif_users']."` u LEFT JOIN `".$GLOBALS['arif_ac']."` a ON u.user_id = a.AA_AGENT LEFT JOIN `".$GLOBALS['arif_tran']."` t ON a.AA_ACNO = t.AT_ACID AND t.AT_TIMESTAMP BETWEEN '".$dateFrom." 00:00:00' AND '".$dateTo." 23:59:59' WHERE u.type = 'agent'";
// ---- if Agent self data filter ----
if ($loginType === 'agent') {
$sql .= " AND u.user_id = '".$loginId."'";
}
$sql .= " GROUP BY u.user_id, u.user_name, u.comi_rate ORDER BY u.user_name ASC";
$result = $conn->query($sql);
echo '
<div class="container mt-3">
<div class="card shadow-sm rounded-3">
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered table-hover align-middle">
<thead class="table-light">
<tr>
<th>Agent ID</th>
<th>Agent Name</th>
<th>Total Collection</th>
<th>Total Commission</th>
</tr>
</thead>
<tbody>';
$grandTotalCommission = 0;
$grandTotalCollection = 0;
if ($result && $result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$collection = $row["total_amount"];
$commission = ($collection * $row["comi_rate"]) / 100;
$grandTotalCollection += $collection;
$grandTotalCommission += $commission;
echo "
<tr>
<td>".$row["user_id"]."</td>
<td>".$row["user_name"]."</td>
<td>".number_format($collection,2)."</td>
<td>".number_format($commission,2)."</td>
</tr>";
}
} else {
echo "<tr><td colspan='4' class='text-center text-muted'>No agents found</td></tr>";
}
echo '
</tbody>
</table>';
// ---- if admin/bm then show grand total ----
if ($loginType !== 'agent') {
echo '<h5 class="text-end">
Grand Total Collection : <b>'.number_format($grandTotalCollection,2).'</b><br>
Grand Total Commission : <b>'.number_format($grandTotalCommission,2).'</b>
</h5>';
}
echo '
</div>
</div>
</div>
';
$conn->close();
}
// ---- Call commission function ----
commission_report($dFrom, $dTo);
?>