643 lines
15 KiB
PHP
Executable File
643 lines
15 KiB
PHP
Executable File
<?php
|
|
|
|
class Devolucion extends Main
|
|
{
|
|
private $devolucionId;
|
|
private $devCedisId;
|
|
private $ventaId;
|
|
private $sucursalId;
|
|
private $usuarioId;
|
|
private $fecha;
|
|
private $productoId;
|
|
private $prodItemId;
|
|
private $cantidad;
|
|
private $disponible;
|
|
private $subtotal;
|
|
private $iva;
|
|
private $total;
|
|
private $precioUnitario;
|
|
|
|
private $fechaI;
|
|
private $fechaF;
|
|
|
|
public function setDevolucionId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->devolucionId = $value;
|
|
}
|
|
|
|
public function setDevCedisId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->devCedisId = $value;
|
|
}
|
|
|
|
public function setVentaId($value)
|
|
{
|
|
$this->Util()->ValidateInteger($value);
|
|
$this->ventaId = $value;
|
|
}
|
|
|
|
public function setSucursalId($value)
|
|
{
|
|
$this->sucursalId = $value;
|
|
}
|
|
|
|
public function setUsuarioId($value)
|
|
{
|
|
$this->usuarioId = $value;
|
|
}
|
|
|
|
public function setFecha($value)
|
|
{
|
|
$this->fecha = $value;
|
|
}
|
|
|
|
public function setProductoId($value)
|
|
{
|
|
$this->productoId = $value;
|
|
}
|
|
|
|
public function setProdItemId($value)
|
|
{
|
|
$this->prodItemId = $value;
|
|
}
|
|
|
|
public function setCantidad($value)
|
|
{
|
|
$this->cantidad = $value;
|
|
}
|
|
|
|
public function setDisponible($value)
|
|
{
|
|
$this->disponible = $value;
|
|
}
|
|
|
|
public function setPrecioUnitario($value)
|
|
{
|
|
$this->precioUnitario = $value;
|
|
}
|
|
|
|
public function setSubtotal($value)
|
|
{
|
|
$this->subtotal = $value;
|
|
}
|
|
|
|
public function setIva($value)
|
|
{
|
|
$this->iva = $value;
|
|
}
|
|
|
|
public function setTotal($value)
|
|
{
|
|
$this->total = $value;
|
|
}
|
|
|
|
public function setFechaI($value)
|
|
{
|
|
$this->fechaI = $value;
|
|
}
|
|
|
|
public function setFechaF($value)
|
|
{
|
|
$this->fechaF = $value;
|
|
}
|
|
|
|
function Info()
|
|
{
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("
|
|
SELECT * FROM devolucion
|
|
WHERE devolucionId ='".$this->devolucionId."'"
|
|
);
|
|
$info = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow();
|
|
|
|
return $info;
|
|
}
|
|
|
|
function InfoVenta()
|
|
{
|
|
$sql = "SELECT * FROM venta WHERE ventaId = '".$this->ventaId."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$info = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow();
|
|
|
|
return $info;
|
|
}
|
|
|
|
function GetCantAllProds(){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM ventaProducto
|
|
WHERE ventaId = "'.$this->ventaId.'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
return $total;
|
|
|
|
}
|
|
|
|
function Enumerate()
|
|
{
|
|
if($this->sucursalId)
|
|
$sqlFilter = ' AND sucursalId = '.$this->sucursalId;
|
|
|
|
$sql = "SELECT COUNT(*) FROM devolucion WHERE 1 ".$sqlFilter;
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
$pages = $this->Util->HandleMultipages($this->page, $total ,WEB_ROOT."/devoluciones");
|
|
|
|
$sqlAdd = "LIMIT ".$pages["start"].", ".$pages["items_per_page"];
|
|
|
|
$sql = "SELECT *
|
|
FROM devolucion
|
|
WHERE 1 ".$sqlFilter."
|
|
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;
|
|
|
|
}//Enumerate
|
|
|
|
function EnumerateCedis()
|
|
{
|
|
$sql = "SELECT COUNT(*) FROM devolucionCedis";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
$pages = $this->Util->HandleMultipages($this->page, $total ,WEB_ROOT."/devoluciones");
|
|
|
|
$sqlAdd = "LIMIT ".$pages["start"].", ".$pages["items_per_page"];
|
|
|
|
$sql = "SELECT *
|
|
FROM devolucionCedis
|
|
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;
|
|
|
|
}//EnumerateCedis
|
|
|
|
function Save(){
|
|
|
|
if($this->Util()->PrintErrors()){
|
|
return false;
|
|
}
|
|
|
|
$sql = "INSERT INTO devolucion
|
|
(
|
|
sucursalId,
|
|
ventaId,
|
|
usuarioId,
|
|
fecha,
|
|
total,
|
|
usado
|
|
)
|
|
VALUES (
|
|
'".$this->sucursalId."',
|
|
'".$this->ventaId."',
|
|
'".$this->usuarioId."',
|
|
'".$this->fecha."',
|
|
'".$this->total."',
|
|
'0'
|
|
)";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$devolucionId = $this->Util()->DBSelect($_SESSION['empresaId'])->InsertData();
|
|
|
|
return $devolucionId;
|
|
|
|
}
|
|
|
|
function SaveProducto(){
|
|
|
|
$sql = "INSERT INTO devolucionProducto
|
|
(
|
|
devolucionId,
|
|
ventaId,
|
|
prodItemId,
|
|
productoId,
|
|
cantidad,
|
|
precioUnitario,
|
|
total
|
|
)
|
|
VALUES (
|
|
'".$this->devolucionId."',
|
|
'".$this->ventaId."',
|
|
'".$this->prodItemId."',
|
|
'".$this->productoId."',
|
|
'".$this->cantidad."',
|
|
'".$this->precioUnitario."',
|
|
'".$this->total."'
|
|
)";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->InsertData();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function GetNextFolio(){
|
|
|
|
$sql = 'SHOW TABLE STATUS LIKE "devolucion"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$row = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow();
|
|
|
|
return $row['Auto_increment'];
|
|
|
|
}
|
|
|
|
function GetProductos(){
|
|
|
|
$sql = 'SELECT * FROM devolucionProducto
|
|
WHERE devolucionId = "'.$this->devolucionId.'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
function GetProductosReporte(){
|
|
|
|
$sql = 'SELECT devolucionProducto.cantidad * producto.costo AS importe FROM devolucionProducto
|
|
LEFT JOIN producto ON producto.productoId = devolucionProducto.productoId
|
|
WHERE devolucionId = "'.$this->devolucionId.'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION["empresaId"])->GetResult();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
function GetSumProductosReporte(){
|
|
|
|
$sql = 'SELECT SUM(devolucionProducto.cantidad * producto.costo) AS importe FROM devolucionProducto
|
|
LEFT JOIN producto ON producto.productoId = devolucionProducto.productoId
|
|
WHERE devolucionId = "'.$this->devolucionId.'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
function GetCantProdsByItem(){
|
|
|
|
$sql = 'SELECT SUM(cantidad) FROM devolucionProducto
|
|
WHERE devolucionId = "'.$this->devolucionId.'"
|
|
AND prodItemId = "'.$this->prodItemId.'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$total = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
return $total;
|
|
|
|
}
|
|
|
|
function GetSaldo(){
|
|
|
|
$sql= 'SELECT total FROM devolucion
|
|
WHERE ventaId = "'.$this->ventaId.'"
|
|
AND usado = "0"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$saldo = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
return $saldo;
|
|
}
|
|
|
|
function ExistTicketSaldo(){
|
|
|
|
$sql= 'SELECT devolucionId FROM devolucion
|
|
WHERE ventaId = "'.$this->ventaId.'"
|
|
AND usado = "0"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$devolucionId = $this->Util()->DBSelect($_SESSION["empresaId"])->GetSingle();
|
|
|
|
return $devolucionId;
|
|
}
|
|
|
|
function UpdateUsado(){
|
|
|
|
$sql = 'UPDATE devolucion SET usado = "1" WHERE ventaId = "'.$this->ventaId.'"';
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->UpdateData();
|
|
|
|
return true;
|
|
}
|
|
|
|
function GetNextNoDevCedis(){
|
|
|
|
$sql = "SHOW TABLE STATUS LIKE 'devolucionCedis'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$row = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow();
|
|
|
|
return $row['Auto_increment'];
|
|
|
|
}//GetNextNoDevCedis
|
|
|
|
function GetInsertIdCedis(){
|
|
|
|
$sql = "SELECT MAX(devCedisId) FROM devolucionCedis";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$devCedisId = $this->Util()->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
return $devCedisId;
|
|
|
|
}//GetInsertIdCedis
|
|
|
|
function SaveDevCedis(){
|
|
|
|
$sql = "INSERT INTO devolucionCedis
|
|
(
|
|
fecha,
|
|
usuarioId
|
|
)
|
|
VALUES (
|
|
'".$this->fecha."',
|
|
'".$this->usuarioId."'
|
|
)";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->InsertData();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function SaveProdCedis(){
|
|
|
|
$sql = "INSERT INTO devolucionProdCedis
|
|
(
|
|
devCedisId,
|
|
sucursalId,
|
|
productoId,
|
|
cantidad,
|
|
disponible
|
|
)
|
|
VALUES (
|
|
'".$this->devCedisId."',
|
|
'".$this->sucursalId."',
|
|
'".$this->productoId."',
|
|
'".$this->cantidad."',
|
|
'".$this->disponible."'
|
|
)";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->InsertData();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function DeleteCedis(){
|
|
|
|
$sql = "DELETE FROM
|
|
devolucionCedis
|
|
WHERE
|
|
devCedisId = '".$this->devCedisId."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData();
|
|
|
|
$sql = "DELETE FROM
|
|
devolucionProdCedis
|
|
WHERE
|
|
devCedisId = '".$this->devCedisId."'";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->DeleteData();
|
|
|
|
$this->Util()->setError(20128, "complete");
|
|
$this->Util()->PrintErrors();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function InfoCedis(){
|
|
|
|
$sql = "SELECT * FROM devolucionCedis WHERE devCedisId = '".$this->devCedisId."'";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$row = $this->Util()->DBSelect($_SESSION['empresaId'])->GetRow();
|
|
|
|
return $row;
|
|
|
|
}//InfoCedis
|
|
|
|
function GetProdsCedis(){
|
|
|
|
$sql = "SELECT * FROM devolucionProdCedis WHERE devCedisId = '".$this->devCedisId."'";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $result;
|
|
|
|
}//GetProdsCedis
|
|
|
|
function UpdateDevProd(){
|
|
|
|
$sql = "UPDATE inventario SET status = 'Devuelto', devCedisId = '".$this->devCedisId."'
|
|
WHERE productoId = '".$this->productoId."'
|
|
AND sucursalId = '".$this->sucursalId."'
|
|
AND status = 'Disponible'
|
|
LIMIT ".$this->cantidad;
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->UpdateData();
|
|
|
|
}//UpdateDevProd
|
|
|
|
function UpdateDispProd(){
|
|
|
|
$sql = "UPDATE inventario SET status = 'Disponible', devCedisId = 0
|
|
WHERE devCedisId = '".$this->devCedisId."'";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->UpdateData();
|
|
|
|
}//UpdateDispProd
|
|
|
|
function CancelarTicket(){
|
|
|
|
global $venta;
|
|
global $sucursal;
|
|
|
|
$sucursalId = $this->sucursalId;
|
|
|
|
$infD = $this->Info();
|
|
|
|
$ventaId = $infD['ventaId'];
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$pagos = $venta->GetPagos();
|
|
$infV = $venta->Info();
|
|
|
|
$idVendedor = $infV['vendedorId'];
|
|
$totalPago = $infV['pago'];
|
|
|
|
$productos = $venta->GetProdsNoDev();
|
|
|
|
if(count($productos) == 0){
|
|
//Cancelamos el status del ticket original
|
|
$venta->setVentaId($infD['ventaId']);
|
|
$venta->setStatus('Cancelado');
|
|
$venta->UpdateStatusCancel();
|
|
return;
|
|
}
|
|
|
|
$totalVta = 0;
|
|
foreach($productos as $res){
|
|
|
|
$total = $res['total'];
|
|
|
|
$productoId = $res['productoId'];
|
|
$cantidad = $res['cantidad'];
|
|
|
|
$valDesc = $res['valDesc'];
|
|
if($res['tipoDesc'] == 'Dinero')
|
|
$total -= $valDesc * $res['cantidad'];
|
|
elseif($res['tipoDesc'] == 'Porcentaje')
|
|
$total -= $total * ($valDesc / 100);
|
|
|
|
//$total = number_format($total,2,'.','');
|
|
|
|
$totalVta += $total;
|
|
|
|
}//foreach
|
|
|
|
//Calculamos el Subtotal y el Iva
|
|
|
|
$sucursal->setSucursalId($sucursalId);
|
|
$porcIva = $sucursal->GetIva();
|
|
$porcIva = $porcIva / 100;
|
|
|
|
$subtotal = $totalVta / (1 + $porcIva);
|
|
$subtotal = number_format($subtotal,2,'.','');
|
|
|
|
$iva = $subtotal * $porcIva;
|
|
$iva = number_format($iva,2,'.','');
|
|
|
|
$fecha = date('Y-m-d H:i:s');
|
|
|
|
$venta->setSucursalId($sucursalId);
|
|
$folio = $venta->GetNextFolio();
|
|
|
|
$venta->setSucursalId($sucursalId);
|
|
$venta->setUsuarioId($_SESSION['loginKey']);
|
|
$venta->setVendedorId($idVendedor);
|
|
$venta->setFolio($folio);
|
|
$venta->setFecha($fecha);
|
|
$venta->setPromocionId(0);
|
|
$venta->setSubtotal($subtotal);
|
|
$venta->setIva($iva);
|
|
$venta->setTotal($totalVta);
|
|
$venta->setPago($totalPago);
|
|
$venta->setStatus('Activo');
|
|
|
|
$ventaId = $venta->Save();
|
|
|
|
//Checamos si hay Descuento Global
|
|
|
|
if($infV['tipoDesc'] != ''){
|
|
|
|
$descVal = 0;
|
|
if($infV['tipoDesc'] == 'Dinero')
|
|
$descVal = $infV['valDesc'];
|
|
elseif($infV['tipoDesc'] == 'Porcentaje')
|
|
$descVal = $total * ($infV['valDesc']/100);
|
|
|
|
$totalVta -= $descVal;
|
|
|
|
//Obtenemos los Totales
|
|
|
|
$subtotal = $totalVta / (1 + $porcIva);
|
|
$subtotal = number_format($subtotal,2,'.','');
|
|
|
|
$iva = $subtotal * $porcIva;
|
|
$iva = number_format($iva,2,'.','');
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$venta->setTipoDesc($infV['tipoDesc']);
|
|
$venta->setValDesc($infV['valDesc']);
|
|
$venta->setSubtotal($subtotal);
|
|
$venta->setIva($iva);
|
|
$venta->setTotal($totalVta);
|
|
|
|
$venta->UpdateDescVta();
|
|
|
|
$venta->setStatus('Activo');
|
|
$venta->UpdateStatus();
|
|
|
|
}//if
|
|
|
|
//Guardamos los Productos
|
|
|
|
foreach($productos as $res){
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$venta->setCantidad($res['cantidad']);
|
|
$venta->setPrecioUnitario($res['precioUnitario']);
|
|
$venta->setTotal($res['total']);
|
|
|
|
$venta->setProdItemId($res['prodItemId']);
|
|
$venta->setProductoId($res['productoId']);
|
|
$venta->setMonederoId($res['monederoId']);
|
|
$venta->setPromocionId($res['promocionId']);
|
|
|
|
$venta->setTipoDesc($res['tipoDesc']);
|
|
$venta->setValDesc($res['valDesc']);
|
|
|
|
$venta->SaveProducto();
|
|
|
|
}//foreach
|
|
|
|
//Guardamos los Pagos
|
|
|
|
foreach($pagos as $res){
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$venta->setMetodoPagoId($res['metodoPagoId']);
|
|
$venta->setMetodoPagoId($res['metodoPagoId']);
|
|
$venta->setMonederoId($res['monederoId']);
|
|
$venta->setDevolucionId($res['devolucionId']);
|
|
$venta->setCantidad($res['cantidad']);
|
|
|
|
$venta->SavePago();
|
|
|
|
}//foreach
|
|
|
|
//Guardamos la Venta Anterior del Ticket Nuevo
|
|
$venta->setVentaId($ventaId);
|
|
$venta->UpdateVentaAnt($infD['ventaId']);
|
|
|
|
//Cancelamos el status del ticket original
|
|
$venta->setVentaId($infD['ventaId']);
|
|
$venta->setStatus('Cancelado');
|
|
$venta->UpdateStatusCancel();
|
|
|
|
return true;
|
|
|
|
}//CancelarTicket
|
|
|
|
function Search(){
|
|
|
|
$sqlFilter = '';
|
|
|
|
if($this->usuarioId)
|
|
$sqlFilter .= ' AND usuarioId = '.$this->usuarioId;
|
|
|
|
$sql = "SELECT * FROM devolucion
|
|
WHERE sucursalId = '".$this->sucursalId."'
|
|
AND fecha >= '".$this->fechaI." 00:00:00'
|
|
AND fecha <= '".$this->fechaF." 23:59:59'
|
|
".$sqlFilter."
|
|
ORDER BY fecha DESC";
|
|
$this->Util()->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$result = $this->Util()->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
return $result;
|
|
|
|
}//Search
|
|
|
|
}//Devolucion
|
|
|
|
?>
|