public function update_pay_reference() { $db = DB::Instance(); $db->StartTrans(); $flash = Flash::Instance(); $errors = array(); if ($this->checkParams('PLPayment')) { $plpayment = $this->_uses[$this->modeltype]; $plpayment->load($this->_data['PLPayment']['id']); if (!$plpayment) { $errors[] = 'Error trying to get Payment Details'; } else { if (isset($this->_data['start_reference']) && isset($this->_data['end_reference']) && $this->_data['end_reference'] != $this->_data['start_reference'] + $plpayment->number_transactions - 1) { $errors[] = 'Reference range does not match number of transactions'; } else { $pltransactions = new PLTransactionCollection(DataObjectFactory::Factory('PLTransaction')); $pltransactions->paidList($plpayment->id); $ext_ref = $this->_data['start_reference']; $progressbar = new progressBar('update_payment_reference'); $callback = function ($pl_data, $key) use(&$ext_ref, &$errors, $db) { $cbtrans = DataObjectFactory::Factory('CBTransaction'); $cbtrans->loadBy(array('source', 'reference', 'ext_reference', 'gross_value'), array('P', $pl_data->our_reference, $pl_data->cross_ref, $pl_data->gross_value)); if (!$cbtrans || !$cbtrans->update($cbtrans->id, 'ext_reference', $ext_ref)) { $errors[] = 'Error updating CB Transaction External Reference : ' . $db->ErrorMsg(); return FALSE; } if (!$pl_data->update($pl_data->id, 'ext_reference', $ext_ref)) { $errors[] = 'Error updating PL Transaction External Reference : ' . $db->ErrorMsg(); return FALSE; } else { $ext_ref += 1; } }; if ($progressbar->process($pltransactions, $callback) === FALSE) { $errors[] = 'Error updating payment reference'; } } } } if (count($errors) > 0) { $flash->addErrors($errors); $this->_templateName = $this->getTemplateName('enter_payment_reference'); $this->view->set('PLPayment', $plpayment); $db->FailTrans(); $db->CompleteTrans(); } else { $db->CompleteTrans(); sendTo('pltransactions', 'select_remittances', $this->_modules, array('id' => $plpayment->id)); } }
public function select_remittances() { $flash = Flash::Instance(); $errors = array(); if (!$this->checkParams('id')) { sendBack(); } else { $plpayment = DataObjectFactory::Factory('PLPayment'); $plpayment->load($this->_data['id']); if (!$plpayment) { $errors[] = 'Error trying to get Payment Details'; } else { $pltransactions = new PLTransactionCollection(); $pltransactions->paidList($plpayment->id); foreach ($pltransactions as $pltransaction) { $pltransaction->gross_value = bcmul($pltransaction->gross_value, -1); $pltransaction->setAdditional('email'); $pltransaction->email = $pltransaction->email_remittance; } } } $type = 'remittance'; $output_details = $this->output_types[$type]; $selected = empty($_SESSION['selected_output'][$type]) ? array() : $_SESSION['selected_output'][$type]; $new_selection = array('count' => 0); foreach ($pltransactions as $detail) { if (isset($selected[$detail->id])) { $new_selection[$detail->id] = $selected[$detail->id]; if ($selected[$detail->id]['select'] == 'true') { $new_selection['count']++; } } else { if (isset($output_details['identifier'])) { $new_selection[$detail->id]['description'] = prettify($output_details['identifier']) . ' : ' . $detail->{$output_details}['identifier']; } else { $new_selection[$detail->id]['description'] = $detail->getIdentifierValue(); } if (empty($new_selection[$detail->id]['description'])) { $new_selection[$detail->id]['description'] = 'no identifier set'; } if (!is_null($detail->method)) { switch ($detail->method) { case 'E': $new_selection[$detail->id]['printaction'] = 'email'; break; case 'D': $new_selection[$detail->id]['printaction'] = 'edi'; break; case 'F': case 'P': $new_selection[$detail->id]['printaction'] = 'print'; break; default: $new_selection[$detail->id]['printaction'] = strtolower($detail->method); } } elseif ($detail->email == '') { $new_selection[$detail->id]['printaction'] = 'print'; } else { $new_selection[$detail->id]['printaction'] = 'email'; } $new_selection[$detail->id]['email'] = $detail->email; if ($detail->remittance_advice) { $new_selection[$detail->id]['select'] = 'true'; $new_selection['count']++; } else { $new_selection[$detail->id]['select'] = 'false'; } } } $_SESSION['selected_output'][$type] = $selected = $new_selection; $this->view->set('type', 'remittance'); $this->view->set('fields', array('payee_name', 'gross_value', 'currency', 'payment_type', 'email')); $this->view->set('clickaction', 'view'); $this->view->set('no_ordering', true); $this->view->set('collection', $pltransactions); $this->_data['printaction'] = $output_details['printaction']; $this->_data['filename'] = 'Remittance'; unset($this->printaction['view']); $this->printAction(); $this->view->set('page_title', $this->getPageName("", 'Print Remitttances for')); $this->view->set('selected_output', $selected); $this->view->set('count_selected', $selected['count']); $this->view->set('type_id', $this->_data['id']); foreach ($this->_modules as $key => $value) { $modules[] = $key . '=' . $value; } $link = implode('&', $modules) . '&controller=' . $this->name . '&action=adjust_selection&type=' . $type; $this->view->set('link', $link); $this->setTemplateName('select_for_output'); }