Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,31 +223,31 @@ public String getDailyStockDetailsReport(ItemStockEntryReport entryReport) {
openingStock = ((Number) objects[10]).longValue();
}
Long adjustedQuantity_FromDate = 0L;
if (objects[11] != null) {
adjustedQuantity_FromDate = ((Number) objects[11]).longValue();
if (objects[15] != null) {
adjustedQuantity_FromDate = ((Number) objects[15]).longValue();
}
Long quantityDispanced = 0L;
if (objects[12] != null) {
quantityDispanced = ((Number) objects[12]).longValue();
if (objects[11] != null) {
quantityDispanced = ((Number) objects[11]).longValue();
}
String itemName = (String) objects[13];
String facilityName = (String) objects[14];
String itemCategoryName = (String) objects[15];
String itemName = (String) objects[12];
String facilityName = (String) objects[13];
String itemCategoryName = (String) objects[14];
Long adjustedQuantity_ToDate = 0L;
if (objects[16] != null) {
adjustedQuantity_ToDate = ((Number) objects[16]).longValue();
if (objects[15] != null) {
adjustedQuantity_ToDate = ((Number) objects[15]).longValue();
}
Long adjustedQuantity_ToDate_Receipt = 0L;
if (objects[17] != null) {
adjustedQuantity_ToDate_Receipt = ((Number) objects[17]).longValue();
if (objects[16] != null) {
adjustedQuantity_ToDate_Receipt = ((Number) objects[16]).longValue();
}
Long adjustedQuantity_ToDate_Issue = 0L;
if (objects[18] != null) {
adjustedQuantity_ToDate_Issue = ((Number) objects[18]).longValue();
if (objects[17] != null) {
adjustedQuantity_ToDate_Issue = ((Number) objects[17]).longValue();
}
Long ClosingStock = 0L;
if (objects[19] != null) {
ClosingStock = ((Number) objects[19]).longValue();
if (objects[18] != null) {
ClosingStock = ((Number) objects[18]).longValue();
}


Expand Down Expand Up @@ -421,31 +421,31 @@ public String getMonthlyReport(ItemStockEntryReport entryReport) {
openingStock = ((Number) objects[10]).longValue();
}
Long adjustedQuantity_FromDate = 0L;
if (objects[11] != null) {
adjustedQuantity_FromDate = ((Number) objects[11]).longValue();
if (objects[15] != null) {
adjustedQuantity_FromDate = ((Number) objects[15]).longValue();
}
Long quantityDispanced = 0L;
if (objects[12] != null) {
quantityDispanced = ((Number) objects[12]).longValue();
if (objects[11] != null) {
quantityDispanced = ((Number) objects[11]).longValue();
}
String itemName = (String) objects[13];
String facilityName = (String) objects[14];
String itemCategoryName = (String) objects[15];
String itemName = (String) objects[12];
String facilityName = (String) objects[13];
String itemCategoryName = (String) objects[14];
Long adjustedQuantity_ToDate = 0L;
if (objects[16] != null) {
adjustedQuantity_ToDate = ((Number) objects[16]).longValue();
if (objects[15] != null) {
adjustedQuantity_ToDate = ((Number) objects[15]).longValue();
}
Long adjustedQuantity_ToDate_Receipt = 0L;
if (objects[17] != null) {
adjustedQuantity_ToDate_Receipt = ((Number) objects[17]).longValue();
if (objects[16] != null) {
adjustedQuantity_ToDate_Receipt = ((Number) objects[16]).longValue();
}
Long adjustedQuantity_ToDate_Issue = 0L;
if (objects[18] != null) {
adjustedQuantity_ToDate_Issue = ((Number) objects[18]).longValue();
if (objects[17] != null) {
adjustedQuantity_ToDate_Issue = ((Number) objects[17]).longValue();
}
Long ClosingStock = 0L;
if (objects[19] != null) {
ClosingStock = ((Number) objects[19]).longValue();
if (objects[18] != null) {
ClosingStock = ((Number) objects[18]).longValue();
}
// Long actualOpening = openingStock + adjustedQuantity_FromDate;
Long actualOpening = openingStock;
Expand Down Expand Up @@ -520,57 +520,50 @@ public String getYearlyReport(ItemStockEntryReport entryReport) {
for (Object[] objects : reports) {
if (objects != null && objects.length > 0) {

String batchNo = (String) objects[3];
String batchNo = objects[3] != null ? objects[3].toString() : null;
Long totalQuantityReceived = 0L;
if (objects[4] != null) {
totalQuantityReceived = ((Number) objects[4]).longValue();
totalQuantityReceived = Long.valueOf(objects[4].toString());
}
Double unitCostPrice = 0.0;
if (objects[5] != null) {
unitCostPrice = ((Number) objects[5]).doubleValue();
unitCostPrice = Double.valueOf(objects[5].toString());
}
Date expiryDate = (Date) objects[6];
Long openingStock = 0L;
if (objects[10] != null) {
openingStock = ((Number) objects[10]).longValue();
openingStock = Long.valueOf(objects[10].toString());
}
Long adjustedQuantity_FromDate = 0L;
if (objects[11] != null) {
adjustedQuantity_FromDate = ((Number) objects[11]).longValue();
if (objects[15] != null) {
adjustedQuantity_FromDate = Long.valueOf(objects[15].toString());
}
Long quantityDispanced = 0L;
if (objects[12] != null) {
quantityDispanced = ((Number) objects[12]).longValue();
if (objects[11] != null) {
quantityDispanced = Long.valueOf(objects[11].toString());
}
String itemName = (String) objects[13];
String facilityName = (String) objects[14];
String itemCategoryName = (String) objects[15];
String itemName = objects[12] != null ? objects[12].toString() : null;
String facilityName = objects[13] != null ? objects[13].toString() : null;
String itemCategoryName = objects[14] != null ? objects[14].toString() : null;
Long adjustedQuantity_ToDate = 0L;
if (objects[16] != null) {
adjustedQuantity_ToDate = ((Number) objects[16]).longValue();
if (objects[15] != null) {
adjustedQuantity_ToDate = Long.valueOf(objects[15].toString());
Comment on lines +538 to +550
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | πŸ”΄ Critical

🧩 Analysis chain

🏁 Script executed:

# First, locate and examine the file around lines 538-550
head -560 src/main/java/com/iemr/inventory/service/report/CRMReportServiceImpl.java | tail -30

Repository: PSMRI/Inventory-API

Length of output: 1242


🏁 Script executed:

# Also get more context around this section to understand the field mappings
sed -n '520,560p' src/main/java/com/iemr/inventory/service/report/CRMReportServiceImpl.java

Repository: PSMRI/Inventory-API

Length of output: 1661


🏁 Script executed:

# Find the SQL query or stored procedure that generates these objects
# Look for the method that calls this code
rg -B 30 "adjustedQuantity_FromDate" src/main/java/com/iemr/inventory/service/report/CRMReportServiceImpl.java | head -80

Repository: PSMRI/Inventory-API

Length of output: 2580


🏁 Script executed:

# Search for stored procedures or SQL queries related to daily stock
fd -e sql -o -e SQL | xargs grep -l "dailystock\|DailyStock" 2>/dev/null | head -5

Repository: PSMRI/Inventory-API

Length of output: 179


🏁 Script executed:

# Find the method name and SQL query for lines 538-550
sed -n '490,560p' src/main/java/com/iemr/inventory/service/report/CRMReportServiceImpl.java | grep -B 50 "adjustedQuantity_FromDate"

Repository: PSMRI/Inventory-API

Length of output: 1590


🏁 Script executed:

# Search for SQL queries related to daily stock summary
fd -e sql -o -e SQL | xargs grep -l "DailyStock\|dailystock" 2>/dev/null

Repository: PSMRI/Inventory-API

Length of output: 181


🏁 Script executed:

# Find nativeQuery or `@Query` annotations in the repository
rg -A 15 "@Query|nativeQuery" src/main/java/com/iemr/inventory --type java -g '*Repo*' | grep -A 15 "dailystock\|summary" -i

Repository: PSMRI/Inventory-API

Length of output: 3986


🏁 Script executed:

# Find the PR_StockDetail stored procedure definition
fd -e sql -o -e SQL | xargs grep -l "PR_StockDetail" 2>/dev/null

Repository: PSMRI/Inventory-API

Length of output: 181


🏁 Script executed:

# Search in database folder for the procedure
find . -type f \( -name "*.sql" -o -name "*.SQL" \) | xargs grep -l "StockDetail" 2>/dev/null

Repository: PSMRI/Inventory-API

Length of output: 47


🏁 Script executed:

# Look for stored procedure files in common locations
fd -path "*/db/*" -o -path "*/database/*" -o -path "*/schema/*" | grep -i sql

Repository: PSMRI/Inventory-API

Length of output: 231


🏁 Script executed:

# Search more broadly for SQL files
find . -name "*.sql" 2>/dev/null | head -20

Repository: PSMRI/Inventory-API

Length of output: 45


🏁 Script executed:

# Look for stored procedure definitions in resources or database files
rg "CREATE.*PROCEDURE.*PR_StockDetail\|CREATE.*PROCEDURE.*PR_StockSummary" -i

Repository: PSMRI/Inventory-API

Length of output: 45


🏁 Script executed:

# Check if there are any SQL files at all in the repository
git ls-files | grep -i "\\.sql$"

Repository: PSMRI/Inventory-API

Length of output: 45


🏁 Script executed:

# Let me compare the two methods that use the same stored procedure to identify the correct indices
echo "=== getYearlyReport method indices ==="
sed -n '530,570p' src/main/java/com/iemr/inventory/service/report/CRMReportServiceImpl.java

echo ""
echo "=== getDailyStockDetailsReport method indices (corrected version) ==="
sed -n '450,500p' src/main/java/com/iemr/inventory/service/report/CRMReportServiceImpl.java

Repository: PSMRI/Inventory-API

Length of output: 3578


🏁 Script executed:

# Check what repository method is called by getYearlyReport
sed -n '505,535p' src/main/java/com/iemr/inventory/service/report/CRMReportServiceImpl.java

Repository: PSMRI/Inventory-API

Length of output: 1048


Critical bug: adjustedQuantity_FromDate and adjustedQuantity_ToDate both incorrectly read from objects[15].

Both fields are assigned the same array index. The correct indices should be objects[11] for adjustedQuantity_FromDate and objects[16] for adjustedQuantity_ToDate, as confirmed by the correctly-implemented getDailyStockDetailsReport() method which uses the same PR_StockDetail stored procedure.

Suggested fix
 				Long adjustedQuantity_FromDate = 0L;
-				if (objects[15] != null) {
-					adjustedQuantity_FromDate = Long.valueOf(objects[15].toString());
+				if (objects[11] != null) {
+					adjustedQuantity_FromDate = Long.valueOf(objects[11].toString());
 				}
 				Long quantityDispanced = 0L;
 				if (objects[11] != null) {
 					quantityDispanced = Long.valueOf(objects[11].toString());
 				}
 				String itemName = objects[12] != null ? objects[12].toString() : null;
 				String facilityName = objects[13] != null ? objects[13].toString() : null;
 				String itemCategoryName = objects[14] != null ? objects[14].toString() : null;
 				Long adjustedQuantity_ToDate = 0L;
-				if (objects[15] != null) {
-					adjustedQuantity_ToDate = Long.valueOf(objects[15].toString());
+				if (objects[16] != null) {
+					adjustedQuantity_ToDate = Long.valueOf(objects[16].toString());
 				}
πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/iemr/inventory/service/report/CRMReportServiceImpl.java`
around lines 538 - 550, In CRMReportServiceImpl update the incorrect array index
usages: change the assignment of adjustedQuantity_FromDate to read from
objects[11] instead of objects[15], and change adjustedQuantity_ToDate to read
from objects[16] instead of objects[15]; locate the assignments to the variables
adjustedQuantity_FromDate and adjustedQuantity_ToDate in the block that also
sets quantityDispanced, itemName, facilityName and itemCategoryName and adjust
the indices accordingly, then run the related report/unit tests to verify
mappings against the PR_StockDetail stored procedure.

}
Long adjustedQuantity_ToDate_Receipt = 0L;
if (objects[17] != null) {
adjustedQuantity_ToDate_Receipt = ((Number) objects[17]).longValue();
if (objects[16] != null) {
adjustedQuantity_ToDate_Receipt = Long.valueOf(objects[16].toString());
}
Long adjustedQuantity_ToDate_Issue = 0L;
if (objects[18] != null) {
adjustedQuantity_ToDate_Issue = ((Number) objects[18]).longValue();
if (objects[17] != null) {
adjustedQuantity_ToDate_Issue = Long.valueOf(objects[17].toString());
}
Long ClosingStock = 0L;
if (objects[19] != null) {
ClosingStock = ((Number) objects[19]).longValue();
if (objects[18] != null) {
ClosingStock = Long.valueOf(objects[18].toString());
}
// Long actualOpening = openingStock + adjustedQuantity_FromDate;
Long actualOpening = openingStock;
Long actualDispensed = quantityDispanced;// - adjustedQuantity_ToDate;
Long actualDispensed = quantityDispanced;
Long actualClosing = ClosingStock;
// if (actualOpening == 0 || actualOpening == null) {
// actualClosing = totalQuantityReceived - actualDispensed + adjustedQuantity_ToDate;
// } else {
// actualClosing = actualOpening - actualDispensed + adjustedQuantity_ToDate;
// totalQuantityReceived = 0L;
// }

YearlyReport stockDetail = new YearlyReport();
stockDetail.setSlNo(slNo++);
Expand Down