402 lines
9.2 KiB
PHP
Executable File
402 lines
9.2 KiB
PHP
Executable File
<?php
|
|
|
|
class Cliente extends Main
|
|
{
|
|
private $clienteId;
|
|
private $nombre;
|
|
private $rfc;
|
|
private $telefono;
|
|
private $email;
|
|
private $userId;
|
|
private $rfcId;
|
|
private $password;
|
|
|
|
private $razonSocial;
|
|
private $calle;
|
|
private $noInt;
|
|
private $noExt;
|
|
private $referencia;
|
|
private $colonia;
|
|
private $localidad;
|
|
private $municipio;
|
|
private $ciudad;
|
|
private $estado;
|
|
private $pais;
|
|
private $codigoPostal;
|
|
|
|
public function setClienteId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->clienteId = $value;
|
|
}
|
|
|
|
public function setNombre($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Nombre");
|
|
$this->nombre = $value;
|
|
}
|
|
|
|
public function setRfc($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=17, $minChars = 1, "RFC");
|
|
$this->rfc = $value;
|
|
}
|
|
|
|
public function setEmail($value)
|
|
{
|
|
if(trim($value) != '')
|
|
$this->Util()->ValidateMail($value, 'Correo Electrónico');
|
|
$this->email = $value;
|
|
}
|
|
|
|
public function setPassword($value)
|
|
{
|
|
$this->password = $value;
|
|
}
|
|
|
|
public function setTelefono($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, "Telefono");
|
|
$this->telefono = $value;
|
|
}
|
|
|
|
public function setRazonSocial($value, $checkIfExists = 0)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=300, $minChars = 1, 'Razón Social');
|
|
$this->razonSocial = $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, 'No. Interior');
|
|
$this->noInt = $value;
|
|
}
|
|
|
|
public function setNoExt($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=255, $minChars = 0, 'No. Exterior');
|
|
$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, 'Código Postal');
|
|
$this->codigoPostal = $value;
|
|
}
|
|
|
|
public $page = 0;
|
|
|
|
public function SetPage($page)
|
|
{
|
|
$this->page = $page;
|
|
}
|
|
|
|
function Info()
|
|
{
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("SELECT * FROM cliente WHERE clienteId ='".$this->clienteId."'");
|
|
$cliente = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow();
|
|
|
|
return $cliente;
|
|
}
|
|
|
|
function Enumerate()
|
|
{
|
|
$db = $this->Util()->DBSelect($_SESSION["empresaId"]);
|
|
|
|
$sql = "SELECT COUNT(*) FROM cliente WHERE baja = '0'";
|
|
$db->setQuery($sql);
|
|
$total = $db->GetSingle();
|
|
|
|
$pages = $this->Util()->HandleMultipages($this->page, $total ,WEB_ROOT."/clientes", "p");
|
|
|
|
$sqlAdd = " LIMIT ".$pages["start"].", ".$pages["items_per_page"];
|
|
|
|
$sql = "SELECT * FROM cliente WHERE baja = '0' ORDER BY nombre ASC".$sqlAdd;
|
|
$db->setQuery($sql);
|
|
$clientes = $db->GetResult();
|
|
|
|
$data["items"] = $clientes;
|
|
$data["pages"] = $pages;
|
|
|
|
return $data;
|
|
}
|
|
|
|
function Save()
|
|
{
|
|
if($this->Util()->PrintErrors())
|
|
return false;
|
|
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("
|
|
INSERT INTO `cliente` (
|
|
`rfc`,
|
|
`nombre`,
|
|
`pais`,
|
|
`calle`,
|
|
`noInt`,
|
|
`noExt`,
|
|
`referencia`,
|
|
`colonia`,
|
|
`localidad`,
|
|
`municipio`,
|
|
`estado`,
|
|
`cp`,
|
|
`email`,
|
|
`telefono`,
|
|
`password`
|
|
)
|
|
VALUES (
|
|
'".$this->rfc."',
|
|
'".$this->razonSocial."',
|
|
'".$this->pais."',
|
|
'".$this->calle."',
|
|
'".$this->noInt."',
|
|
'".$this->noExt."',
|
|
'".$this->referencia."',
|
|
'".$this->colonia."',
|
|
'".$this->localidad."',
|
|
'".$this->municipio."',
|
|
'".$this->estado."',
|
|
'".$this->codigoPostal."',
|
|
'".$this->email."',
|
|
'".$this->telefono."',
|
|
'".$this->password."'
|
|
)"
|
|
);
|
|
|
|
$clienteId = $this->Util()->DBSelect($_SESSION["empresaId"])->InsertData();
|
|
$this->Util()->setError(20020, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return $clienteId;
|
|
}
|
|
|
|
function Delete()
|
|
{
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("DELETE FROM cliente WHERE clienteId = '".$this->clienteId."'");
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData();
|
|
|
|
$this->Util()->setError(20021, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
function Baja(){
|
|
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery("
|
|
UPDATE cliente SET
|
|
baja = '1'
|
|
WHERE
|
|
clienteId = '".$this->clienteId."'"
|
|
);
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->UpdateData();
|
|
|
|
$this->Util()->setError(20021, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return true;
|
|
|
|
}//Baja
|
|
|
|
function GetClteNameById()
|
|
{
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("SELECT nombre FROM cliente WHERE clienteId ='".$this->clienteId."'");
|
|
$nombre = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
return $nombre;
|
|
}
|
|
|
|
function Update()
|
|
{
|
|
if($this->Util()->PrintErrors()){ return false; }
|
|
|
|
if($this->password)
|
|
{
|
|
$addPassword = " `password` ='".$this->password."',";
|
|
}
|
|
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("
|
|
UPDATE `cliente` SET
|
|
`nombre` = '".$this->razonSocial."',
|
|
`pais` = '".$this->pais."',
|
|
`calle` = '".$this->calle."',
|
|
`noInt` = '".$this->noInt."',
|
|
`noExt` = '".$this->noExt."',
|
|
`referencia` = '".$this->referencia."',
|
|
`colonia` = '".$this->colonia."',
|
|
`localidad` = '".$this->localidad."',
|
|
`telefono` = '".$this->telefono."',
|
|
".$addPassword."
|
|
`municipio` = '".$this->municipio."',
|
|
`estado` = '".$this->estado."',
|
|
`cp` = '".$this->codigoPostal."',
|
|
`email` = '".$this->email."',
|
|
`rfc` = '".$this->rfc."'
|
|
WHERE clienteId = '".$this->clienteId."'"
|
|
);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->UpdateData();
|
|
|
|
$this->Util()->setError(20022, "complete");
|
|
$this->Util()->PrintErrors();
|
|
return true;
|
|
}
|
|
|
|
function Search()
|
|
{
|
|
$sql = "SELECT
|
|
*
|
|
FROM
|
|
cliente
|
|
WHERE
|
|
baja = '0'
|
|
AND
|
|
(
|
|
nombre LIKE '%".$this->nombre."%' || rfc LIKE '%".$this->nombre."%'
|
|
)
|
|
ORDER BY
|
|
nombre ASC
|
|
LIMIT
|
|
20";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$clientes = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
$data["items"] = $clientes;
|
|
$data["pages"] = array();
|
|
|
|
return $data;
|
|
}
|
|
|
|
function Suggest($value)
|
|
{
|
|
$sql = "SELECT
|
|
*
|
|
FROM
|
|
cliente
|
|
WHERE
|
|
baja = '0'
|
|
AND
|
|
(
|
|
nombre LIKE '%".$value."%'
|
|
OR rfc LIKE '%".$value."%'
|
|
)
|
|
ORDER BY
|
|
nombre
|
|
LIMIT 10";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
return $result;
|
|
}
|
|
|
|
function LoginFactura()
|
|
{
|
|
$generalDb = new DB;
|
|
|
|
$sql = "SELECT
|
|
*
|
|
FROM
|
|
cliente
|
|
WHERE
|
|
rfc = '".$this->rfc."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$info = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow();
|
|
|
|
$_SESSION['loginKey'] = $info['clienteId'];
|
|
$_SESSION['tipoUsr'] = 'Cliente';
|
|
$_SESSION['rfcClte'] = $this->rfc;
|
|
|
|
$sql = "SELECT * FROM empresa
|
|
WHERE empresaId = '".$_SESSION["empresaId"]."'";
|
|
$generalDb->setQuery($sql);
|
|
$infE = $generalDb->GetRow();
|
|
|
|
$_SESSION["version"] = $infE["version"];
|
|
|
|
return true;
|
|
}
|
|
|
|
function ExistRfc()
|
|
{
|
|
$sql = "SELECT clienteId FROM cliente
|
|
WHERE rfc = '".$this->rfc."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$clienteId = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
return $clienteId;
|
|
}
|
|
|
|
function EnumFacturasByClte()
|
|
{
|
|
$db = $this->Util()->DBSelect($_SESSION["empresaId"]);
|
|
|
|
$sql = "SELECT COUNT(*) FROM comprobante WHERE userId = '".$this->clienteId."'";
|
|
$db->setQuery($sql);
|
|
$total = $db->GetSingle();
|
|
|
|
$pages = $this->Util()->HandleMultipages($this->page, $total ,WEB_ROOT."/clientes", "p");
|
|
|
|
$sqlAdd = " LIMIT ".$pages["start"].", ".$pages["items_per_page"];
|
|
|
|
$sql = "SELECT * FROM comprobante WHERE userId = '".$this->clienteId."' ORDER BY fecha DESC".$sqlAdd;
|
|
$db->setQuery($sql);
|
|
$clientes = $db->GetResult();
|
|
|
|
$data["items"] = $clientes;
|
|
$data["pages"] = $pages;
|
|
|
|
return $data;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
?>
|