예제 #1
0
 public function save()
 {
     $post = $this->_post(NULL, TRUE);
     try {
         if (is_array($post)) {
             $producto = NomProductoTable::getInstance()->find($post['producto_id']);
             if (!$producto) {
                 //Si el producto no existe devuelvo un error
                 $msg = "producto no encontrada.";
                 return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
             }
             if ($post['id']) {
                 $obj = $this->_getTable()->find($post['id']);
                 if (!$obj) {
                     $msg = "{$this->_model} no encontrado.";
                     return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
                 }
             } else {
                 $obj = new $this->_model();
             }
             /* @var $obj Disponibilidad */
             $obj->set('Producto', $producto);
             $obj->fromArray($post, false);
             $obj->save();
             $this->_jsonResponse($obj->toArray());
         }
     } catch (Exception $exc) {
         log_message('error', $exc->getMessage());
         log_message('error', $exc->getTraceAsString());
         $this->_jsonResponse(array("msg" => "Ha ocurrido un error mientras se intentaba guardar."), 500);
     }
 }
예제 #2
0
 public function save()
 {
     $post = $this->_post(NULL, TRUE);
     try {
         if (is_array($post)) {
             $producto = NomProductoTable::getInstance()->find($post['producto_id']);
             if (!$producto) {
                 //Si el producto no existe devuelvo un error
                 $msg = "Producto no encontrado.";
                 return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
             }
             $entidad = NomEntidadTable::getInstance()->find($post['entidad_id']);
             if (!$entidad) {
                 //Si la entidad no existe devuelvo un error
                 $msg = "Entidad no encontrada.";
                 return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
             }
             if ($post['id']) {
                 $inventario = $this->_getTable()->find($post['id']);
                 if (!$inventario) {
                     //Si el inventario no existe devuelvo un error
                     $msg = "ConsumoInter no encontrado.";
                     return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
                 }
             } else {
                 $inventario = new ConsumoInter();
             }
             $inventario->fromArray($post, false);
             $inventario->set('Producto', $producto);
             $inventario->set('Entidad', $entidad);
             $inventario->save();
             //Creating security log
             $this->load->library('appunto-auth/appunto_auth');
             $this->appunto_auth->create_security_log(1, "Asignando/Actualizando tabla " . $this->_model . "[id:" . $inventario->id . "]");
             //End security log
             $this->_jsonResponse($inventario->toArray());
         }
     } catch (Exception $exc) {
         log_message('error', $exc->getMessage());
         log_message('error', $exc->getTraceAsString());
         //Creating security log
         $this->load->library('appunto-auth/appunto_auth');
         $this->appunto_auth->create_security_log(0, "Error creando/actualizando tabla " . $this->_model);
         //End security log
         $this->_jsonResponse(array("msg" => "Ha ocurrido un error mientras se intentaba guardar un producto."), 500);
     }
 }
예제 #3
0
 public function save()
 {
     $post = $this->_post(NULL, TRUE);
     try {
         if (is_array($post)) {
             $producto = NomProductoTable::getInstance()->find($post['producto_id']);
             if (!$producto) {
                 $msg = "Producto no encontrado.";
                 return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
             }
             $boleta = BoletaTable::getInstance()->find($post['boleta_id']);
             if (!$boleta) {
                 $msg = "Boleta no encontrada.";
                 return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
             }
             if ($post['id']) {
                 $boleta_producto = $this->_getTable()->find($post['id']);
                 if (!$boleta_producto) {
                     $msg = "BoletaProducto no encontrado.";
                     return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
                 }
             } else {
                 $boleta_producto = new BoletaProducto();
             }
             $boleta_producto->fromArray($post, false);
             $boleta_producto->set('Producto', $producto);
             $boleta_producto->set('Boleta', $boleta);
             $boleta_producto->save();
             //Creating security log
             $this->load->library('appunto-auth/appunto_auth');
             $this->appunto_auth->create_security_log(1, "Asignando/Actualizando tabla " . $this->_model . "[id:" . $boleta_producto->id . "]");
             //End security log
             $this->_jsonResponse($boleta_producto->toArray());
         }
     } catch (Exception $exc) {
         log_message('error', $exc->getMessage());
         log_message('error', $exc->getTraceAsString());
         //Creating security log
         $this->load->library('appunto-auth/appunto_auth');
         $this->appunto_auth->create_security_log(0, "Error creando/actualizando tabla " . $this->_model);
         //End security log
         $this->_jsonResponse(array("msg" => "Ha ocurrido un error mientras se intentaba guardar una boleta."), 500);
     }
 }
예제 #4
0
 public function save()
 {
     $post = $this->_post(NULL, TRUE);
     try {
         if (is_array($post)) {
             $producto = NomProductoTable::getInstance()->find($post['producto_id']);
             if (!$producto) {
                 //Si el producto no existe devuelvo un error
                 $msg = "Producto no encontrado.";
                 return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
             }
             $fuente = NomMercadoTable::getInstance()->find($post['mercado_id']);
             if (!$fuente) {
                 //Si la fuente no existe devuelvo un error
                 $msg = "Mercado no encontrado.";
                 return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
             }
             if ($post['id']) {
                 $productomercado = $this->_getTable()->find($post['id']);
                 if (!$productomercado) {
                     //Si el producto no existe devuelvo un error
                     $msg = "Producto no encontrado.";
                     return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
                 }
             } else {
                 $productomercado = new ProductoMercado();
             }
             $productomercado->fromArray($post, false);
             $productomercado->set('Producto', $producto);
             $productomercado->set('Mercado', $fuente);
             $productomercado->save();
             $this->_jsonResponse($productomercado->toArray());
         }
     } catch (Exception $exc) {
         log_message('error', $exc->getMessage());
         log_message('error', $exc->getTraceAsString());
         $this->_jsonResponse(array("msg" => "Ha ocurrido un error mientras se intentaba guardar un producto."), 500);
     }
 }
예제 #5
0
 public function save()
 {
     $post = $this->_post(NULL, TRUE);
     try {
         if (is_array($post)) {
             $producto = NomProductoTable::getInstance()->find($post['producto_id']);
             if (!$producto) {
                 //Si el producto no existe devuelvo un error
                 $msg = "Producto no encontrado.";
                 return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
             }
             $entidad = NomEntidadTable::getInstance()->find($post['entidad_id']);
             if (!$entidad) {
                 //Si la entidad no existe devuelvo un error
                 $msg = "Entidad no encontrada.";
                 return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
             }
             if ($post['id']) {
                 $orgnomin = $this->_getTable()->find($post['id']);
                 if (!$orgnomin) {
                     //Si el producto no existe devuelvo un error
                     $msg = "Organismo Nominalizado no encontrado.";
                     return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
                 }
             } else {
                 $orgnomin = new OrgNominalizado();
             }
             $orgnomin->fromArray($post, false);
             $orgnomin->set('Producto', $producto);
             $orgnomin->set('Entidad', $entidad);
             $orgnomin->save();
             $this->_jsonResponse($orgnomin->toArray());
         }
     } catch (Exception $exc) {
         log_message('error', $exc->getMessage());
         log_message('error', $exc->getTraceAsString());
         $this->_jsonResponse(array("msg" => "Ha ocurrido un error mientras se intentaba guardar un producto."), 500);
     }
 }
예제 #6
0
 public function save()
 {
     $post = $this->_post(NULL, TRUE);
     try {
         if (is_array($post)) {
             $producto = NomProductoTable::getInstance()->find($post['producto_id']);
             if (!$producto) {
                 $msg = "Producto no encontrado.";
                 return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
             }
             $nivelAct = BalanceAlimTable::getInstance()->find($post['balance_alim_id']);
             if (!$nivelAct) {
                 $msg = "Balance no encontrado.";
                 return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
             }
             if ($post['id']) {
                 $databaseModel = $this->_getTable()->find($post['id']);
                 if (!$databaseModel) {
                     $msg = "BD no encontrado.";
                     return $this->_jsonResponse(array("msg" => $msg), 404, $msg);
                 }
             } else {
                 $databaseModel = new BaseDatos();
             }
             $databaseModel->fromArray($post, false);
             $databaseModel->set('Producto', $producto);
             $databaseModel->set('BalanceAlim', $nivelAct);
             $databaseModel->save();
             $this->_jsonResponse($databaseModel->toArray());
         }
     } catch (Exception $exc) {
         log_message('error', $exc->getMessage());
         log_message('error', $exc->getTraceAsString());
         $this->_jsonResponse(array("msg" => "Ha ocurrido un error mientras se intentaba guardar BD"), 500);
     }
 }