<?php
//include "clase.conexion.php";
class clsRegistroSobrante extends clsConexion{
	public $varTitulo = "REGISTRO DE SOBRANTE DE MERCADERIA";
	public $varMyTabla  = "_sv_asigncion";
	public $varMyID  	  = "id_asignacion";
	function FormuBusqueda() {
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"300", "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),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$Opcion)
									  ),
						"conte"=>array(array("titulo"=>"N&deg; Asignacion :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"120",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ide", "name"=>"ide", "valor"=>NULL,
																					 "ancho"=>"100", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)")
																			   )
														 	)
											 )				   
								   ),
					  "boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"160", "texto"=>"Buscar Documentos",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xFormSobranteJS()")
									 )
					);
		return $this->setTablaForm($varTabla);
		}
	
	function FormSobrante($varForm  = NULL)  {
		$varIde = ($varForm["ide"]=="")?"NULL":$varForm["ide"];
		$sqlcab = "call spQuery_Asignacion($varIde, NULL, NULL, NULL, NULL, NULL, NULL);";
		$this->AbrirConexion();
		$rscab = $this->Query($sqlcab);
		$this->CerrarConexion();
		$filacab = $this->FetchArray($rscab);
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"400", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo."<br>=> 1) SOBRANTES REGISTRADOS",
						"formu"=>array("id"=>"FormSobrante", "name"=>"FormSobrante", "metodo"=>"POST", "onsubmit"=>"return false;"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"ide2", "name"=>"ide2", "valor"=>$filacab["ASIG"])
									  ),
						"conte"=>array(array("titulo"=>"N&deg; Asignaci&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["ASIG"])))
											 ),
									   array("titulo"=>"F. Reparto :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["FECHA"])))
											 ),
									   array("titulo"=>"Veh&iacute;culo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["PLACA"]." - ".$filacab["VEHICULO"])))
											 ),
									   array("titulo"=>"Conductor :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["CCON"]." - ".$filacab["CONDUCTOR"])))
											 )			   
									   ),
						  "boton"=>array(array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"150",
											   "clase"=>"boton_nuevo", "texto"=>"Nuevo Sobrante", "click"=>"javascrip:xFormDocumentoJS()"),
										 array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											   "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresarBusqueda()")
										 )
					);
		return $this->setTablaForm($varTabla);
		}
	
	function GridSobrante($varIde   = NULL, 
						   $varField = NULL, 
						   $varOrder = NULL
						   )  {
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$varIde = ($varIde=="")?"NULL":$varIde;		
		$sql = "call spQuery_Asignacion_Sobrantes($varIde,$varFie,$varOrd);";
		$varTabla=array("id"=>"theTable2", "name"=>"theTable2", "tamano"=>"800", "sql_cab"=>$sql,	"pages"=>20, "orderfun"=>"xGridSobranteJS",
						"body"=>"Cuerpo",
					    "conte"=>array(array("tamano"=>50, "titulo"=>"IDE", "alinear"=>"center"),
									   array("tamano"=>50, "titulo"=>"FECHA", "alinear"=>"center", "fijo"=>"SI"),
									   array("tamano"=>50, "titulo"=>"DOCUMENTO", "alinear"=>"center", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("tamano"=>50, "titulo"=>"EST", "alinear"=>"center", "fijo"=>"SI"),
									   array("tamano"=>20, "titulo"=>"CREP", "alinear"=>"center", "fijo"=>"SI"),
									   array("tamano"=>250,"titulo"=>"REPARTIDOR", "fijo"=>"SI"),
									   array("tamano"=>60, "titulo"=>"MONTO", "alinear"=>"right", "funcion"=>array("autosuma"))
									   ), 
						"boton"=>array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"images/b_table.png", 
											  "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>VER EL DETALLE DE</b> DEL Sobrante<br><b>Fecha Emisi&oacute;n : </b>"),
															  array("valor"=>1, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Documento : </b>"),
															  array("valor"=>2, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Reparto : </b>"),
															  array("valor"=>5, "tipo"=>"INDEX")
												   			  ),
											  "click"=>array("funcion"=>"FormuDetalleJS",
															 "param"=>array(array("valor"=>0, 	  "tipo"=>"INDEX"))
															)
											  ),
									    array("tipo"=>"img", "id"=>"banu", "name"=>"banu", "img"=>"images/b_table_delete.png", 
											  "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ANULAR</b> EL Sobrante<br><b>Fecha Emisi&oacute;n : </b>"),
															  array("valor"=>1, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Documento : </b>"),
															  array("valor"=>2, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Reparto : </b>"),
															  array("valor"=>5, "tipo"=>"INDEX")
															  ),
											   "click"=>array("funcion"=>"xEliminarJS",
															  "param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																			 array("valor"=>1, "tipo"=>"INDEX"),
																			 array("valor"=>2, "tipo"=>"INDEX"),
																			 array("valor"=>5, "tipo"=>"INDEX"),
																			 array("valor"=>"this", "tipo"=>"NUM") 
																			 )
															  )
											 
											    ),
										   array("tipo"=>"img", "id"=>"bimp", "name"=>"bimp", "img"=>"images/b_printer.png", 
										   		 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>IMPRIMIR</b> EL Sobrante<br><b>Fecha Emisi&oacute;n : </b>"),
																 array("valor"=>1, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Documento : </b>"),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Reparto : </b>"),
																 array("valor"=>5, "tipo"=>"INDEX")
												   				),
												 "click"=>array("funcion"=>"ImprimirDoc",
																"param"=>array(array("valor"=>0, "tipo"=>"INDEX")
																			   )
																)
											 )
										)
							);
		return $this->SetGridTabla2($varTabla);
		
		}
				
	function FormDocumento($varForm  = NULL)  {
		$varIde = ($varForm["ide2"]=="")?"NULL":$varForm["ide2"];
		$sqlcab = "call spQuery_Asignacion($varIde, NULL, NULL, NULL, NULL, NULL, NULL);";
		$this->AbrirConexion();
		$rscab = $this->Query($sqlcab);
		$this->CerrarConexion();
		$filacab = $this->FetchArray($rscab);
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo."<br>=> 2) REGISTRAR SOBRANTE",
						"conte"=>array(array("titulo"=>"N&deg; Asignaci&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"90",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["ASIG"])))
											 ),
									   array("titulo"=>"F. Reparto :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["FECHA"])))
											 ),
									   array("titulo"=>"Veh&iacute;culo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["PLACA"]." - ".$filacab["VEHICULO"])))
											 ),
									   array("titulo"=>"Conductor :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["CCON"]." - ".$filacab["CONDUCTOR"])))
											 )			   
									   )
					);
		$varReturn.= "<form id=\"form\" name=\"form\" method=\"POST\"  onSubmit=\"return validaRegistroPedido(this)\">";
		$varReturn.= $this->setTablaForm($varTabla);
		
		$sqldoc = "select id_tipo_doc, nombre from _sv_tipo_doc_venta where _estado='A' and flag_liq_sobrante='S';";
		$sqlcon = "call spQuery_Combo_Condicion_Venta($_SESSION[_CUSE]);";
		
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"Formtitulo", "titulo"=>"DETALLE DEL DOCUMENTO",						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"asi", "name"=>"asi", "valor"=>$filacab["ASIG"]),
									   array("tipo"=>"oculto", "id"=>"tdcod1", "name"=>"tdcod1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"femi1", "name"=>"femi1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"cond1", "name"=>"cond1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"vcod1", "name"=>"vcod1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"ccod1", "name"=>"ccod1", "valor"=>NULL)
									  ),
						"conte"=>array(array("titulo"=>"Doc. Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"90",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"tdcod", "name"=>"tdcod",
																					 "combo"=>array("sql"=>$sqldoc, "ancho"=>"200", "sincod"=>"SI",
																					 				"titulo"=>"--[[SELECCIONAR]]--", 
																									"reload"=>"xajax_seleccionarNroDocumento(this.value)"
																									)
																			   		),
																			   array("tipo"=>"simple", "valor"=>"<div id=\"divNumDoc\"></div>"
																			   		)
																			   )
														 	)
											 ),
									   array("titulo"=>"Fecha Emision :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"femi", "name"=>"femi", "alinear"=>"center",
																					 "ancho"=>"130", "locked"=>"SI", "valor"=>date("d/m/Y",time()))
																			   )
														 	)
											 ),
									   array("titulo"=>"Condici&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"cond", "name"=>"cond", 
																					 "valor"=>$_POST["cond"], 
																					 "combo"=>array("sql"=>$sqlcon, "ancho"=>"200", "sincod"=>"SI"))
																			   )
														 	)
											 ),
									   array("titulo"=>"Glosa :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"area", "id"=>"glo", "name"=>"glo", "ancho"=>"320", "alto"=>"50"))
									   )
						);
		$varReturn.= $this->setTablaForm($varTabla);
		
		
		$varTabla=array("id"=>"tabla_cli", "name"=>"table_cli", "tamano"=>"450", "clase"=>"Formtitulo", "titulo"=>"DATOS DEL REPARTIDOR",						
						"conte"=>array(array("titulo"=>"Repartidor :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"90",
											 "campo"=>array("tipo"=>"varios", 
															"contenido"=>array(array("tipo"=>"text", "id"=>"ccod", "name"=>"ccod", 
																					 "valor"=>$_POST["ccod"], "ancho"=>"55", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_proveedor_reparto(this.value)", 
																					 "dclick"=>"fn_cargar_listado_proveedor_reparto('ccod', 'cnom')"),
																			   array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", 
																			   		 "valor"=>$_POST["cnom"], 
																					 "ancho"=>"258", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"DNI / RUC :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"dni", "name"=>"dni", 
																					 "valor"=>$_POST["dni"], "ancho"=>"157", "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"ruc", "name"=>"ruc", 
																			   		 "valor"=>$_POST["ruc"], "ancho"=>"157", "alinear"=>"center",
																					 "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Direcci&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"text", "id"=>"txtdir", "name"=>"txtdir", "valor"=>$_POST["txtdir"], 
											 				"ancho"=>"320", "clase"=>"inputDisable", "locked"=>"SI")),
									   array("titulo"=>"Ruta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"rcod", "name"=>"rcod", 
																					 "valor"=>$_POST["rcod"], "ancho"=>"55", "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"rnom", "name"=>"rnom", 
																			   		 "valor"=>$_POST["rnom"], "ancho"=>"258", 
																					 "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Lista Precios :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"lcod", "name"=>"lcod", "valor"=>$_POST["lcod"], 
																					 "ancho"=>"55", "alinear"=>"center", "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"lnom", "name"=>"lnom", "valor"=>$_POST["lnom"], 
																			   		 "ancho"=>"200", "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"lmin", "name"=>"lmin", "valor"=>$_POST["lmin"], 
																					 "ancho"=>"55", "alinear"=>"right", "clase"=>"inputDisable", "locked"=>"SI"),
																			   )
														 	)
											 )
									   ),
						"boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"100",
											 "clase"=>"boton_agregar", "texto"=>"Agregar", "click"=>"javascrip:addProductoSobrante()"),
									   array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresarDescuento()")
									   )
						);
		$varReturn.= $this->setTablaForm($varTabla);
		
		$varReturn.= "<br>";
		$varReturn.= "<table id=\"tblSample\" style=\"padding:0;margin-top:0px;border-collapse:collapse;\" ";
		$varReturn.= "width=680 align=center cellpadding=0 cellspacing=0>";
		$varReturn.= "<tr>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"90\">Codigo";
		$varReturn.= "<input name=\"num\" type=\"hidden\" class=\"input\" id=\"num\" value=\"0\"/>";
		$varReturn.= "</td>";	
		$varReturn.= "<td class=\"FormCampo2\" width=\"300\">Descripcion</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">UM Venta</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Stock</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Precio</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Cantidad</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Total</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"10\"></td>";
		$varReturn.= "</tr>";
		$varReturn.= "<tbody id=\"cuerpoTabla\">";
		$varReturn.= "</tbody>";
		$varReturn.= "<tr>";
		$varReturn.= "<td height=19 class=\"interior\" colspan=6 align=\"right\"><b>Total :</b></td>";	
		$varReturn.= "<td align=\"left\" class=\"interior\">";
		$varReturn.= "<input name='tot' id='tot' type='text' class='inputDisable' readonly style='text-align:right;width:50px' value=0 />";
		$varReturn.= "</td>";
		$varReturn.= "<td class=\"interior\"></td>";
		$varReturn.= "</tr>";
		$varReturn.= "<tr>";
		$varReturn.= "<tr>";
		$varReturn.= "<td height=25 colspan=10 valign=top aling=\"center\" class=\"FormTitulo\">";	
		$varReturn.= "<input id=\"bsav\" class=\"boton_guardar\" type=\"button\" style=\"cursor:pointer; width:150px;\" ";
		$varReturn.= "onclick=\"javascrip:xGrabarJS()\" value=\"Registrar Sobrante\" name=\"bsav\">";
		$varReturn.= "</td>";
		$varReturn.= "</tr>";
		$varReturn.= "</table>";	
		$varReturn.= "</form>";
		return $varReturn;
		}
						
	function ProcesoGrabar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))  ? $_SESSION["_CUSE"] : "1";
		$vnum = $varForm["num"];
		$varEmi = "'".FechaMySql($varForm["femi1"])."'";
		$varTip = (isset($varForm["tdcod1"]) && $varForm["tdcod1"]<>"")?$varForm["tdcod1"]:"NULL";
		$varPro = (isset($varForm["ccod1"]) && $varForm["ccod1"]<>"")?$varForm["ccod1"]:"NULL";
		$varDes = (isset($varForm["cnom"]) && $varForm["cnom"]<>"")?"'".$varForm["cnom"]."'":"NULL";
		
		$varRut = (isset($varForm["rcod"]) && $varForm["rcod"]<>"")?"'".$varForm["rcod"]."'":"'0'";
		$varLis = (isset($varForm["lcod"]) && $varForm["lcod"]<>"")?$varForm["lcod"]:"0";
		
		$varCon = (isset($varForm["cond1"]) && $varForm["cond1"]<>"")?$varForm["cond1"]:"NULL";
		$varVen = (isset($varForm["vcod1"]) && $varForm["vcod1"]<>"")?$varForm["vcod1"]:0;

		$varPed = (isset($varForm["nped"]) && $varForm["nped"]<>"")?"'".$varForm["nped"]."'":"NULL";
		$varGlo = (isset($varForm["glos"]) && $varForm["glos"]<>"")?"'".$varForm["glos"]."'":"NULL";
		$varLoc = 1;
		$varTot = $varForm["tot"];
		
		$varAsi = (isset($varForm["asi"]) && $varForm["asi"]<>"")?$varForm["asi"]:"NULL";
		
		$sql = "call spMante_Sobrante_Cab($varAsi, $varLoc, $varTip, $varCon, $varEmi, $varEmi, $varPro, $varDes, $varGlo, $varTot, $varUsr)";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		$varError  = $Fila[0];
		$NumCompra = $Fila[1];
		$NumDoc    = $Fila[2];
		if($varError=="OK") {
			for($i=1; $i<=$vnum; $i++) {	
				$varCod = str_pad($varForm["icod"][$i],6,"0",STR_PAD_LEFT);
				$varPre = (isset($varForm["ipre"][$i]) && $varForm["ipre"][$i]<>"")?$varForm["ipre"][$i]:0;			
				$varCan = (isset($varForm["ican"][$i]) && $varForm["ican"][$i]<>"")?$varForm["ican"][$i]:0;
				$varUni = (isset($varForm["iuni"][$i]) && $varForm["iuni"][$i]<>"")?"'".$varForm["iuni"][$i]."'":"NULL";
				$sqldet = "call spMante_Sobrante_Det($NumCompra, $varLoc, '$varCod', $varCan, $varPre, $varUni, $varEmi, $varUsr);";	
				$this->AbrirConexion();
				$rs = $this->Query($sqldet);
				$this->CerrarConexion();
				$varsql.=$sqldet;
				}
			}
		$sql = "call spMante_Sobrante_Update($varAsi, $NumCompra);";	
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		$varReturn[0] = $varError;
		$varReturn[1] = $NumDoc;
		return $varReturn;
		}
		
	function ProcesoEliminar($varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "call spMante_Sobrante_Anular($varCod, $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();	
		$varTipo = $this->NumField($rs);
		$varReturn = "";
		if ($varTipo==1) {
			$fila = $this->FetchArray($rs);
			$varReturn = $fila[0];
			}
		else {
			$varReturn.="CPRO\tPRODUCTO\t\t\t\t\t\t\t\t\tUM_COMP.\tCANT.COM.\tCANT.COM2\tUM_STK\tCANT.STK\tDIFER\n";
			$varReturn.="---------------------------------------------------------------------------------------------------------------------";
			$varReturn.="--------------------------------------------------------\n";
			while($fila = $this->FetchArray($rs)) {				
				$varReturn.=$fila["CPRO"]."\t".$fila["PRODUCTO"]."\t\t".$fila["UM_COMPRA"]."\t\t".number_format($fila["CANT_COMPRA"], 2,'.',',')."\t\t";
				$varReturn.=number_format($fila["CANT_COMPRA_STOCK"], 2,'.',',')."\t\t";
				$varReturn.=$fila["UM_STOCK"]."\t\t".str_pad(number_format($fila["CANT_STOCK"], 2,'.',','),6, STR_PAD_LEFT)."\t\t";
				$varReturn.=str_pad(number_format($fila["DIFERENCIA"], 2,'.',','),6, STR_PAD_LEFT)."\n";
				}
			}
		return $varReturn;
		}
	}
	
?>