private function updateDailyPlan($em, $service, $date, $plan, $hpPlan) { $dailyPlan = $em->getRepository('sisconeeAppBundle:PlanMensualServicio')->getPlanOfAServiceInADate($service, $date); if ($dailyPlan == null) { if (!$this->isNullOrEmpty($plan) || !$this->isNullOrEmpty($hpPlan != null)) { // create a new plan $newDailyPlan = new LecturaDiariaServicio(); $newDailyPlan->setIdServicio($service); $newDailyPlan->setPlan($plan); $newDailyPlan->setPlanHorarioPico($hpPlan); $newDailyPlan->setFecha($date); $em->persist($newDailyPlan); $em->flush(); //Register Log $current_user = $this->getCurrentUser(); $date = $newDailyPlan->getFecha()->format('Y-m-d '); $data = $plan . ',' . $hpPlan . ',' . $service . ',' . $date; $em->getRepository('sisconeeAppBundle:Trazas')->persistLog('AƱadir', 'plan_diario_servicio', $newDailyPlan->getId(), $data, $current_user); } } else { if ($this->isNullOrEmpty($plan) && $this->isNullOrEmpty($hpPlan)) { // delete an existent plan $em->remove($dailyPlan); $em->flush(); //Register Log $id = $dailyPlan->getId(); $current_user = $this->getCurrentUser(); $date = $dailyPlan->getFecha()->format('Y-m-d '); $data = $dailyPlan->getPlan() . ',' . $dailyPlan->getPlanHorariopico() . ',' . $service . ',' . $date; $em->getRepository('sisconeeAppBundle:Trazas')->persistLog('Eliminar', 'plan_diario_servicio', $id, $data, $current_user); } else { // update an existent plan if ($dailyPlan->getPlan() != $plan || $dailyPlan->getPlanHorarioPico() != $hpPlan) { $dailyPlan->setPlan($plan); $dailyPlan->setPlanHorarioPico($hpPlan); $em->persist($dailyPlan); $em->flush(); //Register Log $current_user = $this->getCurrentUser(); $date = $dailyPlan->getFecha()->format('Y-m-d '); $data = $dailyPlan->getPlan() . ',' . $dailyPlan->getPlanHorariopico() . ',' . $service . ',' . $date; $em->getRepository('sisconeeAppBundle:Trazas')->persistLog('Actualizar', 'plan_diario_servicio', $dailyPlan->getId(), $data, $current_user); } } } }
function loadPlansFromCsvFiles($dir) { var_dump('loading daily and mensual plans for the services...'); var_dump($dir); $em = $this->manager; $entries = scandir($dir); $i = 0; foreach ($entries as $e) { $i++; var_dump('parsing files in folder ' . $i); $subdir = $dir . '\\' . $e; if (is_dir($subdir) && $e != '.' && $e != '..') { foreach (scandir($subdir) as $file) { $csvFile = $subdir . '\\' . $file; if (is_file($csvFile) && pathinfo($csvFile)['extension'] == "csv") { $fileHandle = fopen($csvFile, "r"); $row = 0; $date = ""; while (($data = fgetcsv($fileHandle, 1000, ",")) != false) { if ($row == 3) { // extract day here $date = date_parse($data[5]); //var_dump ("Loading plan for day: ".$date['day'].'/'.$date['month']); } if ($row >= 6) { if (is_numeric($data[0])) { $code = $data[1]; $service = $em->getRepository('sisconeeAppBundle:Servicio')->findOneByCodClienteEE($code); if ($service == null) { continue; } $lecturaDiariaActual = $em->getRepository('sisconeeAppBundle:LecturaDiariaServicio')->getLectura($date['day'], $date['month'], $date['year'], $service->getId()); if ($lecturaDiariaActual == null) { $planDia = $data[6]; $consumoDia = $data[7]; $lecturaDiariaActual = new LecturaDiariaServicio(); $lecturaDiariaActual->setPlan($planDia); $lecturaDiariaActual->setConsumo($consumoDia); $lecturaDiariaActual->setIdServicio($service); $dateDT = date_create(); date_date_set($dateDT, $date['year'], $date['month'], $date['day']); $lecturaDiariaActual->setFecha($dateDT); $em->persist($lecturaDiariaActual); //plandiario $this->manager->flush(); //var_dump ('saving service '.$service->getId()); } else { //var_dump("Existe " . date_format($lecturaDiariaActual->getFecha(), "m:d:y")); } $lecturaMensual = $em->getRepository('sisconeeAppBundle:PlanAnualEntidad')->getPlanOfAServiceInAMonthYear($service, $date['month'], $date['year']); if ($lecturaMensual == null) { $planMensualValue = $data[5]; $planMensual = new PlanmensualServicio(); $planMensual->setPlan($planMensualValue); $planMensual->setServicio($service); $planMensual->setMes($date['month']); $planMensual->setAnno($date['year']); $em->persist($planMensual); //planmensual $this->manager->flush(); } } } $row++; } $this->manager->flush(); } } } } }