734 lines
15 KiB
PHP
Executable File
734 lines
15 KiB
PHP
Executable File
<?php
|
|
|
|
class Usuario extends Main
|
|
{
|
|
private $usuarioId;
|
|
private $empresaId;
|
|
private $nombre;
|
|
private $apellidos;
|
|
private $calle;
|
|
private $noInt;
|
|
private $noExt;
|
|
private $referencia;
|
|
private $colonia;
|
|
private $localidad;
|
|
private $municipio;
|
|
private $ciudad;
|
|
private $estado;
|
|
private $codigoPostal;
|
|
private $pais;
|
|
private $telefono;
|
|
private $celular;
|
|
private $noImss;
|
|
private $curp;
|
|
private $rfc;
|
|
private $email;
|
|
private $passwd;
|
|
private $tipo;
|
|
private $sucursalId;
|
|
|
|
private $identificacion;
|
|
private $comprobante;
|
|
|
|
public function setUsuarioId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->usuarioId = $value;
|
|
}
|
|
|
|
public function setEmpresaId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->empresaId = $value;
|
|
}
|
|
|
|
public function setNombre($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=300, $minChars = 1, 'Nombre');
|
|
$this->nombre = $value;
|
|
}
|
|
|
|
public function setApellidos($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=300, $minChars = 0, 'Apellidos');
|
|
$this->apellidos = $value;
|
|
}
|
|
|
|
public function setCalle($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=200, $minChars = 0, "Dirección");
|
|
$this->calle = $value;
|
|
}
|
|
|
|
public function setNoInt($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=255, $minChars = 0, "noInt");
|
|
$this->noInt = $value;
|
|
}
|
|
|
|
public function setNoExt($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=255, $minChars = 0, "noExt");
|
|
$this->noExt = $value;
|
|
}
|
|
|
|
public function setLocalidad($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Localidad");
|
|
$this->localidad = $value;
|
|
}
|
|
|
|
public function setColonia($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Colonia");
|
|
$this->colonia = $value;
|
|
}
|
|
|
|
public function setReferencia($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Referencia");
|
|
$this->referencia = $value;
|
|
}
|
|
|
|
public function setMunicipio($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Municipio");
|
|
$this->municipio = $value;
|
|
}
|
|
|
|
public function setCiudad($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Ciudad");
|
|
$this->ciudad = $value;
|
|
}
|
|
|
|
public function setEstado($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Estado");
|
|
$this->estado = $value;
|
|
}
|
|
|
|
public function setPais($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Pais");
|
|
$this->pais = $value;
|
|
}
|
|
|
|
public function setCodigoPostal($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Codigo Postal");
|
|
$this->codigoPostal = $value;
|
|
}
|
|
|
|
public function setTelefono($value)
|
|
{
|
|
$this->telefono = $value;
|
|
}
|
|
|
|
public function setCelular($value)
|
|
{
|
|
$this->celular = $value;
|
|
}
|
|
|
|
public function setNoImss($value)
|
|
{
|
|
$this->noImss = $value;
|
|
}
|
|
|
|
public function setCurp($value)
|
|
{
|
|
$this->curp = $value;
|
|
}
|
|
|
|
public function setRfc($value)
|
|
{
|
|
$this->rfc = $value;
|
|
}
|
|
|
|
public function setPassword($value)
|
|
{
|
|
$this->passwd = $value;
|
|
}
|
|
|
|
public function setTipo($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=300, $minChars = 1, 'Tipo');
|
|
$this->tipo = $value;
|
|
}
|
|
|
|
public function setSucursalId($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=300, $minChars = 0, 'Sucursal');
|
|
$this->sucursalId = $value;
|
|
}
|
|
|
|
public function setEmail($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=300, $minChars = 0, 'Email');
|
|
if($value)
|
|
$this->Util()->ValidateMail($value);
|
|
$this->email = urldecode($value);
|
|
}
|
|
|
|
public function setIdentificacion($value)
|
|
{
|
|
$this->identificacion = $value;
|
|
}
|
|
|
|
public function setComprobante($value)
|
|
{
|
|
$this->comprobante = $value;
|
|
}
|
|
|
|
public function Info()
|
|
{
|
|
$db = new DB(true);
|
|
$db->setQuery("SELECT * FROM usuario WHERE usuarioId ='".$this->usuarioId."'");
|
|
$usuario = $db->GetRow();
|
|
|
|
return $usuario;
|
|
}
|
|
|
|
public function GetUsuariosByEmpresa()
|
|
{
|
|
$sql = "SELECT * FROM usuario
|
|
WHERE empresaId ='".$this->empresaId."'
|
|
AND main = 'no'
|
|
AND baja = '0'";
|
|
$db = new DB(true);
|
|
$db->setQuery($sql);
|
|
$usuarios = $db->GetResult();
|
|
|
|
return $usuarios;
|
|
}
|
|
|
|
public function GetUsuariosBySuc()
|
|
{
|
|
$sql = "SELECT * FROM usuario
|
|
WHERE empresaId ='".$this->empresaId."'
|
|
AND main = 'no'
|
|
AND baja = '0'
|
|
AND sucursalId = '".$this->sucursalId."'";
|
|
$db = new DB(true);
|
|
$db->setQuery($sql);
|
|
$usuarios = $db->GetResult();
|
|
|
|
return $usuarios;
|
|
}
|
|
|
|
public function SaveTemp()
|
|
{
|
|
if($this->Util()->PrintErrors()){
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function Save()
|
|
{
|
|
if($this->Util()->PrintErrors()){
|
|
return false;
|
|
}
|
|
|
|
$db = new DB(true);
|
|
$db->setQuery("
|
|
INSERT INTO usuario (
|
|
empresaId,
|
|
nombre,
|
|
apellidos,
|
|
calle,
|
|
noInt,
|
|
noExt,
|
|
referencia,
|
|
colonia,
|
|
localidad,
|
|
municipio,
|
|
estado,
|
|
pais,
|
|
codigoPostal,
|
|
telefono,
|
|
celular,
|
|
noImss,
|
|
curp,
|
|
rfc,
|
|
email,
|
|
password,
|
|
`type`,
|
|
sucursalId
|
|
)
|
|
VALUES (
|
|
'".$_SESSION["empresaId"]."',
|
|
'".$this->nombre."',
|
|
'".$this->apellidos."',
|
|
'".$this->calle."',
|
|
'".$this->noInt."',
|
|
'".$this->noExt."',
|
|
'".$this->referencia."',
|
|
'".$this->colonia."',
|
|
'".$this->localidad."',
|
|
'".$this->municipio."',
|
|
'".$this->estado."',
|
|
'".$this->pais."',
|
|
'".$this->codigoPostal."',
|
|
'".$this->telefono."',
|
|
'".$this->celular."',
|
|
'".$this->noImss."',
|
|
'".$this->curp."',
|
|
'".$this->rfc."',
|
|
'".$this->email."',
|
|
'".$this->passwd."',
|
|
'".$this->tipo."',
|
|
'".$this->sucursalId."')"
|
|
);
|
|
$usuarioId = $db->InsertData();
|
|
|
|
$this->Util()->setError(20017, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return $usuarioId;
|
|
}
|
|
|
|
public function Update()
|
|
{
|
|
if($this->Util()->PrintErrors()){
|
|
return false;
|
|
}
|
|
|
|
$db = new DB(true);
|
|
$db->setQuery("
|
|
UPDATE usuario SET
|
|
nombre = '".$this->nombre."',
|
|
apellidos = '".$this->apellidos."',
|
|
calle = '".$this->calle."',
|
|
noInt = '".$this->noInt."',
|
|
noExt = '".$this->noExt."',
|
|
referencia = '".$this->referencia."',
|
|
colonia = '".$this->colonia."',
|
|
localidad = '".$this->localidad."',
|
|
municipio = '".$this->municipio."',
|
|
estado = '".$this->estado."',
|
|
pais = '".$this->pais."',
|
|
codigoPostal = '".$this->codigoPostal."',
|
|
telefono = '".$this->telefono."',
|
|
celular = '".$this->celular."',
|
|
noImss = '".$this->noImss."',
|
|
curp = '".$this->curp."',
|
|
rfc = '".$this->rfc."',
|
|
email = '".$this->email."',
|
|
password = '".$this->passwd."',
|
|
`type` = '".$this->tipo."',
|
|
sucursalId = '".$this->sucursalId."'
|
|
WHERE usuarioId = '".$this->usuarioId."'"
|
|
);
|
|
$db->UpdateData();
|
|
|
|
$this->Util()->setError(20019, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return true;
|
|
}
|
|
|
|
public function Delete()
|
|
{
|
|
if($this->Util()->PrintErrors()){
|
|
return false;
|
|
}
|
|
|
|
$db = new DB(true);
|
|
$db->setQuery("DELETE FROM usuario WHERE usuarioId = '".$this->usuarioId."' ");
|
|
$db->DeleteData();
|
|
|
|
$this->Util()->setError(20018, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return true;
|
|
}
|
|
|
|
function Baja(){
|
|
|
|
$db = new DB(true);
|
|
$db->setQuery("
|
|
UPDATE usuario SET
|
|
baja = '1'
|
|
WHERE
|
|
usuarioId = '".$this->usuarioId."'"
|
|
);
|
|
$db->UpdateData();
|
|
|
|
$this->Util()->setError(20110, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return true;
|
|
|
|
}//Baja
|
|
|
|
function SaveSucursal(){
|
|
|
|
$sql = 'INSERT INTO usuarioSuc (usuarioId, sucursalId)
|
|
VALUES ("'.$this->usuarioId.'", "'.$this->sucursalId.'")';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->InsertData();
|
|
|
|
return true;
|
|
}
|
|
|
|
function UpdateIdentificacion(){
|
|
|
|
$db = new DB(true);
|
|
$db->setQuery("
|
|
UPDATE usuario SET
|
|
identificacion = '".$this->identificacion."'
|
|
WHERE
|
|
usuarioId = '".$this->usuarioId."'"
|
|
);
|
|
$db->UpdateData();
|
|
|
|
return true;
|
|
|
|
}//UpdateIdentificacion
|
|
|
|
function UpdateComprobante(){
|
|
|
|
$db = new DB(true);
|
|
$db->setQuery("
|
|
UPDATE usuario SET
|
|
comprobante = '".$this->comprobante."'
|
|
WHERE
|
|
usuarioId = '".$this->usuarioId."'"
|
|
);
|
|
$db->UpdateData();
|
|
|
|
return true;
|
|
|
|
}//UpdateComprobante
|
|
|
|
function GetNameById()
|
|
{
|
|
$sql = 'SELECT nombre FROM usuario
|
|
WHERE usuarioId = "'.$this->usuarioId.'"';
|
|
|
|
$db = new DB(true);
|
|
$db->setQuery($sql);
|
|
$nombre = $db->GetSingle();
|
|
|
|
return $nombre;
|
|
}
|
|
|
|
function GetFullNameById()
|
|
{
|
|
$sql = 'SELECT CONCAT(nombre," ",apellidos) AS name FROM usuario
|
|
WHERE usuarioId = "'.$this->usuarioId.'"';
|
|
|
|
$db = new DB(true);
|
|
$db->setQuery($sql);
|
|
$nombre = $db->GetSingle();
|
|
|
|
return $nombre;
|
|
}
|
|
|
|
function GetInfoBySuc()
|
|
{
|
|
$sql = 'SELECT * FROM usuario
|
|
WHERE sucursalId = "'.$this->sucursalId.'"
|
|
AND `type` = "'.$this->tipo.'"
|
|
LIMIT 1';
|
|
$db = new DB(true);
|
|
$db->setQuery($sql);
|
|
$info = $db->GetRow();
|
|
|
|
return $info;
|
|
}
|
|
|
|
function GetTypeById()
|
|
{
|
|
$sql = 'SELECT type FROM usuario
|
|
WHERE usuarioId = "'.$this->usuarioId.'"';
|
|
$db = new DB(true);
|
|
$db->setQuery($sql);
|
|
$tipo = $db->GetSingle();
|
|
|
|
return $tipo;
|
|
}
|
|
|
|
function GetUserByType()
|
|
{
|
|
$sql = 'SELECT usuarioId FROM usuario
|
|
WHERE type = "'.$this->tipo.'"
|
|
LIMIT 1';
|
|
$db = new DB(true);
|
|
$db->setQuery($sql);
|
|
$usuarioId = $db->GetSingle();
|
|
|
|
return $usuarioId;
|
|
}
|
|
|
|
function GetUserBySucAndType()
|
|
{
|
|
$sql = 'SELECT usuarioId FROM usuario
|
|
WHERE type = "'.$this->tipo.'"
|
|
AND sucursalId = "'.$this->sucursalId.'"
|
|
LIMIT 1';
|
|
$db = new DB(true);
|
|
$db->setQuery($sql);
|
|
$usuarioId = $db->GetSingle();
|
|
|
|
return $usuarioId;
|
|
}
|
|
|
|
function GetUsersBySucAndType($usuarioId = 0)
|
|
{
|
|
if($usuarioId)
|
|
$sqlFilter = ' AND usuarioId = '.$usuarioId;
|
|
|
|
$sql = 'SELECT * FROM usuario
|
|
WHERE baja = "0"
|
|
AND type = "'.$this->tipo.'"
|
|
AND sucursalId = "'.$this->sucursalId.'"
|
|
'.$sqlFilter;
|
|
$db = new DB(true);
|
|
$db->setQuery($sql);
|
|
$usuarios = $db->GetResult();
|
|
|
|
return $usuarios;
|
|
}
|
|
|
|
function IsEmailTaked(){
|
|
|
|
if($this->usuarioId)
|
|
$sqlAdd = ' AND usuarioId <> "'.$this->usuarioId.'"';
|
|
|
|
$sql = 'SELECT usuarioId FROM usuario
|
|
WHERE email = "'.$this->email.'"
|
|
'.$sqlAdd.'
|
|
LIMIT 1';
|
|
$db = new DB(true);
|
|
$db->setQuery($sql);
|
|
$allow = $db->GetSingle();
|
|
|
|
return $allow;
|
|
|
|
}
|
|
|
|
function IsSucChecked(){
|
|
|
|
$sql = 'SELECT COUNT(*) FROM usuarioSuc
|
|
WHERE sucursalId = "'.$this->sucursalId.'"
|
|
AND usuarioId = "'.$this->usuarioId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$checked = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $checked;
|
|
}
|
|
|
|
function DelSupSuc(){
|
|
|
|
$sql = 'DELETE FROM usuarioSuc
|
|
WHERE usuarioId = "'.$this->usuarioId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->DeleteData();
|
|
|
|
return true;
|
|
}
|
|
|
|
public function Search()
|
|
{
|
|
$sqlFilter = '';
|
|
if($this->tipo)
|
|
$sqlFilter .= ' AND type = "'.$this->tipo.'"';
|
|
if($this->sucursalId)
|
|
$sqlFilter .= ' AND sucursalId = "'.$this->sucursalId.'"';
|
|
if($this->nombre)
|
|
$sqlFilter .= ' AND nombre LIKE "%'.$this->nombre.'%"';
|
|
|
|
$sql = "SELECT * FROM usuario
|
|
WHERE empresaId ='".$this->empresaId."'
|
|
AND main = 'no'
|
|
AND baja = '0'".$sqlFilter;
|
|
$db = new DB(true);
|
|
$db->setQuery($sql);
|
|
$usuarios = $db->GetResult();
|
|
|
|
return $usuarios;
|
|
}
|
|
|
|
function AllowPage($page, $usuarioId){
|
|
|
|
$this->setUsuarioId($usuarioId);
|
|
$tipo = $this->GetTypeById();
|
|
|
|
$pages = array();
|
|
|
|
switch($tipo){
|
|
|
|
case 'admin':
|
|
$pages = array(
|
|
'bonificaciones',
|
|
'bonificaciones-agregar',
|
|
'cuentas-pagar',
|
|
'cuentas-pagar-saldos',
|
|
'envios',
|
|
'envios-recibir-reporte',
|
|
'pedidos',
|
|
'pedidos-detalles',
|
|
'devoluciones-pendientes',
|
|
'inventario-actualizar',
|
|
'inventario-fisico',
|
|
'inventario-fisico-agregar',
|
|
'inventario-fisico-detalles',
|
|
'inventario-ajustar-list',
|
|
'ventas',
|
|
'inventario-bloqueados',
|
|
'ventas-ticket'
|
|
);
|
|
break;
|
|
|
|
case 'almacen':
|
|
$pages = array(
|
|
'bonificaciones',
|
|
'bonificaciones-agregar',
|
|
'envios',
|
|
'evaluar-pedidos',
|
|
'pedidos',
|
|
'pedidos-detalles',
|
|
'pedidos-agregar',
|
|
'pedidos-editar',
|
|
'pedidos-distribucion',
|
|
'envios-tienda-cedis',
|
|
'envios-reporte',
|
|
'envios-recibir-reporte',
|
|
'cuentas-pagar',
|
|
'inventario'
|
|
);
|
|
break;
|
|
|
|
case 'cajero':
|
|
$pages = array(
|
|
'descuentos',
|
|
'descuentos-nuevo',
|
|
'devoluciones',
|
|
'devoluciones-nueva',
|
|
'devoluciones-ticket',
|
|
'inventario',
|
|
'inventario-bloqueados',
|
|
'inventario-detalles',
|
|
'inventario-bloqueados-detalles',
|
|
'ventas',
|
|
'ventas-ticket',
|
|
'ventas-nueva',
|
|
'ventas-espera',
|
|
'ventas-cobrar'
|
|
);
|
|
break;
|
|
|
|
case 'compras':
|
|
$pages = array(
|
|
'envios',
|
|
'pedidos',
|
|
'pedidos-detalles',
|
|
'pedidos-agregar',
|
|
'pedidos-editar',
|
|
'inventario-solicitar',
|
|
'inventario-solicitar-detalles'
|
|
);
|
|
break;
|
|
|
|
case 'direccion':
|
|
$pages = array(
|
|
'envios',
|
|
'pedidos',
|
|
'pedidos-detalles',
|
|
'cuentas-pagar-saldos',
|
|
'cuentas-pagar',
|
|
'bonificaciones',
|
|
'bonificaciones-agregar'
|
|
);
|
|
break;
|
|
|
|
case 'distribucion':
|
|
$pages = array(
|
|
'pedidos',
|
|
'pedidos-detalles'
|
|
);
|
|
break;
|
|
|
|
case 'facturacion':
|
|
$pages = array(
|
|
'facturacion',
|
|
'facturacion-nueva',
|
|
'ventas',
|
|
'ventas-ticket',
|
|
'reportes-ventas'
|
|
);
|
|
break;
|
|
|
|
case 'gerente':
|
|
$pages = array(
|
|
'descuentos',
|
|
'descuentos-nuevo',
|
|
'devoluciones',
|
|
'devoluciones-nueva',
|
|
'devoluciones-ticket',
|
|
'envios',
|
|
'envios-recibir-reporte',
|
|
'inventario',
|
|
'inventario-bloqueados',
|
|
'inventario-detalles',
|
|
'inventario-bloqueados-detalles',
|
|
'inventario-solicitar',
|
|
'inventario-solicitar-agregar',
|
|
'inventario-solicitar-detalles',
|
|
'ventas',
|
|
'ventas-ticket',
|
|
'ventas-nueva',
|
|
'ventas-espera',
|
|
'ventas-cobrar',
|
|
'facturacion-nueva'
|
|
);
|
|
break;
|
|
|
|
case 'vendedor':
|
|
$pages = array(
|
|
'inventario',
|
|
'inventario-bloqueados',
|
|
'inventario-detalles',
|
|
'inventario-bloqueados-detalles'
|
|
);
|
|
break;
|
|
|
|
case 'centralizador':
|
|
$pages = array(
|
|
'ventas',
|
|
'ventas-ticket',
|
|
'inventario',
|
|
'pedidos',
|
|
'pedidos-detalles',
|
|
'envios',
|
|
'devoluciones',
|
|
'devoluciones-ticket'
|
|
);
|
|
break;
|
|
|
|
case 'supervisor':
|
|
|
|
$pages = array(
|
|
'inventario-fisico',
|
|
'inventario-fisico-agregar',
|
|
'inventario-fisico-detalles'
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(in_array($page, $pages))
|
|
return true;
|
|
else
|
|
return false;
|
|
|
|
}//AllowPage
|
|
|
|
}
|
|
|
|
|
|
?>
|