public function detailsAction() { $container = new Container('receive_inventory'); $viewModel = new ViewModel(); if (!$container->id) { return $this->redirect()->toRoute('process/receive_inventory'); } $receiveInventoryId = $container->id; $user = $container->user; $receiveInventory = $this->getReceiveInventoryTable()->get($receiveInventoryId, $user); $form = $this->getServiceLocator()->get('Process\\Form\\DetailsReceiveInventoryForm'); $detailsReceiveInventory = new DetailsReceiveInventory(); $form->setInputFilter($detailsReceiveInventory->getInputFilter()); $request = $this->getRequest(); $data = $request->getPost()->toArray(); $form->setData($data); if ($request->isPost()) { $serials = array(); $qty = (int) $data['qty']; $serialValuesElementErrors = true; for ($i = 0; $i < $qty; $i++) { $serialValue = $data['serials'][$i][0]; if (isset($serialValue) && !empty($serialValue)) { $serials[$i] = array_filter($data['serials'][$i]); } else { $serialValuesElementErrors = false; break; } } if ($form->isValid() && $serialValuesElementErrors) { $fileService = $this->getServiceLocator()->get('Admin\\Service\\FileService'); $fileService->setDestination($this->config['component']['details_receive_inventory']['file_path']); $fileService->setSize($this->config['file_characteristics']['file']['size']); $fileService->setExtension($this->config['file_characteristics']['file']['extension']); $manifestFile = $fileService->copy($this->params()->fromFiles('manifest_file')); $data['cost'] = str_replace('.', '', $data['cost']); $data['receive_inventory'] = $container->id; $data['serials'] = json_encode($serials); $data['manifest_file'] = $manifestFile ? $manifestFile : ""; $detailsReceiveInventory->exchangeArray($data); $detailsReceiveInventoryId = $this->getDetailsReceiveInventoryTable()->save($detailsReceiveInventory); $productsReceiveInventory = new ProductsReceiveInventory(); $productsReceiveInventory->setDetailsReceiveInventory($detailsReceiveInventoryId); $productsReceiveInventory->setSerial($serials); $this->getProductsReceiveInventoryTable()->save($productsReceiveInventory); return $this->redirect()->toRoute('process/receive_inventory/add/details'); } else { if (!$serialValuesElementErrors) { $serialValuesMessageError = "debe ingresar el serial principal para cada producto"; $viewModel->setVariable('serialValuesMessageError', $serialValuesMessageError); } } } $detailsReceiveInventory = $this->getDetailsReceiveInventoryTable()->get($container->id); $detailReceiveInventoryList = array(); foreach ($detailsReceiveInventory as $detailReceiveInventory) { $productsReceiveInventory = $this->getProductsReceiveInventoryTable()->getSerialList($detailReceiveInventory->getId()); $serials = array(); foreach ($productsReceiveInventory as $productReceiveInventory) { $serials[] = $productReceiveInventory->getSerial(); $detailReceiveInventory->setQty($productReceiveInventory->getNumber()); } $detailReceiveInventory->setSerials($serials); $detailReceiveInventoryList[] = $detailReceiveInventory; } //dumpx($detailReceiveInventoryList); $viewModel->setVariable('form', $form); $viewModel->setVariable('receiveInventory', $receiveInventory); $viewModel->setVariable('config', $this->config); $viewModel->setVariable('detailReceiveInventoryList', $detailReceiveInventoryList); $viewModel->setTemplate("process/receive-inventory/details"); return $viewModel; }