<?php
//include "clase.conexion.php";
class clsEfectividadProveedor extends clsConexion{
	public $varTitulo 	= "EFECTIVIDAD POR PROVEEDOR";
	function FormuBusqueda() {
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "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"=>$_POST["ecod"], 
																					 "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"=>$_POST["enom"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
															)
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"vcod", "name"=>"vcod", 
																					 "valor"=>$_POST["vcod"],
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_vendedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_vendedor('vcod', 'vnom')"),
																			   array("tipo"=>"text", "id"=>"vnom", "name"=>"vnom", 
																			   		 "valor"=>$_POST["pnom"], 
																					 "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", "locked"=>"SI", "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", "locked"=>"SI", "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()"),
									 )
						);
		return $this->setTablaForm($varTabla);
		}
 	function GridDatos($varForm = NULL
					  )  {						  
		$varEmp  = ($varForm["ecod"]<>"")?$varForm["ecod"]:"NULL";
		$varVen  = ($varForm["vcod"]<>"")?$varForm["vcod"]:"NULL";
		$varIni  = ($varForm["fini"]<>"")?"'".FechaMySql($varForm["fini"])."'":"NULL";
		$varFin  = ($varForm["ffin"]<>"")?"'".FechaMySql($varForm["ffin"])."'":"NULL";
		
		$sql = "call spQuery_Efectividad_Proveedor($varEmp, $varVen, $varIni, $varFin);";
			
		$varCab = array(array("cab"=>"VENTA SOLES (S/.)", "det"=>array("PREVEN.","VENTA","RECHAZ", "PARCIAL", "%EFECT.")),
						array("cab"=>"PEDIDOS", "det"=>array("PREVEN.","VENTA","RECHAZ", "PARCIAL", "%EFECT.")),
						array("cab"=>"PUNTOS DE VENTA", "det"=>array("PREVEN.","VENTA","RECHAZ", "PARCIAL", "%EFECT."))
						);
		$varNiv = array(0 =>array("COD"=>"CPRO","DES"=>"PROVEEDOR"),
						1 =>array("COD"=>"CEMP","DES"=>"EMPRESA"));
		$varFor = array(8 =>array("tipodat"=>"porc", "formula"=>array("valor1"=>4,  "valor2"=>5,  "funcion"=>"porc")),
						13=>array("tipodat"=>"porc", "formula"=>array("valor1"=>9,  "valor2"=>10, "funcion"=>"porc")),
						18=>array("tipodat"=>"porc", "formula"=>array("valor1"=>14, "valor2"=>15, "funcion"=>"porc"))
						);
		return $this->setGridCombina($varCab, $sql, $varNiv, NULL, $varFor);
		}

	function Imprimir($varEmp = NULL,
					  $varVen = NULL,
					  $varIni = NULL,
					  $varFin = NULL
					  )  {	
		$varLin  = ($varLin<>"Ninguno")?"'".$varLin."'":"NULL";
		$varFam  = ($varFam<>"Ninguno")?"'".$varFam."'":"NULL";
		$varSub  = ($varSub<>"Ninguno")?"'".$varSub."'":"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];
		
		if ($varVen<>"") {
			$sql_pro = "select concat(id_proveedor, ' - ', nombre) as proveedor from _sv_proveedor where id_proveedor = $varVen;";
			$this->AbrirConexion();
			$rs_pro = $this->Query($sql_pro);
			$this->CerrarConexion();
			$fila_pro = $this->FetchArray($rs_pro);
			$varCadPro = $fila_pro[0];
			}
		else $varCadPro = "TODOS LOS PROVEEDORES";
		
		$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: 8%; vertical-align: middle; text-align:left;"><b>Empresa </b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="width: 42%; vertical-align: middle; text-align:left;">'.$varCadEmp.'</td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b></b></td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="width: 10%; vertical-align: middle; text-align:left;"><b>Proveedor </b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="width: 40%; vertical-align: middle; text-align:left;" nowrap>'.$varCadPro.'</td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"></td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="width: 10%; vertical-align: middle; text-align:left;"><b>Fechas </b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="width: 40%; vertical-align: middle; text-align:left;" nowrap>'.$varIni." - ".$varFin.'</td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"></td>';
			$html.='</tr>';
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
		$html.='</thead>';	
		$html.='<tr>';	
		$html.='<td>';
			$varEmp  = ($varEmp<>"")?$varEmp:"NULL";
			$varVen  = ($varVen<>"")?$varVen:"NULL";
			$varIni  = ($varIni<>"")?"'".FechaMySql($varIni)."'":"NULL";
			$varFin  = ($varFin<>"")?"'".FechaMySql($varFin)."'":"NULL";
			
			$sql = "call spQuery_Efectividad_Proveedor($varEmp, $varVen, $varIni, $varFin);";
			$varCab = array(array("cab"=>"VENTA SOLES (S/.)", "det"=>array("PREVEN.","VENTA","RECHAZ", "PARCIAL", "%EFECT.")),
							array("cab"=>"PEDIDOS", "det"=>array("PREVEN.","VENTA","RECHAZ", "PARCIAL", "%EFECT.")),
							array("cab"=>"PUNTOS DE VENTA", "det"=>array("PREVEN.","VENTA","RECHAZ", "PARCIAL", "%EFECT."))
							);
			$varNiv = array(0 =>array("COD"=>"CPRO","DES"=>"PROVEEDOR"),
							1 =>array("COD"=>"CEMP","DES"=>"EMPRESA"));
			$varFor = array(8 =>array("tipodat"=>"porc", "formula"=>array("valor1"=>4,  "valor2"=>5,  "funcion"=>"porc")),
							13=>array("tipodat"=>"porc", "formula"=>array("valor1"=>9,  "valor2"=>10, "funcion"=>"porc")),
							18=>array("tipodat"=>"porc", "formula"=>array("valor1"=>14, "valor2"=>15, "funcion"=>"porc"))
							);
			$html.= $this->setGridCombinaPrint($varCab, $sql, $varNiv, $varFor);		
		$html.='</td>';
		$html.='</tr>';
				
		$html.='</table>		
				</body>
				</html>';
		return $html;
		}
	}
?>