Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,20 @@

@RestController
@RequestMapping("/borrow")
public class BorrowController {

public class BorrowController {

@Autowired
private BorrowService bService;


//load all borrow list
@GetMapping
public Collection<Borrow> list() {
return bService.listAll();
}

//borrow list @admin


// @GetMapping("/fetching/{string}/{date1}/{date2}")
// public Collection<BookingView> listinguserdropdown(@PathVariable String string,@PathVariable Date date1, @PathVariable Date date2) {
// return bookingService.listinguserdropdown(string,date1, date2);
// }

//pagenated borrow list at admin borrow
@GetMapping("/pagenated/")
public ResponseEntity<List<Borrow>>getAllBorrows(
@RequestParam(defaultValue = "1") Integer pageNo,
Expand All @@ -62,6 +60,26 @@ public class BorrowController {
}


//load results of issuedate filter
@GetMapping("/loadByIssueDate/{date1}/{date2}")
public ResponseEntity<List<Borrow>> loadByIssueDate(
@PathVariable("date1") Date date1,
@PathVariable("date2") Date date2)
// {
// return bService.loadtAllByIssueDate(Date date1, Date date2);
// }
{
List<Borrow> list = bService.loadtAllByIssueDate(date1, date2);
return new ResponseEntity<List<Borrow>>(list,new HttpHeaders(),
HttpStatus.OK);
}






//Load filtered pagenated borrow list [on filtering]
@GetMapping("/{date1}/{date2}")
public ResponseEntity<List<Borrow>>getFilterBorrow(
// @PathVariable Date date1, @PathVariable Date date2,
Expand All @@ -78,19 +96,13 @@ public class BorrowController {

}

// @PutMapping("/{borrowId}")
// public BorrowDetailView updateApprove(
// @PathVariable("borrowId") Integer borrowId,
// @Valid @RequestBody BorrowForm form
// ) {
// return bService.updates(borrowId, form);
// }


//pagenation+sort at user borrow history
@GetMapping("/userBorrow/pagenated/")
public ResponseEntity<List<Borrow>>getBorrowHistory(
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "2") Integer pageSize,
@RequestParam(defaultValue = "5") Integer pageSize,
@RequestParam(defaultValue = "id") String sortBy)
{
List<Borrow> list = bService.getBorrowHistory(pageNo-1, pageSize, sortBy);
Expand All @@ -104,11 +116,6 @@ public class BorrowController {








@PostMapping
public BorrowDetailView add(@Valid @RequestBody BorrowForm form) {
return bService.add(form);
Expand All @@ -128,10 +135,7 @@ public Collection<Borrow> listUserNotification(Principal p) {
return bService.listNotification();
}

@GetMapping
public Collection<Borrow> list() {
return bService.listAll();
}


@GetMapping("/due")
public Collection<Borrow> listDue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.sql.Date;
import java.util.Collection;
import java.util.List;

//import org.springframework.data.repository.Repository;
import org.springframework.data.repository.PagingAndSortingRepository;
Expand All @@ -24,11 +25,13 @@ public interface BorrowRepository extends PagingAndSortingRepository<Borrow, Int
Collection<BorrowListView> findAllByUserUserId(Integer userId);



//load all @ pagenation
public Page<Borrow> findAll(Pageable paging);

//load all with userId(in user-login)
public Page<Borrow> findAllByUserUserId(Integer userId,Pageable paging);

// public Page<Borrow> findAll(org.springframework.data.domain.Pageable paging);


//To select borrow details with user_id,a day before due day
@Query(value = "select * from borrow where borrow_id in(select borrow_id from borrow where due_date=date_add(curdate(),interval 1 day) and status='APPROVED' and user_id=?1)", nativeQuery = true)
Expand Down Expand Up @@ -69,25 +72,23 @@ public interface BorrowRepository extends PagingAndSortingRepository<Borrow, Int
@Query(value="update borrow set due_days=DATEDIFF(curdate(),due_date) WHERE borrow_id=?",nativeQuery=true)
void findDueDays(Integer borrowId);

//public Borrow save(Collection<Borrow> borrow);

//total sum of fine /user
// @Query(value=" select sum(fine) from borrow where user_id=?",nativeQuery=true)
// void findFineByUserId(Integer userId); public Page<Borrow> findAll(Pageable paging);

// @Query(value = "select * from borrow where issue_date between '2022-12-12' and '2022-12-20' ", nativeQuery = true)
// public Page<Borrow> findbyIssuDate(Pageable paging);

//Load Filterd results
@Query(value = "select * from borrow where issue_date between DATE(?1) and DATE(?2) and status!='REQUESTED'", nativeQuery = true)
List<Borrow> findbyIssuDate(java.sql.Date date1,java.sql.Date date2);


//pagenated filtered results
@Query(value = "select * from borrow where issue_date between DATE(?1) and DATE(?2) and status!='REQUESTED'", nativeQuery = true)
public Page<Borrow> findbyIssuDate( java.sql.Date date1,java.sql.Date date2,Pageable paging);

// public Page<Borrow> findbyIssuDate(java.util.Date date1, java.util.Date date2, Pageable paging);


// @Query(value = "select * from booking where booked_date BETWEEN DATE(?2) AND DATE(?3) and vaccine_id in(select vaccine_id from vaccine where vaccine_type=?1);",nativeQuery = true)
// Collection<Booking> findAll(String string, Date date1, Date date2);




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface BorrowService {
BorrowDetailView add(BorrowForm form);

Collection<Borrow> listAll();
List<Borrow> loadtAllByIssueDate(Date date1, Date date2);

BorrowDetailView list(Integer borrowId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ public BorrowDetailView add(BorrowForm form){

@Override
public Collection<Borrow> listAll() {
return borrowRepository.findAll();

return borrowRepository.findAll();
}


@Override
public List<Borrow> loadtAllByIssueDate(java.sql.Date date1, java.sql.Date date2) {
return borrowRepository.findbyIssuDate(date1,date2);
}


Expand Down Expand Up @@ -213,7 +218,7 @@ public BorrowDetailView listByUser(Integer borrowId, BorrowForm form) {
@Transactional
public List<Borrow>getAllBorrow( java.sql.Date date1, java.sql.Date date2,Integer pageNo, Integer pageSize, String sortBy){

Pageable paging = PageRequest.of(pageNo, pageSize, Sort.by(sortBy));
Pageable paging = PageRequest.of(pageNo, pageSize, Sort .by(sortBy));

Page<Borrow> pagedResult = borrowRepository.findbyIssuDate(date1,date2,paging);

Expand Down
7 changes: 4 additions & 3 deletions FrontEnd/iprjt/src/app/borrow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ export class BorrowService {
return this.http.get("http://localhost:8080/borrow/pagenated/?pageNo="+page+"&pageSize="+tableSize+"&sortBy="+sort)
}

filterBorrowPagination(date1:any,date2:any,page:any,tableSize:any,sort:any){
// return this.http.get("http://localhost:8080/borrow/"+date1+"/"+date2+"?page="+page+"&pageSize="+tableSize+"&sortBy="+sort)
filterBorrowPagination(date1:any,date2:any,page:any,tableSize:any,sort:any){
console.log(date1)
return this.http.get(this.apiurl + "/borrow/"+date1+"/"+date2+"/?pageNo="+page+"&pageSize="+tableSize+"&sortBy="+sort)
}
// return this.http.get(this.apiurl + `/users/fetching/${type}/${date1}/${date2}`, httpOptions)

LoadByIssueDate(date1:any,date2:any){
return this.http.get(this.apiurl + "/borrow/loadByIssueDate/"+date1+"/"+date2);
}

Load(){
return this.http.get('http://localhost:8080/borrow');
Expand Down
4 changes: 3 additions & 1 deletion FrontEnd/iprjt/src/app/borrow/borrow.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ <h2 style="text-align:center ;">Borrow Details</h2>
<div><input type="date" formControlName="date1" value="date1" max="{{date| date:'yyyy/MM/dd' }}" ></div>
<div><input type="date" formControlName="date2" value="date2" max="{{date| date:'yyyy/MM/dd' }}"></div>

<div><input type="button" (click)="getFilter()" value="FILTER"></div>
<div><input type="button" (click)="getFilter()" value="FILTER">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" (click)="clearFilter()" value="CLEAR FILTER">
</div>

<table align="center" class="table-bordered" id="datatable" role="grid" >

Expand Down
113 changes: 43 additions & 70 deletions FrontEnd/iprjt/src/app/borrow/borrow.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class BorrowComponent implements OnInit {
searchData:any
sort:string="status";
len: any;
flag:number=0;
//borrow_id:any;
constructor(private router:Router ,private service:BorrowService,private booksService:BooksService) {

Expand All @@ -51,7 +52,6 @@ export class BorrowComponent implements OnInit {
this.len=result;
console.log(result)
this.count=this.len.length;
console.log(this.count)
//this.data=result;

})
Expand Down Expand Up @@ -84,96 +84,69 @@ export class BorrowComponent implements OnInit {
this.sort=a;
this.page=this.page;
this.tableSize;
this.ngOnInit();

this.ngOnInit();
// this.getFilter();
}
getFilter() {

console.log(this.ObjSampleForm)
// this.page=1

// this.page=1
this.flag=1;
this.service.LoadByIssueDate(this.ObjSampleForm.controls['date1'].value,this.ObjSampleForm.controls['date2'].value).subscribe(result=>{
this.len=result;
console.log(result)
this.count=this.len.length;
})

if(this.searchData==null || this.searchData==""){

this.sort="borrow_id";
this.service.filterBorrowPagination(this.ObjSampleForm.controls['date1'].value,this.ObjSampleForm.controls['date2'].value,this.page,this.tableSize,this.sort).subscribe({
next: (res: any) => {
console.log("infilter")
console.log(res);
console.log("endfilter")
this.len=res;
this.count=this.len.length;
this.data=res;

},
error: (error: any) => {
console.log(error);
}
})
// }
// this.service.Load().subscribe(result=>{
// this.len=result;
// console.log(result)
// this.count=this.len.length;
// // console.log(this.count)
// //this.data=result;
//console.log("--------")
console.log(res);
this.data=res;
},
});

// })
//this.onTableDataChange(this.page);

// if(this.searchData==null || this.searchData==""){
// this.service.borrowPagination(this.page,this.tableSize,this.sort).subscribe((result=>{
// this.data=result;
// console.log('OnloadPagenation')
// console.log(this.data)
// }));
// }
// else{

// this.data=this.searchData
// }


}

else{

this.data=this.searchData
}
}

// LoadBorrow(){
// // this.service.Load().subscribe((data: any)=>{
// // this.borrowdata=data;
// // console.log(data);});
// this.service.Load().subscribe(
// (response) => {
// //this.POSTS = response;
// this.borrowdata=response;
// console.log(response);
// },
// (error) => {
// console.log(error);
// }
// );
// }
clearFilter(){
this.flag=0;
window.location.reload();
}


onTableDataChange(event: any) {
console.log(event)
console.log(event)
if(this.flag==0){
console.log('flag=',this.flag)
this.service.borrowPagination(event,this.tableSize,this.sort).subscribe((result=>{
this.data=result;
console.log('sorted')
}),
);
}
else if(this.flag==1){
console.log('flag=',this.flag)
this.service.filterBorrowPagination(this.ObjSampleForm.controls['date1'].value,this.ObjSampleForm.controls['date2'].value,this.page,this.tableSize,this.sort).subscribe({
next: (res: any) => {
console.log("--------")
console.log(res);
this.data=res;
},
});
}
}
// onTableSizeChange(event: any): void {
// this.tableSize = event.target.value;
// this.page = 1;
// this.LoadBorrow();
// }










///////////////////////////////////////////////- C R U D -////////////////////////////////////////////////////

home()
{
this.router.navigate(['/body'])
Expand Down