{"id":1012,"date":"2022-05-19T12:53:47","date_gmt":"2022-05-19T05:53:47","guid":{"rendered":"https:\/\/www.bagi2info.com\/?p=1012"},"modified":"2023-07-12T14:30:11","modified_gmt":"2023-07-12T07:30:11","slug":"php-membuat-report-dengan-library-phpreport","status":"publish","type":"post","link":"https:\/\/www.bagi2info.com\/en\/php-create-reports-with-the-phpreport-library\/","title":{"rendered":"PHP: Create reports with the PHPReport library"},"content":{"rendered":"\r\n<figure class=\"wp-block-image is-style-default\"><a href=\"https:\/\/www.bagi2info.com\/wp-content\/uploads\/2017\/09\/Template2.png\"><img src =\"https:\/\/www.bagi2info.com\/wp-content\/uploads\/2017\/09\/Template2-1024x546.png\" alt=\"\" class=\"wp-image-1018\"\/><\/a><\/figure >\r\n\r\n\r\n\r\n<figure class=\"wp-block-image is-style-default\"><a href=\"https:\/\/www.bagi2info.com\/wp-content\/uploads\/2017\/09\/Template.png\"><img src =\"https:\/\/www.bagi2info.com\/wp-content\/uploads\/2017\/09\/Template-1024x481.png\" alt=\"\" class=\"wp-image-1016\"\/><\/a><\/figure >\r\n\r\n\r\n\r\n<p>Long story short, I was looking for a framework for reporting on the web, with export to excel and pdf functions, after trying here and there, frameworks like <strong>Kooreport<\/strong>, with quite tempting functions, I finally found <strong> >PHPReport<\/strong>.<\/p>\r\n\r\n\r\n\r\n<p><strong>PHPReport<\/strong> has a feature for exporting to excel and pdf, and can also generate printouts based on templates from excel, after assessment, this feature is very useful for invoice printouts which can be modified as needed.<\/p>\r\n\r\n\r\n\r\n<p>In that case, just step using <strong>PHPReport<\/strong>:<\/p>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li>Please download the library to&nbsp;<a href=\"https:\/\/github.com\/vernes\/PHPReport\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/vernes\/PHPReport<\/a <\/li>\r\n\r\n\r\n\r\n<li>Run composer to download&nbsp;<strong>PHPExcel<\/strong> required library <strong>PHPReport<\/strong><\/li>\r\n\r\n\r\n\r\n<li>Download also <strong>mpdf<\/strong> version 6.0 at the link <a href=\"http:\/\/www.mpdf1.com\/mpdf\/index.php\" target=\"_blank\" rel=\"noopener\">http: \/\/www.mpdf1.com\/mpdf\/index.php<\/a> for the export to pdf function<\/li>\r\n\r\n\r\n\r\n<li>Put mpdf to vendor folder and rename folder to <strong>mpdf60<\/strong><\/li>\r\n\r\n\r\n\r\n<li>Create a sample testing file with the following name <strong>print-pdf-sample.php<\/strong><\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<pre title=\"print-pdf-sample.php\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php line-numbers\">&lt;?php\r\n\r\ninclude 'PHPReport.php';\r\n\r\n$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;\r\n\/\/$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;\r\n\/\/$rendererLibrary = 'tcPDF5.9';\r\n$rendererLibrary = 'mpdf60';\r\n\/\/$rendererLibrary = 'domPDF0.6.0beta3';\r\n\r\n$rendererLibraryPath = dirname(__FILE__).'\/vendor\/' . $rendererLibrary;\r\nPHPExcel_Settings::setPdfRenderer($rendererName,$rendererLibraryPath);\r\n\r\n\/\/which template to use\r\nif(isset($_GET['template']))\r\n$template=$_GET['template'];\r\nelse\r\n$template='invoice. xls';\r\n\r\n\/\/set absolute path to directory with template files\r\n$templateDir='examples\\\\templates\\\\';\r\n\r\n\/\/we get some products, e.g. from database\r\n$products=array(\r\narray('description'=&gt;'Example product','qty'=&gt;2,'price'=&gt;4.5,'total'=&gt;9),\r\narray('description'=&gt;'Another product','qty'=&gt;1,'price'=&gt;13.9,'total'=&gt;13.9),\r\narray('description'=&gt;'Super product!','qty'=&gt;3,'price'=&gt;1.5,'total'=&gt;4.5),\r\narray('description'=&gt;'Yet another great product','qty'=&gt;2,'price'=&gt;10.8,'total'=&gt;21.6),\r\narray('description'=&gt;'Awesome','qty'=&gt;1,'price'=&gt;19.9,'total'=&gt;19.9)\r\n);\r\n\r\n\/\/set config for reports\r\n$config=array(\r\n'template'=>$template,\r\n'templateDir'=>$templateDir\r\n);\r\n\r\n$R=new PHPReport($config);\r\n$R->load(array(\r\narray(\r\n'id'=>'inv',\r\n'data'=&gt;array('date'=&gt;date('Y-m-d'), 'number'=&gt;312,\r\n'customerid'=&gt;12,'orderid'=&gt;517,\r\n'company'=&gt;'Example Inc.',\r\n'address'=&gt;'Some addresses',\r\n'city'=&gt;'Some City, 1122',\r\n'phone'=&gt;'+111222333'),\r\n'format'=&gt;array('date'=&gt;array('datetime'=&gt;'d\/m\/Y'))\r\n),\r\narray(\r\n'id'=&gt;'prod',\r\n'repeat'=&gt;true,\r\n'data'=>$products,\r\n'minRows'=&gt;0,\r\n'format'=&gt;array(\r\n'price'=&gt;array('number'=&gt;array('prefix'=&gt;'$','decimals'=&gt;2)),\r\n'total'=&gt;array('number'=&gt;array('prefix'=&gt;'$','decimals'=&gt;2))\r\n)\r\n),\r\narray(\r\n'id'=&gt;'total',\r\n'data'=&gt;array('price'=&gt;68.9),\r\n'format'=&gt;array(\r\n'price'=&gt;array('number'=&gt;array('prefix'=&gt;'$','decimals'=&gt;2))\r\n)\r\n)\r\n)\r\n         );\r\n\r\necho $R-&gt;render('pdf');\r\nexit();<\/code><\/pre>\r\n\r\n\r\n\r\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\r\n\r\n\r\n\r\n<p>Here <a href=\"https:\/\/www.bagi2info.com\/sample\/PHPReport.zip\"><span style=\"color: #0000ff;\"><strong>sample file<\/strong><\/span> <\/a> which can be put into practice right away, but minus the <strong>phpexcel <\/strong>and <strong>mpdf60<\/strong> libraries.<\/p>\r\n\r\n\r\n\r\n<p>Because it&#8217;s too big to include in the sample file. Please download and make sure the downloaded results are extracted according to the folder in the vendor.<\/p>\r\n\r\n\r\n\r\n<p>Good luck<\/p>\r\n\r\n\r\n\r\n<p><\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Long story short, I was looking for a framework for reporting on the web, with export to excel and pdf functions, after trying here and there, frameworks like Kooreport, with quite tempting functions, I&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1018,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,14],"tags":[62],"class_list":["post-1012","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-komputer","category-recommended","tag-php"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/posts\/1012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/comments?post=1012"}],"version-history":[{"count":6,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/posts\/1012\/revisions"}],"predecessor-version":[{"id":4472,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/posts\/1012\/revisions\/4472"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/media\/1018"}],"wp:attachment":[{"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/media?parent=1012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/categories?post=1012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/tags?post=1012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}