PHP Generator Feature Demo
  • Themes
    • Default
    • Default compact
    • Cerulean
    • Cerulean compact
    • Cosmo
    • Cyborg
    • Darkly
    • Darkly compact
    • Facebook
    • Flatly
    • Journal
    • Lumen
    • Paper
    • Readable
    • Sandstone
    • Simplex
    • Slate
    • Slate compact
    • Spacelab
    • Superhero
    • Superhero compact
    • United
    • United compact
    • Yeti
    • Yeti compact
  • English
    • German
    • Brazilian
    • Czech
    • Danish
    • Spanish
    • Finnish
    • French
    • Hungarian
    • Italian
    • Dutch
    • Polish
    • Russian
    • Swedish
    • Slovak
    • Slovenian
    • Serbian
    • Turkish
    • Arabic
  • Learn more
    • PHP Generator Feature Demo
    • About this demo
    • Download project file for this demo
    • Check out other PHP Generator demos
    • NBA Database Demo
    • Security Demo
    • MySQL Schema Browser Demo
    • Learn more about our products
    • Try PHP Generator for free
    • SQL Maestro Group website
    • Follow us
    • Facebook
    • Twitter
    • YouTube
  • Recently added/updated
    • Grid Toolbar
    • Tabbed Forms
    • Stepped Area Chart
    • Candlestick Chart
    • Histogram Chart
    • Bubble Chart
    • Timeline Chart
    • Gantt Chart
    • Scatter Chart
    • Tree Map Chart
    • Export options
    • Invoice generation
    • Inline Button
    • HTML Wysiwyg
    • Watermarks
  • Data Grid
    • Table View
    • Card View
    • Autohiding Columns
    • Totals
    • Grid Header
    • Column Grouping
    • Record Comparison
    • Unicode Support
    • RSS
    • Custom Drawing
    • Custom Table Template
    • Custom Card Template
    • Custom Toolbar Template
    • Custom View Form
  • Grid Columns
    • Column Types
    • Text Truncating
    • Column Fixed Width
    • Formatting
    • Null Label
    • Hyperlinks
    • Html Display
    • Lookup Data View
    • Custom Rendering
  • Grid Options
    • Fixed Grid Width
    • Fixed Column Header
    • Bordered Table
    • Condensed Table
    • Line Numbers
    • Control Buttons Position
  • Data Sources
    • Table
    • View
    • Non-Updatable Query
    • Updatable Query
    • Updatable View
  • Master-Detail Views
    • Master/Detail Basics
    • Multiple Details
    • Nested Details
    • Card Mode Details
  • Data Input Forms
    • Separate Page
    • Modal Window
    • Inline Editing
    • Form Layouts
    • Tabbed Forms
    • Custom Separate Page
    • Custom Modal Dialog
    • Custom Inline Form
    • Wizard Form
    • Adding multiple records
    • Editors Overview
    • Validation
    • Client-side API
    • Dependent Lookups
    • On-the-Fly Adding
    • Quick Edit
    • Multi Edit
    • Custom Default Values
  • Editors
    • Text
    • Autocomplete
    • Text Area
    • HTML Wysiwyg
    • Spin & Range
    • Upload To Folder
    • Radio Group
    • Combobox
    • Dynamic Combobox
    • Cascading Combobox
    • Dynamic Cascading Combobox
    • Multiple Select
    • Checkbox Group
    • Common Properties
  • Data Filtering
    • Quick Filter
    • Filter Builder
    • Column Filter
    • Preliminary Filter
    • Selection Filters
    • Custom Filter - 1
    • Custom Filter - 2
  • Sorting
    • Sort By Click
    • Sort By Dialog
    • Default Sort Order
  • Partitioning
    • Range
    • List
    • Custom
  • Exporting & Printing
    • Grid
    • Single Record
    • Export Options
    • Custom Grid
    • Custom Single Record
    • User Defined Styles
  • Image Management
    • Image Galleries
    • Thumbnails
    • Linked Images
    • Multi Upload - 1
    • Multi Upload - 2
    • Watermarks
  • Charts
    • Pie Chart
    • Column Chart
    • Bar Chart
    • Line Chart
    • Area Chart
    • Geo Charts
    • Stepped Area
    • Candlestick
    • Histogram
    • Bubble
    • Timeline
    • Gantt
    • Scatter
    • Tree Map
    • Multiple Charts
    • Chart Placement
    • Customizing Charts
    • Dashboard
  • Many-to-Many Relations
    • Classic Junction Table
    • Handling Extra Columns
  • Fine-tuning & Tweaking
    • Custom Icons
    • Custom Theme
    • Custom Editor
    • Page Embedding
    • Ajax-based Validation
    • Color Themes
    • Barcodes Generation
    • Inline Button
    • Conditional Details
    • Using Ajax in Forms
  • Emailing
    • Basic Usage
    • Advanced Usage
  • Calculated Columns
    • Example - 1
    • Example - 2
  • Custom Templates
    • Grid View
    • Card View
    • Grid Toolbar
    • Single Record View
    • Separate Page Editing
    • Modal Dialog Editing
    • Inline Form Editing
    • Wizard Form
    • Custom Filter - 1
    • Custom Filter - 2
    • Export & Print: Data Grid
    • Invoice generation
  1. Exporting & Printing
  2. Exporting & Printing.Custom Single Record
    • Grid
    • Single Record
    • Export Options
    • Custom Grid
    • User Defined Styles

Exporting & Printing.Custom Single Record

Page settings

Appearance

Here you can select the number of cards to be placed in a row for each of supported screen resolutions. Your current resolution is highlighted in this way.

Cancel Save changes
×

This page demonstrates how to customize export to PDF and the Print form for a single record. For this purpose you need to override the export/pdf_record.tpl and view/print_grid.tpl templates respectively (note that the sales_invoice.tpl template is shared between those templates to avoid code duplication) and point PHP Generator to use modified templates with the OnGetCustomTemplate event.

Click any of or buttons to see the generated invoice. Click the button to get familiar with the event handler code.

Add new
Refresh
Export
  • Export to Pdf
  • Export to Excel
  • Export to Word
  • Export to Xml
  • Export to Csv
Print
  • Print current page
  • Print all pages
  • Clear
  • Selection filter
    • Show selected only
    • Show unselected only
    • Show all
  • Export
    • Export to Pdf
    • Export to Excel
    • Export to Word
    • Export to Xml
    • Export to Csv
  • Update
        protected function doGetCustomTemplate($type, $part, $mode, &$result, &$params)
        {
            if (($part == PagePart::RecordCard && $mode == PageMode::ExportPdf) ||
              ($part == PagePart::Grid && $mode == PageMode::PrintOneRecord)) {
                
              $invoiceDetails = array();
              $invoiceId = GetApplication()->GetGETValue('pk0');
              $sql =
                  'SELECT product_name, product_number, quantity, unit_price, (quantity * unit_price) AS total ' .  
                  'FROM invoice_detail ' . 
                  'INNER JOIN product ON product.id = invoice_detail.product_id ' .
                  'WHERE invoice_header_id = %d';   
              $this->GetConnection()->ExecQueryToArray(sprintf($sql, $invoiceId), $invoiceDetails);
              
              $invoiceTotal = 0;
              foreach ($invoiceDetails as $invoiceDetail) {
                  $invoiceTotal += $invoiceDetail['total']; 
              }
              
              $params['InvoiceDetails'] = $invoiceDetails;
              $params['InvoiceNumber'] = 'SI-' . sprintf('%03d', $invoiceId);
              $params['InvoiceSubtotal'] = $invoiceTotal; 
              $params['InvoiceTax'] = $invoiceTotal*0.06; 
              $params['InvoiceTotal'] = $params['InvoiceSubtotal'] + $params['InvoiceTax']; 
            
              if ($mode == PageMode::ExportPdf) {
                  $result = 'sales_invoice_pdf.tpl';
              } else {
                  $result = 'sales_invoice_print.tpl';
              }
            }
            if ($part == PagePart::PrintLayout && $mode == PageMode::PrintOneRecord) {
                $result = 'sales_invoice_print_layout.tpl';
            }
        }
{include file="custom_templates/sales_invoice.tpl" InvoiceDate=$Grid.Row.invoice_date.DisplayValue InvoiceCustomer=$Grid.Row.customer_id.DisplayValue BillToAddress=$Grid.Row.bill_to_address.DisplayValue}
<div id="sales-invoice-content">

    <table class="invoice-header" width="100%" align="center">
        <tr>
            <td>
                <table width="100%">
                    <tr>
                        <td width="50%" style="text-align: left;">
                            <img src="external_data/images/company_logo.png" style="max-height:80px;">
                        </td>
                        <td width="50%" style="text-align: right;font-size: 4em;font-weight: bold;">
                            Sales Invoice
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <table width="100%">
                    <tr>
                        <td width="70%" style="text-align: left;">
                            Company Name, Inc.<br>
                            5553 Cash Avenue<br>
                            Phoenix, AZ 85004
                        </td>
                        <td width="30%">
                            <table class="invoice-info">
                                <tr>
                                    <th style="width: 100px;text-align: right;">Date:</th>
                                    <td style="text-align: center;">{$InvoiceDate}</td>
                                </tr>
                                <tr>
                                    <th style="width: 100px;text-align: right;">Invoice #:</th>
                                    <td style="text-align: center;">{$InvoiceNumber}</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td style="text-align: left">
                <table style="margin-top:20px">
                    <tr>
                        <td style="text-align: left">
                            <strong>Bill to:</strong>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: left">
                            {$InvoiceCustomer}<br>
                            {$BillToAddress}
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <table class="invoice-detail" align="center">
        <tr>
            <th>
                #
            </th>
            <th>
                Item
            </th>
            <th>
                Description
            </th>
            <th>
                Quantity
            </th>
            <th>
                Unit Price
            </th>
            <th>
                Line Total
            </th>
        </tr>
        {foreach from=$InvoiceDetails item=detail name=foo}
            <tr>
                <td style="text-align:center;">
                    {$smarty.foreach.foo.index+1}
                </td>
                <td style="text-align:left;">
                    [{$detail.product_number}]
                </td>
                <td style="text-align:left;">
                    {$detail.product_name}
                </td>
                <td style="text-align:center;">
                    {$detail.quantity}
                </td>
                <td style="text-align:right;">
                    ${$detail.unit_price|number_format:2}
                </td>
                <td style="text-align:right;">
                    ${$detail.total|number_format:2}
                </td>
            </tr>
        {/foreach}
        <tr>
            <td colspan="6" style="border:0">
                <hr>
            </td>
        </tr>
        <tr>
            <td colspan="4" style="border:0">
            </td>
            <th style="text-align:right;">
                Subtotal:
            </th>
            <td style="text-align:right;">
                ${$InvoiceSubtotal|number_format:2}
            </td>
        </tr>
        <tr>
            <td colspan="4" style="border:0">
            </td>
            <th style="text-align:right;">
                Tax rate:
            </th>
            <td style="text-align:right;">
                6%
            </td>
        </tr>
        <tr>
            <td colspan="4" style="border:0">
            </td>
            <th style="text-align:right;">
                Tax:
            </th>
            <td style="text-align:right;">
                ${$InvoiceTax|number_format:2}
            </td>
        </tr>
        <tr>
            <td colspan="4" style="border:0">
            </td>
            <th style="text-align:right;">
                Total:
            </th>
            <td style="text-align:right;">
                ${$InvoiceTotal|number_format:2}
            </td>
        </tr>
    </table>

    <div style="text-align: center">
        <p><em>Total payment due in 30 days</em></p>
        <p><small>If you have any questions about this invoice, please contact<br>
            Martha Hamilton, Phone: (802) 555-3623, Email: m.hamilton@example.com</small></p>
        <p><strong>Thank You For Your Business!</strong></p>
    </div>

</div>
{include file="custom_templates/sales_invoice.tpl" InvoiceDate=$Rows[0][1] InvoiceCustomer=$Rows[0][2] BillToAddress=$Rows[0][3]}

 
Actions Invoice Date Customer Bill To Address
  • Invoice Detail
2018-04-02 James Goodridge 5725 Glaze Drive, San Francisco, CA 94109
  • Invoice Detail
2018-04-09 Patrick Smith 5375 Clearland Circle, Seattle, WA 98104
  • Invoice Detail
2018-05-01 Linda Madson 207 Concerto Circle, Salem, OR 97301
  • Invoice Detail
2018-04-24 Anne Brown 594 Tossing Way, Detroit, MI 48226
  • Invoice Detail
2018-04-22 Paul Davis 2342 Peachwillow, Denver, CO 80203
  • Invoice Detail
2018-05-07 Rebecca Taylor 1192 Parkway Drive, Mill Valley, NE 68601
There are no records to display

Multiple Sort

Column Order

Filter builder

About this demo

This demo application contains 100+ pages and illustrates most of features provided by PHP Generator. Hope it will help you to create even more powerful websites for your users.

You can download the demo project from our website and run the demo on your webserver as described in readme.txt.

Download PHP Generator Free Trial

Legend
New Recently added or significantly updated pages.
Pro Pages illustrating features available only in the Professional edition of PHP Generator.

© 2002- SQL Maestro Group. Follow us:

Created with PHP Generator for MySQL. Want to learn more? Download the demo project!

Change your password

Change password for user ''

Passwords do not match. Please try again.

Close Change password