adamsaghy commented on code in PR #5179:
URL: https://github.com/apache/fineract/pull/5179#discussion_r2618486202
##########
fineract-accounting/src/main/java/org/apache/fineract/accounting/glaccount/jobs/updatetrialbalancedetails/UpdateTrialBalanceDetailsTasklet.java:
##########
@@ -41,59 +43,78 @@ public class UpdateTrialBalanceDetailsTasklet implements
Tasklet {
private final RoutingDataSourceServiceFactory dataSourceServiceFactory;
private final TrialBalanceRepositoryWrapper trialBalanceRepositoryWrapper;
+ private final TrialBalanceRepository trialBalanceRepository;
+ private final JournalEntryRepository journalEntryRepository;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext
chunkContext) throws Exception {
final JdbcTemplate jdbcTemplate = new
JdbcTemplate(dataSourceServiceFactory.determineDataSourceService().retrieveDataSource());
- final StringBuilder tbGapSqlBuilder = new StringBuilder(500);
- tbGapSqlBuilder.append("select distinct(je.transaction_date)
").append("from acc_gl_journal_entry je ")
- .append("where je.transaction_date > (select
coalesce(MAX(created_date),'2010-01-01') from m_trial_balance)");
- final List<LocalDate> tbGaps =
jdbcTemplate.queryForList(tbGapSqlBuilder.toString(), LocalDate.class);
+
+ processTrialBalanceGaps(jdbcTemplate);
+ updateClosingBalances(jdbcTemplate);
+
+ return RepeatStatus.FINISHED;
+ }
+
+ private void processTrialBalanceGaps(JdbcTemplate jdbcTemplate) {
+ LocalDate maxCreatedDate = trialBalanceRepository.findMaxCreatedDate();
+ LocalDate baselineDate = maxCreatedDate != null ? maxCreatedDate :
LocalDate.of(2010, 1, 1);
+ List<LocalDate> tbGaps =
journalEntryRepository.findTransactionDatesAfter(baselineDate);
for (LocalDate tbGap : tbGaps) {
- int days = DateUtils.getExactDifferenceInDays(tbGap,
DateUtils.getBusinessLocalDate());
- if (days < 1) {
+ if (DateUtils.getExactDifferenceInDays(tbGap,
DateUtils.getBusinessLocalDate()) < 1) {
continue;
}
- final StringBuilder sqlBuilder = new StringBuilder(600);
- sqlBuilder.append("Insert Into m_trial_balance(office_id,
account_id, Amount, entry_date, created_date,closing_balance) ")
- .append("Select je.office_id, je.account_id, SUM(CASE WHEN
je.type_enum=1 THEN (-1) * je.amount ELSE je.amount END) ")
- .append("as Amount, Date(je.entry_date) as Entry_Date,
je.transaction_date as Created_Date,sum(je.amount) as closing_balance ")
- .append("from acc_gl_journal_entry je WHERE
je.transaction_date = ? ")
- .append("group by je.account_id, je.office_id,
je.transaction_date, Date(je.entry_date)");
- final int result = jdbcTemplate.update(sqlBuilder.toString(),
tbGap);
- log.debug("{}: Records affected by updateTrialBalanceDetails: {}",
ThreadLocalContextUtil.getTenant().getName(), result);
+ insertTrialBalanceForDate(jdbcTemplate, tbGap);
}
- String distinctOfficeQuery = "select distinct(office_id) from
m_trial_balance where closing_balance is null group by office_id";
- final List<Long> officeIds =
jdbcTemplate.queryForList(distinctOfficeQuery, Long.class);
+ }
+
+ private void insertTrialBalanceForDate(JdbcTemplate jdbcTemplate,
LocalDate tbGap) {
+ final String sql = "Insert Into m_trial_balance(office_id, account_id,
Amount, entry_date, created_date,closing_balance) "
Review Comment:
Please use JPA (entity) for this to create a new entry!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]