/**
  * @author Jose Luis Suarez Nieto
  * @return array
  */
 public function createAction()
 {
     $params = $this->getRequest()->getParams();
     $myFolioImport = new FolioImport();
     $myFolioImport->setIdForwarder($params['merchandiseForwarder']);
     $myFolioImport->setIdPortCustom($params['merchandiseDeparturePort']);
     $myFolioImport->setIdPortDestination($params['destination']);
     $myFolioImport->setIdWarehouse($params['warehouse']);
     if (isset($params['preInspected'])) {
         $myFolioImport->setPreInspected(1);
     } else {
         $myFolioImport->setPreInspected(0);
     }
     if (isset($params['customsBroker']) && $params['customsBroker'] != '') {
         $myFolioImport->setIdCustomsBroker($params['customsBroker']);
     }
     if (isset($params['typeIncome'])) {
         $myFolioImport->setTypeIncome($params['typeIncome']);
     }
     try {
         $this->getFolioImportCatalog()->beginTransaction();
         $this->getFolioImportCatalog()->create($myFolioImport);
         $this->newLogForCreate($myFolioImport);
         $folio = $this->createFolio($myFolioImport->getIdFolioImport());
         $myFolioImport->setFolio($folio);
         $this->getFolioImportCatalog()->update($myFolioImport);
         $this->newLogForCreate($myFolioImport);
         /**
          * To create the notification
          */
         $this->getEventDispatcherService()->createFolioImportNotification($myFolioImport, FolioImportEvent::FOLIO_IMPORT_CREATED);
     } catch (Exception $e) {
         echo $e;
         $this->getFolioImportCatalog()->rollBack();
         die;
     }
     try {
         $booking = new Booking();
         $booking->setIdFolioImport($myFolioImport->getIdFolioImport());
         $booking->setWeight($params['bookingWeight']);
         $booking->setCubicMeters($params['bookingCbm']);
         $this->getCatalog('BookingCatalog')->create($booking);
         $this->getFolioImportCatalog()->update($myFolioImport);
     } catch (Exception $e) {
         $this->setFlash('error', $e->getMessage());
         $this->getFolioImportCatalog()->rollBack();
         $this->_redirect('folio-import/list');
     }
     try {
         foreach ($params['idFreightFare'] as $id => $value) {
             $myFolioImportFreightFare = new FolioImportFreightFare();
             $myFolioImportFreightFare->setIdFolioImport($myFolioImport->getIdFolioImport());
             $myFolioImportFreightFare->setIdFreightFare($id);
             $myFolioImportFreightFare->setQuantity($value);
             $this->getCatalog('FolioImportFreightFareCatalog')->create($myFolioImportFreightFare);
         }
     } catch (Exception $e) {
         echo $e;
         $this->getFolioImportCatalog()->rollBack();
         die;
     }
     try {
         $purchaseOrders = new PurchaseOrderCollection();
         $allPurchaseOrderEntries = new PurchaseOrderEntryCollection();
         foreach ($params['purchaseOrders'] as $purchaseOrder) {
             if (isset($purchaseOrder['value'])) {
                 $SapConnector = new SAPConnectorClient();
                 $myPurchaseOrder = PurchaseOrderQuery::create()->findByPK($purchaseOrder['id']);
                 $myPurchaseOrder->setStatus(PurchaseOrder::$Status['Assigned']);
                 $myPurchaseOrder->setIdFolioImport($myFolioImport->getIdFolioImport());
                 $purchaseOrderEntries = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $purchaseOrder['id'])->find();
                 $result = $SapConnector->purchaseOrder($myPurchaseOrder, $purchaseOrderEntries);
                 $purchaseOrders->append($myPurchaseOrder);
                 $allPurchaseOrderEntries = $allPurchaseOrderEntries->merge($purchaseOrderEntries);
                 if ($result->purchaseOrderResult->code != 200) {
                     $this->setFlash('error', $this->i18n->_($result->purchaseOrderResult->message));
                     $this->getFolioImportCatalog()->rollBack();
                     $this->_redirect('folio-import/list');
                 }
             }
         }
     } catch (Exception $e) {
         echo $e;
         $this->getFolioImportCatalog()->rollBack();
         $this->setFlash('error', $this->i18n->_($e->getMessage()));
         $this->_redirect('folio-import/list');
     }
     $this->getFolioImportCatalog()->commit();
     $this->setFlash('ok', $this->i18n->_("The Folio Import " . $myFolioImport->getFolio() . " has been created."));
     while ($purchaseOrder = $purchaseOrders->read()) {
         $purchaseOrderEntries = $allPurchaseOrderEntries->filterByPurchaseOrderPk($purchaseOrder->getIdPurchaseOrder());
         $this->getEventDispatcherService()->dispatchPurchaseOrderEvent($purchaseOrder, PurchaseOrderEvent::PURCHASEORDER_SHIPPED, $purchaseOrderEntries);
     }
     $this->_redirect('folio-import/list');
 }
Beispiel #2
0
 /**
  * 
  * @return array
  */
 public function createAction()
 {
     extract($_POST);
     $folioImport = new FolioImport();
     $folioImport->setIdFolioImport($id_folio_import);
     $folioImport->setStatus(FolioImport::$Status['Assigned']);
     $this->getCatalog('FolioImportCatalog')->beginTransaction();
     try {
         $this->getCatalog('FolioImportCatalog')->update($folioImport);
     } catch (Exception $e) {
         print_r($folioImport->toArray());
         $this->getCatalog('FolioImportCatalog')->rollBack();
         die;
     }
     $booking = new Booking();
     $booking->setEta($eta);
     $booking->setEtaWarehouse($warehouse_eta);
     $booking->setEtd($etd);
     $booking->setTrackingNumber($tracking_number);
     $booking->setNameVessel($vessel_name);
     $booking->setCarrier($carrier);
     $booking->setContainerNumber($container_number);
     $booking->setCartons($cartons);
     $booking->setCubicMeters($bookingCbm);
     $booking->setWeight($bookingWeight);
     $booking->setSize($size);
     $booking->setIdFolioImport($id_folio_import);
     try {
         $this->getCatalog('BookingCatalog')->create($booking);
         //        	Notification for Compras about the invoices missing
         $this->getEventDispatcherService()->createBookingNotification($booking, BookingEvent::BOOKING_MISSING_INVOICE);
         //        	Notification for Compras about the BL Houses missing
         $this->getEventDispatcherService()->createBookingNotification($booking, BookingEvent::BOOKING_MISSING_BL_HOUSE);
         $folioImport = FolioImportQuery::create()->findByPK($booking->getIdFolioImport());
         $purchaseOrders = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $folioImport->getIdFolioImport())->find();
         while ($purchaseOrders->valid()) {
             $purchaseOrder = $purchaseOrders->read();
             $this->getEventDispatcherService()->dispatchPurchaseOrderEvent($purchaseOrder, PurchaseOrderEvent::PURCHASEORDER_SHIPPED);
         }
     } catch (Exception $e) {
         echo 'booking';
         print_r($booking->toArray());
         $this->getCatalog('FolioImportCatalog')->rollBack();
         $this->setFlash('error', $this->i18n->_($this->CREATE_ERROR));
         $this->_redirect('folio-import/list');
     }
     $idBooking = $booking->getIdBooking();
     $itineraries = $this->getRequest()->getParam('itineraries');
     foreach ($itineraries as $value) {
         extract($value);
         $itinerary = new Itinerary();
         $itinerary->setIdBooking($idBooking);
         $itinerary->setOrigin($origin);
         $itinerary->setDestination($destination);
         $itinerary->setType($type);
         $itinerary->setDays($days);
         $itinerary->setEtd($etd);
         $itinerary->setEta($eta);
         try {
             $this->setFlash('ok', $this->i18n->_($this->CREATE_TRANSPORT_OK));
             $this->getCatalog('ItineraryCatalog')->create($itinerary);
         } catch (Exception $e) {
             $this->setFlash('error', $e);
             $this->getCatalog('ItineraryCatalog')->rollBack();
             $this->_redirect('folio-import/list');
         }
     }
     $this->setFlash('ok', $this->i18n->_($this->CREATE_OK));
     $this->getCatalog('FolioImportCatalog')->commit();
     $this->_redirect('folio-import/details/id/' . $id_folio_import);
 }