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

?>
<?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_pagamentos_2 SET Banco=%s, Fornecedor=%s, Emissao=%s, Vencimento=%s, DtPagamento=%s, Cliente=%s, Pasta=%s, NumFatura=%s, Detalhe=%s, Valor=%s, Ir=%s, Pis=%s, Cofins=%s, Csll=%s, Inss=%s, Iss=%s, Juros=%s, isss=%s, Multa=%s, Desconto=%s, diferenca=%s, outros=%s, Baixadoem=%s, FormaPagamento=%s, Cheque=%s WHERE Id=%s",
                       GetSQLValueString($_POST['Banco'], "int"),
                       GetSQLValueString($_POST['Fornecedor'], "int"),
                       GetSQLValueString(convertdata($_POST['Emissao']), "date"),
                       GetSQLValueString(convertdata($_POST['DtPagamento']), "date"),
                       GetSQLValueString(convertdata($_POST['DtPagamento']), "date"),
                       GetSQLValueString($_POST['Cliente'], "int"),
                       GetSQLValueString($_POST['Pasta'], "int"),
                       GetSQLValueString($_POST['NumFatura'], "text"),
                       GetSQLValueString($_POST['Detalhe'], "text"),
                       GetSQLValueString(numerobrasil($_POST['Valor']), "double"),
                       GetSQLValueString(numerobrasil($_POST['Ir']), "double"),
                       GetSQLValueString(numerobrasil($_POST['Pis']), "double"),
                       GetSQLValueString(numerobrasil($_POST['Cofins']), "double"),
                       GetSQLValueString(numerobrasil($_POST['Csll']), "double"),
                       GetSQLValueString(numerobrasil($_POST['Inss']), "double"),
                       GetSQLValueString(numerobrasil($_POST['Iss']), "double"),
                       GetSQLValueString(numerobrasil($_POST['Juros']), "double"),
                       GetSQLValueString(numerobrasil($_POST['isss']), "int"),
                       GetSQLValueString(numerobrasil($_POST['Multa']), "double"),
                       GetSQLValueString(numerobrasil($_POST['Desconto']), "double"),
					   GetSQLValueString(numerobrasil($_POST['diferenca']), "double"),
					   GetSQLValueString(numerobrasil($_POST['outros']), "double"),
                       GetSQLValueString(convertdata($_POST['DtPagamento']), "date"),
                       GetSQLValueString($_POST['FormaPagamento'], "int"),
                       GetSQLValueString($_POST['Cheque'], "text"),
                       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_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_pagamentos = "SELECT *, DATE_FORMAT(Emissao,'%d/%m/%Y') as dt_emissao, DATE_FORMAT(Vencimento,'%d/%m/%Y') as dt_vencimento, DATE_FORMAT(DtPagamento,'%d/%m/%Y') as dt_pagamento FROM mfin_pagamentos WHERE Id = ".$_GET['id']."";
$pagamentos = mysql_query($query_pagamentos, $paivaconex) or die(mysql_error());
$row_pagamentos = mysql_fetch_assoc($pagamentos);
$totalRows_pagamentos = mysql_num_rows($pagamentos);

mysql_select_db($database_paivaconex, $paivaconex);
$query_fornecedor = "SELECT * FROM mfin_fornecedores ORDER BY NomeFantasia ASC";
$fornecedor = mysql_query($query_fornecedor, $paivaconex) or die(mysql_error());
$row_fornecedor = mysql_fetch_assoc($fornecedor);
$totalRows_fornecedor = mysql_num_rows($fornecedor);

mysql_select_db($database_paivaconex, $paivaconex);
$query_referencia = "SELECT * FROM mfin_clientes ORDER BY NomeFantasia ASC";
$referencia = mysql_query($query_referencia, $paivaconex) or die(mysql_error());
$row_referencia = mysql_fetch_assoc($referencia);
$totalRows_referencia = mysql_num_rows($referencia);

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_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);


//USING
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>

<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<?php include_once('controls/import.php'); ?>

        <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");
		   $("#Pagamento").mask("99/99/9999");
	    });
        

        </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 Pagamentos
    <p></p>
    <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
      <table align="center">
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Banco:</td>
          <td><select name="Banco">
            <?php 
do {  
?>
            <option value="<?php echo $row_banco['Id']?>" <?php if (!(strcmp($row_banco['Id'], htmlentities($row_pagamentos['Banco'], ENT_COMPAT, '')))) {echo "SELECTED";} ?>><?php echo utf8_decode($row_banco['NomeConta'])?></option>
            <?php
} while ($row_banco = mysql_fetch_assoc($banco));
?>
          </select></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Fornecedor:</td>
          <td><select name="Fornecedor">
            <?php 
do {  
?>
            <option value="<?php echo $row_fornecedor['Id']?>" <?php if (!(strcmp($row_fornecedor['Id'], htmlentities($row_pagamentos['Fornecedor'], ENT_COMPAT, '')))) {echo "SELECTED";} ?>><?php echo utf8_decode($row_fornecedor['NomeFantasia'])?></option>
            <?php
} while ($row_fornecedor = mysql_fetch_assoc($fornecedor));
?>
            </select></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Emissao:</td>
          <td><input type="text" name="Emissao" value="<?php echo htmlentities($row_pagamentos['dt_emissao'], ENT_COMPAT, ''); ?>" size="32"  id="Emissao"/></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">DtPagamento:</td>
          <td><input type="text" name="DtPagamento" value="<?php echo htmlentities($row_pagamentos['dt_pagamento'], ENT_COMPAT, ''); ?>" size="32" id="Pagamento" /></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Referencia:</td>
          <td><select name="Cliente">
            <?php 
do {  
?>
            <option value="<?php echo $row_referencia['Id']?>" <?php if (!(strcmp($row_referencia['Id'], htmlentities($row_pagamentos['Cliente'], ENT_COMPAT, '')))) {echo "SELECTED";} ?>><?php echo utf8_decode($row_referencia['NomeFantasia'])?></option>
            <?php
} while ($row_referencia = mysql_fetch_assoc($referencia));
?>
          </select></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Pasta:</td>
          <td><select name="Pasta">
            <?php 
do {  
?>
            <option value="<?php echo $row_pasta['Id']?>" <?php if (!(strcmp($row_pasta['Id'], htmlentities($row_pagamentos['Pasta'], 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">NumFatura:</td>
          <td><input type="text" name="NumFatura" value="<?php echo htmlentities($row_pagamentos['NumFatura'], ENT_COMPAT, ''); ?>" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Detalhe:</td>
          <td><input type="text" name="Detalhe" value="<?php echo htmlentities($row_pagamentos['Detalhe'], ENT_COMPAT, ''); ?>" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Valor:</td>
          <td><span id="sprytextfield1">
          <input type="text" name="Valor" value="<?php echo htmlentities(number_format($row_pagamentos['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">Ir:</td>
          <td><span id="sprytextfield2">
          <input type="text" name="Ir" value="<?php echo htmlentities(number_format($row_pagamentos['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">Pis:</td>
          <td><span id="sprytextfield3">
          <input type="text" name="Pis" value="<?php echo htmlentities(number_format($row_pagamentos['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="sprytextfield4">
          <input type="text" name="Cofins" value="<?php echo htmlentities(number_format($row_pagamentos['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="sprytextfield5">
          <input type="text" name="Csll" value="<?php echo htmlentities(number_format($row_pagamentos['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">Inss:</td>
          <td><span id="sprytextfield6">
          <input type="text" name="Inss" value="<?php echo htmlentities(number_format($row_pagamentos['Inss'],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">Iss:</td>
          <td><span id="sprytextfield7">
          <input type="text" name="Iss" value="<?php echo htmlentities(number_format($row_pagamentos['Iss'],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">Juros:</td>
          <td><span id="sprytextfield8">
          <input type="text" name="Juros" value="<?php echo htmlentities(number_format($row_pagamentos['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="sprytextfield9">
          <input type="text" name="Multa" value="<?php echo htmlentities(number_format($row_pagamentos['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="sprytextfield10">
          <input type="text" name="Desconto" value="<?php echo htmlentities(number_format($row_pagamentos['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">Forma de Pagamento:</td>
          <td><select name="FormaPagamento">
            <?php 
do {  
?>
            <option value="<?php echo $row_forma['Id']?>" <?php if (!(strcmp($row_forma['Id'], htmlentities($row_pagamentos['FormaPagamento'], 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">Cheque:</td>
          <td><input type="text" name="Cheque" value="<?php echo htmlentities($row_pagamentos['Cheque'], ENT_COMPAT, ''); ?>" 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_pagamentos['Id']; ?>" />
      <input type="hidden" name="isss" value="0" />
      <input type="hidden" name="Baixadoem" value="<?php echo htmlentities($row_pagamentos['Baixadoem'], ENT_COMPAT, ''); ?>" />
      <input type="hidden" name="MM_update" value="form1" />
      <input type="hidden" name="Id" value="<?php echo $row_pagamentos['Id']; ?>" />
	  <input type="hidden" name="diferenca" value="0,00"  />
  <input type="hidden" name="outros" value="0,00"  />
    </form>
    <p>&nbsp;</p>
<p></p>
    <p></p>
</div>



</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"});
var sprytextfield9 = new Spry.Widget.ValidationTextField("sprytextfield9", "currency", {format:"dot_comma"});
var sprytextfield10 = new Spry.Widget.ValidationTextField("sprytextfield10", "currency", {format:"dot_comma"});
var sprytextfield11 = new Spry.Widget.ValidationTextField("sprytextfield11", "currency", {format:"dot_comma"});
var sprytextfield12 = new Spry.Widget.ValidationTextField("sprytextfield12", "currency", {format:"dot_comma"});
</script>
</body>
</html>
<?php
mysql_free_result($banco);

mysql_free_result($pagamentos);

mysql_free_result($fornecedor);

mysql_free_result($referencia);

mysql_free_result($forma);

mysql_free_result($pasta);
?>
