@ -222,6 +222,253 @@ public class TonerService {
return map ;
}
/ / = = = = = = = = = = = = = = = = Adding department & toners & printers = = = = = = = = = = = = = = = =
public boolean savenewdepartment ( String department ) {
if ( department = = null | | department . trim ( ) . isEmpty ( ) ) return false ;
String cleanDept = department . trim ( ) ;
try {
String sql = "INSERT INTO toner_department_list (dept_name, is_active, is_delete) VALUES (?, 1, 0)" ;
jdbcTemplate . update ( sql , cleanDept ) ;
return true ;
} catch ( Exception e ) {
try {
String sql2 = "INSERT INTO toner_department_list (department_name, is_active, is_delete) VALUES (?, 1, 0)" ;
jdbcTemplate . update ( sql2 , cleanDept ) ;
return true ;
} catch ( Exception ex ) {
try {
String sql3 = "INSERT INTO toner_department_list (dept_name) VALUES (?)" ;
jdbcTemplate . update ( sql3 , cleanDept ) ;
return true ;
} catch ( Exception ex2 ) {
ex2 . printStackTrace ( ) ;
return false ;
}
}
}
}
public boolean savetonermodel ( int pid , String modelname , String partcode ) {
if ( pid < = 0 | | modelname = = null | | modelname . trim ( ) . isEmpty ( ) ) return false ;
String cleanModel = modelname . trim ( ) ;
String cleanPart = ( partcode ! = null & & ! partcode . trim ( ) . isEmpty ( ) ) ? partcode . trim ( ) : null ;
try {
String sql = "INSERT INTO toner_model_list (pid, model_name, part_code, is_active, is_delete) VALUES (?, ?, ?, 1, 0)" ;
jdbcTemplate . update ( sql , pid , cleanModel , cleanPart ) ;
return true ;
} catch ( Exception e ) {
try {
String sql2 = "INSERT INTO toner_model_list (pid, model_name, part_code) VALUES (?, ?, ?)" ;
jdbcTemplate . update ( sql2 , pid , cleanModel , cleanPart ) ;
return true ;
} catch ( Exception ex ) {
ex . printStackTrace ( ) ;
return false ;
}
}
}
public boolean saveprintermodel ( String printermodel ) {
if ( printermodel = = null | | printermodel . trim ( ) . isEmpty ( ) ) return false ;
String cleanPrinter = printermodel . trim ( ) ;
try {
String sql = "INSERT INTO toner_printer_model_list (printer_name, is_active, is_delete) VALUES (?, 1, 0)" ;
jdbcTemplate . update ( sql , cleanPrinter ) ;
return true ;
} catch ( Exception e ) {
try {
String sql2 = "INSERT INTO toner_printer_model_list (printer_name) VALUES (?)" ;
jdbcTemplate . update ( sql2 , cleanPrinter ) ;
return true ;
} catch ( Exception ex ) {
ex . printStackTrace ( ) ;
return false ;
}
}
}
public boolean updatePrinterModel ( int id , String printermodel ) {
if ( id < = 0 | | printermodel = = null | | printermodel . trim ( ) . isEmpty ( ) ) return false ;
String cleanPrinter = printermodel . trim ( ) ;
try {
String sql = "UPDATE toner_printer_model_list SET printer_name = ? WHERE id = ?" ;
return jdbcTemplate . update ( sql , cleanPrinter , id ) > 0 ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
}
}
public boolean updateTonerModel ( int id , int pid , String modelname , String partcode ) {
if ( id < = 0 | | pid < = 0 | | modelname = = null | | modelname . trim ( ) . isEmpty ( ) ) return false ;
String cleanModel = modelname . trim ( ) ;
String cleanPart = ( partcode ! = null & & ! partcode . trim ( ) . isEmpty ( ) ) ? partcode . trim ( ) : null ;
try {
String sql = "UPDATE toner_model_list SET pid = ?, model_name = ?, part_code = ? WHERE id = ?" ;
return jdbcTemplate . update ( sql , pid , cleanModel , cleanPart , id ) > 0 ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
}
}
public boolean updateDepartment ( int id , String department ) {
if ( id < = 0 | | department = = null | | department . trim ( ) . isEmpty ( ) ) return false ;
String cleanDept = department . trim ( ) ;
try {
String sql = "UPDATE toner_department_list SET dept_name = ? WHERE id = ?" ;
return jdbcTemplate . update ( sql , cleanDept , id ) > 0 ;
} catch ( Exception e ) {
try {
String sql2 = "UPDATE toner_department_list SET department_name = ? WHERE id = ?" ;
return jdbcTemplate . update ( sql2 , cleanDept , id ) > 0 ;
} catch ( Exception ex ) {
ex . printStackTrace ( ) ;
return false ;
}
}
}
public boolean deletePrinterModel ( int id ) {
if ( id < = 0 ) return false ;
try {
String sql = "UPDATE toner_printer_model_list SET is_active = 0, is_delete = 1 WHERE id = ?" ;
return jdbcTemplate . update ( sql , id ) > 0 ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
}
}
public boolean restorePrinterModel ( int id ) {
if ( id < = 0 ) return false ;
try {
String sql = "UPDATE toner_printer_model_list SET is_active = 1, is_delete = 0 WHERE id = ?" ;
return jdbcTemplate . update ( sql , id ) > 0 ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
}
}
public boolean deleteTonerModel ( int id ) {
if ( id < = 0 ) return false ;
try {
String sql = "UPDATE toner_model_list SET is_active = 0, is_delete = 1 WHERE id = ?" ;
return jdbcTemplate . update ( sql , id ) > 0 ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
}
}
public boolean restoreTonerModel ( int id ) {
if ( id < = 0 ) return false ;
try {
String sql = "UPDATE toner_model_list SET is_active = 1, is_delete = 0 WHERE id = ?" ;
return jdbcTemplate . update ( sql , id ) > 0 ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
}
}
public boolean deleteDepartment ( int id ) {
if ( id < = 0 ) return false ;
try {
String sql = "UPDATE toner_department_list SET is_active = 0, is_delete = 1 WHERE id = ?" ;
return jdbcTemplate . update ( sql , id ) > 0 ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
}
}
public boolean restoreDepartment ( int id ) {
if ( id < = 0 ) return false ;
try {
String sql = "UPDATE toner_department_list SET is_active = 1, is_delete = 0 WHERE id = ?" ;
return jdbcTemplate . update ( sql , id ) > 0 ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
}
}
public List < Map < String , Object > > getMasterPrinters ( String status ) {
try {
String sql ;
if ( "deleted" . equalsIgnoreCase ( status ) ) {
sql = "SELECT id, printer_name, is_active, is_delete FROM toner_printer_model_list WHERE (is_delete = 1 OR is_active = 0) ORDER BY id DESC" ;
} else if ( "all" . equalsIgnoreCase ( status ) ) {
sql = "SELECT id, printer_name, is_active, is_delete FROM toner_printer_model_list ORDER BY printer_name ASC" ;
} else {
sql = "SELECT id, printer_name, is_active, is_delete FROM toner_printer_model_list WHERE (is_active IS NULL OR is_active = 1) AND (is_delete IS NULL OR is_delete = 0) ORDER BY printer_name ASC" ;
}
return jdbcTemplate . queryForList ( sql ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return new ArrayList < > ( ) ;
}
}
public List < Map < String , Object > > getMasterToners ( String status ) {
try {
String sql ;
if ( "deleted" . equalsIgnoreCase ( status ) ) {
sql = "SELECT t.id, t.pid, t.model_name, t.part_code, p.printer_name, t.is_active, t.is_delete FROM toner_model_list t " +
"LEFT JOIN toner_printer_model_list p ON t.pid = p.id " +
"WHERE (t.is_delete = 1 OR t.is_active = 0) ORDER BY t.id DESC" ;
} else if ( "all" . equalsIgnoreCase ( status ) ) {
sql = "SELECT t.id, t.pid, t.model_name, t.part_code, p.printer_name, t.is_active, t.is_delete FROM toner_model_list t " +
"LEFT JOIN toner_printer_model_list p ON t.pid = p.id ORDER BY p.printer_name ASC, t.model_name ASC" ;
} else {
sql = "SELECT t.id, t.pid, t.model_name, t.part_code, p.printer_name, t.is_active, t.is_delete FROM toner_model_list t " +
"LEFT JOIN toner_printer_model_list p ON t.pid = p.id " +
"WHERE (t.is_active IS NULL OR t.is_active = 1) AND (t.is_delete IS NULL OR t.is_delete = 0) " +
"ORDER BY p.printer_name ASC, t.model_name ASC" ;
}
return jdbcTemplate . queryForList ( sql ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return new ArrayList < > ( ) ;
}
}
public List < Map < String , Object > > getMasterDepartments ( String status ) {
try {
String sql ;
if ( "deleted" . equalsIgnoreCase ( status ) ) {
sql = "SELECT id, dept_name, is_active, is_delete FROM toner_department_list WHERE (is_delete = 1 OR is_active = 0) ORDER BY id DESC" ;
} else if ( "all" . equalsIgnoreCase ( status ) ) {
sql = "SELECT id, dept_name, is_active, is_delete FROM toner_department_list ORDER BY dept_name ASC" ;
} else {
sql = "SELECT id, dept_name, is_active, is_delete FROM toner_department_list WHERE (is_active IS NULL OR is_active = 1) AND (is_delete IS NULL OR is_delete = 0) ORDER BY dept_name ASC" ;
}
return jdbcTemplate . queryForList ( sql ) ;
} catch ( Exception e ) {
try {
String fallbackSql ;
if ( "deleted" . equalsIgnoreCase ( status ) ) {
fallbackSql = "SELECT id, department_name AS dept_name, is_active, is_delete FROM toner_department_list WHERE (is_delete = 1 OR is_active = 0) ORDER BY id DESC" ;
} else if ( "all" . equalsIgnoreCase ( status ) ) {
fallbackSql = "SELECT id, department_name AS dept_name, is_active, is_delete FROM toner_department_list ORDER BY department_name ASC" ;
} else {
fallbackSql = "SELECT id, department_name AS dept_name, is_active, is_delete FROM toner_department_list WHERE (is_active IS NULL OR is_active = 1) AND (is_delete IS NULL OR is_delete = 0) ORDER BY department_name ASC" ;
}
return jdbcTemplate . queryForList ( fallbackSql ) ;
} catch ( Exception ex ) {
ex . printStackTrace ( ) ;
return new ArrayList < > ( ) ;
}
}
}
public List < Map < String , Object > > getAllActiveToners ( ) {
return getMasterToners ( "active" ) ;
}
/ / = = = = = = = = = = = = = = = = = PRINTERS & TONERS = = = = = = = = = = = = = = = = =
public List < Map < String , Object > > getActivePrinters ( ) {
String sql = "SELECT id, printer_name FROM toner_printer_model_list WHERE is_active = 1 AND is_delete = 0" ;
@ -441,7 +688,9 @@ public class TonerService {
int pid , int tid , int qtyRequested , String newUploadPath , String username ) {
Timestamp now = new Timestamp ( System . currentTimeMillis ( ) ) ;
try {
String safeZoneId = ( zoneId ! = null & & ! zoneId . trim ( ) . isEmpty ( ) & & ! "null" . equalsIgnoreCase ( zoneId ) ) ? zoneId . trim ( ) : null ;
String safeZoneId = ( zoneId ! = null & & ! zoneId . trim ( ) . isEmpty ( ) & & ! "null" . equalsIgnoreCase ( zoneId ) )
? zoneId . trim ( )
: null ;
if ( newUploadPath ! = null & & ! newUploadPath . trim ( ) . isEmpty ( ) ) {
String sql = "UPDATE toner_department_requested_details SET " +
"itcell_ref_no = ?, dept_id = ?, zone_id = ?, pid = ?, tid = ?, " +