<?php

//USING
require_once 'controls/verifylogin.php';
require_once '../Class/model/ContasModel.php';
require_once '../Class/controller/ContasControl.php';
require_once '../Class/model/GrupoContasModel.php';

$control = new ContasControl();
$model = new ContasModel();

$control->setAction();
$control->setId();

$action = $control->getAction();
$id = $control->getId();

//LoadDados
if ($id > 0)
{
	$model->load($id);
}

if($action == 'save')
{
	try 
	{
		$control->GetData();
		header( 'Location: contas.php' );	
	} 
	catch(Exception $err)
	{
		echo "<script>alert('Ocorreu um problema ao salvar o registro.');</script>";
	}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Módulo Financeiro</title>

<?php include_once('controls/import.php'); ?>
<script src="js/contas.js" type="text/javascript"></script>

</head>
<body>

<?php include_once('controls/header.php'); ?>

<div class="content">

<div class="form"><?php include_once('controls/menu.php'); ?>

<div id="conteudo-site">

<div class="titulo-conteudo-site"><img src="images/applications.png"
	title="" alt="" /> Cadastro de Contas</div>

	<form id="frmRegister" method="post" action=""><input type="hidden"
	id="hdnAction" name="action" value="save" /> <input type="hidden"
	id="hdnId" name="Id" value="<?php echo $model->getId();?>" />

	<table border="0" cellpadding="3" cellspacing="0" class="tblGeral"
	width="100%">
	<tr>
		<td><span class="title">Número da Conta:</span></td>
		<td><input type="text" id="numero" name="numero" class="content-data"
			style="width: 60px;" onkeyup="formataInteiro(this,event);" value="<?php echo $model->getNumero();?>" /> *</td>
	</tr>
	<tr>
		<td><span class="title">Nome:</span></td>
		<td><input type="text" id="nome" name="nome" class="content-data"
			style="width: 190px;" value="<?php echo $model->getNome();?>" /> *</td>
	</tr>
	<tr>
		<td><span class="title">N. da Conta Reduzida:</span></td>
		<td><input type="text" id="ncontareduzida" name="ncontareduzida" class="content-data"
			style="width: 60px;" onkeyup="formataInteiro(this,event);" value="<?php echo $model->getNumContaReduzida();?>" /> *</td>
	</tr>
	<tr>
		<td><span class="title">Grupo:</span></td>
		<td>
		<select id="grupo" name="grupo" class="content-data">
			<option value="">Selecione</option>
			<?php 
			
				$grupoContas = new GrupoContasModel();
				
				foreach ($grupoContas->listAll() as $item) {
				
					$select = '';
					if ($item->getId() == $model->getGrupo())
					{
						$select = "selected='selected'";
					}
					
					echo "<option value='{$item->getId()}' {$select}>{$item->getNome()}</option>";
				}
			
			?>
		
		</select> *</td>
	</tr>
	<tr>
		<td><span class="title">Ordem:</span></td>
		<td><input type="text" id="ordem" name="ordem" class="content-data"
			style="width: 190px;" value="<?php echo $model->getOrdem();?>" onkeyup="formataInteiro(this,event);" /> *</td>
	</tr>
	<tr>
		<td><span class="title">Histórico Padrão:</span></td>
		<td><input type="text" id="historicopadrao" name="historicopadrao" class="content-data"
			style="width: 190px;" value="<?php echo $model->getHistoricoPadrao();?>" /> *</td>
	</tr>
</table>

<div id="pBotoes" style="text-align: right"><span>&nbsp;</span> <br />
<input type="submit" id="btnSalvar" name="btnSalvar" class="submit" value="Salvar" /> <input
	type="button" name="btnCancelar" class="submit" value="Cancelar"
	onclick="window. location.href='tiporecebimentos.php'" /></div>

</form>

</div>

</div>

</div>

<?php include_once('controls/footer.php'); ?>

</body>
</html>
