예제 #1
0
 /**
  * Saves a centrocosto edited
  *
  */
 public function saveAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "centrocosto", "action" => "index"));
     }
     $centroCosto_id = $this->request->getPost("centroCosto_id");
     $centrocosto = Centrocosto::findFirstBycentroCosto_id($centroCosto_id);
     if (!$centrocosto) {
         $this->flash->error("Centro Costo no existe - ID: " . $centroCosto_id);
         return $this->dispatcher->forward(array("controller" => "centrocosto", "action" => "index"));
     }
     if ($this->request->getPost("nuevaLinea") == 1) {
         $centroCosto = new Linea();
         $centroCosto->assign(array('linea_nombre' => $this->request->getPost('linea_nombre'), 'linea_habilitado' => 1));
         //el input linea_nombre es para crear una nueva linea
         if (!$centroCosto->save()) {
             foreach ($centroCosto->getMessages() as $message) {
                 $this->flash->error($message);
             }
             return $this->dispatcher->forward(array("controller" => "centrocosto", "action" => "edit", "params" => array($centrocosto->centroCosto_id)));
         }
         $centrocosto->setCentroCostoLineaId($centroCosto->getLineaId());
     } else {
         if ($this->request->getPost("centroCosto_lineaId") != NULL) {
             $centrocosto->setCentroCostoLineaId($this->request->getPost("centroCosto_lineaId"));
         } else {
             $this->flash->error("SELECCIONE LA LINEA");
             return $this->dispatcher->forward(array("controller" => "centrocosto", "action" => "edit", "params" => array($centrocosto->centroCosto_id)));
         }
     }
     $centrocosto->setCentrocostoCodigo($this->request->getPost("centroCosto_codigo"));
     $centrocosto->setCentrocostoHabilitado(1);
     if (!$centrocosto->save()) {
         foreach ($centrocosto->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "centrocosto", "action" => "edit", "params" => array($centrocosto->centroCosto_id)));
     }
     $this->flash->success("Centro Costo ha sido actualizado correctamente");
     return $this->dispatcher->forward(array("controller" => "centrocosto", "action" => "index"));
 }