public function addAction()
 {
     $viewModel = new ViewModel();
     $form = $this->getServiceLocator()->get("Process\\Form\\OutputInventoryForm");
     $viewModel->setVariable('form', $form);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $outputInventory = new OutputInventory();
         $form->setInputFilter($outputInventory->getInputFilter());
         $data = $request->getPost()->toArray();
         $form->setData($data);
         if ($form->isValid()) {
             $authenticationService = new AuthenticationService();
             $user = $authenticationService->getStorage()->read()->id;
             $outputInventory->setUser($user);
             $outputInventory->exchangeArray($data);
             $outputInventoryId = $this->getOutputInventoryTable()->save($outputInventory);
             $container = new Container('output_inventory');
             $container->id = $outputInventoryId;
             $container->user = $user;
             return $this->redirect()->toRoute('process/output_inventory/add/details');
         }
     }
     $viewModel->setVariable('config', $this->config);
     return $viewModel;
 }
 public function save(OutputInventory $outputInventory)
 {
     $data = array('user' => $outputInventory->getUser(), 'client' => $outputInventory->getClient(), 'seller' => $outputInventory->getSeller(), 'payment_method' => $outputInventory->getPaymentMethod(), 'guide' => $outputInventory->getGuideNumber(), 'observations' => $outputInventory->getObservation(), 'register_date' => date("Y-m-d H:i:s", time()), 'update_date' => date("Y-m-d H:i:s", time()));
     $id = (int) $outputInventory->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;
         }
     }
 }