use of edu.cornell.kfs.pdp.dataaccess.CuFormatPaymentDao in project cu-kfs by CU-CommunityApps.
the class CuFormatServiceImpl method startFormatProcess.
@Override
public FormatProcessSummary startFormatProcess(Person user, String campus, List<CustomerProfile> customers, Date paydate, String paymentTypes, String paymentDistribution) {
LOG.debug("startFormatProcess() started");
for (CustomerProfile element : customers) {
LOG.debug("startFormatProcess() Customer: " + element);
}
// Create the process
Date d = new Date();
PaymentProcess paymentProcess = new PaymentProcess();
paymentProcess.setCampusCode(campus);
paymentProcess.setProcessUser(user);
paymentProcess.setProcessTimestamp(new Timestamp(d.getTime()));
this.businessObjectService.save(paymentProcess);
// add an entry in the format process table (to lock the format process)
FormatProcess formatProcess = new FormatProcess();
formatProcess.setPhysicalCampusProcessCode(campus);
formatProcess.setBeginFormat(dateTimeService.getCurrentTimestamp());
formatProcess.setPaymentProcIdentifier(paymentProcess.getId().intValue());
this.businessObjectService.save(formatProcess);
Timestamp now = new Timestamp((new Date()).getTime());
java.sql.Date sqlDate = new java.sql.Date(paydate.getTime());
Calendar c = Calendar.getInstance();
c.setTime(sqlDate);
c.set(Calendar.HOUR, 11);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
c.set(Calendar.MILLISECOND, 59);
c.set(Calendar.AM_PM, Calendar.PM);
Timestamp paydateTs = new Timestamp(c.getTime().getTime());
LOG.debug("startFormatProcess() last update = " + now);
LOG.debug("startFormatProcess() entered paydate = " + paydate);
LOG.debug("startFormatProcess() actual paydate = " + paydateTs);
PaymentStatus format = this.businessObjectService.findBySinglePrimaryKey(PaymentStatus.class, PdpConstants.PaymentStatusCodes.FORMAT);
List customerIds = new ArrayList();
for (Iterator iter = customers.iterator(); iter.hasNext(); ) {
CustomerProfile element = (CustomerProfile) iter.next();
customerIds.add(element.getId());
}
// Mark all of them ready for format
Iterator groupIterator = ((CuFormatPaymentDao) formatPaymentDao).markPaymentsForFormat(customerIds, paydateTs, paymentTypes, paymentDistribution);
while (groupIterator.hasNext()) {
PaymentGroup paymentGroup = (PaymentGroup) groupIterator.next();
paymentGroup.setLastUpdatedTimestamp(paydateTs);
paymentGroup.setPaymentStatus(format);
paymentGroup.setProcess(paymentProcess);
businessObjectService.save(paymentGroup);
}
// summarize them
FormatProcessSummary preFormatProcessSummary = new FormatProcessSummary();
Iterator<PaymentGroup> iterator = this.paymentGroupService.getByProcess(paymentProcess);
while (iterator.hasNext()) {
PaymentGroup paymentGroup = iterator.next();
preFormatProcessSummary.add(paymentGroup);
}
// if no payments found for format clear the format process
if (preFormatProcessSummary.getProcessSummaryList().size() == 0) {
LOG.debug("startFormatProcess() No payments to process. Format process ending");
// ?? maybe call end format process
clearUnfinishedFormat(paymentProcess.getId().intValue());
}
return preFormatProcessSummary;
}
Aggregations