Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //==============================================================
- // INCLUDE DE ARQUIVOS
- //==============================================================
- require_once($_SERVER['BASE_DIR'].'vendor/autoload.php');
- /*** variável do tipo de operação ***/
- $OperacaoID = trim($_POST['OperacaoID']);
- /*** Faz a Verificação do Tipo de SQL a Executar ***/
- switch($OperacaoID){
- case "relatorio_custo_geral" : { RelatorioCustoGeral(); break; }
- //default: { echo "Ocorreu Um erro!";break;}
- }
- /*####################################### Relatório Usuário #######################################*/
- function RelatorioCustoGeral(){
- $edtReferenciaInicial = "01/".$_POST['edtReferenciaInicial'];
- $edtReferenciaFinal = "01/".$_POST['edtReferenciaFinal'];
- $edtTipoRelatorio = $_POST['edtTipoRelatorio'];
- if($_POST['edtReferenciaInicial']==$_POST['edtReferenciaFinal']){
- $tituloReferencia = $_POST['edtReferenciaInicial'];
- }
- else{
- $tituloReferencia = $_POST['edtReferenciaInicial']." à ".$_POST['edtReferenciaFinal']." (média)";
- }
- if (validarData($edtReferenciaInicial, 'dd/mm/aaaa')){
- $edtReferenciaInicial = formatarDataMySQL($edtReferenciaInicial);
- }
- if (validarData($edtReferenciaFinal, 'dd/mm/aaaa')){
- $edtReferenciaFinal = formatarDataMySQL($edtReferenciaFinal);
- }
- /*** Instancia um novo objeto MySQL */
- $mySQL = new MySQL();
- /*** Conecta com o banco MySQL ***/
- $mySQL->conectarMySQL();
- /*** Busca os dados da tabela custoapuracao ***/
- if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo2"){
- $sql_query = "select A.referenciacustoapuracao, A.codigoempresa, B.razaosocialempresa,
- sum(A.rhnumfunc) as rhnumfunc,
- sum(A.rhhoranormal) as rhhoranormal,
- sum(A.rhhorarateio) as rhhorarateio,
- sum(A.rhhoratotal) as rhhoratotal,
- sum(A.rhcusto) as rhcusto,
- sum(A.fihoranormal) as fihoranormal,
- sum(A.fihorarateio) as fihorarateio,
- sum(A.fihoratotal) as fihoratotal,
- sum(A.ficusto) as ficusto,
- sum(A.ctbhoranormal) as ctbhoranormal,
- sum(A.ctbhorarateio) as ctbhorarateio,
- sum(A.ctbhoratotal) as ctbhoratotal,
- sum(A.ctbcusto) as ctbcusto,
- sum(A.jucusto) as jucusto,
- sum(A.ticusto) as ticusto,
- sum(A.dicusto) as dicusto,
- sum(A.oucusto) as oucusto,
- sum(A.totalhora) as totalhora,
- sum(A.totalcusto) as totalcusto,
- sum(A.markup) as markup,
- sum(A.precovenda) as precovenda,
- sum(A.valorhonorario) as valorhonorario,
- sum(A.valorfaturado) as valorfaturado,
- sum(A.valorrecebido) as valorrecebido
- from custoapuracao A
- left join empresa B on (A.codigoempresa = B.codigoempresa)
- where A.referenciacustoapuracao = '".$edtReferenciaInicial."'
- group by 1,2,3
- order by B.razaosocialempresa";
- }//fim if
- else if($edtTipoRelatorio=="modelo3" || $edtTipoRelatorio=="modelo4"){
- $sql_query = "select A.codigoempresa, A.razaosocialempresa,
- round(avg(A.rhnumfunc),2) as rhnumfunc,
- round(avg(A.rhhoranormal),2) as rhhoranormal,
- round(avg(A.rhhorarateio),2) as rhhorarateio,
- round(avg(A.rhhoratotal),2) as rhhoratotal,
- round(avg(A.rhcusto),2) as rhcusto,
- round(avg(A.fihoranormal),2) as fihoranormal,
- round(avg(A.fihorarateio),2) as fihorarateio,
- round(avg(A.fihoratotal),2) as fihoratotal,
- round(avg(A.ficusto),2) as ficusto,
- round(avg(A.ctbhoranormal),2) as ctbhoranormal,
- round(avg(A.ctbhorarateio),2) as ctbhorarateio,
- round(avg(A.ctbhoratotal),2) as ctbhoratotal,
- round(avg(A.ctbcusto),2) as ctbcusto,
- round(avg(A.jucusto),2) as jucusto,
- round(avg(A.ticusto),2) as ticusto,
- round(avg(A.dicusto),2) as dicusto,
- round(avg(A.oucusto),2) as oucusto,
- round(avg(A.totalhora),2) as totalhora,
- round(avg(A.totalcusto),2) as totalcusto,
- round(avg(A.markup),2) as markup,
- round(avg(A.precovenda),2) as precovenda,
- round(avg(A.valorhonorario),2) as valorhonorario,
- round(avg(A.valorfaturado),2) as valorfaturado,
- round(avg(A.valorrecebido),2) as valorrecebido,
- count(*) as contador
- from (
- select A.referenciacustoapuracao, A.codigoempresa, B.razaosocialempresa,
- sum(A.rhnumfunc) as rhnumfunc,
- sum(A.rhhoranormal) as rhhoranormal,
- sum(A.rhhorarateio) as rhhorarateio,
- sum(A.rhhoratotal) as rhhoratotal,
- sum(A.rhcusto) as rhcusto,
- sum(A.ctbhoranormal) as ctbhoranormal,
- sum(A.ctbhorarateio) as ctbhorarateio,
- sum(A.ctbhoratotal) as ctbhoratotal,
- sum(A.ctbcusto) as ctbcusto,
- sum(A.fihoranormal) as fihoranormal,
- sum(A.fihorarateio) as fihorarateio,
- sum(A.fihoratotal) as fihoratotal,
- sum(A.ficusto) as ficusto,
- sum(A.jucusto) as jucusto,
- sum(A.ticusto) as ticusto,
- sum(A.dicusto) as dicusto,
- sum(A.oucusto) as oucusto,
- sum(A.totalhora) as totalhora,
- sum(A.totalcusto) as totalcusto,
- sum(A.markup) as markup,
- sum(A.precovenda) as precovenda,
- sum(A.valorhonorario) as valorhonorario,
- sum(A.valorfaturado) as valorfaturado,
- sum(A.valorrecebido) as valorrecebido
- from custoapuracao A
- left join empresa B on (A.codigoempresa = B.codigoempresa)
- where A.referenciacustoapuracao between '".$edtReferenciaInicial."' and '".$edtReferenciaFinal."'
- group by 1,2,3
- ) A
- group by 1,2
- order by 2";
- }//fim else if
- /*** Executa a consulta no banco MySQL ***/
- $query = $mySQL->executarMySQL($sql_query);
- $rows = $mySQL->contarMySQL($query);
- /*** Verifica se a query foi executada com sucesso, senão cancela ***/
- $aux = "";
- if($query && $rows){
- $i=0;
- $j=2;
- //********** Inicializa as variáveis dos acumuladores de totais **********
- $total_numfunc = 0;
- $total_rhhoranormal = 0;
- $total_rhhorarateio = 0;
- $total_rhhoratotal = 0;
- $total_rhcusto = 0;
- $total_fihoranormal = 0;
- $total_fihorarateio = 0;
- $total_fihoratotal = 0;
- $total_ficusto = 0;
- $total_ctbhoranormal = 0;
- $total_ctbhorarateio = 0;
- $total_ctbhoratotal = 0;
- $total_ctbcusto = 0;
- $total_totalhora = 0;
- $total_jucusto = 0;
- $total_ticusto = 0;
- $total_dicusto = 0;
- $total_oucusto = 0;
- $total_totalcusto = 0;
- $total_markup = 0;
- $total_precovenda = 0;
- $total_valorhonorario = 0;
- $total_valorhonorario13 = 0;
- $total_valorfaturado = 0;
- $total_valorrecebido = 0;
- while($row = $mySQL->mostrarMySQL($query)){
- //********** Atribui os valores da consulta em um array **********
- $vet[$i]['codigoempresa'] = $row['codigoempresa'];
- $vet[$i]['razaosocialempresa'] = formata_campo($row['razaosocialempresa'], '40', ' ', 'E');
- $vet[$i]['rhnumfunc'] = $row['rhnumfunc'];
- $vet[$i]['rhhoranormal'] = $row['rhhoranormal'];
- $vet[$i]['rhhorarateio'] = $row['rhhorarateio'];
- $vet[$i]['rhhoratotal'] = $row['rhhoratotal'];
- $vet[$i]['rhcusto'] = $row['rhcusto'];
- $vet[$i]['fihoranormal'] = $row['fihoranormal'];
- $vet[$i]['fihorarateio'] = $row['fihorarateio'];
- $vet[$i]['fihoratotal'] = $row['fihoratotal'];
- $vet[$i]['ficusto'] = $row['ficusto'];
- $vet[$i]['ctbhoranormal'] = $row['ctbhoranormal'];
- $vet[$i]['ctbhorarateio'] = $row['ctbhorarateio'];
- $vet[$i]['ctbhoratotal'] = $row['ctbhoratotal'];
- $vet[$i]['ctbcusto'] = $row['ctbcusto'];
- $vet[$i]['jucusto'] = $row['jucusto'];
- $vet[$i]['ticusto'] = $row['ticusto'];
- $vet[$i]['dicusto'] = $row['dicusto'];
- $vet[$i]['oucusto'] = $row['oucusto'];
- $vet[$i]['totalhora'] = $row['totalhora'];
- $vet[$i]['totalcusto'] = $row['totalcusto'];
- $vet[$i]['markup'] = $row['markup'];
- $vet[$i]['valorhonorario'] = $row['valorhonorario'];
- $vet[$i]['valorhonorario13'] = ($row['valorhonorario']/12);
- $vet[$i]['precovenda'] = $row['precovenda'];
- $vet[$i]['valorfaturado'] = $row['valorfaturado'];
- $vet[$i]['valorrecebido'] = $row['valorrecebido'];
- //***** Verifica se o preco de venda for maior que zero para efetuar a divisão *****
- //Evitar erro de divisão por 0
- if($row['precovenda'] > 0){
- $vet[$i]['percentuallucro_honorario'] = ((($row['valorhonorario']+($row['valorhonorario']/12))/$row['precovenda'])-1)*100;
- $vet[$i]['percentuallucro_faturado'] = (($row['valorfaturado']/$row['precovenda'])-1)*100;
- $vet[$i]['percentuallucro_recebido'] = (($row['valorrecebido']/$row['precovenda'])-1)*100;
- } // end if
- else{
- $vet[$i]['percentuallucro_honorario'] = "100";
- $vet[$i]['percentuallucro_faturado'] = "100";
- $vet[$i]['percentuallucro_recebido'] = "100";
- } //end else
- //############ Arquivo CSV para Excel ############
- if($i==0){
- $aux .= "codigoempresa;razaosocialempresa;rhnumfunc;rhhoranormal;rhhorarateio;rhhoratotal;rhcusto;fihoranormal;fihorarateio;fihoratotal;ficusto;ctbhoranormal;ctbhorarateio;ctbhoratotal;ctbcusto;".
- "jucusto;ticusto;dicusto;oucusto;totalhora;totalcusto;markup;valorhonorario;valorhonorario13;precovenda;valorfaturado;valorrecebido;%lucro_honorario;%lucro_faturado;%lucro_recebido\n";
- }
- $aux .= $vet[$i]['codigoempresa'] .";". //A 1
- $vet[$i]['razaosocialempresa'].";". //B 2
- formatarValorPadrao($vet[$i]['rhnumfunc'],2).";". //C 3
- formatarValorPadrao($vet[$i]['rhhoranormal'],2).";". //D 4
- formatarValorPadrao($vet[$i]['rhhorarateio'],2).";". //E 5
- "=(D".($i+2)."+E".($i+2).");". //F 6
- "=(\$G\$".($rows+2)."/\$F\$".($rows+2).")*F".($i+2).";". //G 7
- formatarValorPadrao($vet[$i]['fihoranormal'],2).";". //H 8
- formatarValorPadrao($vet[$i]['fihorarateio'],2).";". //I 9
- "=(H".($i+2)."+I".($i+2).");". //J 10
- "=(\$K\$".($rows+2)."/\$J\$".($rows+2).")*J".($i+2).";". //K 11
- formatarValorPadrao($vet[$i]['ctbhoranormal'],2).";". //L 12
- formatarValorPadrao($vet[$i]['ctbhorarateio'],2).";". //M 13
- "=(L".($i+2)."+M".($i+2).");". //N 14
- "=(\$O\$".($rows+2)."/\$N\$".($rows+2).")*N".($i+2).";". //O 15
- //formatarValorPadrao($vet[$i]['jucusto'],2).";". //P 16
- "=(\$P\$".($rows+2)."/\$T\$".($rows+2).")*T".($i+2).";". //O 15 (jucusto)
- //formatarValorPadrao($vet[$i]['ticusto'],2).";". //Q 17
- "=(\$Q\$".($rows+2)."/\$T\$".($rows+2).")*T".($i+2).";". //O 15 (ticusto)
- //formatarValorPadrao($vet[$i]['dicusto'],2).";". //R 18
- "=(\$R\$".($rows+2)."/\$T\$".($rows+2).")*T".($i+2).";". //O 15 (dicusto)
- //formatarValorPadrao($vet[$i]['oucusto'],2).";". //S 19
- "=(\$S\$".($rows+2)."/\$T\$".($rows+2).")*T".($i+2).";". //O 15 (oucusto)
- "=(F".($i+2)."+J".($i+2)."+N".($i+2).");". //T 20
- "=(G".($i+2)."+K".($i+2)."+O".($i+2)."+P".($i+2)."+Q".($i+2)."+R".($i+2)."+S".($i+2).");". //U 21
- formatarValorPadrao($vet[$i]['markup'],2).";". //V 22
- formatarValorPadrao($vet[$i]['valorhonorario'],2).";". //W 23
- formatarValorPadrao($vet[$i]['valorhonorario13'],2).";". //X 24
- "=(U".($i+2)."+V".($i+2).");". //Y 25
- formatarValorPadrao($vet[$i]['valorfaturado'],2).";". //Z 26
- formatarValorPadrao($vet[$i]['valorrecebido'],2).";". //AA 27
- "=(((W".($i+2)."+X".($i+2).")/Y".($i+2).")-1)*100;". //AB 28
- "=(((Z".($i+2).")/Y".($i+2).")-1)*100;". //AC 29
- "=(((AA".($i+2).")/Y".($i+2).")-1)*100;". //AD 30
- ";\n";
- //############ Arquivo CSV para Excel ############
- //********** Acumuladores de Totalizadores **********
- $total_numfunc += $row['rhnumfunc'];
- $total_rhhoranormal += $row['rhhoranormal'];
- $total_rhhorarateio += $row['rhhorarateio'];
- $total_rhhoratotal += $row['rhhoratotal'];
- $total_rhcusto += $row['rhcusto'];
- $total_fihoranormal += $row['fihoranormal'];
- $total_fihorarateio += $row['fihorarateio'];
- $total_fihoratotal += $row['fihoratotal'];
- $total_ficusto += $row['ficusto'];
- $total_ctbhoranormal += $row['ctbhoranormal'];
- $total_ctbhorarateio += $row['ctbhorarateio'];
- $total_ctbhoratotal += $row['ctbhoratotal'];
- $total_ctbcusto += $row['ctbcusto'];
- $total_totalhora += $row['totalhora'];
- $total_jucusto += $row['jucusto'];
- $total_ticusto += $row['ticusto'];
- $total_dicusto += $row['dicusto'];
- $total_oucusto += $row['oucusto'];
- $total_totalcusto += $row['totalcusto'];
- $total_markup += $row['markup'];
- $total_precovenda += $row['precovenda'];
- $total_valorhonorario += $row['valorhonorario'];
- $total_valorhonorario13 += ($row['valorhonorario']/12);
- $total_valorfaturado += $row['valorfaturado'];
- $total_valorrecebido += $row['valorrecebido'];
- $i++;
- } // fim while
- $aux .= "codigoempresa;razaosocialempresa;".
- formatarValorPadrao($total_numfunc,2).";".
- formatarValorPadrao($total_rhhoranormal,2).";".
- formatarValorPadrao($total_rhhorarateio,2).";".
- formatarValorPadrao($total_rhhoratotal,2).";".
- formatarValorPadrao($total_rhcusto,2).";".
- formatarValorPadrao($total_fihoranormal,2).";".
- formatarValorPadrao($total_fihorarateio,2).";".
- formatarValorPadrao($total_fihoratotal,2).";".
- formatarValorPadrao($total_ficusto,2).";".
- formatarValorPadrao($total_ctbhoranormal,2).";".
- formatarValorPadrao($total_ctbhorarateio,2).";".
- formatarValorPadrao($total_ctbhoratotal,2).";".
- formatarValorPadrao($total_ctbcusto,2).";".
- formatarValorPadrao($total_jucusto,2).";".
- formatarValorPadrao($total_ticusto,2).";".
- formatarValorPadrao($total_dicusto,2).";".
- formatarValorPadrao($total_oucusto,2).";".
- formatarValorPadrao($total_totalhora,2).";".
- "=SOMA(U2:U".($i+1).");".
- "=SOMA(V2:V".($i+1).");".
- "=SOMA(W2:W".($i+1).");".
- "=SOMA(X2:X".($i+1).");".
- "=SOMA(Y2:Y".($i+1).");".
- "=SOMA(Z2:Z".($i+1).");".
- "=SOMA(AA2:AA".($i+1).");".
- "=(((W".($i+2)."+X".($i+2).")/Y".($i+2).")-1)*100;".
- "=(((Z".($i+2).")/Y".($i+2).")-1)*100;".
- "=(((AA".($i+2).")/Y".($i+2).")-1)*100;".
- "\n";
- $aux .= "codigoempresa;razaosocialempresa;rhnumfunc;rhhoranormal;rhhorarateio;rhhoratotal;rhcusto;fihoranormal;fihorarateio;fihoratotal;ficusto;ctbhoranormal;ctbhorarateio;ctbhoratotal;ctbcusto;".
- "jucusto;ticusto;dicusto;oucusto;totalhora;totalcusto;markup;valorhonorario;valorhonorario13;precovenda;valorfaturado;valorrecebido;%lucro_honorario;%lucro_faturado;%lucro_recebido\n";
- $BASE_DIR = str_replace((substr( $_SERVER['SCRIPT_NAME'], strpos($_SERVER['SCRIPT_NAME'], DIRECTORY_SEPARATOR, 2) , strlen($_SERVER['SCRIPT_NAME']) )),"", $_SERVER['SCRIPT_FILENAME']);
- $datahoraarquivo = date("YmdHis");
- $NomeArquivoTXT = "tmp/custos_$datahoraarquivo.csv";
- $fp = fopen(BASE_DIR . DS . $NomeArquivoTXT,"w+");
- fputs($fp,$aux);
- fclose($fp);
- $aux = "";
- // Instancia o objeto FPDF (Retrato / milímetros / A4)
- $pdf = new PDF("L","mm","A4");
- //***** Estrutura de repetição que percorre o vetor e imprime *****
- for($i=0;$i<count($vet);$i++){
- $page_height = 210; //tamanho da página em milimetros
- $bottom_margin = 10; //tamanho da margem inferior
- $used_height = $pdf->GetY(); // mm until end of page (less bottom margin of 20mm)
- //***** Imprime o cabeçalho se faltar 20 mm ou menos ou se o $i for igual a 0 *****
- if ( $used_height >= ($page_height-$bottom_margin ) || $i==0){
- $pdf->AddPage();
- if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
- $pdf->SetHeaderTitle("RELATÓRIO DE CUSTOS - REFERÊNCIA: $tituloReferencia - ( $edtTipoRelatorio: conferência )");
- }
- else if($edtTipoRelatorio=="modelo2" || $edtTipoRelatorio=="modelo4"){
- $pdf->SetHeaderTitle("RELATÓRIO DE CUSTOS - REFERÊNCIA: $tituloReferencia - ( $edtTipoRelatorio: %lucro )");
- }
- //****************************************************************
- // Cabeçalho das colunas
- $pdf->SetFont('arial','B',5); //Altera a fonte negrito
- $pdf->Cell(50,4,"EMPRESA",1,0,"L");
- $pdf->SetFillColor(188, 221, 192); //verde claro
- $pdf->Cell(8,4,"Nº FUNC",1,0,"C",1);
- if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
- $pdf->Cell(8,4,"RH HN",1,0,"C",1);
- $pdf->Cell(8,4,"RH HR",1,0,"C",1);
- }
- $pdf->Cell(8,4,"RH HT",1,0,"C",1);
- $pdf->Cell(10,4,"RH CU",1,0,"C",1);
- $pdf->SetFillColor(255, 249, 204); //amarelo claro
- if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
- $pdf->Cell(8,4,"FI HN",1,0,"C",1);
- $pdf->Cell(8,4,"FI HR",1,0,"C",1);
- }
- $pdf->Cell(8,4,"FI HT",1,0,"C",1);
- $pdf->Cell(10,4,"FI CU",1,0,"C",1);
- $pdf->SetFillColor(198, 216, 239); //azul claro
- if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
- $pdf->Cell(8,4,"CTB HN",1,0,"C",1);
- $pdf->Cell(8,4,"CTB HR",1,0,"C",1);
- }
- $pdf->Cell(8,4,"CTB HT",1,0,"C",1);
- $pdf->Cell(10,4,"CTB CU",1,0,"C",1);
- $pdf->SetFillColor(225, 226, 237); // cinza
- $pdf->Cell(10,4,"HR TOT",1,0,"C",1);
- $pdf->Cell(10,4,"JU CU",1,0,"C");
- $pdf->Cell(10,4,"TI CU",1,0,"C");
- $pdf->Cell(10,4,"DI CU",1,0,"C");
- $pdf->Cell(10,4,"OU CU",1,0,"C");
- $pdf->SetFillColor(225, 226, 237); // cinza
- $pdf->Cell(10,4,"TOT CU",1,0,"C",1);
- $pdf->Cell(12,4,"MARKUP",1,0,"C");
- $pdf->Cell(12,4,"P.VENDA",1,0,"C");
- $pdf->Cell(12,4,"HONORÁRIO",1,0,"C");
- $pdf->Cell(12,4,"HONOR. 13º",1,0,"C");
- $pdf->Cell(12,4,"% LUCRO",1,0,"C");
- if($edtTipoRelatorio=="modelo2" || $edtTipoRelatorio=="modelo4"){
- $pdf->Cell(12,4,"FATURADO",1,0,"C");
- $pdf->Cell(12,4,"% LUCRO",1,0,"C");
- $pdf->Cell(12,4,"RECEBIDO",1,0,"C");
- $pdf->Cell(12,4,"% LUCRO",1,0,"C");
- }
- $pdf->Ln();
- $pdf->SetFont('arial','',5); //Altera a fonte para normal
- } //end if
- //****************************************************************
- //$pdf->Cell(50,4, $vet[$i]['razaosocialempresa'],1,0,"L");
- $pdf->Cell(50,4, $pdf->GetY()." - ".$vet[$i]['razaosocialempresa'],1,0,"L"); // debug Y
- $pdf->SetFillColor(188, 221, 192); //verde claro
- $pdf->Cell(8,4,$vet[$i]['rhnumfunc'],1,0,"C",1);
- if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
- $pdf->Cell(8,4,number_format($vet[$i]['rhhoranormal'], 2, ',','.'),1,0,"C",1);
- $pdf->Cell(8,4,number_format($vet[$i]['rhhorarateio'], 2, ',','.'),1,0,"C",1);
- }
- $pdf->Cell(8,4,number_format($vet[$i]['rhhoratotal'], 2, ',','.'),1,0,"C",1);
- $pdf->Cell(10,4,number_format($vet[$i]['rhcusto'], 2, ',','.'),1,0,"C",1);
- $pdf->SetFillColor(255, 249, 204); //amarelo claro
- if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
- $pdf->Cell(8,4,number_format($vet[$i]['fihoranormal'], 2, ',','.'),1,0,"C",1);
- $pdf->Cell(8,4,number_format($vet[$i]['fihorarateio'], 2, ',','.'),1,0,"C",1);
- }
- $pdf->Cell(8,4,number_format($vet[$i]['fihoratotal'], 2, ',','.'),1,0,"C",1);
- $pdf->Cell(10,4,number_format($vet[$i]['ficusto'], 2, ',','.'),1,0,"C",1);
- $pdf->SetFillColor(198, 216, 239); //azul claro
- if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
- $pdf->Cell(8,4,number_format($vet[$i]['ctbhoranormal'], 2, ',','.'),1,0,"C",1);
- $pdf->Cell(8,4,number_format($vet[$i]['ctbhorarateio'], 2, ',','.'),1,0,"C",1);
- }
- $pdf->Cell(8,4,number_format($vet[$i]['ctbhoratotal'], 2, ',','.'),1,0,"C",1);
- $pdf->Cell(10,4,number_format($vet[$i]['ctbcusto'], 2, ',','.'),1,0,"C",1);
- $pdf->SetFillColor(225, 226, 237); // cinza
- $pdf->Cell(10,4,number_format($vet[$i]['totalhora'], 2, ',','.'),1,0,"C",1);
- $pdf->Cell(10,4,number_format($vet[$i]['jucusto'], 2, ',','.'),1,0,"C");
- $pdf->Cell(10,4,number_format($vet[$i]['ticusto'], 2, ',','.'),1,0,"C");
- $pdf->Cell(10,4,number_format($vet[$i]['dicusto'], 2, ',','.'),1,0,"C");
- $pdf->Cell(10,4,number_format($vet[$i]['oucusto'], 2, ',','.'),1,0,"C");
- $pdf->SetFillColor(225, 226, 237); // cinza
- $pdf->Cell(10,4,number_format($vet[$i]['totalcusto'], 2, ',','.'),1,0,"C",1);
- $pdf->Cell(12,4,number_format($vet[$i]['markup'], 2, ',','.'),1,0,"C");
- $pdf->Cell(12,4,number_format($vet[$i]['precovenda'], 2, ',','.'),1,0,"C");
- //Honorario
- $pdf->Cell(12,4,number_format($vet[$i]['valorhonorario'], 2, ',','.'),1,0,"C");
- $pdf->Cell(12,4,number_format($vet[$i]['valorhonorario13'], 2, ',','.'),1,0,"C");
- if(number_format($vet[$i]['percentuallucro_honorario']<0)){
- $pdf->Cell(12,4,"(".number_format($vet[$i]['percentuallucro_honorario']*-1, 2, ',','.')."%)",1,0,"C");
- }
- else{
- $pdf->Cell(12,4,number_format($vet[$i]['percentuallucro_honorario'], 2, ',','.')."%",1,0,"C");
- }
- if($edtTipoRelatorio=="modelo2" || $edtTipoRelatorio=="modelo4"){
- //Faturado
- $pdf->Cell(12,4,number_format($vet[$i]['valorfaturado'], 2, ',','.'),1,0,"C");
- if(number_format($vet[$i]['percentuallucro_faturado']<0)){
- $pdf->Cell(12,4,"(".number_format($vet[$i]['percentuallucro_faturado']*-1, 2, ',','.')."%)",1,0,"C");
- }
- else{
- $pdf->Cell(12,4,number_format($vet[$i]['percentuallucro_faturado'], 2, ',','.')."%",1,0,"C");
- }
- //Faturado
- $pdf->Cell(12,4,number_format($vet[$i]['valorrecebido'], 2, ',','.'),1,0,"C");
- if(number_format($vet[$i]['percentuallucro_recebido']<0)){
- $pdf->Cell(12,4,"(".number_format($vet[$i]['percentuallucro_recebido']*-1, 2, ',','.')."%)",1,0,"C");
- }
- else{
- $pdf->Cell(12,4,number_format($vet[$i]['percentuallucro_recebido'], 2, ',','.')."%",1,0,"C");
- }
- }
- $pdf->Ln();
- } // fim for
- //********** Totalizadores **********
- $pdf->SetFont('arial','B',5); //Altera a fonte para courier negrito
- $pdf->Cell(50,4,"TOTAL",1,0,"L");
- $pdf->SetFillColor(188, 221, 192); //verde claro
- $pdf->Cell(8,4,$total_numfunc,1,0,"C",1);
- if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
- $pdf->Cell(8,4,number_format($total_rhhoranormal,2,',','.'),1,0,"C",1);
- $pdf->Cell(8,4,number_format($total_rhhorarateio,2,',','.'),1,0,"C",1);
- }
- $pdf->Cell(8,4,number_format($total_rhhoratotal,2,',','.'),1,0,"C",1);
- $pdf->Cell(10,4,number_format($total_rhcusto,2,',','.'),1,0,"C",1);
- $pdf->SetFillColor(255, 249, 204); //amarelo claro
- if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
- $pdf->Cell(8,4,number_format($total_fihoranormal, 2, ',','.'),1,0,"C",1);
- $pdf->Cell(8,4,number_format($total_fihorarateio, 2, ',','.'),1,0,"C",1);
- }
- $pdf->Cell(8,4,number_format($total_fihoratotal, 2, ',','.'),1,0,"C",1);
- $pdf->Cell(10,4,number_format($total_ficusto, 2, ',','.'),1,0,"C",1);
- $pdf->SetFillColor(198, 216, 239); //azul claro
- if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
- $pdf->Cell(8,4,number_format($total_ctbhoranormal, 2, ',','.'),1,0,"C",1);
- $pdf->Cell(8,4,number_format($total_ctbhorarateio, 2, ',','.'),1,0,"C",1);
- }
- $pdf->Cell(8,4,number_format($total_ctbhoratotal, 2, ',','.'),1,0,"C",1);
- $pdf->Cell(10,4,number_format($total_ctbcusto, 2, ',','.'),1,0,"C",1);
- $pdf->SetFillColor(225, 226, 237); // cinza
- $pdf->Cell(10,4,number_format($total_totalhora, 2, ',','.'),1,0,"C",1);
- $pdf->Cell(10,4,number_format($total_jucusto, 2, ',','.'),1,0,"C");
- $pdf->Cell(10,4,number_format($total_ticusto, 2, ',','.'),1,0,"C");
- $pdf->Cell(10,4,number_format($total_dicusto, 2, ',','.'),1,0,"C");
- $pdf->Cell(10,4,number_format($total_oucusto, 2, ',','.'),1,0,"C");
- $pdf->Cell(10,4,number_format($total_totalcusto, 2, ',','.'),1,0,"C",1);
- $pdf->Cell(12,4,number_format($total_markup, 2, ',','.'),1,0,"C");
- $pdf->Cell(12,4,number_format($total_precovenda, 2, ',','.'),1,0,"C");
- $pdf->Cell(12,4,number_format($total_valorhonorario, 2, ',','.'),1,0,"C");
- $pdf->Cell(12,4,number_format($total_valorhonorario13, 2, ',','.'),1,0,"C");
- $total_percentuallucro_honorario = ((($total_valorhonorario+$total_valorhonorario13)/$total_precovenda)-1)*100;
- $pdf->Cell(12,4,number_format($total_percentuallucro_honorario, 2, ',','.')."%",1,0,"C");
- if($edtTipoRelatorio=="modelo2" || $edtTipoRelatorio=="modelo4"){
- $total_percentuallucro_faturado = (($total_valorfaturado/$total_precovenda)-1)*100;
- $total_percentuallucro_recebido = (($total_valorrecebido/$total_precovenda)-1)*100;
- $pdf->Cell(12,4,number_format($total_valorfaturado, 2, ',','.'),1,0,"C");
- $pdf->Cell(12,4,number_format($total_percentuallucro_faturado, 2, ',','.')."%",1,0,"C");
- $pdf->Cell(12,4,number_format($total_valorrecebido, 2, ',','.'),1,0,"C");
- $pdf->Cell(12,4,number_format($total_percentuallucro_recebido, 2, ',','.')."%",1,0,"C");
- }
- $pdf->Ln();
- //********** PDF - Gera o arquivo PDF **********
- $BASE_DIR = str_replace((substr( $_SERVER['SCRIPT_NAME'], strpos($_SERVER['SCRIPT_NAME'], DIRECTORY_SEPARATOR, 2) , strlen($_SERVER['SCRIPT_NAME']) )),"", $_SERVER['SCRIPT_FILENAME']);
- $datahoraarquivo = date("YmdHis");
- $NomeArquivoPDF = "tmp/custos_$datahoraarquivo.pdf";
- $pdf->Output(BASE_DIR . DS . $NomeArquivoPDF,"F"); // Gera o PDF
- $arq1="download.php?arq=".basename($NomeArquivoPDF)."&prog=download";
- $arq2="$NomeArquivoPDF";
- $arq1 ="download.php?arq=".basename($NomeArquivoPDF)."&prog=download";
- $arq2 ="$NomeArquivoPDF#view=fit";
- $css = "class='ui-button ui-state-default ui-corner-all'";
- $css ="";
- $aux .= "<p class='ui-widget'>Clique no link abaixo para efetuar o download do arquivo texto: <br />";
- $aux .= " Arquivo TXT Download: <a href='download.php?arq=".basename($NomeArquivoTXT)."&prog=download'>".basename($NomeArquivoTXT)."</a></p>";
- $aux .= "<iframe src='$arq2' $css title=''>".basename($NomeArquivoPDF)."</iframe>";
- $aux .= "<script type='text/javascript' src='js/jquery-init.js' charset='utf-8'></script>";
- $v['success'] = true;
- $v['error'] = "";
- $v['type'] = "pdf";
- $v['orientation'] = "L";
- $v['message'] = $aux;
- } // fim if
- else{
- $aux = " Não existem registros com os filtros informados ou ocorreu algum erro na geração do relatório!";
- $v['success'] = false;
- $v['error'] = $aux;
- $v['type'] = "text";
- $v['message'] = "";
- }
- /*** Conecta com o banco MySQL ***/
- $mySQL->desconectarMySQL();
- /*** Imprime o resultado na tela ***/
- echo json_encode($v);
- /*** Destroi o objeto MySQL */
- unset($mySQL);
- exit;
- } // fim RelatorioUsuario
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement