-CORRECCIÓN DE HORAS EN LOS NEW DATE() PARA LOS REGISTROS EN EL WS

This commit is contained in:
Brayan.Gonzalez 2025-03-04 09:31:47 -07:00
parent 78d9e09391
commit 25fde10e97
6 changed files with 1117 additions and 1043 deletions

View File

@ -113,7 +113,7 @@ public class ExchangeEnebledUsersController implements Serializable {
Date date = new Date(); Date date = new Date();
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(date); calendar.setTime(date);
calendar.add(Calendar.HOUR, -7); calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime(); date = calendar.getTime();
parameters.add(new ModelParameter(TransferCfg.FIELD_LAST_UPDATED_ON, date)); parameters.add(new ModelParameter(TransferCfg.FIELD_LAST_UPDATED_ON, date));
parameters.add(new ModelParameter(TransferCfg.FIELD_ID, transerId)); parameters.add(new ModelParameter(TransferCfg.FIELD_ID, transerId));

View File

@ -284,6 +284,12 @@ public class LoanController implements Serializable {
String comments = "Se pago " + precio + texto; String comments = "Se pago " + precio + texto;
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
LoanDetails details = new LoanDetails( LoanDetails details = new LoanDetails(
UUID.randomUUID().toString(), UUID.randomUUID().toString(),
new Loan(feesToPayByLoanRequestJaxb.getIdLoan()), new Loan(feesToPayByLoanRequestJaxb.getIdLoan()),
@ -294,7 +300,7 @@ public class LoanController implements Serializable {
LoanDetailsType.PAYMENT, LoanDetailsType.PAYMENT,
comments, comments,
feesToPayByLoanRequestJaxb.getIdUser(), feesToPayByLoanRequestJaxb.getIdUser(),
new Date()); date);
parameters.add(new ModelParameter(LoanDetailsCfg.FIELD_ID, ids)); parameters.add(new ModelParameter(LoanDetailsCfg.FIELD_ID, ids));
@ -408,9 +414,6 @@ public class LoanController implements Serializable {
throw new Exception(user_unavailable); throw new Exception(user_unavailable);
} }
//DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();//dateFormat.parse(jaxb.getStrDate());
LoanByUser loanByUser = new LoanByUser( LoanByUser loanByUser = new LoanByUser(
new LoanByUserId(null, jaxb.getUserId()), new LoanByUserId(null, jaxb.getUserId()),
LoanStatus.PENDING, LoanStatus.PENDING,
@ -420,6 +423,12 @@ public class LoanController implements Serializable {
LoanType loanType = loanTypeRepository.findLoanType(jaxb.getLoanTypeId()); LoanType loanType = loanTypeRepository.findLoanType(jaxb.getLoanTypeId());
RouteCtlg routeCtlg = new RouteCtlg(jaxb.getRouteId()); RouteCtlg routeCtlg = new RouteCtlg(jaxb.getRouteId());
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
Loan loan = new Loan( Loan loan = new Loan(
new LoanType(loanType.getId()), new LoanType(loanType.getId()),
null, null,
@ -548,7 +557,13 @@ public class LoanController implements Serializable {
LoanFeeNotification notification = null; LoanFeeNotification notification = null;
try { try {
Date date = new Date(); Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
List<ModelParameter> parameters = new ArrayList<>(); List<ModelParameter> parameters = new ArrayList<>();
Loan loan = loanRepository.findLoanById(transfer.getLoanId()); Loan loan = loanRepository.findLoanById(transfer.getLoanId());
@ -712,7 +727,12 @@ public class LoanController implements Serializable {
PersonJaxb endorsement) throws Exception { PersonJaxb endorsement) throws Exception {
logger.debug("renovation"); logger.debug("renovation");
try { try {
Date date = new Date(); Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
Loan currentLoan = loanRepository.findLoanById(loan); Loan currentLoan = loanRepository.findLoanById(loan);
LoanType newCredit = loanTypeRepository.findLoanType(credit); LoanType newCredit = loanTypeRepository.findLoanType(credit);
@ -844,7 +864,12 @@ public class LoanController implements Serializable {
PersonJaxb endorsement) throws Exception { PersonJaxb endorsement) throws Exception {
logger.debug("renovationHasPaymentToday"); logger.debug("renovationHasPaymentToday");
try { try {
Date date = new Date(); Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
Loan currentLoan = loanRepository.findLoanById(loan); Loan currentLoan = loanRepository.findLoanById(loan);
LoanType newCredit = loanTypeRepository.findLoanType(credit); LoanType newCredit = loanTypeRepository.findLoanType(credit);
@ -972,6 +997,12 @@ public class LoanController implements Serializable {
totalAmountPaid = loan.getAmountPaid().add(discount); totalAmountPaid = loan.getAmountPaid().add(discount);
newLastReferenceNumber = loan.getLastReferenceNumber() + 1; newLastReferenceNumber = loan.getLastReferenceNumber() + 1;
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
loanDetails = new LoanDetails( loanDetails = new LoanDetails(
new Loan(loanByRenovation.getLoanOld().getId()), new Loan(loanByRenovation.getLoanOld().getId()),
new User(user), new User(user),
@ -980,7 +1011,7 @@ public class LoanController implements Serializable {
newLastReferenceNumber, newLastReferenceNumber,
LoanDetailsType.RENOVATION_PAYMENT, LoanDetailsType.RENOVATION_PAYMENT,
user, user,
new Date(), date,
"Retención de " + discount + " el la entrega del crédito renovado"); "Retención de " + discount + " el la entrega del crédito renovado");
} }
@ -1055,6 +1086,12 @@ public class LoanController implements Serializable {
totalAmountPaid = loan.getAmountPaid().add(discount); totalAmountPaid = loan.getAmountPaid().add(discount);
newLastReferenceNumber = loan.getLastReferenceNumber() + 1; newLastReferenceNumber = loan.getLastReferenceNumber() + 1;
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
loanDetails = new LoanDetails( loanDetails = new LoanDetails(
new Loan(loanByRenovation.getLoanOld().getId()), new Loan(loanByRenovation.getLoanOld().getId()),
new User(user), new User(user),
@ -1063,7 +1100,7 @@ public class LoanController implements Serializable {
newLastReferenceNumber, newLastReferenceNumber,
LoanDetailsType.RENOVATION_PAYMENT, LoanDetailsType.RENOVATION_PAYMENT,
user, user,
new Date(), date,
"Retención de " + discount + " el la entrega del crédito renovado"); "Retención de " + discount + " el la entrega del crédito renovado");
} }
@ -1269,11 +1306,17 @@ public class LoanController implements Serializable {
loans.add(new Loan(row.getIdLoan())); loans.add(new Loan(row.getIdLoan()));
}); });
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
loanParams.add(new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, loanStatus)); loanParams.add(new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, loanStatus));
loanParams.add(new ModelParameter(LoanCfg.FIELD_AMOUNT_PAID, new BigDecimal(0))); loanParams.add(new ModelParameter(LoanCfg.FIELD_AMOUNT_PAID, new BigDecimal(0)));
loanParams.add(new ModelParameter(LoanCfg.FIELD_LAST_REFERENCE_NUMBER, 0)); loanParams.add(new ModelParameter(LoanCfg.FIELD_LAST_REFERENCE_NUMBER, 0));
loanParams.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_BY, updateLoanToDeliveryStatusList.getIdUpdateUser())); loanParams.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_BY, updateLoanToDeliveryStatusList.getIdUpdateUser()));
loanParams.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_ON, new Date())); loanParams.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_ON, date));
loanParams.add(new ModelParameter(LoanCfg.FIELD_ID, ids)); loanParams.add(new ModelParameter(LoanCfg.FIELD_ID, ids));
loanByUserParams.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN_BY_USER_STATUS, loanStatus)); loanByUserParams.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN_BY_USER_STATUS, loanStatus));
@ -1300,7 +1343,12 @@ public class LoanController implements Serializable {
logger.debug("updateLoanByIdFromCertifiedView"); logger.debug("updateLoanByIdFromCertifiedView");
try { try {
List<ModelParameter> parameters = new ArrayList<>(); List<ModelParameter> parameters = new ArrayList<>();
Date date = new Date(); Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
parameters.add( parameters.add(
new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, action ? LoanStatus.APPROVED : LoanStatus.REJECTED) new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, action ? LoanStatus.APPROVED : LoanStatus.REJECTED)

View File

@ -1,8 +1,8 @@
/* /*
* Arrebol Consultancy copyright. * Arrebol Consultancy copyright.
* *
* This code belongs to Arrebol Consultancy * This code belongs to Arrebol Consultancy
* its use, redistribution or modification are prohibited * its use, redistribution or modification are prohibited
* without written authorization from Arrebol Consultancy. * without written authorization from Arrebol Consultancy.
*/ */
package com.arrebol.apc.controller.mobile.repository.loan; package com.arrebol.apc.controller.mobile.repository.loan;
@ -23,6 +23,7 @@ import com.arrebol.apc.model.loan.LoanDetails;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -35,185 +36,197 @@ import org.hibernate.query.Query;
*/ */
public class LoanByRenovationRepository extends GenericRepository implements Serializable { public class LoanByRenovationRepository extends GenericRepository implements Serializable {
private static final long serialVersionUID = 1357519239619447184L; private static final long serialVersionUID = 1357519239619447184L;
final Logger logger = LogManager.getLogger(LoanByRenovationRepository.class); final Logger logger = LogManager.getLogger(LoanByRenovationRepository.class);
/** /**
* *
* @param newLoanId * @param newLoanId
* @return * @return
* @throws Exception * @throws Exception
*/ */
public LoanByRenovation findLoanRenovationByNewLoanId(String newLoanId) throws Exception { public LoanByRenovation findLoanRenovationByNewLoanId(String newLoanId) throws Exception {
logger.debug("findLoanRenovationByNewLoanId"); logger.debug("findLoanRenovationByNewLoanId");
try { try {
List<ModelParameter> parameters = new ArrayList<>(); List<ModelParameter> parameters = new ArrayList<>();
parameters.add( parameters.add(
new ModelParameter(LoanByRenovationCfg.FIELD_LOAN_NEW, new Loan(newLoanId)) new ModelParameter(LoanByRenovationCfg.FIELD_LOAN_NEW, new Loan(newLoanId))
); );
return (LoanByRenovation) createNamedQueryUniqueResult( return (LoanByRenovation) createNamedQueryUniqueResult(
LoanByRenovation.class, LoanByRenovation.class,
LoanByRenovationCfg.QUERY_FIND_LOAN_RENOVATION_BY_NEW_LOAN_ID, LoanByRenovationCfg.QUERY_FIND_LOAN_RENOVATION_BY_NEW_LOAN_ID,
parameters); parameters);
} catch (Exception e) { } catch (Exception e) {
logger.error("findLoanRenovationByNewLoanId", e); logger.error("findLoanRenovationByNewLoanId", e);
throw e; throw e;
} }
} }
/** /**
* *
* @param loanByRenovation * @param loanByRenovation
* @param userId * @param userId
* @param comments * @param comments
* @param action * @param action
* @param amount * @param amount
* @param discount * @param discount
* @param loanDetails * @param loanDetails
* @param totalAmountPaid * @param totalAmountPaid
* @param newLastReferenceNumber * @param newLastReferenceNumber
* @param comission * @param comission
* @return * @return
* @throws Exception * @throws Exception
*/ */
public boolean updateLoanRenovationFromCerfierView( public boolean updateLoanRenovationFromCerfierView(
LoanByRenovation loanByRenovation, LoanByRenovation loanByRenovation,
String userId, String userId,
String comments, String comments,
boolean action, boolean action,
BigDecimal amount, BigDecimal amount,
BigDecimal discount, BigDecimal discount,
LoanDetails loanDetails, LoanDetails loanDetails,
BigDecimal totalAmountPaid, BigDecimal totalAmountPaid,
Integer newLastReferenceNumber, Integer newLastReferenceNumber,
ComissionType comission) throws Exception { ComissionType comission) throws Exception {
logger.debug("updateLoanRenovationFromCerfierView"); logger.debug("updateLoanRenovationFromCerfierView");
boolean success = false; boolean success = false;
try { try {
openConnection(); openConnection();
Date lastUpdatedOn = new Date(); Date date2 = new Date();
List<ModelParameter> parameters = new ArrayList<>(); Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(date2);
calendar2.add(Calendar.HOUR_OF_DAY, -7);
date2 = calendar2.getTime();
// Update loanByRenovation details in Renovation table Date lastUpdatedOn = date2;
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_LOAN_RENOVATION_STATUS, action ? LoanRenovationStatus.APPROVED : LoanRenovationStatus.REJECTED)); List<ModelParameter> parameters = new ArrayList<>();
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_COMMENTS, comments));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_LAST_UPDATED_BY, userId));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_LAST_UPDATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_ID, loanByRenovation.getId()));
if (0 < executeQuery(LoanByRenovationCfg.QUERY_UPDATE_LOAN_RENOVATION, parameters)) { // Update loanByRenovation details in Renovation table
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_LOAN_RENOVATION_STATUS, action ? LoanRenovationStatus.APPROVED : LoanRenovationStatus.REJECTED));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_COMMENTS, comments));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_LAST_UPDATED_BY, userId));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_LAST_UPDATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_ID, loanByRenovation.getId()));
parameters.clear(); if (0 < executeQuery(LoanByRenovationCfg.QUERY_UPDATE_LOAN_RENOVATION, parameters)) {
// Update NEW loan details in Loan table parameters.clear();
parameters.add(new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, action ? LoanStatus.APPROVED : LoanStatus.REJECTED));
parameters.add(new ModelParameter(LoanCfg.FIELD_COMMENTS, comments));
parameters.add(new ModelParameter(LoanCfg.FIELD_CREATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_BY, userId));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanCfg.FIELD_ID, loanByRenovation.getLoanNew().getId()));
if (0 < executeQuery(LoanCfg.QUERY_UPDATE_LOAN_WITH_CREATED_ON_BY_ID_FROM_CERTIFIER_VIEW, parameters)) { // Update NEW loan details in Loan table
parameters.clear(); parameters.add(new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, action ? LoanStatus.APPROVED : LoanStatus.REJECTED));
parameters.add(new ModelParameter(LoanCfg.FIELD_COMMENTS, comments));
parameters.add(new ModelParameter(LoanCfg.FIELD_CREATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_BY, userId));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanCfg.FIELD_ID, loanByRenovation.getLoanNew().getId()));
// Update OLD loan details in Loan table if (0 < executeQuery(LoanCfg.QUERY_UPDATE_LOAN_WITH_CREATED_ON_BY_ID_FROM_CERTIFIER_VIEW, parameters)) {
String commentsOldLoan = action ? "Crédito renovado" : "El certificador rechazo la renovación de este crédito"; parameters.clear();
String strQuery = LoanCfg.QUERY_UPDATE_LOAN_BY_ID_FROM_CERTIFIER_VIEW;
if (action && null != loanDetails && null != totalAmountPaid && null != newLastReferenceNumber) { // Update OLD loan details in Loan table
parameters.add(new ModelParameter(LoanCfg.FIELD_AMOUNT_PAID, totalAmountPaid)); String commentsOldLoan = action ? "Crédito renovado" : "El certificador rechazo la renovación de este crédito";
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_REFERENCE_NUMBER, newLastReferenceNumber)); String strQuery = LoanCfg.QUERY_UPDATE_LOAN_BY_ID_FROM_CERTIFIER_VIEW;
strQuery = LoanCfg.QUERY_UPDATE_DISCOUNT_AND_LOAN_BY_ID_FROM_CERTIFIER_VIEW; if (action && null != loanDetails && null != totalAmountPaid && null != newLastReferenceNumber) {
} parameters.add(new ModelParameter(LoanCfg.FIELD_AMOUNT_PAID, totalAmountPaid));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_REFERENCE_NUMBER, newLastReferenceNumber));
parameters.add(new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, action ? LoanStatus.FINISH : LoanStatus.APPROVED)); strQuery = LoanCfg.QUERY_UPDATE_DISCOUNT_AND_LOAN_BY_ID_FROM_CERTIFIER_VIEW;
parameters.add(new ModelParameter(LoanCfg.FIELD_COMMENTS, commentsOldLoan)); }
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_BY, userId));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanCfg.FIELD_ID, loanByRenovation.getLoanOld().getId()));
if (0 < executeQuery(strQuery, parameters)) { parameters.add(new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, action ? LoanStatus.FINISH : LoanStatus.APPROVED));
parameters.add(new ModelParameter(LoanCfg.FIELD_COMMENTS, commentsOldLoan));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_BY, userId));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanCfg.FIELD_ID, loanByRenovation.getLoanOld().getId()));
// Update OLD loanByUser details in Loan By User Table if (0 < executeQuery(strQuery, parameters)) {
List<ModelParameter> params = new ArrayList<>();
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN, new Loan(loanByRenovation.getLoanOld().getId()))); // Update OLD loanByUser details in Loan By User Table
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN_BY_USER_STATUS, action ? LoanStatus.FINISH : LoanStatus.APPROVED)); List<ModelParameter> params = new ArrayList<>();
Query query1 = getSession().createNamedQuery(LoanByUserCfg.QUERY_UPDATE_LOAN_BY_USER_BY_LOAND_ID); params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN, new Loan(loanByRenovation.getLoanOld().getId())));
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN_BY_USER_STATUS, action ? LoanStatus.FINISH : LoanStatus.APPROVED));
params.forEach((param) -> { Query query1 = getSession().createNamedQuery(LoanByUserCfg.QUERY_UPDATE_LOAN_BY_USER_BY_LOAND_ID);
query1.setParameter(param.getParameter(), param.getValue());
});
query1.executeUpdate(); params.forEach((param) -> {
query1.setParameter(param.getParameter(), param.getValue());
});
// Update NEW loanByUser details in Loan By User Table query1.executeUpdate();
params.clear();
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN, new Loan(loanByRenovation.getLoanNew().getId()))); // Update NEW loanByUser details in Loan By User Table
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN_BY_USER_STATUS, action ? LoanStatus.APPROVED : LoanStatus.REJECTED)); params.clear();
Query query2 = getSession().createNamedQuery(LoanByUserCfg.QUERY_UPDATE_LOAN_BY_USER_BY_LOAND_ID); params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN, new Loan(loanByRenovation.getLoanNew().getId())));
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN_BY_USER_STATUS, action ? LoanStatus.APPROVED : LoanStatus.REJECTED));
params.forEach((param) -> { Query query2 = getSession().createNamedQuery(LoanByUserCfg.QUERY_UPDATE_LOAN_BY_USER_BY_LOAND_ID);
query2.setParameter(param.getParameter(), param.getValue());
});
query2.executeUpdate(); params.forEach((param) -> {
query2.setParameter(param.getParameter(), param.getValue());
});
if (action) { query2.executeUpdate();
// Insert new loanDetails (discount) in Loan Details table
if (null != loanDetails) {
getSession().save(loanDetails);
}
// Insert delivery details (To know cash that certifier deliveried) in Delivery Table if (action) {
Delivery delivery = new Delivery( // Insert new loanDetails (discount) in Loan Details table
new User(userId), if (null != loanDetails) {
new Loan(loanByRenovation.getLoanNew().getId()), getSession().save(loanDetails);
amount, }
userId,
new Date(),
comission
);
getSession().save(delivery); Date date = new Date();
} Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
flushAndClear(); // Insert delivery details (To know cash that certifier deliveried) in Delivery Table
closeConnection(); Delivery delivery = new Delivery(
new User(userId),
new Loan(loanByRenovation.getLoanNew().getId()),
amount,
userId,
date,
comission
);
logger.info("Certifier delivery the loan details: " + loanByRenovation); getSession().save(delivery);
success = true; }
} else {
rollback(); flushAndClear();
} closeConnection();
} else {
rollback(); logger.info("Certifier delivery the loan details: " + loanByRenovation);
} success = true;
} else {
rollback();
}
} else { } else {
rollback(); rollback();
} }
return success; } else {
} catch (Exception e) {
rollback(); rollback();
logger.error("updateLoanRenovationFromCerfierView", e); }
throw e; return success;
} } catch (Exception e) {
} rollback();
logger.error("updateLoanRenovationFromCerfierView", e);
throw e;
}
}
private int executeQuery(String xmlQuery, List<ModelParameter> parameters) { private int executeQuery(String xmlQuery, List<ModelParameter> parameters) {
Query query = getSession().createNamedQuery(xmlQuery); Query query = getSession().createNamedQuery(xmlQuery);
parameters.forEach((param) -> { parameters.forEach((param) -> {
query.setParameter(param.getParameter(), param.getValue()); query.setParameter(param.getParameter(), param.getValue());
}); });
return query.executeUpdate(); return query.executeUpdate();
} }
} }

View File

@ -1,8 +1,8 @@
/* /*
* Arrebol Consultancy copyright. * Arrebol Consultancy copyright.
* *
* This code belongs to Arrebol Consultancy * This code belongs to Arrebol Consultancy
* its use, redistribution or modification are prohibited * its use, redistribution or modification are prohibited
* without written authorization from Arrebol Consultancy. * without written authorization from Arrebol Consultancy.
*/ */
package com.arrebol.apc.controller.mobile.repository.loan; package com.arrebol.apc.controller.mobile.repository.loan;
@ -16,6 +16,7 @@ import com.arrebol.apc.model.loan.LoanDetails;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.persistence.Tuple; import javax.persistence.Tuple;
@ -31,169 +32,175 @@ import org.hibernate.query.Query;
*/ */
public class LoanDetailsRepository extends GenericRepository implements Serializable { public class LoanDetailsRepository extends GenericRepository implements Serializable {
/** /**
* *
* @param details * @param details
* @return * @return
* @throws Exception * @throws Exception
*/ */
public boolean saveLoanDetails(LoanDetails details) throws Exception { public boolean saveLoanDetails(LoanDetails details) throws Exception {
logger.debug("saveLoanDetails"); logger.debug("saveLoanDetails");
try { try {
return save(details); return save(details);
} catch (Exception e) { } catch (Exception e) {
logger.error("saveLoanDetails", e); logger.error("saveLoanDetails", e);
throw e; throw e;
} }
} }
public List<LoanDetails> findFeesToPayByLoanId(String xmlQuery, List<ModelParameter> parameters) throws Exception { public List<LoanDetails> findFeesToPayByLoanId(String xmlQuery, List<ModelParameter> parameters) throws Exception {
logger.debug("findFeesToPayByLoanId"); logger.debug("findFeesToPayByLoanId");
List<LoanDetails> results = new ArrayList<>(); List<LoanDetails> results = new ArrayList<>();
try { try {
List<Tuple> tuples = xmlQueryTuple(xmlQuery, parameters); List<Tuple> tuples = xmlQueryTuple(xmlQuery, parameters);
tuples.forEach((tuple) -> { tuples.forEach((tuple) -> {
results.add(new LoanDetails(tuple.get("id", String.class), tuple.get("createdOn", Date.class), tuple.get("feeStatus", FeeStatus.class))); results.add(new LoanDetails(tuple.get("id", String.class), tuple.get("createdOn", Date.class), tuple.get("feeStatus", FeeStatus.class)));
});
} catch (Exception e) {
logger.error("findFeesToPayByLoanId", e);
throw e;
}
return results;
}
/**
*
* @param xmlQuery
* @param parameters
* @return
* @throws Exception
*/
public List<LoanDetails> findLoanDetailsByLoanId(String xmlQuery, List<ModelParameter> parameters) throws Exception {
logger.debug("findLoanDetailsByLoanId");
List<LoanDetails> results = new ArrayList<>();
try {
results = createNamedQueryResultList(LoanDetails.class, xmlQuery, parameters);
} catch (Exception e) {
logger.error("findLoanDetailsByLoanId", e);
throw e;
}
return results;
}
/**
*
* @param xmlQuery
* @param parameters
* @param loanDetails
* @return
* @throws Exception
*/
public boolean updatePaidFeesStatusInLoanDetailIds(String xmlQuery, List<ModelParameter> parameters, LoanDetails loanDetails) throws Exception {
boolean success = false;
Session sssn = null;
Transaction trnsctn = null;
try {
sssn = HibernateUtil.getSessionFactory().getCurrentSession();
trnsctn = sssn.beginTransaction();
Loan loan = sssn.get(Loan.class, loanDetails.getLoan().getId());
if (null != parameters && !parameters.isEmpty()) {
Query query = sssn.createNamedQuery(xmlQuery);
parameters.forEach((param) -> {
query.setParameter(param.getParameter(), param.getValue());
}); });
} catch (Exception e) { query.executeUpdate();
logger.error("findFeesToPayByLoanId", e); logger.debug("Query update executed");
throw e; }
} BigDecimal totalFees = loan.getAmountPaid().add(loanDetails.getPaymentAmount());
return results; loanDetails.setReferenceNumber(loan.getLastReferenceNumber() + 1);
}
/** sssn.save(loanDetails);
*
* @param xmlQuery
* @param parameters
* @return
* @throws Exception
*/
public List<LoanDetails> findLoanDetailsByLoanId(String xmlQuery, List<ModelParameter> parameters) throws Exception {
logger.debug("findLoanDetailsByLoanId");
List<LoanDetails> results = new ArrayList<>(); loan.setAmountPaid(totalFees);
try { loan.setLastReferenceNumber(loan.getLastReferenceNumber() + 1);
results = createNamedQueryResultList(LoanDetails.class, xmlQuery, parameters); loan.setLastUpdatedBy(loanDetails.getCreatedBy());
} catch (Exception e) {
logger.error("findLoanDetailsByLoanId", e);
throw e;
}
return results; Date date = new Date();
} Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
loan.setLastUpdatedOn(date);
/** sssn.update(loan);
*
* @param xmlQuery
* @param parameters
* @param loanDetails
* @return
* @throws Exception
*/
public boolean updatePaidFeesStatusInLoanDetailIds(String xmlQuery, List<ModelParameter> parameters, LoanDetails loanDetails) throws Exception {
boolean success = false;
Session sssn = null; trnsctn.commit();
Transaction trnsctn = null;
try {
sssn = HibernateUtil.getSessionFactory().getCurrentSession();
trnsctn = sssn.beginTransaction();
Loan loan = sssn.get(Loan.class, loanDetails.getLoan().getId()); logger.info("Entity updated");
success = true;
if (null != parameters && !parameters.isEmpty()) { } catch (Exception e) {
Query query = sssn.createNamedQuery(xmlQuery); logger.error("Method updatePaidFeesStatusInLoanDetailIds() ", e);
parameters.forEach((param) -> { if (null != trnsctn) {
query.setParameter(param.getParameter(), param.getValue()); trnsctn.rollback();
}); }
query.executeUpdate(); throw e;
logger.debug("Query update executed"); }
} /* finally {
BigDecimal totalFees = loan.getAmountPaid().add(loanDetails.getPaymentAmount());
loanDetails.setReferenceNumber(loan.getLastReferenceNumber() + 1);
sssn.save(loanDetails);
loan.setAmountPaid(totalFees);
loan.setLastReferenceNumber(loan.getLastReferenceNumber() + 1);
loan.setLastUpdatedBy(loanDetails.getCreatedBy());
loan.setLastUpdatedOn(new Date());
sssn.update(loan);
trnsctn.commit();
logger.info("Entity updated");
success = true;
} catch (Exception e) {
logger.error("Method updatePaidFeesStatusInLoanDetailIds() ", e);
if (null != trnsctn) {
trnsctn.rollback();
}
throw e;
}
/* finally {
if (null != sssn) { if (null != sssn) {
sssn.close(); sssn.close();
} }
}*/ }*/
return success; return success;
} }
/** /**
* *
* @param hbmQuery * @param hbmQuery
* @param params * @param params
* @return * @return
*/ */
public Long countLoandDetails(String hbmQuery, List<ModelParameter> params) { public Long countLoandDetails(String hbmQuery, List<ModelParameter> params) {
Long count; Long count;
Transaction transaction = null; Transaction transaction = null;
try { try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession(); Session session = HibernateUtil.getSessionFactory().getCurrentSession();
transaction = session.beginTransaction(); transaction = session.beginTransaction();
Query query = session.createNamedQuery(hbmQuery); Query query = session.createNamedQuery(hbmQuery);
params.forEach((param) -> { params.forEach((param) -> {
query.setParameter(param.getParameter(), param.getValue()); query.setParameter(param.getParameter(), param.getValue());
}); });
count = (Long) query.getSingleResult(); count = (Long) query.getSingleResult();
transaction.commit(); transaction.commit();
return count; return count;
} catch (Exception e) { } catch (Exception e) {
logger.error("countLoandDetails", e); logger.error("countLoandDetails", e);
if (null != transaction) { if (null != transaction) {
transaction.rollback(); transaction.rollback();
} }
throw e; throw e;
} }
} }
/** /**
* *
* @param hbmQuery * @param hbmQuery
* @param parameters * @param parameters
* @return * @return
* @throws Exception * @throws Exception
*/ */
public boolean updateLoanDetails(String hbmQuery, List<ModelParameter> parameters) throws Exception { public boolean updateLoanDetails(String hbmQuery, List<ModelParameter> parameters) throws Exception {
try { try {
return updateCreateNamedQuery(hbmQuery, parameters); return updateCreateNamedQuery(hbmQuery, parameters);
} catch (Exception e) { } catch (Exception e) {
logger.error("Method updateLoanDetails", e); logger.error("Method updateLoanDetails", e);
throw e; throw e;
} }
} }
private static final long serialVersionUID = -6088464996350747643L; private static final long serialVersionUID = -6088464996350747643L;
final Logger logger = LogManager.getLogger(LoanDetailsRepository.class); final Logger logger = LogManager.getLogger(LoanDetailsRepository.class);
} }

View File

@ -1,8 +1,8 @@
/* /*
* Arrebol Consultancy copyright. * Arrebol Consultancy copyright.
* *
* This code belongs to Arrebol Consultancy * This code belongs to Arrebol Consultancy
* its use, redistribution or modification are prohibited * its use, redistribution or modification are prohibited
* without written authorization from Arrebol Consultancy. * without written authorization from Arrebol Consultancy.
*/ */
package com.arrebol.apc.ws.gasoline; package com.arrebol.apc.ws.gasoline;
@ -14,6 +14,7 @@ import com.arrebol.apc.model.core.User;
import com.arrebol.apc.model.enums.GenericStatus; import com.arrebol.apc.model.enums.GenericStatus;
import com.arrebol.apc.model.gasoline.Gasoline; import com.arrebol.apc.model.gasoline.Gasoline;
import java.io.Serializable; import java.io.Serializable;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
@ -32,45 +33,51 @@ import org.apache.logging.log4j.Logger;
@Path("gasoline") @Path("gasoline")
public class GasolineWS implements Serializable { public class GasolineWS implements Serializable {
@PUT @PUT
@Path("save-new-gasoline-payment") @Path("save-new-gasoline-payment")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response saveNewGasolinePayment(@FormParam("idUser") String idUser, public Response saveNewGasolinePayment(@FormParam("idUser") String idUser,
@FormParam("idOffice") String idOffice, @FormParam("idOffice") String idOffice,
@FormParam("idRoute") String idRoute, @FormParam("idRoute") String idRoute,
@FormParam("total") Double total, @FormParam("total") Double total,
@FormParam("km") Double km, @FormParam("km") Double km,
@FormParam("quantity") Double quantity, @FormParam("quantity") Double quantity,
@FormParam("description") String description) { @FormParam("description") String description) {
Response response; Response response;
try { try {
GasolineController controller = new GasolineController(); GasolineController controller = new GasolineController();
Gasoline gasoline = new Gasoline( Date date = new Date();
UUID.randomUUID().toString(), Calendar calendar = Calendar.getInstance();
new User(idUser), calendar.setTime(date);
new Office(idOffice), calendar.add(Calendar.HOUR_OF_DAY, -7);
new RouteCtlg(idRoute), date = calendar.getTime();
quantity,
km,
total,
GenericStatus.ENABLED,
description,
idUser,
new Date());
if (controller.saveNewGasolinePayment(gasoline)) { Gasoline gasoline = new Gasoline(
response = Response.ok().build(); UUID.randomUUID().toString(),
} else { new User(idUser),
response = Response.status(Response.Status.NOT_ACCEPTABLE).build(); new Office(idOffice),
} new RouteCtlg(idRoute),
} catch (Exception e) { quantity,
logger.error("saveNewGasolineEntry"); km,
total,
GenericStatus.ENABLED,
description,
idUser,
date);
if (controller.saveNewGasolinePayment(gasoline)) {
response = Response.ok().build();
} else {
response = Response.status(Response.Status.NOT_ACCEPTABLE).build(); response = Response.status(Response.Status.NOT_ACCEPTABLE).build();
} }
return response; } catch (Exception e) {
} logger.error("saveNewGasolineEntry");
response = Response.status(Response.Status.NOT_ACCEPTABLE).build();
}
return response;
}
private static final long serialVersionUID = -5280895557294295916L; private static final long serialVersionUID = -5280895557294295916L;
final Logger logger = LogManager.getLogger(getClass()); final Logger logger = LogManager.getLogger(getClass());
} }

File diff suppressed because it is too large Load Diff