<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — TCPDF Module - Override Any Existing FA Reports]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=9018&amp;type=atom" />
	<updated>2022-03-21T05:47:39Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=9018</id>
		<entry>
			<title type="html"><![CDATA[Re: TCPDF Module - Override Any Existing FA Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=40756#p40756" />
			<content type="html"><![CDATA[<p>I will give a try</p>]]></content>
			<author>
				<name><![CDATA[boxygen]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20175</uri>
			</author>
			<updated>2022-03-21T05:47:39Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=40756#p40756</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: TCPDF Module - Override Any Existing FA Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=38940#p38940" />
			<content type="html"><![CDATA[<p>I will soon update this module with some reports like Invoice Receipt, which will give you clear idea on how to use it. If you urgently need any help PM me.</p>]]></content>
			<author>
				<name><![CDATA[dearmosin]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44699</uri>
			</author>
			<updated>2021-01-15T22:29:43Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=38940#p38940</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: TCPDF Module - Override Any Existing FA Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=38831#p38831" />
			<content type="html"><![CDATA[<p>hi dearmosin<br />can you guide me how to implement this? i dont understand the hooks thing in the first step to register module</p>]]></content>
			<author>
				<name><![CDATA[sewkar]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18980</uri>
			</author>
			<updated>2020-12-27T02:18:48Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=38831#p38831</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: TCPDF Module - Override Any Existing FA Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=38410#p38410" />
			<content type="html"><![CDATA[<p>@apmuthu: Sorry for not pushing, README.md to repo. I will update it today with all details.</p><p>@joe: Thanks for your reply, you are correct new version is quite heavy and our current version is absolutely working fine and we can include existing <strong>TCPDF Class</strong> in this module.</p><p>FA TCPDF library used&nbsp; 4.0.027 (2008-09-19)<br />For example: QR Code (2D barcode) support was added from version 4.9.000</p><p>Since version 4.0.027 till 6.3.2 <a href="https://github.com/tecnickcom/TCPDF/blob/main/CHANGELOG.TXT">CHANGE LOG</a></p><p>I know we can create report placing repXXX.php in <strong>company/0/reporting</strong> but was stuck in some places eg: loading images, loading new ttf fonts etc. So came up with this.</p><p><strong>Purpose of this module, is to overwrite existing FA reports with own template report - We can use existing older / newer or any other PDF library.</strong></p><p>We have just pasted TCPDF library into module folder, and include to use it&#039;s class for creating pdf files. If we want to use some other library we can do that as well.&nbsp; </p><p><strong>Why this approach?</strong><br />Changing core system file is not good idea, it may cause problem in updating software and troubleshoot problem.</p><h5>Only those who need huge customization can you it</h5><p>So here is what we are doing - First registering our module to enable hook.</p><div class="codebox"><pre><code>define (&#039;IMPULSE_TCPDF&#039;, 251&lt;&lt;8);

class hooks_TCPDF extends hooks {

    function __construct() {
        $this-&gt;module_name = &#039;TCPDF&#039;;
    }
    
    function install_access() {
        $security_sections[IMPULSE_TCPDF] =  _(&#039;TCPDF&#039;);
        $security_areas[&#039;PULSE_PDF&#039;] = array(IMPULSE_TCPDF|1, _(&#039;Allow PDF Printing&#039;));
        return array($security_areas, $security_sections);
    }
    
    function activate_extension($company, $check_only=true) {
        global $db_connections;
        
        $updates = array( &#039;update.sql&#039; =&gt; array(&#039;TCPDF&#039;));
 
        return $this-&gt;update_databases($company, $updates, $check_only);
    }
    
    function deactivate_extension($company, $check_only=true) {
        global $db_connections;

        $updates = array(&#039;remove.sql&#039; =&gt; array(&#039;TCPDF&#039;));

        return $this-&gt;update_databases($company, $updates, $check_only);
    }
    
}</code></pre></div><p>Now when we activate this module and provide access, while printing reports <strong>reporting/reports_main.php</strong> will scan through each active module searching for <strong>module_folder/reporting/reports_custom.php</strong> to add report and register controls.</p><p>Suppose we want to print rep107 with our template invoice we created with TCPDF or other library. In <strong>module_folder/reporting/reports_custom.php</strong></p><div class="codebox"><pre><code>global $reports;

// Override Reports Here
// You Can Find This In reporting/reports_main.php

$reports-&gt;addReport(RC_CUSTOMER, 107, _(&#039;Print &amp;Invoices&#039;),
    array(    _(&#039;From&#039;) =&gt; &#039;INVOICE&#039;,
            _(&#039;To&#039;) =&gt; &#039;INVOICE&#039;,
            _(&#039;Currency Filter&#039;) =&gt; &#039;CURRENCY&#039;,
            _(&#039;email Customers&#039;) =&gt; &#039;YES_NO&#039;,
            _(&#039;Payment Link&#039;) =&gt; &#039;PAYMENT_LINK&#039;,
            _(&#039;Comments&#039;) =&gt; &#039;TEXTBOX&#039;,
            _(&#039;Customer&#039;) =&gt; &#039;CUSTOMERS_NO_FILTER&#039;,
            _(&#039;Orientation&#039;) =&gt; &#039;ORIENTATION&#039;,
            _(&#039;Copy&#039;) =&gt; &#039;INV_COPY&#039;
));

// Example To Register Controls

function invoice_copy($name, $type) {
    if($type == &#039;INV_COPY&#039;)
        return &quot;&lt;select name = &#039;&quot;.$name.&quot;&#039;&gt;&lt;option value=&#039;0&#039;&gt;&quot;._(&#039;Original Copy For Recipient&#039;).&quot;&lt;/option&gt;&lt;option value=&#039;1&#039;&gt;&quot;._(&#039;Duplicate Copy For Transporter &#039;).&quot;&lt;/option&gt;&lt;option value=&#039;2&#039;&gt;&quot;._(&#039;Triplicate Copy For Supplier&#039;).&quot;&lt;/option&gt;&lt;/select&gt;&quot;;
}

$reports-&gt;register_controls(&#039;invoice_copy&#039;);</code></pre></div><p>We have changed $reports object for our module. With new field <strong>Copy</strong> in Customer -- Print Invoices, same way we can add field or remove field.</p><p><span style="color: #FF0000"><strong>Note: Only Those Report Added here Will Be Replace, Other Reports Does Not Have Any Effect.</strong></span></p><p>Now we need last file <strong>rep107.php</strong> in <strong>module_folder/reporting</strong> this is invoice template file</p><div class="codebox"><pre><code>&lt;?php
        // $page_security can be found in respective file in reporting folder
        $page_security = &#039;SA_SALESTRANSVIEW&#039;;
        ob_start();

        $path_to_root=&quot;..&quot;;

        include_once($path_to_root . &quot;/includes/session.inc&quot;);
        include_once($path_to_root . &quot;/includes/date_functions.inc&quot;);
        include_once($path_to_root . &quot;/includes/data_checks.inc&quot;);
        include_once($path_to_root . &quot;/sales/includes/sales_db.inc&quot;);
        include_once($path_to_root . &quot;/gl/includes/db/gl_db_currencies.inc&quot;);
        include_once($path_to_root . &quot;/inventory/includes/db/items_db.inc&quot;);
       // here you can write your own fuctions
        include_once($path_to_root.&quot;/modules/TCPDF/reporting/includes/db/rep107_db.php&quot;);
       // this can be any PDF Libarary
        require_once($path_to_root . &quot;/modules/TCPDF/tcpdf.php&quot;);

// ---------------------------------------------------------
        $from = $_POST[&#039;PARAM_0&#039;];
        $to = $_POST[&#039;PARAM_1&#039;];
        $invoice_currency = $_POST[&#039;PARAM_2&#039;];
        $email = $_POST[&#039;PARAM_3&#039;];
        $pay_service = $_POST[&#039;PARAM_4&#039;];
        $comments = $_POST[&#039;PARAM_5&#039;];
        $customer = $_POST[&#039;PARAM_6&#039;];
        $i = $_POST[&#039;PARAM_7&#039;];

        if (!$from || !$to) return;

        $dec = user_price_dec();

        $fno = explode(&quot;-&quot;, $from);
        $tno = explode(&quot;-&quot;, $to);
        $from = min($fno[0], $tno[0]);
        $to = max($fno[0], $tno[0]);
        $range = get_invoice_range($from, $to);
        
        // Demo Invoice Starts
        // In this example HTML is used to create PDF file.
        $html = &#039;
        &lt;style&gt;
        table, tr, td {
        padding: 15px;
        }
        &lt;/style&gt;
        &lt;table style=&quot;background-color: #222222; color: #fff&quot;&gt;
        &lt;tbody&gt;
        &lt;tr&gt;
        &lt;td&gt;&lt;h1&gt;INVOICE&lt;strong&gt; #21234&lt;/strong&gt;&lt;/h1&gt;&lt;/td&gt;
        &lt;td align=&quot;right&quot;&gt;
        123 street, ABC Store&lt;br/&gt;
        Country, State, 00000
        &lt;br/&gt;
        &lt;strong&gt;+00-1234567890&lt;/strong&gt; | &lt;strong&gt;abc@xyz&lt;/strong&gt;
        &lt;/td&gt;
        &lt;/tr&gt;
        &lt;/tbody&gt;
        &lt;/table&gt;
        &#039;;
        $html .= &#039;
        &lt;table&gt;
        &lt;tbody&gt;
        &lt;tr&gt;
        &lt;td&gt;Invoice to&lt;br/&gt;
        &lt;strong&gt;Demo Customer&lt;/strong&gt;
        &lt;br/&gt;
        123 street, ABC Store&lt;br/&gt;
        Country, State, 00000
        &lt;/td&gt;
        &lt;td align=&quot;right&quot;&gt;
        &lt;strong&gt;Total Due: $ 23,442.00/strong&gt;&lt;br/&gt;
        Tax ID: ABCDEFGHIJ12345&lt;br/&gt;
        Invoice Date: &#039;.date(&#039;d-m-Y&#039;).&#039;
        &lt;/td&gt;
        &lt;/tr&gt;
        &lt;/tbody&gt;
        &lt;/table&gt;
        &#039;;
        $html .= &#039;
        &lt;table&gt;
        &lt;thead&gt;
        &lt;tr style=&quot;font-weight:bold;&quot;&gt;
        &lt;th&gt;Item name&lt;/th&gt;
        &lt;th&gt;Price&lt;/th&gt;
        &lt;th&gt;Quantity&lt;/th&gt;
        &lt;th&gt;Total&lt;/th&gt;
        &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;&#039;;
        $html .= &#039;
        &lt;tr&gt;
        &lt;td style=&quot;border-bottom: 1px solid #222&quot;&gt;Demo Item&lt;/td&gt;
        &lt;td style=&quot;border-bottom: 1px solid #222&quot;&gt;$23,422.00&lt;/td&gt;
        &lt;td style=&quot;border-bottom: 1px solid #222&quot;&gt;1&lt;/td&gt;
        &lt;td style=&quot;border-bottom: 1px solid #222&quot;&gt;$23,422.00&lt;/td&gt;
        &lt;/tr&gt;
        &#039;;
        $html .=&#039;
        &lt;tr align=&quot;right&quot;&gt;
        &lt;td colspan=&quot;4&quot;&gt;&lt;strong&gt;Grand total: $23,422.00&lt;/strong&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
        &lt;td colspan=&quot;4&quot;&gt;
        &lt;h2&gt;Thank you for your business.&lt;/h2&gt;&lt;br/&gt;
        &lt;strong&gt;Terms and conditions:&lt;br/&gt;&lt;/strong&gt;
        It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English.
        &lt;/td&gt;
        &lt;/tr&gt;
        &lt;/tbody&gt;
        &lt;/table&gt;&#039;;
        // create new PDF document
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, &#039;UTF-8&#039;, false);
        // set default monospaced font
        // set margins
        $pdf-&gt;SetMargins(-1, 0, -1);
        // remove default header/footer
        $pdf-&gt;setPrintHeader(false);
        $pdf-&gt;setPrintFooter(false);
        // set auto page breaks
        $pdf-&gt;SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        // set image scale factor
        $pdf-&gt;setImageScale(PDF_IMAGE_SCALE_RATIO);
        // Set font
        $pdf-&gt;SetFont(&#039;helvetica&#039;, &#039;&#039;, 10);
        $pdf-&gt;AddPage();
        // Print text using writeHTMLCell()
        $pdf-&gt;writeHTMLCell(0, 0, &#039;&#039;, &#039;&#039;, $html, 0, 0, 0, true, &#039;&#039;, true);
        // Demo Invoice Ends

        ob_end_clean();

        $filename = &#039;Invoice&#039;;


        $root_dir =  $_SERVER[&#039;DOCUMENT_ROOT&#039;].substr(company_path(),3). &#039;/pdf_files&#039;;
        $dir = company_path(). &#039;/pdf_files&#039;;

        $fname = $root_dir.&#039;/&#039;.$filename.&#039;.pdf&#039;;
        $pdf-&gt;Output($fname, &#039;F&#039;);


        if ($d = @opendir($dir)) {
        while (($file = readdir($d)) !== false) {
            if (!is_file($dir.&#039;/&#039;.$file) || $file == &#039;index.php&#039;) continue;
            $ftime = filemtime($dir.&#039;/&#039;.$file);
            if (time()-$ftime &gt; 180){
                unlink($dir.&#039;/&#039;.$file);
            }
        }
        closedir($d);
        }

        global $Ajax;
        $Ajax-&gt;popup($dir.&#039;/&#039;.$filename.&#039;.pdf&#039;); 
        exit;</code></pre></div><p>In the above example we included</p><div class="codebox"><pre><code>       // here you can write your own fuctions for this template.
        include_once($path_to_root.&quot;/modules/TCPDF/reporting/includes/db/rep107_db.php&quot;);
       // this can be any PDF Libarary you are trying to print invoice with
        require_once($path_to_root . &quot;/modules/TCPDF/tcpdf.php&quot;);</code></pre></div><p>That&#039;s it now whenever user try to print invoice this report will print.</p><p>Here is sample Invoice Format I Created With TCPDF / dompdf in FrontAccountingERP</p><p><a href="https://mpulse.in/public/TAX_INVOICE_TEMPLATE.pdf">Invoice Template 1 - Rep107</a><br /><a href="https://mpulse.in/public/TAX_INVOICE_TEMPLATE_1.pdf">Invoice Template 2&nbsp; - Rep107</a><br /><a href="https://mpulse.in/public/TAX_INVOICE_TEMPLATE_2.pdf">Invoice Template 3 - Rep107</a><br /><a href="https://mpulse.in/public/PAYMENT_RECEIPT.pdf">Receipt Template 1 - Rep112</a></p><p>Your suggestion, thoughts and comment are appreciated. </p><p>Regards</p>]]></content>
			<author>
				<name><![CDATA[dearmosin]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44699</uri>
			</author>
			<updated>2020-09-28T18:26:01Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=38410#p38410</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: TCPDF Module - Override Any Existing FA Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=38408#p38408" />
			<content type="html"><![CDATA[<p>I don&#039;t understand what is achieved with this version of TCPDF. This version is more than half a GB bigger than our current version, that is working perfectly. </p><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2020-09-28T06:05:14Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=38408#p38408</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: TCPDF Module - Override Any Existing FA Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=38407#p38407" />
			<content type="html"><![CDATA[<p>Provide screenshot of sample invoice.</p><p>TCPDF version used here is v6.3.2 - circa a year ago vintage.</p><p>What was sought to be achieved using the new TCPDF version?</p><p>Provide info on README.md as to which folder should be overwritten and what checks have been made to integrate with existing FrontAccounting Box report constructs.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2020-09-28T04:54:37Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=38407#p38407</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[TCPDF Module - Override Any Existing FA Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=38406#p38406" />
			<content type="html"><![CDATA[<p>I have made this module with TCPDF to over ride existing FA Reports with your own fancy report. Though you need basic PHP knowledge to make one. </p><p><strong>No pre made reports has been provided with this module.</strong></p><p>I have included Demo Rep107 as an example, get an idea from it.</p><p>See TCPDF examples here <a href="https://tcpdf.org/examples/">https://tcpdf.org/examples/</a></p><p>TCPDF Module Github <a href="https://github.com/impulse-solutions/FA-TCPDF">https://github.com/impulse-solutions/FA-TCPDF</a></p><p>Regards</p>]]></content>
			<author>
				<name><![CDATA[dearmosin]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44699</uri>
			</author>
			<updated>2020-09-27T22:10:19Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=38406#p38406</id>
		</entry>
</feed>
