/** * * makeBean * @param array $resultset * @return \Application\Model\Bean\SampleShipment */ protected function makeBean($resultset) { return SampleShipmentFactory::createFromArray($resultset); }
public function sendAction() { $samples = $this->getRequest()->getParam('samples', array()); // echo '<pre>'; // print_r($samples); // die; if (count($samples) == 0) { $this->setFlash('error', $this->i18n->_("Any sample were selected")); return $this->getHelper('redirector')->goto('index'); } $sampleShipmentCatalog = $this->getSampleShipmentCatalog(); $sampleShipmentCatalog->beginTransaction(); try { $sampleShipment = new SampleShipment(); SampleShipmentFactory::populate($sampleShipment, $this->getRequest()->getParams()); $sampleShipmentCatalog->create($sampleShipment); foreach ($samples as $sampleId => $data) { if (!isset($data['selected'])) { continue; } $sample = SampleQuery::create()->findByPKOrThrow($sampleId, $this->i18n->_("Sample with Id {$sampleId} wasn't found")); $sample->setIdSampleShipment($sampleShipment->getIdSampleShipment()); $sample->setIdSupplier($data['supplier']); $sample->setCost($data['cost']); $sample->setShippedQuantity($data['quantity']); $color = $data['id_color'] ? $data['id_color'] : null; $sample->setIdColor($color); $sample->setStatus(Sample::$Status['Sent']); $this->getSampleCatalog()->update($sample); $pendingSamples = SampleQuery::create()->whereAdd(Sample::ID_NPD_SHEET, $sample->getIdNpdSheet())->whereAdd(Sample::STATUS, array(Sample::$Status['Ordered'], Sample::$Status['RequestedToSupplier'], Sample::$Status['SupplierReceived'], Sample::$Status['Confirmed']), SampleQuery::IN)->count(); if (!$pendingSamples) { $npd = NpdSheetQuery::create()->findByPKOrThrow($sample->getIdNpdSheet(), $this->i18n->_("NPD Sheet with Id {$sample->getIdNpdSheet()} wasn't found")); $this->getEventDispatcherService()->dispatchNPDEvent($npd, NPDEvent::NPD_SENT_SAMPLES); } } $sampleShipmentCatalog->commit(); } catch (Exception $e) { $sampleShipmentCatalog->rollBack(); throw $e; } $this->setFlash('ok', $this->i18n->_("Successfully sent")); $this->getHelper('redirector')->goto('index'); }