<?php
    require 'conexion.php';
    require_once('functions.php');
    include(HEADER_TEMPLATE);
    $query_artigos = "SELECT materiais.material FROM materiais";
	$resultado_artigos=$mysqli->query($query_artigos);

    $cidades = "SELECT nome FROM tb_cidades order by nome";
    $estados = "SELECT uf FROM tb_estados";
?>
        <form method="POST" action="companies_salvar.php" autocomplete="off">
            <div class="container">  
                <div class="row">
                    <div class="form-group col-md-5">
                        <label for="tp"></label>
                        <div class="form-group">
                            <label class="radio-inline  col-md-2">
                                <input type="radio" id="type" name="type" value="C" checked> CLIENTE
                            </label>
                            
                            <label class="radio-inline">
                                <input type="radio" id="type" name="type" value="F"> FORNECEDOR
                            </label>
                        </div>                
                    </div>        
                </div>
                <div class="row">

                    <div class="form-group col-md-4">
                        <input type="text" class="form-control" id="company" name="company" placeholder="Informe o nome da empresa" style='text-transform:uppercase' required autofocus>
                    </div>
                        
                    <div class="form-group col-md-4">
                        <input type="text" class="form-control" id="popular_name" name="popular_name" placeholder="Informe Nome Fantasia" style='text-transform:uppercase' required>
                    </div>

                    <div class="form-group col-md-2">
                        <input type="text" class="form-control" id="cpf_cnpj" name="cpf_cnpj" placeholder="CNPJ" required>
                        <script>
                            jQuery(function($){
                            $("#cpf_cnpj").mask("99.999.999/9999-99");
                            });
                        </script>
                    </div>

                    <div class="form-group col-md-2">
                        <input type="text" class="form-control" id="ie" name="ie" placeholder="Inscrição Estadual" maxlength="20">
                    </div>
                        
                </div>

                <div class="row">
                    <div class="form-group col-md-4">
                        <input type="text" class="form-control" id="address" name="address" placeholder="Endereço principal da empresa" style='text-transform:uppercase' required>
                    </div>

                    <div class="form-group col-md-3">
                        <select class="form-control" id="city" name="city" required>
                        <option value="">Selecione a Cidade</option>
                            <?php
                             $resultado_=$mysqli->query($cidades);
                             while($row = $resultado_->fetch_assoc()) { ?>
                                <option value="<?php echo $row['nome']; ?>"><?php echo $row['nome']; ?></option>
                            <?php } ?>
                        </select>
                    </div>

                    <div class="form-group col-md-2">
                        <input type="text" class="form-control" id="hood" name="hood" placeholder="Bairro" style='text-transform:uppercase'>
                    </div>
                    
                    <div class="form-group col-md-2">
                        <input type="text" class="form-control" id="zip_code" name="zip_code" placeholder="CEP" required>
                        <script>
                            jQuery(function($){
                                $("#zip_code").mask("99999-999");
                            });
                        </script>

                        </div>
                   
                    <div class="form-group col-md-1">
                        <select class="form-control" id="state" name="state" required>
                            <?php
                             $resultado_e=$mysqli->query($estados);
                             while($row = $resultado_e->fetch_assoc()) { ?>
                                <option value="<?php echo $row['uf']; ?>"><?php echo $row['uf']; ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="row">                

                    <div class="form-group col-md-4">
                        <input type="text" class="form-control" id="contact1" name="contact1" placeholder="Nome contato" style='text-transform:uppercase' required>
                    </div>
                    
                    <div class="form-group col-md-4">
                        <input type="email" class="form-control" id="email1" name="email1" placeholder="Email" style='text-transform:uppercase'>
                    </div>
                    
                    <div class="form-group col-md-2">
                        <input type="tel" class="form-control" id="phone1" name="phone1" placeholder="Fone" style='text-transform:uppercase' required> 
                        <script>
                            jQuery(function($){
                                $("#phone1").mask("(99)9999-9999");
                            });
                        </script>
                    </div>
                    <div class="form-group col-md-2">
                        <input type="tel" class="form-control" id="cell1" name="cell1" placeholder="celular" style='text-transform:uppercase'>
                        <script>
                            jQuery(function($){
                                $("#cell1").mask("(99)99999-9999");
                            });
                        </script>
                    </div>
                </div>                

                <div class="row">                
                    <div class="container">                     
                        <a href="#demo" data-toggle="collapse">contato adicional</a>                        
                    </div>
                    <div id="demo" class="collapse">
                        <div class="form-group col-md-4">
                            <input type="text" class="form-control" id="contact2" name="contact2" placeholder="Contato (opcional)" style='text-transform:uppercase'>
                        </div>
                        
                        <div class="form-group col-md-4">
                            <input type="email" class="form-control" id="email2" name="email2" placeholder="email (opcional)" style='text-transform:uppercase'>
                        </div>
                        
                        <div class="form-group col-md-2">
                            <input type="tel" class="form-control" id="phone2" name="phone2" placeholder="telefone (opcional)" style='text-transform:uppercase'>
                            <script>
                                jQuery(function($){
                                    $("#phone2").mask("(99)9999-9999");
                                });
                            </script>
                        </div>
                        
                        <div class="form-group col-md-2">
                            <input type="tel" class="form-control" id="cell2" name="cell2" placeholder="celular (opcional)" style='text-transform:uppercase'>
                            <script>
                                jQuery(function($){
                                    $("#cell2").mask("(99)99999-9999");
                                });
                            </script>

                        </div>
                        
                        <div class="container">                     
                            <a href="#demo2" data-toggle="collapse">contato adicional</a>                        
                        </div>

                    </div>
                    <div id="demo2" class="collapse">
                    
                        <div class="form-group col-md-4">
                            <input type="text" class="form-control" id="contact3" name="contact3" placeholder="Contato (opcional)" style='text-transform:uppercase'>
                        </div>
                        
                        <div class="form-group col-md-4">
                            <input type="email" class="form-control" id="email3" name="email3" placeholder="email opcional" style='text-transform:uppercase'>
                        </div>
                        
                        <div class="form-group col-md-2">
                            <input type="tel" class="form-control" id="phone3" name="phone3" placeholder="telefone opcional" style='text-transform:uppercase'>
                            <script>
                                jQuery(function($){
                                    $("#phone3").mask("(99)9999-9999");
                                });
                            </script>
                        </div>
                        
                        <div class="form-group col-md-2">
                            <input type="tel" class="form-control" id="cell3" name="cell3" placeholder="celular opcional" style='text-transform:uppercase'>
                            <script>
                                jQuery(function($){
                                    $("#cell3").mask("(99)99999-9999");
                                });
                            </script>
                        </div>
                    </div>
                </div>
                <hr>
                <div class="row">                

                    <div class="form-group col-md-2">
                        <label for="material">Artigo</label>
                        <select multiple class="form-control" id="material" name="material[]" required>

                            <?php
                             $resultado_artigos=$mysqli->query($query_artigos);
                             while($row = $resultado_artigos->fetch_assoc()) { ?>
                                <option value="<?php echo $row['material']; ?>"><?php echo $row['material']; ?></option>
                            <?php } ?>
                        </select>
                    </div>

                    <div class="form-group col-md-8">
                        <label for="obs">Observação</label>
                        <input type="text" class="form-control" id="obs" name="obs" placeholder="Observações" style='text-transform:uppercase'>
                    </div>

                    <div class="form-group col-md-2">
                        <label for="ativo">Cliente ATIVO?</label>
                        
                        <div class="form-group">
                            
                            <label class="radio-inline  col-md-3">
                                <input type="radio" id="ativo" name="ativo" value="1" checked> SIM
                            </label>
                            
                            <label class="radio-inline">
                                <input type="radio" id="ativo" name="ativo" value="0"> NÃO
                            </label>
                        </div> 
                    </div>                    
                    
                </div>	
                <div class="row">                    
                    <div class="form-group">
                        <div class="col-xs-6 col-xs-offset-3 col-sm-4 col-sm-offset-0">
                            <a href="companies_index.php" class="btn btn-primary">Voltar</a>
                            <button type="submit" class="btn btn-primary">Gravar Registro</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
<?php include(FOOTER_TEMPLATE); ?>        
