CHANGE_SALES_DASHBOARD
This commit is contained in:
parent
6a1e3519d2
commit
0540cd6585
@ -672,7 +672,7 @@ class SalesController extends BaseController
|
||||
}
|
||||
|
||||
|
||||
// ==================== Dashboard ====================
|
||||
// ==================== Dashboard ====================
|
||||
|
||||
public function branchLevelDashboard()
|
||||
{
|
||||
@ -736,19 +736,39 @@ class SalesController extends BaseController
|
||||
|
||||
public function salesManagerLevelDashboard()
|
||||
{
|
||||
$userId = 1;
|
||||
$userId = get_session_userid();
|
||||
// $userId = 1;
|
||||
$db = \Config\Database::connect();
|
||||
|
||||
try {
|
||||
|
||||
$payload = $this->request->getGet();
|
||||
$current_fin_year = $payload['fy'] ?? getCurrentFinancialYear();
|
||||
|
||||
|
||||
$fin_years = $db->table('sales_target')
|
||||
->select('fy_year')
|
||||
->where('user_id', $userId)
|
||||
->orderBy('fy_year', 'desc')
|
||||
->get()
|
||||
->getResultArray();
|
||||
$fin_years = array_column($fin_years, 'fy_year');
|
||||
$fin_years[] = '2024-2025';
|
||||
|
||||
$target = $db->table('sales_target')
|
||||
->where('user_id', $userId)
|
||||
->where('fy_year', '2025-2026')
|
||||
->get()->getRowArray();
|
||||
->where('fy_year', $current_fin_year)
|
||||
->get()
|
||||
->getRowArray();
|
||||
|
||||
$targetAmount = $target['target_amount'] ?? 0.00;
|
||||
|
||||
// get achieved amount from leads table
|
||||
$achievedAmount = $this->getUserAchievedAmount($current_fin_year, $userId);
|
||||
|
||||
$targetAmount = $target['target_amount'] ?? 2500000.00;
|
||||
$achievedAmount = 600000.00;
|
||||
$remainingAmount = $targetAmount - $achievedAmount;
|
||||
$achievementPercent = ($targetAmount > 0) ? round(($achievedAmount / $targetAmount) * 100) : 0;
|
||||
// $achievementPercent = ($targetAmount > 0) ? round(($achievedAmount / $targetAmount) * 100) : 0;
|
||||
$achievementPercent = ($targetAmount > 0) ? min(100, round(($achievedAmount / $targetAmount) * 100)) : 0;
|
||||
|
||||
$activitySummary = [
|
||||
'total' => $this->activityModel->where('assigned_to', $userId)->countAllResults(),
|
||||
@ -779,9 +799,13 @@ class SalesController extends BaseController
|
||||
'lead_count' => $myLeadsCount,
|
||||
'upcoming' => $upcomingActivities,
|
||||
'recent_leads' => $recentLeads,
|
||||
'user_name' => session()->get('first_name') ?? 'John Doe'
|
||||
'fin_years' => $fin_years,
|
||||
'display_fin_years' => format_financial_year($current_fin_year),
|
||||
'user_name' => get_session_userdata()->first_namee ?? ''
|
||||
];
|
||||
|
||||
// dd($data);
|
||||
|
||||
// return view('sales/my_dashboard_view', $data);
|
||||
$this->loadLayout('sales/sales_manager_level_dashboard', $data);
|
||||
|
||||
@ -789,4 +813,27 @@ class SalesController extends BaseController
|
||||
return $this->failServerError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserAchievedAmount($financialYear, $userId)
|
||||
{
|
||||
// Split the string into two years
|
||||
$years = explode('-', $financialYear);
|
||||
$startYear = $years[0]; // 2025
|
||||
$endYear = $years[1]; // 2026
|
||||
|
||||
// Create the timestamps
|
||||
$startFY = $startYear . '-04-01 00:00:00';
|
||||
$endFY = $endYear . '-03-31 23:59:59';
|
||||
|
||||
$achievedAmountData = $this->leadModel
|
||||
->select('SUM(leads.premium_amount) as achieved_amount')
|
||||
->join('leads', 'sales_actual_leads.lead_id = leads.actual_lead_id')
|
||||
->where('sales_actual_leads.assigned_to', $userId)
|
||||
->where('leads.status', 'won')
|
||||
->where('leads.updated_at >=', $startFY)
|
||||
->where('leads.updated_at <=', $endFY)
|
||||
->findAll();
|
||||
|
||||
return $achievedAmountData[0]['achieved_amount'] ?? 0.00;
|
||||
}
|
||||
}
|
||||
@ -1210,7 +1210,7 @@ if (!function_exists('map_relationship')) {
|
||||
* Extract identity from POST body or GET params.
|
||||
* Looks for 'email' or 'mobile_number'.
|
||||
*/
|
||||
function resolveIdentity($request): ?string
|
||||
function resolveIdentity($request): ?string
|
||||
{
|
||||
// Try POST body first
|
||||
$email = $request->getPost('email');
|
||||
@ -1251,7 +1251,7 @@ if (!function_exists('map_relationship')) {
|
||||
}
|
||||
|
||||
|
||||
function recordRateLimitFailure(string $context = 'authApi'): void
|
||||
function recordRateLimitFailure(string $context = 'authApi'): void
|
||||
{
|
||||
/** @var IncomingRequest $request */
|
||||
$request = \Config\Services::request();
|
||||
@ -1276,4 +1276,44 @@ if (!function_exists('map_relationship')) {
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('getCurrentFinancialYear')) {
|
||||
function getCurrentFinancialYear()
|
||||
{
|
||||
// Get current year and month
|
||||
$date = new DateTime();
|
||||
$currentYear = (int)$date->format('Y');
|
||||
$currentMonth = (int)$date->format('m');
|
||||
|
||||
// If month is Jan, Feb, or March, we are still in the previous year's FY
|
||||
if ($currentMonth < 4) {
|
||||
$startYear = $currentYear - 1;
|
||||
$endYear = $currentYear;
|
||||
} else {
|
||||
$startYear = $currentYear;
|
||||
$endYear = $currentYear + 1;
|
||||
}
|
||||
|
||||
return $startYear . '-' . $endYear;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('format_financial_year')) {
|
||||
function format_financial_year(string $financialYear): string
|
||||
{
|
||||
if (empty($financialYear) || !str_contains($financialYear, '-')) {
|
||||
return $financialYear;
|
||||
}
|
||||
|
||||
$years = explode('-', $financialYear);
|
||||
|
||||
// Ensure we have both parts
|
||||
$startYear = $years[0] ?? '';
|
||||
$endYear = $years[1] ?? '';
|
||||
|
||||
return "APR " . $startYear . " - MAR " . $endYear;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<style>
|
||||
.my-dash { padding: 25px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #fff; }
|
||||
.my-dash { padding: 25px; margin-top: -21px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #fff; }
|
||||
.target-card { background: #1e252b; color: white; padding: 30px; border-radius: 15px; position: relative; margin-bottom: 30px; }
|
||||
.target-amount { font-size: 32px; font-weight: bold; margin: 10px 0; }
|
||||
.progress-container { background: #333; height: 8px; border-radius: 4px; margin: 20px 0; overflow: hidden; position: relative; }
|
||||
@ -10,7 +10,7 @@
|
||||
.stat-box .num { font-size: 20px; font-weight: bold; display: block; margin-bottom: 2px; }
|
||||
.stat-box .lbl { font-size: 11px; color: #999; }
|
||||
|
||||
.chart-circle { position: absolute; right: 40px; top: 35px; width: 75px; height: 75px; border: 6px solid #333; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 18px; border-top-color: #ff6b35; }
|
||||
/* .chart-circle { position: absolute; right: 40px; top: 35px; width: 75px; height: 75px; border: 6px solid #333; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 18px; border-top-color: #ff6b35; } */
|
||||
|
||||
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 25px; }
|
||||
.list-card { border: 1px solid #f0f0f0; border-radius: 12px; padding: 25px; background: #fff; }
|
||||
@ -24,26 +24,39 @@
|
||||
<div class="my-dash">
|
||||
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:25px;">
|
||||
<div>
|
||||
<h1 style="font-size:22px; margin:0; font-weight: 700;">My Dashboard</h1>
|
||||
<p style="color:#666; font-size:13px; margin-top: 4px;">Welcome back, <?= $user_name ?></p>
|
||||
<!-- <h1 style="font-size:22px; margin:0; font-weight: 700;">My Dashboard</h1>
|
||||
<p style="color:#666; font-size:13px; margin-top: 4px;">Welcome back, <?= $user_name ?></p> -->
|
||||
</div>
|
||||
<div style="position: relative;">
|
||||
<input type="text" placeholder="Search leads, activities..." style="background:#f5f5f5; padding:10px 20px; border-radius:8px; border:none; width: 250px; font-size: 13px;">
|
||||
<select id="financial_year" name="financial_year" onchange="onFinancialYearChange(this)" style="background:#f5f5f5; padding:10px 20px; border-radius:8px; border:none; width: 250px; font-size: 13px; cursor: pointer;">
|
||||
<?php if(!empty($fin_years)): ?>
|
||||
<?php foreach($fin_years as $year): ?>
|
||||
<option value="<?= $year; ?>"><?= $year; ?></option>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="target-card">
|
||||
<div style="font-size:11px; color:#999; letter-spacing: 1px; font-weight: 600;">YEARLY TARGET 2025</div>
|
||||
<div style="font-size:11px; color:#999; letter-spacing: 1px; font-weight: 600;">YEARLY TARGET</div>
|
||||
<div class="target-amount">₹<?= number_format($target / 100000, 1) ?>L</div>
|
||||
<div style="font-size:12px; color:#777;">Apr 2025 - Mar 2026</div>
|
||||
<div style="font-size:12px; color:#777;"><?= $display_fin_years ?></div>
|
||||
|
||||
<div class="chart-circle">
|
||||
<span style="color:#ff6b35"><?= $percent ?>%</span>
|
||||
<div class="chart-circle" style="position: absolute; right: 40px; top: 35px; width: 75px; height: 75px;">
|
||||
<svg width="75" height="75" viewBox="0 0 75 75" style="transform: rotate(-90deg);">
|
||||
<circle cx="37.5" cy="37.5" r="30" fill="none" stroke="#333" stroke-width="6"/>
|
||||
<circle cx="37.5" cy="37.5" r="30" fill="none" stroke="#ff6b35" stroke-width="6"
|
||||
stroke-dasharray="<?= round(2 * M_PI * 30 * $percent / 100, 2) ?> 188.5"
|
||||
stroke-linecap="round"/>
|
||||
</svg>
|
||||
<span style="position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); color:#ff6b35; font-weight:bold; font-size:14px;"><?= $percent ?>%</span>
|
||||
</div>
|
||||
|
||||
<div class="progress-container">
|
||||
<div class="progress-bar" style="width: <?= $percent ?>%"></div>
|
||||
</div>
|
||||
|
||||
<div style="display:flex; justify-content:space-between; font-size:12px; color: #999;">
|
||||
<span>Achieved <strong style="color:white">₹<?= number_format($achieved / 100000, 1) ?>L</strong></span>
|
||||
<span>Remaining <strong style="color:white">₹<?= number_format($remaining / 100000, 1) ?>L</strong></span>
|
||||
@ -69,7 +82,7 @@
|
||||
<div style="font-weight:600; font-size:14px; color: #333;"><?= $u['company_name'] ?></div>
|
||||
<div style="font-size:11px; color:#999; margin-top: 3px;"><?= strtoupper($u['activity_type'] ?? 'EMAIL') ?> - <?= date('d Mar Y', strtotime($u['scheduled_date'])) ?></div>
|
||||
</div>
|
||||
<button class="badge-done">✓ Done</button>
|
||||
<button class="badge-done">✓ Mark as completed</button>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
@ -90,4 +103,22 @@
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const fy = params.get('fy');
|
||||
if (fy) {
|
||||
document.getElementById('financial_year').value = fy;
|
||||
}
|
||||
});
|
||||
|
||||
function onFinancialYearChange(select) {
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.set('fy', select.value);
|
||||
window.location.href = url.toString();
|
||||
}
|
||||
|
||||
</script>
|
||||
Loading…
Reference in New Issue
Block a user