
<?php 
//USING

require_once('../Connections/paivaconex.php'); 
require_once('funcoes.php'); 

header('Content-Type: text/html; charset=utf-8');

?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE mfin_recebimentos SET Cliente_Id=%s, Pasta_Id=%s, Tipo=%s, Forma=%s, Banco_Id=%s, NumeroNota=%s, Emissao=%s, Vencimento=%s, Recebimento=%s, Juros=%s, Multa=%s, Desconto=%s, pis=%s, cofins=%s, csll=%s, ir=%s, Valor=%s, Detalhe=%s, Cheque=%s, outros=%s, outros2=%s, outros3=%s, outros4=%s, honorarios=%s  WHERE Id=%s",
                       GetSQLValueString($_POST['Cliente_Id'], "int"),
                       GetSQLValueString($_POST['Pasta_Id'], "int"),
                       GetSQLValueString($_POST['Tipo'], "text"),
                       GetSQLValueString($_POST['Forma'], "int"),
                       GetSQLValueString($_POST['Banco_Id'], "text"),
                       GetSQLValueString($_POST['NumeroNota'], "text"),
                       GetSQLValueString(convertdata($_POST['Emissao']), "date"),
                       GetSQLValueString(convertdata($_POST['Recebimento']), "date"),
                       GetSQLValueString(convertdata($_POST['Recebimento']), "date"),
                       GetSQLValueString(numerobrasil($_POST['Juros']), "double"),
                       GetSQLValueString(numerobrasil($_POST['Multa']), "double"),
                       GetSQLValueString(numerobrasil($_POST['Desconto']), "double"),
                       GetSQLValueString(numerobrasil($_POST['pis']), "double"),
                       GetSQLValueString(numerobrasil($_POST['cofins']), "double"),
                       GetSQLValueString(numerobrasil($_POST['csll']), "double"),
                       GetSQLValueString(numerobrasil($_POST['ir']), "double"),
                       GetSQLValueString(numerobrasil($_POST['Valor']), "double"),
                       GetSQLValueString($_POST['Detalhe'], "text"),
                       GetSQLValueString($_POST['Cheque'], "text"),
                       GetSQLValueString(numerobrasil($_POST['outros']), "double"),
					   GetSQLValueString(numerobrasil($_POST['outros2']), "double"),
					   GetSQLValueString(numerobrasil($_POST['outros3']), "double"),
					   GetSQLValueString(numerobrasil($_POST['outros4']), "double"),
					   GetSQLValueString(numerobrasil($_POST['honorarios']), "double"),
					   GetSQLValueString($_POST['Id'], "int")
					   );

  mysql_select_db($database_paivaconex, $paivaconex);
  $Result1 = mysql_query($updateSQL, $paivaconex) or die(mysql_error());
}


mysql_select_db($database_paivaconex, $paivaconex);
$query_tipo = "SELECT * FROM mfin_tiposrecebimentos ORDER BY Id ASC";
$tipo = mysql_query($query_tipo, $paivaconex) or die(mysql_error());
$row_tipo = mysql_fetch_assoc($tipo);
$totalRows_tipo = mysql_num_rows($tipo);

mysql_select_db($database_paivaconex, $paivaconex);
$query_pasta = "SELECT * FROM mfin_pastas ORDER BY Numero ASC";
$pasta = mysql_query($query_pasta, $paivaconex) or die(mysql_error());
$row_pasta = mysql_fetch_assoc($pasta);
$totalRows_pasta = mysql_num_rows($pasta);

mysql_select_db($database_paivaconex, $paivaconex);
$query_cliente = "SELECT * FROM mfin_clientes ORDER BY NomeFantasia ASC";
$cliente = mysql_query($query_cliente, $paivaconex) or die(mysql_error());
$row_cliente = mysql_fetch_assoc($cliente);
$totalRows_cliente = mysql_num_rows($cliente);

mysql_select_db($database_paivaconex, $paivaconex);
$query_forma = "SELECT * FROM mfin_formaspagamentos ORDER BY Id ASC";
$forma = mysql_query($query_forma, $paivaconex) or die(mysql_error());
$row_forma = mysql_fetch_assoc($forma);
$totalRows_forma = mysql_num_rows($forma);

mysql_select_db($database_paivaconex, $paivaconex);
$query_banco = "SELECT * FROM mfin_bancos";
$banco = mysql_query($query_banco, $paivaconex) or die(mysql_error());
$row_banco = mysql_fetch_assoc($banco);
$totalRows_banco = mysql_num_rows($banco);


mysql_select_db($database_paivaconex, $paivaconex);
$query_recebimentos = "SELECT *, DATE_FORMAT(Emissao,'%d/%m/%Y') as dt_emissao, DATE_FORMAT(Vencimento,'%d/%m/%Y') as dt_vencimento, DATE_FORMAT(Recebimento,'%d/%m/%Y') as dt_recebimento FROM mfin_recebimentos WHERE Id = ".$_GET['id']."";
$recebimentos = mysql_query($query_recebimentos, $paivaconex) or die(mysql_error());
$row_recebimentos = mysql_fetch_assoc($recebimentos);
$totalRows_recebimentos = mysql_num_rows($recebimentos);

require_once 'controls/verifylogin.php';

?>

<!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>
<script src="js/jquery-1.7.2.js" type="text/javascript"></script>
<script src="js/jquery.maskedinput-1.3.min.js" type="text/javascript"></script>
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script>
        jQuery(function($){
		   $("#Emissao").mask("99/99/9999");
		   $("#Vencimento").mask("99/99/9999");
		   $("#Recebimento").mask("99/99/9999");
		 });
        
</script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<?php include_once('controls/import.php'); ?>
</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 Recebimentos</div>
<p>&nbsp;</p>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Cliente:</td>
      <td><select name="Cliente_Id">
        <?php 
do {  
?>
        <option value="<?php echo $row_cliente['Id']?>" <?php if (!(strcmp($row_cliente['Id'], htmlentities($row_recebimentos['Cliente_Id'], ENT_COMPAT, '')))) {echo "SELECTED";} ?>><?php echo  utf8_decode($row_cliente['NomeFantasia'])?></option>
        
        
        <?php
} while ($row_cliente = mysql_fetch_assoc($cliente));
?>
      </select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Pasta:</td>
      <td><select name="Pasta_Id">
        <?php 
do {  
?>
        <option value="<?php echo $row_pasta['Id']?>" <?php if (!(strcmp($row_pasta['Id'], htmlentities($row_recebimentos['Pasta_Id'], ENT_COMPAT, '')))) {echo "SELECTED";} ?>><?php echo utf8_decode($row_pasta['Numero'].' '.$row_pasta['Nome'])?></option>
        <?php
} while ($row_pasta = mysql_fetch_assoc($pasta));
?>
        </select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Tipo:</td>
      <td><select name="Tipo">
        <?php 
do {  
?>
        <option value="<?php echo $row_tipo['Id']?>" <?php if (!(strcmp($row_tipo['Id'], htmlentities($row_recebimentos['Tipo'], ENT_COMPAT, '')))) {echo "SELECTED";} ?>><?php echo $row_tipo['Nome']?></option>
        <?php
} while ($row_tipo = mysql_fetch_assoc($tipo));
?>
        </select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Forma:</td>
      <td><select name="Forma">
        <?php 
do {  
?>
        <option value="<?php echo $row_forma['Id']?>" <?php if (!(strcmp($row_forma['Id'], htmlentities($row_recebimentos['Forma'], ENT_COMPAT, '')))) {echo "SELECTED";} ?>><?php echo $row_forma['Nome']?></option>
        <?php
} while ($row_forma = mysql_fetch_assoc($forma));
?>
        </select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Banco:</td>
      <td><select name="Banco_Id">
        <?php 
do {  
?>
        <option value="<?php echo $row_banco['Id']?>" <?php if (!(strcmp($row_banco['Id'], htmlentities($row_recebimentos['Banco_Id'], ENT_COMPAT, '')))) {echo "SELECTED";} ?>><?php echo $row_banco['NomeConta']?></option>
        <?php
} while ($row_banco = mysql_fetch_assoc($banco));
?>
        </select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">NumeroNota:</td>
      <td><input type="text" name="NumeroNota" value="<?php echo htmlentities($row_recebimentos['NumeroNota'], ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Emissao:</td>
      <td><input type="text" name="Emissao" value="<?php echo htmlentities($row_recebimentos['dt_emissao'], ENT_COMPAT, ''); ?>" size="32" id="Emissao" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Recebimento:</td>
      <td><input type="text" name="Recebimento" value="<?php echo htmlentities($row_recebimentos['dt_recebimento'], ENT_COMPAT, ''); ?>" size="32" id="Recebimento" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Juros:</td>
      <td><span id="sprytextfield1">
      <input type="text" name="Juros" value="<?php echo htmlentities(number_format($row_recebimentos['Juros'],2,',','.'), ENT_COMPAT, ''); ?>" size="32" />
      <span class="textfieldRequiredMsg">Um valor e necessario.</span><span class="textfieldInvalidFormatMsg">Formato invalido.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Multa:</td>
      <td><span id="sprytextfield2">
      <input type="text" name="Multa" value="<?php echo htmlentities(number_format($row_recebimentos['Multa'],2,',','.'), ENT_COMPAT, ''); ?>" size="32" />
      <span class="textfieldRequiredMsg">Um valor e necessario.</span><span class="textfieldInvalidFormatMsg">Formato invalido.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Desconto:</td>
      <td><span id="sprytextfield3">
      <input type="text" name="Desconto" value="<?php echo htmlentities(number_format($row_recebimentos['Desconto'],2,',','.'), ENT_COMPAT, ''); ?>" size="32" />
      <span class="textfieldRequiredMsg">Um valor e necessario.</span><span class="textfieldInvalidFormatMsg">Formato invalido.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Pis:</td>
      <td><span id="sprytextfield4">
      <input type="text" name="pis" value="<?php echo htmlentities(number_format($row_recebimentos['pis'],2,',','.'), ENT_COMPAT, ''); ?>" size="32" />
      <span class="textfieldRequiredMsg">Um valor e necessario.</span><span class="textfieldInvalidFormatMsg">Formato invalido.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Cofins:</td>
      <td><span id="sprytextfield5">
      <input type="text" name="cofins" value="<?php echo htmlentities(number_format($row_recebimentos['cofins'],2,',','.'), ENT_COMPAT, ''); ?>" size="32" />
      <span class="textfieldRequiredMsg">Um valor e necessario.</span><span class="textfieldInvalidFormatMsg">Formato invalido.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Csll:</td>
      <td><span id="sprytextfield6">
      <input type="text" name="csll" value="<?php echo htmlentities(number_format($row_recebimentos['csll'],2,',','.'), ENT_COMPAT, ''); ?>" size="32" />
      <span class="textfieldRequiredMsg">Um valor e necessario.</span><span class="textfieldInvalidFormatMsg">Formato invalido.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Ir:</td>
      <td><span id="sprytextfield7">
      <input type="text" name="ir" value="<?php echo htmlentities(number_format($row_recebimentos['ir'],2,',','.'), ENT_COMPAT, ''); ?>" size="32" />
      <span class="textfieldRequiredMsg">Um valor e necessario.</span><span class="textfieldInvalidFormatMsg">Formato invalido.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Valor:</td>
      <td><span id="sprytextfield8">
      <input type="text" name="Valor" value="<?php echo htmlentities(number_format($row_recebimentos['Valor'],2,',','.'), ENT_COMPAT, ''); ?>" size="32" />
      <span class="textfieldRequiredMsg">Um valor e necessario.</span><span class="textfieldInvalidFormatMsg">Formato invalido.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Detalhe:</td>
      <td><textarea name="Detalhe" cols="50" rows="5"><?php echo htmlentities($row_recebimentos['Detalhe'], ENT_COMPAT, ''); ?></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Cheque:</td>
      <td><input type="text" name="Cheque" value="<?php echo htmlentities($row_recebimentos['Cheque'], ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">IPREM:</td>
      <td><input name="outros" type="text" id="outros" value="<?php echo htmlentities(number_format($row_recebimentos['outros'],2,',','.'), ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">HSPMP:</td>
      <td><input name="outros2" type="text" id="outros2" value="<?php echo htmlentities(number_format($row_recebimentos['outros2'],2,',','.'), ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">IRRF - Multi:</td>
      <td><input name="outros3" type="text" id="outros3" value="<?php echo htmlentities(number_format($row_recebimentos['outros3'],2,',','.'), ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Outros:</td>
      <td><input name="outros4" type="text" id="outros4" value="<?php echo htmlentities(number_format($row_recebimentos['outros4'],2,',','.'), ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Honorarios:</td>
      <td><input name="honorarios" type="text" id="honorarios" value="<?php echo number_format($row_recebimentos['honorarios'],2,',','.'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Atualizar registro" /></td>
    </tr>
  </table>
  <input type="hidden" name="Id" value="<?php echo $row_recebimentos['Id']; ?>" />
  <input type="hidden" name="MM_update" value="form1" />
  <input type="hidden" name="Id" value="<?php echo $row_recebimentos['Id']; ?>" />
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>

</div>

</div>

<?php include_once('controls/footer.php'); ?>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "currency", {format:"dot_comma"});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "currency", {format:"dot_comma"});
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "currency", {format:"dot_comma"});
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "currency", {format:"dot_comma"});
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "currency", {format:"dot_comma"});
var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6", "currency", {format:"dot_comma"});
var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7", "currency", {format:"dot_comma"});
var sprytextfield8 = new Spry.Widget.ValidationTextField("sprytextfield8", "currency", {format:"dot_comma"});
</script>
</body>
</html>
<?php
mysql_free_result($tipo);

mysql_free_result($pasta);

mysql_free_result($cliente);

mysql_free_result($forma);

mysql_free_result($banco);

mysql_free_result($recebimentos);
?>
