-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.js
More file actions
127 lines (112 loc) · 8.77 KB
/
Copy pathdata.js
File metadata and controls
127 lines (112 loc) · 8.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* ============================================================
Sahyog – data.js (API-backed + local fallback)
Scheme dataset loaded from backend API
============================================================ */
// ===================== LOCAL FALLBACK CACHE =====================
// The SCHEMES array is populated from the API on page load.
// If the API is unavailable, the local fallback is used.
let SCHEMES = [];
let _schemesLoaded = false;
// ===================== API CONFIG =====================
const DATA_API_BASE = window.SAHYOG_API || "http://localhost:5000/api";
// ===================== LOAD SCHEMES FROM API =====================
async function loadSchemes() {
if (_schemesLoaded && SCHEMES.length > 0) return SCHEMES;
try {
const res = await fetch(`${DATA_API_BASE}/schemes`);
if (res.ok) {
const json = await res.json();
if (json.success && json.data) {
SCHEMES = json.data;
_schemesLoaded = true;
console.log(`[data] Loaded ${SCHEMES.length} schemes from API`);
return SCHEMES;
}
}
} catch (err) {
console.warn("[data] API unavailable, using local fallback:", err.message);
}
// Fallback: use hardcoded data if API fails
if (SCHEMES.length === 0) {
SCHEMES = getLocalFallbackSchemes();
_schemesLoaded = true;
console.log(`[data] Using ${SCHEMES.length} local fallback schemes`);
}
return SCHEMES;
}
/** Send eligibility data to backend for server-side scoring */
async function fetchEligibilityResults(profile) {
try {
const res = await fetch(`${DATA_API_BASE}/schemes/filter`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(profile),
});
if (res.ok) {
const json = await res.json();
if (json.success) {
console.log("[data] Eligibility results from API");
return json;
}
}
} catch (err) {
console.warn("[data] API eligibility check failed, using client-side:", err.message);
}
// Fallback: use client-side scoring from app.js
return null;
}
/** Fetch a single scheme from API */
async function fetchSchemeById(id) {
try {
const res = await fetch(`${DATA_API_BASE}/schemes/${id}`);
if (res.ok) {
const json = await res.json();
if (json.success) return json.data;
}
} catch (err) {
console.warn("[data] API scheme fetch failed, using local:", err.message);
}
// Fallback: search local cache
await loadSchemes();
return SCHEMES.find(s => s.id === parseInt(id)) || null;
}
// ===================== CATEGORIES =====================
const CATEGORIES = {
housing: { label: "Housing", emoji: "🏠", color: "#4f46e5", bg: "#eef2ff" },
health: { label: "Health", emoji: "🏥", color: "#059669", bg: "#ecfdf5" },
education: { label: "Education", emoji: "🎓", color: "#2563eb", bg: "#eff6ff" },
agriculture: { label: "Agriculture", emoji: "🌾", color: "#16a34a", bg: "#f0fdf4" },
finance: { label: "Finance", emoji: "💰", color: "#ca8a04", bg: "#fefce8" },
women: { label: "Women", emoji: "👩", color: "#db2777", bg: "#fdf2f8" },
pension: { label: "Pension", emoji: "🧓", color: "#9333ea", bg: "#faf5ff" },
energy: { label: "Energy", emoji: "🔥", color: "#ea580c", bg: "#fff7ed" },
employment: { label: "Employment", emoji: "💼", color: "#0284c7", bg: "#f0f9ff" },
insurance: { label: "Insurance", emoji: "🛡️", color: "#7c3aed", bg: "#f5f3ff" }
};
const STATES = [
"Andhra Pradesh", "Assam", "Bihar", "Chhattisgarh", "Delhi", "Goa", "Gujarat",
"Haryana", "Himachal Pradesh", "Jharkhand", "Karnataka", "Kerala", "Madhya Pradesh",
"Maharashtra", "Odisha", "Punjab", "Rajasthan", "Tamil Nadu", "Telangana",
"Uttar Pradesh", "Uttarakhand", "West Bengal"
];
// Helper: get scheme by ID from local cache
function getSchemeById(id) {
return SCHEMES.find(s => s.id === parseInt(id));
}
// Helper: capitalize
function capitalize(str) {
if (!str) return "";
return str.charAt(0).toUpperCase() + str.slice(1).replace(/-/g, " ");
}
// ===================== LOCAL FALLBACK DATA =====================
// Minimal inline fallback so the site works without the backend
function getLocalFallbackSchemes() {
return [
{ id:1, name:"Pradhan Mantri Awas Yojana (PMAY)", category:"housing", icon:"🏠", shortDesc:"Affordable housing for all – providing financial assistance for construction or purchase of a pucca house.", benefits:["Subsidy of up to ₹2.67 lakh on home loan interest","Financial assistance up to ₹1.5 lakh for house construction","Special provisions for women-headed households","Coverage in both urban and rural areas"], eligibility:{incomeMax:1800000,ageMin:18,ageMax:70,gender:"all",category:["ews","obc","sc","st","general"],occupation:"all",residence:["urban","rural","semi-urban"],description:"Indian citizen, does not own a pucca house, household income below ₹18 lakh per annum."}, requiredDocuments:["Aadhaar Card","Income Certificate","Address Proof","Bank Account Details","Property Document (if applicable)","Photograph"], tags:["housing","bpl","women","rural"], applicationSteps:["Visit CSC or municipal office","Fill PMAY application form","Submit documents","Verified by authorities","Subsidy credited to bank"] },
{ id:2, name:"PM Kisan Samman Nidhi Yojana", category:"agriculture", icon:"🌾", shortDesc:"Income support of ₹6,000 per year to small and marginal farmers.", benefits:["₹6,000/year in three installments","Direct benefit transfer","No middleman","Covers farming costs"], eligibility:{incomeMax:500000,ageMin:18,ageMax:100,gender:"all",category:["general","obc","sc","st","ews"],occupation:["farmer"],residence:["rural","semi-urban"],description:"Small and marginal farmers with cultivable land up to 2 hectares."}, requiredDocuments:["Aadhaar Card","Land Records","Bank Account","Mobile Number","Domicile Certificate"], tags:["farmer","rural","bpl"], applicationSteps:["Visit pmkisan.gov.in","Register as new farmer","Enter Aadhaar + state","Fill details","Submit"] },
{ id:3, name:"Ayushman Bharat – PMJAY", category:"health", icon:"🏥", shortDesc:"Health coverage of ₹5 lakh per family per year.", benefits:["₹5 lakh coverage","1,393+ procedures","Free treatment","Cashless"], eligibility:{incomeMax:300000,ageMin:0,ageMax:120,gender:"all",category:["sc","st","obc","ews"],occupation:"all",residence:["urban","rural","semi-urban"],description:"BPL families and vulnerable categories."}, requiredDocuments:["Aadhaar Card","Ration Card","Income Certificate","Family ID","Mobile Number"], tags:["health","bpl","sc-st","women","senior"], applicationSteps:["Check on mera.pmjay.gov.in","Visit Ayushman Kendra","Submit documents","Get Ayushman Card","Visit empaneled hospital"] },
{ id:5, name:"PM Mudra Yojana (PMMY)", category:"finance", icon:"💼", shortDesc:"Collateral-free loans up to ₹10 lakh for small businesses.", benefits:["Shishu up to ₹50K","Kishore up to ₹5L","Tarun up to ₹10L","No collateral","Low interest"], eligibility:{incomeMax:1000000,ageMin:18,ageMax:65,gender:"all",category:["general","obc","sc","st","ews"],occupation:["self-employed","business","daily-wage"],residence:["urban","rural","semi-urban"],description:"Small/micro enterprises."}, requiredDocuments:["Aadhaar","PAN","Business Plan","Address Proof","Bank Statements","Photo"], tags:["women","sc-st"], applicationSteps:["Visit bank/NBFC","Fill Mudra form","Submit documents","Bank evaluates","Loan disbursed"] },
{ id:7, name:"PM Scholarship Scheme (PMSS)", category:"education", icon:"🎓", shortDesc:"Scholarships for ex-servicemen's children.", benefits:["₹3,000/month","1-5 years","Professional courses","Direct credit"], eligibility:{incomeMax:600000,ageMin:17,ageMax:25,gender:"all",category:["general","obc","sc","st","ews"],occupation:["student"],residence:["urban","rural","semi-urban"],description:"Wards of ex-servicemen pursuing professional courses."}, requiredDocuments:["Aadhaar","Marksheets","Admission Letter","Bank Details","ESM Certificate","Income Certificate"], tags:["student"], applicationSteps:["Visit KSB portal","Register online","Upload documents","Verified by ZSB","Credited to bank"] },
{ id:14, name:"Senior Citizen Savings Scheme (SCSS)", category:"pension", icon:"🏦", shortDesc:"Guaranteed returns for senior citizens at 8.2% p.a.", benefits:["8.2% interest","Quarterly payout","Up to ₹30L","Tax benefits","5-year tenure"], eligibility:{incomeMax:99999999,ageMin:60,ageMax:120,gender:"all",category:["general","obc","sc","st","ews"],occupation:"all",residence:["urban","rural","semi-urban"],description:"Indian citizen aged 60+."}, requiredDocuments:["Aadhaar","PAN","Age Proof","Bank Details","Photo","Retirement Proof"], tags:["senior"], applicationSteps:["Visit post office/bank","Fill SCSS form","Submit documents","Invest by cheque","Get SCSS passbook"] }
];
}