예제 #1
0
 /**
  * Creates a new orden
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "orden", "action" => "index"));
     }
     $orden = new Orden();
     //Buscar la ultima orden habilitada de la planilla
     $ultimaOrden = Orden::findFirst(array("orden_ultima = 1 AND orden_habilitado=1 AND orden_planillaId = :orden_planillaId:", 'bind' => array('orden_planillaId' => $this->request->getPost("orden_planillaId"))));
     if (!$ultimaOrden) {
         $orden->setOrdenNro(1);
         $orden->setOrdenUltima(1);
     } else {
         $orden->setOrdenNro($ultimaOrden->getOrdenNro() + 1);
         $orden->setOrdenUltima(1);
         $ultimaOrden->setOrdenUltima(0);
         $ultimaOrden->update();
     }
     $orden->setOrdenPlanillaId($this->request->getPost("orden_planillaId"));
     //FIXME: obtener el mes dese orden_fecha
     $orden->setOrdenPeriodo(date('d/m/Y', date(strtotime(date($this->request->getPost("orden_fecha"))))));
     $orden->setOrdenRemito($this->request->getPost("orden_remito"));
     $orden->setOrdenFecha($this->request->getPost("orden_fecha"));
     $orden->setOrdenTransporteId($this->request->getPost("orden_transporteId"));
     $orden->setOrdenTipoEquipoId($this->request->getPost("orden_tipoEquipoId"));
     $orden->setOrdenTipoCargaId($this->request->getPost("orden_tipoCargaId"));
     $orden->setOrdenChoferId($this->request->getPost("orden_choferId"));
     /*Busco los nombre de los clientes, */
     $orden->setOrdenClienteId($this->request->getPost("cliente_id"));
     $orden->setOrdenFrsId($this->request->getPost("frs_id"));
     $orden->setOrdenCentroCostoId($this->request->getPost("centroCosto_id"));
     $orden->setOrdenEquipoPozoId($this->request->getPost("equipoPozo_id"));
     $orden->setOrdenViajeId($this->request->getPost("orden_viajeId"));
     $orden->setOrdenConcatenadoId($this->request->getPost("orden_concatenadoId"));
     $tarifa = new Tarifa();
     $tarifa->setTarifaHoraInicial($this->request->getPost("tarifa_horaInicial"));
     $tarifa->setTarifaHoraFinal($this->request->getPost("tarifa_horaFinal"));
     $tarifa->setTarifaHsServicio($this->request->getPost("tarifa_hsServicio"));
     $tarifa->setTarifaHsHidro($this->request->getPost("tarifa_hsHidro"));
     $tarifa->setTarifaHsMalacate($this->request->getPost("tarifa_hsMalacate"));
     $tarifa->setTarifaHsStand($this->request->getPost("tarifa_hsStand"));
     $tarifa->setTarifaKm($this->request->getPost("tarifa_km"));
     if (!$tarifa->save()) {
         foreach ($tarifa->getMessages() as $mensaje) {
             $this->flash->error($mensaje);
         }
         return $this->dispatcher->forward(array("controller" => "orden", "action" => "index"));
     }
     $orden->setOrdenTarifaId($tarifa->getTarifaId());
     $orden->setOrdenObservacion($this->request->getPost("orden_observacion"));
     $orden->setOrdenConformidad($this->request->getPost("orden_conformidad"));
     $orden->setOrdenNoconformidad($this->request->getPost("orden_noConformidad"));
     $orden->setOrdenFechacreacion(date('Y-m-d'));
     $orden->setOrdenCreadoPor($this->session->get('auth')['usuario_nick']);
     $orden->setOrdenHabilitado(1);
     if (!$orden->save()) {
         //FIXME: ROLLBACK!! para que ultimaOrden vuelva a estar como antes.
         foreach ($orden->getMessages() as $message) {
             $this->flash->error('HUBO UN PROBLEMA AL GENERAR LA ORDEN. <br> <ins>Detalles:</ins><br>' . $message);
         }
         return $this->dispatcher->forward(array("controller" => "orden", "action" => "new"));
     }
     $this->flash->success("La orden se creó correctamente");
     return $this->dispatcher->forward(array("controller" => "orden", "action" => "index"));
 }