Categories
CRM MySQL PHP

How to change the vTiger CRM PDF layout

Files used to generate the PDF


/www/vtigercrm//include/fpdf/pdfconfig.php

// Has thing like change items per page and the $bottom variable
/www/vtigercrm/modules/Quotes/CreatePDF.php

// This script retrieves data and assembles parts of the PDF
/www/vtigercrm/modules/Quotes/pdf_templates/

// Files in this directory contain parts of the PDF (header, footer, and last page)

/vtigercrm/include/fpdf/templates/

// Files in this directory contain body parts for invoices, sale orders, and quotes
/vtigercrm/include/fpdf/pdf.php

// This script contains the functions related to layout of invoice PDF’s, such as font size, font style, font color, as well as other settings.  !!Be careful – always copy your original file and edit the copy.
/vtigercrm/include/fpdf/body.php

// The main body of the invoice. This is the file specified in modules/Invoice/CreatePDF.php You can copy and rename body.php to like body-rev1.php, and edit it as you please, call it out in CreatePDF.php and tweak from there.
/vtigercrm/include/tcpdf/templates/body.php

// vtiger 5.0.4 The main body of the invoice. This is the file specified in modules/Invoice/CreatePDF.php You can copy and rename body.php to like body-rev1.php, and edit it as you please, call it out in CreatePDF.php and tweak from there.

General layout editing


body.php:

  • The x,y,width is specified for the bubble size and position
  • The numbers can be aligned by deleting spaces in the output lines
  • Since CreatePDF.php controls the output for header.php, footer.php and

body.php, move pieces from footer to body if you like, align them and play with the alignment.

  • Check for commented out items regarding sales tax in CreatePDF.php and body.php
  • I added comments from the invoice to the pdf invoice by adding it in CreatePDF and body.php – used mysql to verify the field names were right and it showed up right the first time.

Changing the formating


Text alignment

FILE:

Alignment is controlled by values in an array named “$colsAlign”. For exemple, to center the values in column ‘Total’, change

$colsAlign[“Total”] = “R”;

to

$colsAlign[“Total”] = “C”;

Set font and size

FILE: vtiger/include/fpdf/pdf.php

Change the line:

$this->SetFont( "Helvetica", "", 8);

To whatever you want. There is line for each element in the invoice/quote. One for the table, one for address etc. With the exception of a bubble block which as the names suggests is the block with rounded courners.

Change alignment of company logo

FILE: modules/Invoice/pdf_templates/header.php

To change the alignment of the company logo you need to to go to and change the figures in line 17:

 // ************** Begin company information *****************
 $imageBlock=array("22","6","0","0");

Radius of box curves

FILE: vtigercrm/include/fpdf/pdf.php

Replace ALL values 2.5 and all values 4.5 with a new number greater than 0 i.e. 1.0

 $this->RoundedRect($r1-16, $y1-1, 52, $y2+1, 2.5, 'DF');

Changing the structure


Stop the last page from printing

FILE: vtigercrm/modules/quote/CreatePDF.php

Change the following:

 // would you like and end page?  1 for yes 0 for no
 $endpage="1";

Change to $endpage=”0″; and this will stop the final page from printing.

Vertical lines

FILE: vtigercrm/include/fdpdf/pdf.php

FILE: vtigercrm/include/fdpdf/templates/body.php

The lines and columns may be changed in the /include/fpdf/templates/body.php file.

Ans:The lines between 39 and 59 are for the columns width. The lines from 90 change the contents and the form of the total block To modify the vertical lines have a look at the ./include/fpdf/pdf.php file (from line 328).

Change the products per page

FILE: /include/fpdf/pdfconfig.php

Change the $products_per_page=”6″ variable to whatever you want. This will change it in quotes and invoices. You may also need to change the $bottom variable to inlarge the table.

Change the size of the main table

FILE: /include/fpdf/pdfconfig.php

Change the $bottom variable

Stop an Item from printing

Basic php use // to stop a single line of code from running, if you need to stop a whole segment put a */ before and a /* after.

For example to stop the contact name from printing you would change:

// Contact Name block
$conBlock=array("79","65");
$pdf->addRecBlock($contact_name, "Contact Name",$conBlock);

to:

// Contact Name block
//$conBlock=array("79","65");
//$pdf->addRecBlock($contact_name, "Contact Name",$conBlock);

This way do not have to delete as you may change your mind.

Add in product comments

FILE: vtigercrm/modules/quotes/CreatePDF.php

On line 153 you want to replace this:

$product_name[$i] = $associated_products[$i]['productName'.$i]

with this:

$product_name[$i] = $associated_products[$i]['productName'.$i]."\n-".$associated_products[$i]['comment'.$i];

Custom Fields in PDF

You must change your createpdf.php

Just after populating datas you can add this kind of code. It has been made in order to select customized fields cf_531, cf_545, cf_501 and include them in invoices

Code:

$add_query = "select vtiger_accountscf.* from vtiger_invoice, vtiger_accountscf
where vtiger_invoice.accountid=vtiger_accountscf.accountid AND invoiceid=".$id;
$result = $adb->query($add_query);
$num_rows = $adb->num_rows($result);

if ($num_rows == 1)
{
$reglement=$adb->query_result($result,0,"cf_531");
$mode=$adb->query_result($result,0,"cf_545");
$ntva=$adb->query_result($result,0,"cf_501");
}

Then you can modify your footer or header and include the value of the fields.

Alternative PDF versions


Alternative invoice and quote pdf template are available based from different community contributions:

– see here

and

– see vtiger Forge at http://forge.vtiger.com/projects/crm-now-pdf/

Categories
MySQL PHP

Searching in MySQL with PHP

Creating a PHP script to search through a MySQL database and display the results, is a fairly simple task. Using the MySQL LIKE and NOT LIKE operands, we can find specific values within our database tables.

MySQL gives us the ability to search for terms exactly as they are entered or close to what is entered by using the percentage % or the underscore _ character.

Categories
MySQL PHP

PHP MySQL Count Rows

So, you are looking for a simple way to return the number of entries returned from a database query.

mysql_num_rows

This command counts all the rows currently defined by the database query and returns this value.  The best way to use this command, is while saving it the a variable.

Example