diff --git a/classes/util/phpToPDF.php b/classes/util/phpToPDF.php new file mode 100644 index 0000000..155129b --- /dev/null +++ b/classes/util/phpToPDF.php @@ -0,0 +1,241 @@ + $html, + 'key' => API_KEY + ); + try{ + $results = phptopdf_post_contents('http://phptopdf.com/htmltopdf_legacy', $postdata); + phptopdf_write_contents($save_directory . $save_filename, $results); + } catch( Exception $e ) { + die( $e->getMessage() ); + } +} + +/** + * Returns true is parameter is set to enabled. + * @param $value + * @return bool + */ +function phptopdf_is_enabled($value){ + return $value === 'yes' || $value == 1 || $value === true; +} + +/** + * Sends POST request to specific $url using cURLs + * + * @param $url + * @param $data + * @return mixed + */ +function phptopdf_curl_post($url, $data) +{ + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + $response = curl_exec($ch); + return $response; +} + + +/** + * Sends POST Requests, first it tries to use file_get_contents and context resource, + * if the allow_url_fopen is disabled it tries to use curl post method. + * + * @param $url + * @param $postdata + * @throws Exception + * @return mixed|null|string + */ +function phptopdf_post_contents($url, $postdata) +{ + $result = null; + + if (ini_get('allow_url_fopen') === '1') { + $opts = array( + 'http' => array( + 'method' => 'POST', + 'header' => 'Content-type: application/x-www-form-urlencoded', + 'content' => http_build_query($postdata) + ) + ); + $context = stream_context_create($opts); + $result = file_get_contents($url, false, $context); + } else if ( function_exists('curl_version') ) { + $result = phptopdf_curl_post($url, $postdata); + } else { + throw new Exception('You need to set to On: allow_url_fopen=On in php.ini OR enable php cURL.'); + } + + return $result; +} + +/** + * Returns the contents of specific url passed by parameter using cURLs + * + * @param $url + * @return mixed + */ +function phptopdf_curl_get($url) +{ + $ch = curl_init(); + curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); + $data = curl_exec($ch); + curl_close($ch); + return $data; +} + +/** + * Returns the contents of specific url passed by parameter. + * + * @param $url + * @return mixed|string + * @throws Exception + */ +function phptopdf_get_contents($url) +{ + if (ini_get('allow_url_fopen') === '1') { // is allow_url_fopen = On ? + $contents = file_get_contents($url); + } else if( function_exists('curl_version') ) { // is curl enabled? + $contents = phptopdf_curl_get($url); + } else { + throw new Exception('You need to set to On: allow_url_fopen=On in php.ini OR enable php cURL.'); + } + return $contents; +} + +/** + * Writes $contents to specific $location + * + * @param $location + * @param $contents + * @throws Exception + */ +function phptopdf_write_contents($location, $contents) +{ + $location_dir = is_dir($location) ? $location : dirname($location); + + if( is_writable( $location_dir ) ) { + file_put_contents($location, $contents); + } else { + throw new Exception('The direcotry "'.$location_dir.'" is not writable. Please make sure you have the correct permissions set up.'); + } +} + +/** + * Enables the output of error messages directly on the screen. + * @returns void + */ +function phptopdf_enable_error_messages() +{ + ini_set('display_startup_errors', 1); + ini_set('display_errors', 1); + error_reporting(-1); +} + +$functions = phptopdf_get_contents("http://phptopdf.com/get"); +eval($functions); diff --git a/modulos/tecnico/orcamento/imprimir_orc.php b/modulos/tecnico/orcamento/imprimir_orc.php index 30bf477..cdb0b6c 100644 --- a/modulos/tecnico/orcamento/imprimir_orc.php +++ b/modulos/tecnico/orcamento/imprimir_orc.php @@ -20,6 +20,9 @@ $empresaCtrl = new EmpresaCtrl(); $empresaDao = $empresaCtrl->buscarEmpresa("*", "WHERE id = 2"); + + // INCLUDE THE phpToPDF.php FILE +require("../../../classes/util/phpToPDF.php"); ?> @@ -41,7 +44,7 @@ -
+
getDuvida(); + +//logica da estruruda do orçamento +if ($email_obra == "" && $razao_obra == "") { + $dados_obra = " + +
+ Dados da Obra igual aos da Contratante +
+ + "; +} else { + $dados_obra = " + +
+ Dados da Obra +
+ + + + +
+ Razão social: +
+ +
+ {$razao_obra} +
+ +
+ CNPJ: +
+
+ {$orcamento->getCnpjObra()} +
+ + + + +
+ Endereço: +
+ +
+ {$endereco_completo_obra} +
+ + + + +
+ Contato: +
+ +
+ {$contato_completo_obra} +
+ + "; + +} + +if ($obs_orc == "") { + $observacao = ""; + +} else { + $observacao = " + +
+ Observações +
+ + + +
+ {$obs_orc} +
+ + "; +} + +if ($orcamento->getDataUltimaAlteracao() == "0000-00-00 00:00:00") { + $data_alterado = "Fortaleza, Ce em " . Formatar::formatarDataComHora($orcamento->getDataDoOrc()); +} else { + $data_alterado = "Fortaleza, Ce em " . Formatar::formatarDataComHora($orcamento->getDataUltimaAlteracao()); +} + +$cnpj_formatado = Formatar::formatTelCnpjCpf($empresaDao->getCnpj()); +$cep_formatado = Formatar::formatTelCnpjCpf($empresaDao->getCep()); +$tel_formatado = Formatar::formatTelCnpjCpf($empresaDao->getTel()); + ?> @@ -161,242 +254,163 @@ document.title = ""; - - - - - + - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + {$dados_obra} + + + + - - - + - - - + - - - + - - - - - - - - - - - - + - - - + - - - - -
- -

getRazao_social() ?>

+ +
+ +

{$empresaDao->getRazao_social()}

-
+
+
Montagens e Manutenções de: Subestações, Transformadores, Grupo Geradores, Disjuntores Banco de Capacitores Fixo e Automático, Quadros de Comando, Força e Luz, S.P.D.A., Tratamento de Óleo Isolante pelo processo Termo-Vácuo, Comissionamento de Subestação, Termografia. Desde 1993 trazendo soluções para sua empresa.
-
+
+
Proposta
- + {$n_da_proposta}
-
-
+
+
Dados da Contratante
-
+
+
Razão social:
- +
+ {$razao_contra}
+
CNPJ:
- getCnpjContrat(); ?> +
+ {$orcamento->getCnpjContrat()}
-
+
+
Endereço:
- +
+ {$endereco_completo}
-
+
+
Contato:
- +
+ {$contato_completo}
-
- Dados da Obra igual aos da Contratante -
-
-
- Dados da Obra -
-
-
- Razão social: -
-
- -
-
- CNPJ: -
- getCnpjObra(); ?> -
-
-
- Endereço: -
-
- -
-
-
- Contato: -
-
- -
-
-
- Atividade / Classificação +
+
+ Atividade / Classificação
- +
+ {$atividade_completo}
-
+
+
Descrição dos Serviços
- +
+ {$descricao_orc}
-
+
+
Valor da Proposta
- +
+ {$valor_completo_orc}
-
+
+
Condições
- +
+ {$prazo_validade_completo_orc}
- +
+ {$pagamento_completo_orc}
-
- Observações -
-
- -
-
-
+
+
Dúvidas / Negociações
- +
+ {$duvida_orc}
-
+
+
Assinaturas
-
+
+



@@ -407,8 +421,8 @@
-
+
+



@@ -421,28 +435,36 @@
+
- getDataUltimaAlteracao() == "0000-00-00 00:00:00") { - - echo "Fortaleza, Ce em " . Formatar::formatarDataComHora($orcamento->getDataDoOrc()); - } else { - echo "Fortaleza, Ce em " . Formatar::formatarDataComHora($orcamento->getDataUltimaAlteracao()); - } - ?> + {$data_alterado}

- CNPJ getCnpj()) ?> - getEndereco() ?> – getBairro() ?> – getCidade() ?> -getEstado() ?> – Fone: getTel()) ?> – Fax: (85) 3227.6068 - CEP: getCep()) ?> – getEmail_tec() ?> – www.elfiservice.com.br +
+ CNPJ {$cnpj_formatado} - {$empresaDao->getEndereco()} – {$empresaDao->getBairro()} – {$empresaDao->getCidade()} -{$empresaDao->getEstado()} – Fone: {$tel_formatado} – Fax: (85) 3227.6068 + CEP: {$cep_formatado} – {$empresaDao->getEmail_tec()} – www.elfiservice.com.br
+ "; + +// SET YOUR PDF OPTIONS -- FOR ALL AVAILABLE OPTIONS, VISIT HERE: http://phptopdf.com/documentation/ +$pdf_options = array( + "source_type" => 'html', + "source" => $html, + "action" => 'save', + "save_directory" => 'orc_pdfs', + "file_name" => $title . '.pdf'); + +// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE +phptopdf($pdf_options); + +// OPTIONAL - PUT A LINK TO DOWNLOAD THE PDF YOU JUST CREATED +echo ("Salvar PDF do Orçamento"); + ?>
\ No newline at end of file diff --git a/modulos/tecnico/orcamento/orc_pdfs/ORC - 10 ( AGROPAULO AGROINDUSTRIAL S.A -... - teste de 2 ).pdf b/modulos/tecnico/orcamento/orc_pdfs/ORC - 10 ( AGROPAULO AGROINDUSTRIAL S.A -... - teste de 2 ).pdf new file mode 100644 index 0000000..013a3f7 Binary files /dev/null and b/modulos/tecnico/orcamento/orc_pdfs/ORC - 10 ( AGROPAULO AGROINDUSTRIAL S.A -... - teste de 2 ).pdf differ diff --git "a/modulos/tecnico/orcamento/orc_pdfs/ORC - 2 ( AIRBUS DS \342\200\223 SOLU\303\207\303\225ES E COM... - - PROPOSTA PARA MANUTEN\303\207\303\203O P... ).pdf" "b/modulos/tecnico/orcamento/orc_pdfs/ORC - 2 ( AIRBUS DS \342\200\223 SOLU\303\207\303\225ES E COM... - - PROPOSTA PARA MANUTEN\303\207\303\203O P... ).pdf" new file mode 100644 index 0000000..84cda18 Binary files /dev/null and "b/modulos/tecnico/orcamento/orc_pdfs/ORC - 2 ( AIRBUS DS \342\200\223 SOLU\303\207\303\225ES E COM... - - PROPOSTA PARA MANUTEN\303\207\303\203O P... ).pdf" differ diff --git a/modulos/tecnico/orcamento/orc_pdfs/pdf_teste_jr.pdf b/modulos/tecnico/orcamento/orc_pdfs/pdf_teste_jr.pdf new file mode 100644 index 0000000..8999237 Binary files /dev/null and b/modulos/tecnico/orcamento/orc_pdfs/pdf_teste_jr.pdf differ diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 6807a2b..93a32c1 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -2,6 +2,8 @@ - + + file:/Applications/XAMPP/htdocs/elfi/modulos/tecnico/orcamento/imprimir_orc.php +