<?php
	//-------------------------
	$StrFec=V($_POST['TxtFec']);
	$StrAlm=V($_POST['CboAlm']);
	$StrTot=V($_POST['TxtTot']);
	$StrObs=V($_POST['TxtObs']);
	//ACTIVAR DESDE OTRA PAGINA
	if(strlen($StrId)==0){
		$StrId=V($_GET['Id']);
		if(is_numeric($StrId)==false){$StrId="";
		}else{
			$StrCmd="AR";$LStrPag=V($_GET['Pag']);if(!is_numeric($LStrPag)){$LStrPag="";
		}}}	
	if(strlen($StrCmd)==0){
		$StrFec=date("d-m-y");
	}
	//FUNCION PARA ACTIVAR UN REGISTRO
	if(strlen($StrId)>0 && $StrCmd=="AR"){
		$Id=$StrId;
		$StrFec=gs("DATE_FORMAT(FEC,'%d-%m-%y')","vcaja","ID=$Id");		
		$StrAlm=gs("ALM","vcaja","ID=$Id");		
		$StrTot=gn("TOT","vcaja","ID=$Id");		
		$StrObs=gs("OBS","vcaja","ID=$Id");		
		$LStrFoc="document.getElementById('TxtFec').focus();";		
		$StrGT="S";
	}	
	if($StrCmd=="G" || $StrCmd=="M"){
		$StrAlm_=gn("id_almacen","almacenes","alm_nombre='$StrAlm'");
		$StrFec_=ToDate($StrFec);
	}
	//FUNCIONES DE ACTUALIZACION
	if($StrCmd=="G"){
		$Id=GenId("id_caja","caja_chica");
		$s="INSERT INTO caja_chica VALUES ($Id,'$StrFec_',$StrAlm_,$StrTot,'$StrObs')";
		ejt($s);
		
		if($LStrMM=="S") $LStrMsg="Datos registrados";
		$LStrFoc="document.getElementById('TxtFec').focus();";
		$StrId="";
		$StrFec=date("d-m-y");
		$StrTot="";
		$StrObs="";
		$StrGT="S";
	}
	if($StrCmd=="M"){
		if(strlen($StrGT)==0){
			$s="UPDATE caja_chica SET fecha='$StrFec_',
				id_almacen=$StrAlm_,total=$StrTot,obs='$StrObs' 
				WHERE id_caja=$StrId";	
			ejt($s);
			if($LStrMM=="S") $LStrMsg="Datos actualizados";
			$LStrFoc="document.getElementById('TxtFec').focus();";
			$StrId="";
			$StrFec=date("d-m-y");
			$StrTot="";
			$StrObs="";
			$StrGT="S";
		}
	}
	if($StrCmd=="E"){		
		if(strlen($StrGT)==0){
			$s="DELETE FROM caja_chica WHERE id_caja=$StrId";	
			ejt($s);
			if($LStrMM=="S") $LStrMsg="Registro Eliminado";
			$LStrFoc="document.getElementById('TxtFec').focus();";
			$StrId="";
			$StrFec="";
			$StrTot="";
			$StrObs="";
			$StrGT="S";
		}		
	}
	//////////////////////////////////
	if($StrGT=="S"){
		if(strlen($LStrMsg)>0){
			if(strlen($LStrFoc)==0){
				$LStrMsg="onload=\"alert('$LStrMsg');\"";
			}else{
				$LStrMsg="onload=\"alert('$LStrMsg');$LStrFoc;\"";
			}
		}else{
			if(strlen($LStrFoc)>0){
				$LStrMsg="onload=\"$LStrFoc;\"";
			}
		}
	}else{
		$LStrFoc="document.getElementById('TxtFec').focus();";
		$LStrMsg="onload=\"$LStrFoc;\"";
	}

?>