public function delete() { if (empty($this->_data['SOrderLine']['id'])) { $this->dataError(); sendBack(); } $flash = Flash::Instance(); $sorderline = $this->_uses[$this->modeltype]; $sorderline->load($this->_data['SOrderLine']['id']); if ($sorderline->isLoaded() && $sorderline->delete()) { $flash->addMessage($sorderline->header->getFormatted('type') . ' Line Deleted'); if (isset($this->_data['dialog'])) { $link = array('modules' => $this->_modules, 'controller' => 'sorders', 'action' => 'view', 'other' => array('id' => $sorderline->order_id)); $flash->save(); echo parent::returnJSONResponse(TRUE, array('redirect' => '/?' . setParamsString($link))); exit; } else { sendTo('sorders', 'view', $this->_modules, array('id' => $sorderline->order_id)); } } $flash->addError('Error deleting ' . $sorderline->header->getFormatted('type') . ' Line'); $this->_data['id'] = $this->_data['SOrderLine']['id']; $this->_data['order_id'] = $this->_data['SOrderLine']['order_id']; $this->refresh(); }
public function save() { $flash = Flash::Instance(); $errors = array(); $data = $this->_data['PInvoiceLine']; if (empty($data['invoice_id'])) { $errors[] = 'Invoice header not defined'; } else { $pinvoice = DataObjectFactory::Factory('Pinvoice'); $pinvoice->load($data['invoice_id']); if (!$pinvoice->isLoaded()) { $errors[] = 'Cannot find invoice header'; } elseif ($pinvoice->isLatest($this->_data['PInvoice'], $errors)) { $pinvoiceline = PInvoiceLine::Factory($pinvoice, $data, $errors); if ($pinvoiceline && count($errors) == 0) { if (!$pinvoiceline->save($pinvoice)) { $errors[] = 'Failed to save Purchase ' . $pinvoice->getFormatted('transaction_type') . ' line'; } } } } if (count($errors) == 0) { $flash->addMessage('Purchase ' . $pinvoice->getFormatted('transaction_type') . ' Line Saved'); if (isset($this->_data['saveAnother'])) { $other = array('invoice_id' => $pinvoiceline->invoice_id); if (isset($this->_data['dialog'])) { $other += array('dialog' => ''); } if (isset($this->_data['ajax'])) { $other += array('ajax' => ''); } sendTo($this->name, 'new', $this->_modules, $other); } else { $action = 'view'; $controller = 'pinvoices'; $other = array('id' => $pinvoiceline->invoice_id); } if (isset($this->_data['dialog'])) { $link = array('modules' => $this->_modules, 'controller' => $controller, 'action' => $action, 'other' => $other); $flash->save(); echo parent::returnJSONResponse(TRUE, array('redirect' => '/?' . setParamsString($link))); exit; } else { sendTo($controller, $action, $this->_modules, $other); } } else { $flash->addErrors($errors); $this->_data['id'] = $this->_data['PInvoiceLine']['id']; $this->_data['invoice_id'] = $this->_data['PInvoiceLine']['invoice_id']; $this->refresh(); } }