Util()->ValidateInteger($value); $this->promocionId = $value; } public function setProdCatId($value) { $this->Util()->ValidateInteger($value); $this->prodCatId = $value; } public function setProdSubcatId($value) { $this->Util()->ValidateInteger($value); $this->prodSubcatId = $value; } public function setProveedorId($value) { $this->Util()->ValidateInteger($value); $this->proveedorId = $value; } public function setProductoId($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Código Producto a Regalar'); $this->productoId = $value; } public function setProdItemId($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Producto a Regalar'); $this->prodItemId = $value; } public function setNombre($value) { $this->Util()->ValidateString($value, $max_chars=250, $minChars = 1, 'Nombre'); $this->nombre = $value; } public function setTipo($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Tipo de Promoción'); $this->tipo = $value; } public function setAplica($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Aplica en'); $this->aplica = $value; } public function setAplicaTodos($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Aplicar Promoción a TODOS los productos?'); $this->aplicaTodos = $value; } public function setTotalCompra($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Total de la Compra'); $this->totalCompra = $value; } public function setTipoDesc($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Tipo de Descuento'); $this->tipoDesc = $value; } public function setValorDesc($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Valor del Descuento'); $this->valorDesc = $value; } public function setValorN($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Valor N'); $this->valorN = $value; } public function setValorX($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Valor X'); $this->valorX = $value; } public function setValorY($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Valor Y'); $this->valorY = $value; } public function setCantArtRegalo($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Cant. de Art. a Regalar'); $this->cantArtRegalo = $value; } public function setSucursalId($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Sucursal'); $this->sucursalId = $value; } public function setVigencia($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Vigencia'); $this->vigencia = $value; } public function setFechaIni($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Fecha Inicial'); $this->fechaIni = $value; } public function setFechaFin($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Fecha Final'); $this->fechaFin = $value; } public function setRebajado($value) { $this->Util()->ValidateString($value, $max_chars=1, $minChars = 1, 'Rebajado'); $this->rebajado = $value; } public function setStatus($value) { $this->Util()->ValidateString($value, $max_chars=50, $minChars = 1, 'Status'); $this->status = $value; } function Info(){ $sql = "SELECT * FROM promocion WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $row = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow(); return $row; } function EnumerateAll() { $sql = "SELECT * FROM promocion ORDER BY nombre ASC"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $promociones = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult(); return $promociones; } function EnumBySucursal() { if($this->status) $sqlAdd = ' AND status = "'.$this->status.'"'; $sql = 'SELECT p.* FROM promocion AS p, promocionSuc AS s WHERE p.promocionId = s.promocionId AND s.sucursalId = "'.$this->sucursalId.'" '.$sqlAdd.' ORDER BY p.nombre ASC'; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $promociones = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult(); return $promociones; } public $page = 0; public function SetPage($page) { $this->page = $page; } function Enumerate() { $db = $this->Util()->DBSelect($_SESSION["empresaId"]); $db->setQuery("SELECT COUNT(*) FROM promocion"); $total = $db->GetSingle(); $pages = $this->Util()->HandleMultipages($this->page, $total ,WEB_ROOT."/promociones", "p"); $sqlAdd = " LIMIT ".$pages["start"].", ".$pages["items_per_page"]; $db->setQuery("SELECT * FROM promocion ORDER BY nombre ASC".$sqlAdd); $promociones = $db->GetResult(); $data["items"] = $promociones; $data["pages"] = $pages; return $data; } function SaveTemp(){ if($this->Util()->PrintErrors()){ return false; } return true; } function Save(){ if($this->Util()->PrintErrors()){ return false; } $sql = "INSERT INTO `promocion` ( nombre, tipo, aplica, aplicaTodos, totalCompra, tipoDesc, valorDesc, valorN, valorX, valorY, cantArtRegalo, productoId, vigencia, fechaIni, fechaFin, rebajado, status ) VALUES ( '".utf8_decode($this->nombre)."', '".$this->tipo."', '".$this->aplica."', '".$this->aplicaTodos."', '".$this->totalCompra."', '".$this->tipoDesc."', '".$this->valorDesc."', '".$this->valorN."', '".$this->valorX."', '".$this->valorY."', '".$this->cantArtRegalo."', '".$this->productoId."', '".$this->vigencia."', '".$this->fechaIni."', '".$this->fechaFin."', '".$this->rebajado."', '".$this->status."' )"; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $promocionId = $this->Util()->DBSelect($_SESSION['empresaId'])->InsertData(); $this->Util()->setError(30060, "complete"); $this->Util()->PrintErrors(); return $promocionId; } function Update(){ if($this->Util()->PrintErrors()){ return false; } $sql = "UPDATE `promocion` SET nombre = '".utf8_decode($this->nombre)."', tipo = '".$this->tipo."', aplica = '".$this->aplica."', aplicaTodos = '".$this->aplicaTodos."', totalCompra = '".$this->totalCompra."', tipoDesc = '".$this->tipoDesc."', valorDesc = '".$this->valorDesc."', valorN = '".$this->valorN."', valorX = '".$this->valorX."', valorY = '".$this->valorY."', cantArtRegalo = '".$this->cantArtRegalo."', productoId = '".$this->productoId."', vigencia = '".$this->vigencia."', fechaIni = '".$this->fechaIni."', fechaFin = '".$this->fechaFin."', rebajado = '".$this->rebajado."', status = '".$this->status."' WHERE promocionId = ".$this->promocionId; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->ExecuteQuery(); $this->Util()->setError(30061, "complete"); $this->Util()->PrintErrors(); return true; } function Delete(){ $sql = "DELETE FROM promocion WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $sql = "DELETE FROM promocionSuc WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $sql = "DELETE FROM promocionDepto WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $sql = "DELETE FROM promocionLinea WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $sql = "DELETE FROM promocionProd WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $sql = "DELETE FROM promocionProv WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $sql = "DELETE FROM promocionProdExc WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $this->Util()->setError(30062, "complete"); $this->Util()->PrintErrors(); return true; } function DeleteExtraInfo(){ $sql = "DELETE FROM promocionSuc WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $sql = "DELETE FROM promocionDepto WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $sql = "DELETE FROM promocionLinea WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $sql = "DELETE FROM promocionProd WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $sql = "DELETE FROM promocionProv WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData(); $this->Util()->setError(30062, "complete"); $this->Util()->PrintErrors(); return true; } function SaveSucursal(){ $sql = 'INSERT INTO promocionSuc ( promocionId, sucursalId )VALUES( "'.$this->promocionId.'", "'.$this->sucursalId.'" )'; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->ExecuteQuery(); return true; } function SaveDepto(){ $sql = 'INSERT INTO promocionDepto ( promocionId, prodCatId )VALUES( "'.$this->promocionId.'", "'.$this->prodCatId.'" )'; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->ExecuteQuery(); return true; } function SaveLinea(){ $sql = 'INSERT INTO promocionLinea ( promocionId, prodCatId, prodSubcatId )VALUES( "'.$this->promocionId.'", "'.$this->prodCatId.'", "'.$this->prodSubcatId.'" )'; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->ExecuteQuery(); return true; } function SaveProveedor(){ $sql = 'INSERT INTO promocionProv ( promocionId, proveedorId )VALUES( "'.$this->promocionId.'", "'.$this->proveedorId.'" )'; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->ExecuteQuery(); return true; } function SaveProducto(){ $sql = 'INSERT INTO promocionProd ( promocionId, productoId )VALUES( "'.$this->promocionId.'", "'.$this->productoId.'" )'; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->ExecuteQuery(); return true; } function GetNameById(){ $sql = "SELECT nombre FROM promocion WHERE promocionId = '".$this->promocionId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $name = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); return $name; } function ExistSucursal(){ $sql = "SELECT promSucId FROM promocionSuc WHERE promocionId = '".$this->promocionId."' AND sucursalId = '".$this->sucursalId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $exist = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); return $exist; } function ExistDepto(){ $sql = "SELECT promDeptoId FROM promocionDepto WHERE promocionId = '".$this->promocionId."' AND prodCatId = '".$this->prodCatId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $exist = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); return $exist; } function ExistLinea(){ $sql = "SELECT promLineaId FROM promocionLinea WHERE promocionId = '".$this->promocionId."' AND prodCatId = '".$this->prodCatId."' AND prodSubcatId = '".$this->prodSubcatId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $exist = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); return $exist; } function ExistProveedor(){ $sql = "SELECT promProvId FROM promocionProv WHERE promocionId = '".$this->promocionId."' AND proveedorId = '".$this->proveedorId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $exist = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); return $exist; } function ExistProducto(){ $sql = "SELECT promProdId FROM promocionProd WHERE promocionId = '".$this->promocionId."' AND productoId = '".$this->productoId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $exist = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); return $exist; } function EnumPromosByProd($idProds) { $sql = 'SELECT * FROM promocionProd WHERE productoId IN ('.$idProds.')'; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $promociones = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult(); return $promociones; } function EnumPromosAplicaTodos() { $sql = 'SELECT promocionId FROM promocion WHERE aplicaTodos = "1"'; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $promociones = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult(); return $promociones; } public function GetCantProdsVta(){ global $producto; $conceptos = $_SESSION['conceptos']; $cantidad = 0; foreach($conceptos as $res){ $producto->setProdItemId($res['prodItemId']); $infP = $producto->GetInfoItemById(); if($infP['productoId'] == $this->productoId) $cantidad += $res['cantidad']; } return $cantidad; } public function GetCantGralProdsVta(){ $conceptos = $_SESSION['conceptos']; $cantidad = 0; foreach($conceptos as $res){ $this->setProductoId($res['productoId']); if(!$this->ExistProdInPromo()) continue; $cantidad += $res['cantidad']; } return $cantidad; } public function GetProdBuenFin(){ $conceptos = $_SESSION['conceptos']; $precio = 0; $productoId = 0; foreach($conceptos as $res){ $this->setProductoId($res['productoId']); if(!$this->ExistProdInPromo()) continue; if($precio == 0){ $precio = $res['precio']; $productoId = $res['productoId']; }elseif($res['precio'] < $precio){ $precio = $res['precio']; $productoId = $res['productoId']; } } return $productoId; } public function GetTotalByProdVta(){ global $producto; $conceptos = $_SESSION['conceptos']; $total = 0; foreach($conceptos as $res){ $producto->setProdItemId($res['prodItemId']); $infP = $producto->GetInfoItemById(); if($infP['productoId'] == $this->productoId) $total += $res['total']; } return $total; } function ExistProdInPromo() { $infP = $this->Info(); if($infP['aplicaTodos'] == 1) return 1; $sql = 'SELECT promProdId FROM promocionProd WHERE productoId = "'.$this->productoId.'" AND promocionId = "'.$this->promocionId.'"'; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $promProdId = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); return $promProdId; } function ExcProdInPromo() { //Checamos si el producto esta excluido $sql = 'SELECT promocionId FROM promocionProdExc WHERE productoId = "'.$this->productoId.'" AND promocionId = "'.$this->promocionId.'"'; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $promocionId = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); return $promocionId; } function GetBuenFinId() { $sql = 'SELECT promocionId FROM promocion WHERE tipo = "BuenFin" LIMIT 1'; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $promocionId = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); return $promocionId; } function GetBuenFinIdActivo() { $sql = 'SELECT promocionId FROM promocion WHERE tipo = "BuenFin" AND status = "Activo" LIMIT 1'; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $promocionId = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); return $promocionId; } }//Promocion ?>