Files
ventas_php/ajax/devoluciones-cedis.php

191 lines
4.7 KiB
PHP
Executable File

<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
session_start();
$Usr = $user->Info();
$smarty->assign('Usr', $Usr);
if(isset($_POST['action']))
$_POST['type'] = $_POST['action'];
switch($_POST["type"]){
case 'saveDevolucion':
$products = $_SESSION['prodsDevC'];
$devolucion->setFecha(date('Y-m-d H:i:s'));
$devolucion->setUsuarioId($_SESSION['loginKey']);
$devolucion->SaveDevCedis();
$devCedisId = $devolucion->GetInsertIdCedis();
//Guardamos los Productos
$devolucion->setDevCedisId($devCedisId);
foreach($products as $res){
$devolucion->setSucursalId($res['sucursalId']);
$devolucion->setProductoId($res['productoId']);
$devolucion->setCantidad($res['cantidad']);
$devolucion->setDisponible($res['disponible']);
$devolucion->SaveProdCedis();
//Bloqueamos los productos
$devolucion->UpdateDevProd();
}//foreach
$_SESSION['msgDevC'] = 'Saved';
echo 'ok[#]';
break;
case 'deleteDev':
$devolucion->setDevCedisId($_POST['devCedisId']);
if(!$devolucion->DeleteCedis())
{
echo 'fail[#]';
$smarty->display(DOC_ROOT.'/templates/boxes/status_on_popup.tpl');
}else
{
//Desbloqueamos los productos
$devolucion->UpdateDispProd();
echo 'ok[#]';
$smarty->display(DOC_ROOT.'/templates/boxes/status.tpl');
echo '[#]';
$devoluciones = $devolucion->EnumerateCedis();
$items = array();
foreach($devoluciones['items'] as $res){
$usuario->setUsuarioId($res['usuarioId']);
$res['usuario'] = $usuario->GetNameById();
$items[] = $res;
}
$devoluciones['items'] = $items;
$smarty->assign('devoluciones', $devoluciones);
$smarty->assign('DOC_ROOT', DOC_ROOT);
$smarty->display(DOC_ROOT.'/templates/lists/devoluciones-cedis.tpl');
}
break;
//PRODUCTOS
case 'addProducto':
$products = $_SESSION['prodsDevC'];
$productoId = $_POST['productoId'];
$sucursalId = $_POST['sucursalId'];
$cantidad = intval($_POST['cantidad']);
//Checamos si ya se encuentra el producto agregado
if($productoId == '')
$noError = 20058;
if($cantidad <= 0)
$noError = 30018;
if(count($products) == 0)
$products = array();
$prodFound = 0;
if($productoId){
foreach($products as $res){
if($res['productoId'] == $productoId && $res['sucursalId'] == $sucursalId){
$prodFound = 1;
$noError = 20060;
break;
}
}
}
if($noError){
$util->setError($noError, 'error', '', '');
$util->PrintErrors();
echo 'fail[#]';
$smarty->display(DOC_ROOT.'/templates/boxes/status.tpl');
echo '[#]';
$smarty->assign('products', $products);
$smarty->assign('DOC_ROOT', DOC_ROOT);
$smarty->display(DOC_ROOT.'/templates/lists/pedidos-productos-dev.tpl');
exit;
}
$card['sucursalId'] = $sucursalId;
$card['productoId'] = $productoId;
$card['proveedor'] = $prodCatId;
$card['cantidad'] = $cantidad;
$sucursal->setSucursalId($sucursalId);
$card['sucursal'] = urldecode($sucursal->GetNameById());
$producto->setProductoId($productoId);
$infP = $producto->Info();
$inventario->setProductoId($productoId);
$inventario->setSucursalId($sucursalId);
$card['disponible'] = $inventario->GetDispByProd();
$prodCat->setProdCatId($infP['prodCatId']);
$card['departamento'] = utf8_encode($prodCat->GetNameById());
$prodSubcat->setProdSubcatId($infP['prodSubcatId']);
$card['linea'] = utf8_encode($prodSubcat->GetNameById());
$card['modelo'] = utf8_encode($infP['modelo']);
$card['codigoBarra'] = $infP['codigoBarra'];
$card['atributos'] = utf8_encode($producto->GetAtributosAll());
$products[] = $card;
$_SESSION['prodsDevC'] = $products;
echo 'ok[#]';
$smarty->assign('products', $products);
$smarty->assign('DOC_ROOT', DOC_ROOT);
$smarty->display(DOC_ROOT.'/templates/lists/pedidos-productos-dev.tpl');
break;
case 'deleteProducto':
$k = $_POST['k'];
$products = $_SESSION['prodsDevC'];
unset($products[$k]);
$_SESSION['prodsDevC'] = $products;
echo 'ok[#]';
$smarty->assign('products', $products);
$smarty->assign('DOC_ROOT', DOC_ROOT);
$smarty->display(DOC_ROOT.'/templates/lists/pedidos-productos.tpl');
break;
}//switch
?>