172 lines
4.2 KiB
PHP
Executable File
172 lines
4.2 KiB
PHP
Executable File
<?php
|
|
|
|
$empresa->AuthUser();
|
|
|
|
if(!$usuario->AllowPage($page, $_SESSION['loginKey'])){
|
|
header('Location: '.WEB_ROOT);
|
|
exit;
|
|
}
|
|
|
|
if(isset($_GET['venta2Id'])){
|
|
$_SESSION['idVenta2'] = intval($_GET['venta2Id']);
|
|
header('Location: '.WEB_ROOT.'/ventas-nueva');
|
|
exit;
|
|
}
|
|
|
|
$sucursalId = $_SESSION['idSuc'];
|
|
|
|
$usuario->setUsuarioId($_SESSION['loginKey']);
|
|
$info['usuario'] = $usuario->GetNameById();
|
|
|
|
$venta->setSucursalId($sucursalId);
|
|
$info['folio'] = $venta->GetNextFolio();
|
|
|
|
$metodosPago = $metodoPago->EnumerateAll();
|
|
|
|
$usuario->setTipo('vendedor');
|
|
$usuario->setSucursalId($sucursalId);
|
|
$vendedores = $usuario->GetUsersBySucAndType();
|
|
|
|
//Generamos Registro en la Tabla ControlVenta
|
|
$venta->setUsuarioId($_SESSION['loginKey']);
|
|
$venta->setSucursalId($sucursalId);
|
|
$venta->ControlVenta();
|
|
|
|
$_SESSION['conceptos'] = array();
|
|
|
|
if(isset($_SESSION['idVenta2'])){
|
|
|
|
$venta2Id = $_SESSION['idVenta2'];
|
|
|
|
$venta->setVentaId($venta2Id);
|
|
$infV = $venta->Info2();
|
|
$resProds = $venta->GetProductos2();
|
|
|
|
$venta->DeleteVenta2();
|
|
$venta->DevolverProductos2();
|
|
|
|
$info['subtotal'] = number_format($infV['subtotal'],2);
|
|
$info['iva'] = number_format($infV['iva'],2);
|
|
$info['total'] = number_format($infV['total'],2);
|
|
|
|
$info['vendedorId'] = $infV['vendedorId'];
|
|
|
|
$conceptos = array();
|
|
foreach($resProds as $res){
|
|
|
|
if($res['monederoId']){
|
|
|
|
$monedero->setMonederoId($res['monederoId']);
|
|
$infM = $monedero->Info();
|
|
|
|
$card['name'] = 'Tarjeta de Prepago de '.$res['precioUnitario'];
|
|
$card['tipoProd'] = 'tarjeta';
|
|
$card['prodItemId'] = $res['monederoId'];
|
|
$card['cantidad'] = $res['cantidad'];
|
|
$card['descuento'] = '0.00';
|
|
$card['precio'] = $res['precioUnitario'];
|
|
$total = $card['precio'] * $res['cantidad'];
|
|
$card['total'] = number_format($total,2,'.','');
|
|
|
|
}else{
|
|
|
|
$producto->setProdItemId($res['prodItemId']);
|
|
$infI = $producto->GetInfoItemById();
|
|
|
|
$producto->setProductoId($infI['productoId']);
|
|
$infP = $producto->Info();
|
|
|
|
$atribVal->setAtribValId($infI['tallaId']);
|
|
$talla = $atribVal->GetNameById();
|
|
|
|
$atribVal->setAtribValId($infI['colorId']);
|
|
$color = $atribVal->GetNameById();
|
|
|
|
$name = $infI['codigoBarra'].'<br>';
|
|
$name .= $infP['modelo'].' '.$talla.' '.$color;
|
|
|
|
$card['name'] = utf8_encode($name);
|
|
$card['tipoProd'] = 'producto';
|
|
$card['productoId'] = $res['productoId'];
|
|
$card['prodItemId'] = $res['prodItemId'];
|
|
$card['cantidad'] = $res['cantidad'];
|
|
$card['descuento'] = '0.00';
|
|
$card['precio'] = $res['precioUnitario'];
|
|
$total = $card['precio'] * $res['cantidad'];
|
|
$card['total'] = number_format($total,2,'.','');
|
|
|
|
}
|
|
|
|
$conceptos[] = $card;
|
|
|
|
//Apartamos los productos
|
|
$venta->setCantidad($res['cantidad']);
|
|
$venta->setSucursalId($sucursalId);
|
|
$venta->setProductoId($infI['productoId']);
|
|
$venta->setUsuarioId($_SESSION['loginKey']);
|
|
$venta->ApartarProducts();
|
|
|
|
}//foreach
|
|
|
|
$_SESSION['conceptos'] = $conceptos;
|
|
|
|
//Agrupamos los Productos solo para Vista
|
|
|
|
$prodIds = array();
|
|
foreach($conceptos as $res){
|
|
|
|
$productoId = $res['productoId'];
|
|
|
|
if(!in_array($productoId, $prodIds))
|
|
$prodIds[] = $productoId;
|
|
|
|
}//foreach
|
|
|
|
$concepts = array();
|
|
foreach($prodIds as $productoId){
|
|
|
|
$total2 = 0;
|
|
$precio = 0;
|
|
$cantidad = 0;
|
|
$card = array();
|
|
foreach($conceptos as $res){
|
|
|
|
if($res['productoId'] == $productoId){
|
|
$card = $res;
|
|
|
|
if($res['precio'] > $precio)
|
|
$precio = $res['precio'];
|
|
|
|
$cantidad += $res['cantidad'];
|
|
$total2 += $res['total'];
|
|
}
|
|
|
|
}//foreach
|
|
|
|
$card['precio'] = $precio;
|
|
$card['cantidad'] = $cantidad;
|
|
$card['total'] = $total2;
|
|
|
|
$concepts[] = $card;
|
|
|
|
}//foreach
|
|
|
|
$concepts = $util->DecodeResult($concepts);
|
|
|
|
$_SESSION['idVenta2'] = 0;
|
|
unset($_SESSION['idVenta2']);
|
|
|
|
}//if
|
|
|
|
$msg = $_SESSION['msgI'];
|
|
$_SESSION['msgI'] = '';
|
|
|
|
$smarty->assign('info', $info);
|
|
$smarty->assign('msg', $msg);
|
|
$smarty->assign('metodosPago', $metodosPago);
|
|
$smarty->assign('conceptos', $concepts);
|
|
$smarty->assign('ventas', $ventas);
|
|
$smarty->assign('vendedores', $vendedores);
|
|
|
|
|
|
?>
|