From ca7fddf552cfb35fab55d21b2051726a75c56e02 Mon Sep 17 00:00:00 2001 From: AJITHKUMAR12 Date: Mon, 15 Dec 2025 10:36:42 +0530 Subject: [PATCH] changed foodscheme report --- .mvn/wrapper/maven-wrapper.properties | 19 - hs_err_pid29312.log | 220 ++ .../configuration/AppConfig.java | 60 + .../configuration/DataSourceConfig.java | 123 +- .../controller/FoodSchemeController.java | 213 ++ .../controller/MainController.java | 16 +- .../service/FoodSchemeService.java | 1865 +++++++++++++++++ src/main/resources/application-dev.properties | 4 +- .../modules/food_scheme/driverreport.html | 430 ++++ .../modules/food_scheme/feedbackreport.html | 706 +++++++ .../modules/food_scheme/foodschemereport.html | 1520 ++++++++++++++ 11 files changed, 5095 insertions(+), 81 deletions(-) delete mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100644 hs_err_pid29312.log create mode 100644 src/main/java/com/gcc/commissionerreview/configuration/AppConfig.java create mode 100644 src/main/java/com/gcc/commissionerreview/controller/FoodSchemeController.java create mode 100644 src/main/java/com/gcc/commissionerreview/service/FoodSchemeService.java create mode 100644 src/main/resources/templates/modules/food_scheme/driverreport.html create mode 100644 src/main/resources/templates/modules/food_scheme/feedbackreport.html create mode 100644 src/main/resources/templates/modules/food_scheme/foodschemereport.html diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index d58dfb7..0000000 --- a/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1,19 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -wrapperVersion=3.3.2 -distributionType=only-script -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip diff --git a/hs_err_pid29312.log b/hs_err_pid29312.log new file mode 100644 index 0000000..304d132 --- /dev/null +++ b/hs_err_pid29312.log @@ -0,0 +1,220 @@ +# +# There is insufficient memory for the Java Runtime Environment to continue. +# Native memory allocation (mmap) failed to map 123731968 bytes for G1 virtual space +# Possible reasons: +# The system is out of physical RAM or swap space +# The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap +# Possible solutions: +# Reduce memory load on the system +# Increase physical memory or swap space +# Check if swap backing store is full +# Decrease Java heap size (-Xmx/-Xms) +# Decrease number of Java threads +# Decrease Java thread stack sizes (-Xss) +# Set larger code cache with -XX:ReservedCodeCacheSize= +# JVM is running with Unscaled Compressed Oops mode in which the Java heap is +# placed in the first 4GB address space. The Java Heap base address is the +# maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress +# to set the Java Heap base and to place the Java Heap above 4GB virtual address. +# This output file may be truncated or incomplete. +# +# Out of Memory Error (os_windows.cpp:3548), pid=29312, tid=28704 +# +# JRE version: (17.0.12+8) (build ) +# Java VM: Java HotSpot(TM) 64-Bit Server VM (17.0.12+8-LTS-286, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64) +# No core dump will be written. Minidumps are not enabled by default on client versions of Windows +# + +--------------- S U M M A R Y ------------ + +Command Line: -XX:+ShowCodeDetailsInExceptionMessages com.gcc.commissionerreview.DashboardserviceApplication + +Host: AMD Ryzen 3 5300U with Radeon Graphics , 8 cores, 7G, Windows 11 , 64 bit Build 22621 (10.0.22621.5415) +Time: Mon Dec 1 16:30:57 2025 India Standard Time elapsed time: 0.029072 seconds (0d 0h 0m 0s) + +--------------- T H R E A D --------------- + +Current thread (0x000001e9c9095530): JavaThread "Unknown thread" [_thread_in_vm, id=28704, stack(0x00000017b7800000,0x00000017b7900000)] + +Stack: [0x00000017b7800000,0x00000017b7900000] +Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) +V [jvm.dll+0x67a04a] +V [jvm.dll+0x7da4ed] +V [jvm.dll+0x7dbe33] +V [jvm.dll+0x7dc4a3] +V [jvm.dll+0x24508f] +V [jvm.dll+0x677089] +V [jvm.dll+0x66bd32] +V [jvm.dll+0x301fa6] +V [jvm.dll+0x309546] +V [jvm.dll+0x359d2e] +V [jvm.dll+0x359f5f] +V [jvm.dll+0x2d9078] +V [jvm.dll+0x2d9fe4] +V [jvm.dll+0x7aca21] +V [jvm.dll+0x367591] +V [jvm.dll+0x78b999] +V [jvm.dll+0x3ec83f] +V [jvm.dll+0x3ee471] +C [jli.dll+0x5297] +C [ucrtbase.dll+0x29333] +C [KERNEL32.DLL+0x1259d] +C [ntdll.dll+0x5af78] + + +--------------- P R O C E S S --------------- + +Threads class SMR info: +_java_thread_list=0x00007ffd7e0b7a18, length=0, elements={ +} + +Java Threads: ( => current thread ) + +Other Threads: + 0x000001e9c90f3fe0 GCTaskThread "GC Thread#0" [stack: 0x00000017b7900000,0x00000017b7a00000] [id=13928] + 0x000001e9c91049c0 ConcurrentGCThread "G1 Main Marker" [stack: 0x00000017b7a00000,0x00000017b7b00000] [id=21488] + 0x000001e9c91053d0 ConcurrentGCThread "G1 Conc#0" [stack: 0x00000017b7b00000,0x00000017b7c00000] [id=26372] + +[error occurred during error reporting (printing all threads), id 0xc0000005, EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffd7d8e9b67] + +VM state: not at safepoint (not fully initialized) + +VM Mutex/Monitor currently owned by a thread: ([mutex/lock_event]) +[0x000001e9c9090970] Heap_lock - owner thread: 0x000001e9c9095530 + +Heap address: 0x000000008ac00000, size: 1876 MB, Compressed Oops mode: 32-bit + +CDS archive(s) mapped at: [0x0000000000000000-0x0000000000000000-0x0000000000000000), size 0, SharedBaseAddress: 0x0000000800000000, ArchiveRelocationMode: 1. +Narrow klass base: 0x0000000000000000, Narrow klass shift: 0, Narrow klass range: 0x0 + +GC Precious Log: + + +Heap: + garbage-first heap total 0K, used 0K [0x000000008ac00000, 0x0000000100000000) + region size 1024K, 0 young (0K), 0 survivors (0K) + +[error occurred during error reporting (printing heap information), id 0xc0000005, EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffd7dcd3859] + +GC Heap History (0 events): +No events + +Deoptimization events (0 events): +No events + +Classes unloaded (0 events): +No events + +Classes redefined (0 events): +No events + +Internal exceptions (0 events): +No events + +VM Operations (0 events): +No events + +Events (1 events): +Event: 0.014 Loaded shared library C:\Program Files\Java\jdk-17\bin\java.dll + + +Dynamic libraries: +0x00007ff678e90000 - 0x00007ff678ea0000 C:\Program Files\Java\jdk-17\bin\java.exe +0x00007ffe2f0d0000 - 0x00007ffe2f2e8000 C:\windows\SYSTEM32\ntdll.dll +0x00007ffe2e0f0000 - 0x00007ffe2e1b4000 C:\windows\System32\KERNEL32.DLL +0x00007ffe2c460000 - 0x00007ffe2c833000 C:\windows\System32\KERNELBASE.dll +0x00007ffe2cc60000 - 0x00007ffe2cd71000 C:\windows\System32\ucrtbase.dll +0x00007ffd7f2e0000 - 0x00007ffd7f2fb000 C:\Program Files\Java\jdk-17\bin\VCRUNTIME140.dll +0x00007ffd7f280000 - 0x00007ffd7f299000 C:\Program Files\Java\jdk-17\bin\jli.dll +0x00007ffe2ec00000 - 0x00007ffe2ecb1000 C:\windows\System32\ADVAPI32.dll +0x00007ffe2efe0000 - 0x00007ffe2f087000 C:\windows\System32\msvcrt.dll +0x00007ffe2e7b0000 - 0x00007ffe2e858000 C:\windows\System32\sechost.dll +0x00007ffe2c1f0000 - 0x00007ffe2c218000 C:\windows\System32\bcrypt.dll +0x00007ffe2ecc0000 - 0x00007ffe2edd8000 C:\windows\System32\RPCRT4.dll +0x00007ffe2d210000 - 0x00007ffe2d3c2000 C:\windows\System32\USER32.dll +0x00007ffe2c8c0000 - 0x00007ffe2c8e6000 C:\windows\System32\win32u.dll +0x00007ffe2ee00000 - 0x00007ffe2ee29000 C:\windows\System32\GDI32.dll +0x00007ffe2c220000 - 0x00007ffe2c33b000 C:\windows\System32\gdi32full.dll +0x00007ffe2c3c0000 - 0x00007ffe2c45a000 C:\windows\System32\msvcp_win.dll +0x00007ffe12620000 - 0x00007ffe128bc000 C:\windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.22621.6060_none_2712eda17382d24b\COMCTL32.dll +0x00007ffe22db0000 - 0x00007ffe22dba000 C:\windows\SYSTEM32\VERSION.dll +0x00007ffe2e0a0000 - 0x00007ffe2e0d1000 C:\windows\System32\IMM32.DLL +0x00007ffd7f2b0000 - 0x00007ffd7f2bc000 C:\Program Files\Java\jdk-17\bin\vcruntime140_1.dll +0x00007ffd7e7a0000 - 0x00007ffd7e82e000 C:\Program Files\Java\jdk-17\bin\msvcp140.dll +0x00007ffd7d600000 - 0x00007ffd7e1e0000 C:\Program Files\Java\jdk-17\bin\server\jvm.dll +0x00007ffe2de60000 - 0x00007ffe2de68000 C:\windows\System32\PSAPI.DLL +0x00007ffd7f270000 - 0x00007ffd7f279000 C:\windows\SYSTEM32\WSOCK32.dll +0x00007ffe2eea0000 - 0x00007ffe2ef11000 C:\windows\System32\WS2_32.dll +0x00007ffe27b70000 - 0x00007ffe27ba4000 C:\windows\SYSTEM32\WINMM.dll +0x00007ffe2b1d0000 - 0x00007ffe2b1e8000 C:\windows\SYSTEM32\kernel.appcore.dll +0x00007ffd7f260000 - 0x00007ffd7f26a000 C:\Program Files\Java\jdk-17\bin\jimage.dll +0x00007ffe242e0000 - 0x00007ffe24513000 C:\windows\SYSTEM32\DBGHELP.DLL +0x00007ffe2e860000 - 0x00007ffe2ebf1000 C:\windows\System32\combase.dll +0x00007ffe2d3d0000 - 0x00007ffe2d4a8000 C:\windows\System32\OLEAUT32.dll +0x00007ffe13910000 - 0x00007ffe13942000 C:\windows\SYSTEM32\dbgcore.DLL +0x00007ffe2c340000 - 0x00007ffe2c3bb000 C:\windows\System32\bcryptPrimitives.dll +0x00007ffd7f230000 - 0x00007ffd7f255000 C:\Program Files\Java\jdk-17\bin\java.dll + +dbghelp: loaded successfully - version: 4.0.5 - missing functions: none +symbol engine: initialized successfully - sym options: 0x614 - pdb path: .;C:\Program Files\Java\jdk-17\bin;C:\windows\SYSTEM32;C:\windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.22621.6060_none_2712eda17382d24b;C:\Program Files\Java\jdk-17\bin\server + +VM Arguments: +jvm_args: -XX:+ShowCodeDetailsInExceptionMessages +java_command: com.gcc.commissionerreview.DashboardserviceApplication +java_class_path (initial): C:\Commisoner review may 2025\commissioner_review_1_may2025\target\classes;C:\Users\Ajith\.m2\repository\org\springframework\boot\spring-boot-starter-data-jdbc\3.4.5\spring-boot-starter-data-jdbc-3.4.5.jar;C:\Users\Ajith\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\3.4.5\spring-boot-starter-jdbc-3.4.5.jar;C:\Users\Ajith\.m2\repository\com\zaxxer\HikariCP\5.1.0\HikariCP-5.1.0.jar;C:\Users\Ajith\.m2\repository\org\springframework\spring-jdbc\6.2.6\spring-jdbc-6.2.6.jar;C:\Users\Ajith\.m2\repository\org\springframework\data\spring-data-jdbc\3.4.5\spring-data-jdbc-3.4.5.jar;C:\Users\Ajith\.m2\repository\org\springframework\data\spring-data-relational\3.4.5\spring-data-relational-3.4.5.jar;C:\Users\Ajith\.m2\repository\org\springframework\data\spring-data-commons\3.4.5\spring-data-commons-3.4.5.jar;C:\Users\Ajith\.m2\repository\org\springframework\spring-tx\6.2.6\spring-tx-6.2.6.jar;C:\Users\Ajith\.m2\repository\org\springframework\spring-context\6.2.6\spring-context-6.2.6.jar;C:\Users\Ajith\.m2\repository\org\springframework\spring-beans\6.2.6\spring-beans-6.2.6.jar;C:\Users\Ajith\.m2\repository\org\slf4j\slf4j-api\2.0.17\slf4j-api-2.0.17.jar;C:\Users\Ajith\.m2\repository\org\springframework\boot\spring-boot-starter-thymeleaf\3.4.5\spring-boot-starter-thymeleaf-3.4.5.jar;C:\Users\Ajith\.m2\repository\org\springframework\boot\spring-boot-starter\3.4.5\spring-boot-starter-3.4.5.jar;C:\Users\Ajith\.m2\repository\org\springframework\boot\spring-boot-starter-logging\3.4.5\spring-boot-starter-logging-3.4.5.jar;C:\Users\Ajith\.m2\repository\ch\qos\logback\logback-classic\1.5.18\logback-classic-1.5.18.jar;C:\Users\Ajith\.m2\repository\ch\qos\logback\logback-core\1.5.18\logback-core-1.5.18.jar;C:\Users\Ajith\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.24.3\log4j-to-slf4j-2.24.3.jar;C:\Users\Ajith\.m2\repository\org\apache\logging\log4j\log4j-api\2.24.3\log4j-api-2.24.3.jar;C:\Users\Ajith\.m2\repository\org\slf4j\jul-t +Launcher Type: SUN_STANDARD + +[Global flags] + intx CICompilerCount = 4 {product} {ergonomic} + uint ConcGCThreads = 2 {product} {ergonomic} + uint G1ConcRefinementThreads = 8 {product} {ergonomic} + size_t G1HeapRegionSize = 1048576 {product} {ergonomic} + uintx GCDrainStackTargetSize = 64 {product} {ergonomic} + size_t InitialHeapSize = 123731968 {product} {ergonomic} + size_t MarkStackSize = 4194304 {product} {ergonomic} + size_t MaxHeapSize = 1967128576 {product} {ergonomic} + size_t MinHeapDeltaBytes = 1048576 {product} {ergonomic} + size_t MinHeapSize = 8388608 {product} {ergonomic} + uintx NonNMethodCodeHeapSize = 5839372 {pd product} {ergonomic} + uintx NonProfiledCodeHeapSize = 122909434 {pd product} {ergonomic} + uintx ProfiledCodeHeapSize = 122909434 {pd product} {ergonomic} + uintx ReservedCodeCacheSize = 251658240 {pd product} {ergonomic} + bool SegmentedCodeCache = true {product} {ergonomic} + bool ShowCodeDetailsInExceptionMessages = true {manageable} {command line} + size_t SoftMaxHeapSize = 1967128576 {manageable} {ergonomic} + bool UseCompressedClassPointers = true {product lp64_product} {ergonomic} + bool UseCompressedOops = true {product lp64_product} {ergonomic} + bool UseG1GC = true {product} {ergonomic} + bool UseLargePagesIndividualAllocation = false {pd product} {ergonomic} + +Logging: +Log output configuration: + #0: stdout all=warning uptime,level,tags + #1: stderr all=off uptime,level,tags + +Environment Variables: +PATH=c:\Users\Ajith\AppData\Roaming\Code\User\globalStorage\github.copilot-chat\debugCommand;c:\Users\Ajith\AppData\Roaming\Code\User\globalStorage\github.copilot-chat\copilotCli;C:\Program Files\Common Files\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files\Docker\Docker\resources\bin;C:\Program Files\Java\jdk-17\bin;C:\Program Files\nodejs\;C:\Program Files (x86)\Microsoft SQL Server\160\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\160\Tools\Binn\;C:\Program Files\Microsoft SQL Server\160\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Microsoft SQL Server\160\DTS\Binn\;C:\Program Files\Apache\Maven\apache-maven-3.9.11\bin;C:\Users\Ajith\AppData\Local\Programs\Python\Python313\Scripts\;C:\Users\Ajith\AppData\Local\Programs\Python\Python313\;C:\Users\Ajith\AppData\Local\Programs\Python\Python312\Scripts\;C:\Users\Ajith\AppData\Local\Programs\Python\Python312\;C:\Users\Ajith\AppData\Local\Programs\Python\Launcher\;C:\Users\Ajith\AppData\Local\Microsoft\WindowsApps;C:\Users\Ajith\AppData\Local\Programs\Git\cmd;C:\Users\Ajith\Desktop;C:\Users\Ajith\Desktop\demo\terraform;C:\Users\Ajith\AppData\Roaming\npm;C:\Users\Ajith\AppData\Local\GitHubDesktop\bin;C:\Users\Ajith\AppData\Local\Programs\Microsoft VS Code\bin;c:\Users\Ajith\.vscode\extensions\vscjava.vscode-java-debug-0.58.3\bundled\scripts\noConfigScripts +USERNAME=Ajith +LANG=en_US.UTF-8 +OS=Windows_NT +PROCESSOR_IDENTIFIER=AMD64 Family 23 Model 104 Stepping 1, AuthenticAMD + + + +--------------- S Y S T E M --------------- + +OS: + Windows 11 , 64 bit Build 22621 (10.0.22621.5415) +OS uptime: 4 days 23:37 hours +Hyper-V role detected + +CPU: total 8 (initial active 8) (8 cores per cpu, 2 threads per core) family 23 model 104 stepping 1 microcode 0x0, cx8, cmov, fxsr, ht, mmx, 3dnowpref, sse, sse2, sse3, ssse3, sse4a, sse4.1, sse4.2, popcnt, lzcnt, tsc, tscinvbit, avx, avx2, aes, clmul, bmi1, bmi2, adx, sha, fma, vzeroupper, clflush, clflushopt, hv + +Memory: 4k page, system-wide physical 7502M (201M free) +TotalPageFile size 30030M (AvailPageFile size 94M) +current process WorkingSet (physical memory assigned to process): 11M, peak: 11M +current process commit charge ("private bytes"): 60M, peak: 178M + +vm_info: Java HotSpot(TM) 64-Bit Server VM (17.0.12+8-LTS-286) for windows-amd64 JRE (17.0.12+8-LTS-286), built on Jun 5 2024 06:46:59 by "mach5one" with MS VC++ 17.6 (VS2022) + +END. diff --git a/src/main/java/com/gcc/commissionerreview/configuration/AppConfig.java b/src/main/java/com/gcc/commissionerreview/configuration/AppConfig.java new file mode 100644 index 0000000..6426667 --- /dev/null +++ b/src/main/java/com/gcc/commissionerreview/configuration/AppConfig.java @@ -0,0 +1,60 @@ +package com.gcc.commissionerreview.configuration; + +import org.springframework.beans.factory.annotation.Value; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + + +@Component +@ConfigurationProperties(prefix = "app") +public class AppConfig { + + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + + private String title; + private String baseUrl; + private String getOtpUrl; + private String erpUrl; + + + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getBaseUrl() { + return baseUrl; + } + + public void setBaseUrl(String baseUrl) { + this.baseUrl = baseUrl; + } + + public String getGetOtpUrl() { + return getOtpUrl; + } + + public void setGetOtpUrl(String getOtpUrl) { + this.getOtpUrl = getOtpUrl; + } + + public String getErpUrl() { + return erpUrl; + } + + public void setErpUrl(String erpUrl) { + this.erpUrl = erpUrl; + } + +} \ No newline at end of file diff --git a/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java b/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java index 18485cb..f6474c4 100644 --- a/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java +++ b/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java @@ -1,6 +1,5 @@ package com.gcc.commissionerreview.configuration; - import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; @@ -19,66 +18,74 @@ import javax.sql.DataSource; @Configuration @EnableTransactionManagement public class DataSourceConfig { - - -// private static String host = "localhost:3306"; -// private static String dbpassword = "root"; - - - private static String host = "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; - private static String dbpassword = "gcc-facial-password"; - - public static class MyDataSourceConfig { - @Primary - @Bean(name = "mydatasource") - public DataSource MyDataSource() { -// DriverManagerDataSource dataSource = new DriverManagerDataSource(); -// dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); -// dataSource.setUrl("jdbc:mysql://"+host+"/dashboard_service"); -// dataSource.setUsername("root"); -// dataSource.setPassword("root"); -// return dataSource; - - DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setUrl("jdbc:mysql://"+host+"/commissioner_review"); - //dataSource.setUrl("jdbc:mysql://"+host+"/dashboard_service"); - dataSource.setUsername("root"); - dataSource.setPassword(dbpassword); - dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); - return dataSource; - - - } - - @Primary - @Bean(name = "myTransactionManager") - public PlatformTransactionManager myTransactionManager(@Qualifier("mydatasource") DataSource dataSource) { - return new DataSourceTransactionManager(dataSource); - } - } - - ////////////////////////////// Domestic Waste Management //////////////////////// - @Bean(name = "mysqlSofaBedCollectionDataSource") - public DataSource mysqlSofaBedCollectionDataSource() { - DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); - dataSource.setUrl("jdbc:mysql://"+host+"/domestic_waste_management"); - dataSource.setUsername("root"); - dataSource.setPassword(dbpassword); - return dataSource; - } + private static String host = "localhost:3306"; + private static String dbpassword = "root"; + + // private static String host = + // "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; + // private static String dbpassword = "gcc-facial-password"; + + public static class MyDataSourceConfig { + @Primary + @Bean(name = "mydatasource") + + public DataSource MyDataSource() { + // DriverManagerDataSource dataSource = new DriverManagerDataSource(); + // dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); + // dataSource.setUrl("jdbc:mysql://"+host+"/dashboard_service"); + // dataSource.setUsername("root"); + // dataSource.setPassword("root"); + // return dataSource; - - //////////////////////////////ORACLE //////////////////////// - @Bean(name = "oracleDataSource") - public DataSource oracleDataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName("oracle.jdbc.OracleDriver"); - dataSource.setUrl("jdbc:oracle:thin:@10.1.0.14:1521:chncorp"); - dataSource.setUsername("FAS"); - dataSource.setPassword("FAS"); + dataSource.setUrl("jdbc:mysql://" + host + "/commissioner_review"); + // dataSource.setUrl("jdbc:mysql://"+host+"/dashboard_service"); + dataSource.setUsername("root"); + dataSource.setPassword(dbpassword); + dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); return dataSource; + } -} + @Primary + @Bean(name = "myTransactionManager") + public PlatformTransactionManager myTransactionManager(@Qualifier("mydatasource") DataSource dataSource) { + return new DataSourceTransactionManager(dataSource); + } + } + + ////////////////////////////// Domestic Waste Management + ////////////////////////////// //////////////////////// + @Bean(name = "mysqlSofaBedCollectionDataSource") + public DataSource mysqlSofaBedCollectionDataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); + dataSource.setUrl("jdbc:mysql://" + host + "/domestic_waste_management"); + dataSource.setUsername("root"); + dataSource.setPassword(dbpassword); + return dataSource; + } + + ////////////////////////////// Food distribution //////////////////////// + @Bean(name = "mysqlFoodDistributionDataSource") + public DataSource mysqlFoodDistributionDataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); + dataSource.setUrl("jdbc:mysql://" + host + "/gcc_food_distribution"); + dataSource.setUsername("root"); + dataSource.setPassword(dbpassword); + return dataSource; + } + + ////////////////////////////// ORACLE //////////////////////// + @Bean(name = "oracleDataSource") + public DataSource oracleDataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("oracle.jdbc.OracleDriver"); + dataSource.setUrl("jdbc:oracle:thin:@10.1.0.14:1521:chncorp"); + dataSource.setUsername("FAS"); + dataSource.setPassword("FAS"); + return dataSource; + } +} diff --git a/src/main/java/com/gcc/commissionerreview/controller/FoodSchemeController.java b/src/main/java/com/gcc/commissionerreview/controller/FoodSchemeController.java new file mode 100644 index 0000000..d0979e0 --- /dev/null +++ b/src/main/java/com/gcc/commissionerreview/controller/FoodSchemeController.java @@ -0,0 +1,213 @@ +package com.gcc.commissionerreview.controller; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.gcc.commissionerreview.service.FoodSchemeService; + +@RestController +@RequestMapping("/commissionerreview/api") +public class FoodSchemeController { + + @Autowired + private FoodSchemeService foodSchemeService; + + /* + * @GetMapping("/feedback-summary") + * public List> getFeedbackSummary(@RequestParam String + * date) { + * return feedbackService.getFeedbackSummary(date); + * } + * + * @GetMapping("/driver-report") + * public List> getDriverReport(@RequestParam String date) { + * //System.out.println("Date received in controller: " + date); + * return feedbackService.getDriverReport(date); + * } + */ + // ak + @GetMapping("/feedback-summary") + public ResponseEntity getFeedbackSummary(@RequestParam String date) { + try { + List> data = foodSchemeService.getFeedbackSummary(date); + + Map response = new HashMap<>(); + response.put("status", "success"); + response.put("date", date); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + Map error = new HashMap<>(); + error.put("status", "error"); + error.put("message", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); + } + } + + // ak + @GetMapping("/zone-details") + public ResponseEntity getZoneDetails( + @RequestParam int qid, + @RequestParam String column, + @RequestParam String date) { + + try { + List> data = foodSchemeService.getZoneDetails(qid, column, date); + + Map response = new HashMap<>(); + response.put("status", "success"); + response.put("date", date); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + Map error = new HashMap<>(); + error.put("status", "error"); + error.put("message", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); + } + } + + + + @GetMapping("/ward-details") + public ResponseEntity getWardDetails( + @RequestParam int qid, + @RequestParam String column, + @RequestParam String date, + @RequestParam int zoneId) { + + return ResponseEntity.ok(Map.of( + "status", "success", + "date", date, + "data", foodSchemeService.getWardDetails(qid, column, date, zoneId))); + } + + @GetMapping("/driver-report") + public ResponseEntity getDriverReport(@RequestParam String date, @RequestParam(required = false) Integer zone) { + try { + List> data = foodSchemeService.getDriverReport(date, zone); + + Map response = new HashMap<>(); + response.put("status", "success"); + response.put("date", date); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + Map error = new HashMap<>(); + error.put("status", "error"); + error.put("message", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); + } + } + + @GetMapping("/zones") + public ResponseEntity getZones() { + List> data = foodSchemeService.getZones(); + return ResponseEntity.ok(Map.of("data", data)); + } + + /// yogi + @GetMapping("/abstract") + public ResponseEntity getAbstractReport(@RequestParam String date) { + try { + List> report = foodSchemeService.getAbstractReport(date); + // System.out.println("report : " + report); + + Map response = new HashMap<>(); + response.put("status", "success"); + response.put("date", date); + response.put("data", report); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + Map error = new HashMap<>(); + error.put("status", "error"); + error.put("message", e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); + } + } + + @GetMapping("/zoneandshiftbasedreport") + public ResponseEntity getZoneWiseShiftBasedReport(@RequestParam String date, @RequestParam Integer shiftId) { + try { + List> report = foodSchemeService.getZoneWiseShiftBasedReport(date, shiftId); + // System.out.println("report : " + report); + + Map response = new HashMap<>(); + response.put("status", "success"); + response.put("date", date); + response.put("data", report); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + Map error = new HashMap<>(); + error.put("status", "error"); + error.put("message", e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); + } + } + + @GetMapping("/wardwiseShiftReport") + public ResponseEntity getWardWiseShiftReport( + @RequestParam String date, + @RequestParam Integer shiftId, + @RequestParam Integer zone) { + + try { + List> data = foodSchemeService.getWardWiseShiftReport(shiftId, zone, date); + + Map response = new HashMap<>(); + response.put("status", "success"); + response.put("zone", zone); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + Map error = new HashMap<>(); + error.put("status", "error"); + error.put("message", e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); + } + } + + @GetMapping("/wardlocationreport") + public ResponseEntity getWardLocationReport(@RequestParam String date) { + try { + List> report = foodSchemeService.getWardLocationWiseReport(date); + + Map response = new HashMap<>(); + response.put("status", "success"); + response.put("date", date); + response.put("data", report); + + return ResponseEntity.ok(response); + } catch (Exception e) { + Map error = new HashMap<>(); + error.put("status", "error"); + error.put("message", e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); + } + } + +} diff --git a/src/main/java/com/gcc/commissionerreview/controller/MainController.java b/src/main/java/com/gcc/commissionerreview/controller/MainController.java index 07e1c15..1c35d8e 100644 --- a/src/main/java/com/gcc/commissionerreview/controller/MainController.java +++ b/src/main/java/com/gcc/commissionerreview/controller/MainController.java @@ -1,7 +1,7 @@ package com.gcc.commissionerreview.controller; -import org.springframework.ui.Model; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -163,6 +163,20 @@ public class MainController { public String viewpendingdetails(Model model) { return "modules/sofa_bed/pendingdetails"; } + @GetMapping("/foodSchemeReport") + public String foodSchemereport(Model model) { + return "modules/food_scheme/foodschemereport"; + } + + @GetMapping("/feedbackreport") + public String feedbackreport(Model model) { + return "modules/food_scheme/feedbackreport"; + } + + @GetMapping("/driverreport") + public String driverreport(Model model) { + return "modules/food_scheme/driverreport"; + } } diff --git a/src/main/java/com/gcc/commissionerreview/service/FoodSchemeService.java b/src/main/java/com/gcc/commissionerreview/service/FoodSchemeService.java new file mode 100644 index 0000000..95ec871 --- /dev/null +++ b/src/main/java/com/gcc/commissionerreview/service/FoodSchemeService.java @@ -0,0 +1,1865 @@ +package com.gcc.commissionerreview.service; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import javax.imageio.ImageIO; +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Service; +import java.net.URL; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import javax.imageio.ImageIO; + +import java.util.Arrays; +import java.util.Base64; +import java.util.concurrent.ConcurrentHashMap; +import java.util.Map; + +import com.gcc.commissionerreview.configuration.AppConfig; + +@Service +public class FoodSchemeService { + + @Autowired + private JdbcTemplate jdbcTemplate; + @Autowired + private Environment environment; + @Autowired + private AppConfig appConfig; + + @Autowired + @Value("${fileBaseUrl}") + + private String fileBaseUrl; + + // ak for pdf image render + // private final Map imageCache = new ConcurrentHashMap<>(); + + @Autowired + public void setFeedbackDataSource(@Qualifier("mysqlFoodDistributionDataSource") DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + public FoodSchemeService(Environment environment) { + + this.environment = environment; + + this.fileBaseUrl = environment.getProperty("fileBaseUrl"); + } + /* + * private String convertUrlToBase64(String url) { + * try { + * if (imageCache.containsKey(url)) { + * return imageCache.get(url); + * } + * + * URL imageUrl = new URL(url); + * BufferedImage image = ImageIO.read(imageUrl); + * + * ByteArrayOutputStream baos = new ByteArrayOutputStream(); + * ImageIO.write(image, "jpeg", baos); + * + * String base64 = "data:image/jpeg;base64," + + * Base64.getEncoder().encodeToString(baos.toByteArray()); + * + * imageCache.put(url, base64); + * return base64; + * + * } catch (Exception e) { + * e.printStackTrace(); + * return null; + * } + * } + */ + + public List> getFeedbackSummary(String date) { + + String sql = "SELECT " + + " fq.qid, " + + " fq.question, " + + "fq.qid, " + + + " SUM(CASE WHEN fq.qid = 1 AND fd.q1 = '1' THEN 1 ELSE 0 END) AS on_time_distribution, " + + " SUM(CASE WHEN fq.qid = 1 AND fd.q1 = '2' THEN 1 ELSE 0 END) AS delayeded, " + + + " SUM(CASE WHEN fq.qid = 2 AND fd.q2 = '3' THEN 1 ELSE 0 END) AS good, " + + " SUM(CASE WHEN fq.qid = 2 AND fd.q2 = '4' THEN 1 ELSE 0 END) AS average, " + + + " SUM(CASE WHEN fq.qid = 3 AND fd.q3 = '5' THEN 1 ELSE 0 END) AS sufficient_food_quantity, " + + " SUM(CASE WHEN fq.qid = 3 AND fd.q3 = '6' THEN 1 ELSE 0 END) AS less_quantity " + + + "FROM feedback_questions fq " + // ← space added + "LEFT JOIN feedback_data fd " + // ← space added + " ON fd.isactive = 1 " + // ← space added + " AND fd.isdelete = 0 " + // ← space added + " AND DATE(fd.feedback_date) = ? " + // ← space added + + "WHERE fq.isactive = 1 " + + "AND fq.isdelete = 0 " + + + "GROUP BY fq.qid, fq.question " + + "ORDER BY fq.orderby"; + + return jdbcTemplate.queryForList(sql, date); + + } + + // ak + public List> getZoneDetails(int qid, String column, String date) { + + String sql = "SELECT lm.zone, fq.qid, fq.question, " + + "SUM(CASE " + + " WHEN ? = 'on_time_distribution' AND fd.q1 = '1' THEN 1 " + + " WHEN ? = 'delayeded' AND fd.q1 = '2' THEN 1 " + + + " WHEN ? = 'good' AND fd.q2 = '3' THEN 1 " + + " WHEN ? = 'average' AND fd.q2 = '4' THEN 1 " + + + " WHEN ? = 'sufficient_food_quantity' AND fd.q3 = '5' THEN 1 " + + " WHEN ? = 'less_quantity' AND fd.q3 = '6' THEN 1 " + + " ELSE 0 END) AS count_value " + + + "FROM feedback_data fd " + + "INNER JOIN location_mapping lm ON fd.feedback_by = lm.siloginid " + + "INNER JOIN feedback_questions fq ON fq.qid = ? " + + + "WHERE fd.isactive = 1 " + + "AND fd.isdelete = 0 " + + "AND DATE(fd.feedback_date) = ? " + + + "GROUP BY lm.zone, fq.qid, fq.question " + + "ORDER BY lm.zone"; + + return jdbcTemplate.queryForList( + sql, + column, column, column, column, column, column, // 6 column comparisons + qid, // qid + date // date + ); + } + + /* + * public List> getZoneDetails(int qid, String column, + * String date) { + * + * String sql = "SELECT lm.zone, fq.qid, fq.question, " + + * "SUM(CASE " + + * " WHEN ? = 'on_time_distribution' AND fd.q1 = '1' THEN 1 " + + * " WHEN ? = 'delayeded' AND fd.q1 = '2' THEN 1 " + + * + * " WHEN ? = 'good' AND fd.q2 = '3' THEN 1 " + + * " WHEN ? = 'average' AND fd.q2 = '4' THEN 1 " + + * + * " WHEN ? = 'sufficient_food_quantity' AND fd.q3 = '5' THEN 1 " + + * " WHEN ? = 'less_quantity' AND fd.q3 = '6' THEN 1 " + + * " ELSE 0 END) AS count_value " + + * + * "FROM location_mapping lm " + + * "LEFT JOIN feedback_data fd ON fd.feedback_by = lm.siloginid " + + * " AND fd.isactive = 1 " + + * " AND fd.isdelete = 0 " + + * " AND DATE(fd.feedback_date) = ? " + + * + * "LEFT JOIN feedback_questions fq ON fq.qid = ? " + + * + * "GROUP BY lm.zone, fq.qid, fq.question " + + * "ORDER BY lm.zone"; + * + * return jdbcTemplate.queryForList(sql, + * column, column, column, column, column, column, // bind 6 times + * date, // date + * qid // qid + * ); + * } + */ + + public List> getDriverReport(String date, Integer zone) { + // System.out.println("File Base URL: " + fileBaseUrl);. + String zoneCondition = ""; + if (zone != null) { + zoneCondition = " AND lm.zone = " + zone + " "; + } + System.out.println("zoneCondition: " + zone); + + String sql = "SELECT lm.location AS LocationDescription, " + + "dl.username AS DriverName, " + + "lm.zone AS Zone, " + + "lm.ward AS Ward, " + + "SUBSTRING(dss_start.driver_live_mobile, 4) AS DriverMobile, " + + "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', dss_start.image) AS StartImage, " + + // "CONCAT(dss_start.latitude, ', ', dss_start.longitude) AS StartPoint, " + + "dss_start.address AS StartAddress, " + + + // "DATE_FORMAT(dss_start.datetime, '%Y-%m-%d %H:%i') AS StartTime, " + + "DATE_FORMAT(dss_start.datetime, '%h:%i %p') AS StartTime," + + // "CONCAT(dss_stop.latitude, ', ', dss_stop.longitude) AS EndPoint, " + + "dss_stop.address AS EndAddress, " + + "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', dss_stop.image) AS EndImage, " + + // "DATE_FORMAT(dss_stop.datetime, '%Y-%m-%d %H:%i') AS EndTime " + + "DATE_FORMAT(dss_stop.datetime, '%h:%i %p') AS EndTime " + + + "FROM location_mapping lm " + + "INNER JOIN driver_login dl ON dl.loginid = lm.driverid " + + + "LEFT JOIN driver_start_stop dss_start " + + "ON dss_start.loginid = lm.driverid " + + "AND dss_start.action = 'Start' " + + + "LEFT JOIN driver_start_stop dss_stop " + + "ON dss_stop.loginid = lm.driverid " + + "AND dss_stop.action = 'Stop' " + + "AND dss_stop.startid = dss_start.locationid " + + + "WHERE DATE(dss_start.datetime) = ?" + zoneCondition + + "order by dss_start.datetime"; + + return jdbcTemplate.queryForList(sql, date); + } + + public List> getZones() { + String sql = "SELECT DISTINCT zone FROM location_mapping "; + return jdbcTemplate.queryForList(sql); + } + + // yogi used has old without isactive isdelete + // public List> getAbstractReport(String date) { + + // String sql = """ + // SELECT * FROM ( + + // SELECT + + // sm.name AS shift_name, + // sm.Code as shift_code, + // sm.shiftid as shiftid, + // IFNULL(SUM(gru.total_food_requested), 0) AS food_requested, + // IFNULL(SUM(gru.total_food_received), 0) AS food_delivered, + // IFNULL(SUM(dr.nulm + dr.private + dr.permanent), 0) AS overall_count, + // IFNULL(SUM(dr.nulm + dr.private + dr.permanent), 0) AS present_count, + // IFNULL(SUM(gru.today_absentees_nulm + gru.today_absentees_private + + // gru.today_absentees_permanent), 0) AS unplanned_count, + // IFNULL(SUM(dr.absentees_nulm + dr.absentees_private + + // dr.absentees_permanent), 0) AS absent_count, + // IFNULL(SUM(gru.total_box_shortfall), 0) AS food_shortfall + // FROM shift_master sm + // LEFT JOIN daily_request dr + // ON sm.shiftid = dr.shiftid AND dr.required_date = ? + // LEFT JOIN gcc_received_update gru + // ON gru.requestid = dr.requestid + // GROUP BY sm.shiftid, sm.name + + // UNION ALL + + // SELECT + // 'Total' AS shift_name, + // 'TOTAL' AS shift_code, + // 'TOTAL' as shift_id, + // IFNULL(SUM(gru.total_food_requested), 0), + // IFNULL(SUM(gru.total_food_received), 0), + // IFNULL(SUM(dr.nulm + dr.private + dr.permanent), 0), + // IFNULL(SUM(dr.nulm + dr.private + dr.permanent), 0), + // IFNULL(SUM(gru.today_absentees_nulm + gru.today_absentees_private + + // gru.today_absentees_permanent), 0), + // IFNULL(SUM(dr.absentees_nulm + dr.absentees_private + + // dr.absentees_permanent), 0), + // IFNULL(SUM(gru.total_box_shortfall), 0) + // FROM shift_master sm + // LEFT JOIN daily_request dr + // ON sm.shiftid = dr.shiftid AND dr.required_date = ? + // LEFT JOIN gcc_received_update gru + // ON gru.requestid = dr.requestid + // ) AS final_result + // """; + + // return jdbcTemplate.queryForList(sql, date, date); + // } + + // new abstract report old + // public List> getAbstractReport(String date) { + + // String sql = """ + // SELECT * FROM ( + + // /* ================= SHIFT-WISE SUMMARY ================= */ + // SELECT + // sm.name AS shift_name, + // sm.code AS shift_code, + // sm.shiftid AS shiftid, + + // /* ---------------- TOTAL COMPLEMENT ---------------- */ + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) AS + // total_complement, + + // /* ---------------- WEEKLY OFF ---------------- */ + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + + // dr.weeklyoff_others + dr.weeklyoff_nmr), 0) AS weekly_off, + + // /* ---------------- PLANNED LEAVE ---------------- */ + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + + // dr.absentees_others + dr.absentees_nmr), 0) AS planned_leave, + + // /* ---------------- PRESENT COUNT ---------------- */ + // ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + // - + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + + // dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // - + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + + // dr.absentees_others + dr.absentees_nmr), 0) + // ) AS present_count, + + // /* ---------------- FOOD REQUESTED ---------------- */ + // ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + // - + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + + // dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // - + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + + // dr.absentees_others + dr.absentees_nmr), 0) + // ) AS food_requested, + + // /* ---------------- FOOD DELIVERED ---------------- */ + // IFNULL(SUM(gru.total_food_received), 0) AS food_delivered, + + // /* ---------------- FOOD SHORTFALL ---------------- */ + // ( + // ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + // - + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + + // dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // - + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + + // dr.absentees_others + dr.absentees_nmr), 0) + // ) + // - + // IFNULL(SUM(gru.total_food_received), 0) + // ) AS food_shortfall + + // FROM shift_master sm + // LEFT JOIN daily_request dr + // ON sm.shiftid = dr.shiftid AND dr.required_date = ? + // LEFT JOIN gcc_received_update gru + // ON gru.requestid = dr.requestid + // WHERE sm.isactive = 1 AND sm.isdelete = 0 + // GROUP BY sm.shiftid, sm.name + + // UNION ALL + + // /* ================= TOTAL SUMMARY ================= */ + // SELECT + // 'Total' AS shift_name, + // 'TOTAL' AS shift_code, + // 'TOTAL' AS shiftid, + + // /* TOTAL COMPLEMENT */ + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0), + + // /* WEEKLY OFF */ + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + + // dr.weeklyoff_others + dr.weeklyoff_nmr), 0), + + // /* PLANNED LEAVE */ + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + + // dr.absentees_others + dr.absentees_nmr), 0), + + // /* PRESENT COUNT */ + // ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + // - + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + + // dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // - + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + + // dr.absentees_others + dr.absentees_nmr), 0) + // ), + + // /* FOOD REQUESTED */ + // ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + // - + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + + // dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // - + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + + // dr.absentees_others + dr.absentees_nmr), 0) + // ), + + // /* FOOD DELIVERED */ + // IFNULL(SUM(gru.total_food_received), 0), + + // /* FOOD SHORTFALL */ + // ( + // ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + // - + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + + // dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // - + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + + // dr.absentees_others + dr.absentees_nmr), 0) + // ) + // - + // IFNULL(SUM(gru.total_food_received), 0) + // ) + + // FROM shift_master sm + // LEFT JOIN daily_request dr + // ON sm.shiftid = dr.shiftid AND dr.required_date = ? + // LEFT JOIN gcc_received_update gru + // ON gru.requestid = dr.requestid + // WHERE sm.isactive = 1 AND sm.isdelete = 0 + // ) final_table + // """; + + // return jdbcTemplate.queryForList(sql, date, date); + // } + + // with using isactive and isdelete + public List> getAbstractReport(String date) { + + String sql = """ + SELECT * FROM ( + + /* ================= SHIFT-WISE SUMMARY ================= */ + SELECT + sm.name AS shift_name, + sm.code AS shift_code, + sm.shiftid AS shiftid, + + /* TOTAL COMPLEMENT */ + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) AS total_complement, + + /* WEEKLY OFF */ + IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) AS weekly_off, + + /* PLANNED LEAVE */ + IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + + dr.absentees_others + dr.absentees_nmr), 0) AS planned_leave, + + /* PRESENT COUNT */ + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + - + IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + + dr.absentees_others + dr.absentees_nmr), 0) + ) AS present_count, + + /* FOOD REQUESTED = PRESENT COUNT */ + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + - + IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + + dr.absentees_others + dr.absentees_nmr), 0) + ) AS food_requested, + + /* FOOD DELIVERED */ + IFNULL(SUM(gru.total_food_received), 0) AS food_delivered, + + /* FOOD SHORTFALL */ + ( + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + - + IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + + dr.absentees_others + dr.absentees_nmr), 0) + ) + - + IFNULL(SUM(gru.total_food_received), 0) + ) AS food_shortfall + + FROM shift_master sm + LEFT JOIN daily_request dr + ON sm.shiftid = dr.shiftid + AND dr.required_date = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + LEFT JOIN gcc_received_update gru + ON gru.requestid = dr.requestid + AND gru.isactive = 1 + AND gru.isdelete = 0 + WHERE sm.isactive = 1 AND sm.isdelete = 0 + GROUP BY sm.shiftid, sm.name + + UNION ALL + + /* ================= TOTAL SUMMARY ================= */ + SELECT + 'Total' AS shift_name, + 'TOTAL' AS shift_code, + 'TOTAL' AS shiftid, + + /* TOTAL COMPLEMENT */ + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0), + + /* WEEKLY OFF */ + IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + + dr.weeklyoff_others + dr.weeklyoff_nmr), 0), + + /* PLANNED LEAVE */ + IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + + dr.absentees_others + dr.absentees_nmr), 0), + + /* PRESENT COUNT */ + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + - + IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + + dr.absentees_others + dr.absentees_nmr), 0) + ), + + /* FOOD REQUESTED */ + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + - + IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + + dr.absentees_others + dr.absentees_nmr), 0) + ), + + /* FOOD DELIVERED */ + IFNULL(SUM(gru.total_food_received), 0), + + /* FOOD SHORTFALL */ + ( + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + - + IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + + dr.absentees_others + dr.absentees_nmr), 0) + ) + - + IFNULL(SUM(gru.total_food_received), 0) + ) + + FROM shift_master sm + LEFT JOIN daily_request dr + ON sm.shiftid = dr.shiftid + AND dr.required_date = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + LEFT JOIN gcc_received_update gru + ON gru.requestid = dr.requestid + AND gru.isactive = 1 + AND gru.isdelete = 0 + WHERE sm.isactive = 1 AND sm.isdelete = 0 + ) final_table + """; + + return jdbcTemplate.queryForList(sql, date, date); + } + + public List> getWardDetails(int qid, String column, String date, int zone) { + + String imageColumn = ""; + String whereCondition = ""; // <-- will be used in WHERE + String sumCondition = ""; // <-- used inside SUM() + + switch (column) { + case "on_time_distribution": + imageColumn = "fd.q1_img"; + whereCondition = "fd.q1 = '1'"; + sumCondition = "fd.q1 = '1'"; + break; + + case "delayeded": + imageColumn = "fd.q1_img"; + whereCondition = "fd.q1 = '2'"; + sumCondition = "fd.q1 = '2'"; + break; + + case "good": + imageColumn = "fd.q2_img"; + whereCondition = "fd.q2 = '3'"; + sumCondition = "fd.q2 = '3'"; + break; + + case "average": + imageColumn = "fd.q2_img"; + whereCondition = "fd.q2 = '4'"; + sumCondition = "fd.q2 = '4'"; + break; + + case "sufficient_food_quantity": + imageColumn = "fd.q3_img"; + whereCondition = "fd.q3 = '5'"; + sumCondition = "fd.q3 = '5'"; + break; + + case "less_quantity": + imageColumn = "fd.q3_img"; + whereCondition = "fd.q3 = '6'"; + sumCondition = "fd.q3 = '6'"; + break; + } + + String sql = "SELECT lm.ward,lm.location, fq.question, " + + "SUM(CASE WHEN " + sumCondition + " THEN 1 ELSE 0 END) AS count_value, " + + "CONCAT('" + fileBaseUrl + "/gccofficialapp/files'," + imageColumn + ") AS feedbackImage " + + "FROM feedback_data fd " + + "INNER JOIN location_mapping lm ON fd.feedback_by = lm.siloginid " + + "INNER JOIN feedback_questions fq ON fq.qid = ? " + + "WHERE lm.zone = ? " + + "AND DATE(fd.feedback_date) = ? " + + "AND fd.isactive = 1 AND fd.isdelete = 0 " + + "AND " + whereCondition + " " + // <-- EXACT MATCH ADDED + "GROUP BY lm.ward,lm.location,fq.question, " + imageColumn + " " + + "ORDER BY lm.ward"; + + return jdbcTemplate.queryForList(sql, qid, zone, date); + } + + // with using isactive and isdelete + // public List> getZoneWiseShiftBasedReport(String date, int + // shiftId) { + + // String sql = """ + // SELECT * + // FROM ( + + // /* ================= ZONE-WISE SUMMARY ================= */ + // SELECT + // z.zone AS zone, + + // /* -------- TOTAL COMPLEMENT -------- */ + // ( + // SELECT IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), + // 0) + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) AS total_complement, + + // /* -------- WEEKLY OFF -------- */ + // ( + // SELECT IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + + // dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) AS weekly_off, + + // /* -------- PLANNED LEAVE -------- */ + // ( + // SELECT IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + + // dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr), 0) + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) AS planned_leave, + + // /* -------- PRESENT COUNT -------- */ + // ( + // ( + // SELECT IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), + // 0) + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) + // - + // ( + // SELECT IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + + // dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) + // - + // ( + // SELECT IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + + // dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr), 0) + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) + // ) AS present_count, + + // /* -------- FOOD REQUESTED -------- */ + // ( + // ( + // SELECT IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), + // 0) + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) + // - + // ( + // SELECT IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + + // dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) + // - + // ( + // SELECT IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + + // dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr), 0) + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) + // ) AS food_requested, + + // /* -------- FOOD DELIVERED -------- */ + // ( + // SELECT IFNULL(SUM(gru.total_food_received), 0) + // FROM gcc_received_update gru + // WHERE gru.shiftid = ? + // AND gru.requestid IN ( + // SELECT dr.requestid + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) + // ) AS food_delivered, + + // /* -------- FOOD SHORTFALL (UPDATED) -------- */ + // ( + // ( + // ( + // SELECT IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), + // 0) + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) + // - + // ( + // SELECT IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + + // dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) + // - + // ( + // SELECT IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + + // dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr), 0) + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) + // ) + // - + // ( + // SELECT IFNULL(SUM(gru.total_food_received), 0) + // FROM gcc_received_update gru + // WHERE gru.shiftid = ? + // AND gru.requestid IN ( + // SELECT dr.requestid + // FROM daily_request dr + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + // AND dr.request_by IN ( + // SELECT lm.siloginid FROM location_mapping lm WHERE lm.zone = z.zone + // ) + // ) + // ) + // ) AS food_shortfall + + // FROM ( + // SELECT DISTINCT zone + // FROM location_mapping + // WHERE zone IS NOT NULL + // ORDER BY CAST(zone AS UNSIGNED) + // ) z + + // UNION ALL + + // /* ================= GRAND TOTAL ================= */ + // SELECT + // 'TOTAL' AS zone, + + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0), + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + + // dr.weeklyoff_others + dr.weeklyoff_nmr), 0), + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + + // dr.absentees_others + dr.absentees_nmr), 0), + + // ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + // - + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + + // dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // - + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + + // dr.absentees_others + dr.absentees_nmr), 0) + // ), + + // /* food_requested total = present_count total */ + // ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + // - + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + + // dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // - + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + + // dr.absentees_others + dr.absentees_nmr), 0) + // ), + + // /* delivered */ + // IFNULL(SUM(gru.total_food_received), 0), + + // /* -------- TOTAL FOOD SHORTFALL -------- */ + // ( + // ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + // - + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + + // dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + // - + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + + // dr.absentees_others + dr.absentees_nmr), 0) + // ) + // - + // IFNULL(SUM(gru.total_food_received), 0) + // ) + + // FROM daily_request dr + // LEFT JOIN gcc_received_update gru + // ON gru.requestid = dr.requestid + // WHERE dr.required_date = ? + // AND dr.shiftid = ? + + // ) final_output + + // ORDER BY + // CASE WHEN zone = 'TOTAL' THEN 1 ELSE 0 END, + // CAST(zone AS UNSIGNED); + // """; + + // return jdbcTemplate.queryForList(sql, + // /* zone-wise params */ + // date, shiftId, + // date, shiftId, + // date, shiftId, + // date, shiftId, date, shiftId, date, shiftId, + // date, shiftId, date, shiftId, date, shiftId, + // shiftId, date, shiftId, + + // /* shortfall zone params */ + // date, shiftId, date, shiftId, date, shiftId, + // shiftId, date, shiftId, + + // /* total row */ + // date, shiftId); + // } + + // with using isactive isdelete + public List> getZoneWiseShiftBasedReport(String date, int shiftId) { + + String sql = """ + SELECT * + FROM ( + + /* ================= ZONE-WISE SUMMARY ================= */ + SELECT + z.zone AS zone, + + /* -------- TOTAL COMPLEMENT -------- */ + ( + SELECT IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) AS total_complement, + + /* -------- WEEKLY OFF -------- */ + ( + SELECT IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) AS weekly_off, + + /* -------- PLANNED LEAVE -------- */ + ( + SELECT IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr), 0) + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) AS planned_leave, + + /* -------- PRESENT COUNT -------- */ + ( + ( + SELECT IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) + - + ( + SELECT IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) + - + ( + SELECT IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr), 0) + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) + ) AS present_count, + + /* -------- FOOD REQUESTED -------- */ + ( + ( + SELECT IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) + - + ( + SELECT IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) + - + ( + SELECT IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr), 0) + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) + ) AS food_requested, + + /* -------- FOOD DELIVERED -------- */ + ( + SELECT IFNULL(SUM(gru.total_food_received), 0) + FROM gcc_received_update gru + WHERE gru.shiftid = ? + AND gru.isactive = 1 + AND gru.isdelete = 0 + AND gru.requestid IN ( + SELECT dr.requestid + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) + ) AS food_delivered, + + /* -------- FOOD SHORTFALL -------- */ + ( + ( + ( + SELECT IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) + - + ( + SELECT IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) + - + ( + SELECT IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr), 0) + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) + ) + - + ( + SELECT IFNULL(SUM(gru.total_food_received), 0) + FROM gcc_received_update gru + WHERE gru.shiftid = ? + AND gru.isactive = 1 + AND gru.isdelete = 0 + AND gru.requestid IN ( + SELECT dr.requestid + FROM daily_request dr + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + AND dr.request_by IN ( + SELECT lm.siloginid + FROM location_mapping lm + WHERE lm.zone = z.zone + AND lm.isactive = 1 + AND lm.isdelete = 0 + ) + ) + ) + ) AS food_shortfall + + FROM ( + SELECT DISTINCT zone + FROM location_mapping + WHERE zone IS NOT NULL + AND isactive = 1 + AND isdelete = 0 + ORDER BY CAST(zone AS UNSIGNED) + ) z + + UNION ALL + + /* ================= GRAND TOTAL ================= */ + SELECT + 'TOTAL' AS zone, + + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0), + IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + + dr.weeklyoff_others + dr.weeklyoff_nmr), 0), + IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + + dr.absentees_others + dr.absentees_nmr), 0), + + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + - + IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + + dr.absentees_others + dr.absentees_nmr), 0) + ), + + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + - + IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + + dr.absentees_others + dr.absentees_nmr), 0) + ), + + IFNULL(SUM(gru.total_food_received), 0), + + ( + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + + dr.weeklyoff_others + dr.weeklyoff_nmr), 0) + - + IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + + dr.absentees_others + dr.absentees_nmr), 0) + ) + - + IFNULL(SUM(gru.total_food_received), 0) + ) + + FROM daily_request dr + LEFT JOIN gcc_received_update gru + ON gru.requestid = dr.requestid + AND gru.isactive = 1 + AND gru.isdelete = 0 + WHERE dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + + ) final_output + + ORDER BY + CASE WHEN zone = 'TOTAL' THEN 1 ELSE 0 END, + CAST(zone AS UNSIGNED); + """; + + return jdbcTemplate.queryForList( + sql, + + /* zone-wise params */ + date, shiftId, + date, shiftId, + date, shiftId, + date, shiftId, date, shiftId, date, shiftId, + date, shiftId, date, shiftId, date, shiftId, + shiftId, date, shiftId, + + /* shortfall zone params */ + date, shiftId, date, shiftId, date, shiftId, + shiftId, date, shiftId, + + /* total row */ + date, shiftId); + } + + // without using isactive and isdelete + // public List> getWardWiseShiftReport(Integer shiftId, + // Integer zone, String date) { + + // String sql = """ + // WITH ward_data AS ( + // SELECT + // w.ward, + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others),0) AS + // total_complement, + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + dr.weeklyoff_others + dr.weeklyoff_nmr),0) AS weekly_off, + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.absentees_nulm + // + dr.absentees_others + dr.absentees_nmr),0) AS planned_leave, + + // -- PRESENT COUNT + // ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others),0) + // - IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + + // dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr),0) + // - IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + + // dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr),0) + // ) AS present_count, + + // -- FOOD REQUESTED + // ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others),0) + // - IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + + // dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr),0) + // - IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + + // dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr),0) + // ) AS food_requested, + + // IFNULL(SUM(gru.total_food_received),0) AS food_delivered, + + // -- FOOD SHORTFALL (corrected logic) + // CASE + // WHEN IFNULL(SUM(gru.total_food_received),0) >= ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr),0) + // - IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_nulm + + // dr.weeklyoff_private + dr.weeklyoff_nmr),0) + // - IFNULL(SUM(dr.absentees_permanent + dr.absentees_nulm + + // dr.absentees_private + dr.absentees_nmr),0) + // ) + // THEN 0 + // ELSE ( + // ( + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr),0) + // - IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_nulm + + // dr.weeklyoff_private + dr.weeklyoff_nmr),0) + // - IFNULL(SUM(dr.absentees_permanent + dr.absentees_nulm + + // dr.absentees_private + dr.absentees_nmr),0) + // ) + // - IFNULL(SUM(gru.total_food_received),0) + // ) + // END AS food_shortfall + + // FROM (SELECT DISTINCT ward FROM location_mapping WHERE zone = ? AND ward IS + // NOT NULL) w + // LEFT JOIN location_mapping lm ON lm.ward = w.ward AND lm.zone = ? + // LEFT JOIN daily_request dr ON dr.request_by = lm.siloginid + // AND dr.required_date = ? + // AND dr.shiftid = ? + // LEFT JOIN gcc_received_update gru ON gru.requestid = dr.requestid + + // GROUP BY w.ward + // ) + + // SELECT * FROM ward_data + + // UNION ALL + + // SELECT + // 'TOTAL' AS ward, + // SUM(total_complement), + // SUM(weekly_off), + // SUM(planned_leave), + // SUM(present_count), + // SUM(food_requested), + // SUM(food_delivered), + // SUM(food_shortfall) + // FROM ward_data + + // ORDER BY CASE WHEN ward = 'TOTAL' THEN 1 ELSE 0 END, ward; + // """; + + // Object[] params = new Object[] { + // zone, // w.zone + // zone, // lm.zone + // date, // dr.required_date + // shiftId // dr.shiftid + // }; + + // return jdbcTemplate.queryForList(sql, params); + // } + + // with using isactive isdelete + public List> getWardWiseShiftReport(Integer shiftId, Integer zone, String date) { + + String sql = """ + WITH ward_data AS ( + SELECT + w.ward, + + /* TOTAL COMPLEMENT */ + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) AS total_complement, + + /* WEEKLY OFF */ + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0) AS weekly_off, + + /* PLANNED LEAVE */ + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0) AS planned_leave, + + /* PRESENT COUNT */ + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0) + - + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0) + ) AS present_count, + + /* FOOD REQUESTED */ + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0) + - + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0) + ) AS food_requested, + + /* FOOD DELIVERED */ + IFNULL(SUM(gru.total_food_received), 0) AS food_delivered, + + /* FOOD SHORTFALL */ + CASE + WHEN IFNULL(SUM(gru.total_food_received), 0) >= + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0) + - + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0) + ) + THEN 0 + ELSE + ( + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0) + - + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0) + ) + - + IFNULL(SUM(gru.total_food_received), 0) + ) + END AS food_shortfall + + FROM ( + SELECT DISTINCT ward + FROM location_mapping + WHERE zone = ? + AND ward IS NOT NULL + AND isactive = 1 + AND isdelete = 0 + ) w + + LEFT JOIN location_mapping lm + ON lm.ward = w.ward + AND lm.zone = ? + AND lm.isactive = 1 + AND lm.isdelete = 0 + + LEFT JOIN daily_request dr + ON dr.request_by = lm.siloginid + AND dr.required_date = ? + AND dr.shiftid = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + + LEFT JOIN gcc_received_update gru + ON gru.requestid = dr.requestid + AND gru.isactive = 1 + AND gru.isdelete = 0 + + GROUP BY w.ward + ) + + SELECT * FROM ward_data + + UNION ALL + + SELECT + 'TOTAL' AS ward, + SUM(total_complement), + SUM(weekly_off), + SUM(planned_leave), + SUM(present_count), + SUM(food_requested), + SUM(food_delivered), + SUM(food_shortfall) + FROM ward_data + + ORDER BY + CASE WHEN ward = 'TOTAL' THEN 1 ELSE 0 END, + ward; + """; + + Object[] params = new Object[] { + zone, // ward subquery zone + zone, // lm.zone + date, // dr.required_date + shiftId // dr.shiftid + }; + + return jdbcTemplate.queryForList(sql, params); + } + + // without using isactive and isdelete + // public List> getWardLocationWiseReport(String date) { + + // String sql = """ + // SELECT * FROM ( + // -- ================= LOCATION WISE ================= + // SELECT + // lm.driverid, + // lm.zone, + // lm.ward, + // lm.location, + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others),0) AS + // total_complement, + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + dr.weeklyoff_others + dr.weeklyoff_nmr),0) AS weekly_off, + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.nulm + + // dr.absentees_others + dr.absentees_nmr),0) AS planned_leave, + // (IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others),0) + // - IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.nulm + + // dr.weeklyoff_others + dr.weeklyoff_nmr),0) + // - IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.nulm + + // dr.absentees_others + dr.absentees_nmr),0) + // ) AS present_count, + // (IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others),0) + // - IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.nulm + + // dr.weeklyoff_others + dr.weeklyoff_nmr),0) + // - IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.nulm + + // dr.absentees_others + dr.absentees_nmr),0) + // ) AS food_requested, + // IFNULL(SUM(gru.total_food_received),0) AS food_delivered, + // -- ===== FOOD SHORTFALL LOGIC ===== + // (IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others),0) + // - IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.nulm + + // dr.weeklyoff_others + dr.weeklyoff_nmr),0) + // - IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.nulm + + // dr.absentees_others + dr.absentees_nmr),0) + // ) - IFNULL(SUM(gru.total_food_received),0) AS food_shortfall + // FROM location_mapping lm + // LEFT JOIN daily_request dr + // ON dr.request_by = lm.siloginid AND dr.required_date = ? + // LEFT JOIN gcc_received_update gru + // ON gru.received_by = lm.siloginid AND gru.requestid = dr.requestid + // WHERE lm.ward IS NOT NULL AND lm.location IS NOT NULL + // GROUP BY lm.driverid, lm.zone, lm.ward, lm.location + + // UNION ALL + + // -- ================= TOTAL ROW ================= + // SELECT + // 999999 AS driverid, + // 'TOTAL' AS zone, + // 'TOTAL' AS ward, + // 'TOTAL' AS location, + // IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others),0) AS + // total_complement, + // IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.weeklyoff_nulm + // + dr.weeklyoff_others + dr.weeklyoff_nmr),0) AS weekly_off, + // IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.nulm + + // dr.absentees_others + dr.absentees_nmr),0) AS planned_leave, + // (IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others),0) + // - IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + + // dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr),0) + // - IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.nulm + + // dr.absentees_others + dr.absentees_nmr),0) + // ) AS present_count, + // (IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others),0) + // - IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.nulm + + // dr.weeklyoff_others + dr.weeklyoff_nmr),0) + // - IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.nulm + + // dr.absentees_others + dr.absentees_nmr),0) + // ) AS food_requested, + // IFNULL(SUM(gru.total_food_received),0) AS food_delivered, + // -- ===== FOOD SHORTFALL TOTAL ===== + // (IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others),0) + // - IFNULL(SUM(dr.weeklyoff_permanent + dr.weeklyoff_private + dr.nulm + + // dr.weeklyoff_others + dr.weeklyoff_nmr),0) + // - IFNULL(SUM(dr.absentees_permanent + dr.absentees_private + dr.nulm + + // dr.absentees_others + dr.absentees_nmr),0) + // ) - IFNULL(SUM(gru.total_food_received),0) AS food_shortfall + // FROM daily_request dr + // LEFT JOIN gcc_received_update gru ON gru.requestid = dr.requestid + // WHERE dr.required_date = ? + // ) final_output + // ORDER BY driverid ASC + // """; + + // Object[] params = new Object[] { date, date }; // first for location JOIN, + // second for TOTAL row + // return jdbcTemplate.queryForList(sql, params); + // } + + // with using isactive isdelete + public List> getWardLocationWiseReport(String date) { + + String sql = """ + SELECT * FROM ( + /* ================= LOCATION WISE ================= */ + SELECT + lm.driverid, + lm.zone, + lm.ward, + lm.location, + + /* TOTAL COMPLEMENT */ + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) AS total_complement, + + /* WEEKLY OFF */ + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0) AS weekly_off, + + /* PLANNED LEAVE */ + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0) AS planned_leave, + + /* PRESENT COUNT */ + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0) + - + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0) + ) AS present_count, + + /* FOOD REQUESTED */ + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0) + - + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0) + ) AS food_requested, + + /* FOOD DELIVERED */ + IFNULL(SUM(gru.total_food_received), 0) AS food_delivered, + + /* FOOD SHORTFALL */ + ( + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0) + - + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0) + ) + - + IFNULL(SUM(gru.total_food_received), 0) + ) AS food_shortfall + + FROM location_mapping lm + LEFT JOIN daily_request dr + ON dr.request_by = lm.siloginid + AND dr.required_date = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + + LEFT JOIN gcc_received_update gru + ON gru.requestid = dr.requestid + AND gru.received_by = lm.siloginid + AND gru.isactive = 1 + AND gru.isdelete = 0 + + WHERE lm.ward IS NOT NULL + AND lm.location IS NOT NULL + AND lm.isactive = 1 + AND lm.isdelete = 0 + + GROUP BY + lm.driverid, + lm.zone, + lm.ward, + lm.location + + UNION ALL + + /* ================= TOTAL ROW ================= */ + SELECT + 999999 AS driverid, + 'TOTAL' AS zone, + 'TOTAL' AS ward, + 'TOTAL' AS location, + + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0), + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0), + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0), + + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0) + - + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0) + ), + + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0) + - + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0) + ), + + IFNULL(SUM(gru.total_food_received), 0), + + ( + ( + IFNULL(SUM(dr.permanent + dr.nulm + dr.private + dr.nmr + dr.others), 0) + - + IFNULL(SUM( + dr.weeklyoff_permanent + dr.weeklyoff_private + + dr.weeklyoff_nulm + dr.weeklyoff_others + dr.weeklyoff_nmr + ), 0) + - + IFNULL(SUM( + dr.absentees_permanent + dr.absentees_private + + dr.absentees_nulm + dr.absentees_others + dr.absentees_nmr + ), 0) + ) + - + IFNULL(SUM(gru.total_food_received), 0) + ) + + FROM daily_request dr + LEFT JOIN gcc_received_update gru + ON gru.requestid = dr.requestid + AND gru.isactive = 1 + AND gru.isdelete = 0 + WHERE dr.required_date = ? + AND dr.isactive = 1 + AND dr.isdelete = 0 + + ) final_output + ORDER BY driverid ASC + """; + + Object[] params = new Object[] { + date, // location-wise join + date // total row + }; + + return jdbcTemplate.queryForList(sql, params); + } + +} + +/* + * String sql = "SELECT lm.location AS LocationDescription, "+ + * "dl.username AS DriverName, "+ + * " CONCAT('" + * +fileBaseUrl+"/gccofficialapp/files',dss_start.image) as upload_image_url, "+ + * " CONCAT(dss_start.latitude, ', ', dss_start.longitude) AS StartPoint, "+ + * "Date(dss_start.datetime) AS StartTime, "+ + * + * " CONCAT(dss_stop.latitude, ', ', dss_stop.longitude) AS EndPoint, "+ + * Date(dss_stop.datetime) AS EndTime + * + * FROM location_mapping lm + * INNER JOIN driver_login dl + * ON dl.loginid = lm.driverid + * + * LEFT JOIN driver_start_stop dss_start + * ON dss_start.loginid = lm.driverid + * AND dss_start.action = 'Start' + * + * + * LEFT JOIN driver_start_stop dss_stop + * ON dss_stop.loginid = lm.driverid + * AND dss_stop.action = 'Stop' + * AND dss_stop.startid = dss_start.locationid + * WHERE DATE(dss_start.datetime) = ?"; + * change for full query + */ \ No newline at end of file diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 36b2f7d..3fc6833 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -13,6 +13,4 @@ server.port=8078 #secondary.datasource.username=FAS #secondary.datasource.password=FAS #secondary.datasource.driver-class-name=oracle.jdbc.OracleDriver - - - +fileBaseUrl=https://gccservices.in \ No newline at end of file diff --git a/src/main/resources/templates/modules/food_scheme/driverreport.html b/src/main/resources/templates/modules/food_scheme/driverreport.html new file mode 100644 index 0000000..2efef0c --- /dev/null +++ b/src/main/resources/templates/modules/food_scheme/driverreport.html @@ -0,0 +1,430 @@ + + + + + Food Scheme Operations Dashboard + + + + + + + + + + + + + + +
+

Food Scheme Report

+
+ + + +
+
+ +
+
Driver Logistics Report
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/modules/food_scheme/feedbackreport.html b/src/main/resources/templates/modules/food_scheme/feedbackreport.html new file mode 100644 index 0000000..44ce2bf --- /dev/null +++ b/src/main/resources/templates/modules/food_scheme/feedbackreport.html @@ -0,0 +1,706 @@ + + + + + Feedback Summary Report + + + + + + + + + +
+

Food Scheme – Feedback Summary

+
+ +
+
+ +
+
Feedback Summary
+ +
+ + +
+
+ +
+ +
+
Feedback - Food Distribution Time
+ + + + + + + + + +
CategoryCount
+
+ +
+
Feedback - Food Taste
+ + + + + + + + +
CategoryCount
+
+ +
+
Feedback - Food Quantity
+ + + + + + + + +
CategoryCount
+
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/modules/food_scheme/foodschemereport.html b/src/main/resources/templates/modules/food_scheme/foodschemereport.html new file mode 100644 index 0000000..cd035e3 --- /dev/null +++ b/src/main/resources/templates/modules/food_scheme/foodschemereport.html @@ -0,0 +1,1520 @@ + + + + + + + + Food Distribution Operations Dashboard + + + + + + + + + + + + + + +
+

Food Distribution Report

+
+ + + +
+
+
Shift Wise Overview
+ +
+ + + + + + + +
+ + +
+ + + + + + + + + + + + + + + + + +
ShiftTotal ComplementWeekly OffPlanned LeavePresent CountFood RequestedFood DeliveredFood Shortfall
+
+
+ + + +
+
+
Shift A - Daily Food Menu
+ + + + + + + + + + + + + + + + + + + + + + + + + +
SundayMondayTuesdayWednesdayThursdayFridaySaturday
Sambar Rice (650g) & Porial (100g)Lemon Rice (5000g) & Potato/yam/Raw banana fry (100g)Veg Biryani (500g) & Brinjal Onion (75g)Tomato Rice (500g) & Potato/yam/Raw banana fry (100g)Coriander/Mint Rice (500g) & Potato/yam/Raw banana fry (100g)Tamarind Rice (500g) & Potato/yam/Raw banana fry (100g)Veg Biryani (500g) & Brinjal Onion (75g)
+ +
+
+ + + + + + + + + +
+
+ + + + +
+
+
+
Zone wise Overallview
+ +
+ + +
+ + + + + + + + + + + + + + +
zoneTotal Complementweekly OffPlanned LeavePresent CountFood RequestedFood DeliveredFood Shortfall
+
+
+ + + +
+
+
+
Overall Location wise Overview
+
Select Zone:
+ + +
+ + + + + + + +
+
+ + + + + + + + + + + + + + + + +
ZoneWardLocationsTotal Complementweekly OffPlanned LeavePresent CountFood RequestedFood DeliveredFood Shortfall
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file