totalBonificacion = $value; } function setTotalDevolucion($value) { $this->totalDevolucion = $value; } function setSearch($value) { $this->search = $value; } public function setTipo($value) { //$this->Util()->ValidateString($value, $max_chars=255, $minChars = 1, "Justificacion"); $this->tipo = $value; } public function setJustificanteRechazo($value) { $this->Util()->ValidateString($value, $max_chars=255, $minChars = 1, "Justificacion"); $this->justificanteRechazo = $value; } public function setStatus($value) { //$this->Util()->ValidateInteger($value); $this->status = $value; } public function setBonificacionId($value) { $this->Util()->ValidateInteger($value); $this->bonificacionId = $value; } public function setRestante($value) { //$this->Util()->ValidateInteger($value); $this->restante = $value; } public function setCantidad($value) { //$this->Util()->ValidateInteger($value); $this->cantidad = $value; } public function setPorcentajeBonifica($value) { //$this->Util()->ValidateInteger($value); $this->porcentajeBonifica = $value; } public function setPagoTotal($value) { //$this->Util()->ValidateInteger($value); $this->pagoTotal = $value; } public function setPorcentajeVendido($value) { //$this->Util()->ValidateInteger($value); $this->porcentajeVendido = $value; } public function setPorcentajeAplicado($value) { //$this->Util()->ValidateInteger($value); $this->porcentajeAplicado = $value; } public function setVendido($value) { //$this->Util()->ValidateInteger($value); $this->vendido = $value; } public function setDisponible($value) { //$this->Util()->ValidateInteger($value); $this->disponible = $value; } public function setTotal($value) { //$this->Util()->ValidateInteger($value); $this->total = $value; } public function setCosto($value) { //$this->Util()->ValidateInteger($value); $this->costo = $value; } function setPorcentaje($value){ $this->porcentaje = $value; } public function setProductoId($value) { $this->Util()->ValidateInteger($value); $this->productoId = $value; } public function setPedidoId($value) { $this->Util()->ValidateInteger($value); $this->pedidoId = $value; } public function setProdItemId($value) { $this->Util()->ValidateInteger($value); $this->prodItemId = $value; } public function setProveedorId($value) { $this->Util()->ValidateInteger($value); $this->proveedorId = $value; } public function setFolioProv($value) { $this->folioProv = $value; } public function searchProductoById() { $sql = 'SELECT * FROM producto LEFT JOIN pedidoProducto ON(pedidoProducto.productoId = producto.productoId) LEFT JOIN pedido ON(pedido.pedidoId = pedidoProducto.pedidoId) LEFT JOIN productoItem ON(productoItem.productoId = producto.productoId) WHERE pedido.pedidoId = '.$this->pedidoId.' AND producto.productoId = '.$this->productoId; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $producto = $this->Util()->DBSelect($_SESSION['empresaId'])->GetRow(); return $producto; } public function Save() { $sql = "INSERT INTO bonificacion( `prodItemId`, `proveedorId`, `pedidoId`, `productoId`, `porcentajeBonifica`, `totalBonificacion`, `restanteBonificacion`, `porcentajeAplicado`, `fechaBonificacion`, `totalProductos`, `costoProducto`, `disponible`, `vendido`, `porcentajeVendido`, `cantidad`, `tipo`) VALUES ('".$this->prodItemId."', '".$this->proveedorId."', '".$this->pedidoId."', '".$this->productoId."', '".$this->porcentajeBonifica."', '".$this->pagoTotal."', '".$this->restante."', '".$this->porcentajeAplicado."', '".$this->Util()->TodayHour()."', '".$this->total."', '".$this->costo."', '".$this->disponible."', '".$this->vendido."', '".$this->porcentajeVendido."', '".$this->cantidad."', '".$this->tipo."')"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->InsertData(); $this->Util()->setError(30066, "complete"); $this->Util()->PrintErrors(); return true; } public function checkBonificacion() { $value = true; $sql = "SELECT COUNT(*) FROM bonificacion WHERE proveedorId = '".$this->proveedorId."' AND pedidoId = '".$this->pedidoId."' AND productoId = '".$this->productoId."'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); if($this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle() > 0) $value = false; return $value; } function checkBonificacion2() { $value = true; $sql = "SELECT COUNT(*) FROM bonificacion WHERE proveedorId = '".$this->proveedorId."' AND pedidoId = '".$this->pedidoId."' AND productoId = '".$this->productoId."' AND estatus LIKE 'Aprobado'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $aprobado = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); $sql = "SELECT COUNT(*) FROM bonificacion WHERE proveedorId = '".$this->proveedorId."' AND pedidoId = '".$this->pedidoId."' AND productoId = '".$this->productoId."' AND estatus LIKE 'Pendiente'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $pendiente = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); $sql = "SELECT COUNT(*) FROM bonificacion WHERE proveedorId = '".$this->proveedorId."' AND pedidoId = '".$this->pedidoId."' AND productoId = '".$this->productoId."' AND estatus LIKE 'Aprobado' AND tipo LIKE 'Devolucion'"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $devolucion = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); if($aprobado >= 2 || $pendiente > 0 || $devolucion > 0) $value = false; return $value; } function Enumerate() { $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("SELECT COUNT(*) FROM bonificacion"); $total = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); $pages = $this->Util->HandleMultipages($this->page, $total ,WEB_ROOT."/bonificaciones-pendientes"); //$sqlAdd = " LIMIT ".$pages["start"].", ".$pages["items_per_page"]; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("SELECT * FROM bonificacion ORDER BY fechaBonificacion ASC".$sqlAdd); $bonificaciones = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult(); $data["items"] = $bonificaciones; $data["pages"] = $pages; return $data; } function updateStatus() { $fecha = $this->Util()->Today(); $sql = "INSERT INTO pedidoBonifDevolucion(pedidoId, totalBonificacion, totalDevolucion, fechaAplicado) VALUES(".$this->pedidoId.",".$this->totalBonificacion.",".$this->totalDevolucion.",'".$fecha."')"; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->InsertData(); $sql = "SELECT pedidoBonifDevolucionId FROM pedidoBonifDevolucion WHERE pedidoId = ".$this->pedidoId." AND totalBonificacion = ".$this->totalBonificacion." AND totalDevolucion = ".$this->totalDevolucion." AND fechaAplicado = '".$fecha."' ORDER BY fechaAplicado DESC"; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $pedidoBonifDevolucionId = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle(); $sql = "SELECT * FROM bonificacion WHERE pedidoId = ".$this->pedidoId." AND estatus LIKE 'Pendiente'"; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $resultBonif = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult(); $sql = "UPDATE bonificacion SET estatus = 'Aprobado', cantidad = totalBonificacion, pedidoBonifDevolucionId = ".$pedidoBonifDevolucionId." WHERE pedidoId = ".$this->pedidoId." AND estatus LIKE 'Pendiente'"; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->UpdateData(); foreach($resultBonif as $key => $result) { $sql = "SELECT * FROM producto WHERE productoId = ".$result['productoId']; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $prodInfo = $this->Util()->DBSelect($_SESSION['empresaId'])->GetRow(); $nuevoPrecioVenta = $prodInfo['precioVentaIva']-($prodInfo['precioVentaIva']*($result['porcentajeAplicado']/100)); $nuevoCosto = $prodInfo['costo']-($prodInfo['costo']*($result['porcentajeAplicado']/100)); if($result['tipo'] == "Devolucion") { $sql = "UPDATE inventario SET status = 'Devolucion' WHERE pedidoId = ".$result['pedidoId']." AND productoId = ".$result['productoId']." AND `status` LIKE 'Disponible'"; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->UpdateData(); $sql = "SELECT sucursalId, pedidoId, COUNT(inventarioId) AS cantidadProd FROM inventario WHERE pedidoId = '".$result['pedidoId']."' AND productoId = '".$result['productoId']."' AND `status` LIKE 'Devolucion' GROUP BY sucursalId"; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $devolucionDetails = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult(); foreach($devolucionDetails as $key => $dev) { $costoDevolucion = $prodInfo['costo']*$dev['cantidadProd']; $sql = "INSERT INTO envioDevolucion(sucursalId, pedidoId, productoId, proveedorId, cantidadProd, total, fecha) VALUES('".$dev['sucursalId']."','".$dev['pedidoId']."', '".$prodInfo['productoId']."', '".$prodInfo['proveedorId']."','".$dev['cantidadProd']."','".$costoDevolucion."','".$this->Util()->Today()."')"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->InsertData(); } }else { $sql = "UPDATE inventario SET rebajado = '1', precioVenta = ".$nuevoPrecioVenta." WHERE pedidoId = ".$result['pedidoId']." AND productoId = ".$result['productoId']." AND `status` LIKE 'Disponible'"; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->UpdateData(); $sql = "UPDATE producto SET costo = ".$nuevoCosto." WHERE productoId = ".$result['productoId']; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $this->Util()->DBSelect($_SESSION['empresaId'])->UpdateData(); } } $this->Util()->setError(30067, 'complete'); $this->Util()->PrintErrors(); return true; } function getBonificaciones() { $sql = 'SELECT totalBonif FROM pedido WHERE pedidoId = '.$this->pedidoId; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $total = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle(); return $total; } function getDevoluciones() { $sql = 'SELECT SUM(totalDevolucion) FROM pedidoBonifDevolucion WHERE pedidoId = '.$this->pedidoId; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $producto = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle(); return $producto; } public function SaveDevolucion() { $sql = "INSERT INTO devolucionPedido( `prodItemId`, `proveedorId`, `pedidoId`, `productoId`, `totalDevolucion`, `porcentajeAplicado`, `fechaDevolucion`, `totalProductos`, `costoProducto`, `disponible`, `vendido`, `porcentajeVendido`, `cantidad`) VALUES ('".$this->prodItemId."', '".$this->proveedorId."', '".$this->pedidoId."', '".$this->productoId."', '".$this->pagoTotal."', '".$this->porcentajeAplicado."', '".$this->Util()->TodayHour()."', '".$this->total."', '".$this->costo."', '".$this->disponible."', '".$this->vendido."', '".$this->porcentajeVendido."', '".$this->cantidad."')"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $this->Util()->DBSelect($_SESSION["empresaId"])->InsertData(); $this->Util()->setError(30066, "complete"); $this->Util()->PrintErrors(); return true; } function EnumerateSearch() { if($this->status != "Todos") $sqlAdd1 = " AND estatus LIKE '".$this->status."' "; if($this->pedidoId != 0 && $this->pedidoId != null && $this->pedidoId != "") $sqlAdd2 = " AND pedidoId = '".$this->pedidoId."' "; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("SELECT COUNT(*) FROM bonificacion INNER JOIN proveedor ON(proveedor.proveedorId = bonificacion.proveedorId) WHERE proveedor.nombre LIKE '%".$this->search."%'".$sqlAdd1.$sqlAdd2); $total = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); $pages = $this->Util->HandleMultipages($this->page, $total ,WEB_ROOT."/bonificaciones-pendientes"); $sqlAdd = " LIMIT ".$pages["start"].", ".$pages["items_per_page"]; //echo "SELECT * FROM bonificacion INNER JOIN proveedor ON(proveedor.proveedorId = bonificacion.proveedorId) WHERE proveedor.nombre LIKE '%".$this->search."%'".$sqlAdd1.$sqlAdd2." ORDER BY fechaBonificacion ASC".$sqlAdd; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("SELECT * FROM bonificacion INNER JOIN proveedor ON(proveedor.proveedorId = bonificacion.proveedorId) WHERE proveedor.nombre LIKE '%".$this->search."%'".$sqlAdd1.$sqlAdd2." ORDER BY fechaBonificacion ASC".$sqlAdd); $bonificaciones = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult(); $data["items"] = $bonificaciones; $data["pages"] = $pages; return $data; } function GetPedidos() { if($this->status != "Todos") $sqlAdd1 = " AND estatus LIKE '".$this->status."' "; if($this->pedidoId != 0 && $this->pedidoId != null && $this->pedidoId != "") $sqlAdd2 = " AND bonificacion.pedidoId = '".$this->pedidoId."' "; $sql = "SELECT bonificacion.pedidoId, proveedor.nombre, bonificacion.proveedorId , bonificacion.estatus, pedidoBonifDevolucion.totalBonificacion AS totalBonificacion2, pedidoBonifDevolucion.totalDevolucion FROM bonificacion LEFT JOIN proveedor ON(proveedor.proveedorId = bonificacion.proveedorId) LEFT JOIN pedidoBonifDevolucion ON(pedidoBonifDevolucion.pedidoBonifDevolucionId = bonificacion.pedidoBonifDevolucionId) WHERE proveedor.nombre LIKE '%".$this->search."%'".$sqlAdd1.$sqlAdd2." GROUP BY bonificacion.pedidoId ORDER BY bonificacion.pedidoId"; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $pedidos = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult(); return $pedidos; } function GetBonifByPedido(){ $sql = 'SELECT * FROM bonificacion WHERE pedidoId = "'.$this->pedidoId.'"'; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $bonificaciones = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult(); return $bonificaciones; } function EnumProdsByPedido(){ if($this->productoId) $sqlAdd = ' AND prod.productoId = "'.$this->productoId.'"'; $sql = 'SELECT prod.*, p.totalDesc FROM pedido p, pedidoProducto prod WHERE p.pedidoId = prod.pedidoId AND p.pedidoId = "'.$this->pedidoId.'"'.$sqlAdd; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $productos = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult(); return $productos; } function CantVtasByProd(){ $sql = 'SELECT SUM(cantidad) FROM inventario WHERE productoId = "'.$this->productoId.'" AND pedidoId = "'.$this->pedidoId.'"'; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $total = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle(); return $total; } function GetPorcBonif(){ $sql = 'SELECT * FROM politicaBD WHERE tipo = "Bonificacion" AND baja = "0" ORDER BY porcentajeEvaluacion DESC'; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $politicas = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult(); foreach($politicas as $key => $res) { $porcentaje1 = $res['porcentajeEvaluacion']; if(isset($politicas[$key+1]['porcentajeEvaluacion'])) $porcentaje2 = $politicas[$key+1]['porcentajeEvaluacion']; else $porcentaje2 = 0; //Porc1 = 70, Porc2 = 65 ::::: Porc1 = 65, Porc2= 60 if($this->porcentaje >= $porcentaje2 && $this->porcentaje < $porcentaje1) return $res['porcentajeBonificacion']; } } function EnumBonifDev() { $sql = "SELECT COUNT(*) FROM bonifDev"; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $total = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle(); $pages = $this->Util->HandleMultipages($this->page, $total ,WEB_ROOT."/bonificaciones"); $sqlAdd = "LIMIT ".$pages["start"].", ".$pages["items_per_page"]; $sql = "SELECT * FROM bonifDev ORDER BY fecha DESC ".$sqlAdd; $this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql); $result = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult(); $data["items"] = $result; $data["pages"] = $pages; return $data; } function GetPedidoByFolio(){ $sql = 'SELECT * FROM pedido WHERE (folioProv = "'.$this->folioProv.'" OR folioProv2 = "'.$this->folioProv.'" OR folioProv3 = "'.$this->folioProv.'" OR folioProv4 = "'.$this->folioProv.'" OR folioProv5 = "'.$this->folioProv.'") ORDER BY noPedido ASC'; $this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql); $row = $this->Util()->DBSelect($_SESSION['empresaId'])->GetRow(); return $row; } } ?>