561 lines
14 KiB
PHP
Executable File
561 lines
14 KiB
PHP
Executable File
<?php
|
|
|
|
include_once('../init.php');
|
|
include_once('../config.php');
|
|
include_once(DOC_ROOT.'/libraries.php');
|
|
|
|
session_start();
|
|
|
|
$sucursalId = $_SESSION['idSuc'];
|
|
|
|
$Usr = $user->Info();
|
|
$smarty->assign('Usr', $Usr);
|
|
|
|
if(isset($_POST['action']))
|
|
$_POST['type'] = $_POST['action'];
|
|
|
|
switch($_POST["type"]){
|
|
|
|
case 'addDevolucion':
|
|
|
|
$smarty->assign('DOC_ROOT', DOC_ROOT);
|
|
$smarty->display(DOC_ROOT.'/templates/boxes/agregar-devolucion-popup.tpl');
|
|
|
|
break;
|
|
|
|
case 'saveDevolucion':
|
|
|
|
$ventaId = $_POST['ventaId'];
|
|
$codigo = strtoupper(trim($_POST['codigo']));
|
|
$conceptosD = $_SESSION['conceptosD'];
|
|
|
|
if(count($conceptosD) == 0){
|
|
echo 'fail[#]';
|
|
echo 'Debe agregar al menos un producto.';
|
|
exit;
|
|
}
|
|
|
|
//Obtenemos los Totales
|
|
|
|
$total = 0;
|
|
foreach($conceptosD as $res)
|
|
$total += $res['total'];
|
|
|
|
$card['total'] = $total;
|
|
$card['ventaId'] = $ventaId;
|
|
$_SESSION['infDev'] = $card;
|
|
|
|
echo 'ok[#]';
|
|
exit;
|
|
|
|
//Obtenemos la informacion de la Venta
|
|
/*
|
|
$devolucion->setVentaId($ventaId);
|
|
$infV = $devolucion->InfoVenta();
|
|
$totalP = $devolucion->GetCantAllProds();
|
|
|
|
$fecha = date('Y-m-d H:i:s');
|
|
|
|
$devolucion->setVentaId($ventaId);
|
|
$devolucion->setSucursalId($sucursalId);
|
|
$devolucion->setUsuarioId($_SESSION['loginKey']);
|
|
$devolucion->setFecha($fecha);
|
|
$devolucion->setTotal($total);
|
|
|
|
$devolucionId = $devolucion->Save();
|
|
*/
|
|
|
|
//Guardamos los Productos
|
|
/*
|
|
$totalProdDev = 0;
|
|
foreach($conceptosD as $res){
|
|
|
|
$prodItemId = $res['prodItemId'];
|
|
|
|
$producto->setProdItemId($prodItemId);
|
|
$info = $producto->GetInfoItemById();
|
|
|
|
$devolucion->setDevolucionId($devolucionId);
|
|
$devolucion->setProdItemId($prodItemId);
|
|
$devolucion->setProductoId($info['productoId']);
|
|
$devolucion->setCantidad($res['cantidad']);
|
|
$devolucion->setPrecioUnitario($res['precio']);
|
|
$devolucion->setTotal($res['total']);
|
|
|
|
$devolucion->SaveProducto();
|
|
|
|
$totalProdDev += $res['cantidad'];
|
|
|
|
}//foreach
|
|
*/
|
|
/*
|
|
$valDesc = 0;
|
|
if($infV['tipoDesc'] == 'Dinero'){
|
|
$valDesc = $infV['valDesc'] / $totalP;
|
|
$valDesc = number_format($valDesc,2,'.','');
|
|
$valDesc = $infV['valDesc'] - ($valDesc * $totalProd);
|
|
$infV['valDesc'] = $valDesc;
|
|
$conDesc = true;
|
|
}elseif($infV['tipoDesc'] == 'Porcentaje'){
|
|
$valDesc = ($infV['valDesc'] / 100) * $totalDesc;
|
|
$valDesc = number_format($valDesc,2,'.','');
|
|
$conDesc = true;
|
|
}
|
|
*/
|
|
|
|
$conceptosD = array();
|
|
$_SESSION['conceptosD'] = array();
|
|
|
|
echo 'ok[#]';
|
|
echo $devolucionId;
|
|
|
|
break;
|
|
|
|
case 'getProdInfoDev':
|
|
|
|
$ventaId = $_POST['ventaId'];
|
|
$prodItemId = $_POST['prodItemId'];
|
|
|
|
$producto->setProdItemId($prodItemId);
|
|
$info = $producto->GetInfoItemById();
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$venta->setProdItemId($prodItemId);
|
|
$infP = $venta->InfoProducto();
|
|
|
|
$infV = $venta->Info();
|
|
$totalP = $venta->GetCantAllProds();
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$venta->setProdItemId($prodItemId);
|
|
$disponible = $venta->GetProdDispVta();
|
|
|
|
$conceptosD = $_SESSION['conceptosD'];
|
|
$conceptosD = $util->CheckArray($conceptosD);
|
|
|
|
foreach($conceptosD as $res){
|
|
if($res['prodItemId'] == $prodItemId)
|
|
$disponible -= $res['cantidad'];
|
|
}
|
|
|
|
$producto->setProdItemId($prodItemId);
|
|
$nombre = $producto->GetFullName();
|
|
|
|
$precioUni = $infP['precioUnitario'];
|
|
|
|
//Checamos si tiene descuento
|
|
if($infP['tipoDesc'] == 'Porcentaje'){
|
|
$totalDesc = ($infP['valDesc'] / 100) * $infP['precioUnitario'];
|
|
$precioUni = $precioUni - $totalDesc;
|
|
}else{
|
|
$precioUni = $precioUni - $infP['valDesc'];
|
|
}
|
|
|
|
if($infV['tipoDesc'] == 'Dinero'){
|
|
$valDesc = $infV['valDesc'] / $totalP;
|
|
$valDesc = number_format($valDesc,2,'.','');
|
|
$precioUni -= $valDesc;
|
|
}elseif($infV['tipoDesc'] == 'Porcentaje'){
|
|
$totalDesc = ($infV['valDesc'] / 100) * $precioUni;
|
|
$totalDesc = number_format($totalDesc,2,'.','');
|
|
$precioUni = $precioUni - $totalDesc;
|
|
}
|
|
|
|
if($precioUni == '')
|
|
$precioUni = '0.00';
|
|
|
|
echo 'ok[#]';
|
|
echo $precioUni;
|
|
echo '[#]';
|
|
echo $disponible;
|
|
echo '[#]';
|
|
echo $nombre;
|
|
|
|
break;
|
|
|
|
case 'getProdInfoDevByCode':
|
|
|
|
$ventaId = trim($_POST['ventaId']);
|
|
$codigoBarra = trim($_POST['codigoBarra']);
|
|
|
|
if($ventaId == ''){
|
|
echo 'fail[#]';
|
|
echo 'Por favor, ingrese el Folio Novomoda.';
|
|
exit;
|
|
}
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$infV = $venta->Info();
|
|
|
|
if($infV['sucursalId'] != $sucursalId){
|
|
echo 'fail[#]';
|
|
echo 'El folio no corresponde a esta sucursal. Por favor, verifique.';
|
|
exit;
|
|
}
|
|
|
|
$venta->setVentaId($ventaId);
|
|
if($venta->BuenFinAplicado()){
|
|
echo 'fail[#]';
|
|
echo 'La venta tiene promocion del Buen Fin aplicada. No se puede realizar la devolucion.';
|
|
exit;
|
|
}
|
|
|
|
$producto->setCodigoBarra($codigoBarra);
|
|
$prodItemId = $producto->GetProductByCodigo();
|
|
|
|
$producto->setProdItemId($prodItemId);
|
|
$info = $producto->GetInfoItemById();
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$venta->setProdItemId($prodItemId);
|
|
$infP = $venta->InfoProducto();
|
|
|
|
$venta->setProductoId($infP['productoId']);
|
|
if($venta->IsProdRebajado()){
|
|
echo 'fail[#]';
|
|
echo 'Lo sentimos, pero el producto ingresado tiene rebaja y no aplica para devolucion.';
|
|
exit;
|
|
}
|
|
|
|
$infV = $venta->Info();
|
|
$totalP = $venta->GetCantAllProds();
|
|
|
|
if($infV['status'] == "Cancelado"){
|
|
echo 'fail[#]';
|
|
echo 'Lo sentimos, pero la Nota de Venta se encuentra cancelada.';
|
|
exit;
|
|
}
|
|
|
|
if($infV['status'] == "Facturada"){
|
|
echo 'fail[#]';
|
|
echo 'Lo sentimos, pero la Nota de Venta se encuentra facturada. Debe cancelarla para poder realizar la devolucion.';
|
|
exit;
|
|
}
|
|
|
|
$fechaV = date('Y-m-d',strtotime($infV['fecha']));
|
|
$fechaHoy = date('Y-m-d');
|
|
$dias = $util->GetDiffDates($fechaV, $fechaHoy);
|
|
|
|
$rfc->setRfcId(1);
|
|
$infR = $rfc->Info();
|
|
|
|
$diasDevolucion = $infR['diasDevolucion'];
|
|
|
|
$aplicaDev = true;
|
|
if($dias > $diasDevolucion)
|
|
$aplicaDev = false;
|
|
|
|
if(!$aplicaDev){
|
|
echo 'fail[#]';
|
|
echo 'Lo sentimos, pero la Nota de Venta tiene mas de '.$diasDevolucion.' dias. ';
|
|
echo 'Por lo tanto no aplica la devolucion.';
|
|
exit;
|
|
}//else
|
|
|
|
/*
|
|
if($infV['promocionId']){
|
|
echo 'fail[#]';
|
|
echo 'Lo sentimos, pero por el momento no se pueden realizar devoluciones en ventas con promocion aplicada.';
|
|
exit;
|
|
}
|
|
*/
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$venta->setProdItemId($prodItemId);
|
|
$disponible = $venta->GetProdDispVta();
|
|
|
|
$conceptosD = $_SESSION['conceptosD'];
|
|
$conceptosD = $util->CheckArray($conceptosD);
|
|
|
|
foreach($conceptosD as $res){
|
|
if($res['prodItemId'] == $prodItemId)
|
|
$disponible -= $res['cantidad'];
|
|
}
|
|
|
|
$producto->setProductoId($info['productoId']);
|
|
$nombre = $producto->GetModeloById();
|
|
|
|
$precioUni = $infP['precioUnitario'];
|
|
|
|
//Checamos si tiene descuento
|
|
if($infP['tipoDesc'] == 'Porcentaje'){
|
|
$totalDesc = ($infP['valDesc'] / 100) * $infP['precioUnitario'];
|
|
$precioUni = $precioUni - $totalDesc;
|
|
}else{
|
|
$precioUni = $precioUni - $infP['valDesc'];
|
|
}
|
|
|
|
if($infV['tipoDesc'] == 'Dinero'){
|
|
$valDesc = $infV['valDesc'] / $totalP;
|
|
$valDesc = number_format($valDesc,2,'.','');
|
|
$precioUni -= $valDesc;
|
|
}elseif($infV['tipoDesc'] == 'Porcentaje'){
|
|
$totalDesc = ($infV['valDesc'] / 100) * $precioUni;
|
|
$totalDesc = number_format($totalDesc,2,'.','');
|
|
$precioUni = $precioUni - $totalDesc;
|
|
}
|
|
|
|
echo 'ok[#]';
|
|
echo number_format($precioUni,2,'.','');
|
|
echo '[#]';
|
|
echo $disponible;
|
|
echo '[#]';
|
|
echo utf8_encode($nombre);
|
|
echo '[#]';
|
|
echo $prodItemId;
|
|
|
|
break;
|
|
|
|
/*
|
|
case 'cobrarDev':
|
|
|
|
$conceptosD = $_SESSION['conceptosD'];
|
|
|
|
if(count($conceptosD) == 0){
|
|
echo 'fail[#]';
|
|
echo 'Debe agregar al menos un producto.';
|
|
exit;
|
|
}
|
|
|
|
$total = 0;
|
|
foreach($conceptosD as $res)
|
|
$total += $res['total'];
|
|
|
|
$total = number_format($total,2);
|
|
|
|
echo 'ok[#]';
|
|
|
|
$smarty->assign('total', $total);
|
|
$smarty->assign('DOC_ROOT', DOC_ROOT);
|
|
$smarty->display(DOC_ROOT.'/templates/boxes/cobrar-devolucion-popup.tpl');
|
|
|
|
break;
|
|
*/
|
|
|
|
case 'cancelarDevolucion':
|
|
|
|
$_SESSION['conceptosD'] = array();
|
|
|
|
$conceptosD = array();
|
|
|
|
echo 'ok[#]';
|
|
|
|
$smarty->assign('conceptos', $conceptosD);
|
|
$smarty->assign('DOC_ROOT', DOC_ROOT);
|
|
$smarty->display(DOC_ROOT.'/templates/lists/conceptos.tpl');
|
|
|
|
|
|
break;
|
|
|
|
case 'limpiarForm':
|
|
|
|
$conceptosD = array();
|
|
|
|
echo 'ok[#]';
|
|
|
|
$smarty->assign('conceptos', $conceptosD);
|
|
$smarty->assign('DOC_ROOT', DOC_ROOT);
|
|
$smarty->display(DOC_ROOT.'/templates/lists/conceptos.tpl');
|
|
|
|
break;
|
|
|
|
//PRODUCTOS
|
|
|
|
case 'addProduct':
|
|
|
|
$prodItemId = $_POST['prodItemId'];
|
|
$cantidad = $_POST['cantidad'];
|
|
$ventaId = $_POST['ventaId'];
|
|
|
|
$producto->setProdItemId($prodItemId);
|
|
$info = $producto->GetInfoItemById();
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$venta->setProdItemId($prodItemId);
|
|
$infP = $venta->InfoProducto();
|
|
|
|
$infV = $venta->Info();
|
|
$totalP = $venta->GetCantAllProds();
|
|
|
|
$name = $info['codigoBarra'].'<br>';
|
|
|
|
$producto->setProductoId($infP['productoId']);
|
|
$name .= $producto->GetModeloById();
|
|
|
|
//Checamos si tiene descuento
|
|
if($infP['tipoDesc'] == 'Porcentaje'){
|
|
$totalDesc = ($infP['valDesc'] / 100) * $infP['precioUnitario'];
|
|
$precioUni = $infP['precioUnitario'] - $totalDesc;
|
|
}else{
|
|
$precioUni = $infP['precioUnitario'] - $infP['valDesc'];
|
|
}
|
|
|
|
if($infV['tipoDesc'] == 'Dinero'){
|
|
|
|
$valDesc = $infV['valDesc'] / $totalP;
|
|
$valDesc = number_format($valDesc,2,'.','');
|
|
$precioUni -= $valDesc;
|
|
|
|
}elseif($infV['tipoDesc'] == 'Porcentaje'){
|
|
|
|
$totalDesc = ($infV['valDesc'] / 100) * $precioUni;
|
|
$totalDesc = number_format($totalDesc,2,'.','');
|
|
$precioUni = $precioUni - $totalDesc;
|
|
|
|
}
|
|
|
|
if($precioUni == '')
|
|
$precioUni = '0.00';
|
|
|
|
$card['productoId'] = $infP['productoId'];
|
|
$card['name'] = utf8_encode($name);
|
|
$card['prodItemId'] = $prodItemId;
|
|
$card['cantidad'] = $cantidad;
|
|
$card['descuento'] = '0.00';
|
|
$card['precio'] = $precioUni;
|
|
$total = $card['precio'] * $cantidad;
|
|
$card['total'] = number_format($total,2,'.','');
|
|
|
|
$conceptosD = $_SESSION['conceptosD'];
|
|
|
|
$conceptosD[] = $card;
|
|
|
|
$_SESSION['conceptosD'] = $conceptosD;
|
|
|
|
$total = 0;
|
|
foreach($conceptosD as $res)
|
|
$total += $res['total'];
|
|
|
|
//Agrupamos los Productos solo para Vista
|
|
|
|
$prodIds = array();
|
|
foreach($conceptosD as $res){
|
|
|
|
$productoId = $res['productoId'];
|
|
|
|
if(!in_array($productoId, $prodIds))
|
|
$prodIds[] = $productoId;
|
|
|
|
}//foreach
|
|
|
|
$card = array();
|
|
$concepts = array();
|
|
foreach($prodIds as $productoId){
|
|
|
|
$total2 = 0;
|
|
$precio = 0;
|
|
$cantidad = 0;
|
|
$card = array();
|
|
foreach($conceptosD as $res){
|
|
|
|
if($res['productoId'] == $productoId){
|
|
$card = $res;
|
|
|
|
if($res['precio'] > $precio)
|
|
$precio = $res['precio'];
|
|
|
|
$cantidad += $res['cantidad'];
|
|
|
|
if($res['descuento'] == '100%')
|
|
$res['total'] = 0;
|
|
|
|
$total2 += $res['total'];
|
|
}
|
|
|
|
}//foreach
|
|
|
|
$card['precio'] = $precio;
|
|
$card['cantidad'] = $cantidad;
|
|
$card['total'] = $total2;
|
|
|
|
$concepts[] = $card;
|
|
|
|
}//foreach
|
|
|
|
echo 'ok[#]';
|
|
|
|
$smarty->assign('conceptos', $concepts);
|
|
$smarty->assign('DOC_ROOT', DOC_ROOT);
|
|
$smarty->display(DOC_ROOT.'/templates/lists/conceptos.tpl');
|
|
|
|
echo '[#]';
|
|
echo number_format($total,2);
|
|
|
|
break;
|
|
|
|
case 'deleteProduct':
|
|
|
|
$k = $_POST['k'];
|
|
|
|
/****/
|
|
|
|
$resConceptos = $_SESSION['conceptosD'];
|
|
|
|
$infP = $resConceptos[$k];
|
|
|
|
$conceptosD = array();
|
|
foreach($resConceptos as $res){
|
|
|
|
if($infP['productoId'] != $res['productoId'])
|
|
$conceptosD[] = $res;
|
|
|
|
}//foreach
|
|
|
|
$_SESSION['conceptosD'] = $conceptosD;
|
|
|
|
//Obtenemos los Totales
|
|
|
|
$total = 0;
|
|
foreach($conceptosD as $res)
|
|
$total += $res['total'];
|
|
|
|
echo 'ok[#]';
|
|
|
|
$smarty->assign('conceptos', $conceptosD);
|
|
$smarty->assign('DOC_ROOT', DOC_ROOT);
|
|
$smarty->display(DOC_ROOT.'/templates/lists/conceptos.tpl');
|
|
|
|
echo '[#]';
|
|
echo number_format($total,2);
|
|
echo '[#]';
|
|
echo $infP['prodItemId'];
|
|
|
|
break;
|
|
|
|
case 'searchDevs':
|
|
|
|
$devolucion->setSucursalId($_POST['sucursalId2']);
|
|
$devolucion->setUsuarioId($_POST['usuarioId2']);
|
|
$devolucion->setFechaI(date('Y-m-d',strtotime($_POST['fechaIni2'])));
|
|
$devolucion->setFechaF(date('Y-m-d',strtotime($_POST['fechaFin2'])));
|
|
$resDevs = $devolucion->Search();
|
|
|
|
$items = array();
|
|
foreach($resDevs as $res){
|
|
|
|
$fecha = date('d-m-Y',strtotime($res['fecha']));
|
|
$hora = date('H:i:s',strtotime($res['fecha']));
|
|
$fecha = $util->FormatDateDMMMY($fecha);
|
|
$res['fecha'] = $fecha.' '.$hora;
|
|
|
|
$usuario->setUsuarioId($res['usuarioId']);
|
|
$res['usuario'] = $usuario->GetNameById();
|
|
|
|
$sucursal->setSucursalId($res['sucursalId']);
|
|
$res['sucursal'] = utf8_decode(urldecode($sucursal->GetNameById()));
|
|
|
|
$items[] = $res;
|
|
}
|
|
$devoluciones['items'] = $items;
|
|
|
|
echo 'ok[#]';
|
|
|
|
$smarty->assign('devoluciones', $devoluciones);
|
|
$smarty->assign('DOC_ROOT', DOC_ROOT);
|
|
$smarty->display(DOC_ROOT.'/templates/lists/devoluciones.tpl');
|
|
|
|
break;
|
|
|
|
}//switch
|
|
|
|
?>
|