protected function processDeferral($row) { if ($row) { $paymentRepo = $this->manager->getRepository('TSK\\PaymentBundle\\Entity\\Payment'); $payment = $paymentRepo->findOneBy(array('legacyPaymentId' => $row[0])); if (!$payment) { print "Can't find payment " . $row[0] . "\n"; return null; } $chargePaymentRepo = $this->manager->getRepository('TSK\\PaymentBundle\\Entity\\ChargePayment'); $cps = $chargePaymentRepo->findBy(array('payment' => $payment)); foreach ($cps as $cp) { $journal = new Journal(); $journal->setSchool($this->school); $journal->setCharge($cp->getCharge()); $journal->setPayment($cp->getPayment()); $journal->setJournalDate(new \DateTime($row[3])); $journal->setDebitAmount($row[2]); $journal->setDebitAccount($this->deferralAccount); $journal->setCreditAmount($row[2]); $journal->setCreditAccount($this->incomeAccount); $this->manager->persist($journal); $this->manager->flush(); } } }