<?php
/*
GESTIN - Sistema de Gestion de Incidencias
Copyright (C) 2007 Mathias Rodriguez, Diego Martorell, Matias Bisay
This file is part of GESTIN.
GESTIN is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
GESTIN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GESTIN. If not, see <http://www.gnu.org/licenses/>.
*/
include_once($_SERVER['DOCUMENT_ROOT'] . '/gestin/config.inc.php');
include_once('iMovimientos.php');
class_exists('ConsultaVaciaException') || require_once(EXCEPTION_PATH . 'ConsultaVaciaException.class.php');
class_exists('ErrorConsultaException') || require_once(EXCEPTION_PATH . 'ErrorConsultaException.class.php');
class_exists('ErrorConocido') || require_once(ADT_PATH . 'ErrorConocido.class.php');
class_exists('Conexion') || require_once(DBMS_PATH . 'Conexion.class.php');
final class Movimientos implements iMovimientos {
public static function IngresarMovimiento($fecha,$ubicacion,$descripcion,Usuario $usuarioResponsable) {
$cx = new Conexion(DB_SERVER,DB_NAME,false);
$cx->conectar(DB_MIN_USER,DB_MIN_USER_PW);
$nuevoMovimiento = new Movimiento(0,$fecha, $ubicacion, $descripcion,$usuarioResponsable->getCi());
if(isset($nuevoMovimiento))
$cx->insertar('movimiento','movcod,movfec,movubi,movdes,movusures',$nuevoMovimiento,'');
}
public static function ConsultarMovimiento($id = 0,$fecha = '',$ubicacion = '',$descripcion = '', $usuarioResponsable = '') {
$cx = new Conexion(DB_SERVER,DB_NAME,false);
$cx->conectar(DB_MIN_USER,DB_MIN_USER_PW);
$cond = array((($id != '') ? "movcod=$id " : ''),
(($fecha != '') ? "movfec >= '%$fecha%' " : ''),
(($ubicacion != '') ? "movubi LIKE '%$ubicacion%'" : ''),
(($descripcion != '') ? "movdes LIKE '%$descripcion%'" : ''),
(($usuarioResponsable != '') ? "movusures LIKE '%$usuarioResponsable%'" : ''));
$condicion = '';
$flags = 0;
for($i = 0; $i < count($cond); $i++) {
if($cond[$i]!= '') {
if ($flags==1)
$condicion .= ' AND '.$cond[$i];
else {
$flags = 1;
$condicion .= $cond[$i];
}
}
}
try {
$rs = $cx->consultar('movimiento','*',"$condicion");
}
catch(ConsultaVaciaException $cvExc) {
throw $cvExc;
}
catch(ErrorConsultaException $ecExc) {
throw $ecExc;
}
if(isset($rs) && $rs != null)
return $rs;
}
public static function ModificarMovimiento($id,$nuevaFecha,$nuevaUbicacion,$nuevaDescripcion,$nuevoUsuarioResponsable) {
$cx = new Conexion(DB_SERVER,DB_NAME,false);
$cx->conectar(DB_MIN_USER,DB_MIN_USER_PW);
try {
$rs = $cx->consultar('movimiento','*',"movcod=$id");
}
catch(ConsultaVaciaException $cvExc) {
throw new ConsultaVaciaException('No existe el dato');
}
catch(ErrorConsultaException $ecExc) {
throw $ecExc;
}
if(isset($rs) && $rs != null) {
$movimientoModificado = new Movimiento($id,$nuevaFecha,$nuevaUbicacion,$nuevaDescripcion,$nuevoUsuarioResponsable);
$cx->actualizar('movimiento',
'movfec,movubi,movdes,movusures',
$movimientoModificado->toUpdateString(),"movcod=$id");
}
}
public static function EliminarMovimiento($id) {
$cx = new Conexion(DB_SERVER,DB_NAME,false);
$cx->conectar(DB_MIN_USER,DB_MIN_USER_PW);
try {
$rs = $cx->consultar('movimiento','*',"movcod=$id");
}
catch(ConsultaVaciaException $cvExc) {
throw new ConsultaVaciaException('No existe el dato');
}
catch(ErrorConsultaException $ecExc) {
throw $ecExc;
}
if(isset($rs) && $rs != null) {
$cx->eliminar('movimiento',"movcod=$id");
}
}
}
?>