Ejemplo n.º 1
0
 public function uploadAction(Request $request)
 {
     $form = $this->createForm(new Pud\Upload());
     $form->handleRequest($request);
     if ($request->isMethod("POST")) {
         if ($form->isValid()) {
             try {
                 foreach ($request->files as $uploadedFile) {
                     $file = $uploadedFile['file'];
                     $filename = $file->getClientOriginalName();
                     $file->move(QA\TDQueueAbstract::getUploadReportDir(), $filename);
                     break;
                 }
                 $filepath = QA\TDQueueAbstract::getUploadReportDir() . '/' . $filename;
                 $this->objExcel = \PHPExcel_IOFactory::load($filepath);
                 $this->sheet = $this->objExcel->getActiveSheet();
                 $pudRepository = $this->getDoctrine()->getRepository('AppTruckingBundle:Pud');
                 $em = $this->getDoctrine()->getManager();
                 //массив ошибок, если они есть
                 $error = null;
                 foreach ($this->sheet->getRowIterator() as $row) {
                     $rowIndex = $row->getRowIndex();
                     if ($rowIndex < $this->startRows) {
                         continue;
                     }
                     $row = null;
                     $result = $this->isImportRowCorrect($rowIndex);
                     $row = $result['RESULT'];
                     //проверка нужна на случай если есть незаполненые строки в импортируемом файле.
                     if (!count($row)) {
                         continue;
                     }
                     //если есть ошибки, прерываем загрузку
                     if ($result['SUCCESS'] == false) {
                         $error = $row;
                         break;
                     }
                     $pud = new Entity\Pud();
                     $pud->setCustomerId($row['CUSTOMER']);
                     $pud->setPackingId($row['PACKAGE_TYPE']);
                     $pud->setCargoType($row['TRUCKING_CARGO_TYPE']);
                     $pud->setCargoDescription($this->getCellValue('D', $rowIndex));
                     $pud->setLength($this->getCellValue('E', $rowIndex));
                     $pud->setWidth($this->getCellValue('F', $rowIndex));
                     $pud->setHeight($this->getCellValue('G', $rowIndex));
                     $volume = isset($row['TOTAL_VOLUME']) ? $row['TOTAL_VOLUME'] : $this->getCellValue('H', $rowIndex);
                     $pud->setVolume($volume);
                     $quantity = isset($row['ITEM_QUANTITY']) ? $row['ITEM_QUANTITY'] : $this->getCellValue('I', $rowIndex);
                     $pud->setCountPlaces($quantity);
                     $pud->setSummaryWeight($row['TOTAL_WEIGHT']);
                     $pud->setStackFlag($row['STACKABILITY']);
                     $pud->setShipper($row['SHIPPER']);
                     $pud->setShipperAddress($row['SHIPPER_ADDRESS']);
                     $pud->setLoadTimeSlot($this->renderDateString($row['LOADING_TIME_SLOT']));
                     $pud->setConsignee($row['CONSIGNEE']);
                     $pud->setConsigneeAddress($row['CONSIGNEE_ADDRESS']);
                     $pud->setUnloadTimeSlot($this->renderDateString($row['UNLOADING_TIME_SLOT']));
                     $pud->setSecurityFlag($row['SECURITY']);
                     $pud->setSecurityType($row['SECURITY_TYPE']);
                     $pud->setComments($this->getCellValue('T', $rowIndex));
                     $pud->setStatus($this->getStatus('Uploaded'));
                     $pud->setUserId($this->getUser());
                     $em->persist($pud);
                     $em->flush();
                     $message = "The file name is {$filename} was upload successfully";
                 }
             } catch (\Exception $ex) {
                 $message = 'Error: ' . $ex->getMessage() . '. Line: ' . $ex->getLine() . ' File: ' . $ex->getFile();
                 $logger = $this->get('logger');
                 $logger->error($message);
                 $error[] = $message;
             }
         }
     }
     return $this->render('AppTruckingBundle:Pud:upload.html.twig', ['form' => isset($form) ? $form->createView() : null, 'message' => isset($message) ? $message : null, 'error' => isset($error) ? $error : null]);
 }
 /**
  * Метод возвращает true в случае если PUD находится в статусе TN-received и 
  * ActualCost больше 0
  * @param \App\TruckingBundle\Entity\Pud $pud
  */
 public function isPudClosed(\App\TruckingBundle\Entity\Pud $pud)
 {
     if ($pud->getStatus()->getName() == 'TN received' && $pud->getActualCost() > 0) {
         if ($pud->getSecurityFlag() == 1) {
             if ($pud->getActualSecurityCost() > 0) {
                 return true;
             }
             return false;
         } else {
             return true;
         }
     } else {
         return false;
     }
 }
 private function addPudToTruckOrder(Entity\TruckOrder $truckOrder, Entity\Pud $pud)
 {
     $weight = $truckOrder->getWeight() + $pud->getSummaryWeight();
     $volume = $truckOrder->getVolume() + $pud->getLength() * $pud->getHeight() * $pud->getWidth();
     $packageCount = $truckOrder->getPackageCount() + $pud->getCountPlaces();
     //необходимо подобрать новый грузовик, метод возвращает Площадь и Максимальную высоту всех Pud входящих в TruckOrder
     list($square, $maxHeight) = $this->getDoctrine()->getRepository('AppTruckingBundle:TruckOrder')->getSquareAndMaxHeightById($truckOrder->getId());
     $square = $square + $pud->getWidth() * $pud->getLength() * $pud->getCountPlaces();
     $repositoryTruck = $this->getDoctrine()->getRepository('AppTruckingBundle:Trucks');
     $trucks = $repositoryTruck->getSuitableTruck($weight, $square, $maxHeight);
     if (is_null($trucks)) {
         throw new \Exception('Suitable truck not found');
     } else {
         $truckOrder->setTruckId($repositoryTruck->find($trucks));
         $truckOrder->setWeight($weight);
         $truckOrder->setVolume($volume);
         $truckOrder->setPackageCount($packageCount);
     }
 }