@ -8,20 +8,27 @@ import java.util.stream.Collectors;
import com.fasterxml.jackson.core.JsonProcessingException ;
import com.fasterxml.jackson.databind.ObjectMapper ;
import com.gcc.communityHall.entity.GccBlockingDate ;
import com.gcc.communityHall.entity.Login ;
import com.gcc.communityHall.entity.LoginHallId ;
import com.gcc.communityHall.others.AppConfig ;
import com.gcc.communityHall.repository.GccBlockingDateRepository ;
import com.gcc.communityHall.repository.LoginHallIdRepository ;
import com.gcc.communityHall.repository.LoginRepository ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.format.annotation.DateTimeFormat ;
import org.springframework.stereotype.Controller ;
import org.springframework.ui.Model ;
import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.web.bind.annotation.PathVariable ;
import org.springframework.web.bind.annotation.PostMapping ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestParam ;
import org.springframework.web.bind.annotation.ResponseBody ;
import com.gcc.communityHall.entity.BookingDetails ;
import com.gcc.communityHall.entity.Users ;
import com.gcc.communityHall.repository.BookingDetailsRepository ;
import com.gcc.communityHall.repository.HallDetailsRepository ;
import com.gcc.communityHall.repository.UsersRepository ;
import com.gcc.communityHall.service.BookingService ;
import com.gcc.communityHall.service.HallDetailService ;
@ -29,6 +36,7 @@ import com.gcc.communityHall.service.ReasonMasterService;
import com.gcc.communityHall.service.UserService ;
import jakarta.servlet.http.HttpSession ;
import jakarta.transaction.Transactional ;
@Controller
@RequestMapping ( "/communityhall/headquarters" )
@ -57,13 +65,22 @@ public class HeadquartersController {
@Autowired
private AppConfig appConfig ;
@Autowired
private LoginRepository loginRepository ;
@Autowired
private LoginHallIdRepository loginHallIdRepository ;
@Autowired
private HallDetailsRepository hallDetailsRepository ;
@GetMapping ( "/dashboard" )
public String viewDashboard (
@RequestParam ( required = false , defaultValue = "all zones" ) String zone ,
Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
List < Map < String , Object > > getMonthCount = bookingDetailsRepository . getAllAdminmonthcount ( zone ) ;
@ -88,11 +105,10 @@ public class HeadquartersController {
}
}
@GetMapping ( "/Reports" )
public String viewReports ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
@ -106,7 +122,7 @@ public class HeadquartersController {
@GetMapping ( "/getReport" )
public String getReports ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
@ -120,7 +136,7 @@ public class HeadquartersController {
@GetMapping ( "/approval-history" )
public String viewApproval ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
@ -139,7 +155,7 @@ public class HeadquartersController {
@GetMapping ( "/user-approved" )
public String viewUserApproved ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
@ -158,7 +174,7 @@ public class HeadquartersController {
@GetMapping ( "/user-reject" )
public String viewUserReject ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
@ -176,48 +192,60 @@ public class HeadquartersController {
@PostMapping ( "/getReport" )
public String generateReport ( Model model ,
@RequestParam ( name = "FromDate" ) @DateTimeFormat ( iso = DateTimeFormat . ISO . DATE ) String fromDate ,
@RequestParam ( name = "ToDate" ) @DateTimeFormat ( iso = DateTimeFormat . ISO . DATE ) String toDate ,
@RequestParam ( name = "request" ) String request ,
@RequestParam ( name = "userstatus" , required = false ) String userstatus ,
@RequestParam ( name = "usertype" , required = false ) String usertype ,
@RequestParam ( name = "bookingStatus" , required = false ) String bookingStatus ,
@RequestParam ( name = "refundStatus" , required = false ) String refundStatus ,
@RequestParam ( name = "paymentStatus" , required = false ) String paymentStatus ,
@RequestParam ( name = "filterby" , required = false ) String filterby ,
@RequestParam ( name = "zone1" , required = false , defaultValue = "ALL" ) String zone ,
@RequestParam ( name = "division1" , required = false , defaultValue = "ALL" ) String division ,
@RequestParam ( name = "hall1" , required = false ) Integer hallid ,
@RequestParam ( name = "basedon" , required = false ) String basedon ,
@RequestParam ( name = "bookingId" , required = false ) Long bookingId ,
@RequestParam ( name = "reporttype" , required = false ) String reporttype ,
@RequestParam ( name = "counterId" , required = false ) String counterId , HttpSession session ) throws JsonProcessingException {
@RequestParam ( name = "FromDate" ) @DateTimeFormat ( iso = DateTimeFormat . ISO . DATE ) String fromDate ,
@RequestParam ( name = "ToDate" ) @DateTimeFormat ( iso = DateTimeFormat . ISO . DATE ) String toDate ,
@RequestParam ( name = "request" ) String request ,
@RequestParam ( name = "userstatus" , required = false ) String userstatus ,
@RequestParam ( name = "usertype" , required = false ) String usertype ,
@RequestParam ( name = "bookingStatus" , required = false ) String bookingStatus ,
@RequestParam ( name = "refundStatus" , required = false ) String refundStatus ,
@RequestParam ( name = "paymentStatus" , required = false ) String paymentStatus ,
@RequestParam ( name = "filterby" , required = false ) String filterby ,
@RequestParam ( name = "zone1" , required = false , defaultValue = "ALL" ) String zone ,
@RequestParam ( name = "division1" , required = false , defaultValue = "ALL" ) String division ,
@RequestParam ( name = "hall1" , required = false ) Integer hallid ,
@RequestParam ( name = "basedon" , required = false ) String basedon ,
@RequestParam ( name = "bookingId" , required = false ) Long bookingId ,
@RequestParam ( name = "reporttype" , required = false ) String reporttype ,
@RequestParam ( name = "counterId" , required = false ) String counterId , HttpSession session )
throws JsonProcessingException {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
List < Users > userList = handleUserRequest ( request , fromDate , toDate , userstatus , usertype ) ;
List < Object [ ] > bookingList = handleBookingRequest ( request , fromDate , toDate , bookingStatus , filterby , bookingId , zone , division , hallid ) ;
List < BookingDetails > bookingSettlementList = handleBookingSettlementRequest ( request , fromDate , toDate , refundStatus , filterby ) ;
/ / List < Object [ ] > paymentList = request . equals ( "3" ) ? bookingService . getAllPaymentsDetails ( fromDate , toDate , zone , division , hallid ) : new ArrayList < > ( ) ;
List < Object [ ] > bookingList = handleBookingRequest ( request , fromDate , toDate , bookingStatus , filterby ,
bookingId , zone , division , hallid ) ;
List < BookingDetails > bookingSettlementList = handleBookingSettlementRequest ( request , fromDate , toDate ,
refundStatus , filterby ) ;
/ / List < Object [ ] > paymentList = request . equals ( "3" ) ?
/ / bookingService . getAllPaymentsDetails ( fromDate , toDate , zone , division , hallid ) :
/ / new ArrayList < > ( ) ;
List < Object [ ] > paymentList = new ArrayList < > ( ) ;
List < Object [ ] > extrapaymentList = new ArrayList < > ( ) ;
if ( request . equals ( "3" ) ) {
if ( paymentStatus = = null | | paymentStatus . isEmpty ( ) ) {
paymentList = bookingService . getAllPaymentsDetails ( fromDate , toDate , null , zone , division , hallid ) ;
} else {
paymentList = bookingService . getAllPaymentsDetails ( fromDate , toDate , paymentStatus , zone , division , hallid ) ;
paymentList = bookingService . getAllPaymentsDetails ( fromDate , toDate , paymentStatus , zone , division ,
hallid ) ;
}
}
if ( request . equals ( "8" ) ) {
if ( paymentStatus = = null | | paymentStatus . isEmpty ( ) ) {
extrapaymentList = bookingService . getAllExtraPaymentsDetails ( fromDate , toDate , null , zone , division , hallid ) ;
extrapaymentList = bookingService . getAllExtraPaymentsDetails ( fromDate , toDate , null , zone , division ,
hallid ) ;
} else {
extrapaymentList = bookingService . getAllExtraPaymentsDetails ( fromDate , toDate , paymentStatus , zone , division , hallid ) ;
extrapaymentList = bookingService . getAllExtraPaymentsDetails ( fromDate , toDate , paymentStatus , zone ,
division , hallid ) ;
}
}
List < Object [ ] > userbookingList = request . equals ( "4" ) ? bookingService . getBookingUserDetailsReport ( fromDate , toDate ) : new ArrayList < > ( ) ;
/ / List < Object [ ] > hallbookingList = request . equals ( "5" ) ? bookingService . getBookingHallDetailsReport ( fromDate , toDate ) : new ArrayList < > ( ) ;
List < Object [ ] > userbookingList = request . equals ( "4" )
? bookingService . getBookingUserDetailsReport ( fromDate , toDate )
: new ArrayList < > ( ) ;
/ / List < Object [ ] > hallbookingList = request . equals ( "5" ) ?
/ / bookingService . getBookingHallDetailsReport ( fromDate , toDate ) : new
/ / ArrayList < > ( ) ;
/ / In your controller method
/ / Fetch booking count by zone
List < Object [ ] > totalcount = new ArrayList < > ( ) ;
@ -227,13 +255,13 @@ public class HeadquartersController {
totalcount = bookingDetailsRepository . countBookingsByZone ( ) ;
/ / Format zone data
totalcount = totalcount . stream ( )
. map ( data - > new Object [ ] { "Zone-" + data [ 0 ] , data [ 1 ] } )
. map ( data - > new Object [ ] { "Zone-" + data [ 0 ] , data [ 1 ] } )
. collect ( Collectors . toList ( ) ) ;
} else if ( "division" . equals ( basedon ) ) {
totalcount = bookingDetailsRepository . countBookingsByDivisions ( ) ;
/ / Format division data
totalcount = totalcount . stream ( )
. map ( data - > new Object [ ] { "Division-" + data [ 0 ] , data [ 1 ] } )
. map ( data - > new Object [ ] { "Division-" + data [ 0 ] , data [ 1 ] } )
. collect ( Collectors . toList ( ) ) ;
}
@ -244,22 +272,24 @@ public class HeadquartersController {
model . addAttribute ( "basedon" , basedon ) ;
model . addAttribute ( "totalcount" , totalcount ) ;
model . addAttribute ( "totalBookings" , totalBookings ) ;
List < Object [ ] > hallbookingList = handleBookingHallDetailsReportRequest ( request , fromDate , toDate , filterby , zone , division , hallid ) ;
List < Object [ ] > hallbookingList = handleBookingHallDetailsReportRequest ( request , fromDate , toDate , filterby ,
zone , division , hallid ) ;
if ( "9" . equals ( request ) ) {
if ( "abstract" . equals ( reporttype ) ) {
if ( "abstract" . equals ( reporttype ) ) {
List < Object [ ] > counterBookingList = new ArrayList < > ( ) ;
counterBookingList = bookingService . getCounterWiseBookingCount ( fromDate , toDate ) ;
model . addAttribute ( "counterBookingList" , counterBookingList ) ;
System . out . println ( "counterBookingList.." + counterBookingList ) ;
List < Object [ ] > hallBookingByCounter = bookingService . getHallWiseBookingDetails ( fromDate , toDate , counterId ) ;
List < Object [ ] > hallBookingByCounter = bookingService . getHallWiseBookingDetails ( fromDate , toDate ,
counterId ) ;
/ / Convert to JSON for JS usage
String hallBookingJson = new ObjectMapper ( ) . writeValueAsString ( hallBookingByCounter ) ;
model . addAttribute ( "hallBookingJson" , hallBookingJson ) ;
List < Object [ ] > hallBookingDetails = bookingService . getBookingDetailsForAllHalls ( fromDate , toDate , counterId , hallid ) ;
List < Object [ ] > hallBookingDetails = bookingService . getBookingDetailsForAllHalls ( fromDate , toDate ,
counterId , hallid ) ;
String hallBookingDetailsJson = new ObjectMapper ( ) . writeValueAsString ( hallBookingDetails ) ;
model . addAttribute ( "hallBookingDetailsJson" , hallBookingDetailsJson ) ;
@ -300,7 +330,8 @@ public class HeadquartersController {
}
}
private List < Object [ ] > handleBookingHallDetailsReportRequest ( String request , String fromDate , String toDate , String filterby , String zone , String division , Integer hallid ) {
private List < Object [ ] > handleBookingHallDetailsReportRequest ( String request , String fromDate , String toDate ,
String filterby , String zone , String division , Integer hallid ) {
if ( ! request . equals ( "5" ) ) {
return new ArrayList < > ( ) ;
}
@ -321,7 +352,8 @@ public class HeadquartersController {
return new ArrayList < > ( ) ;
}
private List < Users > handleUserRequest ( String request , String fromDate , String toDate , String userstatus , String usertype ) {
private List < Users > handleUserRequest ( String request , String fromDate , String toDate , String userstatus ,
String usertype ) {
if ( ! request . equals ( "1" ) ) {
return new ArrayList < > ( ) ;
}
@ -337,8 +369,8 @@ public class HeadquartersController {
return userService . getAllUsers ( fromDate , toDate ) ;
}
private List < Object [ ] > handleBookingRequest ( String request , String fromDate , String toDate , String bookingStatus , String filterby , Long bookingId , String zone , String division , Integer hallid ) {
private List < Object [ ] > handleBookingRequest ( String request , String fromDate , String toDate , String bookingStatus ,
String filterby , Long bookingId , String zone , String division , Integer hallid ) {
if ( ! request . equals ( "2" ) ) {
return new ArrayList < > ( ) ;
}
@ -349,10 +381,12 @@ public class HeadquartersController {
return bookingDetailsRepo . getAllBookingDetailsWithBookingId ( fromDate , toDate , bookingId ) ;
}
if ( bookingId ! = null & & ! bookingStatus . isEmpty ( ) ) {
return bookingDetailsRepo . getAllBookingDetailsWithBookingIdwithbookingStatus ( fromDate , toDate , bookingId , bookingStatus ) ;
return bookingDetailsRepo . getAllBookingDetailsWithBookingIdwithbookingStatus ( fromDate , toDate , bookingId ,
bookingStatus ) ;
}
if ( bookingId = = null & & filterby . isEmpty ( ) & & ! bookingStatus . isEmpty ( ) ) {
return bookingService . getBookingDetailsByBookingDateWithStatus ( fromDate , toDate , bookingStatus , zone , division , hallid ) ;
return bookingService . getBookingDetailsByBookingDateWithStatus ( fromDate , toDate , bookingStatus , zone ,
division , hallid ) ;
}
if ( ! filterby . isEmpty ( ) ) {
@ -360,7 +394,8 @@ public class HeadquartersController {
if ( bookingStatus . isEmpty ( ) ) {
return bookingService . getBookingDetailsByBookingDate ( fromDate , toDate , zone , division , hallid ) ;
} else {
return bookingService . getBookingDetailsByBookingDateWithStatus ( fromDate , toDate , bookingStatus , zone , division , hallid ) ;
return bookingService . getBookingDetailsByBookingDateWithStatus ( fromDate , toDate , bookingStatus ,
zone , division , hallid ) ;
}
}
@ -368,7 +403,8 @@ public class HeadquartersController {
if ( bookingStatus . isEmpty ( ) ) {
return bookingService . getBookingDetailsByEventDate ( fromDate , toDate , zone , division , hallid ) ;
} else {
return bookingService . getBookingDetailsByEventDateWithStatus ( fromDate , toDate , bookingStatus , zone , division , hallid ) ;
return bookingService . getBookingDetailsByEventDateWithStatus ( fromDate , toDate , bookingStatus , zone ,
division , hallid ) ;
}
}
@ -377,8 +413,8 @@ public class HeadquartersController {
return new ArrayList < > ( ) ;
}
private List < BookingDetails > handleBookingSettlementRequest ( String request , String fromDate , String toDate , String refundStatus , String filterby ) {
private List < BookingDetails > handleBookingSettlementRequest ( String request , String fromDate , String toDate ,
String refundStatus , String filterby ) {
if ( ! request . equals ( "6" ) ) {
return new ArrayList < > ( ) ;
}
@ -394,7 +430,8 @@ public class HeadquartersController {
if ( refundStatus . isEmpty ( ) ) {
return bookingService . getAllBookingsettlementDetailsByBookingDate ( fromDate , toDate ) ;
} else {
return bookingService . getAllBookingsettlementDetailsByBookingDateWithStatus ( fromDate , toDate , refundStatus ) ;
return bookingService . getAllBookingsettlementDetailsByBookingDateWithStatus ( fromDate , toDate ,
refundStatus ) ;
}
}
@ -402,7 +439,8 @@ public class HeadquartersController {
if ( refundStatus . isEmpty ( ) ) {
return bookingService . getAllBookingsettlementDetailsByEventDate ( fromDate , toDate ) ;
} else {
return bookingService . getAllBookingsettlementDetailsByEventDateWithStatus ( fromDate , toDate , refundStatus ) ;
return bookingService . getAllBookingsettlementDetailsByEventDateWithStatus ( fromDate , toDate ,
refundStatus ) ;
}
}
@ -415,7 +453,7 @@ public class HeadquartersController {
@GetMapping ( "/ongoingevents" )
public String viewRecentevents ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
List < BookingDetails > presenteventslist = bookingDetailsRepository . findPresentBookingList ( ) ;
@ -436,13 +474,14 @@ public class HeadquartersController {
@GetMapping ( "/booking-list" )
public String viewBookingList ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
List < BookingDetails > bookingList = bookingDetailsRepository . getAllApprovedList ( ) ;
model . addAttribute ( "bookingList" , bookingList ) ;
return "headquarters/booking-list" ; / / Assuming "officer/rejected-booking-list" is the name of your HTML template
return "headquarters/booking-list" ; / / Assuming "officer/rejected-booking-list" is the name of your HTML
/ / template
} else {
session . invalidate ( ) ; / / Invalidate the session to clear all session attributes
return "redirect:/communityhall/login" ;
@ -452,7 +491,7 @@ public class HeadquartersController {
@GetMapping ( "/rejected-list" )
public String viewRejectedBookings ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
@ -469,7 +508,7 @@ public class HeadquartersController {
@GetMapping ( "/bookingwaitinglist" )
public String viewWaitingBookings ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
@ -486,7 +525,7 @@ public class HeadquartersController {
@GetMapping ( "/settlement-approved" )
public String viewSettlementMaster ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
List < BookingDetails > approvedSettlements = bookingDetailsRepository . findAllWithApprovedRefundStatus ( ) ;
@ -508,7 +547,7 @@ public class HeadquartersController {
@GetMapping ( "/settlement-initiatedlist" )
public String viewSettlementInitiatedMaster ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
List < BookingDetails > settlement = bookingDetailsRepository . findByBookingDetailsRefundStatus ( ) ;
@ -529,21 +568,21 @@ public class HeadquartersController {
@GetMapping ( "/settlement-list" )
public String settlementPendingList ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
model . addAttribute ( "headquartersname" , headquartersname ) ;
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "title" , "settlement Pending" ) ;
String zone = ( String ) session . getAttribute ( "zone" ) ;
model . addAttribute ( "zone" , zone ) ;
/ / ak
List < BookingDetails > settlementIntiated = bookingDetailsRepository . findSettlementInitiatedPending ( ) ;
/ / ak
List < BookingDetails > settlementIntiated = bookingDetailsRepository . findSettlementInitiatedPending ( ) ;
List < BookingDetails > settlement = bookingDetailsRepository . findAllSettlementPending ( ) ;
List < BookingDetails > cancelledbookings = bookingDetailsRepository . findAllSettlementCancelledList ( ) ;
List < BookingDetails > rejectedbookings = bookingDetailsRepository . findAllSettlementRejectedList ( ) ;
model . addAttribute ( "settlementlist" , settlement ) ;
/ / AK
model . addAttribute ( "settlementIntiated" , settlementIntiated ) ;
/ / AK
model . addAttribute ( "settlementIntiated" , settlementIntiated ) ;
model . addAttribute ( "cancelledbookings" , cancelledbookings ) ;
model . addAttribute ( "rejectedbookings" , rejectedbookings ) ;
return "headquarters/settlement-list" ;
@ -556,7 +595,7 @@ public class HeadquartersController {
@GetMapping ( "/refundfailed-list" )
public String RefundFailedList ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
model . addAttribute ( "headquartersname" , headquartersname ) ;
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
@ -564,8 +603,10 @@ public class HeadquartersController {
String zone = ( String ) session . getAttribute ( "zone" ) ;
model . addAttribute ( "zone" , zone ) ;
List < BookingDetails > settlementrefundfailed = bookingDetailsRepository . findAllSettlementRefundFailed ( ) ;
List < BookingDetails > refundfailedcancelledbookings = bookingDetailsRepository . findAllRefundFaileCancelledList ( ) ;
List < BookingDetails > refundfailedrejectedbookings = bookingDetailsRepository . findAllRefundFaileRejectedList ( ) ;
List < BookingDetails > refundfailedcancelledbookings = bookingDetailsRepository
. findAllRefundFaileCancelledList ( ) ;
List < BookingDetails > refundfailedrejectedbookings = bookingDetailsRepository
. findAllRefundFaileRejectedList ( ) ;
model . addAttribute ( "settlementrefundfailed" , settlementrefundfailed ) ;
model . addAttribute ( "refundfailedcancelledbookings" , refundfailedcancelledbookings ) ;
model . addAttribute ( "refundfailedrejectedbookings" , refundfailedrejectedbookings ) ;
@ -579,7 +620,7 @@ public class HeadquartersController {
@GetMapping ( "/settlement-completedlist" )
public String viewSettlementcompletedMaster ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
List < BookingDetails > completedlist = bookingDetailsRepository . findSettlementCompletedList ( ) ;
@ -600,7 +641,7 @@ public class HeadquartersController {
@GetMapping ( "/settlementlist" )
public String viewSettlementList ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
List < BookingDetails > settlemetList = bookingDetailsRepository . getAllSettlementList ( ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
model . addAttribute ( "settlemetList" , settlemetList ) ;
@ -614,7 +655,7 @@ public class HeadquartersController {
@GetMapping ( "/headquarterspage" )
public String viewcaretaker ( Model model , HttpSession session , @RequestParam ( "bookingId" ) int bookingId ) {
String caretakerName = ( String ) session . getAttribute ( "usertype" ) ;
if ( caretakerName ! = null ) {
if ( caretakerName ! = null & & "headquarters" . equals ( caretakerName ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "caretakerName" , caretakerName ) ;
@ -632,7 +673,7 @@ public class HeadquartersController {
@GetMapping ( "/settlement-reject" )
public String settlementRejectedList ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
List < BookingDetails > settlement = bookingDetailsRepository . findAllSettlementRejected ( ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
model . addAttribute ( "title" , "Settlement Rejected" ) ;
@ -653,7 +694,7 @@ public class HeadquartersController {
@GetMapping ( "/Gccblocking" )
public String viewGccBlocking ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
@ -703,7 +744,7 @@ public class HeadquartersController {
@GetMapping ( "/viewUploadNoc" )
public String viewUploadNoc ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null ) {
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
@ -720,5 +761,255 @@ public class HeadquartersController {
}
}
}
/ / Newly added by kani for care - take and officer login creation 11 / 06 / 2026
@GetMapping ( "/login-creation" )
public String viewLoginCreation ( Model model , HttpSession session ) {
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname ! = null & & "headquarters" . equals ( headquartersname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "headquartersname" , headquartersname ) ;
/ / Fetch existing active non - admin logins ( returns projection , not full entity )
List < Map < String , Object > > loginList = loginRepository . findActiveLogins ( ) ;
model . addAttribute ( "loginList" , loginList ) ;
/ / Fetch hall details for the modal dropdown
List < Map < String , Object > > hallList = hallDetailsRepository . getAllHalls ( ) ;
model . addAttribute ( "hallList" , hallList ) ;
return "headquarters/login-creation" ;
} else {
session . invalidate ( ) ;
return "redirect:/communityhall/login" ;
}
}
@PostMapping ( "/login-creation/save" )
@ResponseBody
@Transactional
public Map < String , Object > saveLoginCreation (
@RequestParam ( "mobileNumber" ) long mobileNumber ,
@RequestParam ( "name" ) String name ,
@RequestParam ( "password" ) String password ,
@RequestParam ( "userType" ) String userType ,
@RequestParam ( "zone" ) String zone ,
@RequestParam ( value = "hallIds" , required = false ) List < Integer > hallIds ,
HttpSession session ) {
Map < String , Object > response = new HashMap < > ( ) ;
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname = = null & & "headquarters" . equals ( headquartersname ) ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Session expired. Please log in again." ) ;
return response ;
}
try {
/* -------- Duplicate hall check for counter / caretaker -------- */
boolean isSingleMode = "counter" . equals ( userType ) | | "caretaker" . equals ( userType ) ;
boolean isMulitpleMode = "officer" . equals ( userType ) ;
if ( isSingleMode & & hallIds ! = null & & ! hallIds . isEmpty ( ) ) {
int hallId = hallIds . get ( 0 ) ;
int existingCount = loginRepository . countActiveLoginsByHallId ( hallId , userType ) ;
if ( existingCount > 0 ) {
/ / Fetch hall name for a clear message
String hallName = hallId + "" ;
try {
String fetched = hallDetailsRepository . findHallNameById ( hallId ) ;
if ( fetched ! = null & & ! fetched . isBlank ( ) )
hallName = fetched ;
} catch ( Exception ignored ) {
}
response . put ( "status" , "error" ) ;
response . put ( "message" , "A login already exists for hall \"" + hallName
+ "\". Only one counter/caretaker login is allowed per hall." ) ;
return response ;
}
}
/* -------- Duplicate hall check for officer -------- */
if ( isMulitpleMode & & hallIds ! = null & & ! hallIds . isEmpty ( ) ) {
int existingCount = loginRepository . getActiveLoginsByHallIds ( hallIds , userType ) ;
if ( existingCount > 0 ) {
response . put ( "status" , "error" ) ;
response . put ( "message" ,
"A login already exists for the selected hall(s). Only one officer login is allowed per hall." ) ;
return response ;
}
}
Login login = new Login ( ) ;
login . setMobileNumber ( mobileNumber ) ;
login . setName ( name ) ;
login . setPassword ( password ) ;
login . setUserType ( userType ) ;
login . setZone ( zone ) ;
login . setActive ( true ) ;
login . setDelete ( false ) ;
if ( hallIds = = null | | hallIds . isEmpty ( ) ) {
/ / HQ may have no hall assigned
loginRepository . save ( login ) ;
} else if ( hallIds . size ( ) = = 1 ) {
/ / Single hall : store directly in login . hallId
login . setHallId ( hallIds . get ( 0 ) ) ;
loginRepository . save ( login ) ;
} else {
/ / Multiple halls : store first in hallId , rest in login_hall_ids
login . setHallId ( hallIds . get ( 0 ) ) ;
Login savedLogin = loginRepository . save ( login ) ;
for ( int hallId : hallIds ) {
LoginHallId loginHallId = new LoginHallId ( savedLogin , hallId ) ;
loginHallIdRepository . save ( loginHallId ) ;
}
}
response . put ( "status" , "success" ) ;
response . put ( "message" , "Login created successfully." ) ;
} catch ( Exception e ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Error creating login: " + e . getMessage ( ) ) ;
}
return response ;
}
@PostMapping ( "/login-creation/delete/{id}" )
@ResponseBody
@Transactional
public Map < String , Object > deleteLogin ( @PathVariable ( "id" ) int id , HttpSession session ) {
Map < String , Object > response = new HashMap < > ( ) ;
String headquartersname = ( String ) session . getAttribute ( "usertype" ) ;
if ( headquartersname = = null & & "headquarters" . equals ( headquartersname ) ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Session expired. Please log in again." ) ;
return response ;
}
try {
Login login = loginRepository . findLoginById ( id ) ;
if ( login = = null ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Login not found." ) ;
return response ;
}
/ / Soft delete : set is_active = 0 , is_delete = 1
login . setActive ( false ) ;
login . setDelete ( true ) ;
loginRepository . save ( login ) ;
/ / Also soft - delete any related login_hall_ids
loginHallIdRepository . softDeleteByLoginId ( id ) ;
response . put ( "status" , "success" ) ;
response . put ( "message" , "Login deleted successfully." ) ;
} catch ( Exception e ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Error deleting login: " + e . getMessage ( ) ) ;
}
return response ;
}
@GetMapping ( "/login-creation/check-mobile" )
@ResponseBody
public Map < String , Object > checkMobileExists ( @RequestParam ( "mobileNumber" ) long mobileNumber , HttpSession session ) {
Map < String , Object > response = new HashMap < > ( ) ;
try {
int count = loginRepository . countByMobileNumber ( mobileNumber ) ;
response . put ( "exists" , count > 0 ) ;
} catch ( Exception e ) {
response . put ( "exists" , false ) ;
response . put ( "error" , e . getMessage ( ) ) ;
}
return response ;
}
@GetMapping ( "/login-creation/halls-by-zone" )
@ResponseBody
public List < Map < String , Object > > getHallsByZone ( @RequestParam ( "zone" ) String zone , HttpSession session ) {
try {
return hallDetailsRepository . getHallsByZone ( zone ) ;
} catch ( Exception e ) {
return new java . util . ArrayList < > ( ) ;
}
}
@GetMapping ( "/login-creation/get-login-halls" )
@ResponseBody
public Map < String , Object > getLoginHalls ( @RequestParam ( "loginId" ) int loginId , HttpSession session ) {
Map < String , Object > response = new HashMap < > ( ) ;
try {
Login login = loginRepository . findLoginById ( loginId ) ;
if ( login = = null ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Login not found." ) ;
return response ;
}
/ / Collect all assigned hall IDs
java . util . List < Integer > assignedHallIds = new java . util . ArrayList < > ( ) ;
if ( login . getHallId ( ) ! = 0 ) {
assignedHallIds . add ( login . getHallId ( ) ) ;
}
loginHallIdRepository . findActiveByLoginId ( loginId ) . forEach ( lh - > assignedHallIds . add ( lh . getHallId ( ) ) ) ;
response . put ( "status" , "success" ) ;
response . put ( "loginId" , loginId ) ;
response . put ( "name" , login . getName ( ) ) ;
response . put ( "zone" , login . getZone ( ) ) ;
response . put ( "userType" , login . getUserType ( ) ) ;
response . put ( "assignedHallIds" , assignedHallIds ) ;
/ / Also return all halls for the zone
response . put ( "hallsForZone" , hallDetailsRepository . getHallsByZone ( login . getZone ( ) ) ) ;
} catch ( Exception e ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Error fetching login halls: " + e . getMessage ( ) ) ;
}
return response ;
}
@PostMapping ( "/login-creation/update-halls" )
@ResponseBody
@Transactional
public Map < String , Object > updateLoginHalls (
@RequestParam ( "loginId" ) int loginId ,
@RequestParam ( "hallIds" ) java . util . List < Integer > hallIds ,
HttpSession session ) {
Map < String , Object > response = new HashMap < > ( ) ;
try {
Login login = loginRepository . findLoginById ( loginId ) ;
if ( login = = null ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Login not found." ) ;
return response ;
}
if ( hallIds = = null | | hallIds . isEmpty ( ) ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "At least one hall must be selected." ) ;
return response ;
}
/ / Clear all existing login_hall_ids rows for this login
loginHallIdRepository . softDeleteByLoginId ( loginId ) ;
if ( hallIds . size ( ) = = 1 ) {
/ / Single hall : store in login . hall_id only
login . setHallId ( hallIds . get ( 0 ) ) ;
loginRepository . save ( login ) ;
} else {
/ / Multiple halls : first goes to login . hall_id , rest to login_hall_ids
login . setHallId ( hallIds . get ( 0 ) ) ;
loginRepository . save ( login ) ;
for ( int i = 1 ; i < hallIds . size ( ) ; i + + ) {
LoginHallId lh = new LoginHallId ( login , hallIds . get ( i ) ) ;
loginHallIdRepository . save ( lh ) ;
}
}
response . put ( "status" , "success" ) ;
response . put ( "message" , "Hall assignment updated successfully." ) ;
} catch ( Exception e ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Error updating halls: " + e . getMessage ( ) ) ;
}
return response ;
}
}