Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
<?php
var inss = 8%;
$tabela = '<table border="1" border: solid gray 5px;>';//abre table
$tabela .='<thead>';//abre cabeçalho
$tabela .= '<tr>';//abre uma linha
$tabela .= '</tr>';//fecha linha
$tabela .='</thead>'; //fecha cabeçalho
$tabela .='<tbody>';//abre corpo da tabela
$db = pg_connect("port=55432 dbname=folha user=fortesrh password=1234");
$consulta=pg_query($db,"SELECT funcionario.nome, funcionario.cargo, cargo.salario from funcionario INNER JOIN cargo ON funcionario.cargo = cargo.descricao ORDER BY funcionario.nome");
while ($linha = pg_fetch_array($consulta)) {//declaração da variável linha trazendo o resultado da query
$tabela .= '<th colspan="2" width="210px">Folha de Pagamento</th>';
$tabela .= '<th colspan="3" width="410px">Data e Assinatura: ____/____/_____ ___________________________________________________</th>';
$tabela .= '</tr>';//fecha linha
$tabela .= '<th width="170px" height="20px" align="left">Empresa: XP Seriços Demonstrativos Ltda ME</th>';
$tabela .= '<th width="100px" align="left">CNPJ: 00.000.000/0000-00</th>';
$tabela .= '<th width="150px" align="center">Admissão: 10/05/2019</th>';
$tabela .= '<th width="150px" align="center">Competência: Junho de 2019</th>';
$tabela .= '</tr>';//fecha linha
$tabela .= '<tr>'; // abre uma linha
$tabela .= '<td>'.$linha['nome'].'</td>'; // coluna nome do funcionario
$tabela .= '<td align="center">'.$linha['cargo'].'</td>'; // coluna cargo
$tabela .= '<td align="center">'.$linha['salario'].'</td>'; // coluna salario
$tabela .= '<td align="center">'.$linha['salario * inss'].'</td>'; // coluna salario
$tabela .= '</tr>'; // fecha linha
$tabela .= '<th width="550px" colspan="5" align="center">----------------------------------------------------------------------</th>';
$tabela .= '</tr>'; // fecha linha
}
$tabela .='</tbody>'; //fecha corpo
$tabela .= '</table>';//fecha tabela
echo $tabela; // imprime
?>
Spoiler>
14 horas atrás, ShadowDLL disse:
Siga as etapas abaixo:
1º Etapa
ATUAL
var inss = 8%;
**ALTERAR POR**
$inss = 8;
**2º Etapa**
**ATUAL**
$tabela .= '<td align="center">'.$linha['salario * inss'].'</td>';
**ALTERAR POR**
$tabela .= '<td align="center">' . $linha [ 'salario' ] * ( $inss / 100 ) . '</td>';
Apresentou o erro:


O valor para calcular: 2990,00 x8% = 239.20
Script modificado:
<?php
$inss = 8;
$tabela = '<table border="1" border: solid gray 5px;>';//abre table
$tabela .='<thead>';//abre cabeçalho
$tabela .= '<tr>';//abre uma linha
$tabela .= '</tr>';//fecha linha
$tabela .='</thead>'; //fecha cabeçalho
$tabela .='<tbody>';//abre corpo da tabela
$db = pg_connect("port=55432 dbname=folha user=fortesrh password=1234");
$consulta=pg_query($db,"SELECT funcionario.nome, funcionario.cargo, cargo.salario from funcionario INNER JOIN cargo ON funcionario.cargo = cargo.descricao ORDER BY funcionario.nome");
while ($linha = pg_fetch_array($consulta)) {//declaração da variável linha trazendo o resultado da query
$tabela .= '<th colspan="2" width="210px">Folha de Pagamento</th>';
$tabela .= '<th colspan="3" width="410px">Data e Assinatura: ____/____/_____ ___________________________________________________</th>';
$tabela .= '</tr>';//fecha linha
$tabela .= '<th width="170px" height="20px" align="left">Empresa: XP Seriços Demonstrativos Ltda ME</th>';
$tabela .= '<th width="100px" align="left">CNPJ: 00.000.000/0000-00</th>';
$tabela .= '<th width="150px" align="center">Admissão: 10/05/2019</th>';
$tabela .= '<th width="150px" align="center">Competência: Junho de 2019</th>';
$tabela .= '</tr>';//fecha linha
$tabela .= '<tr>'; // abre uma linha
$tabela .= '<td>'.$linha['nome'].'</td>'; // coluna nome do funcionario
$tabela .= '<td align="center">'.$linha['cargo'].'</td>'; // coluna cargo
$tabela .= '<td align="center">'.$linha['salario'].'</td>'; // coluna salario
$tabela .= '<td align="center">' . $linha [ 'salario' ] * ( $inss / 100 ) . '</td>';
$tabela .= '</tr>'; // fecha linha
$tabela .= '<th width="550px" colspan="5" align="center">----------------------------------------------------------------------</th>';
$tabela .= '</tr>'; // fecha linha
}
$tabela .='</tbody>'; //fecha corpo
$tabela .= '</table>';//fecha tabela
echo $tabela; // imprime
?>ATUAL
$tabela .= '<td align="center">' . $linha [ 'salario' ] * ( $inss / 100 ) . '</td>';
**ALTERAR POR**
$tabela .= '
<td align="center">'.
number_format (
(
str_replace (
',', '.', preg_replace (
'#[^\d\,]#is', '', $linha [ 'salario' ]
)
) * $inss / 100
), 2, ',', '.'
)
.'</td>'
;
**OBSERVAÇÕES**
Se possível **evitar** o envio de *valores formatados*
ao *banco de dados, pois assim, você evita ter de*
*fazer o trabalho acima...*>
45 minutos atrás, ShadowDLL disse:
ATUAL
$tabela .= '<td align="center">' . $linha [ 'salario' ] * ( $inss / 100 ) . '</td>';
**ALTERAR POR**
$tabela .= '
<td align="center">'.
number_format (
(
str_replace (
',', '.', preg_replace (
'#[^\d\,]#is', '', $linha [ 'salario' ]
)
) * $inss / 100
), 2, ',', '.'
)
.'</td>'
;
**OBSERVAÇÕES**
Se possível **evitar** o envio de *valores formatados*
ao *banco de dados, pois assim, você evita ter de*
*fazer o trabalho acima...*
**Show! deu certo. Vou fazer as demais implementações. Muito obrigado.**>
1 hora atrás, Israel Lira disse:
Show! deu certo. Vou fazer as demais implementações. Muito obrigado.
A seu dispor ;)
>
Em 12/07/2019 at 21:54, ShadowDLL disse:
A seu dispor ;)
Tem mais uma situação que tentei mais não avançou. Quero totalizar um somatório de salario + diasdescanso.
$tabela .= '<td width="150px" align="center">'.number_format ((str_replace (',', '.', preg_replace ('#[^\d\,]#is', '', $linha['salario'])) + $linha [ 'salario' ] / $diasdescanso), 2, ',', '.').'</td>';
/monthly_2019_07/image.png.3f8e614e997d47405c0b0921945d8f56.png" />>
Em 13/07/2019 at 08:53, Israel Lira disse:
Tem mais uma situação que tentei mais não avançou. Quero totalizar um somatório de salario + diasdescanso.
$tabela .= '<td width="150px" align="center">'.number_format ((str_replace (',', '.', preg_replace ('#[^\d\,]#is', '', $linha['salario'])) + $linha [ 'salario' ] / $diasdescanso), 2, ',', '.').'</td>';

Segue exemplo:
**CÓDIGO**
<?php
$inss = 8;
$linha = array (
'nome' => "Israel Lira",
'cargo' => "ADMINISTRADOR",
'salario' => "2.990,50"
);
# DIAS DESCANSO
$diasdescanso = 3;
# SALARIO
$salario = str_replace (
',', '.', preg_replace (
'#[^\d\,]#is', '', $linha['salario']
)
);
$tabela = '<table border="1" border: solid gray 5px;>';//abre table
$tabela .='<thead>';//abre cabeçalho
$tabela .= '<tr>';//abre uma linha
$tabela .= '</tr>';//fecha linha
$tabela .='</thead>'; //fecha cabeçalho
$tabela .='<tbody>';//abre corpo da tabela
$tabela .= '<th colspan="2" width="210px">Folha de Pagamento</th>';
$tabela .= '<th colspan="3" width="410px">Data e Assinatura:____/____/_____ ___________________________________________________</th>';
$tabela .= '</tr>';//fecha linha
$tabela .= '<th width="170px" height="20px" align="left">Empresa: XP Seriços Demonstrativos Ltda ME</th>';
$tabela .= '<th width="100px" align="left">CNPJ:00.000.000/0000-00</th>';
$tabela .= '<th width="150px" align="center">Admissão: 10/05/2019</th>';
$tabela .= '<th width="150px" align="center">Competência: Junho de 2019</th>';
$tabela .= '<th width="150px" align="center">Salário + Descanso</th>';
$tabela .= '</tr>';//fecha linha
$tabela .= '<tr>'; // abre uma linha
$tabela .= '<td>'.$linha['nome'].'</td>'; // coluna nome do funcionario
$tabela .= '<td align="center">'.$linha['cargo'].'</td>'; // coluna cargo
$tabela .= '<td align="center">'.$linha['salario'].'</td>'; // coluna salario
$tabela .= '
<td align="center">'.
number_format (
(
$salario * $inss / 100
), 2, ',', '.'
)
.'</td>'
;
# DIAS DESCANSO
$tabela .= '
<td>'.
number_format (
(
$salario + ( $salario / $diasdescanso )
), 2, ',', '.'
).
'</td>'
;
$tabela .= '</tr>'; // fecha linha
$tabela .= '<th width="550px" colspan="5" align="center">----------------------------------------------------------------------</th>';
$tabela .= '</tr>'; // fecha linha
$tabela .='</tbody>'; //fecha corpo
$tabela .= '</table>';//fecha tabela
echo $tabela; // imprime
?>
Siga as etapas abaixo:
1º Etapa
ATUAL