Merge pull request #210 from Kitzanos/create-application-updates-prod
Cherry-pick(Allowed multiple application for gepafin in case rejected)
This commit is contained in:
@@ -874,6 +874,10 @@ public class ApplicationDao {
|
|||||||
checkCallEndDate(call);
|
checkCallEndDate(call);
|
||||||
// call = callService.validatePublishedCall(call.getId());
|
// call = callService.validatePublishedCall(call.getId());
|
||||||
// checkIfApplicationExists(call, userWithCompanyEntity, userEntity);
|
// checkIfApplicationExists(call, userWithCompanyEntity, userEntity);
|
||||||
|
HubEntity hubEntity = hubService.valdateHub(call.getHub().getId());
|
||||||
|
if(hubEntity.getUniqueUuid().equals(defaultHubUuid)){
|
||||||
|
checkIfApplicationExists(call, userWithCompanyEntity, userEntity);
|
||||||
|
}
|
||||||
ApplicationEntity applicationEntity = createApplicationEntity(userEntity, call, userWithCompanyEntity);
|
ApplicationEntity applicationEntity = createApplicationEntity(userEntity, call, userWithCompanyEntity);
|
||||||
applicationEntity.setComments(applicationRequest.getComments());
|
applicationEntity.setComments(applicationRequest.getComments());
|
||||||
applicationEntity = saveApplicationEntity(applicationEntity);
|
applicationEntity = saveApplicationEntity(applicationEntity);
|
||||||
@@ -886,6 +890,18 @@ public class ApplicationDao {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
public void checkIfApplicationExists(CallEntity call, UserWithCompanyEntity userWithCompanyEntity, UserEntity userEntity){
|
||||||
|
|
||||||
|
List<ApplicationEntity> applications = applicationRepository.findByUserIdAndUserWithCompany_IdAndCall_IdAndIsDeletedFalseAndStatusNot(
|
||||||
|
userEntity.getId(), userWithCompanyEntity.getId(), call.getId(), ApplicationStatusTypeEnum.REJECTED.name()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!applications.isEmpty()) {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_EXISTS));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ApplicationResponse updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status) {
|
public ApplicationResponse updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status) {
|
||||||
|
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
|
|||||||
@@ -77,4 +77,60 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
|
|||||||
List<Long> findApplicationIdsByHubId(@Param("hubId") Long hubId);
|
List<Long> findApplicationIdsByHubId(@Param("hubId") Long hubId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Query("SELECT a.status, COUNT(a.id) FROM ApplicationEntity a WHERE a.isDeleted = false AND a.userId = :userId AND a.userWithCompany.id = :userWithCompanyId AND a.call.hub.id = :hubId GROUP BY a.status")
|
||||||
|
List<Object[]> findApplicationsByStatusAndUserIdAndUserWithCompanyId(@Param("hubId") Long hubId,
|
||||||
|
@Param("userId") Long userId,
|
||||||
|
@Param("userWithCompanyId") Long userWithCompanyId);
|
||||||
|
|
||||||
|
@Query("""
|
||||||
|
SELECT TO_CHAR(a.submissionDate, 'Mon') AS month,
|
||||||
|
SUM(a.amountRequested) AS totalRequested,
|
||||||
|
SUM(a.amountAccepted) AS totalApproved
|
||||||
|
FROM ApplicationEntity a
|
||||||
|
WHERE a.isDeleted = false
|
||||||
|
AND a.status = 'APPROVED'
|
||||||
|
AND a.call.hub.id = :hubId
|
||||||
|
AND a.userId = :userId
|
||||||
|
AND a.userWithCompany.id = :userWithCompanyId
|
||||||
|
GROUP BY TO_CHAR(a.submissionDate, 'Mon'), EXTRACT(YEAR FROM a.submissionDate), EXTRACT(MONTH FROM a.submissionDate)
|
||||||
|
ORDER BY EXTRACT(YEAR FROM a.submissionDate), EXTRACT(MONTH FROM a.submissionDate)
|
||||||
|
""")
|
||||||
|
List<Object[]> findRequestedVsApprovedAmountsPerMonth(
|
||||||
|
@Param("hubId") Long hubId,
|
||||||
|
@Param("userId") Long userId,
|
||||||
|
@Param("userWithCompanyId") Long userWithCompanyId
|
||||||
|
);
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(a) FROM ApplicationEntity a " +
|
||||||
|
"WHERE a.hubId = :hubId " +
|
||||||
|
"AND a.userId = :userId " +
|
||||||
|
"AND a.userWithCompany.id = :userWithCompanyId " +
|
||||||
|
"AND a.isDeleted = false " +
|
||||||
|
"AND a.status IN :statusList " +
|
||||||
|
"AND a.submissionDate IS NOT NULL")
|
||||||
|
Long countSubmittedApplicationsByHubIdAndUserId(
|
||||||
|
@Param("hubId") Long hubId,
|
||||||
|
@Param("userId") Long userId,
|
||||||
|
@Param("userWithCompanyId") Long userWithCompanyId,
|
||||||
|
@Param("statusList") List<String> statusList
|
||||||
|
);
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(a) FROM ApplicationEntity a " +
|
||||||
|
"WHERE a.hubId = :hubId " +
|
||||||
|
"AND a.userId = :userId " +
|
||||||
|
"AND a.userWithCompany.id = :userWithCompanyId " +
|
||||||
|
"AND a.status = :status " +
|
||||||
|
"AND a.isDeleted = false")
|
||||||
|
Long countSubmittedApplicationsByHubIdAndUserIdAndStatus(
|
||||||
|
@Param("hubId") Long hubId,
|
||||||
|
@Param("userId") Long userId,
|
||||||
|
@Param("userWithCompanyId") Long userWithCompanyId,
|
||||||
|
@Param("status") String status);
|
||||||
|
@Query("SELECT SUM(a.amountAccepted) FROM ApplicationEntity a WHERE a.hubId = :hubId AND a.userId = :userId AND a.status = 'APPROVED' AND a.userWithCompany.id = :userWithCompanyId AND a.isDeleted = false")
|
||||||
|
BigDecimal sumAmountRequestedByHubIdAndUserId(@Param("hubId") Long hubId, @Param("userId") Long userId, @Param("userWithCompanyId") Long userWithCompanyId);
|
||||||
|
|
||||||
|
List<ApplicationEntity> findByUserIdAndUserWithCompany_IdAndCall_IdAndIsDeletedFalseAndStatusNot(
|
||||||
|
Long userId, Long userWithCompanyId, Long callId, String status
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user