public function save(ReceiveInventory $receiveInventory) { $data = array('register_date' => date("Y-m-d H:i:s", time()), 'user' => $receiveInventory->getUser(), 'customer' => $receiveInventory->getCustomer(), 'payment_method' => $receiveInventory->getPaymentMethod(), 'shipment' => $receiveInventory->getShipment(), 'guide' => $receiveInventory->getGuideNumber(), 'invoice' => $receiveInventory->getInvoice(), 'invoice_file' => $receiveInventory->getInvoiceFile(), 'observations' => $receiveInventory->getObservation()); $id = (int) $receiveInventory->getId(); $params = array(); $params['table'] = $this->tableGateway->getTableName(); $params['operation'] = 1; $params['data'] = json_encode($data); if ($id == 0) { $this->tableGateway->insert($data); $id = $this->tableGateway->getLastInsertValue(); if ($id) { $params['id'] = $id; $this->featureSet->getEventManager()->trigger("log.save", $this, $params); return $id; } else { return false; } } else { if ($this->get($id)) { $params['id'] = $id; $params['operation'] = 2; $this->featureSet->getEventManager()->trigger("log.save", $this, $params); $this->tableGateway->update($data, array('id' => $id)); return $id; } else { return false; } } }
public function addAction() { $viewModel = new ViewModel(); $form = $this->getServiceLocator()->get("Process\\Form\\ReceiveInventoryForm"); $viewModel->setVariable('form', $form); $request = $this->getRequest(); if ($request->isPost()) { $receiveInventory = new ReceiveInventory(); $form->setInputFilter($receiveInventory->getInputFilter()); $data = $request->getPost()->toArray(); $form->setData($data); if ($form->isValid()) { $fileService = $this->getServiceLocator()->get('Admin\\Service\\FileService'); $fileService->setDestination($this->config['component']['receive_inventory']['file_path']); $fileService->setSize($this->config['file_characteristics']['file']['size']); $fileService->setExtension($this->config['file_characteristics']['file']['extension']); $invoiceFile = $fileService->copy($this->params()->fromFiles('invoice_file')); $data['invoice_file'] = $invoiceFile ? $invoiceFile : ""; $authenticationService = new AuthenticationService(); $user = $authenticationService->getStorage()->read()->id; $receiveInventory->setUser($user); $receiveInventory->exchangeArray($data); $receiveInventoryId = $this->getReceiveInventoryTable()->save($receiveInventory); $container = new Container('receive_inventory'); $container->id = $receiveInventoryId; $container->user = $user; return $this->redirect()->toRoute('process/receive_inventory/add/details'); } } $viewModel->setVariable('config', $this->config); return $viewModel; }