Removed COLLATE specification from Search() LIKE clauses to fix 'COLLATION latin1_swedish_ci is not valid for CHARACTER SET utf8mb4' error. Let MySQL use the table's default collation for LIKE comparisons.
2200 lines
58 KiB
PHP
Executable File
2200 lines
58 KiB
PHP
Executable File
<?php
|
|
|
|
class Producto extends Main
|
|
{
|
|
private $productoId;
|
|
private $proveedorId;
|
|
private $prodCatId;
|
|
private $prodSubcatId;
|
|
private $modelo;
|
|
private $conTallaId;
|
|
private $descripcion;
|
|
private $temporadaId;
|
|
private $colorId;
|
|
private $tallaId;
|
|
private $costo;
|
|
private $precioVenta;
|
|
private $precioVentaIva;
|
|
private $utilidad;
|
|
private $imagen;
|
|
private $tmpImg;
|
|
|
|
private $materialId;
|
|
private $porcentaje;
|
|
|
|
private $prodItemId;
|
|
private $codigoBarra;
|
|
|
|
private $atributoId;
|
|
private $atribValId;
|
|
|
|
private $cantidad;
|
|
private $noIdentificacion;
|
|
private $unidad;
|
|
private $valorUnitario;
|
|
private $excentoIva;
|
|
private $importe;
|
|
|
|
private $sucursalId;
|
|
private $noProveedor;
|
|
private $fechaIni;
|
|
private $fechaFin;
|
|
|
|
public function setProductoId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->productoId = $value;
|
|
}
|
|
|
|
public function setProveedorId($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Proveedor');
|
|
$this->proveedorId = $value;
|
|
}
|
|
|
|
public function setProdCatId($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Departamento');
|
|
$this->prodCatId = $value;
|
|
}
|
|
|
|
public function setProdSubcatId($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Línea');
|
|
$this->prodSubcatId = $value;
|
|
}
|
|
|
|
public function setConTallaId($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Conjunto de Tallas');
|
|
$this->conTallaId = $value;
|
|
}
|
|
|
|
public function setModelo($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Modelo');
|
|
$this->modelo = $value;
|
|
}
|
|
|
|
public function setCosto($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Costo sin IVA');
|
|
$this->costo = $value;
|
|
}
|
|
|
|
public function setPrecioVentaIva($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Precio de Venta con IVA');
|
|
$this->precioVentaIva = $value;
|
|
}
|
|
|
|
public function setPrecioVenta($value)
|
|
{
|
|
$this->precioVenta = $value;
|
|
}
|
|
|
|
public function setUtilidad($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Utilidad');
|
|
$this->utilidad = $value;
|
|
}
|
|
|
|
public function setTemporadaId($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Temporada');
|
|
$this->temporadaId = $value;
|
|
}
|
|
|
|
public function setColorId($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 0, 'Color');
|
|
$this->colorId = $value;
|
|
}
|
|
|
|
public function setColores($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Colores');
|
|
$this->colorId = $value;
|
|
}
|
|
|
|
public function setTallas($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Tallas');
|
|
$this->tallaId = $value;
|
|
}
|
|
|
|
public function setTallaId($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Talla');
|
|
$this->tallaId = $value;
|
|
}
|
|
|
|
public function setDescripcion($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=10000, $minChars = 1, 'Características Especiales');
|
|
$this->descripcion = $value;
|
|
}
|
|
|
|
public function setImagen($value)
|
|
{
|
|
$this->imagen = $value;
|
|
}
|
|
|
|
public function setMaterialId($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=255, $minChars = 1, 'Material');
|
|
$this->materialId = $value;
|
|
}
|
|
|
|
public function setPorcentaje($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=255, $minChars = 1, '% de Material');
|
|
if($value != ''){
|
|
if($value > 0 && $value <= 100){
|
|
$this->porcentaje = $value;
|
|
}else{
|
|
$this->Util()->setError(10020, "error", "", '% de Material');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function setProdItemId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->prodItemId = $value;
|
|
}
|
|
|
|
public function setCodigoBarra($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=255, $minChars = 1, 'Código de Barra');
|
|
$this->codigoBarra = $value;
|
|
}
|
|
|
|
public function setAtributoId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->atributoId = $value;
|
|
}
|
|
|
|
public function setAtribValId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->atribValId = $value;
|
|
}
|
|
|
|
public function setCantidad($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=10000, $minChars = 1, 'Cantidad');
|
|
$this->cantidad = $value;
|
|
}
|
|
|
|
public function setNoIdentificacion($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=10000, $minChars = 1, 'No. de Identificación');
|
|
$this->noIdentificacion = $value;
|
|
}
|
|
|
|
public function setUnidad($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=10, $minChars = 1, 'Unidad');
|
|
$this->unidad = $value;
|
|
}
|
|
|
|
public function setValorUnitario($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=10000, $minChars = 1, 'Valor Unitario');
|
|
$this->valorUnitario = $value;
|
|
}
|
|
|
|
public function setExcentoIva($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=10000, $minChars = 1, 'Excento Iva');
|
|
$this->excentoIva = $value;
|
|
}
|
|
|
|
public function setImporte($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=10000, $minChars = 1, 'Importe');
|
|
$this->importe = $value;
|
|
}
|
|
|
|
public function setSucursalId($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=3, $minChars = 1, 'Importe');
|
|
$this->sucursalId = $value;
|
|
}
|
|
|
|
public function setNoProveedor($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=4, $minChars = 0, '');
|
|
$this->noProveedor = $value;
|
|
}
|
|
|
|
public function setFechaIni($value)
|
|
{
|
|
$this->fechaIni = $value;
|
|
}
|
|
|
|
public function setFechaFin($value)
|
|
{
|
|
$this->fechaFin = $value;
|
|
}
|
|
|
|
public function setTmpImg($value)
|
|
{
|
|
$this->Util()->ValidateString($value, $max_chars=3, $minChars = 1, 'Imagen');
|
|
$this->tmpImg = $value;
|
|
}
|
|
|
|
public $page = 0;
|
|
|
|
public function SetPage($page)
|
|
{
|
|
$this->page = $page;
|
|
}
|
|
|
|
public function Info()
|
|
{
|
|
$sql = 'SELECT
|
|
*
|
|
FROM
|
|
producto
|
|
WHERE
|
|
productoId = "'.$this->productoId.'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$info = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow();
|
|
|
|
return $info;
|
|
}
|
|
|
|
function EnumerateAll()
|
|
{
|
|
$sql = "SELECT *
|
|
FROM producto
|
|
WHERE baja = '0'
|
|
ORDER BY descripcion";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$productos = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
return $productos;
|
|
|
|
}//EnumerateAll
|
|
|
|
function EnumerateAllByModelo()
|
|
{
|
|
$sql = "SELECT *
|
|
FROM producto
|
|
WHERE baja = '0'
|
|
ORDER BY modelo";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$productos = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
return $productos;
|
|
|
|
}//EnumerateAllByModelo
|
|
|
|
function Enumerate()
|
|
{
|
|
$db = $this->Util()->DBSelect($_SESSION["empresaId"]);
|
|
|
|
$sql = "SELECT COUNT(*) FROM producto WHERE baja = '0'";
|
|
$db->setQuery($sql);
|
|
$total = $db->GetSingle();
|
|
|
|
$pages = $this->Util()->HandleMultipages($this->page, $total ,WEB_ROOT."/productos", "p");
|
|
|
|
$sqlAdd = "LIMIT ".$pages["start"].", ".$pages["items_per_page"];
|
|
|
|
$sql = "SELECT *
|
|
FROM producto
|
|
WHERE baja = '0'
|
|
ORDER BY descripcion ".$sqlAdd;
|
|
$db->setQuery($sql);
|
|
$result = $db->GetResult();
|
|
|
|
$data["items"] = $result;
|
|
$data["pages"] = $pages;
|
|
|
|
return $data;
|
|
|
|
}//Enumerate
|
|
|
|
function EnumDuplicados()
|
|
{
|
|
$sql = "SELECT *
|
|
FROM producto
|
|
WHERE codigoBarra LIKE '%-%'
|
|
ORDER BY descripcion ".$sqlAdd;
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
$data["items"] = $result;
|
|
$data["pages"] = $pages;
|
|
|
|
return $data;
|
|
|
|
}//EnumDuplicados
|
|
|
|
function EnumByProveedor($idProd = 0)
|
|
{
|
|
if($idProd)
|
|
$sqlFilter = ' AND productoId = '.$idProd;
|
|
|
|
$sql = "SELECT *
|
|
FROM producto
|
|
WHERE baja = '0'
|
|
AND proveedorId = '".$this->proveedorId."'
|
|
".$sqlFilter."
|
|
ORDER BY descripcion ";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$productos = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
return $productos;
|
|
|
|
}//EnumByProveedor
|
|
|
|
function EnumByProveedorLimit()
|
|
{
|
|
$sql = "SELECT *
|
|
FROM producto
|
|
WHERE baja = '0'
|
|
AND proveedorId = '".$this->proveedorId."'
|
|
ORDER BY descripcion
|
|
LIMIT 2";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$productos = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
return $productos;
|
|
|
|
}//EnumByProveedor
|
|
|
|
function SaveTemp(){
|
|
|
|
if($this->Util()->PrintErrors()){
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function Save(){
|
|
|
|
if($this->Util()->PrintErrors()){
|
|
return false;
|
|
}
|
|
|
|
$sql = "INSERT INTO producto (
|
|
proveedorId,
|
|
prodCatId,
|
|
prodSubcatId,
|
|
conTallaId,
|
|
modelo,
|
|
codigoBarra,
|
|
costo,
|
|
precioVenta,
|
|
precioVentaIva,
|
|
utilidad,
|
|
temporadaId,
|
|
descripcion
|
|
)
|
|
VALUES (
|
|
'".$this->proveedorId."',
|
|
'".$this->prodCatId."',
|
|
'".$this->prodSubcatId."',
|
|
'".$this->conTallaId."',
|
|
'".$this->modelo."',
|
|
'".$this->codigoBarra."',
|
|
'".$this->costo."',
|
|
'".$this->precioVenta."',
|
|
'".$this->precioVentaIva."',
|
|
'".$this->utilidad."',
|
|
'".$this->temporadaId."',
|
|
'".$this->descripcion."'
|
|
)";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$productoId = $this->Util()->DBSelect($_SESSION['empresaId'])->InsertData();
|
|
|
|
$this->Util()->setError(20014, 'complete');
|
|
$this->Util()->PrintErrors();
|
|
|
|
return $productoId;
|
|
|
|
}//Save
|
|
|
|
function Update(){
|
|
|
|
if($this->Util()->PrintErrors()){
|
|
return false;
|
|
}
|
|
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery("
|
|
UPDATE producto SET
|
|
proveedorId = '".$this->proveedorId."',
|
|
prodCatId = '".$this->prodCatId."',
|
|
prodSubcatId = '".$this->prodSubcatId."',
|
|
conTallaId = '".$this->conTallaId."',
|
|
modelo = '".$this->modelo."',
|
|
codigoBarra = '".$this->codigoBarra."',
|
|
costo = '".$this->costo."',
|
|
precioVenta = '".$this->precioVenta."',
|
|
precioVentaIva = '".$this->precioVentaIva."',
|
|
utilidad = '".$this->utilidad."',
|
|
temporadaId = '".$this->temporadaId."',
|
|
descripcion = '".$this->descripcion."'
|
|
WHERE
|
|
productoId = '".$this->productoId."'"
|
|
);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->UpdateData();
|
|
|
|
$this->Util()->setError(20016, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return true;
|
|
|
|
}//Update
|
|
|
|
function UpdateProdItems(){
|
|
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery("
|
|
UPDATE productoItem SET
|
|
codigoBarra = '".$this->codigoBarra."'
|
|
WHERE
|
|
productoId = '".$this->productoId."'"
|
|
);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->UpdateData();
|
|
|
|
return true;
|
|
|
|
}//Update
|
|
|
|
function UpdatePriceInv(){
|
|
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery("
|
|
UPDATE inventario SET
|
|
precioVenta = '".$this->precioVentaIva."'
|
|
WHERE
|
|
(status = 'Disponible' || status = 'Apartado' || status = 'Bloqueado' || status = 'Ajuste' || status = 'Devuelto')
|
|
AND
|
|
productoId = '".$this->productoId."'"
|
|
);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->UpdateData();
|
|
|
|
return true;
|
|
|
|
}//UpdatePriceInv
|
|
|
|
function UpdateImagen(){
|
|
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery("
|
|
UPDATE producto SET
|
|
imagen = '".$this->imagen."'
|
|
WHERE
|
|
productoId = '".$this->productoId."'"
|
|
);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->UpdateData();
|
|
|
|
return true;
|
|
|
|
}//UpdateImagen
|
|
|
|
function Delete(){
|
|
|
|
$sql = "DELETE FROM
|
|
producto
|
|
WHERE
|
|
productoId = '".$this->productoId."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData();
|
|
|
|
$sql = "DELETE FROM
|
|
productoMaterial
|
|
WHERE
|
|
productoId = '".$this->productoId."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData();
|
|
|
|
$sql = "DELETE FROM
|
|
productoItem
|
|
WHERE
|
|
productoId = '".$this->productoId."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData();
|
|
|
|
$sql = "DELETE FROM
|
|
productoAtributo
|
|
WHERE
|
|
productoId = '".$this->productoId."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData();
|
|
|
|
$this->Util()->setError(20015, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return true;
|
|
|
|
}//Delete
|
|
|
|
function Baja(){
|
|
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery("
|
|
UPDATE producto SET
|
|
baja = '1'
|
|
WHERE
|
|
productoId = '".$this->productoId."'"
|
|
);
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->UpdateData();
|
|
|
|
$this->Util()->setError(20015, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return true;
|
|
|
|
}//Baja
|
|
|
|
function DeleteMateriales(){
|
|
|
|
$sql = "DELETE FROM
|
|
productoMaterial
|
|
WHERE
|
|
productoId = '".$this->productoId."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData();
|
|
|
|
return true;
|
|
|
|
}//DeleteMateriales
|
|
|
|
function DeleteAtributos(){
|
|
|
|
$sql = "DELETE FROM
|
|
productoAtributo
|
|
WHERE
|
|
productoId = '".$this->productoId."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData();
|
|
|
|
return true;
|
|
|
|
}//DeleteAtributos
|
|
|
|
function DeleteItemsByTalla(){
|
|
|
|
$sql = "DELETE FROM
|
|
productoItem
|
|
WHERE
|
|
productoId = '".$this->productoId."'
|
|
AND
|
|
tallaId = '".$this->tallaId."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData();
|
|
|
|
return true;
|
|
|
|
}//DeleteItemsByTalla
|
|
|
|
function DeleteItemsByColor(){
|
|
|
|
$sql = "DELETE FROM
|
|
productoItem
|
|
WHERE
|
|
productoId = '".$this->productoId."'
|
|
AND
|
|
colorId = '".$this->colorId."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData();
|
|
|
|
return true;
|
|
|
|
}//DeleteItemsByColor
|
|
|
|
function Search3(){
|
|
|
|
$sqlAdd = '';
|
|
/*
|
|
if($this->noProveedor)
|
|
$sqlAdd .= ' AND proveedorId = "'.$this->noProveedor.'"';
|
|
|
|
if($this->proveedorId)
|
|
$sqlAdd .= ' AND proveedorId = "'.$this->proveedorId.'"';
|
|
|
|
if($this->prodCatId)
|
|
$sqlAdd .= ' AND prodCatId = "'.$this->prodCatId.'"';
|
|
|
|
if($this->descripcion)
|
|
$sqlAdd .= ' AND modelo LIKE "%'.$this->descripcion.'%"';*/
|
|
|
|
if($this->codigoBarra)
|
|
$sqlAdd .= ' AND codigoBarra LIKE "%'.$this->codigoBarra.'%"';
|
|
|
|
if($sqlAdd != ''){
|
|
|
|
$sql = 'SELECT *
|
|
|
|
FROM
|
|
producto
|
|
WHERE
|
|
baja = "0"
|
|
'.$sqlAdd.'
|
|
ORDER BY
|
|
descripcion';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
}else{
|
|
$result = array();
|
|
$pages = array(
|
|
'numbers' => array(),
|
|
'first' => false,
|
|
'prev' => false,
|
|
'next' => false,
|
|
'last' => false,
|
|
'current' => 1,
|
|
'items_per_page' => defined('ITEMS_PER_PAGE') ? ITEMS_PER_PAGE : 20,
|
|
'start' => 0
|
|
);
|
|
}//else
|
|
|
|
$data["items"] = $result;
|
|
$data["pages"] = $pages;
|
|
|
|
return $data;
|
|
|
|
}//Search3
|
|
|
|
function Search(){
|
|
|
|
$sqlAdd = '';
|
|
|
|
$pages = array(
|
|
'numbers' => array(),
|
|
'first' => false,
|
|
'prev' => false,
|
|
'next' => false,
|
|
'last' => false,
|
|
'current' => 1,
|
|
'items_per_page' => defined('ITEMS_PER_PAGE') ? ITEMS_PER_PAGE : 20,
|
|
'start' => 0
|
|
);
|
|
|
|
if($this->noProveedor)
|
|
$sqlAdd .= ' AND prov.noProv = "'.$this->noProveedor.'"';
|
|
|
|
if($this->proveedorId)
|
|
$sqlAdd .= ' AND p.proveedorId = "'.$this->proveedorId.'"';
|
|
|
|
if($this->prodCatId)
|
|
$sqlAdd .= ' AND p.prodCatId = "'.$this->prodCatId.'"';
|
|
|
|
if($this->descripcion)
|
|
$sqlAdd .= ' AND p.modelo LIKE "%'.$this->descripcion.'%"';
|
|
|
|
if($this->codigoBarra)
|
|
$sqlAdd .= ' AND p.codigoBarra LIKE "%'.$this->codigoBarra.'%"';
|
|
|
|
if($sqlAdd != ''){
|
|
|
|
$sql = 'SELECT p.*
|
|
|
|
FROM
|
|
producto AS p,
|
|
proveedor AS prov
|
|
WHERE
|
|
p.proveedorId = prov.proveedorId
|
|
AND
|
|
p.baja = "0"
|
|
'.$sqlAdd.'
|
|
ORDER BY
|
|
descripcion';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
}else{
|
|
$result = array();
|
|
}
|
|
|
|
$data["items"] = $result;
|
|
$data["pages"] = $pages;
|
|
|
|
return $data;
|
|
|
|
}//Search
|
|
|
|
function Search2(){
|
|
|
|
$sqlAdd = '';
|
|
|
|
if($this->noProveedor)
|
|
$sqlAdd .= ' AND prov.noProv = "'.$this->noProveedor.'"';
|
|
|
|
if($this->proveedorId)
|
|
$sqlAdd .= ' AND p.proveedorId = "'.$this->proveedorId.'"';
|
|
|
|
if($this->prodCatId)
|
|
$sqlAdd .= ' AND p.prodCatId = "'.$this->prodCatId.'"';
|
|
|
|
if($this->descripcion)
|
|
$sqlAdd .= ' AND p.modelo LIKE "%'.$this->descripcion.'%"';
|
|
|
|
if($this->codigoBarra)
|
|
$sqlAdd .= ' AND p.codigoBarra LIKE "%'.$this->codigoBarra.'%"';
|
|
|
|
if($sqlAdd != ''){
|
|
|
|
$sql = 'SELECT p.*
|
|
|
|
FROM
|
|
producto AS p,
|
|
proveedor AS prov
|
|
WHERE
|
|
p.proveedorId = prov.proveedorId
|
|
AND
|
|
p.baja = "0"
|
|
'.$sqlAdd.'
|
|
ORDER BY
|
|
descripcion';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
}else{
|
|
$result = array();
|
|
$pages = array(
|
|
'numbers' => array(),
|
|
'first' => false,
|
|
'prev' => false,
|
|
'next' => false,
|
|
'last' => false,
|
|
'current' => 1,
|
|
'items_per_page' => defined('ITEMS_PER_PAGE') ? ITEMS_PER_PAGE : 20,
|
|
'start' => 0
|
|
);
|
|
}//else
|
|
|
|
$data["items"] = $result;
|
|
$data["pages"] = $pages;
|
|
|
|
return $data;
|
|
|
|
}//Search
|
|
|
|
function SearchDuplicados(){
|
|
|
|
$sqlAdd = '';
|
|
|
|
if($this->noProveedor)
|
|
$sqlAdd .= ' AND prov.noProv = "'.$this->noProveedor.'"';
|
|
|
|
if($this->proveedorId)
|
|
$sqlAdd .= ' AND p.proveedorId = "'.$this->proveedorId.'"';
|
|
|
|
if($this->prodCatId)
|
|
$sqlAdd .= ' AND p.prodCatId = "'.$this->prodCatId.'"';
|
|
|
|
if($this->descripcion)
|
|
$sqlAdd .= ' AND p.modelo LIKE "%'.$this->descripcion.'%"';
|
|
|
|
if($this->codigoBarra)
|
|
$sqlAdd .= ' AND p.codigoBarra LIKE "%'.$this->codigoBarra.'%"';
|
|
|
|
if($sqlAdd != ''){
|
|
|
|
$sql = 'SELECT p.*
|
|
|
|
FROM
|
|
producto AS p,
|
|
proveedor AS prov
|
|
WHERE
|
|
p.proveedorId = prov.proveedorId
|
|
AND
|
|
codigoBarra LIKE "%-%"
|
|
'.$sqlAdd.'
|
|
ORDER BY
|
|
descripcion';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
}else{
|
|
$result = array();
|
|
$pages = array(
|
|
'numbers' => array(),
|
|
'first' => false,
|
|
'prev' => false,
|
|
'next' => false,
|
|
'last' => false,
|
|
'current' => 1,
|
|
'items_per_page' => defined('ITEMS_PER_PAGE') ? ITEMS_PER_PAGE : 20,
|
|
'start' => 0
|
|
);
|
|
}//else
|
|
|
|
$data["items"] = $result;
|
|
$data["pages"] = $pages;
|
|
|
|
return $data;
|
|
|
|
}//SearchDuplicados
|
|
|
|
function SearchVta(){
|
|
|
|
$sqlAdd = '';
|
|
|
|
if($this->proveedorId)
|
|
$sqlAdd .= ' AND proveedorId = "'.$this->proveedorId.'"';
|
|
if($this->prodCatId)
|
|
$sqlAdd .= ' AND prodCatId = "'.$this->prodCatId.'"';
|
|
if($this->prodSubcatId)
|
|
$sqlAdd .= ' AND prodSubcatId = "'.$this->prodSubcatId.'"';
|
|
|
|
$sql = 'SELECT
|
|
*
|
|
FROM
|
|
producto
|
|
WHERE baja = "0"
|
|
'.$sqlAdd.'
|
|
ORDER BY
|
|
modelo ASC
|
|
|
|
';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$productos = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $productos;
|
|
|
|
}//SearchVta
|
|
|
|
function SearchPromo(){
|
|
|
|
$sqlAdd = '';
|
|
|
|
if($this->proveedorId)
|
|
$sqlAdd .= ' AND proveedorId = "'.$this->proveedorId.'"';
|
|
if($this->prodCatId)
|
|
$sqlAdd .= ' AND prodCatId = "'.$this->prodCatId.'"';
|
|
if($this->prodSubcatId)
|
|
$sqlAdd .= ' AND prodSubcatId = "'.$this->prodSubcatId.'"';
|
|
|
|
$sql = 'SELECT
|
|
*
|
|
FROM
|
|
producto
|
|
WHERE
|
|
baja = "0"
|
|
'.$sqlAdd.'
|
|
ORDER BY
|
|
modelo ASC
|
|
';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$productos = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $productos;
|
|
|
|
}//SearchPromo
|
|
|
|
function GetVentaPrice(){
|
|
|
|
global $util;
|
|
|
|
$sql = 'SELECT
|
|
precioVenta
|
|
FROM
|
|
inventario AS inv, envio AS env
|
|
WHERE
|
|
inv.envioId = env.envioId
|
|
AND
|
|
inv.sucursalId = "'.$this->sucursalId.'"
|
|
AND
|
|
inv.productoId = "'.$this->productoId.'"
|
|
AND
|
|
inv.status = "Disponible"
|
|
ORDER BY
|
|
env.fechaRecibido DESC,
|
|
inv.inventarioId ASC
|
|
LIMIT 1';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$precioVenta = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $precioVenta;
|
|
|
|
}
|
|
|
|
function SaveMaterial(){
|
|
|
|
if($this->Util()->PrintErrors()){
|
|
return false;
|
|
}
|
|
|
|
$sql = "INSERT INTO productoMaterial (
|
|
productoId,
|
|
materialId,
|
|
porcentaje
|
|
)
|
|
VALUES (
|
|
'".$this->productoId."',
|
|
'".$this->materialId."',
|
|
'".$this->porcentaje."'
|
|
)";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->InsertData();
|
|
|
|
return $true;
|
|
|
|
}//SaveMaterial
|
|
|
|
function SaveItem(){
|
|
|
|
if($this->Util()->PrintErrors()){
|
|
return false;
|
|
}
|
|
|
|
$sql = "INSERT INTO productoItem (
|
|
productoId,
|
|
tallaId,
|
|
colorId,
|
|
codigoBarra
|
|
)
|
|
VALUES (
|
|
'".$this->productoId."',
|
|
'".$this->tallaId."',
|
|
'".$this->colorId."',
|
|
'".$this->codigoBarra."'
|
|
)";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$prodItemId = $this->Util()->DBSelect($_SESSION['empresaId'])->InsertData();
|
|
|
|
return $prodItemId;
|
|
|
|
}//SaveItem
|
|
|
|
function UpdateItem(){
|
|
|
|
$sql = "UPDATE productoItem SET
|
|
codigoBarra = '".$this->codigoBarra."'
|
|
WHERE
|
|
prodItemId = '".$this->prodItemId."'";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->UpdateData();
|
|
|
|
return true;
|
|
|
|
}//UpdateItem
|
|
|
|
function SaveAtributo(){
|
|
|
|
if($this->Util()->PrintErrors()){
|
|
return false;
|
|
}
|
|
|
|
$sql = "INSERT INTO productoAtributo (
|
|
productoId,
|
|
atributoId,
|
|
atribValId
|
|
)
|
|
VALUES (
|
|
'".$this->productoId."',
|
|
'".$this->atributoId."',
|
|
'".$this->atribValId."'
|
|
)";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->InsertData();
|
|
|
|
return $true;
|
|
|
|
}//SaveAtributo
|
|
|
|
function GetColores(){
|
|
|
|
$sql = 'SELECT colorId FROM productoItem
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
GROUP BY colorId';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$colores = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $colores;
|
|
|
|
}
|
|
|
|
function GetTallas(){
|
|
|
|
$sql = 'SELECT tallaId FROM productoItem
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
GROUP BY tallaId';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$tallas = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $tallas;
|
|
|
|
}
|
|
|
|
function GetMaterials(){
|
|
|
|
$sql = 'SELECT * FROM productoMaterial
|
|
WHERE productoId = "'.$this->productoId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$materials = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $materials;
|
|
|
|
}
|
|
|
|
function GetAtributos(){
|
|
|
|
$sql = 'SELECT * FROM productoAtributo
|
|
WHERE productoId = "'.$this->productoId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$atributos = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $atributos;
|
|
|
|
}
|
|
|
|
function GetAtributosGral(){
|
|
|
|
global $prodSubcat;
|
|
global $atribVal;
|
|
|
|
$info = $this->Info();
|
|
|
|
$prodSubcat->setProdSubcatId($info['prodSubcatId']);
|
|
$resAtributos = $prodSubcat->EnumAtributos();
|
|
|
|
$valores = array();
|
|
foreach($resAtributos as $res){
|
|
|
|
$atribVal->setAtributoId($res['atributoId']);
|
|
$resValores = $atribVal->EnumerateAll();
|
|
|
|
foreach($resValores as $val){
|
|
|
|
$this->setAtribValId($val['atribValId']);
|
|
if($this->ExistAtributo())
|
|
$valores[] = $val['nombre'];
|
|
|
|
}
|
|
}
|
|
|
|
$atributos = implode(', ', $valores);
|
|
|
|
return $atributos;
|
|
|
|
}
|
|
|
|
function GetAtributosAll(){
|
|
|
|
global $prodSubcat;
|
|
global $atribVal;
|
|
global $prodCat;
|
|
global $prodSubcat;
|
|
|
|
$info = $this->Info();
|
|
|
|
$valores = array();
|
|
|
|
//Obtenemos el Departamento
|
|
if($info['prodCatId']){
|
|
$prodCat->setProdCatId($info['prodCatId']);
|
|
$valores[] = $prodCat->GetNameById();
|
|
}
|
|
|
|
//Obtenemos la Linea
|
|
if($info['prodSubcatId']){
|
|
$prodSubcat->setProdSubcatId($info['prodSubcatId']);
|
|
$valores[] = $prodSubcat->GetNameById();
|
|
}
|
|
|
|
//Obtenemos los Atributos
|
|
$prodSubcat->setProdSubcatId($info['prodSubcatId']);
|
|
$resAtributos = $prodSubcat->EnumAtributos();
|
|
|
|
foreach($resAtributos as $res){
|
|
|
|
$atribVal->setAtributoId($res['atributoId']);
|
|
$resValores = $atribVal->EnumerateAll();
|
|
|
|
foreach($resValores as $val){
|
|
|
|
$this->setAtribValId($val['atribValId']);
|
|
if($this->ExistAtributo())
|
|
$valores[] = $val['nombre'];
|
|
|
|
}
|
|
}
|
|
|
|
$atributos = implode(', ', $valores);
|
|
|
|
return $atributos;
|
|
|
|
}
|
|
|
|
function GetAtributoVal(){
|
|
|
|
$sql = 'SELECT * FROM productoAtributo
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND atributoId = "'.$this->atributoId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$valores = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $valores;
|
|
|
|
}
|
|
|
|
function ExistTalla(){
|
|
|
|
$sql = 'SELECT COUNT(*) FROM productoItem
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND tallaId = "'.$this->tallaId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$exits = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $exits;
|
|
|
|
}
|
|
|
|
function ExistColor(){
|
|
|
|
$sql = 'SELECT COUNT(*) FROM productoItem
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND colorId = "'.$this->colorId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$exits = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $exits;
|
|
|
|
}
|
|
|
|
function ExistAtributo(){
|
|
|
|
$sql = 'SELECT COUNT(*) FROM productoAtributo
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND atribValId = "'.$this->atribValId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$exits = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $exits;
|
|
|
|
}
|
|
|
|
function GetCodigosBarra(){
|
|
|
|
$sql = 'SELECT * FROM productoItem
|
|
WHERE productoId = "'.$this->productoId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$codigos = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $codigos;
|
|
}
|
|
|
|
function GetCodigoBarra(){
|
|
|
|
$sql = 'SELECT codigoBarra FROM productoItem
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND tallaId = "'.$this->tallaId.'"
|
|
AND colorId = "'.$this->colorId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$codigo = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $codigo;
|
|
}
|
|
|
|
function GetInfoItem(){
|
|
|
|
$sql = 'SELECT * FROM productoItem
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND tallaId = "'.$this->tallaId.'"
|
|
AND colorId = "'.$this->colorId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$info = $this->Util()->DBSelect($_SESSION['empresaId'])->GetRow();
|
|
|
|
return $info;
|
|
}
|
|
|
|
function GetInfoItemById(){
|
|
|
|
$sql = 'SELECT * FROM productoItem
|
|
WHERE prodItemId = "'.$this->prodItemId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$info = $this->Util()->DBSelect($_SESSION['empresaId'])->GetRow();
|
|
|
|
return $info;
|
|
}
|
|
|
|
function ExistCodigoBarra(){
|
|
|
|
$sql = 'SELECT prodItemId FROM productoItem
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND tallaId = "'.$this->tallaId.'"
|
|
AND colorId = "'.$this->colorId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$prodItemId = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $prodItemId;
|
|
}
|
|
|
|
function GetProductByCodigo(){
|
|
|
|
if($this->productoId)
|
|
$sqlAdd = ' AND productoId <> "'.$this->productoId.'"';
|
|
|
|
$sql = 'SELECT prodItemId FROM productoItem
|
|
WHERE codigoBarra = "'.$this->codigoBarra.'"'.$sqlAdd.'
|
|
LIMIT 1';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$prodItemId = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $prodItemId;
|
|
}
|
|
|
|
function GetActiveProductByCodigo(){
|
|
|
|
if($this->productoId)
|
|
$sqlAdd = ' AND productoId <> "'.$this->productoId.'"';
|
|
|
|
$sql = 'SELECT prodItemId FROM productoItem AS pi, producto p
|
|
WHERE p.productoId = pi.productoId
|
|
AND p.baja = "0"
|
|
AND p.codigoBarra = "'.$this->codigoBarra.'"
|
|
'.$sqlAdd.'
|
|
LIMIT 1';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$prodItemId = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $prodItemId;
|
|
}
|
|
|
|
function GetProductByCodigo2(){
|
|
|
|
$sql = 'SELECT prodItemId FROM productoItem
|
|
WHERE codigoBarra = "'.$this->codigoBarra.'"'.$sqlAdd.'
|
|
LIMIT 1';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$prodItemId = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $prodItemId;
|
|
}
|
|
|
|
function GetProductIdByCodigo(){
|
|
|
|
$sql = 'SELECT productoId FROM producto
|
|
WHERE codigoBarra = "'.$this->codigoBarra.'"
|
|
LIMIT 1';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$productoId = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $productoId;
|
|
}
|
|
|
|
function GetProductIdByCodigo2(){
|
|
//" AND proveedorId = "'.$this->proveedorId.'"
|
|
$sql = 'SELECT productoId FROM producto
|
|
WHERE codigoBarra = "'.$this->codigoBarra.'"
|
|
AND baja = "0"
|
|
LIMIT 1';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$productoId = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $productoId;
|
|
}
|
|
|
|
function GetNameById()
|
|
{
|
|
$sql = "SELECT descripcion FROM producto WHERE productoId ='".$this->productoId."'";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$nombre = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $nombre;
|
|
}
|
|
|
|
function _GetCantVendido()
|
|
{
|
|
if($this->sucursalId)
|
|
$sqlFilter = ' AND v.sucursalId = "'.$this->sucursalId.'"';
|
|
|
|
$sql = 'SELECT SUM(p.cantidad)
|
|
FROM venta AS v, ventaProducto AS p
|
|
WHERE v.ventaId = p.ventaId
|
|
AND DATE(v.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(v.fecha) <= "'.$this->fechaFin.'"
|
|
AND p.productoId = "'.$this->productoId.'"'.$sqlFilter;
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$cantidad = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $cantidad;
|
|
}
|
|
|
|
//Original
|
|
|
|
function GetCantVendidoOld()
|
|
{
|
|
if($this->sucursalId)
|
|
$sqlFilter = ' AND v.sucursalId = "'.$this->sucursalId.'" ';
|
|
|
|
$sql = 'SELECT v.ventaId
|
|
FROM venta AS v, ventaProducto AS p
|
|
WHERE v.ventaId = p.ventaId
|
|
AND DATE(v.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(v.fecha) <= "'.$this->fechaFin.'"
|
|
AND p.productoId = "'.$this->productoId.'"
|
|
'.$sqlFilter.'
|
|
GROUP BY p.ventaId';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
$total = 0;
|
|
foreach($result as $res){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE ventaId = "'.$res['ventaId'].'"
|
|
AND productoId = "'.$this->productoId.'"
|
|
AND sucursalId = "'.$this->sucursalId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
}
|
|
|
|
return $total;
|
|
}
|
|
|
|
//Best
|
|
|
|
function GetCantVendido()
|
|
{
|
|
if($this->sucursalId)
|
|
$sqlFilter = ' AND v.sucursalId = "'.$this->sucursalId.'" ';
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario i, venta v
|
|
WHERE i.ventaId = v.ventaId
|
|
AND i.productoId = "'.$this->productoId.'"
|
|
AND DATE(v.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(v.fecha) <= "'.$this->fechaFin.'"
|
|
'.$sqlFilter;
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $total;
|
|
}
|
|
|
|
function GetCantTotalComp()
|
|
{
|
|
$sql = 'SELECT SUM(cantPrendas)
|
|
FROM pedido AS p, pedidoProducto AS prod
|
|
WHERE p.pedidoId = prod.pedidoId
|
|
AND DATE(p.fechaOrdenCompIng) >= "'.$this->fechaIni.'"
|
|
AND DATE(p.fechaOrdenCompIng) <= "'.$this->fechaFin.'"
|
|
AND prod.productoId = "'.$this->productoId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$cantidad = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $cantidad;
|
|
}
|
|
|
|
function _GetCantTotalCompBySuc()
|
|
{
|
|
global $envio;
|
|
|
|
$sql = 'SELECT SUM(er.noPrendas)
|
|
FROM envio AS e, envioRecibir AS er, pedido ped
|
|
WHERE e.envioId = er.envioId
|
|
AND er.pedidoId = ped.pedidoId
|
|
AND DATE(e.fechaRecibido) >= "'.$this->fechaIni.'"
|
|
AND DATE(e.fechaRecibido) <= "'.$this->fechaFin.'"
|
|
AND er.productoId = "'.$this->productoId.'"
|
|
AND e.sucursalId = "'.$this->sucursalId.'"
|
|
AND ped.ajuste = "0"
|
|
AND ped.folioProv NOT REGEXP "^FOLIO"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $total;
|
|
}
|
|
|
|
//Original
|
|
|
|
function GetCantTotalCompBySucOld()
|
|
{
|
|
global $envio;
|
|
|
|
$sql = 'SELECT i.envioId FROM inventario i, envio e
|
|
WHERE i.envioId = e.envioId
|
|
AND e.fecha >= "'.$this->fechaIni.' 00:00:00"
|
|
AND e.fecha <= "'.$this->fechaFin.' 23:59:59"
|
|
AND i.productoId = "'.$this->productoId.'"
|
|
AND i.sucursalId = "'.$this->sucursalId.'"
|
|
AND e.tipo = "CT"
|
|
GROUP BY i.envioId';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$envios = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
$total = 0;
|
|
foreach($envios as $res){
|
|
|
|
$sql = 'SELECT p.pedidoId FROM inventario i, pedido p
|
|
WHERE i.pedidoId = p.pedidoId
|
|
AND p.ajuste = "0"
|
|
AND p.folioProv NOT REGEXP "^FOLIO"
|
|
AND i.productoId = "'.$this->productoId.'"
|
|
AND i.sucursalId = "'.$this->sucursalId.'"
|
|
AND i.envioId = "'.$res['envioId'].'"
|
|
GROUP BY i.pedidoId';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$pedidos = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
foreach($pedidos as $ped){
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE pedidoId = "'.$ped['pedidoId'].'"
|
|
AND productoId = "'.$this->productoId.'"
|
|
AND sucursalId = "'.$this->sucursalId.'"
|
|
AND envioId = "'.$res['envioId'].'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
}
|
|
|
|
}//foreach
|
|
|
|
return $total;
|
|
}
|
|
|
|
//Best
|
|
|
|
function GetCantTotalCompBySuc()
|
|
{
|
|
$sql = 'SELECT SUM(i.cantidad) FROM inventario i
|
|
LEFT JOIN envio e ON e.envioId = i.envioId
|
|
LEFT JOIN pedido p ON p.pedidoId = i.pedidoId
|
|
WHERE e.fecha >= "'.$this->fechaIni.' 00:00:00"
|
|
AND e.fecha <= "'.$this->fechaFin.' 23:59:59"
|
|
AND i.productoId = "'.$this->productoId.'"
|
|
AND i.sucursalId = "'.$this->sucursalId.'"
|
|
AND e.tipo = "CT"
|
|
AND p.ajuste = "0"
|
|
AND p.folioProv NOT REGEXP "^FOLIO"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
return $total;
|
|
}
|
|
|
|
function GetFechaUltCompBySuc()
|
|
{
|
|
$sql = 'SELECT e.fechaRecibido
|
|
FROM envio AS e, envioRecibir AS er
|
|
WHERE e.envioId = er.envioId
|
|
AND er.productoId = "'.$this->productoId.'"
|
|
AND e.sucursalId = "'.$this->sucursalId.'"
|
|
ORDER BY e.fechaRecibido DESC
|
|
LIMIT 1';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$fecha = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $fecha;
|
|
}
|
|
|
|
function GetFechaUltCompra()
|
|
{
|
|
$sql = 'SELECT p.fechaOrdenCompIng
|
|
FROM pedido AS p, pedidoProducto AS prod
|
|
WHERE p.pedidoId = prod.pedidoId
|
|
AND prod.productoId = "'.$this->productoId.'"
|
|
ORDER BY p.fechaOrdenCompIng DESC
|
|
LIMIT 1';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$fecha = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $fecha;
|
|
}
|
|
|
|
function GetModeloById()
|
|
{
|
|
$sql = "SELECT modelo FROM producto WHERE productoId ='".$this->productoId."'";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$modelo = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $modelo;
|
|
}
|
|
|
|
function GetProdItemId(){
|
|
|
|
$sql = "SELECT prodItemId FROM productoItem
|
|
WHERE productoId ='".$this->productoId."'
|
|
AND colorId ='".$this->colorId."'
|
|
AND tallaId ='".$this->tallaId."'";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$prodItemId = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $prodItemId;
|
|
}
|
|
|
|
function GetFullName(){
|
|
|
|
global $producto;
|
|
global $atribVal;
|
|
|
|
$producto->setProdItemId($this->prodItemId);
|
|
$info = $producto->GetInfoItemById();
|
|
|
|
$producto->setProductoId($info['productoId']);
|
|
$infP = $producto->Info();
|
|
|
|
$atribVal->setAtribValId($info['tallaId']);
|
|
$talla = utf8_encode($atribVal->GetNameById());
|
|
|
|
$atribVal->setAtribValId($info['colorId']);
|
|
$color = utf8_encode($atribVal->GetNameById());
|
|
|
|
$name = $infP['modelo'].' '.$talla.' '.$color;
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
function GetFullNombre(){
|
|
|
|
global $producto;
|
|
global $atribVal;
|
|
|
|
$producto->setProdItemId($this->prodItemId);
|
|
$info = $producto->GetInfoItemById();
|
|
|
|
$producto->setProductoId($info['productoId']);
|
|
$infP = $producto->Info();
|
|
|
|
$atribVal->setAtribValId($info['tallaId']);
|
|
$talla = $atribVal->GetNameById();
|
|
|
|
$atribVal->setAtribValId($info['colorId']);
|
|
$color = $atribVal->GetNameById();
|
|
|
|
$name = $infP['modelo'].' '.$talla.' '.$color;
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
function Suggest()
|
|
{
|
|
$sql = "SELECT
|
|
*
|
|
FROM
|
|
producto
|
|
WHERE
|
|
baja = '0'
|
|
AND
|
|
proveedorId = '".$this->proveedorId."'
|
|
AND
|
|
prodCatId = '".$this->prodCatId."'
|
|
AND
|
|
prodSubcatId = '".$this->prodSubcatId."'
|
|
AND
|
|
(modelo LIKE '%".$this->modelo."%'
|
|
OR descripcion LIKE '%".$this->modelo."%'
|
|
OR codigoBarra LIKE '%".$this->modelo."%')
|
|
ORDER BY
|
|
modelo ASC
|
|
LIMIT
|
|
10";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$productos = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $productos;
|
|
}
|
|
|
|
function SuggestVta()
|
|
{
|
|
$sql = "SELECT
|
|
p.*, i.*
|
|
FROM
|
|
producto AS p, productoItem AS i
|
|
WHERE
|
|
baja = '0'
|
|
AND
|
|
p.productoId = i.productoId
|
|
ORDER BY
|
|
p.modelo ASC
|
|
";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$productos = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $productos;
|
|
}
|
|
|
|
function GetAllProdItems()
|
|
{
|
|
$sql = "SELECT * FROM productoItem ORDER BY productoId";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$productos = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $productos;
|
|
}
|
|
|
|
function IsAvailable()
|
|
{
|
|
$sql = "SELECT COUNT(*) FROM inventario
|
|
WHERE productoId = '".$this->productoId."'
|
|
AND sucursalId = '".$this->sucursalId."'
|
|
AND status = 'Disponible'";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$exist = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $exist;
|
|
}
|
|
|
|
function AgregarConceptoFact()
|
|
{
|
|
if($this->Util()->PrintErrors()){
|
|
return false;
|
|
}
|
|
|
|
end($_SESSION["conceptos"]);
|
|
|
|
$cK = key($_SESSION["conceptos"]) + 1;
|
|
|
|
$_SESSION["conceptos"][$cK]['productoId'] = $this->productoId;
|
|
$_SESSION["conceptos"][$cK]["noIdentificacion"] = $this->noIdentificacion;
|
|
$_SESSION["conceptos"][$cK]["cantidad"] = $this->cantidad;
|
|
$_SESSION["conceptos"][$cK]["unidad"] = $this->unidad;
|
|
$_SESSION["conceptos"][$cK]["valorUnitario"] = $this->valorUnitario;
|
|
$_SESSION["conceptos"][$cK]["importe"] = $this->importe;
|
|
$_SESSION["conceptos"][$cK]["excentoIva"] = $this->excentoIva;
|
|
$_SESSION["conceptos"][$cK]["descripcion"] = urldecode($this->descripcion);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function GetTotalDesglosado()
|
|
{
|
|
$values = explode("&", $_POST["form"]);
|
|
foreach($values as $key => $val)
|
|
{
|
|
$array = explode("=", $values[$key]);
|
|
$data[$array[0]] = $array[1];
|
|
}
|
|
|
|
$ivaForm = $data['tasaIva'];
|
|
|
|
if(!$_SESSION["conceptos"])
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$data["subtotal"] = 0;
|
|
$data["descuento"] = 0;
|
|
$data["iva"] = 0;
|
|
$data["ieps"] = 0;
|
|
$data["retIva"] = 0;
|
|
$data["retIsr"] = 0;
|
|
$data["total"] = 0;
|
|
|
|
foreach($data as $key => $value)
|
|
{
|
|
$data[$key] = $this->Util()->RoundNumber($data[$key]);
|
|
}
|
|
|
|
$info = $this->Info();
|
|
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("
|
|
SELECT * FROM sucursal
|
|
LEFT JOIN rfc ON rfc.rfcId = sucursal.rfcId
|
|
WHERE sucursal.sucursalId ='".$info["sucursalId"]."'");
|
|
$sucursal = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow();
|
|
|
|
$suc['iva'] = $ivaForm;
|
|
|
|
foreach($_SESSION["conceptos"] as $key => $concepto)
|
|
{
|
|
$data["subtotalOriginal"] = $this->Util()->RoundNumber($data["subtotalOriginal"] + $importe);
|
|
|
|
$data["subtotal"] = $this->Util()->RoundNumber($data["subtotal"] + $concepto["importe"]);
|
|
|
|
if($concepto["excentoIva"] == "si")
|
|
{
|
|
$_SESSION["conceptos"][$key]["tasaIva"] = 0;
|
|
}
|
|
else
|
|
{
|
|
$_SESSION["conceptos"][$key]["tasaIva"] = $suc["iva"];
|
|
}
|
|
|
|
|
|
if($data["porcentajeDescuento"])
|
|
{
|
|
$data["porcentajeDescuento"];
|
|
}
|
|
|
|
$data["descuentoThis"] = $this->Util()->RoundNumber($_SESSION["conceptos"][$key]["importe"] * ($data["porcentajeDescuento"] / 100));
|
|
$data["descuento"] += $data["descuentoThis"];
|
|
|
|
$afterDescuento = $_SESSION["conceptos"][$key]["importe"] - $data["descuentoThis"];
|
|
if($concepto["excentoIva"] == "si")
|
|
{
|
|
$_SESSION["conceptos"][$key]["tasaIva"] = 0;
|
|
}
|
|
else
|
|
{
|
|
$_SESSION["conceptos"][$key]["tasaIva"] = $suc["iva"];
|
|
}
|
|
|
|
$data["ivaThis"] = $this->Util()->RoundNumber($afterDescuento * ($_SESSION["conceptos"][$key]["tasaIva"] / 100));
|
|
|
|
if(isset($_SESSION["conceptos"][$key]["hardCodedIva"]))
|
|
{
|
|
$data["iva"] = $_SESSION["conceptos"][$key]["hardCodedIva"];
|
|
}
|
|
else
|
|
{
|
|
$data["iva"] += $data["ivaThis"];
|
|
}
|
|
}
|
|
|
|
$data["impuestos"] = $_SESSION["impuestos"];
|
|
|
|
$afterDescuento = $data["subtotal"] - $data["descuento"];
|
|
|
|
$data["afterDescuento"] = $afterDescuento;
|
|
|
|
$data["afterIva"] = $afterDescuento + $data["iva"];
|
|
|
|
if(!$data["porcentajeIEPS"])
|
|
{
|
|
$data["porcentajeIEPS"] = 0;
|
|
}
|
|
|
|
$data["ieps"] = $this->Util()->RoundNumber($data["afterDescuento"] * ($data["porcentajeIEPS"] / 100));
|
|
$afterImpuestos = $afterDescuento + $data["iva"] + $data["ieps"];
|
|
$data["afterImpuestos"] = $afterImpuestos;
|
|
|
|
$data["retIva"] = $this->Util()->RoundNumber($data["afterDescuento"] * ($data["porcentajeRetIva"] / 100));
|
|
$data["retIsr"] = $this->Util()->RoundNumber($data["afterDescuento"] * ($data["porcentajeRetIsr"] / 100));
|
|
$data["total"] = $this->Util()->RoundNumber($data["subtotal"] - $data["descuento"] + $data["iva"] + $data["ieps"] - $data["retIva"] - $data["retIsr"]);
|
|
|
|
return $data;
|
|
}
|
|
|
|
function GetProductByCodigoUtil(){
|
|
|
|
if($this->productoId)
|
|
$sqlAdd = ' AND productoId <> "'.$this->productoId.'"';
|
|
|
|
$sql = 'SELECT productoId FROM productoItem
|
|
WHERE codigoBarra = "'.$this->codigoBarra.'"'.$sqlAdd.'
|
|
LIMIT 1';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$prodItemId = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $prodItemId;
|
|
}
|
|
|
|
function ExistProdItem(){
|
|
|
|
$sql = 'SELECT prodItemId FROM productoItem
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND tallaId = "'.$this->tallaId.'"
|
|
AND colorId = "'.$this->colorId.'"
|
|
LIMIT 1';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$prodItemId = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $prodItemId;
|
|
|
|
}
|
|
|
|
function GetTotalDispGral()
|
|
{
|
|
$sql = "SELECT COUNT(*) FROM inventario
|
|
WHERE productoId = '".$this->productoId."'
|
|
AND status = 'Disponible'";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $total;
|
|
}
|
|
|
|
//Original
|
|
|
|
function GetEntAjusteEnvOld(){
|
|
|
|
global $envio;
|
|
|
|
/*
|
|
$sql = 'SELECT SUM(cantidad) FROM envioReporteProd
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND DATE(fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(fecha) <= "'.$this->fechaFin.'"
|
|
AND sucursalId = "'.$this->sucursalId.'"
|
|
AND status = "Autorizado"
|
|
AND tipo = "Sobrante"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
*/
|
|
|
|
$sql = 'SELECT * FROM inventario i, envio e
|
|
WHERE i.envioId = e.envioId
|
|
AND DATE(e.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(e.fecha) <= "'.$this->fechaFin.'"
|
|
AND i.productoId = "'.$this->productoId.'"
|
|
AND i.sucursalId = "'.$this->sucursalId.'"
|
|
AND e.tipo <> "TT"
|
|
GROUP BY i.envioId';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$envios = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
$total = 0;
|
|
foreach($envios as $res){
|
|
|
|
$envio->setEnvioId($res['envioId']);
|
|
$infE = $envio->Info();
|
|
|
|
$fechaEnvio = date('Y-m-d',strtotime($infE['fechaRecibido']));
|
|
|
|
$sql = 'SELECT * FROM inventario i, pedido p
|
|
WHERE i.pedidoId = p.pedidoId
|
|
AND p.folioProv REGEXP "^FOLIO"
|
|
AND i.productoId = "'.$this->productoId.'"
|
|
AND i.sucursalId = "'.$this->sucursalId.'"
|
|
AND i.envioId = "'.$res['envioId'].'"
|
|
GROUP BY i.pedidoId';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$pedidos = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
foreach($pedidos as $ped){
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE pedidoId = "'.$ped['pedidoId'].'"
|
|
AND productoId = "'.$this->productoId.'"
|
|
AND sucursalId = "'.$this->sucursalId.'"
|
|
AND envioId = "'.$res['envioId'].'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
}
|
|
|
|
//Agregamos los envios de TT antes de ser enviados.
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND envioIdFS = "'.$res['envioId'].'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
}//foreach
|
|
|
|
//Checamos los Envios que fueron enviados a otras Tiendas
|
|
//y que no aparecen en Inventario
|
|
|
|
$sql = 'SELECT * FROM envio e, envioRecibir er
|
|
WHERE e.envioId = er.envioId
|
|
AND DATE(e.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(e.fecha) <= "'.$this->fechaFin.'"
|
|
AND er.productoId = "'.$this->productoId.'"
|
|
AND e.sucursalId = "'.$this->sucursalId.'"
|
|
AND e.tipo <> "TT"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$envios = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
foreach($envios as $res){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE envioId = "'.$res['envioId'].'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$cantidad = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
if($cantidad == 0){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE envioIdFS = "'.$res['envioId'].'"
|
|
AND productoId = "'.$this->productoId.'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
}//if
|
|
|
|
}//foreach
|
|
|
|
return $total;
|
|
}
|
|
|
|
//Best
|
|
|
|
function GetEntAjusteEnv(){
|
|
|
|
$sql = 'SELECT * FROM inventario i, envio e
|
|
WHERE i.envioId = e.envioId
|
|
AND DATE(e.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(e.fecha) <= "'.$this->fechaFin.'"
|
|
AND i.productoId = "'.$this->productoId.'"
|
|
AND i.sucursalId = "'.$this->sucursalId.'"
|
|
AND e.tipo <> "TT"
|
|
GROUP BY i.envioId';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$envios = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
$total = 0;
|
|
foreach($envios as $res){
|
|
|
|
$sql = 'SELECT SUM(i.cantidad) FROM inventario i, pedido p
|
|
WHERE i.pedidoId = p.pedidoId
|
|
AND p.folioProv REGEXP "^FOLIO"
|
|
AND i.productoId = "'.$this->productoId.'"
|
|
AND i.sucursalId = "'.$this->sucursalId.'"
|
|
AND i.envioId = "'.$res['envioId'].'"
|
|
GROUP BY i.pedidoId';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
//Agregamos los envios de TT antes de ser enviados.
|
|
/*
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND envioIdFS = "'.$res['envioId'].'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
*/
|
|
}//foreach
|
|
|
|
//Checamos los Envios que fueron enviados a otras Tiendas
|
|
//y que no aparecen en Inventario
|
|
|
|
$sql = 'SELECT * FROM envio e, envioRecibir er
|
|
WHERE e.envioId = er.envioId
|
|
AND DATE(e.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(e.fecha) <= "'.$this->fechaFin.'"
|
|
AND er.productoId = "'.$this->productoId.'"
|
|
AND e.sucursalId = "'.$this->sucursalId.'"
|
|
AND e.tipo <> "TT"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$envios = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
foreach($envios as $res){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE envioId = "'.$res['envioId'].'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$cantidad = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
if($cantidad == 0){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE envioIdFS = "'.$res['envioId'].'"
|
|
AND productoId = "'.$this->productoId.'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
}//if
|
|
|
|
}//foreach
|
|
|
|
return $total;
|
|
}
|
|
|
|
function GetBloqueadosEnv(){
|
|
|
|
$sql = 'SELECT * FROM inventario i, envio e
|
|
WHERE i.envioId = e.envioId
|
|
AND DATE(e.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(e.fecha) <= "'.$this->fechaFin.'"
|
|
AND i.productoId = "'.$this->productoId.'"
|
|
AND i.sucursalId = "'.$this->sucursalId.'"
|
|
AND e.tipo <> "TT"
|
|
GROUP BY i.envioId';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$envios = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
$total = 0;
|
|
foreach($envios as $res){
|
|
|
|
//Agregamos los envios de TT antes de ser enviados.
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND envioIdFS = "'.$res['envioId'].'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
}//foreach
|
|
|
|
return $total;
|
|
}
|
|
|
|
function GetSalAjusteEnv(){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM envioReporteProd
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND DATE(fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(fecha) <= "'.$this->fechaFin.'"
|
|
AND sucursalId = "'.$this->sucursalId.'"
|
|
AND status = "Autorizado"
|
|
AND tipo = "Faltante"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
//Checamos los ajustes realizados
|
|
|
|
$sql = 'SELECT * FROM inventario i, envio e
|
|
WHERE i.envioId = e.envioId
|
|
AND DATE(e.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(e.fecha) <= "'.$this->fechaFin.'"
|
|
AND i.productoId = "'.$this->productoId.'"
|
|
AND i.sucursalId = "'.$this->sucursalId.'"
|
|
AND i.status = "Ajuste"
|
|
GROUP BY i.envioId';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$envios = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
foreach($envios as $res){
|
|
|
|
$sql = 'SELECT envRepProdId FROM envioReporteProd
|
|
WHERE envioId = "'.$res['envioId'].'"
|
|
AND productoId = "'.$this->productoId.'"
|
|
AND sucursalId = "'.$this->sucursalId.'"
|
|
AND status = "Autorizado"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$existe = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
if(!$existe){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE productoId = "'.$this->productoId.'"
|
|
AND sucursalId = "'.$this->sucursalId.'"
|
|
AND envioId = "'.$res['envioId'].'"
|
|
AND status = "Ajuste"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
}//if
|
|
|
|
}//foreach
|
|
|
|
return $total;
|
|
}
|
|
|
|
//Old
|
|
|
|
function GetEntEnvTTOld(){
|
|
|
|
$sql = 'SELECT e.envioId FROM envio e, envioProducto ep
|
|
WHERE e.envioId = ep.envioId
|
|
AND ep.productoId = "'.$this->productoId.'"
|
|
AND DATE(e.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(e.fecha) <= "'.$this->fechaFin.'"
|
|
AND e.sucursalId = "'.$this->sucursalId.'"
|
|
AND e.status = "Recibido"
|
|
AND e.tipo = "TT"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
$total = 0;
|
|
foreach($result as $res){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE envioId = "'.$res['envioId'].'"
|
|
AND sucursalId = "'.$this->sucursalId.'"
|
|
AND productoId = "'.$this->productoId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
}
|
|
|
|
return $total;
|
|
}
|
|
|
|
//Best
|
|
|
|
function GetEntEnvTT(){
|
|
|
|
|
|
$sql = 'SELECT SUM(ep.recibido) FROM envio e, envioProducto ep
|
|
WHERE e.envioId = ep.envioId
|
|
AND ep.productoId = "'.$this->productoId.'"
|
|
AND DATE(e.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(e.fecha) <= "'.$this->fechaFin.'"
|
|
AND e.sucursalId = "'.$this->sucursalId.'"
|
|
AND e.status = "Recibido"
|
|
AND e.tipo = "TT"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $total;
|
|
}
|
|
|
|
//Old
|
|
|
|
function GetSalEnvTTOld(){
|
|
|
|
$sql = 'SELECT e.envioId FROM envio e, envioProducto ep
|
|
WHERE e.envioId = ep.envioId
|
|
AND ep.productoId = "'.$this->productoId.'"
|
|
AND DATE(e.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(e.fecha) <= "'.$this->fechaFin.'"
|
|
AND e.sucOrigen = "'.$this->sucursalId.'"
|
|
AND (e.status = "Recibido" || e.status = "Pendiente")
|
|
AND e.tipo = "TT"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
$total = 0;
|
|
foreach($result as $res){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE envioId = "'.$res['envioId'].'"
|
|
AND productoId = "'.$this->productoId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
}
|
|
|
|
foreach($result as $res){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE envioIdFS = "'.$res['envioId'].'"
|
|
AND productoId = "'.$this->productoId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
}
|
|
|
|
return $total;
|
|
}
|
|
|
|
//Best
|
|
|
|
function GetSalEnvTT(){
|
|
|
|
$sql = 'SELECT e.envioId FROM envio e, envioProducto ep
|
|
WHERE e.envioId = ep.envioId
|
|
AND ep.productoId = "'.$this->productoId.'"
|
|
AND e.fecha >= "'.$this->fechaIni.' 00:00:00"
|
|
AND e.fecha <= "'.$this->fechaFin.' 23:59:59"
|
|
AND e.sucOrigen = "'.$this->sucursalId.'"
|
|
AND (e.status = "Recibido" || e.status = "Pendiente")
|
|
AND e.tipo = "TT"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
$total = 0;
|
|
foreach($result as $res){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE envioId = "'.$res['envioId'].'"
|
|
AND productoId = "'.$this->productoId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM inventario
|
|
WHERE envioIdFS = "'.$res['envioId'].'"
|
|
AND productoId = "'.$this->productoId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total += $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
}
|
|
|
|
return $total;
|
|
}
|
|
|
|
function GetEntAjusteExcel(){
|
|
|
|
$sql = 'SELECT SUM(ip.cantidad) FROM inventarioWizard i, inventarioWizardProd ip
|
|
WHERE i.invWizardId = ip.invWizardId
|
|
AND ip.productoId = "'.$this->productoId.'"
|
|
AND DATE(i.fecha) >= "'.$this->fechaIni.'"
|
|
AND DATE(i.fecha) <= "'.$this->fechaFin.'"
|
|
AND i.sucursalId = "'.$this->sucursalId.'"';
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$total = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $total;
|
|
}
|
|
|
|
}//Producto
|
|
|
|
?>
|