<?php
//include "clase.conexion.php";
class clsSueldoComision extends clsConexion{
	public $varTitulo 	= "SUELDOS POR COMISIONES";
	function FormuBusqueda() {
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"470", "clase"=>"Formtitulo", "titulo"=>$this->varTitulo,
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST", "onsubmit"=>"return false;"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo)
									  ),
						"conte"=>array(array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ecod", "name"=>"ecod", "valor"=>NULL, 
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_empresa(this.value)", 
																					 "dclick"=>"fn_cargar_listado_empresa('ecod', 'enom')"),
																			   array("tipo"=>"text", "id"=>"enom", "name"=>"enom", "valor"=>NULL, 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
															)
											 ),
									   array("titulo"=>"Fecha Inicio :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"fini", "name"=>"fini", "alinear"=>"center",
																					 "ancho"=>"130", "valor"=>date("01/m/Y",time()))
																			   )
														 	)
											 ),
									   array("titulo"=>"Fecha Fin :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"ffin", "name"=>"ffin", "alinear"=>"center", 
																					 "ancho"=>"130", "valor"=>date("d/m/Y",time()))
																			   )
														 	)
											 )
									   ),
						"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('', 'NEW')"),
									 )
						);
		return $this->setTablaForm($varTabla);
		}
 	function GridDatos($varForm = NULL
					   )  {						  
		$varFIni = ($varForm["fini"]=="")?"NULL":"'".FechaMySql($varForm["fini"])."'";
		$varFFin = ($varForm["ffin"]=="")?"NULL":"'".FechaMySql($varForm["ffin"])."'";
		
		$sql = "call spQuery_Comision_Vendedor('$varForm[ecod]', $varFIni, $varFFin);";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"700", "sql_cab"=>$sql,	"pages"=>100,
						"conte"=>array(array("tamano"=>20, "titulo"=>"CVEN", "alinear"=>"center"),
									   array("tamano"=>200, "titulo"=>"VENDEDOR", "funcion"=>array("contar")),
									   array("tamano"=>60, "titulo"=>"%COM", "alinear"=>"right", "tipodat"=>"PORC"),
									   array("tamano"=>60, "titulo"=>"SUBTOTAL", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("tamano"=>60, "titulo"=>"IGV", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("tamano"=>60, "titulo"=>"TOTAL", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("tamano"=>60, "titulo"=>"COMISION", "alinear"=>"right", "funcion"=>array("autosuma"))
									   ),
						);
		$varReturn = $this->SetGridTabla($varTabla);
		return $varReturn;
		}

	function Imprimir ($varEmp = NULL,
					   $varIni = NULL, 
					   $varFin = NULL
					   )  {
		$sql_emp = "select concat(id_empresa, ' - ', nombre) as empresa from _sv_empresa where id_empresa=$varEmp;";
		$this->AbrirConexion();
		$rs_emp = $this->Query($sql_emp);
		$this->CerrarConexion();
		$fila_emp = $this->FetchArray($rs_emp);
		$varCadEmp = $fila_emp[0];				  
		
		$varAniC = (isset($varAni) && $varAni<>"")?"'".$varAni."'":"NULL";
		$varMesC = (isset($varMes) && $varMes<>"")?"'".$varMes."'":"NULL";
		$varIniC = (isset($varIni) && $varIni<>"")?"'".FechaMySql($varIni)."'":"NULL";
		$varFinC = (isset($varFin) && $varFin<>"")?"'".FechaMySql($varFin)."'":"NULL";
		
		$sql = "call spQuery_Comision_Vendedor($varEmp, $varIniC, $varFinC);";
		
		$html='<table style="width: 98%; 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 class="titu_sup" height="25px">';
			$html.='<td colspan="2"><b>'.$this->varTitulo.'</b></td>';
			$html.='</tr>';
			$html.='<tr class="titu_inf">';
			$html.='<td colspan="2">';
			$html.='<div align="left" style=" width:50%;float:left;">'.$_SESSION["_CABR"].' : '.$_SESSION["_NSYS"].'</div>';
    		$html.='<div align="right" style="width:50%;float:left">'.MostrarFechaActual().'</div>';
			$html.='</td>';
			$html.='</tr>';
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';		
		$html.='<tr>';
		$html.='<td>';
			$html.='<table style="width: 100%;" cellspacing="0" cellpadding="0">';
			$html.='<tr>';
			$html.='<td style="width:80px; vertical-align: middle; text-align:left;"><b>Empresa </b></td>';
			$html.='<td style="width:10px; vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;">'.$varCadEmp.'</td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>Datos </b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;" nowrap>'.$varIni.' - '.$varFin.'</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;">';
		$html.='<thead>';
		$html.='<tr class="titu_tabla">';
		$html.='<td width="2" align="center">&nbsp;</td>';
		$html.='<td width="2" align="center">CVEN</td>';
		$html.='<td width="150">VENDEDOR</td>';
		$html.='<td width="60" align="right">%COM</td>';
		$html.='<td width="60" align="right">SUBTOTAL</td>';
		$html.='<td width="60" align="right">IGV</td>';
		$html.='<td width="60" align="right">TOTAL</td>';
		$html.='<td width="60" align="right">COMISION</td>';
		$html.='</tr>';
		$html.='</thead>';
		//$sql = "call spQuery_Avance_Ventas_Vendedor('$_GET[anio]', '$_GET[mes]', '$_GET[pro]', $varFIni, $varFFin);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$varTotal_1 = 0;
		$varTotal_2 = 0;
		$varTotal_3 = 0;
		$varTotal_4 = 0;
		$varNumDoc = 0;
		while($fila = $this->FetchArray($rs))	{
			$varTotal_1 = $varTotal_1 + $fila["SUBTOTAL"];
			$varTotal_2 = $varTotal_2 + $fila["IGV"];
			$varTotal_3 = $varTotal_3 + $fila["TOTAL"];
			$varTotal_4 = $varTotal_4 + $fila["COMISION"];
			$varNumDoc++;
			$html.='<tr class="cont_tabla">';
			$html.='<td class="center">&nbsp;</td>';
			$html.='<td class="center">'.$fila["CVEN"].'</td>';
			$html.='<td NOWRAP>'.$fila["VENDEDOR"].'</td>';
			$html.='<td class="right">';
			if(!is_null($fila["PORC_COM"]) && $fila["PORC_COM"] <> 0)
				$html.=number_format($fila["PORC_COM"],"2",".",",")."%";
			$html.='</td>';
			$html.='<td class="right">';
			if(!is_null($fila["SUBTOTAL"]) && $fila["SUBTOTAL"] <> 0)
				$html.=number_format($fila["SUBTOTAL"],"2",".",",");
			$html.='</td>';
			$html.='<td class="right">';
			if(!is_null($fila["IGV"]) && $fila["IGV"] <> 0)
				$html.=number_format($fila["IGV"],"2",".",",");
			$html.='</td>';
			$html.='<td class="right">';
			if(!is_null($fila["TOTAL"]) && $fila["TOTAL"] <> 0)
				$html.=number_format($fila["TOTAL"],"2",".",",");
			$html.='</td>';
			$html.='<td class="right">';
			if(!is_null($fila["COMISION"]) && $fila["COMISION"] <> 0)
				$html.=number_format($fila["COMISION"],"2",".",",");
			$html.='</td>';
			$html.='</tr>';
			}
		$html.='<tr class="titu_tabla">';
		$html.='<td class="left"></td>';
		$html.='<td class="left"></td>';
		$html.='<td class="left" colspan="2">'.number_format($varNumDoc,"0",".",",").' Registros</td>';
		$html.='<td class="right">'.number_format($varTotal_1,"2",".",",").'</td>';
		$html.='<td class="right">'.number_format($varTotal_2,"2",".",",").'</td>';
		$html.='<td class="right">'.number_format($varTotal_3,"2",".",",").'</td>';
		$html.='<td class="right">'.number_format($varTotal_4,"2",".",",").'</td>';
		$html.='</tr>';
		$html.='</table>';
		$html.='</td>';
		$html.='</tr>';			
		$html.='</table>';
		return $html;		
		}
		
	}
?>