Ejemplo n.º 1
0
 function preProcessing($id, $jobTemp = null)
 {
     if ($jobTemp == null) {
         $job = new Job();
         $job->setIdNorm($id);
         $job->setIdType(1);
         $job->setIdUser($this->getUser()->getId());
         $job->setDateReceipt(date_create(date('Y-m-d', time())));
         $job->setDateImplement(date_create(date('Y-m-d', time())));
         return $job;
     } else {
         $job = new Job();
         $job->setIdUser($this->getUser()->getId());
         $job->setIdNorm($jobTemp->getIdNorm());
         $job->setDeclarant($jobTemp->getDeclarant());
         $job->setDescription($jobTemp->getDescription());
         $job->setFormula($jobTemp->getFormula());
         $job->setIdType($jobTemp->getIdType());
         $job->setQuantity($jobTemp->getQuantity());
         $job->setRemark($jobTemp->getRemark());
         $job->setSumma($jobTemp->getSumma());
         $job->setValue($jobTemp->getValue());
         $job->setDateReceipt(date_create(date('Y-m-d', time())));
         $job->setDateImplement(date_create(date('Y-m-d', time())));
         return $job;
     }
 }
Ejemplo n.º 2
0
 /**
  * @Route("/import/forum")
  */
 function forumAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $form = $this->createFormBuilder()->add('fileName', 'text', array('label' => 'fileName'))->add('listNumber', 'text', array('label' => 'listNumber'))->add('idUser', 'text', array('label' => 'idUser'))->add('Save', 'submit', array('label' => 'Отправить'))->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $fileName = $request->request->all()['form']['fileName'];
         $listNumber = $request->request->all()['form']['listNumber'];
         $idUser = $request->request->all()['form']['idUser'];
         $xls = $this->get('phpexcel')->createPHPExcelObject($fileName);
         $xls->setActiveSheetIndex($listNumber);
         $sheet = $xls->getActiveSheet();
         $arrImport = array();
         //Массив работ
         $rowEnd = $sheet->getHighestRow();
         for ($row = 2; $row <= $rowEnd; $row++) {
             $description = $sheet->getCellByColumnAndRow(1, $row)->getValue();
             $zayavka = $sheet->getCellByColumnAndRow(2, $row)->getValue();
             $podrazdelenie = $sheet->getCellByColumnAndRow(3, $row)->getValue();
             $declarant = $sheet->getCellByColumnAndRow(4, $row)->getValue();
             $date = new \DateTime();
             $dateReceipt = $date->setTimestamp($this->excel_to_timestamp($sheet->getCellByColumnAndRow(5, $row)));
             $date1 = new \DateTime();
             $dateImplement = $date1->setTimestamp($this->excel_to_timestamp($sheet->getCellByColumnAndRow(6, $row)));
             $preSize = $sheet->getCellByColumnAndRow(7, $row)->getValue();
             $formula = $sheet->getCellByColumnAndRow(8, $row)->getValue();
             $remark = $sheet->getCellByColumnAndRow(9, $row)->getValue();
             if ($declarant == '' or $description == '' or $dateReceipt == '' or $dateImplement == '' or $formula == '') {
             } else {
                 $job = new Job();
                 $norm = $em->getRepository('AppBundle:Norm')->find(229);
                 $job->setIdNorm(229);
                 $job->setIdType(2);
                 $job->setIdUser($idUser);
                 $job->setNorm($norm);
                 $job->setQuantity(1);
                 $job->setValue(0);
                 $job->setSumma(0);
                 $job->setDescription($description);
                 //Описание материала
                 $job->setDeclarant($declarant);
                 //Сотрудник
                 $job->setDateReceipt($dateReceipt);
                 //Дата получения
                 $job->setDateImplement($dateImplement);
                 //Дата выполнения
                 $job->setFormula($formula);
                 //Формула
                 $remark = array('remark' => $remark, 'zayavka' => $zayavka, 'podrazdelenie' => $podrazdelenie, 'preSize' => $preSize);
                 $job->setRemark(serialize($remark));
                 $arrImport[] = $job;
             }
         }
         foreach ($arrImport as $job) {
             $em->persist($job);
         }
         $em->flush();
         return $this->redirectToRoute('homepage');
     }
     return $this->render('form/form.html.twig', array('form' => $form->createView()));
 }