<?php
//include "clase.conexion.php";
class clsMargenProducto extends clsConexion{
	public $varTitulo 	= "MARGEN DE UTILIDAD POR PRODUCTO";
	function FormuBusqueda() {
		$sqanio = "select distinct id_anio, id_anio from _sv_metas order by id_anio desc;";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"400", "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"=>"Periodo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"select", "id"=>"anio", "name"=>"anio",
																				     "combo"=>array("sql"=>$sqanio, "sincod"=>"SI", "titulo"=>"--[[ANIO]]--", "ancho"=>"150",))
																			   )
														   )
										    ),
									   array("titulo"=>"Proveedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"pcod", "name"=>"pcod", 
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_proveedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_proveedor('pcod', 'pnom')"),
																			   array("tipo"=>"text", "id"=>"pnom", "name"=>"pnom", 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 )
									   ),
						"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)  
		{						  
		$sql = "call spQuery_Rentabilidad_Producto('$varForm[anio]',$varForm[pcod]);";
		$varCab = array(array("cab"=>"ENE ".$varForm["anio"], "det"=>array("CAN","PPC","PPV","UTI","PUB")),
						array("cab"=>"FEB ".$varForm["anio"], "det"=>array("CAN","PPC","PPV","UTI","PUB")),
						array("cab"=>"MAR ".$varForm["anio"], "det"=>array("CAN","PPC","PPV","UTI","PUB")),
						array("cab"=>"ABR ".$varForm["anio"], "det"=>array("CAN","PPC","PPV","UTI","PUB")),
						array("cab"=>"MAY ".$varForm["anio"], "det"=>array("CAN","PPC","PPV","UTI","PUB")),
						array("cab"=>"JUN ".$varForm["anio"], "det"=>array("CAN","PPC","PPV","UTI","PUB")),
						array("cab"=>"JUL ".$varForm["anio"], "det"=>array("CAN","PPC","PPV","UTI","PUB")),
						array("cab"=>"AGO ".$varForm["anio"], "det"=>array("CAN","PPC","PPV","UTI","PUB")),
						array("cab"=>"SET ".$varForm["anio"], "det"=>array("CAN","PPC","PPV","UTI","PUB")),
						array("cab"=>"OCT ".$varForm["anio"], "det"=>array("CAN","PPC","PPV","UTI","PUB")),
						array("cab"=>"NOV ".$varForm["anio"], "det"=>array("CAN","PPC","PPV","UTI","PUB")),
						array("cab"=>"DIC ".$varForm["anio"], "det"=>array("CAN","PPC","PPV","UTI","PUB")),
						array("cab"=>"TOTAL ".$varForm["anio"], "det"=>array("CAN","UTI","PUB"))
						);
		$varNiv = array(0 =>array("COD"=>"CPRO","DES"=>"PRODUCTO"),
						1 =>array("COD"=>"XPRO","DES"=>"PROVEEDOR"));
		$varFor = array(5 =>array("decimal"=>"5"),6 =>array("decimal"=>"5"),8 =>array("tipodat"=>"porc"),
						10=>array("decimal"=>"5"),11=>array("decimal"=>"5"),13=>array("tipodat"=>"porc"),
						15=>array("decimal"=>"5"),16=>array("decimal"=>"5"),18=>array("tipodat"=>"porc"),
						20=>array("decimal"=>"5"),21=>array("decimal"=>"5"),23=>array("tipodat"=>"porc"),
						25=>array("decimal"=>"5"),26=>array("decimal"=>"5"),28=>array("tipodat"=>"porc"),
						30=>array("decimal"=>"5"),31=>array("decimal"=>"5"),33=>array("tipodat"=>"porc"),
						35=>array("decimal"=>"5"),36=>array("decimal"=>"5"),38=>array("tipodat"=>"porc"),
						40=>array("decimal"=>"5"),41=>array("decimal"=>"5"),43=>array("tipodat"=>"porc"),
						45=>array("decimal"=>"5"),46=>array("decimal"=>"5"),48=>array("tipodat"=>"porc"),
						50=>array("decimal"=>"5"),51=>array("decimal"=>"5"),53=>array("tipodat"=>"porc"),
						55=>array("decimal"=>"5"),56=>array("decimal"=>"5"),58=>array("tipodat"=>"porc"),
						60=>array("decimal"=>"5"),61=>array("decimal"=>"5"),63=>array("tipodat"=>"porc"),
						66=>array("tipodat"=>"porc")
						);
		$varReturn =  $this->setGridCombina($varCab, $sql, $varNiv, NULL, $varFor);
		return $varReturn;
		}
	function Imprimir ($varAni = NULL, $varPro = NULL)  
		{
		$sql = "call spQuery_Rentabilidad_Producto('$varAni',$varPro);";
		$varCab = array(array("cab"=>"ENE ".$varAni, "det"=>array("CAN","PPC","PPV","UTI")),
						array("cab"=>"FEB ".$varAni, "det"=>array("CAN","PPC","PPV","UTI")),
						array("cab"=>"MAR ".$varAni, "det"=>array("CAN","PPC","PPV","UTI")),
						array("cab"=>"ABR ".$varAni, "det"=>array("CAN","PPC","PPV","UTI")),
						array("cab"=>"MAY ".$varAni, "det"=>array("CAN","PPC","PPV","UTI")),
						array("cab"=>"JUN ".$varAni, "det"=>array("CAN","PPC","PPV","UTI")),
						array("cab"=>"JUL ".$varAni, "det"=>array("CAN","PPC","PPV","UTI")),
						array("cab"=>"AGO ".$varAni, "det"=>array("CAN","PPC","PPV","UTI")),
						array("cab"=>"SET ".$varAni, "det"=>array("CAN","PPC","PPV","UTI")),
						array("cab"=>"OCT ".$varAni, "det"=>array("CAN","PPC","PPV","UTI")),
						array("cab"=>"NOV ".$varAni, "det"=>array("CAN","PPC","PPV","UTI")),
						array("cab"=>"DIC ".$varAni, "det"=>array("CAN","PPC","PPV","UTI")),
						array("cab"=>"TOTAL", "det"=>array($varAni))
						);
		$varNiv = array(0 =>array("COD"=>"CPRO","DES"=>"PRODUCTO"),
						1 =>array("COD"=>"XPRO","DES"=>"PROVEEDOR"));
		$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%;">';
		$html.='<tr>';
		$html.='<td style="width: 9%; vertical-align: middle; text-align:left;"><b>Periodo</b></td>';
		$html.='<td style="width: 1%; vertical-align: middle; text-align:center;"><b>:</b></td>';
		$html.='<td style="width: 40%; vertical-align: middle; text-align:left;"><b>'.MesNombreLargo($varMes).' - '.$varAni.'</b></td>';
		$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b>'.Config("SYSEMP").'</b></td>';
		$html.='</tr>';
		$html.='<tr>';
		$html.='<td style="vertical-align: middle; text-align:left;"><b>Fecha</b></td>';
		$html.='<td style="vertical-align: middle; text-align:center;"><b>:</b></td>';
		$html.='<td style="vertical-align: middle; text-align:left;"><b>'.$varIni.' - '.$varFin.'</b></td>';
		$html.='<td style="vertical-align: middle; text-align:right;"><b>'.$this->varTitulo.'</b></td>';
		$html.='</tr>';
		$html.='<tr>';
		$html.='<td style="vertical-align: middle; text-align:left;"><b>Linea</b></td>';
		$html.='<td style="vertical-align: middle; text-align:center;"><b>:</b></td>';
		$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"><b>';
		if ($_GET[pro]<>"") {
			$sqlp = "select id_proveedor, nombre from _sv_proveedor where id_proveedor=".$varPro;
			$this->AbrirConexion();
			$rsp = $this->Query($sqlp);
			$this->CerrarConexion();
			$filap = $this->FetchArray($rsp);
			$html.= $filap[0].' - '.$filap[1];
			}
		else {
			$html.= 'TODOS LOS PROVEEDORES';
			}
		$html.='</b></td>';
		$html.='<td style="width: 50%; vertical-align: middle; text-align:right;">'.MostrarFechaActual().'</td>';
		$html.='</tr>';
		$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
		$html.='</thead>';	
		$html.='<tr>';
		$html.='<td>';				
		$html.= $this->setGridCombinaPrint($varCab, $sql, $varNiv);
		$html.='</td>';
		$html.='</tr>';			
		$html.='</table>';
		return $html;
		}
	}
?>