236 lines
6.0 KiB
PHP
Executable File
236 lines
6.0 KiB
PHP
Executable File
<?php
|
|
|
|
$empresa->AuthUser();
|
|
|
|
if(!$usuario->AllowPage($page, $_SESSION['loginKey'])){
|
|
header('Location: '.WEB_ROOT);
|
|
exit;
|
|
}
|
|
|
|
$mode = 'cobro';
|
|
if(isset($_GET['ventaId'])){
|
|
$ventaId = intval($_GET['ventaId']);
|
|
$mode = 'detalles';
|
|
}elseif(isset($_GET['descuentoId'])){
|
|
$ventaId = intval($_GET['descuentoId']);
|
|
$mode = 'descuento';
|
|
}else{
|
|
$ventaId = intval($_GET['id']);
|
|
}
|
|
|
|
$rfc->setRfcId(1);
|
|
$infE = $util->EncodeRow($rfc->Info());
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$info = $venta->Info();
|
|
|
|
$sucursalId = $info['sucursalId'];
|
|
|
|
$info['hora'] = date('H:i:s',strtotime($info['fecha']));
|
|
$info['fecha'] = date('d-m-Y',strtotime($info['fecha']));
|
|
|
|
$usuario->setUsuarioId($info['vendedorId']);
|
|
$info['vendedor'] = strtoupper($usuario->GetFullNameById());
|
|
|
|
$usuario->setUsuarioId($info['usuarioId']);
|
|
$info['usuario'] = strtoupper($usuario->GetFullNameById());
|
|
|
|
$sucursal->setSucursalId($info['sucursalId']);
|
|
$infS = $sucursal->Info();
|
|
$infS['nombre'] = strtoupper($infS['nombre']);
|
|
$infS = $util->DecodeUrlRow($infS);
|
|
$infS = $util->DecodeRow($infS);
|
|
|
|
//Obtenemos los Productos
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$resProds = $venta->GetProductos();
|
|
|
|
$productos = array();
|
|
foreach($resProds as $res){
|
|
|
|
$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();
|
|
|
|
if($res['monederoId']){
|
|
$monedero->setMonederoId($res['monederoId']);
|
|
$infM = $monedero->Info();
|
|
$res['codigoBarra'] = $infM['codigo'];
|
|
$res['nombre'] = 'Tarjeta de Prepago de '.$res['total'];
|
|
}else{
|
|
$res['nombre'] = $infP['modelo'];
|
|
$res['codigoBarra'] = $infI['codigoBarra'];
|
|
}
|
|
|
|
/*** OBTENEMOS TOTALES ***/
|
|
|
|
$total = $res['total'];
|
|
$valDesc = $res['valDesc'];
|
|
if($res['tipoDesc'] == 'Dinero')
|
|
$total -= $valDesc * $res['cantidad'];
|
|
elseif($res['tipoDesc'] == 'Porcentaje')
|
|
$total -= $total * ($valDesc / 100);
|
|
|
|
$total = number_format($total,2,'.','');
|
|
|
|
$res['totalDesc'] = $total;
|
|
|
|
$productos[] = $res;
|
|
|
|
}//foreach
|
|
|
|
/*
|
|
if($info['promocionId'] == 0)
|
|
$info['subtotal'] = $subtotal;
|
|
*/
|
|
|
|
//Obtenemos Totales
|
|
|
|
if($info['totalDesc'] > 0){
|
|
|
|
$subtotal2 = $info['subtotalDesc'];
|
|
|
|
$info['subtotal2'] = $subtotal2;
|
|
$info['iva'] = $info['ivaDesc'];
|
|
$info['total'] = $info['totalDesc'];
|
|
|
|
$valDesc = $info['valDesc'];
|
|
if($info['tipoDesc'] == 'Dinero'){
|
|
$subtotal = $subtotal2 + $valDesc;
|
|
$info['descuento'] = $valDesc;
|
|
}else{
|
|
$resDesc = 100 - $valDesc;
|
|
$subtotal = $subtotal2 / ($resDesc / 100);
|
|
$subtotal = number_format($subtotal,2,'.','');
|
|
|
|
$info['descuento'] = $subtotal * ($valDesc / 100);
|
|
}//else
|
|
|
|
$info['subtotal'] = $subtotal;
|
|
|
|
}//if
|
|
|
|
$cambio = 0;
|
|
if($info['pago'] > $info['total'])
|
|
$cambio = $info['pago'] - $info['total'];
|
|
|
|
$info['cambio'] = $cambio;
|
|
|
|
//Agrupamos los Productos solo para Vista
|
|
|
|
$prodIds = array();
|
|
foreach($productos as $res){
|
|
|
|
$productoId = $res['productoId'];
|
|
|
|
if(!in_array($productoId, $prodIds))
|
|
$prodIds[] = $productoId;
|
|
|
|
}//foreach
|
|
|
|
$products = array();
|
|
foreach($prodIds as $productoId){
|
|
|
|
$promocionId = 0;
|
|
$total2 = 0;
|
|
$precio = 0;
|
|
$cantidad = 0;
|
|
$totalDesc = 0;
|
|
$card = array();
|
|
foreach($productos as $res){
|
|
|
|
if($res['productoId'] == $productoId){
|
|
|
|
if($res['promocionId'] > 0){
|
|
$promocionId = $res['promocionId'];
|
|
|
|
$promocion->setPromocionId($promocionId);
|
|
$infProm = $promocion->Info();
|
|
$res['nombre'] .= '<br>Promoción: '.$infProm['nombre'];
|
|
$promocionId = 0;
|
|
|
|
$products[] = $res;
|
|
continue;
|
|
}
|
|
|
|
$card = $res;
|
|
|
|
if($res['precioUnitario'] > $precio)
|
|
$precio = $res['precioUnitario'];
|
|
|
|
$cantidad += $res['cantidad'];
|
|
$totalDesc += $res['totalDesc'];
|
|
|
|
$total2 += $res['total'];
|
|
}
|
|
|
|
}//foreach
|
|
|
|
if($card){
|
|
|
|
$card['precioUnitario'] = $precio;
|
|
$card['cantidad'] = $cantidad;
|
|
$card['total'] = $total2;
|
|
$card['totalDesc'] = $totalDesc;
|
|
$card['promocionId'] = $promocionId;
|
|
|
|
if($card['promocionId']){
|
|
$promocion->setPromocionId($card['promocionId']);
|
|
$infProm = $promocion->Info();
|
|
$nomPromo = $infProm['nombre'];
|
|
|
|
if($infProm['aplica'] == 'N1Desc')
|
|
$nomPromo .= ' Compra '.$infProm['valorN'].' Prods. y apartir del '.($infProm['valorN'] + 1).'o aplica';
|
|
if($infProm['aplica'] == 'XxY')
|
|
$nomPromo .= ' Compra '.$infProm['valorX'].' Prods. al Precio de '.$infProm['valorY'].' por producto.';
|
|
if($infProm['aplica'] == 'CompraX'){
|
|
$producto->setProductoId($infProm['productoId']);
|
|
$prodNom = $producto->GetModeloById();
|
|
$nomPromo .= ' Compra $'.$infProm['totalCompra'].' en Prods. y regala '.$infProm['cantArtRegalo'].' '.$prodNom;
|
|
}
|
|
if($infProm['aplica'] == 'DescCuenta')
|
|
$nomPromo .= ' Compra $'.$infProm['totalCompra'].' en Prods. y aplica ';
|
|
if($infProm['aplica'] == 'ArtConDesc')
|
|
$nomPromo .= ' Articulos despues de $'.$infProm['totalCompra'].' en total de compra aplica ';
|
|
|
|
if($infProm['aplica'] == 'N1Desc' || $infProm['aplica'] == 'DescCuenta' || $infProm['aplica'] == 'ArtConDesc'){
|
|
if($infProm['tipoDesc'] == 'Cantidad')
|
|
$nomPromo .= ' $'.$infProm['valorDesc'].' de Descto.';
|
|
if($infProm['tipoDesc'] == 'Porcentaje')
|
|
$nomPromo .= ' '.$infProm['valorDesc'].'% de Descto.';
|
|
}
|
|
|
|
$card['nombre'] .= '<br>Promoción: '.$nomPromo;
|
|
}
|
|
|
|
$products[] = $card;
|
|
|
|
}
|
|
|
|
}//foreach
|
|
|
|
if($sucursalId == 10)
|
|
$fontSize = 10;
|
|
else
|
|
$fontSize = 11;
|
|
|
|
$smarty->assign('infE', $infE);
|
|
$smarty->assign('infS', $infS);
|
|
$smarty->assign('info', $info);
|
|
$smarty->assign('mode', $mode);
|
|
$smarty->assign('fontSize', $fontSize);
|
|
$smarty->assign('productos', $products);
|
|
$smarty->display(DOC_ROOT."/templates/ventas-ticket.tpl");
|
|
|
|
exit;
|
|
|
|
?>
|