Skip to content

Commit 21562e6

Browse files
authored
Merge pull request pradanvirudhunagar#34 from akshaykumar059004/main
Fix: Dashboard count, field_insp, date formats
2 parents 4a8516a + caa7264 commit 21562e6

File tree

6 files changed

+92
-33
lines changed

6 files changed

+92
-33
lines changed

controllers/dashboardData.controller.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,21 @@ const getTodayFormsStatusCount_sql = `
5959

6060
exports.getTodayFormsStatusCount = asyncHandler(async (req, res) => {
6161
const connection = await db.getConnection();
62-
const date = new Date();
62+
//const date = new Date();
6363
const user_id = req.query.user_id;
64-
const today = new Date(date.getFullYear(), date.getMonth(), date.getDate()).toLocaleDateString('en-CA');// 'YYYY-MM-DD'
64+
//const today = new Date(date.getFullYear(), date.getMonth(), date.getDate()).toLocaleDateString('en-CA');// 'YYYY-MM-DD'
65+
const getFormattedDate = () => {
66+
const today = new Date();
67+
const day = String(today.getDate()).padStart(2, '0'); // Add leading zero if day < 10
68+
const month = String(today.getMonth() + 1).padStart(2, '0'); // Get month (0-11), so +1
69+
const year = today.getFullYear();
70+
71+
return `${day}/${month}/${year}`;
72+
};
73+
74+
//console.log(getFormattedDate()); // Output: 11/05/2025 (depending on today's date)
75+
76+
const today = getFormattedDate();
6577

6678
try {
6779
const [results] = await connection.execute(getTodayFormsStatusCount_sql, [user_id, today]);

controllers/landformData.controller.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const postLandformData_landdetails_sql = `INSERT INTO form_lands (
1515
patta, total_area, taluk, firka, revenue, crop_season, livestocks,
1616
sf_number, soil_type, land_to_benefit, area_benefited,
1717
type_of_work, any_other_works, p_contribution, f_contribution,
18-
total_est, date_of_ins
19-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
18+
total_est, date_of_ins, field_insp
19+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
2020

2121
const postLandformData_bankdetails_sql = `INSERT INTO bank_details (
2222
form_id, account_holder_name, account_number, bank_name,
@@ -99,7 +99,8 @@ exports.postLandformData = asyncHandler(async (req, res) => {
9999
safe(landformData.landDevelopment.pradanContribution),
100100
safe(landformData.landDevelopment.farmerContribution),
101101
safe(landformData.landDevelopment.totalEstimate),
102-
safe(today)
102+
safe(landformData.landDevelopment.date),
103+
safe(landformData.user_id)
103104
]);
104105

105106
//console.log("form id:", form_id);

controllers/plantationformData.controller.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ exports.postPlantationformData = asyncHandler(async (req, res) => {
3333

3434
try {
3535
const plantationformData = req.body;
36-
const date = new Date();
37-
const today = new Date(date.getFullYear(), date.getMonth(), date.getDate()).toLocaleDateString('en-CA');
36+
// const date = new Date();
37+
// const today = new Date(date.getFullYear(), date.getMonth(), date.getDate()).toLocaleDateString('en-CA');
3838
console.log("Received landform data:", plantationformData);
3939

4040
const safe = (value) => value === undefined ? null : value;
@@ -95,13 +95,13 @@ exports.postPlantationformData = asyncHandler(async (req, res) => {
9595
safe(plantationformData.landDevelopment.sfNumber),
9696
safe(plantationformData.landDevelopment.soilTypeCombined),
9797
safe(plantationformData.landDevelopment.landBenefit),
98-
safe(today),
98+
safe(plantationformData.landDevelopment.date),
9999
safe(plantationformData.landDevelopment.proposalArea),
100100
safe(plantationformData.landDevelopment.otherWorks),
101101
safe(plantationformData.landDevelopment.pradanContribution),
102102
safe(plantationformData.landDevelopment.farmerContribution),
103103
safe(plantationformData.landDevelopment.totalEstimate),
104-
safe(today),
104+
safe(plantationformData.user_id),
105105
safe(plantationformData.landDevelopment.workType2)
106106
]);
107107

@@ -118,7 +118,7 @@ exports.postPlantationformData = asyncHandler(async (req, res) => {
118118
safe(plantationformData.bankDetails.farmerAgreed),
119119
]);
120120

121-
console.log(plantationformData.bankDetails.submittedFiles.patta.name);
121+
//console.log(plantationformData.bankDetails.submittedFiles.patta.name);
122122
//Optional: Insert files if present
123123
if (plantationformData.bankDetails.submittedFiles) {
124124
await connection.execute(postLandformData_files_sql, [

controllers/pondformData.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ exports.postPondformData = asyncHandler(async (req, res) => {
9393
safe(pondformData.landDevelopment.sfNumber),
9494
safe(pondformData.landDevelopment.soilTypeCombined),
9595
safe(pondformData.landDevelopment.landBenefit),
96-
safe(today),
96+
safe(pondformData.landDevelopment.date),
9797
safe(pondformData.landDevelopment.length),
9898
safe(pondformData.landDevelopment.breadth),
9999
safe(pondformData.landDevelopment.depth),
@@ -102,7 +102,7 @@ exports.postPondformData = asyncHandler(async (req, res) => {
102102
safe(pondformData.landDevelopment.farmerContribution),
103103
safe(pondformData.landDevelopment.totalEstimate),
104104
safe(pondformData.landDevelopment.landBenefit),
105-
safe(today)
105+
safe(pondformData.user_id)
106106
]);
107107

108108
//console.log("form id:", form_id);

controllers/previewformsData.controller.js

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const getbasicdetails_sql = `SELECT
4848
forms.panchayat,
4949
forms.hamlet,
5050
forms.id_type as idCardType,
51-
forms.id_number as IdCardNumber,
51+
forms.id_number as idCardNumber,
5252
forms.gender,
5353
forms.spouse as fatherSpouse,
5454
forms.type_of_households as householdType,
@@ -68,18 +68,20 @@ const getbasicdetails_sql = `SELECT
6868
WHERE id = ?
6969
`;
7070

71-
const getbankdetails_sql = ` SELECT
72-
bank_details.account_holder_name AS accountHolderName,
73-
bank_details.account_number AS accountNumber,
74-
bank_details.bank_name AS bankName,
75-
bank_details.branch,
76-
bank_details.ifsc_code AS ifscCode,
77-
bank_details.farmer_ack AS farmerAgreed
78-
FROM bank_details
79-
WHERE id = ?
71+
const getbankdetails_sql = `SELECT
72+
bank_details.account_holder_name AS accountHolderName,
73+
bank_details.account_number AS accountNumber,
74+
bank_details.bank_name AS bankName,
75+
bank_details.branch,
76+
bank_details.ifsc_code AS ifscCode,
77+
bank_details.farmer_ack AS farmerAgreed,
78+
forms.status AS formStatus
79+
FROM bank_details
80+
JOIN forms ON bank_details.form_id = forms.id
81+
WHERE bank_details.id = ?
8082
`;
8183

82-
const getlandownwershipdetails_sql = `SELECT
84+
const getlandownwershipdetail_land_sql = `SELECT
8385
form_lands.ownership AS landOwnershipType,
8486
form_lands.well_irrigation AS hasWell,
8587
form_lands.area_irrigated AS areaIrrigated,
@@ -93,6 +95,36 @@ const getbasicdetails_sql = `SELECT
9395
form_lands.livestocks AS livestockCombined
9496
FROM form_lands
9597
WHERE form_id = ?`;
98+
99+
const getlandownwershipdetail_pond_sql = `SELECT
100+
ownership AS landOwnershipType,
101+
well_irrigation AS hasWell,
102+
area_irrigated AS areaIrrigated,
103+
irrigated_lands AS irrigatedLandCombined,
104+
patta AS pattaNumber,
105+
total_area AS totalArea,
106+
taluk,
107+
firka,
108+
revenue AS revenueVillage,
109+
crop_season AS cropSeasonCombined,
110+
livestocks AS livestockCombined
111+
FROM farm_pond_details
112+
WHERE form_id = ?`;
113+
114+
const getlandownwershipdetail_plant_sql = ` SELECT
115+
ownership AS landOwnershipType,
116+
well_irrigation AS hasWell,
117+
area_irrigated AS areaIrrigated,
118+
irrigated_lands AS irrigatedLandCombined,
119+
patta AS pattaNumber,
120+
total_area AS totalArea,
121+
taluk,
122+
firka,
123+
revenue AS revenueVillage,
124+
crop_season AS cropSeasonCombined,
125+
livestocks AS livestockCombined
126+
FROM plantation_details
127+
WHERE form_id = ?`;
96128

97129
const getlandformdetails_sql = `SELECT
98130
forms.created_at AS date,
@@ -153,8 +185,8 @@ const getbasicdetails_sql = `SELECT
153185
exports.getpreviewspecificformData = asyncHandler( async (req, res) => {
154186
const id = req.query.form_id;
155187
const form_type = req.query.form_type;
156-
console.log("Form ID",id);
157-
console.log("Form type",typeof(form_type));
188+
//console.log("Form ID",id);
189+
//console.log("Form type",typeof(form_type));
158190
const connection = await db.getConnection();
159191

160192
try {
@@ -163,40 +195,54 @@ exports.getpreviewspecificformData = asyncHandler( async (req, res) => {
163195
getbankdetails_sql,
164196
[id]
165197
);
166-
198+
// console.log(bankDetails);
167199
const [[basicDetails]] = await connection.execute(
168200
getbasicdetails_sql,
169201
[id]
170202
);
203+
171204
//fetch based on form type
172205
let landDevelopment;
206+
let landOwnership;
173207
if (form_type == 1) {
174208
//fetch land form
175209
[[landDevelopment]] = await connection.execute(
176210
getlandformdetails_sql,
177211
[id,form_type]
178212
);
213+
[[landOwnership]] = await connection.execute(
214+
getlandownwershipdetail_land_sql,
215+
[id]
216+
);
217+
console.log("land:",landOwnership);
179218
} else if (form_type == 2) {
180219
//fetch pond form
181220
[[landDevelopment]] = await connection.execute(
182221
getpondformdetails_sql,
183222
[id,form_type]
184223
);
224+
[[landOwnership]] = await connection.execute(
225+
getlandownwershipdetail_pond_sql,
226+
[id]
227+
);
228+
console.log("pond:",landOwnership);
185229
} else if (form_type == 3) {
186230
//fetch plantation form
187231
[[landDevelopment]] = await connection.execute(
188232
getplantationformdetails_sql,
189233
[id,form_type]
190234
);
191-
console.log(landDevelopment);
235+
[[landOwnership]] = await connection.execute(
236+
getlandownwershipdetail_plant_sql,
237+
[id]
238+
);
239+
console.log("plantation:",landOwnership);
240+
//console.log(landDevelopment);
192241
} else {
193242
return res.status(400).json({ error: 'Unknown form type' });
194243
}
195244

196-
const [[landOwnership]] = await connection.execute(
197-
getlandownwershipdetails_sql,
198-
[id]
199-
);
245+
200246

201247
// 2. Fetch submitted files from separate table
202248
// const [[submittedFiles]] = await connection.execute(
@@ -226,7 +272,7 @@ exports.getpreviewspecificformData = asyncHandler( async (req, res) => {
226272
landDevelopment,
227273
landOwnership
228274
};
229-
console.log(result);
275+
//console.log(result);
230276
res.json(result);
231277

232278
} catch (err) {

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ app.get("/", (req, res) => {
3030
// const errorHandler = require('./middlewares/errorHandler');
3131
// app.use(errorHandler);
3232

33-
app.listen(PORT, () => {
33+
app.listen(PORT,'0.0.0.0', () => {
3434
console.log(`🚀 Server is running on http://localhost:${PORT}`);
3535
});

0 commit comments

Comments
 (0)