Exemple #1
0
 protected function genericSampleNPDNotification(NPDEvent $event, $notificationTypeId, $status)
 {
     $npd = $event->getNPD();
     $sampleObjects = SampleQuery::create()->whereAdd(Sample::ID_NPD_SHEET, $npd->getIdNpdSheet())->whereAdd(Sample::STATUS, $status)->addAscendingOrderBy(Sample::DEADLINE)->find();
     $npdSupplierIds = NpdSheetSupplierQuery::create()->addColumn(NpdSheetSupplier::ID_SUPPLIER)->whereAdd(NpdSheetSupplier::ID_NPD_SHEET, $npd->getIdNpdSheet())->fetchCol();
     $suppliers = SapSupplierQuery::create()->whereAdd(SapSupplier::CARDCODE, $npdSupplierIds, SupplierQuery::IN)->find()->toCombo();
     $colors = \Application\Query\ColorQuery::create()->find()->toCombo();
     $samples = array();
     foreach ($sampleObjects as $sample) {
         if (!$sample instanceof Sample) {
             $sample = new Sample();
         }
         $samples[] = array('Supplier' => utf8_decode($suppliers[$sample->getIdSupplier()]), 'Quantity' => $sample->getQuantity(), 'Color' => $colors[$sample->getIdColor()], 'Remarks' => utf8_decode($sample->getNotes()), 'Deadline' => $sample->getDeadline(), 'Cost' => $sample->getCost(), 'ShippedQuantity' => $sample->getShippedQuantity());
     }
     $vars = array('id_npd_sheet' => $npd->getIdNpdSheet(), 'creation_date' => $npd->getCreationDateAsZendDate()->get("dd-MM-yyyy HH:mm"), 'name' => utf8_decode($npd->getName()), 'description' => utf8_decode($npd->getDescription()), 'samples' => $samples);
     $this->createNotification($notificationTypeId, $vars);
 }
Exemple #2
0
 function orderAction()
 {
     $npds = $this->getRequest()->getParam('npd', array());
     if (count($npds) == 0) {
         throw new Exception($this->i18n->_("Any npd wasn't selected"));
     }
     $sampleCatalog = $this->getSampleCatalog();
     $sampleCatalog->beginTransaction();
     try {
         foreach ($npds as $npdId => $row) {
             $orderedSamples = 0;
             foreach ($row['supplier'] as $i => $supplierId) {
                 if (!isset($row['selected'][$i])) {
                     continue;
                 }
                 //TODO: Cambiar esto al javascript
                 $supplier = $row['supplier'][$i];
                 $quantity = $row['quantity'][$i];
                 $color = $row['color'][$i];
                 $remarks = $row['remarks'][$i];
                 $deadline = $row['deadline'][$i];
                 $cost = $row['cost'][$i];
                 $lastFolio = SampleQuery::create()->removeColumn()->addColumn(Sample::FOLIO)->addDescendingOrderBy(Sample::ID_SAMPLE)->fetchOne();
                 $sample = new Sample();
                 $sample->setIdNpdSheet($npdId);
                 $sample->setIdSupplier($supplier == "" ? null : $supplier);
                 $sample->setIdColor($color == 0 ? null : $color);
                 $sample->setQuantity($quantity);
                 $sample->setNotes($remarks);
                 $sample->setDeadline($deadline);
                 $sample->setCost($cost);
                 $sample->setFolio($lastFolio + 1);
                 $sample->setStatus(Sample::$Status['Ordered']);
                 //die(print_r($sample));
                 $sampleCatalog->create($sample);
                 $orderedSamples++;
             }
             if ($orderedSamples) {
                 $npd = NpdSheetQuery::create()->findByPK($npdId);
                 $this->getEventDispatcherService()->dispatchNPDEvent($npd, NPDEvent::NPD_ORDERED_SAMPLES);
             }
         }
         $sampleCatalog->commit();
     } catch (Exception $e) {
         $sampleCatalog->rollBack();
         throw $e;
     }
     $this->setFlash('ok', $this->i18n->_("Successfully ordered"));
     $this->getHelper('redirector')->goto('index');
 }