public function view() { if (!isset($this->_data['id'])) { $flash->addError('Select an item'); } else { $whtransferline = new WHTransferline(); $whtransferline->load($this->_data['id']); if ($whtransferline) { sendTo('stitems', $this->_data['action'], $this->_modules, array('id' => $whtransferline->stitem_id)); } else { $flash->addError('Error loading item'); } } }
public function save() { $flash = Flash::Instance(); if (strtolower($this->_data['saveform']) == 'cancel') { $flash->addMessage('Action cancelled'); sendTo($this->name, 'index', $this->_modules); } $errors = array(); $db = DB::Instance(); $db->StartTrans(); $header_data = $this->_data['WHTransfer']; $lines_data = array(); if (isset($this->_data['WHTransferLine'])) { $lines_data = $this->_data['WHTransferLine']; $lines_data = DataObjectCollection::joinArray($lines_data); } else { $errors[] = 'No Transfer Lines entered'; } if (isset($header_data['id']) && $header_data['id'] != '') { $action = 'updated'; // delete any lines not submitted $update = array(); foreach ($lines_data as $line) { $update[$line['id']] = $line['id']; } $whtransfer = new WHTransfer(); $whtransfer->load($header_data['id']); if ($whtransfer) { foreach ($whtransfer->transfer_lines as $line) { if (!isset($update[$line->id])) { $whtransferline = new WHTransferline(); $whtransferline->delete($line->id); } } } } else { $action = 'added'; } $whtransfer = WHTransfer::Factory($header_data, $lines_data, $errors); if ($whtransfer && count($errors) == 0) { $whtransfer->save($errors); } if (count($errors) == 0 && $db->CompleteTrans()) { $flash->addMessage('Transfer Number ' . $whtransfer->transfer_number . ' ' . $action . ' successfully'); sendTo($this->name, 'index', $this->_modules); } else { $db->FailTrans(); $flash->addErrors($errors); $this->_new(); $this->_templateName = $this->getTemplateName('new'); } }