<?php

// Criar objeto Janela
$oJanelaPrinc = New R_Janela();
$oJanelaPrinc->sIdObj  = "iJan_LstEntDoc"; 
$oJanelaPrinc->nTop    = 30;
$oJanelaPrinc->nLeft   = 10;
$oJanelaPrinc->nWidth  = 820;   // Largura
$oJanelaPrinc->nHeight = 0;     // Altura
$oJanelaPrinc->nLeft  += ($nTela_W/2)-($oJanelaPrinc->nWidth/2);
$oJanelaPrinc->sTitulo = 'Documentos de entrada';
$oJanelaPrinc->sJavKeyDown = "return Car_".$sNomeAcesso.$nQdrNomeAcs.".Teclas_F(this,event);";
//
$sJavaTravarJ = "parent.document.getElementById('".$oJanelaPrinc->sIdObj."_Travar').style.visibility='visible'; parent.Disabled_In_Elems('".$oJanelaPrinc->sIdObj."',true);";
$oJanelaPrinc->sJavOnClickF = 
    $sJavaTravarJ.
	"parent.document.forms.fmPEntDoc.acao.value='FECHAR'; ".
	"parent.document.forms.fmPEntDoc.Ent_NumCam.value=''; ".
	"parent.document.forms.fmPEntDoc.submit();".
	"";
//
//
// Criar objeto GRID
$oTabelaRegs = New Pad_GridPesq();
$oTabelaRegs->sNomeTabela  = 'est_entrada_geral';
$oTabelaRegs->sIdObjTabela = 'iQdr_ListaEntDoc';
$oTabelaRegs->GLstCampos( 'ETG_IDN_ETG,Controle,60px,STRZERO=7;'.
                          'ETG_DATAENT,Entrada,76px,DTA;'.
                          '____NFISCAL,Documento e série,110px;'.
                          '____FOR_DSC,Fornecedor;'.
                          'ETG_DATAEMS,Emissão,76px,DTA;'.
                          'ETG_I_TOTAL,Subtotal,80px,MOE;'.
                          'ETG_VAL_DES,Desconto,80px,MOE;'.
                          'ETG_D_TOTAL,Total,80px,MOE;'
						 );
$oTabelaRegs->sCampoIndice = 'ETG_IDN_ETG';
$oTabelaRegs->nWidth  = $oJanelaPrinc->nWidth;
$oTabelaRegs->nHeight = 350;    // Altura
$oTabelaRegs->sCampoOnClick  = "Car_".$sNomeAcesso.$nQdrNomeAcs.".P_Sel(<NUMCAM>); Car_".$sNomeAcesso.$nQdrNomeAcs.".P_Atu();";
$oTabelaRegs->sLinhaOnClick  = "Car_".$sNomeAcesso.$nQdrNomeAcs.".PRow_Sel(<QTDCOL>,<SELLIN>);";
$oTabelaRegs->sLinhaOnDblClk = "Car_".$sNomeAcesso.$nQdrNomeAcs.".Pesq_Seleciona();";
$oTabelaRegs->sJavSelectReg = "sSelIndiceC = S_Indice;".
	                          "if (parseInt(sSelIndiceC)>0) {".
	                              "parent.document.getElementById('Ent_Doc_BT_Sel').style.display='inline-block';".
							  "}".
                              'parent.document.getElementById("in_EntDoc_DatIni").focus();';
//
// MONTAR LISTA DE CADASTROS
If ( $sAcao=="LISTAR" ) {
   If ($bDir_Consult) {
	  $nP_NumCam = @$_POST['Ent_NumCam']+0;
	  $s_DataIni = @$_POST['DataIni'];
	  $s_DataFim = @$_POST['DataFim'];
	  $n_Est_Doc = @$_POST['Estado_Doc']+0;
	  // Montar condição para a pesquisa
      $sWhereSQL = '';
	  $sOrderSQL = '';
      If ( $nP_NumCam==0 ) { $nP_NumCam=2; }
	  $aLstCampo = EXPLODE(',',@$oTabelaRegs->aLstCampos[$nP_NumCam-1]);
      If ( STRLEN(@$aLstCampo[0])>0 ) {
	     /*
         If ( STRLEN($sP_PChave)>0 ) {
			If ($nTip_Busca == 1) {
			   $sWhereSQL .= 'AND '.$aLstCampo[0].' LIKE "'.$sP_PChave.'%" ';
			}
			If ($nTip_Busca == 2) {
			   $sWhereSQL .= 'AND '.$aLstCampo[0].' LIKE "%'.$sP_PChave.'%" ';
			}				
	     }
		 */
		 $sOrderSQL = 'ORDER BY '.$aLstCampo[0].' ASC ';
      }
	  //
	  $n_DataIni = ConvertDataSTR(ConvertDataBRUS($s_DataIni));
	  $n_DataFim = ConvertDataSTR(ConvertDataBRUS($s_DataFim));
	  If ( $n_DataIni > ConvertDataSTR('2000-01-01') ) {
	     $sWhereSQL .= "AND ETG_DATAENT>='".DATE('Y-m-d',$n_DataIni)."' ";
	  } Else {
	     $n_DataIni = 0;
	  }
	  If ( $n_DataFim > ConvertDataSTR('2000-01-01') && $n_DataFim >= $n_DataIni ) {
	     $sWhereSQL .= "AND ETG_DATAENT<'".DATE('Y-m-d',$n_DataFim)." 23:59:59' ";
	  } Else {
	     $n_DataFim = 0;
	  }
	  If ($n_Est_Doc==0) {        // Efetivados
	     $sWhereSQL .= "AND ETG_CAN_OPE=0 AND ETG_EFETIVA=1 ";
	  } ElseIf ($n_Est_Doc==1) {  // Cancelados
	     $sWhereSQL .= "AND ETG_CAN_OPE>0 ";
	  } ElseIf ($n_Est_Doc==2) {  // Pendentes para efetivar
	     $sWhereSQL .= "AND ETG_CAN_OPE=0 AND ETG_EFETIVA=0 ";
	  }
	  //
	  $oTabelaRegs->sBDQuery =
		 "SELECT ".
		    "ETG_IDN_ETG,".
		    "ETG_DATAENT,".
		    "ETG_DATAEMS,".
		    "CONCAT(ETG_NFISCAL,'-',ETG_NFSERIE) AS ____NFISCAL,".
			"CONCAT(FOR_CODIGO ,'-',FOR_FANTAS ) AS ____FOR_DSC,".
			"ETG_I_TOTAL,".
			"ETG_VAL_DES,".
			"ETG_D_TOTAL ".
         "FROM est_entrada_geral ".
         "LEFT JOIN cad_fornecedor ON FOR_CODIGO=ETG_COD_FOR ".
         "WHERE 1=1 ".$sWhereSQL.
         $sOrderSQL.
         ";";
	  //
      // Tabela
      $sRet_TelaJ_HTML = $oTabelaRegs->MontaTabelaHTML();
      // Java
      $sRet_Javs .=
         "var iQdr_ListaEntDoc = parent.document.getElementById('".$oTabelaRegs->sIdObjTabela."');".
	     'iQdr_ListaEntDoc.innerHTML = '.JAVA_CharCode($sRet_TelaJ_HTML).';'.
	     '';
      // Java posterior
      $sRet_JavsPos .=
         'parent.Car_'.$sNomeAcesso.$nQdrNomeAcs.'.'.$oTabelaRegs->sNomeTabela.'_Rowsel = 1;'.
         'parent.Car_'.$sNomeAcesso.$nQdrNomeAcs.'.P_Sel('.$nP_NumCam.');'.
         "parent.document.getElementById('in_EntDoc_DatIni').value='".($n_DataIni==0 ? '' : DATE('d/m/Y',$n_DataIni) )."';".
         "parent.document.getElementById('in_EntDoc_DatFim').value='".($n_DataFim==0 ? '' : DATE('d/m/Y',$n_DataFim) )."';".
	     '';
      $sRet_TelaJ_HTML = '';
   }
//
// FECHAR
} ElseIf ( $sAcao=="FECHAR" ) {
   $sRet_Javs .=
	  "parent.document.getElementById('".$sNomeIdJ_Ant."_Travar').style.visibility='hidden';".
	  "parent.Disabled_In_Elems('".$sNomeIdJ_Ant."',false);".
	  $sJavaExePos.
	  'parent.document.getElementById("'.$sNomeIdCampo.'").focus();'.
      "parent.RmElem('".$oJanelaPrinc->sIdObj."');";
//
// JANELA TELA PRINCIPAL
} Else {
   //
   $oJanelaPrinc->aIdsObjList = ARRAY( 'in_EntDoc_DatIni', 'in_EntDoc_DatFim', 'sl_Estado_Doc' );
   // Tela HTML
   $sRet_TelaJ_HTML =
	  $oJanelaPrinc->MontaJanHTML(True).
      '<form name="fmPEntDoc" accept-charset="utf-8" method="post" action="./car_js.php" target="car_'.$sNomeAcesso.($nQdrNomeAcs+1).'">'.
       '<input name="mod" type="hidden" value="'.$sModulo.'">'.
       '<input name="submod" type="hidden" value="'.$sSubModulo.'">'.
       '<input name="acao" type="hidden" value="">'.
	   '<input name="nomeacs" type="hidden" value="'.$sNomeAcesso.'">'.
	   '<input name="Ent_NumCam" type="hidden" value="">'.
   	  '<table width="100%"></tr>'.
   	   '<td width="4px" height="10px" align="left">&nbsp;</td>'.
   	   '<td align="left" width="300px">'.
       	'<table border="0" cellspacing="0" cellpadding="0"><tr>'.
		 '<td width="60px" align="right">'.
		  'Período:&nbsp;'.
		 '</td>'.
		 '<td width="28px" align="center"><img src="images/bimg_calendario.png" border="0" id="bt_EntDoc_DatIni" style="cursor:pointer;"></td>'.
		 '<td width="77px">'.
		   '<input id="in_EntDoc_DatIni" value="'.DATE("d/m/Y").'" name="DataIni" type="text" maxlength="10" style="font-size:12px; width:99%;" autocomplete="off">'.
		 '</td>'.
		 '<td align="center" width="10px">'.
		  '-'.
		 '</td>'.
		 '<td width="28px" align="center"><img src="images/bimg_calendario.png" border="0" id="bt_EntDoc_DatFim" style="cursor:pointer;"></td>'.
		 '<td width="77px">'.
		   '<input id="in_EntDoc_DatFim" name="DataFim" type="text" maxlength="10" style="font-size:12px; width:99%;" autocomplete="off">'.
		 '</td>'.
		'</tr></table>'.
   	   '</td>'.
   	   '<td align="left">'.
		 '<select id="sl_Estado_Doc" name="Estado_Doc">'.
		  '<option value="0" selected>Efetivados</option>'.
		  '<option value="1">Cancelados</option>'.
		  '<option value="2">Pendentes para efetivar</option>'.
		 '</select>'.
   	   '</td>'.
   	   '<td align="right" width="130px">'.
   	   HTML_Botao( 3, 'EntDoc_BT_Pro'  , 'Car_'.$sNomeAcesso.$nQdrNomeAcs.'.P_Atu();'
	                , 'Procurar (F10)' ,'images/btimg_lupa.png',120).
   	   '</td>'.
   	   '<td width="4px" align="left">&nbsp;</td>'.
   	  '</tr></table>'.
      '</form>'.
	  $oTabelaRegs->MontaDivHtml().
   	  '<table width="100%"></tr>'.
   	   '<td width="4px" height="40px" align="left">&nbsp;</td>'.
   	   '</td>'.
   	   '<td>'.
   	    HTML_Botao( 3, 'Ent_Doc_BT_Sel',   'Car_'.$sNomeAcesso.$nQdrNomeAcs.'.Pesq_Seleciona();'
		             , 'Seleciona (ENTER)','images/btimg_ativar.png').'&nbsp;&nbsp;'.
   	   '</td>'.
   	   '<td width="120px" align="left">'.
   	    HTML_Botao( 3, 'Ent_Doc_BT_Fch'   , $oJanelaPrinc->sJavOnClickF
                     , 'Sair (ESC)'       ,'images/btimg_fechar.png').
   	   '</td>'.
   	  '</tr></table>'.
	  $oJanelaPrinc->MontaJanHTML(False);
   //
   $sRet_Javs .=
	  "parent.document.getElementById('".$sNomeIdJ_Ant."_Travar').style.visibility='visible';".
	  "parent.Disabled_In_Elems('".$sNomeIdJ_Ant."',true);".
	  'parent.document.getElementById("dv_MenuL_Barra").style.visibility="hidden";'.
      "var sSelIndiceC='';".
      "function P_Atu() {".
        "sSelIndiceC='';".
	    $oTabelaRegs->MontaJavaAgu().
	    "parent.document.getElementById('Ent_Doc_BT_Sel').style.display='none';".
     	"parent.document.forms.fmPEntDoc.acao.value='LISTAR'; ".
     	"parent.document.forms.fmPEntDoc.Ent_NumCam.value=nPesq_CampoSel+''; ".
     	"setTimeout( function() { parent.document.forms.fmPEntDoc.submit(); }, 100);".
      '}'.
	  'function Pesq_Seleciona() {'.
	    'parent.document.getElementById("'.$sNomeIdCampo.'").value = sSelIndiceC;'.
	    $oJanelaPrinc->sJavOnClickF.
	  '}'.
      $oTabelaRegs->MontaJavaPri();
      '';
   // Java posterior
   $sRet_JavsPos .=
	  "P_Atu();".
	  'parent.document.getElementById("in_EntDoc_DatIni").focus();'.
	  //
      'parent.Calendar.setup({ '.
        'inputField : "in_EntDoc_DatIni", '.
        'trigger    : "bt_EntDoc_DatIni", '.
        'onSelect   : function() { this.hide(); }, '.
        'showTime   : 0, '.
        'dateFormat : "%d/%m/%Y" '.
      '});'.
      'parent.Calendar.setup({ '.
        'inputField : "in_EntDoc_DatFim", '.
        'trigger    : "bt_EntDoc_DatFim", '.
        'onSelect   : function() { this.hide(); }, '.
        'showTime   : 0, '.
        'dateFormat : "%d/%m/%Y" '.
      '});'.
	  //
	  //
	  "function Teclas_F( Objeto, Evento ) {".
         "vNumTecla = parent.Tecla_Apertada(Evento);".
	     "if ( vNumTecla==116) { ".        //  ** [F5] **         Não atualizar
             //
	     "} else if ( vNumTecla==121) { ". //  ** [F10] **        Procurar
	         "P_Atu();".
	     "} else if ( vNumTecla==27) { ".  //  ** [ESC] **        (SAIR)
              "setTimeout( parent.document.getElementById('Ent_Doc_BT_Fch').onclick , 100);".
	     "} else if ( vNumTecla==13) { ". //   ** [ENTER] **      Selecionar
              "if ( parent.document.getElementById('Ent_Doc_BT_Sel').style.display == 'none') {".
                  "sTempId = parent.Proximo_TabObj(parent.document.getElementById('".$oJanelaPrinc->sIdObj."'),parent.sIdHasFocus);".
                  "if ( sTempId.length>0 ) {".
		 		     "var ObjPrx = parent.document.getElementById(sTempId);".
            	     "ObjPrx.focus();".
		 		     "if ( ObjPrx.type=='text' || ObjPrx.type=='textarea' ) {".
            	         "ObjPrx.select();".
		 		     "}".
                  "} else {".
				     "P_Atu();".
                     "parent.document.getElementById('in_EntDoc_DatIni').focus();".
                  "}".
			  "} else {".
                   "setTimeout( parent.document.getElementById('Ent_Doc_BT_Sel').onclick , 100);".
			  "}".
		 "} else {".
	         "P_TeclasPress_fm(Evento);".
		     "return true;".
		 "}".
		 "return false;".
	  '}'.
	  //
	  "";
}
?>