<?php 

    include_once '../auxiliar/login_fora_do_horario_guard.php';
    login_fora_do_horario_guard();

    include_once '../bd/bd_os.inc';
    include_once '../bd/funcoes.inc';
    include "../php/iniciaos.php" ;
    include "../auxiliar/datas.inc";
    include_once '../auxiliar/parametros.inc';
    include '../idiomas/config.inc';
    
    $p_soforma = recebevar("soforma");
    if ($p_soforma){
         setcookie ("soforma", $p_soforma,0,'/');
    }else{
         setcookie ("soforma", "", time() - 3600,'/');
    }   

    if($p_codtra == "null") {
      $transportadora = getTransportadoraPadrao();
      $p_codtra = $transportadora["codtra"];
      $p_transportadora = $transportadora["transportadora"];
    }
?>


<!DOCTYPE html>
<html>

<head>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>AFV 2 | <?php echo $o_dados_adicionais; ?></title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="./../web/bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="./../web/bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="./../web/bower_components/Ionicons/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="./../web/dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="./../web/dist/css/skins/_all-skins.min.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

  <!-- Google Font -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>

<body class="hold-transition skin-blue sidebar-mini">
  <!-- Site wrapper -->
  <div class="wrapper">

    <header class="main-header">
      <!-- Logo -->
      <a href="../html/cadastro.php" class="logo">
        <!-- mini logo for sidebar mini 50x50 pixels -->
        <span class="logo-mini"><b>A</b>ADV</span>
        <!-- logo for regular state and mobile devices -->
        <span class="logo-lg"><b>AFV</b> - ADV Tecnologia </span>
      </a>
      <!-- Header Navbar: style can be found in header.less -->
      <nav class="navbar navbar-static-top">
        <!-- Sidebar toggle button-->
        <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </a>
      </nav>
    </header>

    <!-- =============================================== -->
    <!-- Inserir modal aqui-->
    <div class="modal fade" id="modal-default">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title"><?php echo $m_relatorios; ?></h4>
          </div>
          <div class="modal-body">
            <p>
              <?php
                 include './../html/relatorios.php';              
                ?>
            </p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default pull-left" data-dismiss="modal"><?php echo $bt_sair; ?></button>
          </div>
        </div>
        <!-- /.modal-content -->
      </div>
      <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->
      <!-- Inserir modal aqui-->
      <div class="modal fade" id="modal-consulta">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title"><?php echo $o_consulta_de_dados; ?></h4>
          </div>
          <div class="modal-body">
            <p>
              <div id='content'></div>
            </p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default pull-left" data-dismiss="modal"><?php echo $bt_sair; ?></button>
          </div>
        </div>
        <!-- /.modal-content -->
      </div>
      <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->


    <!-- -->
    <div class="modal fade" id="modal-buscarcliente">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title"><?php echo $b_busca_cliente_nova_venda; ?></h4>
          </div>
          <div class="modal-body">
                                  
              <form action="../php/buscacli.php" method="post" name="procuracadastro" id="procuracadastro">
               
              <div class="box-body">
                <div class="form-group">
                  <label for="Razao"><?php echo $b_razao_social; ?></label>
                  <input name="razao" class="form-control" id="razao" placeholder="<?php echo $b_buscar_cliente; ?>" type="text">
                </div>

                

                <script> document.procuracadastro.razao.focus();</script>  
              </div>
              
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default pull-left" data-dismiss="modal"><?php echo $bt_sair; ?></button>
            <input type="submit" class="btn btn-primary pull-right" name="Enviar" value="<?php echo $bt_localizar; ?>" alt='Localizar' />
          </div>
          </form>   
        </div>
        <!-- /.modal-content -->
      </div>
      <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->                      

    <!-- Fim do modal -->

    <!-- Left side column. contains the sidebar -->
    <aside class="main-sidebar">
      <!-- sidebar: style can be found in sidebar.less -->
      <section class="sidebar">
        <!-- Sidebar user panel -->
        <div class="user-panel">
          <div class="pull-left image">
            <img src="./../icons/frame.png" class="img-circle" alt="User Image">
          </div>
          <div class="pull-left info">
            <p>
              <?php
            include_once '../bd/funcoes.inc';
            $p_codusu = lecookie("codusu"); 
            echo(TrazValorCampo('senhas','usuario', 'codusu', lecookie('codusu'))); 
          ?>
            </p>
          </div>
        </div>

        <!-- sidebar menu: : style can be found in sidebar.less -->
        <ul class="sidebar-menu" data-widget="tree">
          <li class="header"><?php echo $g_painel_navegacao; ?></li>
          <li class="treeview">
            <a href="#">
              <i class="fa fa-dashboard"></i> <span><?php echo $m_vendas; ?></span>
              <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
            </a>
            <ul class="treeview-menu">
              <li><a href="./buscahistvnd.php"><i class="fa fa-circle-o"></i><?php echo $m_historico_venda; ?> </a></li>
              <li><a href="#" data-toggle="modal" data-target="#modal-buscarcliente"><i class="fa fa-circle-o"></i> <?php echo $m_nova_venda; ?></a></li>
            </ul>
          </li>
          <li class="treeview">
            <a href="#">
              <i class="glyphicon glyphicon-user"></i> <span><?php echo $m_clientes; ?></span>
              <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
            </a>
            <ul class="treeview-menu">
              <li><a href="./cadastronovo.php"><i class="fa fa-circle-o"></i><?php echo $m_cadastrar_cliente; ?></a></li>
              <li><a href="#" data-toggle="modal" data-target="#modal-buscarcliente"><i class="fa fa-circle-o"></i>
              <?php echo $m_localizar_cliente; ?></a></li>
            </ul>
          </li>
          <li class="treeview">
            <a href="#" data-toggle="modal" data-target="#modal-default">
              <i class="fa fa-files-o"></i>
              <span><?php echo $m_relatorios; ?></span>
            </a>
          </li>
          <li>
            <a href="./produtos_consulta.php">
              <i class="glyphicon glyphicon-search"></i> <span><?php echo $m_consulta_produtos; ?></span>
            </a>
          </li>
          <li>
            <a href="../php/logoff.php">
              <i class="glyphicon glyphicon-off"></i>
              <span><?php echo $m_Logout; ?></span>
            </a>
          </li>
        </ul>
      </section>
      <!-- /.sidebar -->
    </aside>

    <!-- =============================================== -->

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <h1>
        <?php echo $o_dados_adicionais; ?>
        </h1>
        <ol class="breadcrumb">
          <!-- controle de paginas aqui-->
          <li><a href="#"><i class="fa fa-dashboard"></i> <?php echo $g_inicio; ?></a></li>
          <li><a href='#'><?php echo $bt_novo_pedido; ?></a></li>
          <li><a href='#'><?php echo $bt_finalizar_pedido; ?></a></li>
          <li><a href='#'><?php echo $o_dados_adicionais; ?></a></li>
        </ol>
      </section>

      <!-- Main content -->
      <section class="content">

        <!-- Default box -->
        <div class="box">
          <div class="box-header with-border">
            <h3 class="box-title"><?php echo $o_conferir_dados_adicionais; ?></h3>

            <div class="box-tools pull-right">
              <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
                <i class="fa fa-minus"></i></button>
              <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
                <i class="fa fa-times"></i></button>
            </div>
          </div>
          <div class="box-body">
            <!-- Inserir aqui-->
  















				<div id="conteudo">
				
				<form action="../php/pedidos.php" method="POST" name="novopedido" id="novopedido" >
				<input name="codcli" type="hidden" value ="<?php echo $p_codcli ?>" />
				<input name="razao" type="hidden" value ="<?php echo $p_razao ?>" />


				<input type="hidden" name="codloja" size="15" value=<?php echo $p_codloja ?> > 
				<input type="hidden" name="codtiposai" size="15" value=<?php echo $p_codtiposai ?> > 
				<input type="hidden" name="codvnd" size="15" value=<?php echo $p_codvnd ?> >
				<input type="hidden" name="codtra" size="15" value='<?php echo $p_codtra ?>'>
				<input type="hidden" name="codforma" size="25" value='<?php echo $p_codforma ?>'>
				<input type="hidden" name="codtipo" size="25" value='<?php echo $codTipo ?>'>
				<!-- palm -->
			
      	<?php 

          $p_disableTransp = $p_disableFormaPagto = $p_disableTipoPagto = "";
          $p_exibeBtnTransp = $p_exibeBtnFormaPagto = $p_exibeBtnTipoPagto = true;
          
          //verifica parametro para desabilitar o preenchimento dos 3 campos simultaneamente
          if ($p_nalt_transp_prazo == 1) {
            $p_disableTransp = $p_disableFormaPagto = $p_disableTipoPagto = "readonly";
            $p_exibeBtnTransp = $p_exibeBtnFormaPagto = $p_exibeBtnTipoPagto =false;
           
          }
          

          //verifica parametro para desabilitar o preenchimento do campo que ja vier preenchido.
          //somente o campo que ja vier preenchido do cadastro de cliente será desabilitado

          if ($p_bloqueia_prazo_tipo_transp == 1) {    
            DadosAdic($p_codloja2, $p_loja2, $p_codtra2, $p_transportadora2, $p_codforma2, $p_formapagto2,
                  $p_codvnd2, $p_vendedor2,  $p_razao2,$p_codtiposai2,$p_tiposai2, $p_codcli, $p_codusu,
                  $p_dtentrega2, $codTipo2, $tipoDePagamento2);

            if ($p_codtra2 <> 'null'){
              $p_disableTransp = "readonly";
              $p_exibeBtnTransp = false; 
            }

            if ($p_codforma2 <> 'null'){
              $p_disableFormaPagto = "readonly";
              $p_exibeBtnFormaPagto = false; 
            }

            if ($codTipo2 <> 'null'){
              $p_disableTipoPagto = "readonly";
              $p_exibeBtnTipoPagto = false; 
            }
          }
         
        ?>
  
      
      <?php 

			


							echo"
              $o_transportadora:<br />
                    <div class='input-group input-group-sm'>
											<input type='text' class='form-control'  name='transp' $p_disableTransp size='25' value='";
											if($p_codtra <> 'null'){ echo $p_transportadora; };
											echo "'>"; 
                      if ( $p_exibeBtnTransp ) {
                        echo"				
                          <span class='input-group-btn'>
                          <button onclick=chamaTransp() type='button' class='btn btn-info btn-flat' data-toggle='modal' data-target='#modal-consulta'>$bt_pesquisar </button>
                          </span>";
                      }
                echo "</div>";
										

								?>
					

          <?php echo $o_forma_de_pagamento; ?><br />
				<div class='input-group input-group-sm'>
				<input class='form-control' type="text" name="forma" <?php echo $p_disableFormaPagto; ?> value='<?php if ($p_codforma <> 'null'){echo $p_formapagto;} ?>'>
				<?php
				if ( $p_exibeBtnFormaPagto ) {
				echo "
				<span class='input-group-btn'>
				<button onclick=formaPagamento() data-toggle='modal' data-target='#modal-consulta' type='button' class='btn btn-info btn-flat'>$bt_pesquisar</button>
				</span>";
				}
				?>
				
				</div>


				<?php echo $o_tipo_de_Pagamento; ?><br />
				<div class='input-group input-group-sm'>
          <input class='form-control' type="text" name="tipoDePagamento" <?php echo $p_disableTipoPagto; ?> value='<?php if ($codTipo <> 'null'){echo $tipoDePagamento;} ?>'>
          <?php if ($p_exibeBtnTipoPagto) { ?>
              <span class='input-group-btn'>
                <button onclick=modalTipoDePagamento() data-toggle='modal' data-target='#modal-consulta' type='button' class='btn btn-info btn-flat'><?php echo $bt_pesquisar;?></button>
              </span>
           <?php } ?>
				</div>
		
				<?php
            include '../auxiliar/parametros.inc';

						if ($p_dtentrega){
							$dt = $p_dtentrega; 
						}else{
							$dt = date("d/m/Y");
						}
						
						echo "
						<div class='form-group'>
            $o_previsao_de_entrega<br />
										<div class='input-group input-group-sm'>
										<input class='form-control' type='text' name='dtentrega' size='25' value='$dt'>
						</div>";

						if ($p_mostraobs == 1){
								echo"
								<div class='form-group'>
                $o_obs
                  <textarea name='obs' class='form-control' rows='3'>$p_obs</textarea>
                </div>
								<div class='form-group'>
                $o_obs_interno
                  <textarea name='obs_interno' class='form-control' rows='3'>$p_obs_interno</textarea>
                </div>
              ";
										
						}else{
							echo "<input type='hidden' name='obs'> ";
						}
				?>		 
					
				</div>
	
				<br/>
				<br/>
				<a name='voltar' class='btn btn-primary' href='../php/prazoent.php'><?php echo $bt_voltar; ?></a>
				<a name='salvar' class='btn btn-success' href="javascript: salva();" ><?php echo $bt_salvar; ?></a>

				</form>
				</div>


























            <!-- Finalizar aqui-->
          </div>
          <!-- /.box-body -->
          <!-- /.box-footer-->
        </div>
        <!-- /.box -->

      </section>
      <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

    <?php  include_once '../html/footer.php'; ?>
   
  </div>
  <!-- ./wrapper -->

  <!-- jQuery 3 -->
  <script src="../web/bower_components/jquery/dist/jquery.min.js"></script>
  <!-- Bootstrap 3.3.7 -->
  <script src="../web/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
  <!-- SlimScroll -->
  <script src="../web/bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
  <!-- FastClick -->
  <script src="../web/bower_components/fastclick/lib/fastclick.js"></script>
  <!-- AdminLTE App -->
  <script src="../web/dist/js/adminlte.min.js"></script>
  <!-- AdminLTE for demo purposes -->
  <script src="../web/dist/js/demo.js"></script>
  <script>
    $(document).ready(function () {
      $('.sidebar-menu').tree()
    })
  </script>

<script>

function chamaTransp(){
			chamalink2("Transport='Pesquisar'");
};
function formaPagamento(){
			chamalink3("Formapg='Pesquisar'");
};
function modalTipoDePagamento(){
	$('#content')
   .load('../php/buscacamposos.php?tudo='+encodeURIComponent("tipoDePagamento"));    	
};
function salva(){
			chamalink("Altera='Salvar'");
};

function chamalink(complemento){
	var
				codcli = document.novopedido.codcli.value;
				razao = document.novopedido.razao.value;
				codloja = document.novopedido.codloja.value; 
				codtiposai = document.novopedido.codtiposai.value;
				codvnd = document.novopedido.codvnd.value;
				codtra = document.novopedido.codtra.value;
				codforma = document.novopedido.codforma.value; 
				codTipoPagamento = document.novopedido.codtipo.value; 
				transp = document.novopedido.transp.value;
				forma = document.novopedido.forma.value;
				tipoDePagamento = document.novopedido.tipoDePagamento.value;
				entrega = document.novopedido.dtentrega.value; 
				obs = document.novopedido.obs.value;
				obsInterno = document.novopedido.obs_interno.value;
       
        self.location.href="../php/pedidos.php?codcli="+codcli+"&razao='"+razao+
				"'&codloja="+codloja+"&codtiposai="+codtiposai+"&codvnd="+codvnd+"&codtra="+
				codtra+"&codforma="+codforma+"&transp="+transp+"&forma="+forma+"&dtentrega="+entrega+
				"&obs="+encodeURIComponent(obs)+"&obs_interno="+encodeURIComponent(obsInterno)+"&tipoDePagamento="+tipoDePagamento+"&codTipoPagamento="+codTipoPagamento
        +"&"+complemento;
};


function chamalink2(complemento){
	var
				codcli = document.novopedido.codcli.value;
				razao = document.novopedido.razao.value;
				codloja = document.novopedido.codloja.value; 
				codtiposai = document.novopedido.codtiposai.value;
				codvnd = document.novopedido.codvnd.value;
				codtra = document.novopedido.codtra.value;
				codforma = document.novopedido.codforma.value; 
				transp = document.novopedido.transp.value;
				forma = document.novopedido.forma.value;
				entrega = document.novopedido.dtentrega.value; 
				obs = document.novopedido.obs.value;
        
        if (transp == '') {
         tudo = 'tra';
       }

  $('#content')
   .load('../php/buscacamposos.php?tudo='+encodeURIComponent(tudo)+'&transp='+encodeURIComponent(transp)+'&forma='+encodeURIComponent(forma));    	
		// <!-- /palm -->
};

function chamalink3(complemento){
	var
				codcli = document.novopedido.codcli.value;
				razao = document.novopedido.razao.value;
				codloja = document.novopedido.codloja.value; 
				codtiposai = document.novopedido.codtiposai.value;
				codvnd = document.novopedido.codvnd.value;
				codtra = document.novopedido.codtra.value;
				codforma = document.novopedido.codforma.value; 
				transp = document.novopedido.transp.value;
				forma = document.novopedido.forma.value;
				entrega = document.novopedido.dtentrega.value; 
				obs = document.novopedido.obs.value;
        tudo = '';
        console.log("FORMA>>", forma)
       
       if (forma == '') {
         tudo = 'for';
       }

  $('#content')
   .load('../php/buscacamposos.php?tudo='+encodeURIComponent(tudo)+'&transp='+encodeURIComponent('')+'&forma='+encodeURIComponent(forma));    	
};

</script>
</body>

</html>
