
<?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_insert"])) && ($_POST["MM_insert"] == "form1")) {


  for ($i = 0; $i < count($_POST['cli_valor']); $i++) {


  $insertSQL = sprintf("INSERT INTO mfin_pagamentos (Fornecedor, Pasta, FormaPagamento, Cheque, Banco, Emissao, Vencimento, NumFatura, Cliente, Valor, Ir, Pis, Cofins, Csll, Inss, Iss, Juros, isss, Multa, Desconto, DtPagamento, Baixadoem, Detalhe) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['Fornecedor'], "int"),
                       GetSQLValueString($_POST['Pasta'], "int"),
                       GetSQLValueString($_POST['FormaPagamento'], "int"),
                       GetSQLValueString($_POST['Cheque'], "text"),
                       GetSQLValueString($_POST['Banco'], "int"),
                       GetSQLValueString(convertdata($_POST['Emissao']), "date"),
                       GetSQLValueString(convertdata($_POST['Emissao']), "date"),
                       GetSQLValueString($_POST['NumFatura'], "text"),
                       GetSQLValueString($_POST['cli_id'][$i], "int"),
                       GetSQLValueString(numerobrasil($_POST['cli_valor'][$i]), "double"),
                       GetSQLValueString($_POST['Ir'], "double"),
                       GetSQLValueString($_POST['Pis'], "double"),
                       GetSQLValueString($_POST['Cofins'], "double"),
                       GetSQLValueString($_POST['Csll'], "double"),
                       GetSQLValueString($_POST['Inss'], "double"),
                       GetSQLValueString($_POST['Iss'], "double"),
                       GetSQLValueString($_POST['Juros'], "double"),
                       GetSQLValueString($_POST['isss'], "int"),
                       GetSQLValueString($_POST['Multa'], "double"),
                       GetSQLValueString($_POST['Desconto'], "double"),
                       GetSQLValueString(convertdata($_POST['Emissao']), "date"),
                       GetSQLValueString(convertdata($_POST['Emissao']), "date"),
                       GetSQLValueString($_POST['Detalhe'], "text"));

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


}

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_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_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_tipo = "SELECT * FROM mfin_tiposrecebimentos";
$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_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_formas = "SELECT * FROM mfin_formaspagamentos ORDER BY Id ASC";
$formas = mysql_query($query_formas, $paivaconex) or die(mysql_error());
$row_formas = mysql_fetch_assoc($formas);
$totalRows_formas = mysql_num_rows($formas);


//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="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="js/jquery.maskedinput-1.3.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.js"></script>
<script src="js/multiplos.js" type="text/javascript"></script>
<script>
        jQuery(function($){
		   $("#Emissao").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 - Lan&Ccedil;amento multiplo</div>
    
    
    <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
      <table align="center">
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Fornecedor:</td>
          <td><select name="Fornecedor">
            <?php 
do {  
?>
            <option value="<?php echo $row_fornecedor['Id']?>" ><?php echo $row_fornecedor['NomeFantasia']?></option>
            <?php
} while ($row_fornecedor = mysql_fetch_assoc($fornecedor));
?>
          </select></td>
        </tr>
        <tr> </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 echo $row_pasta['Numero'].' '.$row_pasta['Nome']?></option>
            <?php
} while ($row_pasta = mysql_fetch_assoc($pasta));
?>
          </select></td>
        </tr>
        <tr> </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Forma Pagamento:</td>
          <td><select name="FormaPagamento">
            <?php 
do {  
?>
            <option value="<?php echo $row_formas['Id']?>" ><?php echo $row_formas['Nome']?></option>
            <?php
} while ($row_formas = mysql_fetch_assoc($formas));
?>
          </select></td>
        </tr>
        <tr> </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Cheque:</td>
          <td><input type="text" name="Cheque" value="0" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Banco:</td>
          <td><select name="Banco">
            <?php 
do {  
?>
            <option value="<?php echo $row_banco['Id']?>" ><?php echo $row_banco['NomeConta']?></option>
            <?php
} while ($row_banco = mysql_fetch_assoc($banco));
?>
          </select></td>
        </tr>
        <tr> </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Data:</td>
          <td><span id="sprytextfield2">
            <input type="text" name="Emissao" value="" size="32" id="Emissao" />
            <span class="textfieldRequiredMsg">Um valor e necessario.</span></span></td>
        </tr>
        <tr>
    <td align="center" colspan="2">
    <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Referencia</td>
      <td><select name="Cliente_Id">
        <?php 
do {  
?>
        <option value="<?php echo $row_cliente['Id']?>" ><?php echo $row_cliente['NomeFantasia']?></option>
        <?php
} while ($row_cliente = mysql_fetch_assoc($cliente));
?>
      </select></td>
      <td nowrap="nowrap" align="right">Valor:</td>
      <td><span id="sprytextfield1"><span id="sprytextfield3">
        <input type="text" name="Valor" value="" size="32" />
        <span class="textfieldInvalidFormatMsg">Formato invalido.</span></span><span class="textfieldInvalidFormatMsg">Formato invalido.</span></span></td>
      
    </tr>
    </table>
    </td>
    </tr>
    
    <tr>
    <td colspan="2" align="center"><p>
      <input name="adicionar" type="button" id="adicionar" value="Adicionar" />
    </p>
      <p>&nbsp;</p>
      <p>&nbsp; </p></td>
    </tr>
    <tr>
    <td colspan="2" align="center">
    <table border="0" id="descricao">
  		
	</table>

    </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Total</td>
      
      <td><input name="total" type="text" id="total" value="" size="32" readonly="readonly" /></td>
    </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Detalhe:</td>
          <td><input type="text" name="Detalhe" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">&nbsp;</td>
          <td><input type="submit" value="Inserir registro" /></td>
        </tr>
      </table>
      <input type="hidden" name="Vencimento" value="" />
      <input type="hidden" name="NumFatura" value="0" />
      <input type="hidden" name="Ir" value="0" />
      <input type="hidden" name="Pis" value="0" />
      <input type="hidden" name="Cofins" value="0" />
      <input type="hidden" name="Csll" value="0" />
      <input type="hidden" name="Inss" value="0" />
      <input type="hidden" name="Iss" value="0" />
      <input type="hidden" name="Juros" value="0" />
      <input type="hidden" name="isss" value="0" />
      <input type="hidden" name="Multa" value="0" />
      <input type="hidden" name="Desconto" value="0" />
      <input type="hidden" name="DtPagamento" value="" />
      <input type="hidden" name="Baixadoem" value="" />
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
    <p>&nbsp;</p>
</div>

</div>

</div>

<?php include_once('controls/footer.php'); ?>
<script type="text/javascript">
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "currency", {isRequired:false, format:"dot_comma", validateOn:["change"]});
</script>
</body>
</html>
<?php
mysql_free_result($fornecedor);

mysql_free_result($cliente);

mysql_free_result($pasta);

mysql_free_result($tipo);

mysql_free_result($banco);

mysql_free_result($formas);

?>
