<?php
//include "clase.conexion.php";
class clsBonificacionReporte extends clsConexion{
	public $varTitulo = "REPORTE DE BONIFICICACIONES";
	public $varMyTabla  = "_sv_bonificacion";
	public $varMyID  	  = "id_bonif";
	function FormuBusqueda() {
		$sqlest	= array("A"=>"ACTIVO", "I"=>"INACTIVO");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"400", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - BUSQUEDA",
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST", "onsubmit"=>"return false;"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$Opcion)
									  ),
						"conte"=>array(array("titulo"=>"Estado :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"select_simple", "id"=>"est", "name"=>"est", 
											 "combo"=>array("sql"=>$sqlest, "ancho"=>"150", "titulo"=>"--[[SELECCIONAR]]--"))),
									 ),
					  "boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"100", "texto"=>"Buscar",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xBuscarJS()"),
									 array("tipo"=>"button", "id"=>"bexp", "name"=>"bexp", "ancho"=>"100", "texto"=>"Exportar",
									 	   "clase"=>"boton_exportar", "click"=>"javascript:xExportarJS()"),								
									 array("tipo"=>"button", "id"=>"bimp", "name"=>"bimp", "ancho"=>"100", "texto"=>"Imprimir", 
										   "clase"=>"boton_imprimir", "click"=>"javascript:xImprimirJS()"),
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	
	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varCod = (isset($varForm["cod"]) && $varForm["cod"]<>'')? $varForm["cod"]:"NULL";
		$varNom = $varForm["nam"];
		$varEst = ($varForm["est"]<>"Ninguno")?"'".$varForm["est"]."'":"NULL";
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		
		$sql = "call spQuery_Bonificacion($varCod,'$varNom', $varEst, $varFie, $varOrd)";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"800", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("titulo"=>"CBON",	   	 	"ancho"=>"40", "alinear"=>"center"), 									   
									   array("titulo"=>"BONIFICACION",	"ancho"=>"300", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("titulo"=>"CTIP",	   		"ancho"=>"40", "alinear"=>"center"), 									   
									   array("titulo"=>"TIPO",	   		"ancho"=>"300", "fijo"=>"SI"),									   
									   array("titulo"=>"OPCION",	   	"ancho"=>"300", "fijo"=>"SI"),
									   array("titulo"=>"FECHA INICIO",  "ancho"=>"40", "alinear"=>"center"), 
									   array("titulo"=>"FECHA TERMINO", "ancho"=>"40", "alinear"=>"center"), 
									   array("titulo"=>"ESTADO",	   	"ancho"=>"40", "alinear"=>"center"),
									   array("titulo"=>"FCREADO",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"FUPDATE",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UCREADO",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UUPDATE",  "ancho"=>"100", "oculto"=>"SI")
									   )
						);
		return $this->SetGridTabla2($varTabla);
		//return $sql;
		}
	
	function Imprimir($varEst = NULL)  
		{		
	
		
		$html.='<table style="width: 95%; padding: 0; margin-top:10px; margin-bottom:10px; border-collapse:collapse;" align="center">';
		$html.='<thead>';
		$html.='<tr>';
		$html.='<td>';
			$html.='<table style="width: 100%;" cellspacing="0" cellpadding="0">';
			$html.='<tr>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"><b>'.Config("SYSEMP").'</b></td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b>'.$this->varTitulo.'</b></td>';
			$html.='</tr>';
			$html.='<tr class="titu_inf">';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"><b></b></td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b>'.MostrarFechaActual().'</b></td>';
			$html.='</tr>';
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
		$html.='</thead>';	
		$html.='<tr>';	
		$html.='<td>';
			$html.='<table style="width: 100%;padding: 0; margin-top:0px; margin-bottom:0px; border-collapse:collapse;" align="center">';
			$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
			$varEst = ($varEst<>"Ninguno")?"'".$varEst."'":"NULL";
			$sql = "call spQuery_Bonificacion(NULL, NULL, $varEst, NULL, NULL)";
			$this->AbrirConexion();
			$rs_cab = $this->Query($sql);
			$this->CerrarConexion();
			while($fila_cab = $this->FetchArray($rs_cab))	{
				$html.='<tr class="conte_tabla">';
				$html.='<td align="center" nowrap colspan="6">&nbsp;</td>';
				$html.='</tr>';
				$html.='<tr class="conte_tabla">';
				$html.='<td width="60" align="left"><b>Nombre</b></td>';
				$html.='<td width="5" 	align="center"><b>:</b></td>';
				$html.='<td width="350" align="left" colspan="4" nowrap>'.$fila_cab["CBON"].' - '.$fila_cab["BONIFICACION"].'</td>';
				$html.='</tr>';
				$html.='<tr class="conte_tabla">';
				$html.='<td align="left" nowrap><b>Tipo</b></td>';
				$html.='<td align="center"><b>:</b></td>';
				$html.='<td align="left" nowrap>'.$fila_cab["CTIP"].' - '.$fila_cab["TIPO"].'</td>';
				$html.='<td width="60" align="left" nowrap><b>Opcion</b></td>';
				$html.='<td width="5" align="center"><b>:</b></td>';
				$html.='<td width="250" align="left" nowrap>'.$fila_cab["COPT"].' - '.$fila_cab["OPCION"].'</td>';
				$html.='</tr>';
				$html.='<tr class="conte_tabla">';
				$html.='<td align="left" nowrap><b>Estado</b></td>';
				$html.='<td align="center"><b>:</b></td>';
				$html.='<td align="left">'.$fila_cab["ESTADO"].'</td>';
				$html.='<td align="left" nowrap><b>Rango</b></td>';
				$html.='<td align="center"><b>:</b></td>';
				$html.='<td align="left" nowrap>Desde '.$fila_cab["DESDE"].' Hasta '.$fila_cab["HASTA"].'</td>';
				$html.='</tr>';
				$html.='<tr class="cont_tabla">';
				$html.='<td align="left" nowrap colspan="6"><b>CONDICIONES DE VENTA</b></td>';
				$html.='</tr>';
				$html.='<tr>';
				$html.='<td align="center" nowrap colspan="6">';
				$html.='<table style="width: 100%;padding: 0; margin-top:0px; margin-bottom:0px; border-collapse:collapse;" align="center">';
				$html.='<tr class="titu_tabla">';
				$html.='<td width="30"  align="center">CPRO</td>';
				$html.='<td width="300" align="left">PRODUCTO</td>';
				$html.='<td width="50"  align="center">UM</td>';
				$html.='<td width="50"  align="right">CANT</td>';
				$html.='<td width="80"  align="right">MIN-MAX</td>';
				$html.='</tr>';
				$sql = "select B.id_producto as CPRO, P.descripcion as PRODUCTO,
						B.id_um as UM, B.CANTIDAD, B.MINIMO, B.MAXIMO
						from _sv_bonificacion_venta B
						inner join _sv_producto P ON B.id_producto = P.id_producto
						where B._estado = 'A' 
						and id_bonif = ".$fila_cab["CBON"].";";
				$this->AbrirConexion();
				$rs = $this->Query($sql);
				$this->CerrarConexion();
				while($fila = $this->FetchArray($rs))	{
					$html.='<tr class="cont_tabla">';
					$html.='<td align="center" nowrap>'.$fila["CPRO"].'</td>';
					$html.='<td align="left" nowrap>'.$fila["PRODUCTO"].'</td>';
					$html.='<td align="center" nowrap>'.$fila["UM"].'</td>';
					$html.='<td align="right" nowrap>'.number_format($fila["CANTIDAD"],2,".",",").'</td>';
					$html.='<td align="right" nowrap>'.number_format($fila["MINIMO"],2,".",",").' - '.number_format($fila["MAXIMO"],2,".",",").'</td>';
					$html.='</tr>';
					}
				$html.='</table>';
				$html.='</td>';				
				$html.='</tr>';
				
				$html.='<tr class="cont_tabla">';
				$html.='<td align="left" nowrap colspan="6"><b>PRODUCTOS A BONIFICAR</b></td>';
				$html.='</tr>';
				$html.='<tr>';
				$html.='<td align="center" nowrap colspan="6">';
				$html.='<table style="width: 100%;padding: 0; margin-top:0px; margin-bottom:0px; border-collapse:collapse;" align="center">';
				$html.='<tr class="titu_tabla">';
				$html.='<td width="30"  align="center">CPRO</td>';
				$html.='<td width="300" align="left">PRODUCTO</td>';
				$html.='<td width="50"  align="center">UM</td>';
				$html.='<td width="50"  align="right">CANT</td>';
				$html.='<td width="80"  align="right">CUOTA</td>';
				$html.='</tr>';
				$sql = "select B.id_producto as CPRO, P.descripcion as PRODUCTO,
						B.id_um as UM, B.CANTIDAD, B.CUOTA
						from _sv_bonificacion_bonif B
						inner join _sv_producto P ON B.id_producto = P.id_producto
						where B._estado = 'A' 
						and id_bonif = ".$fila_cab["CBON"].";";
				$this->AbrirConexion();
				$rs = $this->Query($sql);
				$this->CerrarConexion();
				while($fila = $this->FetchArray($rs))	{
					$html.='<tr class="cont_tabla">';
					$html.='<td align="center" nowrap>'.$fila["CPRO"].'</td>';
					$html.='<td align="left" nowrap>'.$fila["PRODUCTO"].'</td>';
					$html.='<td align="center" nowrap>'.$fila["UM"].'</td>';
					$html.='<td align="right" nowrap>'.number_format($fila["CANTIDAD"],2,".",",").'</td>';
					$html.='<td align="right" nowrap>'.number_format($fila["CUOTA"],2,".",",").'</td>';
					$html.='</tr>';
					}
				$html.='</table>';
				$html.='</td>';				
				$html.='</tr>';
				}
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
				
		$html.='</table>		
				</body>
				</html>';
		return $html;
		}	
	}
	
?>