Hi All,
Operating system : Linux Ubuntu 12.04 LTS
Database : MySQL 5.5.41
PHP version : 5.4
Web Server : Apache/2.2.22
i have install already install suitecrm which is working fine !
Now i have created a custom module called as Order which we are using in order management process . All the Order are created using API from Web shop .
So what i am trying to do here is i need a PDF Report based on User search . so what i did is i created a Custom button on basic search called as GetReport as show in screen shot below
my code for adding custom button in basic search is below
under suitecrm/custom/include/SearchForm/tpls/SearchFormGeneric.tpl
{if $module eq 'o_order'}
<input title='Get Report' id='get_report' onclick ="SUGAR.ajaxUI.submitForm(this.form);" class='button' type='submit' name='button' value='GetReport'/>
{/if}
For generating PDF based on search i am using mpdf class and i have created a function hereβs my code for that
Under suitecrmDemo/custom/modules/o_order/views/view.list.php
code :
<?php
require_once('include/MVC/View/views/view.list.php');
class o_orderViewList extends ViewList
{
/**
* @see ViewList::preDisplay()
*/
public function preDisplay()
{
parent::preDisplay();
}
public function display()
{
parent::display();
}
public function listViewProcess() // genrating listview
{
$this->processSearchForm();
$this->lv->searchColumns = $this->searchForm->searchColumns;
if(!$this->headers)
return;
if(empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false){
$this->lv->ss->assign("SEARCH",true);
$this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
$savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : (' - ' . $_REQUEST['saved_search_select_name']);
$configObject = new Configurator();
$configObject->loadConfig();
$configObject->config['save_query'] = 'no';
$configObject->saveConfig();
echo $this->lv->display();
if($_REQUEST['button']=='GetReport'){
$this->getpdf($this->where);
}
}
}
public function getpdf($cond)
{
require_once('modules/AOS_PDF_Templates/PDF_Lib/mpdf.php');
$d_image = explode('?',SugarThemeRegistry::current()->getImageURL('company_logo.png'));
$head = '<table style="width: 100%; font-family: Arial; text-align: center;" border="0" cellpadding="2" cellspacing="2">
<tbody style="text-align: left;">
<tr style="text-align: left;">
<td style="text-align: left;">
<p><img src="'.$d_image[0].'" style="float: left;"/> </p>
</td>
<tr style="text-align: left;">
<td style="text-align: left;"></td>
</tr>
<tr style="text-align: left;">
<td style="text-align: left;">
</td>
<tr style="text-align: left;">
<td style="text-align: left;"></td>
</tr>
<tr style="text-align: left;">
<td style="text-align: left;">
<b>'.strtoupper($this->bean->name).'</b>
</td>
</tr>
</tbody>
</table><br />';
global $db;
$sql = "SELECT o_order.id , o_order.order_number , o_order.billing_address_country , o_order.total_cost , o_order.tracking_id , o_order.billing_address_city , o_order.order_status , o_order.phone_office , jt0.user_name assigned_user_name , jt0.created_by assigned_user_name_owner , 'Users' assigned_user_name_mod, o_order.date_entered , o_order.assigned_user_id FROM o_order LEFT JOIN users jt0 ON o_order.assigned_user_id=jt0.id AND jt0.deleted=0 AND jt0.deleted=0 where ($cond) AND o_order.deleted=0 ORDER BY o_order.date_entered DESC";
$res = $db->query($sql);
$body_head = '<table cellpadding="0" cellspacing="0" width="100%" border="0" ><tbody><tr>
<td scope="col" width="12%" bgcolor="#35478F" color="#FFFFFF" > Order number </td>
<td scope="col" width="12%" bgcolor="#35478F" color="#FFFFFF" > Billing Country </td>
<td scope="col" width="12%" bgcolor="#35478F" color="#FFFFFF" > Order status </td>
<td scope="col" width="12%" bgcolor="#35478F" color="#FFFFFF" > Phone </td>
<td scope="col" width="19%" bgcolor="#35478F" color="#FFFFFF" > Tracking Id </td>
<td scope="col" width="2%" bgcolor="#35478F" color="#FFFFFF" > Total Cost </td>
<td scope="col" width="2%" bgcolor="#35478F" color="#FFFFFF" > Date Entered </td></tr>';
$body_foot = '</tbody></table>';
$out_put='';
while($f_res = $db->fetchByAssoc($res)){
$out_put .= '<tr hight="20"><td scope="row" align="left" valign="top">'.$f_res['order_number'].'</td>
<td scope="row" align="left" valign="top">'.$f_res['billing_address_country'].'</td>
<td scope="row" align="left" valign="top">'.$f_res['order_status'].'</td>
<td scope="row" align="left" valign="top">'.$f_res['phone_office'].'</td>
<td scope="row" align="left" valign="top">'.$f_res['tracking_id'].'</td>
<td scope="row" align="left" valign="top">'.$f_res['total_cost'].'</td>
<td scope="row" align="left" valign="top">'.$f_res['date_entered'].'</td>
</tr>';
}
$table = $body_head.$out_put.$body_foot;
$stylesheet = file_get_contents('themes/Suite7/css/style.css');
$pdf=new mPDF('en','A4','','DejaVuSansCondensed');
$pdf->setAutoFont();
$pdf->WriteHTML($stylesheet,1);
$pdf->WriteHTML($head,2);
$pdf->WriteHTML('<p><h1>Order Report</h1></p>',2);
$pdf->WriteHTML('<p><h1> </h1></p>',2);
$pdf->WriteHTML($table,3);
$pdf->Output('Order Report', "D");
}
}
so now when i click on GetReport button its creating a Pdf based on search criteria . as shown in screen shot
i am using chromium web browser .
Now when i click on itβs showing like this
but if i open the pdf from pdf reader then its working as shown
so my question is
1 ) what might be the problem is it the problem with browser ? or some thing else ?
2 ) or is there a way to attache this file directly with mail ? ( i know this question dose not belong to question title )
Thank you so much for your time !