Advertisement
wanderleihuttel

FPDF Report

May 25th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 32.25 KB | None | 0 0
  1. <?php
  2. //==============================================================
  3. // INCLUDE DE ARQUIVOS
  4. //==============================================================
  5. require_once($_SERVER['BASE_DIR'].'vendor/autoload.php');
  6.  
  7. /*** variável do tipo de operação ***/
  8. $OperacaoID = trim($_POST['OperacaoID']);
  9.  
  10. /*** Faz a Verificação do Tipo de SQL a Executar ***/
  11. switch($OperacaoID){
  12.    case "relatorio_custo_geral"              : { RelatorioCustoGeral(); break; }
  13.    //default:         { echo "Ocorreu Um erro!";break;}
  14. }
  15.  
  16. /*####################################### Relatório Usuário #######################################*/
  17. function RelatorioCustoGeral(){
  18.      
  19.       $edtReferenciaInicial    = "01/".$_POST['edtReferenciaInicial'];
  20.       $edtReferenciaFinal    = "01/".$_POST['edtReferenciaFinal'];
  21.       $edtTipoRelatorio = $_POST['edtTipoRelatorio'];
  22.      
  23.       if($_POST['edtReferenciaInicial']==$_POST['edtReferenciaFinal']){
  24.         $tituloReferencia = $_POST['edtReferenciaInicial'];
  25.       }
  26.       else{
  27.         $tituloReferencia = $_POST['edtReferenciaInicial']." à ".$_POST['edtReferenciaFinal']." (média)";
  28.       }
  29.  
  30.       if (validarData($edtReferenciaInicial, 'dd/mm/aaaa')){
  31.          $edtReferenciaInicial  = formatarDataMySQL($edtReferenciaInicial);
  32.       }
  33.       if (validarData($edtReferenciaFinal, 'dd/mm/aaaa')){
  34.          $edtReferenciaFinal  = formatarDataMySQL($edtReferenciaFinal);
  35.       }
  36.      
  37.       /*** Instancia um novo objeto MySQL */
  38.       $mySQL = new MySQL();
  39.  
  40.       /*** Conecta com o banco MySQL ***/
  41.       $mySQL->conectarMySQL();
  42.      
  43.       /*** Busca os dados da tabela custoapuracao ***/
  44.       if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo2"){
  45.          $sql_query = "select A.referenciacustoapuracao, A.codigoempresa, B.razaosocialempresa,
  46.                       sum(A.rhnumfunc) as rhnumfunc,
  47.                       sum(A.rhhoranormal) as rhhoranormal,
  48.                       sum(A.rhhorarateio) as rhhorarateio,
  49.                       sum(A.rhhoratotal) as rhhoratotal,
  50.                       sum(A.rhcusto) as rhcusto,
  51.                       sum(A.fihoranormal) as fihoranormal,
  52.                       sum(A.fihorarateio) as fihorarateio,
  53.                       sum(A.fihoratotal) as fihoratotal,
  54.                       sum(A.ficusto) as ficusto,
  55.                       sum(A.ctbhoranormal) as ctbhoranormal,
  56.                       sum(A.ctbhorarateio) as ctbhorarateio,
  57.                       sum(A.ctbhoratotal) as ctbhoratotal,
  58.                       sum(A.ctbcusto) as ctbcusto,                      
  59.                       sum(A.jucusto) as jucusto,
  60.                       sum(A.ticusto) as ticusto,
  61.                       sum(A.dicusto) as dicusto,
  62.                       sum(A.oucusto) as oucusto,
  63.                       sum(A.totalhora) as totalhora,
  64.                       sum(A.totalcusto) as totalcusto,
  65.                       sum(A.markup) as markup,
  66.                       sum(A.precovenda) as precovenda,
  67.                       sum(A.valorhonorario) as valorhonorario,
  68.                       sum(A.valorfaturado) as valorfaturado,
  69.                       sum(A.valorrecebido) as valorrecebido
  70.                       from custoapuracao A
  71.                       left join empresa B on (A.codigoempresa = B.codigoempresa)
  72.                       where A.referenciacustoapuracao = '".$edtReferenciaInicial."'
  73.                       group by 1,2,3
  74.                       order by B.razaosocialempresa";
  75.       }//fim if
  76.       else if($edtTipoRelatorio=="modelo3" || $edtTipoRelatorio=="modelo4"){
  77.          $sql_query = "select A.codigoempresa, A.razaosocialempresa,
  78.         round(avg(A.rhnumfunc),2) as rhnumfunc,
  79.         round(avg(A.rhhoranormal),2) as rhhoranormal,
  80.         round(avg(A.rhhorarateio),2) as rhhorarateio,
  81.         round(avg(A.rhhoratotal),2) as rhhoratotal,
  82.         round(avg(A.rhcusto),2) as rhcusto,
  83.         round(avg(A.fihoranormal),2) as fihoranormal,
  84.         round(avg(A.fihorarateio),2) as fihorarateio,
  85.         round(avg(A.fihoratotal),2) as fihoratotal,
  86.         round(avg(A.ficusto),2) as ficusto,
  87.         round(avg(A.ctbhoranormal),2) as ctbhoranormal,
  88.         round(avg(A.ctbhorarateio),2) as ctbhorarateio,
  89.         round(avg(A.ctbhoratotal),2) as ctbhoratotal,
  90.         round(avg(A.ctbcusto),2) as ctbcusto,
  91.         round(avg(A.jucusto),2) as jucusto,
  92.         round(avg(A.ticusto),2) as ticusto,
  93.         round(avg(A.dicusto),2) as dicusto,
  94.         round(avg(A.oucusto),2) as oucusto,
  95.         round(avg(A.totalhora),2) as totalhora,
  96.         round(avg(A.totalcusto),2) as totalcusto,
  97.         round(avg(A.markup),2) as markup,
  98.         round(avg(A.precovenda),2) as precovenda,
  99.         round(avg(A.valorhonorario),2) as valorhonorario,
  100.         round(avg(A.valorfaturado),2) as valorfaturado,
  101.         round(avg(A.valorrecebido),2) as valorrecebido,
  102.         count(*) as contador
  103.         from (
  104.         select A.referenciacustoapuracao, A.codigoempresa, B.razaosocialempresa,
  105.         sum(A.rhnumfunc) as rhnumfunc,
  106.         sum(A.rhhoranormal) as rhhoranormal,
  107.         sum(A.rhhorarateio) as rhhorarateio,
  108.         sum(A.rhhoratotal) as rhhoratotal,
  109.         sum(A.rhcusto) as rhcusto,
  110.         sum(A.ctbhoranormal) as ctbhoranormal,
  111.         sum(A.ctbhorarateio) as ctbhorarateio,
  112.         sum(A.ctbhoratotal) as ctbhoratotal,
  113.         sum(A.ctbcusto) as ctbcusto,
  114.         sum(A.fihoranormal) as fihoranormal,
  115.         sum(A.fihorarateio) as fihorarateio,
  116.         sum(A.fihoratotal) as fihoratotal,
  117.         sum(A.ficusto) as ficusto,
  118.         sum(A.jucusto) as jucusto,
  119.         sum(A.ticusto) as ticusto,
  120.         sum(A.dicusto) as dicusto,
  121.         sum(A.oucusto) as oucusto,
  122.         sum(A.totalhora) as totalhora,
  123.         sum(A.totalcusto) as totalcusto,
  124.         sum(A.markup) as markup,
  125.         sum(A.precovenda) as precovenda,
  126.         sum(A.valorhonorario) as valorhonorario,
  127.         sum(A.valorfaturado) as valorfaturado,
  128.         sum(A.valorrecebido) as valorrecebido
  129.         from custoapuracao A
  130.         left join empresa B on (A.codigoempresa = B.codigoempresa)
  131.         where A.referenciacustoapuracao between '".$edtReferenciaInicial."' and '".$edtReferenciaFinal."'
  132.         group by 1,2,3
  133.         ) A
  134.         group by 1,2
  135.         order by 2";
  136.      
  137.       }//fim else if
  138.      
  139.  
  140.       /*** Executa  a consulta no banco MySQL ***/
  141.       $query = $mySQL->executarMySQL($sql_query);
  142.       $rows = $mySQL->contarMySQL($query);
  143.      
  144.       /*** Verifica se a query foi executada com sucesso, senão cancela ***/
  145.       $aux = "";
  146.       if($query && $rows){
  147.          $i=0;
  148.          $j=2;
  149.          //********** Inicializa as variáveis dos acumuladores de totais **********
  150.          $total_numfunc        = 0;
  151.          $total_rhhoranormal   = 0;
  152.          $total_rhhorarateio   = 0;
  153.          $total_rhhoratotal    = 0;
  154.          $total_rhcusto        = 0;
  155.          $total_fihoranormal   = 0;
  156.          $total_fihorarateio   = 0;
  157.          $total_fihoratotal    = 0;
  158.          $total_ficusto        = 0;
  159.          $total_ctbhoranormal  = 0;
  160.          $total_ctbhorarateio  = 0;
  161.          $total_ctbhoratotal   = 0;
  162.          $total_ctbcusto       = 0;
  163.          $total_totalhora      = 0;
  164.          $total_jucusto        = 0;
  165.          $total_ticusto        = 0;
  166.          $total_dicusto        = 0;
  167.          $total_oucusto        = 0;
  168.          $total_totalcusto     = 0;
  169.          $total_markup         = 0;
  170.          $total_precovenda     = 0;
  171.          $total_valorhonorario = 0;
  172.          $total_valorhonorario13 = 0;
  173.          $total_valorfaturado  = 0;
  174.          $total_valorrecebido  = 0;
  175.          
  176.          
  177.          while($row = $mySQL->mostrarMySQL($query)){
  178.              //********** Atribui os valores da consulta em um array **********
  179.              $vet[$i]['codigoempresa']      = $row['codigoempresa'];
  180.              $vet[$i]['razaosocialempresa'] = formata_campo($row['razaosocialempresa'], '40', ' ', 'E');
  181.              $vet[$i]['rhnumfunc']          = $row['rhnumfunc'];
  182.              $vet[$i]['rhhoranormal']       = $row['rhhoranormal'];
  183.              $vet[$i]['rhhorarateio']       = $row['rhhorarateio'];
  184.              $vet[$i]['rhhoratotal']        = $row['rhhoratotal'];
  185.              $vet[$i]['rhcusto']            = $row['rhcusto'];
  186.              $vet[$i]['fihoranormal']       = $row['fihoranormal'];
  187.              $vet[$i]['fihorarateio']       = $row['fihorarateio'];
  188.              $vet[$i]['fihoratotal']        = $row['fihoratotal'];
  189.              $vet[$i]['ficusto']            = $row['ficusto'];
  190.              $vet[$i]['ctbhoranormal']      = $row['ctbhoranormal'];
  191.              $vet[$i]['ctbhorarateio']      = $row['ctbhorarateio'];
  192.              $vet[$i]['ctbhoratotal']       = $row['ctbhoratotal'];
  193.              $vet[$i]['ctbcusto']           = $row['ctbcusto'];
  194.              $vet[$i]['jucusto']            = $row['jucusto'];
  195.              $vet[$i]['ticusto']            = $row['ticusto'];
  196.              $vet[$i]['dicusto']            = $row['dicusto'];
  197.              $vet[$i]['oucusto']            = $row['oucusto'];
  198.              $vet[$i]['totalhora']          = $row['totalhora'];
  199.              $vet[$i]['totalcusto']         = $row['totalcusto'];
  200.              $vet[$i]['markup']             = $row['markup'];
  201.              $vet[$i]['valorhonorario']     = $row['valorhonorario'];
  202.              $vet[$i]['valorhonorario13']   = ($row['valorhonorario']/12);
  203.              $vet[$i]['precovenda']         = $row['precovenda'];
  204.              $vet[$i]['valorfaturado']      = $row['valorfaturado'];
  205.              $vet[$i]['valorrecebido']      = $row['valorrecebido'];
  206.              
  207.              //***** Verifica se o preco de venda for maior que zero para efetuar a divisão *****
  208.              //Evitar erro de divisão por 0
  209.              if($row['precovenda'] > 0){
  210.                  $vet[$i]['percentuallucro_honorario']  = ((($row['valorhonorario']+($row['valorhonorario']/12))/$row['precovenda'])-1)*100;
  211.                  $vet[$i]['percentuallucro_faturado']   = (($row['valorfaturado']/$row['precovenda'])-1)*100;
  212.                  $vet[$i]['percentuallucro_recebido']   = (($row['valorrecebido']/$row['precovenda'])-1)*100;
  213.              }  // end if
  214.              else{
  215.                 $vet[$i]['percentuallucro_honorario']  = "100";
  216.                 $vet[$i]['percentuallucro_faturado']   = "100";
  217.                 $vet[$i]['percentuallucro_recebido']   = "100";
  218.              } //end else
  219.              
  220.              //############ Arquivo CSV para Excel ############
  221.              if($i==0){
  222.                $aux .= "codigoempresa;razaosocialempresa;rhnumfunc;rhhoranormal;rhhorarateio;rhhoratotal;rhcusto;fihoranormal;fihorarateio;fihoratotal;ficusto;ctbhoranormal;ctbhorarateio;ctbhoratotal;ctbcusto;".
  223.                        "jucusto;ticusto;dicusto;oucusto;totalhora;totalcusto;markup;valorhonorario;valorhonorario13;precovenda;valorfaturado;valorrecebido;%lucro_honorario;%lucro_faturado;%lucro_recebido\n";
  224.              }
  225.              $aux .= $vet[$i]['codigoempresa'] .";".                               //A  1
  226.                      $vet[$i]['razaosocialempresa'].";".                           //B  2
  227.                      formatarValorPadrao($vet[$i]['rhnumfunc'],2).";".             //C  3
  228.                      formatarValorPadrao($vet[$i]['rhhoranormal'],2).";".          //D  4
  229.                      formatarValorPadrao($vet[$i]['rhhorarateio'],2).";".          //E  5
  230.                      "=(D".($i+2)."+E".($i+2).");".                                //F  6
  231.                      "=(\$G\$".($rows+2)."/\$F\$".($rows+2).")*F".($i+2).";".      //G  7
  232.                      formatarValorPadrao($vet[$i]['fihoranormal'],2).";".          //H  8
  233.                      formatarValorPadrao($vet[$i]['fihorarateio'],2).";".          //I  9
  234.                      "=(H".($i+2)."+I".($i+2).");".                                //J 10
  235.                      "=(\$K\$".($rows+2)."/\$J\$".($rows+2).")*J".($i+2).";".      //K 11
  236.                      formatarValorPadrao($vet[$i]['ctbhoranormal'],2).";".         //L 12
  237.                      formatarValorPadrao($vet[$i]['ctbhorarateio'],2).";".         //M 13
  238.                      "=(L".($i+2)."+M".($i+2).");".                                //N 14
  239.                      "=(\$O\$".($rows+2)."/\$N\$".($rows+2).")*N".($i+2).";".      //O 15
  240.                      //formatarValorPadrao($vet[$i]['jucusto'],2).";".               //P 16
  241.                      "=(\$P\$".($rows+2)."/\$T\$".($rows+2).")*T".($i+2).";".      //O 15 (jucusto)
  242.                      //formatarValorPadrao($vet[$i]['ticusto'],2).";".               //Q 17
  243.                      "=(\$Q\$".($rows+2)."/\$T\$".($rows+2).")*T".($i+2).";".      //O 15 (ticusto)
  244.                      //formatarValorPadrao($vet[$i]['dicusto'],2).";".               //R 18
  245.                      "=(\$R\$".($rows+2)."/\$T\$".($rows+2).")*T".($i+2).";".      //O 15 (dicusto)
  246.                      //formatarValorPadrao($vet[$i]['oucusto'],2).";".               //S 19
  247.                      "=(\$S\$".($rows+2)."/\$T\$".($rows+2).")*T".($i+2).";".      //O 15 (oucusto)
  248.                      "=(F".($i+2)."+J".($i+2)."+N".($i+2).");".                    //T 20
  249.                      "=(G".($i+2)."+K".($i+2)."+O".($i+2)."+P".($i+2)."+Q".($i+2)."+R".($i+2)."+S".($i+2).");". //U 21
  250.                      formatarValorPadrao($vet[$i]['markup'],2).";".                //V 22
  251.                      formatarValorPadrao($vet[$i]['valorhonorario'],2).";".        //W 23
  252.                      formatarValorPadrao($vet[$i]['valorhonorario13'],2).";".      //X 24
  253.                      "=(U".($i+2)."+V".($i+2).");".                                //Y 25
  254.                      formatarValorPadrao($vet[$i]['valorfaturado'],2).";".         //Z 26
  255.                      formatarValorPadrao($vet[$i]['valorrecebido'],2).";".         //AA 27
  256.                      "=(((W".($i+2)."+X".($i+2).")/Y".($i+2).")-1)*100;".          //AB 28
  257.                      "=(((Z".($i+2).")/Y".($i+2).")-1)*100;".                      //AC 29
  258.                      "=(((AA".($i+2).")/Y".($i+2).")-1)*100;".                     //AD 30
  259.                      ";\n";
  260.              //############ Arquivo CSV para Excel ############
  261.              
  262.              
  263.              //********** Acumuladores de Totalizadores **********
  264.              $total_numfunc        += $row['rhnumfunc'];
  265.              $total_rhhoranormal   += $row['rhhoranormal'];
  266.              $total_rhhorarateio   += $row['rhhorarateio'];
  267.              $total_rhhoratotal    += $row['rhhoratotal'];
  268.              $total_rhcusto        += $row['rhcusto'];
  269.              $total_fihoranormal   += $row['fihoranormal'];
  270.              $total_fihorarateio   += $row['fihorarateio'];
  271.              $total_fihoratotal    += $row['fihoratotal'];
  272.              $total_ficusto        += $row['ficusto'];
  273.              $total_ctbhoranormal  += $row['ctbhoranormal'];
  274.              $total_ctbhorarateio  += $row['ctbhorarateio'];
  275.              $total_ctbhoratotal   += $row['ctbhoratotal'];
  276.              $total_ctbcusto       += $row['ctbcusto'];
  277.              $total_totalhora      += $row['totalhora'];
  278.              $total_jucusto        += $row['jucusto'];
  279.              $total_ticusto        += $row['ticusto'];
  280.              $total_dicusto        += $row['dicusto'];
  281.              $total_oucusto        += $row['oucusto'];
  282.              $total_totalcusto     += $row['totalcusto'];
  283.              $total_markup         += $row['markup'];
  284.              $total_precovenda     += $row['precovenda'];
  285.              $total_valorhonorario += $row['valorhonorario'];
  286.              $total_valorhonorario13 += ($row['valorhonorario']/12);
  287.              $total_valorfaturado  += $row['valorfaturado'];
  288.              $total_valorrecebido  += $row['valorrecebido'];
  289.              $i++;
  290.          } // fim while
  291.  
  292.             $aux .= "codigoempresa;razaosocialempresa;".
  293.                     formatarValorPadrao($total_numfunc,2).";".
  294.                     formatarValorPadrao($total_rhhoranormal,2).";".
  295.                     formatarValorPadrao($total_rhhorarateio,2).";".
  296.                     formatarValorPadrao($total_rhhoratotal,2).";".
  297.                     formatarValorPadrao($total_rhcusto,2).";".
  298.                     formatarValorPadrao($total_fihoranormal,2).";".
  299.                     formatarValorPadrao($total_fihorarateio,2).";".
  300.                     formatarValorPadrao($total_fihoratotal,2).";".
  301.                     formatarValorPadrao($total_ficusto,2).";".
  302.                     formatarValorPadrao($total_ctbhoranormal,2).";".
  303.                     formatarValorPadrao($total_ctbhorarateio,2).";".
  304.                     formatarValorPadrao($total_ctbhoratotal,2).";".
  305.                     formatarValorPadrao($total_ctbcusto,2).";".
  306.                     formatarValorPadrao($total_jucusto,2).";".
  307.                     formatarValorPadrao($total_ticusto,2).";".
  308.                     formatarValorPadrao($total_dicusto,2).";".
  309.                     formatarValorPadrao($total_oucusto,2).";".
  310.                     formatarValorPadrao($total_totalhora,2).";".
  311.                     "=SOMA(U2:U".($i+1).");".
  312.                     "=SOMA(V2:V".($i+1).");".
  313.                     "=SOMA(W2:W".($i+1).");".
  314.                     "=SOMA(X2:X".($i+1).");".
  315.                     "=SOMA(Y2:Y".($i+1).");".
  316.                     "=SOMA(Z2:Z".($i+1).");".
  317.                     "=SOMA(AA2:AA".($i+1).");".
  318.                     "=(((W".($i+2)."+X".($i+2).")/Y".($i+2).")-1)*100;".
  319.                     "=(((Z".($i+2).")/Y".($i+2).")-1)*100;".
  320.                     "=(((AA".($i+2).")/Y".($i+2).")-1)*100;".
  321.                     "\n";
  322.          
  323.           $aux .= "codigoempresa;razaosocialempresa;rhnumfunc;rhhoranormal;rhhorarateio;rhhoratotal;rhcusto;fihoranormal;fihorarateio;fihoratotal;ficusto;ctbhoranormal;ctbhorarateio;ctbhoratotal;ctbcusto;".
  324.           "jucusto;ticusto;dicusto;oucusto;totalhora;totalcusto;markup;valorhonorario;valorhonorario13;precovenda;valorfaturado;valorrecebido;%lucro_honorario;%lucro_faturado;%lucro_recebido\n";
  325.  
  326.          $BASE_DIR = str_replace((substr( $_SERVER['SCRIPT_NAME'], strpos($_SERVER['SCRIPT_NAME'], DIRECTORY_SEPARATOR, 2) , strlen($_SERVER['SCRIPT_NAME']) )),"", $_SERVER['SCRIPT_FILENAME']);
  327.          $datahoraarquivo = date("YmdHis");
  328.          $NomeArquivoTXT = "tmp/custos_$datahoraarquivo.csv";
  329.          $fp = fopen(BASE_DIR . DS . $NomeArquivoTXT,"w+");
  330.          fputs($fp,$aux);
  331.          fclose($fp);
  332.          $aux = "";
  333.  
  334.          // Instancia o objeto FPDF (Retrato / milímetros / A4)
  335.          $pdf = new PDF("L","mm","A4");
  336.          
  337.          //***** Estrutura de repetição que percorre o vetor e imprime *****
  338.          for($i=0;$i<count($vet);$i++){
  339.                    
  340.              $page_height = 210;             //tamanho da página em milimetros
  341.              $bottom_margin = 10;            //tamanho da margem inferior
  342.              $used_height   = $pdf->GetY();  // mm until end of page (less bottom margin of 20mm)
  343.  
  344.              //***** Imprime o cabeçalho se faltar 20 mm ou menos ou se o $i for igual a 0 *****
  345.              if ( $used_height >=  ($page_height-$bottom_margin ) || $i==0){
  346.                
  347.                 $pdf->AddPage();
  348.  
  349.                 if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
  350.                     $pdf->SetHeaderTitle("RELATÓRIO DE CUSTOS - REFERÊNCIA: $tituloReferencia - ( $edtTipoRelatorio: conferência )");
  351.                 }
  352.                 else if($edtTipoRelatorio=="modelo2" || $edtTipoRelatorio=="modelo4"){
  353.                     $pdf->SetHeaderTitle("RELATÓRIO DE CUSTOS - REFERÊNCIA: $tituloReferencia - ( $edtTipoRelatorio: %lucro )");
  354.                 }
  355.  
  356.                 //****************************************************************
  357.                 // Cabeçalho das colunas
  358.                 $pdf->SetFont('arial','B',5); //Altera a fonte negrito
  359.                 $pdf->Cell(50,4,"EMPRESA",1,0,"L");
  360.                 $pdf->SetFillColor(188, 221, 192); //verde claro
  361.                 $pdf->Cell(8,4,"Nº FUNC",1,0,"C",1);
  362.                
  363.                 if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
  364.                    $pdf->Cell(8,4,"RH HN",1,0,"C",1);
  365.                    $pdf->Cell(8,4,"RH HR",1,0,"C",1);
  366.                 }
  367.                
  368.                 $pdf->Cell(8,4,"RH HT",1,0,"C",1);
  369.                 $pdf->Cell(10,4,"RH CU",1,0,"C",1);
  370.                 $pdf->SetFillColor(255, 249, 204); //amarelo claro
  371.                
  372.                 if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
  373.                    $pdf->Cell(8,4,"FI HN",1,0,"C",1);
  374.                    $pdf->Cell(8,4,"FI HR",1,0,"C",1);
  375.                 }
  376.                 $pdf->Cell(8,4,"FI HT",1,0,"C",1);
  377.                 $pdf->Cell(10,4,"FI CU",1,0,"C",1);
  378.                 $pdf->SetFillColor(198, 216, 239); //azul claro
  379.                
  380.                 if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
  381.                    $pdf->Cell(8,4,"CTB HN",1,0,"C",1);
  382.                    $pdf->Cell(8,4,"CTB HR",1,0,"C",1);
  383.                 }
  384.                
  385.                 $pdf->Cell(8,4,"CTB HT",1,0,"C",1);
  386.                 $pdf->Cell(10,4,"CTB CU",1,0,"C",1);
  387.                 $pdf->SetFillColor(225, 226, 237); // cinza
  388.                 $pdf->Cell(10,4,"HR TOT",1,0,"C",1);
  389.                 $pdf->Cell(10,4,"JU CU",1,0,"C");
  390.                 $pdf->Cell(10,4,"TI CU",1,0,"C");
  391.                 $pdf->Cell(10,4,"DI CU",1,0,"C");
  392.                 $pdf->Cell(10,4,"OU CU",1,0,"C");
  393.                 $pdf->SetFillColor(225, 226, 237); // cinza
  394.                 $pdf->Cell(10,4,"TOT CU",1,0,"C",1);
  395.                 $pdf->Cell(12,4,"MARKUP",1,0,"C");
  396.                 $pdf->Cell(12,4,"P.VENDA",1,0,"C");
  397.                 $pdf->Cell(12,4,"HONORÁRIO",1,0,"C");
  398.                 $pdf->Cell(12,4,"HONOR. 13º",1,0,"C");
  399.                 $pdf->Cell(12,4,"% LUCRO",1,0,"C");
  400.                
  401.                 if($edtTipoRelatorio=="modelo2" || $edtTipoRelatorio=="modelo4"){
  402.                    $pdf->Cell(12,4,"FATURADO",1,0,"C");
  403.                    $pdf->Cell(12,4,"% LUCRO",1,0,"C");
  404.                    $pdf->Cell(12,4,"RECEBIDO",1,0,"C");
  405.                    $pdf->Cell(12,4,"% LUCRO",1,0,"C");
  406.                 }
  407.                 $pdf->Ln();
  408.                
  409.                
  410.                 $pdf->SetFont('arial','',5); //Altera a fonte para normal                  
  411.              } //end if
  412.              //****************************************************************
  413.              
  414.              //$pdf->Cell(50,4, $vet[$i]['razaosocialempresa'],1,0,"L");
  415.              $pdf->Cell(50,4, $pdf->GetY()." - ".$vet[$i]['razaosocialempresa'],1,0,"L"); // debug Y
  416.              $pdf->SetFillColor(188, 221, 192); //verde claro
  417.              $pdf->Cell(8,4,$vet[$i]['rhnumfunc'],1,0,"C",1);
  418.              
  419.              if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
  420.                 $pdf->Cell(8,4,number_format($vet[$i]['rhhoranormal'], 2, ',','.'),1,0,"C",1);
  421.                 $pdf->Cell(8,4,number_format($vet[$i]['rhhorarateio'], 2, ',','.'),1,0,"C",1);
  422.              }
  423.              $pdf->Cell(8,4,number_format($vet[$i]['rhhoratotal'], 2, ',','.'),1,0,"C",1);
  424.              $pdf->Cell(10,4,number_format($vet[$i]['rhcusto'], 2, ',','.'),1,0,"C",1);
  425.  
  426.              $pdf->SetFillColor(255, 249, 204); //amarelo claro
  427.              
  428.              if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
  429.                 $pdf->Cell(8,4,number_format($vet[$i]['fihoranormal'], 2, ',','.'),1,0,"C",1);
  430.                 $pdf->Cell(8,4,number_format($vet[$i]['fihorarateio'], 2, ',','.'),1,0,"C",1);
  431.              }
  432.              $pdf->Cell(8,4,number_format($vet[$i]['fihoratotal'], 2, ',','.'),1,0,"C",1);
  433.              $pdf->Cell(10,4,number_format($vet[$i]['ficusto'], 2, ',','.'),1,0,"C",1);
  434.  
  435.              $pdf->SetFillColor(198, 216, 239); //azul claro
  436.              
  437.              if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
  438.                 $pdf->Cell(8,4,number_format($vet[$i]['ctbhoranormal'], 2, ',','.'),1,0,"C",1);
  439.                 $pdf->Cell(8,4,number_format($vet[$i]['ctbhorarateio'], 2, ',','.'),1,0,"C",1);
  440.              }
  441.              $pdf->Cell(8,4,number_format($vet[$i]['ctbhoratotal'], 2, ',','.'),1,0,"C",1);
  442.              $pdf->Cell(10,4,number_format($vet[$i]['ctbcusto'], 2, ',','.'),1,0,"C",1);
  443.              
  444.              $pdf->SetFillColor(225, 226, 237); // cinza
  445.              $pdf->Cell(10,4,number_format($vet[$i]['totalhora'], 2, ',','.'),1,0,"C",1);
  446.              
  447.              $pdf->Cell(10,4,number_format($vet[$i]['jucusto'], 2, ',','.'),1,0,"C");
  448.              $pdf->Cell(10,4,number_format($vet[$i]['ticusto'], 2, ',','.'),1,0,"C");
  449.              $pdf->Cell(10,4,number_format($vet[$i]['dicusto'], 2, ',','.'),1,0,"C");
  450.              $pdf->Cell(10,4,number_format($vet[$i]['oucusto'], 2, ',','.'),1,0,"C");
  451.              $pdf->SetFillColor(225, 226, 237); // cinza
  452.              $pdf->Cell(10,4,number_format($vet[$i]['totalcusto'], 2, ',','.'),1,0,"C",1);
  453.              $pdf->Cell(12,4,number_format($vet[$i]['markup'], 2, ',','.'),1,0,"C");
  454.              $pdf->Cell(12,4,number_format($vet[$i]['precovenda'], 2, ',','.'),1,0,"C");
  455.              
  456.              //Honorario
  457.              $pdf->Cell(12,4,number_format($vet[$i]['valorhonorario'], 2, ',','.'),1,0,"C");
  458.              $pdf->Cell(12,4,number_format($vet[$i]['valorhonorario13'], 2, ',','.'),1,0,"C");
  459.              
  460.              if(number_format($vet[$i]['percentuallucro_honorario']<0)){
  461.                $pdf->Cell(12,4,"(".number_format($vet[$i]['percentuallucro_honorario']*-1, 2, ',','.')."%)",1,0,"C");
  462.              }
  463.              else{
  464.                 $pdf->Cell(12,4,number_format($vet[$i]['percentuallucro_honorario'], 2, ',','.')."%",1,0,"C");
  465.              }
  466.              
  467.              if($edtTipoRelatorio=="modelo2" || $edtTipoRelatorio=="modelo4"){
  468.                    //Faturado
  469.                    $pdf->Cell(12,4,number_format($vet[$i]['valorfaturado'], 2, ',','.'),1,0,"C");
  470.                    if(number_format($vet[$i]['percentuallucro_faturado']<0)){
  471.                      $pdf->Cell(12,4,"(".number_format($vet[$i]['percentuallucro_faturado']*-1, 2, ',','.')."%)",1,0,"C");
  472.                    }
  473.                    else{
  474.                       $pdf->Cell(12,4,number_format($vet[$i]['percentuallucro_faturado'], 2, ',','.')."%",1,0,"C");
  475.                    }
  476.                    //Faturado
  477.                    $pdf->Cell(12,4,number_format($vet[$i]['valorrecebido'], 2, ',','.'),1,0,"C");
  478.                    if(number_format($vet[$i]['percentuallucro_recebido']<0)){
  479.                      $pdf->Cell(12,4,"(".number_format($vet[$i]['percentuallucro_recebido']*-1, 2, ',','.')."%)",1,0,"C");
  480.                    }
  481.                    else{
  482.                       $pdf->Cell(12,4,number_format($vet[$i]['percentuallucro_recebido'], 2, ',','.')."%",1,0,"C");
  483.                    }
  484.              }
  485.              $pdf->Ln();
  486.          
  487.          } // fim for
  488.          
  489.          
  490.          //********** Totalizadores  **********
  491.          $pdf->SetFont('arial','B',5); //Altera a fonte para courier negrito
  492.          $pdf->Cell(50,4,"TOTAL",1,0,"L");
  493.          $pdf->SetFillColor(188, 221, 192); //verde claro
  494.          $pdf->Cell(8,4,$total_numfunc,1,0,"C",1);
  495.          if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
  496.             $pdf->Cell(8,4,number_format($total_rhhoranormal,2,',','.'),1,0,"C",1);
  497.             $pdf->Cell(8,4,number_format($total_rhhorarateio,2,',','.'),1,0,"C",1);
  498.            
  499.          }
  500.          $pdf->Cell(8,4,number_format($total_rhhoratotal,2,',','.'),1,0,"C",1);
  501.          $pdf->Cell(10,4,number_format($total_rhcusto,2,',','.'),1,0,"C",1);
  502.          
  503.          $pdf->SetFillColor(255, 249, 204); //amarelo claro
  504.          if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
  505.             $pdf->Cell(8,4,number_format($total_fihoranormal, 2, ',','.'),1,0,"C",1);
  506.             $pdf->Cell(8,4,number_format($total_fihorarateio, 2, ',','.'),1,0,"C",1);
  507.          }
  508.          $pdf->Cell(8,4,number_format($total_fihoratotal, 2, ',','.'),1,0,"C",1);
  509.          $pdf->Cell(10,4,number_format($total_ficusto, 2, ',','.'),1,0,"C",1);
  510.          
  511.  
  512.          $pdf->SetFillColor(198, 216, 239); //azul claro
  513.          if($edtTipoRelatorio=="modelo1" || $edtTipoRelatorio=="modelo3"){
  514.             $pdf->Cell(8,4,number_format($total_ctbhoranormal, 2, ',','.'),1,0,"C",1);
  515.             $pdf->Cell(8,4,number_format($total_ctbhorarateio, 2, ',','.'),1,0,"C",1);
  516.          }
  517.          $pdf->Cell(8,4,number_format($total_ctbhoratotal, 2, ',','.'),1,0,"C",1);
  518.          $pdf->Cell(10,4,number_format($total_ctbcusto, 2, ',','.'),1,0,"C",1);
  519.          
  520.          $pdf->SetFillColor(225, 226, 237); // cinza
  521.          $pdf->Cell(10,4,number_format($total_totalhora, 2, ',','.'),1,0,"C",1);
  522.          
  523.          $pdf->Cell(10,4,number_format($total_jucusto, 2, ',','.'),1,0,"C");
  524.          $pdf->Cell(10,4,number_format($total_ticusto, 2, ',','.'),1,0,"C");
  525.          $pdf->Cell(10,4,number_format($total_dicusto, 2, ',','.'),1,0,"C");
  526.          $pdf->Cell(10,4,number_format($total_oucusto, 2, ',','.'),1,0,"C");
  527.          
  528.          $pdf->Cell(10,4,number_format($total_totalcusto, 2, ',','.'),1,0,"C",1);
  529.          
  530.          $pdf->Cell(12,4,number_format($total_markup, 2, ',','.'),1,0,"C");
  531.          $pdf->Cell(12,4,number_format($total_precovenda, 2, ',','.'),1,0,"C");
  532.          $pdf->Cell(12,4,number_format($total_valorhonorario, 2, ',','.'),1,0,"C");
  533.          $pdf->Cell(12,4,number_format($total_valorhonorario13, 2, ',','.'),1,0,"C");
  534.          
  535.          $total_percentuallucro_honorario = ((($total_valorhonorario+$total_valorhonorario13)/$total_precovenda)-1)*100;
  536.          $pdf->Cell(12,4,number_format($total_percentuallucro_honorario, 2, ',','.')."%",1,0,"C");
  537.          
  538.          if($edtTipoRelatorio=="modelo2" || $edtTipoRelatorio=="modelo4"){
  539.             $total_percentuallucro_faturado = (($total_valorfaturado/$total_precovenda)-1)*100;
  540.             $total_percentuallucro_recebido = (($total_valorrecebido/$total_precovenda)-1)*100;
  541.            
  542.             $pdf->Cell(12,4,number_format($total_valorfaturado, 2, ',','.'),1,0,"C");
  543.             $pdf->Cell(12,4,number_format($total_percentuallucro_faturado, 2, ',','.')."%",1,0,"C");
  544.            
  545.             $pdf->Cell(12,4,number_format($total_valorrecebido, 2, ',','.'),1,0,"C");
  546.             $pdf->Cell(12,4,number_format($total_percentuallucro_recebido, 2, ',','.')."%",1,0,"C");
  547.          }
  548.          $pdf->Ln();
  549.                
  550.          
  551.          //********** PDF - Gera o arquivo PDF **********
  552.          $BASE_DIR = str_replace((substr( $_SERVER['SCRIPT_NAME'], strpos($_SERVER['SCRIPT_NAME'], DIRECTORY_SEPARATOR, 2) , strlen($_SERVER['SCRIPT_NAME']) )),"", $_SERVER['SCRIPT_FILENAME']);
  553.          $datahoraarquivo = date("YmdHis");
  554.          $NomeArquivoPDF = "tmp/custos_$datahoraarquivo.pdf";
  555.          $pdf->Output(BASE_DIR . DS . $NomeArquivoPDF,"F"); // Gera o PDF
  556.  
  557.          $arq1="download.php?arq=".basename($NomeArquivoPDF)."&prog=download";
  558.          $arq2="$NomeArquivoPDF";      
  559.          $arq1 ="download.php?arq=".basename($NomeArquivoPDF)."&prog=download";
  560.          $arq2 ="$NomeArquivoPDF#view=fit";
  561.          $css  = "class='ui-button ui-state-default ui-corner-all'";
  562.          $css  ="";
  563.          $aux .= "<p class='ui-widget'>Clique no link abaixo para efetuar o download do arquivo texto: <br />";
  564.          $aux .= "  Arquivo TXT Download: <a href='download.php?arq=".basename($NomeArquivoTXT)."&prog=download'>".basename($NomeArquivoTXT)."</a></p>";
  565.          $aux .= "<iframe src='$arq2' $css title=''>".basename($NomeArquivoPDF)."</iframe>";
  566.          $aux .= "<script type='text/javascript' src='js/jquery-init.js' charset='utf-8'></script>";
  567.          $v['success'] = true;
  568.          $v['error']   = "";
  569.          $v['type']    = "pdf";
  570.          $v['orientation'] = "L";
  571.          $v['message'] = $aux;
  572.       } // fim if
  573.      
  574.       else{
  575.           $aux = " Não existem registros com os filtros informados ou ocorreu algum erro na geração do relatório!";
  576.           $v['success'] = false;
  577.           $v['error']   = $aux;
  578.           $v['type']    = "text";
  579.           $v['message'] = "";
  580.       }
  581.      
  582.       /*** Conecta com o banco MySQL ***/
  583.       $mySQL->desconectarMySQL();
  584.  
  585.       /*** Imprime o resultado na tela ***/
  586.       echo json_encode($v);
  587.  
  588.       /*** Destroi o objeto MySQL */
  589.       unset($mySQL);  
  590.      
  591.       exit;
  592. } // fim RelatorioUsuario
  593.  
  594. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement