Implements the school fees gestion for a student and a payment table containing a history of all the financial transactions of the system

This commit is contained in:
LeoMoulin 2024-04-08 14:50:37 +02:00
parent 194b14f02b
commit e6e147af26
11 changed files with 238 additions and 15 deletions

View File

@ -13,6 +13,7 @@ import ovh.herisson.Clyde.Tables.Role;
import java.util.*; import java.util.*;
@RestController @RestController
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class MinervalController { public class MinervalController {
private final AuthenticatorService authServ; private final AuthenticatorService authServ;
private final MinervalRepository mr; private final MinervalRepository mr;
@ -42,4 +43,14 @@ public class MinervalController {
Minerval m = mlist.get(0); Minerval m = mlist.get(0);
return new ResponseEntity<>(m, HttpStatus.OK); return new ResponseEntity<>(m, HttpStatus.OK);
} }
@PatchMapping("/minerval")
public ResponseEntity<Object> updateMinerval(@RequestBody Minerval updatedMinerval){
Minerval minerval = mr.findById(updatedMinerval.getId());
minerval.setPaidAmount(updatedMinerval.getPaidAmount());
minerval.setToPay(updatedMinerval.getToPay());
mr.save(minerval);
return new ResponseEntity<>(HttpStatus.OK);
}
} }

View File

@ -2,6 +2,7 @@ package ovh.herisson.Clyde.EndPoints;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.MinervalRepository;
import ovh.herisson.Clyde.Repositories.TokenRepository; import ovh.herisson.Clyde.Repositories.TokenRepository;
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository; import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
import ovh.herisson.Clyde.Repositories.UserRepository; import ovh.herisson.Clyde.Repositories.UserRepository;
@ -29,7 +30,9 @@ public class MockController {
public final UserCurriculumRepository ucr; public final UserCurriculumRepository ucr;
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, UserCurriculumRepository ucr){ public final MinervalRepository minervalRepository;
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository){
this.tokenRepo = tokenRepo; this.tokenRepo = tokenRepo;
this.userRepo = userRepo; this.userRepo = userRepo;
this.tokenService = tokenService; this.tokenService = tokenService;
@ -38,6 +41,7 @@ public class MockController {
this.courseService = courseService; this.courseService = courseService;
this.inscriptionService = inscriptionService; this.inscriptionService = inscriptionService;
this.ucr = ucr; this.ucr = ucr;
this.minervalRepository = minervalRepository;
} }
/** Saves an example of each user type by : /** Saves an example of each user type by :
@ -61,6 +65,8 @@ public class MockController {
userRepo.saveAll(mockUsers); userRepo.saveAll(mockUsers);
Minerval minerval = new Minerval(joe.getRegNo(), 0, 852, 2023);
minervalRepository.save(minerval);
// Course / Curriculum part // Course / Curriculum part
Curriculum infoBab1 = new Curriculum(1,"info"); Curriculum infoBab1 = new Curriculum(1,"info");

View File

@ -0,0 +1,42 @@
package ovh.herisson.Clyde.EndPoints;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.PaymentRepository;
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
import ovh.herisson.Clyde.Tables.Minerval;
import ovh.herisson.Clyde.Tables.Payment;
import ovh.herisson.Clyde.Tables.Role;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
@RestController
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class PaymentController {
private final PaymentRepository paymentRepository;
public PaymentController(PaymentRepository paymentRepository){
this.paymentRepository = paymentRepository;
}
//Post a payment record
@PostMapping("/payment")
public ResponseEntity<Object> postPayment(@RequestBody Payment payment){
paymentRepository.save(payment);
return new ResponseEntity<>(HttpStatus.OK);
}
//Get all payment records of a student
@GetMapping("/payment/{studentRegNo}")
public ResponseEntity<ArrayList<Payment>> getPaymentsByUser(@PathVariable long studentRegNo){
ArrayList<Payment> toReturn = paymentRepository.getPaymentsByStudentRegNo(studentRegNo);
return new ResponseEntity<>(toReturn, HttpStatus.OK);
}
}

View File

@ -7,4 +7,6 @@ import java.util.ArrayList;
public interface MinervalRepository extends CrudRepository<Minerval, Long> { public interface MinervalRepository extends CrudRepository<Minerval, Long> {
public ArrayList<Minerval> getMinervalsByStudentRegNoOrderByYearDesc(Long studentRegNo); public ArrayList<Minerval> getMinervalsByStudentRegNoOrderByYearDesc(Long studentRegNo);
public Minerval findById(long id);
} }

View File

@ -0,0 +1,10 @@
package ovh.herisson.Clyde.Repositories;
import org.springframework.data.repository.CrudRepository;
import ovh.herisson.Clyde.Tables.Payment;
import java.util.ArrayList;
public interface PaymentRepository extends CrudRepository<Payment, Long> {
public ArrayList<Payment> getPaymentsByStudentRegNo(long regNo);
}

View File

@ -2,14 +2,8 @@ package ovh.herisson.Clyde.Services;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.CurriculumRepository; import ovh.herisson.Clyde.Repositories.*;
import ovh.herisson.Clyde.Repositories.InscriptionRepository; import ovh.herisson.Clyde.Tables.*;
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Tables.InscriptionRequest;
import ovh.herisson.Clyde.Tables.RequestState;
import ovh.herisson.Clyde.Tables.User;
import ovh.herisson.Clyde.Tables.UserCurriculum;
@Service @Service
public class InscriptionService { public class InscriptionService {
@ -22,14 +16,16 @@ public class InscriptionService {
private final CurriculumRepository curriculumRepo; private final CurriculumRepository curriculumRepo;
private final MinervalRepository minervalRepository;
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
public InscriptionService(InscriptionRepository inscriptionRepo, UserRepository userRepo, UserCurriculumRepository userCurriculumRepo, CurriculumRepository curriculumRepo){ public InscriptionService(InscriptionRepository inscriptionRepo, UserRepository userRepo, UserCurriculumRepository userCurriculumRepo, CurriculumRepository curriculumRepo, MinervalRepository minervalRepository){
this.inscriptionRepo = inscriptionRepo; this.inscriptionRepo = inscriptionRepo;
this.userRepo = userRepo; this.userRepo = userRepo;
this.userCurriculumRepo = userCurriculumRepo; this.userCurriculumRepo = userCurriculumRepo;
this.curriculumRepo = curriculumRepo; this.curriculumRepo = curriculumRepo;
this.minervalRepository = minervalRepository;
} }
public InscriptionRequest save(InscriptionRequest inscriptionRequest){ public InscriptionRequest save(InscriptionRequest inscriptionRequest){
@ -82,6 +78,11 @@ public class InscriptionService {
userRepo.save(userFromRequest); userRepo.save(userFromRequest);
userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),0)); userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),0));
//Create a minerval for the new student
Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023);
minervalRepository.save(minerval);
} }
inscrRequest.setState(requestState); inscrRequest.setState(requestState);
save(inscrRequest); save(inscrRequest);

View File

@ -0,0 +1,84 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.util.Date;
@Entity
public class Payment {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private long studentRegNo;
private String card;
private String client;
private Date expDate;
private int amount;
private Date date;
public Payment(){}
public Payment(long studentRegNo, String card, String client, Date expDate, int amount, Date date){
this.studentRegNo = studentRegNo;
this.card = card;
this.client = client;
this.expDate = expDate;
this.amount = amount;
this.date = date;
}
public long getStudentRegNo() {
return studentRegNo;
}
public void setStudentRegNo(long studentRegNo) {
this.studentRegNo = studentRegNo;
}
public String getCard() {
return card;
}
public void setCard(String card) {
this.card = card;
}
public String getClient() {
return client;
}
public void setClient(String client) {
this.client = client;
}
public Date getExpDate() {
return expDate;
}
public void setExpDate(Date expDate) {
this.expDate = expDate;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public long getId() {
return id;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}

View File

@ -12,6 +12,9 @@
async function upPage(id,review){ async function upPage(id,review){
await validateRegister(id,review); await validateRegister(id,review);
if (review == "Accepted"){
}
requests.value = await getAllRegisters(); requests.value = await getAllRegisters();
} }
</script> </script>

View File

@ -6,12 +6,15 @@
import i18n from "@/i18n.js" import i18n from "@/i18n.js"
import { uploadProfilePicture } from '@/rest/uploads.js' import { uploadProfilePicture } from '@/rest/uploads.js'
import CourseList from "@/Apps/CourseList.vue"; import CourseList from "@/Apps/CourseList.vue";
import {editMinerval, getCurrentMinerval} from "@/rest/minerval.js";
import {postPayment} from "@/rest/payment.js";
const user = ref(await getSelf()); const user = ref(await getSelf());
const UserCurriculum = ref(""); const UserCurriculum = ref("");
const curricula = ref (await getAllCurriculums()); const curricula = ref (await getAllCurriculums());
const minerv = ref({});
if(user.value.role === "Student"){ if(user.value.role === "Student"){
minerv.value = ref(await getCurrentMinerval(user.value.regNo));
UserCurriculum.value = await getSomeonesCurriculumList(user.value.regNo); UserCurriculum.value = await getSomeonesCurriculumList(user.value.regNo);
} }
@ -22,7 +25,8 @@
const curric = ref(false); const curric = ref(false);
const reg = ref(false); const reg = ref(false);
const courseslist = ref(false); const courseslist = ref(false);
const minerval = ref(false);
const paymentPage = ref(false);
const pattern = { const pattern = {
profilPictureUrl:null, profilPictureUrl:null,
email:null, email:null,
@ -37,7 +41,16 @@
id:null, id:null,
} }
//Used to modelize a payment
const paymentData={
studentRegNo: user.value.regNo,
date:null,
card:null,
client:null,
expDate:null,
amount: null
}
const paymentAmount = ref(0);
let toModify= Object.assign({}, pattern); let toModify= Object.assign({}, pattern);
let personnalInfos = Object.assign({}, patternInfos); let personnalInfos = Object.assign({}, patternInfos);
@ -117,7 +130,7 @@
<img class="subContainter" :src=getPP()> <img class="subContainter" :src=getPP()>
</div> </div>
<div class="globalInfos"> <div class="globalInfos">
<div v-if="modif==false && curric==false && reg==false" class="infosContainer"> <div v-if="modif==false && curric==false && reg==false && minerval==false && paymentPage == false" class="infosContainer">
<div> <div>
{{user.firstName}} {{user.lastName}} {{user.firstName}} {{user.lastName}}
</div> </div>
@ -142,6 +155,42 @@
</div> </div>
<div v-if="(user.role==='Student')"> <div v-if="(user.role==='Student')">
<button @click="courseslist=!courseslist">Manage Courses</button> <button @click="courseslist=!courseslist">Manage Courses</button>
<button @click="minerval = !minerval" style="margin-left: 2%">Manage minerval</button>
</div>
</div>
<div v-else-if="minerval" class="infosContainer">
<div v-if="minerv.value.toPay != 0">
Payment : {{minerv.value.toPay}} left to pay
<div v-if="minerv.value.paidAmount <= 50">
<button @click="minerval = !minerval; paymentPage = !paymentPage; paymentAmount = 50">Pay deposit (50)</button>
</div>
<div>
<button @click="minerval = !minerval; paymentPage = !paymentPage; paymentAmount = minerv.value.toPay">Pay all the rest ({{minerv.value.toPay}})</button>
</div>
</div>
<div v-else>
Payment : School fees have already been paid this year
</div>
</div>
<div v-else-if="paymentPage" class="infosContainer">
Proceed to payment of {{paymentAmount}}
<div style="margin-top: 1%">
Client:
<input type="text" v-model="paymentData.client">
</div>
<div style="margin-top: 1%">
Card:
<input type="text" v-model="paymentData.card">
</div>
<div style="margin-top: 1%">
ExpDate:
<input type="date" v-model="paymentData.expDate">
</div>
<div style="margin-top: 1%">
<button @click="paymentPage=!paymentPage;minerval=!minerval;paymentData.amount=paymentAmount;paymentData.date=new Date();postPayment(paymentData);minerv.value.toPay -= paymentAmount; minerv.value.paidAmount += paymentAmount; editMinerval(minerv.value)">Process Payment</button>
</div>
<div>
<button @click="minerval = !minerval; paymentPage = !paymentPage;">Back</button>
</div> </div>
</div> </div>
<div v-else-if="modif" class="infosContainer"> <div v-else-if="modif" class="infosContainer">
@ -207,7 +256,7 @@
</div> </div>
</div> </div>
</div> </div>
<div v-if="modif==false && curric==false && reg==false "class="moreInfos"> <div v-if="modif==false && curric==false && reg==false && minerval==false"class="moreInfos">
<div class = "oldcursus"> <div class = "oldcursus">
<div class="listTitle"> <div class="listTitle">
Anciens Cursus Anciens Cursus

View File

@ -0,0 +1,9 @@
import {restGet, restPatch, restPost} from "@/rest/restConsumer.js";
export async function getCurrentMinerval(userRegNo){
return restGet("/minerval/"+userRegNo)
}
export async function editMinerval(updatedMinerval){
return restPatch("/minerval", updatedMinerval)
}

View File

@ -0,0 +1,6 @@
import {restPost} from "@/rest/restConsumer.js";
export async function postPayment(payment){
return restPost("/payment", payment)
}