SugarCRM 6.5 custom module print pdf layout -
i newly sugarcrm 6.5 developer, have create custom module details print pdf confused in controller action , view.detail page. how create print pdf, please me.
controller function
protected function action_printinvoice(){
global $current_user, $db, $region;
$db = dbmanagerfactory::getinstance(); $id = $_post['record'];
$sql = "select gn.client_name, gn.client_address, gn.client_address_city, gn.client_address_state, gn.client_address_country, gn.client_address_postalcode, gn.id, gn.recipient_name, gn.recipient_address_city, gn.recipient_address_state, gn.recipient_address_country, gn.recipient_address_postalcode, gn.recipient_address, gn.recipient_vat_id, gn.recipient_tax_no, gn.recipient_name, gn.invoice_number ginvo_client_invoice_id, " . " gcstm.* " . "from ginvo_client_invoice gn " . " inner join ginvo_client_invoice_cstm gcstm on gn.id=gcstm.id_c " . "where " . " gn.deleted=0 , gn.id='".$id."' limit 1 ";
$result = $db->query($sql); $ginv_invoice_ary=array(); while($row = $db->fetchbyassoc($result) ) { $ginv_invoice_ary[]=$row; } if ($ginv_invoice_ary[0]['region_c'] == 'non_eu_client_and_freelancer_provider') { $region = 'non eu client , freelancer provider'; }else if($ginv_invoice_ary[0]['region_c'] == 'non_eu_client_and_employed_provider'){ $region = 'non eu client , employed provider'; }else if($ginv_invoice_ary[0]['region_c'] == 'german_client_and_freelancer_provider'){ $region = 'german client , freelancer provider'; }else if($ginv_invoice_ary[0]['region_c'] == 'german_client_and_employed_provider'){ $region = 'german client , employed provider'; }else if($ginv_invoice_ary[0]['region_c'] == 'eu_client_and_freelancer_provider'){ $region = 'eu client , freelancer provider'; }else if ($ginv_invoice_ary[0]['region_c'] == 'eu_client_and_employed_provider') { $region = 'eu client , employed provider'; }else { $region = ''; } echo json_encode($ginv_invoice_ary); //$this->view = 'invoiceprint'; //$this->view = 'custom/modules/ginvo_client_invoice/metadata/clientinvoice.php'; exit;
}
view.detail.php file
<?php require_once('include/mvc/view/views/view.detail.php'); // require_once('modules/ginvo_client_invoice/view/invoice.php'); class ginvo_client_invoiceviewdetail extends viewdetail { function ginvo_client_invoiceviewdetail(){ parent::viewdetail(); } function display(){ echo $ginv_invoice_ary; //$this->populatequotetemplates(); $this->displaypopuphtml(); parent::display(); } function populatequotetemplates(){ global $app_list_strings, $current_user; $inv_id = $this->bean->id; $sql = "select * ginvo_client_invoice deleted=0 , id='$inv_id'"; $res = $this->bean->db->query($sql); $app_list_strings[] = array(); while($row = $this->bean->db->fetchbyassoc($res)){ if($row){ $app_list_strings[$row] = $row; } } } function displaypopuphtml(){ global $app_list_strings,$app_strings, $mod_strings; $templates = array_keys($app_list_strings); if($templates){ echo ' <script> function showpopup(task){ var record = \''.$this->bean->id.'\'; var fdata = {\'record\':record}; var params = jquery.param(fdata); $.ajax({ type:"post", data: fdata, // datatype: "json", // url:"custom/client_invoice.php?"+params, //url:"custom/modules/ginvo_client_invoice/clientinvoice.php?\'+params, url:"index.php?module=ginvo_client_invoice&action=printinvoice", error:function(resp){}, success:function(resp){ $.ajax({ type: "get", url: "custom/clientinvoice.php", data: resp, cache: false, success: function (data) { console.log(data); } }); // location.reload(true); } }); // var w = window.open(\'custom/clientinvoice.php\'); // // $(w).ready(function(){ // w.print(); // }); } </script>'; } else{ echo '<script> function showpopup(task){ alert(\''.$current_user.'\'); } </script>'; } } } ?>
create button on detail view. , extends sugarpdf class per below link. http://support.sugarcrm.com/documentation/sugar_developer/sugar_developer_guide_6.5/application_framework/sugarpdf/generating_pdfs/
you can further read at: https://community.sugarcrm.com/thread/29335-how-to-generate-a-quote-pdf-programmatically https://community.sugarcrm.com/thread/19796
regards, usman
Comments
Post a Comment