While creating reports for invoice in VTiger, I grouped the invoice total and sorted it in descending order,the invoice total was not sorted properly, its being sorted as per the first digit.(For instance if the invoice total is 400,200,2100,100,it is sorted as 400,2100,200,100, the proper order should be 2100,400,200,100).

To get it in proper order put the following code in [vtigerroot]/layouts/vlayout/Reports/ReportContents.tpl in function getReport on line 180 after

$viewer->assign(‘ADVANCEFILTER’, $advFilterSql);

foreach ($data as $key => $row) {

foreach($row as $key1=>$value)






{  $sortkey=’Total’;  }



foreach ($data1 as $key => $row) {

foreach($row as $key1=>$value)

{ if($key1==’Total’)

{  $data1[$key][$key1]=”₹”.$data1[$key][‘Total’];}



/*uncomment below line for getting data in descending order*/



It takes the Total Fields from array, removes the ₹ symbol (or currency selected by user in vtiger), and converts it to string and sort the data on the basis of total field in ascending order.

Data is sorted properly in invoice reports when sorted by total field.

For any further queries get in touch we would be glad to help you Solve your Query